/* ── Reset & tokens (cumabolat.com palette) ──────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #ffffff;
  --surface:      #ffffff;
  --panel:        #f3f6fb;
  --panel-hover:  #e4ecf4;
  --border:       #d4dde8;
  --border-light: #c5d0dc;

  --accent:       #1e3a5f;
  --accent-text:  #153252;
  --accent-glow:  rgba(30, 58, 95, 0.14);
  --accent-dim:   rgba(30, 58, 95, 0.08);

  --green:  #276749;
  --amber:  #975a16;
  --red:    #c53030;

  --text:       #0c1a2e;
  --text-dim:   #5a6d82;
  --text-faint: #8a9bb0;

  --shadow-sm: 0 1px 2px rgba(12, 26, 46, 0.05);
  --shadow-md: 0 10px 34px rgba(12, 26, 46, 0.09);

  --radius:   8px;
  --radius-lg: 12px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --topbar: 54px;
  --world-w: 4000px;
  --world-h: 3000px;
}

html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── App shell ───────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
#topbar {
  height: var(--topbar);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.logo-hex { color: var(--accent); }
.logo-text-wrap { display: flex; flex-direction: column; gap: 0; }
.logo-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.3px;
  line-height: 1.2;
}
.logo-sub {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.scenarios {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
}
.scenario-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  padding: 5px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.scenario-btn:hover { border-color: var(--accent); color: var(--accent); }
.scenario-btn.active {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--panel-hover);
}

.topbar-right { display: flex; gap: 8px; flex-shrink: 0; }
.action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 11px;
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}
.action-btn:hover { border-color: var(--text-dim); color: var(--text); background: var(--panel-hover); }
.action-btn--ghost:hover { border-color: var(--red); color: var(--red); }

/* ── Content area ────────────────────────────────────────────────────────── */
#content {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Palette ─────────────────────────────────────────────────────────────── */
#palette {
  width: 188px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px 8px 10px;
  gap: 10px;
  flex-shrink: 0;
  overflow-y: auto;
}

.panel-heading {
  font-size: 9px;
  letter-spacing: 1.8px;
  color: var(--text-dim);
  padding: 0 4px;
  text-transform: uppercase;
  font-weight: 700;
}

.palette-items { display: flex; flex-direction: column; gap: 3px; }

.palette-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 4px 4px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  transition: border-color 0.12s, background 0.12s;
  user-select: none;
}
.palette-item:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.palette-item.inspector-active {
  border-color: var(--accent);
  background: var(--panel-hover);
  box-shadow: inset 0 0 0 1px rgba(30, 58, 95, 0.1);
}

.palette-item-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 3px 5px;
  border: none;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  transition: background 0.12s;
}
.palette-item-main:hover {
  background: rgba(255, 255, 255, 0.45);
}
.palette-item-main:active {
  transform: scale(0.98);
}

.palette-help {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.palette-help:hover {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--panel-hover);
}
.palette-item.inspector-active .palette-help {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--bg);
}

.palette-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.palette-label { font-size: 11px; font-weight: 500; color: var(--text); }

.presets-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 2px;
  border-top: 1px solid var(--border);
}

.presets-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.preset-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.preset-card:hover,
.preset-card.active {
  border-color: var(--accent);
  background: var(--panel-hover);
}

.preset-card.active {
  box-shadow: inset 0 0 0 1px rgba(30, 58, 95, 0.08);
}

.preset-card__name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.preset-card__desc {
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1.45;
}

.palette-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.palette-hint-row { font-size: 9px; color: var(--text-faint); line-height: 1.8; }
kbd {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  padding: 0 3px;
  font-family: var(--font);
  font-size: 9px;
  color: var(--text-dim);
}

/* ── Canvas wrapper ──────────────────────────────────────────────────────── */
#canvas-wrapper {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

#canvas-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

#canvas-viewport.is-panning {
  cursor: grabbing;
}

#canvas-viewport.can-pan {
  cursor: grab;
}

#canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--world-w);
  height: var(--world-h);
  transform-origin: 0 0;
  will-change: transform;
}

/* Dot-grid background */
#canvas-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 90% at 0% 0%, #d6e4f0 0%, transparent 50%),
    radial-gradient(circle, #d4dde8 1px, transparent 1px);
  background-size: auto, 28px 28px;
  pointer-events: none;
  z-index: 0;
}

/* SVG for connections */
#connections-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

/* Nodes layer */
#nodes-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.canvas-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.canvas-control-btn {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.canvas-control-btn--text {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.canvas-control-btn:hover {
  border-color: var(--border);
  color: var(--accent-text);
  background: var(--panel-hover);
}

.canvas-control-label {
  min-width: 44px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
  user-select: none;
}

/* Empty-state hint */
#canvas-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
  z-index: 5;
  color: var(--text-faint);
}
#canvas-hint span {
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.5px;
  border: 1px dashed var(--border);
  padding: 10px 20px;
  border-radius: var(--radius);
}
#canvas-hint.hidden { display: none; }

