/* Basis: Reset, Typografie, Komponenten (docs/ARCHITECTURE.md §12).
   Keine Inline-Styles moeglich (CSP) - dynamische Werte kommen ueber
   Custom Properties, die JS per setProperty() setzt. */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
  /* Kein Element darf die Seite breiter als den Viewport machen: iOS zoomt
     sonst heraus, bis das breiteste Element passt, und alles andere (Panels,
     Karte) bleibt auf Viewport-Breite stehen. clip statt hidden, damit die
     sticky Top-Bar sticky bleibt (clip erzeugt keinen Scroll-Container);
     hidden als Fallback fuer Safari vor 16. */
  overflow-x: hidden;
  overflow-x: clip;
}
img, picture, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; margin: 0; }
button { cursor: pointer; }
p, h1, h2, h3, h4, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
::selection { background: var(--c-accent-soft); }

/* ---------- Typografie ---------- */
h1, .t-display { font-family: var(--font-display); font-size: var(--fs-display); font-weight: 600; letter-spacing: var(--ls-display); line-height: 1.1; }
h2, .t-title { font-family: var(--font-display); font-size: var(--fs-title); font-weight: 600; letter-spacing: -.015em; line-height: 1.2; }
h3, .t-headline { font-size: var(--fs-headline); font-weight: 600; line-height: 1.3; }
.t-body { font-size: var(--fs-body); font-weight: 400; line-height: var(--lh-body); }
.t-callout { font-size: var(--fs-callout); }
.t-caption, .muted { font-size: var(--fs-caption); color: var(--c-text-2); }
.text-2 { color: var(--c-text-2); }
.text-center { text-align: center; }
strong { font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); padding: 0 22px;
  border: 1px solid transparent; border-radius: var(--r-pill);
  background: var(--c-fill); color: var(--c-text);
  font-size: var(--fs-body); font-weight: 600; line-height: 1; white-space: nowrap;
  text-decoration: none; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-fast) var(--ease-fast), color var(--dur-fast) var(--ease-fast),
              transform var(--dur-fast) var(--ease-fast), box-shadow var(--dur-fast) var(--ease-fast);
}
.btn:hover { background: var(--c-fill-2); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--c-accent); color: var(--c-on-accent); }
.btn-primary:hover { background: var(--c-accent-hover); }
.btn-outline { background: transparent; border-color: var(--c-accent); color: var(--c-accent); }
.btn-outline:hover { background: var(--c-accent-soft); }
.btn-ghost { background: transparent; color: var(--c-accent); }
.btn-ghost:hover { background: var(--c-accent-soft); }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-danger-ghost { background: transparent; color: var(--c-danger); }
.btn-danger-ghost:hover { background: var(--c-danger-soft); }
.btn-sm { min-height: 36px; padding: 0 16px; font-size: var(--fs-callout); }
.btn-block { width: 100%; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--touch); height: var(--touch); padding: 0; border: 0; border-radius: 50%;
  background: var(--c-fill); color: var(--c-text);
  transition: background var(--dur-fast) var(--ease-fast), transform var(--dur-fast) var(--ease-fast);
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover { background: var(--c-fill-2); }
.btn-icon:active { transform: scale(.94); }
.btn-icon svg { width: 20px; height: 20px; }
.linklike { background: none; border: 0; padding: 0; color: var(--c-accent); font-weight: 500; }
.linklike:hover { text-decoration: underline; }

/* ---------- Glas & Karten ---------- */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-edge);
}
.card {
  background: var(--c-surface);
  border-radius: var(--r-l);
  box-shadow: var(--sh-1);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: var(--fs-headline); font-weight: 600; margin-bottom: 12px; }
.hairline { border-top: 1px solid var(--c-line); }
.divider { height: 1px; background: var(--c-line); margin: 16px 0; }

/* ---------- Segmented Control ---------- */
.segmented {
  /* Gleitende Auswahl: ui.js misst das aktive Element (Position + Breite in px),
     weil die Segmente unterschiedlich breit sind. Ohne Messung: unsichtbar. */
  --seg-x: 0px;
  --seg-w: 0px;
  position: relative; display: inline-flex; align-items: stretch;
  padding: 3px; border-radius: var(--r-pill); background: var(--c-fill-2);
  min-width: 100%;
}
.segmented::before {
  content: ""; position: absolute; top: 3px; bottom: 3px; left: 0;
  width: var(--seg-w);
  border-radius: var(--r-pill); background: var(--c-surface); box-shadow: var(--sh-1);
  transform: translateX(var(--seg-x));
  transition: transform var(--dur-sheet) var(--ease-sheet), width var(--dur-sheet) var(--ease-sheet);
}
.seg-item {
  position: relative; z-index: 1; flex: 1 0 0; min-width: 5.75rem; height: 34px; padding: 0 14px;
  border: 0; border-radius: var(--r-pill); background: transparent;
  color: var(--c-text-2); font-size: var(--fs-callout); font-weight: 600; white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-fast);
  -webkit-tap-highlight-color: transparent;
}
.seg-item:hover { color: var(--c-text); }
.seg-item[aria-selected="true"], .seg-item.is-active { color: var(--c-text); }

