/**
 * Accessibility Improvements
 * WCAG 2.1 AA Compliance enhancements
 */

/* =Focus States & Keyboard Navigation
-------------------------------------------------------------- */

/* Enhanced focus visible for keyboard navigation */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.btn:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.2);
}

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

/* Enhanced skip link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    z-index: 100000;
    padding: 10px 15px;
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    transition: top 0.1s ease-in-out;
}

.skip-link:focus {
    top: 0;
    outline-color: white;
}

/* Focus within navigation */
.main-navigation a:focus,
.main-navigation button:focus {
    background-color: rgba(44, 90, 160, 0.1);
    border-radius: 4px;
}

/* Mobile menu toggle keyboard focus */
.menu-toggle:focus-visible {
    background-color: var(--secondary-color);
}

/* =Color Contrast Improvements
-------------------------------------------------------------- */

/* Ensure minimum 4.5:1 contrast ratio for normal text */
:root {
    --text-color: #1a1a1a; /* Darker for better contrast */
    --text-light: #555555; /* Improved from #666666 */
    --text-muted: #6c757d; /* Improved from #999999 */
}

/* Link contrast */
a {
    color: #1a4d8f; /* Darker blue for better contrast */
}

a:hover,
a:focus {
    color: #c23616; /* Darker orange for better contrast */
    text-decoration: underline;
}

/* Button contrast improvements */
.btn-outline {
    border-width: 2px; /* Thicker borders for visibility */
}

.btn-secondary {
    background-color: #d85a2a; /* Darker secondary color */
}

/* Meta text contrast */
.cursus-meta,
.meta-item,
.entry-meta {
    color: var(--text-light);
}

/* Footer contrast */
.site-footer {
    color: #f8f9fa; /* Light text on dark background */
}

.site-footer a {
    color: #ffffff;
}

.site-footer a:hover,
.site-footer a:focus {
    color: var(--accent-color);
}

/* =Screen Reader Only Content
-------------------------------------------------------------- */

.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute !important;
    width: 1px;
    word-wrap: normal !important;
}

.screen-reader-text:focus {
    background-color: var(--bg-light);
    border-radius: 3px;
    box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
    clip: auto !important;
    clip-path: none;
    color: var(--primary-color);
    display: block;
    font-size: 0.875rem;
    font-weight: 700;
    height: auto;
    left: 5px;
    line-height: normal;
    padding: 15px 23px 14px;
    text-decoration: none;
    top: 5px;
    width: auto;
    z-index: 100000;
}

/* =ARIA Labels & Hidden Content
-------------------------------------------------------------- */

/* Ensure hidden content is truly hidden */
[aria-hidden="true"] {
    display: none !important;
}

/* Visually hide but keep accessible */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    border: 0 !important;
    padding: 0 !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    white-space: nowrap !important;
}

/* =Form Accessibility
-------------------------------------------------------------- */

/* Visible focus for form inputs */
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.1);
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

/* Required field indicator */
.required-field::after {
    content: " *";
    color: var(--danger-color);
    font-weight: bold;
}

/* Error states with sufficient contrast */
.error-message,
.form-error {
    color: #b91c1c; /* Dark red for better contrast */
    font-weight: 600;
}

input.error,
textarea.error,
select.error {
    border-color: #b91c1c;
}

/* =Interactive Element States
-------------------------------------------------------------- */

/* Hover states should not be the only visual indicator */
button,
.btn,
a.btn {
    position: relative;
    transition: all 0.2s ease-in-out;
}

/* Disabled state */
button:disabled,
.btn:disabled,
input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Loading state indicator */
.loading::after {
    content: "...";
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}

/* =Motion & Animation Preferences
-------------------------------------------------------------- */

/* Respect reduced motion preference */
@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;
    }

    .smooth-scroll {
        scroll-behavior: auto !important;
    }
}

/* =High Contrast Mode Support
-------------------------------------------------------------- */

@media (prefers-contrast: high) {
    :root {
        --primary-color: #003d82;
        --secondary-color: #b91c1c;
        --text-color: #000000;
        --bg-color: #ffffff;
    }

    a {
        text-decoration: underline;
    }

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

/* =Touch Target Size (Minimum 44x44px)
-------------------------------------------------------------- */

/* Ensure interactive elements are large enough */
a,
button,
input[type="submit"],
input[type="button"],
.btn {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Exception for inline links in text */
p a,
li a {
    min-height: auto;
    min-width: auto;
    display: inline;
}

/* Mobile menu items */
@media (max-width: 768px) {
    .main-navigation a {
        min-height: 48px;
        display: flex;
        align-items: center;
        padding: 12px 20px;
    }
}

/* =Table Accessibility
-------------------------------------------------------------- */

/* Responsive table wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    border-collapse: collapse;
    width: 100%;
}

th {
    font-weight: 600;
    text-align: left;
    background-color: var(--bg-light);
}

/* Zebra striping for better readability */
tbody tr:nth-child(even) {
    background-color: rgba(0,0,0,0.02);
}

/* =Image Accessibility
-------------------------------------------------------------- */

/* Ensure decorative images have empty alt */
img:not([alt]) {
    border: 3px solid red; /* Development aid */
}

/* Lazy loaded images */
img[loading="lazy"] {
    background-color: var(--bg-light);
}

/* =Cookie Consent Accessibility
-------------------------------------------------------------- */

.cookie-consent-banner {
    /* Ensure keyboard can reach all controls */
}

.cookie-consent-banner button:focus-visible {
    outline: 3px solid white;
    outline-offset: 2px;
}

/* =Navigation Accessibility
-------------------------------------------------------------- */

/* Current page indicator */
.current-menu-item > a,
.current_page_item > a {
    font-weight: 600;
    position: relative;
}

.current-menu-item > a::before,
.current_page_item > a::before {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 3px;
    background-color: var(--secondary-color);
}

/* =Print Styles (Accessibility for printing)
-------------------------------------------------------------- */

@media print {
    /* Hide non-essential elements */
    .menu-toggle,
    .skip-link,
    .cookie-consent-banner,
    .back-to-top,
    .announcements-bar,
    .header-top {
        display: none !important;
    }

    /* Ensure readability */
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
    }

    a {
        text-decoration: underline;
    }

    /* Show URLs for links */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.9em;
        color: #666;
    }

    /* Don't show URL for internal anchors */
    a[href^="#"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }
}