/* ── Node cards ──────────────────────────────────────────────────────────── */
.node {
  position: absolute;
  width: 158px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  cursor: grab;
  user-select: none;
  pointer-events: all;
  transition: border-color 0.15s, box-shadow 0.15s;
  will-change: transform;
}
.node:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-md);
}
.node.dragging {
  cursor: grabbing;
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-md);
  z-index: 1000;
}
.node.connect-target {
  border-color: var(--green);
  box-shadow: 0 0 0 2px var(--green);
}
.node.node-critical {
  animation: critical-pulse 1.2s infinite;
}
.node--inspected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-md);
  z-index: 50;
}
@keyframes critical-pulse {
  0%, 100% { box-shadow: 0 0 0 1px var(--red), 0 0 0 0 rgba(197,48,48,0.3); }
  50%       { box-shadow: 0 0 0 1px var(--red), 0 0 6px 4px rgba(197,48,48,0.0); }
}

.node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 7px;
}
.node-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.node-meta { flex: 1; min-width: 0; }
.node-label { font-size: 12px; font-weight: 600; line-height: 1.2; }
.node-desc  { font-size: 9px;  color: var(--text-faint); margin-top: 2px; }

.node-count-row {
  display: flex;
  align-items: center;
  padding: 0 10px 8px;
  gap: 4px;
}
.count-label { font-size: 9px; color: var(--text-faint); flex: 1; letter-spacing: 0.5px; }
.count-ctrl  { display: flex; align-items: center; gap: 3px; }
.count-btn {
  width: 19px;
  height: 19px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 15px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: border-color 0.1s, color 0.1s;
}
.count-btn:hover { border-color: var(--accent); color: var(--accent); }
.count-value { font-size: 11px; color: var(--text); min-width: 22px; text-align: center; }

/* Utilisation bar */
.node-util-bar {
  height: 3px;
  background: var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow: hidden;
}
.node-util-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: inherit;
  transition: width 0.45s ease, background-color 0.45s ease;
}

/* Output handle */
.node-handle {
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--panel);
  cursor: crosshair;
  z-index: 10;
  transition: transform 0.12s, background 0.12s;
}
.node-handle:hover {
  background: var(--accent);
  transform: translateY(-50%) scale(1.4);
  box-shadow: 0 0 6px var(--accent);
}

/* Delete button */
.node-delete {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  line-height: 1;
  padding: 0;
  font-family: var(--font);
}
.node:hover .node-delete { display: flex; }
.node-delete:hover { background: var(--red); border-color: var(--red); color: #fff; }

/* ── SVG edges ───────────────────────────────────────────────────────────── */
.edge-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  opacity: 0.45;
  marker-end: url(#arrow);
  transition: opacity 0.15s;
}
.edge-group:hover .edge-path { opacity: 0.9; }

.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  cursor: pointer;
  pointer-events: stroke;
}

.ghost-line {
  fill: none;
  stroke: var(--green);
  stroke-width: 1.5;
  stroke-dasharray: 7 4;
  opacity: 0.7;
  pointer-events: none;
}

/* Animated packet dots on edges */
.packet {
  fill: var(--accent);
  filter: drop-shadow(0 0 4px var(--accent));
}

/* ── Metrics panel ───────────────────────────────────────────────────────── */
#metrics-panel {
  width: 280px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  overflow-y: auto;
}

/* Health badge */
.health-badge {
  text-align: center;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  border: 1px solid;
  transition: color 0.3s, border-color 0.3s, background 0.3s;
}
.health-healthy  { color: var(--green); border-color: var(--green); background: rgba(39,103,73,0.08); }
.health-degraded { color: var(--amber); border-color: var(--amber); background: rgba(151,90,22,0.08); }
.health-critical {
  color: var(--red); border-color: var(--red); background: rgba(197,48,48,0.08);
  animation: health-pulse 1.2s infinite;
}
.health-unknown  { color: var(--text-faint); border-color: var(--text-faint); background: transparent; }

@keyframes health-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(197,48,48,0.25); }
  50%       { box-shadow: 0 0 0 4px rgba(197,48,48,0);  }
}

/* Metric cards */
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px 11px;
}
.metric-card--hero { padding: 12px 14px 14px; }

.metric-label {
  font-size: 9px;
  color: var(--text-faint);
  letter-spacing: 1.8px;
  margin-bottom: 5px;
}
.metric-value-row { display: flex; align-items: baseline; gap: 5px; }
.metric-num {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
  transition: color 0.4s;
}
.metric-card--hero .metric-num { font-size: 34px; }
.metric-demand {
  font-size: 10px;
  color: var(--amber);
  margin-top: 4px;
  letter-spacing: 0.3px;
}
.metric-demand.hidden { display: none; }
.metric-demand-val { font-weight: 600; }

.metric-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.metric-grid-2 .metric-num { font-size: 20px; }

