/* Address page. Shares the tokens in style.css. */

[hidden] { display: none !important; }
.sprite { display: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
.icon.tiny { width: 14px; height: 14px; vertical-align: -2px; }

/* --- header ------------------------------------------------------------------------- */

header.top { display: flex; align-items: center; gap: var(--s5); padding: var(--s4) 0; max-width: 1400px; }
.brand { display: flex; align-items: center; gap: var(--s2); font-size: 1.25rem; white-space: nowrap; color: var(--text); text-decoration: none; }
.brand .icon { width: 24px; height: 24px; color: var(--accent); }
.tag {
  font-family: var(--font-mono); font-size: 0.62rem; font-weight: 500; letter-spacing: 0.1em;
  color: var(--accent); border: 1px solid currentColor; border-radius: var(--radius-sm); padding: 1px 6px;
}

.stepper { display: flex; gap: var(--s2); list-style: none; margin: 0; padding: 0; flex: 1; justify-content: center; }
.stepper li {
  display: inline-flex; align-items: center; gap: var(--s2); padding: 6px 12px; border-radius: 999px;
  font-size: 0.88rem; color: var(--muted); cursor: pointer; user-select: none;
}
.stepper li + li::before { content: ""; width: 24px; height: 1px; background: var(--border); margin-right: var(--s2); }
.stepper .num {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid var(--border); font-family: var(--font-mono); font-size: 0.72rem;
}
.stepper li.active { color: var(--text); }
.stepper li.active .num { background: var(--ink); border-color: var(--ink); color: var(--ink-text); }
.stepper li.done .num { border-color: var(--accent); color: var(--accent); }

.address-btn {
  background: var(--card); color: var(--text); border: 1px solid var(--border); font-weight: 400;
  display: inline-flex; align-items: center; gap: var(--s2); padding: 6px 12px; max-width: 34ch;
}
.address-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.address-btn .icon { color: var(--muted); }
.address-btn:hover:not(:disabled) { border-color: var(--accent); box-shadow: none; }

body.is-landing .stepper, body.is-landing .address-btn { visibility: hidden; }

/* --- search --------------------------------------------------------------------------- */

.search-row { display: flex; gap: var(--s2); }
.combo { position: relative; flex: 1; min-width: 0; }
.combo-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.combo input {
  width: 100%; font: inherit; padding: 12px 14px 12px 44px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.combo input::placeholder { color: var(--muted); opacity: 0.7; }
.combo input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.suggestions {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  max-height: 320px; overflow: auto;
}
.suggestions li { padding: var(--s2) var(--s3); border-radius: var(--radius-sm); cursor: pointer; }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--sunken); box-shadow: inset 2px 0 0 var(--accent); }
.suggestions li.empty { cursor: default; color: var(--muted); }

/* Landing: the search bar is the page. */
.search-card { display: none; }
body.is-landing .search-card { display: block; max-width: 640px; width: 100%; margin: 0 auto; }
body.is-landing main { min-height: 62vh; display: flex; flex-direction: column; justify-content: center; }
body.is-landing .combo input { padding-top: 16px; padding-bottom: 16px; font-size: 1.1rem; box-shadow: var(--shadow-pop); }
body.is-landing #go { padding: 0 28px; }

/* Address dialog: the same search form, moved in when the address changes. */
.address-dialog {
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); color: var(--text);
  padding: var(--s4); width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow-pop); overflow: visible;
}
.address-dialog::backdrop { background: rgba(61, 46, 34, 0.35); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s3); color: var(--muted); }
.address-dialog .suggestions { position: static; margin-top: var(--s2); box-shadow: none; }

/* --- progress: three steps and a running bar ------------------------------------------ */

.progress { max-width: 640px; margin: var(--s6) auto; display: flex; flex-direction: column; align-items: center; gap: var(--s4); }
.steps { display: flex; gap: var(--s6); list-style: none; margin: 0; padding: 0; }
.steps li { color: var(--border); transition: color 0.4s; }
.steps li .icon { width: 28px; height: 28px; }
.steps li[data-state="done"] { color: var(--muted); }
.steps li[data-state="active"] { color: var(--accent); }
.bar-track { width: 200px; height: 2px; background: var(--sunken); overflow: hidden; border-radius: 1px; }
.bar-track span { display: block; width: 40%; height: 100%; background: var(--accent); animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) { .bar-track span { animation-duration: 4s; } }

