/* ─────────────────────────────────────────────────────────────────────────
   AgniPod console
   Layered: tokens → base → layout → components → views
   ───────────────────────────────────────────────────────────────────────── */

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --primary: #FF6B35;
  --primary-dark: #E85A24;
  --bg: #14141C;
  --panel: #1E1E2E;
  --panel-2: #262638;
  --line: #33334A;
  --text: #EDEDF2;
  --muted: #9A9AAE;
  --ok: #3DD68C;
  --warn: #FFB800;
  --err: #FF5A5A;
  --info-2: #5AA9FF;
  --radius: 10px;
  --radius-sm: 7px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* `--border` was referenced by several components but never defined, which
     made those declarations invalid and silently fell back to currentColor.
     Aliased rather than renamed so both names keep working. */
  --border: #33334A;

  --sidebar-w: 232px;
  --sidebar-w-collapsed: 60px;
  --topbar-h: 46px;

  /* How tall a page-level data table may grow before it scrolls inside itself.
     Capping it is what lets the sticky header actually stick: a sticky `th`
     only sticks to a scrollport that scrolls, and an uncapped wrapper never
     does. */
  --table-max-h: min(72vh, 900px);

  /* The console is dark. Telling the UA so is not cosmetic: it is what makes
     native scrollbars, select popups, date pickers and spinner buttons render
     dark instead of as bright rectangles punched through the page. */
  color-scheme: dark;
}

/* ── Base ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

/* `hidden` is set programmatically all over this console, and it loses to any
   class that sets `display`. Without this, a hidden flex/grid node stays
   visible — which is how empty toolbars and stale bars end up on screen. */
[hidden] { display: none !important; }

html {
  /* Reserve the scrollbar track so opening a modal (which locks body scroll)
     does not shift the whole page sideways. */
  scrollbar-gutter: stable;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

/* While a modal or drawer owns the screen, the page behind it must not scroll:
   scrolling the background instead of the dialog is the most common way a
   dialog appears "stuck". */
body.scroll-locked { overflow: hidden; }

a { color: inherit; }

/* Keyboard focus was invisible everywhere: `input:focus { outline: 0 }` with
   nothing put back, and no ring at all on buttons, links, rows or tabs. */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Jump past the rail straight to the work area. Visible only when focused. */
.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 500;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--primary); border-radius: var(--radius-sm);
  padding: 9px 14px; font-size: 13px; text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus { transform: translateY(0); }

/* Custom scrollbars for the panes that scroll inside the page, so a nested
   scroll region reads as part of the surface rather than an OS artefact. */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 999px;
  border: 2px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
*::-webkit-scrollbar-corner { background: transparent; }
.mono, code { font-family: var(--mono); font-size: .92em; }
.sub { color: var(--muted); font-size: 13px; }
.mb { margin-bottom: 14px; }
.right { text-align: right; }

/* ── Shell ──────────────────────────────────────────────────────────────────
 *
 * Persistent left rail + thin context bar + full-width work area. Desktop
 * first: this is an operations console, and the tables it exists to show are
 * wide. The rail is fixed so navigating never scrolls the nav out of reach.
 */
.spacer { flex: 1; }
.badge {
  font-size: 11px; font-weight: 500; color: var(--muted);
  border: 1px solid var(--line); padding: 2px 8px; border-radius: 999px;
}

#sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 50;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  transition: width .15s ease;
}
#sidebar[hidden] { display: none; }

