/* ==========================================================================
   WCAG Accessibility Toolkit - Frontend Widget
   ========================================================================== */

/* ==========================================================================
   Skip link
   ========================================================================== */
.wcag-skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1565C0;
    color: #fff !important;
    padding: 12px 24px;
    border-radius: 0 0 8px 8px;
    font-size: 16px;
    font-weight: 600;
    z-index: 999999;
    text-decoration: none;
    transition: top 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.wcag-skip-link:focus {
    top: 0;
    outline: 3px solid #FFC107;
    outline-offset: 2px;
}

/* ==========================================================================
   Widget container — izolacja od zmian dostępności
   ========================================================================== */
.wcag-widget {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    letter-spacing: normal !important;
    text-align: left !important;
    -webkit-font-smoothing: antialiased;
}

#wcag-toolkit-widget,
#wcag-toolkit-widget *,
#wcag-toolkit-widget *::before,
#wcag-toolkit-widget *::after {
    filter: none !important;
    text-align: left !important;
}

.wcag-widget--hide-mobile {
    /* Ukryte na mobilnych */
}

@media (max-width: 768px) {
    .wcag-widget--hide-mobile {
        display: none !important;
    }
}

/* ==========================================================================
   Trigger button
   ========================================================================== */
.wcag-widget__trigger {
    border: none;
    border-radius: 50%;
    cursor: pointer !important;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    z-index: 2;
    outline: none;
    padding: 0;
}

.wcag-widget__trigger:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.wcag-widget__trigger:focus-visible {
    outline: 3px solid #FFC107;
    outline-offset: 3px;
}

.wcag-widget--animated .wcag-widget__trigger {
    animation: wcagPulse 3s ease-in-out infinite;
}

.wcag-widget__trigger[aria-expanded="true"] {
    animation: none;
}

@keyframes wcagPulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); }
    50% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 0 0 8px rgba(21, 101, 192, 0.15); }
}

/* ==========================================================================
   Panel
   ========================================================================== */
.wcag-widget__panel {
    position: absolute;
    width: 360px;
    max-height: 80vh;
    background: #FFFFFF !important;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 8px 20px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.9) translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
    z-index: 1;
    color: #1A1A2E !important;
}

.wcag-widget__panel.wcag-panel--open {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

/* Panel position relative to widget */
.wcag-widget--bottom-right .wcag-widget__panel {
    bottom: calc(100% + 12px);
    right: 0;
}

.wcag-widget--bottom-left .wcag-widget__panel {
    bottom: calc(100% + 12px);
    left: 0;
}

.wcag-widget--top-right .wcag-widget__panel {
    top: calc(100% + 12px);
    right: 0;
}

.wcag-widget--top-left .wcag-widget__panel {
    top: calc(100% + 12px);
    left: 0;
}

/* ======================================================================
   Mobile: panel jako bottom-sheet na pełną szerokość ekranu.
   position:fixed żeby nie zależeć od pozycji widgetu.
   ====================================================================== */
@media (max-width: 600px) {
    .wcag-widget__panel {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-height: 85vh !important;
        border-radius: 20px 20px 0 0 !important;
        transform: translateY(100%) !important;
        opacity: 1 !important;
        visibility: hidden !important;
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.35s !important;
    }

    .wcag-widget__panel.wcag-panel--open {
        transform: translateY(0) !important;
        visibility: visible !important;
    }

    /* Drag handle na górze bottom-sheet */
    .wcag-panel__header::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #D0D0D0;
        border-radius: 2px;
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
    }

    .wcag-panel__header {
        position: relative;
        padding-top: 22px !important;
    }

    /* Body panelu — scroll na mobile */
    .wcag-panel__body {
        max-height: calc(85vh - 80px) !important;
        padding: 8px 16px 20px !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Narzędzia — pełna szerokość, czytelne na mobile */
    .wcag-tool {
        padding: 10px 4px !important;
    }

    .wcag-tool__label {
        font-size: 14px !important;
    }

    /* Przyciski opcji — lepszy rozmiar na dotyk (min 44px target) */
    .wcag-btn--option,
    .wcag-btn--step {
        min-height: 40px !important;
        min-width: 40px !important;
        font-size: 13px !important;
    }

    /* Backdrop — przyciemnienie za panelem */
    .wcag-widget__panel.wcag-panel--open::after {
        content: '';
        position: fixed;
        top: -100vh;
        left: 0;
        width: 100vw;
        height: 200vh;
        background: rgba(0, 0, 0, 0.4);
        z-index: -1;
        pointer-events: none;
    }
}

/* ==========================================================================
   Panel header
   ========================================================================== */
.wcag-panel__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
}

