/* ====================================================
   Accessibility Widget - Andrea Berni
   Standalone CSS - no framework dependencies
   ==================================================== */

/* ---- Variables ---- */
:root {
    --a11y-panel-bg: #ffffff;
    --a11y-panel-border: #e2e8f0;
    --a11y-text: #1e293b;
    --a11y-text-muted: #64748b;
    --a11y-accent: #4f46e5;
    --a11y-accent-light: #eef2ff;
    --a11y-active: #4f46e5;
    --a11y-active-text: #ffffff;
    --a11y-radius: 12px;
    --a11y-transition: 0.2s ease;
}

/* ---- Hidden utility ---- */
.a11y-hidden { display: none !important; }

/* ============================================
   TAB BUTTON (side of screen)
   ============================================ */
#a11y-toggle {
    position: fixed;
    z-index: 99998;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 6px;
    border: none;
    color: #fff;
    cursor: pointer;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.05em;
    box-shadow: -2px 0 8px rgba(0,0,0,0.12);
    transition: all var(--a11y-transition);
}
#a11y-toggle:hover { padding-right: 10px; box-shadow: -4px 0 16px rgba(0,0,0,0.18); }
#a11y-toggle:focus-visible { outline: 3px solid var(--a11y-accent); outline-offset: 3px; }

.a11y-icon { width: 20px; height: 20px; }

#a11y-toggle.a11y-btn-large { padding: 14px 8px; font-size: 14px; }
#a11y-toggle.a11y-btn-large .a11y-icon { width: 24px; height: 24px; }

.a11y-btn-label { white-space: nowrap; }

/* Positions */
.a11y-pos-right #a11y-toggle {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 8px 0 0 8px;
}
.a11y-pos-left #a11y-toggle {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 0 8px 8px 0;
}

/* Always show label on tab style */
#a11y-toggle .a11y-btn-label { display: block; }

/* ============================================
   OVERLAY
   ============================================ */
#a11y-overlay {
    position: fixed;
    inset: 0;
    z-index: 99998;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(2px);
    transition: opacity var(--a11y-transition);
}
#a11y-overlay.a11y-visible { display: block !important; }

/* ============================================
   PANEL
   ============================================ */
#a11y-panel {
    position: fixed;
    z-index: 99999;
    top: 0;
    width: 340px;
    max-width: 90vw;
    height: 100vh;
    background: var(--a11y-panel-bg);
    box-shadow: -4px 0 24px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow: hidden;
}
#a11y-panel.a11y-panel-wide { width: 420px; }

.a11y-pos-right #a11y-panel { right: 0; transform: translateX(100%); }
.a11y-pos-left #a11y-panel { left: 0; transform: translateX(-100%); }
#a11y-panel.a11y-visible { display: flex !important; transform: translateX(0) !important; }

/* Header */
.a11y-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--a11y-panel-border);
    flex-shrink: 0;
}
.a11y-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 700;
    color: var(--a11y-text);
    margin: 0;
}
.a11y-title-icon { width: 22px; height: 22px; color: var(--a11y-accent); }

.a11y-header-actions { display: flex; align-items: center; gap: 6px; }

.a11y-reset-btn, .a11y-close-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: 1px solid var(--a11y-panel-border);
    border-radius: 8px;
    background: transparent;
    color: var(--a11y-text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--a11y-transition);
}
.a11y-reset-btn:hover, .a11y-close-btn:hover { background: #f8fafc; color: var(--a11y-text); }
.a11y-action-icon { width: 16px; height: 16px; }

/* Body */
.a11y-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px 24px;
}

/* Sections */
.a11y-section {
    margin-bottom: 20px;
}
.a11y-section:last-child { margin-bottom: 0; }

.a11y-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--a11y-text-muted);
    margin: 0 0 10px 0;
}

/* ============================================
   TEXT SIZE CONTROLS
   ============================================ */
.a11y-size-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
}
.a11y-size-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--a11y-panel-border);
    border-radius: 10px;
    background: #fff;
    font-size: 16px;
    font-weight: 700;
    color: var(--a11y-text);
    cursor: pointer;
    transition: all var(--a11y-transition);
}
.a11y-size-btn:hover { background: var(--a11y-accent-light); border-color: var(--a11y-accent); color: var(--a11y-accent); }
.a11y-size-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--a11y-text);
    min-width: 50px;
    text-align: center;
}

/* ============================================
   TOGGLE BUTTONS
   ============================================ */
.a11y-toggles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.a11y-toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--a11y-panel-border);
    border-radius: 10px;
    background: #fff;
    font-size: 13px;
    color: var(--a11y-text);
    cursor: pointer;
    transition: all var(--a11y-transition);
    text-align: left;
}
.a11y-toggle-btn:hover { border-color: var(--a11y-accent); background: var(--a11y-accent-light); }
.a11y-toggle-btn.a11y-active {
    background: var(--a11y-active);
    border-color: var(--a11y-active);
    color: var(--a11y-active-text);
}
.a11y-toggle-btn.a11y-active .a11y-feat-icon { color: var(--a11y-active-text); }

.a11y-feat-icon { width: 20px; height: 20px; flex-shrink: 0; color: var(--a11y-text-muted); }

/* ============================================
   BODY CLASS EFFECTS
   ============================================ */

/* Text size - zoom approach, works with any CSS framework */
body.a11y-text-110 #a11y-invert-wrapper { zoom: 1.1; }
body.a11y-text-120 #a11y-invert-wrapper { zoom: 1.2; }
body.a11y-text-130 #a11y-invert-wrapper { zoom: 1.3; }
body.a11y-text-140 #a11y-invert-wrapper { zoom: 1.4; }

