/* ==========================================================================
   Seefa ERP Assistant — visual system

   Built on Apple's interface principles: translucent material for chrome,
   springs for anything the user can touch, feedback on pointer-down, and
   size-specific typography. Reduced-motion / transparency / contrast are
   first-class, not afterthoughts.
   ========================================================================== */

/* ---------------------------------------------------------------------------
   PALETTE — "Apple Modern"

     #F5F5F7  mist      page background      (light)
     #1D1D1F  graphite  primary text         (light) / page background (dark)
     #AAAAAA  silver    tertiary text, fills
     #007AFF  azure     the single accent

   Four colours only. Everything else is one of these at an opacity, which is
   what keeps it feeling like one system rather than a collection of screens.
   Semantic colours (success/warning/danger) are kept but used sparingly —
   restraint is the point.

   THEME SWITCHING
     :root                        light by default
     @media (prefers-color-scheme: dark) + :root:not([data-theme="light"])
                                  follow the OS unless the user overrode it
     :root[data-theme="dark"]     explicit user choice, wins over the OS
   The guard on the media query is what lets a manual "light" choice survive
   on a machine set to dark.
--------------------------------------------------------------------------- */

:root {
  /* Type scale — tracking is size-specific; one letter-spacing is wrong somewhere */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable",
          "Segoe UI", system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "Cascadia Code", Consolas, monospace;

  /* --- palette primitives --- */
  --mist:     #F5F5F7;
  --graphite: #1D1D1F;
  --silver:   #AAAAAA;
  --azure:    #007AFF;

  /* Surfaces */
  --bg:            var(--mist);
  --bg-elevated:   #FFFFFF;
  --material:      rgba(255, 255, 255, 0.72);
  --material-edge: rgba(255, 255, 255, 0.55);
  --scrim:         rgba(29, 29, 31, 0.28);

  /* Content — vibrancy: never flat grey over translucent surfaces */
  --text:           var(--graphite);
  --text-secondary: #55555A;
  --text-tertiary:  #86868B;

  --separator:   rgba(29, 29, 31, 0.09);
  --fill:        rgba(170, 170, 170, 0.18);
  --fill-strong: rgba(170, 170, 170, 0.32);

  --accent:       var(--azure);
  --accent-hover: #0A84FF;
  --on-accent:    #FFFFFF;

  --success: #1D8A4E;
  --warning: #B25000;
  --danger:  #D1293D;

  --radius-sm: 10px;
  --radius:    16px;
  --radius-lg: 22px;
  --radius-xl: 30px;

  /* Bigger surfaces read as thicker: stronger blur, deeper shadow */
  --shadow-sm: 0 1px 2px rgba(29,29,31,.05), 0 1px 1px rgba(29,29,31,.03);
  --shadow:    0 4px 16px rgba(29,29,31,.07), 0 1px 3px rgba(29,29,31,.04);
  --shadow-lg: 0 14px 44px rgba(29,29,31,.11), 0 2px 8px rgba(29,29,31,.05);

  /* Springs. Critically damped by default; bounce only after momentum. */
  --spring:        cubic-bezier(0.32, 0.72, 0, 1);
  --spring-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 140ms;
  --dur:      280ms;
  --dur-slow: 420ms;

  color-scheme: light dark;
}

/* Dark tokens, shared by the OS preference and the explicit override. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #000000;
    --bg-elevated:   var(--graphite);
    --material:      rgba(29, 29, 31, 0.72);
    --material-edge: rgba(245, 245, 247, 0.10);
    --scrim:         rgba(0, 0, 0, 0.55);

    --text:           var(--mist);
    --text-secondary: #C6C6CB;
    --text-tertiary:  var(--silver);

    --separator:   rgba(245, 245, 247, 0.12);
    --fill:        rgba(170, 170, 170, 0.16);
    --fill-strong: rgba(170, 170, 170, 0.28);

    --accent:       #0A84FF;
    --accent-hover: #3D9BFF;

    --success: #30D158;
    --warning: #FF9F0A;
    --danger:  #FF453A;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
    --shadow:    0 4px 16px rgba(0,0,0,.55);
    --shadow-lg: 0 14px 44px rgba(0,0,0,.65);
  }
}

:root[data-theme="dark"] {
  --bg:            #000000;
  --bg-elevated:   var(--graphite);
  --material:      rgba(29, 29, 31, 0.72);
  --material-edge: rgba(245, 245, 247, 0.10);
  --scrim:         rgba(0, 0, 0, 0.55);

  --text:           var(--mist);
  --text-secondary: #C6C6CB;
  --text-tertiary:  var(--silver);

  --separator:   rgba(245, 245, 247, 0.12);
  --fill:        rgba(170, 170, 170, 0.16);
  --fill-strong: rgba(170, 170, 170, 0.28);

  --accent:       #0A84FF;
  --accent-hover: #3D9BFF;

  --success: #30D158;
  --warning: #FF9F0A;
  --danger:  #FF453A;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
  --shadow:    0 4px 16px rgba(0,0,0,.55);
  --shadow-lg: 0 14px 44px rgba(0,0,0,.65);
}

/* ------------------------------ theme toggle ------------------------------
   Sun and moon cross-fade and rotate through each other rather than swapping,
   so the control reads as one object changing state, not two icons.
--------------------------------------------------------------------------- */
.theme-toggle { position: relative; overflow: hidden; }
.theme-toggle svg {
  position: absolute;
  transition: opacity var(--dur) var(--spring),
              transform var(--dur) var(--spring);
}
.theme-toggle .icon-sun  { opacity: 0; transform: rotate(-90deg) scale(.5); }
.theme-toggle .icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { opacity: 1; transform: rotate(0deg) scale(1); }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(.5); }
}
:root[data-theme="dark"] .theme-toggle .icon-sun  { opacity: 1; transform: rotate(0deg) scale(1); }
:root[data-theme="dark"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(.5); }

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  /* Body: comfortable leading, tracking near zero */
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ============================ Chrome: translucent material ================ */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--material);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  /* A bright top edge reads as light catching a real material */
  border-bottom: 1px solid var(--separator);
}

.app-bar h1 {
  /* Large text wants negative tracking and tight leading */
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.022em;
  line-height: 1.2;
}

.app-bar .spacer { flex: 1; }

.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 18%, transparent);
  flex: none;
}
.brand-dot[data-state="degraded"] { background: var(--warning);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 18%, transparent); }
.brand-dot[data-state="down"] { background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }

.provider-chip {
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;           /* small text: slightly positive, never negative */
  color: var(--text-secondary);
  background: var(--fill);
  padding: 5px 10px;
  border-radius: 100px;
  font-variant-numeric: tabular-nums;
}

/* ================================ Conversation ============================ */
.thread {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 20px 200px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg { display: flex; flex-direction: column; gap: 8px; }
.msg[data-role="user"] { align-items: flex-end; }

/* Enter along the path it will leave by — spatial consistency */
.msg { animation: msg-in var(--dur) var(--spring) both; }
@keyframes msg-in {
  from { opacity: 0; transform: translateY(12px) scale(0.99); }
  to   { opacity: 1; transform: none; }
}

.bubble {
  max-width: 100%;
  padding: 13px 17px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--separator);
  overflow-wrap: anywhere;
}

.msg[data-role="user"] .bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-color: transparent;
  border-bottom-right-radius: var(--radius-sm);
}

.msg[data-role="assistant"] .bubble { border-bottom-left-radius: var(--radius-sm); }

.msg-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  display: flex; align-items: center; gap: 8px;
  font-variant-numeric: tabular-nums;
}

/* ---- answer internals ---- */
.answer-value {
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.03em;   /* large text: tighten */
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}

.answer-label { font-size: 13px; color: var(--text-secondary); }

table.result {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
}
table.result th {
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 7px 10px;
  border-bottom: 1px solid var(--separator);
  position: sticky; top: 0;
  background: var(--bg-elevated);
}
table.result td { padding: 7px 10px; border-bottom: 1px solid var(--separator); }
table.result tr:last-child td { border-bottom: none; }
table.result td.num { text-align: right; }
.table-scroll { max-height: 340px; overflow: auto; border-radius: var(--radius-sm); }

