/* Switchboard · signed-in surface.
   Denser than the marketing pages (Ledger density 7) but the same tokens.
   Layout: fixed sidebar + scrolling main, one topbar, no nested chrome. */

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

/* ── sidebar ─────────────────────────────────────────────────────────────── */
.side {
  min-width: 0;
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: var(--surface);
}
.side-brand { display: flex; align-items: center; gap: 9px; padding: var(--s4) var(--s4) var(--s3); font-weight: 600; letter-spacing: -0.02em; }
.side-brand .brand-mark { width: 20px; height: 20px; color: var(--accent); }

.org-switch {
  display: flex; align-items: center; gap: var(--s2);
  margin: 0 var(--s3) var(--s4);
  padding: 7px 9px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--ground); font-size: 13.5px; width: calc(100% - var(--s5));
}
.org-switch .avatar {
  width: 20px; height: 20px; flex: none; border-radius: var(--radius-xs);
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
}
.org-switch .chev { margin-left: auto; width: 13px; height: 13px; color: var(--muted); }

.side-nav { min-width: 0; padding-inline: var(--s3); display: grid; gap: 1px; overflow-y: auto; }
.side-group { margin-top: var(--s5); }
.side-group:first-child { margin-top: 0; }
.side-group > h4 {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted); font-weight: 500; padding: 0 9px var(--s2);
}
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 9px; border-radius: var(--radius-sm);
  font-size: 14px; color: var(--ink-2);
  transition: background-color 160ms ease, color 160ms ease;
}
.side-nav a svg, .side-nav a .ic { width: 16px; height: 16px; flex: none; stroke-width: 1.6; }
.side-nav a:hover { background: var(--surface-2); color: var(--ink); }
.side-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.side-nav a .count { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }

.side-foot { margin-top: auto; padding: var(--s3); border-top: 1px solid var(--line); display: grid; gap: var(--s3); }
.usage-meter { display: grid; gap: 6px; padding: 9px; border-radius: var(--radius-sm); background: var(--ground); border: 1px solid var(--line); }
.usage-meter .row { display: flex; justify-content: space-between; font-size: 12px; }
.usage-meter .row b { font-family: var(--mono); font-weight: 500; }
.usage-meter .row .lbl { color: var(--muted); }
.bar { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.bar-warn i { background: var(--warn); }

.user-chip { display: flex; align-items: center; gap: var(--s2); padding: 6px; border-radius: var(--radius-sm); font-size: 13px; }
.user-chip:hover { background: var(--surface-2); }
.user-chip .avatar { width: 24px; height: 24px; flex: none; border-radius: 50%; background: var(--surface-2); color: var(--ink-2); display: grid; place-items: center; font-size: 10.5px; font-weight: 600; font-family: var(--mono); }
.user-chip .who { display: grid; line-height: 1.25; min-width: 0; }
.user-chip .who b { font-weight: 500; }
.user-chip .who span { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

/* ── main ────────────────────────────────────────────────────────────────── */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s4);
  padding: 0 var(--s5); height: 56px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--ground) 90%, transparent);
  backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 17px; letter-spacing: -0.015em; }
.crumbs { display: flex; align-items: center; gap: var(--s2); font-size: 13.5px; color: var(--muted); }
.crumbs a:hover { color: var(--ink); }
.crumbs .sep { opacity: 0.5; }
.topbar-right { display: flex; align-items: center; gap: var(--s3); margin-left: auto; }
.search {
  display: flex; align-items: center; gap: var(--s2);
  padding: 6px 10px; width: 240px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--muted); font-size: 13.5px;
}
.search svg { width: 14px; height: 14px; flex: none; }
.search kbd {
  margin-left: auto; font-family: var(--mono); font-size: 10px;
  padding: 1px 5px; border: 1px solid var(--line-strong); border-radius: 3px;
}
@media (max-width: 1100px) { .search { display: none; } }

/* Grid and flex items default to min-width:auto, so a child that cannot wrap
   (the segmented range picker, a wide table) grows its track instead of
   scrolling inside it — 169px of document overflow at 390px, measured. */
.content { min-width: 0; padding: var(--s5); display: grid; gap: var(--s5); align-content: start; }
.content > *, .split > *, .panel { min-width: 0; }
.content-wide { max-width: 1280px; }

/* ── page toolbar (filters + range) ──────────────────────────────────────── */
.toolbar { min-width: 0; display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.toolbar .grow { margin-left: auto; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); padding: 2px; gap: 2px; }
.segmented button {
  padding: 4px 11px; border: 0; border-radius: var(--radius-xs);
  background: transparent; color: var(--muted); font-size: 13px;
  transition: background-color 160ms ease, color 160ms ease;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--ground); color: var(--ink); font-weight: 500; }
.filter {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--ground); font-size: 13px; color: var(--ink-2);
}
.filter svg, .filter .ic { width: 13px; height: 13px; color: var(--muted); }
.filter:hover { border-color: var(--line-strong); }

/* ── panels ──────────────────────────────────────────────────────────────── */
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--ground); }
.panel-head {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 14px; font-weight: 600; letter-spacing: -0.005em; }
.panel-head .grow { margin-left: auto; }
.panel-body { padding: var(--s4); }
.panel-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: var(--s3); }

