/**
 * Accessibility Enhancements (A11y)
 * WCAG 2.1 AA Compliance
 */

/* ==========================================================================
   1. Skip to Content Link
   ========================================================================== */
.skip-to-content {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    padding: 1rem 2rem;
    background: var(--primary-color, #ff5528);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 8px 8px;
    transition: top 0.3s ease;
}

.skip-to-content:focus {
    top: 0;
    outline: 3px solid var(--secondary-color, #0e2a47);
    outline-offset: 2px;
}

/* ==========================================================================
   2. Focus Indicators
   ========================================================================== */

/* Enhanced focus styles for all interactive elements */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 3px solid var(--primary-color, #ff5528);
    outline-offset: 2px;
}

/* Focus visible for keyboard users only */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible) {
    outline: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid var(--primary-color, #ff5528);
    outline-offset: 2px;
}

/* High contrast focus for dark backgrounds */
.main-footer a:focus-visible,
.mobile-nav__wrapper a:focus-visible {
    outline-color: #fff;
}

/* ==========================================================================
   3. Screen Reader Only Content
   ========================================================================== */
.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: 0;
}

/* Show on focus (for skip links) */
.sr-only-focusable:focus,
.sr-only-focusable:active {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ==========================================================================
   4. 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;
    }

    .wow {
        visibility: visible !important;
        animation: none !important;
    }
}

/* ==========================================================================
   5. High Contrast Mode Support
   ========================================================================== */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #d94400;
        --text-color: #000;
        --bg-color: #fff;
    }

    a, button {
        text-decoration: underline;
    }

    .btn, .eduact-btn {
        border: 2px solid currentColor;
    }
}

/* Forced colors mode (Windows High Contrast) */
@media (forced-colors: active) {
    a:focus,
    button:focus {
        outline: 3px solid CanvasText;
    }

    .btn, .eduact-btn {
        border: 2px solid ButtonText;
    }
}

/* ==========================================================================
   6. Touch Target Sizes (minimum 44x44px)
   ========================================================================== */
.mobile-nav__toggler,
.mobile-nav__close,
.scroll-top,
.main-menu__login,
.main-footer__social a,
.mobile-nav__social a {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Ensure adequate spacing between touch targets */
.main-menu__list > li {
    margin-inline: 0.25rem;
}

.main-footer__social a,
.mobile-nav__social a {
    margin-inline: 0.25rem;
}

/* ==========================================================================
   7. Form Accessibility
   ========================================================================== */

/* Labels should always be visible or properly associated */
label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

/* Required field indicator */
.required::after,
label.required::after {
    content: " *";
    color: #dc3545;
}

/* Error states */
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: #dc3545;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.25);
}

/* Error messages */
.error-message,
[role="alert"] {
    color: #dc3545;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Success states */
input[aria-invalid="false"],
select[aria-invalid="false"],
textarea[aria-invalid="false"] {
    border-color: #28a745;
}

/* ==========================================================================
   8. Link Accessibility
   ========================================================================== */

/* Ensure links are distinguishable */
main a:not(.btn):not(.eduact-btn) {
    text-decoration: underline;
    text-decoration-skip-ink: auto;
    text-underline-offset: 2px;
}

main a:not(.btn):not(.eduact-btn):hover {
    text-decoration-thickness: 2px;
}

/* External link indicator */
a[target="_blank"]::after {
    content: " \2197"; /* Northeast arrow */
    font-size: 0.75em;
    vertical-align: super;
}

/* Hide external indicator for icons/images */
a[target="_blank"]:has(> i),
a[target="_blank"]:has(> img),
.main-footer__social a[target="_blank"]::after,
.mobile-nav__social a[target="_blank"]::after {
    content: none;
}

a[target="_blank"] > i + .sr-only,
a[target="_blank"]:has(> i)::after {
    content: none;
}

/* ==========================================================================
   9. Navigation Accessibility
   ========================================================================== */

/* Dropdown indicators */
.dropdown > a::after {
    content: "";
    display: inline-block;
    width: 0;
    height: 0;
    margin-inline-start: 0.5rem;
    vertical-align: middle;
    border-top: 0.3em solid;
    border-right: 0.3em solid transparent;
    border-left: 0.3em solid transparent;
}

/* Expanded state */
.dropdown > a[aria-expanded="true"]::after {
    border-top: 0;
    border-bottom: 0.3em solid;
}

/* Mobile menu state */
.mobile-nav__toggler[aria-expanded="true"] {
    background: var(--primary-color, #ff5528);
    color: #fff;
}

/* ==========================================================================
   10. Image Accessibility
   ========================================================================== */

/* Ensure images don't overflow */
img {
    max-width: 100%;
    height: auto;
}

/* Placeholder for missing alt text (development only) */
img:not([alt]) {
    outline: 3px dashed #dc3545;
}

img[alt=""] {
    /* Decorative images - no outline needed */
}

/* ==========================================================================
   11. Table Accessibility
   ========================================================================== */
table {
    border-collapse: collapse;
    width: 100%;
}

th {
    text-align: start;
    font-weight: 600;
    background: var(--bg-light, #f8f9fa);
}

th, td {
    padding: 0.75rem;
    border: 1px solid var(--border-color, #dee2e6);
}

/* Responsive tables */
@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ==========================================================================
   12. Loading States
   ========================================================================== */

/* Announce loading to screen readers */
[aria-busy="true"] {
    cursor: wait;
}

[aria-busy="true"]::after {
    content: "";
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-inline-start: 0.5rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   13. Print Styles
   ========================================================================== */
@media print {
    .skip-to-content,
    .mobile-nav__wrapper,
    .scroll-top,
    .search-popup,
    .main-menu__toggler {
        display: none !important;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
    }

    a[href^="#"]::after,
    a[href^="javascript"]::after {
        content: none;
    }
}
