/* =========================================================================
   Session Memory — chat UI
   Dark-first, with a full light theme. Everything is driven by the tokens
   in :root / [data-theme="light"], so the two themes stay in lockstep.
   ========================================================================= */

:root {
  --font-display: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Inter', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Courier New', monospace;

  /* dark (default) */
  --bg: #0b0d12;
  --bg-glow-a: rgba(109, 92, 255, 0.18);
  --bg-glow-b: rgba(0, 194, 168, 0.12);
  --surface: #12151d;
  --surface-2: #171b25;
  --surface-3: #1e2430;
  --border: #242b38;
  --border-soft: #1b212c;
  --text: #e9ecf3;
  --text-dim: #9aa4b8;
  --text-faint: #6a7488;

  --accent: #7c6cff;
  --accent-2: #22d3ee;
  --accent-ink: #ffffff;
  --accent-soft: rgba(124, 108, 255, 0.14);
  --accent-line: rgba(124, 108, 255, 0.35);

  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.12);
  --ok: #34d399;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 12px 32px -12px rgba(0, 0, 0, 0.65);
  --shadow-lg: 0 32px 80px -24px rgba(0, 0, 0, 0.75);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  --sidebar-w: 288px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

[data-theme="light"] {
  --bg: #f4f5f9;
  --bg-glow-a: rgba(124, 108, 255, 0.14);
  --bg-glow-b: rgba(0, 194, 168, 0.10);
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --surface-3: #eef0f7;
  --border: #e2e5ee;
  --border-soft: #eaecf3;
  --text: #10131c;
  --text-dim: #5b6478;
  --text-faint: #8c95a8;

  --accent: #5b4bd6;
  --accent-2: #0891b2;
  --accent-ink: #ffffff;
  --accent-soft: rgba(91, 75, 214, 0.10);
  --accent-line: rgba(91, 75, 214, 0.28);

  --danger: #d64545;
  --danger-soft: rgba(214, 69, 69, 0.10);

  --shadow-sm: 0 1px 2px rgba(16, 19, 28, 0.06);
  --shadow-md: 0 12px 32px -14px rgba(16, 19, 28, 0.22);
  --shadow-lg: 0 32px 80px -28px rgba(16, 19, 28, 0.3);
}

/* Incognito overrides every colour token, so the whole app goes cold and
   slate regardless of which theme you were in. Same idea as a browser's own
   private window: you should never have to read a label to know where you
   are. Set on <html> rather than .app so the page background changes too. */
[data-incognito="true"] {
  --bg: #0c0e13;
  --bg-glow-a: rgba(126, 138, 166, 0.10);
  --bg-glow-b: rgba(80, 90, 115, 0.08);
  --surface: #13161d;
  --surface-2: #181c25;
  --surface-3: #20252f;
  --border: #2a303b;
  --border-soft: #1f242d;
  --text: #dfe3ea;
  --text-dim: #97a0b1;
  --text-faint: #6a7383;

  --accent: #7d879e;
  --accent-2: #5b6479;
  --accent-ink: #0c0e13;
  --accent-soft: rgba(125, 135, 158, 0.15);
  --accent-line: rgba(125, 135, 158, 0.34);

  --shadow-md: 0 12px 32px -14px rgba(0, 0, 0, 0.8);
  --shadow-lg: 0 32px 80px -24px rgba(0, 0, 0, 0.85);
}

* { box-sizing: border-box; }

/* Most of the app's own elements set an explicit `display`, which beats the
   browser's default rule for [hidden] and leaves "hidden" things on screen.
   Settling it once here means every `x.hidden = true` in the JS just works. */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Ambient gradient wash behind everything. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60vw 60vh at 12% -10%, var(--bg-glow-a), transparent 65%),
    radial-gradient(50vw 50vh at 105% 110%, var(--bg-glow-b), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100%;
}

