:root {
  --bg: #0d1117;
  --panel: #151b23;
  --panel-2: #1c232d;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #5b9cf8;
  --green: #31c48d;
  --red: #f4574d;
  --amber: #f0a04b;
  --purple: #a78bfa;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

code, .mono, td.num, th.num { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ---------- layout ---------- */

header {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 16px; letter-spacing: .3px; }
header h1 span { color: var(--muted); font-weight: 400; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

nav {
  display: flex; gap: 4px; padding: 8px 16px 0;
  border-bottom: 1px solid var(--border); background: var(--panel);
  overflow-x: auto;
}
nav button {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 8px 14px; cursor: pointer; font-size: 14px;
  white-space: nowrap;
}
nav button.active { color: var(--text); border-bottom-color: var(--accent); }

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

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; min-width: 0;
}
.card h2 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.card .hint { color: var(--muted); font-size: 12px; margin-top: 10px; line-height: 1.5; }

/* ---------- bits ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--border);
}
.pill.ok { color: var(--green); border-color: #1d4d3a; }
.pill.warn { color: var(--amber); border-color: #5a4322; }
.pill.bad { color: var(--red); border-color: #5a2a27; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }

.big { font-size: 26px; font-weight: 600; line-height: 1.2; }
.big.sm { font-size: 20px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.stat { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; }
.stat + .stat { border-top: 1px solid var(--border); }
.stat .k { color: var(--muted); }
.stat .v { font-family: ui-monospace, Menlo, monospace; }

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

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 9px; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); }
tbody tr { border-bottom: 1px solid #1e252e; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; }

.bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--accent); }

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

button.btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
}
button.btn:hover { border-color: var(--accent); }
button.btn.primary { background: #1b3a63; border-color: #2b5b96; }
button.btn.danger { background: #40201e; border-color: #6b2f2b; }
button.btn:disabled { opacity: .45; cursor: not-allowed; }

input, select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 9px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input.dirty { border-color: var(--amber); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* ---------- chart ---------- */

.chart-wrap { position: relative; width: 100%; }
canvas { width: 100%; height: 340px; display: block; border-radius: 8px; background: #0b0f15; }

/* ---------- overlay ---------- */

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.66);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px; overflow-y: auto; z-index: 50;
}
.overlay[hidden] { display: none; }
.overlay .card { width: min(980px, 100%); }
.overlay-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.overlay-head h2 { margin: 0; text-transform: none; font-size: 16px; color: var(--text); }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 9px; z-index: 100;
  max-width: min(560px, 92vw); box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.toast[hidden] { display: none; }
.toast.err { border-color: var(--red); }

.banner {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 14px;
  border: 1px solid var(--border); background: var(--panel-2); font-size: 13px;
}
.banner.warn { border-color: #5a4322; color: var(--amber); }
.banner.bad { border-color: #5a2a27; color: var(--red); }

ul.reasons { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; }

@media (max-width: 620px) {
  main { padding: 12px 10px; }
  .grid, .grid.two { grid-template-columns: 1fr; }
  header h1 { font-size: 14px; }
  canvas { height: 260px; }
}
