/* WCAG 2.1 AA Accessibility Styles */

/* CSS Custom Properties for Accessibility */
:root {
    --a11y-font-size-base: 16px;
    --a11y-zoom-level: 1;
    --a11y-contrast-mode: normal;
    --a11y-cursor-size: normal;
    --a11y-cursor-color: auto;
}

/* Base font size adjustment */
html {
    font-size: var(--a11y-font-size-base);
}

/* Zoom level adjustment */
body {
    zoom: var(--a11y-zoom-level);
    transform-origin: top right; /* For RTL */
}

/* ============================================
   Accessibility Toolbar Styles
   ============================================ */

/* Toggle Button (Fixed Position) */
.a11y-toolbar-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px; /* Right side to avoid WhatsApp button */
    z-index: 10000;
    background: linear-gradient(135deg, #2B3A67 0%, #1a2540 100%);
    color: #FFFFFF;
    border: none;
    border-radius: 50px;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(43, 58, 103, 0.4);
    transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease, visibility 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    direction: rtl;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto !important; /* Always allow clicks */
}

.a11y-toolbar-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(43, 58, 103, 0.5);
    background: linear-gradient(135deg, #1a2540 0%, #2B3A67 100%);
}

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

.a11y-toolbar-toggle__text {
    font-weight: 700;
}

/* Toolbar Container */
.a11y-toolbar {
    position: fixed;
    bottom: 80px;
    right: 20px; /* Right side to match toggle button */
    width: 90%;
    max-width: 900px;
    max-height: 80vh;
    background: #FFFFFF;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    z-index: 10001;
    display: none;
    flex-direction: column;
    overflow: hidden; /* Hidden for desktop, will be overridden for mobile */
    direction: rtl;
}

.a11y-toolbar.show {
    display: flex !important;
}

.a11y-toolbar.dragging {
    user-select: none;
    cursor: move;
}

/* Toolbar Header */
.a11y-toolbar__header {
    background: linear-gradient(135deg, #2B3A67 0%, #1a2540 100%);
    color: #FFFFFF;
    padding: 1rem 1.5rem;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.a11y-toolbar__header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.a11y-toolbar__title {
    font-size: 1.25rem;
    font-weight: 700;
}

.a11y-toolbar__close {
    background: rgba(255, 255, 255, 0.2);
    color: #FFFFFF;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    transition: all 0.2s ease;
}

.a11y-toolbar__close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.a11y-toolbar__close:focus {
    outline: 2px solid #FD891B;
    outline-offset: 2px;
}

.a11y-toolbar__hint {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-top: 0.25rem;
}

/* Toolbar Buttons Grid */
.a11y-toolbar__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    padding: 1.5rem;
    overflow-y: auto;
    max-height: calc(80vh - 120px);
    flex: 1; /* Allow grid to take available space */
    min-height: 0; /* Important for flex scrolling */
}

/* Toolbar Button */
.a11y-toolbar__btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem 0.75rem;
    background: #F8F9FA;
    border: 2px solid #E2E8F0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    font-weight: 600;
    color: #1E293B;
    min-height: 90px;
}

.a11y-toolbar__btn:hover {
    background: #E2E8F0;
    border-color: #2B3A67;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.a11y-toolbar__btn:focus {
    outline: 3px solid #FD891B;
    outline-offset: 2px;
    border-color: #FD891B;
}

.a11y-toolbar__btn.active {
    background: #2B3A67;
    color: #FFFFFF;
    border-color: #2B3A67;
    box-shadow: 0 0 0 3px rgba(43, 58, 103, 0.2);
}

.a11y-toolbar__btn.active::after {
    content: '✓';
    position: absolute;
    top: 4px;
    left: 4px; /* Right side for RTL */
    background: #FD891B;
    color: #FFFFFF;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.a11y-toolbar__btn svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.a11y-toolbar__btn span {
    text-align: center;
    line-height: 1.3;
}

/* ============================================
   Accessibility Features Styles
   ============================================ */

/* High Contrast Mode */
body.a11y-high-contrast {
    background: #000000 !important;
    color: #FFFF00 !important;
}

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

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

body.a11y-high-contrast button,
body.a11y-high-contrast .btn {
    background: #FFFF00 !important;
    color: #000000 !important;
    border: 2px solid #FFFF00 !important;
}

/* Black & Yellow Theme */
body.a11y-black-yellow {
    background: #000000 !important;
    color: #FFD700 !important;
}

body.a11y-black-yellow * {
    background: #000000 !important;
    color: #FFD700 !important;
    border-color: #FFD700 !important;
}

body.a11y-black-yellow a {
    color: #FFD700 !important;
    text-decoration: underline !important;
}

/* Monochrome Filter */
body.a11y-monochrome * {
    filter: grayscale(100%) !important;
}

/* Sepia Filter */
body.a11y-sepia * {
    filter: sepia(100%) !important;
}

/* Invert Colors */
body.a11y-invert * {
    filter: invert(100%) !important;
}

