:root {
  color-scheme: dark;
  --bg: #090b0d;
  --panel: #11151a;
  --panel-2: #171c22;
  --line: #2b333c;
  --line-strong: #3c4652;
  --ink: #f2f4f5;
  --muted: #9ba5af;
  --yellow: #ffc857;
  --cyan: #56d8ff;
  --green: #75e2a4;
  --orange: #ff9859;
  --red: #ff6472;
  --blueprint: #0e1a22;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
}

button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button {
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #1a2027;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 12px;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
button:hover { border-color: #66717d; background: #20272f; }
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}
button.accent { background: var(--yellow); border-color: var(--yellow); color: #14110a; font-weight: 760; }
button.accent:hover { background: #ffd477; border-color: #ffd477; }
button.quiet, .icon-button { background: transparent; }
button.danger { color: #ffc3c9; border-color: #66313a; }
button.danger:hover { background: #351a20; border-color: var(--red); }

.topbar {
  height: 68px;
  display: grid;
  grid-template-columns: minmax(250px, 1fr) auto minmax(250px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 11, 13, .96);
  position: relative;
  z-index: 4;
}
.brand-lockup { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  width: 34px; height: 34px; border: 1px solid var(--yellow); border-radius: 9px;
  display: grid; place-items: center; color: var(--yellow); font-size: 19px;
}
.eyebrow { color: var(--muted); font-size: .72rem; letter-spacing: .16em; font-weight: 730; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.025em; }
h1 { font-size: 1.06rem; }
h2 { font-size: 1rem; margin-top: 2px; }
.room-stats { display: flex; gap: 20px; color: var(--muted); font-size: .78rem; white-space: nowrap; }
.room-stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.top-actions { display: flex; justify-content: flex-end; gap: 8px; }

.workspace {
  height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
}
.stage-shell { min-width: 0; display: grid; grid-template-rows: 54px minmax(0, 1fr); background: #0c1014; }
.stage-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 8px 16px; border-bottom: 1px solid var(--line); background: #0e1216;
}
.segmented { display: flex; background: #090c0f; padding: 3px; border: 1px solid var(--line); border-radius: 10px; }
.segmented button { min-height: 32px; padding: 5px 12px; border: 0; background: transparent; color: var(--muted); }
.segmented button.active { background: var(--panel-2); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toolbar-group { display: flex; align-items: center; gap: 14px; }
.toggle { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .83rem; cursor: pointer; }
.toggle input { accent-color: var(--yellow); width: 16px; height: 16px; }
.icon-button { width: 36px; padding: 0; font-size: 1.15rem; }

.stage { position: relative; min-height: 0; overflow: hidden; background: var(--blueprint); }
#plan { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
.grid-minor { stroke: #182b35; stroke-width: .17; }
.grid-major { stroke: #243b47; stroke-width: .24; }
.room-fill { fill: url(#majorGrid); }
.wall { stroke: #e6eaed; stroke-width: 3.4; stroke-linecap: square; }
.window { stroke: var(--cyan); stroke-width: 2.2; stroke-linecap: butt; }
.window-glow { stroke: rgba(86,216,255,.16); stroke-width: 6; }
.opening { stroke: var(--orange); stroke-width: 2.2; stroke-dasharray: 3 2; }
.opening-label, .wall-label { fill: #9eb0bc; font-size: 3px; font-weight: 620; letter-spacing: .08em; }
.wall-label { fill: #738692; font-size: 2.7px; }
.guide-line { stroke: rgba(86,216,255,.62); stroke-width: .55; stroke-dasharray: 3 2; }
.guide-zone { fill: rgba(255,152,89,.08); stroke: rgba(255,152,89,.72); stroke-width: .55; stroke-dasharray: 2 1.5; }
.guide-label { fill: #83b9c9; font-size: 2.7px; font-weight: 700; letter-spacing: .08em; }
.dimension-line { stroke: var(--yellow); stroke-width: .46; }
.dimension-tick { stroke: var(--yellow); stroke-width: .72; }
.dimension-text { fill: #ffe5a8; font-size: 3.05px; font-weight: 760; paint-order: stroke; stroke: #0e1a22; stroke-width: 1.4; stroke-linejoin: round; }
.dimension-sub { fill: #bdc9cf; font-size: 2.55px; font-weight: 620; paint-order: stroke; stroke: #0e1a22; stroke-width: 1.25; }
.dimensions-full[hidden] { display: none; }
.status-tag { font-size: 2.25px; font-weight: 850; }
.status-measured { fill: var(--green); }
.status-derived { fill: var(--cyan); }
.status-estimated { fill: var(--orange); }

.plan-item { cursor: grab; filter: url(#itemShadow); }
.plan-item:active { cursor: grabbing; }
.plan-item rect.body { fill: #2d3740; stroke: #86939e; stroke-width: .7; vector-effect: non-scaling-stroke; }
.plan-item text { fill: white; font-size: 3px; font-weight: 720; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.plan-item text.size { fill: #c2ccd2; font-size: 2.35px; font-weight: 560; }
.plan-item.selected rect.body { fill: #3b3422; stroke: var(--yellow); stroke-width: 1.25; }
.plan-item.fail rect.body { fill: #47232a; stroke: var(--red); }
.plan-item.warn rect.body { fill: #463820; stroke: var(--orange); }
.plan-item.estimated rect.body { stroke-dasharray: 2 1; }

.plan-key {
  position: absolute; left: 16px; bottom: 15px; display: flex; gap: 8px; flex-wrap: wrap;
  padding: 7px 9px; border: 1px solid rgba(255,255,255,.10); border-radius: 9px;
  background: rgba(8, 13, 17, .82); backdrop-filter: blur(12px); font-size: .72rem; color: var(--muted);
}
.key { display: inline-flex; align-items: center; gap: 5px; }
.key b, .certainty { min-width: 19px; height: 19px; border-radius: 5px; display: inline-grid; place-items: center; font-size: .68rem; }
.key.measured b, .certainty.measured { color: var(--green); background: rgba(117,226,164,.12); border: 1px solid rgba(117,226,164,.35); }
.key.derived b, .certainty.derived { color: var(--cyan); background: rgba(86,216,255,.11); border: 1px solid rgba(86,216,255,.34); }
.key.estimated b, .certainty.estimated { color: var(--orange); background: rgba(255,152,89,.11); border: 1px solid rgba(255,152,89,.34); }
.stage-status {
  position: absolute; right: 16px; bottom: 15px; max-width: min(58%, 560px); padding: 8px 10px;
  border: 1px solid rgba(255,255,255,.10); border-radius: 9px; background: rgba(8,13,17,.82);
  color: #cbd4d9; font-size: .76rem; backdrop-filter: blur(12px);
}

.model-stage { background: radial-gradient(circle at 50% 30%, #28323c, #0e1216 70%); }
model-viewer { width: 100%; height: 100%; --poster-color: transparent; }
.model-overlay { position: absolute; top: 16px; left: 16px; display: flex; gap: 7px; flex-wrap: wrap; pointer-events: none; }
.model-overlay span { background: rgba(9,11,13,.82); border: 1px solid #424c57; border-radius: 8px; padding: 7px 9px; font-size: .75rem; color: #ffe5a8; }
.model-note { position: absolute; margin: 0; right: 16px; bottom: 16px; background: rgba(9,11,13,.82); border: 1px solid #424c57; border-radius: 8px; padding: 7px 10px; color: var(--muted); font-size: .76rem; }

.inspector {
  overflow: auto; border-left: 1px solid var(--line); background: #0d1014; padding: 12px;
  scrollbar-color: #39434d transparent;
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.panel-heading { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.text-button { border: 0; background: transparent; color: var(--muted); min-height: 28px; padding: 2px 0; }
.layout-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.preset-grid button { text-align: left; padding: 9px; min-height: 55px; }
.preset-grid button strong { display: block; font-size: .79rem; }
.preset-grid button small { display: block; color: var(--muted); font-size: .7rem; margin-top: 2px; font-variant-numeric: tabular-nums; }
.custom-item { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
summary { cursor: pointer; color: #d9dfe3; font-size: .84rem; font-weight: 650; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.custom-fields { margin-top: 10px; }
.field-grid label { color: var(--muted); font-size: .72rem; }
.field-grid .wide { grid-column: 1 / -1; }
input, select {
  width: 100%; display: block; margin-top: 4px; min-height: 37px; border: 1px solid var(--line-strong);
  border-radius: 8px; background: #0c1014; color: var(--ink); padding: 7px 8px;
  font-variant-numeric: tabular-nums;
}
.microcopy { margin: 9px 0 0; color: #7f8a94; font-size: .71rem; line-height: 1.45; }
.survey-note { padding: 9px 0; border-bottom: 1px solid var(--line); display: grid; gap: 3px; }
.survey-note:last-child { border-bottom: 0; padding-bottom: 0; }
.survey-note strong { color: #e6eaed; font-size: .76rem; }
.survey-note span { color: var(--muted); font-size: .71rem; line-height: 1.45; }
.survey-note b { color: var(--cyan); }
.empty-state { color: var(--muted); font-size: .82rem; padding: 6px 0 2px; }
.edge-readout { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 11px; }
.edge-readout span { display: flex; justify-content: space-between; gap: 8px; background: #0c1014; border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; font-size: .7rem; color: var(--muted); }
.edge-readout b { color: #dfe5e8; font-weight: 640; }
.fit-card { margin-top: 9px; border-radius: 8px; padding: 9px 10px; font-size: .76rem; border: 1px solid var(--line); }
.fit-card.pass { border-color: rgba(117,226,164,.4); background: rgba(117,226,164,.08); color: #c5f5d7; }
.fit-card.fail { border-color: rgba(255,100,114,.48); background: rgba(255,100,114,.08); color: #ffd0d4; }
.warning-list { margin-top: 8px; display: grid; gap: 6px; }
.warning { border-left: 2px solid var(--orange); padding: 5px 8px; color: #d4dadd; font-size: .73rem; background: rgba(255,152,89,.055); }
.warning.error { border-color: var(--red); background: rgba(255,100,114,.06); }
.warning.unknown { border-color: #71808c; background: rgba(151,166,177,.05); color: var(--muted); }
.row-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 10px; }
.row-actions button { font-size: .72rem; padding-inline: 6px; }
.measurement-list { margin: 0; display: grid; gap: 1px; }
.measurement-list div { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 7px 0; }
.measurement-list div:last-child { border-bottom: 0; }
.measurement-list dt { color: var(--muted); font-size: .76rem; display: flex; align-items: center; gap: 6px; }
.measurement-list dd { margin: 0; font-size: .78rem; font-weight: 680; font-variant-numeric: tabular-nums; }
.file-links { display: flex; gap: 8px; margin-top: 10px; }
.file-links a { flex: 1; text-align: center; text-decoration: none; color: #dce5e9; border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px; font-size: .73rem; }
.file-links a:hover { border-color: var(--cyan); color: white; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; background: #f2f4f5; color: #101317; border-radius: 9px; padding: 9px 13px; font-size: .79rem; font-weight: 700; z-index: 20; transition: opacity .18s ease, transform .18s ease; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  body { overflow: auto; }
  .topbar { grid-template-columns: 1fr auto; height: auto; min-height: 66px; padding-block: 9px; }
  .room-stats { grid-column: 1 / -1; grid-row: 2; overflow-x: auto; padding-bottom: 2px; }
  .top-actions { grid-column: 2; grid-row: 1; }
  .workspace { height: auto; min-height: calc(100vh - 100px); grid-template-columns: 1fr; }
  .stage-shell { height: min(76vh, 720px); }
  .inspector { border-left: 0; border-top: 1px solid var(--line); overflow: visible; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .panel { margin: 0; }
  .selection-panel { grid-row: span 2; }
}

@media (max-width: 660px) {
  .topbar { display: flex; flex-wrap: wrap; gap: 9px; }
  .brand-lockup { flex: 1; }
  .top-actions button { font-size: .72rem; padding-inline: 8px; }
  .room-stats { width: 100%; max-width: 100%; gap: 4px 13px; flex-wrap: wrap; overflow-x: visible; white-space: normal; }
  .stage-shell { height: 68vh; min-height: 510px; }
  .stage-toolbar { padding-inline: 9px; gap: 6px; }
  .toolbar-group { gap: 8px; }
  .toggle { font-size: .72rem; }
  #zoomFit { display: none; }
  .inspector { grid-template-columns: 1fr; padding: 9px; }
  .selection-panel { grid-row: auto; }
  .plan-key { left: 9px; bottom: 9px; }
  .stage-status { left: 9px; right: 9px; bottom: 52px; max-width: none; }
  .model-overlay { left: 9px; top: 9px; }
  .model-note { left: 9px; right: 9px; bottom: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
