:root {
  --ink: #0b1f33;
  --ink-soft: #3d5266;
  --muted: #6b7c8f;
  --paper: #f3f6fa;
  --panel: #ffffff;
  --line: #d5dde8;
  --teal: #0a7c78;
  --teal-deep: #065f5c;
  --teal-soft: #d7f1ef;
  --panel-glass: rgba(255,255,255,0.72);
  --input: #ffffff;
  --hover: rgba(255,255,255,0.8);
  --chat-bg: #e7ebef;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --amber: #c47a14;
  --rose: #b42345;
  --ok: #1f7a4c;
  --shadow: 0 18px 50px rgba(11, 31, 51, 0.08);
  --radius: 18px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f5f7fa;
  --ink-soft: #d4dbe3;
  --muted: #8d9baa;
  --paper: #0e1621;
  --panel: #17212b;
  --line: #263746;
  --teal: #2a9d8f;
  --teal-deep: #68c7bb;
  --teal-soft: #193d43;
  --panel-glass: rgba(23,33,43,0.88);
  --input: #202b36;
  --hover: rgba(43,82,120,0.32);
  --chat-bg: #0e1621;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --shadow: 0 18px 50px rgba(0,0,0,0.25);
  --amber: #f0b35c;
  --rose: #ff6b83;
  --ok: #63c98a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Author `display:` rules must not override the hidden attribute */
[hidden] { display: none !important; }

button, input, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--teal); }
.mobile-only { display: none !important; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ui-icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-block;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--input);
  color: var(--ink);
  font-size: 1.1rem;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  font-weight: 600;
  transition: transform .15s ease, background .15s ease, opacity .15s ease;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: wait; transform: none; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-deep); }
.btn-soft {
  background: var(--teal-soft);
  color: var(--teal-deep);
  padding: 0.45rem 0.9rem;
  border-radius: 12px;
}
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}

.form-error {
  color: var(--rose);
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
}

