:root {
  --table: #E7EAE8;
  --sheet: #FFFFFF;
  --graphite: #1F2328;
  --lead: #626970;
  --rule: #CDD3D6;
  --rule-strong: #9AA2A8;
  --blue: #5AA9DD;
  --blue-ink: #1D6CA3;
  --redline: #CC3B2F;
  --redline-wash: #FBEDEB;

  --font: "Archivo", "Segoe UI", system-ui, -apple-system, sans-serif;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2rem;
  --radius: 3px;
  --gutter: clamp(16px, 2.5vw, 32px);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--table);
  color: var(--graphite);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.45;
  font-variation-settings: "wdth" 100;
}

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

:focus-visible {
  outline: 2px solid var(--blue-ink);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------------ top bar */

.bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 18px var(--gutter) 10px;
}

.wordmark {
  font-size: var(--step-2);
  font-weight: 700;
  font-variation-settings: "wdth" 125;
  letter-spacing: -0.01em;
  color: var(--graphite);
  text-decoration: none;
}

.text-button {
  background: none;
  border: 0;
  padding: 4px 0;
  cursor: pointer;
  color: var(--blue-ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.text-button:hover { color: var(--graphite); }

.count { font-variant-numeric: tabular-nums; color: var(--lead); }

.key-banner {
  margin: 0 var(--gutter) 12px;
  padding: 10px 14px;
  border-left: 3px solid var(--redline);
  background: var(--redline-wash);
  color: var(--graphite);
}

/* ------------------------------------------------------------------ layout */

.desk {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: var(--gutter);
  align-items: start;
  padding: 8px var(--gutter) 48px;
}

/* ------------------------------------------------------------------ brief (left column) */

.brief { display: grid; gap: 22px; }

.photos {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.photo-drop {
  grid-column: 1 / -1;
  display: grid;
  gap: 4px;
  place-content: center;
  min-height: 150px;
  padding: 20px;
  border: 1.5px dashed var(--rule-strong);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  text-align: center;
}
.photo-drop:hover, .photo-drop.is-over { border-color: var(--blue); background: rgba(90, 169, 221, 0.06); }
.photos.has-photos .photo-drop { min-height: 0; padding: 9px 12px; }
.photos.has-photos .photo-drop-hint { display: none; }
.photos.has-photos .photo-drop-title { font-weight: 500; color: var(--blue-ink); }
.photos.is-full .photo-drop { display: none; }
.photo-drop-title { font-weight: 600; }
.photo-drop-hint { color: var(--lead); font-size: var(--step--1); }

.photo {
  position: relative;
  margin: 0;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  aspect-ratio: 1;
  overflow: hidden;
}
.photos.single .photo { grid-column: 1 / -1; aspect-ratio: 4 / 3; }
.photo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.photo .pdf {
  display: grid; place-content: center; height: 100%; padding: 12px;
  text-align: center; color: var(--lead); font-size: var(--step--1); word-break: break-word;
}
.photo-remove {
  position: absolute; top: 6px; right: 6px;
  padding: 2px 8px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  font-size: var(--step--1);
  cursor: pointer;
}
.photo-remove:hover { border-color: var(--graphite); }

form { display: grid; gap: 16px; margin: 0; }

fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend, .field > span, .option-label {
  display: block;
  padding: 0;
  margin-bottom: 6px;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--graphite);
}

.size-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--sheet);
}
.size-cell {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 0 0 0 10px;
  border-right: 1px solid var(--rule);
}
.size-cell span { color: var(--lead); font-size: var(--step--1); font-weight: 600; }
.size-cell input {
  width: 100%;
  min-width: 0;
  padding: 10px 8px 10px 0;
  border: 0;
  background: transparent;
  font-size: var(--step-1);
  font-variant-numeric: tabular-nums;
}
.size-cell input:focus { outline: none; }
.size-cell:focus-within { box-shadow: inset 0 -2px 0 var(--blue-ink); }

