/**
 * Accessibility Widget Styles
 * WCAG 2.1 Level AA Compliant
 * Version: 1.0.0
 */

/* ========================================
   Screen Reader Only Utility
   ======================================== */
.sr-only, .a11y-skip-link:not(:focus) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ========================================
   Toggle Button
   ======================================== */
.a11y-toggle {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4), 0 2px 4px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999998 !important;
    outline: none;
}

.a11y-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.5), 0 4px 8px rgba(0, 0, 0, 0.3);
}

.a11y-toggle:focus {
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

.a11y-toggle:active {
    transform: scale(1.05);
}

/* RTL Support - Flip toggle button to left side */
[dir="rtl"] .a11y-toggle {
    right: auto;
    left: 20px;
}

/* ========================================
   Widget Container
   ======================================== */
.a11y-widget {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 140px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999999999 !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.a11y-widget.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* RTL Support - Flip widget panel to left side */
[dir="rtl"] .a11y-widget {
    right: auto;
    left: 20px;
}

/* ========================================
   Widget Header
   ======================================== */
.a11y-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: white;
    border-radius: 16px 16px 0 0;
    flex-shrink: 0;
}

.a11y-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.a11y-back-btn,
.a11y-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.a11y-back-btn:hover,
.a11y-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.a11y-back-btn:focus,
.a11y-close:focus {
    outline: 2px solid #fbbf24;
    outline-offset: 2px;
}

/* ========================================
   Widget Body
   ======================================== */
.a11y-widget-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    min-height: 300px;
    max-height: calc(100vh - 280px);
}

.a11y-widget-body::-webkit-scrollbar {
    width: 8px;
}

.a11y-widget-body::-webkit-scrollbar-track {
    background: #f3f4f6;
}

.a11y-widget-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.a11y-widget-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ========================================
   Panels
   ======================================== */
.a11y-panel {
    display: none;
    animation: slideIn 0.3s ease-out;
}

.a11y-panel-active {
    display: block;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ========================================
   Sections
   ======================================== */
.a11y-section {
    margin-bottom: 24px;
}

.a11y-section:last-child {
    margin-bottom: 0;
}

.a11y-section-title {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ========================================
   Buttons
   ======================================== */
.a11y-btn {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.a11y-btn:hover {
    background: #f9fafb;
    border-color: #2563eb;
    color: #2563eb;
}

.a11y-btn:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.a11y-btn.active {
    background: #2563eb;
    border-color: #2563eb;
    color: white;
}

.a11y-btn.active:hover {
    background: #1e40af;
    border-color: #1e40af;
}

.a11y-btn svg {
    flex-shrink: 0;
}

/* Button Grids */
.a11y-buttons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
}

.a11y-buttons-grid .a11y-btn {
    flex-direction: column;
    gap: 6px;
    padding: 14px 10px;
    font-size: 12px;
}

/* Quick Actions */
.a11y-quick-actions {
    display: flex;
    gap: 8px;
}

.a11y-btn-quick {
    flex-direction: column;
    gap: 6px;
    padding: 14px 10px;
    font-size: 13px;
}

/* Control Buttons */
.a11y-btn-control {
    width: 40px;
    height: 40px;
    padding: 0;
    flex: 0 0 auto;
}

/* ========================================
   Menu Items
   ======================================== */
.a11y-menu-item {
    width: 100%;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    text-align: left;
}

.a11y-menu-item:last-child {
    margin-bottom: 0;
}

.a11y-menu-item:hover {
    background: #f9fafb;
    border-color: #2563eb;
    color: #2563eb;
}

.a11y-menu-item:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.a11y-menu-item span {
    flex: 1;
}

.a11y-arrow {
    opacity: 0.5;
    flex-shrink: 0;
}

/* ========================================
   Controls (Sliders)
   ======================================== */
.a11y-control {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.a11y-control-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
}

.a11y-control-value {
    flex: 1;
    text-align: center;
    font-weight: 600;
    color: #2563eb;
    font-size: 15px;
}

.a11y-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.a11y-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #2563eb;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
}

.a11y-slider::-webkit-slider-thumb:hover {
    background: #1e40af;
    transform: scale(1.1);
}

.a11y-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #2563eb;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
}

.a11y-slider::-moz-range-thumb:hover {
    background: #1e40af;
    transform: scale(1.1);
}

