/* ==========================================================================
   BALADY CARE — UNIFIED WCAG 2.2 AA/AAA ACCESSIBILITY STYLESHEET
   Comprehensive Accessibility System:
   - Visual Modes: High Contrast (Black/Yellow), Dark, Light, Sepia
   - Text Controls: Scaling (100%-200%), Line Spacing, Dyslexia Font
   - Cognitive: Color Blind Filters (Protanopia, Deuteranopia, Tritanopia),
                Reduced Motion, Epilepsy Safe (No Flash), Senior Mode, Reader Mode
   - Motor: Min 48px Target Sizes, Voice Command Indicator, Focus Rings
   - Sign Language Avatar & TTS Player Components
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800;900&family=IBM+Plex+Sans+Arabic:wght@400;600;700&family=Inter:wght@400;600;700;800&family=Lexend:wght@400;600;700&display=swap');

/* Skip to Content Link (WCAG 2.2 SC 2.4.1) */
.a11y-skip-link {
  position: absolute;
  top: -100px;
  right: 1rem;
  background: #1e3a8a;
  color: #ffffff;
  padding: 0.85rem 1.5rem;
  font-weight: 800;
  font-size: 1rem;
  z-index: 99999;
  border-radius: 0 0 0.75rem 0.75rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  text-decoration: none;
  border: 3px solid #facc15;
  transition: top 0.2s ease-in-out;
}
.a11y-skip-link:focus {
  top: 0;
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

/* WCAG 2.2 Enhanced Focus Rings (SC 2.4.7 & 2.4.11) */
:focus-visible {
  outline: 3px solid #2563eb !important;
  outline-offset: 3px !important;
}

/* Base Accessible Font & Min Touch Targets (SC 2.5.8 >= 44x44px, AAA >= 48x48px) */
button, a.btn, input[type="submit"], input[type="button"], select {
  min-height: 44px;
}

/* ==========================================================================
   1. VISUAL MODES
   ========================================================================== */

/* A. High Contrast Mode (Yellow / Black - WCAG AAA 7:1+) */
body.a11y-mode-contrast {
  background-color: #000000 !important;
  color: #ffff00 !important;
}
body.a11y-mode-contrast *,
body.a11y-mode-contrast *:before,
body.a11y-mode-contrast *:after {
  background-color: #000000 !important;
  color: #ffff00 !important;
  border-color: #ffff00 !important;
  box-shadow: none !important;
  text-shadow: none !important;
}
body.a11y-mode-contrast a,
body.a11y-mode-contrast button,
body.a11y-mode-contrast input,
body.a11y-mode-contrast select,
body.a11y-mode-contrast textarea {
  color: #ffff00 !important;
  border: 2px solid #ffff00 !important;
  background-color: #121212 !important;
}
body.a11y-mode-contrast :focus-visible {
  outline: 3px solid #00ff00 !important;
  outline-offset: 3px !important;
}
body.a11y-mode-contrast img {
  filter: contrast(150%) brightness(90%);
}

/* B. Dark Mode */
body.a11y-mode-dark {
  background-color: #0f172a !important;
  color: #f8fafc !important;
}
body.a11y-mode-dark .bg-white,
body.a11y-mode-dark .bg-slate-50,
body.a11y-mode-dark .bg-slate-100 {
  background-color: #1e293b !important;
  color: #f8fafc !important;
  border-color: #334155 !important;
}
body.a11y-mode-dark header,
body.a11y-mode-dark aside,
body.a11y-mode-dark .card,
body.a11y-mode-dark table {
  background-color: #1e293b !important;
  color: #f8fafc !important;
  border-color: #334155 !important;
}
body.a11y-mode-dark input,
body.a11y-mode-dark select,
body.a11y-mode-dark textarea {
  background-color: #0f172a !important;
  color: #f8fafc !important;
  border-color: #475569 !important;
}
body.a11y-mode-dark .text-slate-800,
body.a11y-mode-dark .text-slate-700,
body.a11y-mode-dark .text-slate-600 {
  color: #e2e8f0 !important;
}

/* C. Light Mode (Crisp clean white) */
body.a11y-mode-light {
  background-color: #ffffff !important;
  color: #0f172a !important;
}
body.a11y-mode-light .bg-slate-50,
body.a11y-mode-light .bg-slate-100 {
  background-color: #f8fafc !important;
}

/* D. Sepia Mode (Warm Reader-friendly) */
body.a11y-mode-sepia {
  background-color: #fbf0d9 !important;
  color: #433422 !important;
}
body.a11y-mode-sepia .bg-white,
body.a11y-mode-sepia .bg-slate-50,
body.a11y-mode-sepia .bg-slate-100,
body.a11y-mode-sepia aside,
body.a11y-mode-sepia header {
  background-color: #f4e4c1 !important;
  color: #433422 !important;
  border-color: #dec89f !important;
}
body.a11y-mode-sepia input,
body.a11y-mode-sepia select,
body.a11y-mode-sepia textarea {
  background-color: #fff9ed !important;
  color: #433422 !important;
  border-color: #dec89f !important;
}
body.a11y-mode-sepia .text-slate-800,
body.a11y-mode-sepia .text-slate-700,
body.a11y-mode-sepia .text-slate-600 {
  color: #433422 !important;
}

/* ==========================================================================
   2. TEXT CONTROLS & DYSLEXIA
   ========================================================================== */
body.a11y-font-size-1 { font-size: 100% !important; }
body.a11y-font-size-2 { font-size: 115% !important; }
body.a11y-font-size-3 { font-size: 130% !important; }
body.a11y-font-size-4 { font-size: 150% !important; }
body.a11y-font-size-5 { font-size: 175% !important; }

body.a11y-spacing-relaxed {
  line-height: 1.85 !important;
  letter-spacing: 0.04em !important;
  word-spacing: 0.08em !important;
}
body.a11y-spacing-loose {
  line-height: 2.2 !important;
  letter-spacing: 0.08em !important;
  word-spacing: 0.16em !important;
}

/* Dyslexia-Friendly Typography */
body.a11y-font-dyslexic,
body.a11y-font-dyslexic * {
  font-family: 'Lexend', 'Comic Sans MS', 'Trebuchet MS', Arial, sans-serif !important;
  letter-spacing: 0.06em !important;
  line-height: 1.85 !important;
}

/* ==========================================================================
   3. COGNITIVE & ACCESSIBILITY MODES
   ========================================================================== */

/* Color Blind Modes */
body.a11y-cb-protanopia {
  filter: url('#a11y-protanopia-filter') !important;
}
body.a11y-cb-deuteranopia {
  filter: url('#a11y-deuteranopia-filter') !important;
}
body.a11y-cb-tritanopia {
  filter: url('#a11y-tritanopia-filter') !important;
}
body.a11y-cb-monochrome {
  filter: grayscale(100%) contrast(120%) !important;
}

/* Reduced Motion (WCAG SC 2.2.2 & 2.3.3) */
body.a11y-reduced-motion *,
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Epilepsy Safe / No Flash Mode (WCAG SC 2.3.1) */
body.a11y-no-flash * {
  animation: none !important;
  transition: none !important;
  filter: none !important;
}

/* Senior Mode (Large text, high contrast, enlarged targets, simplified view) */
body.a11y-mode-senior {
  font-size: 135% !important;
  line-height: 1.9 !important;
}
body.a11y-mode-senior button,
body.a11y-mode-senior a.btn,
body.a11y-mode-senior input,
body.a11y-mode-senior select {
  min-height: 54px !important;
  font-size: 1.15rem !important;
  padding: 0.85rem 1.25rem !important;
  border-width: 2px !important;
}
body.a11y-mode-senior i.fa-solid,
body.a11y-mode-senior i.fa-regular {
  font-size: 1.35em !important;
}

/* Reader Mode (Distraction-Free Text Centered) */
body.a11y-mode-reader aside,
body.a11y-mode-reader header .banner-decoration,
body.a11y-mode-reader .decorative-element {
  display: none !important;
}
body.a11y-mode-reader main {
  max-width: 800px !important;
  margin: 0 auto !important;
  padding: 2rem 1rem !important;
  font-size: 125% !important;
  line-height: 2 !important;
}

/* Large Cursor Support */
body.a11y-large-cursor,
body.a11y-large-cursor * {
  cursor: default !important;
}
body.a11y-large-cursor a,
body.a11y-large-cursor button,
body.a11y-large-cursor input,
body.a11y-large-cursor select {
  cursor: pointer !important;
}

/* Reading Guide Bar */
#a11yReadingGuide {
  position: fixed;
  left: 0;
  width: 100%;
  height: 4px;
  background: #2563eb;
  pointer-events: none;
  z-index: 99998;
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.6);
  display: none;
}

