/* ==========================================================================
   Aether — private research workstation
   The Nous Research stage: deep navy, electric blue, compressed gothic caps.
   Blue means "live": borders, focus, streaming, the one action that matters.
   Corners are sharp, rules are hairlines, labels are small caps.
   ========================================================================== */

/* --------------------------------------------------------------------------
   TOKENS  (palette values measured from nousresearch.com's computed styles:
   stage #0d0d24, signal #0000f2, hairline #3333f5, ink #f2f2f2, label #e5e5ee)
   -------------------------------------------------------------------------- */
:root {
  --bg:            #0d0d24;
  --bg-elevated:   #0a0a1e;
  --surface:       #12122e;
  --surface-2:     #171738;
  --surface-3:     #1d1d44;
  --hover:         #1d1d44;

  --border:        rgba(101, 101, 255, 0.24);
  --border-subtle: rgba(101, 101, 255, 0.14);
  --border-hover:  rgba(122, 122, 255, 0.48);
  --border-focus:  rgba(51, 51, 245, 0.85);

  --text:          #f2f2f2;
  --text-2:        #b9bcdd;
  --text-3:        #8a8db8;

  --accent:        #3d3df5;
  --accent-hover:  #5a5aff;
  --accent-soft:   rgba(0, 0, 242, 0.18);
  --accent-dim:    rgba(0, 0, 242, 0.14);
  --accent-glow:   rgba(0, 0, 242, 0.22);

  --danger:        #f87171;
  --danger-dim:    rgba(248, 113, 113, 0.10);
  --success:       #4ade80;
  --success-dim:   rgba(74, 222, 128, 0.10);
  --warning:       #fbbf24;
  --warning-dim:   rgba(251, 191, 36, 0.10);

  --font-sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Space Grotesk', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  --font-display: 'Anton', 'Arial Narrow', sans-serif;

  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-6: 24px; --space-8: 32px; --space-12: 48px; --space-16: 64px;

  --radius-xs: 2px; --radius-sm: 2px; --radius-md: 3px;
  --radius-lg: 4px; --radius-xl: 6px; --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.55);

  --dur-fast: 120ms;
  --dur-base: 180ms;
  --ease: cubic-bezier(0.2, 0.8, 0.3, 1);

  --sidebar-w: 290px;
  --topbar-h: 52px;
  --measure: 760px;
}

[data-theme="light"] {
  --bg:            #ffffff;
  --bg-elevated:   #fafafa;
  --surface:       #f6f7f9;
  --surface-2:     #eef0f3;
  --surface-3:     #e6e8ed;
  --hover:         #eef0f3;

  --border:        rgba(0, 0, 0, 0.10);
  --border-subtle: rgba(0, 0, 0, 0.06);
  --border-hover:  rgba(0, 0, 0, 0.16);
  --border-focus:  rgba(47, 90, 230, 0.55);

  --text:          #101114;
  --text-2:        #52525b;
  --text-3:        #71717a;

  --accent:        #0000f2;
  --accent-hover:  #1a1aff;
  --accent-soft:   rgba(0, 0, 242, 0.10);
  --accent-dim:    rgba(0, 0, 242, 0.10);
  --accent-glow:   rgba(0, 0, 242, 0.12);

  --danger:        #dc2626;
  --success:       #16a34a;
  --warning:       #b45309;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.12);
}

/* --------------------------------------------------------------------------
   RESET & FOUNDATIONS
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, textarea, select { font: inherit; color: inherit; background: none; border: none; }
button { cursor: pointer; }
input, textarea { outline: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
textarea:focus-visible, input[type="search"]:focus-visible { outline: none; }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: var(--radius-full); border: 3px solid transparent; background-clip: content-box; }

/* --------------------------------------------------------------------------
   BOOT SKELETON
   -------------------------------------------------------------------------- */
.boot { display: flex; height: 100vh; width: 100vw; background: var(--bg); }
.boot-sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  border-right: 1px solid var(--border-subtle); background: var(--bg-elevated);
}
.boot-main { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 10px; padding: 0 clamp(16px, 8vw, 120px); }
.boot-line { height: 10px; border-radius: var(--radius-sm); background: var(--surface-2); animation: boot-fade 1.2s ease-in-out infinite alternate; }
.boot-line--short { width: 45%; }
@keyframes boot-fade { from { opacity: 0.35; } to { opacity: 0.7; } }

/* --------------------------------------------------------------------------
   SHELL
   -------------------------------------------------------------------------- */
.shell { display: flex; height: 100vh; height: 100dvh; width: 100vw; background: var(--bg); overflow: hidden; }

.main {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  height: 100%; background: var(--bg);
}
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

/* --------------------------------------------------------------------------
   SIDEBAR
   -------------------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  transition: width var(--dur-base) var(--ease), transform var(--dur-base) var(--ease);
  overflow: hidden; position: relative; z-index: 20;
}
.sidebar.collapsed { width: 0; border-right-width: 0; visibility: hidden; }
#menu-btn { display: none; }
.shell.sidebar-collapsed #menu-btn { display: inline-flex; }

.sidebar-brand {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-2);
  min-height: var(--topbar-h);
}
.brand-mark {
  width: 24px; height: 24px; flex-shrink: 0; border-radius: var(--radius-sm);
  background: #0000f2; color: #f2f2f2;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 14px; font-weight: 400;
  border: 1px solid #3333f5;
}
/* The project icon (aether-icon-180.png) in the same slot: cover-crop, no letterbox. */
.brand-mark--img {
  object-fit: cover; border: 1px solid #3333f5; background: #000;
}
.brand-name {
  flex: 1; font-size: 14px; font-weight: 500; letter-spacing: 0.14em;
  text-transform: uppercase; white-space: nowrap; overflow: hidden;
}
.sidebar #sidebar-toggle-btn { width: 28px; height: 28px; color: var(--text-3); }

