/* THMS dashboard — dark-first (users come from Grafana), light supported. */
:root {
  color-scheme: dark;
  --page:#0e1117; --surface:#181b1f; --surface-2:#22252b; --raised:#2c3036;
  --ink:#e6e9ef; --ink-2:#9aa1ab; --muted:#6e757e;
  --line:#2c3036; --grid:#22252b; --ring:rgba(255,255,255,.08);
  --good:#3ec46d; --warn:#f2a93b; --bad:#e0533d; --crit:#d03b3b;
  --accent:#4d9bf5; --accent-2:#a77bf3;
  --shadow:0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.25);
}
:root[data-theme="light"] {
  color-scheme: light;
  --page:#f4f5f7; --surface:#ffffff; --surface-2:#f7f8fa; --raised:#eceef1;
  --ink:#14171c; --ink-2:#565d66; --muted:#868d96;
  --line:#e2e5ea; --grid:#eceef1; --ring:rgba(0,0,0,.07);
  --shadow:0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
}
* { box-sizing:border-box; }
html, body { height:100%; }
body {
  margin:0; background:var(--page); color:var(--ink);
  font:14px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
  -webkit-font-smoothing:antialiased;
}
button, input, select { font:inherit; color:inherit; }
button { cursor:pointer; }
a { color:var(--accent); }
.hidden { display:none !important; }

/* ---------- shell ---------- */
.topbar {
  display:flex; align-items:center; gap:16px; padding:0 16px; height:52px;
  background:var(--surface); border-bottom:1px solid var(--line); position:sticky; top:0; z-index:50;
}
.brand { display:flex; align-items:center; gap:9px; font-weight:650; letter-spacing:-.01em; }
.brand .dot { width:9px; height:9px; border-radius:50%; background:var(--good); box-shadow:0 0 0 3px rgba(62,196,109,.18); }
.brand small { color:var(--muted); font-weight:400; }
.nav { display:flex; gap:2px; margin-left:8px; }
.nav button {
  background:none; border:0; padding:7px 13px; border-radius:7px;
  color:var(--ink-2); font-weight:500;
}
.nav button:hover { background:var(--surface-2); color:var(--ink); }
.nav button[aria-current="page"] { background:var(--raised); color:var(--ink); }
.spacer { flex:1; }
.who { display:flex; align-items:center; gap:10px; color:var(--ink-2); font-size:13px; }
.who b { color:var(--ink); font-weight:600; }
.pill {
  padding:3px 9px; border-radius:999px; background:var(--surface-2);
  border:1px solid var(--line); font-size:11.5px; color:var(--ink-2);
}
.icon-btn {
  background:var(--surface-2); border:1px solid var(--line); border-radius:7px;
  padding:6px 10px; color:var(--ink-2);
}
.icon-btn:hover { color:var(--ink); border-color:var(--muted); }

main { padding:16px; max-width:1720px; margin:0 auto; }

/* ---------- filter bar (Grafana-style) ---------- */
.filters {
  display:flex; flex-wrap:wrap; align-items:center; gap:8px; margin-bottom:16px;
}
.fgroup {
  display:flex; align-items:stretch; border:1px solid var(--line);
  border-radius:8px; overflow:hidden; background:var(--surface);
}
.fgroup label {
  display:flex; align-items:center; padding:0 10px; background:var(--surface-2);
  color:var(--ink-2); font-size:12.5px; border-right:1px solid var(--line); white-space:nowrap;
}
.fgroup select, .fgroup input {
  border:0; background:var(--surface); padding:7px 10px; min-width:120px; outline:none;
}
.fgroup select:focus-visible, .fgroup input:focus-visible { box-shadow:inset 0 0 0 2px var(--accent); }
.fgroup.active { border-color:var(--accent); }

/* ---------- panels ---------- */
.grid { display:grid; gap:12px; grid-template-columns:repeat(12,1fr); }
.panel {
  background:var(--surface); border:1px solid var(--line); border-radius:10px;
  padding:12px 14px 14px; box-shadow:var(--shadow); min-width:0;
}
.panel > h3 {
  margin:0 0 10px; font-size:12.5px; font-weight:600; color:var(--ink-2);
  letter-spacing:.01em; display:flex; align-items:center; gap:6px;
}
.panel > h3 .hint {
  width:14px; height:14px; border-radius:50%; border:1px solid var(--line);
  color:var(--muted); font-size:10px; display:inline-flex; align-items:center;
  justify-content:center; cursor:help; flex:none;
}
.c3{grid-column:span 3}.c4{grid-column:span 4}.c5{grid-column:span 5}
.c6{grid-column:span 6}.c7{grid-column:span 7}.c8{grid-column:span 8}
.c9{grid-column:span 9}.c12{grid-column:span 12}
@media (max-width:1100px){ .c3,.c4,.c5{grid-column:span 6} .c7,.c8,.c9{grid-column:span 12} }
@media (max-width:700px){ .grid > *{grid-column:span 12 !important} }