.sidebar-brand {
  display: flex; align-items: center; gap: 9px;
  padding: 14px 14px 12px; font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.sidebar-brand img { width: 24px; height: 24px; flex: none; }
.collapse-btn { margin-left: auto; font-size: 14px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.nav-group + .nav-group { margin-top: 14px; }
.nav-group-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 4px 10px 6px; font-weight: 600;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; text-decoration: none; color: var(--muted);
  white-space: nowrap;
}
.nav-link:hover { background: var(--panel-2); color: var(--text); }
.nav-link.active { background: var(--panel-2); color: var(--primary); }
/* The active marker is a left bar rather than colour alone, so the current
   section is identifiable without relying on hue discrimination. */
.nav-link.active { box-shadow: inset 2px 0 0 var(--primary); }
.nav-icon {
  width: 18px; text-align: center; flex: none;
  font-size: 13px; opacity: .85;
}

.sidebar-foot {
  border-top: 1px solid var(--line); padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-user {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Collapsed: icons only. Titles keep every destination identifiable. */
body.sidebar-collapsed #sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .brand-name,
body.sidebar-collapsed .nav-group-label,
body.sidebar-collapsed .sidebar-user { display: none; }
body.sidebar-collapsed .sidebar-foot button { padding: 5px 6px; font-size: 11px; }
body.sidebar-collapsed .collapse-btn { transform: rotate(180deg); margin: 0; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 14px 6px; }
body.sidebar-collapsed .nav-link { justify-content: center; padding: 8px 6px; }
body.sidebar-collapsed #main { margin-left: var(--sidebar-w-collapsed); }

#main { margin-left: var(--sidebar-w); min-height: 100vh; transition: margin .15s ease; }
body:not(.authed) #main { margin-left: 0; }

#topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
#topbar[hidden] { display: none; }
.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.crumb-sep { color: var(--muted); }
.env-badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); border: 1px solid var(--line);
  padding: 2px 8px; border-radius: 999px;
}

#app { padding: 20px 22px 48px; max-width: 1680px; }

/* Page header: title and the actions that apply to the whole page. */
.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.page-head-text { flex: 1; min-width: 240px; }
.page-head h1 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.page-head .sub { margin-top: 3px; max-width: 78ch; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Panels ─────────────────────────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.panel-head h2 { font-size: 14px; font-weight: 600; letter-spacing: .02em; flex: 1; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; color: var(--muted); }

input, textarea, select {
  width: 100%; font: inherit; font-size: 14px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px; color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:hover:not(:disabled), textarea:hover:not(:disabled), select:hover:not(:disabled) {
  border-color: var(--muted);
}
/* A visible ring, not just a hue change: the border-colour swap alone was the
   only focus signal and it is easy to miss on a dense form. */
input:focus, textarea:focus, select:focus {
  outline: 0; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255,107,53,.20);
}
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 0; }
input:invalid:not(:placeholder-shown) { border-color: var(--err); }
input:disabled, textarea:disabled, select:disabled { opacity: .55; cursor: not-allowed; }
textarea { resize: vertical; min-height: 62px; }
select { cursor: pointer; }
/* Reset inputs inherit `width: 100%` from the rule above, which stretched a
   checkbox into a bar. Every checkbox in this console is inline with a label. */
input[type=checkbox], input[type=radio] {
  width: auto; accent-color: var(--primary); cursor: pointer;
}

button {
  font: inherit; font-size: 13px; font-weight: 500;
  border: 0; border-radius: var(--radius-sm); padding: 9px 15px;
  cursor: pointer; background: var(--primary); color: #fff;
  white-space: nowrap; line-height: 1.3;
  transition: background .12s ease, opacity .12s ease;
}
button:hover:not(:disabled) { background: var(--primary-dark); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) {
  button, button:active:not(:disabled) { transition: none; transform: none; }
}
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.ghost:hover:not(:disabled) { background: var(--panel-2); }
button.danger { background: transparent; border: 1px solid var(--err); color: var(--err); }
button.danger:hover:not(:disabled) { background: rgba(255,90,90,.12); }
button.sm { padding: 5px 11px; font-size: 12px; }
button.link {
  background: none; border: 0; color: var(--primary); padding: 0;
  font-size: 13px; text-decoration: underline;
}
.link { color: var(--primary); }

details summary { cursor: pointer; font-size: 13px; color: var(--muted); user-select: none; }
details summary:hover { color: var(--text); }
details > *:not(summary) { margin-top: 10px; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow: auto; overscroll-behavior-x: contain; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.02); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Pills / stats ──────────────────────────────────────────────────────── */
.pill {
  font-size: 11px; font-weight: 500; padding: 3px 9px;
  border-radius: 999px; white-space: nowrap; display: inline-block;
}
.pill.ok { background: rgba(61,214,140,.15); color: var(--ok); }
.pill.warn { background: rgba(255,184,0,.15); color: var(--warn); }
.pill.err { background: rgba(255,90,90,.15); color: var(--err); }
.pill.mute { background: var(--panel-2); color: var(--muted); }

.stat-row {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}
.stat { background: var(--panel-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.stat-value { font-size: 20px; font-weight: 600; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ── Progress ───────────────────────────────────────────────────────────── */
.progress {
  position: relative; height: 18px; min-width: 110px;
  background: var(--panel-2); border-radius: 999px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--primary); transition: width .3s; }
.progress-text {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 11px; font-weight: 500;
}

/* ── States ─────────────────────────────────────────────────────────────── */
.empty { padding: 28px; text-align: center; color: var(--muted); font-size: 14px; }
.loading { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--muted); }
.spin {
  width: 15px; height: 15px; border: 2px solid var(--line);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  padding: 18px; border: 1px solid var(--err); border-radius: var(--radius-sm);
  background: rgba(255,90,90,.08); display: flex; align-items: center;
  gap: 14px; justify-content: space-between; flex-wrap: wrap;
}

/* ── Toasts ─────────────────────────────────────────────────────────────────
 *
 * A stack, not a single slot. There was one node reused for every message, so
 * a save that reported success followed immediately by a failure showed only
 * the failure — and a long message was never dismissible early.
 *
 * z-index sits above dialogs (300): a toast raised by an action taken inside a
 * modal has to be visible, or the modal silently swallows its own feedback.
 */
#toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 400;
  /* Oldest at the top, newest nearest the corner — so the entry that ages out
     leaves from the far end rather than from under the reader's eye. */
  display: flex; flex-direction: column; gap: 9px;
  align-items: flex-end; max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 9px; padding: 11px 14px; font-size: 13.5px; line-height: 1.45;
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
  opacity: 0; transform: translateY(10px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: auto; max-width: 100%;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok   { border-left-color: var(--ok); }
.toast.err  { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
.toast.info { border-left-color: var(--info-2); }
.toast-text { flex: 1; min-width: 0; word-break: break-word; }
.toast-close {
  background: transparent; border: 0; color: var(--muted);
  padding: 0 2px; font-size: 13px; line-height: 1.3; flex: none;
}
.toast-close:hover { background: transparent; color: var(--text); }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
@media (max-width: 600px) {
  #toast { left: 16px; right: 16px; bottom: 16px; align-items: stretch; max-width: none; }
}

/* ── Modal ──────────────────────────────────────────────────────────────────
 *
 * The overlay used `place-items: center` on a box with no height limit, so any
 * dialog taller than the viewport — the model register form, a JSON payload, a
 * validation-error table — overflowed equally off the top and bottom with
 * nothing able to scroll. The top of the form and the submit button were both
 * simply unreachable.
 *
 * Now the dialog is a flex column that never exceeds the viewport, its body
 * scrolls, and its header and actions stay pinned. `margin: auto` centres it
 * when it fits without clipping it when it does not.
 */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 300; padding: 24px 20px;
  display: flex; justify-content: center;
  overflow-y: auto; overscroll-behavior: contain;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); max-width: 440px; width: 100%;
  margin: auto;
  display: flex; flex-direction: column;
  max-height: calc(100dvh - 48px);
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}
.modal-body {
  padding: 20px 22px;
  overflow-y: auto; overscroll-behavior: contain;
  flex: 1 1 auto; min-height: 0;
}
/* Inner panes drop their own height caps inside a dialog: the body already
   scrolls, and a scrollbar nested in a scrollbar is a trap, not a feature. */
.modal-body .json-block,
.modal-body .modal-detail,
.modal-body .reasoning-body { max-height: none; }
.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 22px; border-top: 1px solid var(--line); flex: none;
}

/* ── Auth ───────────────────────────────────────────────────────────────── */

/* The login screen is its own full-bleed page, so it must not inherit the work
   area's padding — a 100vh card inside a padded container overflowed by exactly
   that padding, which is why sign-in always had a stray scrollbar and sat a
   little above centre. */
body:not(.authed) #app { padding: 0; max-width: none; }

.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 32px; width: 100%; max-width: 380px; text-align: center;
}
.auth-logo { width: 44px; height: 44px; margin-bottom: 12px; }
.auth-title { font-size: 22px; font-weight: 700; }
.auth-sub { font-size: 13px; color: var(--muted); margin-bottom: 22px; }
.auth-hint { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.auth-form button[type=submit] { margin-top: 4px; padding: 11px; }
.auth-links { display: flex; justify-content: center; gap: 14px; }

.alert {
  display: none; font-size: 13px; padding: 10px 12px;
  border-radius: var(--radius-sm); margin-bottom: 14px; text-align: left;
}
.alert.show { display: block; }
.alert.error { background: rgba(255,90,90,.12); color: var(--err); border: 1px solid var(--err); }
.alert.warn { background: rgba(255,184,0,.12); color: var(--warn); border: 1px solid var(--warn); }
.alert.info { background: var(--panel-2); color: var(--muted); }

.google-slot { margin-top: 18px; }
.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 12px; margin-bottom: 14px;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.google-btn { display: flex; justify-content: center; }

/* ── Tabs ───────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 5px 13px; font-size: 13px;
}
.tab.active { background: var(--panel-2); color: var(--primary); border-color: var(--primary); }
.inline-field { display: flex; align-items: center; gap: 8px; }
.inline-field > span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.inline-field select { width: auto; min-width: 170px; }

/* ── Playground ─────────────────────────────────────────────────────────── */
.playground { display: grid; grid-template-columns: 1fr 260px; gap: 20px; }
.playground-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.playground-side {
  border-left: 1px solid var(--line); padding-left: 18px;
  display: flex; flex-direction: column; gap: 14px;
}
.playground-side h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600;
}