.btn-new-chat {
  margin: var(--space-1) var(--space-3) var(--space-2);
  display: flex; align-items: center; gap: var(--space-2);
  padding: 8px 10px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 14px; font-weight: 500;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn-new-chat:hover { background: var(--surface-2); border-color: var(--border-hover); }
.sidebar.collapsed .btn-new-chat { justify-content: center; }
.sidebar.collapsed .btn-label { display: none; }

.sidebar-search { padding: 0 var(--space-3) var(--space-2); position: relative; }
.sidebar.collapsed .sidebar-search { display: none; }
.sidebar-search-icon {
  position: absolute; left: calc(var(--space-3) + 9px); top: 50%;
  transform: translateY(-50%); color: var(--text-3); pointer-events: none; display: flex;
}
.conv-search {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 7px 10px 7px 30px;
  font-size: 13px; color: var(--text);
  transition: border-color var(--dur-fast) var(--ease);
}
.conv-search::placeholder { color: var(--text-3); }
.conv-search:focus { border-color: var(--border-focus); }

.sidebar-scroll {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 0 var(--space-3) var(--space-3);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar.collapsed .sidebar-scroll { display: none; }
.sidebar-section-label {
  flex: 0 0 auto; padding: var(--space-4) 6px var(--space-1);
  font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-3); user-select: none;
}
.nav-group { display: flex; flex-direction: column; gap: 1px; }

.conv-item {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  width: 100%; padding: 7px 9px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px; text-align: left;
  position: relative; transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.conv-item:hover { background: var(--surface); color: var(--text); }
.conv-item.active { background: var(--surface-2); color: var(--text); }
.conv-item.active::before {
  content: ''; position: absolute; left: -3px; top: 8px; bottom: 8px;
  width: 2px; border-radius: 2px; background: var(--accent);
}
.conv-group-label {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-3); padding: var(--space-3) 6px 2px; user-select: none;
}
.conv-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item-actions { display: none; align-items: center; gap: 2px; flex-shrink: 0; }
.conv-item:hover .conv-item-actions, .conv-item:focus-within .conv-item-actions { display: flex; }
.conv-action-btn {
  padding: 3px; border-radius: var(--radius-xs); color: var(--text-3);
  display: flex; transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.conv-action-btn:hover { color: var(--text); background: var(--surface-3); }
.list-empty { padding: var(--space-6) 8px; text-align: center; color: var(--text-3); font-size: 13px; }

/* The conversation row's own label is a button, so it has to look like the row it is inside. */
.conv-item-main {
  flex: 1; min-width: 0; text-align: left; color: inherit; font: inherit;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 0; background: none;
}

/* Loading rows carry the shape of what they replace, so the sidebar cannot jump when data lands. */
.conv-skeleton { height: 20px; margin: 7px 9px; }
.doc-skeleton { height: 62px; margin-bottom: var(--space-2); }

/* A failed read is drawn as a failed read with a way back, never as an empty list. */
.list-state {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-4) 8px; text-align: center; align-items: center;
}
.list-state .state-error { margin: 0; font-size: 12.5px; line-height: 1.45; }

.load-more {
  width: 100%; padding: 7px 9px; margin-top: var(--space-2);
  border: 1px dashed var(--border-subtle); border-radius: var(--radius-sm);
  color: var(--text-3); font-size: 12.5px; text-align: center;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.load-more:hover { color: var(--text); border-color: var(--border); }
.load-more:disabled { opacity: 0.55; cursor: progress; }

.sidebar-foot {
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-top: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; gap: 1px;
}
.side-link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 7px 9px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px; font-weight: 500;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.side-link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.side-link.active { background: var(--surface-2); color: var(--text); }
.sidebar.collapsed .side-link { justify-content: center; }
button.side-link { text-align: left; width: 100%; }

.sidebar-account { display: flex; margin-top: var(--space-1); }
.account-row {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; padding: 6px 8px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none; color: var(--text-2);
  font: inherit; text-align: left;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
button.account-row:hover { background: var(--surface); color: var(--text); }
.account-row--button { cursor: pointer; border-color: var(--border); }
.account-avatar {
  flex: none; width: 24px; height: 24px; border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  color: var(--accent); background: var(--accent-soft);
}
.account-avatar--local { color: var(--text-3); background: var(--surface-2); }
.account-label { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.account-name { font-size: 13px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-sub { font-size: 11.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-signout { flex: none; width: 28px; height: 28px; }

/* --------------------------------------------------------------------------
   TOPBAR
   -------------------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  height: var(--topbar-h); flex-shrink: 0;
  padding: 0 var(--space-4); border-bottom: 1px solid var(--border-subtle);
}
.topbar-left { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.topbar-title {
  font-size: 14px; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; max-width: 46ch;
}
.topbar-scope {
  font-size: 12px; color: var(--accent); background: var(--accent-soft);
  padding: 2px 8px; border-radius: var(--radius-full);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 24ch;
  cursor: pointer;
}
/* The pill describes the composer's scope, so it is only honest while the chat is on screen. */
.main:not(:has(#view-chat:not(.hidden))) .topbar-scope { display: none; }
.topbar-status { font-size: 12px; color: var(--text-3); font-family: var(--font-mono); }
.topbar-status[data-tone="running"] { color: var(--accent); }
.topbar-status[data-tone="error"] { color: var(--danger); }
.topbar-status[data-tone="ok"] { color: var(--success); }
#project-back-btn, #project-edit-btn { display: none; }
.main:has(#view-project:not(.hidden)) #project-back-btn,
.main:has(#view-project:not(.hidden)) #project-edit-btn { display: inline-flex; }

/* --------------------------------------------------------------------------
   HOME / WELCOME
   -------------------------------------------------------------------------- */
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.welcome {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  gap: var(--space-4); padding: var(--space-8) clamp(16px, 5vw, 40px) var(--space-6);
  max-width: var(--measure); margin: 0 auto; width: 100%;
}
.welcome-kicker {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 700; letter-spacing: 0.36em; text-transform: uppercase;
  color: var(--text-2);
}
.welcome-line {
  font-family: var(--font-display); font-style: normal;
  font-size: clamp(34px, 5.4vw, 58px); line-height: 1.02;
  letter-spacing: 0.015em; text-transform: uppercase; color: var(--text);
  max-width: 16ch;
}
.action-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.action-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: var(--radius-md);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); font-size: 13px;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.action-chip:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-hover); }

/* --------------------------------------------------------------------------
   MESSAGES
   -------------------------------------------------------------------------- */
.messages {
  flex: 1; display: flex; flex-direction: column; gap: var(--space-8);
  padding: var(--space-8) clamp(16px, 5vw, 40px) var(--space-6);
  max-width: var(--measure); margin: 0 auto; width: 100%;
}

.msg-wrap { width: 100%; }
.msg { width: 100%; }

/* user: quiet, right-aligned, modest bubble */
.msg--user, .msg-user { display: flex; justify-content: flex-end; }
.user-bubble, .msg-user-bubble {
  background: var(--surface-2); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: 8px 14px;
  max-width: 84%; font-size: 15px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}

/* assistant: unboxed prose */
.msg--assistant, .msg-assistant { display: flex; flex-direction: column; gap: 0; }
.msg-body, .msg-content { font-size: 15.5px; line-height: 1.72; color: var(--text); word-break: break-word; }

.stream-cursor, .streaming-cursor {
  display: inline-block; width: 2px; height: 1.05em;
  background: var(--accent); margin-left: 3px; vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* --------------------------------------------------------------------------
   STEP LIST — the steps this run took, one quiet row each, above the live line
   -------------------------------------------------------------------------- */
.step-list {
  max-width: 640px;
  margin-bottom: 7px;
}
.step-list[hidden] { display: none; }
.step-row {
  display: flex; align-items: center; gap: 7px;
  min-height: 19px;
  font-size: 12.5px; color: var(--text-3);
  animation: step-in 160ms ease-out;
}
@keyframes step-in {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .step-row { animation: none; }
}
/* One 15px column, so every row's words start at the same x whether the glyph is a globe, a
   magnifier or a check - the list reads as one process without needing a drawn connector. */
.step-icon {
  display: flex; align-items: center; justify-content: center;
  width: 15px; height: 16px; flex-shrink: 0; color: var(--text-3);
}
.step-icon svg { width: 12px; height: 12px; }
.step-label { min-width: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* A page path is an address, not a sentence. Monospace keeps it readable at this size and stops a
   long hostname from being mistaken for something the run wrote about. */
.step-detail {
  min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-mono); font-size: 11.5px;
}
.step-row--more { font-style: italic; opacity: 0.8; }

/* --------------------------------------------------------------------------
   STATUS LINE — one quiet line, from the events that actually arrived
   -------------------------------------------------------------------------- */
.status-line {
  display: flex; align-items: center; gap: 7px;
  margin-bottom: var(--space-3); max-width: 640px;
  font-size: 12.5px; color: var(--text-2);
}
.status-line[data-state="done"],
.status-line[data-state="stopped"] { color: var(--text-3); }
.status-mark { display: flex; align-items: center; flex-shrink: 0; color: var(--text-3); }
.status-line[data-state="running"] .status-mark { color: var(--text-2); }
.status-text {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Three travelling dots, not a pulsing blue light: the line says work is happening, it does not
   announce itself as a status indicator the user has to interpret. */
.status-dots { display: inline-flex; align-items: center; gap: 3px; height: 16px; }
.status-dots i {
  width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: 0.25;
  animation: dot-travel 1.15s ease-in-out infinite;
}
.status-dots i:nth-child(2) { animation-delay: 0.15s; }
.status-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-travel {
  0%, 55%, 100% { opacity: 0.25; transform: translateY(0); }
  25% { opacity: 0.95; transform: translateY(-2px); }
}
.status-line[data-state="stopped"] .status-dots i { animation: none; opacity: 0.55; }
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* --------------------------------------------------------------------------
   SITE MARKS — real icons via this origin's /meta/favicon; the letter is the fallback
   -------------------------------------------------------------------------- */
.site-icon {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; flex-shrink: 0; border-radius: var(--radius-full);
  background: var(--surface-3); border: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 10px; font-weight: 600; color: var(--text-2);
}
/* The fetched icon covers the letter it stands on; when the proxy 404s, chat.js removes
   the image and the hashed hue underneath is what remains. */
.site-favicon {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; padding: 2px; box-sizing: border-box; background: var(--surface-3);
}
/* --site-h is hashed per domain in chat.js; the hue only ever tints a mark, never an accent. */
.site-icon[data-site] {
  background: hsl(var(--site-h, 220) 22% 17%);
  border-color: hsl(var(--site-h, 220) 20% 27%);
  color: hsl(var(--site-h, 220) 45% 74%);
}
[data-theme="light"] .site-icon[data-site] {
  background: hsl(var(--site-h, 220) 34% 93%);
  border-color: hsl(var(--site-h, 220) 26% 84%);
  color: hsl(var(--site-h, 220) 42% 33%);
}
.site-strip { display: inline-flex; align-items: center; flex-shrink: 0; }
/* Overlapped like a stack, each ring separating it from the one behind. */
.site-strip .site-icon + .site-icon { margin-left: -5px; }
.site-strip .site-icon { box-shadow: 0 0 0 1.5px var(--bg); }
.site-icon--more { font-size: 9px; color: var(--text-3); }
.source-item .site-icon { margin-top: 1px; }

/* legacy flow panel (still emitted by the current chat.js until it is replaced) */
.run-flow {
  display: flex; flex-direction: column; gap: 4px;
  padding: var(--space-3); margin-bottom: var(--space-3);
  background: var(--surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); font-size: 12.5px; color: var(--text-2); max-width: 420px;
}
.run-flow-step { display: flex; align-items: center; gap: var(--space-2); }
.run-flow-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex-shrink: 0; animation: breathe 1.5s ease-in-out infinite; }
.run-flow.done .run-flow-dot { animation: none; background: var(--success); }

/* --------------------------------------------------------------------------
   SOURCES / CLAIMS / CITATIONS
   -------------------------------------------------------------------------- */
.sources {
  margin-top: var(--space-4);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  background: var(--surface); overflow: hidden;
}
.sources-head, .evidence-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: 8px 12px; cursor: pointer; user-select: none;
  font-size: 12.5px; font-weight: 500; color: var(--text-2); width: 100%; text-align: left;
  transition: background var(--dur-fast) var(--ease);
}
.sources-head:hover, .evidence-header:hover { background: var(--surface-2); color: var(--text); }
.evidence-head-left { display: flex; align-items: center; gap: 7px; }
.chev { display: flex; color: var(--text-3); transition: transform var(--dur-fast) var(--ease); }
.sources-body, .evidence-body {
  padding: 10px 12px; border-top: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; gap: var(--space-3);
}
.source-item, .citation-item { display: flex; align-items: flex-start; gap: var(--space-2); font-size: 13px; }
.source-num, .citation-num {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; color: var(--text-3);
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  padding: 1px 4px; flex-shrink: 0; margin-top: 2px;
}
.source-text, .citation-text { flex: 1; min-width: 0; }
.source-title, .citation-title { color: var(--text); font-weight: 500; }
.source-title:hover, .citation-title a:hover { color: var(--accent); }
.source-domain, .citation-url {
  font-size: 11.5px; color: var(--text-3); font-family: var(--font-mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.source-snippet, .citation-snippet { font-size: 12.5px; color: var(--text-2); margin-top: 3px; line-height: 1.5; }

/* Verification is a footnote beside the answer, not a stack of alert boxes: the verdict is the
   fact, the coloured rule carries its weight, and only a dispute earns emphasis. */
.claims { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-4); }
.claim, .claim-card {
  padding-left: 10px; border-left: 2px solid var(--border);
  font-size: 13px; color: var(--text-2);
}
.claim-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 2px; }
.claim .chip {
  padding: 0; border: none; background: none;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.02em;
  color: var(--text-3);
}
.claim .chip-ok { color: var(--success); }
.claim .chip-warn { color: var(--warning); }
.claim .chip-bad { color: var(--danger); }
.claim-text { font-size: 13px; color: var(--text-2); }
.claim-quote { font-size: 12px; color: var(--text-3); margin-top: 2px; line-height: 1.45; }
/* One verdict shared by every claim is a footnote, not a stack of identical cards. */
.claim--summary { padding-left: 10px; }
.claim--summary .claim-top { margin-bottom: 0; }
.claim[data-stance="supports"] { border-left-color: var(--success); }
.claim[data-stance="contradicts"] { border-left-color: var(--danger); }
.claim[data-stance="contradicts"] .claim-quote { color: var(--danger); }
.claim-foot { font-size: 11.5px; color: var(--text-3); margin-top: 3px; font-family: var(--font-mono); }

.cite-warning {
  margin-top: var(--space-3); font-size: 12.5px; color: var(--warning);
  background: var(--warning-dim); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm); padding: 6px 10px;
}
/* A run that verified nothing is a fact worth one muted line, not an amber alert box. */
.verify-note { margin-top: var(--space-3); font-size: 12px; color: var(--text-3); }

/* --------------------------------------------------------------------------
   MESSAGE ACTIONS
   -------------------------------------------------------------------------- */
.msg-actions { display: flex; align-items: center; gap: 2px; margin-top: var(--space-3); }
.msg-action, .msg-action-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 7px; border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text-3);
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.msg-action:hover, .msg-action-btn:hover { color: var(--text); background: var(--surface-2); }
.msg-action[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }

/* --------------------------------------------------------------------------
   ERROR CARD
   -------------------------------------------------------------------------- */
.error-card {
  margin-top: var(--space-3); padding: 12px 14px;
  border: 1px solid var(--border-subtle); border-left: 2px solid var(--danger);
  border-radius: var(--radius-md); background: var(--surface); max-width: 560px;
}
.error-title { font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.error-body { font-size: 13px; color: var(--text-2); }
.error-actions { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3); }
.error-toggle { font-size: 12px; color: var(--text-3); padding: 3px 6px; border-radius: var(--radius-xs); }
.error-toggle:hover { color: var(--text-2); background: var(--surface-2); }
.error-tech {
  margin-top: var(--space-2); padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--bg-elevated); border: 1px solid var(--border-subtle);
  font-family: var(--font-mono); font-size: 11.5px; color: var(--text-3);
  display: flex; flex-direction: column; gap: 3px; overflow-x: auto;
}

/* --------------------------------------------------------------------------
   MARKDOWN
   -------------------------------------------------------------------------- */
.md > * + * { margin-top: var(--space-3); }
.md p { margin: 0; }
.md h2 { font-size: 18px; font-weight: 600; line-height: 1.35; margin-top: var(--space-6); }
.md h3 { font-size: 16px; font-weight: 600; line-height: 1.4; margin-top: var(--space-5, 20px); }
.md h4 { font-size: 14.5px; font-weight: 600; margin-top: var(--space-4); }
.md ul, .md ol { padding-left: var(--space-6); }
.md li { margin-bottom: var(--space-1); }
.md li::marker { color: var(--text-3); }
.md blockquote {
  border-left: 2px solid var(--border); padding-left: var(--space-3);
  color: var(--text-2); font-style: normal;
}
.md hr { border: none; border-top: 1px solid var(--border-subtle); margin: var(--space-4) 0; }
.md strong { font-weight: 600; color: var(--text); }
.md a { color: var(--accent); }
.md code {
  font-family: var(--font-mono); font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs); padding: 1px 5px;
}
.md pre { background: none; border: none; padding: 0; margin: 0; }
.md pre code { background: none; border: none; padding: 0; font-size: 13px; }
.md table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--border-subtle); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface); font-weight: 600; }
.md .cite {
  font-family: var(--font-mono); font-size: 11px; color: var(--accent);
  background: var(--accent-soft); border-radius: var(--radius-xs);
  padding: 0 4px; margin: 0 1px; vertical-align: baseline; cursor: pointer;
}
.md .cite:hover { text-decoration: underline; }

