/* ===========================================================================
   JPMate — form controls shared by the organization and contact pages.
   js/forms.js turns each form <select> into the dropdown below and renders
   Turnstile in the site's light/dark theme at the form's width.
   =========================================================================== */

/* Each page maps its own colour tokens onto the dropdown. */
.dd {
  --dd-ease: cubic-bezier(.22, .8, .24, 1);
  --dd-bg: #fffefa; --dd-layer: transparent; --dd-line: #dce2d9; --dd-ink: #243c40;
  --dd-muted: #5e7172; --dd-accent: #215e67; --dd-wash: #eaf0ea; --dd-alert: #b7553c;
  --dd-shadow: 0 22px 44px -22px #1d3a3f66, 0 3px 10px #1d3a3f12;
  position: relative;
  min-width: 0;
}
.organization-page .dd {
  --dd-bg: var(--site-surface); --dd-line: var(--site-line); --dd-ink: var(--site-ink);
  --dd-muted: var(--site-muted); --dd-accent: var(--site-accent); --dd-wash: var(--site-soft);
  --dd-alert: var(--site-coral);
}
.cform .dd {
  --dd-bg: var(--bg); --dd-layer: var(--field-focus); --dd-line: var(--hair2); --dd-ink: var(--tx);
  --dd-muted: var(--muted); --dd-accent: var(--act); --dd-wash: var(--act-soft); --dd-alert: var(--hi);
}
:root[data-theme="dark"] .dd { --dd-shadow: 0 24px 48px -18px #000c, 0 2px 8px #0006; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .dd { --dd-shadow: 0 24px 48px -18px #000c, 0 2px 8px #0006; }
}

/* The select keeps the value and validation; it sits invisibly under the button. */
.dd .dd-native {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  opacity: 0; pointer-events: none;
}

/* The button keeps the field's own look (it takes the select's classes). */
.dd-button {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; margin: 0; text-align: left; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  transition: border-color .3s var(--dd-ease), box-shadow .3s var(--dd-ease), background-color .3s var(--dd-ease);
}
.cform .dd-button {
  font-family: inherit; font-size: 15px; line-height: 1.4; color: var(--tx);
  background: var(--field); border: 1px solid var(--hair); border-radius: 12px; padding: 12px 14px;
}
.cform .dd-button:focus-visible, .cform .dd.open .dd-button {
  outline: none; border-color: var(--act); background: var(--field-focus); box-shadow: 0 0 0 4px var(--act-soft);
}
.organization-page .pilot-form .dd-button:hover, .cform .dd-button:hover { border-color: var(--dd-muted); }
.organization-page .pilot-form .dd-button:focus-visible,
.organization-page .pilot-form .dd.open .dd-button {
  outline: none; border-color: var(--dd-accent); box-shadow: 0 0 0 4px var(--dd-wash);
}
.dd.invalid .dd-button { border-color: var(--dd-alert); }
.dd-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-button.is-placeholder .dd-value { color: var(--dd-muted); }
.dd-chevron {
  flex: none; width: 12px; height: 8px; fill: none; stroke: var(--dd-muted); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
  transition: transform .45s var(--dd-ease), stroke .3s var(--dd-ease);
}
.dd.open .dd-chevron { stroke: var(--dd-accent); transform: rotate(180deg); }
.selwrap:has(.dd)::after { content: none; }

/* The list settles in below the field (or above it near the bottom of the screen). */
.dd-list {
  position: absolute; z-index: 40; top: calc(100% + 8px); left: 0; right: 0;
  max-height: min(340px, 52vh); margin: 0; padding: 6px; overflow-y: auto; overscroll-behavior: contain;
  list-style: none; border: 1px solid var(--dd-line); border-radius: 14px;
  background: linear-gradient(var(--dd-layer), var(--dd-layer)), var(--dd-bg);
  box-shadow: var(--dd-shadow);
  /* The panel fades in fast and evenly and slides 6px; options don't fade on
     their own, so their text is at full ink as soon as the panel is. */
  opacity: 0; transform: translateY(-6px);
  visibility: hidden; pointer-events: none; /* a closing list never catches clicks meant for the field below */
  transition: opacity .16s linear, transform .28s var(--dd-ease), visibility 0s .28s;
}
.dd.up .dd-list { top: auto; bottom: calc(100% + 8px); transform: translateY(6px); }
.dd.open .dd-list { opacity: 1; transform: none; visibility: visible; pointer-events: auto; transition-delay: 0s; }
.dd-option {
  position: relative; display: grid; grid-template-columns: 15px minmax(0, 1fr); align-items: center; gap: 10px;
  padding: 10px 12px 10px 13px; border-radius: 9px; color: var(--dd-ink);
  font-size: 14px; line-height: 1.45; cursor: pointer;
  transition: background-color .25s var(--dd-ease);
}
.dd-option::before {
  content: ""; position: absolute; top: 10px; bottom: 10px; left: 1px; width: 2px; border-radius: 2px;
  background: var(--dd-accent); transform: scaleY(0); transition: transform .3s var(--dd-ease);
}
.dd-option.active { background: var(--dd-wash); }
.dd-option.active::before { transform: scaleY(1); }
.dd-mark {
  width: 13px; height: 13px; background: var(--dd-accent);
  clip-path: polygon(12% 50%, 0 64%, 40% 100%, 100% 22%, 87% 9%, 40% 72%);
  transform: scale(0); transition: transform .35s var(--dd-ease);
}
.dd-option[aria-selected="true"] .dd-mark { transform: scale(1); }
.dd-name { display: block; min-width: 0; }
.dd-option[aria-selected="true"] .dd-name { font-weight: 600; }

/* Turnstile fills the form's width; the frame's corners follow the fields.
   Below 300px (Cloudflare's minimum) it is scaled to the width instead, so the
   widget must not stretch the form: the contact page's one-column grid would
   otherwise grow to the widget's 300px on small phones. */
.cf-turnstile { width: 100%; min-width: 0; max-width: 100%; }
.contact-grid > .cform { min-width: 0; }
.cf-turnstile > div { border-radius: 10px; overflow: hidden; }
.cf-turnstile.ts-narrow { height: calc(65px * var(--ts-scale, 1)); min-height: 0; }
.cf-turnstile.ts-narrow > div { width: 300px; transform: scale(var(--ts-scale, 1)); transform-origin: 0 0; border-radius: calc(10px / var(--ts-scale, 1)); }

@media (prefers-reduced-motion: reduce) {
  .dd-list, .dd-option, .dd-option::before, .dd-mark, .dd-chevron, .dd-button { transition: none; }
}