.transcript {
  min-height: 220px; max-height: 460px; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 14px;
  display: flex; flex-direction: column; gap: 14px;
}
.transcript:empty::after {
  content: "Send a prompt to start."; color: var(--muted); font-size: 14px; margin: auto;
}
.bubble { display: flex; flex-direction: column; gap: 4px; }
.bubble-role {
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
.bubble-body { white-space: pre-wrap; word-break: break-word; line-height: 1.6; }
.bubble.user .bubble-body {
  background: rgba(255,107,53,.10); border-left: 2px solid var(--primary);
  padding: 9px 12px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.bubble.error .bubble-body { color: var(--err); }

.param { display: flex; flex-direction: column; gap: 5px; }
.param-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.param-head > span { font-size: 12px; color: var(--muted); cursor: help; }
.param-head input[type=number] { width: 78px; padding: 4px 7px; font-size: 12px; }
.param input[type=range] { width: 100%; accent-color: var(--primary); padding: 0; background: none; border: 0; }

@media (max-width: 860px) {
  .playground { grid-template-columns: 1fr; }
  .playground-side { border-left: 0; border-top: 1px solid var(--line); padding-left: 0; padding-top: 16px; }
}

/* ── Metric strip (playground) ───────────────────────────────────────────── */
.metric-strip { display: flex; gap: 16px; flex-wrap: wrap; align-items: baseline; }
.metric { display: flex; flex-direction: column; line-height: 1.25; cursor: help; }
.metric-value { font-size: 13px; font-weight: 600; font-family: var(--mono); }
.metric-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}

/* The headline generation speed reads larger than the supporting breakdown. */
.metric.lead .metric-value { font-size: 20px; color: var(--ok); }
.metric.lead .metric-label { color: var(--text); }

/* ── Chart ──────────────────────────────────────────────────────────────── */
.chart { margin-top: 6px; }
.chart-legend {
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); margin-bottom: 8px;
}
.chart-legend .swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px;
}
.chart-legend .swatch.bar { background: var(--panel-2); border: 1px solid var(--line); }
.chart-legend .swatch.line { background: var(--primary); }
.chart-body { width: 100%; }
.spark { width: 100%; height: 120px; display: block; }
.spark-bar { fill: var(--panel-2); }
.spark-line { stroke: var(--primary); }
.chart-axis { display: flex; justify-content: space-between; margin-top: 4px; }

