/* SnapX Studio design system: tokens, base, shared components, the rail and the app shell.
   View layouts live in views.css, the harness (timeline, briefing, routing, plans) in harness.css
   and the data map chrome in map.css. Every colour below is checked by dev/ux/contrast.mjs
   (text ≥ 4.5:1 on every surface it sits on, focus ring ≥ 3:1). */

:root {
  color-scheme: dark;

  /* ── Colour: ground and surfaces ─────────────────────────────────────── */
  --bg: #0b0817;
  --aurora-1: rgba(110, 50, 200, 0.26);
  --aurora-2: rgba(170, 60, 40, 0.18);
  --aurora-3: rgba(80, 40, 160, 0.12);
  --surface-0: rgba(13, 9, 26, 0.66); /* rail and sticky bars (glass) */
  --surface-1: rgba(24, 19, 43, 0.78); /* cards and panels (glass) */
  --surface-2: #1b1531; /* menus, popovers, dialogs, toasts (solid) */
  --surface-3: #261e45; /* selected rows and pressed segments (solid) */
  --surface-inset: rgba(0, 0, 0, 0.3); /* inputs, code, wells */
  --hover: rgba(255, 255, 255, 0.055);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --overlay: rgba(6, 4, 14, 0.66);

  /* ── Colour: text ────────────────────────────────────────────────────── */
  --text: #eeeaf7;
  --text-2: #dcd7ec; /* long-form body copy inside cards */
  --muted: #a9a3c2;
  --faint: #958fb0; /* the lowest text tier: meta, hints, durations */

  /* ── Colour: brand and status (fill and line for tinted chips and banners) ── */
  --primary: #8b5cf6;
  --primary-2: #6d28d9;
  --primary-bg: #6d3ce0;
  --primary-bg-hover: #7848ec;
  --on-primary: #ffffff;
  --primary-text: #c4b5fd;
  --primary-fill: rgba(139, 92, 246, 0.15);
  --primary-line: rgba(139, 92, 246, 0.5);
  --accent: #f97316;
  --on-accent: #1a0f00;
  --accent-text: #fdba74;
  --accent-fill: rgba(249, 115, 22, 0.12);
  --accent-line: rgba(249, 115, 22, 0.45);
  --ok: #34d399;
  --ok-text: #6ee7b7;
  --ok-fill: rgba(52, 211, 153, 0.12);
  --ok-line: rgba(52, 211, 153, 0.38);
  --warn: #fbbf24;
  --warn-text: #fcd34d;
  --warn-fill: rgba(251, 191, 36, 0.12);
  --warn-line: rgba(251, 191, 36, 0.45);
  --bad: #f87171;
  --bad-text: #fca5a5;
  --bad-fill: rgba(248, 113, 113, 0.12);
  --bad-line: rgba(248, 113, 113, 0.5);
  --info: #22d3ee;
  --info-text: #a5f3fc;
  --info-fill: rgba(34, 211, 238, 0.12);
  --info-line: rgba(34, 211, 238, 0.4);
  --index-text: #fde68a; /* "⚡ index" provenance */
  --index-fill: rgba(253, 224, 71, 0.1);
  --index-line: rgba(253, 224, 71, 0.32);
  --danger-bg: #b42323;
  --on-danger: #ffffff;
  --focus: #a78bfa;

  /* ── Type: one scale for the whole app ───────────────────────────────── */
  --font: Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: Inter, "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Cascadia Mono", Consolas, ui-monospace, monospace;
  --fs-2xs: 11px; /* uppercase labels, kbd, counters */
  --fs-xs: 12px; /* meta, chips, hints */
  --fs-sm: 13px; /* secondary text, controls, tables */
  --fs-md: 14px; /* body */
  --fs-lg: 16px; /* card and panel titles */
  --fs-xl: 19px; /* section titles, briefing title */
  --fs-2xl: 24px; /* page titles */
  --fs-3xl: 32px; /* the home hero */
  --lh-tight: 1.25;
  --lh-snug: 1.4;
  --lh: 1.55;
  --fw-medium: 550;
  --fw-semibold: 650;
  --fw-bold: 750;
  --caps: 0.07em; /* letter spacing for uppercase labels */

  /* ── Space: a 4 px rhythm ───────────────────────────────────────────── */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;
  --sp-9: 56px;

  /* ── Shape, size and depth ──────────────────────────────────────────── */
  --r-xs: 6px; /* tags, kbd */
  --r-sm: 8px; /* small controls, segments */
  --r-md: 10px; /* buttons, inputs, list rows */
  --r-lg: 14px; /* cards and panels */
  --r-xl: 18px; /* hero composer, briefing, dialogs */
  --r-pill: 999px;
  --h-sm: 28px;
  --h-md: 34px;
  --h-lg: 42px;
  --shadow-1: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 10px 30px -20px rgba(0, 0, 0, 0.7);
  --shadow-2: 0 18px 50px -12px rgba(0, 0, 0, 0.8);
  --shadow-3: 0 30px 80px -20px rgba(0, 0, 0, 0.9);
  --glow-primary: 0 8px 24px -12px rgba(139, 92, 246, 0.85);
  --blur: blur(14px);

  /* ── Motion ─────────────────────────────────────────────────────────── */
  --dur-fast: 120ms; /* hover, press */
  --dur: 180ms; /* enter, expand */
  --dur-slow: 280ms; /* toasts, dialogs */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  /* ── Layout and layers ──────────────────────────────────────────────── */
  --rail-w: 264px;
  --content-w: 1240px;
  --reading-w: 900px;
  --z-menu: 30;
  --z-modal: 40;
  --z-tray: 60;
  --z-toast: 80;
  --z-skip: 100;

  /* ── Aliases kept for older names (used by other views and packages) ── */
  --panel: var(--surface-1);
  --panel-solid: #17122b;
  --panel-2: var(--hover);
  --radius: var(--r-lg);
}

