/* ============================================================
   AI Huntsville CRM — front-end components
   Built on the AI Huntsville design tokens (system.css). Every
   token has a fallback, and the base primitives below are wrapped
   in :where() (zero specificity) so the theme's own .card / .input /
   .btn rules always win — the plugin only fills gaps.
   ============================================================ */

.aih-crm {
  --aihf-accent: var(--accent, #3861d9);
  --aihf-accent-ink: var(--accent-ink, #2448b8);
  --aihf-fg: var(--fg, #111417);
  --aihf-muted: var(--muted, #48515a);
  --aihf-border: var(--border, #d7dee6);
  --aihf-soft: var(--border-soft, #e6ecf2);
  --aihf-surface: var(--surface, #fff);
  --aihf-pale: var(--pale-blue, #d9e7f5);
  --aihf-tint: var(--pale-tint, #f4f7fa);
  --aihf-ok: var(--ok, #1b7f53);
  --aihf-ok-bg: var(--ok-bg, #e4f3eb);
  --aihf-warn: var(--warn, #8a6212);
  --aihf-warn-bg: var(--warn-bg, #fbf1dc);
  --aihf-err: var(--err, #b3261e);
  --aihf-err-bg: var(--err-bg, #fbe9e7);
  --aihf-r: var(--r-md, 14px);
  --aihf-r-sm: var(--r-sm, 8px);
  --aihf-mono: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  --aihf-display: var(--font-display, system-ui, sans-serif);
  --aihf-t: var(--t, 190ms cubic-bezier(.2,.6,.2,1));
  position: relative;
}

/* ---------- Fallback primitives (theme overrides these) ---------- */
:where(.aih-crm) :where(.card) { background: var(--aihf-surface); border: 1px solid var(--aihf-border); border-radius: var(--aihf-r); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
:where(.aih-crm) :where(.form-grid) { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
:where(.aih-crm) :where(.span-2) { grid-column: 1 / -1; }
:where(.aih-crm) :where(.field) { display: grid; gap: 7px; }
:where(.aih-crm) :where(.field > label) { font-size: 14px; font-weight: 600; }
:where(.aih-crm) :where(.hint) { font-size: 12.5px; color: var(--aihf-muted); }
:where(.aih-crm) :where(.input, .select, .textarea) { width: 100%; min-height: 48px; padding: 12px 14px; background: var(--aihf-surface); border: 1px solid var(--aihf-border); border-radius: var(--aihf-r-sm); font: inherit; font-size: 15.5px; box-sizing: border-box; }
:where(.aih-crm) :where(.textarea) { min-height: 140px; resize: vertical; }
:where(.aih-crm) :where(.field-error) { display: none; font-size: 13px; color: var(--aihf-err); font-weight: 500; }
:where(.aih-crm) :where(.field.has-error .field-error) { display: flex; }
:where(.aih-crm) :where(.btn) { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 48px; padding: 12px 22px; border-radius: var(--aihf-r-sm); border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
:where(.aih-crm) :where(.btn-primary) { background: var(--aihf-accent); color: #fff; }
:where(.aih-crm) :where(.btn-secondary) { background: var(--aihf-surface); color: var(--aihf-fg); border-color: var(--aihf-border); }
:where(.aih-crm) :where(.btn-block) { width: 100%; }
:where(.aih-crm) :where(.form-status) { display: none; padding: 14px 16px; border-radius: var(--aihf-r-sm); font-size: 14.5px; }
:where(.aih-crm) :where(.form-status.is-visible) { display: flex; }
:where(.aih-crm) :where(.form-status--ok) { background: var(--aihf-ok-bg); color: var(--aihf-ok); }
:where(.aih-crm) :where(.form-status--err) { background: var(--aihf-err-bg); color: var(--aihf-err); }
:where(.aih-crm) :where(.eyebrow) { font-family: var(--aihf-mono); font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--aihf-accent); }
:where(.aih-crm) :where(.state-panel) { background: var(--aihf-surface); border: 1px dashed var(--aihf-border); border-radius: var(--aihf-r); padding: 44px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
:where(.aih-crm) :where(.state-panel__icon) { width: 52px; height: 52px; border-radius: 999px; display: grid; place-items: center; background: var(--aihf-pale); color: var(--aihf-accent-ink); }
:where(.aih-crm) :where(.checkbox) { display: grid; grid-template-columns: 22px 1fr; gap: 12px; align-items: start; font-size: 14px; color: var(--aihf-muted); cursor: pointer; }
:where(.aih-crm) :where(.checkbox input) { width: 22px; height: 22px; accent-color: var(--aihf-accent); margin: 1px 0 0; }
:where(.aih-crm) :where(.routing-note) { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--aihf-muted); }
:where(.aih-crm) :where(.sr-only) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Form shell ---------- */
.aih-crm-form { gap: 20px; }
.aih-crm-form.card { padding: clamp(24px, 2.6vw, 36px); }
.aih-crm-intro { color: var(--aihf-muted); font-size: 16px; line-height: 1.6; max-width: 62ch; }
.aih-req { color: var(--aihf-err); }
.aih-crm .field > label:not(.checkbox) { display: block; }
/* A half-width input beside a taller neighbour (e.g. the file drop zone)
   must keep its own height rather than stretch to fill the grid row. */
.aih-crm .form-grid > .field { align-content: start; }
.aih-crm .hint { line-height: 1.5; }
.aih-crm .field-error::before { content: "!"; flex: none; width: 16px; height: 16px; border-radius: 999px; display: inline-grid; place-items: center; background: var(--aihf-err); color: #fff; font: 700 11px/1 system-ui, sans-serif; }
.aih-crm .field-error { align-items: center; gap: 7px; }

/* honeypot — off-screen, never display:none (some bots skip hidden inputs) */
.aih-captcha { margin: 6px 0 4px; }
.aih-captcha .cf-turnstile { display: block; }
.aih-captcha-note { margin: 4px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted, #48515a); }
.aih-captcha-note a { color: inherit; }
.grecaptcha-badge { visibility: hidden; }
.aih-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }

/* numbered section headings — echo the site's 01/02/03 rhythm */
.aih-section { display: grid; grid-template-columns: 46px 1fr; gap: 14px; align-items: start; padding-top: 26px; margin-top: 6px; border-top: 1px solid var(--aihf-soft); }
.form-grid > .aih-section:first-child { padding-top: 0; margin-top: 0; border-top: 0; }
.aih-section__num { font-family: var(--aihf-display); font-size: 30px; font-weight: 600; letter-spacing: -.03em; line-height: 1; color: var(--aihf-accent); opacity: .42; }
.aih-section__title { font-family: var(--aihf-display); font-size: clamp(19px, 1.5vw, 22px); font-weight: 650; letter-spacing: -.02em; line-height: 1.2; color: var(--aihf-fg); margin: 0; }
.aih-section__help { margin-top: 6px; font-size: 14.5px; line-height: 1.55; color: var(--aihf-muted); max-width: 62ch; }

/* ---------- Choice groups ---------- */
.aih-choice { border: 0; margin: 0; padding: 0; min-width: 0; }
.aih-choice > legend { font-size: 14px; font-weight: 600; padding: 0; margin-bottom: 7px; color: var(--aihf-fg); }
.aih-options { display: grid; gap: 8px; }
.aih-options--inline { display: flex; flex-wrap: wrap; }
.aih-option {
  display: flex; align-items: center; gap: 11px; min-height: 48px; padding: 11px 16px;
  border: 1px solid var(--aihf-border); border-radius: var(--aihf-r-sm); background: var(--aihf-surface);
  font-size: 15px; color: var(--aihf-fg); cursor: pointer;
  transition: border-color var(--aihf-t), background var(--aihf-t);
}
.aih-option:hover { border-color: #b9c6d4; }
.aih-option input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--aihf-accent); }
.aih-option:has(input:checked) { border-color: var(--aihf-accent); background: var(--aihf-pale); color: var(--aihf-accent-ink); font-weight: 500; }
.aih-option:has(input:focus-visible) { outline: 3px solid var(--aihf-accent); outline-offset: 2px; }
.aih-options--inline .aih-option { flex: 0 1 auto; }
.aih-choice.has-error .aih-option { border-color: var(--aihf-err); }
.aih-consent .checkbox { color: var(--aihf-muted); line-height: 1.55; }
.aih-consent .checkbox a { color: var(--aihf-accent); }
.aih-consent.has-error .checkbox input { outline: 2px solid var(--aihf-err); outline-offset: 1px; }

/* ---------- Word counter ---------- */
.aih-field-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.aih-field-foot .hint { margin: 0; }
.aih-count { margin-left: auto; flex: none; font-family: var(--aihf-mono); font-size: 11.5px; letter-spacing: .06em; color: var(--aihf-muted); font-variant-numeric: tabular-nums; }
.aih-count.is-near { color: var(--aihf-warn); }
.aih-count.is-over { color: var(--aihf-err); font-weight: 600; }

/* ---------- File drop zone ---------- */
.aih-file {
  position: relative; min-height: 104px; border-radius: var(--aihf-r-sm);
  border: 1.5px dashed #b9c6d4; background: var(--aihf-tint);
  display: grid; place-items: center; text-align: center; padding: 18px;
  transition: border-color var(--aihf-t), background var(--aihf-t);
}
.aih-file__input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; z-index: 1; }
.aih-file__ui { display: grid; gap: 4px; justify-items: center; pointer-events: none; }
.aih-file__icon { color: var(--aihf-accent); display: inline-grid; }
.aih-file__text { font-size: 14.5px; color: var(--aihf-fg); }
.aih-file__text strong { color: var(--aihf-accent); }
.aih-file__meta { font-family: var(--aihf-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--aihf-muted); }
.aih-file:hover, .aih-file.is-drag { border-color: var(--aihf-accent); background: var(--aihf-pale); }
.aih-file:focus-within { outline: 3px solid var(--aihf-accent); outline-offset: 2px; }
.aih-file.has-file { border-style: solid; border-color: var(--aihf-border); background: var(--aihf-surface); min-height: 64px; place-items: stretch; padding: 12px 14px; }
.aih-file.has-file .aih-file__ui { display: none; }
.aih-file.has-file .aih-file__input { pointer-events: none; }
.aih-file__chosen { position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; text-align: left; }
.aih-file__name { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 500; overflow-wrap: anywhere; }
.aih-file__clear { background: none; border: 0; padding: 8px 10px; margin: -8px -6px -8px 0; min-height: 40px; font: inherit; font-size: 13.5px; color: var(--aihf-err); cursor: pointer; border-radius: 6px; }
.aih-file__clear:hover { background: var(--aihf-err-bg); }
.field.has-error .aih-file { border-color: var(--aihf-err); background: var(--aihf-err-bg); }

/* ---------- Submit ---------- */
.aih-crm-submit { position: relative; }
.aih-spinner { display: none; width: 18px; height: 18px; border-radius: 999px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: aih-spin .7s linear infinite; }
.aih-crm-submit.is-loading { pointer-events: none; opacity: .85; }
.aih-crm-submit.is-loading .aih-spinner { display: inline-block; }
@keyframes aih-spin { to { transform: rotate(360deg); } }
.aih-crm-privacy { margin-top: 0 !important; align-items: flex-start !important; line-height: 1.55; }
.aih-crm-privacy svg { flex: none; margin-top: 2px; }
.aih-crm .form-status { gap: 10px; align-items: flex-start; line-height: 1.5; }

/* ---------- Success ---------- */
.aih-crm-success {
  background: var(--aihf-surface); border: 1px solid var(--aihf-border); border-radius: var(--aihf-r);
  padding: clamp(32px, 4vw, 56px) clamp(24px, 3vw, 44px);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px;
  outline: none;
}
.aih-crm-success[hidden] { display: none; }
.aih-crm-success__icon { width: 60px; height: 60px; border-radius: 999px; display: grid; place-items: center; background: var(--aihf-ok-bg); color: var(--aihf-ok); margin-bottom: 4px; }
.aih-crm-success .eyebrow span { color: var(--aihf-fg); letter-spacing: .1em; }
.aih-crm-success .h-card { max-width: 24ch; }
.aih-crm-success__msg { max-width: 52ch; color: var(--aihf-muted); font-size: 16px; line-height: 1.6; }
.aih-crm-success__actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 8px; }
@media (prefers-reduced-motion: no-preference) {
  .aih-crm-success.is-in { animation: aih-pop 420ms cubic-bezier(.2,.6,.2,1); }
  .aih-crm-success.is-in .aih-crm-success__icon { animation: aih-pop 520ms 80ms cubic-bezier(.2,.6,.2,1) both; }
}
@keyframes aih-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Admin-only hints ---------- */
.aih-crm-preview-flag, .aih-crm-admin-hint {
  display: flex; align-items: center; gap: 8px; margin: 0 0 14px; padding: 10px 14px;
  border-radius: var(--aihf-r-sm); background: var(--aihf-warn-bg); color: var(--aihf-warn); font-size: 13.5px; font-weight: 500;
}

/* ---------- Submission status page ---------- */
.aih-status { display: grid; gap: 18px; max-width: 760px; }
.aih-status__card, .aih-status__lookup { gap: 18px; padding: clamp(24px, 3vw, 40px); }
.aih-status__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.aih-status__head .h-card { margin-top: 8px; }
.aih-status__head .meta { margin-top: 10px; }
.aih-status__msg { color: var(--aihf-muted); font-size: 16px; line-height: 1.6; max-width: 60ch; }
.aih-status__withdraw { margin: 0; }
.aih-status-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px;
  font-family: var(--aihf-mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 500;
  background: var(--aihf-pale); color: var(--aihf-accent-ink); white-space: nowrap;
}
.aih-status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 999px; background: currentColor; }
.aih-status-pill--accepted, .aih-status-pill--resolved { background: var(--aihf-ok-bg); color: var(--aihf-ok); }
.aih-status-pill--waitlisted, .aih-status-pill--shortlisted { background: var(--aihf-warn-bg); color: var(--aihf-warn); }
.aih-status-pill--declined, .aih-status-pill--withdrawn { background: var(--aihf-tint); color: var(--aihf-muted); }

.aih-steps { list-style: none; margin: 4px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); }
.aih-steps__item { position: relative; display: grid; justify-items: start; gap: 10px; font-size: 13.5px; font-weight: 500; color: var(--aihf-muted); }
.aih-steps__item::before { content: ""; position: absolute; left: 0; right: 0; top: 7px; height: 2px; background: var(--aihf-soft); }
.aih-steps__item.is-done::before { background: var(--aihf-accent); }
.aih-steps__dot { position: relative; width: 16px; height: 16px; border-radius: 999px; background: var(--aihf-surface); border: 2px solid var(--aihf-border); }
.aih-steps__item.is-done .aih-steps__dot { background: var(--aihf-accent); border-color: var(--aihf-accent); }
.aih-steps__item.is-current .aih-steps__dot { border-color: var(--aihf-accent); box-shadow: 0 0 0 5px rgba(56,97,217,.14); }
.aih-steps__item.is-done, .aih-steps__item.is-current { color: var(--aihf-fg); }
.aih-status__lookup .form-grid { margin-top: 4px; }

/* ---------- Documents library ---------- */
.aih-docs__controls { margin-bottom: 8px; }
.aih-docs__search { max-width: 360px; }
.aih-docs__group { margin-top: 30px; }
.aih-docs__group:first-of-type { margin-top: 12px; }
.aih-docs__heading { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.aih-docs__n { font-family: var(--aihf-mono); font-size: 10.5px; letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; background: var(--aihf-pale); color: var(--aihf-accent-ink); }
.aih-docs__list { display: grid; gap: 12px; }
.aih-doc {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 20px; align-items: center;
  padding: 20px 22px; background: var(--aihf-surface); border: 1px solid var(--aihf-border); border-radius: var(--aihf-r);
  transition: border-color var(--aihf-t), box-shadow var(--aihf-t), transform var(--aihf-t);
  scroll-margin-top: 120px;
}
.aih-doc:hover { border-color: rgba(56,97,217,.4); box-shadow: 0 10px 24px rgba(9,40,74,.07); transform: translateY(-2px); }
.aih-doc:target { border-color: var(--aihf-accent); box-shadow: 0 0 0 3px rgba(56,97,217,.16); }
.aih-doc--featured { border-left: 3px solid var(--aihf-accent); }
.aih-doc__type {
  width: 56px; height: 64px; border-radius: 8px 16px 8px 8px; display: grid; place-items: center;
  background: var(--aihf-pale); color: var(--aihf-accent-ink);
  font-family: var(--aihf-mono); font-size: 11px; font-weight: 500; letter-spacing: .08em;
}
.aih-doc__body { display: grid; gap: 6px; min-width: 0; justify-items: start; }
.aih-doc__title { font-family: var(--aihf-display); font-size: 19px; font-weight: 600; letter-spacing: -.015em; line-height: 1.28; color: var(--aihf-fg); margin: 0; }
.aih-doc__desc { font-size: 15px; line-height: 1.55; color: var(--aihf-muted); max-width: 64ch; }
.aih-doc__meta { font-family: var(--aihf-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--aihf-muted); }
.aih-doc__btn { white-space: nowrap; }
.aih-doc__btn svg { flex: none; }
@media (max-width: 640px) {
  .aih-doc { grid-template-columns: 44px minmax(0, 1fr); gap: 14px 16px; padding: 18px; }
  .aih-doc__type { width: 44px; height: 52px; font-size: 10px; }
  .aih-doc__btn { grid-column: 1 / -1; width: 100%; }
  .aih-docs__search { max-width: none; }
}

/* ---------- Gate dialog ---------- */
.aih-gate {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0;
  border-radius: var(--r-lg, 24px); background: var(--aihf-surface); color: var(--aihf-fg);
  box-shadow: 0 30px 80px rgba(6,25,47,.35);
}
.aih-gate::backdrop { background: rgba(6,25,47,.55); backdrop-filter: blur(4px); }
.aih-gate__form { position: relative; display: flex; flex-direction: column; gap: 16px; padding: clamp(24px, 4vw, 38px); }
.aih-gate__lead { color: var(--aihf-muted); font-size: 15.5px; }
.aih-gate__close { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border-radius: 999px; border: 0; background: var(--aihf-tint); color: var(--aihf-fg); font-size: 24px; line-height: 1; cursor: pointer; }
.aih-gate__close:hover { background: var(--aihf-pale); }
@media (prefers-reduced-motion: no-preference) {
  .aih-gate[open] { animation: aih-pop 260ms cubic-bezier(.2,.6,.2,1); }
}

/* ---------- Footer subscribe feedback ---------- */
[data-aih-subscribe-note].is-ok { color: #9ec2ff; }
[data-aih-subscribe-note].is-err { color: #ffb4ab; }
[data-aih-subscribe] .btn.is-loading { opacity: .7; pointer-events: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .aih-crm .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .aih-section { grid-template-columns: 1fr; gap: 6px; }
  .aih-options--inline { display: grid; }
  .aih-crm-success__actions .btn { width: 100%; }
  .aih-steps__item { font-size: 12px; }
}
