/**
 * VRCC Accessibility Styles
 * WCAG 2.1 Level AA compliance enhancements
 *
 * Includes:
 * - Screen reader only utilities
 * - Focus indicators (2.4.7)
 * - High contrast mode support
 * - Skip links
 * - Keyboard navigation styles
 * - Color contrast fixes
 * - Touch target sizing (44x44px minimum)
 *
 * @package VRCC_Listings
 * @version 2.0.1
 */

/* ============================================
   Screen Reader Only Utility
   WCAG 1.1.1, 4.1.2
   ============================================ */

.sr-only,
.screen-reader-only,
.vrcc-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;
}

/* Show on focus (for skip links) */
.sr-only:focus,
.screen-reader-only:focus,
.vrcc-sr-only:focus {
    position: static;
    width: auto;
    height: auto;
    padding: 0.5rem 1rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: #007FAD;
    color: white;
    z-index: 10000;
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ============================================
   Skip Links
   WCAG 2.4.1 Bypass Blocks
   ============================================ */

.vrcc-skip-links {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
}

.vrcc-skip-link {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.vrcc-skip-link:focus {
    position: static;
    left: 0;
    width: auto;
    height: auto;
    padding: 1rem 1.5rem;
    background: #007FAD;
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    display: inline-block;
    border-radius: 0 0 4px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    outline: 3px solid white;
    outline-offset: 2px;
}

/* ============================================
   Enhanced Focus Indicators
   WCAG 2.4.7 Focus Visible
   Minimum 2px, 3:1 contrast ratio
   ============================================ */

/* Global focus style for keyboard navigation */
body.vrcc-keyboard-nav *:focus {
    outline: 3px solid #007FAD;
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(0, 127, 173, 0.2);
}

/* Interactive elements */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 2px solid #007FAD;
    outline-offset: 2px;
}

/* Enhanced focus for critical actions */
.vrcc-btn:focus,
.vrcc-check-availability:focus,
.vrcc-carousel-pause:focus {
    outline: 3px solid #007FAD;
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(0, 127, 173, 0.25);
}

/* Calendar day focus */
.flatpickr-day:focus {
    outline: 3px solid #007FAD;
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(0, 127, 173, 0.25);
    z-index: 10;
}

/* Swiper slide focus */
.swiper-slide:focus {
    outline: none;
}

.swiper-slide:focus-visible .vrcc-review-card {
    outline: 3px solid #007FAD;
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(0, 127, 173, 0.25);
}

/* Remove focus outline for mouse users */
body:not(.vrcc-keyboard-nav) *:focus {
    outline: none;
    box-shadow: none;
}

/* ============================================
   High Contrast Mode Support
   WCAG 1.4.3, 1.4.6
   ============================================ */

@media (prefers-contrast: high) {
    /* Increase border thickness */
    .vrcc-review-card,
    .flatpickr-calendar,
    button,
    input,
    select {
        border-width: 2px;
    }

    /* Ensure text contrast */
    body,
    .vrcc-review-card,
    .flatpickr-day {
        background: white;
        color: black;
    }

    /* High contrast focus indicators */
    *:focus {
        outline: 4px solid black;
        outline-offset: 2px;
    }

    /* Button states */
    button {
        background: white;
        color: black;
        border: 2px solid black;
    }

    button:hover,
    button:focus {
        background: black;
        color: white;
    }

    /* Disabled state must be distinguishable */
    button:disabled,
    .flatpickr-disabled {
        opacity: 1;
        background: #e0e0e0;
        color: #666;
        border: 2px dashed #666;
    }
}

/* Force colors mode (Windows) */
@media (forced-colors: active) {
    /* Use system colors */
    .vrcc-review-card,
    .flatpickr-day {
        border: 1px solid CanvasText;
    }

    button {
        border: 2px solid ButtonBorder;
    }

    /* Focus indicators use system highlight */
    *:focus {
        outline: 2px solid Highlight;
    }
}

/* ============================================
   Color Contrast Fixes
   WCAG 1.4.3 Contrast (Minimum)
   Text: 4.5:1, Large text: 3:1, UI: 3:1
   ============================================ */

/* Fix limited availability color (yellow -> orange) */
.vrcc-legend-color.limited {
    background-color: #F57C00; /* 4.52:1 contrast on white */
}

.flatpickr-day.vrcc-limited-availability {
    background-color: rgba(245, 124, 0, 0.15);
    border: 2px solid #F57C00;
    color: #000;
}

/* Disabled date enhancements (not just color) */
.flatpickr-disabled {
    background: #ffebee !important;
    color: #c62828 !important; /* 4.53:1 contrast */
    border: 2px solid #d32f2f !important;
    position: relative;
}

/* Add visual indicator beyond color */
.flatpickr-disabled::before {
    content: '✕';
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 10px;
    font-weight: bold;
    color: #c62828;
}

.flatpickr-disabled::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 10%;
    right: 10%;
    height: 2px;
    background: #c62828;
    transform: rotate(-45deg);
}

