/**
 * Accessibility layer for Calcala theme (WCAG 2.1 AA)
 *
 * 1. עזרי קריאת מסך (screen-reader-text, sr-only)
 * 2. קישור דילוג לתוכן
 * 3. מיקוד מקלדת גלוי (focus-visible)
 * 4. רשת בטיחות ניגודיות צבע (AA)
 * 5. הפחתת תנועה (prefers-reduced-motion)
 * 6. טיקרים נעים: כפתור השהיה + מצב השהיה
 * 7. הבחנת קישורים בטקסט תוכן (לא רק בצבע)
 */

/* ---------- 1. עזרי קריאת מסך ---------- */
.screen-reader-text {
    border: 0;
    clip-path: inset(50%);
    height: 1px;
    width: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    word-wrap: normal !important;
}

.sr-only:not(:focus):not(:focus-within) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ויזואליזציה של אלמנטים מוסתרים כשהם מקבלים מיקוד */
.sr-only.focusable:active,
.sr-only.focusable:focus {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
    white-space: normal;
}

/* ---------- 2. קישור דילוג לתוכן ---------- */
.skip-link {
    position: fixed;
    top: -100px;
    right: 1rem;
    z-index: 200;
    background: #065f46;
    color: #ffffff;
    padding: 0.75rem 1.5rem;
    border-radius: 0 0 0.5rem 0.5rem;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: top 0.15s ease-in-out;
}

.skip-link:focus {
    top: 0;
}

#main-content:focus {
    outline: none;
}

/* ---------- 3. מיקוד מקלדת גלוי ---------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
iframe:focus-visible,
[role="tab"]:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid #1d4ed8;
    outline-offset: 2px;
    border-radius: 3px;
}

/* ---------- 4. רשת בטיחות ניגודיות (AA לפחות 4.5:1 על רקע בהיר) ----------
   הכלים הבאים של Tailwind נכשלים בניגודיות כטקסט על רקעים בהירים.
   קידומת html מעלה ספציפיות (0,1,1) כדי לנצח את ה-CDN שמזריק את הכלים
   שלו בסוף ה-head אחרי קובץ זה - סדר טעינה לבדו אינו מספיק.
   מופעים על רקע כהה (טיקר המדדים, הפוטר) מטופלים בתבניות עצמן. */
