/* ============================================================
   Webrex — Sitewide lead popup
   Markup: src/_includes/components/lead-popup.njk
   Brand: black, white, Webrex blue (--w-accent). Buttons reuse
   .w-cta-primary / .w-cta-secondary from buttons.css.
   Loaded non-blocking (media="print" swap), so nothing here
   affects first paint.
   ============================================================ */

.wr-lead {
  --lead-accent: var(--w-accent, #4065C3);
  --lead-accent-soft: var(--w-accent-soft, #294185);
  --lead-ink: var(--w-black, #000);
  --lead-text: #3f3f46;
  --lead-muted: #71717a;
  --lead-line: #e4e4e7;
  --lead-error: #dc2626;
  --lead-ease: cubic-bezier(.22, 1, .36, 1);

  position: fixed;
  inset: 0;
  z-index: 1001; /* above header, same layer family as .w-cal-modal */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 40px);
  font-family: var(--w-btn-font, "Poppins", system-ui, sans-serif);
  overscroll-behavior: contain;
}
.wr-lead[hidden] { display: none; }

.wr-lead__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity .3s ease;
  touch-action: none; /* swiping the backdrop must not scroll the page behind (iOS) */
}

.wr-lead__dialog {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: 100%;
  max-width: 460px;
  max-height: 100%; /* root is sized to the visible screen (keyboard-aware) */
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 36px 32px 28px;
  background: #fff;
  color: var(--lead-text);
  border-radius: 20px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .35), 0 0 0 1px rgba(0, 0, 0, .04);
  opacity: 0;
  transform: translateY(16px) scale(.97);
  transition: opacity .35s var(--lead-ease), transform .45s var(--lead-ease);
  outline: none;
}
/* Brand accent strip */
.wr-lead__dialog::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--lead-accent), var(--lead-accent-soft));
  border-radius: 20px 20px 0 0;
}

.wr-lead.is-open .wr-lead__backdrop { opacity: 1; }
.wr-lead.is-open .wr-lead__dialog { opacity: 1; transform: none; }