/* legacy message typography from the current renderer */
.msg-content p { margin-bottom: var(--space-3); }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content h2 { font-size: 18px; font-weight: 600; margin: var(--space-4) 0 var(--space-2); }
.msg-content h3 { font-size: 16px; font-weight: 600; margin: var(--space-3) 0 var(--space-2); }
.msg-content h4 { font-size: 15px; font-weight: 600; margin: var(--space-2) 0 var(--space-1); }
.msg-content ul, .msg-content ol { margin: var(--space-2) 0 var(--space-3) var(--space-6); }
.msg-content li { margin-bottom: var(--space-1); }
.msg-content strong { font-weight: 600; }
.msg-content a { color: var(--accent); }
.msg-content code {
  font-family: var(--font-mono); font-size: 13px; padding: 1px 5px;
  border-radius: var(--radius-xs); background: var(--surface-2);
}
.msg-content pre { padding: 12px 14px; overflow-x: auto; font-family: var(--font-mono); font-size: 13px; line-height: 1.55; }
.msg-content pre code { padding: 0; background: none; }

/* --------------------------------------------------------------------------
   CODE BLOCKS
   -------------------------------------------------------------------------- */
.code-block {
  margin: var(--space-4) 0; border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); background: var(--bg-elevated); overflow: hidden;
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px; background: var(--surface); border-bottom: 1px solid var(--border-subtle);
}
.code-lang {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-3);
  letter-spacing: 0.04em;
}
.code-copy {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; color: var(--text-3); padding: 2px 6px; border-radius: var(--radius-xs);
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.code-copy:hover { color: var(--text); background: var(--surface-2); }
.code-copy.copied { color: var(--success); }
.code-copy.copy-failed { color: var(--danger); }
.code-block pre, .msg-body pre {
  margin: 0; padding: 12px 14px; overflow-x: auto;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.55;
}

/* --------------------------------------------------------------------------
   COMPOSER
   -------------------------------------------------------------------------- */
.composer {
  flex-shrink: 0;
  padding: var(--space-2) clamp(12px, 5vw, 40px) calc(var(--space-3) + env(safe-area-inset-bottom));
  max-width: calc(var(--measure) + 80px); margin: 0 auto; width: 100%;
}
.composer-box {
  display: flex; flex-direction: column; gap: var(--space-1);
  background: var(--surface); border: 1.5px solid rgba(51, 51, 245, 0.55);
  border-radius: var(--radius-lg); padding: var(--space-2);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.composer-box:focus-within { border-color: #3333f5; box-shadow: 0 0 0 3px var(--accent-glow); }
.composer-input {
  width: 100%; resize: none; border: none; background: transparent;
  min-height: 24px; max-height: 220px;
  padding: 6px 8px 2px; font-size: 15.5px; line-height: 1.55; color: var(--text);
}
.composer-input::placeholder { color: var(--text-3); }
.composer-controls { display: flex; align-items: center; gap: 4px; padding: 2px 4px 0; }
.composer-spacer { flex: 1; }

.control-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px; border-radius: var(--radius-full);
  border: 1px solid var(--border); background: transparent;
  color: var(--text-3); font-size: 12.5px;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.control-chip:hover { color: var(--text); background: var(--surface-2); }
.control-chip[aria-pressed="true"] { color: var(--accent); border-color: var(--border-focus); background: var(--accent-soft); }
.control-chip:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-send, .btn-stop {
  width: 32px; height: 32px; border-radius: var(--radius-full); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
  transition: background var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
.btn-send { background: var(--accent); }
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { background: var(--surface-3); color: var(--text-3); cursor: not-allowed; }
.btn-stop { background: var(--surface-3); color: var(--text); }
.btn-stop:hover { background: var(--danger); color: #fff; }

.composer-note {
  margin: 6px 4px 0; font-size: 11.5px; color: var(--text-3);
  padding-left: calc(env(safe-area-inset-left));
}
.note-key { color: var(--text-2); }

/* --------------------------------------------------------------------------
   ATTACHMENTS
   -------------------------------------------------------------------------- */
.attachment-strip { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: 0 4px var(--space-2); }
.attachment-strip:empty { display: none; }
.attachment {
  position: relative; overflow: hidden; isolation: isolate;
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2);
  min-width: 180px; max-width: 260px;
  padding: 6px 8px 6px 10px; border-radius: var(--radius-md);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--text);
}
.attachment-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }
.attachment-track {
  height: 2px; border-radius: var(--radius-full); background: var(--border);
  margin-top: 4px; overflow: hidden; position: relative;
}
.attachment-fill { height: 100%; width: 0; background: var(--accent); border-radius: var(--radius-full); }
.attachment[data-state="uploading"] .attachment-fill { width: 0; }
.attachment[data-state="processing"] .attachment-fill::after,
.attachment[data-state="uploading"].indeterminate .attachment-fill::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: sweep 1.4s linear infinite;
}
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.attachment[data-state="ready"] { border-color: var(--border); }
.attachment[data-state="ready"] .attachment-meta { color: var(--success); }
.attachment[data-state="processing"] .attachment-meta { color: var(--warning); }
/*
 * This tab stopped watching, not the server: the file is still being read. Neutral colour and a
 * still bar, because an animated one under "Still reading" promises movement this chip no longer
 * can see. It is also not `failed`, which is the one state that must wear the danger colour.
 */
.attachment[data-state="stale"] .attachment-meta { color: var(--text-3); }
.attachment[data-state="stale"] .attachment-error { color: var(--text-2); }
.attachment[data-state="failed"] { border-color: var(--danger); }
.attachment[data-state="failed"] .attachment-meta { color: var(--danger); }
/* A chip that never reached the network, or one the server rejected, has no progress to show. */
.attachment[data-state="failed"] .attachment-track,
.attachment[data-state="rejected"] .attachment-track { display: none; }
.attachment[data-state="rejected"] {
  border-style: dashed; border-color: var(--border-hover);
  background: var(--surface); color: var(--text-2);
}
.attachment[data-state="rejected"] .attachment-meta { color: var(--text-3); }
.attachment[data-state="rejected"] .attachment-error { color: var(--text-2); }
.attachment[data-state="rejected"] .d-flex { opacity: 0.6; }
.attachment-rm {
  flex-shrink: 0; display: flex; padding: 3px; border-radius: var(--radius-xs);
  color: var(--text-3); transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.attachment-rm:hover { color: var(--danger); background: var(--surface-3); }
/* The failure sentence from the server, on its own line under the chip's meta row. */
.attachment-error {
  flex: 1 0 100%; font-size: 11.5px; line-height: 1.35; color: var(--danger);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* legacy pills from the current chat.js */
.composer-attachments { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-2) 4px 0; }
.composer-attachments:empty { display: none; }
.attachment-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--radius-full);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; max-width: 220px;
}
.attachment-pill.uploading { opacity: 0.65; border-style: dashed; }
.attachment-pill.failed { border-color: var(--danger); color: var(--danger); }
.attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------------------
   BANNERS
   -------------------------------------------------------------------------- */
