/* SolarScope design system: deep navy + sun amber + fresh green.
   Tokens first, then base, components, page layouts, AR screen, responsive rules.
   Light/dark: tokens below are light; dark ones apply via [data-theme="dark"] (set by js/theme.js from the
   saved choice or the system setting) and via prefers-color-scheme when JavaScript is off. */

/* ============================== tokens ============================== */
:root {
  color-scheme: light;

  /* brand */
  --navy-950: #050b1f;
  --navy-900: #071029;
  --navy-800: #0b1a3d;
  --navy-700: #12295c;
  --navy-600: #1b3a7a;
  --sun-300: #ffd166;
  --sun-400: #ffbe2e;
  --sun-500: #ffa600;
  --sun-600: #e68a00;
  --sun-ink: #1f1300;          /* text on amber: 9:1 */
  --green-400: #34d399;
  --green-500: #16c784;

  /* surfaces & text (light) */
  --bg: #f3f6fc;
  --surface: #ffffff;
  --surface-2: #eef3fb;
  --surface-3: #e2e9f6;
  --glass: rgba(255, 255, 255, 0.72);
  --ink: #0a1633;
  --muted: #4b5878;            /* 7:1 on white */
  --line: #d6deee;
  --line-strong: #b4c1dc;
  --brand: var(--navy-800);    /* solid buttons, links */
  --brand-ink: #ffffff;
  --link: #1b4fd1;
  --ok-ink: #0b7a52;
  --ok-bg: #dcf7ea;
  --danger: #c8283a;
  --danger-bg: #fde8ea;
  --warn-bg: #fff4d6;
  --warn-line: #f2c14e;
  --warn-ink: #5c3d00;
  --focus: #2f6bff;

  /* map colours (match the canvas drawing in app.js / plan.js) */
  --roof: #22c55e;
  --obs: #ef4444;
  --pv: #2563eb;
  --pv-small: #0d9488;   /* small gap-filling panels (teal), distinct from --pv */

  /* type */
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-body: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --step--1: clamp(0.78rem, 0.76rem + 0.1vw, 0.84rem);
  --step-0: clamp(0.92rem, 0.89rem + 0.15vw, 0.98rem);
  --step-1: clamp(1.06rem, 1rem + 0.3vw, 1.2rem);
  --step-2: clamp(1.25rem, 1.1rem + 0.7vw, 1.55rem);
  --step-3: clamp(1.55rem, 1.25rem + 1.4vw, 2.2rem);
  --step-4: clamp(1.95rem, 1.45rem + 2.4vw, 3.1rem);
  --step-5: clamp(2.3rem, 1.6rem + 3.6vw, 4.1rem);

  /* space */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4.5rem;
  --gutter: clamp(16px, 3.2vw, 36px);
  --page-max: 1440px;

  /* shape & depth */
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgba(10, 22, 51, 0.06), 0 1px 1px rgba(10, 22, 51, 0.04);
  --shadow-2: 0 10px 24px -12px rgba(10, 22, 51, 0.22), 0 2px 6px rgba(10, 22, 51, 0.06);
  --shadow-3: 0 30px 60px -24px rgba(10, 22, 51, 0.35), 0 8px 18px -10px rgba(10, 22, 51, 0.18);
  --ring: 0 0 0 3px var(--surface), 0 0 0 6px var(--focus);

  /* motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 220ms;

  --header-h: 72px;            /* updated by theme.js to the real sticky header height */
  --tap: 44px;                 /* minimum touch target */
}

/* dark tokens: once for the manual choice, once for the system setting without JavaScript */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #060c1d;
  --surface: #0d1730;
  --surface-2: #132042;
  --surface-3: #1b2b55;
  --glass: rgba(13, 23, 48, 0.72);
  --ink: #eaf0ff;
  --muted: #a9b6d6;
  --line: #22335f;
  --line-strong: #34497f;
  --brand: #2a4c9b;
  --brand-ink: #ffffff;
  --link: #8fb0ff;
  --ok-ink: #4ade9b;
  --ok-bg: rgba(22, 199, 132, 0.14);
  --danger: #ff7a85;
  --danger-bg: rgba(255, 90, 105, 0.14);
  --warn-bg: rgba(255, 190, 46, 0.12);
  --warn-line: rgba(255, 190, 46, 0.45);
  --warn-ink: #ffe2a3;
  --focus: #8fb0ff;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 12px 28px -12px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-3: 0 30px 60px -20px rgba(0, 0, 0, 0.7);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #060c1d;
    --surface: #0d1730;
    --surface-2: #132042;
    --surface-3: #1b2b55;
    --glass: rgba(13, 23, 48, 0.72);
    --ink: #eaf0ff;
    --muted: #a9b6d6;
    --line: #22335f;
    --line-strong: #34497f;
    --brand: #2a4c9b;
    --link: #8fb0ff;
    --ok-ink: #4ade9b;
    --ok-bg: rgba(22, 199, 132, 0.14);
    --danger: #ff7a85;
    --danger-bg: rgba(255, 90, 105, 0.14);
    --warn-bg: rgba(255, 190, 46, 0.12);
    --warn-line: rgba(255, 190, 46, 0.45);
    --warn-ink: #ffe2a3;
    --focus: #8fb0ff;
  }
}

/* ============================== base ============================== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }  /* class rules like display:flex must not override hidden */

html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 12px); }
/* Wide screens (large monitors, or a browser zoomed out): zoom the whole page evenly so it fills the
   window instead of a narrow strip of tiny text in the middle. Layout is designed for ~1440-1700px. */
@media (min-width: 1800px) { html { zoom: 1.15; } }
@media (min-width: 2100px) { html { zoom: 1.3; } }
@media (min-width: 2500px) { html { zoom: 1.55; } }
@media (min-width: 3000px) { html { zoom: 1.85; } }
@media (min-width: 3500px) { html { zoom: 2.15; } }
@media (min-width: 4200px) { html { zoom: 2.6; } }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--step-0) / 1.55 var(--font-body);
  overflow-x: hidden;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
