:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --ink: #14181f;
  --muted: #5b6472;
  --line: #dfe3e8;
  --accent: #0d6e6e;
  --accent-soft: #e6f2f2;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --unknown: #6b7280;
  --radius: 12px;
  --control: 8px;
  --shadow: 0 1px 2px rgba(20, 24, 31, .06), 0 8px 24px rgba(20, 24, 31, .08);
  --topbar: 60px;
  --footer: 40px;
  --left: 264px;
  --right: 320px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.sr-only, .skip {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip:focus {
  position: fixed; left: 8px; top: 8px; width: auto; height: auto;
  clip: auto; background: var(--panel); padding: 10px 14px; z-index: 60;
  border-radius: var(--control);
}
.muted { color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar);
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
  flex: none;
}
.brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.brand strong { font-size: 18px; letter-spacing: -.01em; }
.brand span { font-size: 12px; color: var(--muted); }

.search { flex: 1; min-width: 140px; max-width: 420px; position: relative; }
.search input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--control);
  background: var(--bg); color: var(--ink); font: inherit;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-results {
  position: absolute; top: 46px; left: 0; right: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 340px; overflow: auto; display: none; z-index: 50;
}
.search-results.open { display: block; }
.search-results button {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  width: 100%; min-height: 44px; padding: 8px 12px; border: 0; background: none;
  font: inherit; color: var(--ink); text-align: left; cursor: pointer;
}
.search-results button:hover, .search-results button:focus { background: var(--accent-soft); }
.search-results small { color: var(--muted); white-space: nowrap; }
.res-name { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.res-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--control); overflow: hidden; }
.seg .btn { border: 0; border-radius: 0; min-width: 48px; }
.seg .btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: var(--control); background: var(--panel); color: var(--ink);
  font: inherit; font-size: 14px; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: #c6ccd4; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.scope { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.scope.internal { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.who { font-size: 13px; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- workspace ---------- */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--left) minmax(0, 1fr) var(--right);
}
.panel.side {
  background: var(--panel);
  overflow: auto;
  min-height: 0;
  padding: 14px;
}
#layers { border-right: 1px solid var(--line); }
.detail { border-left: 1px solid var(--line); }
.sheet-handle { display: none; }

.stage { position: relative; min-height: 0; min-width: 0; overflow: hidden; }
#graph { position: absolute; inset: 0; background: var(--bg); }
#graph canvas { display: block; }

