/* ─────────────────────────────────────────────────────────────
   Ripple AI chat — brand tokens lifted from /dashboard/style.css.
   Single source of design truth: warm whites, ink black, indigo
   accent, italic-serif emphasis.

   Layout pattern (Grok-style):
   - state-welcome: composer is part of a vertically-centered hero
     block (big wordmark + sub + composer + suggestion chips).
   - state-chat:    composer slides to the bottom, messages flow
     above. JS DOM-moves the composer element between two slots.
   ───────────────────────────────────────────────────────────── */

:root {
  --ink: #1c1917;
  --ink-2: #2a2624;
  --ink-3: #44403c;
  --muted: #78716c;
  --subtle: #a8a29e;
  --white: #fafaf8;
  --surface: #f5f5f4;
  --border: #e7e5e4;
  --indigo: #3730a3;
  --indigo-mid: #6366f1;
  --indigo-light: #ede9fe;
  --amber: #d97706;
  --green: #16a34a;
  --danger: #b91c1c;

  --bg: var(--white);
  --bg-soft: var(--surface);
  --bg-elev: #ffffff;
  --fg: var(--ink);
  --fg-muted: var(--muted);
  --fg-subtle: var(--subtle);
  --accent: var(--indigo);
  --accent-soft: var(--indigo-light);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --radius-composer: 22px;

  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.05), 0 12px 28px -8px rgba(28, 25, 23, 0.08);
  --shadow-composer: 0 1px 2px rgba(28, 25, 23, 0.06), 0 8px 24px -10px rgba(28, 25, 23, 0.12);

  --sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --serif: 'Instrument Serif', 'Source Serif 4', 'Iowan Old Style', Georgia, serif;
  --mono: 'SF Mono', Menlo, Monaco, Consolas, ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f;
    --bg-soft: #1c1917;
    --bg-elev: #1f1c1a;
    --fg: #faf8f6;
    --fg-muted: #b5ada6;
    --fg-subtle: #807973;
    --border: #2a2522;
    --accent: #a5b4fc;
    --accent-soft: rgba(99, 102, 241, 0.18);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 32px -8px rgba(0, 0, 0, 0.45);
    --shadow-composer: 0 1px 2px rgba(0, 0, 0, 0.5), 0 12px 32px -10px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-feature-settings: 'ss01', 'cv11';
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

em {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  letter-spacing: -0.01em;
}

a { color: var(--accent); }

/* ── topbar ────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s, background 0.2s;
}
/* Was grid with justify-self on each child. Flex space-between is more
   defensive on mobile — keeps topbar-right flush at the viewport's right
   edge regardless of how the hidden topbar-nav contributes to layout. */
.topbar > .topbar-nav {
  /* Centered nav (admin only; hidden when signed out) sits between
     wordmark and topbar-right; absolutely positioned so the space-between
     of the two visible siblings isn't affected. Topbar already has
     position: sticky which gives the absolute child a positioning context. */
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
body.state-chat .topbar {
  border-bottom-color: var(--border);
}
/* In dark mode, a hard 1px border reads as a seam against the deep bg.
   Drop it — contrast between fg and bg already gives the topbar enough
   separation from the thread below. */
@media (prefers-color-scheme: dark) {
  body.state-chat .topbar { border-bottom-color: transparent; }
}

.wordmark {
  font-size: 17px;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: -0.01em;
  font-weight: 500;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.nav-link {
  font-size: 13px;
  color: var(--fg-muted);
  text-decoration: none;
  letter-spacing: 0.01em;
  padding: 6px 12px;
  border-radius: 999px;
  transition: color 0.15s, background-color 0.15s;
}
.nav-link:hover { color: var(--fg); background-color: var(--bg-soft); }
.nav-link.is-active {
  color: var(--fg);
  background-color: var(--bg-soft);
  font-weight: 500;
}
.nav-link-btn {
  background: none;
  border: 0;
  font: inherit;
  cursor: pointer;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* ── user menu (signed-in dropdown) ─────────────────────────── */
.user-menu { position: relative; }
.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 7px 14px 7px 16px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.user-menu-trigger:hover { border-color: var(--fg-subtle); }
.user-menu-trigger { padding-left: 6px; }
.user-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}
.user-menu-chev {
  width: 12px;
  height: 12px;
  color: var(--fg-muted);
  transition: transform 0.15s;
}
.user-menu-trigger[aria-expanded="true"] .user-menu-chev { transform: rotate(180deg); }
.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.08);
  z-index: 20;
  animation: dropdown-pop 140ms ease-out;
}
@keyframes dropdown-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.user-menu-email {
  font-size: 12px;
  color: var(--fg-muted);
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  word-break: break-all;
}
.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: none;
  border: 0;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.12s;
}
.user-menu-item:hover { background-color: var(--bg-soft); }