.a11y-slider:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* ========================================
   Footer
   ======================================== */
.a11y-widget-footer {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.a11y-btn-statement {
    width: 100%;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    padding: 10px 16px;
    font-size: 13px;
}

/* ========================================
   Info Box
   ======================================== */
.a11y-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    font-size: 12px;
    color: #1e40af;
}

.a11y-info kbd {
    background: white;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 11px;
    font-weight: 600;
}

/* ========================================
   Skip Links
   ======================================== */
.a11y-skip-links {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
}

.a11y-skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #2563eb;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 8px 0;
    transition: top 0.3s;
    z-index: 10000;
}

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

/* ========================================
   Reading Guide
   ======================================== */
.a11y-reading-guide {
    position: fixed;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(37, 99, 235, 0.8);
    pointer-events: none;
    z-index: 9997;
    box-shadow: 0 0 20px rgba(37, 99, 235, 0.5),
                0 -20px 40px rgba(37, 99, 235, 0.1),
                0 20px 40px rgba(37, 99, 235, 0.1);
}

/* ========================================
   Accessibility Mode Styles
   ======================================== */

/* Color Filters */
html {
    --a11y-color-filter: none;
}

html:not(.a11y-widget):not(#accessibility-widget):not(.a11y-toggle) {
    filter: var(--a11y-color-filter);
}

/* Dark High Contrast - Comprehensive Coverage */
.a11y-contrast-dark-high {
    --contrast-bg: #000;
    --contrast-text: #fff;
    --contrast-link: #ffeb3b;
    --contrast-border: #fff;
    --contrast-heading: #fff;
    --contrast-button-bg: #000;
    --contrast-button-text: #fff;
    --contrast-card-bg: #1a1a1a;
}

/* Base elements */
.a11y-contrast-dark-high body,
.a11y-contrast-dark-high body * {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border-color: var(--contrast-border) !important;
}

/* Links */
.a11y-contrast-dark-high a,
.a11y-contrast-dark-high a *,
.a11y-contrast-dark-high .nav-link,
.a11y-contrast-dark-high .navbar-brand {
    color: var(--contrast-link) !important;
    text-decoration: underline !important;
    background: transparent !important;
}

.a11y-contrast-dark-high a:hover,
.a11y-contrast-dark-high a:focus {
    color: #fff !important;
    background: #ffeb3b !important;
    text-decoration: underline !important;
}

/* Headings */
.a11y-contrast-dark-high h1,
.a11y-contrast-dark-high h2,
.a11y-contrast-dark-high h3,
.a11y-contrast-dark-high h4,
.a11y-contrast-dark-high h5,
.a11y-contrast-dark-high h6 {
    color: var(--contrast-heading) !important;
    background: transparent !important;
}

/* Headers, Navbars, Footers */
.a11y-contrast-dark-high header,
.a11y-contrast-dark-high nav,
.a11y-contrast-dark-high .navbar,
.a11y-contrast-dark-high .header,
.a11y-contrast-dark-high .nav,
.a11y-contrast-dark-high footer,
.a11y-contrast-dark-high .footer {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border: 2px solid var(--contrast-border) !important;
}

/* Dropdowns */
.a11y-contrast-dark-high .dropdown-menu,
.a11y-contrast-dark-high .dropdown-item {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border: 2px solid var(--contrast-border) !important;
}

.a11y-contrast-dark-high .dropdown-item:hover,
.a11y-contrast-dark-high .dropdown-item:focus {
    background: #ffeb3b !important;
    color: #000 !important;
}

/* Cards and Sections */
.a11y-contrast-dark-high .card,
.a11y-contrast-dark-high .card-body,
.a11y-contrast-dark-high .card-header,
.a11y-contrast-dark-high .card-footer,
.a11y-contrast-dark-high section,
.a11y-contrast-dark-high .section,
.a11y-contrast-dark-high .container,
.a11y-contrast-dark-high .row,
.a11y-contrast-dark-high .col,
.a11y-contrast-dark-high [class*="col-"] {
    background: var(--contrast-card-bg) !important;
    color: var(--contrast-text) !important;
    border: 2px solid var(--contrast-border) !important;
}

