/**
 * Accessibility Enhancements
 * WCAG 2.1 AA Compliance
 *
 * Created: 2025-12-06
 * Purpose: FAS 6 Phase 0 - Accessibility improvements
 */

/* ============================================
   FOCUS STATES
   WCAG 2.4.7 Focus Visible (Level AA)
   ============================================ */

/* Enhanced focus indicator for all interactive elements */
:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 3px;
}

/* Remove default outline but keep for :focus-visible */
:focus:not(:focus-visible) {
    outline: none;
}

/* High-contrast focus for buttons */
button:focus-visible,
.btn:focus-visible,
input[type="submit"]:focus-visible {
    outline: 3px solid var(--color-primary-700);
    outline-offset: 3px;
    box-shadow: 0 0 0 4px rgba(74, 127, 181, 0.3);
}

/* Focus for links */
a:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    background-color: rgba(74, 127, 181, 0.1);
}

/* Focus for form inputs */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 1px;
    border-color: var(--color-primary-700);
}


/* ============================================
   SKIP LINK
   WCAG 2.4.1 Bypass Blocks (Level A)
   ============================================ */

.skip-link {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 10000;
    background: var(--color-primary, #2c3e50);
    color: white;
    padding: 10px 20px;
    text-decoration: none;
    font-weight: bold;
    border-radius: 0 0 5px 0;
}

.skip-link:focus {
    position: fixed;
    top: 0;
    left: 0;
    width: auto;
    height: auto;
    overflow: visible;
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}


/* ============================================
   SCREEN READER ONLY
   WCAG 1.3.1 Info and Relationships (Level A)
   ============================================ */

/* Hide visually but keep for screen readers */
.sr-only,
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Allow focus for keyboard navigation */
.sr-only:focus,
.visually-hidden:focus {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}


/* ============================================
   TOUCH TARGET SIZING
   WCAG 2.5.5 Target Size (Level AAA)
   Best practice: Minimum 44x44px
   ============================================ */

/* Ensure minimum touch target size for interactive elements */
button,
.btn,
input[type="submit"],
input[type="button"],
input[type="checkbox"],
input[type="radio"],
a.vote-btn,
.period-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 16px;
}

/* Special handling for icon-only buttons */
button[aria-label]:empty,
.btn[aria-label]:empty {
    min-width: 44px;
    min-height: 44px;
    padding: 12px;
}

/* Checkbox and radio buttons */
input[type="checkbox"],
input[type="radio"] {
    width: 20px;
    height: 20px;
    /* Add padding to reach 44px touch target */
    padding: 12px;
    margin: 4px;
}


/* ============================================
   HIGH CONTRAST MODE SUPPORT
   WCAG 1.4.11 Non-text Contrast (Level AA)
   ============================================ */

@media (prefers-contrast: high) {
    /* Increase border thickness for better visibility */
    button,
    .btn,
    input,
    select,
    textarea {
        border-width: 2px;
        border-style: solid;
    }

    /* Ensure focus is highly visible */
    :focus-visible {
        outline-width: 4px;
        outline-offset: 3px;
    }

    /* Stronger shadows for depth perception */
    .card,
    .metric-card,
    .chart-card,
    .hypothesis-card {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    }
}


/* ============================================
   REDUCED MOTION SUPPORT
   WCAG 2.3.3 Animation from Interactions (Level AAA)
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    /* Disable all animations and transitions */
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Keep essential visibility changes instant */
    .modal,
    .dropdown,
    .tooltip {
        transition: none !important;
    }
}


/* ============================================
   KEYBOARD NAVIGATION ENHANCEMENTS
   WCAG 2.1.1 Keyboard (Level A)
   ============================================ */

/* Visible focus for keyboard navigation */
*:focus-visible {
    /* Ensure focus is visible on all elements */
    z-index: 1;
}

/* Maintain focus ring on modal backdrop clicks */
.modal:focus-within {
    outline: none; /* Modal itself doesn't need outline */
}

.modal *:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}


/* ============================================
   COLOR CONTRAST IMPROVEMENTS
   WCAG 1.4.3 Contrast (Minimum) - Level AA
   Ratio: 4.5:1 for normal text, 3:1 for large text
   ============================================ */

/* Ensure text contrast on colored backgrounds */
.badge,
.priority-badge,
.geo-badge {
    font-weight: 600;
    /* Background colors should be dark enough for white text */
}

/* Links should have sufficient contrast */
a {
    color: var(--color-primary-700); /* Darker blue for better contrast */
    text-decoration: underline; /* Ensure links are identifiable without color alone */
}

a:hover,
a:focus {
    color: var(--color-primary-800); /* Even darker on hover/focus */
    text-decoration: underline;
}

/* Disabled state should be clearly distinguishable */
button:disabled,
.btn:disabled,
input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    border: 2px dashed var(--color-gray-400);
}


/* ============================================
   ARIA LIVE REGION STYLING
   WCAG 4.1.3 Status Messages (Level AA)
   ============================================ */

/* Visual styling for live regions (optional) */
[aria-live="polite"],
[aria-live="assertive"] {
    /* Live regions can be invisible but functional */
    /* Add border for debugging (remove in production) */
    /* border: 2px dotted #3498db; */
}

/* Screen reader announcements */
.sr-alert {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}


/* ============================================
   RESPONSIVE ACCESSIBILITY
   Ensure accessibility on mobile devices
   ============================================ */

@media (max-width: 768px) {
    /* Increase touch target size on mobile */
    button,
    .btn,
    a.vote-btn,
    input[type="submit"] {
        min-height: 48px;
        min-width: 48px;
        padding: 12px 20px;
    }

    /* Larger text for better readability */
    body {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    /* Ensure form inputs are large enough */
    input,
    select,
    textarea {
        min-height: 48px;
        font-size: 16px;
    }
}


/* ============================================
   DARK MODE ACCESSIBILITY
   Maintain contrast in dark mode
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* Ensure focus remains visible in dark mode */
    :focus-visible {
        outline-color: #5dade2;
    }

    /* Adjust link colors for dark backgrounds */
    a {
        color: #5dade2;
    }

    a:hover,
    a:focus {
        color: #85c1e9;
    }
}


/* ============================================
   PRINT ACCESSIBILITY
   Ensure content is accessible when printed
   ============================================ */

@media print {
    /* Remove skip links and nav from print */
    .skip-link,
    nav,
    .navbar {
        display: none;
    }

    /* Ensure links are visible in print */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #555;
    }

    /* Don't print empty links */
    a[href^="#"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }

    /* Ensure focus indicators don't print */
    :focus-visible {
        outline: none;
    }
}
