/* ============================================================================
 * ACCESSIBILITY.CSS — WCAG 2.1 AA layer, site-wide.
 *
 * Loaded LAST in <head> so its rules win the cascade against page-scoped
 * CSS (main.css, home.css, stitch-tokens.css, per-page overrides). Nothing
 * in this file changes visual identity — it only adds/fixes the pieces that
 * make the site usable for people relying on:
 *
 *   - Screen readers (JAWS, NVDA, VoiceOver, TalkBack)
 *   - Keyboard-only navigation
 *   - Zoom (up to 400% per WCAG 1.4.4)
 *   - Reduced motion (vestibular disorders, migraine, epilepsy)
 *   - High contrast (low vision)
 *   - Larger touch targets (motor impairments, tremor)
 *
 * References:
 *   - WCAG 2.1: https://www.w3.org/TR/WCAG21/
 *   - MDN accessibility guide: https://developer.mozilla.org/en-US/docs/Web/Accessibility
 * ========================================================================= */


/* ── 1. SKIP-TO-CONTENT LINK ─────────────────────────────────────────────
   The first thing a keyboard/screen-reader user hits on every page. Lets
   them jump past the nav to the main content in one Tab press. Hidden
   visually until focused (mouse users never see it). WCAG 2.4.1. */
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 8px;
    z-index: 10000;
    padding: 12px 20px;
    background: #033619;
    color: #ffffff;
    font-weight: 600;
    text-decoration: none;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: top 0.15s ease;
}
.skip-to-content:focus,
.skip-to-content:focus-visible {
    top: 8px;
    outline: 3px solid #ffdf98;
    outline-offset: 2px;
    color: #ffffff;
}


/* ── 2. SCREEN-READER-ONLY UTILITY ───────────────────────────────────────
   Hides content visually while keeping it accessible to screen readers.
   Standard clip-path pattern that works in every SR engine. Use for:
   icon-only buttons ("<button>🔍<span class='sr-only'>Search</span>"),
   redundant text ("Read more <span class='sr-only'>about tomatoes</span>"),
   form status ("<div class='sr-only' role='status' aria-live='polite'>"). */
.sr-only,
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}
/* Reveal when the sr-only content is focused (skip-links etc). */
.sr-only-focusable:focus,
.sr-only-focusable:focus-visible {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: 0.4rem 0.8rem !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}


/* ── 3. FOCUS INDICATORS ─────────────────────────────────────────────────
   Every interactive element gets a visible focus ring. Uses :focus-visible
   so mouse clicks don't flash the outline, but keyboard focus does.
   WCAG 2.4.7 (Focus Visible). The ring is a high-contrast gold-on-green
   pair so it's visible against both light and dark backgrounds. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
[role="button"]:focus-visible,
[role="link"]:focus-visible {
    outline: 3px solid #d1ad56 !important;
    outline-offset: 2px !important;
    border-radius: 4px;
    /* Ensure focused element is layered above neighbors so the outline
       isn't clipped by an overflowing parent. */
    position: relative;
    z-index: 1;
}

/* Remove the accidental double-outline on Safari/Chrome for buttons. */
button:focus,
input[type="submit"]:focus,
input[type="button"]:focus { outline: none; }
/* But keep the visible one when it's keyboard-focused: */
button:focus-visible,
input[type="submit"]:focus-visible,
input[type="button"]:focus-visible {
    outline: 3px solid #d1ad56 !important;
    outline-offset: 2px !important;
}


/* ── 4. TOUCH TARGET SIZE ────────────────────────────────────────────────
   WCAG 2.5.5 (AAA — but Apple/Google both make it a requirement).
   All interactive controls hit the 44x44 CSS-pixel minimum. Nested
   controls (a small delete X inside a card) can be smaller if the parent
   is clickable, but on their own they need this. */
@media (pointer: coarse) {
    a.btn, a.button, button, input[type="submit"], input[type="button"],
    .nav-cta, .btn-primary, .btn-secondary, .btn-accent, .btn-danger,
    .nav-toggle, .pricing-btn {
        min-height: 44px;
        min-width: 44px;
    }
}


/* ── 5. REDUCED MOTION ───────────────────────────────────────────────────
   WCAG 2.3.3 (Animation from Interactions). Users who set prefers-
   reduced-motion get ALL animations killed — including hero video,
   GSAP scroll effects, ambient floats, transitions. The home-motion.js
   engine already respects this at the JS layer; this backstops CSS. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    /* Freeze the hero video on the poster frame */
    .hero-video { display: none !important; }
    .hero-video-wrap {
        background-image: url('/assets/video/hero-poster.jpg');
        background-size: cover;
        background-position: center;
    }
}