.section-title {
  display:flex; align-items:center; gap:8px; margin:20px 0 10px;
  font-size:13px; font-weight:600; color:var(--ink-2);
}
.section-title::after { content:""; flex:1; height:1px; background:var(--line); }

/* big stat */
.stat { display:flex; flex-direction:column; justify-content:center; min-height:96px; }
.stat .v { font-size:44px; font-weight:300; line-height:1.05; letter-spacing:-.02em; }
.stat .v small { font-size:20px; font-weight:400; color:var(--ink-2); margin-left:4px; }
.stat .sub { color:var(--muted); font-size:12px; margin-top:4px; }
.v.good{color:var(--good)} .v.warn{color:var(--warn)} .v.bad{color:var(--bad)} .v.crit{color:var(--crit)}
.v.mut{color:var(--muted)}

/* KPI row */
.kpis { display:grid; gap:12px; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); }
.kpi { background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:12px 14px; }
.kpi .k { color:var(--muted); font-size:11.5px; text-transform:uppercase; letter-spacing:.06em; }
.kpi .n { font-size:30px; font-weight:350; margin-top:2px; letter-spacing:-.02em; }

/* tables */
table { width:100%; border-collapse:collapse; font-size:13px; }
th, td { text-align:left; padding:8px 10px; border-bottom:1px solid var(--line); }
th { color:var(--muted); font-weight:600; font-size:11.5px; text-transform:uppercase; letter-spacing:.05em; }
tbody tr:hover { background:var(--surface-2); }
tbody tr.click { cursor:pointer; }
td.num, th.num { text-align:right; font-variant-numeric:tabular-nums; }
.scroll-x { overflow-x:auto; }

/* badges */
.badge {
  display:inline-flex; align-items:center; gap:5px; padding:2px 8px; border-radius:999px;
  font-size:11.5px; font-weight:600; border:1px solid transparent; white-space:nowrap;
}
.badge::before { content:""; width:6px; height:6px; border-radius:50%; background:currentColor; }
.badge.ok   { color:var(--good); background:rgba(62,196,109,.12); border-color:rgba(62,196,109,.25); }
.badge.warn { color:var(--warn); background:rgba(242,169,59,.12); border-color:rgba(242,169,59,.25); }
.badge.bad  { color:var(--bad);  background:rgba(224,83,61,.12);  border-color:rgba(224,83,61,.25); }
.badge.mut  { color:var(--muted);background:var(--surface-2);      border-color:var(--line); }

