/**
 * Interaktive Komponenten: Buttons, Inputs, Cards, Badges, Links, Poll, Quiz, Q&A.
 * Hover-Zustände über echte Farbwechsel, nicht über unberechenbares brightness().
 */

button {
  cursor: pointer;
}

.app:focus {
  outline: none;
}

/* ----- Links: Farbe + Unterstreichung (nicht Farbe allein) ----- */
a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 0.08em;
}

a:hover {
  color: var(--link-hover);
}

/* ----- Logo-Marke ----- */
.logo {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-ink);
  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: -0.06em;
  flex-shrink: 0;
}

.logo.sm {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 0.58rem;
}

/* ----- Cards / Panels ----- */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

/* ----- Inputs ----- */
input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
}

/* Häkchen und Radiobuttons: nie die volle Breite der Zeile (die Regel oben gilt für Textfelder). */
input[type="checkbox"],
input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  min-width: 1.15rem;
  flex: none;
  padding: 0;
  margin: 0.15rem 0 0;
  accent-color: var(--primary-color, #007cc1);
}

input::placeholder,
textarea::placeholder {
  color: var(--placeholder);
  opacity: 1;
}

/* ----- Buttons ----- */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 650;
  min-height: 44px;
  min-width: 44px;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-ink);
}

.btn.primary:hover:not(:disabled) {
  background: var(--btn-primary-hover);
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--bg-soft);
  border-color: var(--ink);
}

/*
 * Design-System-Bridge (Issue #8): Factories setzen .btn-primary / .btn-ghost.
 * Solange das DS-Bundle nicht global geladen wird, Alias auf bestehende Tokens.
 */
.btn.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-ink);
}

.btn.btn-primary:hover:not(:disabled) {
  background: var(--btn-primary-hover);
}

.btn.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.btn-ghost:hover:not(:disabled) {
  background: var(--bg-soft);
  border-color: var(--ink);
}

