/**
 * A11y Engine – Frontend CSS
 * Standardy: WCAG 2.2 (AA/AAA), EN 301 549, EAA
 * Pełna izolacja widgetu od motywów WP, wysoki kontrast i dostępność.
 */

:root {
    --a11y-font-scale: 1;
    --a11y-font-family: inherit;
    --a11y-line-height: normal;
    --a11y-letter-spacing: normal;
    --a11y-word-spacing: normal;
}

/* ==========================================================================
   1. Skip Link (WCAG 2.4.1 Bypass Blocks)
   ========================================================================== */
.a11y-skip-link {
    position: absolute;
    top: -9999px;
    left: 10px;
    z-index: 999999;
    padding: 12px 20px;
    background: #000000 !important;
    color: #ffff00 !important;
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: underline;
    border: 3px solid #ffff00;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    transition: none;
}

.a11y-skip-link:focus,
.a11y-skip-link:focus-visible {
    top: 10px;
    outline: 4px solid #ffffff;
    outline-offset: 2px;
}

/* ==========================================================================
   2. Klasa pomocnicza dla czytników ekranu
   ========================================================================== */
.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;
}

/* ==========================================================================
   3. Skalowanie Tekstu (WCAG 1.4.4 - Zoom do 200%)
   ========================================================================== */
html[data-a11y-scale="125"] { font-size: 125% !important; }
html[data-a11y-scale="150"] { font-size: 150% !important; }
html[data-a11y-scale="175"] { font-size: 175% !important; }
html[data-a11y-scale="200"] { font-size: 200% !important; }

/* ==========================================================================
   4. Typografia i Odstępy Tekstu (WCAG 1.4.12)
   ========================================================================== */
html[data-a11y-dyslexic="true"] body *:not(#a11y-engine-root):not(#a11y-engine-root *) {
    font-family: 'OpenDyslexic', 'Comic Sans MS', 'Trebuchet MS', 'Verdana', sans-serif !important;
}

