/* ==========================================================
   EAA Accessibility Widget  –  elstila theme adaptation
   Primary: #009ad0 / #007ab7  |  Font: Ubuntu
   ========================================================== */

/* --- Widget Trigger (Floating Button) --- */
#eaa-trigger {
    position: fixed;
    bottom: 24px;
    left: 20px;
    /* left side so it doesn't clash with chat/scroll buttons */
    width: 52px;
    height: 52px;
    background: linear-gradient(180deg, #009ad0 0%, #007ab7 100%);
    color: #fff;
    border-radius: 50%;
    text-align: center;
    line-height: 52px;
    font-size: 22px;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0, 122, 183, 0.40);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
    user-select: none;
}

#eaa-trigger:hover,
#eaa-trigger:focus {
    transform: scale(1.07);
    box-shadow: 0 6px 16px rgba(0, 122, 183, 0.55);
}

/* --- Main Panel --- */
#eaa-panel {
    display: none;
    /* controlled by CSS — JS only toggles .active class */
    position: fixed;
    bottom: 90px;
    left: -320px;
    width: 290px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    background: #fff;
    border: 2px solid #009ad0;
    border-radius: 6px;
    z-index: 10000;
    opacity: 0;
    box-shadow: 4px 0 20px rgba(0, 122, 183, 0.18);
    font-family: Ubuntu, 'Open Sans', Arial, sans-serif;
    text-align: left;
}

#eaa-panel.active {
    display: block;
    left: 20px;
    opacity: 1;
    transition: left 0.3s ease, opacity 0.3s ease;
}

/* --- Header --- */
.eaa-header {
    /* Solid #007ab7: white text = 4.71:1 — passes WCAG 4.5:1 for normal text */
    background: #007ab7;
    color: #fff;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 4px 4px 0 0;
}

.eaa-header h3 {
    margin: 0;
    font-size: 15px;
    color: #fff !important;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
    font-family: Ubuntu, 'Open Sans', Arial, sans-serif;
}

#eaa-close {
    background: none;
    border: none;
    color: #fff !important;
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
    opacity: 0.85;
    transition: opacity 0.15s;
}

#eaa-close:hover {
    opacity: 1;
}

/* --- Content Area --- */
.eaa-content {
    padding: 10px 12px 12px;
    background: #fff;
}

.eaa-group {
    margin-bottom: 6px;
}

