/**
 * WEPRO Accessibility Master - Frontend Styles
 * v1.1.0 — Optimized for Performance, WCAG 2.1 AA & EAA Compliance
 */

/* --- 0. Fonts (Self-Hosted, GDPR-Safe) --- */
@font-face {
    font-family: 'OpenDyslexic';
    src: url('../fonts/OpenDyslexic-Regular.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* --- 1. Widget UI Variables (Theming) --- */
:root {
    --wepro-acc-primary: #0056b3;
    --wepro-acc-primary-dark: #004494;
    --wepro-acc-text: #333333;
    --wepro-acc-bg: #ffffff;
    --wepro-acc-border: #f0f0f0;
    --wepro-acc-focus: #ffbf47;
    --wepro-acc-width: 360px;
    --wepro-acc-zindex: 100000000;
    --wepro-acc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --wepro-acc-radius: 12px;
    --wepro-acc-shadow: 0 12px 40px rgba(0,0,0,0.12);
}

/* --- 2. Widget Container (Fixed Wrapper) --- */
.wepro-acc-widget {
    position: fixed;
    z-index: var(--wepro-acc-zindex);
    font-family: var(--wepro-acc-font);
    font-size: 16px;
    line-height: 1.5;
    direction: ltr;
    box-sizing: border-box;
    will-change: transform;
}

.wepro-acc-widget * {
    box-sizing: border-box;
}

/* Desktop Positioning */
.wepro-acc-pos-right { top: 20%; right: 0; }
.wepro-acc-pos-left  { top: 20%; left: 0; }

/* --- 3. Toggle Button (The Icon) --- */
.wepro-acc-toggle {
    background: var(--wepro-acc-primary);
    color: #fff;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 8px 0 0 8px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1),
                width 0.3s ease,
                background-color 0.2s,
                opacity 0.4s;
    position: relative;
    z-index: 20;
}

.wepro-acc-pos-left .wepro-acc-toggle {
    border-radius: 0 8px 8px 0;
}

.wepro-acc-toggle svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
}

.wepro-acc-toggle:hover,
.wepro-acc-toggle:focus {
    width: 60px;
    background: var(--wepro-acc-primary-dark);
    outline: none;
}

.wepro-acc-toggle:focus-visible {
    outline: 3px solid var(--wepro-acc-focus);
    outline-offset: -3px;
}

/* --- Smart Idle State (Docking) --- */
.wepro-acc-pos-right .wepro-acc-toggle.wepro-acc-idle {
    transform: translateX(35px);
    opacity: 0.85;
}

.wepro-acc-pos-left .wepro-acc-toggle.wepro-acc-idle {
    transform: translateX(-35px);
    opacity: 0.85;
}

.wepro-acc-toggle:hover,
.wepro-acc-toggle:focus,
.wepro-acc-toggle:active {
    transform: translateX(0) !important;
    opacity: 1 !important;
}

.wepro-acc-widget.panel-open .wepro-acc-toggle {
    transform: translateX(0) !important;
    opacity: 1 !important;
}

/* --- 4. Main Panel (The Drawer) --- */
.wepro-acc-panel {
    position: absolute;
    top: -20px;
    width: var(--wepro-acc-width);
    background: var(--wepro-acc-bg);
    box-shadow: var(--wepro-acc-shadow);
    border-radius: var(--wepro-acc-radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 10;
    opacity: 1;
    visibility: visible;
    transform: translateX(0) scale(1);
    transition: all 0.35s cubic-bezier(0.25, 1, 0.5, 1);
}

.wepro-acc-pos-right .wepro-acc-panel {
    right: 65px;
    transform-origin: top right;
}

.wepro-acc-pos-left .wepro-acc-panel {
    left: 65px;
    transform-origin: top left;
}

/* Hidden State (Animated) */
.wepro-acc-panel[hidden] {
    display: flex !important;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateX(30px) scale(0.95);
}

.wepro-acc-pos-left .wepro-acc-panel[hidden] {
    transform: translateX(-30px) scale(0.95);
}

/* --- Panel Header --- */
.wepro-acc-header {
    background: linear-gradient(135deg, #fafafa 0%, #f5f5f5 100%);
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--wepro-acc-border);
    border-top: 2.5px solid var(--wepro-acc-primary);
    border-radius: var(--wepro-acc-radius) var(--wepro-acc-radius) 0 0;
}

.wepro-acc-header h3 {
    margin: 0;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--wepro-acc-text);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: flex;
    align-items: center;
    gap: 7px;
}

.wepro-acc-header-icon {
    color: var(--wepro-acc-primary);
    flex-shrink: 0;
    opacity: 0.8;
}

.wepro-acc-close {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 4px;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.wepro-acc-close:hover {
    color: #333;
    background: rgba(0,0,0,0.04);
}

/* --- Panel Body --- */
.wepro-acc-body {
    padding: 16px;
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* --- Control Groups --- */
.wepro-acc-group {
    margin-bottom: 0;
    padding: 14px 0;
    border-bottom: 1px solid var(--wepro-acc-border);
}
.wepro-acc-group:first-child {
    padding-top: 0;
}
.wepro-acc-group:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.wepro-acc-group h4 {
    margin: 0 0 10px 0;
    font-size: 10px;
    text-transform: uppercase;
    color: #999;
    font-weight: 600;
    letter-spacing: 1.2px;
    display: flex;
    align-items: center;
    gap: 5px;
    padding-left: 9px;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wepro-acc-group h4::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 2.5px;
    height: 14px;
    background: var(--wepro-acc-primary);
    border-radius: 2px;
    opacity: 0.6;
}

/* Section title icons */
.wepro-acc-group-icon {
    flex-shrink: 0;
    color: var(--wepro-acc-primary);
    opacity: 0.65;
}

/* Buttons Container (inline row) */
.wepro-acc-controls {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
}

/* 2x2 Contrast Grid */
.wepro-acc-contrast-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    min-width: 0;
}

.wepro-acc-panel .wepro-acc-contrast-grid button {
    min-width: 0;
    font-size: 11px;
    white-space: nowrap;
    padding: 0 6px !important;
}

/* 2-Column Tools Grid (compact) */
.wepro-acc-tools-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.wepro-acc-panel .wepro-acc-tools-grid .wepro-acc-toggle-btn {
    width: 100%;
    margin-bottom: 0;
    min-width: 0;
    font-size: 10px;
    padding: 0 6px;
    min-height: 44px;
}

/* --- Control Buttons (The Look) --- */
.wepro-acc-panel button:not(.wepro-acc-close) {
    background: #f8f9fa;
    border: 1px solid #e2e4e7;
    color: #444;
    padding: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    font-size: 13px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    text-align: center;
    line-height: 1.2;
    transition: all 0.2s ease;
}

.wepro-acc-panel button svg {
    fill: currentColor;
    width: 18px;
    height: 18px;
    pointer-events: none;
}

.wepro-acc-panel button:hover {
    background: #edf0f2;
    border-color: #d0d3d6;
    color: #222;
}

.wepro-acc-panel button.active {
    background: var(--wepro-acc-primary);
    color: #fff;
    border-color: var(--wepro-acc-primary);
    box-shadow: 0 2px 6px rgba(0, 86, 179, 0.3);
}

.wepro-acc-panel button:focus-visible {
    outline: 2px solid var(--wepro-acc-focus);
    outline-offset: 2px;
}

/* --- Reset & Footer --- */
.wepro-acc-footer {
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
}

.wepro-acc-statement-link {
    display: block;
    text-align: center;
    margin-bottom: 12px;
    color: var(--wepro-acc-primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}

.wepro-acc-statement-link:hover {
    text-decoration: underline;
}

.wepro-acc-reset {
    width: 100%;
    background: #fff !important;
    border: 1px solid #e74c3c !important;
    color: #e74c3c !important;
}

.wepro-acc-reset:hover {
    background: #e74c3c !important;
    color: #fff !important;
}

/* --- 5. Mobile & Responsive --- */

@media (max-width: 480px) {
    :root {
        --wepro-acc-width: 320px;
    }

    .wepro-acc-widget {
        top: 20% !important;
        bottom: auto !important;
    }

    .wepro-acc-panel {
        top: 0;
    }

    .wepro-acc-pos-right .wepro-acc-panel {
        right: 60px;
        max-width: calc(100vw - 75px);
    }

    .wepro-acc-pos-left .wepro-acc-panel {
        left: 60px;
        max-width: calc(100vw - 75px);
    }

    .wepro-acc-panel button:not(.wepro-acc-close) {
        font-size: 11px;
        padding: 0 4px;
        min-height: 44px;
    }

    .wepro-acc-tools-grid .wepro-acc-toggle-btn {
        font-size: 9px;
        padding: 0 4px;
    }
}

@media (max-width: 340px) {
    :root {
        --wepro-acc-width: 250px;
    }
}

/* --- 6. Global Accessibility Overrides (Body Classes) --- */

/* High Contrast Mode */
body.wepro-high-contrast {
    background-color: #000 !important;
    color: #fff !important;
}
body.wepro-high-contrast *:not(.wepro-acc-widget *):not(img):not(video):not(.fas):not(.far):not(.fab) {
    background-color: #000 !important;
    color: #fff !important;
    border-color: #fff !important;
    box-shadow: none !important;
    text-shadow: none !important;
}
body.wepro-high-contrast a {
    color: #ffff00 !important;
    text-decoration: underline !important;
}
body.wepro-high-contrast button {
    background-color: #000 !important;
    color: #ffff00 !important;
    border: 1px solid #fff !important;
}

/* Invert Mode */
html.wepro-invert {
    filter: invert(100%);
    background: #fff;
    height: 100%;
}
html.wepro-invert img,
html.wepro-invert video,
html.wepro-invert iframe,
html.wepro-invert .wepro-acc-widget {
    filter: invert(100%);
}

/* Grayscale Mode */
body.wepro-grayscale {
    filter: grayscale(100%);
}

/* Highlight Links */
body.wepro-link-highlight a {
    background: #ffeb3b !important;
    color: #000 !important;
    text-decoration: underline !important;
    padding: 0 2px;
    border-radius: 2px;
}

/* Readable Font */
body.wepro-readable-font {
    font-family: "Arial", "Helvetica", "Verdana", sans-serif !important;
    line-height: 1.6 !important;
    letter-spacing: 0.02em !important;
}

/* Dyslexia-Friendly Font */
body.wepro-dyslexia-font,
body.wepro-dyslexia-font * {
    font-family: "OpenDyslexic", "Comic Sans MS", "Trebuchet MS", Verdana, sans-serif !important;
    line-height: 1.8 !important;
    letter-spacing: 0.05em !important;
    word-spacing: 0.15em !important;
}
/* Keep widget font unchanged */
body.wepro-dyslexia-font .wepro-acc-widget,
body.wepro-dyslexia-font .wepro-acc-widget * {
    font-family: var(--wepro-acc-font) !important;
}

/* --- 7. EU Compliance Features (Navigation & Focus) --- */

/* Skip to Content */
.wepro-acc-skip-link {
    position: fixed;
    top: -100px;
    left: 0;
    z-index: 10000001;
    background: var(--wepro-acc-primary);
    color: #fff;
    padding: 15px 25px;
    font-weight: bold;
    text-decoration: none;
    transition: top 0.2s;
    border-radius: 0 0 8px 0;
    font-family: var(--wepro-acc-font);
}
.wepro-acc-skip-link:focus {
    top: 0;
    outline: 3px solid var(--wepro-acc-focus);
}

/* Forced Focus Ring (WCAG 2.4.7) */
body.wepro-force-focus *:focus-visible {
    outline: 4px solid var(--wepro-acc-focus) !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 6px #000 !important;
}
body.wepro-force-focus,
body.wepro-force-focus a,
body.wepro-force-focus button {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 24 24' fill='black' stroke='white' stroke-width='2'><path d='M0 0L8 22L12 14L20 12L0 0Z'/></svg>") 0 0, auto !important;
}

/* Animation Kill Switch (WCAG 2.2.2) */
body.wepro-stop-animations *,
body.wepro-stop-animations *::before,
body.wepro-stop-animations *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
}

body.wepro-stop-animations video[autoplay],
body.wepro-stop-animations .elementor-background-video-container {
    display: none !important;
}

/* --- 8. Cognitive Support Features --- */

/* Text Spacing (WCAG 1.4.12) */
body.wepro-text-spacing * {
    line-height: 1.8 !important;
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}
body.wepro-text-spacing p {
    margin-bottom: 2em !important;
}

/* Reading Guide */
.wepro-reading-guide-bar {
    position: fixed;
    left: 0;
    width: 100%;
    height: 40px;
    background: rgba(255, 235, 59, 0.2);
    border-top: 3px solid var(--wepro-acc-primary);
    border-bottom: 3px solid var(--wepro-acc-primary);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 99999999;
    transform: translateY(-50%);
    display: none;
}

/* Hide Images Mode */
body.wepro-hide-images img:not(.wepro-acc-widget img),
body.wepro-hide-images svg:not(.wepro-acc-widget svg):not(.wepro-acc-icon),
body.wepro-hide-images picture,
body.wepro-hide-images [role="img"],
body.wepro-hide-images video {
    visibility: hidden !important;
    opacity: 0 !important;
}
