/* ===========================================================================
 *  styles.css  —  HHE donation app (index.php + thank-you.php).
 * ===========================================================================
 *
 *  Goals: clean, accessible, mobile-first, lightly branded (HHE), and
 *  dependency-free (no CSS framework, no web fonts pulled from a CDN).
 *
 *  Structure of this file:
 *    1. Design tokens (CSS custom properties)
 *    2. Base / reset-ish defaults
 *    3. Layout: page, brand header, card, footer
 *    4. Form fields, labels, hints, errors
 *    5. Components: frequency toggle, amount chips, buttons, spinner
 *    6. Thank-you page bits (summary list, tax line, success check)
 *    7. Accessibility helpers + reduced-motion
 * ------------------------------------------------------------------------- */

/* ── 1. Design tokens ───────────────────────────────────────────────────── */
:root {
  /* HHE brand palette: royal purple (from the lotus logo) + gold accent. */
  --brand:        #61368e;   /* HHE purple — primary accent (logo body) */
  --brand-dark:   #4e2a73;   /* hover/active (darker purple) */
  --brand-tint:   #f1ebf7;   /* light purple wash for selected chips, etc. */
  --accent:       #cb8640;   /* HHE gold — secondary accent */
  --accent-dark:  #a86f2f;
  --ink:          #1e293b;   /* near-black slate text */
  --ink-soft:     #475569;   /* secondary text */
  --line:         #e3e0ea;   /* hairline borders (cool neutral) */
  --bg:           #f5f3f8;   /* page background (soft lavender-white) */
  --card-bg:      #ffffff;
  --danger:       #b00020;   /* error text */
  --ok:           #1f7a3d;   /* success check */

  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 6px 24px rgba(40, 24, 60, 0.10);
  --focus:        0 0 0 3px rgba(97, 54, 142, 0.32);

  --maxw:         640px;     /* form column width */
  --gap:          18px;
}

/* ── 2. Base ────────────────────────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
               Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

h1 { margin: 0 0 0.25em; font-size: 1.7rem; line-height: 1.2;
     font-family: Georgia, "Times New Roman", Times, serif; }

a.link {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 2px;
}
a.link:hover { color: var(--brand-dark); }

/* ── 3. Layout ──────────────────────────────────────────────────────────── */
.page {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* Brand header (CSS wordmark, no image dependency). */
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.brand__logo {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  display: block;
}
.brand__text { display: flex; flex-direction: column; }
.brand__name {
  font-weight: 700;
  font-size: 1.1rem;
  font-family: Georgia, "Times New Roman", Times, serif;
  color: #5b1c7a;
}
.brand__tag  { color: var(--ink-soft); font-size: 0.85rem; }

/* The white card that holds the form / confirmation. */
.card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.card__title { color: var(--ink); }
.card__lede  { color: var(--ink-soft); margin: 0 0 22px; }

.page__footer {
  margin-top: 24px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  text-align: center;
}

/* ── 4. Fields ──────────────────────────────────────────────────────────── */
.field { margin-bottom: var(--gap); }

label,
.field__label,
.address legend {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.95rem;
}
.optional { font-weight: 400; color: var(--ink-soft); font-size: 0.85em; }

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 11px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
}
textarea { resize: vertical; min-height: 76px; }

