/* ---------------------------------------------------------------------------
   Palette. Light and dark are both selected sets, not an automatic flip.
   Validated for CVD separation and contrast against each surface.
   --------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);

  --series-1: #2a78d6; /* blue   — calls / sequential default */
  --series-2: #1baf7a; /* aqua   — sales */
  --series-3: #eb6834; /* orange — drops */

  --seq-100: #cde2fb;
  --seq-250: #86b6ef;
  --seq-400: #3987e5;
  --seq-550: #1c5cab;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --success-text: #006300;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 12px rgba(11, 11, 11, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #d95926;
    --seq-100: #184f95;
    --seq-250: #256abf;
    --seq-400: #3987e5;
    --seq-550: #86b6ef;
    --success-text: #0ca30c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --series-2: #199e70;
  --series-3: #d95926;
  --seq-100: #184f95;
  --seq-250: #256abf;
  --seq-400: #3987e5;
  --seq-550: #86b6ef;
  --success-text: #0ca30c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

/* Beat any layout rule that would otherwise resurrect a hidden panel —
   .centre sets display:grid, which outranks the user-agent [hidden] rule. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); }

/* --- Layout ------------------------------------------------------------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { font-weight: 650; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; }
.brand .sub { display: block; font-weight: 400; font-size: 12px; color: var(--text-muted); }

.tabs { display: flex; gap: 4px; background: var(--page); padding: 3px; border-radius: var(--radius-sm); }
.tabs button {
  border: 0; background: transparent; color: var(--text-secondary);
  font: inherit; font-size: 14px; font-weight: 550;
  padding: 6px 14px; border-radius: 4px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }

.topbar .spacer { flex: 1; }
.inline-field { gap: 2px; }
.inline-field label { font-size: 10px; }
.inline-field select { padding: 4px 8px; font-size: 13px; max-width: 190px; }

.clock { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text-secondary); text-align: right; }
.clock .tzline { display: block; font-size: 11px; color: var(--text-muted); }

.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.conn.stale .dot { background: var(--warning); }
.conn.down .dot { background: var(--critical); }

.iconbtn {
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary);
  font: inherit; font-size: 13px; padding: 5px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.iconbtn:hover { color: var(--text-primary); }
a.iconbtn { text-decoration: none; display: inline-block; line-height: normal; }

main { flex: 1; padding: 20px; max-width: 1680px; width: 100%; margin: 0 auto; }
.panel[hidden] { display: none; }

/* --- Stat tiles --------------------------------------------------------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.tile .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.tile .value { font-size: 32px; font-weight: 650; line-height: 1.15; margin-top: 4px; letter-spacing: -0.02em; }
.tile .meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.tile.hero .value { font-size: 48px; }

/* --- Cards -------------------------------------------------------------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card > header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card h2 { font-size: 14px; font-weight: 650; margin: 0; letter-spacing: -0.005em; }
.card .hint { font-size: 12px; color: var(--text-muted); }
.card > header .spacer { flex: 1; }

/* Sits under the tiles: quiet by design, because it is a footnote about where
   two reports disagree, not a warning that anything is broken. */
