/* ---------- themes ---------- */
:root {
  --bg: #f6f7f9;
  --sheet: #ffffff;
  --grid: #d9dde3;
  --grid-major: #c3c9d2;
  --ink: #14181f;          /* component / wire colour */
  --wire: #14181f;
  --label: #6b7382;
  --sel: #1a6dff;
  --sel-fill: rgba(26,109,255,.12);
  --accent: #1a6dff;
  --panel: #ffffff;
  --panel-2: #eef0f4;
  --fg: #1b2029;
  --muted: #7a8394;
  --border: #dfe3ea;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --sheet-shadow: inset 0 0 0 1px var(--border);
  --font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #14161a;
  --sheet: #1a1d22;
  --grid: #2b3038;
  --grid-major: #383f4a;
  --ink: #e7ebf2;
  --wire: #e7ebf2;
  --label: #98a2b3;
  --sel: #58a6ff;
  --sel-fill: rgba(88,166,255,.15);
  --accent: #58a6ff;
  --panel: #1a1d22;
  --panel-2: #23272e;
  --fg: #e7ebf2;
  --muted: #98a2b3;
  --border: #2c313a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}
[data-theme="blueprint"] {
  --bg: #08284d;
  --sheet: #0b3566;
  --grid: rgba(255,255,255,.16);
  --grid-major: rgba(255,255,255,.34);
  --ink: #eaf2ff;
  --wire: #ffffff;
  --label: #b7d3ff;
  --sel: #ffd166;
  --sel-fill: rgba(255,209,102,.16);
  --accent: #ffd166;
  --panel: #0a2f5c;
  --panel-2: #0e3d76;
  --fg: #eaf2ff;
  --muted: #9dc0ef;
  --border: rgba(255,255,255,.18);
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.25);
}

/* ---------- shell ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  display: flex; flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 650; letter-spacing: -.01em; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.group { display: flex; gap: 4px; align-items: center; }
.spacer { flex: 1 1 auto; }

.btn {
  font: inherit; font-size: 13px; color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  line-height: 1.1;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.wide { min-width: 62px; }
.btn.block { width: 100%; margin-top: 8px; }
.btn.danger:hover { border-color: #e5484d; color: #e5484d; }
.btn[aria-pressed="true"], .theme-btn.active {
  background: var(--accent); border-color: var(--accent);
  color: #fff;
}
[data-theme="blueprint"] .btn[aria-pressed="true"],
[data-theme="blueprint"] .theme-btn.active { color: #08284d; }

.layout { flex: 1 1 auto; display: flex; min-height: 0; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 226px; flex: 0 0 226px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 10px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.tool-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; flex: none; }

/* ---------- inspector (right) ---------- */
.inspector {
  width: 250px; flex: 0 0 250px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.insp-head {
  padding: 10px 12px; flex: none;
  border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
.insp-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px; }
.insp-sec { margin-bottom: 16px; }
.insp-lbl { font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.insp-note { font-size: 11px; line-height: 1.45; color: var(--muted); margin: 8px 0 0; }
.insp-empty { color: var(--muted); font-size: 12px; line-height: 1.5; }
.insp-empty p { margin: 0 0 6px; }
.insp-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.insp-actions .btn:last-child { grid-column: 1 / -1; }

.fld { display: block; font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.fld input {
  width: 100%; margin-top: 3px; font: inherit; font-size: 13px;
  padding: 5px 7px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--fg);
}
.fld input:focus { outline: 2px solid var(--sel-fill); border-color: var(--accent); }

.chk { display: flex; align-items: center; gap: 7px; font-size: 12px; margin-top: 10px; cursor: pointer; }
.chk input { accent-color: var(--accent); }

.io-block { margin-bottom: 10px; }
.io-head { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.io-row { display: flex; gap: 4px; margin-bottom: 4px; }
.io-row input {
  flex: 1 1 auto; min-width: 0; font: inherit; font-size: 12px;
  padding: 4px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--fg);
}
.io-row input:focus { outline: 2px solid var(--sel-fill); border-color: var(--accent); }
.io-empty { font-size: 11px; color: var(--muted); font-style: italic; }
.mini {
  font: inherit; font-size: 13px; line-height: 1; cursor: pointer;
  width: 24px; height: 24px; flex: none; padding: 0;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel-2); color: var(--muted);
}
.mini:hover { border-color: var(--accent); color: var(--accent); }
.tool {
  font: inherit; font-size: 11px; color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 4px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.tool .ico { font-size: 16px; line-height: 1; }
.tool:hover { border-color: var(--accent); }
.tool.active { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="blueprint"] .tool.active { color: #08284d; }

.pal-group { margin-bottom: 12px; }
.pal-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 6px 2px;
}
.pal-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.pal-item {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 6px 4px 4px; cursor: pointer; color: var(--fg);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  position: relative;
}
.pal-item:hover { border-color: var(--accent); }
.pal-item.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--sel-fill); }
.pal-item svg { width: 100%; height: 34px; display: block; }
.pal-item .nm { font-size: 10.5px; color: var(--muted); text-align: center; line-height: 1.2; }
.pal-item .key { position: absolute; top: 3px; right: 5px; font-size: 9px; color: var(--muted); font-family: var(--mono); }

