:root {
  --bg: #14171c;
  --panel: #1c2027;
  --panel-2: #232833;
  --line: #313845;
  --text: #dde3ec;
  --text-dim: #8a93a3;
  --accent: #4a8df0;
  --danger: #e05c5c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Header ---------- */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.logo {
  font-weight: 800;
  letter-spacing: 3px;
  font-size: 16px;
}
.logo span { color: var(--accent); }

#setup-name {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  width: 220px;
}

header button, header select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
header button:hover { border-color: var(--accent); }
header button.danger:hover { border-color: var(--danger); color: var(--danger); }

.spacer { flex: 1; }
.hint { color: var(--text-dim); font-size: 12px; }

/* ---------- Main layout ---------- */
main { display: flex; flex: 1; min-height: 0; }

/* ---------- Drawer ---------- */
#drawer {
  width: 250px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  transition: width 0.18s ease;
  flex-shrink: 0;
}
#drawer.collapsed { width: 0; border-right: none; overflow: hidden; }

#drawer-toggle {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: none;
  color: var(--text-dim);
  border-radius: 0 8px 8px 0;
  padding: 14px 4px;
  cursor: pointer;
  font-size: 12px;
}
#drawer-toggle:hover { color: var(--text); border-color: var(--accent); }

.drawer-cat {
  padding: 10px 12px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 3px 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: grab;
  user-select: none;
}
.drawer-item:hover { border-color: var(--accent); }
.drawer-item.placed { opacity: 0.38; }
.drawer-item .thumb {
  flex-shrink: 0;
  border-radius: 3px;
  border: 1px solid #4a5261;
}
.drawer-item .meta { min-width: 0; }
.drawer-item .name { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-item .dims { font-size: 11px; color: var(--text-dim); }

/* ---------- Canvas ---------- */
#canvas-wrap { position: relative; flex: 1; min-width: 0; }
svg#canvas { width: 100%; height: 100%; display: block; background: var(--bg); cursor: default; }
/* device silkscreen, drawer, legend: never text-selectable */
svg#canvas, #drawer, #legend, #scale-note, .hint { user-select: none; -webkit-user-select: none; }
svg#canvas.panning { cursor: grabbing; }

.gear-rect { stroke: #4a5261; stroke-width: 1.2; rx: 6; }
.gear-group { cursor: move; }
.gear-group.selected .gear-rect { stroke: var(--accent); stroke-width: 2.5; }
.gear-name {
  fill: #cdd5e0;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  letter-spacing: 1px;
}
.gear-sub { fill: #79828f; text-anchor: middle; pointer-events: none; }

.port { cursor: crosshair; stroke-width: 1.6; }
.port.dir-in { fill: var(--bg); }
.port.valid-target { stroke-width: 4; }
.port.dimmed { opacity: 0.25; }
.port.snap-glow { stroke-width: 6; }
.port-hit { cursor: crosshair; }

/* Vignelli subway style: solid lines, no motion, rounded octilinear bends */
.cable { fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.cable-hit { fill: none; stroke: transparent; stroke-width: 20; cursor: pointer; }
/* selection = light-grey casing 2mm each side (1972 aesthetic — no glow) */
.cable-casing { fill: none; stroke: #c9ced6; stroke-width: 13; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.cable.mismatch { stroke-dasharray: 4 7; opacity: 0.9; }
/* 2-channel run: dark center stripe turns the pipe into a double line.
   The "cut" gauge — stripe and arrow knockouts — is 1/3 of the cable width. */
.cable-stripe { fill: none; stroke: var(--bg); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
/* cable being connected: solid at half opacity (not dashed) */
.temp-cable { fill: none; stroke-width: 9; opacity: 0.5; stroke-linecap: round; pointer-events: none; }

/* ---------- Tooltip / toast / legend ---------- */
#tooltip {
  position: absolute;
  display: none;
  background: #0d0f13;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  pointer-events: none;
  z-index: 30;
  max-width: 260px;
}
#tooltip .t-type { color: var(--text-dim); }

#toast {
  position: absolute;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: #2a1d1d;
  border: 1px solid var(--danger);
  color: #f0c0c0;
  border-radius: 8px;
  padding: 8px 16px;
  display: none;
  z-index: 30;
  font-size: 13px;
}
#toast.ok { background: #1d2a20; border-color: #3fa06a; color: #bfe8cd; }

#legend {
  position: absolute;
  bottom: 10px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: rgba(20, 23, 28, 0.85);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  z-index: 20;
  color: var(--text-dim);
}
.legend-row { display: flex; gap: 14px; }
.legend-item { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-hint { font-size: 11px; color: var(--text-dim); opacity: 0.85; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

#scale-note {
  position: absolute;
  top: 10px;
  right: 14px;
  color: var(--text-dim);
  font-size: 12px;
  z-index: 20;
  background: rgba(20, 23, 28, 0.85);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
}
