:root {
  color-scheme: light dark;
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-muted: #f1f1f4;
  --fg: #111114;
  --fg-muted: #5c5c66;
  --border: #d4d4da;
  --border-subtle: #e7e7ec;
  --border-strong: #a9a9b3;
  --accent: #0060c9;
  --accent-fill: #0060c9;
  --on-accent: #ffffff;
  --danger-fill: #c8102e;
  --warning-fill: #8a4b00;
  --switch-off: #c7c7cc;
  --radius: 0.75rem;
  --radius-small: 0.625rem;
  --content-width: 900px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23111114'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
}

@media (min-width: 1024px) {
  :root {
    --content-width: 1080px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-muted: #2a2a2d;
    --fg: #f2f2f7;
    --fg-muted: #a5a5ae;
    --border: #3d3d41;
    --border-subtle: #2f2f33;
    --border-strong: #6c6c73;
    --accent: #5aa9ff;
    --accent-fill: #0a63c9;
    --danger-fill: #c4161c;
    --switch-off: #48484a;
    --shadow: none;
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23f2f2f7'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

main {
  flex: 1;
  width: 100%;
  max-width: calc(var(--content-width) + 2rem);
  margin: 0 auto;
  padding: 1.5rem max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left));
}

/* Kopfzeile */
.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right), calc((100% - var(--content-width)) / 2)) 0.5rem max(0.5rem, env(safe-area-inset-left), calc((100% - var(--content-width)) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-title {
  overflow: hidden;
  font-weight: 600;
  font-size: 1.0625rem;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.nav-leading,
.nav-trailing {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav button {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 44px;
  padding: 0.5rem 0.625rem;
  font: inherit;
  font-size: 1rem;
  color: var(--accent);
  white-space: nowrap;
  background: none;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
}

/* App-Ebene (links): Sperren ist durch eine Trennlinie von der Seitennavigation abgesetzt. */
.nav .nav-lock {
  color: var(--fg-muted);
}

.nav .nav-back:not([hidden]) {
  padding-left: 0.875rem;
  border-left: 1px solid var(--border);
  border-radius: 0;
}

/* Seiten-Ebene (rechts): genau eine Hauptaktion, gefüllt; weitere Aktionen zurückhaltend. */
.nav .nav-primary {
  padding: 0.5rem 1rem;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent-fill);
}

.nav .nav-secondary {
  color: var(--accent);
}

.icon {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
}

/* Schmale Bildschirme: Sperren nur als Symbol, im Formular haben die Aktionen Vorrang vor dem Titel. */
@media (max-width: 599px) {
  .nav-lock-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .nav .nav-lock {
    min-width: 44px;
    justify-content: center;
    padding: 0.5rem;
  }

  .nav[data-page="form"] .nav-title {
    visibility: hidden;
  }

  .nav,
  .nav-leading,
  .nav-trailing {
    gap: 0.25rem;
  }

  .nav .nav-back:not([hidden]) {
    padding-left: 0.5rem;
  }

  .nav .nav-secondary .icon {
    display: none;
  }
}

/* Sehr schmal (z. B. iPhone mini mit vergrößerter Anzeige): Zurück nur als Pfeil, Name bleibt für Screenreader. */
@media (max-width: 359px) {
  .nav-back-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .nav .nav-back:not([hidden]) {
    min-width: 44px;
    justify-content: center;
    font-size: 1.375rem;
  }
}

/* Fußzeile */
.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0 1.25rem;
  padding: 1rem max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  font-size: 0.8125rem;
  color: var(--fg-muted);
}

.footer a,
.link-button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0;
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* Schaltflächen */
.button-primary,
.button-secondary {
  min-height: 48px;
  padding: 0.75rem 1.25rem;
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.button-primary {
  color: var(--on-accent);
  background: var(--accent-fill);
}

.button-secondary {
  color: var(--fg);
  background: var(--surface-muted);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.empty-state {
  margin-top: 3rem;
  color: var(--fg-muted);
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