/* Fallback for Firefox (no zoom support) */
@supports not (zoom: 1.1) {
    body.a11y-text-110 #a11y-invert-wrapper { transform: scale(1.1); transform-origin: top left; width: calc(100% / 1.1); }
    body.a11y-text-120 #a11y-invert-wrapper { transform: scale(1.2); transform-origin: top left; width: calc(100% / 1.2); }
    body.a11y-text-130 #a11y-invert-wrapper { transform: scale(1.3); transform-origin: top left; width: calc(100% / 1.3); }
    body.a11y-text-140 #a11y-invert-wrapper { transform: scale(1.4); transform-origin: top left; width: calc(100% / 1.4); }
}

/* High contrast - only affects content wrapper, excludes SVG internals */
body.a11y-high-contrast #a11y-invert-wrapper *:not(svg):not(svg *) {
    color: #000 !important;
    background-color: #fff !important;
    border-color: #000 !important;
}
body.a11y-high-contrast #a11y-invert-wrapper a:not(svg a) {
    color: #0000ee !important;
    text-decoration: underline !important;
}
body.a11y-high-contrast #a11y-invert-wrapper img { filter: contrast(1.5) !important; }
body.a11y-high-contrast #a11y-invert-wrapper svg { background-color: transparent !important; }

/* Inverted contrast - applied to a wrapper, widget stays outside */
body.a11y-inverted-contrast #a11y-invert-wrapper {
    filter: invert(1) hue-rotate(180deg);
}
body.a11y-inverted-contrast #a11y-invert-wrapper img,
body.a11y-inverted-contrast #a11y-invert-wrapper video {
    filter: invert(1) hue-rotate(180deg);
}
#a11y-invert-wrapper { min-height: 100vh; }

/* Highlight links - only content */
body.a11y-highlight-links #a11y-invert-wrapper a {
    outline: 2px solid #f59e0b !important;
    outline-offset: 2px;
    text-decoration: underline !important;
    background-color: rgba(245, 158, 11, 0.1) !important;
}

/* Readable font - only content */
body.a11y-readable-font #a11y-invert-wrapper,
body.a11y-readable-font #a11y-invert-wrapper * {
    font-family: Arial, Helvetica, sans-serif !important;
    letter-spacing: 0.03em !important;
}

/* Text spacing - only content */
body.a11y-text-spacing #a11y-invert-wrapper,
body.a11y-text-spacing #a11y-invert-wrapper * {
    line-height: 2 !important;
    letter-spacing: 0.1em !important;
    word-spacing: 0.2em !important;
}

/* Hide images - only img, video and background-images. Keep inline SVGs visible */
body.a11y-hide-images #a11y-invert-wrapper img,
body.a11y-hide-images #a11y-invert-wrapper video,
body.a11y-hide-images #a11y-invert-wrapper [style*="background-image"] {
    opacity: 0.05 !important;
}

/* Keyboard focus - enhanced visibility for all interactive elements */
body.a11y-keyboard-focus #a11y-invert-wrapper a,
body.a11y-keyboard-focus #a11y-invert-wrapper button,
body.a11y-keyboard-focus #a11y-invert-wrapper input,
body.a11y-keyboard-focus #a11y-invert-wrapper select,
body.a11y-keyboard-focus #a11y-invert-wrapper textarea,
body.a11y-keyboard-focus #a11y-invert-wrapper [tabindex] {
    outline: 2px dashed rgba(245, 158, 11, 0.4) !important;
    outline-offset: 2px !important;
}
body.a11y-keyboard-focus #a11y-invert-wrapper *:focus,
body.a11y-keyboard-focus #a11y-invert-wrapper *:focus-visible {
    outline: 3px solid #f59e0b !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.3) !important;
}

/* Big cursor */
body.a11y-big-cursor,
body.a11y-big-cursor * {
    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 8l14 34 4.5-13.5L40 24z' fill='%23000' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 8 8, auto !important;
}

/* Reading guide */
#a11y-reading-guide-bar {
    position: fixed;
    left: 0;
    width: 100%;
    height: 12px;
    background: rgba(79, 70, 229, 0.15);
    border-top: 2px solid rgba(79, 70, 229, 0.4);
    border-bottom: 2px solid rgba(79, 70, 229, 0.4);
    pointer-events: none;
    z-index: 99997;
    transition: top 0.05s linear;
}
#a11y-reading-guide-bar.a11y-visible { display: block !important; }

/* Stop animations - exclude widget */
body.a11y-stop-animations #a11y-invert-wrapper,
body.a11y-stop-animations #a11y-invert-wrapper *,
body.a11y-stop-animations #a11y-invert-wrapper *::before,
body.a11y-stop-animations #a11y-invert-wrapper *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
}

/* Color blind filters - only on content wrapper */
body.a11y-protanopia #a11y-invert-wrapper { filter: url('#a11y-protanopia-filter') !important; }
body.a11y-deuteranopia #a11y-invert-wrapper { filter: url('#a11y-deuteranopia-filter') !important; }
body.a11y-tritanopia #a11y-invert-wrapper { filter: url('#a11y-tritanopia-filter') !important; }

/* ============================================
   TOAST NOTIFICATION
   ============================================ */
.a11y-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 100000;
    padding: 10px 20px;
    border-radius: 10px;
    background: #1e293b;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
    visibility: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}
.a11y-toast.a11y-toast-visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Screen reader only - invisible but accessible */
.a11y-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;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 640px) {
    #a11y-panel { width: 100%; max-width: 100%; }
    .a11y-toggles { grid-template-columns: 1fr; }
    #a11y-toggle { font-size: 11px; padding: 8px 5px; }
}
