:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1c2330; --muted: #5d6778; --line: #d5d9e0;
  --accent: #1f6feb; --accent-ink: #ffffff; --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e;
  --floor: #fbfbfc; --grid: #e3e6eb; --grid-major: #c9ced6; --wall: #2b3445;
  --halo: rgba(31, 111, 235, 0.13); --pillar: #6b7280; --door: #b45309;
  --shadow: 0 1px 2px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.06);
}
:root[data-theme="dark"] {
  --bg: #11151c; --panel: #1a202b; --ink: #e6e9ef; --muted: #98a2b3; --line: #2c3544;
  --accent: #4c8dff; --accent-ink: #0b1220; --ok: #3fb950; --warn: #d29922; --bad: #f85149;
  --floor: #161c26; --grid: #232b38; --grid-major: #333e50; --wall: #9aa6bb;
  --halo: rgba(76, 141, 255, 0.16); --pillar: #8b95a7; --door: #e3a008;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151c; --panel: #1a202b; --ink: #e6e9ef; --muted: #98a2b3; --line: #2c3544;
    --accent: #4c8dff; --accent-ink: #0b1220; --ok: #3fb950; --warn: #d29922; --bad: #f85149;
    --floor: #161c26; --grid: #232b38; --grid-major: #333e50; --wall: #9aa6bb;
    --halo: rgba(76, 141, 255, 0.16); --pillar: #8b95a7; --door: #e3a008;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
.setup-bar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 12px; margin: 0; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.setup-bar h2 { font-size: .95rem; margin: 0 0 6px; }
.setup-bar h2 span { font-weight: 400; color: var(--muted); }
.setup-bar .hint { margin: 6px 0 0; }
.setup-bar .row { align-items: end; }
.setup-bar .space-setup .row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; }
.setup-bar .space-setup .field { min-width: 0; width: 100%; margin: 0; }
.setup-bar .space-setup input { min-width: 0; width: 100%; }
.preset-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.preset-controls select { min-width: 0; }
.preset-controls button { justify-self: end; }
.library-heading { margin: 0; padding: 10px 12px; font-size: 1rem; border-bottom: 1px solid var(--line); flex-shrink: 0; }
#quoteDialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 20px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; }
#quoteDialog::backdrop { background: rgba(15,23,35,.55); }
#presetFitDialog { width: min(420px, calc(100vw - 32px)); padding: 24px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; }
#presetFitDialog::backdrop { background: rgba(15,23,35,.55); }
#presetFitDialog h2 { font-size: 1.1rem; margin: 0 0 12px; }
.preset-fit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.preset-fit-actions button { min-width: 72px; }
#quoteDialog > form { display: flex; justify-content: end; }
#quoteDialog h2 { font-size: 1.2rem; }
.setup-bar select { width: 100%; }
.quote-cta { margin-left: auto; order: 1; }
.quote-cta small { display: block; font-size: .7rem; font-weight: 400; }
#presetPreview { display: flex; gap: 6px; flex-wrap: wrap; }
#presetPreview img { width: 42px; height: 42px; object-fit: contain; background: white; border-radius: 4px; margin-top: 8px; }
#presetStatus:empty { display: none; }
@media (min-width: 901px) { .rnd-planner .stage { height: calc(100dvh - 120px); min-height: 430px; } }
@media (max-width: 700px) {
  .quote-cta { position: fixed; bottom: 10px; right: 12px; left: 12px; z-index: 10; }
  .rnd-planner { padding-bottom: 80px !important; }
}
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.rnd-planner { display: flex; flex-direction: column; min-height: 100vh; padding: 0 16px 16px; max-width: 1600px; margin: 0 auto; }
header.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 0; }
header.top h1 { font-size: 1.15rem; margin: 0; font-weight: 650; }
header.top .sub { color: var(--muted); font-size: .9rem; flex: 1 1 260px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
button, select, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px;
  cursor: pointer; min-height: 36px;
}
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
.main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; flex: 1; min-height: 0; }
.stage {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden; min-height: 460px; height: calc(100vh - 120px);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#view3d { display: none; }
.stage.is3d #view3d { display: block; }
.stage.is3d #plan { display: none; }
.hud {
  position: absolute; left: 10px; top: 10px; background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; font-size: .82rem; color: var(--muted);
  pointer-events: none; max-width: calc(100% - 150px);
}
.statusbadge {
  position: absolute; right: 10px; top: 10px; padding: 5px 11px; border-radius: 999px; font-size: .85rem; font-weight: 650;
  background: var(--panel); border: 1px solid var(--line);
}
.statusbadge.ok { color: var(--ok); border-color: var(--ok); }
.statusbadge.bad { color: var(--bad); border-color: var(--bad); }
.selbar { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.selbar[hidden] { display: none; }
.selbar button { min-width: 40px; padding: 5px 9px; }
.zoombtns { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; max-width: calc(100% - 20px); overflow-x: auto; padding: 5px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.zoombtns button { min-width: 40px; flex-shrink: 0; white-space: nowrap; }
.zoombtns .clear-layout { background: #c45a12; border-color: #c45a12; color: #fff; font-weight: 650; }
.zoombtns .clear-layout:hover { background: #a6470b; border-color: #a6470b; }
.stage .selbar { bottom: 78px; }
.machine-category { border-bottom: 1px solid var(--line); }
.machine-category summary { padding: 12px 4px; cursor: pointer; font-weight: 650; }
.machine-category summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.category-machines { display: grid; gap: 8px; padding-bottom: 12px; }
.machine-actions { display: grid; gap: 6px; }
.machine-details-link { display: block; text-align: center; text-decoration: none; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; min-height: 36px; }
.machine-details-link:hover { border-color: var(--accent); }
.machine-details-link.disabled { color: var(--muted); opacity: .55; cursor: not-allowed; pointer-events: none; }
.machine-details-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card .name { overflow-wrap: anywhere; }
#machineDetails { width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
#machineDetails::backdrop { background: rgba(15, 23, 35, .55); }
#machineDetails form { display: flex; justify-content: end; }
#machineDetails h2 { font-size: 1.2rem; margin: 16px 0; }
#machineDetailsImage { display: block; width: 100%; height: 200px; object-fit: contain; background: white; border-radius: 8px; }
#machineDetailsImage[hidden] { display: none; }
#machineDetailsDimensions { font-weight: 600; }
#machineDetailsDescription { color: var(--muted); }
aside.side { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - 120px); }
.tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; min-width: 0; }
.tabs button { border: 0; border-radius: 0; background: none; padding: 10px 12px; white-space: nowrap; border-bottom: 3px solid transparent; flex: 1 0 auto; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); font-weight: 650; }
.tabpanel { padding: 12px; overflow: auto; flex: 1; min-height: 0; }
.tabpanel[hidden] { display: none; }
.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; }
.field label { font-size: .82rem; color: var(--muted); }
.field input, .field select, .field textarea, .preset-controls select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; min-height: 36px;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .field { flex: 1 1 110px; }
.cards { display: grid; gap: 8px; }
.card { display: grid; grid-template-columns: 72px 1fr auto; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg); }
.card .thumb { width: 72px; height: 72px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.card .thumb img, .card .thumb svg { max-width: 100%; max-height: 100%; }
.card .name { font-weight: 650; }
.card .dims { color: var(--muted); font-size: .82rem; }
.card .desc { color: var(--muted); font-size: .8rem; grid-column: 2 / 4; }
.card[draggable="true"] { cursor: grab; }
.hint { color: var(--muted); font-size: .85rem; margin: 0 0 10px; }
.warnlist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.warnlist li { border-left: 4px solid var(--line); background: var(--bg); padding: 6px 9px; border-radius: 6px; font-size: .9rem; }
.warnlist li.error { border-left-color: var(--bad); }
.warnlist li.info { border-left-color: var(--warn); }
.warnlist li.good { border-left-color: var(--ok); }
.summary { width: 100%; border-collapse: collapse; font-size: .9rem; }
.summary td, .summary th { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.msg { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; font-size: .9rem; background: var(--bg); border: 1px solid var(--line); }
.quote-layout-summary { display: grid; gap: 3px; margin: 10px 0 14px; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--bg); color: var(--muted); font-size: .84rem; }
.quote-layout-summary strong { color: var(--ink); font-size: .9rem; }
.msg.ok { border-color: var(--ok); } .msg.bad { border-color: var(--bad); }
footer.note { color: var(--muted); font-size: .8rem; padding-top: 10px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 900px) {
  .rnd-planner { padding: 0 16px 16px; }
  .main { grid-template-columns: minmax(0, 1fr); }
  .side, .stage, .tabpanel { min-width: 0; }
  .selbar { bottom: 58px; }
  .tabs button { padding: 10px 7px; font-size: .92rem; }
  .stage { height: min(56vh, 100vw); min-height: 300px; }
  aside.side { max-height: none; }
  .tabpanel { max-height: none; }
  .card { grid-template-columns: 64px 1fr auto; }
  .card .thumb { width: 64px; height: 64px; }
}

.cards h3.cat { margin: 10px 0 0; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.cards h3.cat:first-child { margin-top: 0; }

.warnlist li button { width: 100%; text-align: left; border: 0; background: transparent; min-height: 32px; padding: 3px 4px; }
.warnlist li[role="button"]:focus-visible { outline: 2px solid var(--accent); }
#measureOverlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