/* ── Base ─────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: var(--fs-md) / var(--lh) var(--font); color: var(--text); background: var(--bg); overflow: hidden;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; font-variant-numeric: tabular-nums;
}
button, textarea, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { font-weight: var(--fw-semibold); line-height: var(--lh-tight); }
p { text-wrap: pretty; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: var(--fs-xs); }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.warn-text { color: var(--warn-text); }
.error-text { color: var(--bad-text); }
.ok-text { color: var(--ok-text); }
code { font: var(--fs-xs) var(--mono); color: #d8ccff; }
::selection { background: rgba(139, 92, 246, 0.45); color: #fff; }
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.16) transparent; }

/* ── Accessibility ───────────────────────────────────────────────────── */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link {
  position: absolute; left: var(--sp-3); top: -60px; z-index: var(--z-skip); padding: var(--sp-2) 14px; border-radius: var(--r-md);
  background: var(--surface-2); border: 2px solid var(--focus); color: var(--text); text-decoration: none; font-weight: var(--fw-semibold);
}
.skip-link:focus { top: var(--sp-3); }
/* One clear, solid focus outline everywhere (≥ 3:1 against every surface). */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
main:focus-visible, .transcript:focus-visible { outline-offset: -2px; }
/* Headings and regions that only receive focus from script (dialog titles, the main landmark) show no ring. */
h1[tabindex="-1"]:focus-visible, h2[tabindex="-1"]:focus-visible, h3[tabindex="-1"]:focus-visible, main[tabindex="-1"]:focus:not(:focus-visible) { outline: none; }
kbd {
  display: inline-flex; align-items: center; min-width: 18px; height: 18px; padding: 0 5px; justify-content: center;
  font: 500 var(--fs-2xs) var(--mono); border-radius: var(--r-xs); border: 1px solid var(--line-strong); border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.06); color: var(--text); white-space: nowrap;
}

/* ── Icons (inline SVG sprite in index.html; ui.js icon()) ───────────── */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 24px; height: 24px; }

/* ── Buttons: primary, secondary, ghost, danger; small, default, large ── */
.btn, .primary-btn, .ghost-btn, .secondary-btn, .quiet-btn, .danger-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--h-md); padding: 0 14px;
  border-radius: var(--r-md); border: 1px solid transparent; font-size: var(--fs-sm); font-weight: var(--fw-semibold); line-height: 1.2;
  white-space: nowrap; text-decoration: none; color: var(--text); background: none; user-select: none;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:active:not(:disabled), .primary-btn:active:not(:disabled), .ghost-btn:active:not(:disabled), .secondary-btn:active:not(:disabled), .danger-btn:active:not(:disabled) { transform: translateY(1px); }