/* ── KPI tiles. Layer 4 (outcome) first, layer 1 (infra) last — docs/05. ─── */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s3); }
@media (max-width: 1080px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .tiles { grid-template-columns: 1fr; } }
.tile {
  padding: var(--s4);
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--ground);
  display: grid; gap: 6px; align-content: start;
}
.tile .k .ic { width: 12px; height: 12px; }
.tile .k { display: flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.tile .v { font-family: var(--mono); font-size: 1.75rem; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; }
.tile .v small { font-size: 0.9rem; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.tile .d { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); }
.delta { font-family: var(--mono); font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 3px; }
.delta-up { color: var(--ok); }
.delta-down { color: var(--crit); }
.delta svg, .delta .ic { width: 11px; height: 11px; stroke-width: 2.4; }
/* A target line under the number, so a figure is read against its threshold
   rather than against nothing. Thresholds are sourced in docs/05. */
.tile .target { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }

/* ── tables ──────────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; padding: 9px var(--s4);
  background: var(--surface); border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--muted); font-weight: 500; white-space: nowrap;
}
.tbl tbody td { padding: 10px var(--s4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr { transition: background-color 140ms ease; }
.tbl tbody tr:hover { background: var(--surface); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-family: var(--mono); }
.tbl .t-num { font-family: var(--mono); font-size: 13px; }
.tbl .t-sub { display: block; font-size: 11.5px; color: var(--muted); }
.tbl a.rowlink { color: var(--ink); font-weight: 500; }
.tbl a.rowlink:hover { color: var(--accent); }

/* ── charts (inline SVG, no library) ─────────────────────────────────────── */
.chart { width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; }
.chart .series-a { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-b { fill: none; stroke: var(--warn); stroke-width: 1.75; stroke-dasharray: 4 3; }
.chart .area-a { fill: var(--accent); opacity: 0.09; }
.chart .bar-a { fill: var(--accent); }
.chart .bar-muted { fill: var(--line-strong); }
.legend { display: flex; gap: var(--s4); font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 2px; margin-right: 6px; vertical-align: middle; }
.legend .a i { background: var(--accent); }
.legend .b i { background: var(--warn); }

/* ── transcript ──────────────────────────────────────────────────────────── */
.transcript { display: grid; gap: var(--s4); }
.t-turn { display: grid; grid-template-columns: 62px 1fr; gap: var(--s4); align-items: start; }
.t-turn .ts { font-family: var(--mono); font-size: 11.5px; color: var(--muted); padding-top: 3px; }
.t-turn .bubble { padding: 10px 13px; border-radius: var(--radius); font-size: 14.5px; }
.t-agent .bubble { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent); }
.t-caller .bubble { background: var(--ground); border: 1px solid var(--line-strong); }
.t-turn .who { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.t-tool {
  grid-column: 2; display: inline-flex; align-items: center; gap: var(--s2); flex-wrap: wrap;
  padding: 6px 10px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); background: var(--surface);
}
.t-tool svg, .t-tool .ic { width: 12px; height: 12px; color: var(--accent); }

/* ── audio scrubber ──────────────────────────────────────────────────────── */
.player { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); }
.player .play { width: 32px; height: 32px; flex: none; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--ground); display: grid; place-items: center; }
.player .play svg, .player .play .ic { width: 13px; height: 13px; }
.wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 30px; }
.wave i { flex: 1; background: var(--line-strong); border-radius: 1px; min-width: 2px; }
.wave i.on { background: var(--accent); }
.player .time { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ── two-column detail layout ────────────────────────────────────────────── */
.split { display: grid; grid-template-columns: 1fr 320px; gap: var(--s5); align-items: start; }
@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } }
.kv { display: grid; gap: var(--s3); font-size: 13.5px; }
.kv .r { display: grid; grid-template-columns: 108px 1fr; gap: var(--s3); }
.kv .r dt { color: var(--muted); }
.kv .r dd { margin: 0; }

/* ── config form layout ──────────────────────────────────────────────────── */
.formgrid { display: grid; gap: var(--s5); max-width: 640px; }
.formrow { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
@media (max-width: 720px) { .formrow { grid-template-columns: 1fr; } }
.tabs { display: flex; gap: var(--s5); border-bottom: 1px solid var(--line); }
.tabs a { padding: 10px 0; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }

.toggle-row { display: flex; align-items: flex-start; gap: var(--s4); padding: var(--s4) 0; border-bottom: 1px solid var(--line); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row .txt { display: grid; gap: 3px; }
.toggle-row .txt b { font-weight: 500; font-size: 14px; }
.toggle-row .txt span { font-size: 13px; color: var(--muted); max-width: 54ch; }
.switch { margin-left: auto; flex: none; width: 38px; height: 22px; border-radius: 11px; border: 1px solid var(--line-strong); background: var(--surface-2); position: relative; transition: background-color 180ms ease, border-color 180ms ease; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--ground); transition: transform 180ms ease; box-shadow: 0 1px 2px rgba(0,0,0,0.18); }
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }

/* ── empty state ─────────────────────────────────────────────────────────── */
.empty { display: grid; gap: var(--s3); place-items: center; text-align: center; padding: var(--s8) var(--s5); }
.empty svg { width: 26px; height: 26px; color: var(--muted); stroke-width: 1.4; }
.empty p { font-size: 14px; max-width: 40ch; }

/* ── mobile: the sidebar collapses to a top row ──────────────────────────── */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-nav { display: flex; overflow-x: auto; overscroll-behavior-x: contain; gap: var(--s2); padding-bottom: var(--s3); }
  .side-group { margin-top: 0; display: contents; }
  .side-group > h4 { display: none; }
  .side-nav a { white-space: nowrap; }
  .side-foot { display: none; }
  .org-switch { display: none; }
}