/* Verified badge contrast */
.verified-badge {
    background: #1b5e20; /* 8.59:1 contrast on white */
    color: white;
    border: 1px solid #1b5e20;
}

/* Star ratings visibility */
.review-rating .star.full {
    color: #F57C00; /* Better contrast than #FFB81C */
}

/* Aggregate rating */
.vrcc-aggregate-rating .rating {
    color: #005a7d; /* 4.57:1 contrast */
}

/* ============================================
   Touch Target Sizing
   WCAG 2.5.5 Target Size (Level AAA, but good practice)
   Minimum 44x44 pixels
   ============================================ */

button,
a,
input[type="checkbox"],
input[type="radio"],
.flatpickr-day,
.swiper-button-prev,
.swiper-button-next,
.swiper-pagination-bullet {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Ensure interactive elements have adequate spacing */
.vrcc-reviews-controls label {
    padding: 0.75rem;
    min-height: 44px;
}

/* Calendar days */
.flatpickr-day {
    width: 44px;
    height: 44px;
    line-height: 44px;
}

/* Pagination bullets */
.swiper-pagination-bullet {
    width: 16px;
    height: 16px;
    margin: 0 8px; /* Increased spacing for easier tapping */
}

/* Mobile adjustments */
@media (max-width: 768px) {
    button,
    a {
        min-width: 48px;
        min-height: 48px;
        padding: 0.75rem 1rem;
    }

    .flatpickr-day {
        width: 48px;
        height: 48px;
        line-height: 48px;
    }
}

/* ============================================
   Keyboard Navigation Instructions
   WCAG 3.3.2 Labels or Instructions
   ============================================ */

.vrcc-instructions {
    background: #f0f7fa;
    border-left: 4px solid #007FAD;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
}

.vrcc-instructions p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #333;
}

.vrcc-instructions strong {
    color: #007FAD;
}