/* --- result: one grid, arranged per step ---------------------------------------------- */

header.top, main { max-width: 1400px; }
.result { display: grid; gap: var(--s4); align-items: start; justify-content: center; }
.result .card { margin: 0; }
.result .alert { margin: 0; }

/* Step 1, roof & modules: the image as large as the screen allows, tools beside it. */
body.is-roof .result {
  --stage: min(calc(100vh - 226px), calc(100vw - 500px), 860px);
  grid-template-columns: auto minmax(320px, 400px);
  grid-template-areas: "stage plan" "stage roof";
  grid-template-rows: auto minmax(0, 1fr);
}

body.is-roof .answer, body.is-roof .inputs, body.is-roof .back-btn { display: none; }

/* Step 2, economics: a small image, room for the numbers, chart and inputs. */
body.is-economics .result {
  --stage: 268px;
  grid-template-columns: calc(var(--stage) + 34px) minmax(0, 1fr);
  grid-template-areas: "stage answer" "plan inputs";
  grid-template-rows: auto 1fr;
  justify-content: stretch;
}
body.is-economics .roof-card, body.is-economics .legend, body.is-economics .stage-foot,
body.is-economics .on-image, body.is-economics .seg-pop { display: none !important; }
body.is-economics .stats.big { grid-template-columns: 1fr; }
body.is-economics .stats.big div { display: flex; align-items: baseline; justify-content: space-between; }
body.is-economics .stats.big dd { font-size: 1.5rem; margin: 0; }

.stage-card { grid-area: stage; padding: var(--s4); }
.plan-card { grid-area: plan; display: flex; flex-direction: column; gap: var(--s3); }
.roof-card { grid-area: roof; display: flex; flex-direction: column; gap: var(--s4); align-self: start; }
.answer { grid-area: answer; }
.inputs { grid-area: inputs; }
.stage { width: var(--stage); }


.field { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.field-title { display: inline-flex; align-items: center; gap: var(--s2); font-size: 0.88rem; color: var(--muted); white-space: nowrap; }
.field-title .icon { color: var(--muted); }

button.cta {
  margin-top: auto; display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 14px 20px; font-size: 1rem;
}
.back-btn { align-self: flex-start; }

.seg { display: inline-flex; background: var(--sunken); border-radius: var(--radius); padding: 3px; gap: 2px; }
.seg-btn { background: transparent; color: var(--muted); padding: 6px 10px; border-radius: var(--radius-sm); display: inline-flex; }
.seg-btn:hover:not(:disabled) { box-shadow: none; color: var(--text); }
.seg-btn[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.seg-btn .icon { width: 18px; height: 18px; }
.seg-btn.labelled { gap: 6px; align-items: center; font-size: 0.85rem; padding: 6px 12px; }

/* --- the roof canvas: photo + SVG ----------------------------------------------------- */

.stage { position: relative; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--sunken); }
.stage-inner { position: absolute; inset: 0; transform-origin: 0 0; transition: transform 0.35s ease; }
.stage img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; }

