:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --accent-soft: #cde2fb;
  --grid: #e8e7e3;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good: #1a7f37; --warn: #b35c00; --bad: #c62828;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface-1: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
    --accent: #3987e5; --accent-soft: #184f95; --grid: #2a2a28;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good: #4cb86a; --warn: #e09a3e; --bad: #ef6b6b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface-1: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
  --accent: #3987e5; --accent-soft: #184f95; --grid: #2a2a28;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good: #4cb86a; --warn: #e09a3e; --bad: #ef6b6b;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 14px; font-weight: 600; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h2 .sub { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.muted { color: var(--text-muted); }
.note { color: var(--text-muted); font-size: 12px; margin: 8px 0 0; }
[hidden] { display: none !important; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; min-width: 0; }
.btn { font: inherit; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary); cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:hover { filter: brightness(0.97); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login-card label { display: grid; gap: 4px; font-size: 12px; color: var(--text-secondary); }
input, select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); }
.msg { min-height: 1em; margin: 0; color: var(--bad); font-size: 13px; }
.loading { position: fixed; inset: 0; display: grid; place-items: center; color: var(--text-muted); background: var(--bg); }

/* Header */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface-1); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { font: inherit; border: 0; background: transparent; color: var(--text-secondary); padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--text-primary); font-weight: 600; }
.who { display: flex; align-items: center; gap: 8px; font-size: 12px; }

.status-bar { max-width: 1400px; margin: 12px auto 0; padding: 0 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 12px; }
.upload-msg { font-size: 12px; }
.upload-msg.ok { color: var(--good); } .upload-msg.err { color: var(--bad); }
main, .filters, .foot { max-width: 1400px; margin-left: auto; margin-right: auto; }
main { padding: 0 16px 24px; }
.filters { margin: 16px auto; margin-left: max(16px, calc((100% - 1400px) / 2)); margin-right: max(16px, calc((100% - 1400px) / 2)); display: grid; gap: 12px; }
.label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-right: 8px; }
.range-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.range-text { font-variant-numeric: tabular-nums; font-weight: 600; }
.presets { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .x { opacity: .8; }
.active-filters { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* Dual range slider */
.slider { position: relative; height: 28px; }
.slider-track { position: absolute; left: 0; right: 0; top: 12px; height: 4px; border-radius: 2px; background: var(--grid); }
.slider-fill { position: absolute; top: 0; height: 4px; border-radius: 2px; background: var(--accent); }
.slider input[type=range] { position: absolute; left: 0; width: 100%; top: 4px; margin: 0; height: 20px; background: transparent; pointer-events: none; -webkit-appearance: none; appearance: none; padding: 0; border: 0; }
.slider input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; pointer-events: all; width: 18px; height: 18px; border-radius: 50%; background: var(--surface-1); border: 3px solid var(--accent); cursor: grab; }
.slider input[type=range]::-moz-range-thumb { pointer-events: all; width: 14px; height: 14px; border-radius: 50%; background: var(--surface-1); border: 3px solid var(--accent); cursor: grab; }
.slider input[type=range]::-webkit-slider-runnable-track { background: transparent; }
.slider input[type=range]::-moz-range-track { background: transparent; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .k { font-size: 12px; color: var(--text-secondary); }
.kpi .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .d { font-size: 12px; color: var(--text-muted); }
.kpi .d.up { color: var(--bad); } .kpi .d.down { color: var(--good); }
.kpi .d.up.goodup { color: var(--good); }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 { margin-bottom: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.chart { position: relative; height: 260px; }
.chart.tall { height: 360px; }
.chart.xtall { height: 420px; }

/* Tables */
.table-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--border); border-radius: 8px; }
.table-wrap.short { max-height: 300px; }
.tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
.tbl th, .tbl td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.tbl th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--text-secondary); font-size: 12px; cursor: pointer; user-select: none; z-index: 1; }
.tbl.num td:not(:first-child), .tbl.num th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr:hover td { background: var(--surface-2); }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); position: sticky; bottom: 0; }
.tbl td.wrap { white-space: normal; min-width: 220px; }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.empty { padding: 16px; color: var(--text-muted); }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); }
.tag.TBR { border-color: var(--s8); } .tag.TBI { border-color: var(--s4); }
.tag.Fuel { border-color: var(--s3); } .tag.DeRe { border-color: var(--s7); }
.tag.New { border-color: var(--bad); color: var(--bad); }
.tag.Cleared { border-color: var(--good); color: var(--good); }

.day-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.day-head label { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.day-head .btn { margin-left: auto; }
.search { margin-left: auto; font-size: 13px; padding: 5px 10px; min-width: 220px; font-weight: 400; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.foot { padding: 0 16px 24px; font-size: 12px; }

@media (max-width: 640px) {
  .top { gap: 8px; justify-content: space-between; }
  .tabs { order: 3; flex: 1 0 100%; }
  .who #who { display: none; }
  .search { min-width: 0; width: 100%; margin-left: 0; }
  .kpi .v { font-size: 22px; }
}
