/* ── Forms — shared form components ──────────────────────────────────────
   Used by the data sheet and contact pages (add "forms" to a page's @CSS
   list, e.g. <!-- @CSS: forms,contact -->). Every rule is scoped to
   .amp-form, so put that class on the <form>.

   Components: section groups + headings, text / select / textarea fields,
   Project type dropdown with checkboxes (.multiselect), phone input with
   country code (.phone-input), validation states, consent, submit button.
   Behaviour: js/form-kit.js, js/phone-input.js. Page layout (columns,
   cards, confirmation panels) stays in each page's own stylesheet.
   ──────────────────────────────────────────────────────────────────────── */

.amp-form {
  /* Field boundary: 52% ink on the cream field ≈ 3.2:1 against the field
     and ≈ 3.0:1 against a translucent white card — meets WCAG 1.4.11. */
  --form-field-bg: rgba(250, 248, 246, 0.6);
  --form-field-border: rgba(16, 32, 39, 0.52);
  --form-field-border-focus: rgb(138, 115, 70);
  --form-error: rgb(180, 60, 40);
}

/* Greeting at the top of the form card */
.amp-form .form-intro {
  font-size: clamp(17px, 1.3vw, 19px);
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: -0.01em;
  color: var(--nav-bg);
  max-width: 40ch;
  margin: 0 0 clamp(28px, 3.4vw, 36px);
  text-wrap: pretty;
}

/* Section groups ("About you" / "About your project") */
.amp-form .form-section {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0; /* fieldsets otherwise refuse to shrink below content width */
}
.amp-form .form-section + .form-section {
  margin-top: clamp(12px, 1.5vw, 16px);
  padding-top: clamp(28px, 3.5vw, 36px);
  border-top: 1px solid rgba(16, 32, 39, 0.1);
}
.amp-form .form-section-title {
  /* A <legend> is drawn inside its fieldset's top border by default; with
     the divider above "About your project" that put the heading IN the
     line. Floating it drops it into the content box like a normal heading. */
  float: left;
  width: 100%;
  padding: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: rgb(120, 100, 60);
  margin: 0 0 clamp(20px, 2.4vw, 26px);
}

.amp-form .form-section-title + * {
  clear: both;
}

.amp-form .form-row--half {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(16px, 2vw, 20px);
}
.amp-form .form-group {
  margin-bottom: clamp(20px, 2.5vw, 26px);
}
.amp-form .form-group[hidden] {
  display: none;
}
.amp-form .form-group label,
.amp-form .form-group .form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: rgba(16, 32, 39, 0.63); /* ≈ 4.6:1 on the card */
  margin-bottom: 7px;
  letter-spacing: 0.01em;
}
.amp-form .form-group .req {
  color: var(--form-error);
  margin-left: 1px;
}

.amp-form .form-group input:not([type="checkbox"]),
.amp-form .form-group select,
.amp-form .form-group textarea,
.amp-form .multiselect-trigger {
  width: 100%;
  font-family: 'Aeonik', Arial, 'Helvetica Neue', Helvetica, sans-serif;
  font-size: 16px; /* ≥16px so iOS Safari doesn't zoom on focus */
  color: var(--nav-bg);
  background-color: var(--form-field-bg);
  border: none;
  border-bottom: 1px solid var(--form-field-border);
  border-radius: 6px 6px 0 0;
  padding: 15px 14px;
  outline: none;
  transition: border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
  box-sizing: border-box;
}
.amp-form .form-group input:not([type="checkbox"]):focus,
.amp-form .form-group select:focus,
.amp-form .form-group textarea:focus,
.amp-form .multiselect-trigger:focus-visible,
.amp-form .multiselect.is-open .multiselect-trigger {
  border-bottom-color: var(--form-field-border-focus);
  /* background-color (not the shorthand) so the select chevron survives. */
  background-color: rgba(255, 255, 255, 0.75);
  box-shadow: 0 1px 6px rgba(16, 32, 39, 0.04);
}
/* Keyboard focus ring on fields, on top of the border change. */
.amp-form .form-group input:not([type="checkbox"]):focus-visible,
.amp-form .form-group select:focus-visible,
.amp-form .form-group textarea:focus-visible,
.amp-form .multiselect-trigger:focus-visible {
  outline: 2px solid var(--nav-bg);
  outline-offset: 2px;
}
.amp-form .form-group input::placeholder,
.amp-form .form-group textarea::placeholder {
  /* ≈ 5.9:1 on the field — passes WCAG AA. */
  color: rgba(16, 32, 39, 0.7);
}

/* Chevron shared by <select> and the Project type trigger */
.amp-form .form-group select,
.amp-form .multiselect-trigger {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23102027' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round' opacity='0.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  cursor: pointer;
}
/* Unselected select shows its placeholder option in the placeholder colour. */
.amp-form .form-group select:invalid {
  color: rgba(16, 32, 39, 0.7);
}
.amp-form .form-group select option {
  color: var(--nav-bg);
}
.amp-form .form-group textarea {
  resize: vertical;
  min-height: 110px;
  line-height: 1.5;
}

