/* ============================================
   ACCESSIBILITY TOOLS - WCAG 2.1 AA COMPLIANT
   Israeli Standard 5568 & US Section 508
   ============================================ */

/* Skip to Main Content Link - WCAG Requirement */
.skip-to-main {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 1rem 2rem;
    border-radius: 0 0 8px 8px;
    z-index: 99999;
    font-weight: 600;
    text-decoration: none;
    transition: top 0.3s ease;
}

.skip-to-main:focus {
    top: 0;
    outline: 3px solid #f59e0b;
    outline-offset: 2px;
}

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

/* Reading Guide */
.reading-guide {
    position: fixed;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        rgba(59, 130, 246, 0.15) 40%,
        rgba(59, 130, 246, 0.15) 60%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 99990;
    transition: top 0.05s ease-out;
}

/* ============================================
   MAIN WIDGET STYLES
   ============================================ */

.a11y-widget {
    position: fixed;
    right: 20px;
    top: auto;
    bottom: 40px; /* Above footer on desktop */
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    /* Prevent filters from affecting the widget */
    isolation: isolate;
    filter: none !important;
    -webkit-filter: none !important;
}

/* On desktop, position above feedback bubble (feedback is at bottom: 24px, height ~48px, gap 20px = ~92px from bottom) */
@media (min-width: 769px) {
    .a11y-widget {
        bottom: 92px; /* 24px (feedback bottom) + 48px (feedback height) + 20px (gap) */
        right: 24px; /* Align with feedback bubble */
    }
    
    /* Make toggle button more compact on desktop when near feedback - creative compact design */
    .a11y-toggle-btn {
        width: 46.8px; /* Reduced by 10% (52px * 0.9) */
        height: 46.8px; /* Reduced by 10% (52px * 0.9) */
        border-radius: 10.8px; /* Reduced proportionally */
        box-shadow: 0 3px 15px rgba(37, 99, 235, 0.35), 0 1px 6px rgba(0, 0, 0, 0.1);
    }
    
    .a11y-toggle-btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 18px rgba(37, 99, 235, 0.45), 0 2px 8px rgba(0, 0, 0, 0.12);
    }
    
    .a11y-toggle-btn i {
        font-size: 19.8px; /* Reduced by 10% (22px * 0.9) */
    }
}

/* Toggle Button */
.a11y-toggle-btn {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border: none;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4), 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.a11y-toggle-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.a11y-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(37, 99, 235, 0.5), 0 4px 12px rgba(0, 0, 0, 0.15);
}

.a11y-toggle-btn:hover::before {
    opacity: 1;
}

.a11y-toggle-btn:active {
    transform: translateY(0);
}

.a11y-toggle-btn:focus {
    outline: 3px solid #f59e0b;
    outline-offset: 3px;
}

.a11y-toggle-btn.open {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    box-shadow: 0 4px 20px rgba(29, 78, 216, 0.5), 0 2px 8px rgba(0, 0, 0, 0.1);
}

.a11y-toggle-btn i {
    font-size: 28px;
    position: relative;
    z-index: 1;
}

/* Settings Panel */
.a11y-panel {
    position: absolute;
    bottom: 50px;
    right: 0;
    left: auto;
    width: 380px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    animation: slideUp 0.3s ease;
    display: flex;
    flex-direction: column;
}

/* Ensure panel doesn't exceed viewport on desktop */
@media (min-width: 769px) {
    .a11y-panel {
        /* Use viewport height minus safe margins */
        max-height: min(calc(100vh - 100px), 700px);
    }
}

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

/* Header */
.a11y-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
}

.a11y-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}

.a11y-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

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

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

/* Content */
.a11y-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

/* Section */
.a11y-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid #e2e8f0;
}

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

.a11y-section h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 0.75rem 0;
}

/* Font Size Controls */
.a11y-font-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: #f1f5f9;
    border-radius: 10px;
    padding: 0.75rem;
}

