/*
 * AgentVisor AI console.
 * Design system tuned for a 2026 governance console: monochrome + one accent,
 * typography-first, radius 6/8/12, motion 100–160 ms.
 */

:root {
  color-scheme: light dark;

  /* type scale */
  --t-title: 22px;
  --t-section: 15px;
  --t-body: 14px;
  --t-sec: 13px;
  --t-min: 12px;
  --t-mono: 12.5px;

  /* spacing (4px grid) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;

  /* radii */
  --r-sm: 4px;
  --r: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-full: 999px;

  /* light */
  --canvas: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-hover: #f4f4f5;
  --border: #e6e6e9;
  --border-strong: #d4d4d8;
  --fg: #0f0f13;
  --fg-2: #52525b;
  --fg-3: #6d6d76;
  --fg-4: #a1a1aa;
  --accent: #0a5c8b;
  --accent-2: #0d78b3;
  --accent-hover: #084264;
  --accent-fg: #ffffff;
  --accent-bg: rgba(10, 92, 139, 0.09);
  --accent-border: rgba(10, 92, 139, 0.25);
  --success: #166534;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --success-solid: #16a34a; --solid-fg: #ffffff;
  --warning: #92400e;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --danger: #991b1b;
  --danger-solid: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --shadow-xs: 0 1px 2px 0 rgba(0,0,0,0.04);
  --shadow-sm: 0 2px 6px -1px rgba(0,0,0,0.06), 0 1px 2px -1px rgba(0,0,0,0.03);
  --shadow-md: 0 6px 16px -4px rgba(0,0,0,0.12), 0 2px 6px -2px rgba(0,0,0,0.06);
  --shadow-lg: 0 20px 40px -8px rgba(0,0,0,0.18), 0 4px 10px -2px rgba(0,0,0,0.06);
  --shadow-focus: 0 0 0 3px rgba(10,92,139,0.18);

  --code-bg: #16181d;
  --code-border: #2a2e36;
  --code-fg: #e6e8ec;
  --code-muted: #8b93a1;
  --tok-key: #d18ac5;
  --tok-str: #a5cef5;
  --tok-num: #e59b7c;
  --tok-comment: #7a8290;

  --topbar-h: 52px;
  --sidebar-w: 232px;
  --max: 1240px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #0a0a0c;
    --surface: #131317;
    --surface-2: #17171b;
    --surface-hover: #1e1e23;
    --border: #26262b;
    --border-strong: #363640;
    --fg: #f2f2f4;
    --fg-2: #a5a5ae;
    --fg-3: #b0b0b8;
    --fg-4: #5a5a63;
    --accent: #7cb8dc;
    --accent-2: #99cbea;
    --accent-hover: #a8d3ee;
    --accent-fg: #0a0c10;
    --accent-bg: rgba(124,184,220,0.10);
    --accent-border: rgba(124,184,220,0.32);
    --success: #6ecf8e;
    --success-bg: rgba(110,207,142,0.1);
    --success-border: rgba(110,207,142,0.35);
    --success-solid: #6ecf8e; --solid-fg: #0a0c10;
    --warning: #eab566;
    --warning-bg: rgba(234,181,102,0.1);
    --warning-border: rgba(234,181,102,0.35);
    --danger: #e07b60;
    --danger-solid: #e07b60;
    --danger-bg: rgba(224,123,96,0.1);
    --danger-border: rgba(224,123,96,0.35);
    --shadow-xs: 0 1px 2px 0 rgba(0,0,0,0.4);
    --shadow-sm: 0 2px 6px -1px rgba(0,0,0,0.4), 0 1px 2px -1px rgba(0,0,0,0.3);
    --shadow-md: 0 6px 16px -4px rgba(0,0,0,0.5), 0 2px 6px -2px rgba(0,0,0,0.3);
    --shadow-lg: 0 20px 40px -8px rgba(0,0,0,0.6), 0 4px 10px -2px rgba(0,0,0,0.4);
    --shadow-focus: 0 0 0 3px rgba(124,184,220,0.24);
  }
}

[data-theme="light"] {
  color-scheme: light;
  --canvas: #f7f7f8; --surface: #ffffff; --surface-2: #fafafa; --surface-hover: #f4f4f5;
  --border: #e6e6e9; --border-strong: #d4d4d8;
  --fg: #0f0f13; --fg-2: #52525b; --fg-3: #6d6d76; --fg-4: #a1a1aa;
  --accent: #0a5c8b; --accent-2: #0d78b3; --accent-hover: #084264; --accent-fg: #ffffff;
  --accent-bg: rgba(10,92,139,0.09); --accent-border: rgba(10,92,139,0.25);
  --success: #166534; --success-bg: #f0fdf4; --success-border: #bbf7d0; --success-solid: #16a34a; --solid-fg: #ffffff;
  --warning: #92400e; --warning-bg: #fffbeb; --warning-border: #fde68a;
  --danger: #991b1b; --danger-solid: #dc2626; --danger-bg: #fef2f2; --danger-border: #fecaca;
  --shadow-focus: 0 0 0 3px rgba(10,92,139,0.18);
}
[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0a0a0c; --surface: #131317; --surface-2: #17171b; --surface-hover: #1e1e23;
  --border: #26262b; --border-strong: #363640;
  --fg: #f2f2f4; --fg-2: #a5a5ae; --fg-3: #b0b0b8; --fg-4: #5a5a63;
  --accent: #7cb8dc; --accent-2: #99cbea; --accent-hover: #a8d3ee; --accent-fg: #0a0c10;
  --accent-bg: rgba(124,184,220,0.10); --accent-border: rgba(124,184,220,0.32);
  --success: #6ecf8e; --success-bg: rgba(110,207,142,0.1); --success-border: rgba(110,207,142,0.35); --success-solid: #6ecf8e; --solid-fg: #0a0c10;
  --warning: #eab566; --warning-bg: rgba(234,181,102,0.1); --warning-border: rgba(234,181,102,0.35);
  --danger: #e07b60; --danger-solid: #e07b60; --danger-bg: rgba(224,123,96,0.1); --danger-border: rgba(224,123,96,0.35);
  --shadow-focus: 0 0 0 3px rgba(124,184,220,0.24);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--canvas);
  color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  font-feature-settings: "cv11", "ss01", "ss03";
}
body.locked { overflow: hidden; }

a { color: var(--accent); text-decoration: none; }
/* Links inside flowing text must be distinguishable without color
   alone (axe link-in-text-block, WCAG 1.4.1) — underline them. */
.link-inline { text-decoration: underline; text-underline-offset: 2px; }
/* Settings key/value grids. Fixed 140px label column + unwrappable
   values (emails, org ids, key fingerprints) overflowed the card on
   narrow phones — grid children need min-width:0 and long tokens need
   a break opportunity; below 420px the label column shrinks. */
.kv-grid { display: grid; grid-template-columns: 140px 1fr; gap: 5px 12px; font-size: 13px; }
.kv-grid dt { color: var(--fg-3); }
.kv-grid dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 420px) {
  .kv-grid { grid-template-columns: 100px 1fr; }
}
/* Data-retention form grid: the 200px label column pushed the
   input+days row past the card edge at phone widths — stack instead. */
.ret-grid { display: grid; grid-template-columns: 200px 1fr; gap: 12px 16px; font-size: 13px; align-items: center; }
@media (max-width: 480px) {
  .ret-grid { grid-template-columns: 1fr; gap: 4px 0; }
  .ret-grid > div { margin-bottom: 8px; }
}
a:hover { text-decoration: underline; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }

/* Visible focus rings only for keyboard users (not mouse click). Applies
 * everywhere we haven't already defined a stronger focus style. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
code, pre, .mono {
  font-family: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: var(--t-mono);
  font-feature-settings: "zero", "cv02";
}
.tabular { font-variant-numeric: tabular-nums; }

/* ============================================================
 * AUTH (login / signup) — split screen
 * ============================================================ */

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 1fr;
}
@media (max-width: 900px) { .auth-shell { grid-template-columns: 1fr; } .auth-panel { display: none; } }

.auth-form {
  padding: var(--s-8) var(--s-6);
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  background: var(--surface);
}
.auth-form-inner { width: 100%; max-width: 380px; }
.auth-brand {
  display: flex; align-items: center; gap: var(--s-2);
  margin-bottom: var(--s-8);
  font-weight: 600; font-size: 15px;
  color: var(--fg);
}
.auth-brand-mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  object-fit: contain;
  display: block;
}
.auth-form h1 { font-size: 24px; margin: 0 0 var(--s-1); font-weight: 600; letter-spacing: -0.01em; }
.auth-form .sub { color: var(--fg-2); margin: 0 0 var(--s-6); font-size: var(--t-body); }
.auth-form form { display: flex; flex-direction: column; gap: var(--s-3); }
.auth-form .field { display: flex; flex-direction: column; gap: 5px; }
.auth-form label { font-size: var(--t-sec); color: var(--fg-2); font-weight: 500; }
.auth-form input {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  border-radius: var(--r);
  font-size: var(--t-body);
  font-family: inherit;
  transition: border-color 100ms, box-shadow 100ms;
}
.auth-form input:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow-focus); }
/* Chrome/Safari autofill paints its own opaque yellow/white background,
   which in dark mode floodlights the login card and clashes with the
   theme tokens. -webkit-box-shadow inset is the standard override (the
   UA background can't be set directly); -webkit-text-fill-color themes
   the autofilled text itself. */