.banner {
  max-width: var(--measure); margin: var(--space-2) auto 0;
  width: calc(100% - clamp(32px, 10vw, 80px));
  padding: 9px 12px; border-radius: var(--radius-md);
  font-size: 13px; display: flex; align-items: center; gap: var(--space-2);
}
.banner-error { border: 1px solid var(--danger); background: var(--danger-dim); color: var(--danger); }
.banner-warn { border: 1px solid var(--warning); background: var(--warning-dim); color: var(--warning); }
.banner-close {
  flex: none; margin-left: auto; background: none; border: none;
  color: inherit; font-size: 17px; line-height: 1; cursor: pointer; padding: 0 2px;
}
/* The offline-mode line lives in the composer column, which sizes itself; `.banner`'s message-area
   width and top margin would fight that, so this one takes the full width of its own column. */
.composer .offline-banner { max-width: none; width: 100%; margin: 0 0 var(--space-1); }
.banner-action {
  flex: none; margin-left: auto; background: none; border: 1px solid currentColor;
  border-radius: var(--radius-full); color: inherit; font: inherit; font-size: 12px;
  padding: 2px 10px; cursor: pointer;
}
.banner-action:hover { background: var(--warning-dim); }

/* --------------------------------------------------------------------------
   BUTTONS & CHIPS
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 7px 14px; font-size: 13.5px; font-weight: 500;
  border-radius: var(--radius-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); white-space: nowrap; user-select: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--border-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger-dim); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface); color: var(--text); border-color: var(--border); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-sm); color: var(--text-2);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--radius-full);
  font-size: 11.5px; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.chip-ok, .chip.ok { color: var(--success); border-color: var(--success); background: var(--success-dim); }
.chip-warn, .chip.warn { color: var(--warning); border-color: var(--warning); background: var(--warning-dim); }
.chip-bad, .chip.bad { color: var(--danger); border-color: var(--danger); background: var(--danger-dim); }
.chip-blue, .chip.blue { color: var(--accent); border-color: var(--border-focus); background: var(--accent-soft); }

/* --------------------------------------------------------------------------
   PAGES (Documents / Settings / Project files)
   -------------------------------------------------------------------------- */