.login-body {
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(1rem, var(--safe-top)) max(1rem, var(--safe-right)) max(1rem, var(--safe-bottom)) max(1rem, var(--safe-left));
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
}
.login-theme-toggle {
  position: fixed;
  z-index: 5;
  top: max(1rem, var(--safe-top));
  right: max(1rem, var(--safe-right));
}
.login-atmosphere {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 18% 20%, rgba(10, 124, 120, 0.18), transparent 42%),
    radial-gradient(circle at 82% 10%, rgba(196, 122, 20, 0.12), transparent 36%),
    linear-gradient(155deg, #e7eef7 0%, #f7f9fc 45%, #dff3f1 100%);
  z-index: 0;
}
.login-atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    -28deg,
    transparent 0 18px,
    rgba(11, 31, 51, 0.025) 18px 19px
  );
}
.login-shell {
  position: relative;
  z-index: 1;
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 1.5rem;
  align-items: stretch;
}
.login-brand {
  padding: 2.4rem 1.5rem 2.4rem 0.5rem;
  animation: rise 0.7s ease both;
}
.login-brand h1 {
  font-family: var(--display);
  font-size: clamp(2.2rem, 4vw, 3.4rem);
  line-height: 1.05;
  margin: 1rem 0 0.9rem;
  letter-spacing: -0.03em;
  max-width: 11ch;
}
.brand-lead {
  color: var(--ink-soft);
  font-size: 1.05rem;
  max-width: 34ch;
  line-height: 1.55;
}
.login-card {
  background: var(--panel);
  border: 1px solid rgba(213, 221, 232, 0.9);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  animation: rise 0.7s ease 0.08s both;
}
.login-card h2 { margin: 0 0 1.2rem; font-size: 1.15rem; }
.login-card label { display: grid; gap: 0.35rem; margin-bottom: 0.9rem; }
.login-card label span { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.login-card input {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  background: #fbfcfe;
  outline: none;
  font-size: 16px;
}
.login-card input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(10, 124, 120, 0.15);
}
.login-card .btn-primary { width: 100%; margin-top: 0.4rem; min-height: 48px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.app-body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.app-grid {
  height: 100%;
  display: grid;
  grid-template-columns: 220px 340px minmax(0, 1fr) 260px;
  background:
    linear-gradient(180deg, rgba(215, 241, 239, 0.35), transparent 28%),
    var(--paper);
}

.sidebar {
  padding: 1.2rem 1rem;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(8px);
}
.sidebar-user { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.85rem; }
.side-nav { display: grid; gap: 0.4rem; }
.nav-btn {
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  min-height: 44px;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.nav-btn.active, .nav-btn:hover {
  background: var(--teal-soft);
  color: var(--teal-deep);
}
.brand-actions { display: inline-flex; align-items: center; gap: 0.25rem; }
.brand-row .icon-btn.push-on {
  color: var(--teal-deep);
  background: var(--teal-soft);
}
.stat-strip div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
}
.stat-strip span {
  display: block;
  font-family: var(--display);
  font-size: 1.4rem;
  line-height: 1;
}
.stat-strip small { color: var(--muted); }
.push-box {
  display: grid;
  gap: 0.4rem;
  margin: 0.65rem 0 0.25rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}
.push-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}
.push-btn {
  width: 100%;
  min-height: 42px;
  justify-content: flex-start;
}
.bulk-close-block {
  margin: 0 1rem 0.65rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
  display: grid;
  gap: 0.55rem;
}
.bulk-close-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.bulk-close-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
  align-items: center;
}
.bulk-close-row input[type="date"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input);
  color: var(--ink);
  padding: 0.35rem 0.55rem;
}
.bulk-close-row .btn-soft {
  white-space: nowrap;
  min-height: 40px;
  padding: 0.45rem 0.75rem;
}
.bulk-close-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(11, 31, 51, 0.45);
  backdrop-filter: blur(4px);
}
.modal-card {
  width: min(100%, 420px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: grid;
  gap: 0.85rem;
}
.modal-card h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.25rem;
}
.modal-text {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.45;
}
.modal-check {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  cursor: pointer;
}
.modal-check input {
  margin-top: 0.2rem;
  flex: 0 0 auto;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
}
.logout-btn { width: 100%; min-height: 44px; }

.inbox-pane, .users-pane, .chat-pane, .user-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.inbox-pane, .users-pane { border-right: 1px solid var(--line); background: rgba(255,255,255,0.4); }
.pane-head {
  padding: 1rem;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 0.75rem;
}
.filters {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-weight: 600;
  white-space: nowrap;
  flex: 0 0 auto;
  min-height: 36px;
  touch-action: manipulation;
}
.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
#search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: #fff;
  outline: none;
  font-size: 16px;
}
#search:focus { border-color: var(--teal); }

