/*
 * Dashboard styling. Dark mode is SELECTED, not an inverted flip: the series
 * colours are the palette's own dark steps, validated against the dark surface
 * (docs/dashboard.md). Both scopes are declared — the media query covers the
 * OS setting, the data-theme scope a future toggle.
 */

:root {
  color-scheme: light;
  --page:      #f9f9f7;
  --surface:   #fcfcfb;
  --ink-1:     #0b0b0b;
  --ink-2:     #52514e;
  --muted:     #898781;
  --grid:      #e1e0d9;
  --axis:      #c3c2b7;
  --series-1:  #2a78d6;   /* blue   */
  --series-2:  #eb6834;   /* orange */
  --series-3:  #1baf7a;   /* aqua — 2.74:1 on this surface, hence the
                             mandatory direct labels and table view */
  --good:      #006300;
  --bad:       #b3261e;
  --radius:    10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:     #0d0d0d;
    --surface:  #1a1a19;
    --ink-1:    #ffffff;
    --ink-2:    #c3c2b7;
    --muted:    #898781;
    --grid:     #2c2c2a;
    --axis:     #383835;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good:     #0ca30c;
    --bad:      #f2857e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:     #0d0d0d;
  --surface:  #1a1a19;
  --ink-1:    #ffffff;
  --ink-2:    #c3c2b7;
  --grid:     #2c2c2a;
  --axis:     #383835;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good:     #0ca30c;
  --bad:      #f2857e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink-1);
  font: 15px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 0.95rem; margin: 0; font-weight: 650; }
h3 { font-size: 0.9rem; margin: 0 0 8px; font-weight: 650; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.screen { max-width: 1120px; margin: 0 auto; padding: 16px; }

/* ── sign in ─────────────────────────────────────────────────────────────── */

#screen-auth { display: grid; place-items: center; min-height: 100vh; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: var(--radius);
  padding: 28px;
  width: min(380px, 100%);
}
.auth-card p { margin: 6px 0 20px; }
.auth-card label { display: block; font-size: 0.8rem; color: var(--ink-2); margin-bottom: 6px; }
.auth-card input {
  width: 100%; padding: 10px 12px; margin-bottom: 12px;
  background: var(--page); color: var(--ink-1);
  border: 1px solid var(--axis); border-radius: 8px; font: inherit;
}
#in-code { font: 1.3rem/1 var(--mono); letter-spacing: 0.3em; text-align: center; }
.auth-card button[type="submit"] {
  width: 100%; padding: 10px; border: 0; border-radius: 8px;
  background: var(--series-1); color: #fff; font: inherit; font-weight: 600;
  cursor: pointer;
}
.notice {
  margin: 14px 0 0; padding: 10px 12px; border-radius: 8px;
  background: var(--page); border: 1px solid var(--grid);
  font-size: 0.85rem; color: var(--ink-2);
}

button.link {
  background: none; border: 0; padding: 4px 0; margin-top: 10px;
  color: var(--series-1); font: inherit; cursor: pointer; text-decoration: underline;
}

/* ── chrome ──────────────────────────────────────────────────────────────── */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 4px 0 16px; flex-wrap: wrap;
}
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 0.85rem; }
.topbar-right button.link { margin: 0; }

.filters { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters button {
  padding: 6px 12px; border: 1px solid var(--axis); border-radius: 999px;
  background: var(--surface); color: var(--ink-2); font: inherit; font-size: 0.85rem;
  cursor: pointer;
}
.filters button.on { background: var(--series-1); border-color: var(--series-1); color: #fff; }
#range-label { font-size: 0.8rem; margin-left: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-head input[type="search"] {
  padding: 7px 12px; min-width: 220px;
  background: var(--page); color: var(--ink-1);
  border: 1px solid var(--axis); border-radius: 8px; font: inherit; font-size: 0.85rem;
}

/* ── KPI row ─────────────────────────────────────────────────────────────── */

.kpis {
  display: grid; gap: 10px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.kpi {
  background: var(--surface); border: 1px solid var(--grid);
  border-radius: var(--radius); padding: 12px 14px;
}
.kpi .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.kpi .value { font-size: 1.6rem; font-weight: 640; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { font-size: 0.75rem; color: var(--ink-2); }

/* ── charts ──────────────────────────────────────────────────────────────── */

.charts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
@media (max-width: 520px) { .charts { grid-template-columns: 1fr; } }

.chart-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 2px; }
.chart-note { margin: 0; font-size: 0.75rem; }

.legend { display: flex; gap: 14px; list-style: none; margin: 6px 0 4px; padding: 0; flex-wrap: wrap; }
.legend li { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--ink-2); }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.plot { position: relative; }
.chart { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .tick { font: 11px var(--sans); }
.chart .direct { font: 600 10px var(--sans); }

.tip {
  position: absolute; top: 4px; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--axis);
  border-radius: 8px; padding: 7px 9px; pointer-events: none;
  font-size: 0.78rem; white-space: nowrap; z-index: 2;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.12);
}
.tip-day { color: var(--muted); font-size: 0.72rem; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tip-row strong { margin-left: auto; color: var(--ink-1); font-variant-numeric: tabular-nums; }

.chart-table { margin-top: 10px; }
.chart-table summary {
  cursor: pointer; font-size: 0.78rem; color: var(--series-1); width: max-content;
}
.chart-table table { margin-top: 8px; }
.chart-table { max-height: 320px; overflow: auto; }

/* ── tables ──────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.grid th, table.grid td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
table.grid th {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600;
}
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: var(--page); }
table.grid tbody tr:last-child td { border-bottom: 0; }
td.dim { color: var(--muted); }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600; border: 1px solid var(--axis); color: var(--ink-2);
}
.pill.live   { color: var(--good); border-color: currentColor; }
.pill.ending { color: var(--bad);  border-color: currentColor; }

.pager { display: flex; align-items: center; gap: 12px; margin-top: 12px; font-size: 0.85rem; }
.pager button {
  padding: 6px 12px; border: 1px solid var(--axis); border-radius: 8px;
  background: var(--surface); color: var(--ink-2); font: inherit; font-size: 0.85rem; cursor: pointer;
}
.pager button:disabled { opacity: 0.4; cursor: default; }

/* ── transcript ──────────────────────────────────────────────────────────── */

.turn { margin-bottom: 18px; }
.turn .who {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 4px;
}
.turn .said {
  background: var(--page); border: 1px solid var(--grid);
  border-radius: 8px; padding: 10px 12px; white-space: pre-wrap;
}
.turn.q .said { border-left: 3px solid var(--series-1); }
.turn .meta { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }
