/* TextAI agent console.
   Layout mirrors the conventions of mainstream support desks (Intercom, Crisp,
   Zendesk): a dark icon rail on the far left, then a filterable conversation
   list, the thread, and a visitor detail column on the right. */

:root {
  /* Brand palette shared with the marketing site and the visitor widget. Ink
     and gold are the only two colours the TextAI logo uses. */
  --brand-ink: #0b0b0c;
  --brand-gold: #d4af37;
}

/* ------------------------------------------------------------------ login */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 520px at 12% -10%, var(--primary-soft), transparent 60%),
    radial-gradient(700px 460px at 96% 110%, var(--accent-soft), transparent 60%),
    var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 384px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 30px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

.login-card input {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.login-error { color: var(--accent); font-size: 13px; margin: 0; }

.captcha { display: flex; align-items: stretch; gap: 8px; }
.captcha input { flex: 1 1 auto; min-width: 0; }
.captcha-image {
  flex: 0 0 auto;
  width: 150px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #111114;
  cursor: pointer;
  overflow: hidden;
  line-height: 0;
  display: grid;
  place-items: center;
}
.captcha-image svg { display: block; width: 100%; height: auto; }
.captcha-image:hover { border-color: var(--primary); }

.brand { display: flex; align-items: center; gap: 10px; }

/* The official mark: an ink rounded square with the two gold text lines. */
.brand-mark {
  width: 34px; height: 34px; flex: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8' fill='%230b0b0c'/%3E%3Cpath d='M9 12h14M9 17h9' stroke='%23d4af37' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.brand-name { font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------- app shell */

/* Pin the console to the viewport so every column scrolls on its own instead
   of growing the page and pushing the composer below the fold. */
.app { height: 100vh; height: 100dvh; overflow: hidden; display: flex; }

/* ---- icon rail ---- */

.rail {
  flex: 0 0 68px; width: 68px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: #10141f;
  padding: calc(14px + env(safe-area-inset-top)) 8px calc(14px + env(safe-area-inset-bottom));
}

.rail-brand { margin-bottom: 6px; }
.rail-brand .brand-mark { width: 36px; height: 36px; }

.rail-nav {
  flex: 1; width: 100%; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}

.topnav-item {
  width: 46px; height: 46px; border: 0; border-radius: 13px;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; color: #8b93a7;
  transition: background .15s ease, color .15s ease;
}
.topnav-item svg { width: 21px; height: 21px; display: block; }
.topnav-item:hover { background: rgba(255, 255, 255, .09); color: #fff; }
.topnav-item[data-active='1'] { background: var(--brand-gold); color: var(--brand-ink); }

.rail-foot { display: flex; flex-direction: column; align-items: center; gap: 8px; }
/* The rail sits on a dark surface, so the avatar uses the inverse mark: a gold
   disc with an ink monogram. */
.rail-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--brand-gold); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}

/* ---- workspace ---- */

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

.topbar {
  flex: none; display: flex; align-items: center; gap: 18px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-title { min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.topbar-sub { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 2px; }

.presence-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.presence-dot[data-status='online'] { background: var(--success); }
.presence-dot[data-status='busy'] { background: var(--warning); }

.topbar-stats { flex: 1; display: flex; gap: 8px; flex-wrap: wrap; min-width: 0; }

.stat {
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 14px; border-radius: 10px; background: var(--surface-2);
  min-width: 66px;
}
.stat b { font-size: 15px; line-height: 1.2; }
.stat span { font-size: 11px; color: var(--muted); white-space: nowrap; }

.topbar-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* ---- three column body ---- */

.layout {
  flex: 1; display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 316px;
  min-height: 0;
}

.pane { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.list-pane, .chat-pane { border-right: 1px solid var(--line); }

.pane-head {
  flex: none; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  border-bottom: 1px solid var(--line);
}

.pane-head h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.pane-note { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }

.tabs button {
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--muted);
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.tabs button:hover { color: var(--fg); border-color: var(--muted); }
.tabs button[data-active='1'] { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }

.search, .select {
  width: 100%; padding: 8px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); outline: none;
}
.search:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.select { width: auto; }

/* ---- conversation list ---- */

.list { overflow-y: auto; flex: 1; }

.conv {
  position: relative; display: flex; gap: 12px; padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid var(--line);
  transition: background .12s ease;
}
.conv:hover { background: var(--surface-2); }
.conv[data-active='1'] { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.conv .grow { flex: 1; min-width: 0; }
.conv .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.conv .preview {
  font-size: 12.5px; color: var(--muted); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.conv .unread {
  min-width: 20px; height: 20px; border-radius: 10px; background: var(--accent); color: #fff;
  font-size: 11px; display: grid; place-items: center; padding: 0 6px; font-weight: 700; align-self: center; flex: none;
}

/* Avatars mirror the logo: an ink rounded square with a gold monogram. On dark
   surfaces the inverse (gold square, ink monogram) keeps them legible. */
.avatar {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
  background: var(--brand-ink); color: var(--brand-gold);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
[data-theme='dark'] .avatar { background: var(--brand-gold); color: var(--brand-ink); }
.avatar.lg { width: 40px; height: 40px; border-radius: 12px; font-size: 15px; }
.avatar.xl { width: 48px; height: 48px; border-radius: 14px; font-size: 17px; }

/* ---- chat column ---- */

.chat-head {
  flex: none; display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface);
}

.chat-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-id-text { min-width: 0; }
.chat-head .visitor-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .visitor-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-actions { display: flex; gap: 8px; align-items: center; flex: none; }

.messages {
  flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px;
  background: var(--bg);
}

.msg-row { display: flex; }
.msg-row[data-who='agent'] { justify-content: flex-end; }
.msg-row > div { width: fit-content; max-width: min(76%, 560px); min-width: 0; }

.msg {
  width: fit-content; max-width: 100%; padding: 9px 13px; border-radius: 14px; font-size: 14px;
  white-space: pre-wrap; word-break: break-word;
  background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px;
}

.msg-row[data-who='agent'] .msg {
  background: var(--primary); color: var(--primary-fg); border-color: transparent;
  border-bottom-left-radius: 14px; border-bottom-right-radius: 4px;
}

.msg-meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; align-items: center; }
.msg-row[data-who='agent'] .msg-meta { justify-content: flex-end; }
.msg-meta .tick[data-status='read'] { color: var(--success); }

.sys {
  align-self: center; font-size: 12px; color: var(--muted);
  background: var(--surface-2); padding: 4px 12px; border-radius: 999px;
}

.day-sep {
  align-self: center; margin: 4px 0;
  font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--muted);
  padding: 3px 12px; border-radius: 999px; background: var(--surface-2);
}

.chat-empty {
  margin: auto; display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: var(--muted); text-align: center;
}
.chat-empty svg { width: 44px; height: 44px; opacity: .5; }
.chat-empty p { margin: 0; font-size: 13px; }

.typing { flex: none; height: 18px; font-size: 12px; color: var(--muted); padding: 0 20px; }

.composer {
  position: relative;
  flex: none; display: flex; gap: 10px; align-items: flex-end; padding: 12px 18px;
  border-top: 1px solid var(--line); background: var(--surface);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.emoji-toggle {
  flex: none; width: 42px; height: 42px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
  cursor: pointer; font-size: 19px; line-height: 1;
}
.emoji-toggle:hover { color: var(--fg); }
.emoji-toggle[data-open='1'] { border-color: var(--primary); color: var(--primary); }
.emoji-toggle:disabled { opacity: .5; cursor: not-allowed; }

.emoji-picker {
  position: absolute; left: 18px; bottom: calc(100% + 8px);
  width: 264px; padding: 10px; border-radius: 16px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow-md);
  display: none; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px;
  z-index: 5;
}
.emoji-picker[data-open='1'] { display: grid; }
.emoji-item {
  height: 36px; border: none; border-radius: 10px; background: transparent;
  cursor: pointer; font-size: 20px; line-height: 1;
}
.emoji-item:hover { background: var(--surface-2); }

/* ---- agent seats ---- */

.seats-table { min-width: 640px; }
.seat-form {
  display: grid; gap: 8px; margin-top: 14px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.seat-form input, .seat-form select {
  height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg); font-size: 14px; outline: none; min-width: 0;
}
.seat-form input:focus, .seat-form select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.seat-form .btn { height: 38px; }

.composer textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 132px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); outline: none;
  /* Floor the reply box so it never squeezes below ~22 characters per line. */
  min-width: 22ch;
}
.composer textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.send-btn { flex: none; height: 42px; }

/* ---- detail column ---- */

.detail-scroll {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 16px; display: flex; flex-direction: column; gap: 14px;
}

.detail-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  background: var(--surface); display: flex; flex-direction: column;
}