/* ============================== sidebar ============================== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 12px 12px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(18px);
  border-right: 1px solid var(--border-soft);
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 0;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 6px 18px -8px var(--accent);
}
.brand-mark svg { width: 19px; height: 19px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-text span { font-size: 11px; color: var(--text-faint); }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  transition: background-color 140ms var(--ease), color 140ms var(--ease), border-color 140ms var(--ease);
  flex-shrink: 0;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.sidebar-close, .sidebar-open { display: none; }

.new-row { display: flex; gap: 7px; }
.new-row .new-chat-btn { flex: 1; }

.incognito-btn {
  width: 44px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-dim);
  transition: color 140ms var(--ease), border-color 140ms var(--ease), background-color 140ms var(--ease);
}
.incognito-btn svg { width: 21px; height: 21px; }
.incognito-btn:hover { color: var(--text); border-color: var(--text-faint); background: var(--surface-3); }
[data-incognito="true"] .incognito-btn {
  color: var(--text);
  border-color: var(--text-dim);
  background: var(--surface-3);
  opacity: 1;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 10px 24px -14px var(--accent);
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease), filter 140ms var(--ease);
}
.new-chat-btn svg { width: 17px; height: 17px; }
.new-chat-btn:hover { filter: brightness(1.07); box-shadow: 0 14px 30px -14px var(--accent); }
.new-chat-btn:active { transform: translateY(1px); }

.sidebar-search { position: relative; }
.sidebar-search .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-faint);
  pointer-events: none;
}
.sidebar-search input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  font-size: 13.5px;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease);
}
.sidebar-search input::placeholder { color: var(--text-faint); }
.sidebar-search input:focus { border-color: var(--accent-line); outline: none; }
input[type="search"]::-webkit-search-cancel-button { filter: grayscale(1) opacity(0.5); cursor: pointer; }

.deep-search-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  border: 1px dashed var(--border);
  border-radius: 11px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  transition: border-color 140ms var(--ease), color 140ms var(--ease), background-color 140ms var(--ease);
}
.deep-search-btn span { flex: 1; text-align: left; }
.deep-search-btn:hover { color: var(--text); border-color: var(--accent-line); background: var(--accent-soft); }

kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-faint);
  line-height: 1.4;
}

/* conversation list */
.conversations {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-group {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  padding: 14px 10px 5px;
}
.conv-group:first-child { padding-top: 4px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 8px 9px 11px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  width: 100%;
  transition: background-color 130ms var(--ease), border-color 130ms var(--ease);
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.conv-main { flex: 1; min-width: 0; }
.conv-title {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item.active .conv-title { color: var(--text); font-weight: 600; }
.conv-sub {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.conv-del {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity 130ms var(--ease), color 130ms var(--ease), background-color 130ms var(--ease);
  flex-shrink: 0;
}
.conv-del svg { width: 14px; height: 14px; }
.conv-item:hover .conv-del, .conv-item.active .conv-del { opacity: 1; }
.conv-del:hover { background: var(--danger-soft); color: var(--danger); }

.conv-empty {
  padding: 22px 12px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-faint);
}

.conv-pin {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0.9;
}

.memory-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12.5px;
  transition: border-color 140ms var(--ease), color 140ms var(--ease);
}
.memory-pill svg { width: 15px; height: 15px; flex-shrink: 0; color: var(--accent); }
.memory-pill span { flex: 1; text-align: left; }
.memory-pill b {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.memory-pill:hover { color: var(--text); border-color: var(--accent-line); }

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 6px 2px;
  border-top: 1px solid var(--border-soft);
}
.stat {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.foot-actions { display: flex; gap: 2px; }

#icon-moon { display: none; }
[data-theme="light"] #icon-sun { display: none; }
[data-theme="light"] #icon-moon { display: block; }

/* =============================== main =============================== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  backdrop-filter: blur(14px);
  flex-shrink: 0;
  /* backdrop-filter makes this a stacking context, so the dropdown's own
     z-index can't escape it. Without this the menu renders *behind* the
     message thread (a later positioned sibling) and swallows every click. */
  position: relative;
  z-index: 30;
}

.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-meta { display: flex; gap: 6px; margin-top: 3px; align-items: center; flex-wrap: wrap; }

.chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.chip.mono { font-family: var(--font-mono); }
.chip.subtle {
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--text-faint);
}
.chip.ghostly {
  border-style: dashed;
  border-color: var(--text-faint);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10.5px;
}
.chip.ghostly[hidden] { display: none; }

.topbar-actions { display: flex; align-items: center; gap: 6px; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  transition: color 140ms var(--ease), border-color 140ms var(--ease), background-color 140ms var(--ease);
}
.ghost-btn svg { width: 16px; height: 16px; }
.ghost-btn:hover { color: var(--text); border-color: var(--accent-line); }
.ghost-btn[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 40;
  min-width: 232px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  animation: pop-in 140ms var(--ease);
  /* On a short window the menu is taller than the viewport, which would put
     the last item permanently out of reach. */
  max-height: calc(100vh - 74px);
  overflow-y: auto;
}
.menu button {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  text-align: left;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}
.menu button svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 2px; }
.menu button span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.menu button b { font-weight: 500; }
.menu button i {
  font-style: normal;
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.35;
}
.menu button:hover { background: var(--surface-2); color: var(--text); }
.menu button.warn:hover { background: var(--surface-3); }
.menu button.danger:hover { background: var(--danger-soft); color: var(--danger); }
.menu button.danger:hover i { color: var(--danger); opacity: 0.75; }
.menu-sep { height: 1px; background: var(--border-soft); margin: 5px 4px; }