.eaa-group label {
    display: block;
    color: #3a3939;
    font-weight: 700;
    margin-bottom: 3px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* --- Font Resize Buttons (A- / A / A+) --- */
.eaa-buttons {
    display: flex;
    gap: 5px;
    margin-top: 4px;
}

.eaa-buttons button {
    flex: 1;
    padding: 7px 0;
    cursor: pointer;
    background-color: #f0f8fc !important;
    /* #005f8a on #f0f8fc ≈ 5.2:1 — passes WCAG 4.5:1 for normal text */
    color: #005f8a !important;
    border: 1px solid #9fd0e8;
    font-weight: 700;
    font-size: 14px;
    border-radius: 4px;
    transition: background 0.15s, border-color 0.15s;
    font-family: Ubuntu, 'Open Sans', Arial, sans-serif;
}

.eaa-buttons button:hover {
    background-color: #d6eff8 !important;
    border-color: #009ad0;
}

.eaa-buttons button:focus {
    outline: 2px solid #009ad0;
    outline-offset: 1px;
}

/* --- Feature Toggles --- */
.eaa-toggle {
    width: 100%;
    text-align: left;
    background-color: #f9f9f9 !important;
    color: #3a3939 !important;
    border: 1px solid #ddd;
    padding: 7px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-size: 13px;
    border-radius: 4px;
    margin-bottom: 0;
    text-shadow: none !important;
    box-shadow: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    font-family: Ubuntu, 'Open Sans', Arial, sans-serif;
}

.eaa-toggle:hover {
    background-color: #edf6fb !important;
    border-color: #009ad0;
    color: #007ab7 !important;
}

.eaa-toggle:focus {
    outline: 2px solid #009ad0;
    outline-offset: 1px;
}

/* Active state */
.eaa-toggle.active {
    background-color: #e0f3fa !important;
    border-color: #009ad0;
    color: #005f7f !important;
    font-weight: 700;
}

.eaa-toggle .icon {
    margin-right: 10px;
    width: 20px;
    text-align: center;
    font-size: 15px;
    flex-shrink: 0;
}

/* --- Reset Button --- */
.eaa-reset-btn {
    width: 100%;
    background: linear-gradient(180deg, #e0534a 0%, #c9302c 100%) !important;
    color: #fff !important;
    border: none;
    padding: 8px 10px;
    cursor: pointer;
    font-weight: 700;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 12px;
    font-family: Ubuntu, 'Open Sans', Arial, sans-serif;
    transition: opacity 0.15s;
}

.eaa-reset-btn:hover {
    opacity: 0.88;
}

.eaa-reset-btn:focus {
    outline: 2px solid #c9302c;
    outline-offset: 2px;
}

/* --- Divider between groups --- */
.eaa-divider {
    border: none;
    border-top: 1px solid #eee;
    margin: 4px 0;
}

/* ==========================================================
   ACCESSIBILITY MODES  (applied to <body> / <html>)
   ========================================================== */

/* 1. High Contrast
   Apply dark mode to the page but EXPLICITLY restore the panel,
   because :not() with complex selectors is inconsistent across browsers. */
body.eaa-contrast-mode {
    background-color: #000 !important;
    color: #fff !important;
}

body.eaa-contrast-mode * {
    background-color: #000 !important;
    color: #fff !important;
    border-color: #fff !important;
    box-shadow: none !important;
    text-shadow: none !important;
}

body.eaa-contrast-mode img {
    filter: grayscale(100%) contrast(150%);
}

body.eaa-contrast-mode a {
    color: #ffff00 !important;
    text-decoration: underline !important;
}

/* --- Restore the accessibility panel in contrast mode --- */
body.eaa-contrast-mode #eaa-trigger {
    background: linear-gradient(180deg, #009ad0 0%, #007ab7 100%) !important;
    color: #fff !important;
    border-color: #007ab7 !important;
}

body.eaa-contrast-mode #eaa-panel {
    background: #111 !important;
    border-color: #009ad0 !important;
}

body.eaa-contrast-mode .eaa-header {
    background: #007ab7 !important;
}

body.eaa-contrast-mode .eaa-header h3,
body.eaa-contrast-mode #eaa-close {
    color: #fff !important;
    background: transparent !important;
}

body.eaa-contrast-mode .eaa-content {
    background: #111 !important;
}

body.eaa-contrast-mode .eaa-group label {
    color: #e0e0e0 !important;
    background: transparent !important;
}

body.eaa-contrast-mode .eaa-buttons button {
    background: #222 !important;
    color: #fff !important;
    border-color: #009ad0 !important;
}

body.eaa-contrast-mode .eaa-toggle {
    background: #222 !important;
    color: #fff !important;
    border-color: #555 !important;
}

body.eaa-contrast-mode .eaa-toggle:hover {
    background: #333 !important;
    border-color: #009ad0 !important;
}

body.eaa-contrast-mode .eaa-toggle.active {
    background: #003d4f !important;
    border-color: #009ad0 !important;
    color: #7de0ff !important;
}

body.eaa-contrast-mode .eaa-toggle .icon {
    color: inherit !important;
    background: transparent !important;
}

body.eaa-contrast-mode .eaa-reset-btn {
    background: #c9302c !important;
    color: #fff !important;
}

body.eaa-contrast-mode .eaa-divider {
    border-color: #444 !important;
    background: transparent !important;
}

body.eaa-contrast-mode #eaa-panel img {
    filter: none;
}

/* 2. Grayscale
   PROBLEM: filter on body creates a new containing block for position:fixed
   children, so #eaa-panel and #eaa-trigger detach from the viewport.
   SOLUTION: use a ::before pseudo-element overlay with backdrop-filter,
   which desaturates visually without affecting any stacking contexts.
   The accessibility panel sits above the overlay (z-index 10000 > 9990). */
body.eaa-grayscale-mode::before {
    content: '';
    position: fixed;
    inset: 0;
    /* top/right/bottom/left: 0 */
    z-index: 9990;
    /* above page, below eaa-trigger (9999) */
    backdrop-filter: saturate(0%);
    -webkit-backdrop-filter: saturate(0%);
    pointer-events: none;
    /* don't block clicks on the page */
}

/* Fallback for browsers without backdrop-filter (Firefox < 103) */
@supports not (backdrop-filter: saturate(0%)) {
    body.eaa-grayscale-mode {
        filter: grayscale(100%);
        -webkit-filter: grayscale(100%);
    }

    /* Re-attach panel in fallback mode using translateZ hack */
    body.eaa-grayscale-mode #eaa-panel,
    body.eaa-grayscale-mode #eaa-trigger {
        filter: none !important;
        transform: translateZ(0);
    }
}