/* Native select arrow (inline SVG so there's no external asset). */
select {
  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 fill='%236a5f54' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

/* Consistent, visible focus ring for keyboard + mouse users. */
input:focus,
select:focus,
textarea:focus,
button:focus-visible,
.toggle__input:focus-visible + .toggle__pill,
.chips__input:focus-visible + .chips__chip {
  outline: none;
  box-shadow: var(--focus);
  border-color: var(--brand);
}

.field__hint {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

/* Inline per-field error text. Hidden until .is-visible is toggled by app.js. */
.field__error {
  margin: 6px 0 0;
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 0;
  display: none;
}
.field__error.is-visible { display: block; }

/* Fund description panel (shown under the picker when a fund is chosen). */
.fund-desc {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--brand-tint);          /* light purple wash */
  border-left: 3px solid var(--accent);   /* HHE gold accent */
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.fund-desc__location {
  display: block;
  font-weight: 600;
  color: var(--brand);
  font-size: 0.82rem;
  margin-bottom: 6px;
}
.fund-desc__body {
  margin: 0;
  line-height: 1.5;
  white-space: pre-line;   /* preserve paragraph breaks from the summary */
}
.fund-desc__more {
  display: inline-block;
  margin-top: 6px;
  padding: 0;
  background: none;
  border: none;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brand);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.fund-desc__link {
  display: block;
  margin-top: 8px;
  color: var(--brand);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Hero image on single-fund campaign pages (/iraivan, /tithing). Full-bleed to
   the card edges, rounded to match the card's top corners. */
.campaign-hero {
  display: block;
  width: calc(100% + 48px);
  margin: -28px -24px 22px;
  height: auto;
  aspect-ratio: 2 / 1;
  object-fit: cover;
  border-radius: var(--radius) var(--radius) 0 0;
}

/* Address sub-grouping. */
.address {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  /* Uniform padding: the fieldset now wraps Stripe's Address Element (one
     iframe with no inner margins), so it needs real bottom padding — the old
     2px bottom was tuned for the native inputs' own bottom margins. */
  padding: 14px;
  margin-bottom: var(--gap);
}
.address legend { padding: 0 6px; }

/* Custom amount input wrapper + the "$" prefix. */
.input-prefix { position: relative; }
.input-prefix__symbol {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-soft);
  pointer-events: none;
}
.input-prefix input { padding-left: 24px; }
.field__custom-amount { margin-top: 10px; }

/* Checkbox row (anonymous). */
.field--checkbox {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  align-items: start;
}
.field--checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--brand);
}
.field--checkbox label { margin-bottom: 0; }
.field--checkbox .field__hint { grid-column: 2; }

/* ── 5. Components ──────────────────────────────────────────────────────── */

/* Frequency toggle + amount chips share the "hide the radio, style the label"
   technique so they stay keyboard-accessible while looking like buttons. */
.toggle,
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.toggle__input,
.chips__input {
  /* Visually hidden but still focusable + reachable by label clicks. */
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* Frequency pills: a 2-segment control that fills the row. */
.toggle { border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.toggle__pill {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  text-align: center;
  padding: 9px 14px;
  margin: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-soft);
  user-select: none;
}
.toggle__input:checked + .toggle__pill {
  background: var(--brand);
  color: #fff;
}

/* Amount chips. */
.chips__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  background: #fff;
  user-select: none;
  min-width: 64px;
  text-align: center;
}
.chips__input:checked + .chips__chip {
  background: var(--brand-tint);
  border-color: var(--brand);
  color: var(--brand-dark);
}

/* Buttons. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 18px;
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn--primary {
  background: var(--brand);
  color: #fff;
}
.btn--primary:hover { background: var(--brand-dark); }
.btn[disabled],
.btn.is-busy { opacity: 0.7; cursor: progress; }

/* Inline spinner shown while the create-session request is in flight. */
.btn__spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* The little padlock reassurance line under the button. */
.secure-note {
  margin: 12px 0 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

/* Form-wide error banner (API / network failures). */
.form-error {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: #fdecee;
  border: 1px solid #f3c2c9;
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

/* ── 6. Thank-you page ──────────────────────────────────────────────────── */
.ty-check {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  background: var(--ok);
  color: #fff;
  font-size: 1.8rem;
  border-radius: 50%;
}
.card .ty-check + .card__title { text-align: center; }

/* Receipt-style summary list. */
.summary {
  margin: 20px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.summary__row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.summary__row:last-child { border-bottom: none; }
.summary dt { color: var(--ink-soft); margin: 0; }
.summary dd { margin: 0; font-weight: 600; text-align: right; }
.summary__per { color: var(--ink-soft); font-weight: 400; font-size: 0.85em; }

/* 501(c)(3) tax acknowledgment paragraph. */
.tax-line {
  margin: 18px 0;
  padding: 14px;
  background: var(--brand-tint);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.manage { margin: 18px 0 4px; }
.ty-back { margin-top: 20px; text-align: center; }

/* ── 7. Accessibility helpers ───────────────────────────────────────────── */

/* Screen-reader-only text (used for the custom-amount label). */
.visually-hidden,
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Respect users who prefer reduced motion: kill the spinner animation. */
@media (prefers-reduced-motion: reduce) {
  .btn__spinner { animation: none; }
  * { scroll-behavior: auto !important; }
}

/* ── Narrow screens ─────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .card { padding: 22px 16px; }
  .brand__tag { display: none; } /* keep the header compact on phones */
}
