:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --ink: #1d2320;
  --muted: #5f6a63;
  --line: #dfe3dd;
  --accent: #4f8f2b;
  --accent-ink: #ffffff;
  --accent-soft: #e8f2df;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn-soft: #fff6dc;
  --radius: 12px;
  --pricebar-h: 72px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(var(--pricebar-h) + env(safe-area-inset-bottom, 0px));
}
button, select, input { font: inherit; color: inherit; }
h2 { font-size: 16px; margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sub { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.link-muted { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* Top bar */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { font-weight: 700; margin-right: auto; }
.building-picker select {
  min-height: 40px; padding: 6px 34px 6px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); font-weight: 600; max-width: 60vw;
}

.notice { max-width: 1400px; margin: 10px auto 0; padding: 8px 16px; background: var(--warn-soft); border-radius: 8px; font-size: 13px; }
@media (min-width: 1432px) { .notice { padding: 8px 16px; } }
@media (max-width: 1431px) { .notice { margin-left: 16px; margin-right: 16px; } }

/* Layout */
.layout { max-width: 1400px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr) 400px; align-items: start; }
  .stage { position: sticky; top: 76px; }
}

.view-card, .step { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.view-card { padding: 12px; margin-bottom: 16px; }
.view-card:last-child { margin-bottom: 0; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 12px; }
.svg-wrap { width: 100%; }
.svg-wrap svg { display: block; width: 100%; height: auto; touch-action: none; -webkit-user-select: none; user-select: none; }
.plan-wrap svg { max-height: 48vh; }
.elev-wrap svg { max-height: 32vh; }
@media (min-width: 960px) {
  .plan-wrap svg { max-height: calc(52vh - 120px); }
  .elev-wrap svg { max-height: calc(40vh - 140px); }
}

.panel .step { padding: 16px; margin-bottom: 16px; }
.step h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.num { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 13px; align-items: center; justify-content: center; }

/* Segmented buttons */
.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; min-height: 34px; font-size: 13px; }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }
.seg-wide { display: flex; margin-bottom: 10px; }
.seg-wide button { flex: 1 1 0; }

/* Size grid */
.size-table { width: 100%; border-collapse: separate; border-spacing: 4px; table-layout: fixed; }
.size-table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.size-table th[scope="row"] { text-align: left; width: 44px; }
.size-btn {
  width: 100%; min-height: 44px; border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  cursor: pointer; padding: 4px 2px; font-size: 12px; line-height: 1.2;
}
.size-btn strong { display: block; font-size: 13px; }
.size-btn:hover { border-color: var(--accent); }
.size-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.size-na { display: block; text-align: center; color: #c3c8c3; }

/* Swatches */
.swatches { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.swatch { border: 2px solid transparent; border-radius: 10px; background: none; padding: 0; cursor: pointer; text-align: center; font-size: 12px; }
.swatch .chip { display: block; width: 100%; padding-top: 100%; border-radius: 8px; background-size: cover; background-position: center; }
.swatch span:last-child { display: block; padding: 4px 0 2px; }
.swatch[aria-pressed="true"] { border-color: var(--accent); }
.swatch[aria-pressed="true"] span:last-child { font-weight: 600; }

.opt-group { margin-bottom: 14px; }
.opt-group:last-child { margin-bottom: 0; }
.opt-label { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; min-height: 36px; cursor: pointer; font-size: 13px; text-align: left; }
.chip-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); flex: none; }

