/*
 * ewiwe Accessibility Panel (Base V1)
 *
 * Zwei getrennte Mechanismen, beide ueber CSS Custom Properties, keine
 * harte DOM-Manipulation:
 *
 * 1. Schriftgroesse skaliert `html { font-size }` selbst. Bootstrap
 *    Package baut seine Typografie auf `rem`; eine Skalierung der
 *    Root-Groesse wirkt dadurch automatisch auf jede Bootstrap-Komponente,
 *    ohne eine einzige ihrer Dateien anzufassen.
 * 2. Hoher Kontrast ueberschreibt Bootstraps eigene `--bs-*`-Variablen -
 *    das ist Bootstraps eingebauter Theming-Mechanismus (siehe
 *    `data-bs-theme` fuer den Dark Mode), kein Hack. Navigation, Buttons,
 *    Cards und Formulare sind in Bootstrap 5 vollstaendig aus diesen
 *    Variablen gebaut und uebernehmen die Ueberschreibung deshalb von
 *    selbst.
 */

:root {
  --ewiwe-a11y-font-scale: 1;
}

html {
  font-size: calc(100% * var(--ewiwe-a11y-font-scale, 1));
}

/* --- Hoher Kontrast: Bootstraps eigene Variablen umbelegen -------------- */

html[data-ewiwe-a11y-contrast="high"] {
  --bs-body-color: #000000;
  --bs-body-bg: #ffffff;
  --bs-body-color-rgb: 0, 0, 0;
  --bs-body-bg-rgb: 255, 255, 255;
  --bs-border-color: #000000;
  --bs-link-color: #0000ee;
  --bs-link-hover-color: #0000aa;
  --bs-link-color-rgb: 0, 0, 238;
  --bs-secondary-color: #000000;
  --bs-secondary-bg: #e6e6e6;
  --bs-tertiary-bg: #e6e6e6;

  /* Buttons: Bootstrap baut jede Variante (primary, secondary, ...) aus
     denselben Variablennamen mit Farbsuffix. Die primaere Variante deckt
     den haeufigsten Fall (CTA-Buttons) ab, ohne jede Variante einzeln
     auszuschreiben. */
  --bs-btn-color: #ffffff;
  --bs-btn-bg: #000000;
  --bs-btn-border-color: #000000;
  --bs-btn-hover-bg: #333333;
  --bs-btn-hover-border-color: #000000;
  --bs-btn-focus-shadow-rgb: 0, 0, 0;

  /* Navigation */
  --bs-navbar-color: #000000;
  --bs-navbar-hover-color: #0000ee;
  --bs-navbar-active-color: #0000ee;
  --bs-navbar-brand-color: #000000;
  --bs-nav-link-color: #000000;
  --bs-nav-link-hover-color: #0000ee;

  /* Cards */
  --bs-card-color: #000000;
  --bs-card-bg: #ffffff;
  --bs-card-border-color: #000000;
  --bs-card-cap-bg: #e6e6e6;

  /* Formulare */
  --bs-form-control-color: #000000;
  --bs-form-control-bg: #ffffff;
  --bs-form-control-border-color: #000000;

  color-scheme: light;
}

html[data-ewiwe-a11y-contrast="high"] * {
  /* Textfarbe faellt sonst an einigen Stellen auf browsereigene Defaults
     zurueck, wenn eine Komponente Farbe nicht ueber `--bs-body-color`
     bezieht. Ausdruecklich niedrige Spezifitaet vermieden: das ist eine
     bewusste, sichtbare Ausnahme fuer den Kontrastmodus, keine globale
     Regel, die anderswo mitliest. */
  border-color: currentColor;
}

html[data-ewiwe-a11y-contrast="high"] a:not(.btn) {
  text-decoration: underline;
}

