/*
 * WUSOOL Accessibility Widget v1.2.0
 * Fixed: all features work on WordPress themes
 */

/* ========== כפתור נגישות ========== */
.a11y-btn {
  position: fixed; bottom: 24px; right: 24px; z-index: 9990;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary-dark, #156695); color: #fff;
  display: flex !important; align-items: center; justify-content: center;
  font-size: 26px; box-shadow: 0 4px 20px rgba(21,102,149,.4);
  cursor: pointer; border: none;
  transition: background .3s ease, transform .3s ease;
  visibility: visible !important; opacity: 1 !important;
}
.a11y-btn:hover { background: var(--primary, #51cbcf); transform: scale(1.08); }

/* ========== פאנל ========== */
.a11y-panel {
  position: fixed; bottom: 90px; right: 24px; z-index: 9991;
  width: 340px; max-height: 80vh;
  background: #fff !important; color: #2d3e50 !important;
  border-radius: 16px; box-shadow: 0 12px 50px rgba(0,0,0,.2);
  overflow: hidden; transform: scale(0) translateY(20px);
  transform-origin: bottom right; opacity: 0;
  transition: transform .3s ease, opacity .3s ease;
  pointer-events: none; direction: rtl;
}
.a11y-panel.open { transform: scale(1) translateY(0); opacity: 1; pointer-events: auto; }
.a11y-panel-header {
  background: linear-gradient(135deg, #156695, #0d2137) !important;
  color: #fff !important; padding: 18px 20px;
  display: flex; justify-content: space-between; align-items: center;
}
.a11y-panel-header h3 { font-size: 17px; color: #fff !important; margin: 0; display: flex; align-items: center; gap: 8px; }
.a11y-panel-header h3 i { font-size: 30px !important; }
.a11y-panel-close { background: none; border: none; color: #fff !important; font-size: 22px; cursor: pointer; padding: 4px; }
.a11y-panel-logo {
  height: 36px; width: auto;
  border-radius: 12px;
  object-fit: contain;
}
.a11y-panel-body { padding: 16px; overflow-y: auto; max-height: calc(80vh - 120px); }

/* ========== גריד כפתורים ========== */
.a11y-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.a11y-grid-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 8px; border: 2px solid #e8f0f2; border-radius: 8px;
  cursor: pointer; background: #fff !important;
  transition: border-color .25s, background-color .25s;
  font-family: Tahoma, sans-serif; font-size: 12px;
  color: #2d3e50 !important; font-weight: 700; text-align: center;
}
.a11y-grid-btn:hover { border-color: #51cbcf !important; background: #f0fdfe !important; color: #0d4f75 !important; }
.a11y-grid-btn.active { border-color: #51cbcf !important; background: rgba(81,203,207,.15) !important; color: #156695 !important; }
.a11y-grid-btn i { font-size: 22px; color: #156695 !important; }
.a11y-grid-btn:hover i { color: #51cbcf !important; }
.a11y-grid-btn.active i { color: #51cbcf !important; }

/* ========== סליידרים ========== */
.a11y-slider-group { margin-bottom: 14px; padding: 10px 0; border-top: 1px solid #e8f0f2; }
.a11y-slider-group label { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; color: #1a2a3a !important; margin-bottom: 8px; }
.a11y-slider-group label span { font-size: 12px; color: #51cbcf !important; font-weight: 400; }
.a11y-slider-group input[type="range"] { width: 100%; accent-color: #51cbcf; cursor: pointer; height: 6px; }

/* ── Font size buttons ── */
.a11y-font-btn {
  width: 42px !important; height: 42px !important;
  border: 2px solid #c5cdd5 !important; border-radius: 8px !important;
  background: #fff !important; color: #1a2a3a !important;
  font-size: 18px !important; font-weight: 800 !important;
  cursor: pointer; display: flex !important;
  align-items: center !important; justify-content: center !important;
  transition: all .2s;
}
.a11y-font-btn:hover { border-color: #51cbcf !important; color: #156695 !important; background: #f0fdfe !important; }

/* ========== פעולות ========== */
.a11y-reset {
  width: 100%; padding: 12px; border: 2px solid #ef4444; border-radius: 8px;
  background: #fff !important; color: #ef4444 !important; font-family: Tahoma; font-size: 14px;
  font-weight: 700; cursor: pointer; transition: all .3s ease; margin-top: 8px;
}
.a11y-reset:hover { background: #ef4444 !important; color: #fff !important; }
.a11y-declare-link {
  display: block; text-align: center; margin-top: 12px; font-size: 13px;
  color: #156695 !important; text-decoration: underline; cursor: pointer; font-weight: 700;
}

/* ==============================================================
   ACCESSIBILITY FEATURES
   FIX: Use both #pageWrap AND body fallback for WP compatibility
   ============================================================== */

/* ── 1. High Contrast ── */
body.a11y-high-contrast #pageWrap { filter: contrast(1.5) !important; }
body.a11y-high-contrast:not(:has(#pageWrap)) > *:not(.a11y-btn):not(.a11y-panel):not(.a11y-popup-overlay):not(#a11yTOC):not(#readingLine):not(script):not(style):not(link) {
  filter: contrast(1.5) !important;
}

/* ── 2. Dark Mode ── */
body.a11y-dark-mode { background: #1a1a1a !important; color: #e0e0e0 !important; }
body.a11y-dark-mode *:not(.a11y-btn):not(.a11y-panel):not(.a11y-panel *):not(.a11y-popup-overlay):not(.a11y-popup-overlay *):not(#a11yTOC):not(#a11yTOC *) {
  background-color: inherit; color: inherit;
}
body.a11y-dark-mode h1, body.a11y-dark-mode h2, body.a11y-dark-mode h3, body.a11y-dark-mode h4 { color: #a8e6e8 !important; }
body.a11y-dark-mode a:not(.a11y-panel a):not(.a11y-popup-overlay a) { color: #a8e6e8 !important; }
body.a11y-dark-mode .a11y-btn { background: #156695 !important; color: #fff !important; }
body.a11y-dark-mode .a11y-panel { background: #fff !important; color: #2d3e50 !important; }
body.a11y-dark-mode .a11y-panel * { color: #2d3e50 !important; background: transparent !important; }
body.a11y-dark-mode .a11y-panel .a11y-panel-header, body.a11y-dark-mode .a11y-panel .a11y-panel-header * { background: linear-gradient(135deg,#156695,#0d2137) !important; color: #fff !important; }
body.a11y-dark-mode .a11y-panel .a11y-grid-btn { background: #fff !important; color: #2d3e50 !important; border-color: #e8f0f2 !important; }
body.a11y-dark-mode .a11y-panel .a11y-grid-btn i { color: #156695 !important; }
body.a11y-dark-mode .a11y-popup-overlay > div { background: #fff !important; color: #2d3e50 !important; }
body.a11y-dark-mode .a11y-popup-overlay > div * { color: #2d3e50 !important; }
body.a11y-dark-mode #a11yTOC { background: #fff !important; color: #2d3e50 !important; }
body.a11y-dark-mode #a11yTOC * { color: #2d3e50 !important; }

/* ── 3. Light Contrast ── */
body.a11y-light-contrast { background: #fffff8 !important; }
body.a11y-light-contrast #pageWrap { filter: brightness(1.3) contrast(0.85) !important; }
body.a11y-light-contrast:not(:has(#pageWrap)) > *:not(.a11y-btn):not(.a11y-panel):not(.a11y-popup-overlay):not(#a11yTOC):not(#readingLine):not(script):not(style):not(link) {
  filter: brightness(1.3) contrast(0.85) !important;
}

/* ── 4. Grayscale ── */
body.a11y-grayscale #pageWrap { filter: grayscale(1) !important; }
body.a11y-grayscale:not(:has(#pageWrap)) > *:not(.a11y-btn):not(.a11y-panel):not(.a11y-popup-overlay):not(#a11yTOC):not(#readingLine):not(script):not(style):not(link) {
  filter: grayscale(1) !important;
}

/* ── 5. Invert Colors ── */
body.a11y-invert #pageWrap { filter: invert(1) !important; }
body.a11y-invert:not(:has(#pageWrap)) > *:not(.a11y-btn):not(.a11y-panel):not(.a11y-popup-overlay):not(#a11yTOC):not(#readingLine):not(script):not(style):not(link) {
  filter: invert(1) !important;
}

/* ── 6. Highlight Links ── */
body.a11y-highlight-links a:not(.a11y-panel a):not(.a11y-popup-overlay a):not(.a11y-declare-link) {
  outline: 3px solid #f59e0b !important;
  outline-offset: 2px;
  background: rgba(245,158,11,.12) !important;
}

/* ── 7. Underline Links ── */
body.a11y-underline-links a { text-decoration: underline !important; }

/* ── 8. Big Cursor — 48px ── */
body.a11y-big-cursor, body.a11y-big-cursor * {
  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='M6 6l30 12-12 6-6 12z' fill='%23ffffff' stroke='%23000000' stroke-width='3'/%3E%3Cpath d='M6 6l30 12-12 6-6 12z' fill='%23ffffff' stroke='%23156695' stroke-width='1.5'/%3E%3C/svg%3E") 6 6, auto !important;
}

/* ── 9. Reading Guide ── */
body.a11y-reading-guide .a11y-reading-line {
  position: fixed; left: 0; right: 0; height: 6px;
  background: rgba(81,203,207,.85); z-index: 99999;
  pointer-events: none; transition: top .05s;
  box-shadow: 0 0 10px rgba(81,203,207,.5);
}

/* ── 10. Stop Animations ── */
body.a11y-no-animations *, body.a11y-no-animations *::before, body.a11y-no-animations *::after {
  animation: none !important; transition: none !important;
}

/* ── 11. Dyslexia Font ── */
body.a11y-dyslexia * {
  font-family: OpenDyslexic, Comic Sans MS, Arial, sans-serif !important;
  letter-spacing: .05em !important; word-spacing: .15em !important;
}

/* ── 12. Keyboard Navigation — enhanced ── */
body.a11y-focus-highlight *:focus {
  outline: 3px solid #f59e0b !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 5px rgba(245,158,11,.2) !important;
}
body.a11y-focus-highlight a:focus, body.a11y-focus-highlight button:focus,
body.a11y-focus-highlight input:focus, body.a11y-focus-highlight select:focus,
body.a11y-focus-highlight textarea:focus {
  outline: 3px solid #f59e0b !important;
  outline-offset: 3px !important;
}

/* ── 13. Show ALT ── */
body.a11y-show-alt img[alt] { position: relative; }
body.a11y-show-alt img[alt]::after {
  content: attr(alt); display: block; background: rgba(0,0,0,.85);
  color: #fff !important; font-size: 12px; padding: 6px 10px;
  border-radius: 0 0 8px 8px; text-align: center;
}

/* ── 14. Hide Images ── */
body.a11y-hide-images img:not(.a11y-panel img):not(.a11y-popup-overlay img) { opacity: 0.05 !important; }

/* ── 15. Word Spacing ── */
body.a11y-word-spacing *:not(.a11y-panel *):not(.a11y-popup-overlay *) { word-spacing: .3em !important; }

/* ── 16. TOC — handled by JS, popup styled inline ── */

/* ── 17. ADHD Profile ── */
body.a11y-adhd-profile * { transition: none !important; animation: none !important; }
body.a11y-adhd-profile p, body.a11y-adhd-profile li, body.a11y-adhd-profile span {
  letter-spacing: .02em !important; word-spacing: .12em !important; line-height: 2 !important;
}

/* ── 18. Cognitive Profile ── */
body.a11y-cognitive-profile * { font-family: Tahoma, Arial, sans-serif !important; letter-spacing: .03em !important; }
body.a11y-cognitive-profile p, body.a11y-cognitive-profile li, body.a11y-cognitive-profile span {
  line-height: 2.1 !important; word-spacing: .15em !important;
}

/* ── 19. Screen Reader — handled by JS ── */
/* ── 20. Mute Media — handled by JS ── */

/* ── 21. Text Magnifier — targets content only, not layout ── */
body.a11y-text-magnifier p, body.a11y-text-magnifier li,
body.a11y-text-magnifier span:not(.a11y-panel span),
body.a11y-text-magnifier td, body.a11y-text-magnifier th,
body.a11y-text-magnifier blockquote, body.a11y-text-magnifier figcaption {
  font-size: 120% !important;
}

/* ── Text Align — force with !important for WP themes ── */
body[data-a11y-align="right"] *:not(.a11y-panel *):not(.a11y-popup-overlay *):not(#a11yTOC *) { text-align: right !important; }
body[data-a11y-align="center"] *:not(.a11y-panel *):not(.a11y-popup-overlay *):not(#a11yTOC *) { text-align: center !important; }
body[data-a11y-align="left"] *:not(.a11y-panel *):not(.a11y-popup-overlay *):not(#a11yTOC *) { text-align: left !important; }

/* ── Font Size — target content, not layout elements ── */
html.a11y-font-scaled { /* applied by JS */ }
html.a11y-font-scaled body *:not(.a11y-panel *):not(.a11y-popup-overlay *):not(.a11y-btn):not(nav *):not(header *):not(#wpadminbar *) {
  font-size: inherit !important;
}

/* ========== מובייל ========== */
@media (max-width: 768px) {
  .a11y-btn { width: 50px; height: 50px; font-size: 22px; bottom: 24px; right: 16px; }
  .a11y-panel { width: calc(100vw - 32px); right: 16px; bottom: 84px; max-height: 75vh; }
  .a11y-panel-body { max-height: calc(75vh - 70px); -webkit-overflow-scrolling: touch; }
  .a11y-grid { gap: 8px; }
  .a11y-grid-btn { padding: 10px 6px; font-size: 11px; gap: 4px; }
  .a11y-grid-btn i { font-size: 18px; }
  .a11y-panel-header { padding: 14px 16px; }
  .a11y-panel-header h3 { font-size: 15px; }
  .a11y-panel-header h3 i { font-size: 22px !important; }
  .a11y-font-btn { width: 36px !important; height: 36px !important; font-size: 15px !important; }
  .a11y-popup-overlay > div { margin-top: 2vh !important; max-height: 92vh !important; width: 95% !important; }
}

/* ========== Popup Overlays ========== */
.a11y-popup-overlay {
  display: none; position: fixed; inset: 0; z-index: 99999;
  background: rgba(0,0,0,.6); overflow-y: auto;
  align-items: flex-start; justify-content: center;
}
.a11y-popup-overlay.active { display: flex !important; }
.a11y-popup-overlay > div { background: #fff !important; color: #2d3e50 !important; }

/* ========== Left-positioned ========== */
.a11y-btn.a11y-left { right: auto; left: 24px; }
.a11y-panel.a11y-left { right: auto; left: 24px; transform-origin: bottom left; }
@media (max-width: 768px) {
  .a11y-btn.a11y-left { right: auto; left: 16px; }
  .a11y-panel.a11y-left { right: auto; left: 16px; }
}

/* ========== Language Switcher ========== */
.a11y-lang-switch { display: flex; gap: 6px; justify-content: center; margin-top: 10px; padding-top: 10px; border-top: 1px solid #e8f0f2; }
.a11y-lang-btn {
  padding: 4px 10px; border: 1px solid #d1d5db; border-radius: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  background: #fff !important; color: #475569 !important; transition: all .2s;
}
.a11y-lang-btn:hover, .a11y-lang-btn.active { border-color: #156695; background: #e0f2fe !important; color: #156695 !important; }

/* ═══════════════════════════════════════
   Accessibility Statement Popup
   ═══════════════════════════════════════ */
.a11y-statement-box {
  background: #fff !important; color: #1e293b !important;
  border-radius: 16px; max-width: 680px; width: 94%;
  max-height: 90vh; overflow-y: auto;
  padding: 0; position: relative;
  margin: 3vh auto; box-shadow: 0 24px 80px rgba(0,0,0,.25);
}

/* Close button — VISIBLE, dark circle */
.a11y-stmt-close {
  position: sticky; top: 12px; float: left; z-index: 10;
  margin: 12px 0 0 12px;
  width: 40px; height: 40px; border-radius: 50%;
  background: #1e293b !important; color: #fff !important;
  border: 2px solid #fff; font-size: 22px; line-height: 1;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; transition: background .2s;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.a11y-stmt-close:hover { background: #dc2626 !important; }

/* Header */
.a11y-stmt-header {
  background: linear-gradient(135deg, #156695, #0d2137);
  color: #fff; text-align: center;
  padding: 32px 24px 24px; border-radius: 16px 16px 0 0;
}
.a11y-stmt-header h2 {
  font-size: 22px; margin: 0 0 4px; color: #fff !important;
  font-weight: 800;
}
.a11y-stmt-subtitle { font-size: 15px; color: #a8e6e8 !important; margin: 0 0 6px; font-weight: 600; }
.a11y-stmt-date { font-size: 12px; color: rgba(255,255,255,.6) !important; margin: 0; }
.a11y-stmt-biz-logo { max-height: 50px; max-width: 180px; margin-bottom: 12px; border-radius: 8px; }

/* Sections */
.a11y-stmt-section {
  padding: 20px 28px; border-bottom: 1px solid #f1f5f9;
}
.a11y-stmt-section h3 {
  font-size: 16px; font-weight: 700; color: #156695 !important;
  margin: 0 0 10px; display: flex; align-items: center; gap: 6px;
}
.a11y-stmt-section p {
  font-size: 14px; line-height: 1.9; color: #374151 !important; margin: 0 0 8px;
}
.a11y-stmt-section p:last-child { margin-bottom: 0; }

/* Principles list */
.a11y-stmt-principles {
  list-style: none; padding: 0; margin: 10px 0 0;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.a11y-stmt-principles li {
  background: #f0f7fc; color: #156695 !important;
  padding: 6px 14px; border-radius: 20px;
  font-size: 13px; font-weight: 600;
}

/* Features tags */
.a11y-stmt-features {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px;
}
.a11y-stmt-feat-tag {
  background: #f0fdf4; color: #16a34a !important;
  padding: 5px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
  border: 1px solid #bbf7d0;
}

/* Contact card */
.a11y-stmt-contact-card {
  margin: 0 28px 20px; padding: 20px;
  background: #f8fafc; border-radius: 12px;
  border: 1px solid #e2e8f0;
}
.a11y-stmt-contact-card h3 {
  font-size: 16px; font-weight: 700; color: #1e293b !important;
  margin: 0 0 12px;
}
.a11y-stmt-contact-row {
  font-size: 14px; color: #374151 !important;
  padding: 6px 0; border-bottom: 1px solid #e8f0f2;
}
.a11y-stmt-contact-row:last-of-type { border-bottom: none; }
.a11y-stmt-contact-row a { color: #156695 !important; text-decoration: none; font-weight: 600; }
.a11y-stmt-contact-row a:hover { text-decoration: underline; }

/* Footer */
.a11y-stmt-footer {
  text-align: center; padding: 20px 28px 24px;
  border-top: 1px solid #e2e8f0;
}
.a11y-stmt-footer p { font-size: 11px; color: #94a3b8 !important; margin: 6px 0 0; }

/* Mobile */
@media (max-width: 768px) {
  .a11y-statement-box { width: 96%; margin: 1vh auto; max-height: 95vh; }
  .a11y-stmt-header { padding: 24px 16px 18px; }
  .a11y-stmt-header h2 { font-size: 18px; }
  .a11y-stmt-section { padding: 16px 18px; }
  .a11y-stmt-contact-card { margin: 0 18px 16px; }
  .a11y-stmt-close { width: 36px; height: 36px; font-size: 18px; }
}

/* Dark mode protection for statement */
body.a11y-dark-mode .a11y-statement-box { background: #fff !important; color: #1e293b !important; }
body.a11y-dark-mode .a11y-statement-box * { color: inherit !important; }
body.a11y-dark-mode .a11y-statement-box .a11y-stmt-header,
body.a11y-dark-mode .a11y-statement-box .a11y-stmt-header * { color: #fff !important; }
body.a11y-dark-mode .a11y-statement-box .a11y-stmt-close { background: #1e293b !important; color: #fff !important; }
