/* ============================================================
   voice-ops design system
   Tokens · Layout · Components · Pages
   ============================================================ */

/* ── Tokens ───────────────────────────────────────────────── */
:root {
  /* Type families */
  --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: "Inter Tight", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Type scale — Perfect-fourth-ish, tuned for dense UI */
  --t-display:   30px;   /* page hero numbers / huge KPIs        */
  --t-h1:        22px;   /* page titles                          */
  --t-h2:        16px;   /* section titles                       */
  --t-h3:        12px;   /* card titles (uppercase eyebrow)      */
  --t-body:      14px;   /* default copy                         */
  --t-body-sm:   13px;   /* dense rows, table cells              */
  --t-caption:   12px;   /* secondary meta                       */
  --t-micro:     11px;   /* labels, KPI subs                     */
  --t-eyebrow:   10.5px; /* uppercase labels                     */

  /* Tracking */
  --tr-tight:   -0.02em;
  --tr-snug:    -0.012em;
  --tr-normal:   0;
  --tr-eyebrow:  0.08em;

  /* Spacing rhythm — 4-px base */
  --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;

  /* Radii */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 18px;

  /* Motion — one curve per intent. Use these everywhere. */
  --ease-out:    cubic-bezier(0.22, 0.61, 0.36, 1);     /* settle */
  --ease-in-out: cubic-bezier(0.4, 0.0, 0.2, 1);        /* general */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);     /* pop */
  --dur-fast:    140ms;
  --dur-base:    220ms;
  --dur-slow:    360ms;
}

:root,
[data-theme="dark"] {
  --bg:         #0a0c11;
  --bg-elev:    #10131a;
  --surface-1:  #13161e;
  --surface-2:  #181c26;
  --surface-3:  #20242f;
  --border:     #1e2330;
  --border-strong: #2a3140;
  --text:       #e9ecf3;
  --text-soft:  #b5bcca;
  --muted:      #7a8294;
  --muted-2:    #545c6e;
  --accent:     #7ab2ff;
  --accent-2:   #9dc7ff;
  --accent-soft: rgba(122,178,255,0.13);
  --accent-wash: rgba(122,178,255,0.06);
  --ok:         #5dd693;
  --warn:       #f5b045;
  --no:         #f47474;
  --outcome-order:   #5dd693;
  --outcome-ended:   #7ab2ff;
  --outcome-dropped: #757e91;
  --outcome-other:   #b48cf2;
  --user:       #f5b045;
  --agent:      #7ab2ff;
  --flow:       #b48cf2;
  --tool:       #5eead4;
  --metric:     #94a3b8;
  --button-fg:  #06080d;
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.35);
  --shadow-md:  0 10px 30px -10px rgba(0,0,0,0.55), 0 2px 6px -2px rgba(0,0,0,0.4);
  --shadow-lg:  0 24px 60px -20px rgba(0,0,0,0.7), 0 4px 12px -4px rgba(0,0,0,0.5);
  --ring:       0 0 0 3px rgba(122,178,255,0.22);
  --chart-bar:  #7ab2ff;
  --chart-area: rgba(122,178,255,0.10);
  --chart-grid: #1f2530;
}

[data-theme="light"] {
  --bg:         #f7f8fb;
  --bg-elev:    #ffffff;
  --surface-1:  #ffffff;
  --surface-2:  #ffffff;
  --surface-3:  #f1f4f9;
  --border:     #e7eaf1;
  --border-strong: #cdd3df;
  --text:       #0f141d;
  --text-soft:  #3a4252;
  --muted:      #697283;
  --muted-2:    #99a2b3;
  --accent:     #2a5ce0;
  --accent-2:   #1d49c2;
  --accent-soft: rgba(42,92,224,0.09);
  --accent-wash: rgba(42,92,224,0.04);
  --ok:         #1c9d56;
  --warn:       #b8721a;
  --no:         #d34646;
  --outcome-order:   #1c9d56;
  --outcome-ended:   #2a5ce0;
  --outcome-dropped: #6c7585;
  --outcome-other:   #7c4dd1;
  --user:       #b8721a;
  --agent:      #2a5ce0;
  --flow:       #7c4dd1;
  --tool:       #0d8c84;
  --metric:     #475569;
  --button-fg:  #ffffff;
  --shadow-sm:  0 1px 2px rgba(15,23,42,0.04);
  --shadow-md:  0 12px 32px -14px rgba(15,23,42,0.14), 0 2px 6px -2px rgba(15,23,42,0.06);
  --shadow-lg:  0 28px 60px -24px rgba(15,23,42,0.18), 0 6px 14px -6px rgba(15,23,42,0.08);
  --ring:       0 0 0 3px rgba(42,92,224,0.18);
  --chart-bar:  #2a5ce0;
  --chart-area: rgba(42,92,224,0.08);
  --chart-grid: #e8ecf2;
}

/* ── Reset & base ─────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
html { color-scheme: dark light; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--t-body);
  font-weight: 450;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* cv11 = single-storey "a"; ss01 = simpler letterforms; cv03/cv04 = round dots */
  font-feature-settings: "cv11", "ss01", "ss03", "cv03", "cv04";
}
code, .mono {
  font-family: var(--font-mono);
  font-size: 0.88em;
  font-feature-settings: "ss01", "ss02", "calt";
  font-variant-ligatures: contextual;
}
.muted { color: var(--muted); }
.soft  { color: var(--text-soft); }
.small { font-size: var(--t-caption); }
.tiny  { font-size: var(--t-micro); letter-spacing: 0.4px; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent-soft); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ── Form controls ────────────────────────────────────────── */
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 12px;
  color: var(--text);
  font-weight: 450;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
button {
  background: var(--accent);
  color: var(--button-fg);
  border: 0;
  border-radius: var(--r-md);
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: -0.005em;
  transition: background var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
button:hover { background: var(--accent-2); }
button:active { transform: translateY(1px) scale(0.99); }
button.ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border);
}
button.ghost:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }

/* ── Layout: sidebar + main ───────────────────────────────── */
body {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 20px 12px 14px;
  display: flex; flex-direction: column; gap: var(--sp-2);
  position: sticky; top: 0; height: 100vh;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 20px;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: var(--tr-tight);
}
.logo-mark { color: var(--accent); font-size: 18px; line-height: 1; }
.logo-text { font-size: 15px; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: -0.005em;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active {
  color: var(--text);
  background: var(--accent-soft);
  font-weight: 600;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px; top: 8px; bottom: 8px;
  width: 2px; border-radius: 0 2px 2px 0;
  background: var(--accent);
}
.nav-item.active svg { color: var(--accent); }
.nav-item svg {
  flex: 0 0 16px; color: var(--muted);
  transition: color var(--dur-fast) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.nav-item:hover svg { color: var(--text-soft); }
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.theme-btn {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 8px; font-weight: 500; font-size: 12px;
  display: flex; align-items: center; gap: 8px; width: 100%; justify-content: flex-start;
  cursor: pointer;
}
.theme-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ── Icon button (refresh, etc.) ──────────────────────────── */
.icon-btn {
  background: var(--surface-2); color: var(--text-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 0;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-3); }
.icon-btn:active { transform: translateY(1px) scale(0.96); }
.icon-btn svg { width: 15px; height: 15px; display: block; }

@keyframes spin { to { transform: rotate(360deg); } }
.refresh.is-refreshing svg,
.refresh.htmx-request svg { animation: spin 700ms linear infinite; }
.refresh-wrap { display: inline-flex; align-items: center; gap: 10px; }
.refresh-stamp {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.theme-icon { font-size: 14px; }

.app {
  min-width: 0;
  display: flex; flex-direction: column;
}

/* ── Page header ──────────────────────────────────────────── */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-4);
  padding: 32px 40px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.page-title h1 {
  font-family: var(--font-display);
  font-size: var(--t-h1); font-weight: 600; margin: 0;
  letter-spacing: var(--tr-tight);
  color: var(--text);
}
.page-title .subtitle {
  font-size: var(--t-body-sm);
  color: var(--muted);
  margin-top: 6px;
  font-weight: 450;
  max-width: 64ch;
}
.page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px;
  transition: border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}
.card h3 {
  margin: 0 0 14px;
  font-size: var(--t-h3);
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: var(--tr-eyebrow);
  text-transform: uppercase;
}
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-sub { font-size: var(--t-caption); color: var(--muted); font-weight: 450; }

/* ── KPI grid ─────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--sp-4);
}
.kpi {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px 16px;
  display: flex; flex-direction: column; gap: 4px;
  transition: border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}
.kpi::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
}
.kpi:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.kpi-label {
  font-family: var(--font-sans);
  font-size: var(--t-eyebrow);
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tr-eyebrow);
}
.kpi-value {
  font-family: var(--font-display);
  font-size: var(--t-display);
  font-weight: 600;
  letter-spacing: -0.028em;
  font-variant-numeric: tabular-nums;
  line-height: 1.08;
  color: var(--text);
  margin-top: 6px;
}
.kpi-value .small { font-weight: 500; font-size: 0.55em; color: var(--muted); margin-left: 2px; }
.kpi-sub { font-size: var(--t-micro); color: var(--muted); margin-top: 4px; font-weight: 450; }
.kpi-sub .pos { color: var(--ok); }
.kpi-sub .neg { color: var(--no); }

/* ── Sections & layout ────────────────────────────────────── */
.page {
  padding: 26px 40px 56px;
  display: flex; flex-direction: column; gap: var(--sp-6);
}
.section-title {
  font-size: var(--t-h3); font-weight: 600;
  text-transform: uppercase; letter-spacing: var(--tr-eyebrow);
  color: var(--muted);
  margin: 4px 0 8px;
}
.row-2 { display: grid; grid-template-columns: 2fr 1fr; gap: var(--sp-4); }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
@media (max-width: 1100px) { .row-2, .row-3 { grid-template-columns: 1fr; } }

/* ── Active filter bar ────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 10px 14px;
  padding: 12px 40px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  font-size: var(--t-caption);
}
.filter-bar-label {
  font-size: var(--t-eyebrow);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tr-eyebrow);
  color: var(--muted);
}
.filter-bar-sub {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--t-micro);
}
.filter-bar-sub em { font-style: normal; color: var(--text-soft); font-weight: 500; }
.filter-chips { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
  font-size: var(--t-micro);
  color: var(--text);
  line-height: 1.4;
}
.filter-chip-k {
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 9.5px;
}
.filter-chip-v { color: var(--text); font-weight: 500; }
.filter-chip-x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  color: var(--accent);
  font-size: 14px; line-height: 1;
  font-weight: 500;
  background: transparent;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.filter-chip-x:hover { background: var(--accent); color: var(--button-fg); }
.filter-clear {
  font-size: var(--t-micro);
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  padding: 4px 6px;
  transition: color var(--dur-fast) var(--ease-out);
}
.filter-clear:hover { color: var(--text); }

@media (max-width: 640px) {
  .filter-bar { padding: 10px 16px; gap: 8px; }
  .filter-bar-sub { width: 100%; margin-left: 0; }
}

/* ── Filters / chips ──────────────────────────────────────── */
.filters {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.filters select { min-width: 200px; }
.filters input[type=search] { min-width: 240px; flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; font-size: 12px;
  cursor: pointer; user-select: none;
  transition: border-color 140ms ease, background 140ms ease;
}
.chip:hover { border-color: var(--border-strong); }
.chip input { margin: 0; accent-color: var(--accent); }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ── Calls list ───────────────────────────────────────────── */
.calls-shell {
  display: grid;
  grid-template-columns: 400px 1fr;
  flex: 1;
  min-height: 0;
}
.calls-list-pane {
  border-right: 1px solid var(--border);
  background: var(--surface-1);
  overflow-y: auto;
  max-height: calc(100vh - 1px);
}
.calls-detail-pane {
  overflow-y: auto;
  background: var(--bg);
  max-height: calc(100vh - 1px);
}

/* Universal loading state for any HTMX swap target.
   Add class="swap-target" to a div that other elements swap content into,
   and add hx-indicator="#that-div" to the triggers. During the request,
   HTMX adds .htmx-request to the target → existing content blurs and
   a centered spinner appears. Works for the call detail pane, the call
   list, and any future target we add. */
.swap-target {
  position: relative;
  transition: filter 140ms ease, opacity 140ms ease;
  min-height: 80px;       /* so the spinner has room to sit even on empty targets */
}
.swap-target.htmx-request > * {
  filter: blur(4px);
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
}
.swap-target.htmx-request::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  margin: -16px 0 0 -16px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
  z-index: 2;
  pointer-events: none;
}
.swap-target.htmx-request::before {
  content: "Loading…";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, 28px);
  font-size: 11px;
  letter-spacing: 0.4px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 600;
  z-index: 2;
  pointer-events: none;
}
.list-head {
  position: sticky; top: 0; z-index: 1;
  padding: 14px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.calls { list-style: none; margin: 0; padding: 6px 0; }
.call-row {
  position: relative;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex; flex-direction: column; gap: 5px;
  transition: background var(--dur-fast) var(--ease-out),
              padding-left var(--dur-fast) var(--ease-out);
}
.call-row:hover { background: var(--surface-2); }
.call-row.active { background: var(--accent-soft); }
.call-row.active::before {
  content: "";
  position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 2px; border-radius: 0 2px 2px 0;
  background: var(--accent);
}
.call-row.active .num { color: var(--text); }
.row-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-badges { display: inline-flex; gap: 4px; align-items: center; }
.row-restaurant { font-size: 11px; color: var(--muted); }
.num { font-weight: 600; font-size: var(--t-body); font-variant-numeric: tabular-nums; letter-spacing: -0.005em; font-family: var(--font-mono); }
.badge {
  font-size: 10px; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px; font-weight: 700;
}
.badge.ok { background: rgba(74,222,128,0.16); color: var(--ok); }
.badge.no { background: rgba(122,132,153,0.14); color: var(--muted); }
.badge.rec { background: rgba(106,168,255,0.16); color: var(--accent); padding: 2px 8px; }
.badge.anom {
  background: rgba(245,176,69,0.16);
  color: var(--warn);
  padding: 2px 8px;
  text-transform: lowercase;
  letter-spacing: 0.3px;
  cursor: help;
}
.row-meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }
.row-meta .end { font-style: italic; }
.summary { font-size: 12px; color: var(--muted); }

