:root {
  --edge: #d6d5ce;
  --stage: #f6f6f3;
  --stage-dot: #e3e2dc;
  --node-shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 6px 18px rgba(11, 11, 11, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --edge: #3a3a37;
    --stage: #121211;
    --stage-dot: #262624;
    --node-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --edge: #3a3a37;
  --stage: #121211;
  --stage-dot: #262624;
  --node-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
}

.topo-main { max-width: none; padding: 16px 24px 24px; gap: 12px; }

/* ---------- summary strip ---------- */
.strip {
  display: flex; flex-wrap: wrap; gap: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.strip-item { display: flex; flex-direction: column; gap: 2px; padding: 10px 18px; min-width: 110px; flex: 1 1 0; border-left: 1px solid var(--grid); }
.strip-item:first-child { border-left: 0; }
.strip-label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.strip-value { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; }
.strip-hero .strip-value { font-size: 26px; }
.strip-value .bad { color: var(--critical-text); }

/* ---------- graph card ---------- */
.graph-card { overflow: hidden; }
.graph-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.graph-toolbar .card-sub { margin-left: 8px; }
.zoom { display: inline-flex; gap: 6px; }
.zoom .icon-btn { min-width: 34px; }

.stage {
  position: relative; height: max(480px, calc(100vh - 250px));
  background-color: var(--stage);
  background-image: radial-gradient(var(--stage-dot) 1px, transparent 1px);
  background-size: 22px 22px;
  cursor: grab; touch-action: none; user-select: none;
}
.stage.panning { cursor: grabbing; }
#graph { width: 100%; height: 100%; display: block; }
.hint { padding: 8px 16px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }

.graph-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: var(--ink-2); pointer-events: none; text-align: center; padding: 16px;
}
.graph-empty strong { color: var(--ink); font-size: 15px; }

.legend-box {
  position: absolute; left: 12px; bottom: 12px; display: grid; gap: 4px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; color: var(--ink-2); pointer-events: none;
}
.legend-row { display: flex; align-items: center; gap: 6px; }
.lg-edge { stroke: var(--edge); stroke-width: 6; stroke-linecap: round; }
.lg-flow { stroke: var(--series-1); stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 2 8; }
.lg-bad { stroke: var(--critical); }

/* ---------- edges ---------- */
.edge-base { fill: none; stroke: var(--edge); stroke-linecap: round; transition: stroke-width 0.6s ease, opacity 0.2s; }
.edge-flow {
  fill: none; stroke: var(--series-1); stroke-linecap: round; stroke-dasharray: 1.5 12;
  animation: flow var(--dur, 1.2s) linear infinite; transition: stroke-width 0.6s ease, opacity 0.2s;
}
.edge-flow.bad { stroke: var(--critical); }
.edge-flow.idle { animation: none; opacity: 0.35; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 18; cursor: pointer; }
@keyframes flow { to { stroke-dashoffset: -13.5; } }
@media (prefers-reduced-motion: reduce) { .edge-flow { animation: none; stroke-dasharray: none; opacity: 0.8; } }

.edge-label rect { fill: var(--surface); stroke: var(--border); }
.edge-label text { fill: var(--ink-2); font: 600 11px var(--font); font-variant-numeric: tabular-nums; }
.edge-label text .err { fill: var(--critical-text); }

/* ---------- nodes ---------- */
.node-fo { overflow: visible; }
.node {
  box-sizing: border-box; width: 100%; height: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--node-shadow);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; cursor: pointer;
  font: 12px/1.3 var(--font); color: var(--ink); position: relative; overflow: hidden;
  transition: opacity 0.2s, box-shadow 0.2s, transform 0.2s;
}
.node::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--good); }
.node.warn::before { background: var(--warning); }
.node.crit::before { background: var(--critical); }
.node.down::before { background: var(--muted); }
.node:hover, .node.selected { box-shadow: 0 0 0 2px var(--series-1), var(--node-shadow); }
.node:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--series-1), var(--node-shadow); }

