:root {
  --ground: #F5F4EF;
  --surface: #FFFFFF;
  --ink: #16181D;
  --muted: #5B5E66;
  --line: #DEDCD4;
  --line-soft: #EEEDE7;
  --field: #C9C7BE;
  --accent: #1D3FAF;
  --accent-ink: #142C7A;
  --selected: #EEF1FB;
  --ok: #1E6B3A;   --ok-bg: #DDF1E3;
  --warn: #8A4B00; --warn-bg: #FCEBD3;
  --bad: #9B1C1C;  --bad-bg: #F9DEDC;
  --go: #0B5C5C;   --go-bg: #D8EEEC;
  --vapi: #4B32A0; --vapi-bg: #E9E4F8;
  --live: #8A3F0A; --live-bg: #FBE8D8;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 14px/1.45 var(--sans); }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -0.4px; }
h2 { margin: 0; font-size: 18px; font-weight: 600; }
pre, code, .mono { font-family: var(--mono); }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.ok { color: var(--ok); font-weight: 500; }
.warn { color: var(--warn); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 28px; padding: 12px 32px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font: 600 15px var(--mono); color: var(--ink); text-decoration: none; }
.brand span { color: var(--muted); }
.top nav { display: flex; flex-wrap: wrap; gap: 4px; }
.top nav a { padding: 10px 14px; border-radius: 6px; color: var(--ink); text-decoration: none; font-weight: 500; }
.top nav a[aria-current] { background: var(--ink); color: #fff; }

/* Layout */
.wrap { max-width: 1280px; margin: 0 auto; padding: 32px 24px 64px; display: flex; flex-direction: column; gap: 20px; }
.split { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.grow { flex: 999 1 620px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.stack { flex: 1 1 340px; max-width: 440px; display: flex; flex-direction: column; gap: 16px; }
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.head > div { display: flex; flex-direction: column; gap: 6px; }
.sub { margin: 0; color: var(--muted); max-width: 600px; }
.panel { flex: 1 1 340px; max-width: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.wrap > .panel { max-width: none; }
.stack .panel { max-width: none; }
.box { padding: 14px; border-radius: 8px; background: var(--ground); }

/* Flash */
.flash { padding: 12px 16px; border-radius: 10px; background: var(--ok-bg); color: var(--ok); font-weight: 500; }
.flash.error { background: var(--bad-bg); color: var(--bad); }
.toast { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 16px; padding: 16px; border-radius: 10px; background: var(--ink); color: #fff; }
.toast pre { margin: 8px 0 0; color: #E4E3DD; font-size: 13px; white-space: pre-wrap; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.stat span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
.stat b { font: 500 24px var(--mono); }
@media (max-width: 560px) { .stats { grid-template-columns: minmax(0, 1fr); } }

/* Chips & filters */
.filters { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--field); background: var(--surface); color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 500; }
.chip[aria-current] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* Tables */
.table { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
table { width: 100%; min-width: 820px; border-collapse: collapse; }
th { text-align: left; padding: 12px 16px; color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.6px; border-bottom: 1px solid var(--line); }
td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.selected td { background: var(--selected); }
tr.off td, tr.expired td, tr.archived td { opacity: 0.6; }
tr.off td:last-child, tr.expired td:last-child, tr.archived td:last-child { opacity: 1; }
.num { text-align: right; }
.pin { font: 600 18px var(--mono); letter-spacing: 1px; }
.pin.small { font-size: 14px; }
.who { font-weight: 500; }
.note { color: var(--muted); font-size: 12px; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.rowlink { color: var(--ink); font-weight: 600; text-decoration: none; }
.rowlink:hover { text-decoration: underline; color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.actions form { margin: 0; }
.cc { display: inline-block; min-width: 26px; padding: 2px 4px; border: 1px solid var(--field); border-radius: 4px; font: 600 11px var(--mono); text-align: center; }

/* Badges */
.badge { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-go { background: var(--go-bg); color: var(--go); }
.b-vapi { background: var(--vapi-bg); color: var(--vapi); }
.b-gpt_live { background: var(--live-bg); color: var(--live); }
.b-other { background: #ECEBE4; color: #3A3D44; }
.o-completed, .o-routed { background: var(--ok-bg); color: var(--ok); }
.o-bad_pin, .o-no_pin { background: var(--warn-bg); color: var(--warn); }
.o-hangup, .o-prompted { background: #ECEBE4; color: #3A3D44; }
.o-error { background: var(--bad-bg); color: var(--bad); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--ink); border-radius: 8px; background: var(--surface); color: var(--ink); font: 600 14px var(--sans); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { color: var(--ink); background: var(--ground); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); color: #fff; }
.btn.ghost { border-color: var(--field); font-weight: 500; }
.btn.light { background: #fff; border-color: #fff; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; }

/* Switch */
.switch { width: 52px; height: 44px; padding: 0; border: 0; background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.switch span { position: relative; display: block; width: 40px; height: 22px; border-radius: 11px; background: #B9B7AE; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 8px; background: #fff; transition: left 120ms; }
.switch[aria-pressed="true"] span { background: var(--ok); }
.switch[aria-pressed="true"] span::after { left: 21px; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.form.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form label, .label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
input, select { min-height: 44px; padding: 0 12px; border: 1px solid var(--field); border-radius: 8px; background: var(--surface); color: var(--ink); font: 400 14px var(--sans); }
input.mono { font-family: var(--mono); font-size: 13px; }
input:disabled { background: var(--ground); }
.pin-input { font: 600 20px var(--mono); letter-spacing: 4px; }
.narrow { width: 90px; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
.inline select { min-height: 36px; }
.inline input { min-height: 36px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.hint.warn { color: var(--warn); }
.seg { margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 6px; }
.seg legend { padding: 0 0 6px; font-weight: 500; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; }
.seg legend { grid-column: 1 / -1; }
.seg.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--field); margin-left: -1px; font-weight: 600; cursor: pointer; }
.seg label:first-of-type span { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg label:last-of-type span { border-radius: 0 8px 8px 0; }
.seg input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.code { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--ink); color: #E4E3DD; font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; }
.kv { margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.kv dt { color: var(--muted); margin-top: 8px; }
.kv dd { margin: 0; word-break: break-all; }

/* Timeline */
.timeline { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
.timeline li { display: flex; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.timeline li:last-child { border-bottom: 0; }
.timeline li > :first-child { flex: 0 0 72px; }

/* Recordings */
.recording { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.recording audio { width: min(100%, 520px); }
.rec { display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 4px; background: var(--bad); vertical-align: middle; }

.top .who { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.wrap > .panel.login { width: 100%; max-width: 400px; margin: 48px auto 0; }
