/* Walkround: semantic tokens first; palettes and dark mode only change tokens. */
:root {
  --bg: #f4f1ea; --surface: #fffdf9; --surface-2: #efe9de; --text: #1f2a2c; --muted: #5d6a6c; --border: #ddd4c4;
  --brand: #0f5c63; --brand-ink: #f4f1ea; --brand-soft: #d7ebea; --accent: #b8860b;
  --ok: #2f7d4f; --ok-soft: #dcefe2; --warn: #9a5b00; --warn-soft: #fbecd0; --bad: #b3261e; --bad-soft: #f8dedb;
  --ai: #4a4fb0; --ai-soft: #e3e4f7; --focus: #f3c969;
  --radius: 14px; --shadow: 0 1px 2px #0000000d, 0 4px 14px #0000000a;
  color-scheme: light;
}
:root[data-palette="heritage"] { --brand: #2f5d3a; --brand-soft: #dbe9dc; --bg: #f2f1e8; }
:root[data-palette="slate"] { --brand: #34495e; --brand-soft: #dde4ec; --bg: #f1f2f4; --surface-2: #e7e9ee; --border: #d3d7de; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12181a; --surface: #1a2225; --surface-2: #222c30; --text: #e6ebea; --muted: #a3b0b1; --border: #33413f;
    --brand: #5fb3b0; --brand-ink: #0e1719; --brand-soft: #1f3a3b; --accent: #e3b552;
    --ok: #7fcf9b; --ok-soft: #1e3527; --warn: #f0b860; --warn-soft: #3a2c14; --bad: #f19a92; --bad-soft: #3d1f1c;
    --ai: #a9adf5; --ai-soft: #262a4a; --shadow: none; color-scheme: dark;
  }
  :root[data-palette="heritage"]:not([data-theme="light"]) { --brand: #86c093; --brand-soft: #22372a; }
  :root[data-palette="slate"]:not([data-theme="light"]) { --brand: #9fb6cf; --brand-soft: #253140; }
}
:root[data-theme="dark"] {
  --bg: #12181a; --surface: #1a2225; --surface-2: #222c30; --text: #e6ebea; --muted: #a3b0b1; --border: #33413f;
  --brand: #5fb3b0; --brand-ink: #0e1719; --brand-soft: #1f3a3b; --accent: #e3b552;
  --ok: #7fcf9b; --ok-soft: #1e3527; --warn: #f0b860; --warn-soft: #3a2c14; --bad: #f19a92; --bad-soft: #3d1f1c;
  --ai: #a9adf5; --ai-soft: #262a4a; --shadow: none; color-scheme: dark;
}
:root[data-theme="dark"][data-palette="heritage"] { --brand: #86c093; --brand-soft: #22372a; }
:root[data-theme="dark"][data-palette="slate"] { --brand: #9fb6cf; --brand-soft: #253140; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; scroll-padding-bottom: 90px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: 84px; }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.grow { flex: 1; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Top bar and tabs */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 1.1rem; }
.brand em { font-style: normal; font-weight: 600; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); background: var(--brand-soft); padding: 2px 6px; border-radius: 6px; }
.tabs { margin-left: auto; display: flex; gap: 4px; }
.tabs a { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; min-height: 44px; }
.tabs a svg { width: 20px; height: 20px; fill: currentColor; }
.tabs a.on { color: var(--brand); background: var(--brand-soft); }
.theme { margin-left: 4px; }
@media (max-width: 760px) {
  .tabs { position: fixed; bottom: 0; left: 0; right: 0; margin: 0; background: var(--surface); border-top: 1px solid var(--border); justify-content: space-around; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); z-index: 30; }
  .tabs a { flex-direction: column; gap: 2px; font-size: .75rem; padding: 6px 18px; }
  .theme { margin-left: auto; }
}

.welcome { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 16px; background: var(--brand-soft); border-bottom: 1px solid var(--border); }
.welcome span { flex: 1 1 240px; }

/* Layout */
.page { max-width: 760px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.back { text-decoration: none; font-weight: 600; min-height: 32px; display: inline-flex; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card.empty { text-align: center; }
details.card summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
details.card[open] summary { margin-bottom: 10px; }
.grid2, .grid3, .grid4 { display: grid; gap: 10px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.grid4 { grid-template-columns: repeat(4, 1fr); }
.span2 { grid-column: span 2; }
.span4 { grid-column: 1 / -1; }
@media (max-width: 520px) { .grid4 { grid-template-columns: repeat(2, 1fr); } .grid2 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 10px; min-height: 44px; width: 100%; font-weight: 400; }
textarea { resize: vertical; }
input:disabled { opacity: .5; }
.title-input { font-size: 1.5rem; font-weight: 700; border-color: transparent; background: transparent; padding-left: 0; }
.title-input:hover, .title-input:focus { border-color: var(--border); padding-left: 10px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 500; min-height: 40px; }
label.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
label.check.big { font-size: 1rem; font-weight: 700; }
.checks { display: flex; flex-wrap: wrap; gap: 0 16px; margin: 10px 0; }
.seg { border: 0; padding: 0; margin: 12px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg legend { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span { display: block; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; color: var(--text); cursor: pointer; height: 100%; }
.seg-opt small { display: block; color: var(--muted); font-weight: 400; }
.seg-opt input:checked + span { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.seg-opt input:focus-visible + span { outline: 3px solid var(--focus); }
@media (max-width: 520px) { .seg { grid-template-columns: 1fr; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
.btn.subtle { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; font-size: .8rem; text-decoration: underline; cursor: pointer; }

/* Badges and notices */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.badge.ai { background: var(--ai-soft); color: var(--ai); }
.badge.notes { background: var(--brand-soft); color: var(--brand); }
.badge.manual { background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.notice { padding: 10px 14px; border-radius: 10px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }

/* Jobs and rooms */
.job-card, .room-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.job-price { font-weight: 700; font-size: 1.1rem; text-align: right; white-space: nowrap; }
.add-room { display: flex; gap: 10px; align-items: end; }
.add-room label { flex: 1; }
.sticky-cta { position: sticky; bottom: 76px; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; box-shadow: 0 6px 20px #0000001f; }
@media (min-width: 761px) { .sticky-cta { bottom: 12px; } }

/* Room page */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; font-size: .8rem; color: var(--muted); }
.stat span { display: block; font-size: 1.1rem; font-weight: 700; color: var(--text); }
.stat.strong { background: var(--brand-soft); border-color: transparent; }
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.photo-card { background: var(--bg); box-shadow: none; margin-bottom: 10px; display: flex; flex-direction: column; gap: 10px; }
.photo-row { display: flex; gap: 12px; }
.thumb { width: 132px; height: 99px; object-fit: cover; border-radius: 10px; background: var(--surface-2); flex: none; }
.thumb.missing { opacity: .4; }
.photo-side { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
@media (max-width: 520px) { .photo-row { flex-direction: column; } .thumb { width: 100%; height: auto; aspect-ratio: 4 / 3; } }
.note-box { position: relative; }
.note-box textarea { padding-right: 50px; }
.note-box .mic { position: absolute; right: 2px; top: 2px; }
.mic.live { color: var(--bad); background: var(--bad-soft); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.ai-summary { margin: 0; padding: 8px 12px; border-left: 3px solid var(--ai); background: var(--ai-soft); border-radius: 0 10px 10px 0; font-size: .9rem; }
.suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .9rem; padding: 8px 12px; background: var(--brand-soft); border-radius: 10px; }
.findings { display: flex; flex-direction: column; gap: 8px; }
.finding { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; }
.finding-top { display: flex; justify-content: space-between; align-items: center; margin: -4px -6px 0 0; }
.finding-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#room-notes > * + * { margin-top: 10px; }
.finding-grid .span2 { grid-column: 1 / -1; }

/* Quote page */
.qroom { border-top: 1px solid var(--border); padding-top: 6px; margin-top: 8px; }
.qroom-head { display: flex; justify-content: space-between; align-items: baseline; }
.qroom-head h3 { margin: 8px 0 4px; }
.qroom-head span { font-weight: 700; }
.qline { display: grid; grid-template-columns: auto auto 1fr auto auto; align-items: center; gap: 8px 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.qline:not(:has(img.mini)) { grid-template-columns: auto 1fr auto auto; }
.qline.extra { grid-template-columns: auto 1fr auto; }
.qline.off .qtext, .qline.off .amt { opacity: .45; text-decoration: line-through; }
.qline.edited .hrs input { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.qline .inc { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
.mini { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.qtext { min-width: 0; }
.hrs { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; }
.hrs input { width: 78px; text-align: right; }
.amt { font-weight: 700; text-align: right; min-width: 82px; display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.extra-grid { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; }
@media (max-width: 560px) {
  .qline, .qline:not(:has(img.mini)) { grid-template-columns: auto 1fr auto; }
  .qline .mini { display: none; }
  .qline .hrs { grid-column: 2; }
  .extra-grid { grid-template-columns: 1fr 1fr; }
  .extra-grid > input { grid-column: 1 / -1; }
}
.totals .trow, .doc-totals .trow { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
.trow.total { font-size: 1.2rem; font-weight: 800; border-top: 2px solid var(--text); margin-top: 4px; padding-top: 10px; }
.your-price { flex-direction: row; align-items: center; color: var(--text); font-size: 1rem; background: var(--brand-soft); border-radius: 10px; padding: 8px 10px !important; margin: 4px 0; }
.your-price span { display: flex; flex-direction: column; }
.your-price small { font-weight: 400; color: var(--muted); font-size: .78rem; }
.your-price input { width: 130px; text-align: right; font-weight: 700; }
.trow.diff.up span:last-child { color: var(--ok); font-weight: 700; }
.trow.diff.down span:last-child { color: var(--warn); font-weight: 700; }
#mat-totals { margin-top: 10px; border-top: 1px solid var(--border); }
.actions { justify-content: flex-start; }

/* Customer copy */
.doc { background: #fff; color: #1d2324; border: 1px solid var(--border); border-radius: 6px; padding: 28px; font-size: .95rem; box-shadow: var(--shadow); }
.doc .muted { color: #5f6869; }
.doc h3 { color: #0f5c63; border-bottom: 1px solid #ddd; padding-bottom: 4px; margin-top: 18px; }
.doc-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 3px solid #0f5c63; padding-bottom: 12px; }
.doc-biz { font-size: 1.35rem; font-weight: 800; }
.doc-meta { text-align: right; }
.doc-title { font-size: 1.3rem; font-weight: 800; color: #0f5c63; letter-spacing: .04em; text-transform: uppercase; }
.doc-to { margin: 14px 0; }
.doc-room-head { display: flex; justify-content: space-between; align-items: baseline; }
.doc-room h4 { margin: 10px 0 2px; }
.doc-room ul { margin: 2px 0 6px; padding-left: 20px; }
.doc-totals { margin: 12px 0; max-width: 380px; margin-left: auto; }
.doc-totals .trow.total { border-color: #1d2324; }
.doc table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.doc th, .doc td { text-align: left; padding: 6px 4px; border-bottom: 1px solid #e3e3e3; }
.doc-materials { border: 1px dashed #b8b8b8; border-radius: 8px; padding: 4px 14px; margin-top: 16px; }
.doc-sign { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 28px; }

/* Rates */
.calc-note { align-self: end; padding: 10px 0; font-weight: 700; color: var(--brand); }
.mat-row { padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px dashed var(--border); }
.defect-table { display: flex; flex-direction: column; gap: 6px; }
.dt-head, .dt-row { display: grid; grid-template-columns: 1fr repeat(4, 74px); gap: 6px; align-items: center; }
.dt-head { font-size: .78rem; font-weight: 700; color: var(--muted); }
.dt-row span { font-size: .9rem; }
.dt-row em { display: block; font-style: normal; font-size: .75rem; }
.dt-row input { padding: 6px; text-align: right; }
@media (max-width: 520px) { .dt-head, .dt-row { grid-template-columns: 1fr repeat(4, 54px); } .dt-head span:not(:first-child) { font-size: .68rem; } }
.how { padding-left: 20px; margin: 0 0 12px; }
.how li { margin-bottom: 4px; }

/* Toast and tour */
.toast { position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: min(92vw, 480px); z-index: 60; transition: .2s; font-weight: 600; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff8f7; }
.toast.ok { background: var(--ok); color: #f5fff8; }
:root[data-theme="dark"] .toast.ok, :root[data-theme="dark"] .toast.bad { color: #10181a; }
.tour-box { position: fixed; z-index: 50; border-radius: 14px; box-shadow: 0 0 0 4px var(--focus), 0 0 0 9999px #0000004d; pointer-events: none; transition: all .25s; }
.tour-card { position: fixed; z-index: 55; left: 50%; bottom: 92px; transform: translateX(-50%); width: min(94vw, 440px); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; box-shadow: 0 10px 30px #0000003d; }
.tour-card.centred { bottom: auto; top: 50%; transform: translate(-50%, -50%); }
.tour-card p { margin: 4px 0 12px; }

/* Print: the customer copy only */
@media print {
  body { background: #fff; padding: 0; }
  .no-print, .topbar, .tabs, .welcome, .toast, .tour-box, .tour-card { display: none !important; }
  .page { padding: 0; max-width: none; }
  .doc { border: 0; box-shadow: none; padding: 0; }
  .doc-materials { break-inside: avoid; }
}
::placeholder { color: var(--muted); opacity: .6; }

/* Round 2: pricing choice, logo, suggestions, status */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.seg.two { grid-template-columns: 1fr 1fr; margin-top: 0; }
@media (max-width: 520px) { .seg.two { grid-template-columns: 1fr; } }
.notice.info { background: var(--brand-soft); color: var(--text); }
.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.logo-preview { max-height: 56px; max-width: 180px; border-radius: 6px; background: #fff; padding: 4px; border: 1px solid var(--border); }
.doc-logo { display: block; max-height: 64px; max-width: 220px; margin-bottom: 6px; }
.suggest-card { border-color: var(--accent); }
.sug-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--border); }
#job-status .row + .row, #job-status p + .row { margin-top: 8px; }
#job-status h2 { margin: 0; }
.adjust { margin-top: 10px; }
.adjust summary { cursor: pointer; font-weight: 600; color: var(--brand); min-height: 36px; display: flex; align-items: center; }

/* Set-up questions page */
.q-page { padding-bottom: 24px; }
.q-choice { border: 0; padding: 0; margin: 0; }
.q-choice legend { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.q-choice .check { min-height: 44px; }
.q-send { border-color: var(--brand); }

.past-box { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; margin: 10px 0; }
.past-box .trow { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; }
.past-box .trow.good strong { color: var(--ok); }
.past-box .trow.off strong { color: var(--warn); }