.detail-hero { display: flex; align-items: center; gap: 12px; }
.detail-hero-text { min-width: 0; }
.detail-hero-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-hero-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.detail-fields { margin: 14px 0 0; display: flex; flex-direction: column; }
.detail-fields .row {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 8px 0; border-top: 1px solid var(--line); font-size: 12.5px;
}
.detail-fields dt { color: var(--muted); flex: none; }
.detail-fields dd {
  margin: 0; text-align: right; font-weight: 600; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.detail-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.detail-card-head h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.detail-count {
  min-width: 22px; text-align: center; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 700;
}

.agent-item, .queue-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px;
}
.agent-item + .agent-item, .queue-item + .queue-item { border-top: 1px solid var(--line); }

.agent-item .meta { flex: 1; min-width: 0; }
.agent-item .nm { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-item .sub { font-size: 11px; color: var(--muted); }

.queue-item { cursor: pointer; }
.queue-item:hover { background: var(--surface-2); border-radius: var(--radius-sm); }
.queue-item .qname { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- buttons ---- */

.btn {
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; cursor: pointer; font-weight: 600; font-size: 13px;
  background: var(--surface-2); color: var(--fg-soft);
  transition: filter .15s ease, background .15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-fg); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { color: var(--fg); border-color: var(--muted); }
.btn.warn { background: var(--warning); color: #1f1300; }
.btn.danger { background: var(--accent); color: #fff; }
.btn.block { width: 100%; }
.btn.icon-only { padding: 9px 11px; }

/* ---- toast ---- */

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow-md); z-index: 100; font-size: 13px;
}

.empty { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* -------------------------------------------------- site configuration */

.settings { flex: 1; overflow-y: auto; min-height: 0; background: var(--bg); }

.settings-inner {
  max-width: 980px; margin: 0 auto; padding: 28px 22px 56px;
  display: flex; flex-direction: column; gap: 20px;
}

.settings-head h2 { margin: 0; font-size: 20px; }
.settings-head .pane-note { margin-top: 6px; }
.settings-actions { display: flex; justify-content: flex-end; }

.config-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}

.config-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.config-card-head h3 { margin: 0; font-size: 15px; }

.table-wrap { overflow-x: auto; }
/* Keep a usable editing width on phones by letting the wrapper scroll rather
   than crushing the text columns into a few characters. */
.config-table { width: 100%; min-width: 520px; border-collapse: collapse; }
.faq-table { min-width: 760px; }

.config-table th {
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap;
}

.config-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.config-table tr:last-child td { border-bottom: 0; }
.config-table .col-idx { width: 36px; color: var(--muted); font-size: 12px; }
.config-table .col-parent { width: 118px; }
.config-table .col-act { width: 108px; }

.config-table input, .config-table textarea, .config-table select {
  width: 100%; padding: 8px 10px; outline: none;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg);
}

.config-table textarea { resize: vertical; min-height: 40px; }
.config-table input:focus, .config-table textarea:focus, .config-table select:focus { border-color: var(--primary); }

.config-textarea {
  width: 100%; min-height: 76px; padding: 10px 12px; resize: vertical;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg); font: inherit; outline: none;
}
.config-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* Visitor-flow map: a Gantt-like preview of the quick-answer chain. Every row is
   one question and its bar steps one column to the right for each level of the
   chain, so the order a visitor walks through is readable at a glance. */