.btn.btn-secondary {
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.btn-danger {
  background: var(--status-err-bg, #fca5a5);
  color: var(--status-err, #7f1d1d);
}

.btn.btn-loading .spinner,
.btn .spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-right: 0.4em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.15em;
  animation: pulse-btn-spin 0.7s linear infinite;
}

@keyframes pulse-btn-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Form-Factory-Bridge: createInput nutzt .form-group / .form-label */
.form-group.field .form-label,
.form-label {
  font-weight: 600;
  color: var(--ink);
}

.form-error {
  /* Textfehler auf Seiten-/Karten-BG: --danger (Dark hell), nicht Badge-Ink --status-err */
  color: var(--danger, #b91c1c);
  font-size: 0.9rem;
}

.form-input-error {
  border-color: var(--danger, #b91c1c) !important;
}

/* Toast-Region (showToast) — unten mittig: verdeckt weder Konto-Menü noch Kopfzeile */
.toast-region {
  position: fixed;
  z-index: 10050;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 24px));
  pointer-events: none;
  top: auto;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(-4px);
  /* Ausblendend unsichtbar: darf den Knopf darunter (unten mittig oft „Weiter“) nicht mehr verdecken. */
  pointer-events: none;
}

.toast-message {
  flex: 1;
  font-size: 0.95rem;
  line-height: 1.4;
}

.toast-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  cursor: pointer;
}

.toast-success {
  border-color: var(--status-ok, #14532d);
  background: var(--status-ok-bg, #86efac);
}

.toast-error {
  border-color: var(--status-err, #7f1d1d);
  background: var(--status-err-bg, #fca5a5);
}

.toast-warning {
  border-color: #8a5a00;
  background: var(--status-warn-bg, #facc15);
}

.toast-info {
  border-color: var(--status-info, #0052cc);
  background: var(--status-info-bg, #93c5fd);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-soft);
  border-color: var(--ink);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Touch-Ziele auf schmalen Screens (WCAG 2.5.5). */
@media (max-width: 640px) {
  .icon-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
}

/* Light: Mond (Wechsel nach Dark). Dark: Sonne (Wechsel nach Light). */
html:not([data-theme="dark"]) .icon-sun,
[data-theme="dark"] .icon-moon {
  display: none;
}

/* ----- Status-Punkt (Verbindung) ----- */
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.status i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--status-warn-bg);
  border: 1px solid var(--line);
  contain: layout paint;
}

.status[data-state="open"] i {
  background: var(--status-ok-bg);
}

.status[data-state="closed"] i,
.status[data-state="error"] i {
  background: var(--status-err-bg);
}

.participants {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  font-variant-numeric: tabular-nums;
}

.participants svg {
  width: 18px;
  height: 18px;
}

/* ----- Badges: kräftige Fläche + dunkler Text ----- */
.badge,
.qa-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.4;
  border: 1px solid transparent;
}

.badge-ok,
.badge-approved,
.badge-answered {
  background: var(--status-ok-bg);
  color: var(--status-ok);
  border-color: var(--status-ok);
}

.badge-warn,
.badge-pending {
  background: var(--status-warn-bg);
  color: var(--status-warn);
  border-color: #8a5a00;
}

.badge-err,
.badge-hidden {
  background: var(--status-err-bg);
  color: var(--status-err);
  border-color: var(--status-err);
}

.badge-info,
.badge-live {
  background: var(--status-info-bg);
  color: var(--status-info);
  border-color: var(--status-info);
}

.badge-pending {
  background: var(--status-pending-bg);
  color: var(--status-pending);
  border-color: var(--line);
}

/* ----- Poll-Balken ----- */
.poll {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(10px, 2vh, 22px);
  padding: clamp(16px, 3vw, 48px);
}

.poll-row {
  display: grid;
  grid-template-columns: minmax(90px, 18%) 1fr auto;
  align-items: center;
  gap: 14px;
}

.poll-label {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}

.poll-track {
  position: relative;
  height: clamp(38px, 7vh, 64px);
  border-radius: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  overflow: hidden;
}

.poll-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar-width, 0%);
  border-radius: inherit;
  transition: width 0.55s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: width;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-inline: 12px;
}

.poll-fill[data-color="0"] { background: var(--c1); color: var(--c1-ink); }
.poll-fill[data-color="1"] { background: var(--c2); color: var(--c2-ink); }
.poll-fill[data-color="2"] { background: var(--c3); color: var(--c3-ink); }
.poll-fill[data-color="3"] { background: var(--c4); color: var(--c4-ink); }
.poll-fill[data-color="4"] { background: var(--c5); color: var(--c5-ink); }
.poll-fill[data-color="5"] { background: var(--c6); color: var(--c6-ink); }

/* Individuelle Ergebnisfarben (resultStyle-Palette/Overrides) */
.poll-fill--custom {
  background: var(--bar-bg);
  color: var(--bar-ink);
}

.choice-btn.choice-color--custom {
  border-left: 6px solid var(--choice-accent, var(--bar-bg));
}

.choice-options-item.choice-color--custom,
.stage-choice-option.choice-color--custom,
.present-stage-choice-option.choice-color--custom {
  border-left: 6px solid var(--choice-accent, var(--bar-bg));
}

.poll-pct {
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  min-width: 7.5ch;
  text-align: right;
  color: var(--ink);
}

/* Text im Balken nur, wenn JS ihn einblendet (Balken breit genug) */
.poll-count {
  font-size: 0.9rem;
  font-weight: 700;
  color: inherit;
  text-shadow: none;
}

.poll-count[hidden] {
  display: none !important;
}

/* ----- Wortwolken-Rangliste ----- */
.word-rank {
  border-left: 1px solid var(--line);
  padding: 16px 10px 16px 14px;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  background: var(--bg-elev);
}

.word-rank h3 {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.virtual-list {
  position: relative;
  overflow: auto;
  min-height: 0;
  content-visibility: auto;
}

.virtual-list-spacer {
  width: 100%;
  pointer-events: none;
}

.virtual-list-body {
  position: absolute;
  left: 0;
  right: 8px;
  top: 0;
  will-change: transform;
}

.virtual-row {
  display: grid;
  grid-template-columns: 1.6ch 1fr 3ch;
  gap: 8px;
  align-items: center;
  height: 36px;
  font-size: 0.95rem;
  color: var(--ink);
}

.virtual-row b {
  color: var(--muted);
  font-weight: 600;
}

.virtual-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ----- Deck-Chips ----- */
.deck-chip {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-soft);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-weight: 650;
  cursor: pointer;
}

.deck-chip.is-active {
  border-color: var(--btn-primary-bg);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--btn-primary-bg) 35%, transparent);
}

/* ----- Teilnehmer-Auswahl ----- */
.choice-btn {
  text-align: left;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  font-weight: 650;
  font-size: 1.05rem;
  min-height: 44px;
  min-width: 44px;
}

.choice-btn[data-color="0"] { border-left: 6px solid var(--c1); }
.choice-btn[data-color="1"] { border-left: 6px solid var(--c2); }
.choice-btn[data-color="2"] { border-left: 6px solid var(--c3); }
.choice-btn[data-color="3"] { border-left: 6px solid var(--c4); }
.choice-btn[data-color="4"] { border-left: 6px solid var(--c5); }
.choice-btn[data-color="5"] { border-left: 6px solid var(--c6); }

.choice-btn.is-selected,
.choice-btn:disabled.is-selected {
  outline: 3px solid var(--focus);
  background: var(--bg-soft);
}

.feedback {
  min-height: 1.4em;
  color: var(--feedback);
  font-weight: 650;
}

/* ----- Dialoge ----- */
.admin-dialog,
.consent-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--ink);
  padding: 24px;
  max-width: 28rem;
}

