/* CriticalAsset AI Portal — internal tool stylesheet.
   Tailored palette, no framework. Clean, professional, dense-information-friendly. */

/* Self-hosted Geist Variable. Files vendored from the npm `geist` package's
   dist/fonts/geist-{sans,mono}/ directory at /static/fonts/. Variable fonts
   cover weight 100-900 + italic in a single file each = 4 woff2 total
   (~290KB). font-display: swap so we never block first paint. */
@font-face {
  font-family: "Geist";
  src: url("/static/fonts/Geist-Variable.woff2") format("woff2-variations"),
       url("/static/fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist";
  src: url("/static/fonts/Geist-Italic-Variable.woff2") format("woff2-variations"),
       url("/static/fonts/Geist-Italic-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/static/fonts/GeistMono-Variable.woff2") format("woff2-variations"),
       url("/static/fonts/GeistMono-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/static/fonts/GeistMono-Italic-Variable.woff2") format("woff2-variations"),
       url("/static/fonts/GeistMono-Italic-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg: #0b0f16;
  --bg-elevated: #131a24;
  --bg-card: #1a2230;
  --border: #253042;
  --border-light: #344258;
  --text: #e6ecf5;
  --text-dim: #9aa7bc;
  --text-muted: #5f6e85;
  /* Disabled controls: must clear WCAG AA (4.5:1) on white text + accent bg.
     --text-muted (#5f6e85) is the right token for muted prose, but on a button
     with white text it sits at ~5.3:1 — borderline. --text-disabled is brighter
     (~6.7:1 on white) so disabled CTAs stay legible. */
  --text-disabled: #6d7d94;
  --accent: #4f8cff;
  --accent-hover: #6aa0ff;
  --accent-soft: rgba(79, 140, 255, 0.15);
  --success: #3ecf8e;
  --warning: #f5a623;
  --danger: #e05a5a;
  --mono: "Geist Mono", ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
  /* Sans stack: prefers Geist if a future deploy ships /static/fonts/.
     Falls through to ui-sans-serif (modern OS-default) and the historical
     fallback chain. F-004 in the design audit recommends self-hosting Geist
     (or another expressive typeface); when that lands, the @font-face below
     activates automatically and Geist becomes primary. Until then this is
     the same stack with one extra fallback (ui-sans-serif) for newer browsers. */
  --sans: "Geist", "Geist Variable", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --max-width: 1100px;
  /* 4px-based spacing scale. Use these instead of magic numbers so the same
     padding/gap/margin reads the same across pages. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  /* Canonical breakpoints — referenced via media queries by file name only;
     CSS doesn't allow var() inside @media (max-width: ...). Documented here
     so all stylesheets stay in sync. */
  /* --bp-mobile: 600px;  --bp-tablet: 900px;  --bp-desktop: 1200px; */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

code, pre { font-family: var(--mono); font-size: 0.93em; }
code { background: var(--bg-elevated); padding: 1px 6px; border-radius: 3px; color: #c5d7f0; }

/* Native select unification — tokens-only.
   Default OS-rendered selects render as light gray on macOS Safari and
   Chrome, breaking the dark theme. Reset and draw a custom chevron in
   currentColor so the dropdown looks like part of the app on every browser.
   Each stylesheet defines its own select padding; this rule sets just the
   appearance/background/chevron. */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: var(--bg);
  color: var(--text);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='none' stroke='%239aa7bc' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Top nav --- */
.top-nav {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 32px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
}
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark {
  background: var(--accent);
  color: white;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-text { font-size: 15px; }
.nav-links {
  display: flex;
  gap: 24px;
  margin-left: auto;
}
.nav-links a {
  color: var(--text-dim);
  padding: 12px 0;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-links a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.user-area {
  padding-left: 24px;
  border-left: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--mono);
  position: relative;
}

/* Account menu: <details> + <summary> = no JS, native disclosure with
   built-in keyboard handling (Enter/Space toggles, Esc closes via the
   browser). The <summary> is the visible email + chevron; the <ul>
   pops over absolute-positioned to the right. Click anywhere inside
   to act, click outside to close (browser default for <details>). */
.user-menu {
  display: inline-block;
}
.user-menu > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  user-select: none;
  padding: 4px 0;
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover { color: var(--text); }
.user-menu[open] > summary { color: var(--text); }
.user-menu__chevron {
  transition: transform 120ms;
  flex-shrink: 0;
}
.user-menu[open] .user-menu__chevron {
  transform: rotate(180deg);
}
.user-menu__list {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  list-style: none;
  margin: 0;
  padding: 4px;
  z-index: 100;
  font-family: var(--sans);
}
.user-menu__item {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.user-menu__item:hover {
  background: var(--bg-elevated);
  text-decoration: none;
}
.user-menu__item--logout:hover {
  background: rgba(224, 90, 90, 0.12);
  color: var(--danger);
}
.user-menu__item-label {
  display: block;
  font-weight: 500;
}
.user-menu__item-hint {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.user-menu__item:hover .user-menu__item-hint {
  color: var(--text-dim);
}
.user-menu__item--logout:hover .user-menu__item-hint {
  color: rgba(224, 90, 90, 0.7);
}

/* Mobile top-nav: at <=600px, the brand+links+email overflow in a single row.
   Stack the rows, drop the email text (the menu's email is redundant in the
   summary on small screens), tighten the link gap, and let nav-links scroll
   horizontally if needed. The account menu summary collapses to just the
   chevron icon — tap to open the dropdown with Switch / Sign out actions. */
@media (max-width: 600px) {
  .nav-inner { gap: 16px; padding: 8px 16px; flex-wrap: wrap; }
  .nav-links { gap: 16px; margin-left: 0; width: 100%; overflow-x: auto; }
  .nav-links a { min-height: 40px; padding: 8px 0; flex-shrink: 0; }
  .user-area {
    padding-left: 0;
    border-left: 0;
    margin-left: auto;
  }
  .user-menu > summary {
    font-size: 0;  /* hide the email text */
  }
  .user-menu > summary::before {
    /* small avatar circle so the menu trigger has a tap target on mobile */
    content: "";
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 6px;
  }
  .user-menu__chevron {
    width: 12px;
    height: 8px;
  }
}

/* --- Container --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* --- Hero (landing) --- */
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 48px;
  align-items: start;
  padding: 40px 0 56px;
  border-bottom: 1px solid var(--border);
}
@media (max-width: 600px) {
  .hero { grid-template-columns: 1fr; gap: 24px; padding: 24px 0 40px; }
  .hero-meta { flex-direction: row; flex-wrap: wrap; gap: 12px; }
}
.hero h1 {
  margin: 0 0 16px;
  font-size: 38px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
}
.hero .lede {
  color: var(--text-dim);
  font-size: 17px;
  max-width: 640px;
  margin: 0 0 28px;
}
.cta-row { display: flex; gap: 12px; }
.hero-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}
.meta-chip {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
}
.meta-chip span {
  color: var(--text);
  margin-left: 4px;
}
.chip-ok { color: var(--success) !important; }

/* --- Buttons ---
   The .btn-* variants double as standalone classes — include the base
   reset on the variant selectors so `class="btn-primary"` produces the
   same result as `class="btn btn-primary"`. Single source of truth, no
   per-area duplicates. */
.btn,
.btn-primary,
.btn-ghost,
.btn-secondary,
.btn-danger {
  display: inline-block;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 120ms;
  font-family: inherit;
  text-align: center;
}
.btn:hover,
.btn-primary:hover,
.btn-ghost:hover,
.btn-secondary:hover,
.btn-danger:hover { text-decoration: none; }
.btn:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); color: white; border-color: var(--accent-hover); }
.btn-primary:disabled { background: var(--text-disabled); border-color: var(--text-disabled); cursor: not-allowed; color: white; }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border-light);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text); border-color: var(--text-dim); }
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border-light);
  padding: 8px 14px;
  font-size: 13px;
}
.btn-secondary:hover { background: var(--bg-card); border-color: var(--text-muted); }
.btn-danger {
  background: rgba(224, 90, 90, 0.12);
  color: var(--danger);
  border-color: rgba(224, 90, 90, 0.4);
  padding: 8px 14px;
  font-size: 13px;
}
.btn-danger:hover { background: rgba(224, 90, 90, 0.22); border-color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* --- Capabilities list (replaces the old 3-up emoji card grid on landing).
   Each item is a definition: link as <dt>, prose as <dd>. No icon, no card —
   the link itself is the affordance, the description is the substance. */
.capabilities {
  margin: var(--space-5) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: var(--space-7);
  row-gap: var(--space-5);
}
@media (max-width: 600px) {
  .capabilities { grid-template-columns: 1fr; row-gap: var(--space-4); }
}
.capability { padding: 0; }
.capability dt {
  margin: 0 0 var(--space-1);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.capability dt a {
  color: var(--text);
  border-bottom: 1px solid transparent;
}
.capability dt a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
  text-decoration: none;
}
.capability dd {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.55;
  max-width: 60ch;
}

/* --- Legacy grid cards (kept for any other surfaces still using .card).
   Landing no longer uses this. --- */
.grid { display: grid; gap: 20px; margin: 40px 0; }
.three-up { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 800px) { .three-up { grid-template-columns: 1fr; } }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: border-color 120ms;
}
.card:hover { border-color: var(--border-light); }
.card-icon { font-size: 24px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 16px; }
.card p { color: var(--text-dim); font-size: 14px; margin: 0 0 16px; }
.card-link {
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}