/* ---- SQL provenance: every answer can be audited ---- */
details.sql-disclosure { margin-top: 12px; }
details.sql-disclosure summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 11px;
  background: var(--fill);
  border-radius: 100px;
  display: inline-flex; align-items: center; gap: 6px;
  list-style: none;
  user-select: none;
  transition: background var(--dur-fast) ease-out, transform var(--dur-fast) ease-out;
}
details.sql-disclosure summary::-webkit-details-marker { display: none; }
details.sql-disclosure summary:hover { background: var(--fill-strong); }
details.sql-disclosure summary:active { transform: scale(0.97); }
details.sql-disclosure pre {
  margin-top: 10px;
  padding: 13px 15px;
  background: var(--fill);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  overflow-x: auto;
  white-space: pre;
}

.caveat {
  margin-top: 10px; padding: 9px 13px;
  background: color-mix(in srgb, var(--warning) 10%, transparent);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text-secondary);
}

.chart-holder { margin-top: 14px; height: 260px; position: relative; }

/* ================================ Composer ================================ */
.composer-dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--material);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-top: 1px solid var(--separator);
}

/* Scroll edge effect: fade where content meets floating chrome,
   rather than a hard 1px divider */
.composer-dock::before {
  content: "";
  position: absolute; left: 0; right: 0; top: -28px; height: 28px;
  background: linear-gradient(to top, var(--bg), transparent);
  pointer-events: none;
}

.composer {
  max-width: 820px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius-xl);
  padding: 7px 7px 7px 18px;
  box-shadow: var(--shadow);
  transition: border-color var(--dur) var(--spring),
              box-shadow var(--dur) var(--spring);
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: var(--shadow-lg),
              0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent);
}

.composer textarea {
  flex: 1;
  border: none; outline: none; resize: none; background: none;
  font-family: inherit; font-size: 15px; line-height: 1.45;
  color: var(--text);
  max-height: 160px; padding: 9px 0;
}
.composer textarea::placeholder { color: var(--text-tertiary); }

/* ---- buttons: feedback on pointer-DOWN, never on release ---- */
.btn-icon {
  flex: none;
  width: 38px; height: 38px;
  border: none; border-radius: 50%;
  background: var(--fill);
  color: var(--text-secondary);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background var(--dur-fast) ease-out,
              transform var(--dur-fast) ease-out,
              color var(--dur-fast) ease-out;
}
.btn-icon:hover { background: var(--fill-strong); }
.btn-icon:active { transform: scale(0.92); }   /* instant, on press */
.btn-icon:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-icon svg { width: 19px; height: 19px; }

.btn-send { background: var(--accent); color: var(--on-accent); }
.btn-send:hover { background: var(--accent-hover); }

.btn-mic[data-recording="true"] {
  background: var(--danger); color: var(--on-accent);
  animation: mic-pulse 1.6s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); }
  50%      { box-shadow: 0 0 0 9px color-mix(in srgb, var(--danger) 0%, transparent); }
}

/* ======================= Voice: live transcript review ==================== */
/* Speech is a draft, never an action. It must be reviewable before it commits. */
.voice-panel {
  max-width: 820px; margin: 0 auto 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  /* Materialize: blur + scale together, so it reads as a real surface arriving */
  animation: voice-in var(--dur) var(--spring) both;
}
@keyframes voice-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: blur(0); }
}
.voice-panel[hidden] { display: none; }

.voice-head {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 15px;
  border-bottom: 1px solid var(--separator);
  font-size: 12px; font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em; text-transform: uppercase;
}

.voice-body { padding: 13px 15px; font-size: 15px; line-height: 1.45; min-height: 46px; }
.voice-body .interim { color: var(--text-tertiary); }  /* not yet final */

.voice-actions {
  display: flex; gap: 8px; padding: 0 15px 13px; flex-wrap: wrap;
}
.btn-text {
  border: 1px solid var(--separator);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 15px; border-radius: 100px; cursor: pointer;
  transition: background var(--dur-fast) ease-out, transform var(--dur-fast) ease-out;
}
.btn-text:hover { background: var(--fill); }
.btn-text:active { transform: scale(0.96); }
.btn-text.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn-text.primary:hover { background: var(--accent-hover); }
.btn-text.quiet { color: var(--text-secondary); }

/* Level meter — continuous feedback during the interaction, not just at the end */
.level-meter { display: flex; align-items: center; gap: 3px; height: 15px; }
.level-meter span {
  width: 3px; border-radius: 2px; background: var(--danger);
  height: 20%;
  transition: height 90ms ease-out;   /* tracks the mic 1:1 */
}

/* ================================ Misc ==================================== */
.thinking { display: inline-flex; gap: 4px; align-items: center; padding: 3px 0; }
.thinking i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-tertiary);
  animation: blink 1.3s ease-in-out infinite;
}
.thinking i:nth-child(2) { animation-delay: 0.16s; }
.thinking i:nth-child(3) { animation-delay: 0.32s; }
@keyframes blink { 0%,80%,100% { opacity:.25; transform:scale(.8);} 40% {opacity:1; transform:scale(1);} }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.suggestion {
  border: 1px solid var(--separator);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font: inherit; font-size: 13px;
  padding: 9px 15px; border-radius: 100px; cursor: pointer; text-align: left;
  transition: background var(--dur-fast) ease-out,
              transform var(--dur-fast) ease-out,
              color var(--dur-fast) ease-out;
}
.suggestion:hover { background: var(--fill); color: var(--text); }
.suggestion:active { transform: scale(0.97); }

.empty-state { text-align: center; padding: 56px 20px 24px; }
.empty-state h2 {
  font-size: 27px; font-weight: 650; letter-spacing: -0.028em;
  line-height: 1.15; margin-bottom: 9px;
}
.empty-state p { color: var(--text-secondary); max-width: 460px; margin: 0 auto; }

