/* ============================================================
   Flavor Accessibility — Widget & Accessibility Overrides
   WCAG 2.0 Compliant
   ============================================================ */

/* === Variables === */
:root {
    --flavor-acc-primary: #0077C8;
    --flavor-acc-primary-dark: #005a9e;
    --flavor-acc-bg: #ffffff;
    --flavor-acc-text: #1a1a1a;
    --flavor-acc-text-muted: #5a5a5a;
    --flavor-acc-border: #e0e0e0;
    --flavor-acc-radius: 16px;
    --flavor-acc-shadow: 0 8px 32px rgba(0,0,0,0.18);
    --flavor-acc-icon-size: 56px;
}

/* === Toggle Button — Israeli Accessibility Regulations Compliant ===
 * Requirements:
 * - International accessibility symbol (wheelchair icon)
 * - Text label "נגישות" visible
 * - Fixed position, always visible
 * - Minimum touch target 44×44px (WCAG 2.5.5)
 * - Contrast ratio ≥ 4.5:1 (WCAG 1.4.3)
 * - Keyboard operable with clear focus indicator
 */
.flavor-acc-toggle {
    position: fixed !important;
    bottom: 20px !important;
    z-index: 999990 !important;
    min-width: 44px !important;
    min-height: 44px !important;
    height: auto !important;
    border-radius: 28px !important;
    background: var(--flavor-acc-primary) !important;
    color: #fff !important;
    border: 2px solid rgba(255,255,255,0.3) !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 10px 18px !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3) !important;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
    line-height: 1 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, "Noto Sans Hebrew", sans-serif !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    overflow: visible !important;
    transform: none !important;
    margin: 0 !important;
    text-indent: 0 !important;
    float: none !important;
    clip: auto !important;
    width: auto !important;
    max-width: none !important;
    text-decoration: none !important;
}

.flavor-acc-toggle:hover {
    transform: scale(1.05);
    background: var(--flavor-acc-primary-dark);
    box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}

.flavor-acc-toggle:focus-visible {
    outline: 3px solid #ff0;
    outline-offset: 3px;
}

.flavor-acc-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.flavor-acc-toggle-icon svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
}

.flavor-acc-toggle-label {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.flavor-acc-toggle[data-position="right"] {
    right: 20px !important;
    left: auto !important;
}

.flavor-acc-toggle[data-position="left"] {
    left: 20px !important;
    right: auto !important;
}

/* Pulse animation on load */
@keyframes flavorAccPulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(0,0,0,0.25); }
    50% { box-shadow: 0 4px 16px rgba(0,119,200,0.6); }
}

.flavor-acc-toggle.pulse {
    animation: flavorAccPulse 2s ease-in-out 3;
}

/* === Panel === */
.flavor-acc-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 999995;
    width: 380px;
    max-width: 94vw;
    background: var(--flavor-acc-bg);
    color: var(--flavor-acc-text);
    box-shadow: var(--flavor-acc-shadow);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    overflow: hidden;
}

.flavor-acc-panel[data-position="right"] {
    right: 0;
    border-radius: var(--flavor-acc-radius) 0 0 var(--flavor-acc-radius);
    transform: translateX(100%);
}

.flavor-acc-panel[data-position="left"] {
    left: 0;
    border-radius: 0 var(--flavor-acc-radius) var(--flavor-acc-radius) 0;
    transform: translateX(-100%);
}

.flavor-acc-panel.open {
    transform: translateX(0);
}

/* === Panel Overlay === */
.flavor-acc-overlay {
    position: fixed;
    inset: 0;
    z-index: 999994;
    background: rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s;
}

.flavor-acc-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* === Panel Header === */
.flavor-acc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: var(--flavor-acc-primary);
    color: #fff;
    flex-shrink: 0;
}

.flavor-acc-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
}

.flavor-acc-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.flavor-acc-header button {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s;
    padding: 0;
}

.flavor-acc-header button svg {
    width: 20px;
    height: 20px;
    fill: #fff;
    display: block;
}