.vrcc-instructions kbd {
    background: white;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 0.2em 0.5em;
    font-family: monospace;
    font-size: 0.85em;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ============================================
   ARIA Live Region Styling
   WCAG 4.1.3 Status Messages
   ============================================ */

#vrcc-a11y-announcer,
.vrcc-reviews-live-region {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   Carousel Pause Button
   WCAG 2.2.2 Pause, Stop, Hide
   ============================================ */

.vrcc-carousel-pause {
    background: #fff;
    border: 2px solid #007FAD;
    color: #007FAD;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    min-width: 44px;
    min-height: 44px;
}

.vrcc-carousel-pause:hover {
    background: #007FAD;
    color: white;
}

.vrcc-carousel-pause:focus {
    outline: 3px solid #007FAD;
    outline-offset: 2px;
}

.vrcc-carousel-pause[aria-pressed="true"] {
    background: #007FAD;
    color: white;
}

.pause-icon {
    font-size: 1.2rem;
}

/* Mobile positioning */
@media (max-width: 768px) {
    .vrcc-carousel-pause {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 100;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        min-width: 56px;
        min-height: 56px;
        border-radius: 50%;
        padding: 0;
    }

    .pause-text {
        display: none;
    }
}

/* ============================================
   Form Validation & Error States
   WCAG 3.3.1 Error Identification
   ============================================ */

.vrcc-error,
.vrcc-validation-error {
    color: #c62828;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.vrcc-error::before {
    content: '⚠';
    font-size: 1.2rem;
}

/* Invalid input styling */
input:invalid,
select:invalid,
textarea:invalid {
    border-color: #d32f2f;
}

input:invalid:focus,
select:invalid:focus,
textarea:invalid:focus {
    outline: 2px solid #d32f2f;
    outline-offset: 2px;
}

/* Valid state (optional) */
input:valid,
select:valid,
textarea:valid {
    border-color: #388e3c;
}

/* ============================================
   Helper Text & Status Messages
   WCAG 3.3.2 Labels or Instructions
   ============================================ */

.vrcc-helper-text {
    font-size: 0.9rem;
    color: #666;
    margin-top: 0.5rem;
    line-height: 1.4;
}

.vrcc-helper-text[aria-live] {
    min-height: 1.4em; /* Prevent layout shift */
}

/* ============================================
   Focus Trap Overlay
   Visual indicator when focus trap is active
   ============================================ */

.vrcc-focus-trap-active::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    pointer-events: none;
}

/* ============================================
   Loading States
   WCAG 4.1.3 Status Messages
   ============================================ */

.vrcc-loading {
    position: relative;
    pointer-events: none;
}

.vrcc-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007FAD;
    border-radius: 50%;
    animation: vrcc-spin 1s linear infinite;
    z-index: 10;
}

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

/* ============================================
   Reduced Motion Support
   WCAG 2.3.3 Animation from Interactions
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    /* Disable animations */
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Carousel auto-play disabled */
    .swiper-autoplay {
        animation: none !important;
    }

    /* Loading spinner visible but not animated */
    .vrcc-loading::after {
        animation: none;
        border-top-color: #007FAD;
    }
}

/* ============================================
   Print Styles
   Ensure accessibility in print
   ============================================ */

@media print {
    /* Show URLs for links */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }

    /* Skip links not needed in print */
    .vrcc-skip-links {
        display: none;
    }

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

    /* Carousel controls not needed */
    .swiper-button-prev,
    .swiper-button-next,
    .swiper-pagination,
    .vrcc-carousel-pause {
        display: none;
    }
}

/* ============================================
   Dark Mode Support (Respects prefers-color-scheme)
   WCAG 1.4.8 Visual Presentation
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* Light backgrounds maintained for readability in this case */
    /* Customize if full dark mode is desired */

    .vrcc-instructions {
        background: #1e3a4c;
        border-left-color: #4da6c7;
        color: #e0e0e0;
    }

    .vrcc-instructions strong {
        color: #4da6c7;
    }

    .vrcc-error {
        color: #ef5350;
    }
}

/* ============================================
   Language Support
   Ensure proper font rendering for various languages
   ============================================ */

html[lang^="ar"] {
    direction: rtl;
}

html[lang^="he"] {
    direction: rtl;
}

/* Right-to-left adjustments */
[dir="rtl"] .vrcc-skip-link {
    left: auto;
    right: -10000px;
}

[dir="rtl"] .vrcc-skip-link:focus {
    left: auto;
    right: 0;
    border-radius: 0 0 0 4px;
}

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

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

/* Keyboard-only visible */
.keyboard-only-visible {
    position: absolute;
    left: -10000px;
}

.keyboard-only-visible:focus {
    position: static;
    left: auto;
}

/* Focus within container */
.focus-within:focus-within {
    outline: 2px solid #007FAD;
    outline-offset: 2px;
}

/* Disabled state consistent appearance */
[disabled],
[aria-disabled="true"] {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* ============================================
   Development Helpers (Remove in production)
   ============================================ */

/* Highlight elements with missing alt text */
img:not([alt]),
area:not([alt]),
input[type="image"]:not([alt]) {
    outline: 5px solid red !important;
}

/* Highlight empty links */
a:not([aria-label]):not([aria-labelledby]):empty {
    outline: 5px solid orange !important;
}

/* Highlight low contrast text (approximation) */
.low-contrast-warning {
    background: yellow !important;
    color: black !important;
}