.toast {
  position: fixed; left: 50%; bottom: 108px; transform: translateX(-50%);
  z-index: 80; max-width: 460px;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px 17px; font-size: 14px;
  animation: toast-in var(--dur) var(--spring-bounce) both;  /* momentum: slight bounce */
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
.toast[data-kind="error"] { border-left: 3px solid var(--danger); }

/* ====================== Accessibility: three signals ====================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* Reduced motion means a gentler equivalent, not no feedback */
  .msg, .voice-panel, .toast { animation: fade-only 180ms ease both; }
  @keyframes fade-only { from { opacity: 0; } to { opacity: 1; } }
  .btn-icon:active, .btn-text:active, .suggestion:active { transform: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .app-bar, .composer-dock {
    background: var(--bg-elevated);
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  :root { --separator: rgba(0,0,0,0.45); --text-secondary: var(--text); }
  .bubble, .composer, .voice-panel { border-width: 2px; }
}

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Layout scales with the user's text size: spacing in rem/em, not fixed px */
@media (max-width: 640px) {
  .thread { padding: 16px 14px 190px; }
  .composer-dock { padding: 11px 14px calc(11px + env(safe-area-inset-bottom)); }
  .answer-value { font-size: 25px; }
  .empty-state h2 { font-size: 23px; }
}

/* ==========================================================================
   SIGN IN

   70 / 30 split: a night-sky scene on the left, where login-car.js shows an
   anime-style sports car that breaks down into its parts and rebuilds, and
   a compact form on the right. The scene is decoration only (aria-hidden);
   every motion stops under prefers-reduced-motion.
   ========================================================================== */

.auth-page {
  --bp-bg-1: #0b1424;            /* blueprint navy, same in both themes */
  --bp-bg-2: #0f1f38;
  --bp-line: #6ea8ff;
  --bp-line-soft: rgba(110, 168, 255, .16);
  --bp-ink: #e8f0ff;
  --bp-ink-dim: #9fb4d6;
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
}
/* 70 / 30: the scene is the page; the form needs only a column. The form
   column never drops below what the card needs, nor grows past it. */
.auth-shell { display: grid; grid-template-columns: minmax(0, 1fr) clamp(400px, 30%, 520px); min-height: 100vh; }

/* ---- brand panel -------------------------------------------------------- */
.auth-visual {
  position: relative; overflow: hidden; isolation: isolate;
  /* Night sky: a spotlight glow behind the car, a warm city haze on the
     horizon, then the blueprint navy. */
  background:
    radial-gradient(ellipse 62% 40% at 50% 34%, rgba(72, 132, 255, .30), transparent 70%),
    radial-gradient(ellipse 90% 30% at 50% 48%, rgba(255, 140, 70, .07), transparent 70%),
    linear-gradient(180deg, #091224 0%, var(--bp-bg-2) 45%, var(--bp-bg-1) 100%);
  color: var(--bp-ink);
}
/* The 3D car (login-car.js) fades in over the night sky once it is ready.
   Until then, and without WebGL (`no-3d`), the sky alone is the panel. */
.auth-3d, .auth-3d-labels {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1;
  opacity: 0; transition: opacity 1s ease; pointer-events: none;
}
.auth-visual.is-3d .auth-3d, .auth-visual.is-3d .auth-3d-labels { opacity: 1; }

.auth-visual-copy {
  position: relative; display: flex; flex-direction: column; justify-content: space-between;
  height: 100%; box-sizing: border-box; padding: 40px 48px 52px;
  background: linear-gradient(to top, rgba(11, 20, 36, .92) 0%, rgba(11, 20, 36, .55) 30%, transparent 58%);
}
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; letter-spacing: -.01em;
  text-shadow: 0 1px 10px rgba(4, 10, 24, .85); }
.auth-logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--accent); color: #fff; box-shadow: 0 6px 18px rgba(0, 122, 255, .35);
}
.auth-logo svg { width: 19px; height: 19px; }
.auth-headline {
  margin: auto 0 0; font-size: clamp(28px, 3vw, 40px); line-height: 1.12; font-weight: 700;
  letter-spacing: -.025em;
}
/* entrance */
.auth-headline, .auth-brand { animation: rise .7s cubic-bezier(.2, .8, .2, 1) both; }
.auth-headline { animation-delay: .12s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---- form panel --------------------------------------------------------- */
.auth-panel { position: relative; display: grid; place-items: center; padding: 48px 32px; border-left: 1px solid var(--separator, rgba(0,0,0,.08)); }
.auth-theme { position: absolute; top: 18px; right: 18px; z-index: 2; }
.auth-card { width: 100%; max-width: 380px; animation: rise .6s cubic-bezier(.2, .8, .2, 1) .05s both; }
.auth-mobile-brand { display: none; }
.auth-card h1 { margin: 0 0 6px; font-size: 30px; font-weight: 700; letter-spacing: -.025em; }
.auth-sub { margin: 0 0 28px; color: var(--text-secondary); font-size: 15px; line-height: 1.5; }

.auth-field { margin-bottom: 16px; }
.auth-field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text); }
.auth-input-wrap { position: relative; display: flex; align-items: center; }
.auth-input-wrap > svg {
  position: absolute; left: 14px; width: 17px; height: 17px; color: var(--text-tertiary);
  pointer-events: none; transition: color .15s ease;
}
.auth-input-wrap:focus-within > svg { color: var(--accent); }
.auth-card input[type="text"], .auth-card input[type="password"] {
  width: 100%; height: 48px; box-sizing: border-box; padding: 0 44px 0 42px;
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--bg-elevated); border: 1px solid var(--fill-strong); border-radius: 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.auth-card input::placeholder { color: var(--text-tertiary); }
.auth-card input:hover { border-color: var(--text-tertiary); }
.auth-card input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.auth-reveal {
  position: absolute; right: 6px; width: 36px; height: 36px; border: none; border-radius: 9px;
  background: transparent; color: var(--text-tertiary); cursor: pointer; display: grid; place-items: center;
}
.auth-reveal:hover { color: var(--text); background: var(--fill); }
.auth-reveal:active { transform: scale(.9); }
.auth-reveal svg { width: 17px; height: 17px; }

.auth-submit {
  position: relative; width: 100%; height: 50px; margin-top: 10px; border: none; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font: inherit; font-size: 15.5px; font-weight: 600; color: #fff; cursor: pointer;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff), var(--accent));
  box-shadow: 0 8px 22px -8px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: transform .15s ease, box-shadow .2s ease, filter .15s ease;
}
.auth-submit:hover { filter: brightness(1.06); box-shadow: 0 12px 26px -8px color-mix(in srgb, var(--accent) 80%, transparent); }
.auth-submit:active { transform: scale(.985); }
.auth-arrow { width: 18px; height: 18px; transition: transform .2s ease; }
.auth-submit:hover .auth-arrow { transform: translateX(3px); }
.auth-submit[data-busy="true"] { pointer-events: none; opacity: .8; }
.auth-submit[data-busy="true"] .auth-arrow { display: none; }
.auth-spinner {
  display: none; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff; animation: spin .8s linear infinite;
}
.auth-submit[data-busy="true"] .auth-spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-error {
  display: flex; gap: 10px; align-items: flex-start; margin: 0 0 20px; padding: 12px 14px;
  border-radius: 12px; font-size: 14px; line-height: 1.45;
  color: var(--text); background: color-mix(in srgb, var(--danger) 10%, var(--bg-elevated));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  animation: auth-shake .4s cubic-bezier(.36, .07, .19, .97) both;
}
.auth-error svg { width: 18px; height: 18px; color: var(--danger); flex: none; margin-top: 1px; }
@keyframes auth-shake {
  10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); }
}


/* ---- smaller screens: the blueprint becomes a header band --------------- */
@media (max-width: 900px) {
  .auth-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .auth-visual { height: 230px; }
  .auth-visual-copy { padding: 22px 24px; }
  .auth-headline { font-size: 25px; margin-bottom: 0; }
  .auth-panel { place-items: start center; padding: 32px 20px 40px; }
  .auth-theme { top: 12px; right: 12px; position: fixed; }
}
@media (max-width: 480px) {
  .auth-visual { height: 190px; }
  .auth-card h1 { font-size: 26px; }
  .auth-visual-copy .auth-brand { font-size: 15px; }
}

/* ---- motion & transparency preferences ---------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .auth-headline, .auth-brand, .auth-card { animation: fade-only .2s ease both; }
  .auth-error { animation: none; }
  .auth-spinner { animation-duration: 1.6s; }
}
@keyframes fade-only { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================================================
   INSIGHTS & FORECAST
   ========================================================================== */

.insight {
  border: 1px solid var(--separator);
  border-left: 3px solid var(--text-tertiary);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  margin-top: 10px;
  background: var(--bg-elevated);
}
.insight[data-severity="critical"] { border-left-color: var(--danger); }
.insight[data-severity="warning"]  { border-left-color: var(--warning); }
.insight[data-severity="info"]     { border-left-color: var(--accent); }

.insight-head {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 7px;
}
.insight-title { font-size: 14.5px; font-weight: 600; letter-spacing: -0.012em; }
.insight-badge {
  font-size: 10.5px; font-weight: 650;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 100px;
  background: var(--fill); color: var(--text-secondary);
}
.insight[data-severity="critical"] .insight-badge {
  background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.insight[data-severity="warning"] .insight-badge {
  background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.insight[data-severity="info"] .insight-badge {
  background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); }

.insight-finding { font-size: 14px; line-height: 1.5; }
.insight-action {
  font-size: 13.5px; line-height: 1.5;
  color: var(--text-secondary);
  margin-top: 7px; padding-left: 13px;
  border-left: 2px solid var(--separator);
}
.insight-basis {
  font-size: 11.5px; color: var(--text-tertiary);
  margin-top: 9px; font-style: italic;
}

/* Forecast block — the range is the answer, so it is given equal weight to
   the midpoint rather than shown as a footnote. */
.forecast-box {
  margin-top: 12px; padding: 13px 15px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
}
.forecast-head {
  font-size: 11.5px; font-weight: 640;
  letter-spacing: 0.045em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 9px;
  display: flex; align-items: center; gap: 6px;
}
.forecast-head svg { width: 13px; height: 13px; }

.forecast-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 5px 0;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--separator);
}
.forecast-row:last-of-type { border-bottom: none; }
.forecast-period { font-size: 12.5px; color: var(--text-secondary); min-width: 68px; }
.forecast-value  { font-size: 15px; font-weight: 600; }
.forecast-range  { font-size: 12px; color: var(--text-tertiary); margin-left: auto; }

.forecast-method {
  font-size: 11.5px; color: var(--text-tertiary);
  margin-top: 9px; padding-top: 8px;
  border-top: 1px solid var(--separator);
  line-height: 1.45;
}