.flavor-acc-header button:hover {
    background: rgba(255,255,255,0.35);
}

.flavor-acc-header button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* === Panel Body === */
.flavor-acc-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    -webkit-overflow-scrolling: touch;
}

/* === Section Groups === */
.flavor-acc-section {
    margin-bottom: 20px;
}

.flavor-acc-section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--flavor-acc-text-muted);
    margin: 0 0 10px 0;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--flavor-acc-border);
}

/* === Feature Grid === */
.flavor-acc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* === Feature Button (Toggle) === */
.flavor-acc-feature {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 8px;
    border: 2px solid var(--flavor-acc-border);
    border-radius: 12px;
    background: #fafafa;
    color: var(--flavor-acc-text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    transition: all 0.18s;
    min-height: 80px;
    position: relative;
    line-height: 1.3;
}

.flavor-acc-feature:hover {
    border-color: var(--flavor-acc-primary);
    background: #f0f7ff;
}

.flavor-acc-feature:focus-visible {
    outline: 3px solid var(--flavor-acc-primary);
    outline-offset: 2px;
}

.flavor-acc-feature[aria-pressed="true"] {
    border-color: var(--flavor-acc-primary);
    background: var(--flavor-acc-primary);
    color: #fff;
}

.flavor-acc-feature[aria-pressed="true"] svg {
    fill: #fff;
}

.flavor-acc-feature svg {
    width: 24px;
    height: 24px;
    fill: var(--flavor-acc-primary);
    flex-shrink: 0;
    transition: fill 0.18s;
}

/* === Font Size Slider === */
.flavor-acc-font-control {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: 2px solid var(--flavor-acc-border);
    border-radius: 12px;
    background: #fafafa;
}

.flavor-acc-font-control .label {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
}

.flavor-acc-font-control .value {
    font-weight: 700;
    font-size: 14px;
    min-width: 42px;
    text-align: center;
    color: var(--flavor-acc-primary);
}

.flavor-acc-font-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--flavor-acc-primary);
    background: #fff;
    color: var(--flavor-acc-primary);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.flavor-acc-font-btn:hover {
    background: var(--flavor-acc-primary);
    color: #fff;
}

.flavor-acc-font-btn:focus-visible {
    outline: 3px solid var(--flavor-acc-primary);
    outline-offset: 2px;
}

