/**
 * Comprehensive Accessibility Styles for WCAG 2.1 AA Compliance
 * This stylesheet provides visual focus indicators, screen reader utilities, and accessibility enhancements
 * 
 * @version 1.0
 * @author DNA Romance Development Team
 */

/* ============================================
   Screen Reader Utilities
   ============================================ */

/* Screen reader only content - Bootstrap 5 compatible */
.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;
}

/* Focusable screen reader content */
.sr-only-focusable,
.visually-hidden-focusable {
    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:active,
.sr-only-focusable:focus,
.visually-hidden-focusable:active,
.visually-hidden-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* ============================================
   Skip Links
   ============================================ */

.aria-skip-links {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
    width: 100%;
}

.aria-skip-link {
    position: absolute;
    left: -9999px;
    z-index: 10000;
    padding: 0.75rem 1.5rem;
    background-color: #0F75BD;
    color: #FFFFFF;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 0.25rem 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: none;
}

.aria-skip-link:focus,
.aria-skip-link:active {
    position: absolute;
    left: 0;
    top: 0;
    outline: 3px solid #FFFFFF;
    outline-offset: -3px;
}

.aria-skip-link:hover {
    background-color: #0D5F96;
    color: #FFFFFF;
}

/* ============================================
   Focus Indicators
   ============================================ */

/* Remove default outline for mouse users, keep for keyboard */
body:not(.using-mouse) *:focus {
    outline: 3px solid #0F75BD !important;
    outline-offset: 2px !important;
}

body.using-mouse *:focus {
    outline: none;
}

/* Custom focus styles for specific elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid #0F75BD !important;
    outline-offset: 2px !important;
    transition: outline-offset 0.1s ease-out;
}

/* Form controls focus */
.form-control:focus,
.form-select:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="datetime-local"]:focus,
select:focus,
textarea:focus {
    border-color: #0F75BD;
    box-shadow: 0 0 0 0.2rem rgba(15, 117, 189, 0.25);
    outline: none !important;
}

/* Button focus styles */
.btn:focus,
.btn:focus-visible,
button:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(15, 117, 189, 0.5);
    outline: none !important;
}

/* Primary button focus */
.btn-primary:focus,
.btn-primary:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(15, 117, 189, 0.5);
}

/* Secondary button focus */
.btn-secondary:focus,
.btn-secondary:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(108, 117, 125, 0.5);
}

/* Success button focus */
.btn-success:focus,
.btn-success:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(40, 167, 69, 0.5);
}

/* Danger button focus */
.btn-danger:focus,
.btn-danger:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.5);
}

/* Warning button focus */
.btn-warning:focus,
.btn-warning:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(255, 193, 7, 0.5);
}

/* Info button focus */
.btn-info:focus,
.btn-info:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(23, 162, 184, 0.5);
}

/* Link focus */
a:focus-visible {
    outline: 2px solid #0F75BD;
    outline-offset: 2px;
    text-decoration: underline;
}

/* Card focus */
.card:focus-within {
    box-shadow: 0 0 0 0.25rem rgba(15, 117, 189, 0.25);
}

/* Modal focus */
.modal:focus {
    outline: none !important;
}

.modal-content:focus {
    outline: 3px solid #0F75BD;
    outline-offset: -3px;
}

/* Dropdown focus */
.dropdown-item:focus,
.dropdown-item:focus-visible {
    background-color: #e9ecef;
    outline: 2px solid #0F75BD;
    outline-offset: -2px;
}

/* Navigation focus */
.nav-link:focus,
.nav-link:focus-visible {
    outline: 2px solid #0F75BD;
    outline-offset: 2px;
}

/* Tab focus */
[role="tab"]:focus {
    outline: 2px solid #0F75BD;
    outline-offset: -2px;
    z-index: 1;
}

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

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(15, 117, 189, 0.25);
}

/* Range slider focus */
input[type="range"]:focus {
    outline: 2px solid #0F75BD;
    outline-offset: 2px;
}

/* File input focus */
input[type="file"]:focus-within {
    outline: 2px solid #0F75BD;
    outline-offset: 2px;
}

/* ============================================
   High Contrast Support
   ============================================ */

/* High contrast mode automatic detection and support */
.high-contrast {
    background: white !important;
    color: black !important;
}

.high-contrast * {
    background: white !important;
    color: black !important;
    border-color: black !important;
}

.high-contrast a,
.high-contrast button,
.high-contrast .btn {
    background: white !important;
    color: blue !important;
    border: 2px solid blue !important;
    text-decoration: underline !important;
}

