/*
 * Grundlagen: Reset, Schrift, Fokus, Knöpfe, Felder, Initialen-Bild, Sheet, Segment-Umschalter.
 * Animiert werden nur transform und opacity, immer mit benannten Eigenschaften.
 */

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

html {
  font-family: var(--font);
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  margin: 0;
  min-height: 100dvh;
  font-size: 0.9375rem;
  line-height: 1.4;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 650; letter-spacing: -0.015em; text-wrap: balance; }
p { text-wrap: pretty; }
img, svg { display: block; }
button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-underline-offset: 0.2em; }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--brand) 22%, transparent); }

/* Fokus: 2 px in Markenblau mit Abstand, nur bei Tastaturbedienung. */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
/* Per Skript fokussierte Ziele (Überschrift, Bereich) sind nicht bedienbar und brauchen keinen Ring.
   Bewusst eng gefasst: bedienbare Elemente behalten ihren Ring, auch mit tabindex="-1". */
:is(h1, h2, h3, main, .sidebar-body)[tabindex="-1"]:focus { outline: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon { width: 1.25em; height: 1.25em; flex: none; }

/* ---------- Knöpfe ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--hit);
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-card);
  background: transparent;
  color: var(--brand);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  user-select: none;
  touch-action: manipulation;
  transition: transform var(--dur-press) var(--ease-out);
}
.button:active { transform: scale(0.97); }

.button-primary { background: var(--brand); color: var(--on-brand); }
.button-primary:active { background: var(--brand-press); }
.button-primary[aria-busy="true"] { cursor: progress; }

.button-secondary { background: var(--hairline); color: var(--ink); }

.button-block { display: flex; width: 100%; min-height: 50px; font-size: 1.0625rem; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: var(--hit);
  height: var(--hit);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  transition: transform var(--dur-press) var(--ease-out);
}
.icon-button:active { transform: scale(0.97); }

@media (hover: hover) and (pointer: fine) {
  .button-primary:hover { background: var(--brand-press); }
  .button-secondary:hover { background: color-mix(in srgb, var(--hairline) 160%, transparent); }
  .icon-button:hover { color: var(--ink); background: var(--hairline); }
}

/* ---------- Gruppierte Felder (wie in den Systemeinstellungen) ---------- */

.field-group {
  background: var(--surface);
  border-radius: var(--radius-card);
}

.field {
  position: relative;
  display: grid;
  gap: 1px;
  padding: 9px 16px 10px;
  cursor: text;
}
.field:first-child { border-radius: var(--radius-card) var(--radius-card) 0 0; }
.field:last-child { border-radius: 0 0 var(--radius-card) var(--radius-card); }
.field:only-child { border-radius: var(--radius-card); }
.field + .field::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 16px;
  border-top: 1px solid var(--hairline);
}

.field label {
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1rem;
  letter-spacing: 0.01em;
  color: var(--ink-2);
  cursor: text;
}

.field input {
  width: 100%;
  min-width: 0;
  min-height: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 1.0625rem; /* nie unter 16 px, sonst zoomt iOS */
  line-height: 1.5rem;
  color: var(--ink);
  outline: none;
}
.field input::placeholder { color: var(--ink-3); }

/* Der Fokusring liegt auf der ganzen Zeile. */
.field:has(input:focus-visible) {
  z-index: 1;
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}
.field:has(input:focus-visible)::before,
.field:has(input:focus-visible) + .field::before { border-top-color: transparent; }
.field:has(input[aria-invalid="true"]) label { color: var(--danger); }

.field-hint {
  margin-top: 8px;
  padding-inline: 16px;
  font-size: 0.8125rem;
  line-height: 1.125rem;
  letter-spacing: 0.01em;
  color: var(--ink-2);
}

/* Fehlermeldung in Worten; leer belegt sie keinen Platz, bleibt aber als Live-Region im Baum. */
.form-error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--danger);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25rem;
}
.form-error:not(:empty) { margin-top: 12px; padding-inline: 4px; }
.form-error .icon { width: 18px; height: 18px; margin-top: 1px; }

/* ---------- Initialen-Bild ---------- */

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  /* Weiß erreicht auf dem hellsten Punkt (#6B7079) 5 : 1. */
  background: linear-gradient(180deg, #6B7079, #50545B);
  color: #FFFFFF;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  user-select: none;
}
.avatar-lg { width: 40px; height: 40px; font-size: 0.9375rem; }

/* ---------- Sheet ---------- */