/* ---------- Formulare ---------- */
.field { display: grid; gap: 6px; }
.label { font-size: var(--fs-caption); font-weight: 600; color: var(--c-text-2); }
.input {
  width: 100%; min-height: var(--touch); padding: 0 14px;
  border: 1px solid var(--c-line); border-radius: var(--r-m);
  background: var(--c-surface); color: var(--c-text); font-size: var(--fs-body);
  transition: border-color var(--dur-fast) var(--ease-fast), box-shadow var(--dur-fast) var(--ease-fast);
  -webkit-appearance: none; appearance: none;
}
.input::placeholder { color: var(--c-text-2); opacity: .8; }
.input:focus { outline: none; border-color: var(--c-accent); box-shadow: 0 0 0 4px var(--c-accent-soft); }
textarea.input { min-height: 96px; padding: 10px 14px; resize: vertical; line-height: 1.45; }
select.input { padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--c-text-2) 50%), linear-gradient(135deg, var(--c-text-2) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row .input { flex: 1 1 auto; }
.form-error { color: var(--c-danger); font-size: var(--fs-caption); font-weight: 500; }
.form-hint { color: var(--c-text-2); font-size: var(--fs-caption); }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: var(--touch); }
.check input { width: 18px; height: 18px; accent-color: var(--c-accent); }