/* 3. Highlight Links
   Yellow highlight with dark text — WCAG 1.4.3 compliant (#000 on #ffff00 = 19.1:1).
   Uses outline instead of border to avoid layout shift.
   Smooth transition so toggle-on doesn't flash harshly.
   Nav/menu links get a lighter treatment to avoid breaking layout. */
body.eaa-links-mode a {
    background-color: #ffff00 !important;
    color: #000 !important;
    text-decoration: underline !important;
    outline: 2px solid #b8a000 !important;
    /* golden outline, no layout shift */
    outline-offset: 1px;
    border-radius: 2px;
    transition: background 0.15s, color 0.15s !important;
}

body.eaa-links-mode a:hover,
body.eaa-links-mode a:focus {
    background-color: #ffe600 !important;
    /* slightly deeper on hover */
    color: #000 !important;
    text-decoration: underline !important;
}

/* Don't highlight  the accessibility panel's own links */
body.eaa-links-mode #eaa-panel a {
    background-color: transparent !important;
    color: inherit !important;
    outline: none !important;
    text-decoration: none !important;
}

/* 4. Big Cursor
   Covers all interactive element types, not just a, button.
   Uses a proper 48×48 arrow SVG (white fill + black stroke) for high
   visibility on both dark and light backgrounds. */

/* Standard arrow cursor for everything */
body.eaa-cursor-mode,
body.eaa-cursor-mode *:not(#eaa-panel):not(#eaa-panel *) {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M8 4 L8 38 L18 28 L26 44 L31 42 L23 26 L38 26 Z' fill='white' stroke='black' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") 8 4, default !important;
}

/* Pointer cursor for clickable elements */
body.eaa-cursor-mode a,
body.eaa-cursor-mode button,
body.eaa-cursor-mode input[type="button"],
body.eaa-cursor-mode input[type="submit"],
body.eaa-cursor-mode input[type="reset"],
body.eaa-cursor-mode input[type="checkbox"],
body.eaa-cursor-mode input[type="radio"],
body.eaa-cursor-mode select,
body.eaa-cursor-mode label,
body.eaa-cursor-mode [role="button"],
body.eaa-cursor-mode [onclick],
body.eaa-cursor-mode summary {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M8 4 L8 38 L18 28 L26 44 L31 42 L23 26 L38 26 Z' fill='%23009ad0' stroke='black' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") 8 4, pointer !important;
}

/* Text cursor for text inputs */
body.eaa-cursor-mode input[type="text"],
body.eaa-cursor-mode input[type="email"],
body.eaa-cursor-mode input[type="search"],
body.eaa-cursor-mode input[type="number"],
body.eaa-cursor-mode input[type="password"],
body.eaa-cursor-mode input[type="tel"],
body.eaa-cursor-mode input[type="url"],
body.eaa-cursor-mode textarea {
    cursor: text !important;
    /* keep native text cursor for inputs */
}

/* 5. Font Resize — handled entirely by JS (computed px scaling)
   so it works even when the theme hard-codes px font sizes. */

/* 6. Reading Guide line
   A translucent band that follows the mouse vertically.
   Made taller (48px) with a stronger centre highlight so the user's
   eye line is obvious. z-index 9997 keeps it below the panel (10000)
   and the grayscale overlay (9990 — but overlay is pointer-events:none
   so clicks still land on page content). */
body.eaa-reading-mode .eaa-reading-line {
    position: fixed;
    left: 0;
    width: 100%;
    height: 48px;
    /* Gradient: dark edges → bright centre → dark edges */
    background: linear-gradient(to bottom,
            rgba(0, 154, 208, 0.10) 0%,
            rgba(0, 154, 208, 0.28) 35%,
            rgba(0, 154, 208, 0.36) 50%,
            rgba(0, 154, 208, 0.28) 65%,
            rgba(0, 154, 208, 0.10) 100%);
    border-top: 2px solid rgba(0, 122, 183, 0.70);
    border-bottom: 2px solid rgba(0, 122, 183, 0.70);
    pointer-events: none;
    z-index: 9997;
    top: 0;
    /* CSS transition replaced by JS requestAnimationFrame for smoothness */
    will-change: transform;
}