.trend-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 550;
  padding: 4px 10px; border-radius: 100px;
  background: var(--fill); color: var(--text-secondary);
  margin-top: 9px;
}
.trend-pill svg { width: 12px; height: 12px; }
.trend-pill[data-dir="rising"]  { color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent); }
.trend-pill[data-dir="falling"] { color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ==========================================================================
   PROGRESS, SKELETON, MODEL PANEL

   Apple: feedback must be continuous DURING the interaction, not only at the
   end. A spinner says "wait"; a stage says "here is what is happening, and it
   is going fine". The difference matters most exactly when things are slow.
   ========================================================================== */

.progress {
  display: flex; align-items: center; gap: 11px;
  min-height: 24px;
}
.progress-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); flex: none;
  animation: pulse-dot 1.4s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: .35; transform: scale(.8); }
  50%      { opacity: 1;   transform: scale(1.15); }
}

/* The stage label cross-fades and slides a little, so successive stages read
   as one thing progressing rather than text being replaced. */
.progress-text {
  font-size: 14px; color: var(--text-secondary);
  animation: stage-in 260ms var(--spring) both;
}
@keyframes stage-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: none; }
}

.progress-elapsed {
  margin-left: auto; font-size: 11.5px; color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* Trail of completed stages — reassurance that work is accumulating. */
.progress-trail {
  display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px;
}
.progress-trail span {
  font-size: 11px; color: var(--text-tertiary);
  background: var(--fill); padding: 2px 8px; border-radius: 100px;
  animation: stage-in 220ms var(--spring) both;
}

/* ---- skeleton: only appears once the query is actually running ---- */
.skeleton { margin-top: 12px; }
.skeleton-row {
  height: 13px; border-radius: 5px; margin-bottom: 9px;
  background: linear-gradient(90deg,
              var(--fill) 25%, var(--fill-strong) 37%, var(--fill) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
.skeleton-row:nth-child(1) { width: 92%; }
.skeleton-row:nth-child(2) { width: 78%; animation-delay: .1s; }
.skeleton-row:nth-child(3) { width: 85%; animation-delay: .2s; }
.skeleton-row:nth-child(4) { width: 64%; animation-delay: .3s; }
@keyframes shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ---- word-by-word reveal ---- */
.reveal-word {
  opacity: 0;
  animation: word-in 300ms var(--spring) forwards;
}
@keyframes word-in {
  from { opacity: 0; filter: blur(3px); }
  to   { opacity: 1; filter: blur(0); }
}

/* ============================== model panel ============================== */
/* An invisible scrim: it exists only to catch the click that dismisses the
   popover. Dimming would be wrong here — this is a parallel, non-blocking
   panel, not a modal task, so the flow behind it should stay legible. */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: transparent;
}

/* Anchored popover, NOT a centred modal.
   It originates from the button that opened it, so the spatial relationship
   between control and content is obvious: it scales out of the trigger and
   collapses back into it. Position is set in JS from the button's rect. */
.sheet {
  position: fixed; z-index: 91;
  width: min(430px, calc(100vw - 28px));
  max-height: min(72vh, 620px);
  overflow-y: auto;
  background: var(--material);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  border: 1px solid var(--material-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 18px;
  /* Origin is overridden in JS to point at the trigger. */
  transform-origin: top right;
  animation: popover-in 240ms var(--spring) both;
}

@keyframes popover-in {
  from { opacity: 0; transform: scale(.94) translateY(-6px); filter: blur(5px); }
  to   { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}

/* A small notch tying the panel to its button. */
.sheet::before {
  content: "";
  position: absolute;
  left: var(--notch-x, 24px);
  width: 12px; height: 12px;
  background: var(--material);
  border-left: 1px solid var(--material-edge);
  border-top: 1px solid var(--material-edge);
  transform: rotate(45deg);
  border-radius: 2px 0 0 0;
}
.sheet[data-above="false"]::before { top: -7px; }
/* When the panel flips above the trigger the notch must flip too, or it
   points away from the button it belongs to. */
.sheet[data-above="true"]::before {
  top: auto; bottom: -7px;
  transform: rotate(225deg);
}

/* On phones an anchored popover has nowhere to go — become a bottom sheet,
   which is the right form factor there. */
@media (max-width: 560px) {
  .sheet {
    left: 10px !important; right: 10px !important;
    top: auto !important; bottom: 10px !important;
    width: auto; max-height: 78vh;
    transform-origin: bottom center !important;
    border-radius: var(--radius-lg);
  }
  .sheet::before { display: none; }
  @keyframes popover-in {
    from { opacity: 0; transform: translateY(18px); filter: blur(5px); }
    to   { opacity: 1; transform: translateY(0); filter: blur(0); }
  }
}

.sheet h2 {
  font-size: 16px; font-weight: 640; letter-spacing: -.02em;
  margin-bottom: 3px;
}
.sheet .sheet-sub {
  font-size: 12.5px; color: var(--text-secondary); margin-bottom: 14px;
  line-height: 1.45;
}

.model-card {
  border: 1.5px solid var(--separator);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  padding: 11px 13px; margin-bottom: 8px;
  cursor: pointer;
  transition: border-color var(--dur-fast) ease-out,
              background var(--dur-fast) ease-out,
              transform var(--dur-fast) ease-out;
}
.model-card:hover { background: var(--fill); }
.model-card:active { transform: scale(.99); }
.model-card[data-selected="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.model-card[data-available="false"] { opacity: .55; }

.model-head { display: flex; align-items: center; gap: 9px; margin-bottom: 3px; }
.model-name { font-size: 14.5px; font-weight: 600; }
.model-tag {
  font-size: 10.5px; font-weight: 650; letter-spacing: .04em;
  text-transform: uppercase; padding: 2px 7px; border-radius: 100px;
  background: var(--fill); color: var(--text-secondary);
}
.model-tag[data-state="ok"]   { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.model-tag[data-state="low"]  { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.model-tag[data-state="out"]  { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.model-id { font-size: 11.5px; color: var(--text-tertiary); font-family: var(--font-mono); }

.quota-bar {
  height: 5px; border-radius: 3px; background: var(--fill);
  margin: 9px 0 7px; overflow: hidden;
}
.quota-fill {
  height: 100%; border-radius: 3px; background: var(--success);
  transition: width var(--dur-slow) var(--spring);
}
.quota-fill[data-state="low"] { background: var(--warning); }
.quota-fill[data-state="out"] { background: var(--danger); }

.quota-lines { display: grid; gap: 3px; }
.quota-line {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 11.5px; color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}
.quota-line b { color: var(--text-secondary); font-weight: 600; }
.quota-line .reset { margin-left: auto; }

.sheet-actions {
  display: flex; gap: 8px; margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--separator);
}
.sheet-actions .btn-text { flex: 1; }
.sheet-note {
  font-size: 11.5px; color: var(--text-tertiary); line-height: 1.5;
  margin-top: 12px; padding: 9px 11px;
  background: var(--fill); border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  .progress-text, .progress-trail span, .reveal-word, .sheet {
    animation: fade-only 160ms ease both;
  }
  .skeleton-row, .progress-dot { animation: none; }
  .reveal-word { opacity: 1; }
}

/* ---- OpenRouter free models -------------------------------------------- */
.free-models {
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--separator);
}
.free-models-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 620; margin-bottom: 4px;
}
.free-models-sub {
  font-size: 11.5px; color: var(--text-tertiary);
  line-height: 1.45; margin-bottom: 10px;
}

/* A scrollable column rather than a long list: the menu should not grow
   without bound just because a provider offers forty models. */
.free-model-list {
  display: grid; gap: 5px;
  max-height: 190px; overflow-y: auto;
  padding-right: 3px;
}

.free-model {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  font: inherit; font-size: 12.5px;
  padding: 7px 11px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur-fast) ease-out,
              border-color var(--dur-fast) ease-out,
              transform var(--dur-fast) ease-out;
}
.free-model:hover { background: var(--fill); }
.free-model:active { transform: scale(.985); }
.free-model[data-selected="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}
.free-model-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.free-model-ctx {
  margin-left: auto; flex: none;
  font-size: 11px; color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------------
   Advisory answers

   Visually distinct from the data blocks above it, because it IS different:
   the numbers come from the database, the plays come from the analysts'
   playbook. The label says which, so nobody mistakes a suggestion for a
   measurement. Styled on --success rather than --accent so it does not
   compete with the forecast box when both appear.
   --------------------------------------------------------------------------- */
.advice {
  margin-top: 14px; padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--success) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--success) 20%, transparent);
}

.advice-label {
  font-size: 11.5px; font-weight: 640;
  letter-spacing: 0.045em; text-transform: uppercase;
  color: var(--success); margin-bottom: 11px;
}

.advice-body { margin: 0; padding: 0; list-style: none; }

.advice-head {
  font-size: 13.5px; font-weight: 600;
  color: var(--text-primary);
  margin: 13px 0 6px;
  letter-spacing: -0.006em;
}
.advice-head:first-child { margin-top: 0; }

/* The row count and horizon — real, from the query, so kept legible but
   subordinate to the heading it qualifies. */
.advice-meta {
  font-weight: 450; font-size: 12.5px;
  color: var(--text-secondary);
  letter-spacing: 0;
}

.advice-body li {
  position: relative;
  padding-left: 15px; margin-bottom: 6px;
  font-size: 13.5px; line-height: 1.5;
  color: var(--text-secondary);
}
.advice-body li::before {
  content: ''; position: absolute;
  left: 3px; top: 8px;
  width: 4px; height: 4px; border-radius: 50%;
  background: color-mix(in srgb, var(--success) 60%, transparent);
}
.advice-body li:last-child { margin-bottom: 0; }

.advice-body p {
  margin: 0 0 7px; font-size: 13.5px; line-height: 1.5;
  color: var(--text-secondary);
}

@media (max-width: 560px) {
  .advice { padding: 12px 13px; }
  .advice-body li, .advice-body p { font-size: 13px; }
}

/* ---------------------------------------------------------------------------
   Interpretation — what the result SHOWS.

   Deliberately different from .advice, which says what to DO. Uses --accent so
   the two can appear together without competing for the same visual slot.
   --------------------------------------------------------------------------- */
.interpretation {
  margin-top: 14px; padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
}

.interp-label {
  font-size: 11.5px; font-weight: 640;
  letter-spacing: 0.045em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 10px;
}

.interp-body { margin: 0; padding: 0; list-style: none; }

.interp-head {
  font-size: 13.5px; font-weight: 600;
  color: var(--text-primary);
  margin: 12px 0 5px; letter-spacing: -0.006em;
}
.interp-head:first-child { margin-top: 0; }

.interp-body p {
  margin: 0 0 8px; font-size: 13.5px; line-height: 1.55;
  color: var(--text-secondary);
}
.interp-body p:last-child { margin-bottom: 0; }

.interp-body li {
  position: relative; padding-left: 15px; margin-bottom: 6px;
  font-size: 13.5px; line-height: 1.5; color: var(--text-secondary);
}
.interp-body li::before {
  content: ''; position: absolute; left: 3px; top: 8px;
  width: 4px; height: 4px; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 60%, transparent);
}

@media (max-width: 560px) {
  .interpretation { padding: 12px 13px; }
  .interp-body p, .interp-body li { font-size: 13px; }
}

/* ---- conversation: prose replies and suggestion chips ---- */
.prose p { margin: 0 0 .5em; line-height: 1.5; }
.prose p:last-child { margin-bottom: 0; }
.prose-list { margin: .25em 0 .6em 1.2em; padding: 0; }
.prose-list li { margin: .15em 0; line-height: 1.45; }
.suggestions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem; }
.suggestion {
  font: inherit; font-size: .85rem; cursor: pointer;
  padding: .35rem .7rem; border-radius: 999px;
  border: 1px solid var(--fill-strong); background: var(--fill);
  color: inherit; text-align: left;
}
.suggestion:hover, .suggestion:focus-visible {
  border-color: var(--accent); outline: none;
}

/* ---- export menu ---- */
.export-wrap { position: relative; display: inline-flex; }
.export-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
  width: 252px; padding: 6px;
  background: var(--bg-elevated); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--separator);
}
.export-menu[hidden] { display: none; }
.export-menu button {
  display: block; width: 100%; text-align: left; cursor: pointer;
  font: inherit; color: var(--text); background: transparent;
  border: none; border-radius: var(--radius-sm); padding: 8px 10px;
}
.export-menu button:hover, .export-menu button:focus-visible {
  background: var(--fill); outline: none;
}
.export-menu strong { display: block; font-size: 14px; font-weight: 600; }
.export-menu span { display: block; font-size: 12px; color: var(--text-secondary); }
.export-note {
  margin: 4px 10px 4px; font-size: 11px; color: var(--text-tertiary);
}