.faq-flow-block { display: flex; flex-direction: column; gap: 8px; }
.faq-flow-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; }
.faq-flow-head h4 { margin: 0; font-size: 13px; }
.faq-flow-note { color: var(--muted); font-size: 12px; }

.faq-flow { --flow-step: 92px; display: flex; flex-direction: column; gap: 4px; overflow-x: auto; padding-bottom: 2px; }
.flow-empty { margin: 0; color: var(--muted); font-size: 13px; }

.flow-row {
  display: grid; grid-template-columns: minmax(200px, 1fr) auto;
  gap: 14px; align-items: center; min-width: 460px;
  padding: 3px 6px; border-radius: var(--radius-sm); cursor: pointer;
}
.flow-row:hover { background: var(--surface-2); }

.flow-label { display: flex; align-items: center; gap: 8px; min-width: 0; padding-left: calc(var(--depth) * 18px); }

.flow-step {
  flex: none; width: 20px; height: 20px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: var(--bg); font-size: 11px; font-weight: 600;
}

.flow-idx { flex: none; color: var(--muted); font-size: 11px; }
.flow-q { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

.flow-track {
  position: relative;
  width: calc(var(--steps, 1) * var(--flow-step)); height: 16px;
  border-radius: var(--radius-sm); background-color: var(--surface-2);
  /* One faint line per step keeps the bar offsets readable as a timeline. */
  background-image: repeating-linear-gradient(to right, var(--line) 0 1px, transparent 1px var(--flow-step));
}

.flow-bar {
  position: absolute; display: block; height: 16px;
  left: calc((var(--step) - 1) * var(--flow-step));
  width: calc(var(--flow-step) - 14px);
  border-radius: var(--radius-sm); background: var(--primary);
}

/* Briefly highlights the row a visitor-flow entry points at. */
.config-table tr.row-flash td { background: var(--surface-2); }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

.icon-btn {
  width: 28px; height: 28px; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--muted); font-size: 13px;
}

