/*
 * IHF Design Tokens
 * Single source of truth. Every value in the design system lives here.
 * Rules:
 *   - Never hardcode a hex value anywhere else in the theme.
 *   - Never hardcode a px value that has a token equivalent.
 *   - Adding a new token here requires a comment explaining what it's for.
 */

/*
 * INVARIANT: `:root { ... }` token declarations below must remain UNLAYERED
 * and load before tailwind.css. Tailwind v4's @theme block emits its tokens
 * inside @layer theme; unlayered :root declarations win the cascade, which
 * is what makes `var(--color-navy) -> var(--navy) -> #0e255c` resolve.
 *
 * However, the base resets at the bottom of this file (body, h1, button…)
 * MUST live inside `@layer base` — otherwise they beat every Tailwind utility
 * class (which lives in @layer utilities) and `text-on-cream-65` etc. silently
 * stop working. We declare the layer order here so `base` lands in its
 * intended slot below `utilities`.
 */

@layer theme, base, components, utilities;

:root {

  /* ─── Brand colors ─────────────────────────────────────── */
  --navy:           #0e255c;   /* Primary brand — nav, headings, buttons */
  --navy-deep:      #081640;   /* Darker navy — util bar, safe section bg */
  --navy-mid:       #153070;   /* Mid navy — hover states, donate prompt band */

  --cream:          #fff0e1;   /* Warm white — hero bg, card fills */
  --cream-soft:     #fcefd9;   /* Slightly deeper cream — borders, alt fills */
  --paper:          #fef8f0;   /* Near white — section backgrounds */
  --page:           #eee9e0;   /* Outer page bg — visible as shadow behind .page */

  --gold:           #ffaa00;   /* CTA accent — donate button, highlights */
  --gold-hover:    #e69900;   /* Gold hover state */
  --gold-mid:       #f5c77a;   /* Mid-gold — gradient stops in event hero/card photos */
  --red:            #e84731;   /* Alert, urgency, section tags */
  --red-hover:      #d13b27;   /* Red hover state — used by .btn-red */
  --red-text:       #c73523;   /* Accessible red for text/small filled controls on light surfaces */

  --green:          #1e8449;   /* Form success — phase 2 */
  --green-soft:     #e8f5e9;   /* Form success surface */
  --green-text:     #1b5e20;   /* Form success text */

  /* ─── Semantic overlays — on-navy ──────────────────────── */
  /* Use these for text/borders on navy backgrounds, never raw rgba */
  --on-navy-85:     rgba(255, 240, 225, 0.85);
  --on-navy-70:     rgba(255, 240, 225, 0.70);
  --on-navy-65:     rgba(255, 240, 225, 0.65);
  --on-navy-55:     rgba(255, 240, 225, 0.55);
  --on-navy-45:     rgba(255, 240, 225, 0.45);
  --on-navy-25:     rgba(255, 240, 225, 0.25);
  --on-navy-15:     rgba(255, 240, 225, 0.15);
  --on-navy-10:     rgba(255, 240, 225, 0.10);
  --on-navy-08:     rgba(255, 240, 225, 0.08);

  /* ─── Semantic overlays — on-cream ─────────────────────── */
  /* Use these for text/borders on cream/paper backgrounds */
  --on-cream-85:    rgba(8, 22, 64, 0.85);
  --on-cream-65:    rgba(8, 22, 64, 0.65);
  --on-cream-55:    rgba(8, 22, 64, 0.55);
  --on-cream-50:    rgba(8, 22, 64, 0.50);
  --on-cream-45:    rgba(8, 22, 64, 0.45);
  --on-cream-25:    rgba(8, 22, 64, 0.25);
  --on-cream-18:    rgba(8, 22, 64, 0.18);
  --on-cream-15:    rgba(8, 22, 64, 0.15);
  --on-cream-10:    rgba(8, 22, 64, 0.10);
  --on-cream-08:    rgba(8, 22, 64, 0.08);
  --on-cream-04:    rgba(8, 22, 64, 0.04);

  /* ─── Gold glow alphas — decorative radial backgrounds ─────── */
  --gold-glow-15:   rgba(255, 170, 0, 0.15);
  --gold-glow-12:   rgba(255, 170, 0, 0.12);
  --gold-glow-10:   rgba(255, 170, 0, 0.10);

  /* ─── Typography ────────────────────────────────────────── */
  --font-display:   'Monomakh', Georgia, serif;        /* Headlines, CTAs, logo */
  --font-body:      'DM Sans', system-ui, sans-serif;  /* Body copy, UI, labels */

  /* Type scale — Tailwind v4 defaults.
     The reference build uses Tailwind CDN with no scale overrides, so its
     `text-3xl` etc. render at Tailwind's stock values. We mirror those
     numbers here so our `text-*` utilities match the reference 1:1.
     `--text-md` is a theme-only intermediate body size (kept for
     back-compat with templates that already use the class). */
  --text-xs:        0.75rem;     /* 12px */
  --text-sm:        0.875rem;    /* 14px */
  --text-base:      1rem;        /* 16px */
  --text-md:        1rem;        /* 16px — theme alias for body copy; equivalent to text-base */
  --text-lg:        1.125rem;    /* 18px */
  --text-xl:        1.25rem;     /* 20px */
  --text-2xl:       1.5rem;      /* 24px */
  --text-3xl:       1.875rem;    /* 30px */
  --text-4xl:       2.25rem;     /* 36px */

  /* Display heading sizes — used by .hero-heading and any future
     display-class headings. Distinct from the body text scale above
     so the document-level h1 can scale independently of section h2s. */
  --text-h1-hero:   2.85rem;     /* Hero h1 (home + page heroes) */

  /* Heading leading. Consumed by the @layer base h1 rule below so
     any h1 inherits this without needing a leading-* utility. */
  --leading-h1:     2.75rem;     /* h1 line-height (display headings) */

  /* ─── Layout ────────────────────────────────────────────── */
  --max-width:      1100px;
  --section-pad-x:  2rem;        /* 32px — horizontal padding on all sections */
  --section-pad-y:  3.5rem;      /* 56px — vertical padding on standard sections */
  --section-pad-y-sm: 2.25rem;   /* 36px — vertical padding on compact sections */

  /* ─── Border radius ─────────────────────────────────────── */
  --radius-page:    18px;        /* Outer .page container */
  --radius-card:    14px;        /* Service cards, hero photo, pill cards */
  --radius-card-sm: 10px;        /* Event cards, mini service rows */
  --radius-btn:     6px;         /* Buttons */
  --radius-badge:   100px;       /* Pills, tags, lang toggle (theme name; kept for back-compat) */
  --radius-pill:    100px;       /* Reference name; functional alias of --radius-badge */

  /* ─── Shadows ────────────────────────────────────────────── */
  --shadow-page:    0 4px 40px rgba(0, 0, 0, 0.12);     /* Outer .page shadow */
  --shadow-card:    0 16px 48px rgba(8, 22, 64, 0.15);  /* Hero photo, lifted cards */
  --shadow-soft:    0 4px 12px rgba(8, 22, 64, 0.08);   /* Placeholder elements, subtle lift */
  --shadow-badge:   0 4px 12px rgba(0, 0, 0, 0.08);     /* Photo badge — kept for back-compat */

  /* ─── Section color rhythm (V3 Balanced — locked) ─────────
     Approved page-level color sequence. Adjacent sections must never
     share the same bg (except the navy nav → navy donate hero, which
     is an intentional continuity-of-color on the donate page per V3).
     Phone-bar removed per Issue #19 gate decision. */

  /* Site chrome (loaded on every page) */
  --bg-alert:       var(--red-text);
  --bg-util:        var(--navy-deep);
  --bg-nav:         var(--navy);
  --bg-footer:      var(--navy);

  /* Home page rhythm */
  --bg-hero:        var(--cream);
  --bg-services:    var(--paper);
  --bg-impact:      var(--navy);
  --bg-pillars:     var(--cream);
  --bg-donate:      var(--navy);
  --bg-events:      var(--paper);
  --bg-news:        var(--cream);
  --bg-safe:        var(--navy-deep);

  /* About page rhythm — each section has its own token so the
     home rhythm map (--bg-impact = navy) doesn't conflict with
     About's impact (paper). See .section-about-* in tw-input.css. */
  --bg-about-doj:       var(--navy);
  --bg-about-impact:    var(--paper);
  --bg-about-values:    var(--cream);
  --bg-about-history:   var(--navy);
  --bg-about-partners:  var(--paper);

  /* Services page rhythm — services DOJ is navy-deep, not navy, so
     it doesn't merge with the navy footer (V3 reference had this
     adjacent-same-bg violation; we fix it here). */
  --bg-services-doj:    var(--navy-deep);

  /* Education page rhythm — contact band is navy-deep so it stays
     distinct from the navy footer. */
  --bg-education-programs: var(--paper);
  --bg-education-contact:  var(--navy-deep);

  /* Payments page rhythm — paper methods between the cream hero and the navy footer. */
  --bg-payments-methods:   var(--paper);

  /* Contact page rhythm */
  --bg-contact-form:    var(--paper);

  /* Donate page rhythm — hero reuses --bg-donate (navy). */
  --bg-donate-other:    var(--paper);

  /* Donate thank-you page — navy confirmation band, mirrors the donate
     hero so the give journey reads continuously through to the receipt. */
  --bg-thank-you:       var(--navy);

  /* Generic Page fallback — any templateless page renders on paper,
     distinct from the navy nav above and navy footer below. */
  --bg-page:            var(--paper);

  /* News single — "How IHF can help" callout band is navy-deep so it
     reads as a distinct CTA inside the otherwise cream news single. */
  --bg-news-help:       var(--navy-deep);

  /* Single event — inline RSVP band sits on navy-deep so the cream
     form card pops, and it doesn't share a bg with the paper body
     section above it or the navy share band below it. */
  --bg-event-rsvp:      var(--navy-deep);

  /* News section rhythm */
  --bg-news-hero:       var(--cream);      /* archive + single post hero */
  --bg-news-topics:     var(--navy);       /* topic filter bar */
  --bg-news-list:       var(--paper);      /* archive card grid */
  --bg-news-more:       var(--navy-deep);  /* related posts (single); navy-deep so it doesn't merge into the navy footer */
  --bg-news-cta:        var(--navy-deep);  /* archive newsletter + CLINIC badge; navy-deep keeps the section rhythm (paper list -> navy-deep -> navy footer) */
  --bg-news-post-help:  var(--cream);      /* single "How IHF can help" */
  --bg-news-post-body:  var(--paper);      /* single article body (Background + What's changed) */
  --bg-news-post-foot:  var(--paper);      /* single article source + disclaimer footer */

  /* ─── Transitions ───────────────────────────────────────── */
  --t-fast:         0.15s ease;   /* Hover, focus, small state changes */
  --t-mid:          0.25s ease;   /* Modals, drawers, larger reveals */
  --t-slow:         0.4s ease;    /* Page-level transitions */
  /* Theme back-compat aliases — components.css and Tailwind utilities
     using --transition-fast/--transition-mid resolve to the same timing. */
  --transition-fast: var(--t-fast);
  --transition-mid:  var(--t-mid);
}