/* --- Info block --- */
.info-block {
  padding: 32px 0;
  border-bottom: 1px solid var(--border);
}
.info-block:last-child { border-bottom: none; }
.info-block h2 {
  margin: 0 0 16px;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.prose {
  max-width: 720px;
  color: var(--text-dim);
  margin: 0 0 16px;
}
.prose strong { color: var(--text); }
.plain-list {
  list-style: disc;
  padding-left: 20px;
  max-width: 720px;
  color: var(--text-dim);
}
.plain-list li { margin-bottom: 8px; }

/* --- Docs layout --- */
.doc-body, .toc {
  max-width: var(--max-width);
}
.container:has(.toc) {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 48px;
  max-width: var(--max-width);
  align-items: start;
}
.toc {
  position: sticky;
  top: 72px;
  padding: 16px 16px 16px 0;
  border-right: 1px solid var(--border);
}
.toc h4 {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin-bottom: 6px; }
.toc a {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  padding: 3px 0;
}
.toc a:hover { color: var(--text); text-decoration: none; }

.doc-body h1 {
  margin: 0 0 32px;
  font-size: 30px;
  letter-spacing: -0.02em;
}
.doc-body h2 {
  margin: 40px 0 12px;
  font-size: 20px;
  letter-spacing: -0.01em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.doc-body h2:first-of-type { margin-top: 0; }
.doc-body p { color: var(--text-dim); margin: 12px 0; }
.doc-body ul, .doc-body ol {
  color: var(--text-dim);
  padding-left: 24px;
}
.doc-body li { margin-bottom: 6px; }
.doc-body strong { color: var(--text); }
.doc-footer {
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
}

/* --- Chat --- */
.chat-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  height: calc(100vh - 140px);
  max-height: 900px;
}
@media (max-width: 900px) { .chat-shell { grid-template-columns: 1fr; height: auto; } }

.chat-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* 2026-05-03: scroll internally so the sidebar can't push the page
     when the projects + grounding cards + history stack overflows the
     chat-shell height. min-height:0 is required for a flex child to
     respect overflow-y:auto. */
  min-height: 0;
  overflow-y: auto;
}
.chat-sidebar h4 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.session-meta { display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.session-meta .label {
  color: var(--text-muted);
  margin-right: 6px;
  font-size: 12px;
}
.session-meta select {
  background-color: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 4px 28px 4px 8px;
  font-family: inherit;
  font-size: 12px;
  max-width: 100%;
}
.sidebar-footnote {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 16px;
  line-height: 1.5;
}

.chat-main {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.system-msg, .user-msg, .assistant-msg {
  padding: 14px 18px;
  border-radius: var(--radius);
  max-width: 85%;
  line-height: 1.6;
}
.system-msg {
  background: var(--accent-soft);
  color: var(--text-dim);
  align-self: flex-start;
  font-size: 14px;
}

/* Empty-state prompt suggestions: only renders before any user message;
   chat.js removes the wrapper on first send so the canvas frees up. */
.prompt-suggestions {
  align-self: stretch;
  padding-top: var(--space-2);
}
.prompt-suggestions__label {
  margin: 0 0 var(--space-3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.prompt-suggestions__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}
@media (max-width: 600px) {
  .prompt-suggestions__list { grid-template-columns: 1fr; }
}
.prompt-chip {
  width: 100%;
  text-align: left;
  background: var(--bg-elevated);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 120ms;
  min-height: 44px;
}
.prompt-chip:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-soft);
}
.user-msg {
  background: var(--accent);
  color: white;
  align-self: flex-end;
  white-space: pre-wrap;
}
.assistant-msg {
  background: var(--bg-elevated);
  color: var(--text);
  align-self: flex-start;
  white-space: pre-wrap;
  border: 1px solid var(--border);
}
.assistant-msg.streaming::after {
  content: "▊";
  animation: blink 1s step-end infinite;
  color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }
.assistant-msg .citations {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.assistant-msg .citations a {
  color: var(--text-dim);
  font-family: var(--mono);
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}
.composer textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 60px;
  max-height: 240px;
}
.composer textarea:focus { border-color: var(--accent); }
/* Mouse-click focus: drop the global ring (border accent already signals focus).
   Keyboard focus: keep the global ring for a11y. */
.composer textarea:focus:not(:focus-visible) { outline: none; }
.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.composer-hint {
  font-size: 11px;
  color: var(--text-muted);
}
.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.composer-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: color .12s ease, border-color .12s ease, background .12s ease;
}
.composer-icon-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.composer-icon-btn svg { display: block; }

/* --- V2.5 image-attachment tray --- */
.attach-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius);
  background: var(--bg);
  align-items: center;
}
.attach-card {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.attach-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attach-meta {
  display: none; /* keep cards compact; the thumbnail is the meta */
}
.attach-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.attach-remove:hover { background: rgba(0, 0, 0, 0.85); }
.attach-counter {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* --- V2.5 drop overlay --- */
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(79, 140, 255, 0.15);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.drop-overlay__inner {
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 14px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
}
.composer { position: relative; }

/* --- V2.5 user-msg image strip --- */
.user-msg__attachments {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.user-msg__thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.2);
}

/* /imagine output — Imagen-generated images shown inside the assistant
 * bubble. One full-width tile when n=1; 2-up grid when the user asks
 * for more. Capped width so a 1024×1024 PNG doesn't blow out the
 * conversation column. */
.assistant-msg__images {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}
.assistant-msg__image {
  width: 100%;
  max-height: 480px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border-light, rgba(255, 255, 255, 0.15));
  background: var(--bg, rgba(0, 0, 0, 0.2));
}

/* --- V2.5 history sidebar --- */
.history-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.history-summary {
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 8px;
  list-style: none;
  user-select: none;
}
.history-summary::-webkit-details-marker { display: none; }
.history-summary::before {
  content: "▸";
  font-size: 10px;
  color: var(--text-muted);
  width: 10px;
  display: inline-block;
  transition: transform .15s ease;
}
.history-section[open] > .history-summary::before { transform: rotate(90deg); }
.history-summary__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}
.history-summary__hint {
  font-size: 11px;
  color: var(--text-muted);
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
  max-height: 320px;
  overflow-y: auto;
}
.history-empty {
  margin: 0;
  padding: 12px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
.history-row {
  text-align: left;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  color: var(--text);
  transition: background .12s ease, border-color .12s ease;
}
.history-row:hover {
  background: var(--bg);
  border-color: var(--border-light);
}
.history-row--active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.history-row__title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-row__meta {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* --- V2.5 system warn message (used by attachments toast) --- */
.system-msg--warn {
  border-color: rgba(255, 184, 0, 0.4);
  color: #ffce4d;
}

/* --- V2.6 projects sidebar --- */
.projects-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.projects-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.projects-summary__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  flex: 1;
}
.projects-new-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.projects-new-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.projects-active {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 10px 0;
  padding: 6px 8px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 4px;
}
.projects-active strong {
  color: var(--text);
  font-weight: 500;
}
.projects-active__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.projects-active__clear {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.projects-active__clear:hover { color: var(--text); }

.projects-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 440px;
  overflow-y: auto;
}

.project-folder {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
}
.project-folder--active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.project-folder--unfiled {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-light);
}