/* === Panel Footer === */
.flavor-acc-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--flavor-acc-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.flavor-acc-footer a {
    color: var(--flavor-acc-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.flavor-acc-footer a svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    flex-shrink: 0;
}

.flavor-acc-footer a:hover {
    text-decoration: underline;
}

.flavor-acc-footer a:focus-visible {
    outline: 2px solid var(--flavor-acc-primary);
    outline-offset: 2px;
}

/* ============================================================
   ACCESSIBILITY OVERRIDE CLASSES
   Applied to <html> element
   ============================================================ */

/* WCAG 1.4.3 / 1.4.6 — High Contrast */
html.flavor-high-contrast,
html.flavor-high-contrast body {
    background: #000 !important;
    color: #fff !important;
}
html.flavor-high-contrast *:not(.flavor-acc-panel *):not(.flavor-acc-toggle):not(.flavor-acc-overlay) {
    background-color: #000 !important;
    color: #fff !important;
    border-color: #fff !important;
    text-shadow: none !important;
    box-shadow: none !important;
}
html.flavor-high-contrast a:not(.flavor-acc-panel a) {
    color: #ff0 !important;
}
html.flavor-high-contrast img {
    filter: brightness(1.1) contrast(1.2);
}
html.flavor-high-contrast button:not(.flavor-acc-panel button),
html.flavor-high-contrast input,
html.flavor-high-contrast textarea,
html.flavor-high-contrast select {
    border: 2px solid #fff !important;
}

/* Invert Colors */
html.flavor-invert-colors body {
    filter: invert(1) hue-rotate(180deg);
}
html.flavor-invert-colors .flavor-acc-panel,
html.flavor-invert-colors .flavor-acc-toggle,
html.flavor-invert-colors .flavor-acc-overlay,
html.flavor-invert-colors img,
html.flavor-invert-colors video,
html.flavor-invert-colors svg:not(.flavor-acc-panel svg) {
    filter: invert(1) hue-rotate(180deg);
}

/* WCAG 1.4.1 — Grayscale */
html.flavor-grayscale body {
    filter: grayscale(1);
}
html.flavor-grayscale .flavor-acc-panel,
html.flavor-grayscale .flavor-acc-toggle,
html.flavor-grayscale .flavor-acc-overlay {
    filter: grayscale(0);
}

/* WCAG 1.3.1 / 2.4.4 — Underline Links */
html.flavor-underline-links a:not(.flavor-acc-panel a) {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 3px !important;
}

/* WCAG 1.4.8 — Readable Font */
html.flavor-readable-font *:not(.flavor-acc-panel *):not(i):not(.fa):not(.dashicons):not([class*="icon"]) {
    font-family: Arial, Helvetica, "Noto Sans Hebrew", "Noto Sans", sans-serif !important;
    letter-spacing: 0.02em !important;
    word-spacing: 0.08em !important;
}

/* WCAG 1.4.12 — Text Spacing */
html.flavor-text-spacing *:not(.flavor-acc-panel *) {
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

/* WCAG 1.4.8 — Line Height */
html.flavor-line-height *:not(.flavor-acc-panel *) {
    line-height: 2 !important;
}

/* WCAG 2.3.1 — Stop Animations */
html.flavor-stop-animations *,
html.flavor-stop-animations *::before,
html.flavor-stop-animations *::after {
    animation-duration: 0s !important;
    animation-delay: 0s !important;
    transition-duration: 0s !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
}
html.flavor-stop-animations .flavor-acc-panel,
html.flavor-stop-animations .flavor-acc-panel * {
    transition-duration: 0.2s !important;
}

/* WCAG 2.4.7 — Highlight Focus */
html.flavor-highlight-focus *:focus {
    outline: 3px solid #ff6600 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 5px rgba(255,102,0,0.3) !important;
}

/* Big Cursor */
html.flavor-big-cursor,
html.flavor-big-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' stroke='%23fff' stroke-width='1' d='M5 3l14 8-6 1.5L9 19z'/%3E%3C/svg%3E") 4 2, auto !important;
}
html.flavor-big-cursor a,
html.flavor-big-cursor button,
html.flavor-big-cursor [role="button"],
html.flavor-big-cursor input[type="submit"],
html.flavor-big-cursor input[type="button"],
html.flavor-big-cursor select {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' stroke='%23fff' stroke-width='1' d='M12 3C7 3 3 7 3 12s4 9 9 9 9-4 9-9-4-9-9-9zm0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7zm-1-11h2v4h-2zm0 6h2v2h-2z'/%3E%3C/svg%3E") 12 12, pointer !important;
}

/* Reading Guide */
#flavor-reading-guide {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    height: 12px;
    z-index: 999993;
    pointer-events: none;
    background: rgba(255, 200, 0, 0.35);
    border-top: 2px solid rgba(255, 160, 0, 0.6);
    border-bottom: 2px solid rgba(255, 160, 0, 0.6);
    transition: top 0.05s linear;
}

html.flavor-reading-guide #flavor-reading-guide {
    display: block;
}

/* Image Tooltips (alt text display) — WCAG 1.1.1 */
html.flavor-image-tooltips img[alt]:not([alt=""]) {
    outline: 3px dashed var(--flavor-acc-primary) !important;
    outline-offset: 2px;
    position: relative;
}

/* ============================================================
   NEW FEATURES
   ============================================================ */

/* Dyslexia Font (OpenDyslexic via CDN) */
@import url('https://fonts.cdnfonts.com/css/opendyslexic');