/* location cards */
.loc-grid { display:grid; gap:12px; grid-template-columns:repeat(auto-fill,minmax(260px,1fr)); }
.loc {
  background:var(--surface); border:1px solid var(--line); border-radius:10px;
  padding:13px 14px; cursor:pointer; transition:border-color .12s, transform .12s;
}
.loc:hover { border-color:var(--accent); transform:translateY(-1px); }
.loc .top { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.loc .name { font-weight:600; }
.loc .terr { color:var(--muted); font-size:12px; margin-top:1px; }
.loc .row { display:flex; align-items:baseline; gap:14px; margin-top:11px; }
.loc .big { font-size:27px; font-weight:350; letter-spacing:-.02em; }
.loc .meta { color:var(--ink-2); font-size:12px; }
.bar { height:4px; border-radius:3px; background:var(--raised); overflow:hidden; margin-top:10px; }
.bar > i { display:block; height:100%; border-radius:3px; }

/* forms / modal */
.btn {
  background:var(--accent); color:#fff; border:0; border-radius:8px;
  padding:8px 14px; font-weight:600;
}
.btn:hover { filter:brightness(1.08); }
.btn.sec { background:var(--surface-2); color:var(--ink); border:1px solid var(--line); }
.btn.danger { background:var(--crit); }
.btn:disabled { opacity:.5; cursor:not-allowed; }
.btn.sm { padding:5px 10px; font-size:12.5px; border-radius:6px; }
.modal-back {
  position:fixed; inset:0; background:rgba(0,0,0,.55); display:flex;
  align-items:center; justify-content:center; padding:20px; z-index:100;
}
.modal {
  background:var(--surface); border:1px solid var(--line); border-radius:12px;
  padding:20px; width:min(460px,100%); box-shadow:0 20px 60px rgba(0,0,0,.5);
  max-height:calc(100vh - 40px); overflow-y:auto;
}
.modal h2 { margin:0 0 14px; font-size:17px; }
.field { margin-bottom:12px; }
.field label { display:block; font-size:12.5px; color:var(--ink-2); margin-bottom:5px; }
.field input, .field select {
  width:100%; padding:9px 11px; border-radius:8px;
  border:1px solid var(--line); background:var(--surface-2);
}
.field input:focus, .field select:focus { outline:none; border-color:var(--accent); }
.field .help { font-size:11.5px; color:var(--muted); margin-top:4px; }
/* Form hint text shares the class name of the "?" legend button (.help, below);
   undo the button geometry here so hints render as normal text. */
.field .help {
  display:block; width:auto; height:auto; margin:4px 0 0; padding:0; border:0; border-radius:0;
  background:none; font-weight:400; line-height:1.4; cursor:auto; vertical-align:baseline;
}
.modal-actions { display:flex; gap:8px; justify-content:flex-end; margin-top:18px; }
.err {
  background:rgba(208,59,59,.12); border:1px solid rgba(208,59,59,.3);
  color:var(--crit); padding:9px 11px; border-radius:8px; font-size:13px; margin-bottom:12px;
}
.ok-note {
  background:rgba(62,196,109,.1); border:1px solid rgba(62,196,109,.28);
  color:var(--good); padding:9px 11px; border-radius:8px; font-size:13px; margin-bottom:12px;
}

/* login */
.login-wrap { min-height:100vh; display:flex; align-items:center; justify-content:center; padding:20px; }
.login {
  background:var(--surface); border:1px solid var(--line); border-radius:14px;
  padding:28px; width:min(390px,100%); box-shadow:var(--shadow);
}
.login h1 { margin:0 0 4px; font-size:21px; letter-spacing:-.02em; }
.login p.sub { margin:0 0 20px; color:var(--muted); font-size:13px; }

.empty { color:var(--muted); text-align:center; padding:34px 16px; font-size:13.5px; }
.notes-tbl td, .notes-tbl th { padding:6px 9px; font-size:12.5px; }
.notes-tbl th { text-transform:none; letter-spacing:0; font-size:12px; }
.loading { color:var(--muted); font-size:12.5px; }
svg { display:block; max-width:100%; }
.legend { display:flex; flex-wrap:wrap; gap:12px; margin-top:8px; font-size:11.5px; color:var(--ink-2); }
.legend i { display:inline-block; width:11px; height:3px; border-radius:2px; margin-right:5px; vertical-align:middle; }

/* ---- status legend: tiny "?" beside a column heading -------------------- */
.help {
  display:inline-flex; align-items:center; justify-content:center;
  width:14px; height:14px; padding:0; margin-left:5px;
  border:1px solid var(--line); border-radius:50%;
  background:transparent; color:var(--muted);
  font-family:inherit; font-size:9.5px; font-weight:700; line-height:1;
  cursor:help; vertical-align:middle;
  text-transform:none; letter-spacing:0; flex:none;
}
.help:hover, .help:focus-visible { color:var(--ink); border-color:var(--muted); outline:none; }

/* Lives at <body> level and is positioned in JS — the tables sit inside
   .panel (overflow:hidden) / .scroll-x, which would clip it. */
.help-pop {
  position:fixed; z-index:80; width:min(340px, calc(100vw - 20px));
  /* A legend taller than a short window scrolls inside itself rather than
     being cut off — the clamp in openHelp() keeps it on screen. */
  max-height:calc(100vh - 16px); overflow-y:auto;
  background:var(--surface); border:1px solid var(--line); border-radius:9px;
  padding:11px 12px; box-shadow:0 10px 30px rgba(0,0,0,.4);
  font-size:12px; line-height:1.45; color:var(--ink);
}
.help-pop h4 {
  margin:0 0 9px; font-size:10.5px; font-weight:600; letter-spacing:.5px;
  text-transform:uppercase; color:var(--muted);
}
.help-pop .r { display:flex; gap:8px; align-items:flex-start; }
.help-pop .r + .r { margin-top:7px; }
.help-pop .d { width:7px; height:7px; border-radius:50%; margin-top:5px; flex:none; }
.help-pop .n { font-weight:600; white-space:nowrap; }
.help-pop .m { color:var(--ink-2); }
.help-pop .foot {
  margin-top:10px; padding-top:8px; border-top:1px solid var(--line);
  color:var(--muted); font-size:11.5px;
}

/* API tab */
code { font:12.5px ui-monospace,SFMono-Regular,Menlo,monospace; }
.codebox {
  font:12.5px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace; background:var(--surface-2);
  border:1px solid var(--line); border-radius:8px; padding:9px 11px; margin:0 0 10px;
  word-break:break-all; user-select:all;
}
pre.codebox { word-break:normal; user-select:text; }
.field textarea {
  width:100%; padding:9px 11px; border-radius:8px; border:1px solid var(--line);
  background:var(--surface-2); color:var(--ink); font:12.5px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace; resize:vertical;
}
.field textarea:focus { outline:none; border-color:var(--accent); }

/* Multi-select (territory scope): a list, not a one-line dropdown. */
.field select[multiple] {
  height:auto; padding:6px; line-height:1.6;
}
.field select[multiple] option { padding:3px 6px; border-radius:4px; }
