/**
 * H3 Systems AI - Accessibility Styles (WCAG 2.2 Compliant)
 * 
 * WCAG 2.2 Level AA Compliance
 * - 1.4.3 Contrast (Minimum) - 4.5:1 for normal text, 3:1 for large text
 * - 1.4.11 Non-text Contrast - 3:1 for UI components
 * - 2.4.7 Focus Visible - Visible focus indicators
 * - 2.4.11 Focus Not Obscured (Minimum) - Focus not hidden
 * - 2.4.13 Focus Appearance - Enhanced focus indicators
 * - 2.5.8 Target Size (Minimum) - 24x24px minimum
 */

/* ==========================================================================
   1. COLOR CONTRAST OVERRIDES (WCAG 1.4.3, 1.4.6)
   Ensuring 4.5:1 minimum contrast ratio for normal text
   ========================================================================== */

:root {
    /* Accessible color palette - all meet 4.5:1 on dark background */
    --a11y-text-primary: #ffffff;      /* White on #0a0a0f = 18.3:1 */
    --a11y-text-secondary: #b8b8c0;    /* Light gray on #0a0a0f = 7.8:1 */
    --a11y-text-muted: #9090a0;        /* Muted on #0a0a0f = 5.2:1 */
    --a11y-accent-amber: #fbbf24;      /* Amber on #0a0a0f = 11.4:1 */
    --a11y-accent-green: #34d399;      /* Green on #0a0a0f = 9.1:1 */
    --a11y-accent-red: #f87171;        /* Red on #0a0a0f = 6.5:1 */
    --a11y-link-color: #60a5fa;        /* Blue on #0a0a0f = 6.3:1 */
    
    /* Focus indicator colors */
    --a11y-focus-color: #fbbf24;
    --a11y-focus-offset: 3px;
    --a11y-focus-width: 3px;
}

/* Apply accessible text colors */
body {
    color: var(--a11y-text-primary);
}

.hero-subtitle,
.section-subtitle,
p,
.tool-description,
.practice-description,
.danger-description {
    color: var(--a11y-text-secondary);
}

.stat-label,
.section-tag,
.founder-title {
    color: var(--a11y-text-muted);
}

/* ==========================================================================
   2. FOCUS INDICATORS (WCAG 2.4.7, 2.4.11, 2.4.13)
   Focus Appearance: 2px solid outline with 2px offset, high contrast
   ========================================================================== */

/* Remove default outlines and apply custom focus */
*:focus {
    outline: none;
}

/* Custom focus indicator for all interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
[role="button"]:focus-visible,
[role="link"]:focus-visible,
[role="menuitem"]:focus-visible,
.nav-cta:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible {
    outline: var(--a11y-focus-width) solid var(--a11y-focus-color);
    outline-offset: var(--a11y-focus-offset);
    border-radius: 4px;
    /* Ensure focus is not obscured (2.4.11) */
    position: relative;
    z-index: 1;
}

/* Ensure focus works for links inside navigation */
#primary-menu a:focus-visible,
.footer-links a:focus-visible {
    outline: var(--a11y-focus-width) solid var(--a11y-focus-color);
    outline-offset: var(--a11y-focus-offset);
    border-radius: 4px;
}

/* Enhanced focus for buttons */
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.nav-cta:focus-visible {
    outline: var(--a11y-focus-width) solid var(--a11y-focus-color);
    outline-offset: var(--a11y-focus-offset);
    box-shadow: 0 0 0 6px rgba(251, 191, 36, 0.3);
}

/* Focus within for composite widgets */
.form-group:focus-within {
    outline: 2px solid var(--a11y-focus-color);
    outline-offset: 4px;
    border-radius: 8px;
}

/* Ensure focus indicator has sufficient contrast (2.4.13) */
/* Focus area must be at least 2px thick with 3:1 contrast */
@supports selector(:focus-visible) {
    *:focus:not(:focus-visible) {
        outline: none;
    }
}

/* ==========================================================================
   3. TARGET SIZE (WCAG 2.5.8)
   Minimum 24x24px for all interactive elements
   ========================================================================== */

/* Ensure minimum touch/click target size */
a,
button,
input[type="submit"],
input[type="button"],
input[type="checkbox"],
input[type="radio"],
[role="button"],
[role="link"],
[role="menuitem"] {
    min-height: 44px; /* iOS recommendation, exceeds WCAG minimum */
    min-width: 44px;
}

/* Inline links can be smaller but need adequate spacing */
p a,
li a,
.entry-content a {
    min-height: auto;
    min-width: auto;
    padding: 2px 4px;
    margin: -2px -4px;
    display: inline-block;
}

