:root {
  --blue: #0a5dc2; --blue-d: #084a9b; --green: #3cb54a; --ink: #1b1d22; --muted: #6b7180;
  --line: #d9dde6; --bg: #f3f5f9; --card: #fff; --warn: #c0392b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px; background: #fff; border-bottom: 1px solid var(--line); }
.logo { height: 64px; }
.top-title { flex: 1; font-weight: 700; font-size: 20px; color: var(--blue); }
.steps { display: flex; gap: 6px; padding: 10px 20px; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: calc(65px + env(safe-area-inset-top)); z-index: 4; }
.steps button { flex: 1; min-width: 120px; padding: 12px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font: inherit; font-size: 15px; color: var(--muted); }
.steps button.active { background: var(--blue); color: #fff; border-color: var(--blue); font-weight: 600; }
main { max-width: 900px; margin: 0 auto; padding: 16px 16px 120px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 16px; }
h2 { margin: 0 0 12px; font-size: 19px; color: var(--blue); }
h3 { margin: 20px 0 8px; font-size: 16px; }
label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); font-weight: 600; }
label small { font-weight: 400; }
input, textarea { display: block; width: 100%; margin-top: 5px; padding: 12px 13px; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; background: #fff; -webkit-appearance: none; }
input:focus, textarea:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.span2 { grid-column: span 2; }
label.check { display: flex; align-items: flex-start; gap: 12px; color: var(--ink); font-weight: 400; font-size: 16px; margin: 12px 0; }
label.check input { width: 26px; height: 26px; margin: 0; flex: none; padding: 0; -webkit-appearance: auto; accent-color: var(--blue); }
.check-line { display: flex; align-items: center; gap: 10px; }
.check-line label.check { flex: 1; }
.check-line input:not([type]) { width: 140px; margin: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 12px 0; }
.row .lbl { font-size: 14px; color: var(--muted); font-weight: 600; min-width: 110px; }
.row label.check { margin: 0; }
.row input.short { width: 140px; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.chips button { padding: 11px 18px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font: inherit; font-size: 16px; }
.chips button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.sub { border-left: 3px solid var(--line); padding-left: 14px; margin: 10px 0; }
.note { color: var(--muted); font-size: 14px; margin: 6px 0; }
.btn { padding: 13px 22px; border: 0; border-radius: 10px; background: var(--blue); color: #fff; font: inherit; font-weight: 600; }
.btn:active { background: var(--blue-d); }
.btn.ghost { background: #fff; color: var(--blue); border: 1px solid var(--line); }
.btn.big { width: 100%; padding: 18px; font-size: 19px; }
.btn[disabled] { opacity: .45; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-between; gap: 12px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); z-index: 5; }
.nav .btn { min-width: 140px; }

.struct { display: grid; grid-template-columns: 1.2fr auto 2fr auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.struct input { margin: 0; }
.struct .yn { display: flex; gap: 6px; }
.struct .yn button { padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: inherit; }
.struct .yn button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.struct .x { border: 0; background: none; font-size: 24px; color: var(--muted); padding: 6px; }

.pad-slot { margin: 12px 0; }
.pad-box { display: flex; align-items: center; justify-content: center; height: 110px; border: 2px dashed var(--line);
  border-radius: 12px; background: #fafbfd; color: var(--muted); font-size: 16px; }
.pad-box img { max-height: 96px; max-width: 90%; }
.pad-box.done { border-style: solid; border-color: var(--green); background: #fff; }
.pad-label { font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

.init-row { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.init-row > span { flex: 1; font-size: 15px; }
.init-row .tap { width: 120px; height: 52px; flex: none; border: 2px dashed var(--blue); border-radius: 10px; background: #fff;
  color: var(--blue); font: inherit; font-size: 14px; font-weight: 600; }
.init-row .tap.on { border: 2px solid var(--green); padding: 2px; }
.init-row .tap img { max-height: 44px; max-width: 110px; }
.terms { font-size: 14px; margin: 6px 0 10px; }
.terms summary { color: var(--blue); font-weight: 600; padding: 8px 0; }
.terms #termsText { max-height: 360px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.terms p { margin: 6px 0; }

.missing { color: var(--warn); font-size: 15px; margin-bottom: 10px; }
.missing:empty { display: none; }

.modal { position: fixed; inset: 0; background: rgba(15, 20, 30, .55); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: #fff; border-radius: 16px; padding: 16px; width: min(860px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
#padCanvas { width: 100%; height: 300px; border: 1px solid var(--line); border-radius: 12px; touch-action: none; background:
  linear-gradient(transparent calc(100% - 70px), var(--line) calc(100% - 70px), var(--line) calc(100% - 68px), transparent calc(100% - 68px)); }
.busy { position: fixed; inset: 0; background: rgba(255, 255, 255, .75); z-index: 30; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 600; color: var(--blue); }
[hidden] { display: none !important; }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .struct { grid-template-columns: 1fr auto; } .struct .notes { grid-column: span 2; }
  .top-title { font-size: 16px; }
}

.pdfview { position: fixed; inset: 0; z-index: 25; background: #e6e9f0; display: flex; flex-direction: column; }
.pdfbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: #fff; border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
.pdfbar .btns { margin: 0; }
.pdfbar b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdfpages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px; -webkit-overflow-scrolling: touch; }
.pdfpages canvas { background: #fff; box-shadow: 0 1px 6px rgba(20, 30, 60, .18); max-width: 100%; height: auto; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 15px; max-width: calc(100% - 32px); }

.demo-band { background: #fff6dc; color: #6b5200; font-size: 14px; padding: 8px max(16px, env(safe-area-inset-left)); border-bottom: 1px solid #f0e2b0; }

.addr { position: relative; }
.addr-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 8; margin-top: 4px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(20, 30, 60, .14); overflow: hidden; }
.addr-list button { display: block; width: 100%; text-align: left; padding: 13px 14px; border: 0; border-bottom: 1px solid var(--line);
  background: #fff; font: inherit; color: var(--ink); }
.addr-list button:last-child { border-bottom: 0; }
.addr-list button:active, .addr-list button:hover { background: #eef3fc; }
.addr-list small { display: block; color: var(--muted); font-size: 14px; font-weight: 400; }
.addr-list .google { padding: 6px 14px; text-align: right; font-size: 11px; color: var(--muted); font-weight: 400; }

/* v3: phases, validation, shingle pickers */
select { display: block; width: 100%; margin-top: 5px; padding: 12px 13px; font: inherit; color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; background: #fff; -webkit-appearance: none; appearance: none;
  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; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.steps button.phase { border-style: dashed; }
.steps button:disabled { opacity: .45; }
.steps button.active:disabled { opacity: 1; }
.phase-band { padding: 12px max(16px, env(safe-area-inset-left)); font-weight: 600; font-size: 16px; }
.phase-band.customer { background: #e8f7ea; color: #1d6b2a; }
.phase-band.final, .phase-band.done { background: #e8f0fc; color: var(--blue-d); }
.invalid, input.invalid, select.invalid, textarea.invalid { border-color: var(--warn) !important; background-color: #fff5f4; }
.chips.invalid, .row.invalid, .yn.invalid { outline: 2px solid var(--warn); outline-offset: 4px; border-radius: 12px; }
.chips.locked button { pointer-events: none; }
.chips.locked button:not(.on) { opacity: .4; }
.struct { grid-template-columns: 1.2fr auto auto; }
.struct .snotes { grid-column: 1 / -1; }
.struct .yn .note { margin-right: 6px; }
.inline-num input { max-width: 260px; }
.summary { display: grid; gap: 8px; margin-bottom: 14px; }
.summary div { display: grid; grid-template-columns: 190px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.summary span { color: var(--muted); font-size: 14px; }
.summary b { min-width: 0; overflow-wrap: anywhere; }
.cooling { font-weight: 700; border: 1.5px solid var(--ink); border-radius: 10px; padding: 12px 14px; font-size: 16px; }
@media (max-width: 760px) {
  .grid3 { grid-template-columns: 1fr; }
  .summary div { grid-template-columns: 1fr; gap: 2px; }
  .struct { grid-template-columns: 1fr auto; }
  .struct .yn { grid-column: 1 / -1; }
}

#btnPreview { margin-bottom: 14px; }

/* T&C always visible */
.terms { font-size: 16px; line-height: 1.5; margin: 6px 0 12px; }
.terms #termsText { max-height: 480px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; background: #fafbfd; -webkit-overflow-scrolling: touch; }
.terms p { margin: 10px 0; }
h3 { font-size: 18px; }

.check-line input[list] { width: 180px; margin: 0; }

.trim-item { margin-bottom: 6px; }

/* remote signing */
.handoff-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn.big.ghost { background: #fff; color: var(--blue); border: 2px solid var(--blue); }
.linkbox { display: flex; gap: 8px; }
.linkbox input { margin: 0; min-width: 0; font-size: 14px; }
.card.center { text-align: center; padding: 40px 20px; }
.card.center .btns { justify-content: center; }
.modal-box.wide { width: min(980px, 100%); max-height: 86vh; overflow-y: auto; }
.sent-list { display: grid; gap: 10px; }
.sent-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.sent-item .top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.sent-item .meta { color: var(--muted); font-size: 14px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.pill.sent { background: #fff3d6; color: #7a5600; }
.pill.opened { background: #e3edfb; color: var(--blue-d); }
.pill.signed { background: #e3f5e6; color: #1d6b2a; }
.pill.expired, .pill.cancelled { background: #eee; color: #666; }
.sent-item .btns { margin-top: 4px; }
.sent-item .btns .btn { padding: 9px 14px; font-size: 15px; }
body.remote-mode #steps, body.remote-mode #btnNew, body.remote-mode #btnSent, body.remote-mode .nav { display: none !important; }
@media (max-width: 760px) { .handoff-btns { grid-template-columns: 1fr; } }
.phase-band.remote, .phase-band.sent { background: #fff6dc; color: #6b5200; }

.field-title { font-size: 14px; font-weight: 700; color: var(--ink); margin: 12px 0 4px; }
.check-line input.wide { width: 320px; max-width: 50%; margin: 0; }
.upg { display: grid; grid-template-columns: 1fr 160px auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.upg input { margin: 0; }
.upg .x { border: 0; background: none; font-size: 24px; color: var(--muted); padding: 6px; }
#smsText { font-size: 15px; }
@media (max-width: 760px) { .upg { grid-template-columns: 1fr 110px auto; } .check-line input.wide { max-width: 55%; } }

/* v4 layout pass: compact, aligned rows */
input, select, textarea { font-size: 17px; }
label > input, label > select, label > textarea { font-weight: 400; }
.items { display: grid; margin: 4px 0 8px; }
.item { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; min-height: 52px; padding: 4px 0; border-bottom: 1px solid #eef0f5; }
.items > .item:last-child, .items > .trim-item:last-child .item:first-child { border-bottom: 0; }
.item label.check { margin: 0; flex: 0 0 auto; }
.item input:not([type]), .item input[inputmode] { margin: 0; padding: 10px 12px; }
.item .xs { width: 120px; } .item .sm { width: 180px; } .item .md { width: 280px; max-width: 100%; }
.item .chips { margin: 0; }
.item .chips button { padding: 9px 16px; }
.item-lbl { font-size: 14px; font-weight: 600; color: var(--muted); }
.opt-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 12px 0 2px; }
.opt-row .lbl { width: 110px; font-size: 14px; font-weight: 600; color: var(--muted); }
.opt-row .chips { margin: 0; }
.grid-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-chips button { width: 100%; }
.sub { border-left: 3px solid var(--line); padding-left: 14px; margin: 4px 0 8px; }
.trim-item .sub > .chips { margin: 6px 0; }
.trim-item .sub .item { border-bottom: 0; min-height: 0; }
.struct .yn .note { white-space: nowrap; }
.card h2 { margin-bottom: 8px; }
#warrantyPreview { margin-top: 8px; }
@media (max-width: 600px) { .grid-chips { grid-template-columns: 1fr; } .item .md { width: 100%; } }

/* v5: step titles + phone layout */
.step-head { margin: 4px 4px 14px; }
.step-head h1 { font-size: 24px; margin: 0; color: var(--ink); }
.step-head p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.btn .short { display: none; }
@media (max-width: 600px) {
  html, body { font-size: 16px; }
  .top { gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
  .logo { height: 40px; }
  .top-title { display: none; }
  .top .btn { padding: 9px 12px; font-size: 15px; }
  .top #btnSent { margin-left: auto; }
  .btn .long { display: none; } .btn .short { display: inline; }
  .steps { flex-wrap: nowrap; overflow-x: auto; padding: 8px 12px; gap: 6px; top: calc(57px + env(safe-area-inset-top)); scrollbar-width: none; }
  .steps::-webkit-scrollbar { display: none; }
  .steps button { flex: 0 0 auto; min-width: 0; padding: 8px 12px; font-size: 14px; white-space: nowrap; border-radius: 999px; }
  main { padding: 10px 10px 110px; }
  .card { padding: 14px; border-radius: 12px; margin-bottom: 12px; }
  .step-head h1 { font-size: 21px; }
  h2 { font-size: 18px; }
  input, select, textarea { font-size: 16px; padding: 11px 12px; }
  .item { gap: 8px 10px; }
  .item .sm, .item .md { width: 100%; }
  .item .xs { width: 110px; }
  .item .chips button, .chips button { padding: 9px 13px; font-size: 15px; }
  .opt-row .lbl { width: 100%; }
  .struct { grid-template-columns: 1fr auto; }
  .struct .yn { grid-column: 1 / -1; }
  .nav { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .nav .btn { min-width: 100px; padding: 12px 16px; }
  .btn.big { padding: 15px; font-size: 17px; }
  .summary div { grid-template-columns: 1fr; }
  .init-row .tap { width: 96px; height: 48px; }
  .upg { grid-template-columns: 1fr 100px auto; }
}
.item label.check { flex: 0 1 auto; min-width: 0; }
@media (max-width: 600px) {
  .item .xs { width: calc(50% - 6px); }
  .item label.check + .xs { margin-left: 34px; width: calc(50% - 40px); }
}