.signin-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  text-decoration: none;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 7px 18px;
  border-radius: var(--radius-pill);
  transition: border-color 0.15s, background 0.15s;
  display: inline-block;
}

/* "New chat" — top-right of the topbar. Hidden on welcome (nothing to reset);
   appears once a conversation is in progress. */
.new-chat-btn {
  display: none;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 6px 14px 6px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.new-chat-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.new-chat-btn .icon { width: 14px; height: 14px; }
body.state-chat .new-chat-btn { display: inline-flex; }
.signin-btn:hover { border-color: var(--fg-subtle); }
.signin-btn.signed-in {
  background: var(--ink);
  color: var(--white);
  border-color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  .signin-btn.signed-in { background: var(--fg); color: var(--ink); border-color: var(--fg); }
}

/* ── main ──────────────────────────────────────────────────── */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2rem);
}

/* Welcome state: centered hero with composer */
body.state-welcome main {
  justify-content: center;
}
body.state-welcome #messages { display: none; }
body.state-welcome #composer-slot-bottom { display: none; }

/* Chat state: messages scroll, composer at the bottom */
body.state-chat #welcome { display: none; }
body.state-chat #messages { display: flex; flex-direction: column; gap: 20px; padding: 24px 0 16px; }

/* ── hero ──────────────────────────────────────────────────── */

.welcome {
  text-align: center;
  padding: clamp(2rem, 8vh, 5rem) 0;
}

.hero-title {
  font-size: clamp(2.5rem, 7vw, 4rem);
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.05;
  margin: 0 0 14px;
}
.hero-title em {
  font-size: 1.15em;
  letter-spacing: -0.03em;
  margin-left: 2px;
}

.hero-sub {
  font-size: 16px;
  color: var(--fg-muted);
  max-width: 480px;
  margin: 0 auto 32px;
  line-height: 1.5;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 600px;
  margin: 24px auto 0;
}

.chip {
  font: inherit;
  font-size: 13px;
  color: var(--fg-muted);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s, transform 0.15s;
  text-align: left;
}
.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

/* ── composer slot positioning ─────────────────────────────── */

.composer-slot {
  width: 100%;
  display: flex;
  justify-content: center;
}

/* Welcome: slot is inline with the hero */
#composer-slot-welcome {
  margin-top: 12px;
}

/* Chat-mode bottom slot is sticky at the viewport bottom, with a
   gentle gradient to suggest "the thread continues above". */
.composer-slot-bottom {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 65%, rgba(0,0,0,0));
  padding: 14px clamp(1rem, 4vw, 2rem) 18px;
  z-index: 4;
}

#composer {
  width: 100%;
  max-width: 760px;
}

/* ── composer (the bar itself) ─────────────────────────────── */

.composer {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-composer);
  padding: 12px 12px 10px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-composer);
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-composer);
}

#input {
  background: transparent;
  border: 0;
  outline: 0;
  resize: none;
  font: inherit;
  font-size: 16px;
  color: var(--fg);
  width: 100%;
  min-height: 24px;
  max-height: 200px;
  line-height: 1.5;
  padding: 4px 0 2px;
}
#input::placeholder { color: var(--fg-subtle); }

.composer-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Mode picker — custom button + popover (not <select>) so each row can
   show a short description line. Sole composer chooser since the explicit
   model picker was retired (2026-05-26). */
.picker { flex: 0 1 auto; min-width: 0; }
.mode-picker-wrap { position: relative; }
#mode-picker {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 26px 6px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  position: relative;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-muted) 50%),
                    linear-gradient(135deg, var(--fg-muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
#mode-picker:hover { color: var(--fg); border-color: var(--fg-subtle); background-color: var(--bg-soft); }
#mode-picker:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
#mode-picker[aria-expanded="true"] { color: var(--fg); border-color: var(--fg-subtle); background-color: var(--bg-soft); }

.mode-picker-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 240px;
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg-elev, var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
  z-index: 30;
}
.mode-picker-menu.opens-up {
  top: auto;
  bottom: calc(100% + 8px);
}
.mode-picker-menu[hidden] { display: none; }

.mode-option {
  display: grid;
  grid-template-columns: 1fr 16px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--fg);
  text-align: left;
  transition: background-color 0.1s;
}
.mode-option.is-active { background: var(--bg-soft); }
.mode-option-check {
  font-size: 12px;
  color: var(--accent);
  text-align: center;
  visibility: hidden;
  line-height: 1;
}
.mode-option.is-selected .mode-option-check { visibility: visible; }
.mode-option-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mode-option-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.2;
}
.mode-option-desc {
  font-size: 11.5px;
  color: var(--fg-muted);
  line-height: 1.3;
}

