:root {
  --bg: #f4f5f7; --panel: #ffffff; --line: #e3e5ea; --text: #1b1f27; --muted: #69707d;
  --accent: #2f6fde; --good: #1f9d55; --warn: #c98a00; --bad: #d23f3f; --chip: #eef1f6;
  --c1: #2f6fde; --c2: #e0652e; --c3: #8a4fd8; --c4: #1f9d8a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --line: #262c35; --text: #e7eaef; --muted: #8b93a1;
    --accent: #5b93f5; --good: #3cc47c; --warn: #e2a72e; --bad: #f06363; --chip: #20262f;
    --c1: #5b93f5; --c2: #f08a52; --c3: #b083f0; --c4: #3cc4b0;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 7px 14px;
  cursor: pointer; font-weight: 600; }
button.ghost { background: var(--chip); color: var(--text); }
button.danger { background: var(--bad); }
button:disabled { opacity: .55; cursor: default; }
input, select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }

header { position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1280px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand svg { width: 22px; height: 22px; }
.pill { padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--chip); }
.pill.good { color: var(--good); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
nav { display: flex; gap: 4px; overflow-x: auto; padding: 0 12px 8px; max-width: 1280px; margin: 0 auto;
  scrollbar-width: none; }
nav button { background: transparent; color: var(--muted); padding: 6px 12px; white-space: nowrap; }
nav button.on { background: var(--chip); color: var(--text); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.wide { grid-column: 1 / -1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.card h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  display: flex; align-items: center; gap: 8px; }
.card h3 .spacer { flex: 1; }
.big { font-size: 28px; font-weight: 700; line-height: 1.1; }
.row { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.row:last-child { border-bottom: 0; }
.row span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.good { color: var(--good); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.meter { height: 8px; border-radius: 99px; background: var(--chip); overflow: hidden; margin: 6px 0 2px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter i.warn { background: var(--warn); } .meter i.bad { background: var(--bad); }
.issues { margin: 0; padding: 0; list-style: none; }
.issues li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: baseline; }
.issues li:last-child { border-bottom: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; background: var(--muted); }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.chart { width: 100%; height: 170px; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart path { fill: none; stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.spark { width: 100%; height: 40px; display: block; margin-top: 6px; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

pre.log { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 0;
  max-height: 60vh; overflow: auto; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap;
  word-break: break-all; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.filters input[type=search] { flex: 1; min-width: 160px; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
  padding: 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog input { width: 100%; margin: 12px 0; font-size: 22px; letter-spacing: .3em; text-align: center; }
dialog .actions { justify-content: flex-end; }
.err { color: var(--bad); min-height: 1.4em; font-size: 13px; }
.toast { position: fixed; right: 16px; bottom: 16px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); max-width: 360px; z-index: 20; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px;
  width: min(380px, 100%); display: grid; gap: 12px; }
.login h1 { margin: 0; font-size: 20px; display: flex; gap: 10px; align-items: center; }
.login h1 svg { width: 26px; height: 26px; }
.login label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login input { width: 100%; font-size: 15px; padding: 10px 12px; }
.login button { padding: 11px; font-size: 15px; }
@media (max-width: 600px) {
  main { padding: 12px; }
  .bar { padding: 10px 12px; }
  .big { font-size: 24px; }
}

/* Overview: 12 cards in an even 4 / 2 / 1 grid, no ragged last row. */
.grid.overview { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.overview { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid.overview { grid-template-columns: 1fr; } }
.card { display: flex; flex-direction: column; }
.card .actions:last-child { margin-top: auto; padding-top: 10px; }
.row span:first-child { white-space: nowrap; }
.row span:last-child { overflow-wrap: anywhere; }
.spark { margin-top: auto; }