/* Buttons and Form Controls */
.a11y-contrast-dark-high button,
.a11y-contrast-dark-high .btn,
.a11y-contrast-dark-high input,
.a11y-contrast-dark-high select,
.a11y-contrast-dark-high textarea,
.a11y-contrast-dark-high .form-control,
.a11y-contrast-dark-high .form-select {
    background: var(--contrast-button-bg) !important;
    color: var(--contrast-button-text) !important;
    border: 3px solid var(--contrast-border) !important;
}

.a11y-contrast-dark-high button:hover,
.a11y-contrast-dark-high .btn:hover,
.a11y-contrast-dark-high button:focus,
.a11y-contrast-dark-high .btn:focus {
    background: #ffeb3b !important;
    color: #000 !important;
    border-color: #ffeb3b !important;
}

/* Booking Widget */
.a11y-contrast-dark-high .booking-widget,
.a11y-contrast-dark-high .booking-form,
.a11y-contrast-dark-high .booking-bar,
.a11y-contrast-dark-high .booking-calendar,
.a11y-contrast-dark-high .calendar,
.a11y-contrast-dark-high .datepicker {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border: 3px solid var(--contrast-border) !important;
}

/* Tables */
.a11y-contrast-dark-high table,
.a11y-contrast-dark-high thead,
.a11y-contrast-dark-high tbody,
.a11y-contrast-dark-high tfoot,
.a11y-contrast-dark-high tr,
.a11y-contrast-dark-high th,
.a11y-contrast-dark-high td {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border: 2px solid var(--contrast-border) !important;
}

/* Lists */
.a11y-contrast-dark-high ul,
.a11y-contrast-dark-high ol,
.a11y-contrast-dark-high li,
.a11y-contrast-dark-high dl,
.a11y-contrast-dark-high dt,
.a11y-contrast-dark-high dd {
    background: transparent !important;
    color: var(--contrast-text) !important;
}

/* Badges, Labels, Tags */
.a11y-contrast-dark-high .badge,
.a11y-contrast-dark-high .label,
.a11y-contrast-dark-high .tag,
.a11y-contrast-dark-high .pill {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border: 2px solid var(--contrast-border) !important;
}

/* Alerts and Messages */
.a11y-contrast-dark-high .alert,
.a11y-contrast-dark-high .message,
.a11y-contrast-dark-high .notification,
.a11y-contrast-dark-high .toast {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border: 3px solid var(--contrast-border) !important;
}

/* Modals and Overlays */
.a11y-contrast-dark-high .modal,
.a11y-contrast-dark-high .modal-content,
.a11y-contrast-dark-high .modal-header,
.a11y-contrast-dark-high .modal-body,
.a11y-contrast-dark-high .modal-footer,
.a11y-contrast-dark-high .overlay,
.a11y-contrast-dark-high .popup {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border: 3px solid var(--contrast-border) !important;
}

/* Images and Media - Add borders for visibility */
.a11y-contrast-dark-high img,
.a11y-contrast-dark-high picture,
.a11y-contrast-dark-high video,
.a11y-contrast-dark-high iframe {
    border: 3px solid var(--contrast-border) !important;
    opacity: 0.9 !important;
}

/* Icons */
.a11y-contrast-dark-high .icon,
.a11y-contrast-dark-high i,
.a11y-contrast-dark-high svg {
    color: var(--contrast-text) !important;
    fill: var(--contrast-text) !important;
}

/* Dividers */
.a11y-contrast-dark-high hr,
.a11y-contrast-dark-high .divider {
    border-color: var(--contrast-border) !important;
    background: var(--contrast-border) !important;
}

/* Bright High Contrast - Comprehensive Coverage */
.a11y-contrast-bright-high {
    --contrast-bg: #fff;
    --contrast-text: #000;
    --contrast-link: #00f;
    --contrast-border: #000;
    --contrast-heading: #000;
    --contrast-button-bg: #fff;
    --contrast-button-text: #000;
    --contrast-card-bg: #f5f5f5;
}

/* Base elements */
.a11y-contrast-bright-high body,
.a11y-contrast-bright-high body * {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border-color: var(--contrast-border) !important;
}

/* Links */
.a11y-contrast-bright-high a,
.a11y-contrast-bright-high a *,
.a11y-contrast-bright-high .nav-link,
.a11y-contrast-bright-high .navbar-brand {
    color: var(--contrast-link) !important;
    text-decoration: underline !important;
    background: transparent !important;
}

