:root {
  color-scheme: light;
  --ink: #18201d;
  --muted: #64706a;
  --line: #d9ded9;
  --panel: #ffffff;
  --soft: #f4f6f3;
  --accent: #256f55;
  --accent-dark: #174c3a;
  --warn: #9f3412;
  --danger: #b42318;
  --shadow: 0 14px 40px rgba(18, 31, 26, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] { display: none !important; }
input:disabled, select:disabled { background: #f0f0ee; color: #70756f; }
#showProposedDoors { width: auto; margin-right: 8px; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: #eef1ed;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
}

button:hover,
.tabs button.active {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: #edf8f3;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
}

h2 {
  font-size: 1rem;
}

.status-pill {
  border: 1px solid #9fcab9;
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
  color: var(--accent-dark);
  background: #eefaf4;
  font-weight: 700;
  white-space: nowrap;
}

.status-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill.blocked {
  border-color: #f2b8a4;
  color: var(--danger);
  background: #fff2ed;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 370px) minmax(0, 1fr);
  gap: 18px;
}

.panel,
.input-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.input-panel {
  position: sticky;
  top: 18px;
  align-self: start;
  padding: 18px;
}

.panel {
  padding: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  padding: 0.65rem 0.7rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(37, 111, 85, 0.2);
  border-color: var(--accent);
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.workspace {
  min-width: 0;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric span,
.quote-row small,
.note {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 1.35rem;
}

.warnings,
.workflow {
  margin: 14px 0 0;
  padding-left: 1.2rem;
}

.warnings li,
.workflow li {
  margin: 0.5rem 0;
}

.warnings .blocking {
  color: var(--danger);
}

.warnings .advisory {
  color: var(--warn);
}

.spec-status {
  display: inline-block;
  border: 1px solid #d4b49a;
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  color: var(--warn);
  background: #fff7ed;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.spec-status.blocked {
  border-color: #f2b8a4;
  color: var(--danger);
  background: #fff2ed;
}

.drawing-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.build-controls {
  margin-bottom: 14px;
}

.build-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.build-steps button.active {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.build-stage-summary {
  margin: 0 0 10px;
  font-weight: 700;
}

.drawing-card svg {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.outer {
  fill: #fff;
  stroke: #2f3b36;
  stroke-width: 2;
}

.panel-line {
  fill: #d7e8df;
  stroke: #2f3b36;
  stroke-width: 1.2;
}

.room-line {
  stroke: #8d9b94;
  stroke-width: 1.5;
  stroke-dasharray: 6 5;
}

.shelf-line,
.front-edge {
  stroke: #256f55;
  stroke-width: 4;
}

.support-marker {
  fill: #e7ad4c;
  stroke: #8c5b1e;
  stroke-width: 1;
  stroke-dasharray: 3 2;
}

.dim {
  fill: #46524c;
  font-size: 13px;
  font-weight: 700;
}

.table-wrap {
  max-height: 460px;
  overflow: auto;
}

.survey-table {
  min-width: 600px;
}

.survey-table input,
.survey-table select {
  min-width: 0;
}

.survey-wrap {
  max-height: none;
}

.survey-meta {
  margin-top: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.7rem;
  text-align: left;
  vertical-align: top;
  font-size: 0.88rem;
}

th {
  position: sticky;
  top: 0;
  background: #f8faf8;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.schedule-row,
.quote-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 0;
}

.quote-row.total {
  color: var(--accent-dark);
  font-size: 1.2rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

textarea {
  min-height: 520px;
  resize: vertical;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
}

@media (max-width: 960px) {
  .layout,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .grid.two {
    grid-template-columns: 1fr;
    display: grid;
  }

  .status-group {
    justify-self: start;
    justify-content: flex-start;
  }
}

#printReport { display: none; }
#printReport.preview-visible { display: block; max-width: 182mm; padding: 12mm; margin: 10mm auto; background: white; }
#printReport { font-size: 9pt; line-height: 1.35; color: #111; }
#printReport section { break-before: auto; margin-top: 7mm; }
#printReport h2 { margin: 0 0 2mm; font-size: 14pt; break-after: avoid; }
#printReport .print-identity { margin: 0 0 3mm; font-size: 8pt; overflow-wrap: anywhere; }
#printReport .print-status { font-weight: 800; border: 1px solid #333; padding: 3mm; }
#printReport dl { margin: 2mm 0; }
#printReport dl > div { display: grid; grid-template-columns: 42mm minmax(0, 1fr); gap: 3mm; break-inside: avoid; }
#printReport dt { font-weight: 700; }
#printReport dd { margin: 0; overflow-wrap: anywhere; }
#printReport table { min-width: 0; width: 100%; table-layout: fixed; }
#printReport thead { display: table-header-group; }
#printReport tr { break-inside: avoid; }
#printReport th, #printReport td { padding: 1.5mm; font-size: 8pt; overflow-wrap: anywhere; }
#printReport figure { margin: 3mm 0 5mm; break-inside: avoid; }
#printReport figcaption { font-weight: 700; }
#printReport svg { width: 100%; height: auto; max-height: 100mm; }
#printReport li { margin-bottom: 2mm; overflow-wrap: anywhere; }

@media print {
  @page { size: A4 portrait; margin: 14mm; }
  .app-shell { display: none !important; }
  #printReport, #printReport.preview-visible { display: block; max-width: none; padding: 0; margin: 0; }
  .table-wrap { max-height: none; overflow: visible; }
  th { position: static; }
  .build-steps, #showDoorsControl, .build-controls .section-head button { display: none; }
  body {
    background: #fff;
  }

  .input-panel,
  .tabs,
  button {
    display: none;
  }

  .layout,
  .tab-panel {
    display: block;
  }

  .tab-panel {
    break-inside: avoid;
    margin-bottom: 18px;
  }
}

.phase2-request {
  min-height: 120px;
  font-family: inherit;
  font-size: 1rem;
}
.phase2-result {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8faf8;
}
.phase2-result:empty { display: none; }

.phase2-bays {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.phase2-bays > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.phase2-visual { margin-top: 18px; overflow-x: auto; }
.phase2-concept-svg { width: 100%; min-width: 620px; height: auto; background: white; border: 1px solid var(--line); border-radius: 10px; }
.phase2-concept-svg .p2-shell { fill: #f5f2eb; stroke: #24342c; stroke-width: 3; }
.phase2-concept-svg .p2-gable { fill: #d8d1c4; stroke: #24342c; stroke-width: 1.5; }
.phase2-concept-svg .p2-rail { stroke: #52615a; stroke-width: 5; }
.phase2-concept-svg .p2-shelf { stroke: #826f55; stroke-width: 6; }
.phase2-concept-svg .p2-drawer { fill: #e7dfd1; stroke: #826f55; stroke-width: 2; }
.phase2-concept-svg .p2-title { font-size: 18px; font-weight: 700; fill: #24342c; }
.phase2-concept-svg .p2-label { font-size: 14px; fill: #52615a; }

.phase2-scanner-status {
  display: grid;
  gap: 4px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8faf8;
}
.phase2-scanner-status span { color: var(--muted); }