/* Bottleneck */
.bottleneck-box {
  background: rgba(197,48,48,0.05);
  border: 1px solid rgba(197,48,48,0.22);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: none;
  animation: fade-in 0.25s ease;
}
.bottleneck-box.visible { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.bottleneck-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 9px;
  color: var(--red);
  letter-spacing: 1.8px;
  margin-bottom: 7px;
}
.bottleneck-name { font-size: 14px; font-weight: 600; color: var(--red); margin-bottom: 3px; }
.bottleneck-desc { font-size: 10px; color: var(--text-dim); line-height: 1.5; }

/* Scenario info */
.scenario-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
}
.scenario-text { font-size: 11px; color: var(--accent-text); font-weight: 600; margin-top: 5px; }

/* Inspector */
.inspector-section {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.inspector-hint {
  font-size: 9px;
  color: var(--text-faint);
  line-height: 1.45;
  padding: 0 2px;
}

.inspector-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 10px;
  text-align: center;
  color: var(--text-faint);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.inspector-empty svg { opacity: 0.45; }

.inspector-empty p {
  font-size: 10px;
  line-height: 1.55;
  color: var(--text-dim);
}

.inspector-empty[hidden],
.inspector-content[hidden] {
  display: none;
}

.inspector-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.inspector-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.inspector-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.inspector-header-text { min-width: 0; }

.inspector-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.inspector-tagline {
  font-size: 10px;
  color: var(--accent-text);
  font-weight: 500;
  margin-top: 2px;
  line-height: 1.35;
}

.inspector-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 42vh;
  overflow-y: auto;
  padding-right: 2px;
}

.inspector-block {
  padding: 9px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.inspector-block--sim {
  border-left: 3px solid var(--accent);
  background: var(--panel-hover);
}

.inspector-block--interview {
  border-left: 3px solid var(--amber);
  background: rgba(151, 90, 22, 0.04);
}

.inspector-block-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.inspector-text {
  font-size: 10px;
  color: var(--text);
  line-height: 1.6;
}

.inspector-questions {
  margin: 0;
  padding: 0 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.inspector-questions li {
  font-size: 10px;
  color: var(--text);
  line-height: 1.55;
  padding-left: 2px;
}

.inspector-questions li::marker {
  color: var(--amber);
}

.inspector-add-btn {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.inspector-add-btn:hover {
  background: var(--accent-text);
}

.inspector-add-btn:active {
  transform: scale(0.98);
}

.inspector-add-btn[hidden],
.inspector-on-canvas[hidden] {
  display: none;
}

.inspector-on-canvas {
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.45;
  padding: 0 4px;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Topbar: wrap scenarios onto second row, make them scrollable */
  #topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px 6px;
    gap: 8px;
  }

  .logo-sub { display: none; }

  .scenarios {
    order: 3;
    flex: 0 0 100%;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
  }
  .scenarios::-webkit-scrollbar { display: none; }

  .topbar-right { margin-left: auto; }

  /* Content area: canvas full-width, extra bottom padding for tab bar */
  #content {
    padding-bottom: 56px;
  }

  /* Palette: fixed bottom sheet */
  #palette {
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    z-index: 200;
    width: 100%;
    max-height: 66vh;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-md);
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    overflow-y: auto;
  }
  #palette::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    margin: 10px auto 4px;
    flex-shrink: 0;
  }
  #palette.mobile-open { transform: translateY(0); }

  .palette-items {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .palette-footer { display: none; }

  /* Metrics panel: fixed bottom sheet */
  #metrics-panel {
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    z-index: 200;
    width: 100%;
    max-height: 80vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-md);
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    overflow-y: auto;
  }
  #metrics-panel::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    margin: 10px auto 4px;
    flex-shrink: 0;
  }
  #metrics-panel.mobile-open { transform: translateY(0); }

  /* Let the sheet scroll instead of a fixed inner height */
  .inspector-body { max-height: none; }

  /* Canvas controls above tab bar */
  .canvas-controls { bottom: 72px; }

  /* Enlarge touch targets on nodes */
  .node-handle {
    width: 22px;
    height: 22px;
    right: -11px;
  }

  .node-delete {
    display: flex !important;
    width: 26px;
    height: 26px;
  }

  .count-btn {
    width: 26px;
    height: 26px;
  }
}

/* ── Mobile tab bar ──────────────────────────────────────────────────────── */
.mobile-tabs {
  display: none;
}

@media (max-width: 768px) {
  .mobile-tabs {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(12,26,46,0.06);
    z-index: 300;
  }

  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: transparent;
    color: var(--text-faint);
    font-family: var(--font);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-tab.active {
    color: var(--accent);
  }

  .mobile-tab svg {
    transition: stroke 0.15s;
  }
}

/* ── Mobile overlay backdrop ─────────────────────────────────────────────── */
.mobile-overlay {
  display: none;
}

@media (max-width: 768px) {
  .mobile-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 199;
    background: rgba(12, 26, 46, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
  }

  .mobile-overlay.active {
    opacity: 1;
    pointer-events: all;
  }
}

/* ── Desktop: hide mobile-only elements ──────────────────────────────────── */
@media (min-width: 769px) {
  .mobile-tabs    { display: none !important; }
  .mobile-overlay { display: none !important; }
}