.a11y-contrast-bright-high a:hover,
.a11y-contrast-bright-high a:focus {
    color: #fff !important;
    background: #00f !important;
    text-decoration: underline !important;
}

/* Headings */
.a11y-contrast-bright-high h1,
.a11y-contrast-bright-high h2,
.a11y-contrast-bright-high h3,
.a11y-contrast-bright-high h4,
.a11y-contrast-bright-high h5,
.a11y-contrast-bright-high h6 {
    color: var(--contrast-heading) !important;
    background: transparent !important;
}

/* Headers, Navbars, Footers */
.a11y-contrast-bright-high header,
.a11y-contrast-bright-high nav,
.a11y-contrast-bright-high .navbar,
.a11y-contrast-bright-high .header,
.a11y-contrast-bright-high .nav,
.a11y-contrast-bright-high footer,
.a11y-contrast-bright-high .footer {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border: 2px solid var(--contrast-border) !important;
}

/* All other elements same pattern as dark */
.a11y-contrast-bright-high .dropdown-menu,
.a11y-contrast-bright-high .dropdown-item,
.a11y-contrast-bright-high .card,
.a11y-contrast-bright-high .card-body,
.a11y-contrast-bright-high section,
.a11y-contrast-bright-high .container {
    background: var(--contrast-card-bg) !important;
    color: var(--contrast-text) !important;
    border: 2px solid var(--contrast-border) !important;
}

.a11y-contrast-bright-high button,
.a11y-contrast-bright-high .btn,
.a11y-contrast-bright-high input,
.a11y-contrast-bright-high select,
.a11y-contrast-bright-high textarea {
    background: var(--contrast-button-bg) !important;
    color: var(--contrast-button-text) !important;
    border: 3px solid var(--contrast-border) !important;
}

.a11y-contrast-bright-high button:hover,
.a11y-contrast-bright-high .btn:hover {
    background: #00f !important;
    color: #fff !important;
}

/* Booking Widget */
.a11y-contrast-bright-high .booking-widget,
.a11y-contrast-bright-high .booking-form,
.a11y-contrast-bright-high .booking-bar,
.a11y-contrast-bright-high .booking-calendar {
    background: var(--contrast-bg) !important;
    color: var(--contrast-text) !important;
    border: 3px solid var(--contrast-border) !important;
}

.a11y-contrast-bright-high img,
.a11y-contrast-bright-high picture,
.a11y-contrast-bright-high video {
    border: 3px solid var(--contrast-border) !important;
    opacity: 0.9 !important;
}

/* Dark Mode */
.a11y-dark-mode {
    color-scheme: dark;
}

.a11y-dark-mode body {
    background: #1a1a1a !important;
    color: #e5e5e5 !important;
}

.a11y-dark-mode a {
    color: #60a5fa !important;
}

.a11y-dark-mode #accessibility-widget,
.a11y-dark-mode #accessibility-widget *,
.a11y-dark-mode .a11y-toggle,
.a11y-dark-mode .a11y-toggle * {
    filter: none !important;
}

/* Monochrome Mode */
/* Apply grayscale using backdrop-filter overlay */
html.a11y-monochrome::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backdrop-filter: grayscale(100%);
    -webkit-backdrop-filter: grayscale(100%);
    pointer-events: none;
    z-index: 2147483646; /* Max safe z-index minus 1 */
}

/* Ensure the accessibility widget stays above the overlay */
html.a11y-monochrome #accessibility-widget,
html.a11y-monochrome .a11y-toggle {
    z-index: 2147483647 !important; /* Max safe z-index */
    filter: grayscale(100%) !important;
}

/* Line Height */
.a11y-line-height-relaxed * {
    line-height: 1.75 !important;
}

.a11y-line-height-loose * {
    line-height: 2 !important;
}

/* Letter Spacing */
.a11y-letter-spacing-wide * {
    letter-spacing: 0.05em !important;
}

.a11y-letter-spacing-wider * {
    letter-spacing: 0.1em !important;
}

/* Text Alignment */
.a11y-text-align-left p,
.a11y-text-align-left div,
.a11y-text-align-left span {
    text-align: left !important;
}

.a11y-text-align-center p,
.a11y-text-align-center div,
.a11y-text-align-center span {
    text-align: center !important;
}