/* ── Detail ───────────────────────────────────────────────── */
.detail { padding: 26px 32px; max-width: 900px; margin: 0 auto; }
.detail-head { margin-bottom: 22px; }
.detail-head h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 19px; font-weight: 600;
  letter-spacing: var(--tr-snug);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.detail-head h2 code { color: var(--accent); font-size: 12px; }
.restaurant-tag {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-soft);
  font-weight: 500;
}
.meta-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px 18px;
}
.kv { display: flex; flex-direction: column; gap: 3px; }
.kv .k { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600; }
.kv .v { font-size: 14px; font-variant-numeric: tabular-nums; }
.block { margin-top: 26px; }
.block-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.block h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--muted); margin: 0; font-weight: 600;
}

/* ── "Why this call ended" — disconnect_reason event ──────── */
.why-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px 14px;
}
.why-cell {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 3px;
}
.why-k {
  font-size: var(--t-eyebrow);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: var(--tr-eyebrow);
  font-weight: 600;
}
.why-v {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: var(--tr-snug);
  color: var(--text);
}
.why-v.mono { font-family: var(--font-mono); font-size: 13px; letter-spacing: 0; }
.why-v.why-ok { color: var(--ok); }
.why-v.why-no { color: var(--warn); }
.why-v.why-na { color: var(--muted); font-weight: 500; }
.why-utter { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.why-quote {
  margin: 0;
  padding: 10px 14px;
  border-left: 2px solid var(--accent);
  background: var(--accent-wash);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  font-size: var(--t-body-sm);
  color: var(--text);
  font-style: italic;
  line-height: 1.5;
}

/* ── Audio player ─────────────────────────────────────────── */
.audio-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 16px;
}
.audio-card audio { width: 100%; min-width: 0; }
[data-theme="dark"] audio { filter: invert(0.92) hue-rotate(180deg); }
.audio-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ── Items / order ────────────────────────────────────────── */
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.items > li {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px;
}
.mods { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.states { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.states li {
  display: grid; grid-template-columns: 70px 1fr auto;
  gap: 12px; font-size: 12px; padding: 6px 8px;
  border-radius: 6px;
  align-items: center;
}
.states li:hover { background: var(--surface-2); }
.states .ts { color: var(--muted); font-family: var(--font-mono); }
.state-event { font-weight: 600; color: var(--flow); }
.state-flow { color: var(--muted); font-size: 11px; }

/* ── Transcript feed ──────────────────────────────────────── */
.chat-feed {
  display: flex; flex-direction: column;
  max-width: 720px;
}
.turn {
  display: grid;
  grid-template-columns: 30px 1fr;
  grid-template-areas:
    "avatar head"
    "avatar text";
  column-gap: 12px;
  row-gap: 2px;
  padding-top: 16px;
  position: relative;
}
.turn.turn-cont {
  grid-template-areas: "avatar text";
  padding-top: 3px;
}
.turn-avatar {
  grid-area: avatar;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0;
  user-select: none;
  margin-top: 1px;
}
.turn.turn-cont .turn-avatar { visibility: hidden; height: 0; margin: 0; }
.turn-agent .turn-avatar {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(122,178,255,0.25);
}
.turn-user .turn-avatar {
  background: rgba(245,176,69,0.14);
  color: var(--warn);
  box-shadow: inset 0 0 0 1px rgba(245,176,69,0.28);
}
[data-theme="light"] .turn-agent .turn-avatar { box-shadow: inset 0 0 0 1px rgba(42,92,224,0.20); }
[data-theme="light"] .turn-user  .turn-avatar { box-shadow: inset 0 0 0 1px rgba(184,114,26,0.25); }

.turn-head {
  grid-area: head;
  display: flex; align-items: baseline; gap: 8px;
  line-height: 1.2;
  margin-bottom: 3px;
}
.turn-name {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.005em;
  color: var(--text);
}
.turn-user .turn-name { color: var(--warn); }
.turn-agent .turn-name { color: var(--accent); }
.turn-time {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}
.turn-text {
  grid-area: text;
  font-size: var(--t-body-sm);
  line-height: 1.55;
  color: var(--text);
  font-weight: 450;
  word-break: break-word;
}

/* Subtle separator only between speaker groups (a new turn-head exists). */
.turn:not(.turn-cont) + .turn:not(.turn-cont),
.turn.turn-cont + .turn:not(.turn-cont) {
  margin-top: 4px;
}

/* ── Disclosure (collapsed-by-default sections) ───────────── */
details.tech { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 10px; }
details.tech summary {
  cursor: pointer; list-style: none;
  font-size: 12px; color: var(--text-soft); font-weight: 500;
  padding: 8px 0;
  display: flex; align-items: center; gap: 8px;
  user-select: none;
}
details.tech summary:hover { color: var(--text); }
details.tech summary::-webkit-details-marker { display: none; }
details.tech summary::before {
  content: "";
  width: 8px; height: 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  display: inline-block;
  transition: transform 180ms cubic-bezier(.2,.8,.2,1);
  margin-right: 2px;
}
details.tech[open] summary::before { transform: rotate(45deg); }
.timeline {
  list-style: none; margin: 8px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.ev {
  display: grid; grid-template-columns: 60px 56px 1fr; gap: 10px; align-items: start;
  padding: 6px 8px; border-radius: 6px; font-size: 12px;
}
.ev:hover { background: var(--surface-2); }
.ev .ts { color: var(--muted); font-family: var(--font-mono); }
.ev .who {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 700;
  padding: 2px 6px; border-radius: 4px; align-self: start; text-align: center;
}
.ev .who.user { background: rgba(251,191,36,0.16); color: var(--user); }
.ev .who.agent { background: rgba(106,168,255,0.16); color: var(--agent); }
.ev .who.flow { background: rgba(192,132,252,0.18); color: var(--flow); }
.ev .who.tool { background: rgba(94,234,212,0.16); color: var(--tool); }
.ev .who.metric { background: rgba(148,163,184,0.16); color: var(--metric); }
.ev .text { font-size: 12px; word-break: break-word; line-height: 1.5; }

/* ── Empty / loading ──────────────────────────────────────── */
.empty {
  color: var(--muted); padding: 48px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center;
}
.empty-title { font-size: 14px; color: var(--text-soft); font-weight: 500; }
.empty-sub { font-size: 12px; }

/* ── Charts: sparkline, bars ──────────────────────────────── */
.sparkline { width: 100%; height: 90px; display: block; }
.spark-area { fill: var(--chart-area); }
.spark-line { fill: none; stroke: var(--chart-bar); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-overlay { fill: none; stroke: var(--outcome-order); stroke-width: 1.5; stroke-dasharray: 3 4; }
.spark-axis { stroke: var(--chart-grid); stroke-width: 1; }
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row {
  display: grid; grid-template-columns: 110px 1fr 56px;
  gap: 10px; align-items: center; font-size: 12px;
}
.bar-row .label { color: var(--text-soft); }
.bar-row .track {
  background: var(--surface-3); border-radius: 999px; height: 8px; overflow: hidden;
}
.bar-row .fill {
  height: 100%; background: var(--chart-bar); border-radius: 999px;
  transition: width 240ms cubic-bezier(.2,.8,.2,1);
}
.bar-row .fill.alt { background: var(--chart-bar-2); }
.bar-row .val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.hist {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 6px; align-items: end; height: 120px;
}
.hist-bar {
  display: flex; flex-direction: column; justify-content: flex-end;
  height: 100%; gap: 4px;
}
.hist-bar .stem {
  background: var(--chart-bar); border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 280ms cubic-bezier(.2,.8,.2,1);
}
.hist-bar .lbl { font-size: 10px; color: var(--muted); text-align: center; font-family: var(--font-mono); }
.hist-bar .n   { font-size: 10px; color: var(--text-soft); text-align: center; font-variant-numeric: tabular-nums; }

.pct-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-bottom: 12px;
}
.pct-row .pct {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
.pct .k { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.pct .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Outcome stack-bar (order / agent ended / caller dropped) */
.stack {
  display: flex; height: 10px; border-radius: 999px; overflow: hidden;
  background: var(--surface-3); margin-bottom: 14px;
}
.stack > span { height: 100%; transition: width 320ms cubic-bezier(.2,.8,.2,1); }
.stack .o-order   { background: var(--outcome-order); }
.stack .o-ended   { background: var(--outcome-ended); }
.stack .o-dropped { background: var(--outcome-dropped); }
.stack .o-closed  { background: var(--warn); }
.stack .o-other   { background: var(--outcome-other); }
.stack .d-clean   { background: var(--ok); }
.stack .d-anom    { background: var(--warn); }
.stack .d-dropped { background: var(--outcome-dropped); }
.stack .d-unknown { background: var(--muted-2); }
.legend {
  display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-soft);
}
.legend > div { display: inline-flex; align-items: center; gap: 8px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch.o-order   { background: var(--outcome-order); }
.swatch.o-ended   { background: var(--outcome-ended); }
.swatch.o-dropped { background: var(--outcome-dropped); }
.swatch.o-closed  { background: var(--warn); }
.swatch.o-other   { background: var(--outcome-other); }
.swatch.d-clean   { background: var(--ok); }
.swatch.d-anom    { background: var(--warn); }
.swatch.d-dropped { background: var(--outcome-dropped); }
.swatch.d-unknown { background: var(--muted-2); }
.legend .count { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ── Outcome chip (call-row + detail) */
.outcome {
  font-size: 10px; letter-spacing: 0.4px; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
}
.outcome::before {
  content: ""; width: 6px; height: 6px; border-radius: 999px; display: inline-block;
}
.outcome.order   { background: rgba(93,214,147,0.14); color: var(--outcome-order); }
.outcome.order::before { background: var(--outcome-order); }
.outcome.ended   { background: rgba(122,178,255,0.14); color: var(--outcome-ended); }
.outcome.ended::before { background: var(--outcome-ended); }
.outcome.dropped { background: rgba(117,126,145,0.16); color: var(--muted); }
.outcome.dropped::before { background: var(--outcome-dropped); }
.outcome.closed  { background: rgba(245,176,69,0.14); color: var(--warn); }
.outcome.closed::before  { background: var(--warn); }
.outcome.other   { background: rgba(180,140,242,0.14); color: var(--outcome-other); }
.outcome.other::before { background: var(--outcome-other); }

/* ── Slow tool / blocked-call row */
.row-line {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border);
  align-items: center; font-size: 13px;
}
.row-line:last-child { border-bottom: 0; }
.row-line .lead { font-weight: 500; }
.row-line .meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }

/* ── Result code chip (tool events) */
.rc {
  font-size: 10px; padding: 1px 6px; border-radius: 4px; font-weight: 600;
  text-transform: lowercase; letter-spacing: 0.2px;
}
.rc.ok        { background: rgba(93,214,147,0.14); color: var(--ok); }
.rc.invoked   { background: rgba(122,178,255,0.14); color: var(--accent); }
.rc.blocked   { background: rgba(245,176,69,0.16); color: var(--warn); }
.rc.error,
.rc.halt      { background: rgba(244,116,116,0.16); color: var(--no); }
.rc.not_found,
.rc.wrong_group,
.rc.already_full { background: rgba(117,126,145,0.16); color: var(--muted); }

/* ── Restaurants ──────────────────────────────────────────── */
.r-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.r-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
  transition: transform var(--dur-base) var(--ease-out),
              border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out);
}
.r-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.r-name {
  font-family: var(--font-display);
  font-size: 15px; font-weight: 600;
  letter-spacing: var(--tr-snug);
}
.r-addr { font-size: var(--t-caption); color: var(--muted); font-weight: 450; }
.r-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; }
.r-stat .k {
  font-size: var(--t-eyebrow); color: var(--muted);
  text-transform: uppercase; letter-spacing: var(--tr-eyebrow);
  font-weight: 600;
}
.r-stat .v {
  font-family: var(--font-display);
  font-size: 16px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tr-snug);
}