.auth-form input:-webkit-autofill,
.modal input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--surface) inset;
  -webkit-text-fill-color: var(--fg);
  caret-color: var(--fg);
  transition: background-color 9999s ease-out; /* stall the UA flash */
}
.auth-form button.primary {
  padding: 10px 14px;
  border: 0;
  border-radius: var(--r);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
  margin-top: var(--s-2);
  transition: opacity 100ms, transform 60ms, background 100ms;
}
.auth-form button.primary:hover { background: var(--accent-hover); opacity: 1; }
.auth-form button.primary:active { transform: translateY(1px); }
.auth-form button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-form .sso {
  display: flex; flex-direction: column; gap: var(--s-2);
  margin-bottom: var(--s-5);
}
.auth-form .sso button {
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  border-radius: var(--r);
  font-size: var(--t-body);
  font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: var(--s-2);
  transition: background 80ms;
}
.auth-form .sso button:hover { background: var(--surface-hover); }
.auth-form .sso button svg { width: 16px; height: 16px; }
.auth-form .divider {
  display: flex; align-items: center; gap: var(--s-3);
  color: var(--fg-3); font-size: var(--t-min);
  margin-bottom: var(--s-4);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.auth-form .divider::before, .auth-form .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.auth-alt {
  margin-top: var(--s-4);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
  font-size: var(--t-sec);
  color: var(--fg-2);
  text-align: center;
}
.auth-alt a { color: var(--fg); font-weight: 500; }
.auth-err {
  padding: var(--s-2) var(--s-3);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  border-radius: var(--r);
  font-size: var(--t-sec);
}
/* R121 F2 / F1: informational (non-error) banner rendered by
   renderAuthWithProviders when the user was bounced here by
   the OAuth MFA gate or the /invites/accept requiresLogin
   path. Same visual weight as .auth-err but blue/neutral so
   it doesn't read as a failure. */
.auth-note {
  padding: var(--s-2) var(--s-3);
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--fg);
  border-radius: var(--r);
  font-size: var(--t-sec);
  margin-bottom: var(--s-3);
}
.mock-badge {
  margin-top: var(--s-4);
  padding: 6px var(--s-3);
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  border-radius: var(--r);
  font-size: var(--t-min);
  text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.mock-badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}

/* Right-side product panel with animated event stream */
.auth-panel {
  background: #0a0d14;
  color: #e6e8ec;
  padding: var(--s-8);
  display: flex; flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.auth-panel::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(1200px 700px at 100% 0%, rgba(124,184,220,0.20), transparent 60%),
    radial-gradient(900px 500px at 0% 100%, rgba(124,184,220,0.10), transparent 60%);
}
.auth-panel .panel-inner { position: relative; max-width: 480px; }
.auth-panel h2 {
  font-size: 26px; font-weight: 600; margin: 0 0 var(--s-3);
  letter-spacing: -0.02em; line-height: 1.15;
}
.auth-panel p { color: #a0a8b6; font-size: 15px; margin: 0 0 var(--s-6); line-height: 1.55; }
.auth-panel .demo-stream {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  backdrop-filter: blur(8px);
}
.auth-panel .demo-stream .row {
  display: grid; grid-template-columns: 48px 1fr auto; gap: var(--s-2);
  padding: 6px 0;
  font-size: 12.5px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  animation: fadeInUp 0.4s cubic-bezier(.22,1,.36,1) backwards;
}
.auth-panel .demo-stream .row:last-child { border-bottom: 0; }
.auth-panel .demo-stream .seq { color: #6a7280; }
.auth-panel .demo-stream .msg { color: #d0d4de; }
.auth-panel .demo-stream .msg b { color: #f0f2f6; font-weight: 500; }
.auth-panel .demo-stream .msg .blk { color: #f0906a; font-weight: 500; }
.auth-panel .demo-stream .msg .ok { color: #6ecf8e; font-weight: 500; }
.auth-panel .demo-stream .t { color: #6a7280; font-variant-numeric: tabular-nums; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============================================================
 * APP SHELL
 * ============================================================ */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "topbar topbar" "sidebar main";
  min-height: 100vh;
}
/* Role preview adds a full-width banner row above the topbar. */
.app-shell.has-preview {
  grid-template-rows: auto var(--topbar-h) 1fr;
  grid-template-areas: "pbanner pbanner" "topbar topbar" "sidebar main";
}
.preview-banner {
  grid-area: pbanner;
  display: flex; align-items: center; gap: var(--s-2);
  padding: 6px var(--s-4);
  background: var(--warning-bg, var(--accent-bg));
  border-bottom: 1px solid var(--border);
  color: var(--fg); font-size: var(--t-sec);
}
.preview-banner .btn { margin-left: auto; padding: 3px 10px; font-size: 11.5px; }

.topbar {
  grid-area: topbar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 var(--s-4) 0 var(--s-4);
  gap: var(--s-3);
  position: sticky; top: 0;
  z-index: 20;
}
.topbar .brand {
  display: flex; align-items: center; gap: var(--s-2);
  font-weight: 600; font-size: 14px;
  color: var(--fg);
  letter-spacing: -0.01em;
  width: calc(var(--sidebar-w) - var(--s-4));
}
.topbar .brand-mark {
  width: 22px; height: 22px;
  display: block;
  object-fit: contain;
}
.topbar .env-pill {
  padding: 3px 8px;
  border-radius: var(--r-full);
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
  letter-spacing: 0.02em;
}
.topbar .env-pill::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
}
.topbar .env-pill.live-pulse {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}
.topbar .env-pill.live-pulse::before { background: var(--success-solid); }
.topbar .env-pill.live-pulse .dot { display: none; }
.topbar .env-pill.live-pulse.reconnecting {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning);
}
.topbar .env-pill.live-pulse.reconnecting::before {
  background: var(--warning);
  animation: reconnectPulse 1400ms ease-in-out infinite;
}
@keyframes reconnectPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.topbar .env-pill.live-pulse.pulsing::before {
  animation: livePulse 700ms cubic-bezier(.22,1,.36,1);
}
@keyframes livePulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 currentColor; }
  60% { transform: scale(1.8); box-shadow: 0 0 0 6px transparent; }
  100% { transform: scale(1); box-shadow: 0 0 0 0 transparent; }
}
.topbar .spacer { flex: 1; }
.topbar .cmdk-trigger {
  display: flex; align-items: center; gap: var(--s-2);
  padding: 5px 8px 5px 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  /* Bumped from --fg-3 to --fg-2 so the placeholder text hits WCAG AA
     (4.5:1) against --surface. Previous --fg-3 scored ~3.5:1 which
     axe flagged as a serious contrast violation. */
  color: var(--fg-2);
  font-size: var(--t-sec);
  border-radius: var(--r);
  min-width: 200px;
  transition: border-color 80ms, color 80ms;
}
.topbar .cmdk-trigger:hover { color: var(--fg); border-color: var(--fg-4); }
.topbar .cmdk-trigger svg { width: 14px; height: 14px; opacity: 0.9; }
.topbar .cmdk-trigger .kbd { margin-left: auto; }
.kbd {
  padding: 1px 5px;
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 11px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  background: var(--surface);
  border-radius: var(--r-sm);
  /* WCAG AA contrast: --fg-3 scored ~3.2:1 against --surface. Bumping
     to --fg-2 hits 4.6:1. The visual difference is minimal but the
     accessibility win is real for anyone with light sensitivity. */
  color: var(--fg-2);
  font-weight: 500;
}
.topbar .theme-btn, .topbar .user-btn {
  padding: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-2);
  border-radius: var(--r);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 80ms;
}
.topbar .theme-btn:hover, .topbar .user-btn:hover { background: var(--surface-hover); color: var(--fg); }
.topbar .theme-btn svg { width: 16px; height: 16px; }
.topbar .user-btn { padding: 4px 10px 4px 4px; border-color: var(--border); }
.topbar .avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
}

.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--s-3) var(--s-2);
  display: flex; flex-direction: column;
  gap: 2px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.sidebar a {
  display: flex; align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--r);
  font-size: var(--t-body);
  color: var(--fg-2);
  font-weight: 500;
  transition: background 80ms, color 80ms;
}
.sidebar a:hover { background: var(--surface-hover); color: var(--fg); text-decoration: none; }
.sidebar a.active { background: var(--accent-bg); color: var(--accent-hover); }
/* Active nav item uses an accent-tinted background — the muted
   kbd-hint against that tint fails WCAG AA. Force a stronger color
   just for the active state. */
