@import url("https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700&family=Barlow+Semi+Condensed:wght@400;500;600&display=swap");

:root {
  --bg: #0d1a2a;
  --panel: #13243a;
  --panel-2: #1a2f4a;
  --line: #24405f;
  --ink: #e3ecf5;
  --mute: #8da2b8;
  --faint: #5d7590;
  --up: #2fbf8c;
  --degraded: #f0b341;
  --down: #f2545b;
  --unknown: #6c7e92;
  --accent: #5ba4ff;
  --accent-ink: #06172b;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "Barlow", "Segoe UI", system-ui, sans-serif;
  --font-dense: "Barlow Semi Condensed", "Arial Narrow", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 10px;
  display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 10px 18px; }
.brand b { display: block; font-size: 21px; font-weight: 700; letter-spacing: .02em; }
.brand span { color: var(--mute); font-size: 13px; }
.rail a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-s);
  color: var(--mute); font-weight: 500;
}
.rail a:hover { background: var(--panel-2); color: var(--ink); text-decoration: none; }
.rail a.on { background: var(--panel-2); color: var(--ink); box-shadow: inset 3px 0 0 var(--accent); }
.rail .count { margin-left: auto; font-family: var(--font-dense); font-size: 13px; background: var(--down); color: #fff; border-radius: 10px; padding: 0 7px; }
.rail .foot { margin-top: auto; padding: 10px; color: var(--faint); font-size: 12px; }
.rail .who { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.rail .who b { color: var(--ink); font-size: 14px; font-weight: 600; }
.rail .who span { color: var(--mute); font-size: 12.5px; }
.rail .who a { display: inline; padding: 0; color: var(--accent); }
.rail .who a:hover { background: none; text-decoration: underline; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; background: var(--bg);
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.clock { font-family: var(--font-dense); color: var(--mute); white-space: nowrap; }
.page { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- health bar (branch status proportions) ---------- */
.health { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 0 1 460px; }
.health .bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; flex: 1; background: var(--panel-2); min-width: 120px; }
.health .bar i { display: block; height: 100%; }
.health .legend { display: flex; gap: 12px; font-family: var(--font-dense); font-size: 14px; color: var(--mute); white-space: nowrap; }
.health .legend b { color: var(--ink); font-weight: 600; }

/* ---------- status primitives ---------- */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.s-up { --s: var(--up); }
.s-degraded { --s: var(--degraded); }
.s-down { --s: var(--down); }
.s-unknown { --s: var(--unknown); }
.dot { background: var(--s, var(--unknown)); }
.stxt { color: var(--s); font-weight: 600; text-transform: capitalize; }
.sev { font-family: var(--font-dense); font-weight: 600; font-size: 13px; padding: 1px 7px; border-radius: var(--radius-s); text-transform: capitalize; }
.sev-critical { background: var(--down); color: #fff; }
.sev-major { background: #e07a3f; color: #fff; }
.sev-minor { background: var(--degraded); color: #241a00; }
.sev-info { background: var(--panel-2); color: var(--mute); }

/* WAN path strip — the signature element */
.paths { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.path {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-dense); font-size: 13px; font-weight: 600;
  padding: 2px 8px; border-radius: var(--radius-s);
  border: 1.5px solid var(--s); color: var(--s); background: transparent;
  white-space: nowrap;
}
.path.active { background: var(--s); color: var(--accent-ink); }
.path.s-down { border-style: dashed; }
.path small { font-weight: 500; opacity: .85; }
.paths.big .path { font-size: 15px; padding: 6px 12px; }

/* ---------- panels & layout ---------- */
.grid-ov { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); min-width: 0; }
.panel.flex { display: flex; flex-direction: column; }
.panel > header { display: flex; align-items: baseline; gap: 12px; padding: 14px 16px 10px; }
.panel > header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.panel > header .sub { color: var(--mute); font-size: 13px; }
.panel > header .act { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.panel .body { padding: 0 16px 16px; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.cols-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.figure { background: var(--panel); padding: 12px 16px; }
.figure .v { font-size: 26px; font-weight: 600; line-height: 1.1; }
.figure .l { color: var(--mute); font-size: 13px; }
.figure .d { font-family: var(--font-dense); font-size: 13px; color: var(--mute); margin-top: 2px; }
.figure .d b { font-weight: 600; }

/* attention list */
.attn { list-style: none; margin: 0; padding: 0; }
.attn li { display: grid; grid-template-columns: 9px 1fr auto; gap: 10px; align-items: start; padding: 10px 16px; border-top: 1px solid var(--line); cursor: pointer; }
.attn li:hover { background: var(--panel-2); }
.attn .dot { margin-top: 6px; }
.attn .t { font-weight: 600; }
.attn .m { color: var(--mute); font-size: 13px; }
.attn .when { font-family: var(--font-dense); color: var(--mute); font-size: 13px; white-space: nowrap; }
.empty { padding: 20px 16px; color: var(--mute); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-family: var(--font-dense); font-size: 14.5px; }
.tbl th { text-align: left; color: var(--mute); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--panel); }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--ink); }
.tbl td { padding: 8px 10px; border-bottom: 1px solid rgba(36, 64, 95, .55); vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--panel-2); }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl .nowrap { white-space: nowrap; }
.tbl .strong { font-weight: 600; font-family: var(--font); font-size: 15px; }
.tbl .mute { color: var(--mute); }
.tbl .paths { flex-wrap: nowrap; }
.warn { color: var(--degraded); font-weight: 600; }
.bad { color: var(--down); font-weight: 600; }
.good { color: var(--up); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
  padding: 6px 12px; border-radius: var(--radius-s); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { border-color: var(--down); color: var(--down); background: transparent; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.toggle.on { border-color: var(--up); color: var(--up); }
input.in, select.in, textarea.in {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 6px 10px; min-width: 0;
}
input.in:focus, select.in:focus, textarea.in:focus { border-color: var(--accent); outline: none; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 5px 12px; color: var(--mute); cursor: pointer; font-family: var(--font-dense); font-size: 14px; }
.seg button.on { background: #2a4a72; color: var(--ink); }
.seg button + button { border-left: 1px solid var(--line); }

/* ---------- map ---------- */
.map { position: relative; height: 460px; flex: 1 0 auto; overflow: hidden; border-radius: 0 0 var(--radius-m) var(--radius-m); background: #0a1522; cursor: grab; touch-action: none; }
.map.tall { height: calc(100vh - 150px); min-height: 480px; border-radius: var(--radius-m); }
.map .tiles img { position: absolute; width: 256px; height: 256px; filter: invert(1) hue-rotate(185deg) brightness(.82) saturate(.45) contrast(.95); user-select: none; -webkit-user-drag: none; }
.map .pin { position: absolute; transform: translate(-50%, -50%); width: 14px; height: 14px; border-radius: 50%; background: var(--s); border: 2px solid #0a1522; cursor: pointer; z-index: 2; padding: 0; }
.map .pin.hq { width: 18px; height: 18px; border-radius: 4px; }
.map .pin.s-down::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid var(--down); animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { from { transform: scale(.5); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
.map .tip { position: absolute; z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 10px 12px; min-width: 240px; transform: translate(-50%, calc(-100% - 14px)); pointer-events: auto; cursor: default; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); }
.map .tip .t { font-weight: 600; }
.map .tip .m { color: var(--mute); font-size: 13px; margin-bottom: 6px; }
.map .zoom { position: absolute; right: 10px; top: 10px; z-index: 6; display: flex; flex-direction: column; gap: 4px; }
.map .zoom button { width: 30px; height: 30px; padding: 0; justify-content: center; }
.map .attr { position: absolute; right: 6px; bottom: 4px; z-index: 6; font-size: 11px; color: var(--faint); }

/* ---------- charts ---------- */
.chart { width: 100%; display: block; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--mute); font: 12px var(--font-dense); }
.chart .down-band { fill: rgba(242, 84, 91, .16); }
.legend-row { display: flex; gap: 14px; font-family: var(--font-dense); font-size: 13px; color: var(--mute); }
.legend-row i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

/* ---------- topology ---------- */
.topo { width: 100%; display: block; }
.topo text { fill: var(--ink); font: 14px var(--font-dense); }
.topo .lbl-mute { fill: var(--mute); font-size: 12.5px; }
.topo .node rect, .topo .node circle { fill: var(--panel-2); stroke: var(--s); stroke-width: 2; }
.topo .edge { fill: none; stroke: var(--s); stroke-width: 2; }
.topo .edge.s-down { stroke-dasharray: 5 4; }
.topo .edge.standby { stroke-opacity: .45; }
.topo .clickable { cursor: pointer; }
.topo .clickable:hover rect { stroke-width: 3; }
.autotopo text { font-size: 13.5px; }
.autotopo .t-strong { font-family: var(--font); font-weight: 600; font-size: 14px; }
.autotopo .lbl-mute { font-size: 12.5px; }

/* ---------- branch detail ---------- */
.bhead { display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: flex-end; }
.bhead h2 { margin: 0; font-size: 26px; font-weight: 600; }
.bhead .meta { color: var(--mute); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--mute); }
.kv dd { margin: 0; }
.linkcard { border-top: 1px solid var(--line); padding: 12px 16px; display: grid; grid-template-columns: minmax(200px, 1.4fr) 140px 130px 70px 200px 150px; gap: 14px; align-items: center; font-family: var(--font-dense); }
.linkcard .nm { font-family: var(--font); font-weight: 600; }
.linkcard .nm small { display: block; color: var(--mute); font-weight: 400; font-family: var(--font-dense); }
.linkcard .k { color: var(--mute); font-size: 12px; display: block; }
pre.code { margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 12px; overflow: auto; max-height: 420px; font: 12.5px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; color: #bcd0e4; }

/* ---------- modal / toast / login ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(5, 12, 20, .65); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 17px; }
.modal header button { margin-left: auto; }
.modal .content { padding: 16px 18px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--mute); }
.form label.full { grid-column: 1 / -1; }
.form .in { color: var(--ink); font-size: 15px; }
.toast { position: fixed; bottom: 18px; right: 18px; z-index: 60; background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: var(--radius-s); max-width: 380px; }
.toast.err { border-left-color: var(--down); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 28px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0; font-size: 26px; }
.login p { margin: 0 0 6px; color: var(--mute); }
.login label { display: flex; flex-direction: column; gap: 4px; color: var(--mute); font-size: 13px; }
.login .err { color: var(--down); font-size: 14px; }
.banner { background: rgba(240, 179, 65, .12); border: 1px solid rgba(240, 179, 65, .4); color: var(--degraded); padding: 8px 14px; border-radius: var(--radius-s); font-size: 14px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 8px 14px; color: var(--mute); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid-ov, .cols-2, .cols-3 { grid-template-columns: 1fr; }
  .health .legend { display: none; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail .brand, .rail .foot .poll { display: none; }
  .rail .foot .live { margin: 0; white-space: nowrap; }
  .rail .foot { margin: 0 0 0 8px; padding: 0 4px; flex: none; }
  .rail .who { margin: 0; padding: 0; border: 0; flex-direction: row; gap: 10px; align-items: center; white-space: nowrap; }
  .rail a { flex: none; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; position: static; }
  .health { flex-basis: 100%; order: 3; }
  .page { padding: 16px; }
  .linkcard { grid-template-columns: 1fr 1fr; }
  .form { grid-template-columns: 1fr; }
  .map { height: 360px; }
}
@media (prefers-reduced-motion: reduce) {
  .map .pin.s-down::after { animation: none; transform: scale(1.1); opacity: .8; }
}

/* ---------- tickets ---------- */
.timeline { list-style: none; margin: 0; padding: 0 16px 8px; }
.timeline li { display: grid; grid-template-columns: 9px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.timeline .dot { margin-top: 7px; }
.timeline .tl-head { font-size: 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.timeline .tl-text { white-space: pre-wrap; margin-top: 2px; }
.tag { font-family: var(--font-dense); font-size: 12px; border: 1px solid var(--accent); color: var(--accent); border-radius: var(--radius-s); padding: 0 6px; }
.comment-box { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.comment-box textarea { width: 100%; }
.tbl tr.row-bad td:first-child { box-shadow: inset 3px 0 0 var(--down); }
.form fieldset { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin: 0; }
.form fieldset legend { color: var(--ink); font-weight: 600; padding: 0 6px; }
.form .chips { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--ink); font-size: 14px; }
.form .chips label { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }

/* live-update indicator (sidebar foot) */
.rail .foot .live { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--mute); margin-bottom: 6px; }
.rail .foot .live i { width: 8px; height: 8px; border-radius: 50%; background: var(--degraded); flex: none; }
.rail .foot .live.live { color: var(--ink); }
.rail .foot .live.live i { background: var(--up); box-shadow: 0 0 0 3px rgba(47, 191, 140, .18); }
.rail .foot .live.off i { background: var(--unknown); }
@media (prefers-reduced-motion: no-preference) {
  .rail .foot .live.retrying i, .rail .foot .live.connecting i { animation: livepulse 1.2s ease-in-out infinite; }
}
@keyframes livepulse { 50% { opacity: .5; } }

/* ---------- system page ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.panel > .kv { padding: 0 16px 16px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; word-break: break-all; }
.sysdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 9px; vertical-align: 2px; background: var(--unknown); }
.sysdot.ok { background: var(--up); }
.sysdot.bad { background: var(--down); }

/* ---------- WAN health chip + maintenance badge ---------- */
.hchip { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 22px; padding: 0 6px; border-radius: 4px;
  font-family: var(--font-dense); font-weight: 600; font-size: 13.5px; font-variant-numeric: tabular-nums; border: 1px solid transparent; }
.hchip.good { background: rgba(47, 191, 140, .14); color: var(--up); border-color: rgba(47, 191, 140, .35); }
.hchip.fair { background: rgba(240, 179, 65, .14); color: var(--degraded); border-color: rgba(240, 179, 65, .4); }
.hchip.poor { background: rgba(242, 84, 91, .15); color: var(--down); border-color: rgba(242, 84, 91, .45); }
.hchip.na { color: var(--mute); border-color: var(--line); }
.hchip.big { min-width: 44px; height: 30px; font-size: 18px; }
.mbadge { display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 4px; font-size: 12px; font-weight: 500; white-space: nowrap;
  color: #c9b6ff; background: rgba(150, 120, 255, .14); border: 1px solid rgba(150, 120, 255, .4); vertical-align: 1px; }
.banner.maint { border-color: rgba(150, 120, 255, .5); background: rgba(150, 120, 255, .1); color: var(--ink); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.linkcard .hnote { display: block; font-family: var(--font-dense); font-size: 12.5px; color: var(--mute); margin-top: 2px; }