main { flex: 1 0 auto; }
img, svg, canvas { max-width: 100%; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.12; letter-spacing: -0.02em; margin: 0; }
p { margin: 0; }
a { color: var(--link); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
b, strong { font-weight: 700; }
small { font-size: var(--step--1); }
table { font-variant-numeric: tabular-nums; }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }
/* the canvas editor keeps its own cursor; a ring around it is enough */
canvas:focus-visible { box-shadow: var(--ring); }

::selection { background: var(--sun-300); color: var(--sun-ink); }

.skip-link {
  position: absolute; left: var(--space-4); top: -100px; z-index: 100;
  background: var(--sun-500); color: var(--sun-ink); font-weight: 700;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); text-decoration: none;
}
.skip-link:focus { top: var(--space-3); }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }
.small { font-size: var(--step--1); margin: 0; }
.icon-svg { width: 1.25em; height: 1.25em; flex: none; }

/* ============================== navbar ============================== */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.navbar {
  max-width: var(--page-max); margin: 0 auto;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--gutter);
  min-height: 64px;
}
.brand { display: inline-flex; align-items: center; gap: var(--space-3); color: inherit; text-decoration: none; min-width: 0; min-height: var(--tap); }
.brand-mark {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 12px;
  background: radial-gradient(circle at 30% 30%, var(--sun-300), var(--sun-500) 60%, var(--sun-600));
  color: var(--navy-900);
  box-shadow: 0 6px 18px -6px rgba(255, 166, 0, 0.7);
}
.brand-mark svg { width: 24px; height: 24px; }
.brand > span:last-child { min-width: 0; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; letter-spacing: -0.02em; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-tag { display: block; font-size: var(--step--1); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32ch; }

.nav { flex: none; display: flex; gap: var(--space-1); margin-left: auto; padding: 4px; border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--line); }
.nav a {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  color: var(--muted); font-weight: 600; font-size: var(--step--1); text-decoration: none; white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav a:hover { color: var(--ink); background: var(--surface); }
.nav a[aria-current="page"] { color: var(--brand-ink); background: var(--brand); box-shadow: var(--shadow-1); }
.nav a .icon-svg { width: 18px; height: 18px; }

.badge {
  font-size: var(--step--1); font-weight: 600; padding: 6px 12px; border-radius: var(--radius-pill);
  border: 1px solid var(--line); color: var(--muted); background: var(--surface); white-space: nowrap;
}
.badge.ok { color: var(--ok-ink); border-color: color-mix(in srgb, var(--ok-ink) 40%, transparent); background: var(--ok-bg); }
.badge.off { color: var(--warn-ink); border-color: var(--warn-line); background: var(--warn-bg); }

.theme-toggle {
  flex: none; width: var(--tap); height: var(--tap); padding: 0; display: grid; place-items: center;
  border-radius: 50%; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }

/* ============================== step progress ============================== */
.progress { border-top: 1px solid var(--line); }
.steps {
  --progress: 0;
  position: relative;
  max-width: var(--page-max); margin: 0 auto; padding: var(--space-2) var(--gutter) var(--space-3);
  list-style: none;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2);
}
/* the bar under the steps fills as steps are completed (common.js sets --progress) */
.steps::after {
  content: ""; position: absolute; left: var(--gutter); right: var(--gutter); bottom: 4px; height: 4px;
  border-radius: 4px; background: var(--surface-3);
}
.steps::before {
  content: ""; position: absolute; left: var(--gutter); bottom: 4px; height: 4px; z-index: 1;
  width: calc((100% - 2 * var(--gutter)) * var(--progress));
  border-radius: 4px; background: linear-gradient(90deg, var(--green-500), var(--sun-500));
  transition: width 600ms var(--ease);
}
.steps a {
  display: flex; align-items: center; gap: var(--space-2); min-height: var(--tap);
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: var(--step--1); border-radius: var(--radius-sm);
}
.step-num {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--line-strong); background: var(--surface); font-size: 0.8rem; font-weight: 800;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.step-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps li.current a { color: var(--ink); }
.steps li.current .step-num { border-color: var(--sun-500); background: var(--sun-500); color: var(--sun-ink); transform: scale(1.08); box-shadow: 0 0 0 4px color-mix(in srgb, var(--sun-500) 25%, transparent); }
.steps li.done a { color: var(--ink); }
.steps li.done .step-num { border-color: var(--green-500); background: var(--green-500); color: #04291b; }
.steps li.done .step-num span { display: none; }
.steps li.done .step-num::before { content: "✓"; }

/* ============================== hero ============================== */
.hero {
  position: relative; isolation: isolate; overflow: hidden;
  color: #fff;
  background:
    radial-gradient(900px 420px at 88% -10%, rgba(255, 166, 0, 0.45), transparent 60%),
    radial-gradient(700px 380px at -5% 110%, rgba(22, 199, 132, 0.28), transparent 60%),
    linear-gradient(135deg, var(--navy-950) 0%, var(--navy-800) 55%, #0c2f4f 100%);
}
.hero::after {   /* faint panel grid */
  content: ""; position: absolute; inset: 0; z-index: -1; opacity: 0.12;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.5) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.5) 1px, transparent 1px);
  background-size: 44px 28px;
  mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
}
.hero-inner { max-width: var(--page-max); margin: 0 auto; padding: clamp(28px, 5vw, 64px) var(--gutter) clamp(28px, 4.5vw, 56px); }
.hero h1 { font-size: var(--step-4); font-weight: 800; max-width: 22ch; }
.hero h1 em { font-style: normal; background: linear-gradient(90deg, var(--sun-300), var(--sun-500)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .lead { margin-top: var(--space-3); font-size: var(--step-1); color: rgba(255, 255, 255, 0.82); max-width: 62ch; }
.eyebrow {
  display: inline-flex; align-items: center; gap: var(--space-2);
  margin-bottom: var(--space-3); padding: 6px 12px; border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--sun-300); font-weight: 700; font-size: var(--step--1); letter-spacing: 0.04em; text-transform: uppercase;
}
.hero--home .hero-inner { padding-bottom: calc(clamp(28px, 4.5vw, 56px) + var(--space-6)); }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-5); }
.hero--page .hero-inner { padding-block: clamp(22px, 3.5vw, 40px); display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: var(--space-4); }
.hero--page h1 { font-size: var(--step-3); }
.hero--page .lead { font-size: var(--step-0); margin-top: var(--space-2); }
.hero-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.hero-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); color: #fff; font-size: var(--step--1); font-weight: 600;
}
.hero .back-link { color: #fff; }

/* ============================== buttons ============================== */
button, .btn, .file-btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding: 0 var(--space-4);
  font: 700 var(--step-0) / 1.2 var(--font-body);
  color: var(--brand-ink); background: var(--brand);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none; text-align: center; user-select: none;
  box-shadow: var(--shadow-1);
  transition: transform 120ms var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease), color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