.high-contrast a:focus,
.high-contrast button:focus,
.high-contrast .btn:focus {
    background: black !important;
    color: white !important;
    outline: 3px solid yellow !important;
}

@media (prefers-contrast: high) {
    *:focus {
        outline: 3px solid currentColor !important;
        outline-offset: 3px !important;
    }

    .btn:focus {
        outline: 3px solid currentColor !important;
        outline-offset: 2px !important;
        box-shadow: none !important;
    }

    .form-control:focus {
        outline: 3px solid currentColor !important;
        outline-offset: 0 !important;
        box-shadow: none !important;
    }
    
    /* Enhanced high contrast support for all elements */
    body, html {
        background: white !important;
        color: black !important;
    }
    
    .btn, button {
        border: 2px solid black !important;
        background: white !important;
        color: black !important;
    }
    
    .btn:hover, button:hover {
        background: black !important;
        color: white !important;
    }
    
    input, select, textarea {
        border: 2px solid black !important;
        background: white !important;
        color: black !important;
    }
    
    a {
        color: blue !important;
        text-decoration: underline !important;
    }
    
    a:visited {
        color: purple !important;
    }
}

/* ============================================
   Reduced Motion Support
   ============================================ */

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

    .aria-skip-link {
        transition: none !important;
    }
}

/* ============================================
   Color Contrast Enhancements
   ============================================ */

/* Ensure sufficient contrast for placeholders */
::placeholder {
    color: #6c757d;
    opacity: 1;
}

/* Ensure sufficient contrast for disabled elements */
.form-control:disabled,
.form-control[readonly] {
    background-color: #e9ecef;
    color: #495057;
    opacity: 1;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.65;
}

/* ============================================
   Error States
   ============================================ */

/* Invalid form fields */
.form-control:invalid,
.form-control.is-invalid,
[aria-invalid="true"] {
    border-color: #dc3545;
}

.form-control:invalid:focus,
.form-control.is-invalid:focus,
[aria-invalid="true"]:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.25);
}

/* Error messages */
.invalid-feedback,
.error-message,
[role="alert"] {
    color: #dc3545;
    font-weight: 600;
}

/* ============================================
   Loading States
   ============================================ */

/* Busy states */
[aria-busy="true"] {
    cursor: wait;
}

[aria-busy="true"]::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.7);
    z-index: 1;
}

/* Loading spinner accessibility */
.spinner-border,
.spinner-grow {
    vertical-align: text-bottom;
}

/* ============================================
   Interactive Elements
   ============================================ */

/* Ensure interactive elements are distinguishable */
[role="button"] {
    cursor: pointer;
    user-select: none;
}

[role="button"]:hover {
    text-decoration: underline;
}

/* Expanded/collapsed indicators */
[aria-expanded="true"]::before {
    content: "▼ ";
}

[aria-expanded="false"]::before {
    content: "▶ ";
}

/* Selected states */
[aria-selected="true"] {
    font-weight: 600;
    background-color: #e9ecef;
}

/* Pressed states */
[aria-pressed="true"] {
    background-color: #0F75BD;
    color: white;
}

/* ============================================
   Navigation
   ============================================ */

/* Current page indicator */
[aria-current="page"] {
    font-weight: 600;
    text-decoration: underline;
}

.nav-link[aria-current="page"] {
    background-color: #e9ecef;
    border-radius: 0.25rem;
}

/* Breadcrumb current item */
.breadcrumb-item[aria-current="page"] {
    color: #6c757d;
    font-weight: 600;
}

/* ============================================
   Tables
   ============================================ */

/* Table headers */
th[aria-sort] {
    cursor: pointer;
    user-select: none;
}

th[aria-sort]:hover {
    background-color: #e9ecef;
}

th[aria-sort="ascending"]::after {
    content: " ↑";
}

th[aria-sort="descending"]::after {
    content: " ↓";
}

th[aria-sort="none"]::after {
    content: " ↕";
    opacity: 0.5;
}

/* ============================================
   Modals and Dialogs
   ============================================ */

/* Modal backdrop for screen readers */
.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.5);
}

/* Dialog focus trap indicator */
[role="dialog"][aria-modal="true"] {
    position: relative;
}

/* ============================================
   Forms
   ============================================ */

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

/* Help text styling */
.form-text,
[id^="help-"] {
    color: #6c757d;
    font-size: 0.875rem;
}

