/**
 * AKA Theme V2 - Accessibility Styles
 * WCAG 2.1 AA compliant accessibility enhancements
 * Requirements: 8.2, 8.3, 8.4
 */

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

.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;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Allow screen reader text to be focusable */
.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: inherit !important;
    margin: inherit !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* ============================================
   Skip Links
   ============================================ */

.skip-link,
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 6px;
    z-index: 100000;
    padding: 12px 24px;
    background-color: var(--kurdish-green);
    color: var(--kurdish-white);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: top 0.3s ease;
}

.skip-link:focus,
.skip-to-content:focus {
    top: 0;
    outline: 3px solid var(--kurdish-yellow);
    outline-offset: 2px;
}

/* Multiple skip links container */
.skip-links {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100000;
}

.skip-links a {
    position: absolute;
    top: -100px;
    left: 6px;
    padding: 12px 24px;
    background-color: var(--kurdish-green);
    color: var(--kurdish-white);
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    transition: top 0.3s ease;
}

.skip-links a:focus {
    top: 0;
    outline: 3px solid var(--kurdish-yellow);
    outline-offset: 2px;
}

.skip-links a:nth-child(2):focus {
    left: 180px;
}

.skip-links a:nth-child(3):focus {
    left: 360px;
}

/* ============================================
   Focus Styles
   ============================================ */

/* Default focus outline */
*:focus {
    outline: 2px solid var(--kurdish-yellow);
    outline-offset: 2px;
}

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

/* Enhanced focus for keyboard users */
*:focus-visible {
    outline: 3px solid var(--kurdish-yellow);
    outline-offset: 3px;
}

/* Focus styles for interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid var(--kurdish-yellow);
    outline-offset: 3px;
    border-radius: 4px;
}

/* Focus styles for buttons */
.wp-block-button__link:focus-visible,
button:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid var(--kurdish-yellow);
    outline-offset: 3px;
    box-shadow: 0 0 0 6px rgba(244, 163, 0, 0.3);
}

/* Focus styles for form inputs */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--kurdish-green);
    outline-offset: 0;
    border-color: var(--kurdish-green);
    box-shadow: 0 0 0 4px rgba(19, 111, 99, 0.2);
}

/* Focus styles for navigation links */
.primary-navigation a:focus-visible,
.mobile-navigation a:focus-visible {
    outline: 3px solid var(--kurdish-yellow);
    outline-offset: 2px;
    background-color: rgba(19, 111, 99, 0.1);
}

/* Focus styles for cards */
.card:focus-within {
    outline: 3px solid var(--kurdish-green);
    outline-offset: 4px;
}

/* ============================================
   Keyboard Navigation Support
   ============================================ */

/* Visible focus indicator for all focusable elements */
[tabindex="0"]:focus-visible {
    outline: 3px solid var(--kurdish-yellow);
    outline-offset: 3px;
}

/* Focus trap indicator */
[aria-modal="true"]:focus-within {
    box-shadow: 0 0 0 4px var(--kurdish-green);
}

/* Dropdown menu keyboard navigation */
.primary-navigation .sub-menu:focus-within,
.primary-navigation .children:focus-within {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Tab order visual indicator */
.tab-order-indicator {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 24px;
    height: 24px;
    background-color: var(--kurdish-red);
    color: var(--kurdish-white);
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    pointer-events: none;
}

/* ============================================
   ARIA States and Properties
   ============================================ */

/* Expanded/collapsed states */
[aria-expanded="false"] + .submenu,
[aria-expanded="false"] + .dropdown-content {
    display: none;
}

[aria-expanded="true"] + .submenu,
[aria-expanded="true"] + .dropdown-content {
    display: block;
}

/* Current page indicator */
[aria-current="page"] {
    font-weight: 700;
    color: var(--kurdish-green);
    position: relative;
}

[aria-current="page"]::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 3px;
    background-color: var(--kurdish-yellow);
    border-radius: 2px;
}

/* Disabled state */
[aria-disabled="true"],
[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

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

/* Busy/loading state */
[aria-busy="true"] {
    cursor: wait;
    opacity: 0.7;
}

[aria-busy="true"]::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 8px;
    border: 2px solid var(--kurdish-green);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Invalid form fields */
[aria-invalid="true"] {
    border-color: var(--kurdish-red) !important;
    box-shadow: 0 0 0 3px rgba(201, 48, 62, 0.2);
}

[aria-invalid="true"]:focus {
    outline-color: var(--kurdish-red);
}

/* Required fields */
[aria-required="true"]::after,
.required::after {
    content: ' *';
    color: var(--kurdish-red);
    font-weight: 700;
}

/* Selected state */
[aria-selected="true"] {
    background-color: rgba(19, 111, 99, 0.1);
    border-color: var(--kurdish-green);
}

/* Pressed state for toggle buttons */
[aria-pressed="true"] {
    background-color: var(--kurdish-green);
    color: var(--kurdish-white);
}

/* ============================================
   Semantic Markup Enhancements
   ============================================ */

/* Main landmark */
main,
[role="main"] {
    display: block;
    outline: none;
}

main:focus {
    outline: none;
}

/* Navigation landmarks */
nav,
[role="navigation"] {
    display: block;
}

/* Complementary content */
aside,
[role="complementary"] {
    display: block;
}

/* Banner (header) */
header,
[role="banner"] {
    display: block;
}

/* Content info (footer) */
footer,
[role="contentinfo"] {
    display: block;
}

/* Search landmark */
[role="search"] {
    display: block;
}

/* Article */
article,
[role="article"] {
    display: block;
}

/* Region with accessible name */
section[aria-labelledby],
section[aria-label],
[role="region"][aria-labelledby],
[role="region"][aria-label] {
    display: block;
}

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

/* Label styling */
label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: var(--aka-slate);
}