.panel {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px; margin-bottom: 12px;
}
.panel-title { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 8px; }
.panel label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.panel input {
  width: 100%; margin-top: 3px; font: inherit; font-size: 13px;
  padding: 5px 7px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--panel); color: var(--fg);
}
.panel input:focus { outline: 2px solid var(--sel-fill); border-color: var(--accent); }
.sub-title { font-size: 11px; color: var(--muted); margin-bottom: 6px; }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.swatch {
  aspect-ratio: 1; border-radius: 6px; cursor: pointer; padding: 0;
  border: 1px solid var(--border);
  background: var(--sw, var(--wire));
}
.swatch.auto {
  background: linear-gradient(135deg, var(--wire) 0 50%, transparent 50% 100%), var(--panel);
}
.swatch:hover { transform: scale(1.08); }
.swatch.active { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.hint p { font-size: 11.5px; line-height: 1.45; color: var(--muted); margin: 0 0 6px; }

kbd {
  font-family: var(--mono); font-size: 10.5px;
  background: var(--panel); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 4px; padding: 1px 4px; color: var(--fg);
}

/* ---------- stage / canvas ---------- */
.stage { flex: 1 1 auto; position: relative; min-width: 0; background: var(--bg); }
#canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; touch-action: none; outline: none;
  background: var(--sheet);
  cursor: crosshair;
}
#canvas.tool-select { cursor: default; }
#canvas.panning, #canvas.pan-ready { cursor: grab; }
#canvas.panning { cursor: grabbing; }

#grid-bg { fill: url(#grid-dots); }
[data-theme="blueprint"] #grid-bg { fill: url(#grid-major); }
.grid-dot { fill: var(--grid); }
.grid-line { fill: var(--grid); }
.grid-line.major { fill: var(--grid-major); }
.hide-grid #grid-bg { fill: none; }

.sym { fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.symf { fill: var(--ink); stroke: none; }
.glyph { fill: var(--ink); font-family: var(--font); font-size: 17px; font-weight: 600; text-anchor: middle; }
.wire { fill: none; stroke: var(--wire); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.wire-hit { fill: none; stroke: transparent; stroke-width: 14; stroke-linecap: round; stroke-linejoin: round; }
.hit { fill: transparent; stroke: none; }
.lbl { fill: var(--label); font-family: var(--font); font-size: 12px; text-anchor: middle; }
.txt { fill: var(--ink); font-family: var(--font); font-size: 15px; }
.junction { fill: var(--wire); stroke: none; }
.pinlbl { fill: var(--label); font-family: var(--font); font-size: 10px; }
.boardtitle { fill: var(--ink); font-family: var(--font); font-size: 13px; font-weight: 650; text-anchor: middle; letter-spacing: .06em; }
.node-hit { fill: transparent; stroke: none; }
.node { fill: var(--sheet); stroke: var(--sel); }
.node-g.vertex { cursor: grab; }
.node-g.mid { cursor: copy; }
.node-g.mid .node { fill: transparent; opacity: .7; }
.node-g:hover .node { fill: var(--sel); opacity: 1; }
.pin { fill: var(--sheet); stroke: var(--ink); stroke-width: 1.6; }
.pin.hot { fill: var(--accent); stroke: var(--accent); }
.selbox { fill: var(--sel-fill); stroke: var(--sel); stroke-width: 1.5; stroke-dasharray: 4 3; }
.sel-stroke { stroke: var(--sel) !important; }
.marquee { fill: var(--sel-fill); stroke: var(--sel); stroke-width: 1; stroke-dasharray: 4 3; }
.preview { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.ghost { opacity: .45; }

.statusbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between;
  padding: 5px 10px; font-size: 11.5px; color: var(--muted);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border-top: 1px solid var(--border);
  pointer-events: none;
  font-family: var(--mono);
}

#inline-edit {
  position: absolute; z-index: 5; font: inherit; font-size: 15px;
  padding: 2px 6px; border: 1px solid var(--accent); border-radius: 6px;
  background: var(--panel); color: var(--fg); min-width: 120px;
}

dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 20px 22px;
  background: var(--panel); color: var(--fg); box-shadow: var(--shadow); max-width: 460px;
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin: 0 0 12px; font-size: 16px; }
dialog table { border-collapse: collapse; font-size: 13px; width: 100%; }
dialog td { padding: 3px 8px 3px 0; }
dialog td:first-child { white-space: nowrap; color: var(--muted); }
dialog .muted { color: var(--muted); font-size: 12px; }
dialog form { margin-top: 14px; text-align: right; }

@media (max-width: 1100px) {
  .inspector { width: 210px; flex-basis: 210px; }
}
@media (max-width: 860px) {
  .sidebar { width: 150px; flex-basis: 150px; }
  .pal-grid { grid-template-columns: 1fr; }
}