/* ---------- context meter ---------- */
.context-meter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px 9px 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  transition: border-color 140ms var(--ease);
}
.context-meter:hover { border-color: var(--accent-line); }
.context-meter[hidden] { display: none; }
.meter-track {
  width: 42px;
  height: 5px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
  flex-shrink: 0;
}
.meter-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 320ms var(--ease), background 200ms var(--ease);
}
.context-meter.warm .meter-fill { background: linear-gradient(90deg, #f5a524, #f57c24); }
.meter-label { font-size: 10.5px; color: var(--text-faint); white-space: nowrap; }

.chip-btn { cursor: pointer; transition: border-color 140ms var(--ease), color 140ms var(--ease); }
.chip-btn:hover { border-color: var(--accent-line); color: var(--text-dim); }

/* ---------- incognito ---------- */
.incognito-bar {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 20px;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-dim);
  flex-shrink: 0;
  position: relative;
  z-index: 20;
  animation: msg-in 220ms var(--ease);
}
.incognito-bar[hidden] { display: none; }
.incognito-bar svg { width: 19px; height: 19px; flex-shrink: 0; color: var(--text); }
.incognito-bar span { flex: 1; }
.incognito-bar b { color: var(--text); font-weight: 600; }
.incognito-bar button {
  flex-shrink: 0;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12.5px;
  transition: color 140ms var(--ease), border-color 140ms var(--ease);
}
.incognito-bar button:hover { color: var(--text); border-color: var(--text-faint); }

/* Nothing here is being written down, so nothing here glows. Gradients go
   flat, the accent shadow under user bubbles disappears, and the whole thread
   sits on a faint diagonal hatch you don't get in a normal chat. */
[data-incognito="true"] .msg.user .bubble {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

[data-incognito="true"] .thread-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0 9px,
    color-mix(in srgb, var(--text-faint) 7%, transparent) 9px 10px
  );
}
[data-incognito="true"] .thread { position: relative; z-index: 1; }

[data-incognito="true"] .brand-mark,
[data-incognito="true"] .msg.assistant .avatar {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  box-shadow: none;
}

[data-incognito="true"] .new-chat-btn,
[data-incognito="true"] #send-btn,
[data-incognito="true"] .primary-btn {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--text);
  box-shadow: none;
}