/* Text-to-Speech Spoken Sentence Highlight */
.a11y-tts-highlight {
  background-color: #fef08a !important;
  color: #0f172a !important;
  border-radius: 4px;
  padding: 2px 4px;
  box-shadow: 0 0 0 2px #eab308;
}

/* ==========================================================================
   4. FLOATING ACCESSIBILITY WIDGET & TOOLBAR (TOP/BOTTOM)
   ========================================================================== */
.a11y-fab-btn {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #ffffff;
  border: 3px solid #ffffff;
  box-shadow: 0 10px 25px -3px rgba(30, 58, 138, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  z-index: 9990;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s;
}
.a11y-fab-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 15px 30px -5px rgba(37, 99, 235, 0.6);
}

/* Sign Language Floating FAB */
.a11y-sign-lang-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #059669, #10b981);
  color: #ffffff;
  border: 3px solid #ffffff;
  box-shadow: 0 10px 25px -3px rgba(5, 150, 105, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  z-index: 9990;
  transition: transform 0.2s, box-shadow 0.2s;
}
.a11y-sign-lang-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 15px 30px -5px rgba(16, 185, 129, 0.6);
}

/* Accessibility Drawer / Quick Menu Modal */
#a11yQuickMenu {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 99999;
  display: flex;
  justify-content: flex-start; /* in RTL, flex-start is the right side of the screen */
  align-items: stretch;
  transition: opacity 0.25s ease;
}
#a11yQuickMenu.hidden {
  display: none !important;
}
.a11y-drawer-panel {
  width: 100% !important;
  max-width: 440px !important;
  height: 100vh !important;
  max-height: 100vh !important;
  background: #ffffff !important;
  color: #1e293b !important;
  box-shadow: -10px 0 35px rgba(0, 0, 0, 0.25) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  padding: 0 !important;
  direction: rtl !important;
  text-align: right !important;
  box-sizing: border-box !important;
  animation: a11yDrawerSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes a11yDrawerSlideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}
