/* Bill Support Stats UI */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #006300;
  --bad: #b42323;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --baseline: #898781;
  --seq-0: #f0efec;
  --seq-1: #cde2fb;
  --seq-2: #86b6ef;
  --seq-3: #3987e5;
  --seq-4: #1c5cab;
  --seq-5: #0d366b;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --good: #0ca30c;
    --bad: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --baseline: #a3a29b;
    --seq-0: #242422;
    --seq-1: #104281;
    --seq-2: #1c5cab;
    --seq-3: #3987e5;
    --seq-4: #86b6ef;
    --seq-5: #cde2fb;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --ink: #f0efec; --ink-2: #c3c2b7;
  --muted: #898781; --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --good: #0ca30c; --bad: #e66767;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --baseline: #a3a29b;
  --seq-0: #242422; --seq-1: #104281; --seq-2: #1c5cab; --seq-3: #3987e5; --seq-4: #86b6ef; --seq-5: #cde2fb;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
}
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; letter-spacing: -0.01em; }
h2 { font-size: 14px; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1440px; margin: 0 auto; padding: 0 16px; height: 52px; display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 650; color: var(--ink); text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a { color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; }

/* page */
.page { max-width: 1440px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.report-scope { margin: 0; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; color: var(--ink-2); display: flex; flex-direction: column; gap: 2px; }
.empty { color: var(--ink-2); padding: 32px 0; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }

/* buttons */
.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--ink); border-radius: 6px; padding: 6px 12px; cursor: pointer; line-height: 1.3; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-small { padding: 2px 8px; font-size: 12px; color: var(--ink-2); }
.btn-block { width: 100%; padding: 9px 12px; }
.btn:focus-visible, .chip:focus-visible, input:focus-visible, select:focus-visible, .nav a:focus-visible, .tabs a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* filters */
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 10px; }
.filters-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field label, legend { font-size: 12px; color: var(--ink-2); }
.field-wide { min-width: 220px; }
.field-action { margin-left: auto; }
input[type="date"], select, input:not([type]), input[type="password"] {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis);
  border-radius: 6px; padding: 5px 8px; min-height: 32px; font-variant-numeric: tabular-nums;
}
select { padding-right: 24px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); min-height: 32px; cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.ranges { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-2); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.chip:hover { color: var(--ink); border-color: var(--axis); }
.period-dates { align-items: center; }
.period-set { border: 0; padding: 0; margin: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.period-set legend { float: left; margin-right: 8px; padding: 0; }
.staff-picks { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.staff-picks legend { float: left; margin-right: 6px; padding: 0; }
.staff-picks label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.staff-picks input { accent-color: var(--accent); margin: 0; }
.staff-picks .off { color: var(--muted); }

/* tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; min-height: 84px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi-label { color: var(--ink-2); font-size: 12px; }
.kpi-value { font-size: 24px; font-weight: 600; margin-top: 2px; letter-spacing: -0.01em; }
.kpi-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpis[data-state="loading"]::before { content: "Loading…"; color: var(--muted); align-self: center; }

/* cards */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 10px; min-width: 0; break-inside: avoid; }
.card-wide { grid-column: 1 / -1; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.card-sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.card-tools { display: flex; gap: 4px; flex-shrink: 0; }
.chart { width: 100%; height: 300px; position: relative; }
.card-wide .chart { height: 320px; }
.chart.tall { height: auto; }
[data-state="loading"].chart::before, [data-state="loading"].table-wrap::before { content: "Loading…"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.table-wrap { position: relative; min-height: 60px; overflow-x: auto; }
.state-msg { display: grid; place-items: center; height: 100%; min-height: 120px; color: var(--muted); text-align: center; padding: 16px; }
.state-msg.error { color: var(--bad); }

/* tables */
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data tbody th { font-weight: 500; }
table.data thead th { color: var(--ink-2); font-weight: 600; font-size: 12px; border-bottom-color: var(--axis); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.muted { color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.tag { font-size: 11px; color: var(--muted); margin-left: 6px; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px 24px; }
.login h1 { font-size: 18px; }
.login-sub { color: var(--ink-2); margin: 2px 0 20px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login .field input { width: 100%; }
.login-error { color: var(--bad); margin: 0; font-size: 13px; }

@media (max-width: 960px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .field-action { margin-left: 0; }
}
@media (max-width: 560px) {
  .brand { display: none; }
  .topbar-inner { gap: 8px; }
  .chart, .card-wide .chart { height: 260px; }
}

/* print: weekly report */
@media print {
  :root { color-scheme: light; }
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  .topbar, .filters, .tabs, .card-tools, .ranges { display: none !important; }
  .page { max-width: none; padding: 0; }
  .card, .kpi { border-color: #ccc; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .chart { height: 260px; }
  .chart > div:not(.state-msg) { display: none !important; }
  .chart > img.print-img { display: block !important; width: 100%; height: 100%; object-fit: contain; }
}
img.print-img { display: none; }

/* chart tooltips (rendered by ECharts inside the chart container) */
.tt-title { font-weight: 600; margin-bottom: 4px; color: var(--ink); }
.tt-row { display: flex; align-items: center; gap: 6px; line-height: 1.6; }
.tt-row b { margin-left: auto; padding-left: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tt-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.tt-name { color: var(--ink-2); }
.tt-sub { color: var(--muted); font-size: 11px; margin: -2px 0 2px 14px; }

/* applied on screen during beforeprint so charts are sized for an A4 landscape page */
html.print-mode .page { width: 1030px; max-width: none; padding: 0; margin: 0; }
html.print-mode .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
html.print-mode .chart, html.print-mode .card-wide .chart { height: 260px; }

/* ---------- v2: compare pickers, admin page ---------- */
.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; }
.segmented { border: 0; margin: 0; padding: 2px; display: inline-flex; background: var(--surface-2); border-radius: 8px; align-self: flex-end; min-height: 32px; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 5px 14px; border-radius: 6px; color: var(--ink-2); font-weight: 500; }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.picks { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.picks legend { float: left; margin-right: 6px; padding: 0; font-size: 12px; color: var(--ink-2); }
.pick { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; user-select: none; }
.pick:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.pick:has(input:disabled:not(:checked)) { opacity: .5; cursor: default; }
.pick input { accent-color: var(--accent); margin: 0; }
.pick-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-right: 10px; }
.pick-group-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; min-width: 46px; }
.shift-history { margin: -6px 0 12px; color: var(--ink-2); font-size: 13px; }

.card-flush { margin-bottom: 16px; }
.sync { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; min-height: 76px; }
.sync[data-state="loading"]::before { content: "Loading sync status…"; color: var(--muted); align-self: center; }
.sync-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; min-width: 0; }
.sync-item .kpi-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-state { font-weight: 600; margin-top: 2px; }
.sync-state.ok { color: var(--good); }
.sync-state.bad { color: var(--bad); }
.sync-time { font-weight: 400; color: var(--muted); font-size: 12px; }

.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; min-height: 60px; position: relative; }
.board[data-state="loading"]::before { content: "Loading…"; color: var(--muted); }
.board-col { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.board-col-warn { outline: 1px dashed var(--axis); background: transparent; }
.board-head { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.board-count { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.board-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.board-list li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.board-list a { color: var(--ink); text-decoration: none; }
.board-list a:hover { text-decoration: underline; }
.board-list .muted { color: var(--muted); }

.notice-action { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin-bottom: 12px; }
.field-grow { flex: 1 1 220px; }
.field-grow input { width: 100%; }
input[type="search"] { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis); border-radius: 6px; padding: 5px 8px; min-height: 32px; }
.bulk { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; padding: 10px 12px; margin-bottom: 12px; border-radius: 8px;
        background: color-mix(in srgb, var(--accent) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.bulk strong { align-self: center; margin-right: 6px; }
.bulk .field-action { display: flex; gap: 6px; }

table.data-admin th, table.data-admin td { text-align: left; vertical-align: middle; padding: 6px 8px; }
table.data-admin select, table.data-admin input[type="date"] { min-height: 28px; padding: 3px 6px; }
table.data-admin .col-check { width: 28px; }
table.data-admin input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
table.data-admin tr.row-off .who { color: var(--muted); }
.who { font-weight: 500; }
.who-sub { font-size: 11px; color: var(--muted); font-weight: 400; }
.nowrap { white-space: nowrap; }
table.data td.muted { color: var(--muted); }
.date-cell { display: flex; align-items: center; gap: 2px; }
.btn-icon { padding: 2px 7px; line-height: 1.2; color: var(--ink-2); }
.btn-danger { color: var(--bad); }
.switch { position: relative; display: inline-block; width: 34px; height: 20px; cursor: pointer; vertical-align: middle; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--axis); transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + span { opacity: .5; }

.dialog { border: 1px solid var(--border); border-radius: 12px; padding: 20px; background: var(--surface); color: var(--ink); width: min(440px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog h2 { font-size: 16px; margin-bottom: 4px; }
.dialog form, .dialog > div { display: flex; flex-direction: column; gap: 12px; }
.dialog-text { margin: 0; color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.hist-add { flex-direction: row !important; align-items: flex-end; flex-wrap: wrap; gap: 8px !important; border-top: 1px solid var(--grid); padding-top: 12px; }
#hist-dialog { width: min(520px, calc(100vw - 32px)); }

.toast { position: fixed; right: 16px; bottom: 16px; max-width: min(420px, calc(100vw - 32px)); padding: 10px 14px; border-radius: 8px; z-index: 50;
         background: var(--ink); color: var(--surface); box-shadow: 0 6px 20px rgba(0,0,0,.25); margin: 0; }
.toast-error { background: var(--bad); color: #fff; }
@media print { .toast, .bulk, .toolbar { display: none !important; } }
