:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #657081;
  --paper: #f7f8f5;
  --panel: #ffffff;
  --edge: #8c96a6;
  --edge-soft: rgba(95, 107, 124, 0.18);
  --edge-pod: rgba(116, 95, 148, 0.09);
  --grid: rgba(32, 39, 50, 0.075);
  --normal: #427b8f;
  --balanced-ports: #df8d30;
  --optical-heavy: #d9534f;
  --gpu: #427b8f;
  --switch: #59636f;
  --switch-face: #eef2f4;
  --rubin-gpu: #2c8f68;
  --vera-cpu: #4a89b8;
  --lpu: #c04a8f;
  --fabric: #d09a2d;
  --source: #247a5c;
  --target: #7c4db4;
  --route-short: #0e9f6e;
  --near: #14a6a6;
  --near2: #d6a229;
  --shadow: 0 18px 46px rgba(34, 40, 49, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 12%, rgba(36, 122, 92, 0.12), transparent 28%),
    linear-gradient(135deg, #fbfaf7 0%, #edf4f2 50%, #f6f2ee 100%);
  color: var(--ink);
}

button {
  border: 1px solid rgba(30, 39, 52, 0.14);
  background: #fff;
  color: var(--ink);
  height: 34px;
  min-width: 34px;
  border-radius: 7px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(30, 39, 52, 0.08);
}

button:hover {
  background: #f3f6f5;
  border-color: rgba(30, 39, 52, 0.28);
}

.text-button {
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
}