/* ── 6. HIGH-CONTRAST MODE ───────────────────────────────────────────────
   Windows High Contrast + macOS "Increase contrast" both trigger this.
   Boosts contrast on borders, links, and outlines. WCAG 1.4.11 */
@media (prefers-contrast: more) {
    a { text-decoration: underline; }
    button, .btn, .nav-cta { border: 2px solid currentColor !important; }
    input, textarea, select { border-width: 2px !important; }
    :focus-visible {
        outline-width: 4px !important;
        outline-offset: 3px !important;
    }
}


/* ── 7. LINK IDENTIFIABILITY ────────────────────────────────────────────
   WCAG 1.4.1 — color alone can't be the only signal. Body-text links
   (inside paragraphs) get an underline. Nav/button links keep their
   visual style. We scope this to prose so it doesn't ruin nav design. */
main p a:not([class]),
article p a:not([class]),
.prose a:not([class]),
.legal-doc a:not([class]) {
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
}
main p a:not([class]):hover,
article p a:not([class]):hover {
    text-decoration-thickness: 2px;
}


/* ── 8. FORM ACCESSIBILITY ──────────────────────────────────────────────
   Required indicators + error states that don't rely on color alone. */
label[for]::after,
.form-label::after {
    content: "";
}
label[for] .required,
.form-label .required {
    color: #ba1a1a;
    margin-left: 2px;
    font-weight: 700;
}
.form-error,
[role="alert"] {
    color: #93000a;
    font-weight: 600;
    padding: 0.6rem 0.9rem;
    background: rgba(186, 26, 26, 0.08);
    border-left: 4px solid #ba1a1a;
    border-radius: 4px;
    margin: 0.4rem 0;
}
/* Error inputs — border + icon + not just red */
input:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown) {
    border-color: #ba1a1a;
    border-width: 2px;
}
/* Ensure required fields are announced clearly */
input[required] + .required-mark,
textarea[required] + .required-mark {
    color: #ba1a1a;
    font-weight: 700;
    margin-left: 0.2rem;
}


/* ── 9. TABLE ACCESSIBILITY ─────────────────────────────────────────────
   Data tables should have proper caption/thead/scope. This CSS won't
   fix bad markup but adds visual separation that helps screen-magnifier
   users. */
table {
    border-collapse: collapse;
}
table caption {
    text-align: left;
    padding: 0.4rem 0;
    font-weight: 600;
    color: inherit;
}
th[scope="col"] {
    text-align: left;
    border-bottom: 2px solid currentColor;
}
th[scope="row"] {
    text-align: left;
}


/* ── 10. IMAGES + MEDIA ─────────────────────────────────────────────────
   Placeholder text if an image fails to load AND has alt. Prevents
   broken-image icon with nothing else. */
img { max-width: 100%; height: auto; }
img[alt]:not([alt=""]) {
    /* Only style when non-decorative alt is present. */
    font-style: italic;
    color: #414941;
    font-size: 0.85rem;
}
/* Decorative images should have alt="" — leave them alone. */


/* ── 11. PREVENT HORIZONTAL SCROLL ──────────────────────────────────────
   Users at 400% zoom need reflow, not horizontal scroll. WCAG 1.4.10 */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}


/* ── 12. PRINT STYLES ───────────────────────────────────────────────────
   Print users are effectively an accessibility user (offline / hard-copy
   need). Kill nav/promos/aside so the article content prints cleanly. */
@media print {
    nav, aside, .nav, .footer, .hero-video-wrap,
    [role="banner"], [role="navigation"],
    .skip-to-content, .ad-slot, .promo,
    .hero-video, .hero-scrollcue { display: none !important; }
    body { color: #000; background: #fff; }
    a::after { content: " (" attr(href) ")"; font-size: 0.85em; color: #555; }
    /* Don't append URLs for internal anchors — noise. */
    a[href^="#"]::after,
    a[href^="javascript"]::after { content: ""; }
}


/* ── 13. VIDEO CONTROLS FALLBACK ────────────────────────────────────────
   The hero video is decorative (muted, looping, no dialog). Some SR
   engines still announce it. Ensure decorative videos have aria-hidden
   at markup level (already done in section-hero.php); this backstops. */
video[muted][autoplay][loop] {
    /* Marks decorative videos as SR-ignorable via wrapping div's aria. */
}


/* ── 14. UNIVERSAL: PAUSE ON HOVER FOR MOVING TEXT ──────────────────────
   The seasonal "In Season Near You" ribbon may animate horizontally on
   some pages. WCAG 2.2.2 requires that any auto-moving content pause
   on hover/focus. */
.marquee:hover,
.marquee:focus-within,
[data-marquee]:hover,
[data-marquee]:focus-within {
    animation-play-state: paused !important;
}
