:root {
  --bg: #f4f2ee;
  --paper: #ffffff;
  --ink: #1f2328;
  --muted: #6b7076;
  --line: #dedad3;
  --accent: #b6452c;
  --accent-soft: #fbe3dc;
  --sel: #1a73e8;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; gap: 16px; padding: 8px 14px;
  background: var(--paper); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { color: var(--accent); font-size: 20px; }
.proj { font-weight: 400; color: var(--muted); font-size: 13px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 2px; margin-left: auto; }
.tab { border: 0; background: none; padding: 7px 9px; border-radius: 6px; color: var(--muted); font-weight: 600; }
.tab:hover { background: var(--bg); }
.tab.on { background: var(--ink); color: #fff; }
.segs, .floors { display: inline-flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px; }
.seg { border: 0; background: none; padding: 6px 12px; border-radius: 6px; font-size: 13px; color: var(--muted); }
.seg.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.chk { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

.main { flex: 1; display: flex; min-height: 0; }
.toolbar {
  width: 74px; background: var(--paper); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: stretch; padding: 8px 6px; gap: 3px; overflow-y: auto;
}
.toolbar hr { border: 0; border-top: 1px solid var(--line); margin: 6px 2px; width: auto; }
.tool {
  border: 1px solid transparent; background: none; border-radius: 8px; padding: 6px 2px 5px;
  display: flex; flex-direction: column; align-items: center; font-size: 18px; line-height: 1.1;
}
.tool span { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.tool:hover { background: var(--bg); }
.tool.on { background: var(--accent-soft); border-color: var(--accent); }
.tool.on span { color: var(--accent); font-weight: 600; }
.tool.small { font-size: 15px; }
.newst { font-size: 10.5px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; padding: 2px; margin-bottom: 6px; }
.newst select { font-size: 11px; padding: 3px 1px; border: 1px solid var(--line); border-radius: 5px; }

.stage { flex: 1; position: relative; min-width: 0; }
.floors { position: absolute; top: 10px; left: 10px; z-index: 2; box-shadow: 0 1px 3px rgba(0,0,0,.12); background: #ebe8e2; }
.hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 2;
  background: rgba(31,35,40,.86); color: #fff; font-size: 12.5px; padding: 6px 12px; border-radius: 20px;
  pointer-events: none; max-width: 90%; text-align: center;
}
.view { position: absolute; inset: 0; }
#plan-svg { width: 100%; height: 100%; display: block; background: #fbfaf8; touch-action: none; user-select: none; }
body[data-tool="block"] #plan-svg, body[data-tool="stair"] #plan-svg, body[data-tool="wall"] #plan-svg,
body[data-tool="calibrate"] #plan-svg { cursor: crosshair; }
body[data-tool="backdrop"] #plan-svg { cursor: move; }
body[data-tool="window"] #plan-svg, body[data-tool="door"] #plan-svg, body[data-tool="bifold"] #plan-svg,
body[data-tool="opening"] #plan-svg, body[data-tool="label"] #plan-svg { cursor: copy; }

/* plan drawing */
#plan-svg line, #plan-svg rect, #plan-svg polygon, #plan-svg path, #plan-svg circle { vector-effect: non-scaling-stroke; }
#plan-svg text { font-size: calc(var(--fs) * 1px); font-family: system-ui, Arial, sans-serif; }
.g1 { stroke: #ecebe7; stroke-width: 1; }
.g5 { stroke: #dcdad4; stroke-width: 1; }
.fl { stroke: none; }
.fl-existing { fill: rgba(255,255,255,.55); }
.fl-proposed { fill: rgba(253,240,228,.7); }
.fl-demolish { fill: url(#hatchDemo); }
.nb { fill: #ececec; stroke: #b5b5b5; stroke-width: 1; stroke-dasharray: 4 3; }
.nb-t { fill: #999; text-anchor: middle; dominant-baseline: middle; font-style: italic; }
.ghost { fill: none; stroke: #b9b5ae; stroke-width: 1; stroke-dasharray: 5 4; }
.wst { fill: #111; stroke: #111; stroke-width: 2.2; stroke-linejoin: miter; }
.win { fill: #fff; stroke: #111; stroke-width: 1; }
.glz { stroke: #111; stroke-width: 0.8; }
.jamb { stroke: #111; stroke-width: 1; }
.leaf { stroke: #111; stroke-width: 1.4; fill: none; }
.swing { stroke: #555; stroke-width: 0.8; fill: none; stroke-dasharray: 3 2; }
.head { stroke: #555; stroke-width: 0.8; stroke-dasharray: 4 3; }
.op-proposed .leaf, .op-proposed .win { stroke: var(--accent); }
.stair { fill: rgba(255,255,255,.7); stroke: #333; stroke-width: 1; }
.tread { stroke: #555; stroke-width: 0.8; }
.arrow { stroke: #333; stroke-width: 1; }
.arrowhead { fill: #333; }
.up { fill: #333; text-anchor: middle; }
#plan-svg text.up { font-size: calc(var(--fs) * 0.8px); }
.lbl { fill: #2a2e33; text-anchor: middle; dominant-baseline: middle; font-weight: 600; }
.selbox { fill: rgba(26,115,232,.06); stroke: var(--sel); stroke-width: 1.5; stroke-dasharray: 6 3; }
.selline { stroke: var(--sel); stroke-width: 4; stroke-opacity: .6; }
.selpt { fill: var(--sel); }
.handle { fill: #fff; stroke: var(--sel); stroke-width: 1.5; cursor: grab; }
.preview { fill: rgba(182,69,44,.1); stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 3; }
.preview-line { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 3; }
.calline { stroke: #0b8043; stroke-width: 2; }
.hoverside { stroke: var(--sel); stroke-width: 5; stroke-opacity: .5; }
.dim, .dimx { stroke: #0b57d0; stroke-width: 1; }
.dimx { stroke-opacity: .5; }
.dimt { fill: #0b57d0; text-anchor: middle; font-weight: 600; }
.coords { fill: var(--muted); }
.bnd { fill: none; stroke: #d00; stroke-width: 2.5; stroke-linejoin: round; }
.bnd-draft { fill: none; stroke: #d00; stroke-width: 2; stroke-dasharray: 6 4; }
.bnd-pt { fill: #fff; stroke: #d00; stroke-width: 1.5; }
.redline { color: #d00; font-style: normal; }

/* sheets and statement */
.docbar {
  position: absolute; top: 0; left: 0; right: 0; height: 50px; z-index: 2; display: flex; align-items: center; gap: 8px;
  padding: 0 16px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.docbar-t { font-weight: 600; margin-right: auto; font-size: 14px; }
#view-sheets .cards, #view-statement .st-wrap { top: 50px; }
.cards.sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(560px, 1fr)); grid-auto-rows: max-content; align-content: start; }
.sheet-card .card-body { padding: 8px; background: #e9e7e2; }
.sheet-card .card-body svg { width: 100%; height: auto; max-height: none; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.sheet-card figcaption { text-transform: none; }

.st-wrap { position: absolute; inset: 0; overflow: auto; padding: 16px; display: flex; gap: 16px; align-items: flex-start; }
.st-side { width: 330px; flex-shrink: 0; display: flex; flex-direction: column; gap: 16px; }
.st-card { padding: 14px 16px; font-size: 13px; line-height: 1.45; }
.st-card h3 { margin: 0 0 10px; font-size: 14px; }
.st-card ul { margin: 6px 0 0; padding-left: 18px; }
.st-card li { margin-bottom: 4px; }
.pd-overall { font-weight: 700; padding: 8px 10px; border-radius: 6px; margin: 0 0 10px; }
.pd-item { border-top: 1px solid var(--line); padding: 8px 0; }
.pd-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.v-ok { background: #e3f4e6; color: #1e6b2f; }
.v-no { background: #fde7e4; color: #a3271a; }
.v-maybe { background: #fff4d6; color: #7a5c00; }
.f-no { color: #a3271a; }
.f-ok { color: #1e6b2f; }
.f-maybe { color: #7a5c00; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.checks { list-style: none; padding: 0 !important; margin: 0; }
.checks li { padding: 7px 0 7px 26px; border-top: 1px solid var(--line); position: relative; display: flex; flex-direction: column; gap: 2px; }
.checks li span { color: var(--muted); font-size: 12px; }
.checks li::before { position: absolute; left: 2px; top: 7px; font-weight: 700; }
.c-ok::before { content: "✓"; color: #1e6b2f; }
.c-no::before { content: "!"; color: #a3271a; background: #fde7e4; border-radius: 50%; width: 16px; text-align: center; }
.c-info::before { content: "i"; color: #0b57d0; font-style: italic; font-family: Georgia, serif; }

.a4 {
  background: #fff; width: 210mm; max-width: 100%; min-height: 297mm; padding: 20mm 18mm; flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.15); font-family: Arial, Helvetica, sans-serif; font-size: 11pt; line-height: 1.5; color: #111;
}
.a4:focus { outline: 2px solid var(--sel); }
.a4 h1 { font-size: 22pt; margin: 0 0 4pt; }
.a4 h2 { font-size: 13pt; margin: 18pt 0 6pt; }
.a4 .sub { color: #444; margin: 0 0 12pt; }
.a4 table { border-collapse: collapse; width: 100%; margin: 6pt 0; }
.a4 th, .a4 td { border: 1px solid #bbb; padding: 4pt 7pt; text-align: left; vertical-align: top; font-size: 10pt; }
.a4 .kv th { width: 34%; background: #f4f4f4; }
.a4 .grid th { background: #f4f4f4; }
.a4 mark { background: #fff3a0; }
.a4 ul { padding-left: 18pt; }
.a4 li { margin-bottom: 6pt; }

#view-source .cards { top: 50px; }
.cards.src-pages { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.src-page { width: min(1100px, 100%); flex-shrink: 0; }
.src-page img { width: 100%; height: auto; display: block; border-top: 1px solid var(--line); }
.src-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap; }
.src-btns { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.src-loading { padding: 80px 0; text-align: center; color: var(--muted); border-top: 1px solid var(--line); }
.src-empty { padding: 20px 24px; width: min(700px, 100%); }
.src-empty h3 { margin: 0 0 6px; }
.st-wrap .cards.br-sheets { position: static; flex: 1; min-width: 0; padding: 0; display: grid; grid-template-columns: 1fr; gap: 16px; }
.utab { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.utab th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px; padding: 3px 4px; border-bottom: 1px solid var(--line); }
.utab td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
#br-form select + select { margin-top: 4px; font-size: 12px; color: var(--muted); }
#br-form .btn { width: 100%; margin-top: 4px; }

details.sec { border-top: 1px solid var(--line); padding: 8px 0; }
details.sec summary { font-weight: 700; cursor: pointer; padding: 4px 0; font-size: 13.5px; }
details.sec[open] summary { margin-bottom: 8px; }
.chk-row { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; margin: 4px 0 10px; color: #3b4046; }
.chk-row input { margin-top: 2px; }

/* tour: a ring round each part of the page in turn (the rest dimmed), with a card explaining it */
.tour-btn { margin-left: 4px; }
.tourring { position: fixed; z-index: 4500; border: 3px solid #8ab4f8; border-radius: 14px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5); pointer-events: none; transition: top 0.25s, left 0.25s, width 0.25s, height 0.25s; }
.tourbox { position: fixed; z-index: 4600; width: min(330px, calc(100vw - 24px)); background: #fff; color: #1f2a25; border-radius: 16px; padding: 16px 16px 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); font-size: 14px; line-height: 1.5; }
.tourbox h4 { margin: 0 0 6px; font-size: 17px; line-height: 1.2; font-weight: 700; }
.tourbox p { margin: 0 0 12px; }
.tourbox .trow { display: flex; align-items: center; gap: 6px; }
.tourbox .tcount { font-size: 12px; color: #6b6b74; margin-right: auto; font-variant-numeric: tabular-nums; }
.tourbox .btn { padding: 7px 12px; }
.tourbox .btn[hidden] { display: none; }
.tourbox.warn { border: 3px solid #b3261e; }
.tourbox.warn h4 { color: #b3261e; }
.tourbox.warn h4::before { content: "⚠ "; }

/* guide-only warnings */
.guide-warn { background: #fdecea; border: 1px solid #e8a39c; color: #7a1c14; border-radius: 8px; padding: 10px 12px; font-size: 12.8px; line-height: 1.45; margin: 10px 0; }
.guide-warn b { display: block; margin-bottom: 2px; }
.modal .guide-warn { font-size: 13.5px; }
.chk-row.ack { font-weight: 600; color: #3b4046; }
.docbar-warn { color: #b3261e; font-weight: 700; font-size: 12.5px; background: #fdecea; border: 1px solid #e8a39c; border-radius: 6px; padding: 5px 9px; white-space: nowrap; }
#print-root { display: none; }
@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing { overflow: visible; display: block; height: auto; background: #fff; }
  body.printing #print-root { display: block; }
  .print-sheet { width: 420mm; height: 297mm; overflow: hidden; page-break-after: always; break-after: page; }
  .print-sheet:last-child { page-break-after: auto; break-after: auto; }
  .print-sheet svg { display: block; width: 420mm; height: 297mm; }
  .print-doc { box-shadow: none; padding: 0; width: auto; min-height: 0; }
  .print-doc mark { background: none; }
}

/* drawings */
.cards { position: absolute; inset: 0; overflow: auto; padding: 16px; gap: 16px; }
.cards.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); grid-auto-rows: max-content; align-content: start; }
.cards.single { display: flex; justify-content: center; align-items: flex-start; }
.cards.single .card { width: min(900px, 100%); }
.card { margin: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-body { padding: 12px; }
.card-body svg { width: 100%; height: auto; max-height: 60vh; display: block; }
.card figcaption { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 600; text-transform: capitalize; }

#three-host { position: absolute; inset: 0; }
#three-host canvas { display: block; }
.three-msg { position: absolute; top: 50%; left: 0; right: 0; text-align: center; color: var(--muted); pointer-events: none; }

/* panel */
.panel { width: 300px; background: var(--paper); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px 16px 30px; font-size: 13.5px; }
.panel h2 { font-size: 16px; margin: 2px 0 12px; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; }
.f { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.f span { font-size: 12px; color: var(--muted); }
.f input, .f select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%; }
.f input[type=range] { padding: 0; }
.f input:focus, .f select:focus { outline: 2px solid var(--sel); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.note { color: var(--muted); font-size: 12.5px; line-height: 1.45; margin: 4px 0 10px; }
.row { display: flex; gap: 6px; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: #fff; padding: 7px 11px; border-radius: 6px; font-size: 13px; font-weight: 600; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.danger { color: #b3261e; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.small { padding: 4px 9px; font-size: 12px; text-transform: none; }
.btn.file { position: relative; overflow: hidden; display: inline-block; }
.btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.steps { padding-left: 18px; margin: 0; line-height: 1.5; color: #3b4046; }
.steps li { margin-bottom: 4px; }

/* dialogs */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; padding: 18px 20px; width: min(400px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 12px; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.modal input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); }
.modal .hint { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.modal.wide { width: min(820px, 100%); max-height: 90vh; overflow-y: auto; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.thumb { border: 2px solid var(--line); border-radius: 8px; background: #fff; padding: 6px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.thumb img { width: 100%; height: auto; display: block; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.thumb span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.thumb:hover, .thumb:focus { border-color: var(--sel); outline: none; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); max-width: min(560px, 90vw); text-align: center; line-height: 1.45; background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 60; transition: opacity .4s; }
.toast.out { opacity: 0; }

@media (max-width: 900px) {
  .main { flex-direction: column; }
  .toolbar { width: auto; flex-direction: row; flex-shrink: 0; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; padding: 4px 8px; }
  .toolbar hr { display: none; }
  .tool { min-width: 52px; }
  .stage { min-height: 55vh; flex-shrink: 0; }
  .tool { flex-shrink: 0; }
  .newst { flex-direction: row; align-items: center; margin: 0 4px; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--line); max-height: 40vh; }
  .tabs { margin-left: 0; }
  .cards.grid, .cards.sheets { grid-template-columns: 1fr; }
  .st-wrap { flex-direction: column; }
  .st-side { width: 100%; }
  .a4 { padding: 10mm 8mm; min-height: 0; }
  .docbar { overflow-x: auto; }
  .docbar-t { display: none; }
}