html[data-a11y-spacing="true"] body *:not(#a11y-engine-root):not(#a11y-engine-root *) {
    line-height: 1.8 !important;
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

/* ==========================================================================
   5. Wyróżnianie Elementów (Linki i Nagłówki)
   ========================================================================== */
html[data-a11y-links="true"] a:not(.a11y-skip-link):not(#a11y-engine-root a) {
    text-decoration: underline 3px solid #d32f2f !important;
    text-underline-offset: 4px !important;
    font-weight: 700 !important;
}

html[data-a11y-headings="true"] h1:not(#a11y-engine-root *),
html[data-a11y-headings="true"] h2:not(#a11y-engine-root *),
html[data-a11y-headings="true"] h3:not(#a11y-engine-root *),
html[data-a11y-headings="true"] h4:not(#a11y-engine-root *),
html[data-a11y-headings="true"] h5:not(#a11y-engine-root *),
html[data-a11y-headings="true"] h6:not(#a11y-engine-root *) {
    outline: 2px dashed #0056b3 !important;
    outline-offset: 4px !important;
    background-color: rgba(255, 235, 59, 0.2) !important;
}

/* ==========================================================================
   6. Wstrzymanie Animacji (WCAG 2.2.2 / 2.3.3)
   ========================================================================== */
html[data-a11y-motion="reduced"] *,
html[data-a11y-motion="reduced"] *::before,
html[data-a11y-motion="reduced"] *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

/* ==========================================================================
   7. Tryby Wysokiego Kontrastu (Pełne pokrycie DOM strony poza widżetem)
   ========================================================================== */

/* 7.1 Żółty na czarnym (WCAG AAA) */
html[data-a11y-contrast="yellow-black"],
html[data-a11y-contrast="yellow-black"] body,
html[data-a11y-contrast="yellow-black"] body *:not(#a11y-engine-root):not(#a11y-engine-root *) {
    background-color: #000000 !important;
    background-image: none !important;
    color: #ffff00 !important;
    border-color: #ffff00 !important;
    box-shadow: none !important;
    text-shadow: none !important;
}

html[data-a11y-contrast="yellow-black"] a:not(#a11y-engine-root):not(#a11y-engine-root *),
html[data-a11y-contrast="yellow-black"] a:not(#a11y-engine-root):not(#a11y-engine-root *) * {
    color: #00ffff !important;
    text-decoration: underline !important;
}

html[data-a11y-contrast="yellow-black"] a:not(#a11y-engine-root):not(#a11y-engine-root *):hover,
html[data-a11y-contrast="yellow-black"] a:not(#a11y-engine-root):not(#a11y-engine-root *):focus {
    color: #ffffff !important;
    background-color: #262626 !important;
}

html[data-a11y-contrast="yellow-black"] img,
html[data-a11y-contrast="yellow-black"] picture,
html[data-a11y-contrast="yellow-black"] video,
html[data-a11y-contrast="yellow-black"] canvas,
html[data-a11y-contrast="yellow-black"] svg:not(#a11y-engine-root svg) {
    background-color: transparent !important;
}

/* 7.2 Ciemny kontrast */
html[data-a11y-contrast="dark"],
html[data-a11y-contrast="dark"] body,
html[data-a11y-contrast="dark"] body *:not(#a11y-engine-root):not(#a11y-engine-root *) {
    background-color: #121212 !important;
    background-image: none !important;
    color: #f3f4f6 !important;
    border-color: #4b5563 !important;
    box-shadow: none !important;
    text-shadow: none !important;
}

html[data-a11y-contrast="dark"] a:not(#a11y-engine-root):not(#a11y-engine-root *),
html[data-a11y-contrast="dark"] a:not(#a11y-engine-root):not(#a11y-engine-root *) * {
    color: #fde047 !important;
    text-decoration: underline !important;
}

html[data-a11y-contrast="dark"] a:not(#a11y-engine-root):not(#a11y-engine-root *):hover,
html[data-a11y-contrast="dark"] a:not(#a11y-engine-root):not(#a11y-engine-root *):focus {
    color: #ffffff !important;
    background-color: #1f2937 !important;
}

html[data-a11y-contrast="dark"] img,
html[data-a11y-contrast="dark"] picture,
html[data-a11y-contrast="dark"] video,
html[data-a11y-contrast="dark"] canvas,
html[data-a11y-contrast="dark"] svg:not(#a11y-engine-root svg) {
    background-color: transparent !important;
}

/* 7.3 Odwrócone kolory (Inwersja) */
html[data-a11y-contrast="invert"] {
    filter: invert(100%) hue-rotate(180deg) !important;
}
html[data-a11y-contrast="invert"] img,
html[data-a11y-contrast="invert"] video,
html[data-a11y-contrast="invert"] picture,
html[data-a11y-contrast="invert"] svg,
html[data-a11y-contrast="invert"] canvas,
html[data-a11y-contrast="invert"] #a11y-engine-root {
    filter: invert(100%) hue-rotate(180deg) !important;
}

/* 7.4 Skala szarości */
html[data-a11y-contrast="grayscale"] {
    filter: grayscale(100%) !important;
}

/* ==========================================================================
   8. Toolbar UI (Kompletna izolacja, stały wysoki kontrast elementów)
   ========================================================================== */
#a11y-engine-root {
    position: fixed;
    z-index: 999998;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
    font-size: 15px !important;
    line-height: 1.5 !important;
    color: #0f172a !important;
}

#a11y-engine-root * {
    box-sizing: border-box !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
    text-transform: none !important;
    letter-spacing: normal !important;
}

/* Pozycjonowanie w rogach ekranu */
#a11y-engine-root.a11y-pos-bottom-right { bottom: 24px; right: 24px; }
#a11y-engine-root.a11y-pos-bottom-left  { bottom: 24px; left: 24px; }
#a11y-engine-root.a11y-pos-top-right    { top: 24px; right: 24px; }
#a11y-engine-root.a11y-pos-top-left     { top: 24px; left: 24px; }

/* Przycisk otwierający widżet */
#a11y-engine-root .a11y-toggle-btn {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    background-color: #00457c !important;
    color: #ffffff !important;
    border: 2px solid #ffffff !important;
    border-radius: 50px !important;
    padding: 10px 18px !important;
    cursor: pointer !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3) !important;
    font-weight: 700 !important;
    font-size: 15px !important;
    transition: background-color 0.2s ease, transform 0.15s ease !important;
}

#a11y-engine-root .a11y-toggle-btn:hover {
    background-color: #002e54 !important;
    color: #ffffff !important;
    transform: scale(1.03);
}

#a11y-engine-root button:focus-visible {
    outline: 3px solid #005fcc !important;
    outline-offset: 3px !important;
}

/* Okno dialogowe paska */
#a11y-engine-root .a11y-dialog {
    display: flex !important;
    flex-direction: column !important;
    position: absolute !important;
    width: 360px !important;
    max-width: calc(100vw - 32px) !important;
    max-height: 80vh !important;
    background-color: #ffffff !important;
    color: #0f172a !important;
    border: 2px solid #00457c !important;
    border-radius: 12px !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35) !important;
    overflow: hidden !important;
}

#a11y-engine-root.a11y-pos-bottom-right .a11y-dialog { bottom: 60px; right: 0; }
#a11y-engine-root.a11y-pos-bottom-left  .a11y-dialog { bottom: 60px; left: 0; }
#a11y-engine-root.a11y-pos-top-right    .a11y-dialog { top: 60px; right: 0; }
#a11y-engine-root.a11y-pos-top-left     .a11y-dialog { top: 60px; left: 0; }

#a11y-engine-root .a11y-dialog[hidden] {
    display: none !important;
}