html.flavor-dyslexia-font *:not(.flavor-acc-panel *):not(i):not(.fa):not(.dashicons):not([class*="icon"]) {
    font-family: 'OpenDyslexic', Arial, sans-serif !important;
    letter-spacing: 0.05em !important;
    word-spacing: 0.15em !important;
}

/* Hide Images */
html.flavor-hide-images img:not(.flavor-acc-panel img):not(.flavor-acc-toggle img) {
    opacity: 0.05 !important;
    filter: grayscale(1) !important;
}
html.flavor-hide-images figure,
html.flavor-hide-images picture,
html.flavor-hide-images .wp-block-image,
html.flavor-hide-images [class*="image-container"],
html.flavor-hide-images [class*="img-container"] {
    position: relative;
}
html.flavor-hide-images figure::after,
html.flavor-hide-images picture::after {
    content: attr(aria-label) "📷 תמונה מוסתרת";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    color: #666;
    font-size: 14px;
    border: 2px dashed #ccc;
}

/* Saturation Low */
html.flavor-saturation-low body {
    filter: saturate(0.3);
}
html.flavor-saturation-low .flavor-acc-panel,
html.flavor-saturation-low .flavor-acc-toggle,
html.flavor-saturation-low .flavor-acc-overlay {
    filter: saturate(3.3); /* compensate */
}

/* Saturation High */
html.flavor-saturation-high body {
    filter: saturate(2.5);
}
html.flavor-saturation-high .flavor-acc-panel,
html.flavor-saturation-high .flavor-acc-toggle,
html.flavor-saturation-high .flavor-acc-overlay {
    filter: saturate(0.4); /* compensate */
}

/* ── Color Blindness Simulation Modes ── */
/* Protanopia (red) */
html.flavor-cb-protanopia body {
    filter: url('#flavor-protanopia-filter');
}
/* Deuteranopia (green) */
html.flavor-cb-deuteranopia body {
    filter: url('#flavor-deuteranopia-filter');
}
/* Tritanopia (blue) */
html.flavor-cb-tritanopia body {
    filter: url('#flavor-tritanopia-filter');
}

/* Exclude panel from color blindness filters */
html.flavor-cb-protanopia .flavor-acc-panel,
html.flavor-cb-protanopia .flavor-acc-toggle,
html.flavor-cb-deuteranopia .flavor-acc-panel,
html.flavor-cb-deuteranopia .flavor-acc-toggle,
html.flavor-cb-tritanopia .flavor-acc-panel,
html.flavor-cb-tritanopia .flavor-acc-toggle {
    filter: none !important;
}

/* ── Custom Backgrounds ── */
html.flavor-bg-dark body {
    background-color: #1a1a2e !important;
    color: #e0e0e0 !important;
}
html.flavor-bg-dark *:not(.flavor-acc-panel *):not(.flavor-acc-toggle *):not(.flavor-acc-overlay) {
    background-color: transparent !important;
    color: #e0e0e0 !important;
}
html.flavor-bg-dark a:not(.flavor-acc-panel a) {
    color: #6eb5ff !important;
}

html.flavor-bg-sepia body {
    background-color: #f4ecd8 !important;
    color: #5b4636 !important;
}
html.flavor-bg-sepia *:not(.flavor-acc-panel *):not(.flavor-acc-toggle *):not(.flavor-acc-overlay) {
    background-color: transparent !important;
    color: #5b4636 !important;
}

html.flavor-bg-blue body {
    background-color: #d0e8f2 !important;
    color: #1a3a4a !important;
}
html.flavor-bg-blue *:not(.flavor-acc-panel *):not(.flavor-acc-toggle *):not(.flavor-acc-overlay) {
    background-color: transparent !important;
    color: #1a3a4a !important;
}

/* ── Reading Mask ── */
#flavor-reading-mask-top,
#flavor-reading-mask-bottom {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    z-index: 999992;
    background: rgba(0, 0, 0, 0.75);
    pointer-events: none;
    transition: none;
}
#flavor-reading-mask-top { top: 0; }
#flavor-reading-mask-bottom { bottom: 0; }