.wr-lead__close {
  position: absolute;
  top: 14px; right: 14px;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: #f4f4f5; color: var(--lead-ink);
  cursor: pointer;
  transition: background-color .2s ease, color .2s ease, transform .2s ease;
}
@media (hover: hover) {
  .wr-lead__close:hover { background: var(--lead-ink); color: #fff; transform: rotate(90deg); }
}
.wr-lead__close:focus-visible { outline: 2px solid var(--lead-accent); outline-offset: 2px; }

.wr-lead__eyebrow {
  display: inline-block;
  margin: 0 0 12px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(64, 101, 195, .1);
  color: var(--lead-accent);
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
}
.wr-lead__title {
  margin: 0 0 8px;
  padding-right: 28px;
  color: var(--lead-ink);
  font-size: clamp(20px, 2.4vw, 24px);
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -.02em;
  outline: none;
}
.wr-lead__sub {
  margin: 0 0 22px;
  color: var(--lead-muted);
  font-size: 14.5px;
  line-height: 1.55;
}

.wr-lead__form { display: grid; gap: 14px; }
.wr-lead__field { display: grid; gap: 6px; }
.wr-lead__field label {
  font-size: 13px; font-weight: 500; color: var(--lead-ink);
}
.wr-lead__field label span { color: var(--lead-accent); }
.wr-lead__field input,
.wr-lead__field select,
.wr-lead__field textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  border: 1.5px solid var(--lead-line);
  border-radius: 12px;
  background: #fff;
  color: var(--lead-ink);
  font: inherit;
  font-size: 16px; /* under 16px makes iOS/iPadOS zoom in on focus */
  transition: border-color .2s ease, box-shadow .2s ease;
  -webkit-appearance: none;
  appearance: none;
}
.wr-lead__field textarea { min-height: 84px; resize: vertical; }
.wr-lead__field input::placeholder,
.wr-lead__field textarea::placeholder { color: #a1a1aa; }
.wr-lead__field input:focus,
.wr-lead__field select:focus,
.wr-lead__field textarea:focus {
  outline: none;
  border-color: var(--lead-accent);
  box-shadow: 0 0 0 4px rgba(64, 101, 195, .15);
}
/* Phone: country code dropdown + number */
.wr-lead__phone {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
}
.wr-lead__cc {
  position: relative;
  min-width: 96px;
}
.wr-lead__cc-display {
  box-sizing: border-box;
  display: flex; align-items: center; gap: 6px;
  height: 100%; min-height: 46px;
  padding: 0 12px;
  border: 1.5px solid var(--lead-line);
  border-radius: 12px;
  background: #fafafa;
  color: var(--lead-ink);
  font-size: 15px; font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.wr-lead__cc-display svg { margin-left: auto; color: var(--lead-muted); }
/* The real <select> sits on top, invisible, so the native picker
   (with search-by-typing on desktop, wheel on mobile) still works. */
.wr-lead__cc select {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px;
}
.wr-lead__cc:focus-within .wr-lead__cc-display {
  border-color: var(--lead-accent);
  box-shadow: 0 0 0 4px rgba(64, 101, 195, .15);
}
.wr-lead__field.has-error .wr-lead__cc-display { border-color: var(--lead-error); }
.wr-lead__hint { font-size: 12px; color: var(--lead-muted); }

.wr-lead__field.has-error input,
.wr-lead__field.has-error select,
.wr-lead__field.has-error textarea { border-color: var(--lead-error); }
.wr-lead__field.has-error input:focus { box-shadow: 0 0 0 4px rgba(220, 38, 38, .12); }

.wr-lead__consent {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 12.5px; line-height: 1.5; color: var(--lead-muted);
  cursor: pointer;
}
.wr-lead__consent input {
  flex: none;
  width: 18px; height: 18px;
  margin: 1px 0 0;
  accent-color: var(--lead-accent);
  cursor: pointer;
}
.wr-lead__consent a { color: var(--lead-accent); text-decoration: underline; text-underline-offset: 2px; }
.wr-lead__consent.has-error span { color: var(--lead-error); }

.wr-lead__error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fef2f2;
  color: var(--lead-error);
  font-size: 13px;
}
.wr-lead__error[hidden] { display: none; }

/* Honeypot: off-screen, not display:none (some bots skip hidden fields) */
.wr-lead__hp {
  position: absolute !important;
  left: -9999px; top: auto;
  width: 1px; height: 1px;
  overflow: hidden;
}

.wr-lead__actions { display: grid; gap: 10px; }
.wr-lead__submit { justify-content: center; width: 100%; margin-top: 4px; }
.wr-lead__submit[disabled] { opacity: .7; cursor: progress; }

/* Success view */
.wr-lead__success { text-align: center; padding: 8px 0 4px; }
.wr-lead__success .wr-lead__title { padding-right: 0; }
.wr-lead__success .w-cta-secondary { margin-top: 4px; }
.wr-lead__check {
  display: inline-flex; align-items: center; justify-content: center;
  width: 60px; height: 60px; margin-bottom: 16px;
  border-radius: 50%;
  background: var(--lead-accent); color: #fff;
  animation: wr-lead-pop .5s var(--lead-ease) both;
}
@keyframes wr-lead-pop {
  from { transform: scale(.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Stray tap on the backdrop after typing: gentle shake instead of closing */
.wr-lead__dialog.wr-lead--nudge { animation: wr-lead-nudge .35s ease; }
@keyframes wr-lead-nudge {
  0%, 100% { transform: none; }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Hide floating widgets (Crisp chat bubble) while the popup is open so they
   can't cover the submit button on phones */
html.wr-lead-lock .crisp-client,
html.wr-lead-lock #crisp-chatbox { display: none !important; }

/* Page scroll lock while open */
html.wr-lead-lock,
html.wr-lead-lock body { overflow: hidden; }

/* Phones: small centred card. Labels are visually hidden (field names
   move into the placeholders via lead-popup.js), eyebrow hidden, tight
   spacing, so the whole form and button fit without scrolling, even with
   browser toolbars showing (tested down to 320x480). */
@media (max-width: 640px) {
  .wr-lead { padding: 12px; }
  .wr-lead__dialog {
    max-width: 400px;
    max-height: 100%;
    padding: 18px 16px 16px;
    border-radius: 18px;
  }
  .wr-lead__dialog::before { border-radius: 18px 18px 0 0; height: 3px; }
  .wr-lead__close { top: 10px; right: 10px; width: 32px; height: 32px; }
  .wr-lead__eyebrow { display: none; }
  .wr-lead__title { font-size: 18px; line-height: 1.25; margin: 0 0 4px; padding-right: 34px; }
  .wr-lead__sub { font-size: 13px; line-height: 1.45; margin-bottom: 12px; }
  .wr-lead__form { gap: 8px; }
  .wr-lead__field { gap: 0; }
  .wr-lead__label {
    position: absolute !important;
    width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .wr-lead__field input,
  .wr-lead__field select,
  .wr-lead__field textarea { min-height: 42px; padding: 8px 12px; border-radius: 10px; }
  .wr-lead__phone { gap: 6px; }
  .wr-lead__cc { min-width: 86px; }
  .wr-lead__cc-display { min-height: 42px; padding: 0 10px; border-radius: 10px; font-size: 15px; }
  .wr-lead__consent { font-size: 11.5px; line-height: 1.4; gap: 8px; margin-top: 2px; }
  .wr-lead__consent input { width: 16px; height: 16px; }
  .wr-lead__actions { gap: 8px; }
  .wr-lead__error { padding: 8px 10px; font-size: 12.5px; }
  .wr-lead__submit { margin-top: 2px; padding-top: 10px !important; padding-bottom: 10px !important; }
  .wr-lead__check { width: 52px; height: 52px; margin-bottom: 12px; }
}

/* Extremely short screens: drop the subtitle */
@media (max-width: 640px) and (max-height: 500px) {
  .wr-lead__sub { display: none; }
  .wr-lead__title { margin-bottom: 12px; }
}

/* Very small phones (iPhone SE, Galaxy Fold closed) */
@media (max-width: 360px) {
  .wr-lead { padding: 8px; }
  .wr-lead__dialog { padding: 16px 14px 14px; }
  .wr-lead__cc { min-width: 78px; }
  .wr-lead__cc-display { padding: 0 8px; gap: 4px; }
}

/* Laptops with short screens (e.g. 1366x768): slightly tighter so the
   form + an error message still fit without scrolling */
@media (min-width: 641px) and (max-height: 820px) {
  .wr-lead__dialog { padding: 30px 30px 22px; }
  .wr-lead__sub { margin-bottom: 16px; }
  .wr-lead__form { gap: 11px; }
  .wr-lead__field input,
  .wr-lead__field select,
  .wr-lead__field textarea,
  .wr-lead__cc-display { min-height: 44px; }
}

/* Short screens (phones in landscape, small laptops): tighter spacing, dialog scrolls */
@media (max-height: 560px) and (min-width: 641px) {
  .wr-lead__dialog { padding-top: 26px; padding-bottom: 18px; }
  .wr-lead__eyebrow { margin-bottom: 8px; }
  .wr-lead__sub { margin-bottom: 14px; }
  .wr-lead__form { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .wr-lead__backdrop,
  .wr-lead__dialog { transition: opacity .2s linear; transform: none; }
  .wr-lead__check,
  .wr-lead__dialog.wr-lead--nudge { animation: none; }
}
