/*
 * NFP KENYA — WCAG 2.1 Level AA Accessibility Stylesheet
 * Covers: focus indicators, high contrast, large text,
 *         dyslexia-friendly font, reduced motion, colour contrast,
 *         form accessibility, skip link visibility.
 * ============================================================ */

/* ── 1. GOOGLE FONTS — Dyslexia-friendly (Lexend) ───────────── */
@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@300;400;500;600;700&display=swap');

/* ── 2. SKIP LINK ────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  z-index: 99999;
  background: #1a5c2e;
  color: #ffffff !important;
  padding: 12px 20px;
  border-radius: 0 0 8px 8px;
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
  transition: top 0.2s;
  border: 3px solid #ffffff;
}
.skip-link:focus {
  top: 0;
  outline: 3px solid #ffdd00;
  outline-offset: 2px;
}

/* ── 3. ENHANCED FOCUS INDICATORS (WCAG 2.4.7) ──────────────── */
/* Remove browser default and replace with a visible, high-contrast ring */
*:focus {
  outline: 3px solid #005fcc;
  outline-offset: 3px;
}
*:focus:not(:focus-visible) {
  outline: none; /* hide for mouse users */
}
*:focus-visible {
  outline: 3px solid #005fcc;
  outline-offset: 3px;
  border-radius: 3px;
}

/* Buttons, links, inputs — stronger focus ring */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #005fcc;
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(0, 95, 204, 0.25);
  border-radius: 3px;
}

/* ── 4. COLOUR CONTRAST IMPROVEMENTS (WCAG 1.4.3) ───────────── */
/* Ensure body text is dark enough on light backgrounds */
body {
  color: #1a1a1a; /* higher contrast than typical #333 */
}

/* Light-gray text helpers sometimes used in components */
.text-light,
[class*="text-light"] {
  color: #595959 !important; /* 7:1 on white — AA+ */
}

/* Placeholder text contrast */
::placeholder {
  color: #767676; /* minimum 4.5:1 on white */
  opacity: 1;
}

/* Disabled form controls — keep legible */
:disabled,
[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── 5. FORM ACCESSIBILITY (WCAG 3.3.1, 3.3.2) ──────────────── */

/* Required field indicator */
.form-label .req,
label .req {
  color: #c0392b;
  margin-left: 3px;
  font-weight: 700;
  aria-hidden: true;
}

/* Accessible error state */
.field-error input,
.field-error select,
.field-error textarea {
  border-color: #c0392b !important;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.2) !important;
}
.field-error-msg {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #c0392b;
  font-size: 0.85rem;
  margin-top: 5px;
  font-weight: 600;
}
.field-error-msg::before {
  content: '⚠';
  flex-shrink: 0;
}

/* Accessible success state */
.field-success input,
.field-success select,
.field-success textarea {
  border-color: #1a5c2e !important;
  box-shadow: 0 0 0 3px rgba(26, 92, 46, 0.15) !important;
}

/* Form hint text (aria-describedby) */
.field-hint {
  font-size: 0.82rem;
  color: #595959;
  margin-top: 4px;
  line-height: 1.5;
}

/* Input focus — override any style.css with accessible version */
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid #005fcc !important;
  outline-offset: 1px !important;
  border-color: #005fcc !important;
  box-shadow: 0 0 0 4px rgba(0, 95, 204, 0.2) !important;
}

/* ── 6. LINK ACCESSIBILITY ───────────────────────────────────── */
/* Links that rely on colour alone need a non-colour differentiator */
main a:not(.btn):not([class*="nav"]):not([class*="footer"]) {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── 7. ACCESSIBILITY TOOLBAR WIDGET ─────────────────────────── */
#a11y-toolbar {
  position: fixed;
  bottom: 80px;
  left: 0;
  z-index: 99998;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-family: var(--font-body, 'Inter', sans-serif);
}

/* Trigger button */
#a11y-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1a5c2e;
  color: #ffffff;
  border: none;
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 2px 2px 12px rgba(0,0,0,0.25);
  transition: background 0.2s, transform 0.2s;
  white-space: nowrap;
}
#a11y-trigger:hover { background: #0f3d1e; }
#a11y-trigger:focus-visible {
  outline: 3px solid #ffdd00;
  outline-offset: 2px;
}
#a11y-trigger svg { flex-shrink: 0; }

/* Panel */
#a11y-panel {
  background: #ffffff;
  border: 2px solid #1a5c2e;
  border-left: none;
  border-radius: 0 12px 12px 0;
  padding: 16px;
  width: 240px;
  box-shadow: 4px 4px 20px rgba(0,0,0,0.15);
  display: none;
}
#a11y-panel.open { display: block; }
#a11y-panel h2 {
  font-size: 0.88rem;
  font-weight: 800;
  color: #1a5c2e;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1.5px solid #e5e7eb;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Option rows */
.a11y-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
  gap: 10px;
}
.a11y-option:last-child { border-bottom: none; }
.a11y-option-label {
  font-size: 0.85rem;
  color: #1a1a1a;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.3;
}
.a11y-option-label span { font-size: 1rem; }

