:root {
  --navy: #01223D; --pink: #FC0279;
  --bg: #f4f5f7; --panel: #ffffff; --line: #d9dde3; --text: #1f2933; --muted: #6b7682;
  --accent: #01223D; --accent-2: #FC0279; --warn: #9a5b00; --danger: #b42318; --ok: #047857;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; overflow: hidden; }
button, .btnlike { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 6px 11px; border-radius: 5px; cursor: pointer; white-space: nowrap; display: inline-block; }
button:hover:not(:disabled), .btnlike:hover { border-color: #aab3bd; background: #f8f9fa; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #02182c; }
button.danger { color: var(--danger); border-color: #f0c4c0; }
button.ghost, .btnlike.ghost { background: transparent; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 5px; padding: 5px 8px; background: #fff; color: var(--text); width: 100%; }
input[type=range] { padding: 0; }
input[type=checkbox], input[type=radio] { width: auto; margin: 0 6px 0 0; }
input.short { width: 90px; }
label { display: block; margin: 6px 0; color: var(--muted); font-size: 12px; }
label input, label select, label textarea { margin-top: 3px; color: var(--text); font-size: 14px; }
label.check, label.radio { display: flex; align-items: center; color: var(--text); font-size: 13px; }
label.radio input.short { margin: 0 0 0 8px; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; gap: 18px; padding: 8px 14px; background: #FFFFFF; color: var(--navy); border-bottom: 1px solid #E5E7EB; position: relative; z-index: 3; }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px; background: var(--pink); pointer-events: none; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0; font-size: 17px; line-height: 1; }
.brand-mark { width: 28px; height: 28px; display: block; flex: none; }
.brand-word { font-weight: 750; letter-spacing: -0.4px; color: var(--navy); }
.brand-bot { color: var(--pink); }
.brand small { opacity: .55; font-weight: 400; font-size: 12px; margin-left: 2px; color: var(--navy); }
.steps { display: flex; gap: 2px; flex: 1; }
.steps button { background: transparent; border: none; color: var(--navy); padding: 7px 12px; border-radius: 4px; }
.steps button span { display: inline-block; width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 50%; border: 1px solid var(--navy); font-size: 11px; margin-right: 6px; }
.steps button.active { background: #fff4f8; color: var(--pink); }
.steps button.active span { background: var(--pink); color: #fff; border-color: var(--pink); }
.steps button:hover:not(.active) { background: #f3f4f6; color: var(--navy); }
.projbar { display: flex; gap: 6px; align-items: center; }
.projbar .ghost { color: var(--navy); border-color: #E5E7EB; }
.projbar .ghost:hover { background: #f3f4f6 !important; }
.proj-name { width: 220px; background: #fff; border-color: #E5E7EB; color: var(--navy); }

main { flex: 1; min-height: 0; position: relative; }
.view { display: none; height: 100%; }
.view.active { display: flex; }
#view-draft.active { flex-direction: column; }
.panel { width: 310px; flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 10px 14px 20px; overflow-y: auto; }
.panel.right { border-right: none; border-left: 1px solid var(--line); width: 260px; }
.panel h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 16px 0 6px; font-weight: 650; }
.panel h2:first-child { margin-top: 4px; }
.row { display: flex; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.row.tight label { flex: 1; margin: 0; }
.sub { padding-left: 22px; }
.status { font-size: 12px; color: var(--muted); margin: 6px 0; }
.fine { font-size: 12px; color: var(--muted); line-height: 1.45; }
.muted { color: var(--muted); font-size: 12px; }
.warn { color: var(--warn); font-size: 12px; min-height: 0; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 5px; margin-bottom: 4px; font-size: 13px; }
.list li.active { border-color: var(--pink); background: #fff4f8; }
.list li .grow { flex: 1; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li button { padding: 2px 7px; font-size: 12px; }
.dropzone { border: 1.5px dashed #b9c1ca; border-radius: 6px; padding: 18px 10px; text-align: center; cursor: pointer; color: var(--text); font-size: 13px; }
.dropzone.over { border-color: var(--pink); background: #fff4f8; }
.thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.thumb { border: 1px solid var(--line); border-radius: 5px; overflow: hidden; background: #fff; font-size: 11px; }
.thumb img { display: block; width: 100%; aspect-ratio: 16/10; object-fit: cover; background: #222; cursor: pointer; }
.thumb div { display: flex; justify-content: space-between; align-items: center; padding: 3px 5px; }
.thumb button { padding: 1px 6px; font-size: 11px; }

.stage { flex: 1; min-width: 0; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.stage.dark { background: #111827; }
.stage video { max-width: 100%; max-height: 100%; }
.stage-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; color: #9aa5b1; padding: 30px; line-height: 1.6; pointer-events: none; }
.stage.split { display: grid; grid-template-columns: 1fr 34%; }
.pane { position: relative; height: 100%; min-width: 0; overflow: hidden; }
.pane canvas { display: block; }
.pane.preview { background: #e9ecef; border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.pane.preview canvas { flex: 1; width: 100%; min-height: 0; }
.pane-title { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); padding: 8px 10px; }
.loupe { position: absolute; right: 10px; top: 10px; width: 160px; height: 160px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,.4); pointer-events: none; }

.toolbar { display: flex; gap: 4px; align-items: center; padding: 6px 10px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar button { padding: 5px 10px; }
.toolbar button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.toolbar label.check { margin: 0 4px; font-size: 12px; }
.toolbar .scale-tool { border-color: #86b7a3; color: var(--ok); }
.draft-body { flex: 1; display: flex; min-height: 0; }
.canvas-stage { background: #e9ecef; display: block; }
.canvas-stage canvas { position: absolute; inset: 0; touch-action: none; }
.banner { position: absolute; z-index: 2; top: 8px; left: 50%; transform: translateX(-50%); padding: 5px 12px; border-radius: 4px; font-size: 12px; pointer-events: none; max-width: 90%; text-align: center; }
.banner.unscaled { background: #fff4e0; color: #7a4a00; border: 1px solid #f0d199; }
.banner.est { background: #fff8db; color: #6b5900; border: 1px solid #ecdd95; }
.banner.ok { background: #e7f6ef; color: #035e44; border: 1px solid #a8dcc4; }
.statusbar { display: flex; justify-content: space-between; gap: 20px; padding: 4px 12px; background: #fff; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
#readout { color: var(--text); font-variant-numeric: tabular-nums; }
.scale-card { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 13px; line-height: 1.45; margin-bottom: 6px; }
.scale-card.unscaled { border-color: #f0d199; background: #fffaf0; }
.scale-card.est { border-color: #ecdd95; background: #fffdf2; }
.scale-card.ok { border-color: #a8dcc4; background: #f4fbf7; }
.scale-card b { display: block; }
#props .kv { display: grid; grid-template-columns: 90px 1fr; gap: 3px 8px; font-size: 13px; margin: 6px 0; }
#props .kv span:nth-child(odd) { color: var(--muted); font-size: 12px; }

.paper-stage { background: #c9ced4; padding: 20px; }
.paper-stage canvas { box-shadow: 0 2px 12px rgba(0,0,0,.25); background: #fff; max-width: 100%; max-height: 100%; }

dialog { border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; width: min(440px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15,23,32,.45); }
dialog h3 { margin: 0 0 10px; font-size: 16px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 14px 0 0; }
dialog.help { width: min(720px, 94vw); max-height: 88vh; overflow-y: auto; line-height: 1.5; }
dialog.help h4 { margin: 14px 0 4px; font-size: 13px; }
dialog.help p, dialog.help li { font-size: 13px; }
.keys { color: var(--muted); }
pre#selfTestOut { font-size: 11.5px; background: #f6f7f9; padding: 8px; border-radius: 5px; white-space: pre-wrap; max-height: 260px; overflow: auto; }
pre#selfTestOut:empty { display: none; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 8px 14px; border-radius: 6px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; }

@media (max-width: 820px) {
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; gap: 6px; }
  .steps { order: 3; width: 100%; overflow-x: auto; }
  .proj-name { width: 130px; }
  .view.active { flex-direction: column; }
  .panel, .panel.right { width: 100%; border-right: none; border-bottom: 1px solid var(--line); max-height: 45vh; }
  .stage { min-height: 50vh; }
  .stage.split { grid-template-columns: 1fr; grid-template-rows: 1fr 40%; }
  .draft-body { flex-direction: column; }
}
#props button { white-space: normal; text-align: left; }
#props .row button { flex: 1 1 auto; }

/* v1.1 AI cleanup compare */
.compare { display: flex; gap: 10px; max-width: 80vw; }
.compare figure { margin: 0; flex: 1; min-width: 0; }
.compare img { width: 100%; max-height: 60vh; object-fit: contain; background: #111; border-radius: 4px; }
.compare figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* v1.2.0 plan box + photo zone */
.plan-box { display:flex; flex-direction:column; gap:6px; border:1px solid #f3c2d9; background:#fff7fb; border-radius:8px; padding:10px 12px; margin:8px 0; }
.plan-box .btnlike { align-self:flex-start; text-decoration:none; }
.dropzone.photos { margin-top:8px; }
.btnlike.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- v1.2.0 phone app ---- */
.phone-only { display: none; }
@media (max-width: 820px), (pointer: coarse) and (max-width: 1100px) {
  body.phone .phone-only { display: revert; }
  body.phone .desk-capture { display: none; }
  body.phone .desk-capture.open { display: block; }
  body.phone { overflow: auto; height: auto; min-height: 100%; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  body.phone .view.active > .panel:last-child, body.phone .view.active > aside.panel, body.phone .draft-body > :last-child { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  body.phone button, body.phone .qc-btn, body.phone .btnlike { touch-action: manipulation; }
  body.phone canvas, body.phone .thumb img, body.phone video { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  body.phone .topbar { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  body.phone .projbar > *:not(#btnHelp):not(#btnSave) { display: none; }
  body.phone .steps button { padding: 6px 8px; font-size: 12px; }
  body.phone .view.active { display: flex; flex-direction: column; }
  body.phone .stage { order: -1; min-height: 46vh; }
  body.phone .panel { max-height: none; }
  body.phone button, body.phone .btnlike { min-height: 44px; font-size: 15px; }
  body.phone input, body.phone select, body.phone textarea { font-size: 16px; } /* no iOS zoom on focus */
  body.phone .desk-only { display: none; }
  body.phone #steps { display: none; }
  body.phone #view-capture .stage { display: none; }
  body.phone #view-capture.cam-on .stage { display: flex; }
  body.phone .toast { bottom: calc(80px + env(safe-area-inset-bottom)); max-width: 90vw; }
  body.phone .loupe { width: 110px; height: 110px; left: 10px; right: auto; }
  .quick-capture { display: flex; flex-direction: column; gap: 10px; padding: 4px 0 10px; }
  .qc-lead { margin: 0; font-size: 14px; color: var(--muted); }
  .qc-btn { display: block; text-align: center; padding: 16px; border-radius: 12px; border: 1.5px solid var(--line); font-size: 17px; font-weight: 600; background: #fff; }
  .qc-btn.primary { background: var(--pink, #FC0279); border-color: var(--pink, #FC0279); color: #fff; }
  .qc-more summary { color: var(--muted); padding: 8px 0; }
  body.phone #toolbar { position: sticky; top: 0; z-index: 5; overflow-x: auto; flex-wrap: nowrap; background: #fff; }
  body.phone #toolbar [data-tool="rect"], body.phone #toolbar [data-tool="dim"], body.phone #toolbar [data-tool="text"], body.phone #toolbar [data-tool="pan"], body.phone #toolbar label.check, body.phone #btnRedo { display: none; }
  .done-btn { background: #e9f7ee; border-color: #8fd1a6; }
  #mnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; align-items: center; gap: 8px; padding: 8px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(1,34,61,.08); }
  #mnav button { flex: 0 0 auto; min-width: 88px; }
  #mStep { flex: 1; text-align: center; font-size: 13px; color: var(--muted); }
}
.install-hint { position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 45; display: flex; align-items: center; gap: 10px; background: var(--navy, #01223D); color: #fff; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.install-hint button { color: #fff; border-color: rgba(255,255,255,.3); background: transparent; min-height: 32px; }