.wcag-panel__header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.wcag-panel__title {
    flex: 1;
    font-size: 17px !important;
    font-weight: 700;
    margin: 0;
    padding: 0;
    letter-spacing: -0.01em !important;
}

.wcag-panel__close {
    background: none !important;
    border: none !important;
    cursor: pointer !important;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
}

.wcag-panel__close:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15) !important;
}

.wcag-panel__close:focus-visible {
    outline: 2px solid #FFC107;
    outline-offset: 2px;
}

/* ==========================================================================
   Panel body
   ========================================================================== */
.wcag-panel__body {
    overflow-y: auto;
    max-height: calc(80vh - 60px);
    padding: 8px 14px 14px;
    background: #FFFFFF !important;
}

.wcag-panel__body::-webkit-scrollbar {
    width: 5px;
}

.wcag-panel__body::-webkit-scrollbar-track {
    background: transparent;
}

.wcag-panel__body::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

/* ==========================================================================
   Tool item
   ========================================================================== */
.wcag-tool {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 6px;
    background: #F8FAFC !important;
    border: 1px solid transparent;
    transition: border-color 0.2s, background 0.2s;
    color: #334155 !important;
}

.wcag-tool:hover {
    background: #F0F7FF !important;
    border-color: #DBEAFE !important;
}

.wcag-tool__header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.wcag-tool__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--wcag-primary, #1565C0) !important;
    flex-shrink: 0;
}

.wcag-tool__label {
    font-size: 13px !important;
    font-weight: 600;
    color: #334155 !important;
}

/* Toggle variant */
.wcag-tool--toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
}

.wcag-tool--toggle .wcag-tool__header {
    margin-bottom: 0;
}

/* ==========================================================================
   Controls: Stepper
   ========================================================================== */
