/* =========================================================================
   CIWA — BASE LAYER
   Loads after tokens.css. Contains resets, layout guards, and the
   accessibility floor. No visual design decisions live here.
   ========================================================================= */

/* -------------------------------------------------------------------------
   1. BOX MODEL + OVERFLOW GUARD
   The single most common cause of horizontal scroll on mobile is an element
   using 100vw inside a padded parent. 100vw includes the scrollbar width;
   100% does not. Never use 100vw for widths.
   ------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;   /* stops iOS Safari inflating text on rotate */
  scroll-behavior: smooth;
}

body {
  overflow-x: clip;                 /* better than hidden — doesn't break sticky */
  font-family: var(--ff-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--c-ink);
  background: var(--c-surface);
  -webkit-font-smoothing: antialiased;
}

/* -------------------------------------------------------------------------
   2. TYPOGRAPHY — driven entirely by tokens
   Set these once here; do NOT re-set font sizes per breakpoint in Elementor.
   ------------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--ff-display);
  color: var(--c-ink);
  margin-block: 0 var(--sp-sm);
  text-wrap: balance;               /* stops single-word orphan lines */
}

h1 { font-size: var(--fs-h1); line-height: var(--lh-tight);   letter-spacing: var(--ls-display); }
h2 { font-size: var(--fs-h2); line-height: var(--lh-heading); letter-spacing: var(--ls-display); }
h3 { font-size: var(--fs-h3); line-height: var(--lh-heading); }
h4 { font-size: var(--fs-h4); line-height: var(--lh-heading); }

p {
  margin-block: 0 var(--sp-sm);
  text-wrap: pretty;
}

p, li {
  max-width: var(--w-narrow);       /* keeps line length readable on 1920px */
}

.eyebrow {
  font-size: var(--fs-eyebrow);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  font-weight: 600;
  color: var(--c-brand);
}

/* -------------------------------------------------------------------------
   3. MEDIA
   Every image must be fluid. A fixed-width image is the #1 cause of
   layouts breaking between laptop and desktop.
   ------------------------------------------------------------------------- */
img,
picture,
video,
svg,
iframe {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Images that must hold a shape (cards, hero, thumbnails) */
.media-4x3  { aspect-ratio: 4 / 3;  object-fit: cover; width: 100%; height: auto; }
.media-16x9 { aspect-ratio: 16 / 9; object-fit: cover; width: 100%; height: auto; }
.media-1x1  { aspect-ratio: 1 / 1;  object-fit: cover; width: 100%; height: auto; }

/* Responsive map / video embeds without wrapper divs */
iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
}

/* -------------------------------------------------------------------------
   4. LAYOUT PRIMITIVES
   Use these as Elementor container CSS classes instead of hand-setting
   widths per breakpoint.
   ------------------------------------------------------------------------- */

/* Full-bleed section with boxed content */
.section {
  padding-block: var(--section-py);
  padding-inline: var(--section-px);
}

.section--tight { padding-block: var(--sp-lg); }
.section--alt   { background: var(--c-surface-alt); }

.container {
  width: 100%;
  max-width: var(--w-content);
  margin-inline: auto;
}

.container--narrow { max-width: var(--w-narrow); }
.container--wide   { max-width: var(--w-wide); }

/* Auto-fitting grid. Columns reflow by available space, not by breakpoint.
   This is why it looks correct at 1366, 1440, 1536 AND 1920 with no
   breakpoint overrides at all. */
.grid-auto {
  display: grid;
  gap: var(--gap-grid);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
}

.grid-auto--wide {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
}

/* Fixed 2-up that collapses only when genuinely too narrow */
.split {
  display: grid;
  gap: var(--gap-grid);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr));
  align-items: center;
}

/* Vertical rhythm helper — replaces stacking margin hacks */
.stack > * + * {
  margin-block-start: var(--sp-sm);
}
.stack--lg > * + * {
  margin-block-start: var(--sp-md);
}

/* -------------------------------------------------------------------------
   5. FULL-HEIGHT SECTIONS
   100vh is broken on iOS Safari — the URL bar makes it taller than the
   visible area, pushing content under the chrome. dvh fixes this.
   ------------------------------------------------------------------------- */
.min-h-screen {
  min-height: 100vh;      /* fallback for old browsers */
  min-height: 100dvh;     /* correct value everywhere modern */
}

/* -------------------------------------------------------------------------
   6. ACCESSIBILITY FLOOR
   Non-negotiable for a public-service nonprofit site.
   ------------------------------------------------------------------------- */

/* Visible keyboard focus. Never use outline: none without a replacement. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: var(--ring-focus);
  outline-offset: var(--ring-offset);
  border-radius: var(--radius-sm);
}

/* Minimum tap target — WCAG 2.2 target size */
a.btn,
button,
input[type="submit"],
.elementor-button {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2xs);
}

/* Skip link */
.skip-link:not(:focus) {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Screen-reader-only utility */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* -------------------------------------------------------------------------
   7. ELEMENTOR OVERRIDES
   Elementor ships defaults that fight fluid layouts. Neutralise them.
   ------------------------------------------------------------------------- */

/* Stop Elementor forcing a fixed content width that ignores our token */
.e-con.e-parent > .e-con-inner,
.elementor-section.elementor-section-boxed > .elementor-container {
  max-width: var(--w-content);
}

/* Elementor sets img height:auto but not max-width in some contexts */
.elementor-widget-image img {
  width: 100%;
  height: auto;
}

/* Prevent nested containers inheriting double padding */
.e-con .e-con {
  padding-inline: 0;
}

/* -------------------------------------------------------------------------
   8. DEBUG MODE
   Active only when WP_DEBUG is true. Outlines every container so you can
   see exactly which element is causing horizontal overflow.
   Toggle by adding ?debug=layout to any URL.
   ------------------------------------------------------------------------- */
body.ciwa-debug.debug-layout * {
  outline: 1px solid rgba(255, 0, 90, 0.35);
}

body.ciwa-debug.debug-layout *:hover {
  outline: 2px solid rgba(255, 0, 90, 0.9);
}
