/* ==========================================================================
   Car Key Technologies — Accessibility widget, skip links, focus states,
   and light/dark/high-contrast theme system.
   Loaded after styles.css so these rules can override site tokens.
   ========================================================================== */

/* ---------- Dark theme: re-map the existing design tokens ----------
   styles.css already reads color from CSS custom properties almost
   everywhere, so re-defining the tokens re-themes the whole site
   without touching every selector. The dark hero/nav/footer sections
   use --black/--near-black directly and are intentionally left as-is
   in both themes. */
:root[data-theme="dark"] {
  --white: #17171b;
  --off-white: #1c1c21;
  --ink: #f2f2f4;
  --gray-900: #e7e7ea;
  --gray-700: #c6c6cc;
  --gray-500: #9d9da5;
  --gray-300: #6d6d75;
  --gray-200: #3a3a40;
  --gray-100: #232327;
}
:root[data-theme="dark"] .category-nav { background: rgba(18, 18, 21, 0.88); }
:root[data-theme="dark"] .form-success { background: #0f2417; border-color: #1f4a2c; color: #7cd992; }

/* ---------- Fix: sections that are permanently dark regardless of theme ----------
   .nav, .hero, .page-hero, .footer, .cta-banner, .section-dark, .card-dark, and the
   ghost/accent/gradient buttons all get their background from --black/--near-black/
   --gradient-dark/--gradient-brand or a hardcoded rgba(), none of which change with
   the theme. Their text, however, was styled with var(--white)/var(--ink) in
   styles.css, which DOES change with the theme (and with high-contrast mode, since
   that also sets data-theme="dark" — see a11y.js applyTheme()). Left alone, dark
   mode remaps --white to a near-black surface color, turning this fixed-white text
   into near-invisible near-black-on-black. Pin it back to real white here instead
   of remapping the shared token, since the token is also legitimately used for
   backgrounds elsewhere on the same page. */
:root[data-theme="dark"] .brand,
:root[data-theme="dark"] .nav-links a:hover,
:root[data-theme="dark"] .nav-links a.active,
:root[data-theme="dark"] .nav-toggle,
:root[data-theme="dark"] .hero,
:root[data-theme="dark"] .hero h1,
:root[data-theme="dark"] .hero-stats .stat b,
:root[data-theme="dark"] .btn-ghost,
:root[data-theme="dark"] .page-hero,
:root[data-theme="dark"] .page-hero h1,
:root[data-theme="dark"] .phone-callout a,
:root[data-theme="dark"] .section-dark h2,
:root[data-theme="dark"] .section-dark h3,
:root[data-theme="dark"] .card-dark h3,
:root[data-theme="dark"] .stat-bar .stat b,
:root[data-theme="dark"] .cta-banner,
:root[data-theme="dark"] .cta-banner h2,
:root[data-theme="dark"] .cta-phone a,
:root[data-theme="dark"] .footer-phone a,
:root[data-theme="dark"] .footer a:hover,
:root[data-theme="dark"] .btn-accent,
:root[data-theme="dark"] .step::before {
  color: #ffffff;
}
:root[data-theme="dark"] .phone-callout .icon-circle svg {
  stroke: #ffffff;
}

/* Fix: .eyebrow and .link-arrow use var(--blue), which the dark-theme remap above does
   NOT touch (it stays the light-theme value, #0071e3). Left alone, that text sits on
   the now-dark surfaces at ~3.6:1 (verified live via axe-core: link-arrow measured
   3.61:1 against #1c1c21). Swap to the existing --cyan accent already used elsewhere
   on dark surfaces (nav/footer/cta phone icons), which clears contrast comfortably.
   Scoped to exclude high-contrast mode: that theme already sets its own --blue
   (#66b3ff), independently verified passing, and this selector's higher specificity
   would otherwise silently override that already-correct value. */
:root[data-theme="dark"]:not(.a11y-contrast-high) .eyebrow,
:root[data-theme="dark"]:not(.a11y-contrast-high) .link-arrow {
  color: #29c1ff;
}

/* ---------- High-contrast mode (WCAG AA/AAA target): black / white / yellow ----------
   !important on every token here is required, not decorative: html.a11y-contrast-high
   (0 IDs, 1 class, 1 type) is LESS specific than the dark-theme remap block above,
   :root[data-theme="dark"] (0 IDs, 2 "class-level" selectors, 0 type) — a pseudo-class
   plus an attribute selector together outweigh a class plus a type selector. Since
   high-contrast mode also sets data-theme="dark" (see a11y.js applyTheme()), both
   blocks match simultaneously on every element, and without !important the dark-theme
   values for --white/--off-white/--ink/--gray-900…--gray-100 silently win over the
   high-contrast values for those same tokens — e.g. .btn-primary's "black-on-white"
   text/background collapsed to near-white-on-near-white (a real, live-verified bug). */
html.a11y-contrast-high {
  --black: #000000 !important;
  --near-black: #000000 !important;
  --ink: #ffffff !important;
  --white: #000000 !important;
  --off-white: #000000 !important;
  --gray-900: #ffffff !important;
  --gray-700: #f2f2f2 !important;
  --gray-500: #e2e2e2 !important;
  --gray-300: #cfcfcf !important;
  --gray-200: #555555 !important;
  --gray-100: #1a1a1a !important;
  --blue: #66b3ff !important;
  --blue-dark: #3388ff !important;
  --cyan: #7fe6ff !important;
  --gradient-brand: #1a73e8 !important;
  --gradient-dark: #000000 !important;
  --shadow-soft: none !important;
  --shadow-card: none !important;
}
html.a11y-contrast-high * { text-shadow: none !important; box-shadow: none !important; }
html.a11y-contrast-high body { background: #000 !important; }
html.a11y-contrast-high a { color: #ffd400 !important; text-decoration: underline !important; }
html.a11y-contrast-high .btn { border: 2px solid #fff !important; }
html.a11y-contrast-high .card,
html.a11y-contrast-high .card-dark,
html.a11y-contrast-high .form-card { border: 2px solid #fff !important; }
/* Fix: .btn-accent is a <a> link, so the blanket "a" rule above forces its text to
   yellow (#ffd400). Its background comes from --gradient-brand, which in this mode
   resolves to a solid blue (#1a73e8) rather than black — yellow-on-blue measures
   3.15:1, well under the 4.5:1 minimum (verified live via axe-core). Force the
   background to black here too, matching every other high-contrast button, which
   restores the theme's yellow-on-black contrast (14.67:1). */
html.a11y-contrast-high .btn-accent { background: #000000 !important; }
/* Fix: .btn-primary is also a <a> link, so the same blanket rule forces its text
   yellow — but its background is var(--ink), which resolves to WHITE in this mode
   (by design: it's the theme's one light/inverted button). Yellow-on-white measures
   1.43:1, effectively invisible. NOTE: axe-core did not flag this — it silently
   skips color-contrast checks on :visited links (a documented browser-privacy
   limitation), and this link (href="partners.html") had been visited during
   testing. Found only by manually computing contrast on every button-styled link,
   bypassing that blind spot. Restore the button's intended black text. */
html.a11y-contrast-high .btn-primary { color: #000000 !important; }
/* Fix: the skip links ("Skip to main content" etc.) have their own hardcoded
   background (#0071e3, the brand blue — not a themed token, same in every mode) and
   their own "color: #fff !important". The blanket high-contrast link rule above
   still wins on specificity (html.a11y-contrast-high a beats .a11y-skip-link alone),
   repainting that text yellow — yellow-on-blue at 14px bold measures 3.28:1, under
   the 4.5:1 small-text minimum. Found by manually computing contrast for every
   link/button on the page (axe-core wouldn't have flagged this one either: skip
   links are only reachable/visible via keyboard focus, which most contrast tooling,
   including axe-core's automated color-contrast rule, does not simulate). Give them
   a black background in high-contrast mode instead, matching the theme's other
   buttons (yellow-on-black, 14.67:1). */
html.a11y-contrast-high .a11y-skip-link { background: #000000 !important; }

/* Fix: services.html's CTA banner has a stray inline style="background:var(--ink)"
   baked into its markup (a pre-existing authoring mistake, unrelated to any theme
   code — confirmed absent from every other page's CTA banner). --ink is a TEXT color
   token, not a background one; in light theme it happens to be a dark charcoal that
   coincidentally still looks like a plausible dark banner background, but in
   dark/high-contrast themes --ink is remapped for text-on-dark-surface use (light
   colors), so this one banner silently turns white/near-white instead of dark —
   breaking its own white heading/button text (as low as 1.43:1, confirmed live).
   Inline styles beat non-!important stylesheet rules regardless of selector
   specificity, so !important is required here to win back the class's intended
   background on this one instance (a no-op everywhere else, since it matches what
   the class already renders). */
.cta-banner { background: var(--gradient-dark) !important; }

/* ---------- Baseline WCAG fixes (always on, not gated by the menu) ---------- */
.section p a, .lede a, .card p a, .card-dark p a, .form-note a, .about-copy p a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Fix: de-emphasized footer/breadcrumb text set with a low white-opacity (0.35–0.45)
   against the site's permanently-dark --black background (#0a0a0c) — present on every
   page, regardless of theme, since the footer never changes with the theme toggle.
   Verified live via axe-core (color-contrast, serious) at 3.15–4.48:1; 0.6 clears
   4.5:1 with margin (7.30:1) and matches the opacity already used for de-emphasized
   text elsewhere on dark surfaces in this codebase (.cta-banner p, .section-dark p). */
.footer-brand p,
.footer-phone span,
.footer-bottom,
.breadcrumb {
  color: rgba(255, 255, 255, 0.6);
}

/* Fix: the breadcrumb's "Home" link has no visual distinction (same color, no
   underline, same weight) from the surrounding "/ Page Name" text, so a sighted
   mouse user can't tell it's a link (WCAG 1.4.1 / link-in-text-block, flagged by
   axe-core as "incomplete" on every subpage with a breadcrumb — confirmed a real
   issue via direct computed-style inspection, not a tooling false positive). */
.breadcrumb a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Visible focus indicator for every interactive element, at all times */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #0071e3;
  outline-offset: 2px;
  border-radius: 4px;
}
html[data-theme="dark"] a:focus-visible, html[data-theme="dark"] button:focus-visible,
html[data-theme="dark"] input:focus-visible, html[data-theme="dark"] select:focus-visible,
html[data-theme="dark"] textarea:focus-visible, html[data-theme="dark"] [tabindex]:focus-visible {
  outline-color: #29c1ff;
}

/* ---------- Skip links ---------- */
#a11y-skip-links { position: relative; z-index: 10000; }
.a11y-skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  background: #0071e3;
  color: #fff !important;
  padding: 12px 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none !important;
  transition: top 0.15s ease;
  z-index: 10000;
}
.a11y-skip-link:nth-of-type(2) { left: 220px; }
.a11y-skip-link:nth-of-type(3) { left: 420px; }
.a11y-skip-link:focus { top: 12px; outline: 3px solid #fff; outline-offset: 2px; }

/* ---------- Quick theme toggle (mounted into .nav-cta) ---------- */
.a11y-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  flex-shrink: 0;
}
.a11y-theme-toggle:hover { background: rgba(255, 255, 255, 0.16); }
.a11y-theme-toggle-standalone { position: absolute; top: 14px; right: 32px; z-index: 50; }

/* ---------- Floating accessibility launcher ---------- */
.a11y-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 56px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #0071e3 0%, #29c1ff 100%);
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 113, 227, 0.4);
  cursor: pointer;
  justify-content: center;
}
.a11y-launcher:hover { transform: translateY(-2px); }
.a11y-launcher-label {
  position: absolute;
  width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
@media (max-width: 640px) {
  .a11y-launcher { left: 50%; right: auto; transform: translateX(-50%); bottom: 18px; }
  .a11y-launcher:hover { transform: translateX(-50%) translateY(-2px); }
}

/* ---------- Overlay + dialog panel ---------- */
.a11y-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 10, 12, 0.5);
  z-index: 9999;
}
.a11y-dialog {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 10000;
  width: min(380px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 120px));
  overflow-y: auto;
  background: var(--white);
  color: var(--ink);
  border-radius: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--gray-100);
}
@media (max-width: 640px) {
  .a11y-dialog { left: 16px; right: 16px; bottom: 84px; width: auto; }
}
.a11y-dialog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--gray-100);
  position: sticky; top: 0; background: var(--white);
}
.a11y-dialog-header h2 { font-size: 17px; margin: 0; }
.a11y-close {
  border: none; background: var(--gray-100); color: var(--ink);
  width: 32px; height: 32px; border-radius: 999px; font-size: 20px;
  line-height: 1; cursor: pointer;
}
.a11y-dialog-body { padding: 18px 20px 24px; }
.a11y-group { margin-bottom: 22px; }
.a11y-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--gray-500); margin: 0 0 10px; }
.a11y-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.a11y-btn {
  border: 1px solid var(--gray-200); background: var(--off-white); color: var(--ink);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.a11y-btn:hover { border-color: var(--blue); }
.a11y-btn-text { font-weight: 500; }
.a11y-btn-reset { width: 100%; justify-content: center; display: flex; }
.a11y-value { min-width: 52px; text-align: center; font-weight: 700; }
.a11y-radio, .a11y-checkbox {
  display: flex; align-items: center; gap: 8px; font-size: 14px;
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--gray-100); cursor: pointer;
}
.a11y-checkbox { margin-bottom: 8px; }
.a11y-note { font-size: 12px; color: var(--gray-500); margin: 6px 0 0; }
.a11y-disclaimer { border-top: 1px solid var(--gray-100); padding-top: 14px; margin-top: 4px; }
.a11y-disclaimer a { color: var(--blue); text-decoration: underline; }
.a11y-actions { margin-top: 4px; }

