/**
 * Accessibility and Mobile Improvements for River Island Wildlife Widgets
 * Ensures ADA/WCAG 2.1 AA compliance and mobile optimization
 */

/* ============================================
   FOCUS INDICATORS & KEYBOARD NAVIGATION
   ============================================ */

/* Universal focus indicator for interactive elements */
*:focus-visible {
    outline: 3px solid rgba(46, 125, 50, 0.5) !important;
    outline-offset: 2px !important;
    z-index: 9999;
}

/* Skip to content link for screen readers */
.riew-skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--riew-dark-green, #2a5434);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100000;
}

.riew-skip-link:focus {
    top: 0;
}

/* ============================================
   TOUCH TARGETS & INTERACTIVE ELEMENTS
   ============================================ */

/* Checkbox and radio button improvements - Desktop */
input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 8px;
    cursor: pointer;
    border-radius: 4px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border: 2px solid var(--riew-border, #e0e0e0);
    background: white;
    position: relative;
}

input[type="checkbox"]:checked {
    background: var(--riew-dark-green, #2a5434);
    border-color: var(--riew-dark-green, #2a5434);
}

input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
}

input[type="radio"] {
    width: 18px;
    height: 18px;
    margin-right: 8px;
    cursor: pointer;
}

.riew-checkbox-label,
.riew-radio-label {
    display: flex;
    align-items: center;
    padding: 8px 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.riew-checkbox-label:hover,
.riew-radio-label:hover {
    background: rgba(46, 125, 50, 0.05);
    border-radius: 4px;
}

/* Mobile touch targets - only on mobile */
@media (max-width: 768px) {
    /* Ensure all clickable elements meet minimum 44x44px touch target on mobile */
    .riew-search-clear,
    .riew-filter-checkbox,
    .riew-tab-button,
    .riew-pagination button,
    .riew-pagination a,
    .riew-load-more {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        margin-right: 10px;
    }
    
    .riew-checkbox-label,
    .riew-radio-label {
        min-height: 44px;
        padding: 12px 8px;
    }
}

/* ============================================
   COLOR CONTRAST IMPROVEMENTS
   ============================================ */

/* Ensure text meets WCAG AA contrast ratios */
.riew-fact-label,
.riew-filter-group label {
    color: #1a1a1a; /* Darker for better contrast */
    font-weight: 600;
}

.riew-fact-value {
    color: #333333; /* Ensure 4.5:1 contrast ratio */
}

.riew-count {
    color: #555555; /* Better contrast for count badges */
    font-weight: 500;
}

/* Disabled state with sufficient contrast */
.riew-disabled,
[disabled] {
    opacity: 0.7 !important;
    cursor: not-allowed !important;
}

.riew-disabled .riew-count {
    color: #767676; /* Maintains 4.5:1 even when disabled */
}

/* ============================================
   SCREEN READER SUPPORT
   ============================================ */

/* Visually hidden but available to screen readers */
.riew-sr-only {
    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;
}

/* Announce dynamic content changes */
.riew-live-region {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ============================================
   MOBILE OPTIMIZATIONS - LIST VIEW
   ============================================ */

@media (max-width: 768px) {
    /* Mobile navigation improvements */
    .riew-filters-container {
        padding: 1rem;
    }
    
    /* Collapsible filter groups on mobile */
    .riew-filter-group {
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        margin-bottom: 1rem;
        overflow: visible;
        background: white;
    }
    
    .riew-filter-group > label {
        padding: 1rem;
        margin: 0;
        background: #f5f5f5;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
        user-select: none;
        font-weight: 600;
        font-size: 1rem;
        color: #333;
        border-radius: 8px 8px 0 0;
    }
    
    .riew-filter-group > label:hover {
        background: #ebebeb;
    }
    
    /* Arrow indicator */
    .riew-collapse-arrow {
        display: inline-block;
        margin-left: auto;
        transition: transform 0.3s ease;
        font-size: 0.8rem;
        color: #666;
    }
    
    .riew-filter-group.riew-collapsed .riew-collapse-arrow {
        transform: rotate(-90deg);
    }
    
    /* Content padding when expanded */
    .riew-filter-group .riew-checkbox-group,
    .riew-filter-group .riew-filter,
    .riew-filter-group .riew-taxonomy-container {
        padding: 0.5rem;
    }
    
    /* Stack filters vertically on mobile */
    .riew-filters {
        grid-template-columns: 1fr;
    }
    
    /* Full-width search on mobile */
    .riew-search-container {
        margin-bottom: 1rem;
    }
    
    .riew-search-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 14px 50px 14px 16px;
    }
    
    /* Larger touch targets for filter checkboxes */
    .riew-checkbox-group {
        flex-direction: column;
    }
    
    .riew-checkbox-label {
        width: 100%;
        padding: 14px 12px;
        border-bottom: 1px solid #f0f0f0;
    }
    
    /* Wildlife cards - single column on mobile */
    .riew-wildlife-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
        padding: 0 0.5rem;
    }
    
    .riew-wildlife-card {
        margin: 0;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    /* Improved card layout on mobile */
    .riew-wildlife-card__image {
        height: 200px;
    }
    
    .riew-wildlife-card__content {
        padding: 1rem;
    }
    
    .riew-wildlife-card__title {
        font-size: 1.1rem;
    }
    
    /* Better pagination on mobile */
    .riew-pagination {
        justify-content: center;
        flex-wrap: wrap;
        padding: 1rem;
    }
    
    .riew-pagination button,
    .riew-pagination a {
        margin: 0.25rem;
        padding: 12px 16px;
        font-size: 16px;
    }
    
    /* Load more button full width on mobile */
    .riew-load-more {
        width: 100%;
        padding: 16px;
        font-size: 16px;
        margin: 1rem 0;
    }
}

/* ============================================
   MOBILE OPTIMIZATIONS - SINGLE VIEW
   ============================================ */

@media (max-width: 768px) {
    /* Hero section stacks on mobile */
    .riew-wildlife-single__hero {
        grid-template-columns: 1fr !important;
        gap: 1.5rem;
        padding: 1rem;
    }
    
    .riew-wildlife-single__hero-image {
        max-height: 300px;
        padding: 0.5rem;
    }
    
    .riew-wildlife-single__hero-info {
        padding: 1rem;
    }
    
    .riew-wildlife-single__hero-info .riew-wildlife-single__title {
        font-size: 1.5rem;
    }
    
    .riew-wildlife-single__hero-info .riew-wildlife-single__scientific {
        font-size: 1rem;
    }
    
    /* Quick facts full width on mobile */
    .riew-wildlife-single__hero-right .riew-quick-facts {
        padding: 1rem;
    }
    
    .riew-quick-facts__title {
        font-size: 1.25rem;
    }
    
    .riew-fact-item {
        padding: 0.75rem;
        margin-bottom: 0.5rem;
    }
    
    /* Tabs navigation */
    .riew-tabs {
        grid-template-columns: 1fr !important;
        padding: 1rem;
    }
    
    .riew-tabs__nav {
        flex-direction: column;
        position: static;
        margin-bottom: 1rem;
    }
    
    .riew-tab-button {
        width: 100%;
        text-align: left;
        padding: 14px 16px;
        font-size: 16px;
        margin-bottom: 0.5rem;
    }
    
    .riew-tabs__content {
        padding: 1rem;
    }
    
    /* Gallery responsive */
    .riew-gallery {
        padding: 1rem;
        gap: 0.75rem;
    }
    
    .riew-gallery-cols-2,
    .riew-gallery-cols-3,
    .riew-gallery-cols-4,
    .riew-gallery-cols-5,
    .riew-gallery-cols-6 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Sections padding */
    .riew-section {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .riew-section-title {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }
}

/* ============================================
   VERY SMALL DEVICES (< 375px)
   ============================================ */

@media (max-width: 374px) {
    /* Even smaller text adjustments */
    .riew-wildlife-single__hero-info .riew-wildlife-single__title {
        font-size: 1.25rem;
    }
    
    .riew-wildlife-card__title {
        font-size: 1rem;
    }
    
    /* Single column gallery on very small screens */
    .riew-gallery-cols-2,
    .riew-gallery-cols-3,
    .riew-gallery-cols-4,
    .riew-gallery-cols-5,
    .riew-gallery-cols-6 {
        grid-template-columns: 1fr !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;
    }
    
    .riew-wildlife-single__hero-image:hover {
        transform: none !important;
    }
    
    .riew-gallery-item:hover {
        transform: none !important;
    }
}

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

@media (prefers-contrast: high) {
    .riew-wildlife-card,
    .riew-quick-facts,
    .riew-tabs__content {
        border: 2px solid currentColor;
    }
    
    .riew-badge {
        border: 2px solid currentColor;
    }
    
    *:focus-visible {
        outline-width: 4px !important;
    }
}

/* ============================================
   DARK MODE SUPPORT (Optional - add .dark-mode class to body to enable)
   ============================================ */

body.dark-mode .riew-wildlife-list-widget,
body.dark-mode .riew-wildlife-single {
    background: #1a1a1a;
    color: #e0e0e0;
}

body.dark-mode .riew-wildlife-card,
body.dark-mode .riew-tabs__content,
body.dark-mode .riew-quick-facts {
    background: #2a2a2a;
    color: #e0e0e0;
    border-color: #444;
}

body.dark-mode .riew-search-input,
body.dark-mode .riew-filter {
    background: #2a2a2a;
    color: #e0e0e0;
    border-color: #444;
}

body.dark-mode .riew-fact-label {
    color: #b0b0b0;
}

body.dark-mode .riew-fact-value {
    color: #e0e0e0;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .riew-filters-container,
    .riew-pagination,
    .riew-load-more,
    .riew-search-container {
        display: none !important;
    }
    
    .riew-wildlife-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .riew-wildlife-card {
        page-break-inside: avoid;
    }
    
    .riew-tabs {
        display: block !important;
    }
    
    .riew-tabs__nav {
        display: none !important;
    }
    
    .riew-tab-pane {
        display: block !important;
        page-break-inside: avoid;
    }
}