.wcag-tool__controls--stepper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wcag-tool__value {
    font-size: 13px !important;
    font-weight: 700;
    color: var(--wcag-primary, #1565C0) !important;
    min-width: 44px;
    text-align: center !important;
}

/* ==========================================================================
   Controls: Options
   ========================================================================== */
.wcag-tool__controls--options {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.wcag-btn {
    border: none;
    cursor: pointer !important;
    font-family: inherit;
    transition: all 0.2s ease;
    outline: none;
}

.wcag-btn:focus-visible {
    outline: 2px solid #1565C0;
    outline-offset: 2px;
}

.wcag-btn--step {
    width: 36px;
    height: 32px;
    border-radius: 8px;
    background: #FFFFFF !important;
    border: 1px solid #E2E8F0 !important;
    color: #334155 !important;
    font-size: 14px !important;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wcag-btn--step:hover {
    background: var(--wcag-primary, #1565C0) !important;
    color: #FFFFFF !important;
    border-color: var(--wcag-primary, #1565C0) !important;
}

.wcag-btn--option {
    padding: 6px 12px;
    border-radius: 7px;
    background: #FFFFFF !important;
    border: 1px solid #E2E8F0 !important;
    color: #64748B !important;
    font-size: 12px !important;
    font-weight: 600;
}

.wcag-btn--option:hover {
    border-color: var(--wcag-primary, #1565C0) !important;
    color: var(--wcag-primary, #1565C0) !important;
}

.wcag-btn--option.wcag-btn--active {
    background: var(--wcag-primary, #1565C0) !important;
    color: #FFFFFF !important;
    border-color: var(--wcag-primary, #1565C0) !important;
}

.wcag-btn--reset {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    background: #FEF2F2 !important;
    color: #DC2626 !important;
    font-size: 13px !important;
    font-weight: 600;
    border: 1px solid #FECACA !important;
}

.wcag-btn--reset:hover {
    background: #DC2626 !important;
    color: #FFFFFF !important;
}

.wcag-btn--statement {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    background: #F0F7FF !important;
    color: var(--wcag-primary, #1565C0) !important;
    font-size: 13px !important;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid #DBEAFE !important;
}

.wcag-btn--statement:hover {
    background: #DBEAFE !important;
}

/* ==========================================================================
   Toggle switch (frontend)
   ========================================================================== */
.wcag-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.wcag-switch__input {
    opacity: 0;
    width: 0;
    height: 0;
}

.wcag-switch__slider {
    position: absolute;
    cursor: pointer !important;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #CBD5E1 !important;
    border-radius: 22px;
    transition: 0.3s;
}

.wcag-switch__slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white !important;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.wcag-switch__input:checked + .wcag-switch__slider {
    background-color: var(--wcag-primary, #1565C0) !important;
}

.wcag-switch__input:checked + .wcag-switch__slider:before {
    transform: translateX(18px);
}

.wcag-switch__input:focus-visible + .wcag-switch__slider {
    outline: 2px solid #1565C0;
    outline-offset: 2px;
}

/* ==========================================================================
   Panel sections
   ========================================================================== */
.wcag-panel__toggles {
    margin-top: 4px;
}

.wcag-panel__statement {
    margin-top: 10px;
}

.wcag-panel__footer {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #E2E8F0 !important;
}

/* ==========================================================================
   Reading guide
   ========================================================================== */
.wcag-reading-guide {
    display: none;
    position: fixed;
    left: 0;
    width: 100%;
    height: 12px;
    background: rgba(21, 101, 192, 0.12);
    border-top: 2px solid rgba(21, 101, 192, 0.5);
    border-bottom: 2px solid rgba(21, 101, 192, 0.5);
    z-index: 999998;
    pointer-events: none;
    transition: top 0.05s linear;
}

.wcag-reading-guide--active {
    display: block;
}

/* ==========================================================================
   Accessibility modifications applied to page
   UWAGA: Selektory wykluczają widget (#wcag-toolkit-widget)
   ========================================================================== */

/* Dyslexia font */
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff') format('woff');
    font-weight: normal;
    font-display: swap;
}

body.wcag-dyslexia-font *:not(#wcag-toolkit-widget):not(#wcag-toolkit-widget *) {
    font-family: 'OpenDyslexic', 'Comic Sans MS', cursive, sans-serif !important;
}

/* Highlight links */
body.wcag-highlight-links a:not(#wcag-toolkit-widget a) {
    outline: 3px solid #FFC107 !important;
    outline-offset: 2px !important;
    text-decoration: underline !important;
    background-color: rgba(255, 193, 7, 0.1) !important;
}

/* Big cursor */
body.wcag-big-cursor,
body.wcag-big-cursor *:not(#wcag-toolkit-widget):not(#wcag-toolkit-widget *) {
    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 4l28 20H20l12 16-4 2-12-16-8 12z' fill='%23000' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 4 4, auto !important;
}

/* Hide images */
body.wcag-hide-images img:not(#wcag-toolkit-widget img),
body.wcag-hide-images svg:not(#wcag-toolkit-widget svg),
body.wcag-hide-images video,
body.wcag-hide-images [role="img"],
body.wcag-hide-images picture {
    opacity: 0.05 !important;
}

/* Stop animations */
body.wcag-stop-animations *:not(#wcag-toolkit-widget):not(#wcag-toolkit-widget *) {
    animation: none !important;
    transition: none !important;
}

/* High contrast — filter na WRAPPERZE, nie na body!
   Gdyby filter był na body, łamie position:fixed widgetu. */
body.wcag-contrast-high #wcag-page-wrapper {
    filter: contrast(1.5) !important;
}

body.wcag-contrast-inverted #wcag-page-wrapper {
    filter: invert(1) hue-rotate(180deg) !important;
}

body.wcag-contrast-inverted #wcag-page-wrapper img,
body.wcag-contrast-inverted #wcag-page-wrapper video,
body.wcag-contrast-inverted #wcag-page-wrapper picture {
    filter: invert(1) hue-rotate(180deg) !important;
}

/* Dark mode — BEZ gwiazdki *, targetujemy konkretne elementy */
body.wcag-contrast-dark {
    background-color: #1a1a2e !important;
    color: #e0e0e0 !important;
}

body.wcag-contrast-dark p,
body.wcag-contrast-dark span,
body.wcag-contrast-dark div:not(#wcag-toolkit-widget):not(#wcag-toolkit-widget *),
body.wcag-contrast-dark section,
body.wcag-contrast-dark article,
body.wcag-contrast-dark header:not(#wcag-toolkit-widget *),
body.wcag-contrast-dark footer,
body.wcag-contrast-dark main,
body.wcag-contrast-dark aside,
body.wcag-contrast-dark nav,
body.wcag-contrast-dark h1, body.wcag-contrast-dark h2,
body.wcag-contrast-dark h3, body.wcag-contrast-dark h4,
body.wcag-contrast-dark h5, body.wcag-contrast-dark h6,
body.wcag-contrast-dark li, body.wcag-contrast-dark ul, body.wcag-contrast-dark ol,
body.wcag-contrast-dark td, body.wcag-contrast-dark th, body.wcag-contrast-dark table {
    background-color: #1a1a2e !important;
    color: #e0e0e0 !important;
    border-color: #444 !important;
}

body.wcag-contrast-dark a:not(#wcag-toolkit-widget a) {
    color: #6CB4EE !important;
}

/* Saturation — filter na WRAPPERZE */
body.wcag-saturation-low #wcag-page-wrapper {
    filter: saturate(0.5) !important;
}

body.wcag-saturation-desaturated #wcag-page-wrapper {
    filter: saturate(0) !important;
}

/* Text alignment */
body.wcag-text-left *:not(#wcag-toolkit-widget):not(#wcag-toolkit-widget *) {
    text-align: left !important;
}

body.wcag-text-center *:not(#wcag-toolkit-widget):not(#wcag-toolkit-widget *) {
    text-align: center !important;
}

body.wcag-text-right *:not(#wcag-toolkit-widget):not(#wcag-toolkit-widget *) {
    text-align: right !important;
}

/* Focus highlight */
body.wcag-focus-highlight *:not(#wcag-toolkit-widget *):focus {
    outline: 3px solid #FF6B00 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 6px rgba(255, 107, 0, 0.2) !important;
}

/* Page structure headings overlay */
body.wcag-page-structure h1::before,
body.wcag-page-structure h2::before,
body.wcag-page-structure h3::before,
body.wcag-page-structure h4::before,
body.wcag-page-structure h5::before,
body.wcag-page-structure h6::before {
    display: inline-block;
    padding: 1px 6px;
    margin-right: 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    color: #FFFFFF;
    vertical-align: middle;
}

body.wcag-page-structure h1::before { content: 'H1'; background: #DC2626; }
body.wcag-page-structure h2::before { content: 'H2'; background: #EA580C; }
body.wcag-page-structure h3::before { content: 'H3'; background: #D97706; }
body.wcag-page-structure h4::before { content: 'H4'; background: #65A30D; }
body.wcag-page-structure h5::before { content: 'H5'; background: #0891B2; }
body.wcag-page-structure h6::before { content: 'H6'; background: #7C3AED; }

body.wcag-page-structure [role="banner"],
body.wcag-page-structure [role="navigation"],
body.wcag-page-structure [role="main"],
body.wcag-page-structure [role="contentinfo"],
body.wcag-page-structure [role="complementary"],
body.wcag-page-structure header,
body.wcag-page-structure nav,
body.wcag-page-structure main,
body.wcag-page-structure footer,
body.wcag-page-structure aside {
    outline: 2px dashed rgba(21, 101, 192, 0.5) !important;
    outline-offset: 2px !important;
    position: relative;
}

body.wcag-page-structure nav::after { content: 'NAV'; }
body.wcag-page-structure main::after { content: 'MAIN'; }
body.wcag-page-structure header::after { content: 'HEADER'; }
body.wcag-page-structure footer::after { content: 'FOOTER'; }
body.wcag-page-structure aside::after { content: 'ASIDE'; }

body.wcag-page-structure nav::after,
body.wcag-page-structure main::after,
body.wcag-page-structure header::after,
body.wcag-page-structure footer::after,
body.wcag-page-structure aside::after {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(21, 101, 192, 0.85);
    color: #FFFFFF;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    z-index: 99999;
    pointer-events: none;
}