.sidebar a.active .kbd-hint { color: var(--accent-hover); opacity: 0.75; }
[data-theme="dark"] .sidebar a.active { color: var(--fg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .sidebar a.active { color: var(--fg); } }
.sidebar a svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.9; }
.sidebar a .badge {
  margin-left: auto;
  padding: 1px 6px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: 11px;
  color: var(--fg-3);
  font-weight: 500;
}
.sidebar a .kbd-hint {
  margin-left: auto;
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 10.5px;
  /* Was --fg-4; hint text failed WCAG AA. --fg-3 (post-token-bump)
     hits 4.5:1 against sidebar surface. */
  color: var(--fg-3);
}
.sidebar .group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-3);
  padding: var(--s-4) 10px var(--s-1);
  font-weight: 600;
}
/* When the chip is a real <button> (multi-org switcher) reset the
   button chrome so it renders identically to the static div. */
button.org-switcher { font: inherit; text-align: left; border: 0; cursor: pointer; }
.sidebar .org-switcher {
  padding: 8px 10px;
  border-radius: var(--r);
  display: flex; align-items: center; gap: var(--s-2);
  cursor: pointer;
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: var(--s-2);
}
.sidebar .org-switcher:hover { background: var(--surface-hover); }
.sidebar .org-switcher .avatar {
  width: 20px; height: 20px; border-radius: 4px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}
.sidebar .org-switcher .env {
  margin-left: auto; font-size: 10.5px; color: var(--fg-3); font-weight: 500;
}

.main {
  grid-area: main;
  /* 84px bottom: the floating tour-launcher pill (fixed, bottom-right)
   * must never cover the last row's action buttons at max scroll. */
  padding: var(--s-6) var(--s-6) 84px;
  max-width: var(--max);
  width: 100%;
  /* Grid children default to min-content sizing on their main axis, which
   * lets wide tables push the column wider than the viewport. Constrain
   * explicitly so mobile layouts don't get horizontal scroll. */
  min-width: 0;
  /* clip, not hidden: overflow-x:hidden silently makes .main a scroll
     container (computed overflow-y becomes auto), which retargets every
     position:sticky descendant — the sticky table headers stuck to a
     scrollport that never scrolls, i.e. never stuck at all. clip keeps
     the horizontal containment without creating a scroll container. */
  overflow-x: clip;
}

.page-header {
  display: flex; align-items: baseline;
  gap: var(--s-4);
  /* Wrap at every width, not just phones: at tablet/split-screen
     widths (768–900px) the session-detail receipt buttons overflowed
     .main's clip and were unreachable — no scrollbar, just gone. */
  flex-wrap: wrap;
  row-gap: var(--s-2);
  margin-bottom: var(--s-4);
}
.page-header h1 {
  font-size: var(--t-title);
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-header .sub { color: var(--fg-2); font-size: var(--t-sec); }
.page-header .actions { margin-left: auto; display: flex; gap: var(--s-2); align-items: center; }

/* Time range chip group */
.range-group {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--surface);
}
.range-group button {
  padding: 5px 10px;
  border: 0;
  background: transparent;
  color: var(--fg-2);
  font-size: var(--t-sec);
  font-weight: 500;
  border-right: 1px solid var(--border);
}
.range-group button:last-child { border-right: 0; }
.range-group button.active { background: var(--fg); color: var(--canvas); }
.range-group button:not(.active):hover { background: var(--surface-hover); color: var(--fg); }

/* ============================================================
 * CARDS
 * ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
}
.card h2 {
  font-size: var(--t-section);
  margin: 0 0 var(--s-3);
  font-weight: 600;
  letter-spacing: -0.005em;
  display: flex; align-items: baseline; gap: var(--s-2);
}
.card h2 .count { font-weight: 400; color: var(--fg-3); font-size: var(--t-sec); }
.card h2 .grow { flex: 1; }

/* ============================================================
 * STATS + SPARKLINES
 * ============================================================ */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  position: relative;
  overflow: hidden;
}
.stat .head { display: flex; align-items: center; gap: var(--s-1); }
/* A stat rendered as a link (drill-down into a pre-filtered list). */
a.stat { display: block; text-decoration: none; color: inherit; }
a.stat.linked:hover { border-color: var(--accent); }
a.stat.linked:hover .label::after { content: " →"; }
.stat .label {
  font-size: 11.5px;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  flex: 1;
}
.stat .value {
  font-size: 26px;
  font-weight: 600;
  color: var(--fg);
  margin-top: 6px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat .delta {
  font-size: var(--t-min);
  color: var(--fg-3);
  margin-top: 4px;
}
.stat .delta .up { color: var(--success); font-weight: 500; }
.stat .delta .dn { color: var(--danger); font-weight: 500; }
.stat .spark {
  position: absolute; right: var(--s-3); bottom: var(--s-3);
  width: 88px; height: 28px;
  opacity: 0.9;
}
.stat.savings .value { color: var(--success); }
.stat.blocks .value { color: var(--danger-solid); }

/* Full-width chart */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-4) var(--s-2);
  margin-bottom: var(--s-4);
}
.chart-card .head {
  display: flex; align-items: baseline; gap: var(--s-3);
  margin-bottom: var(--s-2);
}
.chart-card .head h2 {
  font-size: var(--t-section); margin: 0; font-weight: 600;
}
.chart-card .head .sub { color: var(--fg-3); font-size: var(--t-sec); }
.chart-card .legend { margin-left: auto; display: flex; gap: var(--s-3); font-size: var(--t-min); color: var(--fg-2); }
.chart-card .legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.chart-svg { width: 100%; height: 180px; display: block; }
.chart-svg .grid line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-svg .axis text { fill: var(--fg-3); font-size: 10px; font-family: inherit; }
.chart-svg .bar { fill: var(--accent); opacity: 0.85; transition: opacity 120ms ease; }
.chart-svg .bar.blocked { fill: var(--danger-solid); opacity: 0.9; }
/* R202 F1: hovered bar pops so the exact stack under the cursor
   is visible on dense (60+ bucket) renders where a 2 px bar was
   otherwise indistinguishable from its neighbours. */
.chart-svg .bar.hover { opacity: 1; filter: brightness(1.08); }
.chart-svg .area { fill: var(--accent); fill-opacity: 0.12; stroke: var(--accent); stroke-width: 1.5; }
.chart-svg .cursor { stroke: var(--fg-3); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-card { position: relative; }
.chart-tip {
  position: absolute;
  background: var(--fg);
  color: var(--canvas);
  padding: 6px 10px;
  border-radius: var(--r);
  font-size: 11.5px;
  pointer-events: none;
  box-shadow: var(--shadow-md);
  z-index: 10;
  min-width: 160px;
}
/* R202 F1: pointer arrow below the tooltip so the eye connects
   the label to the bar it describes. Uses a CSS ::after triangle
   sized to match the tooltip surface. */
.chart-tip::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--fg);
}
.chart-tip .tip-label {
  color: var(--canvas);
  opacity: 0.7;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  /* R202 F1: hold the rate pill on the same line as the bucket
     label so the tooltip stays compact (2 lines of counts + 1
     header row) even when both are populated. */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
/* R202 F1: block-rate pill next to the bucket label. `.quiet`
   applies when the bucket has zero activity so a hover on empty
   space returns something readable instead of blank counts. */
.chart-tip .tip-rate {
  font-size: 9.5px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  color: var(--canvas);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  opacity: 0.9;
}
.chart-tip .tip-rate.danger {
  background: var(--danger-solid);
  color: #fff;
  opacity: 1;
}
.chart-tip .tip-rate.quiet {
  background: rgba(255, 255, 255, 0.1);
  opacity: 0.6;
}
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.chart-tip .tip-row .d { display: inline-block; width: 6px; height: 6px; border-radius: 2px; }
.chart-tip .tip-row b { margin-left: auto; font-weight: 600; }
/* R202 F1: brighten the muted spend row — prior 0.7 opacity on
   the same low-contrast `var(--canvas)` color made the number
   unreadable in light-mode. Bumping to 0.85 keeps the visual
   hierarchy (spend is secondary) while staying WCAG-legible. */
.chart-tip .tip-row.muted { color: var(--canvas); opacity: 0.85; }
.chart-svg .hover-strip { cursor: crosshair; }

/* R202 F1: empty-state card that replaces the SVG when every
   bucket in the window is 0/0. Same visual footprint as the
   chart (180 px tall inside .chart-card) so the surrounding
   legend + sub-heading stay aligned instead of collapsing. */
.chart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 180px;
  gap: 6px;
  color: var(--fg-2);
  padding: 0 var(--s-4);
  text-align: center;
}
.chart-empty-icon {
  font-size: 28px;
  opacity: 0.5;
  margin-bottom: 2px;
}
.chart-empty-title {
  font-size: var(--t-body);
  font-weight: 500;
  color: var(--fg);
}
.chart-empty-sub {
  font-size: var(--t-sec);
  color: var(--fg-3);
  max-width: 380px;
}