/* ── Diagnostics ────────────────────────────────────────────────────────── */
.banner {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel-2); margin-bottom: 16px;
}
.banner.ok   { border-color: var(--ok);   background: rgba(61,214,140,.08); }
.banner.warn { border-color: var(--warn); background: rgba(255,184,0,.08); }
.banner.err  { border-color: var(--err);  background: rgba(255,90,90,.08); }

.check-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.check {
  border: 1px solid var(--line); border-left-width: 3px;
  border-radius: var(--radius-sm); padding: 12px 14px; background: var(--panel-2);
}
.check.ok   { border-left-color: var(--ok); }
.check.warn { border-left-color: var(--warn); }
.check.fail { border-left-color: var(--err); }
.check-head { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.check-msg { font-size: 13px; line-height: 1.5; }

/* ── Dashboard ─────────────────────────────────────────────────────────
 *
 * The dashboard's job is to make a problem unmissable before anything is
 * read in detail, so severity is carried by colour and position rather than
 * by text the operator has to scan for.
 */

/* One verdict, legible from across a room. */
.health-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; margin-bottom: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
}
.health-bar .health-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--muted); flex: none;
}
.health-bar .health-text { font-size: 16px; font-weight: 600; }
.health-bar .health-sub { color: var(--muted); font-size: 13px; margin-left: auto; }

