:root {
  color-scheme: light;
  --bg: #e4ddd0;
  --panel: #f6f3ec;
  --ink: #1c2420;
  --muted: #5d675f;
  --line: #d4cdc0;
  --accent: #0e6844;
  --accent-strong: #0a4d33;
  --danger: #8d2b2b;
  --warn: #f8e4dc;
  --stage: #fbfaf6;
  --header: #1e2a24;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

button, input, select { font: inherit; color: inherit; }

.app {
  min-width: 1100px;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  grid-template-areas:
    "toolbar toolbar toolbar"
    "left workspace right";
}

.toolbar {
  grid-area: toolbar;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  background: var(--header);
  color: #f6f3ec;
}

.toolbar h1 {
  margin: 0 8px 0 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.toolbar button,
.unit-picker select {
  background: #314037;
  color: #f6f3ec;
  border: 1px solid #4d6156;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.toolbar button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
}

.toolbar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.unit-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.sidebar {
  background: var(--panel);
  border-color: var(--line);
  overflow: auto;
  padding: 16px;
}

.sidebar-left { grid-area: left; border-right: 1px solid var(--line); }
.sidebar-right { grid-area: right; border-left: 1px solid var(--line); }

.workspace {
  grid-area: workspace;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 12px 0;
}

.view-tabs button {
  border: 1px solid var(--line);
  background: #efeae1;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

.view-tabs button[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.stage-wrap {
  flex: 1;
  min-height: 0;
  margin: 12px;
  background: var(--stage);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

#stage {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--stage);
}

.view-hint {
  margin: 0 16px 12px;
  color: var(--muted);
  font-size: 13px;
}

.section-title {
  margin: 18px 0 8px;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.field span, .field-label {
  font-size: 12px;
  color: var(--muted);
}

.field input, .field select, .stack-control {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.opening-list, .issues { list-style: none; margin: 0; padding: 0; }

.opening-list button {
  width: 100%;
  text-align: left;
  margin-bottom: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: white;
  cursor: pointer;
}

.opening-list button.selected {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.opening-list button.has-error { background: var(--warn); }

.add-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}

button.primary {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

button.danger {
  background: white;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.issues li, .form-message {
  background: var(--warn);
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  margin-bottom: 6px;
}

.form-message:empty { display: none; }

.stage-message { margin: 0 16px 8px; }

.placement-summary { margin: 0 0 4px; font-size: 14px; }

.placement-size { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: -1px;
}

.swatch.garage-door { background: #3d4c5c; }
.swatch.personnel-door { background: #8d6234; }
.swatch.window { background: #8ec8e8; }
.swatch.obstruction { background: #c4623a; }

.empty-copy { color: var(--muted); font-size: 14px; line-height: 1.45; }

.side-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

.side-tabs button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}

.side-tabs button[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.product-detail {
  margin: 8px 0 12px;
  padding: 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
}

.product-detail h3 { margin: 0 0 6px; font-size: 15px; }

.product-detail p { margin: 0 0 8px; color: var(--muted); }

.product-detail dl { display: grid; grid-template-columns: 7.5rem 1fr; gap: 4px 8px; margin: 0; }

.product-detail dt { color: var(--muted); }

.product-detail dd { margin: 0; }

.demo-badge {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #efe4c4;
  color: #6a4b12;
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.parts-list { margin: 8px 0 0; padding-left: 18px; }

button.primary:disabled { opacity: 0.45; cursor: not-allowed; }

#stage .room, #stage .wall {
  fill: #f3efe4;
  stroke: #243028;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

#stage .grid-line {
  stroke: #ddd6c8;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

#stage .drawing-label {
  fill: #243028;
  pointer-events: none;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

#stage .drawing-label.wall-name { fill: #6a736c; }

#stage .opening {
  stroke: #1c2420;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  cursor: grab;
}

#stage .opening.selected { stroke: #0e6844; stroke-width: 4; }
#stage .opening.invalid { stroke: var(--danger); stroke-width: 4; }

#stage .placement {
  fill: #1f6b45;
  stroke: #10281c;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  cursor: grab;
}

#stage .placement.selected { stroke: #f4d35e; stroke-width: 4; }
#stage .placement.preview { opacity: 0.72; }
#stage .placement.invalid { fill: #8d2b2b; }
#stage .placement-label { fill: #f6f3ec; }
#stage.dragging, body.placing { cursor: grabbing; }
body.placing { user-select: none; }
