:root {
  --navy: #003B71; --navy-2: #0a4d8c; --navy-3: #002a52; --gold: #EAAD32;
  --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f8f9fb; --border: #dde2ea; --border-2: #c9d0db;
  --text: #1c2430; --text-2: #4d5a6b; --muted: #7b8796;
  --s1: #2F6DB5; --s2: #D9822B; --grid: #e7ebf0;
  --ok: #1e8a4c; --ok-bg: #e3f4ea; --warn: #b26a00; --warn-bg: #fff2d9; --crit: #c62828; --crit-bg: #fde6e6;
  --unk: #7b8796; --unk-bg: #eceff3; --link: #0a5bb0; --focus: #EAAD32;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --surface: #1a1f27; --surface-2: #20262f; --border: #2c3440; --border-2: #3a4452;
    --text: #e6eaf0; --text-2: #b3bdca; --muted: #8a95a4;
    --s1: #4A86D4; --s2: #B97A1F; --grid: #2a313c;
    --ok: #4cc27f; --ok-bg: #173325; --warn: #f0b048; --warn-bg: #3a2d14; --crit: #ff6b6b; --crit-bg: #3d1c1c;
    --unk: #9aa5b3; --unk-bg: #262d36; --link: #7fb2ff; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --surface: #1a1f27; --surface-2: #20262f; --border: #2c3440; --border-2: #3a4452;
  --text: #e6eaf0; --text-2: #b3bdca; --muted: #8a95a4;
  --s1: #4A86D4; --s2: #B97A1F; --grid: #2a313c;
  --ok: #4cc27f; --ok-bg: #173325; --warn: #f0b048; --warn-bg: #3a2d14; --crit: #ff6b6b; --crit-bg: #3d1c1c;
  --unk: #9aa5b3; --unk-bg: #262d36; --link: #7fb2ff; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", Calibri, system-ui, -apple-system, Roboto, sans-serif; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---- layout ---- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #dce6f2; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px 12px; color: #fff; font-weight: 600; font-size: 17px; letter-spacing: .02em; }
.brand svg { flex: none; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: #9fb6cf; letter-spacing: .03em; }
.picker { margin: 4px 12px 8px; }
.picker label { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #8fa9c6; margin: 8px 6px 3px; }
.picker select { width: 100%; background: var(--navy-3); color: #fff; border: 1px solid #23548a; border-radius: 6px; padding: 7px 8px; }
.nav { list-style: none; margin: 8px 0; padding: 0 8px; flex: 1; overflow: auto; }
.nav .sect { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #8fa9c6; padding: 14px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #dce6f2; padding: 8px 10px; border-radius: 6px; border-left: 3px solid transparent; }
.nav a:hover { background: var(--navy-2); text-decoration: none; }
.nav a.active { background: var(--navy-2); color: #fff; border-left-color: var(--gold); }
.nav .badge { margin-left: auto; background: var(--crit); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; }
.side-foot { padding: 12px 18px; font-size: 12px; color: #9fb6cf; border-top: 1px solid #154a80; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.side-foot button { background: none; border: 1px solid #2c5e94; color: #dce6f2; border-radius: 6px; padding: 4px 8px; cursor: pointer; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.crumbs { color: var(--muted); font-size: 13px; }
.crumbs b { color: var(--text); font-weight: 600; }
.topbar .spacer { flex: 1; }
.search { width: 260px; max-width: 40vw; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }
.page { padding: 20px 24px 40px; max-width: 1500px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

/* ---- components ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.grid { display: grid; gap: 16px; align-items: start; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.stack > * + * { margin-top: 16px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-2); background: var(--surface); padding: 7px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: var(--crit); border-color: var(--crit); }
.btn.sm { padding: 4px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }
.input, select.input, textarea.input { width: 100%; padding: 7px 9px; border: 1px solid var(--border-2); border-radius: 6px; background: var(--surface); }
textarea.input { font-family: var(--mono); font-size: 12.5px; min-height: 140px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl.nowrap td { white-space: nowrap; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface-2); }
.tbl td.r, .tbl th.r { text-align: right; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill .ico { width: 14px; height: 14px; flex: none; }
.st-online { color: var(--ok); background: var(--ok-bg); }
.st-alerting { color: var(--warn); background: var(--warn-bg); }
.st-offline, .sev-critical { color: var(--crit); background: var(--crit-bg); }
.st-unknown, .st-disabled, .st-empty, .sev-info { color: var(--unk); background: var(--unk-bg); }
.sev-warning { color: var(--warn); background: var(--warn-bg); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.online { background: var(--ok); } .dot.alerting { background: var(--warn); } .dot.offline { background: var(--crit); }
.dot.unknown, .dot.disabled { background: var(--unk); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--unk-bg); color: var(--text-2); margin-right: 4px; }
.tag.up { background: var(--ok-bg); color: var(--ok); } .tag.down { background: var(--crit-bg); color: var(--crit); }

.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .v { font-size: 30px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.kpi .sub { color: var(--muted); font-size: 12px; }

.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.site { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--surface); cursor: pointer; border-top: 3px solid var(--unk); }
.site:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.site.online { border-top-color: var(--ok); } .site.alerting { border-top-color: var(--warn); } .site.offline { border-top-color: var(--crit); }
.site .name { font-weight: 600; } .site .addr { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.site .devs { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.site .devs span { display: flex; align-items: center; gap: 7px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 0 0 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--gold); font-weight: 600; }

.dev-head { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }
.dev-head .title { display: flex; align-items: center; gap: 10px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 20px; margin: 8px 0 18px; }
.facts div span { display: block; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.facts div b { font-weight: 600; font-size: 13.5px; word-break: break-all; }

.ports { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; padding: 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.port-grp { display: flex; flex-direction: column; gap: 4px; }
.port-grp .lbl { font-size: 11px; color: var(--muted); }
.port-row { display: flex; gap: 4px; }
.port { width: 34px; height: 28px; border-radius: 4px; border: 2px solid var(--border-2); background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--muted); cursor: default; position: relative; }
.port.up { background: var(--ok); border-color: var(--ok); color: #fff; }
.port.down { background: var(--surface); border-color: var(--border-2); }
.port.admin { background: repeating-linear-gradient(45deg, var(--unk-bg), var(--unk-bg) 3px, var(--surface) 3px, var(--surface) 6px); }
.port.standby { border-color: var(--ok); border-style: dashed; color: var(--ok); }
.port.wan.down { border-color: var(--crit); color: var(--crit); }
.port.cell { border-radius: 14px; }

.signal { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; vertical-align: middle; }
.signal i { width: 4px; background: var(--border-2); border-radius: 1px; }
.signal i.on { background: var(--text); }
.bar-mini { height: 6px; width: 70px; background: var(--grid); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.bar-mini i { display: block; height: 100%; background: var(--s1); border-radius: 3px; }
.bar-mini i.hot { background: var(--warn); }

.term { background: #0f1720; color: #d6e2f0; font-family: var(--mono); font-size: 12.5px; padding: 12px 14px; border-radius: 6px; white-space: pre-wrap; word-break: break-word; min-height: 120px; max-height: 520px; overflow: auto; margin: 0; }
.diff .add { color: #7ee2a0; } .diff .del { color: #ff9b9b; } .diff .hunk { color: #8fb7ff; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 10.5px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .xhair { stroke: var(--border-2); stroke-width: 1; }
.chart .legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; flex-wrap: wrap; }
.chart .legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart .legend i { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border-2); border-radius: 6px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; z-index: 3; }
.tip .t { color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.tip .r { display: flex; align-items: center; gap: 6px; }
.tip .r b { font-variant-numeric: tabular-nums; }
.tip .r i { width: 10px; height: 2px; display: inline-block; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

.hbar { display: grid; grid-template-columns: minmax(90px, 150px) 1fr 76px; gap: 8px; align-items: center; font-size: 12.5px; margin-bottom: 6px; }
.hbar .track { height: 10px; background: var(--grid); border-radius: 0 4px 4px 0; }
.hbar .track i { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 18, 32, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.x { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.err { background: var(--crit); color: #fff; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-3) 60%, #001a33 100%); }
.login { background: var(--surface); width: 100%; max-width: 380px; border-radius: 12px; padding: 28px; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.login .brand { color: var(--navy); padding: 0 0 18px; }
.login .brand small { color: var(--muted); }
.login .err { color: var(--crit); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.qr { background: #fff; padding: 10px; border-radius: 8px; display: inline-block; }
.qr svg { width: 180px; height: 180px; display: block; }

.mobile-nav { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .mobile-nav { display: inline-flex; }
  .g2, .g3, .g4, .g-side { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; }
  .page { padding: 16px; }
  .search { width: 140px; }
}
