/* ==========================================================================
   The Home Insulators - contact / lead form.

   Loaded ONLY by page-contact.php (handle "thi-leads", dependency "thi-style"),
   so it can never affect the rest of the site. Every selector is scoped to
   .thi-lead-box or a .thi- class - nothing here restyles a shared element.

   Everything is built out of the theme's own tokens (--navy, --ink, --line,
   --ember, --surface, --shadow ...), which are already redefined for dark mode
   in style.css, so this file is dark-mode-correct without a single media query
   of its own. The two exceptions are the error and success colours, which the
   theme has no token for; they are declared as local variables on .thi-lead-box
   with a dark-mode override that matches style.css's own guard pattern
   (:root:not([data-theme="light"])).

   Mobile-first: the base rules are the phone layout, and the only width query
   is a small comfort bump at 560px and up.
   ========================================================================== */

.thi-lead-box {
  /* Local tokens. Not in style.css - errors and confirmations have no theme colour. */
  --thi-err: #C0261C;
  --thi-err-bg: #FCEDEC;
  --thi-err-line: #E9B6B1;
  --thi-ok: #14663C;
  --thi-ok-bg: #E7F4EC;
  --thi-ok-line: #B5DCC5;
  --thi-field-gap: 18px;

  position: relative;
  /* Deliberately NOT overflow:hidden. Google's autocomplete dropdown is
     positioned out of the address field, and clipping it to the card would cut
     the suggestions off. The thermal bar below gets its own rounded corners
     instead. */
}

/* A thin thermal rule across the top of the card, the same gradient the hero
   and the header mark use. Ties the form to the brand without adding weight. */
.thi-lead-box::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 4px;
  border-radius: 17px 17px 0 0;
  background: var(--thermal);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .thi-lead-box {
    --thi-err: #FF8F82;
    --thi-err-bg: #2C1614;
    --thi-err-line: #5A2C26;
    --thi-ok: #79D9A6;
    --thi-ok-bg: #10281C;
    --thi-ok-line: #22523A;
  }
}

/* --------------------------------------------------------------- the form */

.thi-form {
  display: flex;
  flex-direction: column;
  gap: var(--thi-field-gap);
  margin: 0;
}

.thi-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.thi-lead-box .thi-field label {
  font-size: .82rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink);
  line-height: 1.3;
}

.thi-req,
.thi-opt {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.thi-req { color: var(--ember); }
.thi-opt { color: var(--muted); }

/* --------------------------------------------------------------- controls */

.thi-form .thi-input,
.thi-form .thi-textarea {
  width: 100%;
  max-width: 100%;
  font-family: inherit;
  font-size: 1.02rem;   /* >=16px: stops iOS Safari zooming the page on focus */
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 11px;
  padding: .78em .9em;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.thi-form .thi-input {
  min-height: 52px;   /* comfortable thumb target on a phone */
}

.thi-form .thi-textarea {
  min-height: 118px;
  resize: vertical;
}

.thi-form .thi-input::placeholder,
.thi-form .thi-textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

.thi-form .thi-input:hover,
.thi-form .thi-textarea:hover {
  border-color: var(--navy);
}

/* Keyboard focus keeps the site-wide ring from style.css and adds a navy edge
   so the active box is obvious with a mouse too. */
.thi-form .thi-input:focus,
.thi-form .thi-textarea:focus {
  border-color: var(--navy);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--navy-tint);
}

/* ------------------------------------------------------------ hints/errors */

.thi-lead-box .thi-field-hint {
  margin: 0;
  font-size: .86rem;
  line-height: 1.45;
  color: var(--muted);
}

/* A soft note, not an error: leads.js uses this for a short phone number.
   The field stays valid and the lead still sends - a nine-digit typo is worth
   far more than a blocked submission. */
.thi-lead-box .thi-field-hint.thi-hint-warn {
  color: var(--ember-deep);
  font-weight: 700;
}

.thi-lead-box .thi-field-err {
  margin: 0;
  font-size: .88rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--thi-err);
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

/* [hidden] is a UA-origin display:none, so the author-origin display:flex above
   outranks it: without this guard every field renders an empty red "!" badge on
   first load, and leads.js setting node.hidden = true never clears one. */
.thi-lead-box .thi-field-err[hidden] { display: none; }

.thi-lead-box .thi-field-err::before {
  content: "!";
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--thi-err);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
}

.thi-field.is-error > label { color: var(--thi-err); }

.thi-field.is-error .thi-input,
.thi-field.is-error .thi-textarea,
.thi-form .thi-input[aria-invalid="true"],
.thi-form .thi-textarea[aria-invalid="true"] {
  border-color: var(--thi-err);
  background: var(--thi-err-bg);
}