.page, .page-wrap { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-8) clamp(16px, 5vw, 40px) var(--space-16); }
.page > *, .page-wrap-inner { max-width: 900px; margin-left: auto; margin-right: auto; }
.page-wrap-inner { max-width: 900px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6);
}
.page-title { font-size: 20px; font-weight: 600; letter-spacing: -0.015em; }
.page-subtitle { font-size: 13.5px; color: var(--text-3); margin-top: 2px; }
.page-actions { display: flex; align-items: center; gap: var(--space-2); }

.drop-zone {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 1px dashed var(--border); border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-4); text-align: center; cursor: pointer;
  background: var(--surface); margin-bottom: var(--space-6);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { color: var(--text-3); display: flex; margin-bottom: 4px; }
.drop-title { font-size: 14px; font-weight: 500; }
.drop-sub { font-size: 12.5px; color: var(--text-3); }

.doc-list { display: flex; flex-direction: column; gap: var(--space-2); }
.doc-card {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--surface); border: 1px solid var(--border-subtle);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.doc-card:hover { border-color: var(--border); background: var(--surface-2); }
.doc-icon-wrap {
  width: 32px; height: 32px; border-radius: var(--radius-sm); flex-shrink: 0;
  background: var(--surface-2); color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
}
.doc-meta { flex: 1; min-width: 0; }
.doc-name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-submeta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: 3px; font-size: 12px; color: var(--text-3); }
.doc-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.doc-error-text { font-size: 12.5px; color: var(--danger); margin-top: 4px; }
.doc-progress-bar { height: 2px; background: var(--border); border-radius: var(--radius-full); margin-top: 6px; overflow: hidden; }
.doc-progress-fill { height: 100%; background: var(--warning); border-radius: var(--radius-full); }
.upload-progress-bar {
  font-size: 13px; color: var(--text-2); padding: 8px 12px; margin-bottom: var(--space-3);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
}
#doc-error { margin-bottom: var(--space-3); font-size: 13px; color: var(--danger); }