/* Associated label and input */
label + input,
label + select,
label + textarea {
    margin-top: 4px;
}

/* Fieldset and legend */
fieldset {
    border: 2px solid var(--aka-light-gray);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

legend {
    font-weight: 600;
    color: var(--kurdish-green);
    padding: 0 8px;
}

/* Error messages */
.error-message,
[role="alert"] {
    color: var(--kurdish-red);
    font-size: 14px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.error-message::before,
[role="alert"]::before {
    content: '⚠';
    font-size: 16px;
}

/* Success messages */
.success-message {
    color: var(--kurdish-green);
    font-size: 14px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.success-message::before {
    content: '✓';
    font-size: 16px;
}

/* Help text */
.help-text,
[aria-describedby] + .description {
    font-size: 13px;
    color: var(--aka-gray);
    margin-top: 4px;
}

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

/* Images without alt text warning (dev mode) */
img:not([alt]) {
    outline: 4px dashed var(--kurdish-red);
}

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

/* Figure and figcaption */
figure {
    margin: 0;
}

figcaption {
    font-size: 14px;
    color: var(--aka-gray);
    margin-top: 8px;
    text-align: center;
}

/* ============================================
   Link Accessibility
   ============================================ */

/* Links must be distinguishable */
a {
    color: var(--kurdish-green);
    text-decoration: underline;
    text-underline-offset: 3px;
}

a:hover {
    color: var(--kurdish-red);
    text-decoration-thickness: 2px;
}

/* External link indicator */
a[target="_blank"]::after,
a[rel*="external"]::after {
    content: ' ↗';
    font-size: 0.8em;
    vertical-align: super;
}

/* Download link indicator */
a[download]::after {
    content: ' ⬇';
    font-size: 0.9em;
}

/* Email link indicator */
a[href^="mailto:"]::before {
    content: '✉ ';
}

/* Phone link indicator */
a[href^="tel:"]::before {
    content: '📞 ';
}

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

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

caption {
    font-weight: 600;
    text-align: left;
    margin-bottom: 8px;
    color: var(--aka-slate);
}

th {
    background-color: var(--aka-light-gray);
    font-weight: 600;
    text-align: left;
    padding: 12px;
    border: 1px solid var(--aka-gray);
}

td {
    padding: 12px;
    border: 1px solid var(--aka-light-gray);
}

/* Row headers */
th[scope="row"] {
    background-color: rgba(19, 111, 99, 0.05);
}

/* Sortable table headers */
th[aria-sort] {
    cursor: pointer;
}

th[aria-sort]::after {
    content: ' ⇅';
    opacity: 0.5;
}

th[aria-sort="ascending"]::after {
    content: ' ↑';
    opacity: 1;
}

th[aria-sort="descending"]::after {
    content: ' ↓';
    opacity: 1;
}

/* ============================================
   Color Contrast Helpers
   ============================================ */

/* High contrast text on dark backgrounds */
.text-on-dark {
    color: var(--kurdish-white);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* High contrast text on light backgrounds */
.text-on-light {
    color: var(--aka-slate);
}

/* Ensure minimum contrast ratio */
.high-contrast {
    color: var(--aka-black);
    background-color: var(--kurdish-white);
}

/* ============================================
   Motion and Animation Accessibility
   ============================================ */

/* 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;
    }
    
    .skip-link,
    .skip-to-content {
        transition: none;
    }
}

/* Pause animations on hover for users who need more time */
@media (prefers-reduced-motion: no-preference) {
    .animated:hover {
        animation-play-state: paused;
    }
}

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

@media (prefers-contrast: high) {
    /* Increase border visibility */
    *:focus-visible {
        outline: 4px solid currentColor !important;
        outline-offset: 4px !important;
    }
    
    /* Ensure buttons are visible */
    button,
    .wp-block-button__link,
    [role="button"] {
        border: 3px solid currentColor !important;
    }
    
    /* Ensure links are visible */
    a {
        text-decoration: underline !important;
        text-decoration-thickness: 2px !important;
    }
    
    /* Ensure form inputs are visible */
    input,
    select,
    textarea {
        border: 3px solid currentColor !important;
    }
    
    /* Ensure cards have visible borders */
    .card {
        border: 3px solid currentColor !important;
    }
}

/* ============================================
   Print Accessibility
   ============================================ */

@media print {
    /* Show URLs for links */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    /* Don't show URLs for internal links */
    a[href^="#"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }
    
    /* Ensure sufficient contrast */
    * {
        color: #000 !important;
        background: #fff !important;
    }
}

/* ============================================
   Live Region Announcements
   ============================================ */

/* Live region for dynamic content updates */
.live-region,
[aria-live] {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Visible live region for important announcements */
.live-region-visible,
[aria-live="assertive"] {
    position: relative;
    left: auto;
    width: auto;
    height: auto;
    overflow: visible;
    padding: 12px 16px;
    background-color: var(--kurdish-yellow);
    color: var(--aka-black);
    border-radius: 8px;
    font-weight: 500;
}

/* Status messages */
[role="status"] {
    padding: 12px 16px;
    background-color: rgba(19, 111, 99, 0.1);
    border-left: 4px solid var(--kurdish-green);
    border-radius: 0 8px 8px 0;
}

/* Alert messages */
[role="alert"] {
    padding: 12px 16px;
    background-color: rgba(201, 48, 62, 0.1);
    border-left: 4px solid var(--kurdish-red);
    border-radius: 0 8px 8px 0;
}