.a11y-drawer-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-sizing: border-box;
}
.a11y-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-sizing: border-box;
}
.a11y-drawer-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
  box-sizing: border-box;
}
.a11y-drawer-card {
  width: 100% !important;
  display: flex !important;
  flex-direction: column !important;
  box-sizing: border-box !important;
}

/* Sign Language Avatar Interactive Box */
#a11ySignAvatarBox {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 320px;
  background: #ffffff;
  border-radius: 1.25rem;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.05);
  border: 2px solid #10b981;
  z-index: 9991;
  overflow: hidden;
  direction: rtl;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
#a11ySignAvatarBox.hidden {
  display: none;
}

/* Avatar Stage Animation */
.a11y-avatar-stage {
  height: 190px;
  background: radial-gradient(circle at 50% 40%, #ecfdf5, #d1fae5);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* Animated Hands Keyframes */
@keyframes gesture-wave-right {
  0%, 100% { transform: rotate(0deg) translate(0, 0); }
  25% { transform: rotate(-25deg) translate(-4px, -8px); }
  75% { transform: rotate(15deg) translate(4px, -4px); }
}
@keyframes gesture-wave-left {
  0%, 100% { transform: rotate(0deg) translate(0, 0); }
  35% { transform: rotate(20deg) translate(4px, -6px); }
  70% { transform: rotate(-15deg) translate(-2px, -3px); }
}
@keyframes avatar-head-nod {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

.avatar-active .hand-right {
  animation: gesture-wave-right 1.2s infinite ease-in-out;
  transform-origin: 120px 130px;
}
.avatar-active .hand-left {
  animation: gesture-wave-left 1.4s infinite ease-in-out;
  transform-origin: 80px 130px;
}
.avatar-active .avatar-head {
  animation: avatar-head-nod 2s infinite ease-in-out;
  transform-origin: 100px 70px;
}

/* Voice Command Active Ring */
.a11y-mic-active {
  animation: mic-pulse 1.5s infinite;
}
@keyframes mic-pulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { box-shadow: 0 0 0 15px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Screen Reader Live Announcements (Visually Hidden) */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Accessible Forms Focus & Error Highlighting */
.a11y-field-error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25) !important;
}
.a11y-field-success {
  border-color: #10b981 !important;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2) !important;
}

/* Responsive Mobile Adjustments */
@media (max-width: 640px) {
  .a11y-fab-btn {
    bottom: 16px;
    left: 16px;
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
  .a11y-sign-lang-btn {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
  #a11ySignAvatarBox {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 74px;
  }
}