/* ============================================================
 * TABLES
 * ============================================================ */
.table-wrap {
  /* overflow: clip (not hidden) keeps the border-radius clipping but
     does NOT create a scroll container — position:sticky on th would
     otherwise silently never stick (it would target this non-scrolling
     clip box instead of the page). Phones override to overflow-x:auto,
     which trades sticky headers for horizontal scroll. */
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); overflow: clip;
  /* Positioning context so absolutely-positioned .sr-only table headers
     stay inside the (possibly scrolling) wrap instead of extending the
     document's scroll width on phones. */
  position: relative;
}
/* table-layout: fixed prevents any single evil-long cell from stretching
   the whole table. Combined with the per-cell truncation below, hostile
   or accidentally-long user data stays contained. */
table { width: 100%; border-collapse: collapse; font-size: var(--t-body); table-layout: fixed; }
th, td { padding: 10px var(--s-4); text-align: left; }
/* Every cell truncates its overflowing content. The full string is
   available via a native tooltip (title attr, set by the renderer when
   worth doing) or by clicking into the row's detail view. */
td, th { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Actions columns: under table-layout:fixed the sr-only header gets an
   equal 1/n share regardless of content, so multi-button cells spilled
   past their td into overflow:hidden dead space — the buttons rendered
   clipped and mouse clicks landed on the td, not the button (found on
   webhooks/SSO/deployments Delete). Explicit widths sized to the button
   set fix both paint and hit-testing. */
th.act-1 { width: 110px; }
th.act-2 { width: 180px; }
th.act-3 { width: 264px; }
th.act-4 { width: 376px; }
/* Sortable column headers: the whole label is a button. Inherits the
   th typography so sortable and plain headers read identically. */
th .th-sort {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit;
}
th .th-sort:hover { color: var(--fg); }
th .th-sort.active { color: var(--fg); }
th[aria-sort] { white-space: nowrap; }
/* Cells that hold two lines (deployment name + subhead) opt back in. */
td > div:first-child { overflow: hidden; text-overflow: ellipsis; }
th {
  font-size: 11.5px;
  color: var(--fg-2);
  font-weight: 600;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  /* Column context survives long lists (250-row bigdata sessions):
     headers stick just below the sticky topbar. Opaque background so
     rows scroll underneath; z below the topbar's 20. border-collapse
     drops a stuck th's border, so the separator is an inset shadow. */
  position: sticky;
  top: var(--topbar-h);
  z-index: 5;
  box-shadow: inset 0 -1px 0 var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: 0; }
tbody tr[data-clickable] { cursor: pointer; }
tbody tr[data-clickable]:hover { background: var(--surface-hover); }
td .id { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 11.5px; color: var(--fg-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
td .actor { display: flex; align-items: center; gap: 6px; }
td .actor .av { width: 20px; height: 20px; border-radius: 50%; background: var(--surface-hover); border: 1px solid var(--border); display: grid; place-items: center; font-size: 10px; font-weight: 600; color: var(--fg-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--r-full);
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid transparent;
  line-height: 1.5;
  /* Keep the dot + label on one line inside narrow table cells —
     without this, e.g. the Status column wraps "connected" under the
     dot in the Deployments table. */
  white-space: nowrap;
}
/* Inline icons inside pills (Google/Microsoft on the SSO tab, webhook
   event chips, …). An SVG with no width/height attribute renders at
   the CSS default replaced-element size — the provider logos blew up
   to ~110px and shattered the pills. Size + align them like text. */
.pill svg {
  width: 12px;
  height: 12px;
  vertical-align: -2px;
}
.pill.ok { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
.pill.warn { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.pill.err { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.pill.neutral { background: var(--surface-hover); border-color: var(--border); color: var(--fg-2); }
.pill.accent { background: var(--accent-bg); border-color: var(--accent-border); color: var(--accent); }
.pill.status-dot::before {
  content: ""; display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: currentColor;
  margin-right: 5px; vertical-align: middle;
}

/* ============================================================
 * BUTTONS
 * ============================================================ */
.btn {
  padding: 6px 10px;
  border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  font-size: var(--t-sec);
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 100ms, border-color 100ms, transform 60ms;
  line-height: 1.5;
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--fg); color: var(--canvas); border-color: var(--fg); }
.btn.primary:hover { opacity: 0.92; background: var(--fg); }
.btn.accent { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); opacity: 1; }
.btn.danger { color: var(--danger); border-color: var(--danger-border); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }
.btn.ok-flash { background: var(--success-bg); border-color: var(--success-border); color: var(--success); transition: background 120ms ease, color 120ms ease; }

/* ============================================================
 * FILTER BAR
 * ============================================================ */
.filter-bar {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: var(--s-3);
  flex-wrap: wrap;
}
/* Applied-filter pill for filters that arrive via cross-links (no
   widget in the bar), e.g. policy — dismissible. */
.filter-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--accent-bg); border: 1px solid var(--accent-border);
  font-size: var(--t-sec); color: var(--fg);
}
.filter-pill button {
  background: none; border: 0; cursor: pointer; padding: 0 2px;
  color: var(--fg-2); font-size: 12px; line-height: 1;
}
.filter-pill button:hover { color: var(--fg); }
.filter-bar .search {
  position: relative; flex: 1; min-width: 220px;
}
.filter-bar .search input {
  width: 100%;
  padding: 7px 12px 7px 32px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  border-radius: var(--r);
  font-size: var(--t-body);
  font-family: inherit;
}
.filter-bar .search input:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow-focus); }
.filter-bar .search svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--fg-3);
}
.filter-bar select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  border-radius: var(--r);
  font-size: var(--t-sec);
  font-family: inherit;
}
.filter-bar select:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow-focus); }
.filter-bar .toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg-2);
  border-radius: var(--r);
  font-size: var(--t-sec);
  font-weight: 500;
}
.filter-bar .toggle input { margin: 0; accent-color: var(--accent); }
.filter-bar .toggle:has(input:checked) { background: var(--accent-bg); border-color: var(--accent-border); color: var(--accent); }

/* ============================================================
 * SESSION DETAIL — compact events + right drawer
 * ============================================================ */
.detail-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: var(--s-3);
}
@media (max-width: 960px) { .detail-grid { grid-template-columns: 1fr; } }

.events-card { padding: 0; overflow: hidden; }
.events-card .events-head {
  padding: 12px var(--s-4);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: baseline; gap: var(--s-2);
  background: var(--surface-2);
}
.events-card .events-head h2 { font-size: var(--t-section); margin: 0; font-weight: 600; }
.events-card .events-head .count { color: var(--fg-3); font-size: var(--t-sec); font-weight: 400; margin-left: 4px; }
.events-card .events-head .actions { margin-left: auto; display: flex; gap: 4px; }
/* Event triage: kind chips + text filter in the stream header. */
.events-head .evt-filters { margin-left: auto; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.evt-chip {
  border: 1px solid var(--border); background: var(--bg); color: var(--fg-2);
  border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 500;
  cursor: pointer; display: inline-flex; gap: 4px; align-items: center;
}
.evt-chip .n { color: inherit; opacity: 0.85; font-weight: 400; }
.evt-chip:hover { border-color: var(--accent); }
.evt-chip.active { background: var(--accent-bg); border-color: var(--accent); color: var(--fg); }
.evt-chip.chip-danger.active { background: var(--danger-bg); border-color: var(--danger-solid); }
.events-head #evtSearch {
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: var(--r-sm); padding: 2px 8px; font-size: 11.5px; width: 110px;
}
.evt.evt-hidden { display: none; }

/* R102 F1: pill shown to member-role users where the server has
   redacted event.body/event.sub. Neutral rather than alarming
   so the SPA doesn't imply an error state. */