/* ---- answer feedback ---- */
.rate { display: inline-flex; gap: 2px; margin-left: 8px; vertical-align: middle; }
.rate-btn {
  border: none; background: transparent; color: var(--text-tertiary);
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  display: inline-grid; place-items: center; padding: 0;
}
.rate-btn svg { width: 15px; height: 15px; }
.rate-btn:hover { background: var(--fill); color: var(--text-secondary); }
.rate-btn[aria-pressed="true"] { color: var(--accent); background: var(--fill); }
.rate-note { display: flex; gap: 8px; margin: 6px 0 4px; max-width: 640px; }
.rate-note input {
  flex: 1; font: inherit; font-size: 13px; color: var(--text);
  background: var(--fill); border: 1px solid var(--separator);
  border-radius: var(--radius-sm); padding: 6px 10px;
}
.rate-thanks { font-size: 12px; color: var(--text-secondary); }
a.btn-icon { text-decoration: none; }

/* ===========================================================================
   Admin dashboard
   Structure follows shadcn/ui "dashboard-01": inset sidebar (288px) on a
   muted page, content in one rounded panel with a 48px header, KPI "section
   cards", chart cards, a tabbed data table. Spacing: 16px gaps (24px from
   768px), 24px card padding, 12px card radius, hairline borders, xs shadow.

   Chart colours: the data-viz reference categorical slots 1-4, validated
   against this app's card surfaces (#FFFFFF light, #1D1D1F dark) - every hard
   check passes in both modes. Light slots 3-4 sit below 3:1 on white, so
   every chart carries a legend and a table view.
   =========================================================================== */
.admin {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --status-good: #0ca30c; --status-warning: #e8a20a; --status-critical: #d03b3b;
  --tone-good: #0f7a36; --tone-bad: #c0352b;
  --viz-grid: #ececef; --viz-base: #d4d4d8; --viz-muted: #a1a1aa;
  --panel: #ffffff; --page: #f4f4f5; --line: #e4e4e7;
  --muted-fg: #71717a; --hover: #f4f4f5; --active: #e4e4e7;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .admin {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --tone-good: #3fbf6a; --tone-bad: #f07167;
    --viz-grid: #2a2a2e; --viz-base: #3f3f46; --viz-muted: #71717a;
    --panel: #1d1d1f; --page: #0b0b0c; --line: #2e2e33;
    --muted-fg: #a1a1aa; --hover: #26262a; --active: #2e2e33;
  }
}
:root[data-theme="dark"] .admin {
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --tone-good: #3fbf6a; --tone-bad: #f07167;
  --viz-grid: #2a2a2e; --viz-base: #3f3f46; --viz-muted: #71717a;
  --panel: #1d1d1f; --page: #0b0b0c; --line: #2e2e33;
  --muted-fg: #a1a1aa; --hover: #26262a; --active: #2e2e33;
}

body.admin { background: var(--page); color: var(--text); font-size: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.admin svg:not(.viz-svg) { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.admin code { font-size: 12.5px; background: var(--hover); padding: 1px 5px; border-radius: 4px; }

/* ---- shell ---------------------------------------------------------- */
.sb-shell { display: flex; min-height: 100vh; }
.sb {
  position: sticky; top: 0; height: 100vh; width: 288px; flex: none;
  display: flex; flex-direction: column; gap: 4px; padding: 12px 12px 12px;
}
.sb-brand {
  display: flex; align-items: center; gap: 10px; padding: 8px; margin-bottom: 8px;
  color: var(--text); text-decoration: none; border-radius: 8px;
}
.sb-brand:hover { background: var(--hover); }
.sb-logo {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--text); color: var(--panel);
}
.sb-logo svg { width: 16px; height: 16px; stroke-width: 2.4; }
.sb-brand-text { font-weight: 600; font-size: 15px; }
.sb-group { display: flex; flex-direction: column; gap: 2px; padding: 4px 0; }
.sb-label { font-size: 12px; font-weight: 500; color: var(--muted-fg); padding: 8px 8px 4px; }
.sb-group a, .sb-group button {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 8px;
  border-radius: 8px; border: none; background: transparent; cursor: pointer;
  font: inherit; font-size: 14px; color: var(--text); text-decoration: none; text-align: left;
}
.sb-group a:hover, .sb-group button:hover { background: var(--hover); }
.sb-group a[aria-current="page"] { background: var(--active); font-weight: 600; }
.sb-group svg { width: 16px; height: 16px; flex: none; color: var(--muted-fg); }
.sb-group a[aria-current="page"] svg { color: var(--text); }
.sb-count:not(:empty) {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
  background: var(--tone-bad); color: #fff;
}
.sb-bottom { margin-top: auto; }
.sb .theme-toggle .icon-sun, .sb .theme-toggle .icon-moon { position: static; transform: none; opacity: 1; }
.sb .theme-toggle .icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sb .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .sb .theme-toggle .icon-moon { display: none; }
}
:root[data-theme="dark"] .sb .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .sb .theme-toggle .icon-moon { display: none; }
.sb-user {
  display: flex; align-items: center; gap: 10px; padding: 8px; margin-top: 4px;
  border-top: 1px solid var(--line); padding-top: 12px;
}
.sb-avatar {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: var(--active); font-weight: 600; font-size: 13px;
}
.sb-user-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.sb-user-text strong { font-size: 13.5px; }
.sb-user-text span { font-size: 12px; color: var(--muted-fg); text-transform: capitalize; }

