/* Shared accessibility primitives (WCAG 2.1 AA / Section 508).

   Additive and safe to include on any surface: a visible keyboard focus ring,
   a screen-reader-only utility, skip-link styling, and reduced-motion /
   forced-colors guards. Later per-surface remediation PRs build on these.

   SINGLE SOURCE. Ships in lg-core-base and is served by every app at the
   relative path `ui/a11y.css` through lg_core_base.ui. Never copy it into a
   product's static directory — tests/test_ui_assets_core_base.py fails if a
   copy appears.

   COLORS ARE TOKENS. Every color below is a civicline.css semantic token, so
   these primitives follow the light and dark palettes with the rest of the
   page. Each fallback is that token's light value, for a page that loads this
   file alone; none is a color of its own. */

/* 2.4.7 Focus Visible: a clear keyboard focus ring on every interactive
   element. :focus-visible shows it for keyboard users without flashing on
   mouse click. */
:where(
  a, button, input, select, textarea, summary, [tabindex],
  [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="checkbox"]
):focus-visible {
  outline: 3px solid var(--cl-color-focus-ring, #2563eb);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Screen-reader-only content: visually hidden but still announced (labels,
   skip-link targets, live-region status text). */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 2.4.1 Bypass Blocks: skip-to-content link, hidden until keyboard-focused. */
.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 1000;
  padding: 0.5rem 0.9rem;
  background: var(--cl-color-accent, #2563eb);
  color: var(--cl-color-text-inverse, #ffffff);
  border-radius: 0 0 6px 6px;
  text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 0;
}

/* 2.3.3 / 2.2.2: honor a user's reduced-motion preference. */
@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;
  }
}

/* Windows High Contrast / forced-colors: keep the focus ring visible. */
@media (forced-colors: active) {
  :where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid Highlight;
  }
}

/* 3.3.1 Error Identification / 3.3.2 Labels or Instructions: the error-summary
   contract. A failed submit renders a summary listing every problem and moves
   focus to it; each entry links to the control that caused it, and that control
   carries aria-invalid plus an inline .field-error it names in
   aria-describedby. Color is never the only signal — every error is text.

   The summary is focused programmatically via tabindex="-1", so it needs a
   plain :focus ring: :focus-visible is not guaranteed to fire for a scripted
   focus() the way it does for a Tab. */
.error-summary {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border: 2px solid var(--cl-color-danger-text, #991b1b);
  border-radius: 0.4rem;
  background: var(--cl-color-danger-surface, #fee2e2);
  color: var(--cl-color-text, #0f172a);
}
.error-summary:focus {
  outline: 3px solid var(--cl-color-focus-ring, #2563eb);
  outline-offset: 2px;
}
.error-summary h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}
.error-summary ul {
  margin: 0;
  padding-left: 1.2rem;
  list-style: disc;
}
.error-summary a {
  color: var(--cl-color-danger-text, #991b1b);
}
.field-error {
  margin: 0.25rem 0 0;
  color: var(--cl-color-danger-text, #991b1b);
  font-size: 0.9rem;
}
/* An unset slot must not reserve space; it stays in the DOM so
   aria-describedby always resolves. */
.field-error:empty {
  display: none;
}
[aria-invalid="true"] {
  border: 2px solid var(--cl-color-danger-text, #991b1b);
}
