:root {
  color-scheme: light;
  --page:           #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6;
  --series-2:       #eb6834;
  --status-good:    #0ca30c;
  --status-critical:#d03b3b;
  --critical-wash:  #fbeaea;
  --good-wash:      #e9f6e9;
  --accent:         #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --critical-wash:  #35201f;
    --good-wash:      #1c2a1c;
    --accent:         #3987e5;
  }
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page); color: var(--text-primary);
  font-size: 14px; line-height: 1.45;
}
.hidden { display: none !important; }

/* ---- auth screens ---- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; width: 100%; max-width: 380px;
}
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }
.auth-card label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-top: 12px; }
.auth-card input {
  font: inherit; width: 100%; margin-top: 4px; padding: 9px 11px;
  border: 1px solid var(--baseline); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary);
}
.auth-card .btn { width: 100%; margin-top: 18px; }
.auth-error { color: var(--status-critical); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---- app shell ---- */
header {
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  padding: 12px 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
header h1 { font-size: 17px; font-weight: 700; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-secondary); }
.role-chip {
  font-size: 11px; font-weight: 700; border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 8px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em;
}
nav { display: flex; gap: 2px; padding: 8px 20px 0; flex-wrap: wrap; background: var(--surface-1); border-bottom: 1px solid var(--border); }
nav button {
  font: inherit; font-weight: 600; color: var(--text-secondary);
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 8px 14px; cursor: pointer;
}
nav button.active { color: var(--text-primary); border-bottom-color: var(--accent); }
main { padding: 18px 20px 48px; max-width: 1150px; margin: 0 auto; }

/* ---- components ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 13px 15px; }
.tile .label { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.tile .value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--text-muted); }
.tile.alert .value { color: var(--status-critical); }
.banner {
  background: var(--critical-wash); border: 1px solid var(--status-critical);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 13px;
}
.banner strong { color: var(--status-critical); }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin-bottom: 0; }
.card-head .spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--text-secondary); font-weight: 600;
  border-bottom: 1px solid var(--baseline); padding: 6px 8px; white-space: nowrap;
}
td { padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td.wrap { white-space: normal; min-width: 120px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.low td { background: var(--critical-wash); }
.badge {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 11px; font-weight: 700; border-radius: 999px; padding: 2px 8px;
}
.badge.low { background: var(--critical-wash); color: var(--status-critical); border: 1px solid var(--status-critical); }
.badge.ok  { background: var(--good-wash); color: var(--status-good); border: 1px solid var(--status-good); }
form.entry { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
form.entry label { font-size: 12px; font-weight: 600; color: var(--text-secondary); display: block; }
form.entry input, form.entry select {
  font: inherit; width: 100%; margin-top: 3px; padding: 7px 9px;
  border: 1px solid var(--baseline); border-radius: 7px;
  background: var(--surface-1); color: var(--text-primary);
}
form.entry .full { grid-column: 1 / -1; }
.btn {
  font: inherit; font-weight: 700; color: #fff; background: var(--accent);
  border: none; border-radius: 7px; padding: 9px 18px; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.small { padding: 5px 12px; font-size: 12px; }
.btn.ghost {
  background: none; color: var(--text-secondary); border: 1px solid var(--baseline); font-weight: 600;
}
.btn.danger-link {
  background: none; color: var(--status-critical); border: none; font-size: 12px;
  padding: 2px 6px; text-decoration: underline; cursor: pointer;
}
.btn.edit-link {
  background: none; color: var(--accent); border: none; font-size: 12px;
  padding: 2px 6px; text-decoration: underline; cursor: pointer;
}
.chart-wrap { position: relative; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chip { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tooltip {
  position: absolute; pointer-events: none; display: none;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.15); z-index: 5;
  white-space: nowrap;
}
.muted { color: var(--text-muted); font-size: 12px; }
section.tab { display: none; }
section.tab.active { display: block; }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: var(--page); border-radius: 8px;
  padding: 10px 18px; font-size: 13px; display: none; z-index: 20; max-width: 90vw;
}
