:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page-plane:      #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1: #2a78d6; --series-2: #008300; --series-3: #e87ba4; --series-4: #eda100;
  --series-5: #1baf7a; --series-6: #eb6834; --series-7: #4a3aa7; --series-8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page-plane:      #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --series-1: #3987e5; --series-2: #008300; --series-3: #d55181; --series-4: #c98500;
    --series-5: #199e70; --series-6: #d95926; --series-7: #9085e9; --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page-plane:      #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);
  --series-1: #3987e5; --series-2: #008300; --series-3: #d55181; --series-4: #c98500;
  --series-5: #199e70; --series-6: #d95926; --series-7: #9085e9; --series-8: #e66767;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
}
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; color: var(--text-secondary); }
.muted { color: var(--text-muted); }
a { color: var(--series-1); }

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.9rem 1.5rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; }
.topnav { display: flex; gap: 1.1rem; flex: 1; }
.topnav a { color: var(--text-secondary); text-decoration: none; padding: 0.3rem 0; border-bottom: 2px solid transparent; }
.topnav a.active, .topnav a:hover { color: var(--text-primary); border-bottom-color: var(--series-1); }
.logout-link { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }

.page { max-width: 1040px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.25rem;
}

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpi-tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.1rem; }
.kpi-label { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: 1.6rem; font-weight: 600; margin-top: 0.2rem; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 0.75rem; margin-top: 0.15rem; }

.filter-bar { margin-bottom: 1.25rem; }
.preset-row { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; flex-wrap: wrap; }
.preset { padding: 0.35rem 0.8rem; border-radius: 999px; border: 1px solid var(--border); text-decoration: none; color: var(--text-secondary); font-size: 0.85rem; }
.preset.is-selected { background: var(--series-1); color: #fff; border-color: var(--series-1); }
.custom-row { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-secondary); }
.custom-row label { display: flex; flex-direction: column; gap: 0.25rem; }
.custom-row input, .custom-row select { padding: 0.35rem 0.5rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); }
.custom-row button, .upload-form button, .login-card button, .button {
  padding: 0.45rem 1rem; border-radius: 6px; border: none; background: var(--series-1); color: #fff;
  cursor: pointer; font-size: 0.85rem; text-decoration: none; display: inline-block;
}

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--gridline); }
.data-table th { color: var(--text-muted); font-weight: 500; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty-state { text-align: center; padding: 3rem 1rem; }
.empty-state p { color: var(--text-secondary); margin-bottom: 1rem; }

.login-wrap { display: flex; justify-content: center; padding-top: 3rem; }
.login-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; width: 320px; display: flex; flex-direction: column; gap: 0.8rem; }
.login-card input { padding: 0.55rem 0.7rem; border-radius: 6px; border: 1px solid var(--border); background: var(--page-plane); color: var(--text-primary); }

.flash-list { margin-bottom: 1rem; }
.flash { background: var(--surface-1); border: 1px solid var(--series-1); border-left-width: 4px; padding: 0.6rem 0.9rem; border-radius: 6px; margin-bottom: 0.5rem; font-size: 0.9rem; }

/* charts */
.chart-svg { width: 100%; height: auto; display: block; }
.gridline { stroke: var(--gridline); stroke-width: 1; }
.axis-label { fill: var(--text-muted); font-size: 10px; }
.chart-area { fill: var(--series-1); opacity: 0.08; }
.chart-line-path { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-point { fill: var(--surface-1); stroke: var(--series-1); stroke-width: 2; }
.chart-crosshair { stroke: var(--baseline); stroke-width: 1; }
.chart-line { position: relative; }
.chart-tooltip {
  position: absolute; pointer-events: none; background: var(--text-primary); color: var(--surface-1);
  padding: 0.35rem 0.6rem; border-radius: 6px; font-size: 0.78rem; white-space: nowrap;
  transform: translate(-50%, -110%);
}
.hbar-rect { transition: opacity 0.1s; }
.hbar-row:hover .hbar-rect { opacity: 0.85; }
.hbar-label { fill: var(--text-secondary); font-size: 12px; }
.hbar-value { fill: var(--text-primary); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-bottom: 0.6rem; font-size: 0.8rem; color: var(--text-secondary); }
.legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-empty { display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 0.9rem; }