button:hover, .btn:hover, .file-btn:hover { box-shadow: var(--shadow-2); transform: translateY(-1px); }
button:active, .btn:active, .file-btn:active { transform: translateY(0) scale(0.97); box-shadow: var(--shadow-1); }
button:disabled, button[aria-disabled="true"] {
  opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; filter: saturate(0.6);
}

button.primary, .btn-primary {
  color: var(--sun-ink);
  background: linear-gradient(180deg, var(--sun-400), var(--sun-500));
  border-color: var(--sun-600);
  box-shadow: 0 10px 22px -10px rgba(230, 138, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
button.primary:hover, .btn-primary:hover { background: linear-gradient(180deg, var(--sun-300), var(--sun-400)); }
button.primary { min-height: 52px; font-size: var(--step-1); border-radius: var(--radius); }
/* disabled primary: solid and muted, so nothing shows through it (it can sit in the sticky action bar) */
button.primary:disabled { opacity: 1; filter: none; color: var(--muted); background: var(--surface-3); border-color: var(--line-strong); box-shadow: none; }

button.secondary, .btn-secondary, .file-btn {
  color: var(--ink); background: var(--surface); border-color: var(--line-strong); box-shadow: none;
}
button.secondary:hover, .btn-secondary:hover, .file-btn:hover { background: var(--surface-2); border-color: var(--ink); box-shadow: none; }
.btn-ghost-light { color: #fff; background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.35); box-shadow: none; }
.btn-ghost-light:hover { background: rgba(255, 255, 255, 0.18); }

button.icon { width: var(--tap); padding: 0; font-size: 1.2rem; }
.small-btn { min-height: var(--tap); padding: 0 var(--space-3); font-size: var(--step--1); }
button.linkish { min-height: 0; padding: 0; background: none; border: 0; box-shadow: none; color: var(--link); text-decoration: underline; font-weight: 700; }
button.linkish:hover { transform: none; }

/* busy state (common.js adds .is-busy while a request runs) */
button.is-busy { position: relative; color: transparent !important; pointer-events: none; opacity: 1; }
button.is-busy::after {
  content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid currentColor; border-color: rgba(0, 0, 0, 0.25); border-top-color: var(--navy-900);
  animation: spin 0.8s linear infinite;
}
button.secondary.is-busy::after, button:not(.primary).is-busy::after { border-color: rgba(127, 127, 127, 0.35); border-top-color: var(--sun-500); }
@keyframes spin { to { transform: rotate(360deg); } }

.file-btn { position: relative; }
.file-btn input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-btn:focus-within { box-shadow: var(--ring); }

/* ============================== form controls ============================== */
label { display: flex; flex-direction: column; gap: 6px; font-size: var(--step--1); font-weight: 600; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: var(--space-2); color: var(--ink); min-height: var(--tap); cursor: pointer; }

input[type=number], input[type=search], input[type=text], select {
  -webkit-appearance: none; appearance: none;
  width: 100%; min-height: var(--tap);
  font: 500 var(--step-0) / 1.2 var(--font-body);
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0 var(--space-3);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
input[type=number] { font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { opacity: 0.5; }
input::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
input:hover, select:hover { border-color: var(--ink); }
input:focus-visible, select:focus-visible {
  border-color: var(--focus); box-shadow: 0 0 0 4px color-mix(in srgb, var(--focus) 25%, transparent); border-radius: var(--radius-sm);
}
input:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; background: var(--surface-2); }
select {
  padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237b89aa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}

input[type=checkbox] {
  -webkit-appearance: none; appearance: none; flex: none; margin: 0;
  width: 22px; height: 22px; border-radius: 7px; cursor: pointer;
  border: 2px solid var(--line-strong); background: var(--surface);
  display: grid; place-items: center;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
input[type=checkbox]::after {
  content: ""; width: 6px; height: 11px; margin-top: -2px;
  border: solid var(--sun-ink); border-width: 0 3px 3px 0; transform: rotate(45deg) scale(0);
  transition: transform 160ms var(--ease);
}
input[type=checkbox]:checked { background: var(--sun-500); border-color: var(--sun-600); }
input[type=checkbox]:checked::after { transform: rotate(45deg) scale(1); }
input[type=checkbox]:focus-visible { box-shadow: var(--ring); }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: var(--tap); background: transparent; cursor: pointer;
  --fill: 50%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 8px;
  background: linear-gradient(90deg, var(--sun-500) var(--fill), var(--surface-3) var(--fill));
}
input[type=range]::-moz-range-track { height: 8px; border-radius: 8px; background: var(--surface-3); }
input[type=range]::-moz-range-progress { height: 8px; border-radius: 8px; background: var(--sun-500); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 26px; height: 26px; margin-top: -9px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--sun-500); box-shadow: var(--shadow-2);
  transition: transform 120ms var(--ease);
}
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: var(--surface); border: 3px solid var(--sun-500); box-shadow: var(--shadow-2);
}
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.15); }
input[type=range]:focus-visible { box-shadow: none; }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: var(--ring); }
input[type=range]:focus-visible::-moz-range-thumb { box-shadow: var(--ring); }

.row { display: flex; gap: var(--space-3); }
.row > * { flex: 1; min-width: 0; }