/* Felder im Sheet heben sich vom Sheet ab: hell etwas dunkler, im Dunkeln etwas heller. */
.sheet { --surface: var(--bg-side); }
@media (prefers-color-scheme: dark) {
  .sheet { --surface: color-mix(in srgb, var(--ink) 7%, var(--bg)); }
}

.sheet {
  /* Eigene Position statt der von :modal, damit das Sheet beim Ausblenden nach close() nicht springt. */
  position: fixed;
  inset: 0;
  width: min(100% - 32px, 480px);
  max-width: none;
  max-height: min(100dvh - 64px, 720px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow-sheet);
  overflow: hidden;
}
.sheet::backdrop { background: var(--scrim); }
/* Nach close() bleiben Sheet und Abdunkelung noch in der obersten Ebene, bis die Ausblendung (WAAPI,
   opacity/transform) fertig ist; die Seite ist dabei schon wieder bedienbar. Diskret, nichts Sichtbares. */
.sheet, .sheet::backdrop {
  transition: display var(--dur-nav) allow-discrete, overlay var(--dur-nav) allow-discrete;
}
/* Spaltenlayout auch ohne [open]: Beim Ausblenden nach close() hält die Animation display: flex. */
.sheet { flex-direction: column; }
.sheet[open] { display: flex; }

.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 6px 6px 0 20px;
}
.sheet-head h2 { flex: 1; font-size: 1.0625rem; line-height: 1.375rem; }
.sheet-body { flex: 1; min-height: 0; overflow: auto; padding: 8px 20px 20px; overscroll-behavior: contain; }
.sheet-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
}

@media (max-width: 639px) {
  .sheet {
    width: 100%;
    max-height: calc(100dvh - 24px - env(safe-area-inset-top));
    margin: auto 0 0;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
  }
  .sheet-foot .button { flex: 1; }
}

/* ---------- Segment-Umschalter ---------- */

.segmented {
  position: relative;
  display: flex;
  padding: 2px;
  border: 0;
  margin: 0;
  min-width: 0;
  border-radius: 9px;
  background: var(--hairline);
}
/*
 * Daumen aus drei Teilen, damit die runden Ecken beim Gleiten zwischen verschieden breiten Segmenten
 * nicht verzerren: zwei feste Kappen (nur verschoben) und ein eckiges Mittelstück (verschoben und
 * gestreckt). Ein gemeinsamer Schatten über drop-shadow, damit keine Nähte entstehen.
 */
.segmented { --thumb: var(--bg); }
.segmented-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  width: 0;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / .08)) drop-shadow(0 2px 3px rgb(0 0 0 / .06));
}
/* Bis zur ersten Messung (Maße erst im Dokument bekannt) bleibt der Daumen unsichtbar, statt kurz links zu stehen. */
.segmented:not([data-placed]) .segmented-thumb { visibility: hidden; }
.thumb-part {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background: var(--thumb);
  transform-origin: left center;
}
.thumb-start { width: 8px; border-radius: 7px 0 0 7px; }
.thumb-mid { width: 100px; }
.thumb-end { width: 8px; border-radius: 0 7px 7px 0; }
.segment {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  min-height: 32px;
  padding: 0 6px;
  border-radius: 7px;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1rem;
  letter-spacing: 0.01em;
  /* Auf der getönten Spur reicht --ink-2 nicht für 4,5 : 1. */
  color: color-mix(in srgb, var(--ink) 72%, transparent);
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* Trefferfläche auf 44 px Höhe erweitern, ohne das Bild zu ändern. */
.segment::after { content: ''; position: absolute; inset: -6px 0; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
/* Die fette Breite ist immer reserviert, damit beim Umschalten nichts springt. */
.segment-label { display: grid; }
.segment-label::after {
  content: attr(data-label);
  height: 0;
  overflow: hidden;
  visibility: hidden;
  font-weight: 600;
  user-select: none;
}
.segment:has(input:checked) { color: var(--ink); font-weight: 600; }
.segment:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 0; }

@media (prefers-color-scheme: dark) {
  .segmented { --thumb: color-mix(in srgb, var(--ink) 16%, var(--bg)); }
}

/* ---------- Weniger Bewegung: nur weiche Überblendungen ---------- */

@media (prefers-reduced-motion: reduce) {
  .button, .icon-button { transition: opacity var(--dur-press) ease; }
  .button:active, .icon-button:active { transform: none; opacity: 0.7; }
}