/* Primary: one per view, the action that moves work forward. */
.primary-btn, .btn-primary {
  background: var(--primary-bg); color: var(--on-primary); border-color: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), var(--glow-primary);
}
.primary-btn:hover:not(:disabled), .btn-primary:hover:not(:disabled) { background: var(--primary-bg-hover); }
/* Secondary (the historic name is ghost-btn): bordered, quiet fill. */
.ghost-btn, .secondary-btn { background: rgba(255, 255, 255, 0.045); border-color: var(--line-strong); }
.ghost-btn:hover:not(:disabled), .secondary-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.09); border-color: rgba(255, 255, 255, 0.24); }
/* Ghost: no frame until hovered. */
.quiet-btn { color: var(--muted); }
.quiet-btn:hover:not(:disabled) { color: var(--text); background: var(--hover); }
/* Danger: solid for destructive confirmations, red text on secondary buttons otherwise. */
.danger-btn { background: var(--danger-bg); color: var(--on-danger); }
.danger-btn:hover:not(:disabled) { background: #c42a2a; }
.ghost-btn.danger, .quiet-btn.danger, .icon-btn.danger, .link-btn.danger, .danger { color: var(--bad-text); }
.ghost-btn.danger:hover:not(:disabled) { border-color: var(--bad-line); background: var(--bad-fill); }
.primary-btn:disabled, .ghost-btn:disabled, .secondary-btn:disabled, .quiet-btn:disabled, .danger-btn:disabled, .btn:disabled { opacity: 0.45; box-shadow: none; }
.small-btn { min-height: var(--h-sm); padding: 0 10px; font-size: var(--fs-xs); border-radius: var(--r-sm); gap: 5px; }
.large-btn { min-height: var(--h-lg); padding: 0 18px; font-size: var(--fs-md); }
a.ghost-btn, a.primary-btn, a.link-btn { text-decoration: none; }
.link-btn {
  display: inline; background: none; border: 0; padding: 0; color: var(--primary-text); font-weight: var(--fw-medium);
  cursor: pointer; border-radius: 4px; text-decoration: none; text-underline-offset: 3px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn .icon { vertical-align: -3px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 28px; height: 28px; padding: 0 6px;
  background: none; border: 1px solid transparent; border-radius: var(--r-sm); color: var(--muted);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--hover); }
.icon-btn:disabled { opacity: 0.35; }
.btn-label { min-width: 0; }

/* ── Inputs ──────────────────────────────────────────────────────────── */
label { display: grid; gap: 5px; font-size: var(--fs-sm); color: var(--muted); font-weight: var(--fw-medium); }
/* :where() keeps these defaults at zero specificity, so any component class can override them. */
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"])), :where(select), :where(textarea) {
  min-height: var(--h-md); padding: 6px 11px; color: var(--text); background: var(--surface-inset);
  border: 1px solid var(--line-strong); border-radius: var(--r-md); outline: 0;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
:where(textarea) { resize: vertical; line-height: var(--lh); padding-block: 8px; }
:where(select) {
  appearance: none; padding-right: 30px; cursor: pointer;
  background: var(--surface-inset) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a9a3c2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 9px center / 14px;
}
select option { background: var(--surface-2); color: var(--text); }
:where(input, select, textarea):hover:not(:focus):not(:disabled) { border-color: rgba(255, 255, 255, 0.24); }
/* Text fields show focus with a solid border and a soft ring (component classes override this). */
input:focus, select:focus-visible, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.22); }
input[type="checkbox"]:focus, input[type="radio"]:focus { box-shadow: none; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input::placeholder, textarea::placeholder { color: var(--faint); opacity: 1; }
input[type="search"]::-webkit-search-cancel-button { filter: invert(0.7); }
.check { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--muted); grid-auto-flow: column; }
.input-icon { position: relative; display: flex; align-items: center; }
.input-icon > .icon { position: absolute; left: 11px; color: var(--faint); pointer-events: none; }
.input-icon > input { padding-left: 34px; width: 100%; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--sp-3); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }

/* ── Chips, badges, tags and pills: one metric, colour by tone ──────── */
.chip, .tag, .pill, .env, .risk, .stage-pill, .src-badge, .pm-tag, .kind-tag, .prov, .ps-writes, .map-kind {
  display: inline-flex; align-items: center; gap: 4px; min-height: 20px; padding: 0 8px; border-radius: var(--r-pill);
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); line-height: 1.2; white-space: nowrap; border: 1px solid transparent; vertical-align: middle;
}
.chip, .tag, .pm-tag { background: rgba(255, 255, 255, 0.07); color: var(--muted); }
.chip-primary, .tone-primary { background: var(--primary-fill); color: var(--primary-text); border-color: var(--primary-line); }
.chip-accent, .tag-custom { background: var(--accent-fill); color: var(--accent-text); border-color: transparent; }
.chip-ok { background: var(--ok-fill); color: var(--ok-text); border-color: var(--ok-line); }
.chip-warn { background: var(--warn-fill); color: var(--warn-text); border-color: var(--warn-line); }
.chip-bad { background: var(--bad-fill); color: var(--bad-text); border-color: var(--bad-line); }
.env { text-transform: uppercase; letter-spacing: 0.04em; font-weight: var(--fw-bold); font-size: 10.5px; padding: 0 7px; }
.env-dev { color: var(--ok-text); background: var(--ok-fill); border-color: var(--ok-line); }
.env-test { color: var(--warn-text); background: var(--warn-fill); border-color: var(--warn-line); }
.env-prod { color: var(--bad-text); background: var(--bad-fill); border-color: var(--bad-line); }
.pill { font-weight: var(--fw-bold); }
.pill-ok, .pill-active, .pill-approve, .pill-approve_with_edits { background: var(--ok-fill); color: var(--ok-text); }
.pill-denied, .pill-cancelled, .pill-reject { background: var(--bad-fill); color: var(--bad-text); }
.pill-error, .pill-on_hold, .pill-defer, .pill-request_changes, .pill-rework { background: var(--warn-fill); color: var(--warn-text); }
.pill-completed { background: var(--primary-fill); color: var(--primary-text); }
.badge {
  margin-left: auto; display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--r-pill); background: var(--accent); color: var(--on-accent); font-size: var(--fs-2xs); font-weight: var(--fw-bold); line-height: 1;
}
.count { font-size: var(--fs-2xs); color: var(--faint); font-weight: var(--fw-semibold); }