/* ============================== cards & panels ============================== */
.card, .step {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.step {
  padding: var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-3);
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.step:focus-within { border-color: var(--line-strong); box-shadow: var(--shadow-2); }
.step h2 { font-size: var(--step-1); font-weight: 700; display: flex; gap: var(--space-3); align-items: center; }
.step h2 > span:first-child {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px;
  background: var(--navy-800); color: var(--sun-400); font-size: 0.85rem; font-weight: 800;
}
:root[data-theme="dark"] .step h2 > span:first-child { background: var(--sun-500); color: var(--sun-ink); }
details.step > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  min-height: var(--tap); border-radius: var(--radius-sm);
}
details.step > summary::-webkit-details-marker { display: none; }
details.step > summary::after, details.collapsible > summary::after {
  content: ""; flex: none; width: 10px; height: 10px; margin-right: 6px;
  border: solid var(--muted); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
  transition: transform var(--dur) var(--ease);
}
details[open].step > summary::after, details[open].collapsible > summary::after { transform: rotate(-135deg); }

.note {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-3); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted); font-size: var(--step--1);
}
.note.is-warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }
.note .note-action { align-self: flex-start; min-height: var(--tap); font-size: var(--step--1); }

.warn {
  display: flex; gap: var(--space-3); align-items: flex-start;
  background: var(--warn-bg); color: var(--warn-ink);
  border: 1px solid var(--warn-line); border-radius: var(--radius);
  padding: var(--space-3) var(--space-4); font-size: var(--step--1);
}
.warn::before { content: "⚠"; font-size: 1.1rem; line-height: 1.2; }

.status {
  min-height: 28px; margin: var(--space-3) 0 0; font-size: var(--step--1); font-weight: 600; color: var(--muted);
  display: flex; align-items: center; gap: var(--space-2);
}
.status:empty { visibility: hidden; }
.status.error { color: var(--danger); }
.status.error::before { content: "!"; display: grid; place-items: center; flex: none; width: 20px; height: 20px; border-radius: 50%; background: var(--danger-bg); font-weight: 800; }
.status.busy::before {
  content: ""; flex: none; width: 16px; height: 16px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--sun-500); animation: spin 0.8s linear infinite;
}

.ok-chip, .todo-chip { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 3px 9px; border-radius: var(--radius-pill); white-space: nowrap; }
.ok-chip { background: var(--ok-bg); color: var(--ok-ink); }
.todo-chip { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }

/* ============================== workspace (image & scan pages) ============================== */
.workspace {
  max-width: var(--page-max); width: 100%; margin: 0 auto;
  padding: var(--space-5) var(--gutter) var(--space-6);
  display: grid; gap: var(--space-5);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "work" "inputs" "report";
}
body[data-page="scan"] .workspace { grid-template-areas: "inputs" "work" "report"; }
.inputs { grid-area: inputs; display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.work { grid-area: work; }
.workspace > .report { grid-area: report; }

/* sticky bottom action bar (sticks while the inputs column is on screen) */
.action-bar {
  position: sticky; bottom: 0; z-index: 5;
  margin: 0 calc(-1 * var(--space-2));
  padding: var(--space-3) var(--space-2) calc(var(--space-3) + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--bg) 14px);
}
.action-bar button { width: 100%; }

/* ---------- image editor ---------- */
.stage-wrap { min-width: 0; }   /* no padding: app.js sizes the canvas from this element's width */
.stage {
  position: relative;
  background:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%, transparent 75%, var(--surface-2) 75%) 0 0 / 22px 22px,
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%, transparent 75%, var(--surface-2) 75%) 11px 11px / 22px 22px,
    var(--surface);
  border: 1px solid var(--line);   /* app.js / plan.js expect 8 px padding + 1 px border (18 px) */
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  min-height: 300px;
  display: flex;
  padding: 8px;
  overflow: auto;                  /* scrolls when zoomed in */
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;       /* pinch over the image zooms the image, not the page */
}
.placeholder { text-align: center; padding: var(--space-6) var(--space-4); max-width: 440px; margin: auto; display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.placeholder strong { font-family: var(--font-display); font-size: var(--step-2); display: block; color: var(--ink); }
.placeholder-icon {
  display: grid; place-items: center; width: 76px; height: 76px; border-radius: 22px; font-size: 36px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--sun-500) 25%, transparent), color-mix(in srgb, var(--green-500) 20%, transparent));
  animation: float 4s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateY(-6px); } }
.canvas-box { position: relative; line-height: 0; margin: auto; flex: none; border-radius: 6px; overflow: hidden; box-shadow: var(--shadow-2); }
.canvas-box canvas { display: block; max-width: none; }   /* zoom sets the size; it must not be capped */
#overlay { position: absolute; inset: 0; touch-action: none; cursor: crosshair; image-rendering: pixelated; }

.zoombar {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-3);
  padding: 6px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1);
}
.zoombar button { min-height: var(--tap); }
.zoombar button.icon { width: var(--tap); }
.zoombar button.active { background: var(--pv); border-color: var(--pv); color: #fff; }
.zoom-val { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; }
.zoom-hint { margin-left: var(--space-1); }

.legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); font-size: var(--step--1); color: var(--muted); align-items: center; margin-top: var(--space-2); }
.legend > span { display: inline-flex; align-items: center; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: 6px; }
.sw.roof { background: var(--roof); }
.sw.obs { background: var(--obs); }
.sw.panel { background: var(--pv); }
.sw.panel-small { background: var(--pv-small); }
.sw.panel-spare { background: transparent; border: 2px dashed var(--muted); }
.budget-note { margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--ok-bg); color: var(--ok-ink); border: 1px solid color-mix(in srgb, var(--ok-ink) 35%, transparent); }
.budget-note strong { display: block; margin-bottom: 2px; }
.budget-note p { margin: 0; }
#panelTypes tr.total td { font-weight: 800; background: var(--surface-2); }
.sw.setback { background: rgba(245, 158, 11, 0.55); }

/* brush toolbar under the image; sticky at the bottom of the screen on phones */
.editor-toolbar {
  margin-top: var(--space-3);
  display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr);
  padding: var(--space-3); border-radius: var(--radius);
  background: var(--glass); border: 1px solid var(--line); box-shadow: var(--shadow-2);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.editor-toolbar .tb-row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.editor-toolbar .tb-row > label { flex: 1 1 160px; }