.a11y-font-controls button {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #fff;
    border: 2px solid #e2e8f0;
    color: #1e293b;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.a11y-font-controls button:hover:not(:disabled) {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.a11y-font-controls button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

.font-size-display {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
    min-width: 50px;
    text-align: center;
}

/* Button Groups */
.a11y-button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.a11y-button-group button {
    flex: 1;
    min-width: 70px;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    background: #f1f5f9;
    border: 2px solid transparent;
    color: #475569;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.a11y-button-group button:hover {
    background: #e2e8f0;
}

.a11y-button-group button.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

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

.a11y-button-group.small button {
    min-width: 60px;
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
}

/* Toggle Items */
.a11y-toggles {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.a11y-toggle-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: #f8fafc;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.a11y-toggle-item:hover {
    background: #f1f5f9;
}

.a11y-toggle-item span:first-child {
    font-size: 0.85rem;
    color: #334155;
    font-weight: 500;
}

.a11y-toggle-item input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: #cbd5e1;
    border-radius: 24px;
    transition: background 0.3s ease;
    flex-shrink: 0;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.a11y-toggle-item input:checked + .toggle-slider {
    background: #2563eb;
}

.a11y-toggle-item input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

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

/* Spacing Controls */
.a11y-spacing-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.spacing-option {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.spacing-option > span {
    font-size: 0.8rem;
    color: #64748b;
    font-weight: 500;
}

/* Footer */
.a11y-footer {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}

.a11y-reset-btn {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    background: #fee2e2;
    border: none;
    color: #dc2626;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.a11y-reset-btn:hover {
    background: #fecaca;
}

.a11y-reset-btn:focus {
    outline: 2px solid #dc2626;
    outline-offset: 2px;
}

.a11y-statement-link {
    text-align: center;
    font-size: 0.85rem;
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
}

.a11y-statement-link:hover {
    text-decoration: underline;
}

/* Compliance Notice */
.a11y-compliance {
    padding: 0.75rem 1.25rem;
    background: #1e293b;
    text-align: center;
}

.a11y-compliance p {
    margin: 0;
    font-size: 0.7rem;
    color: #94a3b8;
}

/* ============================================
   ACCESSIBILITY MODE STYLES
   Applied to body element
   ============================================ */

/* Font Size Scaling */
:root {
    --a11y-font-scale: 1;
}

/* Small font size (80-90%) */
body.a11y-font-small {
    font-size: 0.85em !important;
}

body.a11y-font-small p,
body.a11y-font-small span,
body.a11y-font-small li,
body.a11y-font-small td,
body.a11y-font-small th,
body.a11y-font-small label,
body.a11y-font-small a {
    font-size: 0.9em !important;
}

/* Large font size (110-120%) */
body.a11y-font-large {
    font-size: 1.15em !important;
}

body.a11y-font-large p,
body.a11y-font-large span:not(.MuiChip-label),
body.a11y-font-large li,
body.a11y-font-large td,
body.a11y-font-large th,
body.a11y-font-large label,
body.a11y-font-large a {
    font-size: 1.1em !important;
}

body.a11y-font-large h1 { font-size: 2.5rem !important; }
body.a11y-font-large h2 { font-size: 2rem !important; }
body.a11y-font-large h3 { font-size: 1.5rem !important; }
body.a11y-font-large h4 { font-size: 1.25rem !important; }

/* Extra large font size (130-150%) */
body.a11y-font-xlarge {
    font-size: 1.35em !important;
}

body.a11y-font-xlarge p,
body.a11y-font-xlarge span:not(.MuiChip-label),
body.a11y-font-xlarge li,
body.a11y-font-xlarge td,
body.a11y-font-xlarge th,
body.a11y-font-xlarge label,
body.a11y-font-xlarge a {
    font-size: 1.3em !important;
}

body.a11y-font-xlarge h1 { font-size: 3rem !important; }
body.a11y-font-xlarge h2 { font-size: 2.5rem !important; }
body.a11y-font-xlarge h3 { font-size: 1.75rem !important; }
body.a11y-font-xlarge h4 { font-size: 1.5rem !important; }

body.a11y-font-xlarge button,
body.a11y-font-xlarge input,
body.a11y-font-xlarge textarea,
body.a11y-font-xlarge select {
    font-size: 1.2em !important;
}

/* High Contrast */
body.a11y-high-contrast {
    background: #fff !important;
    color: #000 !important;
}

body.a11y-high-contrast * {
    border-color: #000 !important;
}

body.a11y-high-contrast a,
body.a11y-high-contrast button {
    color: #000 !important;
    text-decoration: underline !important;
}

/* Dark Contrast */
body.a11y-dark-contrast {
    background: #1a1a1a !important;
    color: #f5f5f5 !important;
}

body.a11y-dark-contrast * {
    background-color: inherit !important;
    color: inherit !important;
    border-color: #444 !important;
}

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

/* Inverted Colors - Apply to html, not body to avoid affecting widget */
html.a11y-inverted {
    filter: invert(1) hue-rotate(180deg) !important;
}

html.a11y-inverted img,
html.a11y-inverted video {
    filter: invert(1) hue-rotate(180deg) !important;
}

/* Grayscale - Apply to html */
html.a11y-grayscale {
    filter: grayscale(100%) !important;
}

/* Ensure portal container is never affected by filters */
#a11y-portal {
    filter: none !important;
    -webkit-filter: none !important;
}

#a11y-portal .a11y-widget {
    filter: none !important;
    -webkit-filter: none !important;
}