.project-folder__summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  padding: 6px 8px;
  user-select: none;
  border-radius: var(--radius);
}
.project-folder__summary::-webkit-details-marker { display: none; }
.project-folder__summary::before {
  content: "▸";
  font-size: 9px;
  color: var(--text-muted);
  width: 8px;
  display: inline-block;
  transition: transform .15s ease;
}
.project-folder[open] > .project-folder__summary::before { transform: rotate(90deg); }
.project-folder__summary:hover {
  background: rgba(255, 255, 255, 0.03);
}
.project-folder__name {
  font-size: 13px;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-folder__count {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--bg);
}
.project-folder__pin,
.project-folder__edit {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  font-size: 12px;
}
.project-folder__pin:hover,
.project-folder__edit:hover { color: var(--text); }
.project-folder--active .project-folder__pin {
  color: var(--accent);
}

.project-folder__threads {
  padding: 4px 4px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* --- V2.6 move-to-project context menu --- */
.move-menu {
  z-index: 100;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  padding: 4px;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.move-menu__title {
  padding: 6px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 2px;
}
.move-menu__item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.move-menu__item:hover { background: var(--accent-soft); color: var(--accent); }

/* --- V2.6 project editor modal --- */
.project-editor {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.project-editor__card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 24px;
  width: min(540px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.project-editor__card h3 {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 600;
}
.project-editor__card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.project-editor__card input[type=text],
.project-editor__card textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  width: 100%;
}
.project-editor__card input[type=text]:focus,
.project-editor__card textarea:focus {
  border-color: var(--accent);
  outline: none;
}
.project-editor__corpora {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--bg);
}
.project-editor__corpus-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  font-weight: normal;
  padding: 4px 0;
  cursor: pointer;
}
.project-editor__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}
.project-editor__delete {
  margin-right: auto;
  color: #ff6464;
}
.project-editor__delete:hover { color: #ff8080; }

/* --- V2.7 account dossier page --- */
.account-shell {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}
.account-main {
  min-width: 0;
}
.account-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 20px;
}
.account-back {
  font-size: 12px;
  color: var(--text-muted);
}
.account-back:hover { color: var(--text); }
.account-header h1 {
  margin: 8px 0 4px 0;
  font-size: 22px;
  font-weight: 600;
}
.account-meta {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}
.account-loading,
.account-error {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius);
}
.account-error {
  border-color: rgba(255, 100, 100, 0.4);
  color: #ff8080;
}
.account-section {
  margin-bottom: 28px;
}
.account-section h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 12px 0;
}
.account-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}
.account-section dl {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 4px 16px;
  font-size: 13px;
}
.account-section dt {
  color: var(--text-muted);
}
.account-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.account-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px;
}
.account-card h3 {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 500;
}
.account-card__meta {
  margin: 0 0 4px 0;
  font-size: 11px;
  color: var(--text-muted);
}
.account-card__desc {
  margin: 8px 0 0 0;
  font-size: 13px;
  color: var(--text);
}
.account-card--note {
  background: var(--bg);
  border-style: dashed;
}
.account-empty {
  margin: 0;
  padding: 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius);
}

.account-rail {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  height: fit-content;
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.account-rail h2 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.account-rail__hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}
.account-rail__target select,
.account-rail textarea,
.account-rail input[type=text] {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
}
.account-rail label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.account-rail__actions {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}
.account-rail__status {
  font-size: 12px;
  margin: 0;
  padding: 6px 8px;
  border-radius: 4px;
}
.account-rail__status--ok {
  color: #6fc78a;
  background: rgba(111, 199, 138, 0.1);
  border: 1px solid rgba(111, 199, 138, 0.3);
}
.account-rail__status--err {
  color: #ff8080;
  background: rgba(255, 128, 128, 0.1);
  border: 1px solid rgba(255, 128, 128, 0.3);
}

@media (max-width: 900px) {
  .account-shell {
    grid-template-columns: 1fr;
  }
  .account-rail {
    position: static;
  }
}

/* ========================================================================
   V2.7 chat surface — modern Claude/ChatGPT-style layout
   ======================================================================== */

/* The chat page is full-bleed: the wrapping `.container` (1100px centered
 * column with 40px/24px/80px padding) would squeeze the grid into a
 * narrow strip with gutters, so when a `.chat2` is mounted we strip its
 * parent .container's padding/max-width entirely. The footer is also
 * suppressed below — the composer is the bottom of the page. */
.container:has(.chat2) {
  max-width: none;
  padding: 0;
  margin: 0;
}
body:has(.chat2) .footer { display: none; }

.chat2 {
  display: grid;
  grid-template-columns: 260px 1fr;
  /* Top-nav is position:sticky so it occupies layout space. Subtract a
   * conservative nav height so the chat fills the rest of the viewport
   * exactly. */
  height: calc(100vh - 60px);
  background: var(--bg);
  border-top: 1px solid var(--border);
  width: 100%;
  overflow: hidden;
}
.chat2.is-collapsed { grid-template-columns: 0 1fr; }
.chat2.is-collapsed .chat2__sidebar { transform: translateX(-100%); pointer-events: none; }

@media (max-width: 800px) {
  .chat2 { grid-template-columns: 1fr; }
  .chat2__sidebar {
    position: fixed;
    top: 60px;
    bottom: 0;
    left: 0;
    width: 280px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .18s ease;
  }
  .chat2.is-open .chat2__sidebar { transform: translateX(0); }
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.chat2__sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  min-height: 0;
  transition: transform .18s ease;
}
.chat2__sidebar-top {
  padding: 12px 12px 8px 12px;
}
.chat2__newchat {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.chat2__newchat:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }

.chat2__sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 0 8px 8px 8px;
}

.chat2__section {
  padding: 8px 4px;
  margin-bottom: 8px;
}
.chat2__section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.chat2__active-banner {
  margin: 4px 0 8px 0;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 6px;
}