/* ── Recent calls strip ───────────────────────────────────── */
.recent {
  display: flex; flex-direction: column; gap: 4px;
}
.recent-row {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 10px; padding: 8px 10px; border-radius: 8px;
  align-items: center; font-size: 12px;
  transition: background 120ms ease;
}
.recent-row:hover { background: var(--surface-2); }
.recent-row .who { color: var(--text-soft); }
.recent-row .when { color: var(--muted); font-family: var(--font-mono); }

/* ── Section header on analytics page ─────────────────────── */
.section {
  display: flex; flex-direction: column; gap: var(--sp-4);
  padding-top: 6px;
}
.section + .section {
  padding-top: 28px;
  border-top: 1px solid var(--border);
  margin-top: var(--sp-3);
}
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 14px;
  margin-bottom: 2px;
}
.section-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--t-h2);
  font-weight: 600;
  letter-spacing: var(--tr-snug);
  color: var(--text);
}
.section-head .hint {
  font-size: var(--t-caption);
  color: var(--muted);
  font-weight: 450;
  max-width: 52ch;
  text-align: right;
}

/* ── Percentile hero card (perf section) ──────────────────── */
.perf {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}
.perf:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.perf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.perf-name { font-size: var(--t-body-sm); color: var(--text-soft); font-weight: 550; letter-spacing: -0.005em; }
.perf-n { font-size: var(--t-micro); color: var(--muted); font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.perf-hero {
  display: flex; align-items: baseline; gap: 10px;
  margin: 4px 0 4px;
}
.perf-p95 {
  font-family: var(--font-display);
  font-size: var(--t-display); font-weight: 600;
  letter-spacing: -0.028em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--text);
}
.perf-unit { font-size: var(--t-body); color: var(--muted); font-weight: 500; }
.perf-label {
  font-size: var(--t-eyebrow); color: var(--muted);
  text-transform: uppercase; letter-spacing: var(--tr-eyebrow);
  font-weight: 600;
}
.perf-percentiles {
  display: flex; gap: 18px; font-size: var(--t-caption); color: var(--muted);
}
.perf-percentiles strong {
  color: var(--text-soft); font-weight: 600; font-variant-numeric: tabular-nums;
}
.mini-bars {
  display: flex; align-items: flex-end;
  height: 22px;
  gap: 2px; margin-top: 6px;
  overflow: hidden;             /* belt-and-braces against any overflow */
  flex-shrink: 0;
}
.mini-bars span {
  flex: 1 1 0;
  background: var(--accent);
  opacity: 0.35;
  border-radius: 2px;
  min-height: 2px;
  max-height: 100%;
  transition: opacity 160ms ease;
}
.perf:hover .mini-bars span { opacity: 0.55; }