.settings-layout { display: flex; gap: var(--space-8); align-items: flex-start; }
.settings-nav { width: 180px; flex-shrink: 0; display: flex; flex-direction: column; gap: 1px; position: sticky; top: 0; }
.settings-nav-btn {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; text-align: left;
  padding: 7px 10px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 500; color: var(--text-2);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.settings-nav-btn:hover { background: var(--surface); color: var(--text); }
.settings-nav-btn.active { background: var(--surface-2); color: var(--text); }
.settings-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-6); }
.settings-card {
  padding: var(--space-5, 20px) var(--space-6); border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--border-subtle);
}
.settings-card-title { font-size: 15px; font-weight: 600; margin-bottom: var(--space-4); }
.settings-table { display: flex; flex-direction: column; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: 8px 0; border-bottom: 1px solid var(--border-subtle); font-size: 13.5px;
}
.settings-row:last-child { border-bottom: none; }
.settings-key { color: var(--text-2); }
.settings-val { color: var(--text); font-weight: 500; display: flex; align-items: center; gap: 6px; text-align: right; }
.settings-note { color: var(--text-3); font-size: 13px; padding: var(--space-4) 0; }
.settings-section { margin-top: var(--space-4); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.status-dot.green { background: var(--success); }
.status-dot.yellow { background: var(--warning); }
.status-dot.red { background: var(--danger); }

/* --------------------------------------------------------------------------
   PROJECTS
   -------------------------------------------------------------------------- */
.project-new-row {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  padding: 7px 9px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; color: var(--text-2); text-align: left;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.project-new-row:hover { background: var(--surface); color: var(--text); }
.project-item { border-radius: var(--radius-sm); margin-bottom: 1px; }
.project-item-row {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 7px 9px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px; font-weight: 500; text-align: left;
  border-left: 2px solid transparent; position: relative; cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.project-item-row:hover { background: var(--surface); color: var(--text); }
.project-item-row.active { background: var(--surface-2); color: var(--text); border-left-color: var(--accent); }
.project-item-chevron { display: flex; flex-shrink: 0; color: var(--text-3); transition: transform var(--dur-fast) var(--ease); }
.project-item-chevron.open { transform: rotate(90deg); }
.project-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item-actions { display: none; align-items: center; gap: 2px; flex-shrink: 0; margin-left: auto; }
.project-item-row:hover .project-item-actions,
.project-item-row:focus-within .project-item-actions { display: flex; }
.project-action-btn {
  padding: 3px; border-radius: var(--radius-xs); color: var(--text-3); display: flex;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.project-action-btn:hover { color: var(--text); background: var(--surface-3); }
.project-convs { padding-left: var(--space-5, 20px); display: flex; flex-direction: column; gap: 1px; }
.project-conv-item {
  display: flex; align-items: center; width: 100%; padding: 5px 8px;
  border-radius: var(--radius-sm); font-size: 12.5px; color: var(--text-3); text-align: left;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.project-conv-item:hover { background: var(--surface); color: var(--text-2); }
.project-conv-item.active { background: var(--surface-2); color: var(--text); }
.project-convs-empty { font-size: 12px; color: var(--text-3); padding: 4px 8px; }
.projects-empty { padding: var(--space-4) 8px; text-align: center; font-size: 12px; color: var(--text-3); line-height: 1.6; }
.projects-empty-cta {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 6px;
  font-size: 12px; font-weight: 500; color: var(--accent); cursor: pointer;
  padding: 3px 6px; border-radius: var(--radius-xs);
}
.projects-empty-cta:hover { background: var(--accent-soft); }
.sidebar-divider { height: 1px; background: var(--border-subtle); margin: 6px 8px; flex-shrink: 0; }
.sidebar.collapsed #project-list-section, .sidebar.collapsed .sidebar-divider { display: none; }
#project-list-section { flex: 0 0 auto; padding-bottom: 0; }

.project-tabs {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) clamp(16px, 5vw, 40px);
  border-bottom: 1px solid var(--border-subtle); flex-shrink: 0;
}
.project-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: var(--radius-sm);
  font-size: 12.5px; font-weight: 500; color: var(--text-3);
  border: 1px solid transparent;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.project-tab:hover { color: var(--text); background: var(--surface); }
.project-tab.active { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.project-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.project-files-wrap { flex: 1; overflow-y: auto; padding: var(--space-6) clamp(16px, 5vw, 40px); }
.project-hero-title { font-size: 20px; font-weight: 600; letter-spacing: -0.015em; }
.project-hero-sub { font-size: 13.5px; color: var(--text-3); margin-top: 2px; }
.project-back-btn {
  display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text-3);
  padding: 4px 8px; border-radius: var(--radius-sm); white-space: nowrap;
}
.project-back-btn:hover { color: var(--text); background: var(--surface); }
#project-indicator { color: var(--accent); font-weight: 500; }
#proj-doc-list { margin-top: var(--space-4); }
#proj-modal-delete { width: 100%; }

.project-form { display: flex; flex-direction: column; gap: 14px; }
.project-field { display: flex; flex-direction: column; gap: 5px; }
.project-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.project-input, .project-textarea {
  width: 100%; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 11px; font-size: 14px; color: var(--text);
  resize: vertical; transition: border-color var(--dur-fast) var(--ease);
}
.project-input:focus, .project-textarea:focus { border-color: var(--border-focus); outline: none; }
.project-input::placeholder, .project-textarea::placeholder { color: var(--text-3); }
.project-char-hint { font-size: 11px; color: var(--text-3); text-align: right; }
.project-danger-zone { margin-top: 6px; padding-top: var(--space-4); border-top: 1px solid var(--border-subtle); }
.project-danger-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--danger); margin-bottom: var(--space-2);
}

/* --------------------------------------------------------------------------
   MODAL / PALETTE / TOAST / SCRIM / CONTEXT MENU
   -------------------------------------------------------------------------- */
.modal-scrim {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: var(--space-4);
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5, 20px); border-bottom: 1px solid var(--border-subtle);
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-body { padding: var(--space-5, 20px); }
.modal-body-text { color: var(--text-2); font-size: 14px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: var(--space-2);
  padding: var(--space-3) var(--space-5, 20px); border-top: 1px solid var(--border-subtle);
}

#command-palette { position: fixed; inset: 0; z-index: 61; }
.palette-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 60; }
.palette-modal {
  position: fixed; top: 14%; left: 50%; transform: translateX(-50%);
  width: min(92%, 540px); z-index: 61;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden;
  display: flex; flex-direction: column;
}
.palette-input {
  width: 100%; padding: 14px 16px; font-size: 15px; color: var(--text);
  border-bottom: 1px solid var(--border-subtle); background: transparent;
}
.palette-input::placeholder { color: var(--text-3); }
.palette-list { max-height: 340px; overflow-y: auto; padding: var(--space-2); }
.palette-group-label {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-3); padding: var(--space-2) 10px 4px;
}
.palette-item {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 8px 10px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text-2);
  text-align: left; transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.palette-item.active, .palette-item:hover { background: var(--surface-2); color: var(--text); }
