:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #646b78;
  --line: #d9dde4;
  --edge: #9aa3b2;
  --accent: #2f6fed;
  --accent-soft: #e6eeff;
  --ok: #1f9d55;
  --off: #8b93a1;
  --warn: #c98a04;
  --bad: #d23f3f;
  --server: #16181d;
  --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 {
    --bg: #0f1115;
    --panel: #171a21;
    --ink: #e8eaef;
    --muted: #98a0ae;
    --line: #2a2f3a;
    --edge: #5b6474;
    --accent: #6b9bff;
    --accent-soft: #1b2741;
    --ok: #3cc47c;
    --off: #6f7787;
    --warn: #e0a826;
    --bad: #f06363;
    --server: #e8eaef;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }

.bar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; flex-wrap: wrap; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo { width: 18px; height: 18px; border-radius: 5px; background: linear-gradient(135deg, var(--accent), #7a5cff); display: inline-block; }
.mapinfo { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; flex-wrap: wrap; }
.mapname { font-weight: 600; }
.who { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.live.on .pulse { background: var(--ok); box-shadow: 0 0 0 0 rgba(31, 157, 85, .5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 6px rgba(31, 157, 85, 0); } 100% { box-shadow: 0 0 0 0 rgba(31, 157, 85, 0); } }
@media (prefers-reduced-motion: reduce) { .live.on .pulse { animation: none; } }

button { font: inherit; border-radius: 8px; border: 1px solid transparent; padding: 8px 14px; cursor: pointer; background: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); padding: 5px 10px; font-weight: 500; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select { font: inherit; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.login { display: grid; place-items: center; min-height: 70vh; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(420px, 100%); box-shadow: var(--shadow); display: grid; gap: 10px; }
.card label { font-weight: 600; font-size: 13px; margin-top: 6px; }
.card input { font: inherit; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.err { color: var(--bad); min-height: 1.5em; margin: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panelhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -0.5px; }
.dot.active { background: var(--ok); } .dot.offline { background: var(--off); }
.dot.no_route { background: var(--warn); } .dot.blocked, .dot.expired { background: var(--bad); }

.treewrap { overflow: auto; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
#tree { display: block; min-width: 100%; }
#tree .edge { stroke: var(--edge); stroke-width: 1.6; fill: none; }
#tree .edge.hl { stroke: var(--accent); stroke-width: 3; }
#tree .rtt { font-size: 11px; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; font-variant-numeric: tabular-nums; }
#tree .rtt.hl { fill: var(--accent); font-weight: 600; }
#tree .direct { stroke: var(--ok); stroke-width: 1.8; stroke-dasharray: 6 5; fill: none; }
#tree .direct.hl { stroke-width: 3; }
#tree .direct-rtt { fill: var(--ok); }
#tree .node { cursor: pointer; }
#tree .node rect { fill: var(--panel); stroke: var(--line); stroke-width: 1.2; }
#tree .node:hover rect { stroke: var(--accent); }
#tree .node.sel rect { stroke: var(--accent); stroke-width: 2.5; fill: var(--accent-soft); }
#tree .node.onpath rect { stroke: var(--accent); stroke-width: 2; }
#tree .node .name { font-weight: 600; font-size: 13px; fill: var(--ink); }
#tree .node .sub { font-size: 11px; fill: var(--muted); font-family: ui-monospace, Consolas, monospace; }
#tree .node .st { stroke: var(--panel); stroke-width: 2; }
#tree .st.active { fill: var(--ok); } #tree .st.offline { fill: var(--off); }
#tree .st.no_route { fill: var(--warn); } #tree .st.blocked, #tree .st.expired { fill: var(--bad); }
#tree .badge { font-size: 10px; font-weight: 700; fill: var(--accent); }
#tree .server rect { fill: var(--server); stroke: var(--server); }
#tree .server text { fill: var(--panel); font-weight: 700; }
#tree .detached { font-size: 11px; fill: var(--muted); }
.hint { font-size: 12px; margin: 8px 2px 0; }

.side h2:not(:first-child) { margin-top: 18px; }
.path { font-size: 14px; line-height: 1.6; }
.path .big { font-size: 20px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.path .hops { color: var(--ink); }
.path ol { padding-left: 18px; margin: 8px 0 0; }
.detail { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg); }
tbody tr.sel { background: var(--accent-soft); }
td.num { font-variant-numeric: tabular-nums; }
.foot { font-size: 12px; text-align: right; margin-top: 10px; }
