/*
 * Realdot AR – Frontend
 *
 * Anpassen am besten über die Variablen (AR-Modelle → Custom CSS),
 * nicht durch Ändern dieser Datei – sie wird bei Plugin-Updates ersetzt.
 */

.rd-ar {
  --rd-ar-height: 500px;
  --rd-ar-bg: radial-gradient(circle, #333333, #000000);
  --rd-ar-accent: #111111;          /* aktive Pill, AR-Knopf */
  --rd-ar-accent-text: #ffffff;
  --rd-ar-surface: rgba(255, 255, 255, 0.94); /* Pills und Steuerknöpfe */
  --rd-ar-surface-text: #1a1a1a;
  --rd-ar-focus: #005fcc;           /* Fokusrahmen, mit weißem Innenrand */
  --rd-ar-radius: 999px;
  --rd-ar-hint: #555555;
  --rd-ar-tipp-bg: rgb(90, 178, 48); /* AR-Hinweis */
  --rd-ar-tipp-text: #0d1f05;        /* dunkel: 6.5:1 auf dem Grün. Weiß hätte nur 2.7:1 (WCAG 1.4.3) */
  --rd-ar-popup-bg: #ffffff;         /* QR-Code */
  --rd-ar-popup-text: #1a1a1a;

  position: relative;
  container-type: inline-size;
  margin: 0 0 1.5em;
}

/* Unabhängig vom Theme: Breiten inklusive Innenabstand */
.rd-ar,
.rd-ar *,
.rd-ar *::before,
.rd-ar *::after {
  box-sizing: border-box;
}

/* Nur für Screenreader sichtbar */
.rd-ar__sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Viewer ---------- */

.rd-ar__viewer {
  display: block;
  width: 100%;
  height: var(--rd-ar-height);
  background: var(--rd-ar-bg);
  border-radius: 6px;
  --poster-color: transparent;
  --progress-bar-color: transparent;
}

.rd-ar__viewer:focus-visible,
.rd-ar__viewer.is-kbd-focus {
  outline: 3px solid var(--rd-ar-focus);
  outline-offset: 3px;
}

.rd-ar__progress {
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  overflow: hidden;
  border-radius: 6px 6px 0 0;
  pointer-events: none;
}

.rd-ar__progress-bar {
  display: block;
  height: 100%;
  background: var(--rd-ar-focus);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.2s, opacity 0.3s;
}

.rd-ar:not(.is-loading) .rd-ar__progress-bar {
  opacity: 0;
}

/* ---------- Pills (Farbe / Ausrichtung) ---------- */

.rd-ar__pills {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  max-width: calc(100% - 96px);
}

.rd-ar__pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 4px;
  border: 0;
  border-radius: var(--rd-ar-radius);
  background: var(--rd-ar-surface);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
}

.rd-ar__pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  min-width: 36px;
  padding: 0 14px;
  border-radius: var(--rd-ar-radius);
  color: var(--rd-ar-surface-text);
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
}

