:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #161f33;
  --muted: #6b7689;
  --line: #e3e8f0;
  --accent: #2f6df6;
  --accent-soft: #eaf1fe;
  --good: #1c9b62;
  --warn: #c9770a;
  --shadow: 0 1px 2px rgba(19, 32, 57, .06), 0 4px 16px rgba(19, 32, 57, .05);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141d;
    --panel: #171e2a;
    --ink: #e8ecf4;
    --muted: #93a0b5;
    --line: #26303f;
    --accent: #5b8dff;
    --accent-soft: #1c2740;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---------------------------------------------------------------- shell */

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px; height: 58px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 650; letter-spacing: -.01em; margin-right: 8px; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 6px 12px; border-radius: 8px; text-decoration: none;
  color: var(--muted); font-size: 14px; font-weight: 500;
}
.nav a:hover { background: var(--accent-soft); color: var(--accent); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.topbar form { margin: 0; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px;
}
.panel h2 { margin: 0 0 4px; font-size: 16px; font-weight: 620; }
.panel h2 + .sub { margin: 0 0 16px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

/* ---------------------------------------------------------------- controls */

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 20px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 15px; font: inherit; font-size: 14px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }

button, select, input[type=text], input[type=email], input[type=password], input[type=date] {
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; padding: 7px 11px;
}
button { cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 550; }
button.primary:hover { filter: brightness(1.07); }
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
.spacer { flex: 1; }
.range-label { font-weight: 600; font-size: 15px; white-space: nowrap; }

/* ---------------------------------------------------------------- stats */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 17px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .v { font-size: 25px; font-weight: 650; letter-spacing: -.02em; margin-top: 5px; }
.stat .n { color: var(--muted); font-size: 12px; margin-top: 2px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 620; padding: 0 10px 8px 0;
  border-bottom: 1px solid var(--line);
}
td { padding: 9px 10px 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.name { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter { background: var(--line); border-radius: 3px; height: 7px; min-width: 60px; }
.meter > i { display: block; height: 7px; border-radius: 3px; background: var(--accent); }
.pct { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }
.empty { color: var(--muted); font-size: 14px; padding: 26px 0; text-align: center; }

.scroll-x { overflow-x: auto; }

/* ---------------------------------------------------------------- forms */

.auth { max-width: 420px; margin: 8vh auto; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 570; margin-bottom: 5px; }
.field input, .field select { width: 100%; }
.hint { color: var(--muted); font-size: 12px; margin-top: 5px; }
.error { background: #fdecec; color: #9b2226; padding: 10px 13px; border-radius: 9px; font-size: 13px; margin-bottom: 14px; }
.notice { background: var(--accent-soft); color: var(--accent); padding: 11px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 16px; }
.ok-note { background: #e7f6ec; color: #1c6b3a; padding: 11px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 16px; }

.pill { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--line); color: var(--muted); }
.pill.live { background: #e7f6ec; color: var(--good); }
.pill.stale { background: #fdf1e2; color: var(--warn); }

code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.copy-row { display: flex; gap: 8px; align-items: center; margin: 8px 0 4px; }
.copy-row input { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

.chart { width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.legend b { color: var(--ink); font-weight: 550; }