.health-bar.healthy  { border-color: var(--ok);   background: rgba(61,214,140,.07); }
.health-bar.healthy  .health-dot { background: var(--ok); }
.health-bar.warning  { border-color: var(--warn); background: rgba(255,184,0,.07); }
.health-bar.warning  .health-dot { background: var(--warn); }
.health-bar.critical { border-color: var(--err);  background: rgba(255,90,90,.09); }
.health-bar.critical .health-dot {
  background: var(--err);
  /* Motion only for critical: it earns attention exactly once, and using it
   * anywhere else would spend that budget on things that can wait. */
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; } }

/* Respect a stated preference for reduced motion over our attention-grabbing. */
@media (prefers-reduced-motion: reduce) {
  .health-bar.critical .health-dot { animation: none; }
}

.anomaly-list { display: flex; flex-direction: column; gap: 8px; }
.anomaly {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border-left: 3px solid var(--muted); background: var(--panel-2);
}
.anomaly.critical { border-left-color: var(--err); }
.anomaly.warning  { border-left-color: var(--warn); }
.anomaly-tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 600; padding-top: 2px; min-width: 54px; color: var(--muted);
}
.anomaly.critical .anomaly-tag { color: var(--err); }
.anomaly.warning  .anomaly-tag { color: var(--warn); }
.anomaly-msg { font-size: 14px; }
.anomaly-detail { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* A stat's colour states the verdict so the number does not have to be
 * compared against a threshold the reader is expected to remember. */
.stat.ok   .stat-value { color: var(--ok); }
.stat.warn .stat-value { color: var(--warn); }
.stat.err  .stat-value { color: var(--err); }
.stat-hint {
  font-size: 10px; color: var(--muted); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Desktop-first: this is an operations console on a wide screen, and the
 * paired panels are meant to be read side by side. */
.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 16px; align-items: start;
}
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ── Playground: reasoning, notes, thinking toggle ─────────────────────── */

/* The model's thinking, collapsed by default so the answer leads. */
.reasoning {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel-2); font-size: 13px;
}
.reasoning > summary {
  cursor: pointer; padding: 6px 10px; color: var(--muted);
  user-select: none; list-style-position: inside;
}
.reasoning > summary:hover { color: var(--text); }
.reasoning-body {
  padding: 8px 10px; border-top: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word; line-height: 1.55;
  color: var(--muted); max-height: 320px; overflow-y: auto;
}

/* A truncation/other advisory attached to a specific answer. */
.bubble-note {
  font-size: 12px; color: var(--warn);
  background: rgba(255,184,0,.1); border-radius: var(--radius-sm);
  padding: 5px 9px;
}

/* The checkbox toggle reads as a control, not body text. */
.inline-field.toggle { gap: 6px; cursor: pointer; }
.inline-field.toggle input { width: auto; margin: 0; cursor: pointer; }
.inline-field.toggle > span { color: var(--text); }

/* ── Experiment (side-by-side comparison) ──────────────────────────────── */

/* The A/B/C badge shared by variant editors and result columns. */
.variant-tag {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: var(--primary); color: #fff;
  font-weight: 700; font-size: 12px;
}

/* Variant editor cards sit in a wrapping row so up to four fit a wide screen. */
.variants { display: flex; gap: 12px; flex-wrap: wrap; }
.variant {
  flex: 1 1 240px; min-width: 220px; max-width: 340px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px; background: var(--panel-2);
  display: flex; flex-direction: column; gap: 10px;
}
.variant-head { display: flex; align-items: center; }
.vfields { display: flex; gap: 10px; flex-wrap: wrap; }
.vfield { display: flex; flex-direction: column; gap: 4px; flex: 1 1 90px; }
.vfield > span { font-size: 11px; color: var(--muted); }
.vfield input, .vfield select, .variant select { width: 100%; }
/* A 28px target rather than a 13px glyph: these are close and remove buttons,
   and they were genuinely hard to hit. */
.icon-btn {
  background: transparent; border: 0; color: var(--muted);
  padding: 0; font-size: 13px; line-height: 1; flex: none;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
}
/* Neutral by default: three of the four icon buttons in this console are
   "close", and colouring those like a delete misreads the action. */
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--panel-2); }
/* Not `.danger` — that class already paints a bordered button, which is not
   what an icon-only control should become on hover. */
.icon-btn.remove:hover:not(:disabled) { color: var(--err); background: rgba(255,90,90,.12); }

