/* NEF Lead Collection — single-screen intake form, tuned for iPhone. */

:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f7f7fa;
  --text: #11131a;
  --text-dim: #6b7280;
  --line: #e3e3ea;
  /* Sampled from the wordmark in icons/logo.png. */
  --accent: #1d5781;
  --good: #17803d;
  --good-bg: #e6f6ec;
  --warn: #a55a00;
  --warn-bg: #fdf1de;
  --far: #b3261e;
  --far-bg: #fdeceb;
  --radius: 14px;
  --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f5f5f7;
    --text-dim: #9a9aa2;
    --line: #38383a;
    /* The brand navy is too dark to read on black, so lift it for dark mode. */
    --accent: #64a8dd;
    --good: #5fd67f;
    --good-bg: #10301b;
    --warn: #ffb454;
    --warn-bg: #362508;
    --far: #ff7a70;
    --far-bg: #3a1310;
  }
}

* { box-sizing: border-box; }

/* Several elements below set an explicit `display`, which would otherwise beat
   the user-agent's [hidden] rule and leave "hidden" nodes on screen. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    calc(env(safe-area-inset-bottom) + 24px)
    env(safe-area-inset-left);
}

.topbar {
  padding: 22px 20px 10px;
  max-width: 560px;
  margin: 0 auto;
}
/* A dedicated dark-mode artwork is swapped in via <picture>, so the wordmark
   needs no plate and no filter — it sits directly on the background. */
.topbar picture { display: block; }

.logo {
  display: block;
  /* Sized by width so it scales predictably on narrow phones; the cap keeps
     it from dominating the screen on wider ones. */
  width: min(300px, 82%);
  height: auto;
  margin: 2px auto 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-weight: 700;
}
.topbar .sub {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 15px;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- fields ---------- */

.field {
  margin: 0 0 18px;
  border: 0;
  padding: 0;
}

label,
legend,
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 6px;
  padding: 0;
}

.optional {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  opacity: 0.7;
}

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="password"],
textarea {
  width: 100%;
  /* 16px minimum, or Safari zooms the whole page on focus. */
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  min-height: var(--tap);
  appearance: none;
}

textarea { resize: vertical; line-height: 1.4; }

input:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.hint {
  margin: 6px 2px 0;
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------- town combobox ---------- */

.combo { position: relative; }

.combo-status {
  position: absolute;
  right: 13px;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}
.combo.is-busy .combo-status {
  opacity: 1;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.suggestions {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.suggestions li {
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.suggestions li[aria-selected="true"],
.suggestions li:hover {
  background: var(--surface-2);
}
.suggestions .s-main { font-weight: 600; }
.suggestions .s-sub { font-size: 14px; color: var(--text-dim); }

/* ---------- result card ---------- */

.result {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  margin: 0 0 20px;
  overflow: hidden;
}

.result-town {
  margin: 0;
  font-weight: 600;
  font-size: 17px;
}
.result-civic {
  margin: 3px 0 0;
  color: var(--text-dim);
  font-size: 15px;
}

.badge {
  margin: 14px 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface-2);
}
.badge-metric {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.badge-label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge.tone-good { background: var(--good-bg); color: var(--good); }
.badge.tone-warn { background: var(--warn-bg); color: var(--warn); }
.badge.tone-far  { background: var(--far-bg);  color: var(--far);  }
.badge.tone-none { color: var(--text-dim); }

.map-wrap {
  position: relative;
  /* Taller than the old 2:1 strip — there's no point being able to pan and
     zoom through a letterbox. */
  aspect-ratio: 3 / 2;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}

/* Static fallback, sitting underneath the interactive canvas. */
.map-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--surface-2);
}

/* Two classes on purpose. Mapbox GL's stylesheet is injected at runtime, so it
   lands after this file, and its `.mapboxgl-map { position: relative }` would
   otherwise win on source order and collapse the container to zero height. */
.map-wrap .map-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Revealed only once the map has painted, so a map that initialises but
     never draws can't cover the static image with a black rectangle. */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.map-wrap .map-canvas.is-ready {
  opacity: 1;
  pointer-events: auto;
}

.map-cta {
  position: absolute;
  /* Top-left is the only free corner: Mapbox puts its logo bottom-left,
     attribution bottom-right, and the zoom controls sit top-right. */
  left: 10px;
  top: 10px;
  /* Above Mapbox's own control containers, which sit at z-index 2. */
  z-index: 3;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  text-decoration: none;
}

/* Mapbox's own controls, nudged to match the app's rounding. */
.map-wrap .mapboxgl-ctrl-group { border-radius: 10px; }

.warn-strip {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 14px;
}

/* ---------- segmented control ---------- */

/* minmax is sized so the longest label ("Replacement") never overflows its
   cell on a 375px-wide iPhone. */
.segmented {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.seg {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  min-height: var(--tap);
  padding: 10px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  appearance: none;
}
.seg[aria-checked="true"],
.seg[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* These carry an icon and a longer label ("Returning customer"), which
   would overflow the fixed single line the other segments use. */
.seg-flag {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: normal;
  line-height: 1.25;
  font-size: 15px;
  padding: 8px 10px;
}
.seg-flag .glyph { width: 18px; height: 18px; }

/* Lead source: eight options, so they're smaller than the other segments —
   three across on a 375px iPhone — with the logo stacked over the label. */
.segmented.sources {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}

.seg-source {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  line-height: 1.2;
  padding: 10px 6px;
  white-space: normal;
}

/* Icons are painted with the text colour through a mask, so one plain SVG
   works on light, dark and the selected (white-on-blue) state. */
.glyph {
  width: 22px;
  height: 22px;
  flex: none;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

/* ---------- sign-in screens ---------- */

/* The page heading and tagline belong to the lead form, not the sign-in. */
body.is-gated .topbar h1,
body.is-gated .topbar .sub { display: none; }

.gate {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 20px;
}

.gate-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gate-panel h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.gate-sub {
  margin: 4px 0 18px;
  color: var(--text-dim);
  font-size: 15px;
}

.gate-panel .btn { margin-top: 4px; }

.qr {
  display: block;
  width: 180px;
  height: 180px;
  margin: 8px 0;
  padding: 8px;
  /* QR codes need dark on light to scan, whatever the theme. */
  background: #fff;
  border-radius: 10px;
}

.setup-key {
  display: block;
  margin: 6px 0 14px;
  font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  user-select: all;
  -webkit-user-select: all;
}

.gate-error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--far-bg);
  color: var(--far);
  font-size: 15px;
}

#gate-sign-out { margin: 18px auto 0; }

/* ---------- after sending ---------- */

.sent {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sent p {
  margin: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--good);
}
.sent.is-warn p { color: var(--far); }

.btn.is-busy { opacity: 0.7; pointer-events: none; }

.account {
  margin: 28px 0 0;
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
}

.link-button {
  font: inherit;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 8px 4px;
  cursor: pointer;
}

/* ---------- recipient ---------- */

#recipient-hint { margin-top: 8px; }

.manual-label { margin-top: 10px; }

/* ---------- preview ---------- */

.preview { margin: 0 0 20px; }

.preview-toggle {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 8px 0;
  min-height: 40px;
  cursor: pointer;
}

.preview-body {
  margin: 4px 0 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* ---------- actions ---------- */

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 6px 0 0;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  min-height: 52px;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--accent); border-color: var(--line); }
.btn-quiet {
  background: none;
  color: var(--text-dim);
  min-height: 44px;
  font-size: 15px;
  font-weight: 500;
}

.btn.is-disabled {
  opacity: 0.42;
  pointer-events: none;
}

.missing {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