/* Mode picker + web-search toggle sit on the left of composer-controls. */
.picker-group { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; min-width: 0; }

/* Web-search toggle. Standalone pill sitting in `.picker-group` next to the
   mode switch. When active, accent-soft background + accent border so it
   reads as "this changes how your message will be answered" — more visually
   committed than the mode chips. */
.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px 4px 8px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.toggle-chip:hover { color: var(--fg); border-color: var(--fg-subtle); }
.toggle-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.toggle-chip.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: transparent;
}
.toggle-chip.is-disabled,
.toggle-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  color: var(--fg-muted);
  background: var(--bg-soft);
  border-color: var(--border);
}
.toggle-chip.is-disabled:hover,
.toggle-chip:disabled:hover {
  color: var(--fg-muted);
  border-color: var(--border);
}
.toggle-chip-icon { width: 14px; height: 14px; flex: 0 0 auto; }

/* Attach-image button reuses the .toggle-chip pill styling. The 📎 icon shares
   .toggle-chip-icon sizing. Disabled state mirrors the web-search toggle. */

/* Staged-image thumbnail strip (vision). Sits above the textarea inside the
   composer; full-width, wraps. Hidden (via [hidden]) when nothing is staged. */
.image-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 4px;
}
.image-strip[hidden] { display: none; }

.image-chip {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  flex: 0 0 auto;
}
.image-chip-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-chip-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(28, 25, 23, 0.72);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.image-chip-remove:hover { background: rgba(28, 25, 23, 0.9); }
.image-chip-remove:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Thumbnails inside a sent user bubble. */
.bubble-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.bubble-image {
  max-width: 180px;
  max-height: 180px;
  border-radius: var(--radius-sm);
  display: block;
  object-fit: cover;
}
.bubble-images:last-child { margin-bottom: 0; }
.bubble-text { white-space: pre-wrap; }

/* Generated images (admin "Allow images"). Streamed {image} frames render here,
   above the caption text. Larger than the read-image thumbnails since the image
   is the deliverable. */
.gen-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.gen-images:empty { display: none; }
.gen-image {
  max-width: min(100%, 384px);
  max-height: 384px;
  width: auto;
  height: auto;
  border-radius: var(--radius-md, 10px);
  border: 1px solid var(--border);
  display: block;
}
.gen-image-placeholder {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--fg-muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
}
.gen-image-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: gen-image-spin 0.7s linear infinite;
  flex: 0 0 auto;
}
@keyframes gen-image-spin { to { transform: rotate(360deg); } }
.gen-image-error {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--danger, #c0392b);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
}

/* Drag-and-drop / paste overlay (vision). Full-window, purely visual —
   pointer-events:none so it never captures the underlying drop target. */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(28, 25, 23, 0.32);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  pointer-events: none;
  animation: drop-overlay-in 120ms ease-out;
}
.drop-overlay[hidden] { display: none; }
@keyframes drop-overlay-in { from { opacity: 0; } to { opacity: 1; } }
.drop-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 36px 52px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: var(--shadow-composer);
  color: var(--fg);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 1.02rem;
}
.drop-overlay-icon {
  width: 34px;
  height: 34px;
  color: var(--accent);
}

/* Research-mode progress card. Lives inside the assistant bubble above the
   answer body while planning + searching, then collapses into a clean
   <details class="research-sources"> disclosure once the synthesizer's
   citations frame arrives. */
.research-progress {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--fg-muted);
  line-height: 1.45;
}
.research-progress-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--fg);
}
.rp-spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  animation: rp-spin 0.7s linear infinite;
  flex: 0 0 auto;
}
.rp-check,
.rp-x {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  position: relative;
  flex: 0 0 auto;
}
.rp-check { background: var(--accent-soft); }
.rp-x { background: rgba(185, 28, 28, 0.12); }
.rp-check::after,
.rp-x::after {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
}
.rp-check::after { content: '✓'; color: var(--accent); }
.rp-x::after { content: '!'; color: var(--danger); }
@keyframes rp-spin { to { transform: rotate(360deg); } }

