/* Sarah's calls: Clocktower Cars dashboard. Light theme only. */
:root {
  color-scheme: light;
  --navy: #0f2a44;
  --navy-2: #173a5c;
  --teal: #0f766e;
  --teal-2: #115e59;
  --teal-soft: #ecfdf8;
  --ink: #142233;
  --ink-2: #3d4b5c;
  --muted: #5f6e82;
  --line: #e3e8ef;
  --line-2: #cfd7e2;
  --page: #f3f5f8;
  --card: #ffffff;
  --grid: #e8ebe6;
  --axis: #c3c2b7;
  --critical: #d03b3b;
  --critical-soft: #fdf0f0;
  --focus: #2a78d6;
  /* Outcome colours, in stack order (validated as a set). Text never uses them. */
  --c-booked: #008300;
  --c-changed: #2a78d6;
  --c-cancelled: #eb6834;
  --c-transferred: #6250d6;
  --c-no_booking: #1baf7a;
  --c-ended_early: #eda100;
  --c-problem: #e34948;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 42, 68, 0.06), 0 1px 1px rgba(15, 42, 68, 0.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--teal-2); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.noscript { padding: 24px; }
.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; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- buttons and inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--line-2); background: #fff; color: var(--ink);
  cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { background: #f6f8fb; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-2); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(15, 42, 68, 0.06); }
.btn.small { height: 28px; padding: 0 9px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; flex: none; }
.input, .select {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-2); background: #fff; min-width: 0;
}
.input:focus, .select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px rgba(42, 120, 214, 0.15); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); font-weight: 600; }

