:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0da;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --grid: #e7e5df;
  --accent: #2a78d6;
  --good: #008300;
  --bad: #c9302c;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-other: #9a988f;
}
@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;
    --grid: #2a2a27;
    --accent: #3987e5;
    --good: #2fa84f;
    --bad: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-other: #6f6e68;
  }
}
: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;
  --grid: #2a2a27;
  --accent: #3987e5;
  --good: #2fa84f;
  --bad: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-other: #6f6e68;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.6 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }

header.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
header.top h1 { font-size: 16px; margin: 0; letter-spacing: .02em; }
nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav.tabs button, .btn {
  border: 1px solid transparent; background: none; color: var(--text-secondary);
  padding: 6px 12px; border-radius: 8px; font: inherit; cursor: pointer;
}
nav.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
.btn { border-color: var(--border); background: var(--surface-1); color: var(--text-primary); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:hover { filter: brightness(1.05); }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
section[hidden] { display: none; }

.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 16px; }
.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; min-width: 0;
}
.card h2 { font-size: 14px; margin: 0 0 4px; }
.card .sub { color: var(--text-muted); font-size: 12px; margin: 0 0 12px; }
.kpi .label { color: var(--text-secondary); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.25; }
.kpi .detail { color: var(--text-muted); font-size: 12px; }
.good { color: var(--good); }
.bad { color: var(--bad); }

.meter { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter.over > span { background: var(--bad); }

.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 360px; }
.chart-box.short { height: 220px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 10px; font-size: 12px; color: var(--text-secondary); }
.legend button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.legend button[aria-pressed="false"] { opacity: .4; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
input, select {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-width: 0;
}
input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--surface-1); }
.table-wrap { max-height: 480px; overflow: auto; }
td input[type="number"] { width: 120px; }
.tag { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 12px; white-space: nowrap; }
.tag i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.muted { color: var(--text-muted); }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text-primary); color: var(--surface-1); padding: 10px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
details summary { cursor: pointer; color: var(--text-secondary); font-size: 12px; margin-top: 8px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card .error { color: var(--bad); font-size: 13px; min-height: 1.2em; margin: 0; }

@media (max-width: 640px) {
  header.top { padding: 10px 16px; }
  main { padding: 16px; }
  .two { grid-template-columns: 1fr; }
  .kpi .value { font-size: 22px; }
}