/* Das Radio bleibt im Baum (Tastatur, Screenreader), liegt aber unsichtbar über der Pill. */
.rd-ar__radio {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.rd-ar__pill:has(.rd-ar__radio:checked) {
  background: var(--rd-ar-accent);
  color: var(--rd-ar-accent-text);
}

.rd-ar__pill:has(.rd-ar__radio:focus-visible) {
  outline: 3px solid var(--rd-ar-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #ffffff;
}

.rd-ar__pill.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.rd-ar__pill.is-disabled .rd-ar__radio {
  cursor: not-allowed;
}

.rd-ar__swatch {
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 50%;
  background: var(--rd-ar-swatch, #cccccc);
  /* Rand mit ausreichend Kontrast auf hellem und dunklem Grund (WCAG 1.4.11) */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.8);
}

.rd-ar__icon {
  flex: none;
}

/* ---------- AR-Knopf ---------- */

.rd-ar__ar-button {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--rd-ar-radius);
  background: var(--rd-ar-accent);
  color: var(--rd-ar-accent-text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.rd-ar__ar-button:focus-visible,
.rd-ar__control:focus-visible,
.rd-ar__load-button:focus-visible {
  outline: 3px solid var(--rd-ar-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #ffffff;
}

/* ---------- Steuerknöpfe (drehen, zoomen, Pause) ---------- */

.rd-ar__controls {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rd-ar__control {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--rd-ar-surface);
  color: var(--rd-ar-surface-text);
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
}

.rd-ar__control:hover,
.rd-ar__pill:hover:not(.is-disabled) {
  filter: brightness(0.94);
}

/* Pause-Knopf: zeigt „Pause“ oder „Play“ je nach Zustand */
.rd-ar__control .rd-ar__icon--play,
.rd-ar__control.is-paused .rd-ar__icon--pause {
  display: none;
}

.rd-ar__control.is-paused .rd-ar__icon--play {
  display: block;
}

/* ---------- Poster / „3D-Modell laden“ ---------- */

.rd-ar__poster {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.rd-ar__load-button {
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--rd-ar-radius);
  background: var(--rd-ar-accent);
  color: var(--rd-ar-accent-text);
  font: inherit;
  cursor: pointer;
}

/* ---------- QR-Code (Geräte ohne AR) ---------- */

/* Liegt außerhalb von <model-viewer>, deshalb von oben gemessen: Viewerhöhe minus Abstand */
.rd-ar__qr-button {
  position: absolute;
  top: calc(var(--rd-ar-height) - 62px);
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--rd-ar-radius);
  background: var(--rd-ar-accent);
  color: var(--rd-ar-accent-text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.rd-ar__qr-button[hidden] {
  display: none;
}

.rd-ar__qr-button:focus-visible,
.rd-ar__qr-kopieren:focus-visible,
.rd-ar__schliessen:focus-visible,
.rd-ar__qr-titel:focus-visible {
  outline: 3px solid var(--rd-ar-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #ffffff;
}

/* Popups sitzen über dem Knopf unten in der Mitte, mit Pfeil nach unten */
.rd-ar__qr,
.rd-ar__tipp {
  position: absolute;
  top: calc(var(--rd-ar-height) - 74px);
  left: 50%;
  z-index: 3;
  width: min(420px, calc(100% - 32px));
  transform: translate(-50%, -100%);
  border-radius: 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
}

.rd-ar__qr::after,
.rd-ar__tipp::after {
  content: "";
  position: absolute;
  bottom: -7px;
  left: 50%;
  width: 14px;
  height: 14px;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
}

.rd-ar__qr[hidden],
.rd-ar__tipp[hidden] {
  display: none;
}

.rd-ar__qr {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 16px;
  padding: 18px 48px 18px 18px;
  background: var(--rd-ar-popup-bg);
  color: var(--rd-ar-popup-text);
}

.rd-ar__qr-bild img {
  display: block;
  width: 132px;
  height: 132px;
  image-rendering: pixelated;
}

.rd-ar__qr-bild[hidden] {
  display: none;
}

.rd-ar__qr-titel {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

.rd-ar__qr-text {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.45;
}

.rd-ar__qr-kopieren {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid currentColor;
  border-radius: var(--rd-ar-radius);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- AR-Hinweis (Geräte mit AR) ---------- */

.rd-ar__tipp {
  padding: 16px 52px 16px 18px;
  background: var(--rd-ar-tipp-bg);
  color: var(--rd-ar-tipp-text);
}

.rd-ar__tipp-titel {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
}

.rd-ar__tipp-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

/* ---------- Schließen-Knopf (×) ---------- */

.rd-ar__schliessen {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.12);
  color: inherit;
  cursor: pointer;
}

.rd-ar__schliessen:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* ---------- Hinweis und Fehler ---------- */

.rd-ar__hint {
  margin: 8px 0 0;
  color: var(--rd-ar-hint);
  font-size: 13px;
  line-height: 1.5;
}

.rd-ar.has-error .rd-ar__status {
  position: static !important;
  width: auto;
  height: auto;
  margin: 8px 0 0;
  clip: auto;
  white-space: normal;
  color: #b00020;
  font-size: 14px;
}

/* ---------- Schmale Viewer (Handy) ---------- */

@container (max-width: 520px) {
  .rd-ar__pills {
    flex-direction: row;
    flex-wrap: wrap;
    top: 12px;
    left: 12px;
    max-width: calc(100% - 76px);
  }

  .rd-ar__pill {
    padding: 0 10px;
  }

  /* Text nur visuell ausblenden – Screenreader lesen ihn weiter vor */
  .rd-ar__pill .rd-ar__pill-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .rd-ar__controls {
    top: 12px;
    right: 12px;
  }

  .rd-ar__ar-button,
  .rd-ar__qr-button {
    width: calc(100% - 32px);
    justify-content: center;
  }

  .rd-ar__qr {
    grid-template-columns: 1fr;
    justify-items: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rd-ar__progress-bar {
    transition: none;
  }
}

/* Hinweis für Redakteure, wenn ein Shortcode ins Leere zeigt */
.rd-ar-hinweis {
  padding: 10px 14px;
  border-left: 4px solid #dba617;
  background: #fff8e5;
  color: #1d2327;
  font-size: 14px;
}