/* ============================================
   Tooltips
   ============================================ */

/* Ensure tooltips are readable */
.tooltip {
    font-size: 0.875rem;
    line-height: 1.5;
    max-width: 280px;
}

.tooltip-inner {
    padding: 0.5rem 0.75rem;
}

/* ============================================
   Progress Indicators
   ============================================ */

/* Progress bar enhancements */
.progress {
    background-color: #e9ecef;
    font-size: 0.75rem;
    line-height: 1rem;
}

.progress-bar {
    color: #fff;
    text-align: center;
    white-space: nowrap;
    transition: width 0.6s ease;
}

@media (prefers-reduced-motion: reduce) {
    .progress-bar {
        transition: none;
    }
}

/* ============================================
   Alerts and Notifications
   ============================================ */

/* Alert focus */
.alert:focus {
    outline: 3px solid currentColor;
    outline-offset: 2px;
}

/* Toast notifications */
.toast {
    max-width: 350px;
    font-size: 0.875rem;
}

.toast:focus-within {
    box-shadow: 0 0 0 0.25rem rgba(15, 117, 189, 0.25);
}

/* ============================================
   Images
   ============================================ */

/* Decorative images */
img[alt=""],
img[role="presentation"] {
    user-select: none;
}

/* Image loading states */
img:not([src]),
img[src=""] {
    visibility: hidden;
}

img.loading {
    background: #f0f0f0;
    min-height: 100px;
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    /* Hide screen reader only content in print */
    .sr-only,
    .visually-hidden,
    .aria-skip-links {
        display: none !important;
    }

    /* Show URLs for links */
    a[href^="http"]:after {
        content: " (" attr(href) ")";
    }

    /* Show alt text for images */
    img:after {
        content: " (Image: " attr(alt) ")";
    }

    /* Ensure focus indicators don't print */
    *:focus {
        outline: none !important;
        box-shadow: none !important;
    }
}

/* ============================================
   Dark Mode Support
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* Adjust focus colors for dark mode */
    body:not(.using-mouse) *:focus {
        outline-color: #4dabf7 !important;
    }

    .form-control:focus {
        border-color: #4dabf7;
        box-shadow: 0 0 0 0.2rem rgba(77, 171, 247, 0.25);
    }

    .btn:focus {
        box-shadow: 0 0 0 0.25rem rgba(77, 171, 247, 0.5);
    }

    /* Adjust skip link colors */
    .aria-skip-link {
        background-color: #1971c2;
        color: #ffffff;
    }

    .aria-skip-link:hover {
        background-color: #1864ab;
    }

    /* Adjust selection colors */
    ::selection {
        background-color: #4dabf7;
        color: #000000;
    }
}

/* ============================================
   Custom Component Styles
   ============================================ */

/* Accessible accordions */
.accordion-button:focus {
    z-index: 3;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(15, 117, 189, 0.25);
}

/* Accessible carousels */
.carousel-control-prev:focus,
.carousel-control-next:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.carousel-indicators button:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Accessible badges */
.badge:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Accessible close buttons */
.btn-close:focus {
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(15, 117, 189, 0.25);
    opacity: 1;
}

/* ============================================
   Utility Classes
   ============================================ */

/* Force visible focus */
.focus-visible {
    outline: 3px solid #0F75BD !important;
    outline-offset: 2px !important;
}

/* Remove focus */
.focus-none:focus {
    outline: none !important;
    box-shadow: none !important;
}

/* High contrast borders */
.border-high-contrast {
    border: 2px solid currentColor !important;
}

/* Text spacing for readability */
.text-spacing {
    letter-spacing: 0.12em;
    word-spacing: 0.16em;
    line-height: 1.5;
}

/* Large touch targets */
.touch-target {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Site-Specific Overrides
   ============================================ */

/* DNA Romance specific */
.dnaromance-theme [role="main"]:focus {
    outline-color: #0F75BD;
}

/* DateMetriX specific */
.datemetrix-theme [role="main"]:focus {
    outline-color: #7C4DFF;
}

/* GenePool specific */
.genepool-theme [role="main"]:focus {
    outline-color: #00BCD4;
}

/* WellMatched specific */
.wellmatched-theme [role="main"]:focus {
    outline-color: #4CAF50;
}

/* Gene Recovery specific */
.generecovery-theme [role="main"]:focus {
    outline-color: #FF5722;
}

/* Heritable Health specific */
.heritablehealth-theme [role="main"]:focus {
    outline-color: #009688;
}