:root {
  --film: #e9ece8;        /* drafting film */
  --paper: #fbfbf9;       /* sheet */
  --graphite: #23272b;    /* lines, text */
  --lead: #5c636a;        /* secondary text */
  --rule: #cfd5d1;        /* hairlines */
  --rule-strong: #9aa39e;
  --blue: #7fb3c8;        /* non-photo blue: grid, focus, selection */
  --ink: #2b6f9e;         /* chart marks */
  --red: #c8322b;         /* redline: code issues only */
  --sheet-w: 392px;
  --font: "Archivo", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--film);
  color: var(--graphite);
  font: 400 15px/1.5 var(--font);
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.app { display: grid; grid-template-columns: var(--sheet-w) 1fr; height: 100vh; }

/* ---- parameter sheet (title-block cells) -------------------------------------- */
.sheet {
  background: var(--paper);
  border-right: 1px solid var(--rule-strong);
  display: flex; flex-direction: column;
  min-height: 0;
}
.titleblock { padding: 22px 20px 16px; border-bottom: 1px solid var(--graphite); }
.titleblock h1 {
  margin: 0;
  font-size: 46px; line-height: .95; font-weight: 760; font-stretch: 62%;
  letter-spacing: -.01em;
}
.lede { margin: 10px 0 14px; color: var(--lead); max-width: 34ch; }
.preset { display: flex; align-items: baseline; gap: 10px; font-size: 13px; color: var(--lead); }
.preset select {
  flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--rule-strong); border-radius: 3px;
  background: var(--paper); color: var(--graphite); font-size: 14px;
}

#params { flex: 1; overflow-y: auto; min-height: 0; }
.block { border: 0; margin: 0; padding: 14px 0 0; border-bottom: 1px solid var(--graphite); }
.block legend {
  float: left; width: 100%;
  padding: 0 20px 8px; font-size: 19px; font-weight: 650; font-stretch: 75%;
}
.hint { clear: both; margin: 0 20px 10px; color: var(--lead); font-size: 13px; max-width: 46ch; }