.icon-btn:hover:not(:disabled) { color: var(--fg); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn[data-remove]:hover { color: var(--accent); border-color: var(--accent); }

/* ----------------------------------------------------------- marketplace */

.market-tabs { display: flex; flex-wrap: wrap; gap: 8px; }

.market-tab {
  padding: 7px 14px; cursor: pointer; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--muted);
}
.market-tab:hover { color: var(--fg); }
.market-tab[data-active='1'] { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }

.market-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); }

.market-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.market-card:hover { box-shadow: var(--shadow-sm); }

.market-card-head { display: flex; align-items: center; gap: 12px; }

/* Marketplace entry badges follow the same monogram rule as avatars. */
.market-badge {
  flex: none; width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; font-size: 16px; font-weight: 700;
  background: var(--brand-ink); color: var(--brand-gold);
}
[data-theme='dark'] .market-badge { background: var(--brand-gold); color: var(--brand-ink); }

.market-card-meta { min-width: 0; }
.market-card-name { font-size: 14px; font-weight: 600; }
.market-card-vendor { font-size: 12px; color: var(--muted); }

.market-card-desc { margin: 0; flex: 1; font-size: 13px; color: var(--fg-soft); line-height: 1.55; }

.market-card-foot { display: flex; justify-content: flex-end; }
.market-install { padding: 7px 16px; }

/* --------------------------------------------------------- responsive */

.back-btn { display: none; }

@media (max-width: 1280px) {
  .layout { grid-template-columns: 312px minmax(0, 1fr); }
  .detail-pane { display: none; }
}

@media (max-width: 900px) {
  .rail { flex-basis: 56px; width: 56px; }
  .topnav-item { width: 42px; height: 42px; }

  .topbar { flex-wrap: wrap; gap: 10px; row-gap: 8px; }
  .topbar-stats { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .topbar-actions { margin-left: 0; }

  .layout { grid-template-columns: minmax(0, 1fr); }
  .list-pane { display: none; border-right: 0; }
  .list-pane[data-show='1'] { display: flex; }
  .chat-pane[data-show='0'] { display: none; }
  .back-btn { display: inline-flex; }
}
