/* ---------- Farben (hell / dunkel) ---------- */
:root, :root[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --text: #17202e;
  --muted: #5d6b80;
  --line: #dde3ec;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #e6eeff;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --banner: linear-gradient(120deg, #1e3a8a, #2563eb 55%, #0ea5e9);
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 4px 16px rgb(16 24 40 / .07);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f141c;
  --surface: #171e29;
  --surface-2: #1f2835;
  --text: #e7ecf3;
  --muted: #9aa8bb;
  --line: #2c3747;
  --accent: #6b97ff;
  --accent-ink: #0b1220;
  --accent-soft: #1d2a45;
  --warn: #f0a24a;
  --danger: #f87171;
  --ok: #4ade80;
  --banner: linear-gradient(120deg, #0f1d45, #1a3a8f 55%, #0b5f86);
  --shadow: 0 1px 2px rgb(0 0 0 / .35), 0 6px 20px rgb(0 0 0 / .3);
  color-scheme: dark;
}
:root {
  --radius: 14px;
  /* Feste Hoehe des Formulars, unabhaengig von der Anzahl der Boxen */
  --wiz-h: clamp(420px, calc(100dvh - 300px), 600px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }
h1, h2 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h2:focus { outline: none; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }

/* ---------- Kopf ---------- */
.top { background: var(--banner); color: #fff; padding: 26px 0 62px; }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; gap: 14px; align-items: center; min-width: 0; }
.brand svg { width: 44px; height: 44px; flex: none; }
.brand svg rect { fill: rgb(255 255 255 / .16); }
.brand svg path { stroke: #fff; stroke-width: 3; stroke-linecap: round; fill: none; }
.brand h1 { font-size: 1.5rem; }
.brand p { margin: 2px 0 0; opacity: .85; }

.theme-toggle {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgb(255 255 255 / .35);
  background: rgb(255 255 255 / .12); color: #fff; cursor: pointer; display: grid; place-items: center;
}
.theme-toggle:hover { background: rgb(255 255 255 / .22); }
.theme-toggle:focus-visible { outline: 3px solid rgb(255 255 255 / .6); outline-offset: 2px; }
.theme-toggle svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; }
/* Symbol zeigt den Modus, der beim Klick eingeschaltet wird */
:root[data-theme="dark"] .theme-toggle .icon-moon,
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }

main.wrap { margin-top: -40px; }

/* ---------- Schritte ---------- */
.stepper {
  list-style: none; margin: 0 0 16px; padding: 10px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.stepper li {
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 4px; border-radius: 10px;
  color: var(--muted); font-weight: 600; font-size: .95rem; user-select: none;
}
.stepper li span {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-2); font-size: .85rem;
}
.stepper li.active { background: var(--accent-soft); color: var(--accent); }
.stepper li.active span { background: var(--accent); color: var(--accent-ink); }
.stepper li.done { color: var(--text); cursor: pointer; }
.stepper li.done:hover { background: var(--surface-2); }
.stepper li.done span { background: var(--ok); color: #fff; }

/* ---------- Formular mit seitlichen Pfeilen ---------- */
.stage { position: relative; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.wizard { height: var(--wiz-h); padding: 24px; margin-bottom: 16px; }
.step { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.step-head { margin-bottom: 16px; flex: none; }
.step-head p { margin: 6px 0 0; }
.step-body { flex: 1; min-height: 0; }
.step-body.scroll { overflow-y: auto; padding-right: 4px; margin-right: -4px; }
.step-body.fill { overflow: hidden; }
.step-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); margin-top: 12px; min-height: 52px; }
.step-foot.end { justify-content: flex-end; }

.nav-arrow {
  position: absolute; top: calc(var(--wiz-h) / 2); transform: translateY(-50%);
  width: 56px; height: 104px; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  display: grid; place-items: center; border-radius: 12px; padding: 0;
  transition: color .15s, background .15s;
}
.nav-arrow svg { width: 30px; height: 60px; fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.nav-arrow:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.nav-arrow:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent); }
.nav-arrow.prev { left: -76px; }
.nav-arrow.next { right: -76px; }
.nav-arrow.next.ready { color: var(--accent); }
.nav-arrow[disabled] { visibility: hidden; }
.mobile-nav { display: none; }

/* ---------- Werkzeugleiste und Chips ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; flex: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 6px 12px; font: inherit; font-size: .9rem; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.count { font-weight: 600; color: var(--accent); }

/* ---------- Box-Kacheln (seitenweise) ---------- */
.boxes {
  --box-h: 72px; --divider-h: 14px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; align-content: start;
}
.boxes .box { height: var(--box-h); }
.divider { grid-column: 1 / -1; height: var(--divider-h); display: flex; align-items: center; }
.divider::before { content: ""; flex: 1; border-top: 2px dashed var(--line); }
.box {
  position: relative; display: flex; flex-direction: column; justify-content: center; gap: 1px;
  padding: 8px 12px 8px 44px; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer;
  background: var(--surface); transition: border-color .12s, background .12s; min-width: 0;
}
.box input { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.box b { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box small { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box small.warn { color: var(--warn); }
.box:hover { border-color: var(--accent); }
.box:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.pager { display: flex; align-items: center; gap: 6px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); }
.pager-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.pager-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.pager-btn:hover:not([disabled]) { border-color: var(--accent); color: var(--accent); }
.pager-btn[disabled] { opacity: .35; cursor: default; }

/* ---------- Formularfelder ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; align-items: end; margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
.field input, .field select {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 10px; padding: 9px 11px; min-height: 44px; width: 100%;
}
.field select:disabled { opacity: .5; }
.field input:focus, .field select:focus, .chip:focus-visible, .btn:focus-visible, .box:focus-within, .option:focus-within, .pager-btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 1px; border-color: var(--accent);
}
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; font-size: .95rem; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { margin: 0; font-size: .9rem; color: var(--muted); min-height: 1.4em; }
.hint.warn { color: var(--warn); }

/* ---------- Auswahl-Karten ---------- */
.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; border: 0; padding: 0; margin: 0; }
.options legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.options.compact { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-top: 18px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1.5px solid var(--line); border-radius: 12px;
  cursor: pointer; background: var(--surface);
}
.option input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.option span { display: flex; flex-direction: column; }
.option small { color: var(--muted); }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

details { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.contents ul { margin: 10px 0 0; padding-left: 20px; }
.contents li { margin: 4px 0; }

.summary { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; border-radius: 10px; padding: 11px 20px; cursor: pointer; border: 1.5px solid transparent;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn.ghost:hover { border-color: var(--accent); }

/* ---------- Fertig ---------- */
.done { justify-content: center; }
.done-inner { text-align: center; }
.done svg { width: 64px; height: 64px; margin-bottom: 8px; }
.done svg circle { fill: color-mix(in srgb, var(--ok) 15%, transparent); stroke: var(--ok); stroke-width: 1.5; }
.done svg path { fill: none; stroke: var(--ok); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.done p { margin: 8px 0 0; overflow-wrap: anywhere; }
.row-center { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 20px; }

/* ---------- Meldungen oben rechts ---------- */
.toasts {
  position: fixed; top: 16px; right: 16px; z-index: 20; display: flex; flex-direction: column; gap: 10px;
  width: min(380px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto; position: relative; overflow: hidden; display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); color: var(--text); border-radius: 12px; box-shadow: 0 8px 28px rgb(0 0 0 / .18);
  border-left: 4px solid var(--accent); padding: 14px 40px 18px 14px; font-weight: 500;
  animation: toast-in .32s cubic-bezier(.2, .9, .3, 1.1);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--ok); }
.toast.leaving { animation: toast-out .28s ease-in forwards; }
.toast .ticon { flex: none; width: 22px; height: 22px; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; stroke: var(--accent); }
.toast.error .ticon { stroke: var(--danger); }
.toast.success .ticon { stroke: var(--ok); }
.toast .close {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1;
}
.toast .close:hover { background: var(--surface-2); color: var(--text); }
.toast .bar {
  position: absolute; left: 0; bottom: 0; height: 4px; width: 100%; background: currentColor; opacity: .25;
  transform-origin: left; animation: toast-bar 10s linear forwards;
}
.toast.error .bar { color: var(--danger); opacity: .45; }
.toast.success .bar { color: var(--ok); opacity: .45; }
.toast:hover .bar { animation-play-state: paused; }
@keyframes toast-in { from { transform: translateX(calc(100% + 24px)); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateX(calc(100% + 24px)); opacity: 0; } }
@keyframes toast-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------- Laeuft ---------- */
.overlay {
  position: fixed; inset: 0; background: rgb(10 15 25 / .55); display: grid; place-items: center; padding: 16px; z-index: 30;
  backdrop-filter: blur(2px);
}
.busy-card { background: var(--surface); border-radius: var(--radius); padding: 30px 28px; text-align: center; max-width: 380px; width: 100%; box-shadow: var(--shadow); }
.busy-card p { margin: 8px 0 0; }
.big { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.spinner {
  width: 44px; height: 44px; margin: 0 auto 14px; border-radius: 50%;
  border: 4px solid var(--surface-2); border-top-color: var(--accent); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.foot { color: var(--muted); font-size: .9rem; text-align: center; padding-bottom: 32px; }
.foot p { margin: 6px 0; }
.legal a { color: var(--muted); }
.legal a:hover { color: var(--accent); }
.legal span { margin: 0 8px; }

@media (prefers-reduced-motion: reduce) {
  .toast, .toast.leaving { animation-duration: .01s; }
  .spinner { animation-duration: 3s; }
}

/* ---------- Schmalere Bildschirme: feste Navigationsleiste unten ---------- */
@media (max-width: 1099px) {
  .mobile-nav {
    display: flex; align-items: center; justify-content: center; position: fixed; left: 0; right: 0; bottom: 0; z-index: 14;
    height: calc(64px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgb(0 0 0 / .08);
    color: var(--muted); font-weight: 600; font-size: .9rem;
  }
  .nav-arrow {
    position: fixed; top: auto; bottom: calc(8px + env(safe-area-inset-bottom)); transform: none; z-index: 15;
    width: 48px; height: 48px; border-radius: 12px;
  }
  .nav-arrow svg { width: 16px; height: 30px; stroke-width: 3.4; }
  .nav-arrow.prev { left: 12px; }
  .nav-arrow.next { right: 12px; }
  .nav-arrow.next.ready { background: var(--accent); color: var(--accent-ink); }
  body { padding-bottom: 80px; }
}

@media (max-width: 640px) {
  :root { --wiz-h: clamp(340px, calc(100dvh - 330px), 600px); }
  .top { padding: 16px 0 52px; }
  .brand svg { width: 36px; height: 36px; }
  .brand h1 { font-size: 1.15rem; }
  .brand p { font-size: .85rem; }
  .wizard { padding: 16px; }
  .stepper { gap: 2px; padding: 6px; margin-bottom: 12px; }
  .stepper li { flex-direction: column; gap: 2px; font-size: .72rem; padding: 6px 2px; }
  .step-head { margin-bottom: 12px; }
  .step-head p { font-size: .9rem; }
  h2 { font-size: 1.1rem; }
  .toolbar { gap: 6px; margin-bottom: 10px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -16px; padding-inline: 16px; }
  .toolbar::-webkit-scrollbar { display: none; }
  .chip { padding: 5px 10px; font-size: .85rem; flex: none; }
  .step[data-step="1"] .step-head p { display: none; }
  .wide-only { display: none; }
  .count, #page-info { white-space: nowrap; }
  .step-foot { min-height: 48px; padding-top: 10px; margin-top: 10px; }
  .pager-btn { width: 34px; height: 34px; }
  .foot { font-size: .82rem; padding-bottom: 16px; }
  .foot p { margin: 3px 0; }
  .boxes { grid-template-columns: 1fr; gap: 8px; --box-h: 60px; --divider-h: 10px; }
  .grid2, .grid3 { grid-template-columns: 1fr; gap: 10px; }
  .summary { grid-template-columns: 1fr; gap: 2px; }
  .summary dd { margin-bottom: 8px; }
  .toasts { top: 10px; right: 10px; width: calc(100vw - 20px); }
}