.chat2__projects {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat2__hint {
  margin: 6px 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.chat2__sidebar-bottom {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat2__footnote {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Main pane ───────────────────────────────────────────────────────── */
.chat2__main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  background: var(--bg);
}

.chat2__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.chat2__sidebar-toggle { display: none; }
@media (max-width: 800px) { .chat2__sidebar-toggle { display: inline-flex; } }

.chat2__header-title {
  flex: 1;
  min-width: 0;
}
.chat2__header-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat2__header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat2__model {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
}
.chat2__model:hover { color: var(--text); }
.chat2__sources-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: color .12s ease, border-color .12s ease;
}
.chat2__sources-btn:hover { color: var(--text); border-color: var(--accent); }
.chat2__sources-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.chat2__sources-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.chat2__sources-count[hidden] { display: none; }

.chat2__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.chat2__icon-btn:hover { background: var(--bg); color: var(--text); border-color: var(--border-light); }

/* ── Conversation column ─────────────────────────────────────────────── */
.chat2__convo {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 24px 16px;
  scroll-behavior: smooth;
}
.chat2__convo > * {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

.chat2__welcome {
  padding: 64px 16px 24px 16px;
  text-align: center;
}
.chat2__welcome h1 {
  margin: 0 0 12px 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.chat2__welcome p {
  margin: 0 auto 28px auto;
  max-width: 540px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-muted);
}
.chat2__chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-width: 600px;
  margin: 0 auto;
}
@media (max-width: 600px) { .chat2__chips { grid-template-columns: 1fr; } }
.chat2__chip {
  text-align: left;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.chat2__chip:hover { border-color: var(--accent); background: var(--bg); }

/* Message bubbles — Claude-style (no avatar tags, just left/right alignment with type rhythm) */
.chat2__convo .user-msg,
.chat2__convo .assistant-msg,
.chat2__convo .system-msg {
  margin: 0 auto 24px auto;
  max-width: 760px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
}
.chat2__convo .user-msg {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 14px 18px;
  margin-left: auto;
  margin-right: 0;
  max-width: 600px;
}
.chat2__convo .assistant-msg {
  padding: 6px 0;
}
.chat2__convo .assistant-msg.streaming::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: chat2-blink 1.1s steps(2) infinite;
}
@keyframes chat2-blink { 50% { opacity: 0; } }
.chat2__convo .system-msg {
  border-left: 2px solid var(--accent);
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
}
.chat2__convo .citations {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.chat2__convo .citations a { color: var(--text-muted); text-decoration: underline; }

/* ── Markdown rendering inside assistant bubbles ─────────────────────── */
/* Spacing rule: every block element gets a single em of vertical rhythm.
 * The assistant-msg padding handles the outer gap, so first/last children
 * have their margins zeroed to avoid double-space. */
.chat2__convo .assistant-msg .md > *:first-child { margin-top: 0; }
.chat2__convo .assistant-msg .md > *:last-child { margin-bottom: 0; }
.chat2__convo .assistant-msg .md p,
.chat2__convo .assistant-msg .md ul,
.chat2__convo .assistant-msg .md ol,
.chat2__convo .assistant-msg .md blockquote,
.chat2__convo .assistant-msg .md table,
.chat2__convo .assistant-msg .md pre {
  margin: 0 0 0.85em 0;
}
.chat2__convo .assistant-msg .md h1,
.chat2__convo .assistant-msg .md h2,
.chat2__convo .assistant-msg .md h3,
.chat2__convo .assistant-msg .md h4 {
  margin: 1.2em 0 0.5em 0;
  line-height: 1.3;
}
.chat2__convo .assistant-msg .md h1 { font-size: 1.4em; font-weight: 600; }
.chat2__convo .assistant-msg .md h2 { font-size: 1.2em; font-weight: 600; }
.chat2__convo .assistant-msg .md h3 { font-size: 1.1em; font-weight: 600; }
.chat2__convo .assistant-msg .md h4 { font-size: 1em; font-weight: 600; }
.chat2__convo .assistant-msg .md ul,
.chat2__convo .assistant-msg .md ol {
  padding-left: 1.5em;
}
.chat2__convo .assistant-msg .md li { margin: 0.2em 0; }
.chat2__convo .assistant-msg .md li > p { margin: 0.2em 0; }
.chat2__convo .assistant-msg .md a {
  color: var(--accent, #4f8cff);
  text-decoration: underline;
}
.chat2__convo .assistant-msg .md strong { font-weight: 600; color: var(--text); }
.chat2__convo .assistant-msg .md em { font-style: italic; }
.chat2__convo .assistant-msg .md blockquote {
  border-left: 3px solid var(--border-light);
  padding: 4px 12px;
  color: var(--text-muted);
}
.chat2__convo .assistant-msg .md hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 1em 0;
}
.chat2__convo .assistant-msg .md table {
  border-collapse: collapse;
  font-size: 13px;
}
.chat2__convo .assistant-msg .md th,
.chat2__convo .assistant-msg .md td {
  border: 1px solid var(--border-light);
  padding: 6px 10px;
  text-align: left;
}
.chat2__convo .assistant-msg .md th { background: var(--bg-elevated); font-weight: 600; }

/* Inline code and fenced blocks. Prism's `prism-tomorrow` theme paints
 * the tokens; we just give the wrapper a tasteful container that fits
 * the dark UI. */
.chat2__convo .assistant-msg .md :not(pre) > code {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--mono, "SF Mono", ui-monospace, Menlo, monospace);
  font-size: 0.92em;
}
.chat2__convo .assistant-msg .md pre {
  background: #1e1e2e;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
}
.chat2__convo .assistant-msg .md pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* Mermaid SVG container — center the diagram and constrain width so
 * a 1200px-wide flowchart doesn't blow out the conversation column. */
.chat2__convo .assistant-msg .md .mermaid {
  margin: 1em 0;
  text-align: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
}
.chat2__convo .assistant-msg .md .mermaid svg {
  max-width: 100%;
  height: auto;
}

/* ── Composer toolbar: tool pills (Web/Code) + voice ─────────────────── */
.chat2__tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--border-light);
  border-radius: 13px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.chat2__tool-pill:hover { color: var(--text); border-color: var(--accent); }
.chat2__tool-pill.is-active {
  background: var(--accent-soft, rgba(79, 140, 255, 0.18));
  border-color: var(--accent);
  color: var(--accent);
}
.chat2__icon-btn.is-active {
  color: var(--accent);
  border: 1px solid var(--accent);
  background: var(--accent-soft, rgba(79, 140, 255, 0.18));
}

/* Stop-mode for the send button: tinted red, square stop icon */
.chat2__send.is-streaming {
  background: #c0392b;
}
.chat2__send.is-streaming:hover { background: #e74c3c; }
.chat2__send.is-streaming svg { display: none; }
.chat2__send.is-streaming::before {
  content: "";
  display: block;
  width: 10px;
  height: 10px;
  background: white;
  border-radius: 1px;
}

/* ── Per-message hover toolbar (Copy / Regenerate) ───────────────────── */
.chat2__convo .assistant-msg { position: relative; }
.msg-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .12s ease;
  pointer-events: none;
}
.chat2__convo .assistant-msg:hover .msg-actions {
  opacity: 1;
  pointer-events: auto;
}
.msg-action {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  border-radius: 5px;
  cursor: pointer;
  padding: 0;
}
.msg-action:hover { color: var(--text); border-color: var(--accent); }
.msg-action.is-ok { color: #2ecc71; border-color: #2ecc71; }
.chat2__convo .user-msg__attachments {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat2__convo .user-msg__thumb {
  width: 90px;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

/* ── Composer ────────────────────────────────────────────────────────── */
.chat2__composer-wrap {
  padding: 0 16px 16px 16px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.chat2__composer {
  position: relative;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 12px 14px 8px 14px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.chat2__composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat2__tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 8px 0;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 8px;
}
.chat2__tray[hidden] { display: none; }

.chat2__composer textarea {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  min-height: 24px;
  max-height: 240px;
  padding: 4px 0;
  overflow-y: auto;
}
.chat2__composer textarea::placeholder { color: var(--text-muted); }

.chat2__composer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 6px;
}
.chat2__composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.chat2__grounding-status {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat2__grounding-status.is-active { color: var(--accent); }

.chat2__composer-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.chat2__hint--composer {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono, monospace);
}

.chat2__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  transition: opacity .12s ease, background .12s ease;
}
.chat2__send:hover:not(:disabled) { background: var(--accent-hover); }
.chat2__send:disabled {
  background: var(--border-light);
  cursor: not-allowed;
}
.chat2__send svg { display: block; }

/* ── Drop overlay (rendered into composer dynamically by attachments.js) ── */
.chat2__drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(79, 140, 255, 0.12);
  border: 2px dashed var(--accent);
  border-radius: 14px;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  backdrop-filter: blur(2px);
}

/* ── Attachment thumbnails inside the composer tray ──────────────────── */
.chat2__tray .attach-card {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border-light);
}
.chat2__tray .attach-thumb { width: 100%; height: 100%; object-fit: cover; }
.chat2__tray .attach-meta { display: none; }
.chat2__tray .attach-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.65);
  color: white;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.chat2__tray .attach-counter {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  align-self: center;
}

/* ── Sources popover ─────────────────────────────────────────────────── */
/* Visibility is driven by the `is-open` class — never the `[hidden]`
 * attribute. JS toggling `element.hidden` was unreliable here because
 * an explicit `display: flex` outranks `[hidden]` on CSS specificity.
 * Class-based toggle removes the entire battleground. */
.chat2__popover {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.4);
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
  animation: chat2-popover-fade .14s ease-out;
}
.chat2__popover.is-open { display: flex; }
@keyframes chat2-popover-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
/* Lock background scroll while the popover is open. */
body.chat2-popover-open { overflow: hidden; }
/* Belt-and-suspenders: also honor [hidden] in case anything still
 * sets the attribute. Cheap to keep. */
.chat2__popover[hidden] { display: none; }
.chat2__popover-card {
  width: min(560px, 92vw);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  padding: 16px 18px;
}
.chat2__popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.chat2__popover-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.chat2__popover-hint {
  margin: 0 0 14px 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* The existing v2-grounding-host renders details/summary cards inside the
   popover. Tighten its visual to match the modern card style. */
.chat2__popover-card .ground-group {
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--bg);
}
.chat2__popover-card .ground-group[open] { background: var(--bg-elevated); }
.chat2__popover-card .ground-group summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  user-select: none;
  font-size: 13px;
  font-weight: 500;
}
.chat2__popover-card .ground-group summary::-webkit-details-marker { display: none; }
.chat2__popover-card .ground-group summary::before {
  content: "▸";
  font-size: 9px;
  color: var(--text-muted);
  transition: transform .15s ease;
}
.chat2__popover-card .ground-group[open] summary::before { transform: rotate(90deg); }
/* Explicit colors here — the legacy .ground-* rules at the bottom of
 * this file hardcode #0f172a / #64748b (designed for a light theme
 * sidebar). They cascade through whenever a chat2-prefixed rule
 * doesn't redeclare color, painting near-black text on the dark
 * popover. Force the dark-theme tokens. */