.redacted-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--panel, #f0f0f0);
  color: var(--fg-3, #666);
  font-size: 11px;
  cursor: help;
  border: 1px solid var(--border, #ddd);
}
/* iOS Safari force-zooms the page when focusing any input whose
   font-size is under 16px — tapping the session search on the QR path
   made the whole console lurch. pointer:coarse covers iPads too (the
   760px breakpoint missed them); mice stay on the compact sizes.
   !important on purpose: this must beat every per-component input rule
   (.filter-bar .search input, .modal input, .cmdk input, …). */
@media (max-width: 760px), (pointer: coarse) {
  input, select, textarea { font-size: 16px !important; }
}
@media (max-width: 760px) {
  .events-head { flex-wrap: wrap; }
  .events-head .evt-filters { margin-left: 0; width: 100%; }
}

.evt {
  display: grid;
  grid-template-columns: 32px auto 1fr 120px auto;
  align-items: center;
  gap: var(--s-2);
  padding: 7px var(--s-4);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  transition: background 80ms;
}
.evt:last-child { border-bottom: 0; }
.evt:hover { background: var(--surface-hover); }
.evt .seq { color: var(--fg-3); font-family: "SF Mono", ui-monospace, monospace; font-size: 11px; }
.evt .icon {
  width: 18px; height: 18px; border-radius: 4px;
  display: grid; place-items: center;
  background: var(--surface-hover);
  color: var(--fg-2);
  font-size: 10.5px; font-weight: 600;
  margin-left: calc(var(--depth, 0) * 14px);
  box-shadow: calc(var(--depth, 0) * -4px) 0 0 var(--accent-border);
}
.evt .icon.ok { background: var(--success-bg); color: var(--success); }
.evt .icon.err { background: var(--danger-bg); color: var(--danger); }
.evt .icon.accent { background: var(--accent-bg); color: var(--accent); }
.evt .body { color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.evt .body b { font-weight: 500; }
.evt .body .sub { color: var(--fg-3); font-size: 12px; margin-left: 4px; }
.evt .dur {
  color: var(--fg-3); font-size: 11px;
  font-variant-numeric: tabular-nums;
  min-width: 44px; text-align: right;
}
.evt .waterfall {
  position: relative;
  height: 14px;
  width: 120px;
}
.evt .wf-track {
  position: absolute; inset: 6px 0;
  background: var(--surface-hover);
  border-radius: 999px;
}
.evt .wf-bar {
  position: absolute;
  height: 4px;
  top: 5px;
  background: var(--accent);
  border-radius: 999px;
  min-width: 2px;
}
.evt.err { background: linear-gradient(to right, var(--danger-bg) 0%, transparent 40%); }
.evt.ok { background: linear-gradient(to right, var(--success-bg) 0%, transparent 40%); }
.evt.selected { background: var(--accent-bg); }
.evt:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Right side drawer for event details */
.event-drawer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
}
.event-drawer h3 { font-size: var(--t-section); margin: 0 0 var(--s-3); font-weight: 600; }
.event-drawer .meta {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 4px var(--s-3);
  font-size: var(--t-sec);
  margin-bottom: var(--s-3);
}
.event-drawer .meta dt { color: var(--fg-3); }
.event-drawer .meta dd { margin: 0; color: var(--fg); }
.event-drawer .evt-link-btn { font-size: 11px; padding: 3px 8px; }
.event-drawer .payload {
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--code-border);
  border-radius: var(--r);
  padding: var(--s-3);
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow: auto;
}
.event-drawer .payload b { color: #f0f2f6; font-weight: 500; }
.event-drawer .empty-mini {
  padding: var(--s-6) var(--s-4);
  color: var(--fg-3);
  text-align: center;
  font-size: var(--t-sec);
  background: var(--surface-2);
  border-radius: var(--r);
  border: 1px dashed var(--border);
}

/* Session summary strip */
.session-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: var(--s-3);
}
.session-summary .cell .label {
  font-size: 11px; color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
}
.session-summary .cell .value {
  font-size: 15px; font-weight: 600; color: var(--fg); margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.session-summary .cell.savings .value { color: var(--success); }
.session-summary .cell.blocks .value { color: var(--danger-solid); }

/* ============================================================
 * RECEIPT PANEL (with verified badge)
 * ============================================================ */
.receipt-card { padding: 0; overflow: hidden; }
.receipt-head {
  padding: var(--s-3) var(--s-4);
  background: var(--success-bg);
  border-bottom: 1px solid var(--success-border);
  display: flex; align-items: center; gap: var(--s-2);
  transition: background 160ms, border-color 160ms;
}
.receipt-head[data-verify-state="pending"] {
  background: var(--surface-hover);
  border-bottom-color: var(--border);
}
.receipt-head[data-verify-state="pending"] .check {
  background: var(--fg-3);
  animation: verifyPulse 900ms ease-in-out infinite;
}
.receipt-head[data-verify-state="pending"] .title { color: var(--fg-2); }
.receipt-head[data-verify-state="unsupported"] {
  background: var(--warning-bg);
  border-bottom-color: var(--warning-border);
}
.receipt-head[data-verify-state="unsupported"] .check { background: var(--warning); }
.receipt-head[data-verify-state="unsupported"] .title { color: var(--warning); }
.receipt-head[data-verify-state="invalid"] {
  background: var(--danger-bg);
  border-bottom-color: var(--danger-border);
}
.receipt-head[data-verify-state="invalid"] .check { background: var(--danger-solid); }
.receipt-head[data-verify-state="invalid"] .title { color: var(--danger); }
@keyframes verifyPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }
.receipt-head .check {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--success-solid); color: var(--solid-fg);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}
.receipt-head .title { font-weight: 600; color: var(--success); font-size: var(--t-body); }
.receipt-head .kf { margin-left: auto; font-family: "SF Mono", ui-monospace, monospace; color: var(--success); font-size: 11px; }
.receipt-head[data-verify-state="pending"] .kf { color: var(--fg-3); }
.receipt-head[data-verify-state="unsupported"] .kf { color: var(--warning); }
.receipt-head[data-verify-state="invalid"] .kf { color: var(--danger); }
.receipt-body { padding: var(--s-3) var(--s-4); }
.receipt-body .kv {
  display: grid; grid-template-columns: 130px 1fr;
  gap: 5px var(--s-3);
  font-size: var(--t-sec);
  margin-bottom: var(--s-3);
}
.receipt-body .kv dt { color: var(--fg-3); }
.receipt-body .kv dd { margin: 0; color: var(--fg); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.receipt-body .kv dd.mono, .receipt-body .kv dd .mono {
  font-family: "SF Mono", ui-monospace, monospace; font-size: 11.5px;
  overflow-wrap: anywhere;
  word-break: break-all;
}
.receipt-body .policies { display: flex; flex-wrap: wrap; gap: 5px; }
.receipt-body .raw-toggle {
  margin-top: var(--s-3);
  border-top: 1px solid var(--border);
  padding-top: var(--s-3);
}
.receipt-body .raw-toggle summary {
  cursor: pointer; font-size: var(--t-sec); color: var(--fg-2); font-weight: 500;
  list-style: none;
}
.receipt-body .raw-toggle summary::-webkit-details-marker { display: none; }
.receipt-body .raw-toggle summary::before { content: "▸ "; color: var(--fg-3); }
.receipt-body .raw-toggle[open] summary::before { content: "▾ "; }
.receipt-body .raw {
  background: var(--code-bg); color: var(--code-fg); border: 1px solid var(--code-border);
  padding: var(--s-3); border-radius: var(--r);
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 11px; line-height: 1.55;
  white-space: pre; overflow: auto;
  margin-top: var(--s-2);
  max-height: 260px;
}

/* ============================================================
 * EMPTY STATES
 * ============================================================ */
.empty {
  padding: var(--s-8) var(--s-6);
  text-align: center;
}
.empty .icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  margin: 0 auto var(--s-4);
  color: var(--fg-3);
}
.empty .icon svg { width: 22px; height: 22px; }
.empty h3 { color: var(--fg); font-size: 15px; margin: 0 0 6px; font-weight: 600; }
.empty p { margin: 0 auto var(--s-4); font-size: var(--t-sec); color: var(--fg-2); max-width: 380px; }

