/* Tokens: light by default, dark from the OS setting. Series colors are the validated
   categorical palette (dataviz reference instance), slots used in fixed order. */
:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6e6d68;
  --link: #1c5cab;
  --error: #b42318;
  --error-bg: #fdecea;
  --warning-bg: #fff4d6;
  --grid: #e3e2de;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --series-other: #9a998f;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface: #1a1a19;
    --surface-2: #242423;
    --border: #383835;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #a3a29a;
    --link: #86b6ef;
    --error: #f97066;
    --error-bg: #3a1714;
    --warning-bg: #3a2e0c;
    --grid: #383835;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --series-other: #75746d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--link); }
code { font-size: 0.9em; }

.top {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.top .brand { font-weight: 600; color: var(--text); text-decoration: none; }
.top nav { display: flex; gap: 16px; }
.top nav a { text-decoration: none; }
.logout { margin-left: auto; display: flex; gap: 12px; align-items: center; }
.who { color: var(--text-2); }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
h1 { font-size: 1.6em; margin: 0 0 8px; }
h1 .muted { font-size: 0.6em; font-weight: normal; }
h2 { font-size: 1.15em; margin: 28px 0 8px; }
.muted { color: var(--muted); }
.crumbs { margin: 0 0 4px; color: var(--muted); }

.error { color: var(--error); background: var(--error-bg); padding: 8px 12px; border-radius: 6px; }
.warning { background: var(--warning-bg); padding: 8px 12px; border-radius: 6px; }

button, .button {
  font: inherit;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .button:hover { border-color: var(--text-2); }
button.link { border: 0; background: none; padding: 0; color: var(--link); }

input, select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.login { max-width: 360px; margin: 64px auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; }

.reports { list-style: none; padding: 0; }
.reports li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.reports .title { font-weight: 600; font-size: 1.05em; }
.reports p { margin: 4px 0 0; }

.params { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; margin: 16px 0 8px; }
.params label { display: flex; flex-direction: column; gap: 4px; color: var(--text-2); font-size: 0.9em; }
.ranges { display: flex; gap: 16px; margin: 0 0 16px; font-size: 0.9em; }
.period { color: var(--text-2); }
.actions { display: flex; gap: 12px; align-items: center; }
.hint { font-size: 0.85em; margin-top: 0; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

.charts { display: grid; gap: 24px; margin: 16px 0; }
.chart h3 { font-size: 0.95em; margin: 0 0 4px; color: var(--text-2); font-weight: 600; }
.chart .canvas { position: relative; height: 320px; }

.table-wrap { overflow-x: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: 6px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 0.9em; }
table.grid th, table.grid td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.grid th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover { background: var(--surface-2); }
.schema table.grid { width: auto; min-width: 480px; }
