/*
 * Mermaid Divers Aruba — Formdesk responsive layout + visual theme v4
 * Target: dive_packages full draft (all booking, diver and card-placeholder fields).
 * NOTE: The stacking selectors worked in the user's iPhone test.
 * The remaining Formdesk item spacing is configurable under Layout.
 * CSS selectors for Formdesk's generated table structure have
 * not been confirmed against the raw HTML. Test before reusing on other forms.
 * The responsive v2 rules are preserved; the theme rules below are new and should be tested.
 */

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

/* iOS Safari should not zoom the page when a visitor focuses a field. */
@media screen and (max-width: 700px) {
  html,
  body {
    max-width: 100%;
  }

  form {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /*
   * Formdesk uses table cells for its side-by-side question layout.
   * Target only the row containing BOTH test name fields, leaving date-picker
   * and other Formdesk internal tables untouched.
   *
   * The fields' Formdesk identifiers are first_name and last_name.
   */
  form tr:has(input:is([name*="first_name"], [id*="first_name"])):has(input:is([name*="last_name"], [id*="last_name"])) {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  form tr:has(input:is([name*="first_name"], [id*="first_name"])):has(input:is([name*="last_name"], [id*="last_name"])) > td {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-bottom: 0 !important; /* v2: remove extra gap between stacked name fields */
    float: none !important;
  }

  /* Ensure form text fields stay in their available column. */
  form input[type="text"],
  form input[type="email"],
  form input[type="tel"],
  form input[type="number"],
  form input[type="date"],
  form input[type="search"],
  form textarea,
  form select {
    box-sizing: border-box !important;
    max-width: 100% !important;
    font-size: 16px !important;
  }

  /* The name inputs should fill the single column after stacking. */
  form input:is([name*="first_name"], [id*="first_name"],
                [name*="last_name"], [id*="last_name"]) {
    width: 100% !important;
    min-width: 0 !important;
  }
}


/* ================================================================
   v3 – Mermaid Divers visual theme (matching website build v0.5.10)
   Purely visual; the working v2 responsive layout above is unchanged.
   ================================================================ */
:root {
  --mda-navy: #023047;
  --mda-ink: #14313f;
  --mda-muted: #5f7884;
  --mda-border: #aacbd7;
  --mda-yellow: #ffb703;
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--mda-ink);
  background-color: #f3fbfe;
}

form {
  color: var(--mda-ink);
}

/* Formdesk may render its form title outside the form element. */
h1, h2, h3 {
  color: var(--mda-navy);
}

/* Change colors and corners only; keep field widths and stacking as in v2. */
form input[type="text"],
form input[type="email"],
form input[type="tel"],
form input[type="number"],
form input[type="date"],
form textarea,
form select {
  font-family: inherit;
  color: var(--mda-ink);
  background-color: #fff;
  border: 1px solid var(--mda-border);
  border-radius: 10px;
}

form input[type="text"]:focus,
form input[type="email"]:focus,
form input[type="tel"]:focus,
form input[type="number"]:focus,
form input[type="date"]:focus,
form textarea:focus,
form select:focus {
  border-color: #0077b6;
  outline: 2px solid rgba(0, 119, 182, .22);
  outline-offset: 1px;
}

/* Only the actual submit action – never date picker or other controls. */
form input[type="submit"],
form button[type="submit"] {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background-color: var(--mda-yellow);
  color: #241900;
  font-family: inherit;
  font-size: 16px;
  font-weight: 750;
  min-height: 48px;
  padding: 11px 24px;
  cursor: pointer;
}

form input[type="submit"]:hover,
form button[type="submit"]:hover {
  background-color: #edab00;
}

@media screen and (max-width: 700px) {
  /* Explicitly retain the iPhone 16px+ field rule introduced in v2. */
  form input[type="text"],
  form input[type="email"],
  form input[type="tel"],
  form input[type="number"],
  form input[type="date"],
  form input[type="search"],
  form textarea,
  form select { font-size: 16px !important; }
}


/* ================================================================
   v4 – all CURRENT two-column Formdesk question rows on mobile

   The original v3 iPhone fix for the name row remains intact above.
   The rules below also stack side-by-side dates, contact details,
   accommodation/transport, card placeholders, and Diver 1–8 fields.

   Scope: @media max-width 767px and only rows having actual form
   controls in TWO distinct direct table cells. Formdesk date-picker
   icons, help text and plain-text separators are not targeted.

   Safeguard: two adjacent SELECT controls are not stacked by the
   general rule. This preserves a possible month/year two-selector
   date control. Diver 1–8 selector pairs are explicitly included.

   NOTE: Formdesk generates its own table markup. These selectors
   are a tested layout strategy, not a verified live DOM contract.
   ================================================================ */

@media screen and (max-width: 767px) {
  html, body { max-width: 100% !important; }

  body, form, form > table {
    box-sizing: border-box !important;
    max-width: 100% !important;
  }

  /* A pair of answer controls arranged in two table cells.
   * Exclude SELECT+SELECT except for clearly named individual-diver
   * questions to preserve the expiration month/year pair. */
  form tr:not([hidden]):not([style*="display:none"]):not([style*="display: none"]):not([aria-hidden="true"]):not(.hidden):not(.is-hidden):has(> td:nth-of-type(2)):has(> td:first-of-type :is(input:not([type="hidden"]), textarea)):has(> td:nth-of-type(2) :is(input:not([type="hidden"]), select, textarea)),
  form tr:not([hidden]):not([style*="display:none"]):not([style*="display: none"]):not([aria-hidden="true"]):not(.hidden):not(.is-hidden):has(> td:nth-of-type(2)):has(> td:first-of-type select):has(> td:nth-of-type(2) :is(input:not([type="hidden"]), textarea)),
  form tr:not([hidden]):not([style*="display:none"]):not([style*="display: none"]):not([aria-hidden="true"]):not(.hidden):not(.is-hidden):has(> td:nth-of-type(2)):has(> td:first-of-type [name*="diver_"]):has(> td:nth-of-type(2) [name*="diver_"]),
  form tr:not([hidden]):not([style*="display:none"]):not([style*="display: none"]):not([aria-hidden="true"]):not(.hidden):not(.is-hidden):has(> td:nth-of-type(2)):has(> td:first-of-type [id*="diver_"]):has(> td:nth-of-type(2) [id*="diver_"]) {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  /* Corresponding cells only. Avoid changing cell display on every
   * internal date-picker or layout table. */
  form tr:not([hidden]):not([style*="display:none"]):not([style*="display: none"]):not([aria-hidden="true"]):not(.hidden):not(.is-hidden):has(> td:nth-of-type(2)):has(> td:first-of-type :is(input:not([type="hidden"]), textarea)):has(> td:nth-of-type(2) :is(input:not([type="hidden"]), select, textarea)) > td:not([hidden]):not([style*="display:none"]):not([style*="display: none"]),
  form tr:not([hidden]):not([style*="display:none"]):not([style*="display: none"]):not([aria-hidden="true"]):not(.hidden):not(.is-hidden):has(> td:nth-of-type(2)):has(> td:first-of-type select):has(> td:nth-of-type(2) :is(input:not([type="hidden"]), textarea)) > td:not([hidden]):not([style*="display:none"]):not([style*="display: none"]),
  form tr:not([hidden]):not([style*="display:none"]):not([style*="display: none"]):not([aria-hidden="true"]):not(.hidden):not(.is-hidden):has(> td:nth-of-type(2)):has(> td:first-of-type [name*="diver_"]):has(> td:nth-of-type(2) [name*="diver_"]) > td:not([hidden]):not([style*="display:none"]):not([style*="display: none"]),
  form tr:not([hidden]):not([style*="display:none"]):not([style*="display: none"]):not([aria-hidden="true"]):not(.hidden):not(.is-hidden):has(> td:nth-of-type(2)):has(> td:first-of-type [id*="diver_"]):has(> td:nth-of-type(2) [id*="diver_"]) > td:not([hidden]):not([style*="display:none"]):not([style*="display: none"]) {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    float: none !important;
    box-sizing: border-box !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-bottom: 0 !important;
  }

  /* iOS text zoom fix – retain at >=16px even for new fields.
     Keep original desktop sizes and default Formdesk control logic. */
  form input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
  form select, form textarea {
    font-size: 16px !important;
    box-sizing: border-box !important;
    max-width: 100% !important;
    min-width: 0;
  }

  /* Text fields get usable width on mobile; date widgets and their
     paired month/year dropdowns keep their native control widths. */
  form input[type="text"]:not([name*="date"]):not([id*="date"]):not([name*="last_dive"]):not([id*="last_dive"]),
  form input[type="email"], form input[type="tel"], form input[type="search"],
  form textarea {
    width: 100% !important;
  }

  /* Allow date placeholders to be read on small iPhones. */
  form input:is([name*="date"], [id*="date"], [name*="last_dive"], [id*="last_dive"]) {
    min-width: min(136px, 100%) !important;
    max-width: 100% !important;
  }

  /* Prevent titles, separator notes and hyperlinks from stretching
     the viewport on a long mobile form. */
  form :is(h1, h2, h3, p, label, legend) {
    overflow-wrap: anywhere;
  }
  form img { max-width: 100% !important; height: auto !important; }

  /* Control pairs in a single field, such as the expiration month
     and year, are left untouched – no blanket table/tr/td rule. */
}

/* 320px supplementary accommodation; desktop unaffected. */
@media screen and (max-width: 360px) {
  form { margin-left: auto; margin-right: auto; }
  form input[type="date"] { max-width: 100% !important; }
}


/* ================================================================
   v5 — MOBILE TEXT-AREA FIT (the three long-answer questions)

   These rules are additive to the user-tested v4 layout. They ONLY
   affect small screens and do not alter the desktop layout, diver
   dependencies, date pickers, menus or booking fields.

   Formdesk can assign an intrinsic size through textarea cols/width
   or through a containing table cell. In Safari this can cause the
   page to shift/zoom horizontally when a long-answer field is focused.
   ================================================================ */
@media screen and (max-width: 767px) {
  /* Keep every long-answer field inside the visible form/viewport,
     even when Formdesk supplies a large cols, width or min-width. */
  html body form textarea,
  html body form textarea[cols] {
    display: block !important;
    width: min(100%, calc(100vw - 40px)) !important;
    max-width: min(100%, calc(100vw - 40px)) !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    font-size: 16px !important; /* Prevent iPhone's focus-zoom */
    line-height: 1.4 !important;
    overflow-wrap: anywhere !important;
    resize: vertical;
  }

  /* Prevent a Formdesk table cell containing a large text area from
     reserving a wider minimum width than the mobile form. */
  html body form td:has(textarea),
  html body form th:has(textarea) {
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
}
