/* Transit Power Map: full-height app. Top bar, wiring board (left), details panel (right). */
:root {
  color-scheme: dark;
  --bg: #0A1324;
  --board: #0E192D;
  --tile: #142239;
  --tile-hi: #1B2D4B;
  --line: #24365A;
  --fg: #E5ECF6;
  --muted: #8C9CB6;
  --dc: #D9822B;
  --dc-neg: #5E6F8C;
  --v24: #F0B33E;
  --ac: #45BDF2;
  --data: #8592AA;
  --sig: #5CC98A;
  --warn: #F2A93B;
  --warn-bg: #2A2012;
  --pin: #E0559B;
  --font-display: "IBM Plex Sans Condensed", "Arial Narrow", "Segoe UI", sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.5; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ac); outline-offset: 2px; }

.app { height: 100vh; height: 100dvh; min-height: 560px; display: grid; grid-template-rows: auto minmax(0, 1fr); }

/* ---------- top bar */
.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px;
  padding: 12px var(--gutter-r) 12px var(--gutter-l); border-bottom: 1px solid var(--line);
}
.kicker { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 2px; }
h1 { font-family: var(--font-display); font-weight: 700; font-size: 26px; line-height: 1.1; margin: 0; letter-spacing: 0.01em; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill {
  font-size: 13px; font-weight: 500; background: var(--tile); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; min-height: 34px; display: inline-flex; align-items: center; gap: 8px;
}
.pill:hover { background: var(--tile-hi); }
.pill[aria-pressed="false"] { color: var(--muted); }
.pill[aria-pressed="false"] .swatch { opacity: 0.35; }
.pill.toggle[aria-pressed="true"] { border-color: var(--ac); background: #12304A; }
.swatch { width: 20px; height: 0; border-top: 3px dashed var(--dc); }
.swatch.ac { border-top-color: var(--ac); }
.swatch.ctl { border-top: 3px dotted var(--data); }
.ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.zoom { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; background: var(--tile); overflow: hidden; }
.zoom button { background: none; border: 0; min-width: 36px; min-height: 34px; padding: 0 10px; font-size: 15px; }
.zoom button:hover { background: var(--tile-hi); }
.zoom #zoomLabel { font: 500 12px var(--font-mono); color: var(--muted); min-width: 46px; text-align: center; }

/* ---------- main area */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 390px; min-height: 0; }
.stage { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-width: 0; min-height: 0; border-right: 1px solid var(--line); }
.board { overflow: auto; background: var(--board); position: relative; overscroll-behavior: contain; }
.board.panning { cursor: grabbing; }
.board svg { display: block; }
.legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--muted);
  padding: 9px var(--gutter-r) 10px var(--gutter-l); border-top: 1px solid var(--line); background: var(--bg);
}
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.lg { width: 26px; height: 0; border-top: 3px dashed var(--dc); }
.lg.neg { border-top-color: var(--dc-neg); }
.lg.v24 { border-top-color: var(--v24); }
.lg.ac { border-top-color: var(--ac); }
.lg.data { border-top: 3px dotted var(--data); }
.lg.sig { border-top: 3px dotted var(--sig); }
.lg.box { width: 22px; height: 12px; border: 1.5px dashed var(--muted); border-radius: 3px; }
.lg.chipS, .lg.chipC { width: 22px; height: 12px; border: 1.5px solid var(--ac); background: #13304C; border-radius: 3px; }
.lg.chipC { border-color: var(--v24); background: #2A2614; }

/* ---------- svg board */
.grid { fill: url(#dots); opacity: 0; transition: opacity .2s; pointer-events: none; }
svg.editing .grid { opacity: 1; }
#dots circle { fill: #2A3E63; }
.node { cursor: pointer; outline: none; }
svg.editing .node { cursor: grab; touch-action: none; }
svg.editing .node.dragging { cursor: grabbing; }
.node rect.bg { fill: var(--tile); stroke: var(--line); stroke-width: 1.5; transition: fill .15s, stroke .15s; }
.node rect.bg.shelly { stroke: var(--ac); fill: #13304C; }
.node rect.bg.conv { stroke: var(--v24); fill: #2A2614; }
.node rect.bg.thermo { stroke: var(--warn); fill: #2A2012; }
.node:hover rect.bg.shelly, .node:hover rect.bg.conv, .node:hover rect.bg.thermo { fill: var(--tile-hi); }
.node.dash rect.bg { stroke-dasharray: 7 5; stroke: var(--muted); }
.node:hover rect.bg { fill: var(--tile-hi); }
.node.sel rect.bg, .node:focus-visible rect.bg { stroke: var(--ac); stroke-width: 2.5; fill: var(--tile-hi); stroke-dasharray: none; }
.node.dragging rect.bg { stroke: var(--ac); stroke-width: 2.5; fill: var(--tile-hi); filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.55)); }
.node .hit { fill: transparent; }
svg.editing { cursor: crosshair; }
.board.space-pan svg, .board.space-pan .node { cursor: grab; }
.marquee { fill: rgba(69, 189, 242, 0.08); stroke: var(--ac); stroke-width: 1.5; stroke-dasharray: 6 4; pointer-events: none; vector-effect: non-scaling-stroke; }
.node.msel rect.bg { stroke: var(--ac); stroke-width: 2.5; stroke-dasharray: 7 4; fill: var(--tile-hi); }
.node.chip.msel .chipbg { stroke: var(--fg); stroke-width: 2.5; stroke-dasharray: 4 3; }
.node.dot.msel .dotn { stroke: var(--ac); stroke-width: 3.5; }
.node.chassis.msel .chas { stroke: var(--ac); }
.node.chip .chipbg { fill: var(--tile-hi); stroke: var(--dc); stroke-width: 1.5; }
.node.chip.sel .chipbg, .node.chip:focus-visible .chipbg, .node.chip.dragging .chipbg { stroke: var(--ac); stroke-width: 2.5; }
.chiptx { fill: var(--fg); font: 600 10px var(--font-mono); pointer-events: none; }
.node.chip .chipbg.shelly { stroke: var(--ac); fill: #13304C; }
.node.chip .chipbg.conv { stroke: var(--v24); fill: #2A2614; }
.node.chip .chipbg.thermo { stroke: var(--warn); fill: #2A2012; }
.dotn { fill: var(--dc); stroke: var(--board); stroke-width: 2; }
.node.dot:hover .dotn, .node.dot.sel .dotn, .node.dot:focus-visible .dotn, .node.dot.dragging .dotn { stroke: var(--ac); stroke-width: 3; }
.plabel { fill: var(--muted); font: 500 10.5px var(--font-mono); pointer-events: none; }
.ptxt { fill: var(--muted); font: 500 10px var(--font-mono); }
.node.chassis.sel .chas, .node.chassis:focus-visible .chas, .node.chassis.dragging .chas { stroke: var(--ac); }
.ph { filter: drop-shadow(0 0 0.7px rgba(214, 228, 250, 0.65)); pointer-events: none; }
.t-title { fill: var(--fg); font: 600 15px var(--font-display); letter-spacing: 0.01em; pointer-events: none; }
.t-sub { fill: var(--muted); font: 400 11.5px var(--font-body); pointer-events: none; }
.lbl { fill: var(--muted); font: 500 12px var(--font-mono); }
.lbl-dc { fill: var(--dc); font: 500 12px var(--font-mono); }
.lbl-warn { fill: var(--warn); font: 600 12px var(--font-body); }
.parts, .parts * { pointer-events: none; }
.edges { pointer-events: none; }
.w { fill: none; stroke-linecap: round; stroke-linejoin: round; transition: opacity .15s; }
.w.dc { stroke: var(--dc); stroke-width: 3.5; stroke-dasharray: 14 9; }
.w.dc.heavy { stroke-width: 5.5; }
.w.dc.thin { stroke-width: 2; stroke-dasharray: 8 7; }
.w.v24 { stroke: var(--v24); stroke-width: 3; stroke-dasharray: 12 8; }
.w.neg { stroke: var(--dc-neg); stroke-width: 4; stroke-dasharray: 14 9; }
.w.neg.heavy { stroke-width: 5.5; }
.w.ac { stroke: var(--ac); stroke-width: 3.5; stroke-dasharray: 14 9; }
.w.data { stroke: var(--data); stroke-width: 2; stroke-dasharray: 2 6; }
.w.sig { stroke: var(--sig); stroke-width: 2; stroke-dasharray: 2 6; }
.deco { transition: opacity .15s; }
svg.focus .w:not(.hl) { opacity: 0.13; }
svg.focus .deco:not(.hl) { opacity: 0.2; }
.gl rect { fill: var(--board); stroke: var(--muted); stroke-width: 1.5; }
.gl path { fill: none; stroke: var(--dc); stroke-width: 2.4; stroke-linecap: round; }
.gl rect.fz { fill: none; stroke: var(--dc); stroke-width: 1.8; }
.gl.ac path { stroke: var(--ac); }
.pin rect { fill: var(--pin); }
.pin text { fill: #FFFFFF; font: 700 11px var(--font-mono); }
.vanline { stroke: var(--fg); stroke-width: 2.2; fill: none; stroke-linejoin: round; pointer-events: none; }
.wheel { fill: var(--tile); stroke: var(--fg); stroke-width: 2.2; pointer-events: none; }
.chas { stroke: var(--fg); stroke-width: 2; fill: none; stroke-linecap: round; }
svg.hide-dc .L-dc, svg.hide-ac .L-ac, svg.hide-ctl .L-ctl { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .w.dc, .w.ac, .w.v24, .w.neg { animation: flow 1.6s linear infinite; }
  .w.neg { animation-direction: reverse; }
}
@keyframes flow { to { stroke-dashoffset: -46; } }

/* ---------- side panel */
.side { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; background: var(--bg); }
.tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  font-size: 13.5px; font-weight: 500; padding: 8px 10px 9px; white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--ac); }
.panes { overflow-y: auto; min-height: 0; }
.tabpanel { padding: 18px 20px 28px; }
.tabpanel h2 { font-family: var(--font-display); font-weight: 600; font-size: 22px; margin: 0; line-height: 1.2; text-wrap: balance; }
.tabpanel h3 { font-family: var(--font-mono); font-size: 11.5px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; }
.tabpanel p { margin: 10px 0 0; }
.sub { color: var(--muted); margin: 4px 0 0; font-size: 14px; }
.dimgs { display: flex; flex-wrap: wrap; gap: 14px; margin: 16px 0 0; }
.dimgs img { height: 78px; width: auto; max-width: 150px; object-fit: contain; filter: drop-shadow(0 0 0.7px rgba(214, 228, 250, 0.65)); }
.spec { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 16px 0 0; font-size: 14px; }
.spec dt { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding-top: 2px; }
.spec dd { margin: 0; min-width: 0; }
.chip { display: inline-block; font: 700 11px var(--font-mono); color: #FFFFFF; background: var(--pin); border-radius: 999px; padding: 1px 7px; margin: 0 2px; vertical-align: 1px; }
.note { margin: 16px 0 0; padding: 10px 12px; border-left: 3px solid var(--warn); background: var(--warn-bg); border-radius: 0 8px 8px 0; font-size: 14px; }
.conns { display: flex; flex-wrap: wrap; gap: 6px; }
.conn {
  display: inline-flex; align-items: center; gap: 7px; font-size: 13px; background: var(--tile); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 10px 5px 6px; min-height: 32px; text-align: left;
}
.conn:hover { background: var(--tile-hi); }
.tag { font: 600 10px var(--font-mono); letter-spacing: 0.04em; border-radius: 4px; padding: 1px 5px; color: var(--bg); background: var(--dc); }
.tag.ac { background: var(--ac); }
.tag.ctl { background: var(--sig); }
.verify { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.verify li { display: grid; grid-template-columns: 42px minmax(0, 1fr); align-items: baseline; }
.verify li .chip { justify-self: start; margin: 0; }
.iso { margin: 14px 0 0; padding-left: 18px; display: grid; gap: 10px; font-size: 14px; }
.warnhead { color: var(--warn); }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 6px 12px;
  background: var(--tile); border: 1px solid var(--line); border-radius: 10px; font-size: 13.5px; font-weight: 500; text-align: center;
}
.btn:hover { background: var(--tile-hi); }
.btn.danger { color: #F3B7B7; }
.btn input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
label.btn { cursor: pointer; position: relative; }
label.btn:focus-within { outline: 2px solid var(--ac); outline-offset: 2px; }
#copybox { width: 100%; min-height: 140px; margin-top: 12px; background: var(--board); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: 12px var(--font-mono); resize: vertical; }
.keys { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; color: var(--fg); }
kbd { font: 600 11.5px var(--font-mono); background: var(--tile); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: #1F3354; color: var(--fg); border: 1px solid #36507E; border-radius: 10px; padding: 9px 16px;
  font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); z-index: 10; max-width: calc(100vw - 32px);
}

@media (max-width: 960px) {
  .app { height: auto; min-height: 0; display: block; }
  .main { display: block; }
  .stage { border-right: 0; }
  .board { height: 64vh; height: 64dvh; min-height: 360px; }
  .side { border-top: 1px solid var(--line); }
  .panes { overflow: visible; }
  h1 { font-size: 22px; }
}
