/*
 * Casita website forms.
 *
 * Scoped to .casita-form so nothing here can reach the rest of the theme.
 * Every colour and measurement is a custom property declared on that scope:
 * dropping this into the live site means overriding the tokens, not hunting
 * through the rules.
 *
 * Contact Form 7 adds its own classes to the controls it renders
 * (.wpcf7-form-control, .wpcf7-not-valid, .wpcf7-response-output); those are
 * styled here too so a validation failure looks like part of the form rather
 * than like the plugin's default red text.
 */

.wpcf7,
.casita-form {
  --casita-text:        #1b1b1f;
  --casita-muted:       #5f6670;
  --casita-line:        #d6d9de;
  --casita-line-strong: #a9aeb6;
  --casita-field-bg:    #fff;
  --casita-accent:      #1f5d8c;
  --casita-accent-dark: #17486c;
  --casita-accent-soft: rgba(31, 93, 140, 0.16);
  --casita-danger:      #b3261e;
  --casita-danger-soft: #fdf3f2;
  --casita-success:     #1d6b3f;
  --casita-success-soft:#f1f8f3;
  --casita-radius:      8px;
  --casita-gap:         1.15rem;
  /* One column width, used by the form and by the reply underneath it. */
  --casita-measure:     44rem;
}

.casita-form {
  max-width: var(--casita-measure);
  margin-inline: auto;
  color: var(--casita-text);
  font-size: 1rem;
  line-height: 1.5;
}

/* --- heading ----------------------------------------------------------- */
.casita-form__head {
  margin-bottom: 1.75rem;
}

.casita-form__head h3 {
  margin: 0 0 0.4rem;
  font-size: 1.6rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.casita-form__lede {
  margin: 0;
  color: var(--casita-muted);
  font-size: 0.95rem;
}

/* --- grouping ---------------------------------------------------------- */
.casita-section {
  border: 0;
  margin: 0 0 1.5rem;
  padding: 0;
}

/* The gap and the rule between groups sit on the <legend>, not on the
   <fieldset>. A fieldset applies its padding-top below the legend rather than
   above it, so putting the separator there pushed each group's fields away
   from their own heading and left the groups themselves running together. */
.casita-section + .casita-section {
  margin-top: 1.5rem;
}

.casita-section + .casita-section .casita-section__title {
  border-top: 1px solid var(--casita-line);
  padding-top: 1.5rem;
}

/* A <legend>, so a screen reader announces which group a field belongs to.
   Legends carry browser padding and sit on the border by default; both are
   reset so it reads as a plain heading above the group. */
.casita-section__title {
  display: block;
  width: 100%;
  margin: 0 0 1rem;
  padding: 0;
  float: none;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--casita-muted);
}

.casita-field {
  margin-bottom: var(--casita-gap);
}

.casita-field:last-child {
  margin-bottom: 0;
}

/* Two or three fields on one line, stacking on narrow screens. */
.casita-row {
  display: grid;
  gap: 0 1rem;
  grid-template-columns: 1fr 1fr;
}

.casita-row--thirds {
  grid-template-columns: 2fr 1fr 1fr;
}

@media (max-width: 640px) {
  .casita-row,
  .casita-row--thirds {
    grid-template-columns: 1fr;
  }
}

/* --- labels ------------------------------------------------------------ */
.casita-field > label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.005em;
}

/* The asterisk carries meaning, so it gets a title rather than being read
   out as a bare star. */
.casita-form abbr[title] {
  margin-left: 0.15rem;
  color: var(--casita-danger);
  text-decoration: none;
  border: 0;
}

.casita-hint {
  margin: 0.4rem 0 0;
  color: var(--casita-muted);
  font-size: 0.8125rem;
}

/* A hint the customer is meant to act on, not just read past — the comment
   box on the sales form asks for a zip code and for the word "Zoom", and
   both change what happens to the enquiry. Colour alone carries that, with
   no weight change: the theme's font has no 600 face, so asking for one made
   the browser synthesise a bold and this one line stopped matching every
   other hint on the page. */
.casita-hint--notice {
  color: var(--casita-accent);
}

/* --- controls ---------------------------------------------------------- */
.casita-form .wpcf7-form-control-wrap {
  display: block;
}

.casita-form input[type="text"],
.casita-form input[type="email"],
.casita-form input[type="tel"],
.casita-form input[type="number"],
.casita-form textarea,
.casita-form select {
  box-sizing: border-box;
  width: 100%;
  min-height: 3.1rem;             /* comfortable target, was theme default */
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--casita-line);
  border-radius: var(--casita-radius);
  background: var(--casita-field-bg);
  color: inherit;
  font: inherit;
  font-size: 1rem;                /* 16px: stops iOS zooming on focus */
  line-height: 1.4;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.casita-form textarea {
  height: 9rem;
  min-height: 6rem;
  resize: vertical;
}

.casita-form input:hover:not(:focus),
.casita-form textarea:hover:not(:focus) {
  border-color: var(--casita-line-strong);
}

.casita-form input:focus,
.casita-form textarea:focus,
.casita-form select:focus {
  outline: none;                  /* replaced, not removed */
  border-color: var(--casita-accent);
  box-shadow: 0 0 0 3px var(--casita-accent-soft);
}

.casita-form ::placeholder {
  color: #9aa0a8;
  opacity: 1;
}