/* The saved-chat list is still there, but it isn't what you're looking at. */
[data-incognito="true"] .conversations { opacity: 0.45; }
[data-incognito="true"] .conversations:hover { opacity: 0.8; }
[data-incognito="true"] .memory-pill { opacity: 0.45; }

/* incognito empty state */
.incognito-empty {
  max-width: 520px;
  margin: 0 auto;
  padding: 7vh 8px 0;
  text-align: center;
}
.incognito-empty[hidden] { display: none; }
.incognito-mask {
  width: 72px;
  height: 72px;
  margin: 0 auto 22px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.incognito-mask svg { width: 36px; height: 36px; }
.incognito-empty h2 {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}
.incognito-empty > p {
  color: var(--text-dim);
  font-size: 14.5px;
  margin: 0 auto 24px;
  max-width: 430px;
}
.incognito-facts {
  display: grid;
  gap: 8px;
  text-align: left;
  max-width: 400px;
  margin: 0 auto;
}
.incognito-fact {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}
.incognito-fact svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 2px; }
.incognito-fact.no svg { color: var(--text-faint); }
.incognito-fact.yes svg { color: var(--text); }

/* ============================== thread ============================== */
.thread-wrap { position: relative; flex: 1; min-height: 0; }

.thread {
  height: 100%;
  overflow-y: auto;
  padding: 26px 20px 12px;
  scroll-behavior: smooth;
}

.thread-inner-pad { height: 8px; }

/* empty state */
.empty-state {
  max-width: 620px;
  margin: 0 auto;
  padding: 6vh 8px 0;
  text-align: center;
}
.empty-orb {
  width: 68px;
  height: 68px;
  margin: 0 auto 22px;
  border-radius: 24px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 20px 50px -18px var(--accent);
  animation: float 5s ease-in-out infinite;
}
.empty-state h2 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}
.empty-state p {
  color: var(--text-dim);
  font-size: 14.5px;
  margin: 0 auto 26px;
  max-width: 470px;
}
.empty-state em { color: var(--accent); font-style: normal; font-weight: 600; }

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}
.suggestions button {
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--text-dim);
  font-size: 13.5px;
  text-align: left;
  line-height: 1.45;
  transition: transform 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease), background-color 150ms var(--ease);
}
.suggestions button:hover {
  transform: translateY(-2px);
  border-color: var(--accent-line);
  color: var(--text);
  background: var(--surface);
}

/* messages */
.msg {
  display: flex;
  gap: 13px;
  max-width: 820px;
  margin: 0 auto 22px;
  animation: msg-in 260ms var(--ease);
}
.msg.user { flex-direction: row-reverse; }

.avatar {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-display);
  margin-top: 2px;
}
.msg.assistant .avatar {
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
}
.msg.assistant .avatar svg { width: 16px; height: 16px; }
.msg.user .avatar {
  background: var(--surface-3);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.msg-col { min-width: 0; max-width: 100%; display: flex; flex-direction: column; }
.msg.user .msg-col { align-items: flex-end; }

.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 11px;
  color: var(--text-faint);
}
.msg-role {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 10px;
}
.msg.assistant .msg-role { color: var(--accent); }
.msg-index { font-family: var(--font-mono); opacity: 0.65; }

.bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14.8px;
  line-height: 1.68;
  overflow-wrap: anywhere;
  max-width: 100%;
}
.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-top-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}
.msg.user .bubble {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 62%, var(--accent-2)));
  color: var(--accent-ink);
  border-top-right-radius: 5px;
  box-shadow: 0 10px 26px -16px var(--accent);
}

.msg.highlight .bubble {
  animation: flash 1.8s var(--ease);
}

/* markdown inside bubbles */
.bubble > *:first-child { margin-top: 0; }
.bubble > *:last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 10px; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  font-family: var(--font-display);
  margin: 18px 0 8px;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.bubble h1 { font-size: 19px; }