html.flavor-reading-mask #flavor-reading-mask-top,
html.flavor-reading-mask #flavor-reading-mask-bottom {
    display: block;
}

/* ── Text-to-Speech Active Highlight ── */
.flavor-tts-highlight {
    background: #ffeb3b !important;
    color: #000 !important;
    outline: 2px solid #f9a825;
    border-radius: 3px;
}

/* ── Magnifier Lens ── */
#flavor-magnifier {
    display: none;
    position: fixed;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 3px solid var(--flavor-acc-primary);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    pointer-events: none;
    z-index: 999998;
    overflow: hidden;
    background: #fff;
}

html.flavor-magnifier #flavor-magnifier {
    display: block;
}

/* ── Page Structure Panel ── */
#flavor-page-structure {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 999998;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.3);
    width: 400px;
    max-width: 90vw;
    max-height: 70vh;
    overflow-y: auto;
    padding: 20px;
    direction: rtl;
}

#flavor-page-structure h3 {
    margin: 0 0 12px;
    font-size: 18px;
    border-bottom: 2px solid var(--flavor-acc-primary);
    padding-bottom: 8px;
}

#flavor-page-structure .fps-item {
    padding: 6px 0;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

#flavor-page-structure .fps-item a {
    color: var(--flavor-acc-primary);
    text-decoration: none;
}

#flavor-page-structure .fps-item a:hover {
    text-decoration: underline;
}

#flavor-page-structure .fps-h1 { font-weight: 700; font-size: 16px; }
#flavor-page-structure .fps-h2 { padding-right: 16px; font-weight: 600; }
#flavor-page-structure .fps-h3 { padding-right: 32px; }
#flavor-page-structure .fps-h4 { padding-right: 48px; font-size: 13px; }
#flavor-page-structure .fps-h5,
#flavor-page-structure .fps-h6 { padding-right: 64px; font-size: 12px; }

#flavor-page-structure .fps-close {
    position: absolute;
    top: 10px;
    left: 10px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    width: 30px;
    height: 30px;
}

/* ── Background Selector Row ── */
.flavor-acc-bg-row {
    display: flex;
    gap: 8px;
}

.flavor-acc-bg-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px;
    border: 2px solid var(--flavor-acc-border);
    border-radius: 10px;
    background: #fafafa;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--flavor-acc-text);
    transition: all 0.15s;
}

.flavor-acc-bg-btn span:first-child {
    display: block;
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.flavor-acc-bg-btn:hover {
    border-color: var(--flavor-acc-primary);
}

.flavor-acc-bg-btn[aria-pressed="true"] {
    border-color: var(--flavor-acc-primary);
    background: var(--flavor-acc-primary);
    color: #fff;
}

/* ============================================================
   Font Size Scaling
   ============================================================ */
html[data-flavor-font-scale] {
    /* JS sets --flavor-font-scale */
}

html[data-flavor-font-scale] *:not(.flavor-acc-panel *) {
    font-size: calc(1em * var(--flavor-font-scale, 1)) !important;
}

/* Ensure the root respects the scale */
html[data-flavor-font-scale] body {
    font-size: calc(16px * var(--flavor-font-scale, 1)) !important;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 420px) {
    .flavor-acc-panel {
        width: 100vw;
        max-width: 100vw;
        border-radius: 0;
    }

    .flavor-acc-toggle {
        bottom: 12px;
        padding: 8px 14px;
    }

    .flavor-acc-toggle[data-position="right"] {
        right: 12px;
    }

    .flavor-acc-toggle[data-position="left"] {
        left: 12px;
    }

    .flavor-acc-toggle-label {
        font-size: 13px;
    }

    .flavor-acc-toggle-icon svg {
        width: 22px;
        height: 22px;
    }
}

/* ============================================================
   Print — hide widget
   ============================================================ */
@media print {
    .flavor-acc-toggle,
    .flavor-acc-panel,
    .flavor-acc-overlay,
    #flavor-reading-guide {
        display: none !important;
    }
}