.layer-dim path { fill: rgba(28, 23, 18, 0.5); }
.layer-outline path { fill: none; stroke: #f7f0e3; stroke-width: 2; vector-effect: non-scaling-stroke; }

.face {
  fill: var(--c); fill-opacity: 0.5; stroke: var(--c); stroke-width: 1.5; vector-effect: non-scaling-stroke;
  transition: fill-opacity 0.15s;
}
.face.unmeasured { stroke-dasharray: 4 3; fill-opacity: 0.3; }
.overlay.has-hl .face { fill-opacity: 0.2; }
.overlay.has-hl .face.hl { fill-opacity: 0.75; stroke: #f7f0e3; stroke-width: 2; }

.object { stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.object.solar { fill: url(#hatch-solar); stroke: var(--accent); }
.solar-bg { fill: rgba(45, 76, 255, 0.35); }
.solar-line { stroke: #c9d2ff; stroke-width: 1.5; }
.object.other { fill: rgba(29, 26, 23, 0.6); stroke: #1d1a17; }

/* Modules: on = dark glass with a cobalt edge (the electric layer); off = a dashed slot. */
.module {
  fill: rgba(247, 240, 227, 0.08); stroke: rgba(247, 240, 227, 0.55); stroke-width: 0.8;
  stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; cursor: pointer;
  transition: fill 0.12s, stroke 0.12s;
}
.module:hover { fill: rgba(130, 150, 255, 0.35); }
.module.on { fill: #18204a; fill-opacity: 0.92; stroke: #8ea0ff; stroke-dasharray: none; stroke-width: 1; }
.module.on:hover { fill: #2d4cff; }
.overlay[data-mode="analysis"] .layer-faces .face { fill-opacity: 0.3; }
/* Touch: the image scrolls the page like any other content; only drawing captures the finger. */
.overlay { touch-action: pan-x pan-y pinch-zoom; }
.overlay[data-mode="draw"] { touch-action: none; }

/* Photo view: just the outline. Heights view: no overlay at all. */
.overlay[data-mode="photo"] .layer-faces,
.overlay[data-mode="photo"] .layer-objects,
.overlay[data-mode="photo"] .layer-dim { display: none; }
.overlay[data-mode="heights"] { display: none; }

.legend { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s3); font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }
.legend-bar { flex: 1; height: 6px; border-radius: 3px; }

.keys { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); list-style: none; margin: 0; padding: 0;
        font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); }
.keys li { display: inline-flex; align-items: center; gap: 6px; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.swatch.solar { background: var(--accent); }
.swatch.other { background: #1d1a17; }

/* --- panel: stats and faces ----------------------------------------------------------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3); margin: 0; }
.stats div { background: var(--sunken); border-radius: var(--radius); padding: var(--s3); }
.stats dt { color: var(--muted); display: flex; align-items: center; gap: 6px; font-size: 0.8rem; }
.stats dt .icon { width: 18px; height: 18px; }
.stats.big { grid-template-columns: repeat(2, 1fr); }
.stats.big dd { font-size: 1.9rem; font-weight: 300; }
.stats.big dt .icon { color: var(--accent); }
.stats dd { margin: var(--s2) 0 0; font-size: 1.3rem; font-weight: 400; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }

.faces { list-style: none; margin: 0; padding: 0; }
.face-row {
  display: grid; grid-template-columns: 10px 24px 3.2rem 1fr auto 2rem; gap: var(--s3); align-items: center;
  padding: var(--s2) var(--s2); border-radius: var(--radius-sm); cursor: default;
  border-bottom: 1px solid var(--border);
}
.face-row:last-child { border-bottom: 0; }
.face-row.hl, .face-row:hover { background: var(--sunken); }
.face-row:focus-visible { outline-offset: -2px; }
.face-row.unmeasured { color: var(--muted); }
.face-row .dir { font-family: var(--font-mono); font-size: 0.85rem; }
.face-row .num { font-family: var(--font-mono); font-size: 0.88rem; font-variant-numeric: tabular-nums; text-align: right; }
.face-row .pitch { color: var(--muted); }
.face-row .mods {
  justify-self: end; min-width: 1.6rem; text-align: center; font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--accent); border-radius: var(--radius-sm);
}
.face-row .mods:not(:empty) { background: var(--accent-soft); padding: 1px 4px; }

.dial { width: 24px; height: 24px; }
.dial-ring { fill: none; stroke: var(--border); stroke-width: 1.2; }
.dial-north { stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round; }
.dial-needle { fill: var(--text); }
.dial-flat { fill: var(--muted); }
.face-row.unmeasured .dial-needle { fill: var(--muted); }

/* --- footer --------------------------------------------------------------------------- */

.site-footer { max-width: 1400px; margin: var(--s7) auto 0; border-top: 1px solid var(--border); padding-top: var(--s3); }
body.is-roof .site-footer, body.is-economics .site-footer, body.is-installers .site-footer { margin-top: var(--s3); border-top: 0; padding-top: 0; font-size: 0.72rem; }
.site-footer p { margin: 4px 0; }

@media (max-width: 900px) {
  header.top { flex-wrap: wrap; gap: var(--s2); }
  .stepper { order: 3; flex-basis: 100%; justify-content: flex-start; }
  body.is-roof .result, body.is-economics .result {
    --stage: calc(100vw - 66px);
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "plan" "roof" "answer" "inputs";
  }
  body.is-economics .result { --stage: min(calc(100vw - 66px), 360px); }

}
@media (max-width: 600px) {
  .search-row { flex-direction: column; }
  body.is-landing #go { padding: 12px; }
  .stats { gap: var(--s2); }
  .stats div { padding: var(--s2); }
  .stats dd { font-size: 1.05rem; }
}

/* --- answer, chart and inputs --------------------------------------------------------- */

.answer { transition: opacity 0.2s; display: flex; flex-direction: column; gap: var(--s4); }
.answer.busy { opacity: 0.6; }
.answer-grid { grid-template-columns: repeat(3, 1fr); }
.answer-grid dd { font-size: 1.7rem; font-weight: 300; }
.answer-grid dt { color: var(--text); }
.answer-grid dt .icon { color: var(--accent); }

.chart-wrap { position: relative; }
.chart-keys { display: flex; gap: var(--s4); list-style: none; margin: 0 0 var(--s2); padding: 0; font-size: 0.78rem; color: var(--muted); }
.chart-keys li { display: inline-flex; align-items: center; gap: 6px; }
.swatch.prod { background: var(--accent); }
.swatch.cons { background: var(--text); opacity: 0.35; }
.chart { width: 100%; height: clamp(140px, calc(100vh - 640px), 260px); display: block; overflow: visible; }
.bar-prod { fill: var(--accent); }
.bar-cons { fill: var(--text); opacity: 0.35; }
.chart-label { font-family: var(--font-mono); font-size: 11px; fill: var(--muted); }

.inputs { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3) var(--s6); align-content: start; }
.input-row { display: grid; grid-template-columns: 8.5rem 1fr 5.5rem; gap: var(--s3); align-items: center; min-height: 36px; }
.input-row .val { font-family: var(--font-mono); font-size: 0.82rem; text-align: right; font-variant-numeric: tabular-nums; }
.input-row .seg { justify-self: start; }
.hp { display: flex; align-items: center; gap: var(--s3); }
@media (max-width: 1100px) { .inputs { grid-template-columns: 1fr; } }

input[type="range"] { width: 100%; accent-color: var(--accent); }
.range-wrap { position: relative; }
.range-wrap .mark {
  position: absolute; top: -6px; width: 2px; height: 8px; margin-left: -1px; background: var(--accent);
  border-radius: 1px; cursor: pointer;
}
.range-wrap .mark::after { content: ""; position: absolute; inset: -6px -6px; }
#in-bat.auto { accent-color: var(--ink); }

.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--sunken); border: 1px solid var(--border); border-radius: 10px; cursor: pointer; transition: background 0.15s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform 0.15s, background 0.15s; }
.switch input:checked + span { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--accent); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- draw mode ------------------------------------------------------------------------ */

button.secondary {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; font-size: 0.88rem;
}
button.secondary:hover:not(:disabled) { border-color: var(--accent); box-shadow: none; }
.draw-tools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.icon-btn { background: transparent; color: var(--muted); padding: 6px 8px; display: inline-flex; }
.icon-btn:hover:not(:disabled) { color: var(--text); box-shadow: none; background: var(--sunken); }
.icon-btn.primary { background: var(--ink); color: var(--ink-text); }
.icon-btn.primary:hover:not(:disabled) { background: var(--ink); box-shadow: 0 0 0 3px var(--accent-soft); color: var(--ink-text); }
.icon-btn:disabled { opacity: 0.3; }

.overlay[data-mode="draw"] .layer-faces,
.overlay[data-mode="draw"] .layer-objects,
.overlay[data-mode="draw"] .layer-modules,
.overlay[data-mode="draw"] .layer-dim { display: none; }
.overlay[data-mode="draw"] { cursor: crosshair; }
.overlay[data-mode="draw"][data-tool="select"] { cursor: default; }

.edit-shape { stroke-width: 1.5; vector-effect: non-scaling-stroke; fill-opacity: 0.3; }
.edit-shape.face { fill: #e8a92a; stroke: #f7f0e3; }
.edit-shape.solar { fill: #2d4cff; stroke: #c9d2ff; fill-opacity: 0.45; }
.edit-shape.other { fill: #1d1a17; stroke: #f7f0e3; fill-opacity: 0.55; stroke-dasharray: 3 2; }
.edit-shape.selected { stroke: #8ea0ff; stroke-width: 2.5; fill-opacity: 0.45; }
.edit-line { fill: none; stroke: #f7f0e3; stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-dasharray: 4 3; }
.handle { fill: #f7f0e3; stroke: #2d4cff; stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: move; }
.handle.first { fill: #2d4cff; stroke: #f7f0e3; cursor: pointer; }
.mid { fill: rgba(247, 240, 227, 0.5); stroke: #2d4cff; stroke-width: 1; vector-effect: non-scaling-stroke; cursor: copy; }
.address-dialog .search-row { align-items: flex-start; }
.address-dialog .combo-icon { top: 24px; }
.address-dialog #go { height: 46px; }
.how-link { color: var(--text); }
body.is-roof .site-footer, body.is-economics .site-footer, body.is-installers .site-footer { display: flex; gap: var(--s4); }
body.is-roof .site-footer p, body.is-economics .site-footer p, body.is-installers .site-footer p { margin: 0; }

/* --- controls on the image ------------------------------------------------------------ */

.on-image { position: absolute; z-index: 2; }
.on-image.seg, .on-image .seg { background: rgba(247, 240, 227, 0.92); box-shadow: 0 2px 10px rgba(29, 26, 23, 0.25); }
.on-image.tl { top: 10px; left: 10px; }
.on-image.tr { top: 10px; right: 10px; }
.on-image.right { top: 50%; right: 10px; transform: translateY(-50%); display: flex; flex-direction: column; gap: var(--s2); }
.on-image.right[hidden] { display: none; }
.seg.vertical { flex-direction: column; }
.on-image .icon-btn { color: var(--text); }
.on-image .icon-btn:hover:not(:disabled) { background: var(--sunken); }

.annotate {
  bottom: 10px; right: 10px; display: flex; align-items: center; gap: var(--s2);
  background: rgba(247, 240, 227, 0.92); border-radius: var(--radius); padding: 4px 4px 4px 12px;
  box-shadow: 0 2px 10px rgba(29, 26, 23, 0.25); font-size: 0.74rem; color: var(--text);
}
.annotate .pen { background: var(--ink); color: var(--ink-text); padding: 6px; }
.annotate .pen:hover:not(:disabled) { background: var(--ink); color: var(--ink-text); box-shadow: 0 0 0 3px var(--accent-soft); }
.annotate .pen .icon { width: 16px; height: 16px; }

/* While annotating: only the draw bar on the image. */
body.drawing .on-image.tl, body.drawing .on-image.tr, body.drawing .annotate,
body.drawing .seg-pop, body.drawing .fab { display: none !important; }

/* Legend under the image, with the toggle that slides the roof segments out over it. */
.stage-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-top: var(--s3); }
.seg-toggle {
  background: transparent; color: var(--muted); padding: 4px 6px; display: inline-flex; align-items: center; gap: 2px;
  border: 1px solid var(--border);
}
.seg-toggle:hover:not(:disabled) { color: var(--text); border-color: var(--accent); box-shadow: none; }
.seg-toggle[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.seg-toggle .chevron { width: 14px; height: 14px; transition: transform 0.2s; }
.seg-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.seg-pop {
  position: absolute; z-index: 3; left: 10px; right: 10px; bottom: 10px; max-height: 55%;
  overflow: auto; background: var(--card); border-radius: var(--radius); padding: var(--s2);
  box-shadow: var(--shadow-pop); animation: pop-up 0.2s ease;
}
@keyframes pop-up { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .seg-pop { animation: none; } }

/* Floating action button: always reachable in step 1. */
.fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 20; display: none; align-items: center; gap: var(--s2);
  padding: 14px 22px; font-size: 1rem; border-radius: 999px; box-shadow: 0 8px 24px rgba(29, 26, 23, 0.3);
}
body.is-roof #to-economics, body.is-economics #to-installers { display: inline-flex; }
.fab:hover:not(:disabled) { box-shadow: 0 8px 24px rgba(29, 26, 23, 0.3), 0 0 0 4px var(--accent-soft); }
.on-image .icon-btn.primary, .on-image .icon-btn.primary:hover:not(:disabled) { color: var(--ink-text); background: var(--ink); }
.stage:has(.seg-pop:not([hidden])) .annotate { display: none; }

/* Page 2: the modules card and the inputs card share one row height. */
body.is-economics .plan-card, body.is-economics .inputs { align-self: stretch; }
body.is-economics .plan-card .back-btn { margin-top: auto; }
.car { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.car input[type="range"] { flex: 1; min-width: 60px; }

/* --- step 3: summary and the installer form ------------------------------------------- */

.summary-card, .lead-card { display: none; }
body.is-roof .summary-card, body.is-economics .summary-card { display: none; }
body.is-installers .result {
  --stage: 268px;
  grid-template-columns: calc(var(--stage) + 34px) minmax(0, 1fr);
  grid-template-areas: "stage lead" "summary lead";
  grid-template-rows: auto 1fr;
  justify-content: stretch;
}
body.is-installers .summary-card { display: flex; grid-area: summary; flex-direction: column; gap: var(--s3); }
body.is-installers .lead-card { display: block; grid-area: lead; align-self: stretch; }
body.is-installers .plan-card, body.is-installers .roof-card, body.is-installers .answer,
body.is-installers .inputs, body.is-installers .legend, body.is-installers .stage-foot,
body.is-installers .on-image, body.is-installers .seg-pop { display: none !important; }
body.is-installers .overlay { pointer-events: none; }

.summary-card h2, .lead-card h2 { font-size: 1.1rem; font-weight: 500; margin: 0; }
.summary { display: flex; flex-direction: column; margin: 0; }
.summary div { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: 6px 0; border-bottom: 1px solid var(--border); }
.summary div:last-child { border-bottom: 0; }
.summary dt { display: inline-flex; align-items: center; gap: var(--s2); font-size: 0.82rem; color: var(--muted); }
.summary dt .icon { width: 16px; height: 16px; color: var(--accent); }
.summary dd { margin: 0; font-family: var(--font-mono); font-size: 0.85rem; text-align: right; }
.summary-card .back-btn { margin-top: auto; }

.lead-card { padding: var(--s5) var(--s6); }
#lead-form { display: flex; flex-direction: column; gap: var(--s3); max-width: 720px; }
.lead-sub { margin: calc(-1 * var(--s3)) 0 0; color: var(--muted); font-size: 0.9rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3) var(--s4); }
.form-grid .f.wide:has(input[readonly]) { grid-column: auto; }
.f { display: flex; flex-direction: column; gap: 6px; font-size: 0.8rem; color: var(--muted); }
.f.wide { grid-column: 1 / -1; }
.f .opt { font-size: 0.72rem; opacity: 0.8; }
.f input, .f select, .f textarea {
  font: inherit; font-size: 0.95rem; color: var(--text); background: var(--sunken);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; resize: vertical;
}
.f input:focus, .f select:focus, .f textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.f input[readonly] { color: var(--muted); }
.f input.invalid { border-color: var(--error-text); }
.hp-field { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.consent { display: flex; gap: var(--s3); align-items: flex-start; font-size: 0.82rem; line-height: 1.5; color: var(--text); }
.consent input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.consent.invalid { color: var(--error-text); }
#lead-submit { align-self: flex-start; margin-top: 0; }
#lead-submit:disabled { opacity: 0.5; }
.lead-done { text-align: center; padding: var(--s7) var(--s4); }
.lead-done .icon.big { width: 48px; height: 48px; color: var(--accent); }
.lead-done h2 { margin: var(--s3) 0 var(--s2); }
@media (max-width: 900px) {
  body.is-installers .result { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "summary" "lead"; --stage: min(calc(100vw - 66px), 360px); }
  .form-grid { grid-template-columns: 1fr; }
}

/* --- language switch and landing headline --------------------------------------------- */

.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 2px; }
.lang-switch button {
  background: transparent; color: var(--muted); padding: 3px 10px; border-radius: 999px;
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500; letter-spacing: 0.06em;
}
.lang-switch button:hover:not(:disabled) { color: var(--text); box-shadow: none; }
.lang-switch button[aria-pressed="true"] { background: var(--ink); color: var(--ink-text); }
body.is-landing .address-btn { display: none; }

.hero { font-size: clamp(2rem, 4vw, 3rem); font-weight: 300; letter-spacing: -0.02em; text-align: center; margin: 0 0 var(--s2); }
.hero-sub { text-align: center; color: var(--muted); margin: 0 0 var(--s6); }
.search-card .hero, .search-card .hero-sub { display: none; }
body.is-landing .search-card .hero, body.is-landing .search-card .hero-sub { display: block; }

/* --- phones ------------------------------------------------------------------------------
   One column, a two-line header, a compact step indicator and the main action as a bar
   at the bottom of the screen (reachable with a thumb). */

html, body { overflow-x: clip; }

@media (max-width: 700px) {
  body { padding: 0 12px calc(84px + env(safe-area-inset-bottom)); }
  body.is-landing { padding-bottom: 24px; }

  header.top {
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "brand lang" "addr addr" "steps steps";
    gap: 10px; padding: 14px 0 10px;
  }
  .brand { grid-area: brand; font-size: 1.05rem; }
  .brand .icon { width: 20px; height: 20px; }
  .lang-switch { grid-area: lang; }
  .address-btn { grid-area: addr; max-width: none; width: 100%; justify-content: flex-start; padding: 8px 12px; }
  .address-btn span { flex: 1; text-align: left; }
  body.is-landing header.top { grid-template-areas: "brand lang"; }
  body.is-landing .stepper, body.is-landing .address-btn, body.is-loading .stepper { display: none; }

  /* Step indicator: three numbers, only the current step named. */
  .stepper { grid-area: steps; order: 0; flex-basis: auto; justify-content: flex-start; gap: 4px; }
  .stepper li { padding: 2px 4px; gap: 6px; font-size: 0.82rem; }
  .stepper li + li::before { width: 14px; margin-right: 4px; }
  .stepper li:not(.active) > span:not(.num) { display: none; }

  .card { padding: 12px; }
  .result { gap: 12px; }

  body.is-roof .result, body.is-economics .result, body.is-installers .result {
    --stage: calc(100vw - 48px);
    grid-template-columns: minmax(0, 1fr);
    justify-content: stretch;
  }
  body.is-roof .result { grid-template-areas: "stage" "plan" "roof"; grid-template-rows: auto; }
  .stage-card { padding: 12px; }

  /* Controls on the image: finger-sized, the annotate prompt shortened to its button. */
  .on-image .seg-btn, .on-image .icon-btn { padding: 8px; }
  .on-image.tl { top: 8px; left: 8px; }
  .on-image.tr { top: 8px; right: 8px; }
  .on-image.right { right: 8px; gap: 6px; }
  .on-image.right .seg-btn, .on-image.right .icon-btn { padding: 6px; }
  .annotate { bottom: 8px; right: 8px; padding: 4px; }
  .annotate span { display: none; }
  .annotate .pen { padding: 8px; }
  .annotate .pen .icon { width: 18px; height: 18px; }
  .stage-foot { gap: var(--s2); }
  .seg-toggle { padding: 6px 8px; flex: none; }
  .seg-pop { left: 6px; right: 6px; bottom: 6px; max-height: 70%; }
  .face-row { grid-template-columns: 10px 22px 2.6rem 1fr auto 1.8rem; gap: 8px; padding: 6px 4px; }

  .stats { gap: var(--s2); }
  .stats div { padding: 10px; }
  .stats dd { font-size: 1.05rem; }
  .stats.big dd { font-size: 1.5rem; }

  /* The main action: a bar along the bottom edge. */
  .fab {
    left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
    justify-content: center; padding: 15px 20px; border-radius: var(--radius-lg);
  }

  /* Step 2: the numbers first, then a small image beside the panels, then the inputs. */
  body.is-economics .result {
    --stage: 128px;
    grid-template-columns: calc(var(--stage) + 24px) minmax(0, 1fr);
    grid-template-areas: "answer answer" "stage plan" "inputs inputs";
    grid-template-rows: auto;
  }
  body.is-economics .stage-card { padding: 12px; align-self: stretch; }
  body.is-economics .plan-card { align-self: stretch; padding: 12px; gap: 8px; }
  body.is-economics .stats.big div { padding: 8px 10px; flex-direction: column; align-items: flex-start; gap: 2px; }
  body.is-economics .stats.big dd { font-size: 1.2rem; }
  body.is-economics .plan-card .back-btn { padding: 6px 10px; font-size: 0.8rem; }
  .answer { gap: 12px; }
  .answer-grid { gap: 6px; }
  .answer-grid div { padding: 8px; }
  .answer-grid dt { font-size: 0.68rem; gap: 4px; align-items: flex-start; min-height: 2.2em; }
  .answer-grid dt .icon { width: 14px; height: 14px; flex: none; }
  .answer-grid dd { font-size: 1.05rem; font-weight: 400; margin-top: 4px; }
  .chart { height: 150px; }
  .chart-keys { font-size: 0.72rem; }

  .inputs { grid-template-columns: 1fr; gap: 14px; }
  .input-row { grid-template-columns: 1fr auto; grid-template-areas: "title val" "ctrl ctrl"; gap: 8px; min-height: 0; }
  .input-row > .field-title { grid-area: title; }
  .input-row > .val { grid-area: val; }
  .input-row > :nth-child(2) { grid-area: ctrl; }
  .car { flex-wrap: wrap; }
  .car .seg-btn { padding: 8px 12px; }
  input[type="range"] { height: 28px; }

  /* Step 3: plan summary beside a small image, then the form in one column. */
  body.is-installers .result {
    --stage: 128px;
    grid-template-columns: calc(var(--stage) + 24px) minmax(0, 1fr);
    grid-template-areas: "stage summary" "lead lead";
    grid-template-rows: auto;
  }
  body.is-installers .summary-card { padding: 12px; gap: 6px; }
  .summary-card h2 { font-size: 0.95rem; }
  .summary div { padding: 3px 0; }
  .summary dt { font-size: 0.72rem; }
  .summary dt .icon { display: none; }
  .summary dd { font-size: 0.74rem; }
  .summary-card .back-btn { padding: 5px 8px; font-size: 0.78rem; }
  .lead-card { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .f input, .f select, .f textarea { font-size: 16px; padding: 11px 12px; }   /* 16px: no zoom-in on iOS */
  #lead-submit { align-self: stretch; justify-content: center; padding: 15px; }
  .lead-done { padding: 40px 8px; }
  .consent { display: grid; grid-template-columns: 16px 1fr; column-gap: 12px; row-gap: 4px; }
  .consent a { grid-column: 2; }
  body.is-installers { padding-bottom: 24px; }

  .address-dialog { width: calc(100vw - 24px); padding: 12px; margin-top: 12px; }
  .combo input { font-size: 16px; }

  body.is-roof .site-footer, body.is-economics .site-footer, body.is-installers .site-footer { flex-direction: column; gap: 4px; }
}
