/* ==========================================================================
   Wiederverwendbare Bausteine
   ========================================================================== */

/* ------------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  /* 44px Mindesthoehe – Touch-Zielgroesse nach WCAG. */
  min-height: 44px;
  padding: 0 var(--space-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.btn svg {
  width: 17px;
  height: 17px;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--text-subtle);
}

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

.btn--primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-accent);
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: transparent;
}

.btn--danger {
  background: transparent;
  color: var(--bad-text);
  border-color: color-mix(in oklab, var(--bad) 40%, transparent);
}

.btn--danger:hover {
  background: var(--bad-soft);
  border-color: var(--bad);
}

.btn--sm {
  min-height: 36px;
  padding-inline: var(--space-4);
  font-size: 0.83rem;
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

/* ------------------------------------------------------------- Icon-Buttons */
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.icon-btn:hover {
  background: var(--surface-sunken);
  color: var(--text);
}

/* Nur das zum aktiven Theme passende Icon zeigen. */
.icon-theme-light,
.icon-theme-dark {
  display: none;
}

:root[data-theme='light'] .icon-theme-auto,
:root[data-theme='dark'] .icon-theme-auto {
  display: none;
}

:root[data-theme='light'] .icon-theme-light,
:root[data-theme='dark'] .icon-theme-dark {
  display: block;
}

/* -------------------------------------------------------------------- Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-3);
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pill--ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------ Combobox + Autocomplete */
.combo {
  position: relative;
  flex: 1;
  min-width: 0;
}

.combo__icon {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
}

.combo__input {
  width: 100%;
  height: 54px;
  padding: 0 44px 0 46px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  font-size: 1rem;
  font-weight: 500;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.combo__input::placeholder {
  color: var(--text-subtle);
  font-weight: 400;
}

.combo__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px color-mix(in oklab, var(--accent) 22%, transparent);
}

.combo__input:focus-visible {
  outline: none;
}

.combo__clear {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  color: var(--text-subtle);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.combo__clear:hover {
  background: var(--surface-sunken);
  color: var(--text);
}

.combo__clear svg {
  width: 16px;
  height: 16px;
}

/* Vorschlagsliste */
.ac {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: min(46vh, 340px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: ac-in var(--t-fast) var(--ease);
}

@keyframes ac-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.ac__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-align: left;
  font-size: 0.94rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}

.ac__item:hover,
.ac__item.is-active {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.ac__emoji {
  font-size: 1.15rem;
  line-height: 1;
  width: 1.5em;
  text-align: center;
  flex: none;
}

.ac__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ac__name mark {
  background: none;
  color: var(--accent-text);
  font-weight: 700;
}

.ac__meta {
  flex: none;
  font-size: 0.73rem;
  color: var(--text-subtle);
  font-weight: 500;
}

.ac__item.is-used {
  opacity: 0.45;
}

.ac__item.is-used .ac__meta {
  color: var(--bad-text);
}

.ac__empty {
  padding: var(--space-4);
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-subtle);
}

/* ------------------------------------------------------------------ Banner */
.banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border: 1px solid color-mix(in oklab, var(--accent) 35%, var(--border));
  border-radius: var(--radius-lg);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.88rem;
  font-weight: 500;
  animation: view-in var(--t-med) var(--ease);
}

.banner__text {
  flex: 1;
  min-width: 0;
}

.banner__close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--radius-full);
  color: inherit;
  opacity: 0.65;
}

.banner__close:hover {
  opacity: 1;
  background: color-mix(in oklab, var(--accent) 14%, transparent);
}

.banner__close svg {
  width: 15px;
  height: 15px;
}

/* ------------------------------------------------------------------ Panels */
.panel {
  margin-top: var(--space-5);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.panel__title {
  font-size: 1.05rem;
  margin-bottom: var(--space-2);
}

.panel__note,
.panel__empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.panel__empty {
  text-align: center;
  padding: var(--space-4) 0;
  margin-bottom: 0;
}

/* -------------------------------------------------------------- Statistik */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--space-4) var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  text-align: center;
}

.stat-card--accent {
  background: var(--accent-soft);
  border-color: color-mix(in oklab, var(--accent) 30%, var(--border));
}

.stat-card--accent .stat-card__value {
  color: var(--accent-text);
}

.stat-card__value {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 6vw, 1.9rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-card__label {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Verteilungsbalken */
.dist {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dist__row {
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  align-items: center;
  gap: var(--space-3);
}

.dist__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.dist__track {
  position: relative;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  overflow: hidden;
}

.dist__bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 26px;
  padding-inline: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  /* Von 0 auf Zielbreite animieren – Breite setzt JS. */
  transition: width var(--t-slow) var(--ease);
}

.dist__row.is-empty .dist__bar {
  background: var(--border);
  color: var(--text-subtle);
}

.dist__row.is-best .dist__bar {
  background: var(--ok);
}

.stats-actions {
  margin-top: var(--space-6);
  display: flex;
  justify-content: center;
}

/* ------------------------------------------------------------------ Dialoge */
.modal {
  width: min(680px, calc(100vw - 2rem));
  max-height: min(86dvh, 900px);
  /* Der Browser zentriert modale Dialoge ueber `margin: auto`. Unser
     Reset (`* { margin: 0 }`) wuerde das aushebeln – daher hier explizit. */
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal--narrow {
  width: min(460px, calc(100vw - 2rem));
}

.modal::backdrop {
  background: rgb(10 10 14 / 0.52);
  backdrop-filter: blur(3px);
}

.modal[open] {
  animation: modal-in var(--t-med) var(--ease-back);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
}

.modal__close-form {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 2;
}

.modal__close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-muted);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.modal__close:hover {
  background: var(--border);
  color: var(--text);
}

.modal__close svg {
  width: 17px;
  height: 17px;
}

.modal__title {
  padding: var(--space-5) var(--space-6) var(--space-3);
  font-size: 1.3rem;
}

.modal__body {
  padding: 0 var(--space-6) var(--space-6);
  overflow-y: auto;
  max-height: calc(86dvh - 90px);
  font-size: 0.92rem;
  color: var(--text-muted);
}

.modal__body p + p,
.modal__body > * + * {
  margin-top: var(--space-3);
}

.modal__sub {
  margin-top: var(--space-5) !important;
  font-size: 0.95rem;
  color: var(--text);
}

.modal__note {
  font-size: 0.84rem;
  color: var(--text-subtle);
}

.steps {
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.steps li {
  counter-increment: step;
  position: relative;
  padding-left: 2.25rem;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.05em;
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 800;
}

.steps strong,
.prop-list strong {
  color: var(--text);
}

.prop-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: 0.88rem;
}

.prop-list li {
  padding-left: var(--space-4);
  position: relative;
}

.prop-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border-strong);
}