html .text-gray-400 { color: #6b7280; }
html .text-gray-500 { color: #4b5563; } /* על רקע gray-100 המקורי נכשל בשוליים (4.44:1) */
footer .text-gray-400 { color: #9ca3af; } /* חריגה: © בפוטר הכהה, שם gray-400 עובר */
html .text-green-500, html .text-green-600 { color: #047857; }
html .text-emerald-500, html .text-emerald-600 { color: #047857; }
html .text-red-500 { color: #dc2626; }
html .text-blue-500 { color: #1d4ed8; }
html .text-amber-500, html .text-amber-600 { color: #b45309; }
html .text-yellow-500, html .text-yellow-600 { color: #a16207; }
html .text-orange-500, html .text-orange-600 { color: #9a3412; }

/* כפתורים ראשיים: הירוק הראשי מוכהה בשורש (var). לצערנו hover שקול לרקע - מכהים גם אותו */
html a.bg-\[var\(--primary-color\)\]:hover,
html button.bg-\[var\(--primary-color\)\]:hover,
html .bg-\[var\(--primary-color\)\]:hover,
html a.bg-emerald-600:hover,
html button.bg-emerald-600:hover,
html a.bg-green-600:hover,
html button.bg-green-600:hover {
    background-color: #065f46;
}

/* רקעי ירוק בינוניים עם טקסט לבן: הכהיה לרמה שעוברת AA (5.5:1) */
html .bg-emerald-600,
html .bg-green-600 {
    background-color: #047857;
}

/* רקעים בהירים עם טקסט לבן (toasts, תגי התקדמות, סרגלים): הכהיה ל-AA */
html .bg-emerald-500,
html .bg-green-500 {
    background-color: #047857;
}

html .bg-red-500 {
    background-color: #dc2626;
}

html .bg-blue-500 {
    background-color: #1d4ed8;
}

/* placeholder נראה וקריא יותר */
::placeholder { color: #4b5563; opacity: 1; }

/* ---------- 5. הפחתת תנועה ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .animate-marquee-rtl,
    .ticker-content {
        animation: none !important;
        transform: none !important;
    }

    html {
        scroll-behavior: auto;
    }
}

/* ---------- 6. טיקרים נעים: השהיה ---------- */
/* WCAG 2.2.2: תוכן נע מעל 5 שניות חייב אפשרות השהיה. הכפתור מוסף בתבניות
   ומטופל ב-assets/js/accessibility.js */
.calcala-ticker .calcala-ticker-toggle .icon-pause,
.calcala-ticker.is-paused .calcala-ticker-toggle .icon-play { display: flex; }
.calcala-ticker.is-paused .calcala-ticker-toggle .icon-pause,
.calcala-ticker .calcala-ticker-toggle .icon-play { display: none; }

.calcala-ticker.is-paused .animate-marquee-rtl,
.calcala-ticker.is-paused .ticker-content {
    animation-play-state: paused;
}

.calcala-ticker-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    cursor: pointer;
}

/* ---------- 7. הבחנת קישורים בטקסט תוכן ---------- */
/* קו תחתון בריחוף של קישורי "לכל..." - רק על הטקסט, לא על אייקון החץ.
   text-decoration מתפשט מהאב למרות no-underline על הבן, ולכן מבטלים
   את הקו ברמת הקישור ומחילים אותו רק על ספאן הטקסט. */
@supports selector(:has(*)) {
    html a:has(> .material-symbols-outlined.no-underline):hover {
        text-decoration: none;
    }
    html a:has(> .material-symbols-outlined.no-underline):hover > span:not(.material-symbols-outlined) {
        text-decoration: underline;
    }
}

/* 1.4.1: קישור בתוך פסקת טקסט חייב סימון שאינו צבע בלבד */
.entry-content a,
.article-content a,
.prose a,
.wp-block-post-content a,
.calcala-rich-text a {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

/* כפתורים ותגיות שנבנים כקישורים לא צריכים קו תחתון */
.entry-content a.btn,
.entry-content a[class*="bg-"],
.prose a[class*="bg-"] {
    text-decoration: none;
}

/* ---------- 8. סרגל כלי נגישות (צף) ---------- */
/* כפתור קבוע בצד שמאל שפותח פאנל הגדרות; המצב נשמר ב-localStorage
   ומיושם ב-assets/js/accessibility.js */
.calcala-a11y-toolbar {
    position: fixed;
    top: 40%;
    left: 0;
    z-index: 99999;
    direction: rtl;
    font-family: inherit;
    line-height: 1.4;
}

.calcala-a11y-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border: none;
    border-radius: 0 0.75rem 0.75rem 0;
    background: var(--primary-color, #047857);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.calcala-a11y-fab:hover { background: #065f46; }

.calcala-a11y-panel {
    position: fixed;
    top: 50%;
    left: 3.25rem;
    transform: translateY(-50%);
    width: min(320px, calc(100vw - 4.5rem));
    max-height: 80vh;
    overflow-y: auto;
    background: #fff;
    color: #111827;
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 1rem;
}

.calcala-a11y-panel[hidden] { display: none; }

.calcala-a11y-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.calcala-a11y-panel-head h3 { font-size: 1.05rem; font-weight: 700; margin: 0; }

.calcala-a11y-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: 0.5rem;
    background: #f3f4f6;
    color: #111827;
    cursor: pointer;
}

.calcala-a11y-close:hover { background: #e5e7eb; }

.calcala-a11y-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid #f3f4f6;
}

.calcala-a11y-row-title {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: #111827;
}

.calcala-a11y-row-title .material-symbols-outlined {
    font-size: 1.15rem;
    color: #047857;
}

/* מתג (switch) */
.calcala-a11y-switch {
    position: relative;
    flex-shrink: 0;
    width: 2.75rem;
    height: 1.5rem;
    border: none;
    border-radius: 9999px;
    background: #d1d5db;
    cursor: pointer;
    transition: background 0.15s ease-in-out;
}

.calcala-a11y-switch::after {
    content: "";
    position: absolute;
    top: 0.1875rem;
    right: 0.1875rem;
    width: 1.125rem;
    height: 1.125rem;
    border-radius: 9999px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: right 0.15s ease-in-out;
}

.calcala-a11y-switch[aria-checked="true"] { background: #047857; }
.calcala-a11y-switch[aria-checked="true"]::after { right: calc(100% - 1.3125rem); }

/* קבוצות בחירה מקוטעות (גודל טקסט / ניגודיות) */
.calcala-a11y-seg { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; }

.calcala-a11y-seg > button {
    padding: 0.25rem 0.6rem;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    background: #fff;
    color: #374151;
    cursor: pointer;
}

.calcala-a11y-seg > button:hover { background: #f3f4f6; }

.calcala-a11y-seg > button[aria-checked="true"] {
    background: #047857;
    border-color: #047857;
    color: #fff;
}

.calcala-a11y-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    padding: 0.75rem 0 0.25rem;
}

.calcala-a11y-links a {
    color: #047857;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.calcala-a11y-reset {
    display: block;
    width: 100%;
    margin-top: 0.6rem;
    padding: 0.45rem;
    font-size: 0.9rem;
    font-weight: 700;
    border: 2px solid #047857;
    border-radius: 0.6rem;
    background: #fff;
    color: #047857;
    cursor: pointer;
}

.calcala-a11y-reset:hover { background: #ecfdf5; }

/* --- השפעות המצבים על האתר --- */

/* גודל טקסט: כל האתר בנוי ב-rem, הגדלת השורש מגדילה הכול פרופורציונלית */
html.calcala-a11y-text-0 { font-size: 90% !important; }
html.calcala-a11y-text-2 { font-size: 112.5% !important; }
html.calcala-a11y-text-3 { font-size: 125% !important; }

/* ניגודיות כהה: רקע שחור, טקסט צהוב; הסרגל עצמו לא מושפע */
html.calcala-a11y-contrast-dark body { background: #000 !important; }
html.calcala-a11y-contrast-dark body *:not(.calcala-a11y-toolbar):not(.calcala-a11y-toolbar *) {
    background-color: #000 !important;
    color: #ffe066 !important;
    border-color: #ffe066 !important;
    box-shadow: none !important;
    text-decoration-color: #ffe066 !important;
}
html.calcala-a11y-contrast-dark body a:not(.calcala-a11y-toolbar a):not(.calcala-a11y-toolbar a *) {
    color: #ffe066 !important;
    text-decoration: underline !important;
}
html.calcala-a11y-contrast-dark img,
html.calcala-a11y-contrast-dark video,
html.calcala-a11y-contrast-dark canvas { filter: brightness(0.8); }

/* ניגודיות בהירה: רקע לבן, טקסט שחור, קישורים כחולים */
html.calcala-a11y-contrast-light body { background: #fff !important; }
html.calcala-a11y-contrast-light body *:not(.calcala-a11y-toolbar):not(.calcala-a11y-toolbar *) {
    background-color: #fff !important;
    color: #000 !important;
    border-color: #000 !important;
    box-shadow: none !important;
}
html.calcala-a11y-contrast-light body a:not(.calcala-a11y-toolbar a):not(.calcala-a11y-toolbar a *) {
    color: #0000ee !important;
    text-decoration: underline !important;
}

/* מונוכרום (גווני אפור) — פילטר על השורש לא שובר position:fixed */
html.calcala-a11y-mono { filter: grayscale(1); }

/* קו תחתון לכל הקישורים (1.4.1) */
html.calcala-a11y-underline a {
    text-decoration: underline !important;
    text-underline-offset: 3px !important;
}

/* עצירת אנימציות ומעברים (2.2.2 ברמת ממשק) */
html.calcala-a11y-stopanim *,
html.calcala-a11y-stopanim *::before,
html.calcala-a11y-stopanim *::after {
    animation: none !important;
    transition: none !important;
}
html.calcala-a11y-stopanim { scroll-behavior: auto !important; }

/* מרווחי שורות מוגדלים (1.4.12: קריאת טקסט) */
html.calcala-a11y-linespace body p,
html.calcala-a11y-linespace body li,
html.calcala-a11y-linespace body dd,
html.calcala-a11y-linespace body dt,
html.calcala-a11y-linespace body td,
html.calcala-a11y-linespace body th,
html.calcala-a11y-linespace body blockquote,
html.calcala-a11y-linespace body figcaption {
    line-height: 2 !important;
}

/* פונט קריא — Arial לכל הטקסט, למעט אייקונים (1.4.12) */
html.calcala-a11y-readfont body *:not(.calcala-a11y-toolbar):not(.calcala-a11y-toolbar *):not(.material-symbols-outlined):not(.material-icons):not(i[class^="fa"]):not(i[class*=" fa"]) {
    font-family: Arial, "Segoe UI", "Helvetica Neue", sans-serif !important;
}

/* סמן עכבר מוגדל */
html.calcala-a11y-bigcursor,
html.calcala-a11y-bigcursor * {
    cursor: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Ccircle cx='24' cy='24' r='14' fill='%23ffffff' stroke='%23000000' stroke-width='6'/%3E%3C/svg%3E") 24 24, auto !important;
}

/* ---------- הדפסה ---------- */
@media print {
    .skip-link,
    .calcala-ticker-toggle,
    .calcala-a11y-toolbar { display: none !important; }
}
