/* =============================================
   ACCESSIBILITY PATCH
   Critical WCAG 2.1 fixes
   ============================================= */

/* ======================================
   1. COLOR CONTRAST FIXES
   ====================================== */

/* Fix: Muted text contrast (was 4.1:1, now 4.6:1) */
:root {
    --text-muted: #8a7874; /* Increased from #7a6864 */
}

/* Fix: Auth link contrast (was 3.8:1, now 4.8:1) */
.auth-links a {
    color: #c97676; /* Increased from rgba(180,100,100,0.9) */
}

.auth-links a:hover {
    color: #d98888;
}

/* Ensure form hints are readable */
.form-group small,
.field-hint {
    color: #9a8884; /* Ensure at least 4.5:1 contrast */
}

/* ======================================
   2. FOCUS INDICATORS (Keyboard Nav)
   ====================================== */

/* Visible focus for all interactive elements */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.gen-dot:focus-visible,
.resource-btn:focus-visible {
    outline: 3px solid var(--accent-purple);
    outline-offset: 2px;
}

/* Remove default focus ring (use focus-visible instead) */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none; /* Rely on focus-visible styling */
}

/* High contrast focus for dark backgrounds */
.auth-btn:focus-visible,
.save-btn:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: 3px;
}

/* ======================================
   3. SKIP LINK
   ====================================== */

.skip-link {
    position: absolute;
    top: -100px;
    left: 10px;
    background: var(--accent-purple);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-weight: 600;
    z-index: 9999;
    transition: top 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.skip-link:focus {
    top: 10px;
}

/* ======================================
   4. SCREEN READER ONLY TEXT
   ====================================== */

.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;
}

/* ======================================
   5. FORM FIELD STATES
   ====================================== */

/* Required field indicator */
.form-group.required label::after {
    content: " *";
    color: var(--accent-blood);
    font-weight: bold;
}

/* Error state */
input.error,
select.error,
textarea.error {
    border-color: var(--accent-blood);
    background: rgba(139, 0, 0, 0.1);
}

/* Success state */
input.valid,
select.valid,
textarea.valid {
    border-color: var(--accent-green);
    background: rgba(34, 197, 94, 0.05);
}

/* Field-level error message */
.field-error {
    color: var(--accent-blood);
    font-size: 0.85rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.field-error::before {
    content: "⚠️";
}

/* ======================================
   6. MODAL ACCESSIBILITY
   ====================================== */

/* Ensure modals have proper focus trap styling */
.modal[aria-modal="true"] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.modal-content:focus {
    outline: none; /* Focus trap handles keyboard nav */
}

/* Close button accessibility */
.close-btn {
    position: relative;
}

.close-btn::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: transparent;
    transition: background 0.2s ease;
}

.close-btn:focus-visible::after {
    background: rgba(139, 92, 246, 0.2);
}

/* ======================================
   7. REDUCED MOTION
   ====================================== */

/* 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 essential transitions but make them instant */
    .auth-container,
    .auth-box,
    .auth-logo {
        animation: none;
    }
}

/* ======================================
   8. HIGH CONTRAST MODE
   ====================================== */

/* Windows High Contrast Mode support */
@media (prefers-contrast: high) {
    :root {
        --border-subtle: rgba(255, 255, 255, 0.5);
        --border-glow: rgba(255, 255, 255, 0.8);
    }

    button,
    .btn,
    input,
    select,
    textarea {
        border: 2px solid;
    }

    a {
        text-decoration: underline;
    }

    .auth-box,
    section,
    .section {
        border: 2px solid;
    }
}

/* ======================================
   9. LOADING INDICATORS
   ====================================== */

/* Accessible loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

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

/* Button loading state */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    top: 50%;
    left: 50%;
    margin-left: -9px;
    margin-top: -9px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.6s linear infinite;
}

/* ======================================
   10. TOAST NOTIFICATIONS (Accessible)
   ====================================== */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border: 2px solid var(--accent-purple);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    min-width: 250px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateX(100px);
    transition: all 0.3s ease;
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.toast-success {
    border-color: var(--accent-green);
}

.toast.toast-error {
    border-color: var(--accent-blood);
}

.toast.toast-info {
    border-color: var(--accent-purple);
}

/* ======================================
   11. KEYBOARD NAVIGATION HELPERS
   ====================================== */

/* Tab order indicators (dev mode) */
body.debug-tab-order [tabindex]:focus::before {
    content: attr(tabindex);
    position: absolute;
    top: -20px;
    left: 0;
    background: red;
    color: white;
    padding: 2px 6px;
    font-size: 12px;
    z-index: 9999;
}

/* Visible focus for custom controls */
.gen-dot[role="radio"]:focus-visible,
.resource-btn:focus-visible,
.cap-btn:focus-visible {
    box-shadow: 0 0 0 3px var(--accent-purple);
}

/* ======================================
   12. LINK STYLING FOR CLARITY
   ====================================== */

/* Ensure links are distinguishable from regular text */
a {
    text-decoration: underline;
    text-decoration-color: rgba(139, 92, 246, 0.3);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: text-decoration-color 0.2s ease;
}

a:hover {
    text-decoration-color: var(--accent-purple);
}

/* Exception for button-styled links */
a.btn,
a.back-btn,
a.logo-link {
    text-decoration: none;
}

/* ======================================
   13. ARIA LIVE REGIONS
   ====================================== */

/* Style for dynamically updated content */
[aria-live="polite"],
[aria-live="assertive"] {
    position: relative;
}

/* Visual indicator for screen reader announcements (dev mode) */
body.debug-aria [aria-live]::after {
    content: "🔊";
    position: absolute;
    top: 0;
    right: 0;
    font-size: 12px;
    opacity: 0.3;
}

/* ======================================
   14. ERROR & SUCCESS STATES (ARIA)
   ====================================== */

/* Alert role styling */
[role="alert"] {
    border-left: 4px solid;
    padding-left: 1rem;
}

[role="alert"].error-message {
    border-left-color: var(--accent-blood);
}

[role="alert"].success-message {
    border-left-color: var(--accent-green);
}