.empty-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-8);
  display: grid; grid-template-columns: 1fr 1fr;
  gap: var(--s-6);
  align-items: center;
}
@media (max-width: 900px) { .empty-hero { grid-template-columns: 1fr; } }
.empty-hero h2 { font-size: 20px; margin: 0 0 var(--s-2); font-weight: 600; letter-spacing: -0.01em; }
.empty-hero p { color: var(--fg-2); font-size: var(--t-body); margin: 0 0 var(--s-4); }
.empty-hero .snippet {
  background: var(--code-bg); color: var(--code-fg); border: 1px solid var(--code-border);
  padding: var(--s-3) var(--s-4); border-radius: var(--r);
  font-family: "SF Mono", ui-monospace, monospace; font-size: 12px;
  /* pre-wrap: preserve the '\n' between the two shell commands as a
     hard line break, but let long lines soft-wrap on spaces so the
     snippet stays fully visible instead of clipping under a horizontal
     scrollbar in narrow grid columns. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.empty-hero .snippet .prompt { color: #8b93a1; }
.empty-hero .snippet .cmd { color: #f0f2f6; }

/* ============================================================
 * MODAL / CONFIRM
 * ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: grid; place-items: center;
  z-index: 100;
  padding: var(--s-4);
  animation: fadeIn 100ms ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
/* Scroll chaining: hitting the end of an inner scroller must not start
   scrolling the page behind it — especially under an open modal, where
   the "background page crept away" effect is disorienting. */
.modal, .cmdk .list, .sidebar, .event-drawer .payload, .policy-preview, .policy-body, #accountMenu, #orgMenu { overscroll-behavior: contain; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 140ms cubic-bezier(.22,1,.36,1);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal.modal-wide { max-width: 640px; }
/* Policy template picker: radio cards. */
.tpl-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-2); }
.tpl-chip { position: relative; cursor: pointer; }
.tpl-chip input { position: absolute; opacity: 0; pointer-events: none; }
.tpl-chip .tpl-body {
  display: flex; flex-direction: column; gap: 3px; height: 100%;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg); transition: border-color 120ms, background 120ms;
}
.tpl-chip .tpl-label { font-size: var(--t-body); font-weight: 600; color: var(--fg); }
.tpl-chip .tpl-hint { font-size: 11.5px; color: var(--fg-3); line-height: 1.35; }
.tpl-chip input:checked + .tpl-body { border-color: var(--accent); background: var(--accent-bg); }
.tpl-chip input:focus-visible + .tpl-body { outline: 2px solid var(--accent); outline-offset: 2px; }
.policy-preview { margin: 0; max-height: 180px; overflow: auto; }
@media (max-width: 640px) { .tpl-row { grid-template-columns: 1fr; } }
.modal h2 { font-size: 17px; margin: 0 0 var(--s-1); font-weight: 600; letter-spacing: -0.01em; }
.modal .sub { color: var(--fg-2); font-size: var(--t-body); margin: 0 0 var(--s-4); }
.modal form { display: flex; flex-direction: column; gap: var(--s-3); }
.modal .field { display: flex; flex-direction: column; gap: 4px; }
.modal label { font-size: var(--t-sec); font-weight: 500; color: var(--fg-2); }
.modal input, .modal select, .modal textarea {
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  border-radius: var(--r);
  font-size: var(--t-body);
  font-family: inherit;
}
.modal input:focus, .modal select:focus, .modal textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--shadow-focus);
}
.modal .actions {
  display: flex; gap: var(--s-2);
  justify-content: flex-end;
  margin-top: var(--s-3);
  /* Long forms (SAML add-IdP) scroll inside the modal on phones —
     keep Save/Cancel reachable without scrolling a 9-field form.
     The negative offsets counter the modal's own padding so the bar
     hugs the true bottom edge; short modals are unaffected. */
  position: sticky;
  bottom: calc(-1 * var(--s-5));
  margin-bottom: calc(-1 * var(--s-5));
  padding: var(--s-3) 0 var(--s-5);
  background: var(--surface);
}
.confirm-danger h2 { color: var(--danger); }
.token-display {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: var(--s-3);
  border-radius: var(--r);
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 12px;
  word-break: break-all;
  border: 1px solid var(--code-border);
  position: relative;
}
.notice {
  padding: var(--s-3);
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning);
  border-radius: var(--r);
  font-size: var(--t-sec);
  display: flex; align-items: flex-start; gap: 8px;
}
.notice svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }

/* ============================================================
 * COMMAND PALETTE (⌘K)
 * ============================================================ */
.cmdk-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: grid; place-items: start center;
  padding-top: 14vh;
  z-index: 200;
  animation: fadeIn 80ms ease-out;
}
.cmdk {
  width: 100%; max-width: 640px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn 120ms cubic-bezier(.22,1,.36,1);
}
.cmdk input {
  width: 100%;
  padding: 14px 18px;
  border: 0;
  background: transparent;
  color: var(--fg);
  font-size: 15px;
  font-family: inherit;
  border-bottom: 1px solid var(--border);
}
.cmdk input:focus { outline: none; }
.cmdk .list { max-height: 60vh; overflow-y: auto; padding: 6px; }
.cmdk .group-label {
  padding: 8px 12px 4px;
  font-size: 10.5px;
  color: var(--fg-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.cmdk .item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: var(--r);
  color: var(--fg);
  font-size: 13.5px;
  cursor: pointer;
}
.cmdk .item .desc { color: var(--fg-3); font-size: 12px; margin-left: 6px; }
.cmdk .item.selected { background: var(--accent-bg); color: var(--accent-hover); }
[data-theme="dark"] .cmdk .item.selected { color: var(--fg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cmdk .item.selected { color: var(--fg); } }
.cmdk .item svg { width: 15px; height: 15px; opacity: 0.8; }
.cmdk .item .kbd { margin-left: auto; }
.cmdk-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex; gap: var(--s-3); align-items: center;
  color: var(--fg-3);
  font-size: 11.5px;
  background: var(--surface-2);
}
.cmdk-footer .hint { display: inline-flex; align-items: center; gap: 4px; }
.cmdk .empty-hint { padding: 24px 16px; text-align: center; color: var(--fg-3); font-size: var(--t-sec); }

/* ============================================================
 * TOAST
 * ============================================================ */
#toastStack {
  position: fixed;
  right: var(--s-6);
  /* Clear of the tour launcher pill (bottom-right, ~64px tall zone). */
  bottom: 76px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 32px));
}
#toastStack .toast { position: static; pointer-events: auto; }
.toast {
  position: fixed;
  bottom: var(--s-6); right: var(--s-6);
  padding: 10px 14px;
  background: var(--fg);
  color: var(--canvas);
  border-radius: var(--r);
  font-size: var(--t-sec);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  animation: toastIn 120ms cubic-bezier(.22,1,.36,1);
  /* Unbroken tokens/URLs in a message (a copy-failure echoing an
     av_live_… token) once stretched a toast to ~885px — off the left
     edge of a phone. Cap and wrap anywhere. */
  max-width: min(420px, calc(100vw - 24px));
  overflow-wrap: anywhere;
  display: flex; align-items: center; gap: 8px;
}
.toast.err { background: var(--danger-solid); color: var(--solid-fg); }
.toast .toast-undo {
  background: transparent; border: 1px solid color-mix(in srgb, var(--canvas) 40%, transparent);
  color: inherit; border-radius: var(--r-sm); padding: 2px 10px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.toast .toast-undo:hover { border-color: var(--canvas); }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============================================================
 * SKELETON LOADERS
 * ============================================================ */
.skl {
  background: linear-gradient(90deg, var(--surface-hover) 0%, var(--surface-2) 50%, var(--surface-hover) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
  display: block;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skl.h-24 { height: 24px; }
.skl.h-16 { height: 16px; }
.skl.h-12 { height: 12px; }
.skl.h-100 { height: 100px; }
.skl.h-180 { height: 180px; }
.skl.w-2 { width: 20%; }
.skl.w-4 { width: 40%; }
.skl.w-6 { width: 60%; }
.skl.w-8 { width: 80%; }
.skl.w-full { width: 100%; }

/* ============================================================
 * SETTINGS TABS
 * ============================================================ */
.settings-shell {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: var(--s-4);
}
@media (max-width: 800px) { .settings-shell { grid-template-columns: 1fr; } }
/* Grid children default to min-content sizing: a wide table inside the
   panel blew the whole panel out to ~640px on a 390px phone, pushing
   header buttons (+ Add IdP) off-viewport. The .main clip used to mask
   it (scripts could still scroll there; thumbs could not). */
.settings-panel { min-width: 0; }
.settings-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
  height: fit-content;
}
.settings-nav button {
  text-align: left;
  padding: 7px 10px;
  border-radius: var(--r);
  border: 0;
  background: transparent;
  color: var(--fg-2);
  font-size: var(--t-body);
  font-weight: 500;
  transition: background 80ms, color 80ms;
}
.settings-nav button:hover { background: var(--surface-hover); color: var(--fg); }
.settings-nav button.active { background: var(--accent-bg); color: var(--accent-hover); }
[data-theme="dark"] .settings-nav button.active { color: var(--fg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .settings-nav button.active { color: var(--fg); } }
.settings-panel .card { margin-bottom: var(--s-3); }

/* ============================================================
 * POLICIES
 * ============================================================ */
.policy-row .name {
  display: flex; align-items: center; gap: 6px;
  font-weight: 500;
}
.policy-row .kind { font-size: 11.5px; color: var(--fg-3); margin-top: 2px; }
.policy-body {
  background: var(--code-bg); color: var(--code-fg); border: 1px solid var(--code-border);
  border-radius: var(--r);
  padding: var(--s-3) var(--s-4);
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 12px; line-height: 1.6;
  white-space: pre;
  overflow: auto;
}
.policy-body .k { color: var(--tok-key); }
.policy-body .s { color: var(--tok-str); }
.policy-body .n { color: var(--tok-num); }
.policy-body .c { color: var(--tok-comment); }

.switch {
  display: inline-block;
  width: 30px; height: 17px;
  background: var(--border-strong);
  border: 0;
  padding: 0;
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 120ms;
  vertical-align: middle;
}
.switch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: white;
  transition: transform 120ms;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
/* Windows High Contrast: backgrounds are stripped, which erased the
   track and knob entirely (white-on-white). Borders survive forced
   colors, so draw the control with them; the knob position (left vs
   right) plus the filled knob on 'on' carries the state. */
@media (forced-colors: active) {
  .switch { border: 1px solid ButtonText; }
  .switch::after { background: ButtonText; box-shadow: none; border: 1px solid ButtonText; }
  .switch:not(.on)::after { background: Canvas; }
}
.switch.on { background: var(--success-solid); }
.switch.on::after { transform: translateX(13px); }

/* ============================================================
 * DEPLOYMENT DETAIL
 * ============================================================ */
.dep-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.dep-summary .cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
}
.dep-summary .cell .label {
  font-size: 11px; color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
}
.dep-summary .cell .value {
  font-size: 15px; font-weight: 600; color: var(--fg); margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.dep-summary .cell .value.mono { font-family: "SF Mono", ui-monospace, monospace; font-size: 12px; word-break: break-all; }

/* ============================================================
 * LOADING
 * ============================================================ */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
 * RESPONSIVE
 * ============================================================ */
@media (max-width: 760px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "topbar" "main"; }
  .app-shell.has-preview { grid-template-rows: auto var(--topbar-h) 1fr; grid-template-areas: "pbanner" "topbar" "main"; }
  .sidebar { display: none; }
  /* Bottom padding clears both the tab bar (56px) and the tour pill. */
  .main { padding: var(--s-4) var(--s-4) 132px; }
  .topbar { overflow: hidden; }
  /* R286 (user report: "header on mobile is quite compressed"): the
     search trigger used to shrink to ~31px with its ⌘K kbd bleeding
     outside the border, and the avatar squashed to 9px beside a
     3-character email. The trigger becomes a fixed icon-only button
     (⌘K is a hardware-keyboard affordance; the magnifier alone reads
     as search) and nothing in the right cluster may shrink below its
     content. */
  .topbar .cmdk-trigger { min-width: 0; flex-shrink: 0; padding: 12px; }
  .topbar .cmdk-trigger span:not(.kbd) { display: none; }
  .topbar .cmdk-trigger .kbd { display: none; }
  .topbar .cmdk-trigger svg { width: 16px; height: 16px; }
  .topbar .theme-btn { flex-shrink: 0; }
  .topbar .avatar { flex-shrink: 0; }
  /* Keep the Demo/Live pill visible: phones are exactly where the
     demo-table QR code lands, and the pill is the only signal that
     the data is fixtures. Trim its padding instead of hiding it. */
  .topbar .env-pill { padding: 3px 6px; }
  /* Brand stays on one line; the search trigger and user button
     absorb the shrink instead. */
  .topbar .brand { width: auto; white-space: nowrap; flex-shrink: 0; }
  .topbar .user-btn { max-width: 40vw; overflow: hidden; }
  .topbar .user-btn span:last-child { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
  /* Tables scroll inside their card instead of inflating the page
     width (overflow:hidden let the table force the whole console
     wider than the phone screen). min-width keeps rows readable. */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* No sticky headers on phones: the wrap above is a scroll container,
     so a sticky th retargets to IT, hovers over the rows, and eats
     their taps (elementFromPoint returned the TH over a data cell). */
  th { position: static; }
  .table-wrap table { min-width: 640px; }
}
/* Foldable cover displays (Galaxy Fold: 280px). The 760px tier still
   overflowed the topbar by ~55px — the account button (the ONLY path
   to sign-out/theme) was clipped clean off behind overflow:hidden.
   Logo stands in for the wordmark; the email hides (the avatar initial
   remains); gaps and padding tighten. */
/* Compact phones (≤480px): the ellipsized email adds nothing next to
   the avatar initial — hide it (the account menu shows the full email)
   and let the chip collapse to the avatar. The 340px foldable tier
   below only has to handle the wordmark after this. */
@media (max-width: 480px) {
  .topbar .user-btn span:last-child { display: none; }
  .topbar .user-btn { max-width: none; padding: 4px; }
}
@media (max-width: 340px) {
  .topbar { gap: var(--s-2); padding: 0 var(--s-3); }
  .topbar .brand span { display: none; }
}
@media (max-width: 760px) {
  /* Header actions wrap under the title instead of overflowing. */
  .page-header { flex-wrap: wrap; row-gap: var(--s-2); }
  .page-header .actions { flex-wrap: wrap; row-gap: var(--s-2); }
  /* Event rows: drop the waterfall column so message + duration fit. */
  .evt { grid-template-columns: 32px auto minmax(0, 1fr) auto; }
  .evt .waterfall { display: none; }
  /* Keep the tour launcher compact so it covers less content. */
  #avTourLauncher button { padding: 9px 6px 9px 14px; font-size: 13px; }
  #avTourLauncher #avTourDismiss { padding: 9px 12px 9px 4px; }
}

/* ============================================================
 * ACCESSIBILITY UTILITIES
 * ============================================================ */
/* Screen-reader-only: visible to AT, hidden from sighted users.
   Used for table headers on action columns (e.g. Rotate/Delete) where
   the visible cell holds buttons instead of a text label. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  border: 0;
}

/* ============================================================
 * GUIDED FLOW TOUR (tour.js)
 * ============================================================ */
/* Never float the launcher over an open modal / palette: at phone
 * heights it sat exactly on a long form's Save/Cancel row (z 900 vs
 * the backdrop's 100). While anything locks the body, the user's
 * intent is the dialog. */
body.locked #avTourLauncher { display: none; }
#avTourLauncher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--accent);
  /* --accent-fg, not #fff: dark theme's accent is a light blue, where
   * white text fails contrast (caught by the dual-theme axe pass). */
  color: var(--accent-fg);
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  animation: toastIn 200ms cubic-bezier(.22,1,.36,1);
}
#avTourLauncher button {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 11px 8px 11px 18px;
  font-weight: 600;
  font-size: var(--t-body, 14px);
}
#avTourLauncher #avTourDismiss {
  padding: 11px 14px 11px 6px;
  opacity: 0.75;
  font-weight: 400;
}
#avTourLauncher #avTourDismiss:hover { opacity: 1; }
#avTourLauncher #avTourStart:hover { text-decoration: underline; }