.tools { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); }
.tool { background: var(--surface); color: var(--ink); border-color: var(--line-strong); box-shadow: none; font-size: var(--step--1); padding: 0 var(--space-2); }
.tool:hover { background: var(--surface-2); }
.tool .sw { margin-right: 0; }
.tool.active[data-tool="1"] { background: var(--roof); border-color: var(--roof); color: #04230f; }
.tool.active[data-tool="2"] { background: var(--obs); border-color: var(--obs); color: #fff; }
.tool.active[data-tool="0"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.tool.active[data-tool="point"] { background: var(--pv); border-color: var(--pv); color: #fff; }

.samples { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.samples button { padding: 0; min-height: 0; border: 2px solid var(--line); background: none; border-radius: 12px; overflow: hidden; line-height: 0; box-shadow: none; }
.samples button:hover { border-color: var(--sun-500); }
.samples img { width: 64px; height: 64px; object-fit: cover; }
.calib { display: flex; gap: var(--space-2); align-items: flex-end; }
.calib label { flex: 1; }

/* ---------- scan page ---------- */
.plan-stage { min-height: 300px; }
.plan-stage .placeholder p { margin: 0; }
#plan { display: block; margin: auto; touch-action: none; max-width: none; }
.plan-info { margin-top: var(--space-2); }
.howto { font-size: var(--step--1); color: var(--muted); border-radius: var(--radius-sm); background: var(--surface-2); padding: var(--space-2) var(--space-3); }
.howto summary { cursor: pointer; color: var(--ink); font-weight: 700; min-height: var(--tap); display: flex; align-items: center; }
.howto ol { margin: var(--space-2) 0 0; padding-left: 20px; display: grid; gap: 4px; }
.or { display: flex; align-items: center; gap: var(--space-3); color: var(--muted); font-size: var(--step--1); font-weight: 600; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.obs-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.obs-list:empty { display: none; }
.obs-list li {
  display: flex; align-items: center; gap: var(--space-2); min-height: var(--tap); padding: 4px 4px 4px var(--space-3);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface);
  transition: border-color var(--dur) var(--ease);
}
.obs-list li:hover { border-color: var(--line-strong); }
.obs-list li > span:first-child { flex: 1; font-weight: 600; }
.obs-list li.sel { border-color: var(--obs); box-shadow: 0 0 0 3px color-mix(in srgb, var(--obs) 18%, transparent); }
.obs-list button.icon { width: var(--tap); min-height: var(--tap); }

/* ============================== report ============================== */
.report { container-type: inline-size; display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.report:not([hidden]) { animation: rise 520ms var(--ease) both; }
.report-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.report-head h2 { font-size: var(--step-3); }

.summary-hero {
  position: relative; overflow: hidden; isolation: isolate;
  display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr);
  padding: clamp(18px, 3vw, 28px); border-radius: var(--radius-lg); color: #fff;
  background:
    radial-gradient(600px 260px at 100% 0%, rgba(255, 166, 0, 0.5), transparent 60%),
    linear-gradient(135deg, var(--navy-900), var(--navy-700));
  box-shadow: var(--shadow-3);
}
.sum-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sum-label { font-size: var(--step--1); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--sun-300); }
.sum-value {
  font-family: var(--font-display); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap;
  font-size: clamp(2rem, 9cqi, 3.1rem);   /* one column on phones */
}
@container (min-width: 520px) { .sum-value { font-size: clamp(1.7rem, 4.6cqi, 3.1rem); } }
.sum-unit { font-size: 0.5em; font-weight: 700; color: rgba(255, 255, 255, 0.8); margin-left: 4px; }
.sum-item small { color: rgba(255, 255, 255, 0.78); margin-top: 4px; }
.sum-item.is-key .sum-value { color: var(--sun-300); }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-4); border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow-1); min-width: 0;
  animation: rise 520ms var(--ease) both;
}
.kpi:nth-child(2) { animation-delay: 60ms; } .kpi:nth-child(3) { animation-delay: 120ms; }
.kpi:nth-child(4) { animation-delay: 180ms; } .kpi:nth-child(5) { animation-delay: 240ms; } .kpi:nth-child(6) { animation-delay: 300ms; }
.kpi-icon {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; margin-bottom: var(--space-2);
  background: color-mix(in srgb, var(--kpi-c, var(--sun-500)) 16%, transparent); color: var(--kpi-c, var(--sun-600));
}
.kpi-icon svg { width: 22px; height: 22px; }
.kpi > span:not(.kpi-icon) { font-family: var(--font-display); font-size: var(--step-3); font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi small { color: var(--muted); font-weight: 600; }
.kpi[data-kind="panels"] { --kpi-c: #2563eb; }
.kpi[data-kind="kw"] { --kpi-c: #e68a00; }
.kpi[data-kind="kwh"] { --kpi-c: #d97706; }
.kpi[data-kind="save"] { --kpi-c: #0f9d6a; }
.kpi[data-kind="pay"] { --kpi-c: #7c3aed; }
.kpi[data-kind="co2"] { --kpi-c: #16a34a; }

.tables { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
.data-table, .report table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-1); overflow: hidden; font-size: var(--step--1);
}
caption { text-align: left; font-family: var(--font-display); font-weight: 700; font-size: var(--step-1); padding: 0 0 var(--space-2) 2px; color: var(--ink); }
td, th { padding: 10px 14px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
tbody tr:first-child td { border-top: 0; }
thead th { border-top: 0; background: var(--surface-2); font-weight: 700; color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td.num { text-align: right; font-weight: 700; white-space: nowrap; }
#costs tr:nth-child(3) td { background: color-mix(in srgb, var(--sun-500) 12%, transparent); font-size: var(--step-0); }

details.collapsible {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-1); overflow: hidden;
}
details.collapsible > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  min-height: 56px; padding: 0 var(--space-4); font-family: var(--font-display); font-weight: 700; font-size: var(--step-1);
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary:hover { background: var(--surface-2); }
details.collapsible > summary small { font-family: var(--font-body); font-weight: 600; color: var(--muted); margin-left: auto; }
details.collapsible .table-wrap { border-top: 1px solid var(--line); }
details.collapsible table.assumptions { border: 0; border-radius: 0; box-shadow: none; }
.assumptions td { overflow-wrap: anywhere; }
.assumptions td:nth-child(3) { color: var(--muted); }

.installer-cta {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-5);
  padding: var(--space-4); border-radius: var(--radius-lg);
  background: linear-gradient(135deg, color-mix(in srgb, var(--green-500) 14%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in srgb, var(--green-500) 35%, var(--line));
}
.installer-cta p { flex: 1 1 220px; }
.installer-cta button { flex: 1 1 260px; }

/* report: more columns as its own width grows */
@container (min-width: 520px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .summary-hero { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tables { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container (min-width: 1000px) {
  .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
/* narrow report: assumption rows become stacked cards instead of a wide table */
@container (max-width: 560px) {
  .assumptions thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .assumptions tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px var(--space-3); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--line); }
  .assumptions tbody tr:first-child { border-top: 0; }
  .assumptions td { display: block; padding: 0; border: 0; }
  .assumptions td:nth-child(1) { font-weight: 700; }
  .assumptions td:nth-child(2) { grid-column: 1; grid-row: 2; font-variant-numeric: tabular-nums; }
  .assumptions td:nth-child(3) { grid-column: 1 / -1; font-size: 0.78rem; }
  .assumptions td:nth-child(4) { grid-column: 2; grid-row: 1; }
}

/* ============================== landing page ============================== */
.home-main { max-width: var(--page-max); width: 100%; margin: 0 auto; padding: 0 var(--gutter) var(--space-7); }
.choices { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); margin-top: calc(-1 * var(--space-6)); position: relative; z-index: 2; }
.choice {
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: clamp(20px, 3vw, 32px); border-radius: var(--radius-lg);
  background: var(--surface); color: inherit; text-decoration: none;
  border: 1px solid var(--line); box-shadow: var(--shadow-3);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
  animation: rise 600ms var(--ease) both;
}
.choice:nth-child(2) { animation-delay: 90ms; }
.choice:hover { transform: translateY(-4px); border-color: var(--sun-500); }
.choice:focus-visible { border-radius: var(--radius-lg); }
.choice-icon { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 18px; font-size: 30px; background: linear-gradient(135deg, var(--sun-300), var(--sun-500)); box-shadow: 0 10px 22px -10px rgba(230, 138, 0, 0.8); }
.choice:nth-child(2) .choice-icon { background: linear-gradient(135deg, var(--green-400), var(--green-500)); box-shadow: 0 10px 22px -10px rgba(22, 199, 132, 0.8); }
.choice h2 { font-size: var(--step-2); }
.choice p { color: var(--muted); }
.choice ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-weight: 600; }
.choice li { display: flex; gap: var(--space-2); align-items: baseline; }
.choice li::before { content: "✓"; color: var(--ok-ink); font-weight: 800; }
.choice-cta { margin-top: auto; padding-top: var(--space-2); display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 800; color: var(--link); }
.choice:hover .choice-cta { gap: var(--space-3); }

.how { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); margin-top: var(--space-6); counter-reset: how; }
.how h2 { grid-column: 1 / -1; font-size: var(--step-2); }
.how-step { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-4); border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.how-step b { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; background: var(--navy-800); color: var(--sun-400); font-family: var(--font-display); }
:root[data-theme="dark"] .how-step b { background: var(--sun-500); color: var(--sun-ink); }
.how-step span { font-weight: 700; }
.how-step small { color: var(--muted); font-weight: 500; }

/* ============================== installers page ============================== */
.inst-page { max-width: 1180px; width: 100%; margin: 0 auto; padding: var(--space-5) var(--gutter) var(--space-7); display: flex; flex-direction: column; gap: var(--space-5); }
.inst-page h2 { font-size: var(--step-2); margin-bottom: var(--space-3); }
.back-link { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); font-weight: 700; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.inst-summary, .inst-loc { padding: clamp(16px, 2.5vw, 24px); }
.inst-summary .kpis { margin-bottom: var(--space-3); }
.inst-summary p + p { margin-top: var(--space-2); }
.inst-summary .kpi { animation: none; }
.inst-loc { display: flex; flex-direction: column; gap: var(--space-3); }
.inst-loc h2 { margin: 0; }
.inst-loc-actions { display: flex; gap: var(--space-3); align-items: end; flex-wrap: wrap; }
.inst-loc-actions > * { flex: 1 1 220px; }
.inst-loc-actions label { color: var(--ink); }

.inst-filters {
  display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr);
  padding: var(--space-4); border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1);
}
.inst-filters label { color: var(--ink); }
.inst-filters label.inline { font-weight: 600; }

.inst-list { container-type: inline-size; list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
@media (min-width: 760px) { .inst-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.inst-card { container-type: inline-size; animation: rise 420ms var(--ease) both; }
.inst-card article {
  height: 100%; display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-4); border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2);
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.inst-card article:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.inst-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.inst-card h3 { font-size: var(--step-1); overflow-wrap: anywhere; }
.dist {
  font-size: 0.75rem; font-weight: 800; white-space: nowrap; padding: 4px 10px; border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--sun-500) 18%, transparent); color: var(--warn-ink); border: 1px solid var(--warn-line);
}
.inst-contact { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.inst-contact a {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 0 var(--space-3);
  border-radius: var(--radius-sm); border: 1.5px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font-weight: 700; font-size: var(--step--1); text-decoration: none; text-align: center;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform 120ms var(--ease);
}
.inst-contact a:hover { border-color: var(--ink); background: var(--surface-2); }
.inst-contact a:active { transform: scale(0.97); }
.inst-contact a.call {
  grid-column: 1 / -1; min-height: 52px; font-size: var(--step-0); color: #fff; border-color: transparent;
  background: linear-gradient(180deg, #13a86f, #0b8a59); box-shadow: 0 10px 22px -12px rgba(11, 138, 89, 0.9);
}
.inst-contact a.call:hover { background: linear-gradient(180deg, #16b97a, #0d9a63); }
.inst-contact a.call span { font-weight: 500; opacity: 0.95; }
@container (min-width: 460px) { .inst-contact { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.inst-card dl { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; font-size: var(--step--1); }
.inst-card dt { color: var(--muted); font-weight: 700; font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; margin-top: var(--space-2); }
.inst-card dd { margin: 0; overflow-wrap: anywhere; }
@container (min-width: 460px) {
  .inst-card dl { grid-template-columns: max-content minmax(0, 1fr); gap: 6px var(--space-4); }
  .inst-card dt { margin-top: 0; }
}
.report-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.report-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.history { max-width: var(--page-max); width: 100%; margin: 0 auto; padding: 0 var(--gutter) var(--space-6); }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.history-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-3); }
.history-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); }
.history-item img { width: 84px; height: 60px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
.history-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.history-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
@media (max-width: 599px) { .history-item { flex-wrap: wrap; } .history-actions { width: 100%; justify-content: flex-start; } }
.photo-plan { margin: 0 0 var(--space-4); padding: var(--space-3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.photo-plan figcaption { font-family: var(--font-display); font-weight: 700; font-size: var(--step-1); margin-bottom: var(--space-2); }
.photo-plan canvas { display: block; width: 100%; max-width: 100%; }
.advanced { margin-top: var(--space-3); border-top: 1px solid var(--line); padding-top: var(--space-2); }
.advanced summary { cursor: pointer; font-weight: 700; font-size: var(--step--1); color: var(--muted); }
.advanced[open] summary { margin-bottom: var(--space-2); }
.obs-sizes ul { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: grid; gap: var(--space-2); }
.obs-sizes li.obs-card { display: block; padding: var(--space-3); border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.obs-sizes .obs-card .row { margin-top: 4px; flex-wrap: wrap; }
.obs-sizes .obs-card .row > label { flex: 1 1 calc(50% - var(--space-3)); min-width: 0; }
.obs-head { display: flex; align-items: center; gap: 8px; font-size: var(--step--1); font-weight: 700; margin-bottom: 6px; }
.obs-badge { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #7f1d1d; color: #fff; border: 2px solid #fff; font-size: 0.8rem; flex: none; }
.side-preview { margin: var(--space-3) 0 0; padding: var(--space-3); border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.side-preview figcaption { font-weight: 700; font-size: var(--step--1); margin-bottom: 4px; }
.side-preview svg { display: block; width: 100%; max-width: 360px; height: auto; margin: 0 auto; }
.side-preview .note { margin-top: var(--space-2); }
.shape-choice { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-bottom: var(--space-2); }
.obs-sizes li > span { grid-column: 1 / -1; font-size: var(--step--1); font-weight: 700; }
.demo-badge { display: inline-block; margin: 4px 0 0; padding: 3px 10px; border-radius: var(--radius-pill); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.04em; color: var(--warn-ink); background: var(--warn-bg); border: 1px solid var(--warn-line); }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { font-size: 0.74rem; font-weight: 600; padding: 3px 10px; border-radius: var(--radius-pill); border: 1px solid var(--line); background: var(--surface-2); }
.inst-source { margin-top: auto; padding-top: var(--space-2); border-top: 1px dashed var(--line); }
.inst-source a { color: inherit; }
.inst-empty { text-align: center; padding: var(--space-6) var(--space-4); border-radius: var(--radius-lg); border: 2px dashed var(--line-strong); background: var(--surface); display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.inst-empty .placeholder-icon { margin-bottom: var(--space-2); }
.inst-empty .small { max-width: 60ch; margin-top: var(--space-2); }
.inst-empty button { margin-top: var(--space-3); }

/* loading skeletons (installers.js shows them while a request runs) */
.skeleton { list-style: none; padding: var(--space-4); border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line); display: grid; gap: var(--space-3); }
.skeleton i { display: block; height: 14px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.skeleton i:nth-child(1) { height: 22px; width: 60%; }
.skeleton i:nth-child(2) { height: 52px; border-radius: var(--radius-sm); }
.skeleton i:nth-child(3) { width: 85%; }
.skeleton i:nth-child(4) { width: 70%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============================== footer ============================== */
.site-footer { margin-top: auto; background: var(--navy-950); color: rgba(255, 255, 255, 0.78); font-size: var(--step--1); }
.footer-inner { max-width: var(--page-max); margin: 0 auto; padding: var(--space-6) var(--gutter); display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
.site-footer .brand-name { color: #fff; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.site-footer a { color: #fff; font-weight: 600; }
.site-footer a:focus-visible { box-shadow: 0 0 0 3px var(--navy-950), 0 0 0 6px var(--sun-400); }
.site-footer p { max-width: 80ch; }

/* ============================== motion ============================== */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.fade-in { animation: rise 520ms var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important; animation-iteration-count: 1 !important;
    transition-duration: 1ms !important; scroll-behavior: auto !important;
  }
}

/* ============================== AR measuring screen (WebXR dom-overlay over the camera) ==============================
   Phone-first: slim top bar, big Place button, one compact row of actions, centre kept clear. */
.ar-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  pointer-events: none; color: #fff; font-size: 14px; line-height: 1.35; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.ar-panel {
  pointer-events: auto; background: rgba(5, 11, 31, 0.55);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 18px; padding: 8px 12px;
  width: 100%; max-width: 560px; margin: 0 auto;
}
.ar-track { font-size: 12px; font-weight: 700; color: var(--sun-400); }
.ar-track.ok { color: var(--green-400); }
#arMsg { font-size: 13px; opacity: 0.95; }
.ar-live { font-family: var(--font-display); font-size: 24px; font-weight: 800; margin: 2px 0; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ar-list { font-size: 12px; opacity: 0.9; }
.ar-debug { font: 10px/1.3 ui-monospace, monospace; opacity: 0.7; white-space: pre-wrap; margin-top: 4px; }
.ar-warn { color: var(--sun-400); font-weight: 600; }
.ar-bottom { display: flex; flex-wrap: wrap; gap: 6px; }
.ar-bottom button {
  flex: 1 1 calc(33% - 6px); min-width: 0; min-height: var(--tap); padding: 0 6px; font-size: 13px;
  border-radius: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: none;
  color: var(--sun-ink); background: var(--sun-500); border-color: var(--sun-600);
}
.ar-bottom button.secondary { color: #fff; background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.45); }
.ar-bottom button.place { flex: 1 1 100%; font-size: 18px; min-height: 56px; font-weight: 800; }
.ar-bottom button:disabled { opacity: 0.35; }
.ar-crosshair {
  position: fixed; left: 50%; top: 50%; width: 40px; height: 40px; margin: -20px 0 0 -20px;
  border: 2px solid rgba(255, 255, 255, 0.95); border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(0, 0, 0, 0.35); pointer-events: none;
}
.ar-crosshair::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px;
  border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
}
@media (max-height: 520px) {  /* phone held sideways */
  .ar-live { font-size: 18px; }
  #arMsg, .ar-list { display: none; }
  .ar-bottom button { min-height: 38px; }
  .ar-bottom button.place { min-height: 44px; font-size: 16px; }
}

/* ============================== responsive (mobile first) ============================== */
/* phones: hide what does not fit, keep the editor toolbar on screen while editing */
@media (max-width: 599px) {
  .brand-tag, .badge { display: none; }
  .brand-mark { width: 36px; height: 36px; }
  .nav { padding: 3px; }
  .nav a { padding: 0 10px; min-height: var(--tap); }
  .nav a .nav-text { display: none; }   /* icons only; each link keeps an aria-label */
  .nav a .icon-svg { width: 20px; height: 20px; }
  .step-label { font-size: 0.72rem; }
  .steps { gap: 4px; }
  .steps a { flex-direction: column; gap: 2px; text-align: center; }
  .zoom-hint { display: none; }
  .editor-toolbar { position: sticky; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 6; }
  .stage { min-height: 260px; }
  td, th { padding: 9px 10px; }
}

/* tablets and small laptops: the navbar has room for the name, not the tagline */
@media (max-width: 1023px) { .brand-tag { display: none; } .badge { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; } }

/* very narrow phones: the logo alone stands for the name (still read out by screen readers) */
@media (max-width: 399px) {
  .brand-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .site-footer .brand-name { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
}

/* tablets */
@media (min-width: 600px) {
  .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .how { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .footer-inner { grid-template-columns: auto 1fr; align-items: start; }
  .footer-inner > p { grid-column: 1 / -1; }
  .inst-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inst-filters .grow { grid-column: 1 / -1; }
}

/* desktop: two columns, inputs on the left (scrolling on their own), editor + report on the right */
@media (min-width: 1024px) {
  .workspace,
  body[data-page="scan"] .workspace {
    grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "inputs work" "inputs report";
    align-items: start;
  }
  .inputs {
    position: sticky; top: calc(var(--header-h) + var(--space-4));
    max-height: calc(100dvh - var(--header-h) - var(--space-5));
    overflow-y: auto; overscroll-behavior: contain;
    padding: 2px 6px 0 2px; margin: -2px -6px 0 -2px;   /* room for focus rings inside the scroll box */
    scrollbar-width: thin;
  }
  .action-bar { margin: 0; padding-inline: 0; }
  .how { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .inst-filters { grid-template-columns: 2fr 1fr 1fr; align-items: end; }
  .inst-filters .grow { grid-column: auto; }
  .inst-filters label.inline, .inst-filters #resetBtn { grid-column: auto; }
}

@media (min-width: 1024px) and (max-height: 760px) {  /* short laptop screens, e.g. 1366 x 768 */
  .hero--page .hero-inner { padding-block: 18px; }
  .step { padding: var(--space-3); gap: var(--space-2); }
}

@media print {
  .site-header, .site-footer, .action-bar, .editor-toolbar, .installer-cta, .theme-toggle { display: none !important; }
  .inputs { position: static; max-height: none; overflow: visible; }
  body { background: #fff; color: #000; }
}

/* ============================== help chat ============================== */
.chat-fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 90;
  display: inline-flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 18px 0 14px;
  border-radius: var(--radius-pill); border: 0; cursor: pointer; font: 800 0.95rem/1 var(--font-body);
  color: var(--sun-ink); background: linear-gradient(135deg, var(--sun-300), var(--sun-500));
  box-shadow: 0 10px 26px -8px rgba(230, 138, 0, 0.75);
}
.chat-fab span[aria-hidden] { font-size: 1.3rem; }
.chat-fab.raised { bottom: calc(92px + env(safe-area-inset-bottom)); }
@media (min-width: 1024px) { .chat-fab.raised { bottom: calc(16px + env(safe-area-inset-bottom)); } }
.chat-panel {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 91;
  width: min(400px, calc(100vw - 32px)); height: min(600px, calc(100vh - 32px)); height: min(600px, calc(100dvh - 32px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 24px 60px -18px rgba(5, 11, 31, 0.55);
}
.chat-panel[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.chat-head > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-sub { font-size: 0.78rem; color: var(--muted); }
.chat-head button { min-height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 700; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; font-size: 0.92rem; line-height: 1.5; overflow-wrap: anywhere; }
.chat-msg p { margin: 0 0 6px; } .chat-msg p:last-child { margin-bottom: 0; }
.chat-msg ol { margin: 4px 0 6px; padding-left: 1.2em; } .chat-msg li { margin: 3px 0; }
.chat-msg.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 4px; }
.chat-msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-msg.typing { display: flex; gap: 5px; padding: 14px 16px; }
.chat-msg.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: chat-dot 1s infinite ease-in-out; }
.chat-msg.typing span:nth-child(2) { animation-delay: 0.15s; } .chat-msg.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .chat-msg.typing span { animation: none; } }
.chat-chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 10px; }
.chat-chips:empty { display: none; }
.chat-chip { flex: none; min-height: 34px; padding: 0 12px; border-radius: var(--radius-pill); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-size: 0.8rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.chat-input { flex: 1; min-width: 0; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink); font: inherit; font-size: 16px; }
.chat-send { min-width: 48px; min-height: 44px; border-radius: 12px; border: 0; cursor: pointer; font-size: 1.1rem; color: var(--sun-ink); background: var(--sun-500); }
.chat-send:disabled { opacity: 0.5; }
@media (max-width: 599px) {
  .chat-panel { right: 0; left: 0; bottom: 0; width: 100%; height: 85vh; height: 85dvh; border-radius: 18px 18px 0 0; }
  .chat-fab-label { display: none; }
  .chat-fab { width: 56px; padding: 0; justify-content: center; }
}
@media print { .chat-fab, .chat-panel { display: none !important; } }