.shell {
  --camera-pan-right: calc(360px + 16px + 16px + 14px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
  transition: grid-template-columns 180ms ease, gap 180ms ease;
}

.shell.side-panel-collapsed {
  --camera-pan-right: calc(42px + 8px + 16px + 14px);
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
}

.workspace,
.side-panel {
  border: 1px solid rgba(30, 39, 52, 0.12);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(30, 39, 52, 0.1);
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 4px;
  color: #577066;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(20px, 2.1vw, 30px);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}

.topology-tab {
  height: 30px;
  padding: 0 12px;
  min-width: auto;
  border-radius: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.topology-tab.active {
  border-color: rgba(36, 122, 92, 0.36);
  background: #eaf6f1;
  color: #1f604b;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  overflow: hidden;
}

.slice-selector {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 4;
  width: 70px;
  border: 1px solid rgba(30, 39, 52, 0.14);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 28px rgba(30, 39, 52, 0.12);
  border-radius: 8px;
  padding: 9px 8px;
  backdrop-filter: blur(12px);
}

.slice-selector[hidden] {
  display: none;
}

.fabric-selector {
  width: 122px;
}

.torus-selector {
  width: 92px;
}

.slice-selector strong {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
}

.slice-buttons {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.slice-button {
  width: 100%;
  height: 26px;
  min-width: 0;
  padding: 0;
  border-radius: 7px;
  color: #324052;
  font-size: 12px;
  font-weight: 850;
}

.slice-button.active {
  border-color: rgba(36, 122, 92, 0.42);
  background: #e6f4ef;
  color: #1d5f49;
}

.fabric-button {
  padding: 0 7px;
  font-size: 11px;
}

.slice-stats {
  display: grid;
  gap: 3px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid rgba(30, 39, 52, 0.1);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
  text-align: center;
}

.slice-stats span {
  display: block;
}

.coordinate-panel {
  position: absolute;
  right: 18px;
  top: 14px;
  z-index: 4;
  width: 214px;
  border: 1px solid rgba(30, 39, 52, 0.14);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 28px rgba(30, 39, 52, 0.12);
  border-radius: 8px;
  padding: 10px 12px;
  color: #324052;
  backdrop-filter: blur(12px);
}

.coordinate-panel[hidden] {
  display: none;
}

.coordinate-panel strong {
  display: block;
  margin-bottom: 8px;
  color: #1f2933;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
}

.coord-grid {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 5px 8px;
  align-items: center;
  font-size: 11px;
  line-height: 1.25;
}

.coord-axis {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}

.coord-axis.x {
  background: #276f9f;
}

.coord-axis.y {
  background: #2b7a54;
}

.coord-axis.z {
  background: #b66a3c;
}

.coordinate-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.topology-3d {
  width: 100%;
  height: 100%;
  min-height: 680px;
  display: block;
  position: relative;
  touch-action: none;
  cursor: grab;
}

.topology-3d canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.external-topology-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #090a0a;
}

body.external-topology-active .shell {
  grid-template-columns: minmax(0, 1fr);
}

body.external-topology-active .side-panel,
body.external-topology-active .hop-lane-panel,
body.external-topology-active .camera-pan-controls {
  display: none;
}

body.external-topology-active .topbar .toolbar {
  display: none;
}

body.external-topology-active .workspace {
  min-height: calc(100vh - 32px);
}

body.external-topology-active .topology-3d {
  min-height: calc(100vh - 128px);
}

.topology-3d.dragging {
  cursor: grabbing;
}

.topology-3d.picking {
  cursor: pointer;
}

.camera-pan-controls {
  position: fixed;
  right: var(--camera-pan-right);
  bottom: 18px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 34px);
  grid-template-rows: repeat(3, 34px);
  gap: 5px;
  padding: 8px;
  border: 1px solid rgba(30, 39, 52, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 12px 28px rgba(30, 39, 52, 0.14);
  backdrop-filter: blur(12px);
}

.pan-button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 7px;
  color: #334155;
  font-size: 16px;
  line-height: 1;
}

.pan-button:active {
  transform: translateY(1px);
}

.pan-button.up {
  grid-column: 2;
  grid-row: 1;
}

.pan-button.left {
  grid-column: 1;
  grid-row: 2;
}

.pan-button.right {
  grid-column: 3;
  grid-row: 2;
}

.pan-button.down {
  grid-column: 2;
  grid-row: 3;
}

.group-outline {
  fill: rgba(255, 255, 255, 0.56);
  stroke: rgba(36, 47, 61, 0.16);
  stroke-width: 1;
}

.group-label {
  fill: rgba(24, 32, 42, 0.58);
  font-size: 11px;
  font-weight: 800;
  pointer-events: none;
  text-anchor: middle;
}

.board-ring {
  fill: none;
  stroke: rgba(62, 85, 92, 0.14);
  stroke-width: 1;
  pointer-events: none;
}

.edge {
  stroke: var(--edge-soft);
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.edge.board {
  stroke-width: 1.05;
}

.edge.group {
  stroke: rgba(223, 141, 48, 0.16);
  stroke-width: 1.1;
}

.edge.pod {
  stroke: var(--edge-pod);
  stroke-width: 0.7;
}

.edge.nvlink {
  stroke: rgba(66, 123, 143, 0.12);
  stroke-width: 0.75;
}

.edge.nvl_trunk {
  stroke: rgba(214, 162, 41, 0.38);
  stroke-width: 1.35;
}

.edge.near {
  stroke: rgba(20, 166, 166, 0.54);
  stroke-width: 1.8;
}

.route-edge {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.route-edge.shortest {
  stroke: var(--route-short);
  stroke-width: 4.2;
}

.node {
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 1.2;
  transition: r 120ms ease;
}

.node.normal {
  fill: var(--normal);
}

.node.balancedPorts {
  fill: var(--balanced-ports);
}

.node.opticalHeavyPorts {
  fill: var(--optical-heavy);
}

.node.gpu {
  fill: var(--gpu);
}

.switch-node {
  cursor: pointer;
}

.switch-node rect {
  fill: var(--switch-face);
  stroke: var(--switch);
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
}

.switch-node text {
  fill: var(--switch);
  font-size: 8px;
  font-weight: 850;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
}

.switch-node.near1 rect {
  fill: #e1f5f4;
  stroke: var(--near);
  stroke-width: 2;
}

.switch-node.hovered rect,
.switch-node.source rect,
.switch-node.target rect,
.switch-node.route-node rect {
  stroke: #111827;
  stroke-width: 2.2;
}

.switch-node.source rect {
  fill: #eafff6;
  stroke: var(--source);
}

.switch-node.target rect {
  fill: #fbf7ff;
  stroke: var(--target);
}

.node.near2 {
  fill: var(--near2);
  r: 4.6;
}

.node.near1 {
  fill: var(--near);
  r: 5.3;
}

.node.hovered {
  fill: #1f2937;
  r: 7;
  stroke: #fff;
  stroke-width: 2;
}

.node.source {
  fill: var(--source);
  r: 7.2;
  stroke: #eafff6;
  stroke-width: 2.2;
}

.node.target {
  fill: var(--target);
  r: 7.2;
  stroke: #fbf7ff;
  stroke-width: 2.2;
}

.node.route-node {
  stroke: #111827;
  stroke-width: 1.7;
}

.tooltip {
  position: absolute;
  z-index: 5;
  max-width: min(310px, calc(100vw - 42px));
  padding: 12px 13px;
  border: 1px solid rgba(30, 39, 52, 0.16);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 34px rgba(30, 39, 52, 0.18);
  color: var(--ink);
  border-radius: 8px;
  pointer-events: none;
  backdrop-filter: blur(12px);
}

.tooltip strong {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
}

.tooltip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.hop-lane-panel {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 4;
  width: min(320px, calc(100% - 28px));
  max-height: 48px;
  overflow: hidden;
  border: 1px solid rgba(30, 39, 52, 0.14);
  background: rgba(255, 255, 255, 0.91);
  box-shadow: 0 12px 28px rgba(30, 39, 52, 0.14);
  border-radius: 8px;
  padding: 10px 12px;
  backdrop-filter: blur(12px);
  transition: width 160ms ease, max-height 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.hop-lane-panel.expanded,
.hop-lane-panel:hover,
.hop-lane-panel:focus-within {
  width: min(520px, calc(100% - 28px));
  max-height: min(38%, 360px);
  overflow: auto;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 18px 38px rgba(30, 39, 52, 0.18);
}

.hop-lane-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 0;
}

.hop-lane-panel.expanded .hop-lane-head,
.hop-lane-panel:hover .hop-lane-head,
.hop-lane-panel:focus-within .hop-lane-head {
  margin-bottom: 8px;
}

.hop-lane-head strong {
  font-size: 13px;
}

.hop-lane-head span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.hop-lane-content {
  color: #2d3540;
  font-size: 12px;
  line-height: 1.45;
  display: none;
}

.hop-lane-panel.expanded .hop-lane-content,
.hop-lane-panel:hover .hop-lane-content,
.hop-lane-panel:focus-within .hop-lane-content {
  display: block;
}

.hop-lane-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.hop-lane-table th,
.hop-lane-table td {
  border-top: 1px solid rgba(30, 39, 52, 0.09);
  padding: 6px 5px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.hop-lane-table th {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}

.hop-lane-table td {
  font-size: 11px;
}

.lane-note {
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  overflow: auto;
  padding: 14px;
  position: relative;
  transition: padding 180ms ease, background-color 180ms ease;
}

.side-panel-body {
  display: contents;
}

.side-panel-toggle {
  position: sticky;
  top: 0;
  z-index: 6;
  align-self: flex-start;
  width: 32px;
  min-width: 32px;
  height: 32px;
  margin: -4px 0 -2px auto;
  border-color: rgba(30, 39, 52, 0.18);
  background: rgba(255, 255, 255, 0.94);
  color: #334155;
  font-size: 19px;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(30, 39, 52, 0.12);
  backdrop-filter: blur(10px);
}

.side-panel-toggle:hover {
  background: #f5f8f7;
}

.shell.side-panel-collapsed .side-panel {
  align-items: center;
  overflow: hidden;
  padding: 10px 5px;
}

.shell.side-panel-collapsed .side-panel-body {
  display: none;
}

.shell.side-panel-collapsed .side-panel-toggle {
  align-self: center;
  margin: 0;
}

.status-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  min-width: 0;
  border: 1px solid rgba(30, 39, 52, 0.1);
  background: #fbfcfa;
  border-radius: 8px;
  padding: 10px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  line-height: 1.1;
}

.selection-panel,
.routes-panel,
.hover-panel,
.legend-panel {
  border-top: 1px solid rgba(30, 39, 52, 0.12);
  padding-top: 14px;
}

.pick-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 11px;
}

.pick-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b8c0c9;
}

.pick-row.source .pick-dot {
  background: var(--source);
}

.pick-row.target .pick-dot {
  background: var(--target);
}

.pick-row p {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.pick-row strong {
  display: block;
  min-width: 0;
  margin-top: 2px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#routeSummary {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.routes-list {
  display: grid;
  gap: 9px;
  margin-top: 11px;
}

.route-card {
  border: 1px solid rgba(30, 39, 52, 0.1);
  background: #fbfcfa;
  border-left: 5px solid var(--route-short);
  border-radius: 8px;
  padding: 10px 10px 9px;
}

.route-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 800;
}

.route-title span:last-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.route-path {
  color: #2d3540;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.route-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

#nodeDetails {
  display: grid;
  gap: 8px;
  margin: 11px 0 0;
}

#nodeDetails div {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 8px;
  font-size: 12px;
}

#nodeDetails dt {
  color: var(--muted);
  font-weight: 750;
}