.palette-item-left { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.palette-kbd {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--text-3);
  padding: 1px 5px; border-radius: var(--radius-xs); background: var(--surface-3);
}
.palette-empty { padding: var(--space-8); text-align: center; color: var(--text-3); font-size: 13.5px; }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 15; }

.ctx-menu {
  position: fixed; z-index: 100; list-style: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 4px; min-width: 170px; box-shadow: var(--shadow-lg);
}
#ctx-menu {
  position: fixed; z-index: 100;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 4px; min-width: 170px;
  box-shadow: var(--shadow-lg); list-style: none;
}
.ctx-item {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  padding: 6px 9px; border-radius: var(--radius-sm);
  font-size: 13.5px; color: var(--text-2); text-align: left;
}
.ctx-item:hover { background: var(--surface-2); color: var(--text); }
.ctx-item.danger { color: var(--danger); }

.toast-container {
  position: fixed; bottom: var(--space-6); right: var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-2);
  z-index: 200; pointer-events: none;
}
.toast-item {
  pointer-events: auto; display: flex; align-items: center; gap: var(--space-2);
  padding: 9px 14px; border-radius: var(--radius-md);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-md); font-size: 13.5px; color: var(--text);
  max-width: 360px; animation: toast-in var(--dur-base) var(--ease);
}
.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--danger); }
.toast-warning { border-color: var(--warning); }
.toast-item.dismissing { opacity: 0; transition: opacity var(--dur-base) var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.toast {
  position: fixed; bottom: var(--space-6); right: var(--space-6); z-index: 200;
  padding: 9px 14px; border-radius: var(--radius-md);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md);
  font-size: 13.5px; max-width: 360px;
}