.cells { clear: both; display: grid; border-top: 1px solid var(--rule); }
.c4 { grid-template-columns: repeat(4, 1fr); }
.cell {
  display: flex; flex-direction: column; gap: 1px; min-width: 0;
  padding: 6px 10px 7px 12px;
  border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.cells .cell:nth-child(4n), .cells .span4, .cells .span2:nth-child(2n) { border-right: 0; }
.span2 { grid-column: span 2; }
.span4 { grid-column: span 4; }
.cell:focus-within { background: #eef5f8; box-shadow: inset 2px 0 0 var(--blue); }
.cap { font-size: 12px; font-stretch: 75%; font-weight: 500; color: var(--lead); }
.cell input[type="text"], .cell input[type="number"] {
  width: 100%; border: 0; padding: 0; background: transparent;
  font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.cell input:focus { outline: none; }
.cell.check { justify-content: space-between; }
.cell.check input { width: 18px; height: 18px; accent-color: var(--graphite); }
.unit-input { display: flex; align-items: baseline; gap: 4px; }
.unit-input i { font-style: normal; color: var(--lead); font-size: 13px; }

.seg { display: flex; margin-top: 3px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: block; text-align: center; padding: 4px 6px; font-size: 14px;
  border: 1px solid var(--rule-strong); margin-left: -1px;
}
.seg label:first-child span { border-radius: 3px 0 0 3px; margin-left: 0; }
.seg label:last-child span { border-radius: 0 3px 3px 0; }
.seg input:checked + span { background: var(--graphite); border-color: var(--graphite); color: var(--paper); }
.seg input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 1px; position: relative; z-index: 1; }

body[data-use="residential"] .com-only, body[data-use="commercial"] .res-only { display: none; }

.ranges { clear: both; width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ranges th {
  font-size: 12px; font-stretch: 75%; font-weight: 500; color: var(--lead); text-align: left;
  padding: 4px 12px; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.ranges th:nth-child(n+2), .ranges td:nth-child(n+2) { width: 74px; text-align: right; }
.ranges td { padding: 0 12px; border-bottom: 1px solid var(--rule); height: 34px; }
.ranges td:first-child { font-size: 14px; }
.ranges tr.off td:first-child { color: var(--lead); }
.ranges tr.req td:first-child { font-weight: 600; }
.ranges input {
  width: 52px; text-align: right; border: 1px solid transparent; border-radius: 3px; padding: 2px 4px;
  background: transparent; font-size: 15px;
}
.ranges input:hover { border-color: var(--rule); }
.ranges input:focus { outline: none; border-color: var(--blue); background: #eef5f8; }

.actions { padding: 14px 20px 18px; border-top: 1px solid var(--graphite); background: var(--paper); }
button.primary {
  width: 100%; padding: 12px 16px; border: 0; border-radius: 3px; cursor: pointer;
  background: var(--graphite); color: var(--paper);
  font-size: 17px; font-weight: 650; font-stretch: 87%;
}
button.primary:hover { background: #3a4046; }
button.primary:disabled { opacity: .55; cursor: progress; }
.error { color: var(--red); margin: 8px 0 0; font-size: 14px; min-height: 0; }
.error:empty { display: none; }

/* ---- drafting film --------------------------------------------------------------- */
.film {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background-color: var(--film);
  background-image:
    linear-gradient(rgba(127,179,200,.30) 1px, transparent 1px),
    linear-gradient(90deg, rgba(127,179,200,.30) 1px, transparent 1px),
    linear-gradient(rgba(127,179,200,.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(127,179,200,.14) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
}
.bar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--paper); border-bottom: 1px solid var(--rule-strong);
}
.tabs { display: flex; gap: 2px; }
.tabs button {
  border: 0; background: none; padding: 6px 10px; cursor: pointer; font-size: 16px; font-weight: 600;
  font-stretch: 87%; color: var(--lead); border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--graphite); border-bottom-color: var(--graphite); }
.tabs button:disabled { opacity: .45; cursor: default; }
#count-badge { font-variant-numeric: tabular-nums; color: var(--lead); font-weight: 500; }
.status { margin: 0; flex: 1; color: var(--lead); font-size: 14px; min-width: 12ch; font-variant-numeric: tabular-nums; }
.bar-actions { display: flex; gap: 8px; align-items: center; }
.bar-actions button, .file-btn, a.btn, button.ghost {
  display: inline-block; padding: 6px 12px; border: 1px solid var(--rule-strong); border-radius: 3px;
  background: var(--paper); cursor: pointer; font-size: 14px; text-decoration: none; color: var(--graphite);
}
.bar-actions button:hover, .file-btn:hover, a.btn:hover, button.ghost:hover { border-color: var(--graphite); }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-btn:focus-within { outline: 2px solid var(--blue); outline-offset: 2px; }

#grid { flex: 1; overflow-y: auto; padding: 24px; min-height: 0; }
.empty { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 360px); gap: 32px; align-items: center; max-width: 960px; margin: 6vh auto 0; }
.empty img { width: 100%; opacity: .55; mix-blend-mode: multiply; }
.empty h2 { margin: 0 0 6px; font-size: 24px; font-weight: 650; font-stretch: 80%; }
.empty p { margin: 0; color: var(--lead); max-width: 40ch; }
.sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 22px; }

.plan {
  display: flex; flex-direction: column; text-align: left; padding: 0; cursor: pointer;
  background: var(--paper); border: 1px solid var(--rule-strong); border-radius: 2px;
}
.plan:hover { border-color: var(--graphite); }
.plan[aria-current="true"] { outline: 2px solid var(--blue); outline-offset: 2px; }
.plan .art { position: relative; aspect-ratio: 16 / 9; border-bottom: 1px solid var(--rule); overflow: hidden; }
.plan img { position: absolute; inset: 10px; width: calc(100% - 20px); height: calc(100% - 20px); object-fit: contain; }
.plan.pending .art { display: grid; place-items: center; }
.plan .cap-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 9px 12px 11px; }
.plan h3 { margin: 0; font-size: 17px; font-weight: 650; font-stretch: 80%; }
.plan .meta { margin: 0; color: var(--lead); font-size: 13px; font-variant-numeric: tabular-nums; grid-column: 1; }
.plan .verdict { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.verdict.ok { color: var(--graphite); }
.verdict.bad { color: var(--red); }
.verdict svg { flex: none; }
.plan.pending { cursor: default; border-style: dashed; background: rgba(251,251,249,.55); }
.plan.pending .art { color: var(--lead); font-size: 14px; }
.plan.pending:hover { border-color: var(--rule-strong); }
.plan.pending[data-live] { background: var(--paper); }
.plan.pending img.live { opacity: .9; }
.plan .progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--rule); }
.plan .progress span { display: block; height: 100%; width: 0; background: var(--blue); transition: width .35s linear; }
.plan.arrived .art img { animation: plot .7s steps(14, end) both; }
@keyframes plot { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* ---- analysis --------------------------------------------------------------------- */
#analysis { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#analysis[hidden] { display: none; }
.an-head { display: flex; align-items: center; gap: 16px; padding: 12px 20px; flex-wrap: wrap; background: var(--paper); }
.an-title { flex: 1; min-width: 200px; }
.an-title h2 { margin: 0; font-size: 26px; line-height: 1.1; font-weight: 700; font-stretch: 70%; }
.an-title p { margin: 2px 0 0; color: var(--lead); font-size: 14px; font-variant-numeric: tabular-nums; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.toggle input { accent-color: var(--red); width: 16px; height: 16px; }
.an-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; min-height: 0; border-top: 1px solid var(--rule-strong); }
.viewer { position: relative; overflow: hidden; cursor: grab; background: var(--paper); min-height: 320px; }
.viewer.dragging { cursor: grabbing; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.stage img { display: block; user-select: none; -webkit-user-drag: none; }
.zoom { position: absolute; right: 14px; bottom: 14px; display: flex; background: var(--paper); border: 1px solid var(--rule-strong); border-radius: 3px; }
.zoom button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: 15px; min-width: 38px; }
.zoom button + button { border-left: 1px solid var(--rule); }

.report { overflow-y: auto; background: var(--paper); border-left: 1px solid var(--rule-strong); }
.report section { padding: 16px 20px 18px; border-bottom: 1px solid var(--rule); }
.report h3 { margin: 0 0 8px; font-size: 18px; font-weight: 650; font-stretch: 78%; }
.report .note { margin: 0 0 10px; color: var(--lead); font-size: 13px; }
.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.issues li { display: grid; grid-template-columns: 30px 1fr; gap: 8px; font-size: 14px; line-height: 1.4; }
.issues small { display: block; color: var(--lead); font-size: 12px; }
.issues .warn .msg { color: var(--graphite); }
.delta { width: 26px; height: 23px; position: relative; display: grid; place-items: end center; color: var(--red); font-size: 11px; font-weight: 700; padding-bottom: 2px; }
.delta svg { position: absolute; inset: 0; }
.delta b { position: relative; }
.pass { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 0; }

.bars { display: grid; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 132px 1fr 44px; align-items: center; gap: 8px; font-size: 13px; }
.bar-row .name { color: var(--graphite); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .name em { font-style: normal; color: var(--lead); font-size: 11px; margin-left: 4px; }
.bar-row .track { height: 12px; border-bottom: 1px solid var(--rule); position: relative; }
.bar-row .fill { position: absolute; left: 0; bottom: 0; height: 10px; background: var(--ink); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--lead); }

.spark { width: 100%; height: 92px; display: block; overflow: visible; }
.spark .grid { stroke: var(--rule); stroke-width: 1; }
.spark .line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .area { fill: var(--ink); opacity: .1; }
.spark .cross { stroke: var(--lead); stroke-width: 1; }
.spark .dot { fill: var(--ink); stroke: var(--paper); stroke-width: 2; }
.spark text { font-size: 11px; fill: var(--lead); font-variant-numeric: tabular-nums; }

.schedule { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.schedule th { text-align: left; font-weight: 500; font-stretch: 75%; color: var(--lead); font-size: 12px; padding: 3px 6px 3px 0; border-bottom: 1px solid var(--rule); }
.schedule td { padding: 4px 6px 4px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.schedule td:nth-child(3) { text-align: right; white-space: nowrap; }
.schedule tr.floor td { font-weight: 600; padding-top: 10px; border-bottom-color: var(--rule-strong); }
.rules { margin: 0; padding-left: 18px; font-size: 13px; color: var(--graphite); display: grid; gap: 4px; }

.tip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 280px;
  background: var(--graphite); color: var(--paper); font-size: 13px; padding: 6px 9px; border-radius: 3px;
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .sheet { border-right: 0; border-bottom: 1px solid var(--rule-strong); }
  #params { overflow: visible; }
  .film { min-height: 100vh; }
  .an-body { grid-template-columns: 1fr; }
  .viewer { height: 60vh; }
  .report { border-left: 0; border-top: 1px solid var(--rule-strong); }
  .empty { grid-template-columns: 1fr; }
  #grid { padding: 16px; }
  .bar { padding: 10px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .plan.arrived .art img { animation: none; }
  .plan .progress span { transition: none; }
}