.unit-switch { display: inline-flex; align-self: stretch; }
.size-row .unit-switch { padding: 4px; gap: 2px; }
.unit-switch button {
  padding: 4px 9px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--lead);
  font-size: var(--step--1);
  cursor: pointer;
}
.unit-switch button[aria-checked="true"] { background: var(--graphite); color: var(--sheet); }
.options .unit-switch { border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: 3px; gap: 2px; background: var(--sheet); }

.hint { margin: 6px 0 0; color: var(--lead); font-size: var(--step--1); max-width: 46ch; }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--rule-strong);
}
.mode-switch button {
  padding: 6px 2px 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--lead);
  font-size: var(--step--1);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.mode-switch button[aria-checked="true"] { color: var(--graphite); border-bottom-color: var(--graphite); }
.mode-switch button:hover { color: var(--graphite); }
.estimate-note { margin-top: 0; color: var(--graphite); }

.field input, .field textarea, .option select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--sheet);
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field textarea:focus, .option select:focus { outline: 2px solid var(--blue-ink); outline-offset: -1px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.options { border-top: 1px solid var(--rule-strong); padding-top: 10px; }
.options summary { cursor: pointer; font-weight: 600; font-size: var(--step--1); padding: 4px 0; }
.options[open] summary { margin-bottom: 10px; }
.option { display: grid; gap: 4px; margin-bottom: 14px; }
.option.check { grid-template-columns: auto 1fr; align-items: start; gap: 10px; font-size: var(--step--1); }
.option.check input { margin: 3px 0 0; accent-color: var(--graphite); }

.primary, .secondary {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.primary { border: 1px solid var(--graphite); background: var(--graphite); color: var(--sheet); }
.primary:hover { background: #343a41; }
.primary:disabled { background: #B9BFC3; border-color: #B9BFC3; color: #F3F4F4; cursor: not-allowed; }
.secondary { border: 1px solid var(--graphite); background: var(--sheet); color: var(--graphite); }
.secondary:hover { background: var(--table); }
.secondary.small { padding: 7px 12px; font-size: var(--step--1); }
#drawButton { width: 100%; font-size: var(--step-1); }
.run-hint { margin-top: -8px; }

.redline-note {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid var(--redline);
  background: var(--redline-wash);
  color: var(--graphite);
}

/* ------------------------------------------------------------------ sheet */

.sheet-area { display: grid; gap: 18px; min-width: 0; }

.sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 236px;
  min-height: min(76vh, 760px);
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  box-shadow: 0 1px 0 rgba(31, 35, 40, 0.06), 0 18px 40px -26px rgba(31, 35, 40, 0.45);
}

.drawing {
  position: relative;
  display: grid;
  place-items: center;
  padding: clamp(16px, 3vw, 40px);
  min-height: 420px;
  border-right: 1px solid var(--graphite);
  outline: 1px solid var(--graphite);
  outline-offset: -10px;
}

.sheet-svg { width: 100%; height: 100%; max-height: 68vh; overflow: visible; }

.empty { max-width: 44ch; text-align: left; justify-self: center; }
.empty-title {
  margin: 0 0 10px;
  font-size: var(--step-3);
  line-height: 1.1;
  font-weight: 650;
  font-variation-settings: "wdth" 112;
  letter-spacing: -0.015em;
}
.empty-body { margin: 0 0 18px; color: var(--lead); }
.empty-small { margin: 12px 0 0; color: var(--lead); font-size: var(--step--1); }

.sheet-prompt {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0; max-width: 34ch; text-align: center; color: var(--blue-ink);
}

.status {
  position: absolute;
  right: 28px; top: 26px;
  display: grid;
  gap: 2px;
  max-width: 36ch;
  padding: 8px 10px;
  text-align: right;
  background: rgba(255, 255, 255, 0.9);
}
.status-stage { font-weight: 600; color: var(--blue-ink); }
.status-time { color: var(--lead); font-size: var(--step--1); font-variant-numeric: tabular-nums; }

/* svg drawing: --u is one screen pixel in drawing units, set from JS */
.sheet-svg { --u: 1px; }
.sheet-svg .construction { stroke: var(--blue); stroke-width: calc(var(--u) * 1); fill: none; }
.sheet-svg .projector { stroke: var(--blue); stroke-width: calc(var(--u) * 0.75); fill: none; opacity: 0.55; }
.sheet-svg.has-result .construction { opacity: 0.35; }
.sheet-svg.has-result .projector { opacity: 0.18; }
.sheet-svg .ink { fill: none; stroke: var(--graphite); stroke-linejoin: round; stroke-linecap: round; }
.sheet-svg .outline { stroke-width: calc(var(--u) * 1.6); }
.sheet-svg .detail { stroke-width: calc(var(--u) * 0.8); }
.sheet-svg .hidden { stroke-width: calc(var(--u) * 0.8); stroke-dasharray: calc(var(--u) * 6) calc(var(--u) * 4); }
.sheet-svg .dim-line { stroke: var(--graphite); stroke-width: calc(var(--u) * 0.7); fill: none; }
.sheet-svg.frames-only .dim-line { stroke: var(--blue-ink); }
.sheet-svg text { font-family: var(--font); fill: var(--graphite); }
.sheet-svg.frames-only text { fill: var(--blue-ink); }
.sheet-svg .dim-text { font-variant-numeric: tabular-nums; }
.sheet-svg .view-label { font-weight: 600; }
.sheet-svg.drawing-in .annotation { opacity: 0; animation: fade-in 0.4s ease 1.2s forwards; }
@keyframes fade-in { to { opacity: 1; } }

/* reading the photo: a single blue scan line across the pinned photo */
.photo.is-reading::after {
  content: "";
  position: absolute; left: 0; right: 0; top: 0;
  height: 2px;
  background: var(--blue);
  box-shadow: 0 0 10px 2px rgba(90, 169, 221, 0.55);
  animation: scan 2.6s ease-in-out infinite alternate;
}
@keyframes scan { from { top: 4%; } to { top: 96%; } }

/* ------------------------------------------------------------------ title strip */

.title-strip { display: flex; flex-direction: column; font-size: var(--step--1); }
.tb-row { padding: 10px 14px; border-bottom: 1px solid var(--rule); }
.tb-row:last-child { border-bottom: 0; }
.tb-label { display: block; color: var(--lead); margin-bottom: 2px; }
.tb-value { display: block; overflow-wrap: anywhere; }
.tb-item { padding-top: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--graphite); }
.tb-name {
  font-size: var(--step-1);
  line-height: 1.2;
  font-weight: 700;
  font-variation-settings: "wdth" 118;
}
.tb-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tb-size-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 4px; }
.tb-size-grid label { display: grid; gap: 1px; color: var(--lead); }
.tb-size-grid input {
  width: 100%;
  padding: 4px 5px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  font-size: var(--step-0);
  font-variant-numeric: tabular-nums;
  color: var(--graphite);
}
.tb-size-grid input:disabled { color: var(--graphite); -webkit-text-fill-color: var(--graphite); opacity: 1; }
.tb-size-grid input:not(:disabled) { border-color: var(--rule-strong); background: var(--sheet); }
.tb-source { margin: 6px 0 0; color: var(--lead); }
.tb-lock { display: flex; align-items: center; gap: 8px; margin-top: 8px; cursor: pointer; }
.tb-lock input { margin: 0; accent-color: var(--graphite); }
#resizeButton { margin-top: 8px; }
.tb-block-base { font-weight: 600; overflow-wrap: anywhere; }
.tb-block-views { color: var(--lead); }
.tb-actions { margin-top: auto; display: grid; gap: 10px; border-top: 1px solid var(--graphite); border-bottom: 0; padding-bottom: 14px; }
.tb-actions .primary { width: 100%; }

/* ------------------------------------------------------------------ assumptions (redline notes) */

.assumptions {
  padding: 0 4px;
  max-width: 78ch;
}
.assumptions h2 {
  margin: 0 0 6px;
  font-size: var(--step-0);
  color: var(--redline);
}
.assumptions ul { margin: 0; padding-left: 18px; color: var(--graphite); }
.assumptions li { margin: 3px 0; }
.assumptions li::marker { color: var(--redline); }

.scale-help { padding: 0 4px; max-width: 78ch; }
.scale-help h2 { margin: 0 0 4px; font-size: var(--step-0); }
.scale-help p { margin: 0 0 8px; color: var(--lead); }
.scale-help dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.scale-help dt { font-weight: 600; }
.scale-help dd { margin: 0; }
.scale-help kbd {
  padding: 0 4px;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  background: var(--sheet);
  font-family: inherit;
  font-size: 0.92em;
}

/* ------------------------------------------------------------------ library drawer */

.library {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(380px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--sheet);
  border-left: 1px solid var(--rule-strong);
  box-shadow: -18px 0 40px -28px rgba(31, 35, 40, 0.5);
  z-index: 20;
  animation: slide-in 0.22s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.library-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 18px 20px 12px; border-bottom: 1px solid var(--graphite);
}
.library-head h2 { margin: 0; font-size: var(--step-1); font-variation-settings: "wdth" 115; }
.library-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.library-item { display: grid; grid-template-columns: 84px 1fr; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--rule); }
.library-item.is-current { background: rgba(90, 169, 221, 0.08); }
.library-open { display: contents; cursor: pointer; }
.library-thumb {
  width: 84px; height: 64px; object-fit: contain;
  border: 1px solid var(--rule); background: var(--sheet);
}
.library-thumb.placeholder { display: grid; place-content: center; color: var(--lead); font-size: 11px; }
.library-meta { min-width: 0; display: grid; align-content: start; gap: 2px; }
.library-name {
  font-weight: 600; text-align: left; background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--graphite); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.library-name:hover { color: var(--blue-ink); text-decoration: underline; }