.research-queries {
  list-style: none;
  padding: 0;
  margin: 8px 0 0 19px;
}
.research-query {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  color: var(--fg-muted);
}
.research-query.is-done { color: var(--fg); }
.research-query-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.research-query-count {
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  flex: 0 0 auto;
}

/* Collapsible sources block — replaces .research-progress in place once the
   synth's citations frame arrives. Wraps a horizontally-scrollable strip of
   source cards inside a <details> so the user can minimize the strip to a
   single-row preview (favicons + count). Width is clamped to the bubble's
   content area; the strip scrolls horizontally when there are more cards
   than fit, instead of blowing out the bubble. */
.research-sources-wrap {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin: 0 0 12px;
}
.research-sources-summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.research-sources-summary:hover,
.research-sources-summary:focus-visible {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}
.research-sources-summary::-webkit-details-marker { display: none; }
.research-sources-preview {
  display: flex;
  gap: 3px;
  align-items: center;
  flex: 0 0 auto;
}
.research-sources-preview-favicon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--border);
}
.research-sources-count {
  flex: 1 1 auto;
}
.research-sources-chev {
  flex: 0 0 auto;
  display: inline-flex;
  width: 14px;
  height: 14px;
  transition: transform 0.18s ease;
}
.research-sources-chev svg { width: 100%; height: 100%; }
.research-sources-wrap[open] .research-sources-chev { transform: rotate(180deg); }
.research-sources-wrap:not([open]) .research-sources { display: none; }
.research-sources-wrap[open] .research-sources-summary { margin-bottom: 4px; }

.research-sources {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 2px 10px;
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.research-sources::-webkit-scrollbar { height: 6px; }
.research-sources::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.research-source-card {
  flex: 0 0 168px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  font-size: 12px;
  line-height: 1.35;
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}
.research-source-card:hover,
.research-source-card:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.research-source-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.research-source-favicon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border-radius: 3px;
  background: var(--border);
}
.research-source-host {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.research-source-num {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: 4px;
  line-height: 1.4;
}
.research-source-title {
  font-size: 12px;
  color: var(--fg);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Inline citation pills — injected by linkifyCitations() once the synth's
   citations frame arrives. Each pill is a real <a> linking to the source URL;
   hover title carries hostname + article title. Renders as a small superscript
   chip so it sits next to the cited word without disturbing the line height. */
.citation-link {
  display: inline-block;
  font-size: 0.72em;
  line-height: 1.4;
  font-weight: 600;
  vertical-align: super;
  margin: 0 0.1em;
  padding: 0 0.4em;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.citation-link:hover,
.citation-link:focus-visible {
  background: var(--accent);
  color: white;
  outline: none;
  text-decoration: none;
}

/* Send / Stop — round icon button */
#send-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
#send-btn:hover:not(:disabled) { background: var(--ink-2); }
#send-btn:active:not(:disabled) { transform: scale(0.95); }
#send-btn:disabled { opacity: 0.32; cursor: not-allowed; }
#send-btn .icon { width: 18px; height: 18px; display: block; }
#send-btn .icon-stop { display: none; }
body.state-streaming #send-btn .icon-send { display: none; }
body.state-streaming #send-btn .icon-stop { display: block; }

@media (prefers-color-scheme: dark) {
  #send-btn { background: var(--fg); color: var(--ink); }
  #send-btn:hover:not(:disabled) { background: var(--fg-muted); color: var(--ink); }
}

/* ── messages ──────────────────────────────────────────────── */

.msg {
  display: flex;
  flex-direction: column;
  max-width: 92%;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.msg.error { align-self: stretch; align-items: stretch; }

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  min-width: 0;
}

.msg.user .bubble {
  background: var(--ink);
  color: var(--white);
  white-space: pre-wrap;
  border-bottom-right-radius: 4px;
}
@media (prefers-color-scheme: dark) {
  .msg.user .bubble { background: var(--fg); color: var(--ink); }
}

.msg.assistant .bubble {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg);
  border-bottom-left-radius: 4px;
}
.msg.assistant .bubble p { margin: 0 0 10px; }
.msg.assistant .bubble p:last-child { margin-bottom: 0; }
.msg.assistant .bubble ul,
.msg.assistant .bubble ol { margin: 6px 0 10px 22px; padding: 0; }
.msg.assistant .bubble li { margin-bottom: 4px; }
.msg.assistant .bubble pre {
  background: var(--bg-soft);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
  font-family: var(--mono);
  border: 1px solid var(--border);
}
.msg.assistant .bubble code {
  background: var(--bg-soft);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.9em;
}
.msg.assistant .bubble pre code { background: none; padding: 0; }

/* Reasoning-tier "Thinking…" disclosure. Sits above .answer-body inside
   the assistant bubble. Open while reasoning streams, auto-collapses with
   a "Thought for Ns" summary when the actual answer starts. Non-reasoning
   models never render this element. */
.msg.assistant .bubble details.thinking {
  margin: -2px 0 10px;
  padding: 8px 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.msg.assistant .bubble details.thinking summary {
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-subtle);
  letter-spacing: 0.02em;
  list-style: none;
}
.msg.assistant .bubble details.thinking summary::-webkit-details-marker { display: none; }
.msg.assistant .bubble details.thinking summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  transition: transform 0.15s;
}
.msg.assistant .bubble details.thinking[open] summary::before {
  transform: rotate(90deg);
}
.msg.assistant .bubble details.thinking .thinking-body {
  margin-top: 8px;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--fg-muted);
}