/* The overlay absorbs every click outside the card so a stray click
   can't navigate the app underneath a tour step (audit D1). Tour
   advancement is via the card buttons / arrow keys. */
#avTour { position: fixed; inset: 0; z-index: 950; pointer-events: auto; }
.av-tour-hole {
  position: fixed;
  border-radius: 10px;
  /* The spotlight: everything but the hole is dimmed. */
  box-shadow: 0 0 0 9999px rgba(8, 15, 24, 0.55), 0 0 0 2px var(--accent);
  transition: left 200ms ease, top 200ms ease, width 200ms ease, height 200ms ease;
}
.av-tour-card {
  position: fixed;
  width: 380px;
  max-width: calc(100vw - 24px);
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  transition: left 200ms ease, top 200ms ease;
}
.av-tour-card.centered {
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 9999px rgba(8, 15, 24, 0.55), 0 16px 48px rgba(0, 0, 0, 0.35);
}
.av-tour-step {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 6px;
}
.av-tour-card h3 { margin: 0 0 6px; font-size: 16px; }
.av-tour-card p { margin: 0 0 14px; font-size: 13.5px; line-height: 1.55; color: var(--fg-2); }
.av-tour-card p code { font-size: 12px; }
.av-tour-actions { display: flex; align-items: center; gap: 8px; }
.av-tour-spacer { flex: 1; }
.av-tour-actions button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
  border-radius: 8px;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.av-tour-actions .av-tour-next {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.av-tour-actions .av-tour-skip {
  border: 0;
  background: none;
  color: var(--fg-3);
  padding-left: 0;
}
.av-tour-actions .av-tour-skip:hover { color: var(--fg-1); }

/* Simulated-attack: the savings stat pulses when new money is kept. */
@keyframes avStatPulse {
  0% { box-shadow: 0 0 0 0 var(--success-bg); }
  50% { box-shadow: 0 0 0 10px transparent; background: var(--success-bg); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.stat.av-pulse { animation: avStatPulse 1.2s ease 2; }
tr.av-new-row td { animation: avStatPulse 1.2s ease 2; }

@media (prefers-reduced-motion: reduce) {
  /* Global kill-switch (WCAG 2.3.3): 18 animation/transition sites and
   * counting — enumerating them drifted (modals, palette, skeleton
   * shimmer, and live-pulse all shipped after the original list).
   * Near-zero durations instead of `none` so any future animationend
   * listeners still fire. */
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .av-tour-hole, .av-tour-card { transition: none; }
  .stat.av-pulse, tr.av-new-row td { animation: none; }
  .toast, #avTourLauncher { animation: none; }
}

/* ============================================================
 * FRESH-WORKSPACE ONBOARDING CHECKLIST (overview, fresh mode only)
 * ============================================================ */
.onboard-card { padding: var(--s-4) var(--s-5); margin-bottom: var(--s-4); }
.ob-head { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); }
.ob-head h2 { margin: 0; font-size: var(--t-section); font-weight: 600; }
.ob-count { color: var(--fg-3); font-size: var(--t-sec); }
.ob-bar {
  flex: 1;
  max-width: 220px;
  margin-left: auto;
  height: 6px;
  background: var(--surface-hover);
  border-radius: 999px;
  overflow: hidden;
}
.ob-bar span {
  display: block;
  height: 100%;
  background: var(--success-solid);
  border-radius: 999px;
  transition: width 400ms ease;
}
.ob-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  gap: var(--s-3);
}
.ob-step {
  display: flex;
  gap: var(--s-2);
  align-items: flex-start;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  text-decoration: none;
  color: inherit;
  background: var(--surface-2);
}
.ob-step.done { border-color: var(--success-border, var(--border)); background: var(--success-bg); }
a.ob-step:hover { border-color: var(--accent); }
.ob-tick {
  flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-hover);
  color: var(--fg-3);
  margin-top: 1px;
}
.ob-tick.done { background: var(--success-solid); color: var(--solid-fg); }
.ob-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ob-label { font-weight: 600; font-size: var(--t-sec); }
.ob-sub { color: var(--fg-3); font-size: var(--t-min); }