.ticket-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.5rem;
  -webkit-overflow-scrolling: touch;
}
.ticket-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 16px;
  padding: 0.95rem 0.9rem;
  display: grid;
  gap: 0.25rem;
  margin-bottom: 0.35rem;
  color: inherit;
  min-height: 64px;
  touch-action: manipulation;
}
.ticket-item:hover { background: rgba(255,255,255,0.8); }
.ticket-item.active {
  background: #fff;
  border-color: var(--line);
  box-shadow: 0 8px 24px rgba(11, 31, 51, 0.06);
}
.ticket-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}
.ticket-id { font-weight: 700; }
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.18rem 0.5rem;
}
.badge-open { background: #fff1d6; color: var(--amber); }
.badge-in_progress { background: var(--teal-soft); color: var(--teal-deep); }
.badge-closed { background: #e7f6ec; color: var(--ok); }
.ticket-subject {
  color: var(--ink-soft);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ticket-sub { color: var(--muted); font-size: 0.78rem; }

.chat-pane { background: #f7fafc; position: relative; }
.empty-state {
  margin: auto;
  text-align: center;
  color: var(--ink-soft);
  padding: 2rem;
  animation: rise .5s ease both;
}
.empty-state h2 {
  font-family: var(--display);
  margin: 0.6rem 0 0.4rem;
  color: var(--ink);
}
.chat-wrap { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(8px);
}
.chat-head-main { min-width: 0; flex: 1; }
.chat-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
}
.chat-head p { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.88rem; }
.chat-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.back-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.2rem;
  flex: 0 0 auto;
  touch-action: manipulation;
}

.mobile-user-card {
  margin: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.mobile-user-card summary {
  list-style: none;
  cursor: pointer;
  padding: 0.7rem 1rem;
  font-weight: 600;
  color: var(--teal-deep);
}
.mobile-user-card summary::-webkit-details-marker { display: none; }
.mobile-user-card dl {
  margin: 0;
  padding: 0 1rem 0.9rem;
  display: grid;
  gap: 0.55rem;
}
.mobile-user-card dt {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}
.mobile-user-card dd { margin: 0.1rem 0 0; font-weight: 600; }

.messages {
  flex: 1;
  overflow: auto;
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  width: fit-content;
  max-width: min(420px, 72%);
  padding: 0.55rem 0.75rem;
  border-radius: 14px;
  line-height: 1.4;
  animation: rise .25s ease both;
  word-break: break-word;
}
.bubble .bubble-text {
  margin: 0;
  white-space: pre-wrap;
}
.bubble.user {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
}
.bubble.admin {
  align-self: flex-end;
  background: var(--teal);
  color: #fff;
}
.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0.2rem;
  max-width: 90%;
}
.bubble .meta {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.7rem;
  opacity: 0.75;
}
.attach-tag {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  opacity: 0.9;
}
.attach-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.45rem;
}
.attach-preview {
  display: block;
  max-width: min(360px, 100%);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(11, 31, 51, 0.08);
}
.attach-preview img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 420px;
  object-fit: contain;
  background: rgba(0,0,0,0.04);
}
.bubble.admin .attach-preview { border-color: rgba(255,255,255,0.25); }
.attach-file {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: inherit;
  font-size: 0.88rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 0.9rem 1.1rem calc(1.1rem + var(--safe-bottom));
  background: #fff;
}
.composer-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.55rem;
  align-items: end;
}
.composer textarea {
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem 0.85rem;
  outline: none;
  min-height: 48px;
  max-height: 140px;
  font-size: 16px;
}
.composer textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(10, 124, 120, 0.12);
}
.file-btn {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  background: #f8fafc;
  touch-action: manipulation;
}
.file-name { margin: 0.45rem 0 0; color: var(--muted); font-size: 0.82rem; word-break: break-all; }
#send-btn { min-height: 48px; }

