/**
 * Accessibility Enhancements
 * IT Allies Neuro Theme
 * 
 * WCAG 2.1 AA Compliant Styles
 * - Skip to Content Link
 * - Enhanced Focus Indicators
 * - Keyboard Navigation
 * - Screen Reader Support
 */

/* ============================================
   1. SKIP TO CONTENT LINK
   ============================================ */

.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    z-index: 100000;
    padding: 1rem 1.5rem;
    background-color: #6366f1;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 0.375rem 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: top 0.3s ease, box-shadow 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #ec4899;
    outline-offset: 2px;
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.2);
}

.skip-link:hover:focus {
    background-color: #4f46e5;
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.25);
}


/* ============================================
   2. ENHANCED FOCUS INDICATORS
   ============================================ */

/* Remove default outline for custom styling */
*:focus {
    outline: none;
}

/* Global Focus Style */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus,
[tabindex]:focus {
    outline: 3px solid #6366f1;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    transition: outline-offset 0.2s ease, box-shadow 0.2s ease;
}

/* Focus for Interactive Elements */
button:focus,
.wp-block-button__link:focus,
input[type="submit"]:focus,
input[type="button"]:focus {
    outline: 3px solid #ec4899;
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(236, 72, 153, 0.15);
}

/* Navigation Links Focus */
nav a:focus,
.wp-block-navigation-item a:focus {
    outline: 2px solid #8b5cf6;
    outline-offset: 4px;
    background-color: rgba(139, 92, 246, 0.05);
    border-radius: 0.25rem;
}