/* Toggle switch */
.a11y-toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.a11y-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.a11y-toggle-track {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 50px;
  cursor: pointer;
  transition: background 0.2s;
  display: block; /* works for both span and label */
  /* prevent label default margin/padding */
  margin: 0;
  padding: 0;
}
.a11y-toggle-track::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.a11y-toggle input:checked + .a11y-toggle-track { background: #1a5c2e; }
.a11y-toggle input:checked + .a11y-toggle-track::after { transform: translateX(20px); }
.a11y-toggle input:focus-visible + .a11y-toggle-track {
  outline: 3px solid #005fcc;
  outline-offset: 2px;
}
/* Prevent the hidden checkbox from interfering with layout */
.a11y-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* Reset button */
#a11y-reset {
  width: 100%;
  margin-top: 12px;
  padding: 8px;
  background: none;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.8rem;
  color: #595959;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.2s;
}
#a11y-reset:hover { border-color: #1a5c2e; color: #1a5c2e; }
#a11y-reset:focus-visible { outline: 3px solid #005fcc; outline-offset: 2px; }

/* ── 8. HIGH CONTRAST MODE (body.a11y-contrast) ──────────────── */
body.a11y-contrast {
  background: #000000 !important;
  color: #ffffff !important;
}
body.a11y-contrast *:not(script):not(style) {
  background-color: #000000 !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}
body.a11y-contrast a { color: #ffdd00 !important; text-decoration: underline !important; }
body.a11y-contrast button,
body.a11y-contrast .btn {
  background: #ffdd00 !important;
  color: #000000 !important;
  border: 2px solid #ffffff !important;
}
body.a11y-contrast img { filter: grayscale(30%) contrast(120%); }
body.a11y-contrast .navbar,
body.a11y-contrast .topbar,
body.a11y-contrast .footer {
  background: #111111 !important;
  border-bottom: 2px solid #ffffff !important;
}
body.a11y-contrast .nav-logo-text .name,
body.a11y-contrast .nav-logo-text .acronym,
body.a11y-contrast .nav-links a {
  color: #ffffff !important;
}
body.a11y-contrast input,
body.a11y-contrast select,
body.a11y-contrast textarea {
  background: #111111 !important;
  color: #ffffff !important;
  border: 2px solid #ffdd00 !important;
}
body.a11y-contrast #a11y-panel { background: #111111 !important; }
body.a11y-contrast #a11y-trigger { background: #ffdd00 !important; color: #000000 !important; }

/* ── 9. LARGE TEXT MODE (body.a11y-large-text) ───────────────── */
body.a11y-large-text {
  font-size: 120% !important;
}
body.a11y-large-text p,
body.a11y-large-text li,
body.a11y-large-text label,
body.a11y-large-text span,
body.a11y-large-text td,
body.a11y-large-text th {
  font-size: 1.1em !important;
  line-height: 1.8 !important;
}
body.a11y-large-text h1 { font-size: 2.4rem !important; }
body.a11y-large-text h2 { font-size: 2rem !important; }
body.a11y-large-text h3 { font-size: 1.6rem !important; }
body.a11y-large-text h4 { font-size: 1.3rem !important; }
body.a11y-large-text .btn,
body.a11y-large-text button {
  font-size: 1.05rem !important;
  padding: 14px 28px !important;
}

/* ── 10. DYSLEXIA-FRIENDLY FONT (body.a11y-dyslexia) ────────── */
body.a11y-dyslexia,
body.a11y-dyslexia * {
  font-family: 'Lexend', sans-serif !important;
  letter-spacing: 0.04em !important;
  word-spacing: 0.12em !important;
  line-height: 1.75 !important;
}
body.a11y-dyslexia p,
body.a11y-dyslexia li {
  max-width: 75ch;
}

/* ── 11. REDUCED MOTION (body.a11y-reduced-motion) ──────────── */
body.a11y-reduced-motion *,
body.a11y-reduced-motion *::before,
body.a11y-reduced-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

/* Also respect system preference natively */
@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;
  }
}

/* ── 12. UNDERLINE LINKS (body.a11y-underline) ───────────────── */
body.a11y-underline a {
  text-decoration: underline !important;
  text-underline-offset: 4px !important;
}

/* ── 13. SCREEN READER ONLY UTILITY ──────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── 14. ARIA LIVE REGION ────────────────────────────────────── */
#a11y-live-region {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ── 15. FOCUS TRAP OVERLAY (for modals/mobile nav) ─────────── */
[aria-modal="true"] {
  isolation: isolate;
}

/* ── 16. MOBILE RESPONSIVE ───────────────────────────────────── */
@media (max-width: 480px) {
  #a11y-panel { width: 220px; }
  #a11y-trigger { padding: 10px 12px; font-size: 0.8rem; }
}

/* ── 17. COOKIE BANNER AVOIDANCE ─────────────────────────────── */
/* When the cookie banner is open, shift the toolbar above it.
   The JS in accessibility.js adds .a11y-above-cookie to #a11y-toolbar
   and removes it when the banner is dismissed.                   */
#a11y-toolbar.a11y-above-cookie {
  /* Move up by the measured height of the cookie banner + a gap */
  bottom: var(--cookie-banner-height, 320px);
  transition: bottom 0.3s ease;
}
#a11y-toolbar {
  transition: bottom 0.3s ease;
}