.bubble h2 { font-size: 17px; }
.bubble h3 { font-size: 15.5px; }
.bubble h4 { font-size: 14.5px; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 21px; }
.bubble li { margin-bottom: 4px; }
.bubble li::marker { color: var(--text-faint); }
.msg.user .bubble li::marker { color: rgba(255,255,255,0.6); }
.bubble a { color: var(--accent-2); text-decoration: underline; text-underline-offset: 2px; }
.msg.user .bubble a { color: #fff; }
.bubble blockquote {
  margin: 0 0 10px;
  padding: 2px 0 2px 13px;
  border-left: 3px solid var(--accent-line);
  color: var(--text-dim);
}
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.bubble code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 1.5px 5px;
  border-radius: 5px;
  background: var(--surface-3);
  border: 1px solid var(--border-soft);
}
.msg.user .bubble code {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.16);
}
.bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin: 0 0 10px;
  display: block;
  overflow-x: auto;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.bubble th { background: var(--surface-2); font-weight: 600; }

.code-block {
  position: relative;
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  overflow: hidden;
}
.msg.user .code-block { background: rgba(0, 0, 0, 0.22); border-color: rgba(255,255,255,0.15); }
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 6px 13px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}
.msg.user .code-head { border-color: rgba(255,255,255,0.15); color: rgba(255,255,255,0.75); }
.code-copy {
  border: none;
  background: transparent;
  color: inherit;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 6px;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}
.code-copy:hover { background: var(--surface-3); color: var(--text); }
.code-block pre {
  margin: 0;
  padding: 12px 13px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.8px;
  line-height: 1.62;
}
.code-block pre code { background: none; border: none; padding: 0; font-size: inherit; }

/* per-message actions */
.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 150ms var(--ease);
}
.msg:hover .msg-actions, .msg-actions:focus-within, .msg-actions.busy { opacity: 1; }
.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-faint);
  font-size: 11.5px;
  transition: color 130ms var(--ease), background-color 130ms var(--ease), border-color 130ms var(--ease);
}
.msg-action svg { width: 14px; height: 14px; }
.msg-action:hover { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.msg-action.playing { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.msg-action.loading { color: var(--accent); }
.msg-action.loading svg { animation: spin 900ms linear infinite; }

/* typing indicator */
.typing { display: inline-flex; gap: 5px; padding: 5px 2px; }
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: blink-dot 1.25s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.16s; }
.typing span:nth-child(3) { animation-delay: 0.32s; }

/* caret while streaming */
.streaming .bubble > :last-child::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--accent);
  border-radius: 2px;
  animation: caret 1s steps(2) infinite;
}

.scroll-bottom {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-dim);
  box-shadow: var(--shadow-md);
  animation: pop-in 160ms var(--ease);
  z-index: 5;
}
.scroll-bottom svg { width: 17px; height: 17px; }
.scroll-bottom:hover { color: var(--text); border-color: var(--accent-line); }
/* `display: grid` above outranks the UA's [hidden] { display: none }, so the
   hidden state has to be restated explicitly. */
.scroll-bottom[hidden] { display: none; }

/* ============================= composer ============================= */
.composer-wrap {
  padding: 10px 20px 16px;
  flex-shrink: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 8px 8px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-md);
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
.composer:focus-within {
  border-color: var(--accent-line);
  box-shadow: var(--shadow-md), 0 0 0 4px var(--accent-soft);
}

#message-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  padding: 9px 0;
  max-height: 190px;
  font-size: 14.8px;
  line-height: 1.55;
  outline: none;
}
#message-input::placeholder { color: var(--text-faint); }

.mic-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text-faint);
  transition: color 140ms var(--ease), background-color 140ms var(--ease), border-color 140ms var(--ease);
}
.mic-btn svg { width: 18px; height: 18px; }
.mic-btn:hover { color: var(--text); background: var(--surface-2); }
.mic-btn[aria-pressed="true"] {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
  animation: mic-pulse 1.6s ease-in-out infinite;
}
.mic-btn[hidden] { display: none; }