/* ── Data table ───────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--t-body-sm); }
.data-table thead th {
  text-align: left;
  font-size: var(--t-eyebrow); font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: var(--tr-eyebrow);
  padding: 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table thead th.num {
  text-align: right;
  font-family: var(--font-sans);
  font-size: var(--t-eyebrow);
}
.data-table tbody td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-weight: 450;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background var(--dur-fast) var(--ease-out); }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: var(--t-caption);
  color: var(--text);
}
.data-table td.tool { font-family: var(--font-mono); font-weight: 500; color: var(--text-soft); }
.data-table td .dim { color: var(--muted); font-weight: 400; }

/* ── Inline result-code segmented bar ─────────────────────── */
.seg {
  display: flex; height: 8px; border-radius: 999px; overflow: hidden;
  background: var(--surface-3);
}
.seg > span { height: 100%; }
.seg .s-ok      { background: var(--outcome-order); }
.seg .s-invoked { background: var(--accent); }
.seg .s-blocked { background: var(--warn); }
.seg .s-error,
.seg .s-halt    { background: var(--no); }
.seg .s-not_found,
.seg .s-wrong_group,
.seg .s-already_full { background: var(--muted-2); }

/* compact three-column grid for behavior block */
.row-3-tight { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 1100px) { .row-3-tight { grid-template-columns: 1fr; } }