/* Rethink — "Think more carefully" affordance under non-reasoning answers.
   Caps at 3 per session; once clicked, button disables and a sibling
   assistant message with .rethink-label streams the reasoning answer below. */
.msg.assistant .rethink-btn {
  align-self: flex-start;
  margin: 6px 0 0;
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font: inherit;
  font-size: 12px;
  color: var(--fg-muted);
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.msg.assistant .rethink-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.msg.assistant .rethink-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.msg.assistant .rethink-label {
  align-self: flex-start;
  margin: 6px 4px 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-subtle);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.msg.assistant .bubble blockquote {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  color: var(--fg-muted);
  margin: 8px 0;
}
.msg.assistant .bubble h1,
.msg.assistant .bubble h2,
.msg.assistant .bubble h3 {
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 14px 0 6px;
}
.msg.assistant .bubble h1 { font-size: 1.25em; }
.msg.assistant .bubble h2 { font-size: 1.15em; }
.msg.assistant .bubble h3 { font-size: 1.05em; }

.attribution {
  font-size: 12px;
  color: var(--fg-subtle);
  margin-top: 6px;
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
}
.attribution em {
  color: var(--fg-muted);
  font-size: 14px;
  margin-right: 1px;
}

.cursor {
  display: inline-block;
  width: 7px;
  height: 0.95em;
  background: var(--fg-muted);
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink 0.95s steps(2, start) infinite;
  border-radius: 1px;
}
@keyframes blink { to { visibility: hidden; } }

.msg.error .bubble {
  background: rgba(185, 28, 28, 0.06);
  border: 1px solid rgba(185, 28, 28, 0.25);
  color: var(--danger);
  font-size: 14px;
}

/* ── below-composer affordances ───────────────────────────── */

.status {
  margin: 8px 4px 0;
  font-size: 12px;
  color: var(--fg-subtle);
  min-height: 16px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.status.error { color: var(--danger); }

/* Action-row variant used by the Turnstile timeout-recovery flow. Inline
   buttons render alongside the message in a single horizontally-centered row. */
.status.with-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--danger);
}
.status-action {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  font: inherit;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.status-action:hover {
  background: var(--bg-hover, var(--bg-elev));
  border-color: var(--fg-subtle);
}

/* Cloudflare Turnstile widget. With appearance:'interaction-only' the
   widget is invisible for humans (silent token); CF promotes it to a
   visible check only when interaction is genuinely needed. So no
   min-height reservation — it expands only when CF actually paints. */
.turnstile-container {
  margin: 0 auto;
  display: flex;
  justify-content: center;
}
.turnstile-container:not(:empty) { margin-bottom: 10px; }
.turnstile-container[hidden] { display: none; }

/* Page-level footnote — pinned to the viewport bottom on the welcome screen.
   Hidden once a chat starts (composer takes the bottom). */
.page-footnote {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--fg-subtle);
  letter-spacing: 0.01em;
  text-align: center;
  z-index: 3;
  pointer-events: auto;
}
.page-footnote a { color: var(--fg-muted); text-decoration: none; }
.page-footnote a:hover { color: var(--accent); text-decoration: underline; }
body.state-chat .page-footnote { display: none; }
/* If signed-in admin, the sidebar reserves 260px on the left — shift the
   footnote to stay centered within the remaining viewport. */
@media (min-width: 641px) {
  body.state-authed .page-footnote { left: calc(50% + 130px); }
  body.state-authed.sidebar-collapsed .page-footnote { left: 50%; }
}