/* ─── Base resets ──────────────────────────────────────────
   Ported from V3 reference build (assets/css/tokens.css).

   These MUST live inside `@layer base` so Tailwind utility classes
   (`text-on-cream-65`, `leading-tight`, etc.) can override them. If
   these rules are unlayered they win the cascade unconditionally —
   `body { color: var(--navy-deep) }` then beats every `text-*` utility,
   and `h1 { line-height: 1.15 }` beats `leading-tight`. We hit that
   trap once; the layer makes the fix structural. */

@layer base {
  *, *::before, *::after { box-sizing: border-box; }

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

  body {
    margin: 0;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    line-height: 1.6;
    color: var(--navy-deep);
    background: var(--page);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  /* Heading styles do NOT live in @layer base because Tailwind v4's
     Preflight (also @layer base, loaded after tokens.css) explicitly
     resets h1–h6 to inherit font-size + font-weight. Source order
     within a layer is the tiebreaker, so any heading rules here are
     overwritten. Heading roles live as component classes in
     tw-input.css: .hero-heading, .section-heading,
     .section-heading-on-navy. Each fully owns its typography. */

  p { margin: 0; }

  a { color: inherit; text-decoration: none; }

  img { max-width: 100%; display: block; }

  button { font-family: var(--font-body); cursor: pointer; }
}