/* --------------------------------------------------------------------------
   EMPTY / LOADING
   -------------------------------------------------------------------------- */
.panel-empty { text-align: center; padding: var(--space-8); color: var(--text-3); font-size: 13px; }
.state-note { color: var(--text-3); font-size: 13px; }
.state-error { color: var(--danger); font-size: 13px; }
.skeleton { background: var(--surface-2); border-radius: var(--radius-sm); animation: boot-fade 1.2s ease-in-out infinite alternate; }

/* --------------------------------------------------------------------------
   RESPONSIVE
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .sidebar, .sidebar.collapsed {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(var(--sidebar-w), 84vw);
    visibility: hidden; border-right-width: 1px;
    transform: translateX(-105%);
    /* The delay is what keeps the panel painted while it slides out and drops it out of the
       tab order and the a11y tree once it is off-screen; a translated-only drawer stays
       focusable, which is how keyboard users end up in a sidebar they cannot see. */
    transition: transform var(--dur-base) var(--ease), visibility 0s linear var(--dur-base);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open-drawer {
    transform: translateX(0); visibility: visible;
    transition: transform var(--dur-base) var(--ease), visibility 0s;
  }
  .sidebar.collapsed .sidebar-scroll,
  .sidebar.collapsed .sidebar-search,
  .sidebar.collapsed .btn-label,
  .sidebar.collapsed .side-label { display: revert; }
  .sidebar.collapsed .btn-new-chat { justify-content: flex-start; }
  .sidebar.collapsed .side-link { justify-content: flex-start; }
  #menu-btn { display: inline-flex; }
}

@media (max-width: 768px) {
  .settings-layout { flex-direction: column; gap: var(--space-4); }
  .settings-nav { width: 100%; flex-direction: row; overflow-x: auto; position: static; padding-bottom: var(--space-1); }
  .settings-nav-btn { white-space: nowrap; width: auto; }
}

@media (max-width: 640px) {
  html, body { font-size: 15px; }
  .topbar { padding: 0 var(--space-3); }
  .topbar-title { max-width: 18ch; }
  .messages { padding: var(--space-5, 20px) var(--space-3) var(--space-4); gap: var(--space-6); }
  .welcome { padding: var(--space-6) var(--space-3) var(--space-4); }
  .composer { padding-left: var(--space-2); padding-right: var(--space-2); }
  .composer-note { display: none; }
  .chip-label { display: none; }
  .control-chip { padding: 6px 8px; }
  .attachment { max-width: 100%; width: 100%; }
  .user-bubble, .msg-user-bubble { max-width: 92%; }
  .page, .page-wrap { padding: var(--space-6) var(--space-3) var(--space-12); }
  .btn, .icon-btn, .action-chip, .control-chip { min-height: 36px; }
}

@media (max-width: 380px) {
  .action-chips { gap: 6px; }
}

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

@media (prefers-contrast: more) {
  :root { --border: rgba(255, 255, 255, 0.22); --border-subtle: rgba(255, 255, 255, 0.16); --text-3: #9ea3ae; }
}

@media (forced-colors: active) {
  .btn, .icon-btn, .control-chip, .composer-box, .doc-card, .modal { border: 1px solid CanvasText; }
}

/* --------------------------------------------------------------------------
   UTILITIES

   static-ui.ts sends `style-src 'self' https://fonts.googleapis.com` with no
   'unsafe-inline', so the browser discards every style="" attribute. These
   classes carry the declarations those attributes asked for, and sit last so
   they win by source order against equal-specificity component rules above.
   -------------------------------------------------------------------------- */
.d-flex { display: flex; }
.flex-none { flex-shrink: 0; }
.text-muted { color: var(--text-3); }
.text-danger { color: var(--danger); }
.font-sans { font-family: var(--font-sans); }
.toolbar-row { display: flex; gap: var(--space-2); align-items: center; }
.inline-row { display: flex; gap: var(--space-2); }
.row-end { display: flex; justify-content: flex-end; gap: var(--space-2); margin-bottom: var(--space-4); }
.meta-code { font-size: 12px; font-family: var(--font-mono); }
.meta-code-muted { font-size: 12px; font-family: var(--font-mono); color: var(--text-3); }
.accent-swatch { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); display: inline-block; }
.footnote { margin-top: var(--space-3); font-size: 12px; color: var(--text-3); }
.delete-btn { color: var(--text-3); }

/* ══════════════════════ LANDING (signed-out welcome) ══════════════════════
   The clip, full-bleed, with a single button over it and nothing else: no scrim, no copy.
   The poster is painted by the browser from the video's `poster` attribute and is also the
   CSS background beneath the video, so a decode failure or reduced-motion setting leaves a
   composed still frame rather than a black panel. */
.landing {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg);
}
.landing-media {
  position: absolute;
  inset: 0;
  background: var(--bg) url('./landing-poster.jpg') center / cover no-repeat;
}
.landing-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* When the clip cannot play, drop it so the poster background shows through cleanly. */
.landing--no-video .landing-video { display: none; }
.landing--static .landing-video { display: none; }
.landing-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-6);
  width: min(920px, 100%);
  animation: landing-rise 900ms var(--ease) both;
}
.landing-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 48px;
  padding: 0 var(--space-6);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--dur-base) var(--ease), border-color var(--dur-base) var(--ease), transform var(--dur-fast) var(--ease);
}
.landing-btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 3px; }
.landing-btn--primary {
  /* Signal blue: the exact #0000f2 the site's own --background variable carries. */
  background: #0000f2;
  color: #f2f2f2;
  border-color: #3333f5;
  /* The one bit of shade left on this screen: the button's own drop, so it reads on any frame. */
  box-shadow: 0 8px 32px rgba(0, 0, 40, 0.35);
}
.landing-btn--primary:hover { background: #1a1aff; transform: translateY(-1px); }
.landing-note {
  margin: var(--space-6) 0 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #f2f2f2;
  max-width: 52ch;
  /* Bare text over the clip: a shadow per glyph keeps it legible on bright water without
     reintroducing a panel or gradient behind it. */
  text-shadow: 0 1px 12px rgba(0, 0, 20, 0.85);
}
@keyframes landing-rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .landing-content { animation: none; }
  .landing-btn { transition: none; }
}