#send-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
  color: var(--accent-ink);
  transition: transform 140ms var(--ease), filter 140ms var(--ease), opacity 140ms var(--ease);
}
#send-btn svg { width: 18px; height: 18px; }
#send-btn .stop-icon { display: none; }
#send-btn:hover:not(:disabled) { filter: brightness(1.08); }
#send-btn:active:not(:disabled) { transform: scale(0.94); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.composer.busy #send-btn { background: var(--surface-3); color: var(--text); opacity: 1; cursor: pointer; }
.composer.busy #send-btn .send-icon { display: none; }
.composer.busy #send-btn .stop-icon { display: block; }

.composer-hint {
  max-width: 820px;
  margin: 9px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ============================== modals ============================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  padding: 12vh 20px 20px;
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  backdrop-filter: blur(6px);
  animation: fade-in 140ms var(--ease);
  /* Panels that size to their content (rather than capping at 72vh) can be
     taller than a short window. Let the backdrop scroll so the buttons at the
     bottom stay reachable instead of falling off the screen. */
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 640px;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop-in 180ms var(--ease);
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.search-bar svg { width: 18px; height: 18px; color: var(--text-faint); flex-shrink: 0; }
.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 15.5px;
}
.search-bar input::placeholder { color: var(--text-faint); }

.search-results { overflow-y: auto; padding: 8px; }
.search-hint, .search-empty {
  padding: 26px 18px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  margin: 0;
}

.search-count {
  padding: 6px 12px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-faint);
}

.result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 13px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease);
}
.result:hover, .result.cursor {
  background: var(--surface-2);
  border-color: var(--border);
}
.result-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--text-faint);
}
.result-role {
  font-family: var(--font-mono);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-3);
}
.result-role.model { background: var(--accent-soft); color: var(--accent); }
.result-conv {
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-snippet {
  font-size: 13.2px;
  color: var(--text-dim);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.result-snippet mark {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--text);
  border-radius: 3px;
  padding: 0 2px;
}

/* voice modal */
.voice-panel { max-width: 560px; }
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h3 {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0 0 3px;
}
.modal-head p { margin: 0; font-size: 12.5px; color: var(--text-faint); max-width: 380px; }

.voice-list {
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}
.voice-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: transparent;
  text-align: left;
  transition: border-color 130ms var(--ease), background-color 130ms var(--ease);
}
.voice-option:hover { border-color: var(--accent-line); }
.voice-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.voice-dot {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-display);
  background: var(--surface-3);
  color: var(--text-dim);
}
.voice-option.selected .voice-dot {
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
}
.voice-meta { min-width: 0; }
.voice-name { display: block; font-size: 13.5px; font-weight: 600; }
.voice-vibe {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voice-controls {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--border-soft);
}
.voice-controls label { flex: 1; display: block; min-width: 0; }
.voice-controls label span {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.voice-controls label b { font-family: var(--font-mono); color: var(--text-dim); font-weight: 500; }
.voice-controls input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- shared modal bits ---------- */
.primary-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
  color: var(--accent-ink);
  font-size: 13.5px;
  font-weight: 600;
  transition: filter 140ms var(--ease), transform 140ms var(--ease);
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:active { transform: translateY(1px); }

.danger-btn { color: var(--danger); }
.danger-btn:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.modal-actions.end { justify-content: flex-end; }

.field-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 0 0 8px;
}
.field-hint { font-size: 11.5px; color: var(--text-faint); margin: 8px 0 0; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
}
.toggle-row input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.action-group { display: flex; gap: 7px; flex-shrink: 0; }

/* ---------- settings modal ---------- */
.settings-panel { max-width: 540px; }
.settings-body { padding: 16px 18px; overflow-y: auto; }

.model-list { display: grid; gap: 7px; margin-bottom: 20px; }
.model-option {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: transparent;
  text-align: left;
  transition: border-color 130ms var(--ease), background-color 130ms var(--ease);
}
.model-option:hover { border-color: var(--accent-line); }
.model-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.model-radio {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  transition: border-color 130ms var(--ease), box-shadow 130ms var(--ease);
}
.model-option.selected .model-radio {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 3px var(--accent);
}
.model-meta { min-width: 0; }
.model-name { display: block; font-size: 13.5px; font-weight: 600; }
.model-blurb { display: block; font-size: 11.5px; color: var(--text-faint); }
.model-id {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  white-space: nowrap;
}