/* Sichtbare Fokuszustaende bleiben im Kontrastmodus mindestens so
   deutlich wie im Standard - eine eigene Regel, weil ein umgestellter
   Fokusring in Bootstraps `--bs-focus-ring-color` sonst denselben
   hellblauen Ton wie im Standardmodus zeigen wuerde. */
html[data-ewiwe-a11y-contrast="high"] :focus-visible {
  outline: 3px solid #000000;
  outline-offset: 2px;
}

/* --- Panel ---------------------------------------------------------- */

.ewiwe-a11y {
  position: fixed;
  z-index: 2000;
  top: 1rem;
  right: 1rem;
  max-width: calc(100vw - 2rem);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Ohne JavaScript bleibt das Panel unsichtbar: es kann keine seiner
   Funktionen erfuellen (kein localStorage, keine Custom-Property-Aenderung),
   und ein Knopf, der nichts tut, ist schlechter als kein Knopf. Progressive
   Enhancement: `accessibility-panel.js` entfernt `[hidden]`, sobald es
   wirklich laeuft. */
.ewiwe-a11y[hidden] {
  display: none;
}

.ewiwe-a11y[data-ewiwe-a11y-position="top-left"] {
  right: auto;
  left: 1rem;
}

.ewiwe-a11y[data-ewiwe-a11y-position="bottom-right"] {
  top: auto;
  bottom: 1rem;
}

.ewiwe-a11y[data-ewiwe-a11y-position="bottom-left"] {
  top: auto;
  right: auto;
  bottom: 1rem;
  left: 1rem;
}

.ewiwe-a11y__toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  list-style: none;
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  background: #1a1a1a;
  color: #ffffff;
  font-size: 0.9rem;
  line-height: 1;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  user-select: none;
}

.ewiwe-a11y__toggle::-webkit-details-marker {
  display: none;
}

.ewiwe-a11y__toggle:focus-visible {
  outline: 3px solid #ffbf47;
  outline-offset: 2px;
}

.ewiwe-a11y__toggle-icon {
  font-size: 1.1rem;
}

.ewiwe-a11y__panel {
  margin-top: 0.5rem;
  padding: 1rem;
  border-radius: 0.75rem;
  background: #ffffff;
  color: #1a1a1a;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}

.ewiwe-a11y__group {
  border: 1px solid #d0d0d0;
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  margin: 0 0 0.75rem;
}

.ewiwe-a11y__group legend {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0 0.25rem;
}

.ewiwe-a11y__buttons {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.ewiwe-a11y__btn {
  border: 1px solid #767676;
  background: #ffffff;
  color: #1a1a1a;
  border-radius: 0.4rem;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.ewiwe-a11y__btn:hover {
  background: #f0f0f0;
}

.ewiwe-a11y__btn:focus-visible {
  outline: 3px solid #005fcc;
  outline-offset: 2px;
}

.ewiwe-a11y__btn[aria-pressed="true"] {
  background: #1a1a1a;
  color: #ffffff;
  border-color: #1a1a1a;
}

.ewiwe-a11y__actions {
  margin-top: 0.5rem;
}

.ewiwe-a11y__reset {
  width: 100%;
  border: 1px dashed #767676;
  background: transparent;
  color: #1a1a1a;
  border-radius: 0.4rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.ewiwe-a11y__reset:focus-visible {
  outline: 3px solid #005fcc;
  outline-offset: 2px;
}

.ewiwe-a11y__note {
  margin: 0.6rem 0 0;
  font-size: 0.75rem;
  color: #4a4a4a;
}

.ewiwe-a11y__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;
}

/* `prefers-reduced-motion` respektieren, auch ohne den spaeteren
   expliziten Umschalter aus Issue #5 - die Grundregel gilt unabhaengig
   davon, ob ein Besucher sie je im Panel sieht. */
@media (prefers-reduced-motion: no-preference) {
  .ewiwe-a11y__panel {
    transition: opacity 120ms ease-out;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ewiwe-a11y,
  .ewiwe-a11y * {
    animation: none !important;
    transition: none !important;
  }
}
