/**
 * Accessibility Styles
 * WCAG 2.1 Level AA Compliance
 */

/* Skip to main content link for keyboard navigation */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: #f78500;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    border-radius: 0 0 4px 0;
}

.skip-to-main:focus {
    top: 0;
}

/* Focus indicators - WCAG 2.1 requirement */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 3px solid #f78500;
    outline-offset: 2px;
}

/* High contrast focus for better visibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid #f78500;
    outline-offset: 2px;
}

/* Remove default outline but keep focus-visible */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Ensure sufficient color contrast - WCAG AA requires 4.5:1 for normal text */
body {
    color: #111827; /* Dark gray on white = 16.1:1 ratio */
    background: #ffffff;
}

/* Link colors with sufficient contrast */
a {
    color: #120a02; /* EII dark brown - 16.1:1 contrast ratio */
    text-decoration: underline;
}

a:hover {
    color: #f78500; /* EII orange - 4.5:1 contrast ratio */
}

/* Button contrast */
.btn-primary {
    background: #f78500;
    color: #ffffff;
    /* 4.52:1 contrast ratio */
}

.btn-secondary {
    background: #6b7280;
    color: #ffffff;
    /* 4.54:1 contrast ratio */
}

/* Form elements with proper labels */
label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #374151;
}

/* Required field indicator */
.required::after {
    content: " *";
    color: #dc2626;
    font-weight: bold;
}

/* Error messages with sufficient contrast */
.error-message {
    color: #991b1b; /* 7.71:1 contrast ratio */
    background: #fee2e2;
    padding: 8px 12px;
    border-radius: 4px;
    border-left: 4px solid #dc2626;
    margin-top: 5px;
}

/* Success messages */
.success-message {
    color: #e67700; /* EII darker orange - 7.35:1 contrast ratio */
    background: #fff3e0;
    padding: 8px 12px;
    border-radius: 4px;
    border-left: 4px solid #f78500;
    margin-top: 5px;
}

/* Screen reader only content */
.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;
}

/* Screen reader only but focusable */
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Ensure images have alt text - visual indicator for missing alt */
img:not([alt]) {
    border: 3px solid #dc2626;
}

/* Proper heading hierarchy - visual indicators */
h1 {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 1rem;
}

h2 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 0.875rem;
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 0.75rem;
}

h4 {
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 0.625rem;
}

/* Ensure sufficient line height for readability */
p, li, td, th {
    line-height: 1.6;
}

/* Minimum touch target size - WCAG 2.1 requirement (44x44px) */
button,
a.btn,
input[type="submit"],
input[type="button"],
input[type="checkbox"],
input[type="radio"] {
    min-height: 44px;
    min-width: 44px;
}

/* For smaller interactive elements, add padding */
input[type="checkbox"],
input[type="radio"] {
    width: 20px;
    height: 20px;
    margin: 12px; /* Adds to touch target */
}

/* Table accessibility */
table {
    border-collapse: collapse;
    width: 100%;
}

th {
    text-align: left;
    font-weight: 600;
}

/* Caption for tables */
caption {
    font-weight: 600;
    text-align: left;
    padding: 10px 0;
    caption-side: top;
}

/* Form fieldset and legend */
fieldset {
    border: 1px solid #d1d5db;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 6px;
}

legend {
    font-weight: 600;
    padding: 0 10px;
    color: #111827;
}

/* Loading states with ARIA */
[aria-busy="true"] {
    opacity: 0.6;
    pointer-events: none;
}

/* Disabled states */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Alert roles */
[role="alert"] {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
}

[role="alert"][aria-live="assertive"] {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #dc2626;
}

/* Status messages */
[role="status"] {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    background: #fff3e0;
    color: #e67700;
    border-left: 4px solid #f78500;
}

/* Progress indicators */
[role="progressbar"] {
    background: #e5e7eb;
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
}

[role="progressbar"] > div {
    background: #f78500;
    height: 100%;
    transition: width 0.3s ease;
}

/* Modal/Dialog accessibility */
[role="dialog"] {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
}

[role="dialog"] [aria-label] {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 16px;
}

/* Backdrop for modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

/* Navigation landmarks */
nav[aria-label] {
    /* Ensure navigation has proper labels */
}

/* Main content landmark */
main {
    /* Ensure main content is properly marked */
}

/* Complementary content */
aside {
    /* Ensure sidebars are properly marked */
}

/* Text resize support - must work up to 200% */
html {
    font-size: 16px;
}

@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;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    * {
        border-color: currentColor;
    }
    
    button,
    .btn {
        border: 2px solid currentColor;
    }
}

/* Dark mode support (respects user preference) */
@media (prefers-color-scheme: dark) {
    body {
        background: #111827;
        color: #f9fafb;
    }
    
    a {
        color: #f78500;
    }
    
    .btn-primary {
        background: #f78500;
    }
}

/* Ensure form inputs are properly associated with labels */
input:not([id]),
select:not([id]),
textarea:not([id]) {
    /* Visual indicator for inputs without IDs (accessibility issue) */
    border: 2px dashed #dc2626 !important;
}

/* Keyboard navigation indicators */
.keyboard-user *:focus {
    outline: 3px solid #f78500;
    outline-offset: 2px;
}

/* Print styles for accessibility */
@media print {
    .no-print {
        display: none !important;
    }
    
    a[href]::after {
        content: " (" attr(href) ")";
    }
    
    abbr[title]::after {
        content: " (" attr(title) ")";
    }
}
