:root {
  --brand: #E31B23;
  --brand-dark: #B8141B;
  --ink: #1d1d1f;
  --muted: #62646a;
  --line: #dcdfe4;
  --bg: #f2f3f5;
  --card: #ffffff;
  --pass: #12823B;
  --pass-bg: #e6f4ea;
  --fail: #D3161E;
  --fail-bg: #fde8e8;
  --adv: #B45309;
  --adv-bg: #fef3c7;
  --na: #555;
  --na-bg: #eceef1;
  --radius: 14px;
  --tap: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  min-height: 56px; padding: env(safe-area-inset-top, 0px) 8px 0 8px;
  background: var(--brand); color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
.topbar-back { width: 48px; height: 48px; border: 0; background: transparent; color: #fff; display: grid; place-items: center; border-radius: 12px; }
.topbar-back:active { background: rgba(255,255,255,.18); }
.topbar-back[hidden] { display: none; }
.topbar-title { flex: 1; font-weight: 700; font-size: 18px; padding-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.net { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px; margin-right: 4px; }
.net.offline { background: #fff; color: var(--brand); }

main { max-width: 760px; margin: 0 auto; padding: 14px 14px calc(110px + var(--safe-b)); outline: none; }

/* Headings and text */
h1 { font-size: 24px; margin: 6px 2px 14px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; }
h3 { font-size: 17px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card.tight { padding: 12px 14px; }

/* Forms */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
label.field > span .req { color: var(--brand); }
input[type=text], input[type=email], input[type=date], input[type=time], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: var(--tap);
  font: inherit; color: inherit;
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
  appearance: none; -webkit-appearance: none;
}
textarea { min-height: 76px; resize: vertical; line-height: 1.35; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(227,27,35,.15); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.row4 input { padding: 10px 8px; text-align: center; }
.hint { font-size: 13px; color: var(--muted); margin-top: -6px; margin-bottom: 12px; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); font-weight: 600; }
.toggle input { width: 52px; height: 32px; appearance: none; -webkit-appearance: none; background: #cfd2d8; border-radius: 99px; position: relative; flex: none; transition: background .15s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s; }
.toggle input:checked { background: var(--pass); }
.toggle input:checked::after { left: 23px; }

/* Buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 56px; padding: 12px 18px;
  font: inherit; font-weight: 700; color: #fff; background: var(--brand);
  border: 0; border-radius: 14px; text-decoration: none; cursor: pointer;
}
.btn:active { background: var(--brand-dark); transform: translateY(1px); }
.btn[disabled] { background: #c9cbd0; color: #fff; }
.btn.secondary { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn.secondary:active { background: #f4f4f6; }
.btn.ghost { background: transparent; color: var(--brand); min-height: 48px; }
.btn.danger { background: #fff; color: var(--fail); border: 1.5px solid #f3c2c4; }
.btn.small { min-height: 44px; width: auto; padding: 8px 14px; font-size: 15px; border-radius: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }
.stack > * + * { margin-top: 10px; }

.sticky-actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: rgba(242,243,245,.94); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.sticky-actions .inner { max-width: 732px; margin: 0 auto; display: flex; gap: 10px; }
.sticky-actions .btn { flex: 1; }

/* Segmented result selector */
.seg { display: flex; gap: 6px; margin: 10px 0; }
.seg button {
  flex: 1; min-height: 52px; font: inherit; font-weight: 800; letter-spacing: .02em;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--muted);
}
.seg button.on[data-value=PASS] { background: var(--pass); border-color: var(--pass); color: #fff; }
.seg button.on[data-value=FAIL] { background: var(--fail); border-color: var(--fail); color: #fff; }
.seg button.on[data-value=NA] { background: var(--na); border-color: var(--na); color: #fff; }
.seg button.on:not([data-value=PASS]):not([data-value=FAIL]):not([data-value=NA]) { background: var(--ink); border-color: var(--ink); color: #fff; }

/* Badges */
.badge { display: inline-block; font-size: 12px; font-weight: 800; padding: 4px 9px; border-radius: 99px; letter-spacing: .03em; white-space: nowrap; }
.badge.PASS { background: var(--pass-bg); color: var(--pass); }
.badge.FAIL { background: var(--fail-bg); color: var(--fail); }
.badge.ADV { background: var(--adv-bg); color: var(--adv); }
.badge.NONE { background: var(--na-bg); color: var(--na); }
.badge.draft { background: var(--na-bg); color: var(--na); }
.badge.queued { background: #e7eefc; color: #1d4ed8; }
.badge.uploading { background: #e7eefc; color: #1d4ed8; }
.badge.uploaded { background: var(--pass-bg); color: var(--pass); }
.badge.failed { background: var(--fail-bg); color: var(--fail); }

/* Lists */
.list-item {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border-radius: var(--radius); padding: 14px 14px; margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05); text-decoration: none; color: inherit; min-height: 64px;
}
.list-item:active { background: #fafafa; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .t1 { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .t2 { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .warn { font-size: 13px; color: var(--fail); font-weight: 600; margin-top: 2px; }
.list-item .side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.chev { color: #b4b7bd; flex: none; }

.door-card { background: #fff; border-radius: var(--radius); margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.05); overflow: hidden; }
.door-card .list-item { margin: 0; box-shadow: none; border-radius: 0; }
.door-card .door-actions { display: flex; border-top: 1px solid var(--line); }
.door-card .door-actions button { flex: 1; min-height: 46px; border: 0; background: #fff; font: inherit; font-size: 15px; font-weight: 600; color: var(--muted); }
.door-card .door-actions button + button { border-left: 1px solid var(--line); }
.door-card .door-actions button:active { background: #f4f4f6; }
.door-card .door-actions .del { color: var(--fail); }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }

/* Line items (components / checks / checklist) */
.item { background: #fff; border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.05); border-left: 5px solid var(--line); }
.item.r-PASS { border-left-color: var(--pass); }
.item.r-FAIL { border-left-color: var(--fail); }
.item.r-NA { border-left-color: var(--na); }
.item-head { display: flex; align-items: flex-start; gap: 8px; }
.item-head .name { flex: 1; font-weight: 700; padding-top: 2px; }
.item-head input.name-input { flex: 1; min-height: 44px; font-weight: 700; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); display: grid; place-items: center; flex: none; font-size: 22px; }
.icon-btn:active { background: #f1f1f3; }
.required-note { font-size: 13px; font-weight: 700; color: var(--fail); margin: 6px 0; }
.required-note.ok { color: var(--pass); }
.remedial { background: #fff7f7; border: 1.5px dashed #f2b8bb; border-radius: 12px; padding: 12px; margin-top: 10px; }
.remedial h4 { margin: 0 0 8px; font-size: 14px; color: var(--fail); text-transform: uppercase; letter-spacing: .04em; }
.hidden { display: none !important; }

/* Photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 10px; }
.photo { position: relative; background: #f4f4f6; border-radius: 10px; overflow: hidden; }
.photo img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #e9e9ec; }
.photo .cap { width: 100%; border: 0; border-top: 1px solid var(--line); border-radius: 0; min-height: 44px; padding: 8px 10px; font-size: 14px; background: #fff; }
.photo .del { position: absolute; top: 6px; right: 6px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 20px; line-height: 1; }
.photo .tag { position: absolute; top: 6px; left: 6px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 800; padding: 3px 7px; border-radius: 6px; }
.add-photo { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; margin-top: 10px; border: 1.5px dashed #b9bcc3; border-radius: 12px; background: #fafafb; font: inherit; font-weight: 700; color: var(--ink); }
.add-photo:active { background: #f0f0f2; }
.add-photo.required { border-color: var(--fail); color: var(--fail); background: #fff7f7; }

/* Summary / review */
.summary-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px; border-radius: var(--radius); color: #fff; font-weight: 800; margin-bottom: 12px; }
.summary-banner.PASS { background: var(--pass); }
.summary-banner.FAIL { background: var(--fail); }
.summary-banner.ADV { background: #D97706; }
.summary-banner.NONE { background: #8a8d93; }
.summary-banner .big { font-size: 22px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: #fff; border-radius: 12px; padding: 12px; text-align: center; }
.stat .n { font-size: 26px; font-weight: 800; }
.stat .l { font-size: 13px; color: var(--muted); }
.problems { background: #fff7f7; border: 1.5px solid #f3c2c4; color: #8f1117; border-radius: var(--radius); padding: 12px 14px 4px; margin-bottom: 12px; }
.problems ul { margin: 6px 0 8px; padding-left: 20px; }
.problems li { margin-bottom: 4px; }
.declaration { font-size: 15px; background: #fafafb; border-radius: 12px; padding: 12px; border: 1px solid var(--line); }

/* Signature */
.sig-pad { width: 100%; height: 200px; background: #fff; border: 2px dashed #b9bcc3; border-radius: 14px; display: block; touch-action: none; }
.sig-img { display: block; max-width: 100%; max-height: 120px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; margin-bottom: 10px; }

/* Progress */
.progress { height: 8px; background: #e3e5e9; border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--brand); transition: width .3s; }

/* Toast and modal */
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: #1d1d1f; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; padding: 16px 16px calc(16px + var(--safe-b)); }
.modal[hidden] { display: none; }
.modal .sheet { width: 100%; max-width: 520px; background: #fff; border-radius: 18px; padding: 20px; max-height: 90vh; overflow: auto; }
.modal .sheet h3 { font-size: 19px; }
@media (min-width: 640px) { .modal { align-items: center; } }

.install-banner { display: flex; gap: 12px; align-items: center; background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: 15px; }
.install-banner img { width: 44px; height: 44px; border-radius: 10px; }
.install-banner .x { margin-left: auto; }

.brand-hero { text-align: center; padding: 10px 0 6px; }
.brand-hero img { width: 220px; max-width: 70%; }
.steps { display: flex; gap: 6px; justify-content: center; margin: 4px 0 16px; }
.steps span { width: 34px; height: 5px; border-radius: 99px; background: #d5d7dc; }
.steps span.on { background: var(--brand); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