#nodeDetails dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.legend-panel {
  display: grid;
  gap: 8px;
}

.legend-line {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #2d3540;
  font-size: 12px;
}

.chip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid #fff;
  flex: 0 0 auto;
}

.chip.normal {
  background: var(--normal);
}

.chip.balanced-ports {
  background: var(--balanced-ports);
}

.chip.optical-heavy {
  background: var(--optical-heavy);
}

.chip.gpu {
  background: var(--gpu);
}

.chip.switch {
  width: 14px;
  height: 9px;
  border-radius: 3px;
  background: var(--switch-face);
  border-color: var(--switch);
}

.chip.spine-switch {
  width: 14px;
  height: 9px;
  border-radius: 3px;
  background: #f3ecfb;
  border-color: var(--target);
}

.chip.rubin-gpu {
  background: var(--rubin-gpu);
}

.chip.vera-cpu {
  background: var(--vera-cpu);
}

.chip.lpu {
  background: var(--lpu);
}

.chip.fabric {
  width: 14px;
  height: 9px;
  border-radius: 3px;
  background: #fff7e3;
  border-color: var(--fabric);
}

.line {
  width: 26px;
  height: 0;
  border-top: 3px solid rgba(95, 107, 124, 0.25);
  flex: 0 0 auto;
}