.node-head { display: flex; align-items: center; gap: 6px; min-width: 0; }
.node-name { font-weight: 650; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.node-status { font-size: 11px; color: var(--ink-2); white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.st { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; font-size: 9px; font-weight: 800; color: #fff; }
.st-good { background: var(--good); }
.st-warn { background: var(--warning); color: #3d2a00; }
.st-crit { background: var(--critical); }
.st-down { background: var(--muted); }

.node-pods { display: flex; align-items: center; gap: 3px; color: var(--ink-2); font-size: 11px; min-height: 12px; }
.pod { width: 9px; height: 9px; border-radius: 2px; background: var(--series-1); }
.pod.quiet { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
.pod-count { margin-left: 4px; white-space: nowrap; }

.node-main { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.node-rps { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; }
.node-rps small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.node-meta { text-align: right; color: var(--ink-2); font-size: 11px; line-height: 1.35; font-variant-numeric: tabular-nums; }
.node-meta .bad { color: var(--critical-text); font-weight: 600; }

.node-res { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px 6px; font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.node-res .track { height: 5px; border-radius: 3px; background: var(--meter-track); overflow: hidden; }
.node-res .fill { height: 100%; width: 0; border-radius: 3px; background: var(--series-1); transition: width 0.6s ease; }
.node-res .fill.warn { background: var(--warning); }
.node-res .fill.crit { background: var(--critical); }
.node-res b { font-weight: 600; color: var(--ink); text-align: right; min-width: 52px; }

/* users + external nodes */
.node.users { align-items: center; justify-content: center; text-align: center; gap: 2px; border-radius: 40px; }
.node.users::before, .node.external::before { display: none; }
.node.users .glyph { width: 26px; height: 26px; color: var(--series-1); }
.node.users .node-name { flex: none; }
.node.external { border-style: dashed; box-shadow: none; background: var(--surface); justify-content: center; gap: 3px; }
.node.external .node-name { font-weight: 600; font-size: 12px; }
.node.external .ext-meta { color: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.ext-tag { font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }

/* focus mode: hovering / selecting a node dims everything not connected to it */
#graph.focusing .node-g:not(.hl) .node { opacity: 0.35; }
#graph.focusing .edge-g:not(.hl) .edge-base,
#graph.focusing .edge-g:not(.hl) .edge-flow { opacity: 0.12; }
#graph.focusing .edge-label:not(.hl) { opacity: 0.15; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: min(560px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: -12px 0 32px rgba(0, 0, 0, 0.18);
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-title { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; min-width: 0; }
.drawer-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { overflow-y: auto; padding: 14px 18px 24px; display: grid; gap: 16px; align-content: start; }
.d-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.d-kpi { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.d-kpi .l { color: var(--muted); font-size: 11px; white-space: nowrap; }
.d-kpi .v { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-section h3 { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.d-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.d-chart { border: 1px solid var(--border); border-radius: 8px; padding: 6px 6px 2px; }
.d-chart .t { font-size: 11px; color: var(--ink-2); padding: 0 4px; }
.d-chart .chart { height: 110px; position: relative; }
.d-section .table td, .d-section .table th { padding: 6px 8px; }
.conn-dir { color: var(--muted); font-size: 11px; width: 28px; }

@media (max-width: 700px) {
  .topo-main { padding: 12px 16px 20px; }
  .strip-item { min-width: 45%; border-left: 0; border-top: 1px solid var(--grid); }
  .graph-toolbar .card-sub { display: none; }
  .legend-box { display: none; }
  .d-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .d-charts { grid-template-columns: 1fr; }
}

.drawer[hidden], .graph-empty[hidden] { display: none; }
.pod-name { display: inline-block; max-width: 190px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.drawer-body { grid-template-columns: minmax(0, 1fr); grid-auto-rows: max-content; }
.d-section { overflow-x: auto; }

@media (max-width: 700px) {
  .strip-item { min-width: 33%; padding: 8px 12px; }
  .strip-value, .strip-hero .strip-value { font-size: 17px; }
  .stage { height: 70vh; }
}

/* ---------- categorical slots (pods in the drawer charts) — validated reference palette ---------- */
:root {
  --cat-1: #2a78d6; --cat-2: #eb6834; --cat-3: #1baf7a; --cat-4: #eda100;
  --cat-5: #e87ba4; --cat-6: #008300; --cat-7: #4a3aa7; --cat-8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500;
    --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9; --cat-8: #e66767;
  }
}
:root[data-theme="dark"] {
  --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500;
  --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9; --cat-8: #e66767;
}

/* ---------- richer node cards ---------- */
.node.service { gap: 7px; padding: 10px 12px 9px 14px; }
.node-head { align-items: center; gap: 8px; }
.node-icon {
  flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-2);
}
.node-icon svg { width: 17px; height: 17px; }
.node-icon.small { width: 24px; height: 24px; }
.node-icon.role-gateway { background: var(--series-1-wash); color: var(--series-1); }
.node-icon.role-web { color: var(--series-1); }
.node-icon.role-worker { color: var(--ink-2); }
.node-icon.role-db { background: var(--series-1-wash); color: var(--series-1); }
.node-icon.role-ext { background: transparent; color: var(--muted); }
.node-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.node-title .node-name { flex: none; }
.node-sub { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node.role-gateway { background: linear-gradient(180deg, var(--series-1-wash), transparent 46px), var(--surface); }

.node-traffic { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.node-spark { width: 112px; height: 34px; flex: none; overflow: visible; }
.spark-area { fill: var(--series-1-wash); stroke: none; }
.spark-line { fill: none; stroke: var(--series-1); stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-linejoin: round; }

.node-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface-2); border-radius: 8px; padding: 5px 8px; }
.node-stats div { display: flex; flex-direction: column; min-width: 0; }
.node-stats .k { color: var(--muted); font-size: 10px; }
.node-stats b { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.node-stats .bad { color: var(--critical-text); }

.node-res { grid-template-columns: 30px 1fr 58px; gap: 5px 6px; }
.node-res .rl { color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: 0.04em; }
.stack { display: flex; gap: 2px; height: 8px; border-radius: 4px; background: var(--meter-track); overflow: hidden; }
.seg { height: 100%; background: var(--series-1); transition: width 0.6s ease; }
.seg:last-child { border-radius: 0 4px 4px 0; }
.seg.warn { background: var(--warning); }
.seg.crit { background: var(--critical); }

.node-pods { margin-top: auto; }

/* database cards */
.node.database { gap: 6px; border-radius: 12px 12px 18px 18px; }
.node.database::before { display: none; }
.node.database .node-traffic { align-items: center; }
.node.database .node-rps { font-size: 19px; }
.node.database .node-meta { text-align: right; }
.db-callers { display: flex; flex-wrap: wrap; gap: 4px; overflow: hidden; max-height: 20px; }
.caller { font-size: 10px; color: var(--ink-2); background: var(--surface-2); border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.node.external .node-head { gap: 8px; }

/* drawer additions */
.chart-tall { height: 140px !important; }
.d-section h3 .h-sub { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); margin-left: 6px; }
.pod-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }
.pod-legend .lg-item { display: inline-flex; align-items: center; gap: 6px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 11px; }
.pod-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tooltip .tt-block { height: 10px; width: 10px; border-radius: 3px; }
.tooltip .tt-total { border-top: 1px solid var(--grid); margin-top: 4px; padding-top: 4px; }
.lg-stack { display: inline-flex; gap: 2px; width: 34px; height: 8px; border-radius: 4px; overflow: hidden; background: var(--meter-track); }
.lg-stack i { background: var(--series-1); width: 8px; }