/* ── small screens ─────────────────────────────────────────── */

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; gap: 8px; }
  main { padding: 0 16px; }
  .composer-slot-bottom { padding: 12px 16px 16px; }
  .hero-title { font-size: 2.25rem; }
  .hero-sub { font-size: 15px; margin-bottom: 24px; }

  /* Mobile composer: with the explicit-model picker + segmented switch
     retired, the row is mode-picker + search-toggle + send. Tighten font
     and padding so the trio fits one line at 320px+ viewports. */
  .picker-group { gap: 6px; }
  #mode-picker {
    min-width: 84px;
    font-size: 11px;
    padding: 5px 22px 5px 10px;
    background-position: calc(100% - 10px) 11px, calc(100% - 5px) 11px;
    background-size: 4px 4px;
  }
  /* Collapse the web / images / attach toggles to icon-only at this width —
     their labels wrap and crowd the row. They become square icon buttons; the
     label text is kept as a visually-hidden accessible name (the buttons also
     carry title / aria-label tooltips). The "Think" mode picker keeps its label
     since it's a dropdown that needs one. */
  .toggle-chip {
    width: 34px;
    height: 34px;
    padding: 0;
    gap: 0;
    justify-content: center;
    flex: 0 0 auto;
  }
  .toggle-chip > span {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .toggle-chip-icon { width: 16px; height: 16px; }
  .composer-controls { align-items: center; }
}

/* ── motion preferences ───────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ── sidebar (admin-only, Phase 13.6) ──────────────────────────
   Anonymous users never see this. The grid switch only activates
   with body.state-authed, so the default flex layout is preserved
   pixel-for-pixel for signed-out visitors.
   --topbar-h is the measured topbar height; sidebar sticks below it
   instead of being hidden behind it (topbar has z-index 5). */

:root { --topbar-h: 56px; }

.sidebar { display: none; }

body.state-authed .sidebar {
  /* `position: fixed` (not sticky) on desktop. Earlier attempts with sticky
     + height: 100vh + display: grid hit a Chromium issue where the sticky
     element's layout height intermittently collapses to content size when
     the grid container has overflowing content. That broke both flex-grow
     on .conv-list and grid 1fr expansion of the conv list row, so the foot
     never landed at the bottom. Fixed positioning sidesteps the entire
     interaction — top/bottom anchors define height directly from viewport
     edges, independent of vh/dvh calculation and ancestor scroll context.
     The body grid still reserves a 260px column for layout; the fixed
     sidebar paints over it. */
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  overflow: hidden;
  z-index: 5;
}

/* Claude-pattern: when authed, the topbar disappears entirely on desktop and
   the sidebar owns brand + nav + user menu. Body becomes a 2-col grid (no
   topbar row). On mobile the topbar comes back as a minimal bar with the
   drawer toggle. */
body.state-authed {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  grid-template-rows: 1fr auto;
}
body.state-authed > .topbar          { display: none; }
body.state-authed > .sidebar         { grid-row: 1 / 3; grid-column: 1; }
/* Explicit grid-row placement for sidebar children. Auto-placement was
   miscomputing the foot row even after `display: grid; grid-template-rows:
   auto auto 1fr auto` — likely Chromium getting confused by the
   `<div class="sidebar-empty" hidden>` sibling between conv-list and foot.
   Pinning each child to a fixed row removes the ambiguity. */
body.state-authed .sidebar > .sidebar-brand { grid-row: 1; grid-column: 1; }
body.state-authed .sidebar > .sidebar-head  { grid-row: 2; grid-column: 1; }
body.state-authed .sidebar > .conv-list     { grid-row: 3; grid-column: 1; }
body.state-authed .sidebar > .sidebar-foot  { grid-row: 4; grid-column: 1; align-self: end; }
/* Sidebar-empty lives as a HTML sibling of conv-list but the JS moves it
   INSIDE conv-list when it needs to be shown. If it ever appears as a
   direct child of .sidebar (race or JS failure), hide it — the empty-state
   text doesn't justify breaking the grid layout. */
body.state-authed .sidebar > .sidebar-empty { display: none; }
body.state-authed > #main            { grid-column: 2; grid-row: 1; }
body.state-authed > #composer-slot-bottom { grid-column: 2; grid-row: 2; }

/* Collapsed state — sidebar slides out, main takes the full width.
   The floating .sidebar-toggle becomes the only way back in. */
body.state-authed.sidebar-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
body.state-authed.sidebar-collapsed .sidebar { display: none; }

/* Floating sidebar toggle — only used when sidebar is collapsed on desktop,
   or as the drawer toggle on mobile. When sidebar is open, the inline
   .sidebar-collapse-btn at the top of the sidebar handles closing. */