/* inset panel */
.sb-inset {
  flex: 1; min-width: 0; margin: 8px 8px 8px 0; background: var(--panel);
  border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); border: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.site-head {
  position: sticky; top: 0; z-index: 5; height: 56px; flex: none;
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: var(--panel); border-radius: 12px 12px 0 0;
}
.site-head h1 { font-size: 16px; font-weight: 600; margin: 0; }
.site-head-spacer { flex: 1; }
.sb-toggle { display: none; }

/* controls */
.btn, .ctl {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border-radius: 8px; font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); white-space: nowrap;
}
.ctl { padding-right: 8px; }
.ctl[hidden], .btn[hidden] { display: none; }
.btn svg { width: 15px; height: 15px; }
.btn:hover, .ctl:hover { background: var(--hover); }
.btn-primary { background: var(--text); color: var(--panel); border-color: var(--text); }
.btn-primary:hover { background: var(--text); opacity: .88; }
.btn-primary:disabled svg { animation: spin 1s linear infinite; }
.btn-outline { background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted-fg); }
/* Destructive actions (Dismiss, Disable): red, so they never pass for routine
   ones. Tinted rather than solid red: they are row actions, not alarms. */
.btn-danger {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
}
.btn-danger:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  border-color: color-mix(in srgb, var(--danger) 50%, transparent);
}
.btn-danger:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn:disabled { opacity: .6; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn-primary:disabled svg { animation: none; } }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: none; background: transparent;
  color: var(--text); cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 18px; height: 18px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); font-size: 13px; font-weight: 500;
  color: var(--text); text-decoration: none;
}
.status-pill:hover { background: var(--hover); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--status-good); flex: none; }
.status-pill[data-state="warning"] .dot, .dot[data-state="warning"] { background: var(--status-warning); }
.status-pill[data-state="critical"] .dot, .dot[data-state="critical"] { background: var(--status-critical); }
.status-pill[data-state="good"] .dot, .dot[data-state="good"] { background: var(--status-good); }

/* page */
.page { padding: 16px; display: flex; flex-direction: column; gap: 16px; transition: opacity .2s ease; }
.page > section { display: flex; flex-direction: column; gap: 16px; }
.page > section[hidden] { display: none; }
.page.is-loading { opacity: .55; }
.page-foot { margin: 0; font-size: 12px; color: var(--muted-fg); }
@media (min-width: 768px) {
  .page, .page > section { gap: 24px; }
  .page { padding: 24px; }
}

/* ---- cards ---------------------------------------------------------- */
.card {
  margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04); padding: 24px; min-width: 0;
  display: flex; flex-direction: column; gap: 16px;
}
.card-flush { padding: 0; gap: 0; }
.card-flush > .card-header { padding: 20px 24px 16px; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.card-header-tabs { flex-direction: column; align-items: stretch; gap: 10px; }
.card-title { font-size: 15px; font-weight: 600; margin: 0; line-height: 1.3; }
.card-desc { font-size: 13px; color: var(--muted-fg); margin: 4px 0 0; }
.card-header-tabs .card-desc { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (min-width: 768px) { .grid-2 { gap: 24px; } }

/* KPI section cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (min-width: 768px) { .kpi-grid { gap: 24px; } }
.kpi {
  display: flex; flex-direction: column; gap: 6px; padding: 20px 24px;
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
  background: linear-gradient(to top, color-mix(in srgb, var(--accent) 4%, var(--panel)), var(--panel));
}
.kpi-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kpi-label { font-size: 13.5px; color: var(--muted-fg); }
.kpi-value { font-size: 30px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; }
.kpi-foot { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; font-size: 13px; }
.kpi-line { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.kpi-line svg { width: 15px; height: 15px; }
.kpi-context { color: var(--muted-fg); }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px;
  border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }
.badge-outline { border: 1px solid var(--line); color: var(--text); }
.badge-outline[data-tone="good"] { color: var(--tone-good); }
.badge-outline[data-tone="bad"] { color: var(--tone-bad); }
.badge-soft { background: var(--hover); color: var(--text); }
.badge-soft[data-kind="verified"]::before, .badge-soft[data-kind="cached"]::before,
.badge-soft[data-kind="ai"]::before, .badge-soft[data-kind="conversation"]::before {
  content: ""; width: 7px; height: 7px; border-radius: 2px; margin-right: 2px;
}
.badge-soft[data-kind="verified"]::before { background: var(--series-1); }
.badge-soft[data-kind="cached"]::before { background: var(--series-2); }
.badge-soft[data-kind="ai"]::before { background: var(--series-3); }
.badge-soft[data-kind="conversation"]::before { background: var(--series-4); }
.badge-soft[data-kind="failed"], .badge-soft[data-kind="unanswered"] {
  background: color-mix(in srgb, var(--tone-bad) 12%, transparent); color: var(--tone-bad);
}
.badge-soft[data-kind="ok"] {
  background: color-mix(in srgb, var(--tone-good) 12%, transparent); color: var(--tone-good);
}

/* tabs (shadcn TabsList) */
.tabs { display: inline-flex; align-self: flex-start; gap: 2px; padding: 3px; border-radius: 10px; background: var(--hover); }
.tabs button {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px;
  border: none; border-radius: 7px; background: transparent; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 500; color: var(--muted-fg);
}
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.tab-badge:not(:empty) {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; display: grid; place-items: center;
  font-size: 11px; background: var(--active); color: var(--text);
}

/* tables */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-weight: 500; color: var(--muted-fg); font-size: 12.5px;
  height: 40px; padding: 0 12px; background: var(--hover); white-space: nowrap;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.tbl th:first-child, .tbl td:first-child { padding-left: 24px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 24px; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--hover) 60%, transparent); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .sub { font-size: 12.5px; color: var(--muted-fg); margin-top: 3px; }
.tbl .sub.t-bad { color: var(--tone-bad); font-weight: 500; }
.tbl details summary { cursor: pointer; font-size: 12.5px; color: var(--muted-fg); margin-top: 4px; }
.tbl pre { white-space: pre-wrap; font-size: 12px; background: var(--hover); border-radius: 8px; padding: 10px; margin: 6px 0 0; }
.tbl-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; border-top: 1px solid var(--line); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: nowrap; }
.fails { margin: 6px 0 0; padding-left: 16px; }
.fails li { margin-bottom: 4px; }
.fails span { display: block; font-size: 12.5px; color: var(--muted-fg); }
.muted { color: var(--muted-fg); }
.t-bad { color: var(--tone-bad); font-weight: 600; }
.empty { margin: 0; padding: 32px 24px; text-align: center; color: var(--muted-fg); font-size: 13.5px; }

/* lists (health, facts) */
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.list li, .list .list-row {
  display: flex; align-items: center; gap: 10px; padding: 12px 24px; border-bottom: 1px solid var(--line);
}
.list li:last-child, .list .list-row:last-child { border-bottom: none; }
.list-label, .list dt { flex: 1; color: var(--text); }
.list-value, .list dd { margin: 0; color: var(--muted-fg); text-align: right; }

.code {
  margin: 0; white-space: pre-wrap; font-size: 12.5px; line-height: 1.55; background: var(--hover);
  border-radius: 8px; padding: 14px 16px; max-height: 520px; overflow: auto;
}