/* --- Mobile adjustments --- */
@media (max-width: 480px) {
    #eaa-panel {
        width: calc(100vw - 20px);
        left: -110vw;
    }

    #eaa-panel.active {
        left: 10px;
    }

    #eaa-trigger {
        bottom: 16px;
        left: 14px;
        width: 46px;
        height: 46px;
        font-size: 20px;
    }
}

/* --- Trigger: flex centering for SVG icon --- */
#eaa-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    /* override the old text line-height trick */
}

#eaa-trigger svg {
    display: block;
    flex-shrink: 0;
}

/* --- 7. Page Reader: element highlight on hover --- */
.eaa-reading-highlight {
    outline: 3px solid #009ad0 !important;
    outline-offset: 2px;
    border-radius: 2px;
    background-color: rgba(0, 154, 208, 0.07) !important;
    transition: outline 0.1s, background-color 0.1s;
}

/* --- 8. Page Reader: toast notification (replaces blocking alert) --- */
#eaa-reader-toast {
    position: fixed;
    bottom: 88px;
    /* just above the trigger button */
    left: 20px;
    max-width: 260px;
    background: #007ab7;
    color: #fff;
    font-family: Ubuntu, 'Open Sans', Arial, sans-serif;
    font-size: 13px;
    line-height: 1.4;
    padding: 10px 14px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 10001;
    animation: eaaToastIn 0.25s ease;
    pointer-events: none;
}

@keyframes eaaToastIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Screen-reader only utility (ARIA live region) --- */
.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;
}

/* ==========================================================
   NEW ACCESSIBILITY MODES
   NOTE: Avoid complex :not() selectors — CSS Level 3 only supports
   simple selectors inside :not(). Instead: apply broadly, then
   explicitly restore the accessibility panel below.
   ========================================================== */

/* 9. Letter Spacing */
body.eaa-spacing-wide * {
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

/* Restore panel */
body.eaa-spacing-wide #eaa-panel *,
body.eaa-spacing-wide #eaa-trigger {
    letter-spacing: normal !important;
    word-spacing: normal !important;
}

/* 10. Line Height */
body.eaa-lh-wide * {
    line-height: 1.8 !important;
}

/* Restore panel */
body.eaa-lh-wide #eaa-panel *,
body.eaa-lh-wide #eaa-trigger {
    line-height: normal !important;
}

/* 11. Dyslexia Font
   Font loaded via JS <link> injection to avoid invalid @import position.
   Falls back to Comic Sans if OpenDyslexic hasn't loaded yet. */
body.eaa-dyslexia-mode * {
    font-family: 'OpenDyslexic', 'Comic Sans MS', cursive !important;
    letter-spacing: 0.05em !important;
    word-spacing: 0.1em !important;
    line-height: 1.6 !important;
}

/* Restore panel */
body.eaa-dyslexia-mode #eaa-panel *,
body.eaa-dyslexia-mode #eaa-trigger {
    font-family: Ubuntu, 'Open Sans', Arial, sans-serif !important;
    letter-spacing: normal !important;
    word-spacing: normal !important;
    line-height: normal !important;
}

/* --- Contrast mode overrides for new buttons --- */
body.eaa-contrast-mode #eaa-spacing-norm,
body.eaa-contrast-mode #eaa-spacing-wide,
body.eaa-contrast-mode #eaa-lh-norm,
body.eaa-contrast-mode #eaa-lh-wide {
    background: #222 !important;
    color: #fff !important;
    border-color: #009ad0 !important;
}

/* ==========================================================
   KEYBOARD FOCUS VISIBILITY (WCAG 2.4.7)
   Shows focus ring ONLY when navigating via keyboard (Tab)
   ========================================================== */
:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 2px solid #009ad0 !important;
    outline-offset: 2px;
}

/* ==========================================================
   SKIP LINK FOR KEYBOARD USERS (WCAG 2.4.1)
   ========================================================== */
.eaa-skip-link {
    position: absolute;
    top: -100px;
    left: 15px;
    background: #007ab7;
    color: #ffffff !important;
    padding: 10px 18px;
    z-index: 100001;
    font-weight: 700;
    font-size: 14px;
    border-radius: 0 0 6px 6px;
    text-decoration: underline;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: top 0.2s ease-in-out;
}

.eaa-skip-link:focus,
.eaa-skip-link:focus-visible {
    top: 0;
    outline: 3px solid #ffff00 !important;
    outline-offset: 1px;
}