/* Navigation items */
#primary-menu a,
.footer-links a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
}

/* Form inputs */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="search"],
textarea,
select {
    min-height: 44px;
    padding: 12px 16px;
}

/* Icon-only buttons need explicit sizing */
.mobile-menu-toggle,
.founder-link,
[aria-label]:not([aria-label=""]) {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Social links spacing */
.founder-links {
    gap: 8px;
}

/* ==========================================================================
   4. SKIP LINKS & NAVIGATION (WCAG 2.4.1, 2.4.5)
   ========================================================================== */

/* Enhanced skip link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--a11y-focus-color);
    color: #000000;
    padding: 16px 24px;
    border-radius: 0 0 8px 8px;
    font-weight: 700;
    font-size: 1rem;
    z-index: 100000;
    transition: top 0.3s ease;
    text-decoration: none;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #ffffff;
    outline-offset: 2px;
}

/* Skip link for keyboard users to bypass sections */
.skip-section {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.skip-section:focus {
    position: fixed;
    top: 80px;
    left: 16px;
    width: auto;
    height: auto;
    background: var(--bg-secondary);
    color: var(--a11y-text-primary);
    padding: 12px 20px;
    border: 2px solid var(--a11y-focus-color);
    border-radius: 8px;
    z-index: 99999;
}

/* ==========================================================================
   5. SCREEN READER UTILITIES (WCAG 1.3.1)
   ========================================================================== */

/* Visually hidden but accessible to screen readers */
.sr-only,
.screen-reader-text,
.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;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Allow screen reader text to become visible on focus */
.sr-only-focusable:focus,
.sr-only-focusable:active,
.screen-reader-text:focus,
.screen-reader-text:active {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: 12px 20px !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    clip-path: none !important;
    white-space: normal !important;
    background: var(--bg-secondary);
    color: var(--a11y-text-primary);
    border: 2px solid var(--a11y-focus-color) !important;
    border-radius: 4px;
    z-index: 100000;
}

/* ==========================================================================
   6. FORM ACCESSIBILITY (WCAG 1.3.5, 3.3.1, 3.3.2)
   ========================================================================== */

/* Form labels must be visible */
label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--a11y-text-primary);
}

/* Required field indicator */
label[for] .required,
.required-indicator {
    color: var(--a11y-accent-red);
    margin-left: 4px;
}

/* Add "required" text for screen readers */
label[for] .required::after {
    content: " (required)";
    position: absolute;
    left: -9999px;
}

/* Error states */
.form-error,
[aria-invalid="true"] {
    border-color: var(--a11y-accent-red) !important;
    border-width: 2px;
}

.error-message,
[role="alert"] {
    color: var(--a11y-accent-red);
    font-size: 0.875rem;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.error-message::before {
    content: "⚠";
    font-size: 1.1em;
}

/* Success states */
.form-success,
[aria-live="polite"].success {
    color: var(--a11y-accent-green);
}

/* Input descriptions */
.input-description,
[id$="-description"] {
    font-size: 0.875rem;
    color: var(--a11y-text-muted);
    margin-top: 4px;
}

/* Autocomplete styling */
input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px var(--bg-secondary) inset;
    -webkit-text-fill-color: var(--a11y-text-primary);
}

/* ==========================================================================
   7. MOTION & ANIMATION (WCAG 2.3.3)
   Respect prefers-reduced-motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    /* Disable parallax and floating animations */
    .bg-grid,
    .bg-gradient,
    .privacy-visual::before,
    .potential-section::before {
        animation: none !important;
    }
    
    /* Keep focus transitions but make them instant */
    *:focus-visible {
        transition: none !important;
    }
    
    /* Disable hover transforms */
    .danger-card:hover,
    .tool-card:hover,
    .practice-card:hover,
    .benefit-card:hover {
        transform: none !important;
    }
}

/* Provide pause control for animations */
.animation-paused,
.animation-paused * {
    animation-play-state: paused !important;
}

/* ==========================================================================
   8. COLOR INDEPENDENCE (WCAG 1.4.1)
   Don't rely on color alone to convey information
   ========================================================================== */

/* Risk badges need icons, not just colors */
.risk-badge::before {
    margin-right: 6px;
}

.risk-badge.risk-lower::before {
    content: "✓";
}

.risk-badge.risk-caution::before {
    content: "⚠";
}

.risk-badge.risk-high::before {
    content: "✕";
}

