:root {
  --ink: #16181d;
  --ink-fg: #f4f1ea;
  --bg: #f4f2ed;
  --card: #ffffff;
  --fg: #1b1d22;
  --muted: #6b6f78;
  --border: #e2ded4;
  --gold: #e6b422;
  --gold-dark: #b98c0e;
  --gold-soft: #fbf3dc;
  --danger: #c62f24;
  --ok: #1f7a43;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216; --card: #1b1e24; --fg: #ecebe7; --muted: #9aa0aa; --border: #2c3038;
    --gold-soft: #2b2513; --danger: #ef5b4f; --ok: #4cc27c;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.45 var(--font); }
body.no-scroll { overflow: hidden; }
#app { max-width: 36rem; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h2 { font-size: 1rem; margin: 0; }
h3 { font-size: .9rem; margin: 0; }
p { margin: 0; }

/* Shell */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #fff; color: #16181d; border-bottom: 1px solid #e2ded4; padding: calc(8px + env(safe-area-inset-top)) 16px 8px; }
.logo-link { display: block; line-height: 0; flex: none; }
.logo { height: 42px; width: auto; display: block; }
.top .title { padding-left: 12px; border-left: 2px solid #e2ded4; }
.title { font-size: 1.1rem; margin: 0; line-height: 1.2; color: #16181d; }
main { flex: 1; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.tabs { position: fixed; inset: auto 0 0 0; z-index: 20; max-width: 36rem; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { white-space: nowrap; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 2px; font-size: 11px; font-weight: 700; color: var(--muted); text-decoration: none; }
.tabs a.active { color: var(--fg); background: var(--gold-soft); }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.save-banner { position: sticky; top: 0; z-index: 40; background: var(--danger); color: #fff; padding: 10px 14px; font-size: .9rem; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.save-banner .chip { background: rgba(255,255,255,.15); border-color: transparent; color: #fff; }
.notice { background: var(--gold-soft); border: 1px solid var(--gold); border-radius: var(--radius); padding: 10px 12px; font-size: .9rem; }

/* Layout helpers */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.block { display: block; text-decoration: none; }
.card.ready { border-color: var(--gold); }
.space-y > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row { display: flex; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.gap, .gap { gap: 8px; }
.row.between { justify-content: space-between; gap: 8px; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.wide { width: 100%; }
.center { text-align: center; }
.left { text-align: left; }
.block { display: block; }
.pt { padding-top: 8px; }
.pt-s { padding-top: 10px; }
.bold { font-weight: 700; }
.small { font-size: .9rem; }
.xs { font-size: .78rem; }
.muted { color: var(--muted); }
.space-y > .tight { margin-top: 2px; }
.danger { color: var(--danger); }
.ok { color: var(--ok); }
.num { min-width: 1.2em; text-align: center; }
.pill { background: var(--gold); color: #1b1d22; border-radius: 6px; }
.tag { display: inline-block; background: var(--gold-soft); border-radius: 6px; padding: 2px 8px; font-size: .8rem; font-weight: 700; }
.w-cost { width: 6.5rem; flex: none; }

/* Forms */
.label { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.field { width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); font-size: 16px; }
.field:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
.field.invalid { border-color: var(--danger); outline-color: var(--danger); }
.field.date { width: auto; min-height: 36px; padding: 4px 8px; margin-left: auto; }
textarea.field { min-height: 90px; resize: vertical; }
.field-error { display: block; color: var(--danger); font-size: .78rem; margin-top: 4px; }
.field-error[hidden] { display: none; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.check { width: 22px; height: 22px; accent-color: var(--gold-dark); flex: none; }

/* 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 transparent; font-weight: 700; text-decoration: none; text-align: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: #1b1d22; }
.btn-ink { background: var(--ink); color: var(--ink-fg); }
@media (prefers-color-scheme: dark) { .btn-ink { background: #f4f1ea; color: #16181d; } }
.btn-outline { background: var(--card); border-color: var(--border); }
.btn-outline.light { background: transparent; color: inherit; border-color: rgba(255,255,255,.35); }
.btn-ghost { background: transparent; color: inherit; }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn.sq { min-height: 36px; width: 36px; padding: 0; font-size: 1.1rem; }
.btn.tall { min-height: 56px; }
.btn.huge { min-height: 64px; font-size: 1.1rem; }
.link { background: none; border: 0; padding: 6px 0; text-decoration: underline; font-weight: 700; color: inherit; }
.link.light { color: var(--ink-fg); }
.plain { background: none; border: 0; padding: 0; text-align: left; }
.chip { min-height: 34px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); font-size: .82rem; font-weight: 700; }
.chip:disabled { opacity: .45; }
.chip-on { background: var(--ink); color: var(--ink-fg); border-color: var(--ink); }
.chip.danger { color: var(--danger); }
.chip.st { padding: 4px 9px; min-width: 44px; }
.chip.on-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.chip.on-na { background: var(--muted); border-color: var(--muted); color: #fff; }
.chip.on-report { background: var(--danger); border-color: var(--danger); color: #fff; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button { min-height: 40px; border: 0; border-radius: 8px; background: transparent; font-weight: 700; font-size: .9rem; }
.segmented button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 4px 4px 4px 10px; }

/* Inspection */
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--ink); color: var(--ink-fg); padding: 9px 16px; }
.item { border-top: 1px solid var(--border); padding: 9px 12px 9px 16px; }
.item:first-of-type { border-top: 0; }
.saved { border-top: 1px solid var(--border); padding-top: 10px; }

/* Photos */
.stamp-preview { width: 100%; height: auto; border-radius: 10px; display: block; }
.photos > * + * { margin-top: 8px; }
.grid3 .thumb, .photos .grid3 > button { aspect-ratio: 1; padding: 0; border: 4px solid transparent; border-radius: 8px; overflow: hidden; background: var(--border); }
.thumb.sel { border-color: var(--gold); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(10,11,14,.95); display: flex; flex-direction: column; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom)); color: #fff; }
.lb-img { margin: auto; max-width: 100%; max-height: 85vh; object-fit: contain; }

/* Camera */
.camera { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: flex; flex-direction: column; }
.cam-top { display: flex; justify-content: space-between; align-items: center; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
.cam-count { font-weight: 700; font-size: .9rem; }
.cam-labelrow { padding: 0 12px 8px; }
.cam-label { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.2); color: #fff; }
.cam-label::placeholder { color: rgba(255,255,255,.6); }
.cam-stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cam-video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.cam-preview { max-width: 100%; max-height: 100%; object-fit: contain; }
.cam-status { position: absolute; max-width: 22rem; padding: 16px; text-align: center; }
.cam-status[hidden] { display: none; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.on { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .8; } to { opacity: 0; } }
.cam-bottom { display: flex; gap: 12px; justify-content: center; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.cam-shutter { flex: 1; min-height: 60px; font-size: 1.1rem; }
.cam-shutter[hidden], .cam-bottom .btn[hidden] { display: none; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 70; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--ink-fg); padding: 10px 16px; border-radius: 10px; font-size: .9rem; opacity: 0; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
[hidden] { display: none !important; }
.item .link { margin-left: 6px; padding: 0 4px; }

/* Inspection: room counters stack on narrow phones so they never run off screen */
.rooms { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 440px) { .rooms { grid-template-columns: 1fr 1fr; } }
.grid2 > *, .grid3 > * { min-width: 0; }
.stepper .num { font-size: 1.05rem; min-width: 1.6em; }
.stepper .btn.sq { width: 44px; min-height: 44px; }
.finding { border: 1px solid var(--border); border-left: 4px solid var(--danger); border-radius: 10px; padding: 10px 12px; background: var(--card); }
.finding > * + * { margin-top: 8px; }
.card h2 + .block, .card h2 + .field { margin-top: 6px; }

/* Camera flash selector */
.flash-bar { display: flex; gap: 4px; }
.flash-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 46px; height: 46px; padding: 0;
  border: 2px solid transparent; border-radius: 8px; background: transparent; color: #fff; }
.flash-btn svg { width: 20px; height: 20px; fill: currentColor; }
.flash-btn span { font-size: 9px; font-weight: 800; letter-spacing: .04em; line-height: 1; margin-top: 2px; }
.flash-btn.on { border-color: var(--gold); background: rgba(230, 180, 34, .18); color: var(--gold); }
.flash-bar.unsupported .flash-btn { opacity: .35; }
.cam-bottom { align-items: center; } .cam-count { min-width: 3.5em; text-align: center; }
#take-photos { scroll-margin-top: 76px; }

/* Instructions button + popup */
.btn-help { background: #0b436c; color: #fff; min-height: 38px; padding: 6px 14px; font-size: .9rem; border-radius: 8px; flex: none; margin-left: auto; }
.top .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.top > .row { min-width: 0; flex: 1; }
.back { align-self: flex-start; }
.help-overlay { position: fixed; inset: 0; z-index: 80; background: rgba(10, 11, 14, .55); display: flex; align-items: flex-end; justify-content: center; padding: 12px; }
@media (min-width: 600px) { .help-overlay { align-items: center; } }
.help { background: var(--card); color: var(--fg); width: 100%; max-width: 34rem; max-height: calc(100vh - 24px - env(safe-area-inset-top)); display: flex; flex-direction: column;
  border-radius: 16px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.help-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.help-head h2 { font-size: 1.1rem; }
.help-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.help-body section + section { margin-top: 14px; }
.help-body h3 { font-size: .95rem; color: #1f7a43; margin-bottom: 4px; }
@media (prefers-color-scheme: dark) { .help-body h3 { color: var(--ok); } }
.help-body ul { margin: 0; padding-left: 1.2em; }
.help-body li { margin: 4px 0; font-size: .92rem; line-height: 1.45; }


/* Camera: location + time-check status */
.cam-info { padding: 0 12px 8px; font-size: .78rem; color: rgba(255,255,255,.8); line-height: 1.4; }
.cam-info .good { color: #7ee2a0; }
.cam-info .warn { color: #ffd166; }
.clock-warn { margin-top: 6px; background: #c62f24; color: #fff; border-radius: 8px; padding: 8px 10px; font-weight: 700; font-size: .82rem; }
.thumb { position: relative; }
.clock-badge { position: absolute; left: 4px; bottom: 4px; background: #c62f24; color: #fff; font-size: 10px; font-weight: 800; padding: 2px 5px; border-radius: 4px; }
.lb-note { background: #c62f24; color: #fff; border-radius: 8px; padding: 8px 10px; font-size: .88rem; font-weight: 700; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: .95rem; }
.toggle input { width: 22px; height: 22px; accent-color: var(--gold-dark); }
.grid-addr { display: grid; grid-template-columns: 1fr 6.5rem; gap: 12px; } .grid-addr > * { min-width: 0; }
.toast { pointer-events: none; }
fieldset:disabled .field { background: var(--bg); color: var(--muted); }

/* Camera: comment mode */
.cam-bottom.with-comment { flex-wrap: wrap; }
.cam-bottom.with-comment .cam-count { flex-basis: 100%; text-align: center; }
.cam-comment-btn { flex: 1; min-height: 60px; font-size: 1.05rem; background: transparent; color: #fff; border-color: rgba(255,255,255,.5); }
.cam-comment { position: absolute; inset: 0; z-index: 5; background: #111; color: #fff; display: flex; flex-direction: column; gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); }
.cam-comment[hidden] { display: none; }
.cam-comment-text { flex: 0 1 40vh; min-height: 140px; background: #1d2026; color: #fff; border-color: #3a3f48; font-size: 17px; }
.cam-comment-take { min-height: 60px; font-size: 1.1rem; }
/* Sorting General entries */
.sort-card { border-left: 4px solid var(--gold); }
.pick { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 4px solid transparent; background: var(--border); }
.pick.on { border-color: var(--gold); }
.pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pick .view { position: absolute; inset: 0; border: 0; background: transparent; padding: 0; }
.pick .tick { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.45);
  color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; padding: 0; }
.pick.on .tick { background: var(--gold); color: #1b1d22; }

/* Terms of Service (first launch) */
body.gate .top, body.gate .tabs { display: none; }
body.gate main { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.btn-navy { background: #0b436c; color: #fff; box-shadow: 0 3px 0 #072c47; }
.btn-navy:active { transform: translateY(2px); box-shadow: 0 1px 0 #072c47; }
.tos-screen { min-height: calc(100vh - 32px); display: flex; align-items: center; justify-content: center; }
.tos-frame { width: 100%; max-width: 26rem; background: var(--bg); border: 4px solid #0b436c; border-radius: 22px; overflow: hidden; padding-bottom: 28px; }
.tos-band { position: relative; margin-top: 30px; background: #0b436c; color: #fff; display: flex; align-items: center; gap: 14px; padding: 10px 16px 10px 10px; }
.tos-logo { flex: none; background: #fff; border: 3px solid #0b436c; outline: 3px solid #fff; padding: 6px 8px; margin: -24px 0; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.tos-logo img { display: block; height: 52px; width: auto; }
.tos-band h1 { margin: 0; font-size: 1.45rem; line-height: 1.2; }
.tos-welcome { margin: 40px 22px 0; background: var(--card); border: 1.5px solid #0b436c; border-radius: 14px; padding: 18px 20px; }
.tos-welcome p { color: #0b436c; font-size: .98rem; line-height: 1.6; margin: 0; }
@media (prefers-color-scheme: dark) { .tos-welcome p { color: var(--fg); } }
.tos-brand { font-size: 1.15rem; }
.tos-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 26px; padding: 0 22px; }
.tos-step { color: #1f7a43; font-weight: 800; font-size: 1.15rem; margin: 6px 0 0; }
@media (prefers-color-scheme: dark) { .tos-step { color: var(--ok); } }
.tos-btn { width: 100%; max-width: 15rem; min-height: 50px; font-size: 1.05rem; }
.tos-pop { max-width: 40rem; }
.tos-doc h3 { font-size: .95rem; color: #0b436c; margin: 16px 0 6px; }
@media (prefers-color-scheme: dark) { .tos-doc h3 { color: #8cc4ef; } }
.tos-doc p { font-size: .9rem; line-height: 1.55; margin: 0 0 8px; }
.tos-draft { background: var(--gold-soft); border: 1px solid var(--gold); border-radius: 8px; padding: 6px 10px; font-weight: 700; font-size: .82rem !important; }
.tos-doc p { white-space: pre-line; }
.attest { align-items: flex-start; font-size: .9rem; } .attest input { margin-top: 2px; flex: none; }