/* Big Cursor */
.a11y-big-cursor,
.a11y-big-cursor * {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><path d="M4 4 L4 26 L10 20 L14 28 L18 26 L14 18 L22 18 Z" fill="black" stroke="white" stroke-width="1"/></svg>') 0 0, auto !important;
}

/* Hide Images */
.a11y-hide-images img,
.a11y-hide-images picture,
.a11y-hide-images video {
    opacity: 0.1 !important;
}

.a11y-hide-images img[alt]::after {
    content: attr(alt);
    display: block;
    background: #f3f4f6;
    padding: 8px;
    color: #374151;
    font-size: 14px;
    opacity: 1 !important;
}

/* Pause Animations */
.a11y-pause-animations *,
.a11y-pause-animations *::before,
.a11y-pause-animations *::after {
    animation-play-state: paused !important;
    animation-duration: 0s !important;
    transition: none !important;
}

/* Highlight Links */
.a11y-highlight-links a {
    background: #fef3c7 !important;
    padding: 2px 4px !important;
    border-radius: 3px !important;
    text-decoration: underline !important;
    font-weight: 600 !important;
}

/* Enhanced Focus */
.a11y-enhanced-focus *:focus {
    outline: 3px solid #fbbf24 !important;
    outline-offset: 2px !important;
}

/* Screen Reader Mode */
.a11y-screen-reader-mode {
    /* Simplify layout for screen readers */
}

.a11y-screen-reader-mode *:focus {
    outline: 4px solid #fbbf24 !important;
    outline-offset: 3px !important;
}

/* ========================================
   Responsive Design
   ======================================== */
/* ========================================
   Mobile Responsive Design
   ======================================== */

/* Tablets and small laptops */
@media (max-width: 768px) {
    .a11y-widget {
        bottom: 30px;
        right: 15px;
        left: 15px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 160px);
    }

    .a11y-toggle {
        bottom: 100px;
        right: 15px;
        width: 52px;
        height: 52px;
    }

    .a11y-widget-body {
        max-height: calc(100vh - 260px);
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    .a11y-widget {
        bottom: 20px;
        right: 8px;
        left: 8px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 150px);
        border-radius: 12px;
    }

    .a11y-toggle {
        bottom: 30px;
        right: 10px;
        width: 50px;
        height: 50px;
        box-shadow: 0 4px 15px rgba(37, 99, 235, 0.5);
    }

    .a11y-widget-header {
        padding: 16px;
        border-radius: 12px 12px 0 0;
    }

    .a11y-title {
        font-size: 16px;
    }

    .a11y-widget-body {
        padding: 14px;
        max-height: calc(100vh - 180px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .a11y-buttons-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .a11y-buttons-grid .a11y-btn {
        padding: 12px 8px;
        font-size: 11px;
        min-height: 70px;
    }

    .a11y-section {
        margin-bottom: 18px;
    }

    .a11y-section-title {
        font-size: 12px;
        margin-bottom: 10px;
    }

    .a11y-btn {
        padding: 10px 12px;
        font-size: 13px;
        /* Touch-friendly target size */
        min-height: 44px;
    }

    .a11y-menu-item {
        padding: 14px;
        font-size: 14px;
        min-height: 50px;
    }

    .a11y-control {
        gap: 10px;
    }

    .a11y-control-buttons {
        gap: 8px;
    }

    .a11y-btn-control {
        width: 44px;
        height: 44px;
    }

    .a11y-slider {
        height: 8px;
    }

    .a11y-slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }

    .a11y-slider::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }

    .a11y-quick-actions {
        flex-direction: column;
        gap: 8px;
    }

    .a11y-btn-quick {
        width: 100%;
        flex-direction: row;
        justify-content: center;
    }

    .a11y-widget-footer {
        padding: 12px 14px;
    }

    .a11y-back-btn,
    .a11y-close {
        width: 40px;
        height: 40px;
    }

    .a11y-info {
        padding: 10px;
        font-size: 11px;
    }

    .a11y-info kbd {
        padding: 2px 5px;
        font-size: 10px;
    }
}

