/**
 * Accessibility Styles
 * Styles for improved accessibility and WCAG compliance
 */

/* ========================================
   SCREEN READER ONLY
   ======================================== */

/**
 * Visually hidden but accessible to screen readers
 * Use for labels, instructions, and content that should only be read
 */
.sr-only,
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/**
 * Make visually hidden element focusable
 */
.sr-only-focusable:focus,
.sr-only-focusable:active,
.visually-hidden-focusable:focus,
.visually-hidden-focusable:active {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ========================================
   SKIP NAVIGATION LINK
   ======================================== */

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary-600, #7c3aed);
    color: white;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 0.5rem 0;
    z-index: 9999;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--color-warning, #f6ad55);
    outline-offset: 3px;
}

/* ========================================
   FOCUS INDICATORS
   ======================================== */

/**
 * Enhanced focus indicators for keyboard navigation
 * Ensures visibility across all interactive elements
 */
*:focus {
    outline: 2px solid var(--color-primary-500, #8b5cf6);
    outline-offset: 2px;
}

/* Remove outline for mouse users, keep for keyboard users */
*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--color-primary-500, #8b5cf6);
    outline-offset: 2px;
}

/* Specific focus styles for different elements */
a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--color-primary-600, #7c3aed);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.2);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-primary-500, #8b5cf6);
    outline-offset: 0;
    border-color: var(--color-primary-500, #8b5cf6);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

/* Card and clickable elements */
.card:focus-visible,
.patient-card:focus-visible,
.pain-zone-card:focus-visible,
.package-card:focus-visible,
.time-slot:focus-visible {
    outline: 3px solid var(--color-primary-600, #7c3aed);
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(139, 92, 246, 0.2);
}

/* ========================================
   HIGH CONTRAST MODE SUPPORT
   ======================================== */

@media (prefers-contrast: high) {
    *:focus-visible {
        outline-width: 3px;
        outline-offset: 3px;
    }

    .btn {
        border: 2px solid currentColor;
    }

    a {
        text-decoration: underline;
    }
}

/* ========================================
   REDUCED MOTION
   ======================================== */

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

    /* Still allow essential transitions for focus indicators */
    *:focus {
        transition: outline-offset 0s;
    }
}

/* ========================================
   FORM ACCESSIBILITY
   ======================================== */

/**
 * Required field indicator
 */
.required-indicator,
.required::after {
    color: var(--color-danger, #fc8181);
    content: ' *';
    font-weight: bold;
    margin-left: 0.25rem;
}

/**
 * Form error states
 */
.is-invalid:focus,
.form-control.is-invalid:focus {
    border-color: var(--color-danger-dark, #f56565);
    box-shadow: 0 0 0 3px rgba(252, 129, 129, 0.25);
}

.invalid-feedback {
    display: none;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--color-danger-dark, #f56565);
}

.is-invalid ~ .invalid-feedback {
    display: block;
}

/* Add icon to validation messages */
.invalid-feedback::before {
    content: '⚠ ';
    font-weight: bold;
}

.valid-feedback::before {
    content: '✓ ';
    font-weight: bold;
}

/* ========================================
   MODAL ACCESSIBILITY
   ======================================== */

/**
 * Ensure modals have proper backdrop
 */
.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.7);
}

/**
 * Modal focus trap indicator
 */
.modal-dialog:focus-within {
    outline: none;
}

.modal-header .btn-close:focus-visible {
    outline: 2px solid white;
    outline-offset: -2px;
}

/* ========================================
   TABLE ACCESSIBILITY
   ======================================== */

/**
 * Screen reader only table caption
 */
table caption.sr-only {
    /* Already handled by .sr-only class */
}

/**
 * Highlight row on focus/hover for better tracking
 */
table tbody tr:hover,
table tbody tr:focus-within {
    background-color: rgba(139, 92, 246, 0.05);
    outline: 2px solid rgba(139, 92, 246, 0.3);
    outline-offset: -2px;
}

/* ========================================
   BUTTON ACCESSIBILITY
   ======================================== */

/**
 * Ensure disabled buttons are clearly indicated
 */
button:disabled,
.btn:disabled,
[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/**
 * Icon-only buttons must have labels
 */
button:not(:has(span:not(.sr-only))):not(:has(text)):empty {
    min-width: 2.5rem;
    min-height: 2.5rem;
}

/* ========================================
   LINK ACCESSIBILITY
   ======================================== */

/**
 * Underline links for better visibility
 */
main a:not(.btn):not(.nav-link):not(.card) {
    text-decoration: underline;
}

main a:not(.btn):not(.nav-link):not(.card):hover {
    text-decoration: none;
}

/**
 * External link indicator
 */
a[target="_blank"]:not(.no-external-icon)::after {
    content: ' ↗';
    font-size: 0.875em;
    vertical-align: super;
}

a[target="_blank"] .sr-only::after {
    content: none;
}

/* ========================================
   PAGINATION ACCESSIBILITY
   ======================================== */

.pagination {
    list-style: none;
}

.page-item.active .page-link {
    font-weight: 700;
}

.page-item.disabled .page-link {
    cursor: not-allowed;
}

/* ========================================
   TOAST/ALERT ACCESSIBILITY
   ======================================== */

/**
 * Ensure alerts have proper roles and are announced
 */
.alert[role="alert"] {
    /* Automatically announced by screen readers */
}

.toast[role="status"] {
    /* Politely announced by screen readers */
}

/* ========================================
   LOADING STATES
   ======================================== */

/**
 * Loading spinner with screen reader text
 */
.spinner-border {
    vertical-align: middle;
}

.spinner-border + .sr-only {
    /* Screen reader will announce loading state */
}

/* ========================================
   DROPDOWN ACCESSIBILITY
   ======================================== */

.dropdown-menu {
    /* Ensure dropdowns are keyboard navigable */
}

.dropdown-item:focus-visible {
    background-color: var(--color-primary-100, #ede9fe);
    outline: 2px solid var(--color-primary-500, #8b5cf6);
    outline-offset: -2px;
}

/* ========================================
   BREADCRUMB ACCESSIBILITY
   ======================================== */

.breadcrumb {
    list-style: none;
}

.breadcrumb-item.active {
    font-weight: 600;
}

/* ========================================
   STATUS INDICATORS
   ======================================== */

/**
 * Ensure status badges have sufficient contrast
 */
.badge {
    font-weight: 600;
    padding: 0.35em 0.65em;
}

/* Add text to complement color for colorblind users */
.badge-success::before,
.bg-success::before {
    content: '✓ ';
}

.badge-danger::before,
.bg-danger::before {
    content: '✗ ';
}

.badge-warning::before,
.bg-warning::before {
    content: '⚠ ';
}

/* ========================================
   PRINT STYLES (Accessibility)
   ======================================== */

@media print {
    /* Show skip links and hidden content in print */
    .sr-only {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        overflow: visible;
        clip: auto;
        white-space: normal;
    }

    /* Remove unnecessary elements from print */
    .skip-link,
    .sidebar,
    button,
    .btn {
        display: none;
    }

    /* Ensure good contrast for printing */
    body {
        background: white;
        color: black;
    }

    a {
        text-decoration: underline;
    }

    /* Show URLs for links */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.875em;
    }
}

/* ========================================
   DARK MODE SUPPORT (Future)
   ======================================== */

@media (prefers-color-scheme: dark) {
    /* Dark mode specific accessibility adjustments */
    .skip-link {
        background: var(--color-primary-400, #a78bfa);
    }

    .skip-link:focus {
        outline-color: var(--color-warning-light, #fbd38d);
    }
}

/* ========================================
   MOBILE NAVIGATION
   ======================================== */

/**
 * Mobile navbar toggle styles
 */
@media (max-width: 767.98px) {
    /* Ensure sidebar takes full width on mobile when open */
    #sidebarMenu {
        position: fixed;
        top: 56px; /* Height of mobile navbar */
        left: 0;
        width: 80%;
        max-width: 300px;
        height: calc(100vh - 56px);
        overflow-y: auto;
        z-index: 1040;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }

    /* Backdrop when sidebar is open */
    #sidebarMenu.show::before {
        content: '';
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }

    /* Auto-close sidebar when clicking a link */
    #sidebarMenu .nav-link {
        cursor: pointer;
    }

    /* Adjust main content to not overlap with mobile navbar */
    main {
        padding-top: 1rem !important;
    }
}

/* Mobile navbar styling */
.navbar.d-md-none {
    position: sticky;
    top: 0;
    z-index: 1050;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}