#persona-input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 140ms var(--ease);
}
#persona-input:focus { border-color: var(--accent-line); }
#persona-input::placeholder { color: var(--text-faint); }

/* ---------- memory modal ---------- */
.memory-panel { max-width: 560px; }
.memory-add {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.memory-add input {
  flex: 1;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13.5px;
  outline: none;
  transition: border-color 140ms var(--ease);
}
.memory-add input:focus { border-color: var(--accent-line); }
.memory-add input::placeholder { color: var(--text-faint); }

.memory-list { overflow-y: auto; padding: 10px; flex: 1; min-height: 120px; }
.memory-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  transition: background-color 120ms var(--ease);
}
.memory-item:hover { background: var(--surface-2); }
.memory-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-top: 8px;
}
.memory-text { flex: 1; font-size: 13.5px; line-height: 1.5; min-width: 0; }
.memory-when { font-size: 11px; color: var(--text-faint); display: block; margin-top: 2px; }
.memory-del {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-faint);
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 120ms var(--ease), color 120ms var(--ease), background-color 120ms var(--ease);
}
.memory-del svg { width: 14px; height: 14px; }
.memory-item:hover .memory-del { opacity: 1; }
.memory-del:hover { background: var(--danger-soft); color: var(--danger); }
.memory-empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  margin: 0;
  line-height: 1.6;
}

/* ---------- generic dialog ---------- */
/* The backdrop is a flex row, so its default `align-items: stretch` pulls
   every panel to full height. The scrolling panels (search, voice, settings,
   memory) want that; these two are short and fixed, and stretching left a
   slab of dead space under the buttons. */
.dialog-panel, .auth-panel { align-self: flex-start; }

.dialog-panel { max-width: 420px; }
.dialog-panel h3 {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0;
  padding: 20px 20px 0;
}
.dialog-panel p {
  margin: 8px 0 0;
  padding: 0 20px;
  font-size: 13.5px;
  color: var(--text-dim);
  line-height: 1.6;
}
#dialog-input {
  margin: 16px 20px 0;
  width: calc(100% - 40px);
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
  outline: none;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
#dialog-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#dialog-input[hidden] { display: none; }
.dialog-panel .modal-actions { margin-top: 18px; border-top: none; }
.dialog-panel.danger .primary-btn { background: var(--danger); color: #fff; }

/* ---------- auth modal ---------- */
.auth-panel {
  max-width: 400px;
  max-height: none;
  padding: 26px 26px 20px;
  text-align: center;
  position: relative;
  overflow: visible;
}
.auth-close { position: absolute; top: 12px; right: 12px; }

.auth-mark {
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
}
.auth-mark svg { width: 24px; height: 24px; }

.auth-panel h3 {
  font-family: var(--font-display);
  font-size: 19px;
  margin: 0 0 5px;
}
.auth-panel > p {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-faint);
  line-height: 1.5;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  margin-bottom: 18px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
}
.auth-tabs button {
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  transition: background-color 140ms var(--ease), color 140ms var(--ease);
}
.auth-tabs button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.auth-form { display: grid; gap: 12px; text-align: left; }
.auth-field { display: grid; gap: 6px; }
.auth-field[hidden] { display: none; }
.auth-field > span {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.auth-field > span i {
  font-style: normal;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.75;
}
.auth-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-error {
  margin: 0;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.45;
}
.auth-error[hidden] { display: none; }

.auth-keep { margin-top: 2px; }
.auth-keep[hidden] { display: none; }

.primary-btn.block, .ghost-btn.block {
  display: block;
  width: 100%;
  text-align: center;
  padding: 11px 16px;
}
.primary-btn[disabled] { opacity: 0.6; pointer-events: none; }

.auth-foot {
  margin: 16px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-faint);
}