/* ---------- top bar ---------- */
.topbar { background: var(--navy); color: #fff; }
.topbar .inner { max-width: 1320px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo { width: 30px; height: 30px; flex: none; }
.brand .name { font-weight: 700; font-size: 15px; letter-spacing: 0.1px; }
.brand .sub { color: #a9c3dc; font-size: 12.5px; }
.topbar .spacer { flex: 1; }
.topbar .updated { color: #a9c3dc; font-size: 12.5px; }
.topbar .btn.ghost { color: #e6eef6; }
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 42, 68, 0.16); padding: 6px;
}
.menu-list .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-list .who b { display: block; }
.menu-list button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; }
.menu-list button:hover { background: #f3f6fa; }

/* ---------- layout ---------- */
.wrap { max-width: 1320px; margin: 0 auto; padding: 16px 20px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 6px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 14.5px; font-weight: 700; }
.card-head .hint { color: var(--muted); font-size: 12.5px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 8px 16px 16px; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding: 12px 14px; margin-bottom: 14px; }
.filters .group { display: flex; flex-direction: column; gap: 4px; }
.filters .group > .lbl { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.filters .dates { display: flex; gap: 6px; align-items: center; }
.filters .dates .input { width: 140px; }
.filters .search { flex: 1 1 220px; min-width: 180px; }
.filters .search .input { width: 100%; }
.toggle { display: inline-flex; align-items: center; gap: 8px; height: 34px; cursor: pointer; user-select: none; font-weight: 500; }
.toggle input { width: 16px; height: 16px; accent-color: var(--teal); }
.multi { position: relative; }
.multi > .btn { min-width: 150px; justify-content: space-between; }
.multi-list {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 25; min-width: 240px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 42, 68, 0.16); padding: 6px;
}
.multi-list label { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.multi-list label:hover { background: #f3f6fa; }
.multi-list input { width: 16px; height: 16px; accent-color: var(--teal); }
.multi-list .foot { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }
.chips-active { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 6px 0 10px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line-2); font-size: 12.5px;
}
.chip button { border: 0; background: none; cursor: pointer; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.chip button:hover { background: #eef2f6; color: var(--ink); }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { padding: 14px 16px 13px; }
.kpi .label { font-size: 12.5px; color: var(--ink-2); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi .label .key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.kpi .value { font-size: 28px; font-weight: 650; letter-spacing: -0.4px; margin-top: 4px; line-height: 1.15; }
.kpi .note { font-size: 12.5px; color: var(--muted); margin-top: 3px; min-height: 18px; }

/* ---------- chart + breakdown ---------- */
.panels { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 12px; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; height: 28px; padding: 0 10px; cursor: pointer; font-size: 12.5px; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.chart-box { position: relative; }
.chart-box svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart-box .axis-text { fill: #6d6c66; font-size: 11px; }
.chart-box .grid { stroke: var(--grid); stroke-width: 1; }
.chart-box .baseline { stroke: var(--axis); stroke-width: 1; }
.chart-box .hit { fill: transparent; cursor: pointer; }
.chart-box .col:hover .seg-rect, .chart-box .col:focus .seg-rect { filter: brightness(1.12); }
.chart-box .col:focus { outline: none; }
.chart-box .col:focus .hit { stroke: var(--focus); stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-empty { height: 240px; display: grid; place-items: center; color: var(--muted); text-align: center; }
.chart-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 10px; }
.chart-table th, .chart-table td { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.chart-table th:first-child, .chart-table td:first-child { text-align: left; }
.chart-table-wrap { max-height: 260px; overflow: auto; }
.breakdown { list-style: none; margin: 0; padding: 0; }
.breakdown li { margin: 0; }
.breakdown button {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; text-align: left;
  padding: 8px 8px; border: 0; background: none; border-radius: 8px; cursor: pointer;
}
.breakdown button:hover { background: #f5f7fa; }
.breakdown button[aria-pressed="true"] { background: var(--teal-soft); box-shadow: inset 0 0 0 1px #b6e8dc; }
.breakdown .name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.breakdown .name i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.breakdown .count { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.breakdown .count b { color: var(--ink); }
.breakdown .track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: #eef1f5; overflow: hidden; }
.breakdown .fill { height: 100%; border-radius: 4px; min-width: 0; }

/* ---------- calls table ---------- */
.table-wrap { overflow-x: auto; }
table.calls { width: 100%; border-collapse: separate; border-spacing: 0; }
table.calls th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px;
  border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap;
}
table.calls td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.calls tbody tr { cursor: pointer; }
table.calls tbody tr:hover td { background: #f8fafc; }
table.calls tbody tr.open td { background: var(--teal-soft); }
table.calls tbody tr:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.when b { display: block; font-weight: 600; white-space: nowrap; }
.when span { color: var(--muted); font-size: 12.5px; }
td.caller-cell { white-space: nowrap; font-variant-numeric: tabular-nums; }
.summary { color: var(--ink-2); max-width: 520px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rec-cell { text-align: center; width: 48px; }
.rec-icon { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--teal-soft); color: var(--teal); }
.rec-icon svg { width: 14px; height: 14px; }
.rec-none { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; height: 24px; padding: 0 10px 0 8px; border-radius: 999px;
  background: #f1f4f8; color: var(--ink); font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.pill i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 6px; font-size: 11.5px; font-weight: 600; background: #eef1f5; color: var(--ink-2); }
.tag.test { background: #f1eefe; color: #4a3aa7; }
.tag.warn { background: var(--critical-soft); color: #a62828; }
.tag svg { width: 12px; height: 12px; }
.booking-cell .ref { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.booking-cell .state { font-size: 12px; color: var(--ink-2); }
.booking-cell .pick { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.state-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.state-active { background: #0ca30c; }
.state-changed { background: #2a78d6; }
.state-cancelled { background: #9aa6b5; }
.state-failed { background: var(--critical); }
.pager { display: flex; align-items: center; gap: 10px; padding: 12px 16px; flex-wrap: wrap; }
.pager .spacer { flex: 1; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.loading-frame { transition: opacity 0.15s; }
.is-loading .loading-frame { opacity: 0.5; }
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; background: var(--critical-soft); color: #7f1d1d; border: 1px solid #f5caca; }
.banner .spacer { flex: 1; }
.info-banner { background: #f0f6ff; color: #173a5c; border-color: #cfe0f7; }

/* ---------- drawer ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(15, 42, 68, 0.28); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 100vw); background: #fff; z-index: 41;
  box-shadow: -12px 0 40px rgba(15, 42, 68, 0.2); display: flex; flex-direction: column;
}
.drawer-head { padding: 14px 18px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.drawer-head .title { flex: 1; min-width: 0; }
.drawer-head h2 { margin: 6px 0 2px; font-size: 17px; }
.drawer-head .meta { color: var(--muted); font-size: 13px; }
.drawer-body { overflow-y: auto; padding: 16px 18px 40px; flex: 1; }
.drawer section { margin-bottom: 20px; }
.drawer h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--teal); margin: 0 0 8px; }
.player { background: #f6f8fb; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.player audio { width: 100%; display: block; }
.player .speeds { display: flex; gap: 6px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.player .note { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.player .unavailable { color: var(--ink-2); }
.what { font-size: 14.5px; line-height: 1.5; }
.review { background: var(--teal-soft); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; font-size: 13px; }
.facts div span { display: block; color: var(--muted); font-size: 12px; }
.facts code { font-size: 12px; word-break: break-all; }
.booking-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.booking-card .top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.booking-card .top b { font-size: 15px; font-variant-numeric: tabular-nums; }
.booking-card dl { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
.booking-card dt { color: var(--muted); }
.booking-card dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 10px 0 0; border-top: 1px dashed var(--line-2); padding-top: 8px; font-size: 12.5px; }
.timeline li { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; }
.timeline li .when { color: var(--muted); white-space: nowrap; }
.timeline li.this { font-weight: 600; }
.linkish { border: 0; background: none; color: var(--teal-2); text-decoration: underline; cursor: pointer; padding: 0; font-size: inherit; }
.transcript { display: flex; flex-direction: column; gap: 8px; }
.turn { display: flex; gap: 8px; align-items: flex-start; }
.turn .bubble { padding: 8px 11px; border-radius: 12px; max-width: 85%; font-size: 13.5px; line-height: 1.45; overflow-wrap: anywhere; white-space: normal; }
.turn.sarah .bubble { background: #eef4fb; border-top-left-radius: 4px; }
.turn.caller { flex-direction: row-reverse; }
.turn.caller .bubble { background: #f2f2ee; border-top-right-radius: 4px; }
.turn .who { font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.turn .ts { border: 0; background: none; color: var(--teal-2); font-size: 11.5px; cursor: pointer; padding: 10px 0 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.turn .ts:hover { text-decoration: underline; }
.turn.event { justify-content: center; }
.turn.event .ev { font-size: 12px; color: var(--ink-2); background: #fafafa; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; display: inline-flex; gap: 6px; align-items: center; }
.turn.event .ev svg { width: 12px; height: 12px; }
.turn.event.failed .ev { background: var(--critical-soft); border-color: #f5caca; color: #8a2020; }
.turn.event.ok .ev { background: #f0faf0; border-color: #cbe9cb; color: #14532d; }
.turn.playing .bubble { box-shadow: inset 0 0 0 2px #7fb3ea; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 55%, #1c4a6e 100%); }
.login .panel { width: min(400px, 100%); background: #fff; border-radius: 16px; padding: 28px 26px 22px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25); }
.login .brand { margin-bottom: 18px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login p.lead { margin: 0 0 18px; color: var(--muted); }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login .input { height: 40px; }
.login .btn.primary { height: 40px; justify-content: center; }
.login .error { color: #a62828; background: var(--critical-soft); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.login .help { color: var(--muted); font-size: 12.5px; margin-top: 14px; }

/* ---------- modal, tooltip, toast ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(15, 42, 68, 0.35); padding: 16px; }
.modal .panel { width: min(420px, 100%); background: #fff; border-radius: 14px; padding: 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
.modal h2 { margin: 0 0 12px; font-size: 17px; }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.modal .error { color: #a62828; font-size: 13px; }
.tooltip {
  position: fixed; z-index: 80; pointer-events: none; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 42, 68, 0.18); padding: 9px 11px; font-size: 12.5px; min-width: 170px;
}
.tooltip .t-head { font-weight: 700; margin-bottom: 6px; }
.tooltip .t-row { display: grid; grid-template-columns: 14px 1fr auto; gap: 7px; align-items: center; padding: 1px 0; }
.tooltip .t-row i { height: 2px; border-radius: 1px; display: block; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }
.tooltip .t-row span { color: var(--ink-2); }
.tooltip .t-foot { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 5px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 90; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); font-size: 13.5px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 920px) {
  .panels { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .topbar .inner { padding: 10px 14px; gap: 8px; }
  .topbar .updated, .brand .sub { display: none; }
  .wrap { padding: 12px 12px 32px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 23px; }
  .filters { padding: 10px; gap: 8px; }
  .filters .group { flex: 1 1 140px; }
  .filters .dates .input { width: 100%; }
  .multi > .btn { width: 100%; min-width: 0; }
  table.calls thead { display: none; }
  table.calls, table.calls tbody, table.calls tr, table.calls td { display: block; width: 100%; }
  table.calls tr { border-bottom: 1px solid var(--line); padding: 10px 12px; position: relative; }
  table.calls td { border: 0; padding: 2px 0; }
  table.calls td.rec-cell { position: absolute; right: 12px; top: 12px; width: auto; }
  table.calls td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-size: 12.5px; }
  .multi-list { max-width: calc(100vw - 24px); }
  .summary { max-width: none; }
  .drawer { width: 100vw; }
  .facts { grid-template-columns: minmax(0, 1fr); }
  .booking-card dl { grid-template-columns: 96px 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media print {
  .topbar .btn, .filters, .pager, .drawer, .backdrop { display: none !important; }
  body { background: #fff; }
}