.chat2__popover-card .ground-label { font-weight: 500; color: var(--text); }
.chat2__popover-card .ground-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}
.chat2__popover-card .ground-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat2__popover-card .ground-badge.is-active { background: var(--accent); color: white; }
.chat2__popover-card .ground-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
}
/* Re-grid the row inside the popover (the legacy `label.ground-row`
 * grid layout below is more specific by tag-qualifier, but we want a
 * tighter dark-theme variant here). Matches the legacy structure:
 * checkbox spans both rows on the left; display name on row 1, sub on
 * row 2 in column 2. */
.chat2__popover-card label.ground-row {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 1px;
  padding: 8px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.chat2__popover-card label.ground-row:hover { background: var(--bg); }
.chat2__popover-card label.ground-row input {
  grid-row: 1 / span 2;
  align-self: center;
}
.chat2__popover-card label.ground-row span {
  grid-column: 2; grid-row: 1;
  color: var(--text);
  display: block;
}
.chat2__popover-card label.ground-row small {
  grid-column: 2; grid-row: 2;
  color: var(--text-muted);
  font-size: 11px;
}
.chat2__popover-card .ground-empty {
  padding: 8px 0 4px 14px;
  font-size: 12px;
  color: var(--text-muted);
}
.chat2__popover-card .ground-empty a {
  color: var(--accent);
  text-decoration: underline;
}

/* Project folder rows in the new sidebar */
.chat2__projects .project-folder {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
}
.chat2__projects .project-folder--active { background: var(--accent-soft); border-radius: 6px; }
.chat2__projects .project-folder__summary {
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.chat2__projects .project-folder__summary::-webkit-details-marker { display: none; }
.chat2__projects .project-folder__summary::before {
  content: "▸";
  font-size: 9px;
  color: var(--text-muted);
  transition: transform .15s ease;
}
.chat2__projects .project-folder[open] > .project-folder__summary::before { transform: rotate(90deg); }
.chat2__projects .project-folder__summary:hover { background: var(--bg); }
.chat2__projects .project-folder__name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat2__projects .project-folder__count {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.chat2__projects .project-folder__pin,
.chat2__projects .project-folder__edit {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 4px;
}
.chat2__projects .project-folder__pin:hover,
.chat2__projects .project-folder__edit:hover { color: var(--text); }
.chat2__projects .project-folder__threads {
  padding: 2px 4px 6px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat2__projects .history-row {
  text-align: left;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .12s ease, color .12s ease;
}
.chat2__projects .history-row:hover { background: var(--bg); color: var(--text); }
.chat2__projects .history-row--active { background: var(--accent-soft); color: var(--accent); }
.chat2__projects .history-row__title { display: block; }
.chat2__projects .history-row__meta { display: none; }
.chat2__projects .history-empty {
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text-muted);
  margin: 0;
}

/* --- V2 Corpora section --- */
.v2-corpora-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.v2-corpora-section h4 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.v2-select {
  width: 100%;
  background-color: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 6px 28px 6px 8px;
  font-family: inherit;
  font-size: 12px;
}
.v2-actions {
  display: flex;
  gap: 8px;
}
.v2-actions .btn {
  flex: 1;
}
.dropzone {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 120ms;
}
.dropzone.hidden {
  display: none;
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.upload-status {
  font-size: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-dim);
  border-left: 3px solid var(--border-light);
}
.upload-status.hidden {
  display: none;
}
.upload-status.info {
  border-left-color: var(--accent);
  color: var(--text);
}
.upload-status.success {
  border-left-color: var(--success);
  color: var(--text);
}
.upload-status.error {
  border-left-color: var(--danger);
  color: #ffb4b4;
}
.v2-hint {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.45;
}

/* --- Footer --- */
.footer {
  border-top: 1px solid var(--border);
  padding: 24px;
  color: var(--text-muted);
  font-size: 12px;
}
.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}
.footer-row--meta { color: var(--text-muted); }
.footer-brand { color: var(--text-dim); font-weight: 500; }
.footer-links {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}
.footer-links a {
  color: var(--text-dim);
  text-decoration: none;
}
.footer-links a:hover { color: var(--text); text-decoration: underline; }
.footer-tag { font-family: var(--mono); }

/* Hero supplementary line below the CTAs (landing page). */
.hero-foot {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 640px;
  line-height: 1.5;
}

/* Long-form doc pages (privacy, terms, security): metadata line under H1. */
.doc-meta {
  margin: -20px 0 32px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Capability list (landing). Two-up on desktop, one-column on mobile. */
.capabilities {
  margin: 24px 0 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}
@media (max-width: 800px) {
  .capabilities { grid-template-columns: 1fr; }
}
.capability dt {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
}
.capability dt a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms;
}
.capability dt a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
  text-decoration: none;
}
.capability dd {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.55;
}

/* ================= Pricing Companion ================= */

.pricing-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 0;
}

.pricing-banner {
  background: rgba(245, 166, 35, 0.12);
  border: 1px solid rgba(245, 166, 35, 0.35);
  border-left: 4px solid var(--warning);
  color: var(--warning);
  padding: 12px 16px;
  border-radius: 6px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 20px;
  font-size: 13px;
}

.pricing-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
}