/* ---------- signed-out chrome ---------- */
.guest-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 9px;
  padding: 18px 14px;
  margin: 4px 0;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.guest-card[hidden] { display: none; }
.guest-card-icon {
  width: 38px;
  height: 38px;
  margin: 0 auto 2px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}
.guest-card-icon svg { width: 20px; height: 20px; }
.guest-card h3 {
  font-family: var(--font-display);
  font-size: 14px;
  margin: 0;
}
.guest-card p {
  margin: 0 0 6px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-faint);
}
.guest-card .primary-btn.block,
.guest-card .ghost-btn.block { padding: 9px 12px; font-size: 13px; }

.guest-bar {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 20px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-line);
  font-size: 12.5px;
  color: var(--text-dim);
  flex-shrink: 0;
  position: relative;
  z-index: 20;
}
.guest-bar[hidden] { display: none; }
.guest-bar svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--accent); }
.guest-bar span { flex: 1; }
.guest-bar b { color: var(--text); font-weight: 600; }
.guest-bar button {
  flex-shrink: 0;
  padding: 5px 12px;
  border: 1px solid var(--accent-line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 500;
  transition: filter 140ms var(--ease);
}
.guest-bar button:hover { filter: brightness(1.1); }

/* ---------- account row ---------- */
.account-row { padding-top: 8px; }
.account-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  text-align: left;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease);
}
.account-btn:hover { border-color: var(--accent-line); background: var(--surface-3); }
.avatar-chip {
  width: 27px;
  height: 27px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--accent-2)));
  color: var(--accent-ink);
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
}
.account-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.account-text b {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-text i {
  font-style: normal;
  font-size: 10.5px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-caret { width: 15px; height: 15px; flex-shrink: 0; color: var(--text-faint); }

/* Signed out, the account row is the call to action rather than a profile. */
.account-row.guest .avatar-chip {
  background: var(--surface-3);
  color: var(--text-faint);
  border: 1px solid var(--border);
}

/* ============================== toast ============================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(520px, calc(100vw - 40px));
  padding: 11px 17px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 200ms var(--ease);
}
.toast[hidden] { display: none; }
.toast.error { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.toast.ok { border-color: var(--ok); }

/* ============================ scrollbars ============================ */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================ animations ============================ */
@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes blink-dot {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}
@keyframes caret { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-9px) rotate(4deg); }
}
@keyframes flash {
  0%, 100% { box-shadow: var(--shadow-sm); }
  20% { box-shadow: 0 0 0 3px var(--accent-line); }
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 0 5px var(--danger-soft); }
}

/* ============================ responsive ============================ */
@media (max-width: 900px) {
  .suggestions { grid-template-columns: 1fr; }
  .voice-list { grid-template-columns: 1fr; }
  /* Hiding just the label left a bare capsule sitting there looking like a
     rendering glitch — drop the whole meter instead. */
  .context-meter { display: none; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, var(--sidebar-w));
    z-index: 60;
    background: var(--surface);
    transform: translateX(-102%);
    transition: transform 240ms var(--ease);
  }
  .app.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .sidebar-close, .sidebar-open { display: grid; }
  .scrim {
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0, 0, 0, 0.5);
    animation: fade-in 160ms var(--ease);
  }
  .scrim[hidden] { display: none; }
  .topbar { padding: 10px 12px; }
  .thread { padding: 18px 12px 8px; }
  .composer-wrap { padding: 8px 12px 12px; }
  .composer-hint { display: none; }
  #autospeak-btn span { display: none; }
  .modal-backdrop { padding: 6vh 12px 12px; }
  .msg-actions { opacity: 1; }
  .voice-controls { flex-wrap: wrap; }
  .incognito-bar { padding: 9px 12px; font-size: 11.5px; }
  .incognito-bar b + br { display: none; }
  .model-id { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .thread { scroll-behavior: auto; }
}
