/**
 * WEPRO Accessibility Master - Frontend Styles
 * Optimized for Performance & WCAG Compliance
 */

/* --- 1. Widget UI Variables (Theming) --- */
:root {
    --wepro-acc-primary: #0056b3;       /* Professional Blue */
    --wepro-acc-primary-dark: #004494;  /* Hover State */
    --wepro-acc-text: #333333;          /* Dark Grey Text */
    --wepro-acc-bg: #ffffff;            /* White Background */
    --wepro-acc-border: #f0f0f0;        /* Subtle Border */
    --wepro-acc-focus: #ffbf47;         /* Accessibility Focus Ring */
    --wepro-acc-width: 320px;           /* Optimal Panel Width */
    --wepro-acc-zindex: 100000000;      /* Always on Top (Higher than Reading Guide) */
    --wepro-acc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --wepro-acc-radius: 12px;           /* Modern Rounded Corners */
    --wepro-acc-shadow: 0 12px 40px rgba(0,0,0,0.12); /* Elegant Drop Shadow */
}

/* --- 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;
    /* Prevent layout thrashing during animations */
    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; /* Rounded Left */
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Transition for Hover + Smart Docking */
    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; /* Above Panel */
}

.wepro-acc-pos-left .wepro-acc-toggle {
    border-radius: 0 8px 8px 0; /* Rounded Right */
}

/* Icon Styling */
.wepro-acc-toggle svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
}

.wepro-acc-toggle:hover,
.wepro-acc-toggle:focus {
    width: 60px; /* Slight expansion on hover */
    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) --- */
/* If idle & right-positioned -> slide right */
.wepro-acc-pos-right .wepro-acc-toggle.wepro-acc-idle {
    transform: translateX(35px); /* 70% hidden */
    opacity: 0.85; /* Slightly transparent */
}

/* If idle & left-positioned -> slide left */
.wepro-acc-pos-left .wepro-acc-toggle.wepro-acc-idle {
    transform: translateX(-35px);
    opacity: 0.85;
}

/* Instant Wake-up on Interaction */
.wepro-acc-toggle:hover,
.wepro-acc-toggle:focus,
.wepro-acc-toggle:active {
    transform: translateX(0) !important;
    opacity: 1 !important;
}

/* Never hide if panel is open */
.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; /* Align top roughly with toggle center */
    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;
    
    /* Animation Defaults */
    opacity: 1;
    visibility: visible;
    transform: translateX(0) scale(1);
    transition: all 0.35s cubic-bezier(0.25, 1, 0.5, 1); /* Elegant Ease-Out */
}

/* Panel Alignment */
.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; /* Keep layout for animation */
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    
    /* Slide Out Effect */
    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: #fafafa;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--wepro-acc-border);
}

.wepro-acc-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--wepro-acc-text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.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: 20px;
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth iOS Scroll */
}

/* --- Control Groups --- */
.wepro-acc-group {
    margin-bottom: 24px;
}
.wepro-acc-group:last-child {
    margin-bottom: 0;
}

.wepro-acc-group h4 {
    margin: 0 0 10px 0;
    font-size: 11px;
    text-transform: uppercase;
    color: #888;
    font-weight: 700;
    letter-spacing: 0.8px;
}

/* Buttons Container */
.wepro-acc-controls,
.wepro-acc-grid {
    display: flex;
    gap: 10px;
    flex-wrap: nowrap; /* Prevent wrapping on mobile */
}

.wepro-acc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
}

/* Full Width Buttons (Navigation) */
.wepro-acc-toggle-btn {
    width: 100%;
    margin-bottom: 10px;
}

/* --- Control Buttons (The Look) --- */
.wepro-acc-panel button:not(.wepro-acc-close) {
    background: #f8f9fa;
    border: 1px solid #e2e4e7;
    color: #444;
    padding: 0 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    font-size: 14px;
    
    /* Layout & Touch Size */
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px; /* Ideal touch target */
    text-align: center;
    line-height: 1.2;
    transition: all 0.2s ease;
}

/* Icon styling inside buttons */
.wepro-acc-panel button svg {
    fill: currentColor;
    width: 18px;
    height: 18px;
    pointer-events: none;
}

/* Hover State */
.wepro-acc-panel button:hover {
    background: #edf0f2;
    border-color: #d0d3d6;
    color: #222;
}

/* Active State */
.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: 10px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
}

.wepro-acc-statement-link {
    display: block;
    text-align: center;
    margin-bottom: 15px;
    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 Optimizations --- */

/* Tablet & Mobile (< 480px) */
@media (max-width: 480px) {
    :root {
        --wepro-acc-width: 290px; /* Slightly narrower for small screens */
    }

    /* Fix Toggle Position on Mobile */
    .wepro-acc-widget {
        top: 20% !important; /* Keep it high enough so panel fits below */
        bottom: auto !important;
    }
    
    /* Panel Adjustments */
    .wepro-acc-panel {
        top: 0; /* Align with toggle */
    }

    /* Prevent overflow on small screens */
    .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);
    }

    /* Tighter text for small buttons */
    .wepro-acc-panel button:not(.wepro-acc-close) {
        font-size: 13px;
        padding: 0 4px;
        min-height: 44px; /* Still touch friendly */
    }
}

/* Ultra Small Screens (Fold, SE) */
@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;
}
/* Force override all elements except widget, images, and videos */
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%;
}
/* Re-invert media so they look natural */
html.wepro-invert img,
html.wepro-invert video,
html.wepro-invert iframe,
html.wepro-invert .wepro-acc-widget { 
    filter: invert(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;
}

/* --- 7. EU Compliance Features (Navigation & Focus) --- */

/* Feature 1: Skip to Content (Hidden by default, visible on Focus) */
.wepro-acc-skip-link {
    position: fixed;
    top: -100px;
    left: 0;
    z-index: 10000001; /* Must be extremely high */
    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);
}

/* Feature 2: 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; /* Double border for contrast */
}
/* Make the cursor huge in this mode too */
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;
}

/* Feature 3: Animation Kill Switch (WCAG 2.2.2) */
body.wepro-stop-animations *,
body.wepro-stop-animations *::before,
body.wepro-stop-animations *::after {
    /* Stop CSS Animations */
    animation: none !important;
    transition: none !important;
    
    /* Stop Smooth Scrolling (Instant jumps) */
    scroll-behavior: auto !important;
}

/* Hide Background Videos in this mode to prevent motion sickness */
body.wepro-stop-animations video[autoplay],
body.wepro-stop-animations .elementor-background-video-container {
    display: none !important;
}

/* --- 8. Cognitive Support Features (New EU) --- */

/* Feature 4: 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;
}

/* Feature 5: Reading Guide */
.wepro-reading-guide-bar {
    position: fixed;
    left: 0;
    width: 100%;
    height: 40px; /* The reading window */
    background: rgba(255, 235, 59, 0.2); /* Gentle Yellow highlighter style */
    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); /* Dim everything else */
    pointer-events: none; /* Let clicks pass through */
    z-index: 99999999; /* Below the Widget */
    transform: translateY(-50%);
    display: none; /* Controlled by JS */
}