.sidebar-toggle {
  position: fixed;
  top: 11px;
  left: 14px;
  z-index: 6;
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.sidebar-toggle:hover { color: var(--fg); border-color: var(--fg-subtle); background: var(--bg-soft); }
.sidebar-toggle svg { width: 14px; height: 14px; display: none; }
.sidebar-toggle .icon-expand { display: block; }
/* Only show the floating toggle when collapsed on desktop. */
body.state-authed.sidebar-collapsed .sidebar-toggle { display: inline-flex; }

/* Sidebar brand row — wordmark + inline collapse chevron. */
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 8px 18px;
  flex: 0 0 auto;
}
.sidebar-wordmark {
  font-size: 17px;
  font-weight: 500;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.sidebar-collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border: 0;
  color: var(--fg-muted);
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}
.sidebar-collapse-btn:hover { color: var(--fg); background: var(--bg-elev); }
.sidebar-collapse-btn svg { width: 14px; height: 14px; }

/* Sidebar footer — pinned bottom by margin-top:auto. Contains dashboard link
   + user menu. The dropdown opens UPWARD because the menu sits at the bottom
   of the sidebar. */
.sidebar-foot {
  /* Bottom row of the sidebar grid. `margin-top: auto` is no longer needed —
     grid's `auto` track sits flush at the bottom after the `1fr` conv-list. */
  padding: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-user-menu { position: relative; }
.sidebar-user-trigger {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.12s;
}
.sidebar-user-trigger:hover { background: var(--bg-elev); }
.sidebar-user-trigger .user-avatar { width: 28px; height: 28px; }
.sidebar-user-name {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.sidebar-user-trigger .user-menu-chev { width: 12px; height: 12px; color: var(--fg-muted); flex: 0 0 auto; }
.sidebar-user-dropdown {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 4px;
  right: 4px;
  top: auto;
}

.sidebar-head {
  padding: 4px 12px 10px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Dashboard nav link — sits below "+ New chat", above the conversation list.
   Less prominent than the primary CTA but a peer of conversation items. */
.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-top: 4px;
  font-size: 13px;
  color: var(--fg-muted);
  text-decoration: none;
  border-radius: 8px;
  transition: color 0.15s, background-color 0.12s;
}
.sidebar-nav-link:hover { color: var(--fg); background: var(--bg-elev); }
.sidebar-nav-icon { width: 14px; height: 14px; flex: 0 0 auto; }

.sidebar-new-chat {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  margin: 0;
  font: inherit;
  font-size: 13px;
  color: var(--fg-muted);
  background: none;
  background-color: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  transition: color 0.15s, background-color 0.12s;
}
.sidebar-new-chat:hover { color: var(--fg); background-color: var(--bg-elev); }
.sidebar-new-chat:focus { outline: 0; }
.sidebar-new-chat:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sidebar-new-chat-icon { width: 14px; height: 14px; flex: 0 0 auto; }

/* is-active state — shared by Dashboard nav link and the New chat button on
   the chat page (when no specific conversation is open). */
.sidebar-nav-link.is-active,
.sidebar-new-chat.is-active {
  color: var(--fg);
  background: var(--accent-soft);
  font-weight: 500;
}

.conv-list {
  /* Lives in the `1fr` row of the sidebar grid. min-height: 0 is still
     required so the grid 1fr child can shrink below its intrinsic min-content
     height — without it, a long conversation list would push the foot off
     the bottom edge instead of scrolling internally. */
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.conv-list::-webkit-scrollbar { width: 8px; }
.conv-list::-webkit-scrollbar-thumb { background: transparent; border-radius: 4px; }
.conv-list:hover::-webkit-scrollbar-thumb { background: var(--border); }

.conv-item-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
}
.conv-item {
  display: block;
  /* `flex: 1 1 auto` is intentionally scoped to .conv-item-wrap's flex-row
     context below. Putting it on the bare .conv-item meant items rendered
     directly under .conv-list (a flex column) stretched vertically — the
     spacing bug the dashboard sidebar showed before /shared/convList.js
     unified both renderers. */
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: transparent;
  border: 0;
  text-align: left;
  padding: 8px 28px 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.12s, color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.conv-item-wrap > .conv-item { flex: 1 1 auto; width: auto; }
.conv-item:hover { background: var(--bg-elev); }
.conv-item.is-active {
  background: var(--accent-soft);
  color: var(--fg);
  font-weight: 500;
}

.conv-kebab {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--fg-muted);
  cursor: pointer;
  opacity: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.12s, background-color 0.12s, color 0.12s;
}
.conv-kebab svg { width: 14px; height: 14px; fill: currentColor; }
.conv-kebab:hover { background: var(--bg-soft); color: var(--fg); }
.conv-item-wrap:hover .conv-kebab,
.conv-item-wrap:focus-within .conv-kebab { opacity: 1; }
@media (max-width: 640px) {
  /* No hover on touch — keep the kebab visible so users can find it. */
  .conv-kebab { opacity: 1; }
}

.conv-action-menu {
  position: fixed;
  z-index: 100;
  min-width: 140px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.conv-action-menu[hidden] { display: none; }
.conv-action-menu button {
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  text-align: left;
  padding: 6px 10px;
  cursor: pointer;
}
.conv-action-menu button:hover { background: var(--bg-soft); }
.conv-action-menu button.danger { color: var(--danger); }
.conv-action-menu button.danger:hover { background: rgba(220, 38, 38, 0.08); }

.sidebar-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 12px;
  color: var(--fg-subtle);
  line-height: 1.5;
}

/* Hide the topbar New chat button when the sidebar owns that role (desktop).
   When the sidebar is collapsed, bring the topbar button back so the user
   isn't stranded without a "new chat" affordance. */
@media (min-width: 641px) {
  body.state-authed.state-chat:not(.sidebar-collapsed) #new-chat-btn { display: none; }
}

/* Mobile: revert grid to flex (single column). Topbar comes back (minimal:
   drawer toggle + wordmark + avatar) since the sidebar isn't pinned. */
@media (max-width: 640px) {
  body.state-authed {
    display: flex;
    flex-direction: column;
  }
  /* Restore the topbar on mobile — overrides the desktop hide. */
  body.state-authed > .topbar { display: grid; grid-template-columns: auto 1fr auto; }
  /* Sidebar (drawer) sits below the mobile topbar, not at top:0. */
  body.state-authed .sidebar { top: var(--topbar-h); height: calc(100dvh - var(--topbar-h)); }
  /* Hide the in-sidebar brand on mobile — topbar already shows it. Saves
     vertical space in the drawer. */
  body.state-authed .sidebar-brand { display: none; }
  /* Sidebar foot avatar style not relevant in drawer; use compact look. */
  /* Topbar user menu → avatar-only circle on mobile. */
  body.state-authed .topbar .user-menu-trigger {
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    justify-content: center;
    gap: 0;
  }
  body.state-authed .topbar .user-menu-name,
  body.state-authed .topbar .user-menu-chev { display: none; }
  body.state-authed .topbar .user-avatar { display: block; width: 100%; height: 100%; object-fit: cover; }
  /* Default: drawer closed. */
  body.state-authed .sidebar { display: none; }
  /* Open: slide in from left as a fixed overlay below the topbar.
     Keep `display: grid` (NOT flex) — the base .sidebar rule lays the children
     out with grid-template-rows: auto auto 1fr auto (brand/head/conv-list/foot).
     Overriding to display:flex here defaulted to flex-direction:row, which made
     the conversation list render as a second column beside the nav. */
  body.state-authed.sidebar-open-mobile .sidebar {
    display: grid;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(82vw, 320px);
    height: calc(100dvh - var(--topbar-h));
    z-index: 10;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
  }
  body.state-authed.sidebar-open-mobile .sidebar-backdrop {
    display: block;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9;
  }
  /* Toggle visible on mobile (was hidden in the previous iteration).
     Sits at top-left like desktop; pushes wordmark right via topbar padding. */
  body.state-authed .sidebar-toggle { display: inline-flex; }
  body.state-authed .topbar { padding-left: 54px; }
  /* On mobile the toggle never represents "expand collapsed sidebar" — the
     drawer either is or isn't open. Always show the open/menu icon. */
  body.state-authed .sidebar-toggle .icon-collapse { display: none; }
  body.state-authed .sidebar-toggle .icon-expand { display: block; }
  /* Hide secondary nav; user-menu still has Sign out. */
  body.state-authed .topbar-nav { display: none; }
  /* Icon-only New chat on mobile so it doesn't wrap. */
  body.state-chat .new-chat-btn { padding: 7px; width: 32px; height: 32px; gap: 0; justify-content: center; }
  body.state-chat .new-chat-btn span { display: none; }
}

/* Backdrop element default — never rendered above mobile breakpoint. */
.sidebar-backdrop { display: none; }

@media (prefers-color-scheme: dark) {
  body.state-authed .sidebar { background: var(--bg-soft); border-right-color: var(--border); }
  .conv-item:hover { background: var(--bg-elev); }
  .conv-item.is-active { background: var(--accent-soft); }
}