/* ---------- Text size / line spacing tokens ---------- */
html.a11y-text-110 body { font-size: 1.1em; }
html.a11y-text-125 body { font-size: 1.25em; }
html.a11y-text-150 body { font-size: 1.5em; }
html.a11y-text-175 body { font-size: 1.75em; }
html.a11y-text-200 body { font-size: 2em; }

html.a11y-line-plus20 body { line-height: 1.8; }
html.a11y-line-plus40 body { line-height: 2.1; }
html.a11y-line-plus20 p, html.a11y-line-plus40 p { line-height: inherit; }

/* ---------- Highlight links ---------- */
html.a11y-highlight-links a:not(.btn):not(.nav-toggle) {
  background: rgba(255, 214, 0, 0.35);
  padding: 0 2px;
  border-radius: 3px;
}

/* ---------- Dyslexia-friendly font ---------- */
html.a11y-dyslexia-font body,
html.a11y-dyslexia-font input,
html.a11y-dyslexia-font select,
html.a11y-dyslexia-font textarea {
  font-family: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, Arial, sans-serif !important;
}

/* ---------- Reading guide ---------- */
#a11y-reading-guide-bar {
  position: fixed;
  left: 0; right: 0;
  height: 44px;
  background: rgba(255, 214, 0, 0.22);
  border-top: 2px solid rgba(255, 180, 0, 0.85);
  border-bottom: 2px solid rgba(255, 180, 0, 0.85);
  pointer-events: none;
  z-index: 9997;
}

/* ---------- Big cursor ---------- */
html.a11y-big-cursor, html.a11y-big-cursor * {
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24"><path d="M4 2l14 8-6 2 4 7-3 1.6-4-7-4.5 4.4z" fill="black" stroke="white" stroke-width="1.2"/></svg>') 4 4, auto !important;
}

/* ---------- Enhanced always-visible focus ring ---------- */
html.a11y-focus-ring a:focus, html.a11y-focus-ring button:focus,
html.a11y-focus-ring input:focus, html.a11y-focus-ring select:focus,
html.a11y-focus-ring textarea:focus, html.a11y-focus-ring [tabindex]:focus {
  outline: 4px solid #ffd400 !important;
  outline-offset: 3px !important;
}

/* ---------- Reduce motion ---------- */
html.a11y-reduce-motion *,
html.a11y-reduce-motion *::before,
html.a11y-reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}
html.a11y-reduce-motion .reveal { opacity: 1 !important; transform: none !important; }