/* ---------- Badges & Chips ---------- */
.badge {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px;
  border-radius: var(--r-pill); font-size: var(--fs-caption); font-weight: 600; letter-spacing: .01em;
  background: var(--c-fill-2); color: var(--c-text-2); white-space: nowrap;
}
.badge-admin { background: var(--c-accent-soft); color: var(--c-accent); }
.badge-family { background: var(--c-success-soft); color: var(--c-success); }
.badge-danger { background: var(--c-danger-soft); color: var(--c-danger); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--r-pill); background: var(--c-fill);
  color: var(--c-text); font-size: var(--fs-callout); font-weight: 500; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-fast), color var(--dur-fast) var(--ease-fast);
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { background: var(--c-fill-2); }
.chip.is-active, .chip[aria-pressed="true"] { background: var(--c-text); color: var(--c-bg); }
.chip--current { border-color: var(--c-accent); color: var(--c-accent); }
.chip-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip-row::-webkit-scrollbar { display: none; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: var(--z-toast);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  transform: translateX(-50%); width: min(92vw, 420px); pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 100%; padding: 12px 18px; border-radius: var(--r-pill);
  background: rgba(29, 29, 31, .92); color: #f5f5f7; font-size: var(--fs-callout); font-weight: 500;
  box-shadow: var(--sh-2); text-align: center;
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  animation: toast-in var(--dur-sheet) var(--ease-sheet) both;
}
.toast-error { background: rgba(255, 59, 48, .94); color: #fff; }
.toast-success { background: rgba(52, 199, 89, .94); color: #fff; }
.toast.is-leaving { animation: toast-out var(--dur-fast) var(--ease-fast) both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Sheet (unten auf Phones, seitlich ab 700 px) ---------- */
.layer-backdrop {
  position: fixed; inset: 0; z-index: var(--z-sheet); background: var(--c-scrim);
  opacity: 0; transition: opacity var(--dur-sheet) var(--ease-sheet);
}
.layer-backdrop.is-open { opacity: 1; }
.sheet {
  position: fixed; z-index: calc(var(--z-sheet) + 1); display: flex; flex-direction: column;
  background: var(--c-surface); box-shadow: var(--sh-2);
  left: 0; right: 0; bottom: 0; max-height: min(88dvh, 100%);
  border-radius: var(--r-l) var(--r-l) 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(100%); transition: transform var(--dur-sheet) var(--ease-sheet);
}
.sheet.is-open { transform: none; }
.sheet-header {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px 10px;
  border-bottom: 1px solid var(--c-line); flex: 0 0 auto;
}
.sheet-grip { position: absolute; top: 6px; left: 50%; width: 36px; height: 5px; border-radius: 3px; background: var(--c-fill-3); transform: translateX(-50%); }
.sheet-title { flex: 1 1 auto; font-size: var(--fs-headline); font-weight: 600; line-height: 1.25; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet-close { flex: 0 0 auto; width: 32px; height: 32px; }
@media (min-width: 700px) {
  .sheet {
    left: auto; top: 0; bottom: 0; width: min(460px, 100%); max-height: none;
    border-radius: var(--r-l) 0 0 var(--r-l);
    transform: translateX(100%);
  }
  .sheet-wide { width: min(720px, 100%); }
  .sheet-grip { display: none; }
  .sheet-header { padding: 18px 20px 12px; }
  .sheet-body { padding: 20px; }
}

/* ---------- Modal ---------- */
.modal-backdrop { z-index: var(--z-modal); }
.modal {
  position: fixed; z-index: calc(var(--z-modal) + 1); left: 50%; top: 50%;
  width: min(92vw, 440px); max-height: 90dvh; display: flex; flex-direction: column;
  background: var(--c-surface); border-radius: var(--r-l); box-shadow: var(--sh-2);
  transform: translate(-50%, -50%) scale(.96); opacity: 0;
  transition: transform var(--dur-sheet) var(--ease-sheet), opacity var(--dur-fast) var(--ease-fast);
}
.modal.is-open { transform: translate(-50%, -50%); opacity: 1; }
.modal-wide { width: min(94vw, 720px); }
.modal-header { padding: 20px 20px 4px; }
.modal-title { font-size: var(--fs-headline); font-weight: 600; }
.modal-body { padding: 12px 20px; overflow-y: auto; color: var(--c-text); }
.modal-text { color: var(--c-text-2); font-size: var(--fs-callout); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 20px 20px; flex-wrap: wrap; }

/* ---------- Leerzustand ---------- */
.empty-state { text-align: center; padding: 48px 24px; color: var(--c-text-2); }
.empty-icon { font-size: 44px; line-height: 1; margin-bottom: 12px; }
.empty-title { font-size: var(--fs-headline); font-weight: 600; color: var(--c-text); margin-bottom: 6px; }
.empty-text { font-size: var(--fs-callout); }

/* ---------- Fehlerseite ---------- */
.error-page { display: grid; place-items: center; padding: 24px; }
.error-card { width: min(100%, 420px); text-align: center; padding: 36px 28px; display: grid; gap: 10px; justify-items: center; }
.error-code { font-family: var(--font-display); font-size: 3.5rem; font-weight: 200; letter-spacing: -.03em; line-height: 1; color: var(--c-text-2); }
.error-title { font-size: var(--fs-headline); font-weight: 600; letter-spacing: 0; line-height: 1.3; }
.error-hint { color: var(--c-text-2); font-size: var(--fs-callout); margin-bottom: 12px; }
.error-links { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; font-size: var(--fs-caption); color: var(--c-text-2); }
.error-links a { color: inherit; }
.error-links a:hover { color: var(--c-text); }

/* ---------- Layout-Helfer ---------- */
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.no-scrollbar { scrollbar-width: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.progress {
  height: 6px; border-radius: 3px; background: var(--c-fill-2); overflow: hidden;
}
.progress-bar { height: 100%; width: calc(var(--progress, 0) * 1%); background: var(--c-accent); border-radius: 3px; transition: width var(--dur-sheet) var(--ease-sheet); }

/* ---------- Bewegung ---------- */
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.fade-up { animation: fade-up var(--dur-sheet) var(--ease-sheet) both; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

/* ---------- Rechtstexte (Impressum / Datenschutz) ---------- */
.legal {
  max-width: 44rem;
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 4.5rem) 1.25rem 4rem;
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--c-text);
}
.legal h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4.5vw, 2.75rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 1.5rem;
}
.legal h2 {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 2.4rem 0 0.6rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--c-line);
}
.legal h3 { font-size: 1.0625rem; font-weight: 600; margin: 1.4rem 0 0.4rem; }
.legal p, .legal ul, .legal ol { margin: 0 0 0.9rem; }
.legal ul, .legal ol { padding-left: 1.3rem; }
.legal li { margin-bottom: 0.3rem; }
.legal a { color: var(--c-accent); text-decoration: none; }
.legal a:hover { text-decoration: underline; }
.legal code {
  font-size: 0.9em;
  background: var(--c-fill, rgba(0, 0, 0, 0.05));
  border-radius: 6px;
  padding: 0.1em 0.4em;
}
.legal mark {
  background: rgba(255, 214, 10, 0.35);
  color: inherit;
  border-radius: 4px;
  padding: 0 0.25em;
  font-weight: 600;
}
.legal .legal-nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.9375rem;
  color: var(--c-text-2);
  margin-bottom: 2rem;
}
.legal table { border-collapse: collapse; width: 100%; font-size: 0.9375rem; }
.legal th, .legal td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--c-line); vertical-align: top; }