.pricing-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  align-self: start;
}
.pricing-sidebar h4 {
  margin: 0 0 14px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin: 14px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pricing-select {
  width: 100%;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 28px 8px 10px;
  border-radius: 5px;
  font-size: 14px;
}

.plan-info {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 10px 12px;
  font-size: 13px;
  min-height: 44px;
}
.plan-info .muted { color: var(--text-muted); font-size: 12px; }
.plan-missing {
  color: var(--warning);
  font-size: 12px;
  font-family: var(--mono);
  line-height: 1.5;
}

.btn-primary.btn-lg {
  width: 100%;
  margin-top: 18px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.btn-primary.btn-lg:disabled {
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: not-allowed;
  border: 1px solid var(--border);
}
.btn-primary.btn-lg:not(:disabled):hover {
  background: var(--accent-hover);
}

.pricing-hint {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
  margin: 16px 0 0;
}

.pricing-details {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.pricing-details summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.pricing-history {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  font-size: 13px;
}
.pricing-history li { padding: 4px 0; }

.pricing-main {
  min-width: 0;
}

.pricing-empty {
  background: var(--bg-card);
  border: 1px dashed var(--border-light);
  border-radius: 8px;
  padding: 60px 40px;
  text-align: center;
}
.pricing-empty h2 {
  font-size: 18px;
  font-weight: 500;
  margin: 0 0 12px;
  color: var(--text-dim);
}
.pricing-empty .muted { color: var(--text-muted); font-size: 13px; }

.pricing-output {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 32px;
}
.pricing-output.hidden { display: none; }
.pricing-empty.hidden { display: none; }

.hero-price {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.hero-amount {
  font-size: 56px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.hero-currency {
  font-size: 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.hero-meta {
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.hero-meta .dot { color: var(--text-muted); }

.section-head {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin: 24px 0 12px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.pricing-trace {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.pricing-trace thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.pricing-trace th.num, .pricing-trace td.num { text-align: right; font-variant-numeric: tabular-nums; }
.pricing-trace tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.pricing-trace tbody tr.fired {
  border-left: 3px solid var(--accent);
}
.pricing-trace tbody tr.not-fired {
  opacity: 0.55;
  border-left: 3px solid var(--border);
}
.pricing-trace tbody tr.fired td:first-child,
.pricing-trace tbody tr.not-fired td:first-child { padding-left: 10px; }
.pricing-trace .muted { color: var(--text-muted); font-size: 12px; }

.citation-chip {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-family: var(--mono);
  margin-right: 4px;
  margin-bottom: 2px;
  cursor: help;
}

.missing-section {}
.missing-section.hidden { display: none; }
.missing-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}
.missing-list li {
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  margin-bottom: 8px;
  font-size: 13px;
}
.missing-list li .hint {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 4px;
}

@media print {
  .pricing-sidebar { display: none; }
  .pricing-grid { grid-template-columns: 1fr; }
  .pricing-banner { color: #b86e00; background: #fff8e1; border-color: #b86e00; }
  body { background: white; color: black; }
  .pricing-output { background: white; border: 1px solid #ccc; color: black; }
  .hero-amount { color: black; }
  .pricing-trace thead th { color: black; }
  .citation-chip { background: #eef3ff; color: #1848a8; }
  .pricing-trace tbody tr { page-break-inside: avoid; }
}

@media (max-width: 900px) {
  .pricing-grid { grid-template-columns: 1fr; }
  .pricing-main { display: none; }
  .pricing-sidebar::after {
    content: "This tool is best used on desktop.";
    display: block;
    margin-top: 16px;
    font-size: 12px;
    color: var(--warning);
  }
}

/* ---- Settings · CriticalAsset connections ---- */

:root {
  --state-ok: var(--success, #3ecf8e);
  --state-attn: var(--warning, #f5a623);
  --state-fail: var(--danger, #e05a5a);
  --state-idle: var(--text-muted);
  --success: #3ecf8e;
  --danger: #e05a5a;
}

.settings-shell { max-width: 720px; margin: 0 auto; padding: 24px 16px; }
.settings-header { margin-bottom: 20px; }
.settings-header h1 { margin: 0 0 6px; font-size: 22px; }
.settings-subline { color: var(--text-muted); font-size: 12px; line-height: 1.5; }
.settings-details-inline summary { cursor: pointer; color: var(--accent); display: inline; }
.settings-details-list { margin: 8px 0 0 18px; font-size: 12px; color: var(--text-dim); line-height: 1.6; }

/* Settings sub-nav — chip-row at the top of every /settings/* page. Defined
   here (not in drive.css) because both templates render it and only
   settings_drive.html loads drive.css. */
.settings-subnav {
  display: flex;
  gap: var(--space-1);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-1);
  margin-bottom: var(--space-4);
  width: fit-content;
}
.settings-subnav__link {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
  text-decoration: none;
  font-weight: 500;
}
.settings-subnav__link:hover {
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
}
.settings-subnav__link.is-active {
  background: var(--bg-card);
  color: var(--text);
}

.ca-conn-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 10px;
  transition: background 0.8s ease;
}
.ca-conn-card.primary { padding: 20px 24px; border-left: 3px solid var(--accent); }
.ca-conn-card.secondary { padding: 12px 16px; background: var(--bg-elevated); }
.ca-conn-card.flash { background: var(--accent-soft); }

.ca-conn-top { display: flex; align-items: center; gap: 12px; }
.ca-conn-state { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.ca-conn-label { flex: 1; font-size: 15px; }
.ca-conn-actions { display: flex; gap: 6px; align-items: center; }

.state-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.state-dot.state-ok { color: var(--state-ok); }
.state-dot.state-attn { color: var(--state-attn); }
.state-dot.state-fail { color: var(--state-fail); }
.state-dot.state-idle { color: var(--state-idle); background: transparent; border: 1px solid currentColor; }

.ca-conn-meta { font-size: 12px; font-family: var(--mono); margin-top: 4px; }
.ca-conn-meta-sub { font-size: 12px; margin-top: 2px; }
.error-inline { color: var(--state-fail); }

.ca-conn-detail { margin-top: 8px; font-size: 12px; }
.ca-conn-detail summary { color: var(--text-muted); cursor: pointer; }
.ca-conn-detail .mono { font-family: var(--mono); color: var(--text-dim); }
.meta-label { display: inline-block; width: 80px; color: var(--text-muted); }

.kebab { position: relative; display: inline-block; }
.kebab-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  list-style: none;
  padding: 4px 0;
  margin: 4px 0 0;
  min-width: 160px;
  display: none;
  z-index: 10;
  font-size: 13px;
}
.kebab-menu.open { display: block; }
.kebab-menu li {
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text-dim);
}
.kebab-menu li:hover { background: var(--bg-elevated); color: var(--text); }
.kebab-menu li.danger { color: var(--state-fail); }
.kebab-menu li.danger:hover { background: rgba(224, 90, 90, 0.1); }

/* .btn-sm and .btn-danger were redefined here in legacy settings styles —
   that override pulled .btn-sm padding back below the F-018 touch-target
   minimum (44px) and conflicted with the F-009 button consolidation in the
   global block. The global definitions win. */

.ca-conns-add-row { margin-top: 16px; }

/* Drawer + modal */
.ca-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 480px;
  max-width: 100vw;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,0.4);
  z-index: 50;
  overflow-y: auto;
}
.ca-drawer.hidden { display: none; }
.ca-drawer-inner { padding: 24px 28px; }
.ca-drawer-head { position: relative; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.ca-drawer-head h3 { margin: 0 0 6px; font-size: 17px; }
.ca-drawer-head p { margin: 0; font-size: 12px; }
.ca-drawer-close {
  position: absolute; top: 0; right: 0;
  background: transparent; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 18px;
}
.ca-drawer-form fieldset { border: none; padding: 0; margin: 0; }
.field-hint { font-size: 11px; color: var(--text-muted); margin: 4px 0 10px; }
.field-hint code { font-family: var(--mono); color: var(--text-dim); background: var(--bg-elevated); padding: 1px 4px; border-radius: 3px; }
.ca-drawer-form fieldset[disabled] { opacity: 0.6; }
.ca-drawer-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.drawer-error {
  background: rgba(224, 90, 90, 0.1);
  border: 1px solid var(--state-fail);
  border-left: 3px solid var(--state-fail);
  color: #ffb4b4;
  padding: 10px 12px;
  border-radius: 4px;
  margin-bottom: 14px;
  font-size: 13px;
}

.ca-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 60;
  display: flex; align-items: center; justify-content: center;
}
.ca-modal.hidden { display: none; }
.ca-modal-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px 28px;
  max-width: 520px;
  width: 92vw;
}
.ca-modal-inner h3 { margin: 0 0 12px; font-size: 17px; }
.ca-modal-inner p { font-size: 13px; line-height: 1.6; }

.audit-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  align-items: center;
}
.audit-row .audit-ts { color: var(--text-muted); font-size: 11px; }
.audit-row .audit-event { font-weight: 500; }
.audit-row.audit-login_succeeded { border-left: 2px solid var(--state-ok); padding-left: 8px; }
.audit-row.audit-login_failed,
.audit-row.audit-deleted { border-left: 2px solid var(--state-fail); padding-left: 8px; }
.audit-row.audit-rotated { border-left: 2px solid var(--accent); padding-left: 8px; }
.audit-row.audit-tested,
.audit-row.audit-created,
.audit-row.audit-set_primary { border-left: 2px solid var(--state-idle); padding-left: 8px; }

@media (max-width: 900px) {
  .ca-drawer { width: 100vw; border-left: none; }
  .settings-shell::after {
    content: "This page is best used on desktop.";
    display: block;
    margin-top: 16px;
    font-size: 12px;
    color: var(--state-attn);
  }
}

/* ---- Source toggle + Location meta ---- */
.source-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  padding: 4px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
}
.source-toggle-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  transition: background 100ms ease;
}
.source-toggle-option input[type="radio"] {
  appearance: none;
  width: 10px;
  height: 10px;
  border: 1px solid var(--border-light);
  border-radius: 50%;
  margin: 0;
}
.source-toggle-option input[type="radio"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.source-toggle-option:has(input:checked) {
  background: var(--bg-card);
  color: var(--text);
}
.source-block { margin-top: 10px; }
.source-block.hidden { display: none; }
.location-meta {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
  min-height: 0;
}
.location-meta:empty { display: none; }

/* ---- Secondary actions + facts summary ---- */
.pricing-secondary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}
.pricing-facts-summary {
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
}
.pricing-facts-summary.hidden { display: none; }
.scenario-badge {
  display: inline-block;
  background: rgba(245, 166, 35, 0.18);
  color: var(--warning);
  border: 1px solid rgba(245, 166, 35, 0.4);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  vertical-align: middle;
  margin-left: 8px;
}
.scenario-badge.hidden { display: none; }
#pricing-packet-link {
  color: var(--accent);
  cursor: pointer;
}
#pricing-packet-link.hidden { display: none; }

/* ---- Chat facts pill ---- */
.facts-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--accent-soft);
  border: 1px solid rgba(79, 140, 255, 0.3);
  border-radius: 6px;
  font-size: 12px;
  flex-wrap: wrap;
}
.facts-pill .facts-count {
  font-weight: 600;
  color: var(--accent);
}
.facts-pill .facts-fields {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.facts-pill .facts-link {
  font-weight: 500;
}

/* Admin tool-call inline pill — surfaces a Gemini function_call as it runs.
   Three states: running (animated dot), ok (moss), err (rose). args block
   appears only when the model passed non-empty arguments. Palette echoes the
   API Keys admin tab so the same operations look the same in both surfaces. */
.admin-tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 4px;
  padding: 6px 10px;
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 6px;
  background: rgba(184, 118, 31, 0.08);
  font-size: 12px;
  flex-wrap: wrap;
  max-width: 100%;
}
.admin-tool-pill__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #b8761f;
}
.admin-tool-pill--running .admin-tool-pill__dot {
  background: #b8761f;
  box-shadow: 0 0 0 0 rgba(184, 118, 31, 0.6);
  animation: admin-tool-pulse 1.2s infinite;
}
.admin-tool-pill--ok .admin-tool-pill__dot { background: #4a6b3a; }
.admin-tool-pill--err .admin-tool-pill__dot { background: #a83232; }
.admin-tool-pill__name {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text);
}
.admin-tool-pill__state {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.admin-tool-pill__args {
  flex-basis: 100%;
  margin: 4px 0 0;
  padding: 6px 8px;
  background: rgba(0,0,0,0.18);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-dim);
  max-height: 120px;
  overflow: auto;
}
@keyframes admin-tool-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(184, 118, 31, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(184, 118, 31, 0); }
  100% { box-shadow: 0 0 0 0 rgba(184, 118, 31, 0); }
}

/* ---- Rule authoring page ---- */
.rules-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
}
.rules-main {
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 32px;
}
.rules-textarea,
.rules-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 5px;
  font-family: inherit;
  font-size: 14px;
  box-sizing: border-box;
}
.rules-textarea:focus,
.rules-input:focus { border-color: var(--accent); }
/* Mouse-click focus: drop the global ring (the accent border already signals focus).
   Keyboard focus: keep the global ring via :focus-visible. */