.reconcile {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: -4px 0 16px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
  max-width: 92ch;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* --- Tables ------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: 650; padding: 6px 10px;
  border-bottom: 1px solid var(--axis); white-space: nowrap;
}
thead th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text-primary); }
thead th[aria-sort]:not([aria-sort="none"]) { color: var(--text-primary); }
tbody td { padding: 7px 10px; border-bottom: 1px solid var(--grid); }
tbody tr:hover { background: color-mix(in srgb, var(--series-1) 6%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { padding: 8px 10px; border-top: 1px solid var(--axis); font-weight: 650; font-variant-numeric: tabular-nums; }

.rank { color: var(--text-muted); font-variant-numeric: tabular-nums; width: 34px; }
.rank.top { color: var(--text-primary); font-weight: 650; }
.who { display: flex; flex-direction: column; }
.who .id { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Magnitude bar inside a table cell. Sequential single hue, 4px rounded end. */
.magnitude { position: relative; width: 118px; }
.magnitude .bar {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  height: 8px; background: var(--seq-400); border-radius: 0 4px 4px 0; opacity: 0.85;
}
.magnitude .txt { position: relative; padding-left: 4px; font-variant-numeric: tabular-nums; }
body.tv .magnitude { width: 150px; }

/* --- Status chips ------------------------------------------------------- */

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); white-space: nowrap;
}
.chip .swatch { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }
.chip[data-state="INCALL"] .swatch, .chip[data-state="QUEUE"] .swatch { background: var(--series-1); }
.chip[data-state="READY"] .swatch { background: var(--good); }
.chip[data-state="PAUSED"] .swatch { background: var(--warning); }
.chip[data-state="CLOSER"] .swatch { background: var(--series-2); }
.chip[data-state="DEAD"] .swatch { background: var(--critical); }

.sale-flag { color: var(--success-text); font-weight: 650; }

/* --- Controls ----------------------------------------------------------- */

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 650; }
input[type="date"], input[type="text"], input[type="password"], input[type="number"], select {
  font: inherit; font-size: 14px; padding: 6px 9px;
  border: 1px solid var(--axis); border-radius: var(--radius-sm);
  background: var(--surface-1); color: var(--text-primary);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

.presets { display: flex; gap: 4px; }
.presets button {
  font: inherit; font-size: 13px; padding: 6px 11px; cursor: pointer;
  border: 1px solid var(--axis); background: var(--surface-1); color: var(--text-secondary);
  border-radius: var(--radius-sm);
}
.presets button[aria-pressed="true"] { background: var(--series-1); border-color: var(--series-1); color: #fff; font-weight: 600; }

.btn {
  font: inherit; font-size: 14px; font-weight: 600; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--series-1); background: var(--series-1); color: #fff; border-radius: var(--radius-sm);
}
.btn.secondary { background: var(--surface-1); color: var(--text-primary); border-color: var(--axis); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Charts ------------------------------------------------------------- */

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axisline { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.chart text.value-label { fill: var(--text-secondary); font-weight: 600; }
.chart .line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart .marker { stroke: var(--surface-1); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 30;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 7px 10px; font-size: 12px; color: var(--text-primary);
  white-space: nowrap; transform: translate(-50%, -100%); opacity: 0; transition: opacity 90ms;
}
.tooltip.show { opacity: 1; }
.tooltip .t-title { font-weight: 650; margin-bottom: 2px; }
.tooltip .t-row { display: flex; gap: 10px; justify-content: space-between; color: var(--text-secondary); }
.tooltip .t-row b { color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 600; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* --- Floor strip -------------------------------------------------------- */

.floor-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.floor-strip .fs {
  display: flex; align-items: baseline; gap: 7px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 11px; background: var(--page);
}
.floor-strip .fs b { font-size: 18px; font-variant-numeric: tabular-nums; }
.floor-strip .fs span { font-size: 12px; color: var(--text-secondary); }

/* --- States ------------------------------------------------------------- */

.empty, .loading { padding: 28px; text-align: center; color: var(--text-muted); font-size: 14px; }
.banner {
  border: 1px solid var(--border); border-left: 3px solid var(--warning);
  background: var(--surface-1); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 13px; color: var(--text-secondary); margin-bottom: 14px;
}
.banner.error { border-left-color: var(--critical); }
.banner b { color: var(--text-primary); }

/* --- Login / setup ------------------------------------------------------ */

.centre { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.sheet {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 26px; width: 100%; max-width: 460px;
}
.sheet.wide { max-width: 720px; }
.sheet h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
.sheet p.lede { color: var(--text-secondary); font-size: 14px; margin: 0 0 20px; }
.sheet .field { margin-bottom: 13px; }
.sheet .field input, .sheet .field select { width: 100%; }
.sheet fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.sheet legend {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 700; padding: 0 0 8px;
}
.sheet .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.msg { font-size: 13px; padding: 9px 12px; border-radius: var(--radius-sm); margin-bottom: 14px; }
.msg.ok { background: color-mix(in srgb, var(--good) 12%, transparent); color: var(--success-text); }
.msg.bad { background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--critical); }
.msg.work { background: color-mix(in srgb, var(--series-1) 12%, transparent); color: var(--series-1); }
.help { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* --- TV mode ------------------------------------------------------------
   For the wall screen: bigger type, no chrome that nobody can click anyway. */

body.tv { font-size: 19px; }
body.tv .topbar { padding: 14px 24px; }
body.tv .tile .value { font-size: 46px; }
body.tv .tile.hero .value { font-size: 68px; }
body.tv table { font-size: 19px; }
body.tv thead th { font-size: 13px; }
body.tv tbody td { padding: 10px 12px; }
body.tv .tabs, body.tv .hide-on-tv { display: none; }

@media print {
  .topbar, .controls, .tabs { display: none; }
  .card { break-inside: avoid; box-shadow: none; }
}

/* --- Overlay panel ------------------------------------------------------- */

.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: color-mix(in srgb, var(--page) 78%, transparent);
  backdrop-filter: blur(2px);
  display: grid; place-items: start center;
  padding: 40px 20px; overflow: auto;
}
.overlay .sheet { max-width: 620px; }
.sheet-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.sheet-head h1 { flex: 1; margin: 0; }

.user-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--grid);
}
.user-row:last-child { border-bottom: 0; }
.user-row .u-name { flex: 1; font-weight: 600; }
.user-row .u-you { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.role-pill {
  font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-secondary);
}
.role-pill[data-role="admin"] { color: var(--series-1); border-color: var(--series-1); }
.linkbtn {
  border: 0; background: none; font: inherit; font-size: 13px; cursor: pointer;
  color: var(--text-secondary); text-decoration: underline; padding: 2px 4px;
}
.linkbtn:hover { color: var(--critical); }
.linkbtn.plain:hover { color: var(--text-primary); }