.line.group {
  border-top-color: rgba(223, 141, 48, 0.5);
}

.line.copper {
  border-top-color: rgba(182, 106, 60, 0.74);
}

.line.pod {
  border-top-color: rgba(116, 95, 148, 0.42);
}

.line.optical {
  border-top-color: rgba(47, 125, 193, 0.82);
}

.line.optical-fabric {
  border-top-color: rgba(22, 90, 159, 0.88);
  border-top-width: 5px;
}

.line.nvlink {
  border-top-color: rgba(66, 123, 143, 0.5);
}

.line.nvl_trunk {
  border-top-color: rgba(214, 162, 41, 0.75);
}

.line.nvl_leaf {
  border-top-color: rgba(66, 123, 143, 0.42);
}

.line.nvl_spine {
  border-top-color: rgba(124, 77, 180, 0.65);
  border-top-width: 4px;
}

.line.rubin_nvlink {
  border-top-color: rgba(44, 143, 104, 0.58);
}

.line.lpu_c2c {
  border-top-color: rgba(192, 74, 143, 0.55);
}

.line.rubin_lpu {
  border-top-color: rgba(82, 132, 189, 0.62);
}

.source-note {
  margin-top: auto;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

@media (max-width: 980px) {
  .shell {
    --camera-pan-right: 22px;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(640px, 72vh) auto;
  }

  .shell.side-panel-collapsed {
    --camera-pan-right: 22px;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(640px, 72vh) 42px;
  }

  .side-panel {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .shell {
    --camera-pan-right: 14px;
    padding: 8px;
    gap: 8px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .status-panel {
    grid-template-columns: 1fr;
  }
}