/* ── Primary button (Dial trigger) ────────────────────────── */
.primary-btn {
  background: var(--accent); color: var(--button-fg);
  border: 0; border-radius: 8px;
  padding: 8px 14px; font-weight: 600; font-size: 13px;
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer;
  transition: filter 140ms ease, transform 100ms ease;
}
.primary-btn:hover { filter: brightness(1.07); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn svg { opacity: 0.9; }

/* ── Modal (dialer) ───────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fade-in 200ms var(--ease-out);
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
}
[data-theme="light"] .modal-backdrop { background: rgba(15, 22, 36, 0.34); }
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: min(520px, 96vw);
  padding: 24px 24px 22px;
  animation: scale-in 260ms var(--ease-out);
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.modal-head h2, .modal-head h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: var(--tr-snug);
  margin: 0;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scale-in {
  from { opacity: 0; transform: scale(0.965) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Banner inside modal */
.banner {
  font-size: 12px;
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-soft);
}
.banner.warn { border-color: rgba(245,176,69,0.4); background: rgba(245,176,69,0.08); color: var(--warn); }
.banner.ok   { color: var(--muted); }

/* Dial form layout */
.dial-form {
  display: flex; gap: 10px; align-items: flex-end;
  flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 11px; color: var(--muted); font-weight: 500; }
.dial-form select, .dial-form input { padding: 10px 12px; font-size: 14px; }
.dial-form select { min-width: 168px; }
.dial-form input { width: 100%; min-width: 160px; }
.dial-go {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--button-fg);
  border: 0; border-radius: 8px; padding: 10px 16px;
  font-weight: 600; font-size: 14px; cursor: pointer;
  transition: filter 140ms ease;
}
.dial-go:hover { filter: brightness(1.07); }
.dial-spinner { display: none; }
.dial-spinner.htmx-request, .dial-go.htmx-request .dial-spinner { display: inline-flex; }
.dial-go.htmx-request svg:not(.dial-spinner svg) { display: none; }
.dial-spinner svg { width: 14px; height: 14px; animation: spin 700ms linear infinite; }

/* Dial result */
.dial-result {
  margin-top: 14px;
  border-radius: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.dial-result.ok { border-color: rgba(93,214,147,0.4); }
.dial-result.err { border-color: rgba(244,116,116,0.4); background: rgba(244,116,116,0.06); }
.dial-result-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dial-result-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px 16px; margin-top: 8px; font-size: 12px;
}
.dial-result-meta .k { color: var(--muted); }
.dial-result-meta .v { color: var(--text); }
.status-dot {
  width: 8px; height: 8px; border-radius: 999px; display: inline-block;
  background: var(--muted);
}
.status-dot.ringing {
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(93,214,147,0.6);
  animation: pulse 1.4s cubic-bezier(.2,.8,.2,1) infinite;
}
.status-dot.err { background: var(--no); }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(93,214,147,0.55); }
  70%  { box-shadow: 0 0 0 10px rgba(93,214,147,0); }
  100% { box-shadow: 0 0 0 0 rgba(93,214,147,0); }
}

kbd {
  font-family: var(--font-mono); font-size: 10px;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; color: var(--text-soft);
}

/* ── Login screen ─────────────────────────────────────────── */
/* Force-reset body's app grid for this page, regardless of source order. */
body.login-body {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}
.login-shell {
  width: 100%;
  display: flex; justify-content: center;
}
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 36px 32px 28px;
  width: min(400px, 100%);
  display: flex; flex-direction: column; gap: 20px;
  box-shadow: var(--shadow-lg);
  animation: card-rise 480ms var(--ease-out) both;
}
@keyframes card-rise {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.login-brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-display);
  font-weight: 600; font-size: 13px;
  color: var(--text-soft);
  letter-spacing: var(--tr-snug);
}
.login-brand .logo-mark { color: var(--accent); font-size: 16px; }
.login-card h1 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 26px; font-weight: 600;
  letter-spacing: var(--tr-tight);
  line-height: 1.15;
}
.login-sub {
  margin: 0; color: var(--muted);
  font-size: var(--t-body-sm);
  line-height: 1.55;
  max-width: 36ch;
}

.password-wrap {
  position: relative; display: flex; align-items: center;
}
.password-wrap input {
  flex: 1; padding: 11px 40px 11px 14px;
  font-size: 14px;
}
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; cursor: pointer;
  color: var(--muted); padding: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
  transition: color 140ms ease, background 140ms ease;
}
.pw-toggle:hover { color: var(--text); background: var(--surface-3); }
.pw-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.login-go {
  background: var(--accent); color: var(--button-fg);
  border: 0; border-radius: 10px; padding: 12px 16px;
  font-weight: 600; font-size: 14px; cursor: pointer;
  margin-top: 2px;
  transition: filter 140ms ease, transform 100ms ease;
}
.login-go:hover { filter: brightness(1.07); }
.login-go:active { transform: translateY(1px); }

.login-foot {
  display: flex; justify-content: center;
  padding-top: 4px; margin-top: 4px;
  border-top: 1px solid var(--border);
}
.login-foot a { text-decoration: none; }
.login-foot a:hover { color: var(--text); }
.logout-form { margin-top: 6px; }
.logout-btn {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 8px;
  font-size: 12px; font-weight: 500;
  display: flex; align-items: center; gap: 8px; width: 100%;
  justify-content: flex-start; cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}
.logout-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ── Nav badge (for "hack"-flagged items) ─────────────────── */
.nav-badge {
  margin-left: auto;
  background: rgba(245,176,69,0.16);
  color: var(--warn);
  font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  padding: 1px 6px; border-radius: 999px;
}