.stage-status {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  color: var(--muted); font-size: 14px; text-align: center; max-width: 320px;
}
.stage-hud {
  position: absolute; left: 12px; top: 12px; z-index: 5;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.age-badge {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .92); color: var(--muted);
}
.age-badge.ok { border-color: #bbf7d0; color: var(--ok); background: #f0fdf4; }
.age-badge.warn { border-color: #fed7aa; color: var(--warn); background: #fffbeb; }
.age-badge.bad { border-color: #fecaca; color: var(--bad); background: #fef2f2; }
.flash {
  font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px;
  border: 1px solid #fecaca; background: #fef2f2; color: var(--bad); cursor: pointer;
  font-family: inherit;
}
.flash:empty { display: none; }

/* ---------- panels ---------- */
.panel h2 {
  margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 6px;
}
.panel section + section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.hint {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line);
  font-size: 10px; color: var(--muted); cursor: help;
}
.quick-views { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-views .btn { flex: 1 1 45%; min-height: 34px; padding: 0 8px; font-size: 13px; }
.quick-views .btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.checklist label {
  display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 3px 6px;
  border-radius: var(--control); cursor: pointer; font-size: 13.5px;
}
.checklist label:hover { background: var(--bg); }
.checklist input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.checklist .count { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.checklist li.off { opacity: .55; }
.sw { display: inline-flex; width: 18px; height: 18px; flex: none; }
.sw svg { display: block; }
.legend { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.status-key { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--muted); }
.status-item { display: inline-flex; align-items: center; gap: 5px; }
.ring { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--unknown); display: inline-block; }
.ring.stale { border-style: dashed; border-color: #9ca3af; }
.status-filter select {
  width: 100%; min-height: 40px; margin-top: 8px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--control);
  background: var(--panel); font: inherit; font-size: 14px;
}
.edge-dash { width: 18px; height: 0; border-top: 2px dashed #94a3b8; flex: none; }
.rows li { display: block; }
.link-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; min-height: 36px; padding: 4px 6px; border: 0; border-radius: var(--control);
  background: none; font: inherit; font-size: 13px; color: var(--ink); text-align: left; cursor: pointer;
}
.link-row:hover, .link-row:focus { background: var(--bg); }
.row-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- detail ---------- */
.detail { font-size: 14px; }
.eyebrow { margin: 0 0 2px; display: flex; align-items: center; gap: 6px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.detail-title { margin: 0 0 6px; font-size: 18px; line-height: 1.25; overflow-wrap: anywhere; }
.detail-desc { margin: 8px 0; color: #2b323c; font-size: 13.5px; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); background: #f3f4f6; color: var(--unknown);
}
.pill.ok { color: var(--ok); border-color: #bbf7d0; background: #f0fdf4; }
.pill.warn { color: var(--warn); border-color: #fed7aa; background: #fffbeb; }
.pill.bad { color: var(--bad); border-color: #fecaca; background: #fef2f2; }
.detail-meta { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 13px; margin: 10px 0; }
.detail-meta dt { color: var(--muted); }
.detail-meta dd { margin: 0; overflow-wrap: anywhere; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.detail-h { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
.neighbours { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.neighbours .link-row { border: 1px solid var(--line); }
.neighbours .count { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ---------- footer ---------- */
.atlas-footer {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px;
  padding: 8px 16px; border-top: 1px solid var(--line); background: var(--panel);
  font-size: 12.5px; color: var(--muted); flex: none;
}
.atlas-footer a { color: inherit; text-decoration-color: #c6ccd4; }
.atlas-footer a:hover { color: var(--accent); }
.atlas-footer .spacer { margin-left: auto; }
.atlas-footer .sep { opacity: .5; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; background: var(--unknown); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* ---------- watchdog page (kept) ---------- */
.doc { max-width: 960px; margin: 0 auto; padding: 32px 24px 64px; }
.doc h1 { font-size: 26px; margin: 0 0 4px; }
.doc h2 { font-size: 18px; margin: 32px 0 10px; }
.doc p { margin: 8px 0; }
.doc .sub { color: var(--muted); }
.state-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin: 20px 0 8px; }
.state-strip div { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 12px; }
.state-strip b { display: block; font-size: 20px; letter-spacing: -.01em; }
.state-strip span { font-size: 12px; color: var(--muted); }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.week div { border: 1px solid var(--line); border-radius: var(--control); padding: 10px 6px; text-align: center; background: var(--panel); }
.week div.ok { background: #f0fdf4; border-color: #bbf7d0; }
.week div.warn { background: #fffbeb; border-color: #fed7aa; }
.week div.bad { background: #fef2f2; border-color: #fecaca; }
.week div.none { background: #f3f4f6; }
.week b { display: block; font-size: 16px; }
.week small { color: var(--muted); }
table.runs { width: 100%; border-collapse: collapse; font-size: 14px; }
table.runs th, table.runs td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.runs th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.checks li { display: flex; align-items: baseline; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--control); background: var(--panel); font-size: 14px; }
.checks .name { min-width: 190px; font-weight: 500; }
.checks .detail { color: var(--muted); font-size: 13px; }
.dl { display: grid; grid-template-columns: 190px 1fr; gap: 6px 12px; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

/* ---------- mobile ---------- */
.mobile-bar { display: none; }
.only-3d { display: inline-flex; }
body:not(.mode-3d) #toggle-rotate { display: none; }

@media (max-width: 900px) {
  :root { --topbar: 52px; }

  .topbar { flex-wrap: wrap; gap: 4px 6px; padding: 5px 8px; min-height: 0; }
  .brand { flex: 0 0 auto; }
  .brand strong { font-size: 16px; }
  .brand span { display: none; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .search input { height: 36px; font-size: 14px; }
  .toolbar { gap: 4px; margin-left: auto; }
  .toolbar .scope, .toolbar .who { display: none; }
  .toolbar .btn { min-height: 34px; padding: 0 8px; font-size: 13px; }
  .toolbar .btn.primary { padding: 0 10px; }
  #toggle-rotate { display: none; }
  .seg .btn { min-width: 40px; }

  .workspace { grid-template-columns: 1fr; }
  .panel.side {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    max-height: 72dvh; border: 1px solid var(--line); border-bottom: 0;
    border-radius: 16px 16px 0 0; box-shadow: 0 -12px 32px rgba(20, 24, 31, .18);
    transform: translateY(105%); transition: transform .22s ease;
    padding: 6px 14px calc(72px + env(safe-area-inset-bottom)); overflow: auto;
  }
  .panel.side.open { transform: translateY(0); }
  #layers { border-right: 1px solid var(--line); }
  .detail { border-left: 1px solid var(--line); }
  .sheet-handle {
    display: flex; justify-content: center; align-items: center;
    height: 26px; margin: -2px -14px 8px; cursor: grab; touch-action: none;
  }
  .sheet-handle span {
    width: 44px; height: 5px; border-radius: 999px; background: #c6ccd4; display: block;
  }
  .stage { flex: 1; min-height: 0; }
  .stage-hud { left: 10px; top: 10px; }
  .age-badge, .flash { font-size: 11px; }
  .mobile-bar {
    display: flex; gap: 8px; position: absolute; left: 12px; right: 12px; bottom: 12px;
    z-index: 45; justify-content: center;
  }
  .mobile-bar .btn {
    min-height: 44px; min-width: 76px; box-shadow: var(--shadow); background: rgba(255,255,255,.96);
  }
  .atlas-footer { font-size: 11px; gap: 4px 8px; padding: 6px 10px; }
  .atlas-footer .sep { display: none; }
  .state-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .week { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dl { grid-template-columns: 1fr; }
  .dl dt { margin-top: 8px; }
  .doc { padding: 24px 16px 48px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* Status filter bar: click Online / Offline to show only those nodes. */
.net-status {
  position: absolute; left: 12px; right: 12px; top: 12px; z-index: 4;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  pointer-events: none;
}
.net-status .ns-btn {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .94);
  color: var(--ink); cursor: pointer;
}
.net-status .ns-btn b { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); }
.net-status .ns-btn:hover { border-color: var(--ink); }
.net-status .ns-btn.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.net-status .ns-btn.is-active b { color: #e6e9ec; }
.net-status .ns-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.ns-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ns-dot.ok { background: #22c55e; }
.ns-dot.warn { background: #f59e0b; }
.ns-dot.bad { background: #ef4444; }
.ns-dot.unk { background: #94a3b8; }
/* keep the age badge clear of the new bar */
.stage-hud { top: 54px; }
@media (max-width: 720px) {
  /* One scrollable row: wrapping it to two lines collides with the age badge. */
  .net-status {
    right: 8px; left: 8px; gap: 4px;
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .net-status::-webkit-scrollbar { display: none; }
  .net-status .ns-btn { font-size: 11px; padding: 4px 8px; flex: 0 0 auto; }
}

/* ---------- hierarchy tree (default view) ---------- */
#tree {
  position: absolute; inset: 0; overflow: auto; display: none;
  padding: 104px 18px 28px; background: var(--bg); scroll-behavior: smooth;
}
body.view-tree #tree { display: block; }
body.view-tree #graph { display: none; }
body.view-tree .only-map { display: none !important; }
.tree-server {
  max-width: 980px; margin: 0 auto 18px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--panel); overflow: hidden;
}
.tree-server-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.tree-server-title { border: 0; background: none; padding: 0; font: inherit; font-size: 16px; font-weight: 800; color: var(--ink); cursor: pointer; }
.tree-server-title:hover { color: var(--accent); }
.tree-server-role { color: var(--muted); font-size: 12px; }
.tree-server-stats { margin-left: auto; color: var(--accent); font-weight: 700; font-size: 12px; }
.tree-group { border-top: 1px solid var(--line); }
.tree-group:first-of-type { border-top: 0; }
.tree-group-head { display: flex; gap: 8px; padding: 7px 16px; background: #f7f9fa; color: var(--muted); font-size: 10.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.tree-group-head .count { margin-left: auto; font-weight: 700; }
.tree-row { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 33px; padding: 4px 16px; border: 0; border-top: 1px solid #f0f2f4; background: none; font: inherit; color: var(--ink); text-align: left; cursor: pointer; }
.tree-row:hover, .tree-row:focus-visible { background: #f2f7f7; outline: 0; }
.tree-row.is-selected { background: var(--accent-soft); }
.tree-row.is-site { padding-left: 26px; font-weight: 600; }
.tree-row.is-child { padding-left: 54px; font-size: 12.5px; color: #4b5563; }
.tree-row .sw { width: 16px; height: 16px; }
.tree-row .sw svg { width: 16px; height: 16px; }
.tree-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-kids { color: var(--muted); font-size: 10.5px; white-space: nowrap; }
.tree-type { color: var(--muted); font-size: 10px; white-space: nowrap; }
.tree-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--unknown); }
.tree-dot.ok { background: var(--ok); }
.tree-dot.warn { background: var(--warn); }
.tree-dot.bad { background: var(--bad); }
@media (max-width: 700px) {
  #tree { padding: 100px 10px 92px; }
  .tree-row.is-child { padding-left: 38px; }
  .tree-type { display: none; }
}
