:root {
  --bg: #0f1419;
  --panel: #171e26;
  --panel-2: #1e2731;
  --line: #2a3542;
  --text: #dbe4ee;
  --muted: #8796a8;
  --accent: #3fb6ff;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --bad: #ff5d5d;
  --input: #0f161d;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f6f9; --panel: #ffffff; --panel-2: #f6f8fb; --line: #dfe5ec; --text: #17202a; --muted: #5f6f81;
    --accent: #0a74c9; --ok: #12925b; --warn: #b07800; --bad: #d23636; --input: #ffffff; --shadow: 0 4px 16px rgba(20, 30, 40, .1);
  }
}
* { 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); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 10px; font-weight: 650; }
h2 { font-size: 18px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 18px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }

/* Top bar */
.top { display: flex; align-items: center; gap: 16px; height: 54px; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1000; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: 17px; color: var(--text); }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.top .spacer { flex: 1; }
.top .who { color: var(--muted); font-size: 13px; }

/* Layout */
.layout { display: grid; grid-template-columns: 210px 1fr; min-height: calc(100vh - 54px); }
nav.side { background: var(--panel); border-right: 1px solid var(--line); padding: 12px 8px; }
nav.side a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--text); margin-bottom: 2px; }
nav.side a:hover { background: var(--panel-2); text-decoration: none; }
nav.side a.active { background: var(--accent); color: #fff; }
nav.side .badge { float: right; background: var(--bad); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; }
main { padding: 20px 24px; min-width: 0; }
.page-public { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }

/* Panels */
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.card.tight { padding: 10px 12px; }
.stat .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 10px; flex-wrap: wrap; }

/* Tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel-2); }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }

/* Pills */
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; white-space: nowrap; }
.pill.up, .pill.ok { color: var(--ok); } .pill.down, .pill.bad { color: var(--bad); } .pill.partial, .pill.warn { color: var(--warn); }
.pill.info { color: var(--accent); } .pill.mut { color: var(--muted); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; margin: 1px 2px 1px 0; }

/* Forms */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 7px; padding: 6px 12px; cursor: pointer; }
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.small { padding: 2px 8px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--input); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; width: 100%; }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.checks label { display: flex; align-items: center; gap: 5px; }
.hint { font-size: 12px; color: var(--muted); margin: -4px 0 10px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 2000; display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; overflow-y: auto; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(720px, 100%); box-shadow: var(--shadow); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; }
.modal .body { padding: 14px 16px; }
.modal footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.error-box { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); border-radius: 7px; padding: 8px 10px; margin-bottom: 10px; }

/* Map */
#map { height: calc(100vh - 54px - 120px); min-height: 420px; border-radius: 10px; border: 1px solid var(--line); background: #1d1f21; }
.maptools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.maptools .mode { color: var(--warn); font-weight: 600; }
.nn-node { display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 6px; color: #fff; font: 700 11px/1 system-ui; border: 2px solid rgba(255, 255, 255, .85); box-shadow: 0 1px 4px rgba(0, 0, 0, .5); }
.nn-node.down { background: var(--bad) !important; }
.nn-site { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.leaflet-popup-content { font-size: 13px; }
.leaflet-container { font: inherit; }

/* Toast */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 9px 16px; border-radius: 8px; z-index: 3000; }
#toast.bad { border-color: var(--bad); color: var(--bad); }

/* Speed test result */
.result { max-width: 680px; margin: 30px auto; }
.big { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: center; }
.big .v { font-size: 40px; font-weight: 750; font-variant-numeric: tabular-nums; }
.big .u { color: var(--muted); font-size: 13px; }
.trace td { font-family: var(--mono); font-size: 12.5px; }

/* Compass for sectors */
.compass { width: 200px; height: 200px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  nav.side { display: flex; overflow-x: auto; padding: 6px; border-right: 0; border-bottom: 1px solid var(--line); }
  nav.side a { white-space: nowrap; margin: 0 2px; }
  main { padding: 14px 16px; }
  .big .v { font-size: 28px; }
  .top .who { display: none; }
}
.maptools .spacer { flex: 1; }