.thi-field.is-error .thi-input:focus,
.thi-field.is-error .thi-textarea:focus,
.thi-form .thi-input[aria-invalid="true"]:focus,
.thi-form .thi-textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 4px var(--thi-err-line);
}

/* ------------------------------------------------------- the error summary */

.thi-alert {
  margin: 0 0 22px;
  padding: 16px 18px;
  border: 1.5px solid var(--thi-err-line);
  border-left-width: 5px;
  border-left-color: var(--thi-err);
  border-radius: 12px;
  background: var(--thi-err-bg);
  color: var(--ink);
}

.thi-alert:focus { outline: none; }
.thi-alert:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

.thi-lead-box .thi-alert strong {
  display: block;
  font-size: 1.02rem;
  color: var(--thi-err);
  letter-spacing: -.01em;
}

.thi-lead-box .thi-alert p {
  margin: 4px 0 0;
  font-size: .95rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.thi-lead-box .thi-alert ul {
  margin: 10px 0 0;
  padding-left: 1.15em;
  font-size: .93rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.thi-lead-box .thi-alert li { margin: 0 0 4px; }

/* -------------------------------------------------------------- honeypot */
/* Off-screen, NOT display:none - a bot skips display:none and fills this.
   aria-hidden on the wrapper plus tabindex="-1" on the input (in the markup)
   keeps screen readers and the Tab key out of it. */

.thi-hp {
  position: absolute !important;
  left: -9999px !important;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* --------------------------------------------------------------- submit */

.thi-form .thi-submit {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
  padding: 1.02em 1.35em;
  font-size: 1.05rem;
  min-height: 56px;
}

.thi-form .thi-submit[disabled] {
  opacity: .6;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.thi-lead-box .thi-fineprint {
  margin: 0;
  font-size: .84rem;
  line-height: 1.55;
  color: var(--muted);
}

.thi-lead-box .thi-fineprint a {
  color: var(--ember);
  font-weight: 700;
  white-space: nowrap;
}

.thi-lead-box .thi-fineprint a:hover { text-decoration: underline; }

/* ------------------------------------------------- Google Places widget */
/* <gmp-place-autocomplete> uses a CLOSED shadow DOM. Only width, border,
   border-radius and font-family reach the host element; everything inside is
   reachable only through Google's documented --gmp-mat-* custom properties.
   Do not try to pierce it - that breaks on Google's next weekly release.
   Expect the inner padding and focus ring to be a near, not exact, match. */

.thi-form gmp-place-autocomplete,
.thi-form gmp-basic-place-autocomplete {
  display: block;
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  font-family: var(--font);
  --gmp-mat-color-surface: var(--bg);
  --gmp-mat-color-on-surface: var(--ink);
  --gmp-mat-color-on-surface-variant: var(--ink-soft);
  --gmp-mat-color-primary: var(--navy);
  --gmp-mat-color-outline-decorative: var(--line);
  --gmp-mat-font-family: var(--font);
}

.thi-form gmp-place-autocomplete:hover {
  border-color: var(--navy);
}

/* Google's dropdown renders in the page, not in the card, so it must sit above
   the sticky header (z-index 50 in style.css). */
.pac-container,
.gmp-place-autocomplete-list {
  z-index: 60 !important;
}

/* ----------------------------------------------------------- success panel */

.thi-success {
  text-align: center;
  padding: 6px 0 2px;
}

.thi-success-mark {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--thi-ok-bg);
  border: 2px solid var(--thi-ok-line);
}

.thi-success-mark svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--thi-ok);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.thi-lead-box .thi-success h3 {
  font-size: 1.5rem;
  margin-bottom: 10px;
}

.thi-lead-box .thi-success p {
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.6;
  margin-bottom: 0;
}

.thi-lead-box .thi-success-hurry {
  margin-top: 22px;
  font-weight: 700;
  color: var(--ink);
}

.thi-success .thi-success-call {
  width: 100%;
  justify-content: center;
  margin-top: 12px;
  min-height: 56px;
  font-size: 1.05rem;
}

.thi-lead-box .thi-success-again {
  margin-top: 18px;
  font-size: .9rem;
}

.thi-lead-box .thi-success-again a {
  color: var(--ember);
  font-weight: 700;
}

.thi-lead-box .thi-success-again a:hover { text-decoration: underline; }

/* ------------------------------------------------------ contact-card note */

.thi-area-note {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: .95rem;
  line-height: 1.6;
  color: var(--ink-soft);
}

/* --------------------------------------------------------------- comfort */

@media (min-width: 560px) {
  .thi-lead-box { --thi-field-gap: 20px; }
  .thi-lead-box .thi-field label { font-size: .84rem; }
}

@media (prefers-reduced-motion: reduce) {
  .thi-form .thi-input,
  .thi-form .thi-textarea { transition: none; }
}