/* Highlight Titles */
body.a11y-highlight-titles h1,
body.a11y-highlight-titles h2,
body.a11y-highlight-titles h3,
body.a11y-highlight-titles h4,
body.a11y-highlight-titles h5,
body.a11y-highlight-titles h6 {
    outline: 3px solid #FD891B !important;
    outline-offset: 2px !important;
    background: rgba(253, 137, 27, 0.1) !important;
    padding: 0.25rem 0.5rem !important;
    border-radius: 4px !important;
}

/* Highlight Links */
body.a11y-highlight-links a {
    outline: 2px solid #2B3A67 !important;
    outline-offset: 2px !important;
    background: rgba(43, 58, 103, 0.1) !important;
    padding: 0.125rem 0.25rem !important;
    border-radius: 2px !important;
    text-decoration: underline !important;
}

/* Readable Fonts */
body.a11y-readable-fonts,
body.a11y-readable-fonts * {
    font-family: Arial, sans-serif !important;
}

/* Large Cursor */
body.a11y-white-cursor * {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32"><circle cx="16" cy="16" r="14" fill="white" stroke="black" stroke-width="2"/></svg>') 16 16, auto !important;
}

body.a11y-black-cursor * {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32"><circle cx="16" cy="16" r="14" fill="black" stroke="white" stroke-width="2"/></svg>') 16 16, auto !important;
}

/* Stop Animations */
body.a11y-stop-blinks *,
body.a11y-stop-blinks *::before,
body.a11y-stop-blinks *::after {
    animation-duration: 0s !important;
    animation-delay: 0s !important;
    transition-duration: 0s !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
}

/* Reader View */
body.a11y-reader-view aside,
body.a11y-reader-view nav:not(.main-nav),
body.a11y-reader-view .sidebar,
body.a11y-reader-view footer:not(.site-footer) {
    display: none !important;
}

body.a11y-reader-view main {
    max-width: 800px !important;
    margin: 0 auto !important;
    padding: 2rem !important;
}

/* Enhanced Focus Indicators */
*:focus-visible {
    outline: 3px solid #FD891B !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(253, 137, 27, 0.2) !important;
}

/* Skip to Main Content Link */
.skip-to-main {
    position: absolute;
    top: -100px;
    left: 0;
    background: #2B3A67;
    color: #FFFFFF;
    padding: 1rem 2rem;
    text-decoration: none;
    font-weight: 700;
    z-index: 10002;
    border-radius: 0 0 8px 0;
}

.skip-to-main:focus {
    top: 0;
    outline: 3px solid #FD891B;
    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-width: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .a11y-toolbar-toggle {
        bottom: 15px;
        right: 15px;
        padding: 10px 16px;
        font-size: 0.875rem;
    }

    .a11y-toolbar {
        bottom: 70px;
        right: 10px;
        left: 10px;
        top: 10px;
        width: calc(100% - 20px);
        max-width: none;
        height: calc(100vh - 80px) !important; /* Force fixed height on mobile */
        max-height: calc(100vh - 80px) !important;
        overflow: hidden;
        /* Don't force display - only show when .show class is present */
        flex-direction: column;
    }

    .a11y-toolbar.show {
        display: flex !important; /* Only show when explicitly opened */
    }

    .a11y-toolbar__header {
        padding: 0.875rem 1rem;
        flex-shrink: 0;
        flex-grow: 0;
    }

    .a11y-toolbar__title {
        font-size: 1.125rem;
    }

    .a11y-toolbar__hint {
        font-size: 0.8125rem;
        margin-top: 0.25rem;
    }

    .a11y-toolbar__grid {
        display: grid !important; /* Force grid display */
        grid-template-columns: repeat(2, 1fr); /* 2 columns on mobile */
        gap: 0.75rem;
        padding: 1rem;
        overflow-y: auto;
        overflow-x: hidden;
        flex: 1 1 0; /* Take remaining space, start from 0 */
        min-height: 0; /* Critical for flex scrolling */
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    .a11y-toolbar__btn {
        min-height: 75px;
        padding: 0.625rem 0.5rem;
        font-size: 0.75rem;
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .a11y-toolbar__btn svg {
        width: 20px;
        height: 20px;
    }

    .a11y-toolbar__btn span {
        font-size: 0.6875rem;
        line-height: 1.2;
    }
}

/* High Contrast Focus for Keyboard Navigation */
body.a11y-keyboard-nav *:focus {
    outline: 4px solid #FD891B !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 6px rgba(253, 137, 27, 0.3) !important;
}

/* Tooltip Styles */
[data-tooltip] {
    position: relative;
}

[data-tooltip]:hover::after,
body.a11y-tooltip-visible [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1E293B;
    color: #FFFFFF;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.875rem;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 0.5rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

[data-tooltip]:hover::before,
body.a11y-tooltip-visible [data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1E293B;
    z-index: 1000;
    margin-bottom: -6px;
}