/* Components */
.component-list { display: grid; gap: 8px; }
.comp { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.comp-icon { width: 44px; height: 36px; flex: none; }
.comp-body { flex: 1 1 auto; min-width: 0; }
.comp-name { font-weight: 600; font-size: 13px; }
.comp-meta { color: var(--muted); font-size: 12px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

/* Inspector */
.inspector { border: 2px solid var(--accent); border-radius: 10px; padding: 12px; margin: 10px 0 14px; background: #fbfdf9; }
.inspector-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; margin-bottom: 8px; }
.inspector-title { font-weight: 700; }
.inspector .row { margin-top: 10px; }
.inspector .row-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; }
.inspector input[type="range"] { width: 100%; min-height: 32px; accent-color: var(--accent); }
.nudge { display: flex; gap: 6px; margin-top: 6px; }
.nudge .btn { flex: 1 1 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--ink); }
.btn-sm { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #efc9c5; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .seg button:focus-visible, .size-btn:focus-visible, .swatch:focus-visible, .chip-btn:focus-visible { outline: 3px solid #9cc77c; outline-offset: 1px; }

/* Summary */
.lines { width: 100%; border-collapse: collapse; font-size: 14px; }
.lines td { padding: 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines td:last-child { text-align: right; white-space: nowrap; padding-left: 12px; }
.lines tr.total td { font-weight: 700; font-size: 16px; border-bottom: 0; padding-top: 10px; }
.lines .incl { color: var(--accent); font-weight: 600; }
.issue { padding: 8px 10px; border-radius: 8px; font-size: 13px; margin-bottom: 8px; }
.issue.error { background: var(--danger-soft); color: var(--danger); }
.issue.warn { background: var(--warn-soft); }
.features { margin-top: 12px; font-size: 13px; }
.features summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.features ul { padding-left: 18px; margin: 6px 0; }

/* Price bar */
.pricebar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.06); padding-bottom: env(safe-area-inset-bottom, 0px); }
.pricebar-inner { max-width: 1400px; margin: 0 auto; height: var(--pricebar-h); padding: 0 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pricebar-label { font-size: 12px; color: var(--muted); }
.pricebar-total { font-size: 22px; font-weight: 800; }
.pricebar-actions { display: flex; gap: 8px; }

/* Modal */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; }
.modal-box pre { white-space: pre-wrap; word-wrap: break-word; font-family: inherit; font-size: 14px; background: var(--bg); border-radius: 8px; padding: 12px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.toast { position: fixed; left: 50%; bottom: calc(var(--pricebar-h) + 16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* SVG drawing styles */
.dim { font-size: 150px; fill: #5f6a63; font-family: var(--font); }
.dim-line { stroke: #9aa39d; stroke-width: 12; fill: none; }
.wall-label { font-size: 170px; font-weight: 700; fill: #8a948d; letter-spacing: 20px; font-family: var(--font); }
.opening { cursor: grab; }
.opening.dragging { cursor: grabbing; }
.wall-hit { cursor: pointer; }

@media (max-width: 420px) {
  .pricebar-total { font-size: 19px; }
  .btn { padding: 8px 10px; }
  .swatches { gap: 6px; }
  .size-btn { font-size: 11px; }
}

@media print {
  .topbar, .pricebar, .panel, .notice, .toast, .modal { display: none !important; }
  body { padding: 0; background: #fff; }
  .layout { display: block; }
  .stage { position: static; }
}

/* View switch and 3D */
.view-switch { margin-bottom: 12px; }
.view-switch button { min-height: 40px; font-size: 14px; }
.three-wrap { position: relative; width: 100%; height: 56vh; min-height: 300px; border-radius: 8px; overflow: hidden; background: #dfe9ef; touch-action: none; }
.three-wrap canvas { display: block; width: 100% !important; height: 100% !important; }
.three-msg { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px; color: var(--muted); font-size: 14px; }
.three-msg[hidden] { display: none; }
@media (min-width: 960px) { .three-wrap { height: calc(100vh - 290px); } }

/* Placed doors and windows */
.mini-head { font-size: 14px; margin: 16px 0 0; }
.placed-list { display: grid; gap: 6px; margin-bottom: 4px; }
.placed { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 6px 10px; cursor: pointer; min-height: 48px; }
.placed:hover { border-color: var(--accent); }
.placed[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.placed .comp-icon { width: 34px; height: 30px; }
.placed-body { flex: 1 1 auto; min-width: 0; font-size: 13px; }
.placed-body strong { display: block; font-size: 13px; }
.placed-body span { color: var(--muted); font-size: 12px; }
.placed-go { color: var(--muted); font-size: 12px; white-space: nowrap; }