/* Very small phones */
@media (max-width: 360px) {
    .a11y-widget {
        bottom: 20px;
        right: 5px;
        left: 5px;
    }

    .a11y-toggle {
        width: 46px;
        height: 46px;
        bottom: 30px;
        right: 8px;
    }

    .a11y-widget-body {
        padding: 12px;
    }

    .a11y-control-buttons {
        flex-wrap: wrap;
        justify-content: center;
    }

    .a11y-control-value {
        width: 100%;
        order: -1;
        margin-bottom: 8px;
    }

    .a11y-buttons-grid .a11y-btn {
        padding: 10px 6px;
        font-size: 10px;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .a11y-widget {
        bottom: 20px;
        max-height: calc(100vh - 130px);
    }

    .a11y-toggle {
        bottom: 30px;
        width: 44px;
        height: 44px;
    }

    .a11y-widget-body {
        max-height: calc(100vh - 140px);
        padding: 12px;
    }

    .a11y-section {
        margin-bottom: 12px;
    }

    .a11y-buttons-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Safe area for notched phones (iPhone X+) 
@supports (padding: max(0px)) {
    .a11y-widget {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }

    .a11y-toggle {
        bottom: max(10px, calc(10px + env(safe-area-inset-bottom)));
        right: max(10px, calc(10px + env(safe-area-inset-right)));
    }
}
*/
/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .a11y-btn {
        /* Larger touch targets */
        min-height: 48px;
    }

    .a11y-btn:active {
        transform: scale(0.97);
        background: #dbeafe;
    }

    .a11y-btn.active:active {
        background: #1e40af;
    }

    .a11y-menu-item {
        min-height: 52px;
    }

    .a11y-menu-item:active {
        background: #dbeafe;
    }

    .a11y-toggle:active {
        transform: scale(0.95);
    }

    .a11y-slider {
        height: 10px;
    }

    .a11y-slider::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
    }

    .a11y-slider::-moz-range-thumb {
        width: 28px;
        height: 28px;
    }

    /* Mobile backdrop when widget is open */
    .a11y-widget.active::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: -1;
        pointer-events: none;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .a11y-widget,
    .a11y-toggle,
    .a11y-skip-links,
    .a11y-reading-guide {
        display: none !important;
    }
}

/* ========================================
   High Contrast Mode Detection (Windows)
   ======================================== */
@media (prefers-contrast: high) {
    .a11y-toggle {
        border: 2px solid currentColor;
    }

    .a11y-btn {
        border-width: 2px;
    }
}

/* ========================================
   Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .a11y-widget {
        transition: opacity 0.2s;
        transform: none !important;
    }

    .a11y-panel {
        animation: none;
    }
}

/* ========================================
   Dark Mode Preference
   ======================================== */
@media (prefers-color-scheme: dark) {
    .a11y-widget {
        background: #1f2937;
        color: #f9fafb;
    }

    .a11y-section-title {
        color: #f9fafb;
    }

    .a11y-btn {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }

    .a11y-btn:hover {
        background: #4b5563;
    }

    .a11y-menu-item {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }

    .a11y-widget-footer {
        border-top-color: #4b5563;
    }

    .a11y-btn-statement {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }

    .a11y-info {
        background: #1e3a5f;
        border-color: #2563eb;
        color: #bfdbfe;
    }

    .a11y-slider {
        background: #4b5563;
    }
}

/* ========================================
   Exceptions (Don't apply text changes to widget itself)
   ======================================== */
#accessibility-widget,
#accessibility-widget *,
#accessibility-toggle,
.a11y-skip-links,
.a11y-skip-links * {
    font-size: initial !important;
    line-height: initial !important;
    letter-spacing: initial !important;
}

/* ========================================
   RTL Support - Flip to left side (high specificity)
   ======================================== */
[dir="rtl"] .a11y-toggle,
[dir="rtl"] #accessibility-toggle {
    right: auto !important;
    left: 20px !important;
}

[dir="rtl"] .a11y-widget,
[dir="rtl"] #accessibility-widget {
    right: auto !important;
    left: 20px !important;
}

@media (max-width: 768px) {
    [dir="rtl"] .a11y-toggle,
    [dir="rtl"] #accessibility-toggle {
        left: 15px !important;
    }

    [dir="rtl"] .a11y-widget,
    [dir="rtl"] #accessibility-widget {
        left: 15px !important;
    }
}

@media (max-width: 480px) {
    [dir="rtl"] .a11y-toggle,
    [dir="rtl"] #accessibility-toggle {
        left: 10px !important;
    }

    [dir="rtl"] .a11y-widget,
    [dir="rtl"] #accessibility-widget {
        left: 8px !important;
    }
}
