/**
 * Accessibility & ARIA Improvements
 * Addresses AIdevTeam findings for better screen reader support
 */

/* 1. Skip to Content Links */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #0F75BD;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 9999;
    border-radius: 0 0 4px 4px;
    font-weight: bold;
}

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

/* 2. Focus Indicators for All Interactive Elements */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[role="button"]:focus,
[role="link"]:focus,
[role="menuitem"]:focus,
[role="tab"]:focus,
[tabindex]:focus {
    outline: 3px solid #0F75BD !important;
    outline-offset: 2px !important;
    z-index: 1;
}

/* High contrast focus indicators */
@media (prefers-contrast: high) {
    *:focus {
        outline: 4px solid #000 !important;
        outline-offset: 3px !important;
        box-shadow: 0 0 0 2px #fff, 0 0 0 6px #000 !important;
    }
}

/* 3. Screen Reader Only Content */
.sr-only,
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.sr-only-focusable:focus,
.visually-hidden-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: inherit !important;
    margin: inherit !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* 4. Button Accessibility Improvements */
.btn,
button,
[role="button"] {
    /* Ensure buttons have proper accessible names */
    min-width: 44px !important;
    min-height: 44px !important;
}

/* Add visual indicator for buttons with only icons */
.btn[aria-label]:not(:has(span, .btn-text))::after {
    content: "";
    position: absolute;
    top: -2px;
    right: -2px;
    width: 6px;
    height: 6px;
    background: #F72C93;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s;
}

.btn[aria-label]:not(:has(span, .btn-text)):hover::after {
    opacity: 1;
}

/* 5. Form Accessibility */
.form-group {
    position: relative;
}

/* Ensure all inputs have proper labels */
input:not([aria-label]):not([aria-labelledby]):not([id]) {
    border: 2px solid #dc3545 !important;
}

input:not([aria-label]):not([aria-labelledby]):not([id])::after {
    content: "Missing label - accessibility issue";
    position: absolute;
    bottom: -20px;
    left: 0;
    color: #dc3545;
    font-size: 12px;
    font-weight: bold;
}

/* Required field indicators */
.required::after,
[required]::after,
[aria-required="true"]::after {
    content: " *";
    color: #dc3545;
    font-weight: bold;
}

/* Error message styling */
.invalid-feedback,
.field-error,
[role="alert"] {
    color: #dc3545 !important;
    font-weight: bold !important;
    background: #f8d7da !important;
    padding: 0.375rem 0.75rem !important;
    border-radius: 0.375rem !important;
    border: 1px solid #f1aeb5 !important;
    margin-top: 0.25rem !important;
}

/* 6. Navigation Accessibility */
.navbar-nav .nav-link {
    position: relative;
}

/* Add keyboard navigation indicators */
.navbar-nav .nav-link:focus::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 117, 189, 0.1);
    border-radius: 4px;
    z-index: -1;
}

/* Dropdown accessibility */
.dropdown-toggle::after {
    /* Ensure dropdown arrows are visible */
    border: none;
    content: "▼";
    font-size: 0.75em;
    margin-left: 0.5rem;
}

.dropdown-menu {
    /* Better contrast for dropdown menus */
    border: 2px solid #adb5bd !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
}

.dropdown-item:focus,
.dropdown-item:hover {
    background-color: #0F75BD !important;
    color: #fff !important;
}

/* 7. Modal Accessibility */
.modal[aria-modal="true"] {
    /* Ensure modals trap focus */
    position: fixed;
    z-index: 1050;
}

.modal-backdrop {
    /* Stronger backdrop for better visibility */
    background-color: rgba(0, 0, 0, 0.7) !important;
}

.modal-header .btn-close {
    /* Larger close button for better accessibility */
    width: 44px !important;
    height: 44px !important;
    opacity: 1 !important;
    background-image: none !important;
}

.modal-header .btn-close::before {
    content: "✕";
    font-size: 24px;
    font-weight: bold;
    color: #6c757d;
}

.modal-header .btn-close:hover::before {
    color: #000;
}

/* 8. Table Accessibility */
table {
    /* Ensure tables have proper structure */
    border-collapse: collapse !important;
    width: 100% !important;
}