/* Results: one column per variant, equal width, compared at a glance. */
.results {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  align-items: start;
}
.result-col {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  overflow: hidden; display: flex; flex-direction: column;
}
.result-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.result-config { font-size: 11px; color: var(--muted); word-break: break-word; }
.result-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.result-text { white-space: pre-wrap; word-break: break-word; line-height: 1.55; font-size: 14px; }
.result-error { color: var(--err); font-size: 13px; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Compact per-result metric strip; tokens/sec leads. */
.mini-strip { display: flex; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.mini-stat { display: flex; flex-direction: column; }
.mini-value { font-family: var(--mono); font-weight: 600; font-size: 13px; }
.mini-stat.lead .mini-value { font-size: 18px; color: var(--ok); }
.mini-stat.warn .mini-value { color: var(--warn); }
.mini-label { font-size: 9px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* ═══════════════════════════════════════════════════════════════════════════
   Components
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Data table ─────────────────────────────────────────────────────────────
 *
 * Every list is a narrowing problem, so the toolbar (search + filters) is part
 * of the table rather than something each view rebuilds.
 */
.data-table { display: flex; flex-direction: column; gap: 10px; }

.table-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
/* Grows into spare room, but never collapses to an unusable sliver when the
   filter row wraps beside it. */
.table-search { flex: 1 1 220px; max-width: 300px; min-width: 150px; padding: 7px 10px; font-size: 13px; }
.table-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.table-filters select { width: auto; min-width: 130px; max-width: 200px; padding: 7px 9px; font-size: 13px; }

.table-body { position: relative; min-height: 60px; }
/* Bottom-right, not top-right: at the top it sat directly over the column
   headings it was obscuring the meaning of. */
.table-refreshing {
  position: absolute; bottom: 10px; right: 14px; z-index: 3;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; pointer-events: none;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
.table-refreshing .loading { padding: 5px 12px; font-size: 12px; }

/* The wrapper is the scrollport: capped in height so the header can stick to
   it, and scrolling on both axes so a twelve-column table stays reachable. */
.data-table .table-wrap {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  max-height: var(--table-max-h);
}
/* Inside a drawer the panel already scrolls; a second nested scrollport there
   would be a trap rather than a convenience. */
.drawer-body .data-table .table-wrap,
.modal-body .data-table .table-wrap { max-height: none; }

.data-table table { font-size: 13.5px; }
.data-table th {
  background: var(--panel-2); position: sticky; top: 0; z-index: 2;
  /* `border-collapse: collapse` drops a sticky cell's own border once it
     detaches, so the rule under the header is drawn as an inset shadow. */
  border-bottom: 0; box-shadow: inset 0 -1px 0 var(--line);
}
.data-table.dense td { padding: 6px 10px; }
.data-table.dense th { padding: 6px 10px; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); background: var(--line); }
th.sortable:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
th.sorted { color: var(--primary); }
.sort-arrow { margin-left: 5px; font-size: 9px; opacity: .6; }
th.sorted .sort-arrow { opacity: 1; }
/* Hint the sort affordance on hover without moving anything. */
th.sortable:not(.sorted):hover .sort-arrow { opacity: 1; }

tr.clickable { cursor: pointer; }
/* The generic row hover is 2% white, which on this panel is nearly invisible.
   A row that *does* something on click should say so. */
tbody tr.clickable:hover { background: rgba(255,255,255,.05); }
/* Outline inset, or border-collapse clips it against the neighbouring rows. */
tbody tr:focus-visible,
.table-wrap:focus-visible {
  outline: 2px solid var(--primary); outline-offset: -2px;
}
tr.selected { background: rgba(255,107,53,.07); }
.select-col { width: 34px; }
.select-col input { width: auto; margin: 0; }
/* A row flagged by its view (stale, over budget, failing) carries a left bar
   so it is findable while scanning, not only once read. */
tr.row-warn td:first-child { box-shadow: inset 2px 0 0 var(--warn); }
tr.row-err  td:first-child { box-shadow: inset 2px 0 0 var(--err); }

.table-footer {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  font-size: 12px;
}
.pager { display: flex; align-items: center; gap: 6px; }
.pager .sub { min-width: 58px; text-align: center; }

.bulk-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: rgba(255,107,53,.10); border: 1px solid var(--primary);
  font-size: 13px;
}
.bulk-bar[hidden] { display: none; }

.column-picker { position: relative; }
.column-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px; min-width: 190px;
  max-height: 320px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 12px 28px rgba(0,0,0,.45);
}
.column-menu[hidden] { display: none; }
.column-option {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 5px; font-size: 13px; cursor: pointer;
}
.column-option:hover { background: var(--panel); }
.column-option input { width: auto; margin: 0; }

/* ── Skeleton ───────────────────────────────────────────────────────────── */
.skeleton { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.skeleton-row { display: flex; gap: 10px; }
.skeleton-cell {
  flex: 1; height: 16px; border-radius: 4px;
  background: linear-gradient(90deg, var(--panel-2) 25%, var(--line) 50%, var(--panel-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton-cell { animation: none; }
}

/* ── Key/value detail lists ─────────────────────────────────────────────── */
.kv {
  display: grid; grid-template-columns: minmax(130px, auto) 1fr;
  gap: 6px 16px; font-size: 13px; align-items: baseline;
}
.kv dt { color: var(--muted); }
.kv dd { word-break: break-word; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.field-hint { font-size: 11px; color: var(--muted); line-height: 1.4; }
.field-error { font-size: 11.5px; color: var(--err); }
.field .req { color: var(--err); font-style: normal; margin-left: 3px; }
input.invalid, textarea.invalid, select.invalid { border-color: var(--err); }
.field.full { grid-column: 1 / -1; }
.checkbox-field { justify-content: center; }
.form-error {
  font-size: 13px; color: var(--err);
  background: rgba(255,90,90,.10); border: 1px solid var(--err);
  border-radius: var(--radius-sm); padding: 9px 12px;
}
.form-error[hidden] { display: none; }
.form-actions { margin-top: 4px; }
.form-dirty[hidden] { display: none; }

/* ── Drawer ─────────────────────────────────────────────────────────────── */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0); transition: background .18s ease;
  display: flex; justify-content: flex-end;
}
.drawer-overlay.open { background: rgba(0,0,0,.55); }
.drawer {
  width: min(760px, 92vw); height: 100%;
  background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .18s ease;
  box-shadow: -18px 0 44px rgba(0,0,0,.35);
}
.drawer.narrow { width: min(520px, 92vw); }
.drawer-overlay.open .drawer { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer-overlay { transition: none; }
}

.drawer-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.drawer-title { flex: 1; min-width: 0; }
.drawer-title h2 { font-size: 16px; font-weight: 600; }
.drawer-actions { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.drawer-tabs {
  display: flex; gap: 4px; padding: 10px 18px 0;
  border-bottom: 1px solid var(--line);
}
.drawer-tabs[hidden] { display: none; }
.drawer-tabs .tab { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.drawer-body {
  /* `min-height: 0` is what actually lets this scroll: without it the flex
     item refuses to shrink below its content and the panel grows past the
     drawer instead of scrolling inside it. */
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain; padding: 18px;
  display: flex; flex-direction: column; gap: 16px;
}
.drawer-body .panel { margin-bottom: 0; }
.drawer-body:focus { outline: 0; }

/* On a phone the drawer is the screen; a 8vw sliver of dimmed page behind it
   is not a useful affordance. */
@media (max-width: 640px) {
  .drawer, .drawer.narrow { width: 100%; }
  .drawer-head { padding: 14px; }
  .drawer-body { padding: 14px; }
  .drawer-tabs { padding: 10px 14px 0; overflow-x: auto; }
}

/* ── Modal extensions ───────────────────────────────────────────────────── */
.modal.wide { max-width: 820px; }
.modal-head {
  display: flex; align-items: center; gap: 12px; flex: none;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 15px; font-weight: 600; flex: 1; min-width: 0; }
.modal-detail {
  margin-top: 10px; font-size: 12.5px; color: var(--muted);
  background: var(--panel-2); border-radius: var(--radius-sm); padding: 9px 11px;
  max-height: 220px; overflow-y: auto;
}

/* ── Charts ─────────────────────────────────────────────────────────────── */
.chart-svg { width: 100%; height: 100%; display: block; }
.grid-line { stroke: var(--line); stroke-width: 1; }
.axis-label { fill: var(--muted); font-size: 10px; font-family: var(--mono); }
.chart-legend .swatch { border-radius: 2px; }

.ranked-bars { display: flex; flex-direction: column; gap: 7px; }
.ranked-row {
  display: grid; grid-template-columns: minmax(110px, 200px) 1fr auto;
  gap: 12px; align-items: center; font-size: 13px;
}
.ranked-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranked-track { height: 14px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.ranked-fill { height: 100%; background: var(--primary); border-radius: 4px; }
.ranked-fill.ok { background: var(--ok); }
.ranked-fill.warn { background: var(--warn); }
.ranked-fill.err { background: var(--err); }
.ranked-value { font-size: 12px; min-width: 62px; text-align: right; }

.sparkline { display: inline-block; vertical-align: middle; line-height: 0; }

.proportion { display: flex; flex-direction: column; gap: 6px; }
.proportion-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--panel-2); }
.proportion-seg { background: var(--primary); }
.proportion-seg.ok { background: var(--ok); }
.proportion-seg.warn { background: var(--warn); }
.proportion-seg.err { background: var(--err); }
.proportion-seg.mute { background: var(--line); }
.proportion-legend { display: flex; gap: 14px; flex-wrap: wrap; }
.proportion-legend .swatch {
  display: inline-block; width: 8px; height: 8px; border-radius: 2px;
  margin-right: 5px; background: var(--primary);
}
.proportion-legend .swatch.ok { background: var(--ok); }
.proportion-legend .swatch.warn { background: var(--warn); }
.proportion-legend .swatch.err { background: var(--err); }
.proportion-legend .swatch.mute { background: var(--line); }

/* ── JSON viewer ────────────────────────────────────────────────────────── */
.json-block {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 12px; line-height: 1.5; max-height: 340px;
  overflow: auto; white-space: pre; color: var(--text);
}

/* ── Layout grids ───────────────────────────────────────────────────────── */
.grid-3 {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 16px; align-items: start;
}
.grid-sidebar {
  display: grid; grid-template-columns: 1fr 320px;
  gap: 16px; align-items: start;
}
@media (max-width: 1280px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-sidebar { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; }
}

/* ── Notices ────────────────────────────────────────────────────────────── */
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 13px; border-radius: var(--radius-sm);
  background: var(--panel-2); border-left: 3px solid var(--line);
  font-size: 13px; line-height: 1.5;
}
.notice.warn { border-left-color: var(--warn); background: rgba(255,184,0,.07); }
.notice.err  { border-left-color: var(--err);  background: rgba(255,90,90,.08); }
.notice.info { border-left-color: var(--info-2); background: rgba(90,169,255,.07); }

/* ── Small utilities ────────────────────────────────────────────────────── */
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.dim { color: var(--muted); }
.gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }

/* Two-line table cell: the value, and the context that qualifies it. */
.cell-2 { display: flex; flex-direction: column; line-height: 1.35; }
.cell-2 .sub { font-size: 11px; }

/* ── Responsive ─────────────────────────────────────────────────────────────
 *
 * Below tablet width the rail became a horizontally-scrolling strip of sixteen
 * unlabelled glyphs — every destination reachable only by scrolling a bar and
 * guessing at an icon. It is an off-canvas drawer instead: full labels, one
 * tap to open, tap-away or Escape to dismiss.
 */
.nav-toggle { display: none; }
#nav-scrim { display: none; }

@media (max-width: 860px) {
  #nav-scrim {
    display: block;
    position: fixed; inset: 0; z-index: 45;
    background: rgba(0,0,0,.55);
    opacity: 0; pointer-events: none; transition: opacity .18s ease;
  }
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid var(--line); color: var(--text);
    padding: 6px 10px; font-size: 15px; line-height: 1; flex: none;
  }
  .nav-toggle:hover:not(:disabled) { background: var(--panel-2); }

  #sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 8px 0 32px rgba(0,0,0,.45);
  }
  body.nav-open #sidebar { transform: translateX(0); }
  body.nav-open #nav-scrim { opacity: 1; pointer-events: auto; }

  /* The collapsed-rail treatment is a desktop affordance; in the drawer the
     labels are the whole point, so undo it here. */
  #sidebar, body.sidebar-collapsed #sidebar { width: var(--sidebar-w); }
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .brand-name,
  body.sidebar-collapsed .nav-group-label,
  body.sidebar-collapsed .sidebar-user { display: revert; }
  body.sidebar-collapsed .sidebar-brand { justify-content: flex-start; padding: 14px 14px 12px; }
  body.sidebar-collapsed .nav-link { justify-content: flex-start; padding: 7px 10px; }
  body.sidebar-collapsed .sidebar-foot button { padding: 9px 15px; font-size: 13px; }

  #main, body.sidebar-collapsed #main { margin-left: 0; }
  .collapse-btn { display: none; }
  #app { padding: 14px 14px 40px; }
  #topbar { padding: 0 14px; }
  .panel { padding: 15px; }
  .page-head h1 { font-size: 18px; }
  /* On a phone the viewport is the constraint; a nested scrollport inside it
     leaves almost nothing visible. */
  .data-table .table-wrap { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  #sidebar, #nav-scrim, #main { transition: none; }
}