/* ── Project type: dropdown with checkboxes ── */
.amp-form .multiselect {
  position: relative;
}
.amp-form .multiselect-trigger {
  display: block;
  text-align: left;
}
.amp-form .multiselect.is-open .multiselect-trigger {
  /* Flip the chevron while open. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 7l5-5 5 5' stroke='%23102027' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round' opacity='0.6'/%3E%3C/svg%3E");
}
.amp-form .multiselect-summary {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.amp-form .multiselect-summary.is-placeholder {
  color: rgba(16, 32, 39, 0.7);
}
.amp-form .multiselect-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: min(360px, 60vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fbfaf8;
  border: 1px solid rgba(16, 32, 39, 0.14);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(16, 32, 39, 0.12), 0 2px 6px rgba(16, 32, 39, 0.06);
  padding: 6px;
}
.amp-form .multiselect-panel[hidden] {
  display: none;
}
.amp-form .multiselect-options {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}
/* label.multiselect-option out-specifies ".form-group label" (display:block etc.) */
.amp-form .form-group label.multiselect-option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px; /* WCAG 2.5.5 target size */
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--nav-bg);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.amp-form .multiselect-option:hover {
  background-color: rgba(16, 32, 39, 0.05);
}
.amp-form .multiselect-option:focus-within {
  background-color: rgba(16, 32, 39, 0.06);
  outline: 2px solid var(--nav-bg);
  outline-offset: -2px;
}
.amp-form .multiselect-option input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--nav-bg);
  cursor: pointer;
}
/* The option row carries the focus ring, so hide the checkbox's own. */
.amp-form .multiselect-option input[type="checkbox"]:focus-visible {
  outline: none;
}

/* ── Phone: country code selector + number (js/phone-input.js) ──
   One field visually: a shared background and bottom border, with the
   code and number split by a hairline. The native <select> sits
   transparently over the compact "GB +44" display, so the closed state is
   short while the open list shows full country names. */
.amp-form .phone-input {
  display: flex;
  align-items: stretch;
  background-color: var(--form-field-bg);
  border-bottom: 1px solid var(--form-field-border);
  border-radius: 6px 6px 0 0;
  transition: border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
}
.amp-form .phone-code {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  border-right: 1px solid rgba(16, 32, 39, 0.16);
}
.amp-form .phone-code-display {
  display: block;
  min-width: 96px;
  padding: 15px 34px 15px 14px;
  font-size: 16px;
  line-height: normal;
  color: var(--nav-bg);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23102027' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round' opacity='0.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.amp-form .form-group .phone-code-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px; /* ≥16px so iOS Safari doesn't zoom on focus */
  padding: 0;
  border: 0;
  background: none;
}
.amp-form .form-group .phone-code-select:focus-visible + .phone-code-display {
  outline: 2px solid var(--nav-bg);
  outline-offset: -2px;
  border-radius: 6px 0 0 0;
}
.amp-form .form-group input.phone-number {
  flex: 1 1 auto;
  min-width: 0;
  background-color: transparent;
  border-bottom: 0;
  border-radius: 0 6px 0 0;
  box-shadow: none;
}
.amp-form .form-group input.phone-number:focus {
  background-color: transparent;
  box-shadow: none;
}
.amp-form .form-group input.phone-number:focus-visible {
  outline-offset: -2px;
}
.amp-form .phone-input:focus-within {
  border-bottom-color: var(--form-field-border-focus);
  background-color: rgba(255, 255, 255, 0.75);
  box-shadow: 0 1px 6px rgba(16, 32, 39, 0.04);
}
/* Visitor typed their own "+" code — the selector is ignored, so dim it. */
.amp-form .phone-input--manual-code .phone-code-display {
  opacity: 0.4;
}
.amp-form .form-group--error .phone-input {
  border-bottom-color: var(--form-error);
  background-color: rgba(180, 60, 40, 0.03);
}
/* Extra .phone-input keeps this above the generic error rule below. */
.amp-form .form-group--error .phone-input input.phone-number {
  background-color: transparent;
}

/* ── Validation state (driven by js/form-kit.js) ── */
.amp-form .form-error {
  font-size: 12px;
  color: var(--form-error);
  margin: 5px 0 0;
  display: none;
}
.amp-form .form-group--error .form-error {
  display: block;
}
.amp-form .form-group--error input:not([type="checkbox"]),
.amp-form .form-group--error select,
.amp-form .form-group--error textarea,
.amp-form .form-group--error .multiselect-trigger {
  border-bottom-color: var(--form-error);
  background-color: rgba(180, 60, 40, 0.03);
}

/* ── Consent + submit ── */
.amp-form .form-consent {
  font-size: 12px;
  line-height: 1.55;
  color: rgba(16, 32, 39, 0.63);
  margin: clamp(4px, 1vw, 8px) 0 clamp(18px, 2vw, 22px);
}

.amp-form .form-submit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--cream);
  background: var(--nav-bg);
  border: none;
  border-radius: 0;
  padding: 14px 42px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.amp-form .form-submit:hover {
  background: #1a3340;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 32, 39, 0.1);
}
.amp-form .form-submit:active {
  transform: translateY(0);
  box-shadow: none;
}
.amp-form .form-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.amp-form .form-submit--sending {
  pointer-events: none;
}
.amp-form .form-submit:focus-visible {
  outline: 2px solid var(--nav-bg);
  outline-offset: 3px;
}

/* Submit error (network / HubSpot failure) */
.amp-form .form-submit-error {
  font-size: 13px;
  color: var(--form-error);
  margin-top: 12px;
  line-height: 1.5;
}

/* Noscript fallback */
.amp-form .form-noscript-notice {
  font-size: 14px;
  line-height: 1.5;
  color: var(--form-error);
  margin-top: 16px;
  padding: 16px;
  background: rgba(180, 60, 40, 0.05);
  border-radius: 6px;
}
.amp-form .form-noscript-notice a {
  color: var(--form-error);
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .amp-form .form-submit,
  .amp-form .form-group input,
  .amp-form .form-group select,
  .amp-form .form-group textarea,
  .amp-form .multiselect-trigger,
  .amp-form .multiselect-option,
  .amp-form .phone-input {
    transition: none;
  }
  .amp-form .form-submit:hover {
    transform: none;
  }
}

@media (max-width: 600px) {
  .amp-form .form-row--half {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .amp-form .form-submit {
    width: 100%;
    justify-content: center;
  }
}