/* --- validation -------------------------------------------------------- */
.casita-form .wpcf7-not-valid {
  border-color: var(--casita-danger);
  background: var(--casita-danger-soft);
}

.casita-form .wpcf7-not-valid:focus {
  box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.16);
}

.casita-form .wpcf7-not-valid-tip {
  display: block;
  margin-top: 0.35rem;
  color: var(--casita-danger);
  font-size: 0.8125rem;
  font-weight: 500;
}

/*
 * The form-wide reply.
 *
 * Contact Form 7 renders this after the form body, which puts it outside
 * .casita-form and so outside the column width -- which is why it ran the
 * full width of the page while the form it answers sat in a narrower one,
 * reading like something the page said rather than something the form did.
 * Same measure and same centring fixes that.
 *
 * The thick left edge takes its colour from border-color below, so the
 * success and failure rules do not have to know it is there.
 */
.wpcf7 .wpcf7-response-output {
  max-width: var(--casita-measure);
  margin: 1.5rem auto 0;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--casita-line);
  border-left-width: 4px;
  border-radius: var(--casita-radius);
  font-size: 0.925rem;
  font-weight: 500;
  line-height: 1.45;
}

.wpcf7 form.invalid .wpcf7-response-output,
.wpcf7 form.unaccepted .wpcf7-response-output,
.wpcf7 form.failed .wpcf7-response-output {
  border-color: var(--casita-danger);
  background: var(--casita-danger-soft);
  color: var(--casita-danger);
}

.wpcf7 form.sent .wpcf7-response-output {
  border-color: var(--casita-success);
  background: var(--casita-success-soft);
  color: var(--casita-success);
}

/*
 * When the form body carries a [response] tag the reply is rendered inside
 * .casita-form, in the same box as the fields, and lines up with them exactly
 * rather than by being given a matching width. The rules above stay for a form
 * whose body has not been updated: Contact Form 7 appends its own reply after
 * the form body when no [response] tag is found, and that one is outside this
 * column and has to be measured back into line.
 */
.casita-form .wpcf7-response-output {
  /*
   * Inside the column now, so it shares the form's width instead of being
   * given a matching one. Sized like a field -- same minimum height, same
   * padding, same corner -- so the reply reads as another row of the form
   * rather than as a strip of text underneath it.
   */
  display: flex;
  align-items: center;
  box-sizing: border-box;
  min-height: 3.1rem;
  max-width: none;
  margin: 1.5rem 0 0;
  padding: 0.8rem 0.95rem;
}

/*
 * One tip per field, however many times Submit is pressed.
 *
 * Contact Form 7 appends a tip without checking for one already there:
 *
 *     const t = document.createElement("span");
 *     t.classList.add("wpcf7-not-valid-tip");
 *     e.appendChild(t);
 *
 * and its cleanup removes a single one, with querySelector rather than
 * querySelectorAll. Live validation on change and the submit response can both
 * append within one cycle -- validation resolves through a promise, so its tip
 * can land after the submit has already cleared -- and from then on each
 * submit removes one and adds one, so the pair never goes away.
 *
 * Both tips say the same thing, so hiding the later one loses nothing. This is
 * presentational on purpose: the duplicate is still in the markup, aria-hidden
 * as Contact Form 7 marks it, so no screen reader reads it twice either way,
 * and if the plugin stops duplicating them this rule simply stops matching.
 */
.casita-form .wpcf7-not-valid-tip + .wpcf7-not-valid-tip {
  display: none;
}

/* --- submit ------------------------------------------------------------ */
.casita-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.75rem;
}

.casita-form input[type="submit"] {
  appearance: none;
  min-height: 3.1rem;
  padding: 0.8rem 2rem;
  border: 0;
  border-radius: var(--casita-radius);
  background: var(--casita-accent);
  color: #fff;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, transform 60ms ease;
}

.casita-form input[type="submit"]:hover {
  background: var(--casita-accent-dark);
}

.casita-form input[type="submit"]:active {
  transform: translateY(1px);
}

.casita-form input[type="submit"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--casita-accent-soft);
}

/* While the submission is in flight CF7 marks the form; the button should
   stop inviting a second click that would create a second lead. */
.wpcf7 form.submitting .casita-form input[type="submit"] {
  opacity: 0.65;
  pointer-events: none;
}

.casita-form .wpcf7-spinner {
  margin: 0;
}

.casita-required-note {
  margin: 0;
  color: var(--casita-muted);
  font-size: 0.8125rem;
}

/* --- a note on dark mode ------------------------------------------------
   There is deliberately no prefers-color-scheme block here. The form has to
   match the page it sits in, and the theme does not follow the reader's
   system setting: honouring it here produced a black form on a white page
   for anyone whose OS is set to dark. A site running a dark theme should
   redeclare the tokens above instead, which is what they are for. */

/* --- honeypot ----------------------------------------------------------
   The trap field from casita-odoo-spam.php. Positioned off-screen rather
   than display:none or hidden: a bot that skips hidden inputs would skip
   the trap along with them, which is the opposite of the point. It is
   tabindex="-1" in the markup, so keyboard users never land on it. */
.casita-trap {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* --- reduced motion ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .casita-form input,
  .casita-form textarea,
  .casita-form input[type="submit"] {
    transition: none;
  }
}