.rules-textarea:focus:not(:focus-visible),
.rules-input:focus:not(:focus-visible) { outline: none; }
.rules-textarea:disabled,
.rules-input:disabled { opacity: 0.55; cursor: not-allowed; }
.rules-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.rules-candidate {
  margin-top: 28px;
  padding: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.rules-candidate.hidden { display: none; }
.rules-candidate-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.rules-json-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre;
  overflow-x: auto;
  color: #c5d7f0;
  min-height: 60px;
  margin-bottom: 12px;
}
.rules-warnings {
  background: rgba(245, 166, 35, 0.1);
  border: 1px solid rgba(245, 166, 35, 0.4);
  color: var(--warning);
  padding: 10px 12px;
  border-radius: 4px;
  margin: 12px 0;
  font-size: 12px;
}
.rules-warnings.hidden { display: none; }
.rules-warnings ul { margin: 6px 0 0 18px; }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}
.rules-active { margin-top: 28px; }
.rule-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 13px;
}
.rule-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.rule-card-body { margin-top: 8px; line-height: 1.7; }
.packet-meta-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-right: 6px;
}

/* ---- Indication Packet (print-first) ---- */
.packet-shell {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 0;
}
.packet-print-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.packet {
  background: white;
  color: #1a2230;
  border: 1px solid #d0d7e2;
  border-radius: 4px;
  padding: 36px 40px;
}
.packet-header {
  border-bottom: 2px solid #1a2230;
  padding-bottom: 14px;
  margin-bottom: 24px;
}
.packet-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: #1a2230;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.packet-brand .brand-mark {
  background: #1a2230;
  color: white;
  padding: 2px 6px;
  border-radius: 2px;
  font-size: 10px;
}
.packet-title {
  font-size: 26px;
  font-weight: 600;
  margin-top: 10px;
}
.packet-disclosure {
  background: #fff8e1;
  color: #8a5a00;
  border: 1px solid #d4a900;
  padding: 8px 12px;
  margin-top: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 12px;
  border-radius: 2px;
}
.packet-hero { margin-bottom: 28px; }
.packet-amount-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: flex-start;
}
.packet-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5f6e85;
  margin-bottom: 4px;
}
.packet-amount {
  font-size: 42px;
  font-weight: 600;
  color: #1a2230;
  font-variant-numeric: tabular-nums;
}
.packet-subtle {
  font-size: 12px;
  color: #5f6e85;
  margin-top: 4px;
}
.packet-meta-block {
  font-size: 12px;
  line-height: 1.8;
  color: #1a2230;
}
.packet-meta-block .mono { font-family: var(--mono); font-size: 11px; }
.packet-h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #5f6e85;
  margin: 24px 0 10px;
  border-top: 1px solid #d0d7e2;
  padding-top: 14px;
}
.packet-trace {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.packet-trace thead th {
  text-align: left;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #5f6e85;
  font-size: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid #1a2230;
}
.packet-trace th.num, .packet-trace td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.packet-trace tbody td {
  padding: 10px;
  border-bottom: 1px solid #e0e6ef;
  vertical-align: top;
}
.packet-trace .mono { font-family: var(--mono); color: #5f6e85; font-size: 10px; }
.packet-trace tr.fired { border-left: 3px solid #4f8cff; }
.packet-trace tr.not-fired { border-left: 3px solid #e0e6ef; opacity: 0.55; }
.packet-trace tbody tr td:first-child { padding-left: 10px; }
.packet-muted { color: #5f6e85; font-size: 11px; }
.packet-citation {
  font-size: 11px;
  margin-bottom: 4px;
}
.packet-excerpt {
  color: #5f6e85;
  font-style: italic;
  margin-top: 2px;
  font-size: 10px;
  line-height: 1.5;
}
.packet-missing {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  font-size: 12px;
}
.packet-missing li {
  padding: 8px 10px;
  background: #f5f7fa;
  border: 1px solid #d0d7e2;
  border-radius: 3px;
  margin-bottom: 6px;
}
.packet-footer {
  margin-top: 32px;
  padding-top: 14px;
  border-top: 2px solid #1a2230;
  font-size: 10px;
  color: #5f6e85;
  line-height: 1.6;
}

@media print {
  .no-print, .top-nav, .footer, .packet-print-controls { display: none !important; }
  body { background: white !important; color: black !important; }
  .container { max-width: none; padding: 0; }
  .packet-shell { padding: 0; margin: 0; max-width: none; }
  .packet {
    border: none;
    padding: 10px 20px;
    max-width: none;
  }
  .packet-header { page-break-after: avoid; }
  .packet-disclosure {
    position: running(disclaimer);
  }
  @page {
    margin: 20mm 18mm 25mm;
    @bottom-center {
      content: "INDICATION — NOT A QUOTE · non-binding · internal use only · page " counter(page);
      font-size: 9px;
      color: #8a5a00;
    }
  }
  .packet-trace tr { page-break-inside: avoid; }
  .packet-section, .packet-footer { page-break-inside: avoid; }
}

/* V2.2 domain-grouped grounding picker (chat sidebar). */
.ground-summary {
  font-size: 12px;
  margin: 6px 0 10px;
  padding: 6px 8px;
  border-radius: 4px;
}
.ground-summary.is-warn { background: #fef3c7; color: #92400e; }
.ground-summary.is-ok   { background: #d1fae5; color: #065f46; }

#v2-grounding-host { display: flex; flex-direction: column; gap: 6px; }
.ground-loading, .ground-err, .ground-empty {
  font-size: 12px; color: #64748b; padding: 6px 8px;
}
.ground-err { color: #991b1b; }

details.ground-group {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0;
}
details.ground-group > summary {
  cursor: pointer;
  padding: 8px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}
details.ground-group > summary::-webkit-details-marker { display: none; }
details.ground-group > summary::before {
  content: "▸";
  font-size: 10px;
  color: #94a3b8;
  transition: transform 0.1s;
}
details.ground-group[open] > summary::before { transform: rotate(90deg); }
.ground-label { font-weight: 600; color: #0f172a; }
.ground-hint { color: #64748b; font-size: 11px; flex: 1; }
.ground-badge {
  background: #e2e8f0;
  color: #475569;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}
.ground-badge.is-active { background: #2563eb; color: #fff; }

.ground-list {
  padding: 4px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
label.ground-row {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
label.ground-row:hover { background: #e2e8f0; }
label.ground-row input { grid-row: 1 / span 2; align-self: center; }
label.ground-row span { grid-column: 2; color: #0f172a; }
label.ground-row small { grid-column: 2; color: #64748b; font-size: 10px; }

/* ========================================================================
   V2.7 chat — mobile-responsive overhaul (2026-05-06)
   ========================================================================

   Targets the laundry list of mobile bugs that "the mobile version sucks"
   shorthanded:

   1. iOS auto-zooms when you focus an input with font-size < 16px.
      Composer textarea was 15px. Bump to 16px on touch screens.
   2. `100vh` lies on iOS Safari — it doesn't account for the dynamic URL
      bar OR the keyboard. We use `100dvh` with a JS fallback to a CSS
      var (`--chat-h`) that chat2.js updates from window.visualViewport.
      That keeps the composer visible even with the keyboard up.
   3. The sidebar drawer slides in but has no scrim — desktop muscle
      memory, looks broken on phone. Add a tappable backdrop layer.
   4. Header was four desktop-sized controls competing for a 360px row.
      At ≤480px we shrink the model select to icon-only, the Sources
      label hides (count badge stays), and the title gets clipped
      gracefully.
   5. Touch targets — iOS HIG says 44pt min, Material 48dp. Composer +
      header buttons were ~26px. Bump to 40-44px on touch screens.
   6. Composer pills (Attach / Voice / Web / Code / status / Cmd-Enter
      hint / Send) wrap to a multi-row layout with horizontal-scrolling
      tool pills on small screens. Hint text hides on mobile (the
      keyboard shortcut is desktop-only anyway).
   7. Sources popover was a top-floating modal — replaced with a
      bottom-sheet pattern at ≤640px (slides up from bottom, full
      width, rounded top corners, max-height 88dvh).
   8. Safe-area insets — composer respects env(safe-area-inset-bottom)
      so the iPhone home indicator doesn't overlap the send button.
   9. The body scroll-lock that already existed for the popover gets
      extended to "sidebar open" too, preventing the page itself from
      scrolling behind the drawer. */

/* Touch-device baseline — 16px font-size on textarea kills iOS auto-zoom.
 * Scoped to coarse pointers so desktop keeps the tighter 15px. */
@media (hover: none) and (pointer: coarse) {
  .chat2__composer textarea {
    font-size: 16px;
  }
}

/* Dynamic viewport for the chat shell. Falls back gracefully:
 *   - Modern browsers honor 100dvh directly.
 *   - chat2.js sets `--chat-h` from window.visualViewport.height when the
 *     keyboard opens or the URL bar slides; that wins via specificity.
 *   - Old browsers ignore dvh and fall back to the existing 100vh rule. */
.chat2 {
  height: var(--chat-h, calc(100dvh - 60px));
}

/* ── ≤800px: tablet / small laptop ─────────────────────────────────── */
@media (max-width: 800px) {
  /* Backdrop scrim under the slide-in sidebar — invisible until the
   * shell flips to .is-open. Tap dismisses (chat2.js wires this). */
  .chat2::before {
    content: "";
    position: fixed;
    inset: 60px 0 0 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 49;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
  }
  .chat2.is-open::before {
    opacity: 1;
    pointer-events: auto;
  }

  /* Lock body scroll while the sidebar drawer is open so the page
   * doesn't tug behind the scrim. Mirrors the popover lock pattern. */
  body.chat2-sidebar-open { overflow: hidden; }

  /* Sidebar already slides in from the left. Bump its z-index above the
   * scrim and give it the same dvh-aware sizing so it doesn't overflow
   * the URL bar / keyboard area. */
  .chat2__sidebar {
    z-index: 50;
    height: var(--chat-h, calc(100dvh - 60px));
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
  }

  /* Composer surfaces (welcome + messages) get more horizontal real
   * estate on small screens — drop the desktop centering padding. */
  .chat2__convo { padding-left: 12px; padding-right: 12px; }
  .chat2__welcome { padding: 32px 4px; }
  .chat2__welcome h1 { font-size: 22px; line-height: 1.2; }
  .chat2__welcome p { font-size: 14px; }

  /* Welcome chips: keep flex-wrap but cap chip width so a single long
   * chip doesn't blow the layout out. */
  .chat2__chips { gap: 6px; }
  .chat2__chip {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
    font-size: 13px;
    padding: 10px 12px;
    text-align: left;
  }

  /* Message bubbles widen toward the screen edges on phones. Keep
   * alternating alignment but let user msgs go to 92% on mobile. */
  .chat2__convo .user-msg { max-width: 92%; }
  .chat2__convo .assistant-msg { max-width: 100%; }
}

/* ── ≤480px: phone portrait ────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Header: shrink the gap, push title to ellipsis-fast, and make
   * everything tappable. */
  .chat2__header {
    padding: 8px 10px;
    gap: 6px;
  }
  .chat2__header-name {
    font-size: 13px;
  }

  /* Touch targets: 40px+ height on the small interactive controls. */
  .chat2__icon-btn,
  .chat2__sidebar-toggle {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  /* Model select: collapse to a tight pill, single-letter visual on
   * narrow screens. The full label still works because it's a real
   * <select> — the dropdown shows the full options when tapped. */
  .chat2__model {
    padding: 8px 10px;
    height: 40px;
    font-size: 13px;
    /* Cap width so "Gemini 2.5 Pro" doesn't dominate the row. */
    max-width: 110px;
    text-overflow: ellipsis;
  }

  /* Sources button: icon-only on phone, count badge stays visible.
   * The text label is purely decorative; the icon + badge convey
   * everything users need to know. */
  .chat2__sources-btn {
    height: 40px;
    padding: 0 10px;
    gap: 4px;
  }
  .chat2__sources-btn > span:not(.chat2__sources-count) {
    /* Hide the "Sources" word; keep the count badge. */
    display: none;
  }

  /* Composer: bigger tap-targets for every button, allow tool pills
   * to wrap to a second row, and surface the safe-area inset so the
   * send button doesn't kiss the iPhone home indicator. */
  .chat2__composer-wrap {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }
  .chat2__composer {
    padding: 10px 12px;
  }
  .chat2__composer textarea {
    /* Reinforced from the touch-device baseline above for old browsers
     * that don't honor (hover: none) media query reliably. */
    font-size: 16px;
    min-height: 28px;
  }

  /* Composer bar wraps; left actions become a horizontally-scrolling
   * row of pills if they overflow, right actions (send) stay pinned. */
  .chat2__composer-bar {
    flex-wrap: wrap;
    gap: 6px;
  }
  .chat2__composer-actions {
    flex: 1 1 100%;
    order: 2;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Hide scrollbar visual but keep the scroll behavior. */
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .chat2__composer-actions::-webkit-scrollbar { display: none; }

  .chat2__composer-right {
    order: 1;
    flex: 0 0 auto;
    margin-left: auto;
  }

  /* Buttons inside the composer-actions row: bigger, no-shrink so the
   * row scrolls instead of squashing them. */
  .chat2__composer-actions > .chat2__icon-btn {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
  }
  .chat2__tool-pill {
    height: 36px;
    padding: 0 12px;
    flex: 0 0 auto;
    font-size: 13px;
  }
  .chat2__send {
    width: 44px;
    height: 44px;
  }

  /* Cmd-Enter hint is desktop muscle memory — useless on phone. */
  .chat2__hint--composer { display: none; }

  /* Grounding status text: hide on the narrowest phones — the count
   * badge on the Sources button conveys the same info. */
  .chat2__grounding-status { display: none; }

  /* Welcome chips become single column for max readability. */
  .chat2__chips { grid-template-columns: 1fr; }
  .chat2__chip { flex-basis: 100%; }
}

/* ── Bottom-sheet popover at ≤640px ────────────────────────────────── */
@media (max-width: 640px) {
  .chat2__popover {
    /* Anchor to bottom; slide up. */
    align-items: flex-end;
    padding: 0;
  }
  .chat2__popover-card {
    width: 100%;
    max-width: 100%;
    max-height: 88dvh;
    border-radius: 16px 16px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    /* Reserve room for the iPhone home indicator. */
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    /* Slide-up animation — wins over the top-fade keyframe via cascade
     * order (this rule comes later in the stylesheet). */
    animation: chat2-popover-slideup .2s cubic-bezier(0.32, 0.72, 0, 1);
  }
  @keyframes chat2-popover-slideup {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
}

/* ── Top nav mobile fixes (carries through to chat) ──────────────── */
@media (max-width: 600px) {
  /* When the chat shell is mounted, the nav is the only horizontal
   * non-chat surface — make sure it doesn't wrap into a multi-row
   * monster that pushes the chat down. The 60px height the chat shell
   * subtracts assumes a single-row nav. */
  body:has(.chat2) .nav-links {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  body:has(.chat2) .nav-links::-webkit-scrollbar { display: none; }
  body:has(.chat2) .nav-links a {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}