/* providers under the tokens chart */
.providers { border-top: 1px solid var(--line); padding-top: 14px; }
.providers-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.providers-head span:last-child { color: var(--muted-fg); font-weight: 400; }

/* ---- charts (admin-charts.js) --------------------------------------- */
.viz-legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12.5px; color: var(--muted-fg); margin-bottom: -6px; }
.viz-legend:empty { display: none; }
.viz-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.viz-key { display: inline-block; flex: none; }
.viz-key-rect { width: 10px; height: 10px; border-radius: 3px; }
.viz-key-line { width: 14px; height: 2px; border-radius: 1px; }
.viz-mount { min-height: 60px; }
.admin .viz-svg { display: block; overflow: visible; outline: none; stroke: none; }
.viz-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; shape-rendering: crispEdges; }
.viz-base { stroke: var(--viz-base); stroke-width: 1; shape-rendering: crispEdges; }
.viz-tick { font-size: 11.5px; fill: var(--muted-fg); stroke: none; font-variant-numeric: tabular-nums; }
.viz-label { font-size: 13px; fill: var(--text); stroke: none; }
.viz-value { font-size: 12.5px; fill: var(--muted-fg); stroke: none; font-weight: 500; }
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-area { opacity: .12; stroke: none; }
.viz-dot { stroke: var(--panel); stroke-width: 2; }
.viz-cross { stroke: var(--viz-base); stroke-width: 1; pointer-events: none; }
.viz-hit { fill: transparent; stroke: none; }
.viz-col path, .viz-col rect { stroke: none; }
.viz-col { transition: opacity .12s ease; }
.viz-col.viz-dim { opacity: .4; }
.viz-tip {
  position: absolute; z-index: 100; pointer-events: none; min-width: 160px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12); padding: 8px 10px; font-size: 12.5px;
}
.viz-tip-title { color: var(--muted-fg); margin-bottom: 4px; }
.viz-tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.7; }
.viz-tip-row strong { font-variant-numeric: tabular-nums; min-width: 44px; }
.viz-tip-name { color: var(--muted-fg); }
.viz-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.viz-table th, .viz-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.viz-table th { color: var(--muted-fg); font-weight: 500; }
.viz-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- responsive ----------------------------------------------------- */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .sb {
    position: fixed; left: 0; top: 0; z-index: 40; background: var(--panel);
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 24px rgba(0,0,0,.18);
    width: 272px;
  }
  body.sb-open .sb { transform: none; }
  .sb-scrim { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); }
  .sb-toggle { display: grid; }
  .sb-inset { margin: 0; border-radius: 0; border: none; }
  .site-head { border-radius: 0; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .kpi-grid, .kpi-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .site-head { flex-wrap: wrap; height: auto; padding: 8px 12px; row-gap: 8px; }
  .site-head h1 { flex: 1; }
  .site-head-spacer { display: none; }
  .btn-primary span { display: none; }
  .site-head { flex-wrap: nowrap; height: 56px; }
  #statusText { display: none; }
  .status-pill { padding: 0 11px; }
  .site-head h1 { font-size: 15px; }
  .ctl { max-width: 132px; }
  .row-actions { flex-wrap: wrap; justify-content: flex-start; }
  .card { padding: 18px; }
  .card-flush > .card-header { padding: 16px 18px 12px; }
  .tbl th:first-child, .tbl td:first-child { padding-left: 18px; }
  .tbl th:last-child, .tbl td:last-child { padding-right: 18px; }
  .row-actions { justify-content: flex-start; }
}

/* users page */
.user-form {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px;
  padding: 16px 24px 20px; border-top: 1px solid var(--line); background: var(--hover);
}
.user-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
.user-form input, .user-form select {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-size: 13.5px;
}
.user-form input:focus-visible, .user-form select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.user-form small { font-weight: 400; font-size: 12px; }
.user-form .row-actions { grid-column: 1 / -1; }
.user-form[hidden] { display: none; }
.pw-row { display: flex; gap: 6px; }
.pw-row input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.secret-box {
  display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: center;
  margin: 0 24px 16px; padding: 14px 16px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--tone-good) 40%, transparent);
  background: color-mix(in srgb, var(--tone-good) 8%, var(--panel));
}
.secret-box[hidden] { display: none; }
.secret-box p { margin: 2px 0 0; }
.secret-box code { font-size: 15px; padding: 6px 10px; background: var(--panel); border: 1px solid var(--line); user-select: all; }
.ctl-sm { height: 30px; font-size: 12.5px; width: 100%; }
@media (max-width: 900px) {
  .user-form { grid-template-columns: minmax(0, 1fr); }
  .secret-box { grid-template-columns: 1fr; }
}

/* ==========================================================================
   PREMIUM GLASS THEME
   Frosted-glass surfaces over a strong, matte colour field.

     ink       #070B16 / #E8EBF4   the page (dark / light)
     cobalt    #5872FF / #3550E8   the accent: actions, the user's own words
     tangerine #FF8A3D             the second accent: brand details, sparingly
     violet, teal                  only in the background mesh

   The mesh is fixed to the viewport so the glass always has colour to blur.
   A fine grain over everything makes the colour matte rather than glossy.
   Real blur (backdrop-filter) is used only on chrome that floats over
   content (bar, composer, sheets, menus, sidebar, sign-in card); bubbles and
   cards are translucent over an already-soft background, which reads as
   frosted at no GPU cost.
   Placed last so it layers over the base system without rewriting it.
   ========================================================================== */
:root {
  --ink:            #e8ebf4;
  --bg:             var(--ink);
  --mesh:
    radial-gradient(60vw 50vh at 8% 0%, rgba(61, 90, 254, .24), transparent 70%),
    radial-gradient(50vw 45vh at 95% 8%, rgba(124, 77, 255, .16), transparent 70%),
    radial-gradient(55vw 50vh at 78% 100%, rgba(255, 122, 26, .16), transparent 70%),
    radial-gradient(45vw 40vh at 0% 100%, rgba(0, 170, 160, .10), transparent 70%);
  --glass-1:        rgba(255, 255, 255, .56);
  --glass-2:        rgba(255, 255, 255, .64);
  --glass-solid:    rgba(250, 251, 255, .96);
  --glass-strong:   rgba(248, 250, 255, .90);
  --glass-opaque:   #f8f9fe;
  --glass-input:    rgba(255, 255, 255, .72);
  --glass-edge:     rgba(255, 255, 255, .75);
  --glass-highlight: rgba(255, 255, 255, .9);
  --grain-opacity:  .045;

  --bg-elevated:    var(--glass-1);
  --material:       var(--glass-2);
  --material-edge:  var(--glass-edge);

  --text:           #12182b;
  --text-secondary: #47506a;
  --text-tertiary:  #6d7792;
  --separator:      rgba(18, 24, 43, .08);
  --fill:           rgba(18, 24, 43, .05);
  --fill-strong:    rgba(18, 24, 43, .09);

  --accent:         #3550e8;
  --accent-hover:   #2a43d4;
  --accent-2:       #f2711c;
  --on-accent:      #ffffff;

  --shadow-sm: 0 1px 2px rgba(30, 40, 90, .06);
  --shadow:    0 10px 30px rgba(35, 50, 110, .10), 0 1px 2px rgba(35, 50, 110, .06);
  --shadow-lg: 0 24px 60px rgba(35, 50, 110, .16), 0 2px 6px rgba(35, 50, 110, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink:            #070b16;
    --bg:             var(--ink);
    --mesh:
      radial-gradient(60vw 50vh at 8% 0%, rgba(68, 96, 255, .40), transparent 70%),
      radial-gradient(50vw 45vh at 95% 8%, rgba(132, 84, 255, .30), transparent 70%),
      radial-gradient(55vw 50vh at 78% 100%, rgba(255, 122, 26, .20), transparent 70%),
      radial-gradient(45vw 40vh at 0% 100%, rgba(0, 186, 170, .14), transparent 70%);
    --glass-1:        rgba(24, 32, 58, .50);
    --glass-2:        rgba(14, 20, 40, .62);
    --glass-solid:    rgba(16, 22, 42, .94);
    --glass-strong:   rgba(15, 21, 40, .90);
    --glass-opaque:   #111930;
    --glass-input:    rgba(255, 255, 255, .06);
    --glass-edge:     rgba(255, 255, 255, .10);
    --glass-highlight: rgba(255, 255, 255, .07);
    --grain-opacity:  .06;

    --bg-elevated:    var(--glass-1);
    --material:       var(--glass-2);
    --material-edge:  var(--glass-edge);
    --scrim:          rgba(4, 7, 16, .6);

    --text:           #eef2ff;
    --text-secondary: #b7c0d8;
    --text-tertiary:  #8590ae;
    --separator:      rgba(255, 255, 255, .08);
    --fill:           rgba(255, 255, 255, .06);
    --fill-strong:    rgba(255, 255, 255, .11);

    --accent:         #5872ff;
    --accent-hover:   #6f87ff;
    --accent-2:       #ff8a3d;
    --on-accent:      #ffffff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow:    0 10px 30px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
    --ink:            #070b16;
    --bg:             var(--ink);
    --mesh:
      radial-gradient(60vw 50vh at 8% 0%, rgba(68, 96, 255, .40), transparent 70%),
      radial-gradient(50vw 45vh at 95% 8%, rgba(132, 84, 255, .30), transparent 70%),
      radial-gradient(55vw 50vh at 78% 100%, rgba(255, 122, 26, .20), transparent 70%),
      radial-gradient(45vw 40vh at 0% 100%, rgba(0, 186, 170, .14), transparent 70%);
    --glass-1:        rgba(24, 32, 58, .50);
    --glass-2:        rgba(14, 20, 40, .62);
    --glass-solid:    rgba(16, 22, 42, .94);
    --glass-strong:   rgba(15, 21, 40, .90);
    --glass-opaque:   #111930;
    --glass-input:    rgba(255, 255, 255, .06);
    --glass-edge:     rgba(255, 255, 255, .10);
    --glass-highlight: rgba(255, 255, 255, .07);
    --grain-opacity:  .06;

    --bg-elevated:    var(--glass-1);
    --material:       var(--glass-2);
    --material-edge:  var(--glass-edge);
    --scrim:          rgba(4, 7, 16, .6);

    --text:           #eef2ff;
    --text-secondary: #b7c0d8;
    --text-tertiary:  #8590ae;
    --separator:      rgba(255, 255, 255, .08);
    --fill:           rgba(255, 255, 255, .06);
    --fill-strong:    rgba(255, 255, 255, .11);

    --accent:         #5872ff;
    --accent-hover:   #6f87ff;
    --accent-2:       #ff8a3d;
    --on-accent:      #ffffff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow:    0 10px 30px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);
}

/* ---- the field: colour mesh + matte grain -------------------------------- */
/* Two fixed layers under everything, not `background-attachment: fixed` on
   the body: that repaints the whole page on every scroll frame, while these
   are composited once and simply stay put. */
html { background: var(--bg); }
body, body.admin, .auth-page { background: transparent; }
body::before, body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
}
body::before { background: var(--mesh); }
body::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: var(--grain-opacity);
}