/* ── Cards and panels ────────────────────────────────────────────────── */
.panel {
  background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-4) 18px;
  backdrop-filter: var(--blur); box-shadow: var(--shadow-1);
}
.panel-head { display: flex; align-items: center; gap: var(--sp-2); min-height: 24px; }
.panel-title { margin: 0; font-size: var(--fs-lg); }
.section-label, .bf-sub {
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); letter-spacing: var(--caps); text-transform: uppercase; color: var(--faint);
}
.interactive { cursor: pointer; transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.interactive:hover { border-color: var(--primary-line); }

/* ── Segmented controls and tabs ─────────────────────────────────────── */
.seg { display: inline-flex; align-items: center; gap: 2px; padding: 3px; background: var(--surface-inset); border: 1px solid var(--line); border-radius: var(--r-md); max-width: 100%; }
.seg-wrap { flex-wrap: wrap; }
.seg-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 11px; border: 0; border-radius: 7px; background: none;
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--muted); white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-selected="true"], .seg-btn[aria-pressed="true"], .seg-btn[aria-checked="true"] { background: var(--surface-3); color: #fff; box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.35); }
.seg-btn .count:not(:empty) { margin-left: 2px; min-width: 18px; height: 18px; display: inline-grid; place-items: center; background: var(--accent); color: var(--on-accent); border-radius: var(--r-pill); padding: 0 5px; font-weight: var(--fw-bold); }

/* ── Tables ──────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
.data-table, .audit { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.data-table { margin: var(--sp-1) 0 var(--sp-3); }
.data-table th, .audit th {
  text-align: left; padding: 8px 12px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--muted);
  background: rgba(255, 255, 255, 0.035); position: sticky; top: 0; white-space: nowrap;
}
.data-table td, .audit td { padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:hover td, .audit tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
.kv-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); margin: var(--sp-2) 0; }
.kv-table th { text-align: left; color: var(--muted); font-weight: var(--fw-semibold); width: 30%; padding: 5px 12px 5px 0; vertical-align: top; }
.kv-table td { padding: 5px 0; overflow-wrap: anywhere; }

/* ── Empty, loading (skeleton) and error states ──────────────────────── */
.empty-state {
  display: grid; justify-items: center; gap: 6px; padding: var(--sp-7) var(--sp-5); text-align: center; color: var(--muted);
  border: 1px dashed var(--line-strong); border-radius: var(--r-lg); list-style: none; background: rgba(255, 255, 255, 0.015);
}
.empty-state .es-icon { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: var(--sp-1); border-radius: 12px; background: var(--primary-fill); color: var(--primary-text); }
.empty-state .es-title { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text); }
.empty-state .es-text { margin: 0; max-width: 460px; font-size: var(--fs-sm); color: var(--muted); }
.empty-state .es-action { margin-top: var(--sp-2); display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }
.empty-state.compact { padding: var(--sp-5) var(--sp-4); }
.big-empty { padding: var(--sp-9) var(--sp-5); }
.error-state { border-style: solid; border-color: var(--bad-line); background: var(--bad-fill); }
.error-state .es-icon { background: rgba(248, 113, 113, 0.18); color: var(--bad-text); }
.error-state .es-text { color: var(--text-2); }
.skeleton { display: grid; gap: var(--sp-2); list-style: none; }
.skel {
  display: block; height: 12px; border-radius: var(--r-xs);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.11) 40%, rgba(255, 255, 255, 0.05) 80%) 0 0 / 300% 100%;
  animation: shimmer 1.4s var(--ease-in-out) infinite;
}
.skel-row { display: flex; align-items: center; gap: var(--sp-3); padding: 12px 14px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-1); }
.skel-card { display: grid; gap: 10px; padding: var(--sp-4) 18px; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--surface-1); }
.skel-avatar { width: 28px; height: 28px; border-radius: 50%; flex: none; }
.skel-lines { flex: 1; display: grid; gap: 7px; }
.skel.w-30 { width: 30%; } .skel.w-45 { width: 45%; } .skel.w-60 { width: 60%; } .skel.w-80 { width: 80%; } .skel.w-100 { width: 100%; }
.skel.h-lg { height: 18px; } .skel.h-xl { height: 26px; } .skel.h-block { height: 64px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ── Toasts ──────────────────────────────────────────────────────────── */
.toasts { position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: var(--z-toast); display: grid; gap: var(--sp-2); justify-items: end; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; max-width: min(440px, calc(100vw - 32px)); padding: 10px 14px 10px 12px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line-strong); box-shadow: var(--shadow-2); font-size: var(--fs-sm); font-weight: var(--fw-medium);
  pointer-events: auto; animation: toast-in var(--dur-slow) var(--ease); transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
}
.toast::before { content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--ok); }
.toast-bad { border-color: var(--bad-line); }
.toast-bad::before { background: var(--bad); }
.toast-warn::before { background: var(--warn); }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

/* ── Dialogs, sheets and popovers share one surface ──────────────────── */
.dialog-backdrop, .tray-backdrop { position: fixed; inset: 0; z-index: var(--z-tray); background: var(--overlay); backdrop-filter: blur(2px); animation: fade-in var(--dur) var(--ease); }
.dialog-backdrop { display: grid; justify-items: center; align-items: start; padding: 12vh var(--sp-4) var(--sp-4); }
.dialog {
  width: min(640px, 100%); max-height: 72vh; display: flex; flex-direction: column; border-radius: var(--r-xl); overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line-strong); box-shadow: var(--shadow-3); animation: pop-in var(--dur) var(--ease);
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: var(--fs-lg); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(-6px) scale(0.985); } }