.user-pane {
  border-left: 1px solid var(--line);
  padding: 1.1rem;
  background: rgba(255,255,255,0.65);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.user-pane h3 {
  margin: 0 0 0.8rem;
  font-family: var(--display);
  flex: 0 0 auto;
}
.user-pane dl {
  margin: 0;
  display: grid;
  gap: 0.7rem;
  flex: 1;
  min-height: 0;
  align-content: start;
}
.user-pane dt { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.user-pane dd { margin: 0.15rem 0 0; font-weight: 600; }

.users-pane { grid-column: 2 / -1; }
.users-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.5rem 1rem 1rem;
  -webkit-overflow-scrolling: touch;
}
.users-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.users-table th, .users-table td {
  padding: 0.8rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.users-table th { color: var(--muted); font-weight: 600; background: #f8fafc; }

@media (max-width: 1100px) {
  .app-grid { grid-template-columns: 200px 300px minmax(0, 1fr); }
  .user-pane { display: none !important; }
}

@media (max-width: 860px) {
  .mobile-only { display: initial !important; }
  .login-shell { grid-template-columns: 1fr; gap: 1rem; }
  .login-brand { padding: 0.25rem 0.25rem 0; }
  .login-brand h1 {
    font-size: clamp(1.9rem, 9vw, 2.6rem);
    max-width: none;
  }
  .brand-lead { font-size: 0.98rem; max-width: none; }
  .login-card { padding: 1.35rem; border-radius: 22px; }

  .app-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: 0.55rem;
    padding: calc(0.65rem + var(--safe-top)) max(0.75rem, var(--safe-right)) 0.65rem max(0.75rem, var(--safe-left));
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
    z-index: 5;
  }
  .sidebar-brand { min-width: 0; flex: 1; }
  .sidebar-brand .brand-mark { font-size: 1.05rem; }
  .sidebar-user {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .side-nav { display: flex; gap: 0.3rem; flex: 0 0 auto; }
  .nav-btn {
    padding: 0.55rem 0.7rem;
    font-size: 0.85rem;
    white-space: nowrap;
  }
  .stat-strip,
  .logout-btn:not(.mobile-only) { display: none !important; }
  .push-box { display: none !important; }
  .logout-btn.mobile-only {
    display: inline-flex !important;
    width: auto;
    padding: 0.5rem 0.7rem;
    font-size: 0.82rem;
    flex: 0 0 auto;
  }

  .inbox-pane,
  .chat-pane,
  .users-pane {
    display: none;
    min-height: 0;
    height: 100%;
    border-right: 0;
  }
  .app-grid.show-list .inbox-pane { display: flex; }
  .app-grid.show-chat .chat-pane { display: flex; }
  .app-grid.show-users .users-pane {
    display: flex;
    grid-column: 1;
  }
  .app-grid.show-list .chat-pane,
  .app-grid.show-list .users-pane,
  .app-grid.show-chat .inbox-pane,
  .app-grid.show-chat .users-pane,
  .app-grid.show-users .inbox-pane,
  .app-grid.show-users .chat-pane { display: none; }

  .empty-state { display: none; }

  .chat-head {
    padding: 0.7rem 0.75rem;
    align-items: center;
    gap: 0.55rem;
  }
  .chat-head h2 { font-size: 1.1rem; }
  .chat-head p {
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .chat-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 42%;
  }
  .chat-actions .btn-soft {
    padding: 0.4rem 0.65rem;
    font-size: 0.78rem;
    white-space: nowrap;
  }
  .back-btn { display: inline-grid !important; place-items: center; }

  .mobile-user-card[hidden] { display: none !important; }
  .mobile-user-card:not([hidden]) { display: block !important; }

  .messages { padding: 0.85rem 0.75rem; }
  .bubble { max-width: min(340px, 78%); }
  .attach-preview { max-width: 100%; }
  .attach-preview img { max-height: 260px; }

  .composer { padding: 0.65rem 0.7rem calc(0.75rem + var(--safe-bottom)); }
  .composer-row {
    grid-template-columns: 1fr 48px;
    grid-template-areas:
      "text text"
      "file send";
  }
  .composer textarea { grid-area: text; min-height: 52px; }
  .file-btn { grid-area: file; }
  #send-btn {
    grid-area: send;
    width: 100%;
    border-radius: 14px;
  }

  .pane-head { padding: 0.75rem; }
  .ticket-list { padding: 0.35rem 0.45rem calc(0.75rem + var(--safe-bottom)); }

  .users-pane .pane-head h2 { font-size: 1.05rem; margin: 0; }
  .users-table-wrap { padding: 0.35rem 0.55rem calc(0.85rem + var(--safe-bottom)); }
  .users-table,
  .users-table thead,
  .users-table tbody,
  .users-table th,
  .users-table td,
  .users-table tr { display: block; }
  .users-table thead { display: none; }
  .users-table tr {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    margin-bottom: 0.55rem;
    padding: 0.7rem 0.8rem;
  }
  .users-table td {
    border: 0;
    padding: 0.2rem 0;
    font-size: 0.88rem;
  }
  .users-table td:nth-child(1)::before { content: "ID · "; color: var(--muted); font-weight: 600; }
  .users-table td:nth-child(2)::before { content: "Имя · "; color: var(--muted); font-weight: 600; }
  .users-table td:nth-child(3)::before { content: "Заявки · "; color: var(--muted); font-weight: 600; }
  .users-table td:nth-child(4)::before { content: "Открыто · "; color: var(--muted); font-weight: 600; }
  .users-table td:nth-child(5)::before { content: "Визит · "; color: var(--muted); font-weight: 600; }
  .users-table td:last-child { padding-top: 0.55rem; }
}

@media (max-width: 420px) {
  .sidebar-brand .brand-mark { font-size: 0.95rem; }
  .nav-btn { padding: 0.5rem 0.55rem; font-size: 0.8rem; }
  .chat-actions { max-width: 38%; }
}

/* Telegram-inspired chat experience */
.app-grid {
  background: var(--paper);
}
.sidebar,
.inbox-pane,
.users-pane,
.user-pane,
.chat-head {
  background: var(--panel-glass);
}
.chip,
#search,
.back-btn,
.mobile-user-card,
.composer,
.composer textarea,
.file-btn,
.users-table,
.users-table th,
.users-table tr {
  background: var(--input);
  color: var(--ink);
}
.chat-pane {
  background-color: var(--chat-bg);
}
.messages {
  background-color: var(--chat-bg);
  background-image:
    radial-gradient(circle at 20px 20px, rgba(10,124,120,.055) 1.2px, transparent 1.3px),
    radial-gradient(circle at 60px 60px, rgba(10,124,120,.045) 1.2px, transparent 1.3px);
  background-size: 80px 80px;
}

.ticket-item {
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 0.75rem;
  align-items: center;
  padding: 0.72rem 0.65rem;
  border-radius: 11px;
}
.ticket-item:hover { background: var(--hover); }
.ticket-item.active {
  background: var(--teal);
  border-color: transparent;
  color: #fff;
  box-shadow: none;
}
.ticket-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #54a7df, #337ead);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  position: relative;
  overflow: hidden;
}
.ticket-avatar img,
.profile-avatar img,
.table-avatar img,
.header-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}
.header-avatar,
.profile-avatar,
.table-avatar {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(145deg, #54a7df, #337ead);
  color: #fff;
  font-weight: 750;
}
.header-avatar { width: 44px; height: 44px; font-size: .76rem; }
.profile-avatar { width: 64px; height: 64px; font-size: 1rem; }
.table-avatar { width: 34px; height: 34px; font-size: .65rem; }
.profile-summary {
  display: flex !important;
  align-items: center;
  gap: .75rem;
  padding-bottom: .85rem;
  margin-bottom: .15rem;
  border-bottom: 1px solid var(--line);
}
.profile-summary strong { display: block; overflow-wrap: anywhere; }
.profile-summary small { display: block; margin-top: .15rem; color: var(--muted); }
.status-pill {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: .38rem;
  border-radius: 999px;
  padding: .32rem .58rem;
  font-size: .78rem;
  font-weight: 750;
}
.status-pill.active { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.status-pill.blocked { color: var(--rose); background: color-mix(in srgb, var(--rose) 12%, transparent); }
.user-table-name { display: inline-flex; align-items: center; gap: .55rem; }
.ticket-content {
  min-width: 0;
  display: grid;
  gap: 0.16rem;
}
.ticket-top,
.ticket-bottom {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ticket-top time {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}
.ticket-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.91rem;
}
.ticket-preview {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.8rem;
}
.ticket-details {
  color: var(--muted);
  font-size: 0.68rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ticket-details .ui-icon { vertical-align: -0.16em; margin-right: .2rem; }
.ticket-item.active .ticket-preview,
.ticket-item.active .ticket-details,
.ticket-item.active .ticket-top time {
  color: rgba(255,255,255,.78);
}
.unread-badge {
  flex: 0 0 auto;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  display: inline-grid;
  place-items: center;
  background: var(--teal);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
}
.ticket-item.active .unread-badge {
  background: #fff;
  color: var(--teal);
}

.bubble {
  max-width: min(560px, 78%);
  border-radius: 12px;
  padding: 0.52rem 0.68rem 0.38rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.bubble.user {
  background: var(--bubble-in);
  border: 0;
  border-bottom-left-radius: 3px;
}
.bubble.admin {
  background: var(--bubble-out);
  color: var(--ink);
  border-bottom-right-radius: 3px;
}
.bubble .meta {
  text-align: right;
  color: var(--muted);
}
.bubble.admin .meta { color: color-mix(in srgb, var(--ink) 58%, transparent); }
.attach-video {
  display: block;
  width: min(420px, 100%);
  max-height: 420px;
  border-radius: 10px;
  background: #000;
}
.attach-audio {
  display: block;
  width: min(360px, 100%);
}
.media-card { display: grid; gap: 0.28rem; }
.download-link {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  justify-self: end;
  color: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: none;
  opacity: .78;
}
.attach-file {
  min-width: min(300px, 100%);
  padding: 0.68rem;
  border-radius: 10px;
  background: rgba(10,124,120,.1);
  text-decoration: none;
}
.attach-file span {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-file strong { font-size: 0.72rem; }
.attach-file strong { display: inline-flex; align-items: center; gap: .22rem; }
.attach-tag { display: inline-flex; align-items: center; gap: .3rem; }
.chat-head p {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .35rem .55rem;
}
.chat-status {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  border-radius: 999px;
  padding: .18rem .46rem;
  font-weight: 700;
}
.chat-status.status-open { color: var(--amber); background: color-mix(in srgb, var(--amber) 13%, transparent); }
.chat-status.status-in_progress { color: var(--teal-deep); background: var(--teal-soft); }
.chat-status.status-closed { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }

.composer { position: relative; }
.composer-row {
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  max-width: 900px;
  margin: 0 auto;
}
.composer-icon,
.file-btn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  font-size: 1.35rem;
}
.composer-icon:hover,
.file-btn:hover { background: var(--hover); color: var(--teal); }
.composer textarea {
  border-radius: 22px;
  padding: 0.75rem 1rem;
}
.emoji-picker {
  position: absolute;
  left: 1rem;
  bottom: calc(100% - 0.2rem);
  z-index: 15;
  width: min(360px, calc(100vw - 2rem));
  max-height: 260px;
  overflow: auto;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  grid-template-columns: repeat(8, 1fr);
  gap: 0.2rem;
}
.emoji-picker:not([hidden]) { display: grid; }
.emoji-option {
  border: 0;
  border-radius: 9px;
  background: transparent;
  height: 38px;
  font-size: 1.28rem;
}
.emoji-option:hover { background: var(--hover); }

[data-theme="dark"] .login-atmosphere {
  background:
    radial-gradient(circle at 18% 20%, rgba(42,157,143,.18), transparent 42%),
    radial-gradient(circle at 82% 10%, rgba(43,82,120,.2), transparent 36%),
    linear-gradient(155deg, #0e1621 0%, #17212b 100%);
}
[data-theme="dark"] .login-card,
[data-theme="dark"] .stat-strip div {
  border-color: var(--line);
}
[data-theme="dark"] .login-card input {
  background: var(--input);
  color: var(--ink);
}

@media (max-width: 860px) {
  .theme-toggle { width: 34px; height: 34px; }
  .composer-row {
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    grid-template-areas:
      "emoji text file"
      "send send send";
  }
  .emoji-btn { grid-area: emoji; }
  .composer textarea { grid-area: text; }
  .file-btn { grid-area: file; }
  #send-btn { grid-area: send; }
  .emoji-picker { left: 0.7rem; }
}

@media (max-width: 420px) {
  .theme-toggle { width: 32px; height: 32px; font-size: .95rem; }
  .ticket-item { grid-template-columns: 44px minmax(0, 1fr); }
  .ticket-avatar { width: 44px; height: 44px; }
}