/* ── Language switches list ───────────────────────────────── */
.lang-switches {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.lang-switches li {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center; gap: 10px;
  font-size: var(--t-caption);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.lang-from { color: var(--text-soft); text-align: right; font-weight: 500; }
.lang-arrow { color: var(--muted); font-family: var(--font-mono); }
.lang-to { color: var(--accent); font-weight: 600; }
.lang-n {
  color: var(--muted); font-variant-numeric: tabular-nums;
  font-family: var(--font-mono); font-size: var(--t-micro);
}

/* ── Outbound dials table ─────────────────────────────────── */
.ob-table { width: 100%; }
.ob-row { cursor: pointer; }
.ob-row:hover { background: var(--surface-2); }
.ob-detail { display: none; background: var(--surface-2); }
.ob-detail.open { display: table-row; }
.ob-detail-inner { padding: 10px 14px 14px; }
.ob-events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.ob-events li { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.ob-events .ts { color: var(--muted); }
.ob-err { color: var(--no); font-size: 12px; }

.ob-status {
  font-size: 10px; padding: 2px 7px; border-radius: 999px; font-weight: 700;
  text-transform: lowercase; letter-spacing: 0.3px;
  display: inline-block;
}
.ob-status.ob-ok    { background: rgba(93,214,147,0.16);  color: var(--ok); }
.ob-status.ob-warn  { background: rgba(245,176,69,0.16);  color: var(--warn); }
.ob-status.ob-no    { background: rgba(244,116,116,0.16); color: var(--no); }
.ob-status.ob-muted { background: var(--surface-3); color: var(--muted); }
.ob-ok { color: var(--ok); font-size: 12px; }

.sid-btn {
  display: inline-block; background: transparent;
  border: 1px solid var(--border); color: var(--text-soft);
  padding: 3px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 500; text-decoration: none;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}
.sid-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.sid-copy {
  background: transparent; border: 0; cursor: pointer;
  color: var(--muted); padding: 4px;
  margin-left: 2px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle;
  transition: color 140ms ease, background 140ms ease;
}
.sid-copy:hover { color: var(--text); background: var(--surface-3); }
.sid-copy.copied { color: var(--ok); }
.sid-copy.copied svg { transform: scale(1.15); }

/* ── Motion ───────────────────────────────────────────────── */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in-soft {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px) scale(0.992); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Page-level entrance — gentler, content-respecting. */
.page-head { animation: fade-in-soft 320ms var(--ease-out) both; }
.page { animation: rise-in 380ms var(--ease-out) both; animation-delay: 40ms; }
.calls-shell, .detail { animation: rise-in 340ms var(--ease-out) both; }

/* Stagger first row of KPIs and section cards — small, deliberate, never showy. */
.kpi-grid > .kpi { animation: rise-in 420ms var(--ease-out) both; }
.kpi-grid > .kpi:nth-child(1) { animation-delay: 40ms; }
.kpi-grid > .kpi:nth-child(2) { animation-delay: 90ms; }
.kpi-grid > .kpi:nth-child(3) { animation-delay: 140ms; }
.kpi-grid > .kpi:nth-child(4) { animation-delay: 190ms; }
.kpi-grid > .kpi:nth-child(5) { animation-delay: 240ms; }
.kpi-grid > .kpi:nth-child(6) { animation-delay: 290ms; }

.row-2 > *, .row-3 > *, .row-3-tight > * { animation: rise-in 420ms var(--ease-out) both; }
.row-2 > *:nth-child(2),
.row-3 > *:nth-child(2),
.row-3-tight > *:nth-child(2) { animation-delay: 70ms; }
.row-3 > *:nth-child(3),
.row-3-tight > *:nth-child(3) { animation-delay: 130ms; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Responsive ───────────────────────────────────────────── */
/* Four tiers, narrowing as you go:
   ≤1024px  small laptop / tablet landscape — scale spacing
   ≤900px   tablet portrait — sidebar becomes a top app bar
   ≤640px   phone — stack page-head, 2-up KPIs, full-width filters
   ≤420px   tiny phone — type tightens, padding shrinks further
*/

/* ── Tablet landscape (≤1024px) ───────────────────────────── */
@media (max-width: 1024px) {
  .page { padding: 22px 28px 48px; }
  .page-head { padding: 26px 28px 18px; }
  .detail   { padding: 22px 24px; }
  .calls-shell { grid-template-columns: 340px 1fr; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .row-3-tight[style*="grid-template-columns"] {
    /* Inline-styled 4-col grids (hallucination KPIs) drop to 2-col here. */
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ── Tablet portrait (≤900px): sidebar → bottom tab bar + top tray ──
   Mobile-native architecture:
     • Nav becomes a fixed bottom tab bar (5 items, all visible, thumb-reach)
     • Theme + sign-out become a floating top-right tray (icons only)
     • Logo retired on mobile — page-head titles already identify the view
     • Body padding compensates so content never sits under either bar
   The desktop sidebar element still exists; we just lift its children
   into fixed positions via CSS, no JS or template changes needed.            */
@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    /* Reserve vertical space for top tray + bottom nav so .app content
       never disappears under either of them. iOS safe-area for notch / home-bar. */
    padding-top: max(0px, env(safe-area-inset-top));
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  /* The .sidebar element becomes a non-visual container — its children
     are repositioned individually. */
  .sidebar {
    display: contents;
  }
  .logo { display: none; }

  /* ── Bottom tab bar (the nav) ── */
  .nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface-1) 92%, transparent);
    backdrop-filter: saturate(140%) blur(12px);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px -12px rgba(0,0,0,0.18);
  }
  .nav-item {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 3px;
    padding: 6px 4px;
    border-radius: 10px;
    font-size: 10.5px;
    font-weight: 500;
    color: var(--muted);
    line-height: 1.1;
    min-height: 50px;
    position: relative;
    /* Hide the desktop active-rail; bottom nav uses its own indicator. */
  }
  .nav-item svg {
    width: 20px; height: 20px;
    color: var(--muted);
    transition: color var(--dur-fast) var(--ease-out),
                transform var(--dur-fast) var(--ease-out);
  }
  .nav-item:active svg { transform: scale(0.9); }
  .nav-item.active {
    color: var(--accent);
    background: transparent;
    box-shadow: none;
    font-weight: 600;
  }
  .nav-item.active svg { color: var(--accent); }
  /* iOS-style active indicator: small bar at the top of the active tab */
  .nav-item.active::before {
    content: "";
    position: absolute;
    top: -1px; left: 50%;
    transform: translateX(-50%);
    width: 22px; height: 2.5px;
    border-radius: 0 0 3px 3px;
    background: var(--accent);
    /* Override the desktop left-rail styling */
    bottom: auto;
  }
  .nav-badge {
    /* The "hack" badge becomes a tiny corner dot on mobile */
    position: absolute; top: 4px; right: 50%;
    transform: translate(14px, 0);
    margin: 0; padding: 0;
    width: 6px; height: 6px;
    background: var(--warn); color: transparent;
    border-radius: 50%;
    font-size: 0;
  }

  /* ── Top utility tray (theme + sign out) ── */
  .sidebar-footer {
    position: fixed;
    top: calc(8px + env(safe-area-inset-top));
    right: 10px;
    z-index: 35;
    display: flex; gap: 6px;
    margin: 0; padding: 0; border: 0;
    pointer-events: auto;
  }
  .theme-btn, .logout-btn {
    width: 38px; height: 38px;
    padding: 0; gap: 0;
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface-1) 88%, transparent);
    backdrop-filter: saturate(140%) blur(10px);
    -webkit-backdrop-filter: saturate(140%) blur(10px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--text-soft);
  }
  .theme-btn:hover, .logout-btn:hover { color: var(--text); }
  .theme-btn .theme-label,
  .logout-btn .logout-label { display: none; }
  .logout-form { margin: 0; }

  /* Page-head no longer competes with a top sidebar — give it a touch
     of right padding so it doesn't sit under the top tray icons. */
  .page-head { padding-right: calc(40px + 86px); }

  .calls-shell { grid-template-columns: 1fr; }
  .calls-list-pane {
    max-height: 50vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .calls-detail-pane { max-height: none; }

  /* Wide data tables get horizontal scroll inside their card so the
     overall layout doesn't break. The card grows a scrollbar of its own. */
  .card:has(> .data-table),
  .card:has(> table.data-table) { overflow-x: auto; }
  .data-table { min-width: 560px; }
}

/* ── Phone (≤640px) ───────────────────────────────────────── */
@media (max-width: 640px) {
  :root {
    --t-display: 26px;   /* KPI hero numbers shrink slightly */
    --t-h1:      19px;
  }
  .page { padding: 18px 16px 32px; gap: var(--sp-5); }
  .page-head {
    /* Right padding reserves room for the floating top tray
       (2 × 38px buttons + spacing). */
    padding: 18px 96px 14px 16px;
    flex-direction: column; align-items: stretch;
    gap: 12px;
  }
  .page-actions { width: 100%; }
  .filters { width: 100%; flex-wrap: wrap; }
  .filters select,
  .filters input[type=search] {
    width: 100%; min-width: 0; flex: 1 1 100%;
  }

  /* 2-up KPIs on phone — 1-up is overkill, 4-up never fits */
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px 14px 12px; }
  .kpi-value { font-size: var(--t-display); }

  /* Inline-styled "row-3-tight" 4-col grids → 2-col already; here go 2-col on phone too */
  .row-3-tight[style*="grid-template-columns"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .card { padding: 16px; border-radius: var(--r-md); }
  .perf { padding: 14px 16px; }

  .detail { padding: 18px 16px; }
  .detail-head h2 { font-size: 17px; gap: 8px; }
  .detail-head h2 code { word-break: break-all; }

  /* Meta KV grid — 2-up at this size, single only on tiny */
  .meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
  .why-grid  { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
  .why-cell  { padding: 9px 11px; }
  .why-v     { font-size: 14px; }

  /* Chat feed: drop the max-width cap so messages use the screen */
  .chat-feed { max-width: none; }
  .turn { column-gap: 10px; }
  .bubble { max-width: 88%; }

  /* Touch-friendly buttons. 38px height feels right on phones; system
     guidelines (44px) are for full taps — these are surrounded by spacing. */
  .icon-btn { width: 38px; height: 38px; }
  button, .primary-btn, .dial-go, .login-go { padding: 10px 14px; }
  .nav-item { padding: 9px 12px; min-height: 38px; }

  /* Audio card — let the player breathe */
  .audio-card { flex-wrap: wrap; }
  .audio-card audio { flex: 1 1 100%; }
  .audio-meta { width: 100%; text-align: right; }

  /* Modal padding tightens; never let it touch the edge */
  .modal-backdrop { padding: 12px; }
  .modal { padding: 18px 18px 16px; }
  .modal-head h2, .modal-head h3 { font-size: 16px; }
  .dial-form { gap: 8px; }
  .dial-form select, .dial-form input { width: 100%; min-width: 0; }

  /* Section dividers tighter */
  .section + .section { padding-top: 22px; }
  .section-head { flex-wrap: wrap; gap: 4px; }
  .section-head .hint { text-align: left; max-width: none; }

  /* Outbound table: rows are clickable to expand — keep the table but make
     it scroll horizontally rather than break layout. */
  .ob-table { min-width: 640px; }
}

/* ── Tiny phone (≤420px) ──────────────────────────────────── */
@media (max-width: 420px) {
  :root {
    --t-display: 24px;
    --t-h1:      18px;
  }
  .page { padding: 14px 12px 28px; }
  .page-head { padding: 14px 92px 12px 12px; }
  .detail { padding: 14px 12px; }

  /* Single column when there's truly no room */
  .meta-grid { grid-template-columns: 1fr; }
  .why-grid  { grid-template-columns: 1fr; }

  .kpi { padding: 12px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

  /* Call-row meta wraps better at this width */
  .row-top { gap: 6px; }
  .row-badges { flex-wrap: wrap; justify-content: flex-end; }
  .call-row { padding: 12px 14px; }

  /* Bubble feed tightens a touch more */
  .turn-avatar { width: 24px; height: 24px; font-size: 10px; }
  .turn { grid-template-columns: 24px 1fr; column-gap: 10px; }

  /* Tighten nav padding but keep labels — horizontal scroll handles
     overflow, and label text is more recognisable than icons alone. */
  .nav-item { padding: 8px 10px; }
}

/* ── Login: card sits nicely on phone ─────────────────────── */
@media (max-width: 500px) {
  body.login-body { padding: 16px; }
  .login-card { padding: 24px 22px 22px; }
  .login-card h1 { font-size: 22px; }
}