.inline-chip {
  display: inline-grid;
  place-items: center;
  width: 1.4em;
  height: 1.4em;
  vertical-align: -0.3em;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text);
}

.inline-chip svg {
  width: 11px;
  height: 11px;
}

/* Beispielzeile im Hilfedialog */
.example-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.example-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 42px;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  font-size: 0.74rem;
  font-weight: 650;
  text-align: center;
  color: #fff;
  line-height: 1.1;
}

.example-tile svg {
  width: 11px;
  height: 11px;
}

.example-tile.is-match { background: var(--ok); }
.example-tile.is-partial { background: var(--warn); color: var(--warn-fg); }
.example-tile.is-miss { background: var(--bad); }

/* ---------------------------------------------------------- Einstellungen */
/* Auf schmalen Displays untereinander – sonst wird der Beschreibungstext
   neben dem Bedienelement auf ein Wort pro Zeile zusammengequetscht. */
.setting {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border);
}

.setting:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.setting__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.setting__name {
  font-size: 0.92rem;
  font-weight: 650;
  color: var(--text);
}

.setting__desc {
  font-size: 0.79rem;
  color: var(--text-subtle);
}

.segmented {
  display: flex;
  flex: none;
  padding: 3px;
  gap: 2px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}

.segmented button {
  min-height: 32px;
  padding-inline: var(--space-3);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.segmented button:hover {
  color: var(--text);
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--accent-text);
  box-shadow: var(--shadow-xs);
}

/* Schalter */
.switch {
  flex: none;
  padding: var(--space-1);
}

.switch__track {
  display: block;
  width: 46px;
  height: 27px;
  padding: 3px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  transition: background var(--t-med) var(--ease);
}

.switch__thumb {
  display: block;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t-med) var(--ease-back);
}

.switch[aria-checked='true'] .switch__track {
  background: var(--accent);
}

.switch[aria-checked='true'] .switch__thumb {
  transform: translateX(19px);
}

/* ------------------------------------------------------------------- Toasts */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: max-content;
  max-width: calc(100vw - 2rem);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  background: var(--text);
  color: var(--bg);
  font-size: 0.87rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--t-med) var(--ease-back);
}

.toast.is-leaving {
  animation: toast-out var(--t-med) var(--ease) forwards;
}

.toast svg {
  width: 16px;
  height: 16px;
}

.toast--error {
  background: var(--bad);
  color: #fff;
}

.toast--ok {
  background: var(--ok);
  color: #fff;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.94);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
}

/* ============================================================ Breakpoints */

@media (min-width: 560px) {
  .stat-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat-grid--compact {
    grid-template-columns: repeat(4, 1fr);
  }

  .example-row {
    grid-template-columns: repeat(8, 1fr);
  }
}

/* Ab hier ist genug Platz fuer Text und Bedienelement nebeneinander. */
@media (min-width: 480px) {
  .setting {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
  }
}

/* Schmale Geraete: Innenabstaende der Dialoge reduzieren, damit mehr
   Platz fuer den eigentlichen Inhalt bleibt. */
@media (max-width: 479px) {
  .modal__title {
    padding-inline: var(--space-4);
  }

  .modal__body {
    padding-inline: var(--space-4);
  }
}

@media (min-width: 860px) {
  .stat-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* Tiere ohne Emoji bekommen das Pfoten-Icon – ein Emoji-Fallback waere
   im dunklen Design kaum sichtbar. */
.ac__emoji-fallback {
  width: 16px;
  height: 16px;
  margin-inline: auto;
  color: var(--text-subtle);
  opacity: 0.7;
}

/* --------------------------------------------------- Zurückhaltender Button */
/* Für Aktionen, die es geben muss, aber nicht beworben werden sollen
   (z. B. „Aufgeben“) – klar erkennbar, aber nie mit dem Hauptbutton
   verwechselbar. */
.btn--quiet {
  background: transparent;
  border-color: transparent;
  color: var(--text-subtle);
  box-shadow: none;
  font-weight: 600;
}

.btn--quiet:hover {
  background: var(--surface-sunken);
  border-color: var(--border);
  color: var(--text-muted);
}

/* Gefüllte Warnfarbe – nur für die endgültige Bestätigung im Dialog. */
.btn--danger-solid {
  background: var(--bad);
  border-color: transparent;
  color: #fff;
}

.btn--danger-solid:hover {
  background: color-mix(in oklab, var(--bad) 85%, black);
  border-color: transparent;
}

/* Aktionsreihe am Ende eines Dialogs. */
.modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-5) !important;
}

@media (max-width: 420px) {
  .modal__actions {
    flex-direction: column-reverse;
  }

  .modal__actions .btn {
    width: 100%;
  }
}