.admin-dialog::backdrop,
.consent-dialog::backdrop {
  background: rgba(26, 29, 35, 0.55);
}

/* Geschlossene native Dialoge nie im Seitenfluss anzeigen (Admin-Session-Deck). */
dialog.admin-dialog:not([open]) {
  display: none !important;
}

.consent-dialog[hidden] {
  display: none !important;
}

/*
  Datenschutz-Hinweis zentriert im Viewport — Button darf nicht vom Footer
  oder der Browser-Leiste abgeschnitten werden (Join/Mobile).
*/
.consent-dialog:not([hidden]) {
  position: fixed;
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
  margin: 0;
  z-index: 100;
  width: min(26rem, calc(100vw - 32px));
  max-height: min(28rem, calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.consent-dialog h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.consent-dialog .btn {
  margin-top: 14px;
  width: 100%;
}

.admin-dialog p {
  margin: 10px 0 0;
  color: var(--muted);
}

/* Dialog „Exportieren …“ (session/exportDialog.js): zwei Gruppen mit Optionsfeldern. */
.export-dialog fieldset {
  border: 0;
  margin: 0 0 14px;
  padding: 0;
}

.export-dialog legend {
  font-weight: 650;
  margin-bottom: 6px;
  padding: 0;
}

.export-dialog__option {
  align-items: flex-start;
  display: flex;
  gap: 8px;
  margin: 6px 0;
}

.export-dialog__option input:disabled + span {
  opacity: 0.75;
}

.word-form .btn {
  margin-top: 12px;
  width: 100%;
}

/* ----- Q&A-Karten ----- */
.qa-container {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  height: 100%;
  min-height: 0;
  padding: 12px 16px;
}

.qa-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.qa-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.qa-filters .is-on {
  border-color: var(--focus);
  background: var(--bg-soft);
}

/* Filter-Roving: klarer Tastatur-Fokusring (Maus ohne Ring via accessibility.css). */
.qa-filters button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.qa-mod {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.9rem;
}

.qa-top3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.qa-featured,
.qa-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: start;
  color: var(--ink);
}

.qa-rank {
  font-weight: 800;
  color: var(--link);
}

.qa-virtual {
  min-height: 0;
  height: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-elev);
}

.qa-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
}

.view-join .qa-container,
.view-join .quiz-container {
  flex: 1;
  min-height: 240px;
}

.qa-row {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
}

.qa-text {
  margin: 0;
  font-weight: 650;
  color: var(--ink);
}

.qa-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.qa-composer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

/* Composer-Fehler: sichtbar + Screenreader (role/aria-live setzt JS). */
.qa-composer-error:empty,
.qa-composer-error[hidden] {
  display: none;
}

.qa-composer-error:not(:empty):not([hidden]) {
  margin: 0 0 8px;
  color: var(--pulse-error, #b42318);
}

.qa-inline-answer {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.qa-composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  resize: none;
}