/* Link Highlight */
body.a11y-link-highlight a {
    background: #fef08a !important;
    color: #000 !important;
    padding: 2px 4px !important;
    border-radius: 3px !important;
    text-decoration: underline !important;
}

/* Readable Font (Dyslexia-friendly) */
body.a11y-readable-font,
body.a11y-readable-font * {
    font-family: 'OpenDyslexic', 'Comic Sans MS', 'Arial', sans-serif !important;
    letter-spacing: 0.05em !important;
    word-spacing: 0.1em !important;
}

/* Line Height */
body.a11y-line-height-large,
body.a11y-line-height-large * {
    line-height: 1.8 !important;
}

body.a11y-line-height-xlarge,
body.a11y-line-height-xlarge * {
    line-height: 2.2 !important;
}

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

body.a11y-letter-spacing-wider,
body.a11y-letter-spacing-wider * {
    letter-spacing: 0.2em !important;
}

/* Large Cursor */
body.a11y-cursor-large,
body.a11y-cursor-large * {
    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 fill="black" stroke="white" stroke-width="1" d="M5,2 L5,28 L12,21 L18,30 L22,28 L16,19 L26,19 Z"/></svg>'), auto !important;
}

body.a11y-cursor-xlarge,
body.a11y-cursor-xlarge * {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><path fill="black" stroke="white" stroke-width="2" d="M8,3 L8,42 L18,31 L27,45 L33,42 L24,28 L39,28 Z"/></svg>'), auto !important;
}

/* Reduce Motion */
body.a11y-reduce-motion,
body.a11y-reduce-motion * {
    animation: none !important;
    transition: none !important;
}

/* Focus Highlight */
body.a11y-focus-highlight *:focus {
    outline: 4px solid #f59e0b !important;
    outline-offset: 4px !important;
    box-shadow: 0 0 0 8px rgba(245, 158, 11, 0.3) !important;
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */

@media (max-width: 768px) {
    .a11y-widget {
        left: 15px;
        right: auto;
        bottom: 20px; /* Bottom left corner on mobile */
        top: auto;
    }

    .a11y-toggle-btn {
        width: 43.2px !important; /* Reduced by 10% (48px * 0.9) */
        height: 43.2px !important; /* Reduced by 10% (48px * 0.9) */
        border-radius: 50% !important; /* Force circular shape */
        min-width: 43.2px !important; /* Ensure no min-width override */
        min-height: 43.2px !important; /* Ensure no min-height override */
        padding: 0 !important; /* Remove any padding that might cause ellipse */
    }

    .a11y-toggle-btn i {
        font-size: 18px; /* Reduced by 10% (20px * 0.9) */
    }

    .a11y-panel {
        width: calc(100vw - 30px);
        max-width: 360px;
        left: 15px;
        right: 15px;
        bottom: 60px;
        top: 20px;
        max-height: calc(100vh - 80px);
        min-height: auto;
        position: fixed;
        display: flex;
        flex-direction: column;
    }
    
    .a11y-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        min-height: 0;
    }

    .a11y-button-group button {
        min-width: 60px;
        font-size: 0.75rem;
        padding: 0.5rem;
    }

    .a11y-button-group.small button {
        min-width: 50px;
        font-size: 0.7rem;
    }
}

@media (max-width: 400px) {
    .a11y-panel {
        width: calc(100vw - 20px);
        left: -5px;
    }

    .a11y-header h2 {
        font-size: 1rem;
    }

    .a11y-section h3 {
        font-size: 0.85rem;
    }

    .a11y-toggle-item span:first-child {
        font-size: 0.8rem;
    }
}

/* High contrast mode for the widget itself */
@media (prefers-contrast: high) {
    .a11y-toggle-btn {
        border: 3px solid #000;
    }
    
    .a11y-panel {
        border: 2px solid #000;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .a11y-panel {
        animation: none;
    }
    
    .a11y-toggle-btn {
        transition: none;
    }
}