/* Nagłówek okna */
#a11y-engine-root .a11y-dialog-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    background-color: #00457c !important;
    color: #ffffff !important;
    padding: 14px 18px !important;
    border-bottom: 1px solid #002e54 !important;
}

#a11y-engine-root .a11y-dialog-title {
    margin: 0 !important;
    font-size: 1.15rem !important;
    font-weight: 700 !important;
    color: #ffffff !important;
}

#a11y-engine-root .a11y-close-btn {
    background: transparent !important;
    border: 1px solid rgba(255, 255, 255, 0.5) !important;
    border-radius: 4px !important;
    color: #ffffff !important;
    font-size: 24px !important;
    line-height: 1 !important;
    width: 32px !important;
    height: 32px !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

#a11y-engine-root .a11y-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* Ciało dialogu */
#a11y-engine-root .a11y-dialog-body {
    padding: 16px !important;
    overflow-y: auto !important;
    max-height: calc(80vh - 120px) !important;
    background-color: #ffffff !important;
}

#a11y-engine-root .a11y-group {
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    padding: 12px !important;
    margin: 0 0 14px 0 !important;
    background-color: #ffffff !important;
}

#a11y-engine-root .a11y-group-title {
    font-weight: 700 !important;
    font-size: 14px !important;
    padding: 0 6px !important;
    color: #00457c !important;
    background-color: #ffffff !important;
}

/* 8.1 Siatka przycisków wyboru kontrastu */
#a11y-engine-root .a11y-button-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
}

#a11y-engine-root .a11y-opt-btn {
    padding: 9px 10px !important;
    border: 1.5px solid #cbd5e1 !important;
    background-color: #f8fafc !important;
    color: #0f172a !important;
    border-radius: 6px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    text-align: center !important;
    transition: all 0.15s ease !important;
}

#a11y-engine-root .a11y-opt-btn:hover {
    background-color: #e2e8f0 !important;
    color: #00457c !important;
    border-color: #00457c !important;
}