.library-sub { color: var(--lead); font-size: var(--step--1); }
.library-sub.failed { color: var(--redline); }
.library-row-actions { display: flex; gap: 12px; font-size: var(--step--1); }
.library-row-actions .danger { color: var(--redline); }
.library-empty, .library-spend { padding: 16px 20px; margin: 0; color: var(--lead); font-size: var(--step--1); }
.library-spend { border-top: 1px solid var(--rule); }

/* ------------------------------------------------------------------ drag and drop */

.drop-veil {
  position: fixed; inset: 0; z-index: 30;
  display: none; place-items: center;
  background: rgba(231, 234, 232, 0.86);
  border: 3px dashed var(--blue);
  pointer-events: none;
}
.drop-veil p { font-size: var(--step-3); font-weight: 650; font-variation-settings: "wdth" 112; color: var(--blue-ink); }
body.is-dragging .drop-veil { display: grid; }

/* ------------------------------------------------------------------ small screens */

@media (max-width: 980px) {
  .desk { grid-template-columns: 1fr; }
  .sheet { grid-template-columns: 1fr; }
  .drawing { border-right: 0; border-bottom: 1px solid var(--graphite); min-height: 320px; }
  .title-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tb-item, .tb-actions, .tb-size { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .size-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .size-row .unit-switch { grid-column: 1 / -1; border-top: 1px solid var(--rule); justify-content: flex-end; }
  .field-pair { grid-template-columns: 1fr; }
  .title-strip { grid-template-columns: 1fr; }
  .empty-title { font-size: var(--step-2); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet-svg.drawing-in .annotation { animation: none !important; opacity: 1 !important; }
  .photo.is-reading::after { animation: none; top: 50%; }
  .library { animation: none; }
}