/* ---- glass primitives ------------------------------------------------------ */
.app-bar, .composer, .sheet, .export-menu, .toast, .voice-panel, .viz-tip, .auth-card {
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
}
.app-bar {
  background: var(--glass-2);
  border-bottom: 1px solid var(--glass-edge);
  box-shadow: inset 0 -1px 0 var(--separator);
}
.bubble, .suggestion, .insight, .model-card, .free-model, .card {
  background: var(--glass-1);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-sm);
}
.sheet, .export-menu, .toast, .voice-panel, .viz-tip {
  background: var(--glass-2);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-lg);
}
/* Panels that open OVER content (the AI-provider sheet, the download menu,
   the voice panel, toasts) get strong glass: about 90% opaque with a heavy
   blur, so the answer behind them is only a hint of colour, never something
   to read through. The chrome (bar, composer) keeps the lighter glass. */
.sheet, .sheet::before, .export-menu, .voice-panel, .toast {
  background: var(--glass-strong);
}
.sheet, .export-menu, .voice-panel, .toast {
  backdrop-filter: blur(40px) saturate(160%);
  -webkit-backdrop-filter: blur(40px) saturate(160%);
  border-color: color-mix(in srgb, var(--text) 10%, var(--glass-edge));
}
/* The download menu lives INSIDE the frosted app bar, and a backdrop-filter
   on a parent stops a child's blur at the parent: the menu cannot blur the
   page behind the bar, so through 10% transparency the answer text stayed
   readable. Opaque instead, in the glass's own colour. */
.export-menu { background: var(--glass-opaque); }

/* The user's own words: solid matte cobalt, the one saturated surface. */
.msg[data-role="user"] .bubble {
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 32%, transparent);
}

/* A floating composer pill instead of a full-width bar. */
.composer-dock { background: none; border-top: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
.composer-dock::before { display: none; }
.composer {
  background: var(--glass-2);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-lg);
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--glass-edge));
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-lg),
              0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}

/* Sticky table headers must stay readable over the rows scrolling under them. */
table.result th { background: var(--glass-solid); }

/* ---- sign-in: the form is a glass card on the colour field ---------------- */
.auth-panel { background: none; border-left: none; }
.auth-card {
  max-width: 400px; padding: 36px 30px 28px; border-radius: 26px;
  background: var(--glass-2);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-lg);
}
.auth-card input[type="text"], .auth-card input[type="password"] {
  background: var(--glass-input); border-color: var(--glass-edge);
}
.auth-card input:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--glass-edge)); }
.auth-submit {
  background: var(--accent);                       /* matte: flat colour, no gloss */
  box-shadow: 0 10px 26px -8px color-mix(in srgb, var(--accent) 70%, transparent);
}
.auth-submit:hover { background: var(--accent-hover); filter: none; }
.auth-logo { background: var(--accent); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent); }

/* The scene: a cinematic vignette that pulls the eye to the car. */
.auth-visual::after {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(ellipse 85% 75% at 50% 42%, transparent 55%, rgba(3, 6, 14, .55) 100%),
    linear-gradient(90deg, transparent 88%, rgba(3, 6, 14, .35));
}

/* ---- admin: the same glass, on the same field ----------------------------- */
.admin {
  --series-1: var(--accent);   /* the first series is the brand cobalt (>3:1 on both card colours) */
  --page: transparent; --panel: var(--glass-1); --line: rgba(18, 24, 43, .08);
  --hover: rgba(18, 24, 43, .05); --active: rgba(18, 24, 43, .09);
  --muted-fg: #5d6784; --viz-grid: rgba(18, 24, 43, .07); --viz-base: rgba(18, 24, 43, .18);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .admin {
    --series-1: var(--accent);
    --page: transparent; --panel: var(--glass-1); --line: rgba(255, 255, 255, .08);
    --hover: rgba(255, 255, 255, .06); --active: rgba(255, 255, 255, .11);
    --muted-fg: #8f9ab8; --viz-grid: rgba(255, 255, 255, .07); --viz-base: rgba(255, 255, 255, .16);
  }
}
:root[data-theme="dark"] .admin {
    --series-1: var(--accent);
    --page: transparent; --panel: var(--glass-1); --line: rgba(255, 255, 255, .08);
    --hover: rgba(255, 255, 255, .06); --active: rgba(255, 255, 255, .11);
    --muted-fg: #8f9ab8; --viz-grid: rgba(255, 255, 255, .07); --viz-base: rgba(255, 255, 255, .16);
}
.sb-inset {
  background: var(--glass-1);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}
.admin .card { background: color-mix(in srgb, var(--glass-1) 80%, transparent); }
.sb-logo { background: var(--accent); color: #fff; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); opacity: 1; }
@media (max-width: 1024px) {
  .sb {
    background: var(--glass-2);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
  }
}

/* ---- accessibility -------------------------------------------------------- */
/* Asked for less transparency: solid surfaces, no blur, no grain. */
@media (prefers-reduced-transparency: reduce) {
  /* Every theme selector, so dark mode honours it too (its own selectors are
     more specific than a bare :root). */
  :root, :root[data-theme], :root:not([data-theme="light"]) {
    --glass-1: var(--glass-solid); --glass-2: var(--glass-solid);
    --glass-strong: var(--glass-solid); --grain-opacity: 0;
  }
  .app-bar, .composer, .sheet, .export-menu, .toast, .voice-panel, .viz-tip, .auth-card, .sb-inset, .sb {
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
}
/* Browsers without backdrop-filter: make the floating glass nearly opaque so
   text over content stays readable. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .app-bar, .composer, .sheet, .export-menu, .toast, .voice-panel, .auth-card { background: var(--glass-solid); }
}