/* Form Input Focus Enhancement */
input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
textarea:focus {
    border-color: #6366f1;
    box-shadow: 
        0 0 0 3px rgba(99, 102, 241, 0.1),
        0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Checkbox & Radio Focus */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* Select Dropdown Focus */
select:focus {
    border-color: #6366f1;
    outline: 2px solid #6366f1;
    outline-offset: 0;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Card/Link Focus for Cards */
.wp-block-group.is-style-card-hover:focus-within,
.wp-block-group.is-style-glass-card:focus-within {
    outline: 3px solid #8b5cf6;
    outline-offset: 4px;
    box-shadow: 
        0 0 0 6px rgba(139, 92, 246, 0.1),
        0 20px 25px -5px rgba(0, 0, 0, 0.1);
}


/* ============================================
   3. KEYBOARD NAVIGATION ENHANCEMENTS
   ============================================ */

/* Visible focus for keyboard users only */
.js-focus-visible :focus:not(.focus-visible) {
    outline: none;
    box-shadow: none;
}

.js-focus-visible .focus-visible {
    outline: 3px solid #6366f1;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* Tab Panel Focus */
[role="tabpanel"]:focus {
    outline: 2px dashed #6366f1;
    outline-offset: 4px;
}

/* Menu Items */
[role="menu"] [role="menuitem"]:focus,
[role="menubar"] [role="menuitem"]:focus {
    background-color: rgba(99, 102, 241, 0.1);
    outline: 2px solid #6366f1;
    outline-offset: -2px;
}

/* Mobile Menu Focus States */
.mobile-menu-toggle:focus {
    outline: 3px solid #ec4899;
    outline-offset: 4px;
    box-shadow: 0 0 0 6px rgba(236, 72, 153, 0.1);
}

.mobile-menu a:focus {
    background-color: rgba(99, 102, 241, 0.1);
    outline: 2px solid #6366f1;
    outline-offset: -2px;
    border-radius: 0.5rem;
}


/* ============================================
   4. SCREEN READER SUPPORT
   ============================================ */

/* Screen Reader Only Text */
.sr-only,
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sr-only-focusable:focus,
.screen-reader-text:focus {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    padding: 1rem;
    background-color: #6366f1;
    color: #ffffff;
    font-size: 1rem;
    border-radius: 0.375rem;
    z-index: 100000;
}


/* ============================================
   5. HIGH CONTRAST MODE SUPPORT
   ============================================ */

/* Windows High Contrast Mode */
@media (prefers-contrast: high) {
    a:focus,
    button:focus,
    input:focus,
    textarea:focus,
    select:focus {
        outline: 4px solid;
        outline-offset: 3px;
    }
    
    .skip-link:focus {
        outline: 4px solid;
    }
}


/* ============================================
   6. REDUCED MOTION SUPPORT
   ============================================ */

/* Respect user's motion preferences */
@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;
    }
    
    /* Keep focus indicators animated */
    *:focus {
        transition: outline-offset 0s, box-shadow 0s;
    }
}


/* ============================================
   7. FOCUS VISIBLE POLYFILL SUPPORT
   ============================================ */

/* For browsers that don't support :focus-visible */
.js-focus-visible :focus:not([data-focus-visible-added]) {
    outline: none;
    box-shadow: none;
}

.js-focus-visible [data-focus-visible-added] {
    outline: 3px solid #6366f1;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}


/* ============================================
   8. INTERACTIVE ELEMENT STATES
   ============================================ */

/* Disabled State */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled,
[aria-disabled="true"] {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

button:disabled:focus,
input:disabled:focus,
select:disabled:focus,
textarea:disabled:focus {
    outline: 2px dashed #9ca3af;
    outline-offset: 2px;
}

/* Active/Pressed State */
[aria-pressed="true"],
[aria-expanded="true"] {
    background-color: rgba(99, 102, 241, 0.1);
    border-color: #6366f1;
}


/* ============================================
   9. LINK UNDERLINES FOR ACCESSIBILITY
   ============================================ */

/* Ensure links in text content are underlined */
.entry-content a:not(.wp-block-button__link),
.wp-block-post-content a:not(.wp-block-button__link),
article a:not(.wp-block-button__link) {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.entry-content a:hover:not(.wp-block-button__link),
.wp-block-post-content a:hover:not(.wp-block-button__link),
article a:hover:not(.wp-block-button__link) {
    text-decoration-thickness: 2px;
}

.entry-content a:focus:not(.wp-block-button__link),
.wp-block-post-content a:focus:not(.wp-block-button__link),
article a:focus:not(.wp-block-button__link) {
    text-decoration-thickness: 2px;
    outline: 3px solid #6366f1;
    outline-offset: 2px;
}


/* ============================================
   10. BUTTON & INTERACTIVE SIZE
   ============================================ */

/* Ensure minimum touch target size (44x44px per WCAG) */
button,
.wp-block-button__link,
input[type="submit"],
input[type="button"],
a.button {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem 1.5rem;
}

/* Icon-only buttons */
button[aria-label]:not(:has(text)),
.icon-button {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem;
}


/* ============================================
   11. FORM VALIDATION & ERROR STATES
   ============================================ */

/* Error State */
input:invalid:not(:focus),
textarea:invalid:not(:focus),
select:invalid:not(:focus),
[aria-invalid="true"] {
    border-color: #dc2626;
}

input:invalid:focus,
textarea:invalid:focus,
select:invalid:focus,
[aria-invalid="true"]:focus {
    outline-color: #dc2626;
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.1);
}

/* Success State */
input:valid,
textarea:valid,
select:valid,
[aria-invalid="false"] {
    border-color: #10b981;
}

.error-message,
[role="alert"].error {
    color: #dc2626;
    font-weight: 600;
    padding: 0.5rem;
    border-left: 4px solid #dc2626;
    background-color: rgba(220, 38, 38, 0.05);
    margin-top: 0.5rem;
}


/* ============================================
   12. LOADING & BUSY STATES
   ============================================ */

[aria-busy="true"] {
    opacity: 0.6;
    pointer-events: none;
    cursor: wait;
}

[aria-busy="true"]::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid rgba(99, 102, 241, 0.3);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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


/* ============================================
   13. MODAL & DIALOG ACCESSIBILITY
   ============================================ */

[role="dialog"],
[role="alertdialog"],
.modal {
    outline: none;
}

[role="dialog"]:focus,
[role="alertdialog"]:focus,
.modal:focus {
    outline: 3px solid #6366f1;
    outline-offset: -3px;
}

/* Modal Overlay */
.modal-overlay {
    background-color: rgba(15, 23, 41, 0.75);
}

/* Focus trap within modal */
.modal-open body > *:not(.modal-overlay):not(.modal) {
    filter: blur(2px);
    pointer-events: none;
}


/* ============================================
   14. TOOLTIP ACCESSIBILITY
   ============================================ */

[role="tooltip"] {
    position: absolute;
    z-index: 1000;
    padding: 0.5rem 0.75rem;
    background-color: #0f1729;
    color: #ffffff;
    font-size: 0.875rem;
    border-radius: 0.375rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-width: 250px;
}

[aria-describedby]:focus ~ [role="tooltip"],
[aria-describedby]:hover ~ [role="tooltip"] {
    opacity: 1;
    visibility: visible;
}


/* ============================================
   15. RESPONSIVE FOCUS INDICATORS
   ============================================ */

/* Mobile Devices - Larger touch targets */
@media (max-width: 782px) {
    button,
    .wp-block-button__link,
    input[type="submit"],
    a.button {
        min-height: 48px;
        min-width: 48px;
        padding: 1rem 1.75rem;
    }
    
    /* Mobile menu items */
    .mobile-menu a {
        min-height: 48px;
        padding: 1rem 1.5rem;
    }
}

/* Tablet & Desktop */
@media (min-width: 783px) {
    /* Keyboard users get more visible focus */
    .keyboard-user *:focus {
        outline-width: 4px;
        outline-offset: 3px;
    }
}


/* ============================================
   16. PRINT STYLES FOR ACCESSIBILITY
   ============================================ */

@media print {
    .skip-link,
    .mobile-menu-toggle,
    nav,
    .cookie-consent-banner {
        display: none;
    }
    
    a[href^="http"]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #4a5578;
    }
}