/* ── Aurora ground and the app shell ─────────────────────────────────── */
.aurora {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(900px 600px at 12% 8%, var(--aurora-1), transparent 60%),
    radial-gradient(800px 600px at 92% 95%, var(--aurora-2), transparent 60%),
    radial-gradient(700px 500px at 70% 20%, var(--aurora-3), transparent 60%);
}
.app { position: relative; z-index: 1; display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.stage { position: relative; min-width: 0; min-height: 0; height: 100%; display: flex; flex-direction: column; }
.banner {
  display: flex; align-items: center; gap: 10px; margin: var(--sp-3) var(--sp-6) 0; padding: 10px 14px; border-radius: var(--r-md); font-size: var(--fs-sm);
  background: var(--warn-fill); border: 1px solid var(--warn-line); color: var(--text);
}

/* ── Rail ────────────────────────────────────────────────────────────── */
.rail {
  display: flex; flex-direction: column; gap: 2px; min-height: 0; padding: 14px 10px 10px;
  background: var(--surface-0); border-right: 1px solid var(--line); backdrop-filter: var(--blur); overflow-y: auto;
}
.rail-top { display: flex; align-items: center; gap: var(--sp-2); padding: 0 2px 10px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; background: none; border: 0; padding: 2px; text-align: left; border-radius: var(--r-md); }
.logo-chip { background: #fff; border-radius: 9px; padding: 4px 7px; display: inline-flex; flex: none; box-shadow: 0 4px 18px rgba(139, 92, 246, 0.25); }
.logo-chip img { height: 24px; display: block; }
.brand-text { font-family: var(--font-display); font-weight: var(--fw-semibold); font-size: 15px; letter-spacing: 0.1px; white-space: nowrap; }
.rail-tools { display: flex; gap: 2px; }
.rail-heading, .nav-heading {
  margin: 14px 10px 4px; font-size: var(--fs-2xs); font-weight: var(--fw-semibold); letter-spacing: var(--caps); text-transform: uppercase; color: var(--faint);
}
.nav-heading:first-child { margin-top: 6px; }

/* Command bar button ("Search or jump to… Ctrl K") */
.cmd-btn {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-height: var(--h-md); padding: 0 10px; margin-bottom: 2px;
  border-radius: var(--r-md); border: 1px solid var(--line); background: rgba(255, 255, 255, 0.035); color: var(--muted); font-size: var(--fs-sm); text-align: left;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.cmd-btn:hover { color: var(--text); border-color: var(--line-strong); background: var(--hover); }
.cmd-btn .cmd-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-btn kbd { background: transparent; }

.nav { display: grid; gap: 1px; }
.nav-item, .inbox-btn {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--h-md); padding: 0 10px; border-radius: var(--r-sm);
  text-align: left; background: none; border: 0; font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--text-2);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item:hover, .inbox-btn:hover { background: var(--hover); color: var(--text); }
.nav-icon { display: inline-grid; place-items: center; width: 18px; flex: none; color: var(--muted); }
.nav-icon .icon { width: 17px; height: 17px; }
.nav-label, .inbox-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item[aria-current="page"], .nav-item[aria-current="true"] { background: var(--primary-fill); color: #fff; }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.nav-item[aria-current="page"] .nav-icon { color: var(--primary-text); }
.inbox-btn.has-items { background: var(--accent-fill); color: var(--text); }
.inbox-btn.has-items .nav-icon { color: var(--accent-text); }

.team, .instances { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; }
.member, .instance {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: var(--r-sm); min-height: 40px;
  background: none; border: 0; text-align: left; transition: background-color var(--dur-fast) var(--ease);
}
.member:hover, .instance:hover { background: var(--hover); }
.member[aria-current="true"] { background: var(--primary-fill); }
.member > span:last-child { min-width: 0; flex: 1; }
.member-name, .instance-name { display: block; font-weight: var(--fw-semibold); font-size: var(--fs-sm); line-height: var(--lh-tight); }
.member-state, .instance-ops { display: block; font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member[data-state="working"] .member-state { color: var(--primary-text); }
.member[data-state="waiting"] .member-state { color: var(--warn-text); }
.member[data-state="error"] .member-state { color: var(--bad-text); }
.instance { justify-content: space-between; }
.instances li { list-style: none; }
.idx-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); margin-right: 6px; vertical-align: 1px; }
.idx-dot.on { background: #fde047; box-shadow: 0 0 8px rgba(253, 224, 71, 0.6); }

.rail-foot { margin-top: auto; padding: var(--sp-3) 8px 2px; font-size: var(--fs-xs); color: var(--muted); display: flex; align-items: center; gap: var(--sp-2); border-top: 1px solid var(--line); }
.rail-foot #engine { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.engine-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.engine-dot[data-state="ok"] { background: var(--ok); box-shadow: 0 0 8px rgba(52, 211, 153, 0.7); }
.engine-dot[data-state="warn"] { background: var(--warn); }
.engine-dot[data-state="bad"] { background: var(--bad); }
.keys-btn { margin-left: auto; }
.rail-mobile { display: none; }

/* ── Bot avatar ──────────────────────────────────────────────────────── */
.avatar-wrap { position: relative; display: inline-flex; flex: none; }
.bot { width: 38px; height: 38px; display: block; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35)); }
.avatar-lg .bot { width: 64px; height: 64px; }
.avatar-md .bot { width: 40px; height: 40px; }
.avatar-sm .bot { width: 28px; height: 28px; }
.avatar-xs .bot { width: 20px; height: 20px; filter: none; }
.status-dot { position: absolute; right: -1px; bottom: 1px; width: 10px; height: 10px; border-radius: 50%; background: #6b7280; border: 2px solid var(--panel-solid); }
[data-state="idle"] .status-dot, .status-dot[data-state="idle"] { background: var(--ok); }
[data-state="working"] .status-dot, .status-dot[data-state="working"] { background: #a78bfa; animation: pulse 1.2s ease-in-out infinite; }
[data-state="waiting"] .status-dot, .status-dot[data-state="waiting"] { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
[data-state="error"] .status-dot, .status-dot[data-state="error"] { background: var(--bad); }
.bot .eye { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
[data-state="working"] .bot .antenna, [data-state="waiting"] .bot .antenna { animation: glow 0.9s ease-in-out infinite alternate; }
[data-state="working"] .bot .eye { fill: #e9d5ff; }
.avatar-stack { display: inline-flex; align-items: center; flex: none; }
.avatar-stack .avatar-wrap + .avatar-wrap { margin-left: -8px; }
.stack-more { font-size: var(--fs-2xs); color: var(--muted); margin-left: 4px; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.6); } 50% { box-shadow: 0 0 0 5px rgba(167, 139, 250, 0); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.15); } }
@keyframes glow { from { opacity: 0.45; } to { opacity: 1; } }

/* ── Narrow screens: the rail becomes a two-row top bar ───────────────── */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .rail { flex-direction: column; gap: 6px; padding: 8px 12px 6px; border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .rail-top { padding: 0; }
  .brand-text { display: none; }
  .rail-mobile { display: flex; gap: 4px; align-items: center; }
  .rail .cmd-btn, .rail .inbox-btn.rail-wide, .rail-heading, .nav-heading, .team, .instances, .rail-foot { display: none; }
  .rail .nav {
    display: flex; gap: 4px; margin: 0 -12px; padding: 0 12px 2px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity;
    /* A soft fade at the right edge says "there is more". */
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }
  .rail .nav::-webkit-scrollbar { display: none; }
  .rail .nav-group { display: contents; }
  .rail .nav-item { width: auto; flex: none; min-height: 32px; padding: 0 11px; gap: 7px; border-radius: var(--r-pill); font-size: var(--fs-sm); scroll-snap-align: start; }
  .rail .nav-item[aria-current="page"]::before { display: none; }
  .rail .nav-item[aria-current="page"] { box-shadow: inset 0 0 0 1px var(--primary-line); }
  .rail .nav-item .badge { margin-left: 2px; }
  .banner { margin-inline: var(--sp-3); }
  .toasts { left: var(--sp-3); right: var(--sp-3); bottom: var(--sp-3); justify-items: stretch; }
}
.rail-mobile .icon-btn { width: 36px; height: 36px; position: relative; }
.rail-mobile .badge { position: absolute; top: 1px; right: 0; margin: 0; min-width: 16px; height: 16px; font-size: 10px; }

/* Reduced motion: static states instead of pulses, blinks, shimmer and slides. */
@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur: 0ms; --dur-slow: 0ms; }
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .braille::after { content: "\2026" !important; }
  .skel { background: rgba(255, 255, 255, 0.07); }
}