th {
    /* Ensure table headers are properly styled */
    background-color: #f8f9fa !important;
    font-weight: bold !important;
    text-align: left !important;
    padding: 0.75rem !important;
    border: 1px solid #adb5bd !important;
}

td {
    padding: 0.75rem !important;
    border: 1px solid #dee2e6 !important;
}

/* Add scope indicators for complex tables */
th[scope="col"]::before {
    content: "📊 ";
    opacity: 0.7;
}

th[scope="row"]::before {
    content: "📋 ";
    opacity: 0.7;
}

/* 9. Image Accessibility */
img:not([alt]) {
    /* Highlight images without alt text */
    border: 3px solid #dc3545 !important;
    outline: 3px solid #fff !important;
}

img:not([alt])::after {
    content: "Missing alt text";
    position: absolute;
    background: #dc3545;
    color: white;
    padding: 2px 4px;
    font-size: 12px;
    font-weight: bold;
    z-index: 10;
}

/* Decorative images */
img[alt=""],
img[role="presentation"] {
    border: none !important;
    outline: none !important;
}

/* 10. Link Accessibility */
a:not([href]) {
    /* Highlight links without href */
    background: #fff3cd !important;
    border: 1px solid #ffc107 !important;
    padding: 2px 4px !important;
}

/* External link indicators */
a[href^="http"]:not([href*="localhost"]):not([href*="dnaromance.com"]):not([href*="datemetrix.com"])::after {
    content: " ↗";
    font-size: 0.8em;
    color: #6c757d;
}

/* 11. Card Accessibility */
.card {
    /* Better contrast for cards */
    border: 1px solid #adb5bd !important;
}

.card[role="button"],
.card[tabindex] {
    /* Clickable cards */
    cursor: pointer !important;
    transition: all 0.2s ease !important;
}

.card[role="button"]:hover,
.card[tabindex]:hover {
    border-color: #0F75BD !important;
    box-shadow: 0 4px 8px rgba(15, 117, 189, 0.2) !important;
}

/* 12. Progress and Status Indicators */
.progress {
    /* Better visibility for progress bars */
    border: 1px solid #adb5bd !important;
    background-color: #f8f9fa !important;
}

.progress-bar {
    /* Ensure progress text is visible */
    color: #000 !important;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8) !important;
    font-weight: bold !important;
}

/* 13. Toast and Alert Accessibility */
.alert {
    /* Stronger borders for alerts */
    border-width: 2px !important;
    font-weight: 500 !important;
}

.alert[role="alert"] {
    /* Ensure alerts are announced */
    position: relative;
}

.alert[role="alert"]::before {
    content: "⚠ ";
    font-weight: bold;
    font-size: 1.2em;
}

.alert-success[role="alert"]::before {
    content: "✓ ";
    color: #198754;
}

.alert-danger[role="alert"]::before {
    content: "✗ ";
    color: #dc3545;
}

.alert-info[role="alert"]::before {
    content: "ℹ ";
    color: #0dcaf0;
}

/* 14. Loading States */
.loading,
[aria-busy="true"] {
    position: relative;
    pointer-events: none;
}

.loading::after,
[aria-busy="true"]::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top: 2px solid #0F75BD;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 15. Language and Region */
[lang]:not([lang="en"]),
[lang]:not([lang="en-US"]) {
    /* Indicate content in other languages */
    font-style: italic;
}

[lang]:not([lang="en"])::before,
[lang]:not([lang="en-US"])::before {
    content: attr(lang) ": ";
    font-size: 0.8em;
    color: #6c757d;
    font-style: normal;
    text-transform: uppercase;
}

/* 16. Print Accessibility */
@media print {
    .sr-only {
        position: static !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
        clip: auto !important;
        white-space: normal !important;
    }
    
    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #000;
    }
    
    .skip-link {
        display: none;
    }
}

/* 17. Motion Preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .loading::after,
    [aria-busy="true"]::after {
        animation: none;
        border: 2px solid #0F75BD;
    }
}

/* 18. High Contrast Mode */
@media (prefers-contrast: high) {
    .card,
    .btn,
    .form-control,
    .alert {
        border-width: 3px !important;
    }
    
    .text-muted {
        color: #000 !important;
    }
    
    a {
        text-decoration: underline !important;
        text-decoration-thickness: 2px !important;
    }
}