/* Links need underlines, not just color */
.entry-content a,
p a:not(.btn-primary):not(.btn-secondary) {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.entry-content a:hover,
p a:not(.btn-primary):not(.btn-secondary):hover {
    text-decoration-thickness: 2px;
}

/* Status indicators need text + icon */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ==========================================================================
   9. TEXT SPACING (WCAG 1.4.12)
   Content must adapt to user text spacing preferences
   ========================================================================== */

/* Ensure content works with:
   - Line height 1.5x font size
   - Paragraph spacing 2x font size  
   - Letter spacing 0.12x font size
   - Word spacing 0.16x font size
*/

body {
    line-height: 1.6; /* Already > 1.5 */
}

p {
    margin-bottom: 1.5em; /* > 2x line height */
}

/* Don't use fixed heights that could clip text */
.hero-subtitle,
.section-subtitle,
.card-description {
    min-height: auto;
    height: auto;
    overflow: visible;
}

/* ==========================================================================
   10. REFLOW (WCAG 1.4.10)
   Content must reflow at 320px width without horizontal scrolling
   ========================================================================== */

@media screen and (max-width: 320px) {
    body {
        font-size: 16px;
    }
    
    .hero h1 {
        font-size: 1.75rem;
    }
    
    .section-title {
        font-size: 1.5rem;
    }
    
    .hero-stats {
        flex-direction: column;
    }
    
    .stat {
        width: 100%;
        text-align: center;
    }
    
    .nav-container {
        padding: 0 12px;
    }
    
    .benefits-grid,
    .dangers-grid,
    .tools-grid,
    .practices-container {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   11. IMAGES & MEDIA (WCAG 1.1.1, 1.4.5)
   ========================================================================== */

/* Ensure all images have alt text indicators */
img:not([alt]) {
    outline: 3px solid var(--a11y-accent-red);
}

/* Decorative images */
img[alt=""],
[role="presentation"],
[aria-hidden="true"] img {
    outline: none;
}

/* SVG accessibility */
svg[role="img"] {
    /* Ensure SVGs are announced */
}

svg:not([role="img"]):not([aria-hidden="true"]) {
    /* Flag SVGs without proper roles */
}

/* ==========================================================================
   12. HIGH CONTRAST MODE (WCAG 1.4.11)
   ========================================================================== */

@media (prefers-contrast: high) {
    :root {
        --border-color: #ffffff;
        --a11y-text-secondary: #ffffff;
        --a11y-text-muted: #e0e0e0;
    }
    
    .danger-card,
    .tool-card,
    .practice-card,
    .benefit-card {
        border-width: 2px;
        border-color: #ffffff;
    }
    
    .btn-primary,
    .btn-secondary {
        border-width: 2px;
    }
    
    /* Ensure form fields are visible */
    input,
    textarea,
    select {
        border: 2px solid #ffffff;
    }
    
    /* Stronger focus indicator */
    *:focus-visible {
        outline-width: 4px;
        outline-color: #ffffff;
    }
}

/* Windows High Contrast Mode */
@media (forced-colors: active) {
    .btn-primary,
    .btn-secondary,
    .nav-cta {
        border: 2px solid currentColor;
    }
    
    *:focus-visible {
        outline: 3px solid Highlight;
    }
    
    .skip-link:focus {
        background: Highlight;
        color: HighlightText;
    }
}

/* ==========================================================================
   13. LANDMARK VISIBILITY FOR TESTING
   ========================================================================== */

/* Debug mode - uncomment to visualize landmarks
[role="banner"]::before { content: "HEADER"; }
[role="main"]::before { content: "MAIN"; }
[role="navigation"]::before { content: "NAV"; }
[role="contentinfo"]::before { content: "FOOTER"; }
[role="region"]::before { content: attr(aria-label); }
*/

/* ==========================================================================
   14. CONSISTENT HELP (WCAG 3.2.6)
   Help mechanisms in same relative location
   ========================================================================== */

.help-link,
.contact-link {
    /* Always in footer and fixed position */
}

/* Fixed help button (optional) */
.a11y-help-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    min-width: 44px;
    min-height: 44px;
    background: var(--bg-secondary);
    border: 2px solid var(--a11y-focus-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    cursor: pointer;
}

/* ==========================================================================
   15. PRINT ACCESSIBILITY
   ========================================================================== */

@media print {
    /* Ensure sufficient contrast for printing */
    body {
        background: white !important;
        color: black !important;
    }
    
    a {
        color: black !important;
        text-decoration: underline !important;
    }
    
    /* Show URLs for links */
    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        word-break: break-all;
    }
    
    /* Don't print decorative elements */
    .bg-grid,
    .bg-gradient,
    [aria-hidden="true"] {
        display: none !important;
    }
    
    /* Ensure headings stand out */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        color: black !important;
    }
}
