/* Accessibility Enhancements - WCAG AA Compliance */

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --color-primary: #0056B3;
        --color-navy: #000000;
        --color-neutral-40: #000000;
        --color-neutral-20: #000000;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}

/* Reduced Motion Support */
@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;
    }
}

/* Focus Visible - Enhanced for Keyboard Navigation */
*:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
}

/* Skip Links */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--color-primary);
    color: var(--color-neutral-90);
    padding: var(--space-3) var(--space-5);
    z-index: var(--z-tooltip);
    text-decoration: none;
    font-weight: var(--font-weight-semibold);
    border-radius: 0 0 var(--radius-md) 0;
}

.skip-link:focus {
    top: 0;
    left: 0;
}

/* ARIA Live Regions */
[role="status"],
[role="alert"],
[aria-live] {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

[aria-live="polite"]:not(:empty),
[aria-live="assertive"]:not(:empty) {
    position: static;
    left: auto;
    width: auto;
    height: auto;
    overflow: visible;
}

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Ensure minimum touch target sizes (WCAG 2.5.5) */
button,
a,
input[type="button"],
input[type="submit"],
input[type="reset"],
.btn {
    min-height: 44px;
    min-width: 44px;
}

/* Ensure sufficient color contrast */
.text-muted {
    color: var(--color-neutral-40);
}

/* Ensure form labels are always visible */
.form-label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: var(--font-weight-medium);
}

/* Error states for forms */
.form-input:invalid:not(:focus):not(:placeholder-shown) {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px var(--color-danger-light);
}

.form-input:invalid:not(:focus):not(:placeholder-shown) + .form-error {
    display: block;
    color: var(--color-danger);
    font-size: var(--font-size-small);
    margin-top: var(--space-2);
}

.form-error {
    display: none;
}

/* Loading states with accessible text */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--color-neutral-60);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-spinner::after {
    content: "Loading...";
    position: absolute;
    left: -10000px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Ensure images have alt text (visual indicator in dev) */
img:not([alt]) {
    outline: 2px dashed var(--color-danger);
}

img[alt=""] {
    outline: 2px dashed var(--color-warning);
}

/* Link focus states */
a:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    text-decoration: underline;
}

/* Button focus states */
button:focus-visible,
.btn:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
}

/* Ensure sufficient spacing for readability */
p, li {
    line-height: 1.6;
    margin-bottom: var(--space-4);
}

/* Heading hierarchy */
h1 + h2,
h2 + h3,
h3 + h4 {
    margin-top: var(--space-6);
}

/* Ensure tables are accessible */
table {
    border-collapse: collapse;
    width: 100%;
}

table th {
    text-align: left;
    font-weight: var(--font-weight-semibold);
    padding: var(--space-3);
    background-color: var(--color-neutral-70);
}

table td {
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-neutral-60);
}

table caption {
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-4);
    text-align: left;
}

/* Ensure modals are accessible */
[role="dialog"] {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: var(--z-modal);
    background: var(--color-neutral-90);
    padding: var(--space-6);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
}

[role="dialog"]:focus {
    outline: none;
}

/* Modal backdrop */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal-backdrop);
}

/* Ensure dropdowns are keyboard accessible */
[role="menu"],
[role="listbox"] {
    list-style: none;
    padding: 0;
    margin: 0;
}

[role="menuitem"],
[role="option"] {
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
}

[role="menuitem"]:hover,
[role="menuitem"]:focus,
[role="option"]:hover,
[role="option"]:focus {
    background-color: var(--color-primary-50);
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

/* Ensure landmarks are properly identified */
main[role="main"] {
    min-height: 50vh;
}

/* Print accessibility */
@media print {
    a[href^="http"]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    .no-print {
        display: none !important;
    }
}