#a11y-engine-root .a11y-opt-btn[aria-pressed="true"] {
    background-color: #00457c !important;
    color: #ffffff !important;
    border-color: #00457c !important;
    font-weight: 700 !important;
}

#a11y-engine-root .a11y-opt-btn[aria-pressed="true"]:hover {
    background-color: #002e54 !important;
    color: #ffffff !important;
}

/* 8.2 Przyciski powiększania tekstu */
#a11y-engine-root .a11y-scale-controls {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px !important;
}

#a11y-engine-root .a11y-scale-btn {
    flex: 1 !important;
    padding: 10px !important;
    background-color: #f1f5f9 !important;
    color: #0f172a !important;
    border: 2px solid #94a3b8 !important;
    border-radius: 6px !important;
    font-size: 17px !important;
    font-weight: 800 !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    transition: all 0.15s ease !important;
}

#a11y-engine-root .a11y-scale-btn * {
    color: inherit !important;
}

#a11y-engine-root .a11y-scale-btn:hover {
    background-color: #00457c !important;
    color: #ffffff !important;
    border-color: #00457c !important;
}

#a11y-engine-root .a11y-scale-value {
    font-size: 1.2rem !important;
    font-weight: 800 !important;
    min-width: 60px !important;
    text-align: center !important;
    color: #0f172a !important;
}

/* 8.3 Przełączniki funkcji pionowych */
#a11y-engine-root .a11y-toggle-stack {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
}

#a11y-engine-root .a11y-switch-btn {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    padding: 10px 12px !important;
    border: 1.5px solid #cbd5e1 !important;
    background-color: #ffffff !important;
    color: #0f172a !important;
    border-radius: 6px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    text-align: left !important;
    transition: all 0.15s ease !important;
}

#a11y-engine-root .a11y-switch-btn span:last-child {
    color: #0f172a !important;
}

#a11y-engine-root .a11y-switch-btn:hover {
    background-color: #f1f5f9 !important;
    border-color: #00457c !important;
}

#a11y-engine-root .a11y-switch-btn:hover span:last-child {
    color: #00457c !important;
}

#a11y-engine-root .a11y-switch-indicator {
    width: 20px !important;
    height: 20px !important;
    border: 2px solid #475569 !important;
    border-radius: 4px !important;
    background-color: #ffffff !important;
    display: inline-block !important;
    position: relative !important;
    flex-shrink: 0 !important;
}

#a11y-engine-root .a11y-switch-btn[aria-pressed="true"] {
    background-color: #e0f2fe !important;
    border-color: #0284c7 !important;
}

#a11y-engine-root .a11y-switch-btn[aria-pressed="true"] span:last-child {
    color: #0369a1 !important;
    font-weight: 700 !important;
}

#a11y-engine-root .a11y-switch-btn[aria-pressed="true"] .a11y-switch-indicator {
    background-color: #0284c7 !important;
    border-color: #0284c7 !important;
}

#a11y-engine-root .a11y-switch-btn[aria-pressed="true"] .a11y-switch-indicator::after {
    content: "" !important;
    position: absolute !important;
    top: 2px !important;
    left: 6px !important;
    width: 5px !important;
    height: 10px !important;
    border: solid #ffffff !important;
    border-width: 0 2.5px 2.5px 0 !important;
    transform: rotate(45deg) !important;
}

/* 8.4 Stopka dialogu i Reset */
#a11y-engine-root .a11y-dialog-footer {
    padding: 12px 16px !important;
    background-color: #f8fafc !important;
    border-top: 1px solid #cbd5e1 !important;
}

#a11y-engine-root .a11y-reset-btn {
    width: 100% !important;
    padding: 10px !important;
    background-color: #dc2626 !important;
    color: #ffffff !important;
    border: 2px solid #b91c1c !important;
    border-radius: 6px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    transition: background-color 0.15s ease !important;
}

#a11y-engine-root .a11y-reset-btn:hover {
    background-color: #b91c1c !important;
    color: #ffffff !important;
    border-color: #991b1b !important;
}
