/* ============================================
   WCAG 2.1 AA Accessibility Improvements
   ============================================ */

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: #2563eb;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 9999;
    border-radius: 0 0 4px 0;
    font-weight: 600;
    font-size: 14px;
}

.skip-to-main:focus {
    top: 0;
}

/* Respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Enhanced focus indicators */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Improved color contrast for text */
body {
    color: #e5e7eb;
}

p, li, span {
    color: #e5e7eb;
}

/* Ensure minimum touch target sizes */
button,
a[href],
input[type="button"],
input[type="submit"],
.btn,
[role="button"] {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Form labels - improved contrast */
label {
    color: #e5e7eb;
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
}

label[for] {
    cursor: pointer;
}

/* Form inputs - better accessibility */
input,
textarea,
select {
    min-height: 44px;
    font-size: 16px; /* Prevent zoom on iOS */
    border: 2px solid #475569;
    padding: 12px 16px;
}

input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
}

/* Error states with better contrast */
.error,
.alert-danger,
[aria-invalid="true"] {
    background: rgba(239, 68, 68, 0.12);
    border: 2px solid #ef4444;
    color: #fca5a5;
}

/* Success states */
.success,
.alert-success {
    background: rgba(34, 197, 94, 0.12);
    border: 2px solid #22c55e;
    color: #86efac;
}

/* Icon-only buttons need labels */
[class*="icon"] button,
button i:only-child {
    position: relative;
}

/* Navigation focus indicators */
nav a:focus {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
    border-radius: 4px;
    padding: 4px 8px;
}

/* Heading hierarchy */
h1 {
    font-size: 2.25rem;
    margin-bottom: 1.5rem;
}

h2 {
    font-size: 1.875rem;
    margin-bottom: 1.25rem;
}

h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

h4 {
    font-size: 1.25rem;
    margin-bottom: 0.875rem;
}

h5 {
    font-size: 1.125rem;
    margin-bottom: 0.75rem;
}

h6 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

/* Links - ensure proper contrast */
a {
    color: #60a5fa;
    text-decoration: underline;
}

a:visited {
    color: #a78bfa;
}

a:focus,
a:hover {
    text-decoration: underline;
    outline: none;
}

/* Table accessibility */
table {
    border-collapse: collapse;
}

th {
    text-align: left;
    font-weight: 700;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid #475569;
    padding: 12px;
    color: #e5e7eb;
}

td {
    border: 1px solid #475569;
    padding: 12px;
}

/* Image alt text - ensure visible for debugging */
img[alt=""],
img:not([alt]) {
    border: 2px solid #ef4444;
}

/* Lists should use proper semantic tags */
ul, ol {
    margin-left: 1.5em;
    margin-bottom: 1em;
}

/* Live region announcements */
[aria-live] {
    position: relative;
}

/* Focus visible for better keyboard navigation */
:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

/* Ensure placeholder text doesn't replace labels */
input::placeholder,
textarea::placeholder {
    opacity: 0.7;
    color: #9ca3af;
    font-style: italic;
}

/* Spinner and loading indicators need aria-labels */
.spinner,
.loader {
    position: relative;
}

/* Carousel - pause animation on focus or hover */
[role="region"] {
    position: relative;
}

.carousel-track:focus-within,
.carousel-track:hover {
    animation-play-state: paused;
}

/* Utility classes for screen readers */
.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;
}

.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Icons should have aria-hidden when decorative */
[aria-hidden="true"] {
    pointer-events: none;
}

/* Focus management for modals and overlays */
[role="dialog"] {
    position: relative;
    z-index: 1000;
}

[role="dialog"]:focus {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

/* Color indicators need text labels too */
.status-indicator::after {
    content: attr(data-status);
    margin-left: 8px;
    font-size: 0.875rem;
}

/* Improved form error messages */
.form-error {
    color: #fca5a5;
    font-size: 0.875rem;
    margin-top: 4px;
    display: block;
}

.form-error::before {
    content: "Error: ";
    font-weight: 700;
}

/* Buttons with better states */
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

button:active:not(:disabled) {
    transform: translateY(0px);
}

/* Improved button focus states */
button:focus:not(:focus-visible) {
    outline: none;
}

button:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

/* Link focus states */
a:focus:not(:focus-visible) {
    outline: none;
}

a:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Cards and containers - clear hierarchy */
[role="main"] {
    position: relative;
}

article {
    margin-bottom: 2rem;
}

section {
    margin-bottom: 2rem;
}

/* Responsive text sizing */
@media (max-width: 768px) {
    body {
        font-size: 16px; /* Prevent iOS zoom */
    }

    button,
    input,
    textarea,
    select {
        font-size: 16px; /* Prevent iOS zoom */
    }
}

/* High contrast mode support */
@media (prefers-contrast: more) {
    body {
        color: #ffffff;
    }

    a {
        color: #0ea5e9;
        text-decoration: underline;
        font-weight: 600;
    }

    button,
    input,
    textarea,
    select {
        border-width: 2px;
        font-weight: 600;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: #000000;
        color: #ffffff;
    }

    a {
        color: #60a5fa;
    }

    input,
    textarea,
    select {
        background: #111827;
        color: #f3f4f6;
        border-color: #374151;
    }

    input:focus,
    textarea:focus,
    select:focus {
        background: #1f2937;
        border-color: #3b82f6;
    }
}
