/**
 * MYBOS Accessibility Improvements
 * Enhances keyboard navigation, focus states, and screen reader support
 */

/* ========================================
   1. SKIP LINKS
   ======================================== */

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #0a1628;
    color: #d4af37;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    font-weight: 600;
    border-radius: 0 0 4px 0;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #d4af37;
    outline-offset: 2px;
}

/* ========================================
   2. FOCUS STATES
   ======================================== */

/* High-contrast focus indicator for all interactive elements */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 3px solid #d4af37 !important;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.2);
}

/* Remove default browser outline */
*:focus {
    outline: none;
}

/* Button focus states */
button:focus-visible,
.btn:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid #d4af37;
    outline-offset: 3px;
}

/* Form input focus improvements */
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: #0066cc;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
    outline: 2px solid #0066cc;
    outline-offset: 1px;
}

/* Checkbox and radio focus */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

/* Link focus within text */
a:focus {
    background-color: rgba(212, 175, 55, 0.1);
    text-decoration: underline;
    text-decoration-thickness: 2px;
}

/* ========================================
   3. KEYBOARD NAVIGATION
   ======================================== */

/* Visible focus for keyboard users only */
.js-focus-visible :focus:not(.focus-visible) {
    outline: none;
    box-shadow: none;
}

.js-focus-visible .focus-visible {
    outline: 3px solid #d4af37;
    outline-offset: 2px;
}

/* Tab order indicator */
[tabindex="-1"]:focus {
    outline: none;
}

/* Navigation skip to main content */
#main-content:focus {
    outline: none;
}

/* ========================================
   4. SCREEN READER IMPROVEMENTS
   ======================================== */

/* Visually hidden but accessible to 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;
}

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

/* Hide purely decorative elements from screen readers */
.aria-hidden {
    aria-hidden: true;
}

/* ========================================
   5. FORM ACCESSIBILITY
   ======================================== */

/* Required field indicators */
.required {
    color: #ef4444;
    font-weight: bold;
}

.required::after {
    content: " (required)";
    font-size: 0;
}

/* Error messages should be clearly associated */
.form-error {
    color: #ef4444;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-error::before {
    content: "⚠";
    font-size: 1rem;
}

/* Field with error state */
.form-input.error,
.form-select.error,
.form-textarea.error {
    border-color: #ef4444;
    background-color: #fef2f2;
}

.form-input.error:focus,
.form-select.error:focus,
.form-textarea.error:focus {
    outline-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* Success state */
.form-input.success,
.form-select.success,
.form-textarea.success {
    border-color: #10b981;
    background-color: #f0fdf4;
}

/* ========================================
   6. COLOR CONTRAST IMPROVEMENTS
   ======================================== */

/* Ensure minimum 4.5:1 contrast for normal text */
.text-gray-500 {
    color: #6b7280 !important; /* 4.54:1 on white */
}

.text-gray-600 {
    color: #4b5563 !important; /* 7.73:1 on white */
}

/* Link contrast */
a {
    color: #0066cc; /* 6.34:1 on white */
}

a:hover {
    color: #004999; /* 9.48:1 on white */
}

/* Button text contrast */
.bg-primary,
.bg-secondary {
    color: #ffffff !important; /* Ensure white text on dark backgrounds */
}

/* Placeholder text should meet contrast requirements */
::placeholder {
    color: #6b7280;
    opacity: 1;
}

/* ========================================
   7. INTERACTIVE ELEMENT STATES
   ======================================== */

/* Disabled state should be clearly indicated */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled,
[aria-disabled="true"] {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #f3f4f6;
    color: #9ca3af;
}

/* Hover states for mouse users */
@media (hover: hover) {
    a:hover {
        text-decoration: underline;
        text-decoration-thickness: 2px;
    }

    button:hover:not(:disabled) {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}

/* Active/pressed state */
button:active:not(:disabled) {
    transform: translateY(0);
}

/* ========================================
   8. LIVE REGIONS & ALERTS
   ======================================== */

/* Alert/notification styles */
[role="alert"],
[role="status"],
.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    border-left: 4px solid;
}

.alert-success {
    background: #d1fae5;
    border-color: #10b981;
    color: #065f46; /* 7.84:1 contrast */
}

.alert-error {
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b; /* 8.59:1 contrast */
}

.alert-info {
    background: #dbeafe;
    border-color: #3b82f6;
    color: #1e3a8a; /* 11.35:1 contrast */
}

.alert-warning {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #78350f; /* 8.31:1 contrast */
}

/* ========================================
   9. LOADING STATES
   ======================================== */

/* Loading spinner for screen readers */
.loading {
    position: relative;
}

.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #d4af37;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========================================
   10. MODAL/DIALOG ACCESSIBILITY
   ======================================== */

/* Modal backdrop */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 9998;
}

/* Modal container */
[role="dialog"],
[role="alertdialog"] {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 0.75rem;
    padding: 2rem;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 9999;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

/* Modal close button */
.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.375rem;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: #f3f4f6;
}

.modal-close:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

/* ========================================
   11. TABLE ACCESSIBILITY
   ======================================== */

/* Ensure table headers are clearly defined */
table th {
    font-weight: 600;
    text-align: left;
    background: #f3f4f6;
    padding: 0.75rem;
}

table td {
    padding: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
}

/* Highlight row on focus */
table tr:focus-within {
    background: #f9fafb;
    outline: 2px solid #0066cc;
    outline-offset: -2px;
}

/* ========================================
   12. MOBILE TOUCH TARGETS
   ======================================== */

/* Minimum 44x44px touch targets (WCAG 2.5.5 Level AAA) */
@media (max-width: 768px) {
    button,
    a,
    input[type="checkbox"],
    input[type="radio"],
    select {
        min-height: 44px;
        min-width: 44px;
    }

    /* Exception for inline links within text */
    p a,
    li a {
        min-height: auto;
        min-width: auto;
        display: inline;
        padding: 0.25rem 0.125rem;
    }
}

/* ========================================
   13. 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;
    }
}

/* ========================================
   14. HIGH CONTRAST MODE
   ======================================== */

/* Windows High Contrast Mode support */
@media (prefers-contrast: high) {
    button,
    a,
    input,
    select,
    textarea {
        border: 2px solid;
    }

    .alert {
        border-width: 3px;
    }
}

/* ========================================
   15. PRINT ACCESSIBILITY
   ======================================== */

@media print {
    /* Hide non-essential elements */
    .skip-link,
    nav,
    footer,
    .modal-backdrop {
        display: none;
    }

    /* Ensure links are visible */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.875em;
        color: #4b5563;
    }

    /* Don't show links for anchor or JavaScript links */
    a[href^="#"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }
}
