:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #efeee9;
  --border: #dddbd3;
  --grid: #e6e4dd;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6d6c67;
  --series-1: #2a78d6;
  --series-1-soft: #cde2fb;
  --good: #0a7d3a;
  --critical: #c22b2b;
  --focus: #2a78d6;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #34332f;
    --grid: #2b2a27;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9d9c93;
    --series-1: #3987e5;
    --series-1-soft: #184f95;
    --good: #4cc27a;
    --critical: #ef6b6b;
    --focus: #6da7ec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface-1: #1a1a19; --surface-2: #242422; --border: #34332f; --grid: #2b2a27;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #9d9c93;
  --series-1: #3987e5; --series-1-soft: #184f95; --good: #4cc27a; --critical: #ef6b6b; --focus: #6da7ec;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text-primary); font-size: 14px; line-height: 1.45; }
[hidden] { display: none !important; }
.muted { color: var(--text-muted); }
.error { color: var(--critical); min-height: 1.2em; margin: 0; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 14px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.btn { font: inherit; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  border-radius: 7px; padding: 6px 12px; cursor: pointer; }
.btn-primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-secondary); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; display: grid; gap: 12px; }
.login-card label { display: grid; gap: 4px; color: var(--text-secondary); }
.login-card input { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg); color: var(--text-primary); }

/* top bar: filters in one row */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface-1); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; letter-spacing: .02em; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1; }
.who { display: flex; align-items: center; gap: 4px; }
select, input[type=date] { font: inherit; color: var(--text-primary); background: var(--bg);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; }
.custom { display: inline-flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg); }
.seg button { font: inherit; border: 0; background: transparent; color: var(--text-secondary); padding: 5px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--series-1); }
.seg-small button { padding: 3px 8px; font-size: 12px; }

main { max-width: 1240px; margin: 0 auto; padding: 16px 24px 40px; display: grid; gap: 16px; }
.status { margin: 0; min-height: 1.2em; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile-label { color: var(--text-secondary); font-size: 12px; }
.tile-value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.tile-sub { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.delta-up::before { content: "▲ "; }
.delta-down::before { content: "▼ "; }

/* cards */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

/* charts */
.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g.hover .bar { fill: var(--series-1); opacity: .8; }
.chart .baseline { stroke: var(--text-muted); stroke-width: 1; }
.empty { color: var(--text-muted); padding: 24px 0; text-align: center; margin: 0; }
.table-view summary { cursor: pointer; color: var(--text-secondary); font-size: 12px; margin-top: 8px; }

.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .15); white-space: nowrap; }
.tip strong { font-variant-numeric: tabular-nums; }

/* ranked lists: a bar behind each row */
table.list { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.list th { text-align: right; font-weight: 500; color: var(--text-muted); font-size: 12px; padding: 0 0 6px 10px; }
table.list th:first-child { text-align: left; padding-left: 0; }
table.list td { padding: 0; border-top: 2px solid var(--surface-1); }
table.list td.num { text-align: right; padding: 4px 0 4px 10px; white-space: nowrap; color: var(--text-secondary); }
table.list td.num.main { color: var(--text-primary); }
.label-cell { position: relative; padding: 4px 8px; max-width: 0; width: 100%; }
.label-bar { position: absolute; inset: 0 auto 0 0; background: var(--series-1-soft); border-radius: 0; opacity: .55; }
.label-text { position: relative; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.plain { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13px; }
table.plain th, table.plain td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--grid); }
table.plain th:first-child, table.plain td:first-child { text-align: left; }
.more { font: inherit; font-size: 12px; margin-top: 8px; }
.props { margin: 4px 0 8px 12px; font-size: 12px; color: var(--text-secondary); }

.foot { font-size: 12px; text-align: center; padding: 8px 0; }

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .top { padding: 10px 16px; gap: 8px; }
  main { padding: 12px 16px 32px; }
  .seg button { padding: 5px 7px; }
  .custom { width: 100%; }
  .custom input { flex: 1; min-width: 0; }
  .tile-value { font-size: 22px; }
  .filters { width: 100%; }
  #ranges { overflow-x: auto; max-width: 100%; }
}
