:root {
  --bg: #14171a;
  --panel: #1c2024;
  --line: #2f353b;
  --text: #e4e7ea;
  --muted: #8b949c;
  --accent: #f5a524;
  --room: #3fa7d6;
  --wall: #e8594f;
  --ok: #5cb85c;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, "Segoe UI", sans-serif;
  display: flex; flex-direction: column;
}
button, .btn {
  background: #272c31; color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 6px 10px; font: inherit; cursor: pointer;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.active { background: var(--accent); color: #111; border-color: var(--accent); }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
kbd { opacity: .6; font: 11px monospace; margin-left: 4px; }
input, select {
  background: #101316; color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; padding: 5px 7px; font: inherit; width: 100%;
}
#topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { margin-right: 8px; }
#tools { display: flex; gap: 4px; }
.spacer { flex: 1; }
main { flex: 1; display: flex; min-height: 0; }
#stageWrap { flex: 1; position: relative; min-width: 0; }
#stage { width: 100%; height: 100%; display: block; background: #0d0f11; touch-action: none; }
#stage.tool-select { cursor: default; }
#stage.tool-wall, #stage.tool-room, #stage.tool-scale, #stage.tool-area, #stage.tool-door, #stage.tool-window, #stage.tool-point, #stage.tool-cable, #stage.tool-dim, #stage.tool-outer, #stage.tool-box { cursor: crosshair; }
#stage.tool-pan, #stage.panning { cursor: grab; }
#empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); pointer-events: none; text-align: center;
}
#stageWrap.dragover { outline: 2px dashed var(--accent); outline-offset: -6px; }
#hint {
  position: absolute; left: 10px; bottom: 10px; background: rgba(20,23,26,.85);
  border: 1px solid var(--line); border-radius: 5px; padding: 5px 9px; color: var(--muted);
  pointer-events: none; max-width: calc(100% - 20px);
}
#panel {
  width: 300px; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 12px;
}
#panel h4 {
  margin: 16px 0 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
#panel h4:first-child { margin-top: 0; }
#panel label.f { display: block; margin: 6px 0; color: var(--muted); font-size: 12px; }
#panel label.f input, #panel label.f select { margin-top: 2px; color: var(--text); font-size: 14px; }
.row { display: flex; gap: 8px; margin-top: 8px; }
.row > * { flex: 1; }
.muted { color: var(--muted); }
.good { color: var(--ok); }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; justify-content: space-between; padding: 4px 6px; border-radius: 4px; cursor: pointer;
}
.list li:hover { background: #262b30; }
.list li.sel { background: #3a2f17; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin-top: 0; }
#leadDlg { width: min(640px, 94vw); }
#leadDlg textarea { width: 100%; font: 12px/1.4 ui-monospace, Consolas, monospace; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 6px; }
#leadDlg pre.lead { white-space: pre-wrap; font: 12px/1.4 ui-monospace, Consolas, monospace; background: var(--bg); padding: 8px; border-radius: 4px; max-height: 50vh; overflow: auto; }
@media (max-width: 800px) {
  main { flex-direction: column; }
  #panel { width: 100%; max-height: 40%; border-left: 0; border-top: 1px solid var(--line); }
}

.palgroup { margin: 6px 0; }
.palgroup button.pal { display: block; width: 100%; text-align: left; margin: 2px 0; padding: 4px 8px; font-size: 13px; }
.palgroup button.pal b { display: inline-block; min-width: 26px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; color: #fff; text-shadow: 0 0 2px #000; border: 1px solid rgba(255,255,255,.25); }
.chip.dark { color: #111; text-shadow: none; }
details.wiresel { margin: 4px 0; }
details.wiresel summary { cursor: pointer; font-size: 12px; color: #9aa5ad; }
.wrow { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 0; }
.wrow > span:first-of-type { flex: 1; }
.wrow select { width: auto; max-width: 150px; font-size: 11px; padding: 1px 4px; }
.wrow select.off { opacity: .5; }

.strip { overflow-x: auto; border: 1px solid var(--line); border-radius: 4px; margin: 2px 0 6px; background: #111; }
.strip img { display: block; max-width: none; height: 70px; }

.figcard { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin: 8px 0; background: #14181b; }
.figcard img { display: block; max-width: 100%; background: #fff; border-radius: 3px; margin-bottom: 6px; }

dialog.wide { width: min(900px, 94vw); max-height: 90vh; overflow-y: auto; }
.estopts { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 8px; }
.estopts select { width: auto; }
.estopts .chk { display: flex; gap: 6px; align-items: center; }
.estopts .chk input { width: auto; }
.pkgs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.pkg { border: 1px solid var(--line); border-radius: 6px; padding: 8px; cursor: pointer; }
.pkg.on { border-color: var(--accent); background: #2a2417; }
table.est { width: 100%; border-collapse: collapse; }
table.est th, table.est td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.est td.num { text-align: right; white-space: nowrap; }
table.est input { width: 100px; }
.esttotal { margin: 10px 0; font-size: 16px; }
.assump { color: var(--muted); padding-left: 18px; }
@media print { body > *:not(dialog) { display: none; } dialog { position: static; border: 0; color: #000; background: #fff; } button { display: none; } }

.glyphs { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.gl { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 4px; padding: 4px; background: #1b1f23; }
.gl.skip { opacity: .45; }
.gl img { height: 38px; width: auto; max-width: 56px; background: #fff; }
.gl select { width: 58px; padding: 2px; font-size: 13px; }
.gl label { font-size: 11px; color: var(--muted); display: flex; gap: 3px; align-items: center; }
.gl label input { width: auto; }
.gl button { padding: 1px 6px; font-size: 11px; }
.chips { margin: 4px 0; color: var(--muted); font-size: 12px; }
.chips button { margin-left: 4px; padding: 2px 8px; font-size: 13px; }

.lvtabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.lvtabs button { padding: 4px 9px; }

.palgroup button.pal { display: flex; align-items: center; gap: 8px; }
.palgroup button.pal .sym { display: inline-flex; width: 36px; justify-content: center; flex: none; }

.learnmsg { white-space: pre-line; margin-top: 6px; font-size: 12px; }


button.danger { background: #7a2420; border-color: #e8594f; color: #fff; }

#panel h4.sec { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 6px; }
#panel h4.sec::before { content: '▾'; font-size: 11px; width: 10px; color: var(--accent); }
#panel h4.sec.closed::before { content: '▸'; }
#panel h4.sec:hover { color: var(--text); }
#panel h4.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { background: rgba(245,165,36,.45); } 100% { background: transparent; } }

.grp { border: 1px solid #2a3036; border-radius: 6px; padding: 6px 8px; margin: 6px 0; }
.grphead { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; }
.grphead .chk { margin-left: auto; }
.warn { color: #f5a524; }

button.mini { padding: 1px 8px; font-size: 11px; }