/* Plain-language recap on blocked-session pages */
.story-banner {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-3);
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: var(--r-md);
}
.story-banner .sb-icon { font-size: 20px; flex: none; }
.story-banner p { margin: 0; font-size: var(--t-sec); line-height: 1.5; color: var(--fg); }
.story-banner .btn { flex: none; white-space: nowrap; }
@media (max-width: 760px) {
  .story-banner { flex-wrap: wrap; }
}

/* ============================================================
 * BILLING: pricing tiers + unit-economics math
 * ============================================================ */
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: var(--s-3);
  margin-top: var(--s-3);
}
.price-tier {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.price-tier.highlight { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.price-tier h3 { margin: 0; font-size: var(--t-section); }
.price-tier .pt-price { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.price-tier .pt-per { font-size: 14px; font-weight: 500; color: var(--fg-3); }
.price-tier .pt-price-sub { color: var(--fg-3); font-size: var(--t-min); min-height: 1.2em; }
.price-tier ul {
  margin: var(--s-2) 0;
  padding: 0 0 0 1.1em;
  color: var(--fg-2);
  font-size: var(--t-sec);
  display: grid;
  gap: 4px;
  flex: 1;
}
.price-tier .btn, .price-tier .pill { align-self: start; }
.billing-math {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s-3);
  margin-top: var(--s-3);
}
.billing-math .bm-num { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.billing-math .bm-label { color: var(--fg-3); font-size: var(--t-min); margin-top: 2px; }

/* Click-to-copy for credential values */
.copyable { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0; }
.copy-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg-3);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  font-size: 11px;
  line-height: 1.5;
  cursor: pointer;
  flex: none;
}
.copy-btn:hover { color: var(--fg); border-color: var(--border-strong); }

/* ============================================================
 * PRINT — the session page doubles as an evidence pack.
 * "Hand it to an auditor" should survive a printer: light palette
 * regardless of theme, chrome and controls gone, receipt + event
 * trail intact with their status colors.
 * ============================================================ */
@media print {
  /* An evidence pack must be COMPLETE: on-screen triage filters (kind
   * chips / text search) hide rows via .evt-hidden, but a printed
   * audit document silently missing events would look complete while
   * being cropped. Print every event regardless of the live filter. */
  .evt.evt-hidden { display: grid !important; }
  :root, [data-theme="dark"], [data-theme="light"] {
    color-scheme: light;
    --canvas: #ffffff; --surface: #ffffff; --surface-2: #fafafa; --surface-hover: #f4f4f5;
    --border: #d4d4d8; --border-strong: #a1a1aa;
    --fg: #0f0f13; --fg-2: #3f3f46; --fg-3: #52525b; --fg-4: #71717a;
    --accent: #0a5c8b; --accent-2: #0d78b3; --accent-hover: #084264; --accent-fg: #ffffff;
    --accent-bg: rgba(10,92,139,0.09); --accent-border: rgba(10,92,139,0.25);
    --success: #166534; --success-bg: #f0fdf4; --success-border: #bbf7d0; --success-solid: #16a34a; --solid-fg: #ffffff;
    --warning: #92400e; --warning-bg: #fffbeb; --warning-border: #fde68a;
    --danger: #991b1b; --danger-solid: #dc2626; --danger-bg: #fef2f2; --danger-border: #fecaca;
    --shadow-focus: none; --shadow-lg: none;
  }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { background: #fff; }
  /* Chrome + every interactive control off the page. */
  .topbar, .sidebar, .preview-banner, #toastStack, #avTour, #avTourLauncher,
  .filter-bar, .evt-filters, .page-header .actions, button, .modal-backdrop,
  .onboard-card, .range-group { display: none !important; }
  .app-shell { display: block; min-height: 0; }
  .main { padding: 0; max-width: none; }
  /* Stack the detail grid; keep blocks whole across page breaks. */
  .detail-grid { display: block; }
  .detail-grid > div { margin-top: 12px; }
  .card, .receipt-card, .event-drawer, .evt, .session-summary, .story-banner { break-inside: avoid; box-shadow: none; }
  a { color: inherit; text-decoration: none; }
  /* Payloads should not truncate in evidence. */
  .evt .body { white-space: normal; overflow: visible; text-overflow: clip; }
  .event-drawer .payload { max-height: none; overflow: visible; }
  .policy-preview, .policy-body { max-height: none; overflow: visible; }
  /* Printed-only provenance footer (rendered by the session page). */
  .print-only { display: block !important; }
  /* An empty inspector ("Click an event to inspect") is noise on paper. */
  .event-drawer:has(.empty-mini) { display: none !important; }
}
.print-only { display: none; }

/* Account menu (topbar avatar dropdown). */
#accountMenu, #orgMenu {
  position: fixed;
  min-width: 240px;
  /* Cap: the menu is sized by its content, and a long signup email
     once stretched it to ~1040px wide. Head lines ellipsize below. */
  max-width: min(320px, calc(100vw - 16px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 500;
  animation: modalIn 120ms cubic-bezier(.22,1,.36,1);
}
#accountMenu .am-head, #orgMenu .am-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; font-size: var(--t-sec); }
#accountMenu .am-head, #accountMenu .am-head .am-sub, #orgMenu .am-head, #orgMenu .am-head .am-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#accountMenu .am-head .am-sub, #orgMenu .am-head .am-sub { color: var(--fg-3); font-size: 11.5px; margin-top: 2px; }
#accountMenu [role=menuitem], #orgMenu [role=menuitem] {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left;
  background: none; border: 0; cursor: pointer;
  padding: 8px 10px; border-radius: var(--r-sm);
  font: inherit; font-size: var(--t-sec); color: var(--fg);
}
#accountMenu [role=menuitem]:hover, #accountMenu [role=menuitem]:focus-visible, #orgMenu [role=menuitem]:hover, #orgMenu [role=menuitem]:focus-visible { background: var(--surface-hover); }
#accountMenu .am-danger, #orgMenu .am-danger { color: var(--danger); }
#accountMenu .am-sep, #orgMenu .am-sep { border-top: 1px solid var(--border); margin: 6px 0; }
@media (prefers-reduced-motion: reduce) { #accountMenu { animation: none; } }

/* Bottom tab bar — phone-width primary navigation (hidden on desktop,
 * where the sidebar handles it). Fixed, safe-area aware.
 *
 * Stacking scale (bottom → top): topbar 20 · tabbar 90 ·
 * modal-backdrop 100 · cmdk-backdrop 200 · shortcut hint 300 ·
 * account menu 500 · tour launcher 900 (hidden while body.locked) ·
 * tour overlay 950 · toasts 1000 (pointer-events none).
 * The tab bar sits BELOW every overlay: it used to be z 400, above
 * open modals — a mid-form tab tap navigated and destroyed the modal
 * with no confirmation. */
.tabbar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 90;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tabbar a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 6px;
  font-size: 10.5px; font-weight: 500;
  color: var(--fg-3); text-decoration: none;
}
.tabbar a svg { width: 20px; height: 20px; }
.tabbar a.active { color: var(--accent); }
.tabbar a:active { background: var(--surface-hover); }
@media (max-width: 760px) {
  .tabbar { display: flex; }
  /* Lift the floating tour pill and toasts above the tab bar. These
     overrides live here, after the tour/toast base rules — putting
     them in the main responsive block (earlier in the file) silently
     lost to source order at equal specificity. */
  #avTourLauncher { bottom: 68px; }
  #toastStack { bottom: 120px; }
}
@media print { .tabbar { display: none !important; } }

/* Prev/next session pager on the detail header. */
.sess-nav { display: inline-flex; align-items: center; gap: 4px; }
.sess-nav .btn { padding: 5px 10px; font-weight: 600; }
.sess-nav .btn[disabled] { opacity: 0.4; cursor: default; }
.sess-nav-pos { color: var(--fg-3); font-size: var(--t-sec); min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }
@media print { .sess-nav { display: none !important; } }

/* Programmatic focus target for route changes — no ring on the whole
 * content column (focus is managed deliberately; SR still announces). */
.main:focus { outline: none; box-shadow: none; }
