:root {
  --ground:      #FAFAF7;
  --surface:     #FFFFFF;
  --surface-2:   #F3F3EC;
  --ink:         #23281F;
  --muted:       #6C7266;
  --rule:        #DEDFD6;
  --accent:      #3E5C3A;
  --accent-soft: #E7ECDF;
  --danger:      #A8571E;
  --warn:        #8A6D1E;
  --warn-soft:   #F4ECD8;
  --sex-male:    #2C6E9B;
  --sex-female:  #A8571E;
  --focus:       #3E5C3A;
  --pop-shadow:  0 6px 22px rgba(35, 40, 31, .14);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground:      #171B15;
    --surface:     #1F241C;
    --surface-2:   #262C22;
    --ink:         #E9EAE1;
    --muted:       #9AA093;
    --rule:        #333A30;
    --accent:      #93B587;
    --accent-soft: #2A3325;
    --danger:      #D98A4E;
    --warn:        #D9B65B;
    --warn-soft:   #322B18;
    --sex-male:    #6FA8CE;
    --sex-female:  #D98A4E;
    --focus:       #93B587;
    --pop-shadow:  0 6px 22px rgba(0, 0, 0, .38);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: "Libre Franklin", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* Übersicht und Detail scrollen unabhängig: App füllt genau den Viewport */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar, .tabs, .subtabs { flex: none; }

/* ---------- Topbar ---------- */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .8rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.rasse {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-family: "Fraunces", Georgia, serif;
  font-size: 1rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(46vw, 34rem);
  pointer-events: none;
}
.rasse:empty { display: none; }
@media (max-width: 700px) { .rasse { display: none; } }
.nav-toggle {
  flex: none;
  width: 1.9rem;
  height: 1.9rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.nav-toggle:hover { border-color: var(--muted); }
.nav-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.brand { display: flex; align-items: center; gap: .7rem; }
.brand .mark {
  width: 1.4rem; height: 1.4rem;
  border: 2px solid var(--accent);
  border-radius: 50% 50% 50% 2px;
  flex: none;
}
.brand strong {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: 1.15rem;
  letter-spacing: .02em;
}
.brand .sub {
  display: block;
  font-size: .74rem;
  color: var(--muted);
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42ch;
}
@media (max-width: 780px) { .brand .sub { max-width: 20ch; } }
/* Verbindungsstatus – dezenter Punkt statt Button-Optik */
.conn-status {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin-left: .4rem;
  font-size: .68rem;
  letter-spacing: .04em;
  color: var(--muted);
  white-space: nowrap;
}
.conn-status::before {
  content: "";
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.conn-status.ok::before    { background: var(--accent); }
.conn-status.error::before { background: var(--danger); }
.conn-status.error         { color: var(--danger); }
@media (max-width: 780px) { .conn-status .conn-label { display: none; } }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: .15rem;
  padding: 0 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.tab {
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: .7rem .85rem;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.tab:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tab-settings { margin-left: auto; }
.tab[hidden] { display: none; }

.subtabs[hidden] { display: none; }
.subtabs {
  display: flex;
  gap: .2rem;
  padding: .35rem 1.2rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--rule);
}
.subtab {
  font: inherit;
  font-size: .82rem;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: .3rem .7rem;
  cursor: pointer;
}
.subtab:hover { color: var(--ink); }
.subtab[aria-selected="true"] {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--rule);
}
.subtab:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.list-pane[hidden] { display: none; }

/* ---------- Layout ---------- */
.grid {
  display: grid;
  grid-template-columns: minmax(15rem, 22rem) 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.grid.nav-collapsed { grid-template-columns: 1fr; }
.grid.nav-collapsed .list-pane { display: none; }
/* Ansichten ohne Liste (Einstellungen, Datensicherung, Benutzer, Protokoll):
   Detailbereich nutzt die ganze Breite statt nur die (leere) Listenspalte */
.grid:has(> .list-pane[hidden]) { grid-template-columns: 1fr; }
/* Handy-Master-Detail: siehe @media (max-width: 720px) am Dateiende */

/* ---------- List ---------- */
.list-pane {
  border-right: 1px solid var(--rule);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.list-head {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .9rem;
  border-bottom: 1px solid var(--rule);
}
.list-head-tools { display: flex; gap: .5rem; align-items: center; }
.list-head-tools #new-btn { margin-left: auto; }   /* „Neu" rechtsbündig */
.list-head input {
  width: 100%;
  min-width: 0;
  padding: .5rem .6rem;
  font: inherit;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--rule);
  border-radius: 3px;
}
.count {
  margin: 0;
  padding: .5rem .95rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.rows li {
  padding: .6rem .95rem;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
}
.rows li:hover { background: var(--surface-2); }
.rows li:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.rows li[aria-current="true"] {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.rows .r-name { font-weight: 500; }
.rows .r-sub {
  font-size: .78rem;
  color: var(--muted);
}
.rows .r-sub .zw {
  font-family: "IBM Plex Mono", monospace;
  font-size: .72rem;
}
.rows li.rows-more {
  padding: .7rem .95rem;
  cursor: default;
  text-align: center;
  border-bottom: none;
}
.rows li.rows-more:hover { background: none; }
.rows li.rows-more .btn { width: 100%; }

/* ---------- Detail ---------- */
.detail-pane { padding: 1.4rem clamp(1rem, 3vw, 2rem); min-width: 0; overflow-y: auto; }
.detail-head[hidden], .detail-tabs[hidden], .detail-nav[hidden] { display: none; }
.detail-head {
  display: flex;
  align-items: center;
  gap: .8rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding-bottom: .8rem;
  border-bottom: 1px solid var(--rule);
}
.detail-head .rec-meta { margin-left: auto; }
.detail-back {
  display: none;
  align-items: center;
  font: inherit;
  font-size: .82rem;
  color: var(--accent);
  background: none;
  border: none;
  padding: .2rem .1rem .2rem 0;
  cursor: pointer;
  flex: none;
}
.detail-back:hover { text-decoration: underline; }
.detail-back:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.detail-back[hidden] { display: none !important; }
.detail-nav { display: flex; gap: .25rem; flex: none; }
.detail-nav button {
  width: 1.7rem;
  height: 1.7rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.detail-nav button:hover:not(:disabled) { border-color: var(--muted); }
.detail-nav button:disabled { opacity: .35; cursor: default; }
.detail-nav button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.detail-tabs {
  display: flex;
  gap: .2rem;
  margin-bottom: 1.3rem;
}
.dtab {
  font: inherit;
  font-size: .85rem;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: .4rem .7rem;
  cursor: pointer;
}
.dtab:hover { color: var(--ink); }
.dtab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.dtab:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.detail-tabs { flex-wrap: wrap; }

.fieldset { display: contents; }
.fieldset[hidden] { display: none; }
.fieldset-head {
  display: none;
  grid-column: 1 / -1;
  font-family: "IBM Plex Mono", monospace;
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 1.4rem 0 .6rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--rule);
}
.fieldset:first-child .fieldset-head { margin-top: 0; }
/* ohne Tabs (Neuerfassung): Abschnittsüberschriften zeigen */
.detail-tabs[hidden] ~ form .fieldset-head { display: block; }
.detail-head h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: 1.4rem;
  margin: 0;
}
.rec-meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: .7rem;
  color: var(--muted);
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .9rem 1rem;
  max-width: 40rem;
}
.section-head {
  grid-column: 1 / -1;
  font-family: "IBM Plex Mono", monospace;
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 1.5rem 0 .1rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--rule);
}
.section-head:first-child { margin-top: 0; }

.fld { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.req-mark { color: var(--danger); font-weight: 600; }

.warnings {
  margin: 0 0 1.3rem;
  padding: .75rem .9rem;
  background: var(--warn-soft);
  border-left: 3px solid var(--warn);
  font-size: .88rem;
}
.warnings strong {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: .68rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--warn);
  margin-bottom: .35rem;
}
.warnings ul { margin: 0; padding-left: 1.1rem; }
.warnings li { margin: .15rem 0; }
.r-warn { color: var(--warn); cursor: help; }

/* ---------- Stammbaum ---------- */
.ped-controls { display: flex; gap: .5rem; margin-bottom: 1.1rem; }
.pedigree-scroll { overflow-x: auto; padding-bottom: .5rem; }
.pedigree {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(9rem, 1fr));
  grid-template-rows: repeat(var(--rows), var(--rowh));
  gap: 5px 10px;
  min-width: 40rem;
}
.ped-box {
  position: relative;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--rule);
  background: var(--surface);
  padding: .3rem .5rem;
  font-size: .8rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
}
.ped-box:not([data-col="1"])::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 50%;
  width: 10px;
  border-top: 1px solid var(--rule);
}
.ped-box.ped-r { border-left-color: var(--sex-male); }
.ped-box.ped-h { border-left-color: var(--sex-female); }
.ped-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ped-zwinger {
  font-size: .72rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ped-meta {
  color: var(--muted);
  font-size: .7rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pedigree-compact .ped-zwinger { display: none; }
.pedigree-compact .ped-name { font-size: .75rem; }
.pedigree-compact .ped-meta { font-size: .65rem; }
.ped-empty {
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border-style: dashed;
  border-left-style: dashed;
}
.ped-extern .ped-name { font-style: italic; font-weight: 400; }
.ped-link { cursor: pointer; }
.ped-link:hover { background: var(--accent-soft); }
.ped-link:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* Gemeinsame Vorfahren (Inzucht) */
.ped-box.ped-common {
  background: var(--warn-soft);
  border-color: var(--warn);
}
.ped-box.ped-common.ped-link:hover { background: var(--warn-soft); filter: brightness(.97); }
.ped-common-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 1rem;
  height: 1rem;
  padding: 0 .18rem;
  background: var(--warn);
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
  line-height: 1rem;
  text-align: center;
  border-radius: 0 0 0 3px;
}
.ped-legend {
  margin-top: .9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .8rem;
  font-size: .8rem;
}
.ped-legend-cap { color: var(--muted); }
.ped-legend-item {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font: inherit;
  background: none;
  border: none;
  padding: 0;
  color: var(--ink);
  text-decoration: none;
}
.ped-legend-item.linklike { cursor: pointer; }
.ped-legend-item.linklike:hover { color: var(--accent); text-decoration: underline; }
.ped-legend .ped-common-badge {
  position: static;
  display: inline-block;
  border-radius: 2px;
}

.combo-open {
  position: absolute;
  top: 50%;
  right: 1.75rem;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--muted);
  font-size: .95rem;
  line-height: 1;
  padding: .1rem .25rem;
  cursor: pointer;
}
.combo-open:hover { color: var(--accent); }
.fld > span {
  font-family: "IBM Plex Mono", monospace;
  font-size: .66rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
.fld input, .fld textarea, .fld select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: .5rem .6rem;
  width: 100%;
  resize: vertical;
}
.fld input::placeholder { color: var(--muted); opacity: .75; letter-spacing: .06em; }
/* Falls ein Datumsfeld doch mal als type=date sichtbar ist: linksbündig
   (iOS/iPadOS-Safari zentriert sonst den Wert). */
.fld input[type="date"] { min-width: 0; text-align: left; }
.fld input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.fld select:disabled { opacity: .55; }
.fld-check {
  flex-direction: row;
  align-items: center;
  gap: .5rem;
}
.fld-check > span { order: 2; text-transform: none; letter-spacing: normal; font-size: .82rem; font-family: "Libre Franklin", sans-serif; color: var(--ink); }
.fld-check input { width: auto; }

/* ---------- Messfeld-Verlauf (10 Jahres-Zellen) ---------- */
.mgrid-head, .mgrid-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(4.5rem, 7rem) 1fr;
  align-items: center;
  gap: .35rem .5rem;
}
.mgrid-head { margin: .5rem 0 -.1rem; }
.mgrid-head .mgrid-label {
  font-size: .68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.mgrid-label {
  font-size: .82rem;
  text-align: right;
  color: var(--ink);
}
.mgrid-cells {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 3px;
}
.mgrid-head .mgrid-cells span {
  text-align: center;
  font-size: .62rem;
  letter-spacing: -.02em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-family: "IBM Plex Mono", monospace;
}
.mgrid-cell {
  width: 100%;
  min-width: 0;
  padding: .3rem .1rem;
  font: inherit;
  font-size: .8rem;
  text-align: center;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.mgrid-cell:hover { border-color: var(--muted); }
.mgrid-cell:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; }
@media (max-width: 640px) {
  .mgrid-head, .mgrid-row { grid-template-columns: 1fr; gap: .15rem; }
  .mgrid-head .mgrid-label { display: none; }   /* nur die Jahreszahlen zeigen */
  .mgrid-label { text-align: left; }
  .mgrid-cells { grid-template-columns: repeat(10, minmax(1.7rem, 1fr)); }
  .mgrid-head .mgrid-cells span { font-size: .55rem; }
}

/* ---------- Tag-Feld ---------- */
.tags-box {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: .35rem .4rem;
  background: var(--surface);
  cursor: text;
}
.tags-box:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  background: var(--accent-soft);
  color: var(--ink);
  border-radius: 3px;
  padding: .12rem .1rem .12rem .5rem;
  font-size: .82rem;
  white-space: nowrap;
}
.tag-chip button {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 .3rem;
}
.tag-chip button:hover { color: var(--danger); }
.tags-box .tags-input {
  flex: 1 1 7rem;
  min-width: 6rem;
  border: none;
  padding: .25rem;
  background: transparent;
}
.tags-box .tags-input:focus-visible { outline: none; }

/* ---------- Combobox (Typeahead für Relationen) ---------- */
.combo-box { position: relative; }
.combo-input { padding-right: 1.9rem; }          /* Platz für × */
.combo .combo-input { padding-right: 3.25rem; }  /* Platz für ↗ und × */
.combo-clear {
  position: absolute;
  top: 50%;
  right: .35rem;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  padding: .1rem .3rem;
  cursor: pointer;
}
.combo-clear:hover { color: var(--ink); }
.combo-list {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 3px);
  margin: 0;
  padding: .25rem 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: var(--pop-shadow);
  max-height: 13rem;
  overflow-y: auto;
}
.combo-list li {
  padding: .45rem .65rem;
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.combo-list li.active,
.combo-list li:hover { background: var(--accent-soft); }
.combo-list li.combo-empty {
  color: var(--muted);
  cursor: default;
}
.combo-list li.combo-empty:hover { background: none; }
.fld-full { grid-column: 1 / -1; }
@media (min-width: 560px) {
  .fld-s  { grid-column: span 1; max-width: 9rem; }
  .fld-xs { grid-column: span 1; max-width: 6rem; }
  .fld-l  { grid-column: span 1; }
}
@media (max-width: 559px) {
  .fields { grid-template-columns: 1fr; }
  .fld-full, .fld-s, .fld-xs, .fld-l { grid-column: 1 / -1; }
}

/* Feld-Gruppe: mehrere Felder in einer Zeile (Anrede/Name/Vorname, Land/PLZ/Ort) */
.fld-group {
  grid-column: 1 / -1;
  display: flex;
  gap: .3rem 1rem;
  flex-wrap: wrap;
  align-items: start;
}
.fld-group > .fld {
  flex: 1 1 9rem;
  min-width: 0;
  max-width: none;
  grid-column: auto;
}
.fld-group > .fld-xs { flex: 0 0 4.5rem; }
.fld-group > .fld-s  { flex: 0 0 8.5rem; }
@media (max-width: 559px) {
  .fld-group > .fld,
  .fld-group > .fld-xs,
  .fld-group > .fld-s { flex: 1 1 100%; }
}

input:focus-visible, textarea:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

/* ---------- Buttons ---------- */
.actions {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin-top: 1.4rem;
  max-width: 40rem;
}
.btn {
  font: inherit;
  font-size: .86rem;
  padding: .5rem .9rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ground);
  font-weight: 500;
}
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { background: transparent; }
/* Anlegen-Aktion vom Werkzeug-Set (Filter, Listen) abgesetzt */
.btn-new {
  margin-left: .35rem;
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 500;
}
.btn-new:hover { background: var(--accent); border-color: var(--accent); color: var(--ground); }
.btn-danger { color: var(--danger); border-color: var(--danger); margin-left: auto; }
.btn-danger:hover { background: var(--danger); color: var(--ground); }

.status {
  font-size: .8rem;
  color: var(--muted);
}
.status.ok    { color: var(--accent); }
.status.error { color: var(--danger); }

/* ---------- Related (Tab "Hunde" bei Züchter/Besitzer) ---------- */
.related { max-width: 40rem; }
.related[hidden] { display: none; }
.related-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.related-list li { font-size: .9rem; }
.related-empty { color: var(--muted); font-size: .88rem; margin: 0; }

/* ---------- Empty ---------- */
.empty { color: var(--muted); padding-top: 2rem; }
.linklike, .empty .linklike {
  font: inherit;
  color: var(--accent);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Filter ---------- */
.list-head #filter-btn[aria-pressed="true"],
.list-head #filter-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.filter-banner {
  display: flex;
  align-items: center;
  gap: .75rem 1rem;
  flex-wrap: wrap;
  padding: .7rem .95rem;
  background: var(--accent);
  color: #fff;
  border-bottom: 1px solid var(--rule);
}
.filter-banner[hidden] { display: none; }
.filter-banner .fb-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.filter-banner #fb-count {
  font-family: "IBM Plex Mono", monospace;
  font-size: .95rem;
  letter-spacing: .04em;
}
.filter-banner #fb-crit {
  font-size: .78rem;
  opacity: .92;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filter-banner .fb-actions { display: flex; gap: .4rem; flex: none; }
.filter-banner .btn {
  background: rgba(255, 255, 255, .14);
  border-color: rgba(255, 255, 255, .5);
  color: #fff;
}
.filter-banner .btn:hover { background: rgba(255, 255, 255, .26); border-color: #fff; }

.filter-panel[hidden] { display: none; }
.filter-title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: 1.3rem;
  margin: 0 0 1rem;
}
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem;
  margin-bottom: 1.3rem;
}
.filter-tab {
  font: inherit;
  font-size: .85rem;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: .4rem .7rem;
  cursor: pointer;
}
.filter-tab:hover { color: var(--ink); }
.filter-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.filter-tab:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
/* Reiter, der Filterkriterien enthält: Punkt-Markierung + Akzentfarbe */
.filter-tab.has-crit { color: var(--accent); font-weight: 600; }
.filter-tab.has-crit::after {
  content: "";
  display: inline-block;
  width: .4rem;
  height: .4rem;
  margin-left: .35rem;
  vertical-align: middle;
  border-radius: 50%;
  background: var(--accent);
}
.filter-section[hidden] { display: none; }
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .9rem 1rem;
  max-width: 40rem;
}
.filter-grid .fld-full { grid-column: 1 / -1; }
@media (max-width: 560px) { .filter-grid { grid-template-columns: 1fr; } }

.saved-filters { margin-top: 1.4rem; max-width: 40rem; }
.saved-head {
  font-family: "IBM Plex Mono", monospace;
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: .5rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--rule);
}
.saved-filters .saved-chip + .saved-chip { margin-top: .4rem; }
.saved-chip {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--rule);
  border-radius: 3px;
  overflow: hidden;
}
.saved-use {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  text-align: left;
  font: inherit;
  background: var(--surface-2);
  border: none;
  color: var(--ink);
  cursor: pointer;
  padding: .45rem .6rem;
}
.saved-use:hover { background: var(--accent-soft); }
.saved-name { font-size: .88rem; font-weight: 500; }
.saved-crit {
  font-size: .72rem;
  line-height: 1.35;
  color: var(--muted);
}
.saved-del {
  flex: none;
  font: inherit;
  font-size: .95rem;
  background: var(--surface-2);
  border: none;
  border-left: 1px solid var(--rule);
  color: var(--muted);
  cursor: pointer;
  padding: 0 .65rem;
}
.saved-del:hover { background: var(--danger); color: #fff; }

/* ---------- Inzuchtkoeffizient (berechnet) ---------- */
.inzucht-note {
  grid-column: 1 / -1;
  margin: -.2rem 0 .3rem;
  padding: .5rem .65rem;
  background: var(--surface-2);
  border-left: 3px solid var(--rule);
  border-radius: 2px;
  font-size: .82rem;
}
.inzucht-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .3rem .5rem; }
.inzucht-val { font-family: "IBM Plex Mono", monospace; font-size: .95rem; }
.inzucht-val.iz-ok      { color: var(--accent); }
.inzucht-val.iz-erhoeht { color: var(--warn); }
.inzucht-val.iz-mittel  { color: var(--danger); }
.inzucht-val.iz-hoch    { color: var(--danger); font-weight: 700; }
.iz-take { font-size: .78rem; }
.inzucht-sub { color: var(--muted); margin-top: .15rem; font-size: .76rem; }
.inzucht-ahnen { margin-top: .4rem; }
.inzucht-ahnen summary {
  cursor: pointer;
  color: var(--accent);
  font-size: .78rem;
}
.iz-ahn {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  padding: .18rem 0 .18rem .8rem;
  border-top: 1px solid var(--rule);
}
.iz-ahn:first-of-type { margin-top: .3rem; }
.iz-beitrag { font-family: "IBM Plex Mono", monospace; color: var(--muted); white-space: nowrap; }

/* ---------- Erbfehler-Träger (berechnet) ---------- */
.erbf-note {
  grid-column: 1 / -1;
  margin: -.2rem 0 .3rem;
  padding: .5rem .65rem;
  background: var(--surface-2);
  border-left: 3px solid var(--rule);
  border-radius: 2px;
  font-size: .82rem;
}
.erbf-label { font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: .3rem; }
.erbf-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .4rem; }
.erbf-val { color: var(--danger); }
.erbf-eigen { margin-top: .4rem; color: var(--muted); font-size: .78rem; }
.erbf-grund { padding: .18rem 0 .18rem .8rem; }
.erbf-liste { margin-top: .4rem; }
.erbf-liste summary { cursor: pointer; color: var(--accent); font-size: .78rem; }
.erbf-row {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  padding: .18rem 0 .18rem .8rem;
  border-top: 1px solid var(--rule);
}
.erbf-row:first-of-type { margin-top: .3rem; }
.erbf-code { color: var(--muted); white-space: nowrap; font-size: .78rem; }

/* schreibgeschütztes, berechnetes Feld */
.fld-ro input { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }

/* ---------- Stammbaum: Kopfzeile nur im Druck / PDF ---------- */
.ped-print-head { display: none; text-align: center; }
.ped-print-run {
  font-family: "IBM Plex Mono", monospace;
  font-size: .68rem;
  letter-spacing: .04em;
  color: var(--muted);
  padding-bottom: 1.5mm;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 3mm;
}
.ped-print-verein {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.05rem;
  color: var(--ink);
  margin-bottom: 1mm;
}
.ped-print-head strong {
  display: block;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: 1.25rem;
}
.ped-info {
  margin: .1rem 0 1rem;
  font-size: .85rem;
  color: var(--muted);
}

/* ---------- Listen / Auswertungen: Menü + Dialog ---------- */
.print-root { display: none; }

.menu-pop {
  position: fixed;
  z-index: 60;
  min-width: 15rem;
  max-width: 22rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
  padding: .3rem;
  max-height: 70vh;
  overflow-y: auto;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: .4rem .55rem;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  border-radius: 4px;
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-sep {
  padding: .5rem .55rem .2rem;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.menu-tmpl { display: flex; align-items: center; }
.menu-tmpl .menu-item { flex: 1; }
.menu-del {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: .2rem .5rem;
  border-radius: 4px;
}
.menu-del:hover { background: var(--warn-soft); color: var(--danger); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(20, 22, 18, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 1rem;
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface);
  border-radius: 8px;
  padding: 1.2rem 1.3rem 1.3rem;
  width: min(38rem, 100%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal h3 { margin: 0 0 .8rem; font-family: "Fraunces", Georgia, serif; }
.modal-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin: .4rem 0;
  font-size: .86rem;
}
.modal-row > input[type="text"], .modal-row > select { flex: 1; }
.modal-row > span:first-child, .modal-row { color: var(--ink); }
.modal-note { font-size: .78rem; color: var(--muted); margin: .3rem 0 .6rem; }
.modal-sub {
  margin: .9rem 0 .35rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 5px; overflow: hidden; }
.seg-btn {
  border: 0;
  background: var(--surface);
  color: var(--ink);
  padding: .35rem .7rem;
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
}
.seg-btn.on { background: var(--accent); color: #fff; }
.col-picker {
  border: 1px solid var(--rule);
  border-radius: 5px;
  max-height: 15rem;
  overflow-y: auto;
}
.col-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .25rem .5rem;
  border-bottom: 1px solid var(--rule);
  font-size: .84rem;
  color: var(--muted);
}
.col-row:last-child { border-bottom: 0; }
.col-row.on { color: var(--ink); background: var(--surface-2); }
.col-nm { flex: 1; }
.col-w {
  width: 3.4rem;
  padding: .15rem .3rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .78rem;
  text-align: right;
}
.col-w:disabled { opacity: .35; }
.col-mv {
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  width: 1.5rem;
  height: 1.4rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: .6rem;
  line-height: 1;
}
.col-mv:disabled { opacity: .3; cursor: default; }
.modal-hint { font-size: .72rem; color: var(--muted); }
.modal-foot { display: flex; gap: .5rem; margin-top: 1.1rem; flex-wrap: wrap; }

/* ---------- Datensicherung ---------- */
.backup-view { max-width: 62rem; }
.bk-sec-backup, .bk-sec-restore { max-width: 40rem; }
.bk-title { font-family: "Fraunces", Georgia, serif; margin: 0 0 .4rem; }
.bk-intro { color: var(--muted); font-size: .88rem; margin: 0 0 1.3rem; }

.bk-sec {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem 1.1rem 1.1rem;
  margin-bottom: 1.2rem;
}
.bk-sec-backup { border-top: 3px solid var(--accent); }
.bk-sec-restore { border-top: 3px solid var(--danger); background: var(--surface-2); }
.bk-sec-h {
  margin: 0 0 .2rem;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.05rem;
}
.bk-sec-desc { margin: 0 0 .9rem; font-size: .84rem; color: var(--muted); }

.bk-card {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  padding: .7rem .85rem;
  margin-bottom: 1rem;
  background: var(--surface-2);
}
.bk-card.due { border-left-color: var(--warn); background: var(--warn-soft); }
.bk-status-line { font-weight: 500; }
.bk-due-note { margin-top: .35rem; font-size: .85rem; color: var(--warn); }

.bk-actions { margin-bottom: 1rem; }

.bk-reminder {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
  padding-top: .9rem;
  border-top: 1px solid var(--rule);
}
.bk-rem-lbl { font-size: .88rem; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.bk-rem-lbl input { width: 4rem; }
.bk-rem-hint { font-size: .8rem; color: var(--muted); }
.bk-rem-hint.ok { color: var(--accent); }

.bk-restore-warn {
  font-size: .85rem;
  color: var(--danger);
  margin-bottom: .8rem;
}
.bk-restore {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
}
.bk-restore input[type="file"] { font-size: .82rem; max-width: 100%; }
.bk-check { display: flex; align-items: flex-start; gap: .4rem; font-size: .8rem; color: var(--muted); margin-top: .6rem; }

.bk-hist { font-size: .82rem; color: var(--muted); }
/* Verlauf als Liste (reflowt bei jeder Breite, Rahmen bleibt aussen) */
.bk-hist-list { list-style: none; margin: 0; padding: 0; }
.bk-hist-item {
  padding: .5rem 0;
  border-top: 1px solid var(--rule);
}
.bk-hist-item:first-child { border-top: 0; padding-top: 0; }
.bk-hi-head { color: var(--ink); font-weight: 500; }
.bk-hist-item.restore .bk-hi-head { color: var(--warn); }
.bk-hi-meta { margin-top: .15rem; overflow-wrap: anywhere; }

/* „Sicherung fällig"-Marker an Einstellungen-Tab und Datensicherung-Subtab */
.tab.needs-backup::after,
.subtab.needs-backup::after {
  content: "";
  display: inline-block;
  width: .42rem;
  height: .42rem;
  border-radius: 50%;
  background: var(--warn);
  margin-left: .35rem;
  vertical-align: middle;
}

/* ---------- Anmeldung / 2FA ---------- */
body.auth-open { overflow: hidden; }
.auth-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--ground);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 1rem 2rem;
  overflow-y: auto;
}
.auth-view[hidden] { display: none; }
.auth-card {
  width: min(24rem, 100%);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.6rem 1.5rem 1.7rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .12);
}
.auth-brand {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  letter-spacing: .12em;
  color: var(--accent);
}
.auth-h { margin: .1rem 0 1.1rem; font-size: 1.25rem; font-family: "Fraunces", Georgia, serif; }
.auth-row { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .7rem; font-size: .82rem; color: var(--muted); }
.auth-row[hidden] { display: none; }
.auth-row input, .auth-row select {
  padding: .5rem .55rem;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--ground);
  color: var(--ink);
  font: inherit;
}
.auth-check { display: flex; align-items: center; gap: .4rem; font-size: .85rem; margin: .2rem 0 .9rem; }
.auth-submit { width: 100%; margin-top: .4rem; }
.auth-msg { margin: .7rem 0 0; font-size: .84rem; color: var(--muted); }
.auth-msg.err { color: var(--danger); }
.auth-qr { display: flex; justify-content: center; margin: .8rem 0 .4rem; }
.auth-qr svg { width: 11rem; height: 11rem; }
.auth-secret {
  font-family: "IBM Plex Mono", monospace;
  font-size: .78rem;
  text-align: center;
  color: var(--muted);
  word-break: break-all;
  margin-bottom: .8rem;
}

/* Konto-Selbstverwaltung */
.auth-card:has(.konto-sec) { width: min(26rem, 100%); }
.konto-sec { border-top: 1px solid var(--rule); margin-top: 1.3rem; padding-top: 1rem; }
.konto-sec h2 {
  margin: 0 0 .7rem;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.konto-sec .auth-msg { margin: 0 0 .6rem; }
.konto-hint { font-size: .8rem; color: var(--muted); margin: .3rem 0 0; }
.konto-close { margin-top: 1.4rem; }

/* ---------- Topbar: Benutzer ---------- */
.topbar-user { display: flex; align-items: center; gap: .6rem; margin-left: auto; }
.topbar-user[hidden] { display: none; }
.tb-ident {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .1rem;
  line-height: 1.15;
  text-align: right;
  cursor: pointer;
  border-radius: 4px;
  padding: .1rem .3rem;
}
.tb-ident:hover { background: var(--surface-2); }
.tb-ident:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.tb-name { font-weight: 500; font-size: .85rem; }
.tb-rolle {
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.topbar-user .btn { padding: .25rem .6rem; font-size: .78rem; }
/* Handy: nur der (gekürzte) Name, weiter anklickbar für „Mein Konto" */
@media (max-width: 640px) {
  .tb-rolle { display: none; }
  .tb-name { max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Nur-Lese-Modus: Felder sind per readonly/disabled gesperrt (JS), Backend blockt
   zusätzlich. Hier nur die optische Dämpfung – Textfelder bleiben kopierbar. */
body.ro-modus #fields input:read-only,
body.ro-modus #fields textarea:read-only { background: var(--surface); opacity: .8; }
body.ro-modus #fields input:disabled,
body.ro-modus #fields select:disabled,
body.ro-modus #fields button:disabled { opacity: .55; pointer-events: none; }
body.ro-modus #fields .combo-clear:disabled { display: none; }

/* ---------- Benutzerverwaltung ---------- */
.admin-view { max-width: 52rem; }
.admin-view[hidden] { display: none; }
.bn-list { margin-top: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.bn-row {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: .6rem .8rem;
}
.bn-row.inaktiv { opacity: .55; }
.bn-head { font-size: .9rem; }
.bn-rolle { color: var(--accent); }
.bn-off { color: var(--danger); }
.bn-2fa, .bn-pwch { font-size: .72rem; color: var(--muted); }
.bn-actions { margin-top: .35rem; display: flex; gap: .9rem; flex-wrap: wrap; font-size: .82rem; }
.bn-form, .bn-new {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  margin-top: .6rem; padding-top: .6rem; border-top: 1px solid var(--rule);
}
.bn-new { border-top: 0; }
.bn-form input, .bn-form select { padding: .35rem .45rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--ground); color: var(--ink); font: inherit; }
.bn-check { display: flex; align-items: center; gap: .3rem; font-size: .85rem; }
.bn-pw {
  border: 1px solid var(--accent);
  background: var(--surface-2);
  border-radius: 6px;
  padding: .7rem .85rem;
  font-size: .84rem;
  margin-bottom: .6rem;
}
.bn-pw-code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.05rem;
  margin-top: .35rem;
  user-select: all;
}

/* ---------- Änderungsprotokoll ---------- */
.log-filter { display: flex; gap: .5rem; margin: 1rem 0 .6rem; flex-wrap: wrap; }
.log-filter select { padding: .35rem .5rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--ground); color: var(--ink); font: inherit; }
.log-list { display: flex; flex-direction: column; }
.log-item { padding: .45rem 0; border-top: 1px solid var(--rule); font-size: .85rem; }
.log-item:first-child { border-top: 0; }
.log-zeit { color: var(--muted); margin-right: .6rem; white-space: nowrap; }
.log-user { font-weight: 500; margin-right: .6rem; }
.log-akt {
  display: inline-block; font-size: .72rem; padding: .02rem .4rem;
  border-radius: 999px; border: 1px solid var(--rule); margin-right: .5rem;
}
.log-akt-delete { color: var(--danger); border-color: var(--danger); }
.log-akt-create { color: var(--accent); border-color: var(--accent); }
.log-akt-restore, .log-akt-rolle { color: var(--warn); border-color: var(--warn); }
.log-obj { color: var(--ink); }
.log-diff { color: var(--muted); font-size: .78rem; margin: .1rem 0 0 .3rem; overflow-wrap: anywhere; }

/* ---------- Handy: Übersicht ⇆ Detail als geschobene Vollbild-Screens ----------
   Ohne Auswahl sieht man die Übersicht; beim Anwählen eines Datensatzes schiebt
   sie nach links raus und die Detailsicht rein (Zurück per Button / Gerätetaste).
   Steht bewusst am Dateiende, damit die Overrides die Basisregeln gewinnen. */
@media (max-width: 720px) {
  .grid {
    display: flex;
    width: 200vw;
    transition: transform .28s ease;
  }
  .grid > .list-pane,
  .grid > .detail-pane { flex: 0 0 100vw; min-width: 0; }
  .grid.show-detail { transform: translateX(-100vw); }
  /* Ansichten ohne Übersichtsspalte (Einstellungen, Datensicherung …): ein Screen */
  .grid:has(> .list-pane[hidden]) { width: 100vw; transform: none; }
  .grid:has(> .list-pane[hidden]) > .detail-pane { flex-basis: 100vw; }
  .list-pane { border-right: none; }
  .detail-pane {
    border-top: none;
    padding-top: 0;                 /* Kopfzeile klebt bündig oben */
  }
  .detail-back { display: inline-flex; }
  /* Kopfzeile: „‹ Übersicht" links, ‹ › ganz rechts, Titel auf eigener Zeile */
  .detail-head {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--ground);
    margin: 0 calc(-1 * clamp(1rem, 3vw, 2rem)) 1rem;
    padding: .7rem clamp(1rem, 3vw, 2rem);
    row-gap: .35rem;
  }
  .detail-head .detail-nav { margin-left: auto; }
  .detail-head h2 { flex-basis: 100%; order: 1; }
  .detail-head .rec-meta { order: 2; margin-left: 0; }
}
@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  .grid { transition: none; }
}

/* ---------- Druck / PDF: nur den Stammbaum ausgeben ---------- */
@media print {
  @page { size: A4 portrait; margin: 10mm 10mm 14mm; }
  /* 5-Gen ist breit -> quer, falls der Browser benannte Seiten unterstützt */
  @page ped5 { size: A4 landscape; margin: 8mm; }
  /* Ausdruck immer hell, unabhängig vom OS-Theme */
  :root {
    --ground: #fff; --surface: #fff; --surface-2: #f3f3ec; --ink: #23281f;
    --muted: #555; --rule: #b9bab0; --accent: #3e5c3a;
    --warn: #8a6d1e; --warn-soft: #f4ecd8;
    --sex-male: #2c6e9b; --sex-female: #a8571e; --danger: #a8571e;
  }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { height: auto; display: block; overflow: visible; background: #fff; }
  .topbar, .tabs, .subtabs, .list-pane, .detail-head, .detail-tabs,
  .detail-nav, #form, #warnings, #empty, .ped-controls,
  .filter-banner, .filter-panel { display: none !important; }
  .grid { display: block; overflow: visible; grid-template-columns: 1fr; }
  .detail-pane { display: block; overflow: visible; padding: 0; }
  .related { display: block !important; max-width: none; }
  .ped-print-head { display: block; margin-bottom: 2mm; }
  .ped-info { text-align: center; color: #333; font-size: .78rem; margin: 0 0 4mm; }
  .pedigree-scroll { overflow: visible; padding: 0; }
  .pedigree {
    min-width: 0;
    width: 100%;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    /* Zeilen wachsen mit dem Inhalt -> nichts wird abgeschnitten */
    grid-template-rows: repeat(var(--rows), minmax(var(--rowh), auto));
    gap: 2px 4px;
  }
  .ped-box { padding: .12rem .3rem; overflow: visible; break-inside: avoid; }
  .ped-name { font-weight: 500; white-space: normal; overflow-wrap: anywhere; }
  .ped-zwinger, .ped-meta { white-space: normal; overflow-wrap: anywhere; }
  .ped-common-badge { font-size: .5rem; min-width: .8rem; height: .8rem; line-height: .8rem; }
  .ped-legend { margin-top: 5mm; font-size: .7rem; break-inside: avoid; }
  .ped-legend-item.linklike { color: var(--ink); text-decoration: none; }

  /* 3 Generationen: Name + Zwinger + StB-Nr. */
  .pedigree:not(.pedigree-compact) {
    --rowh: 2.9rem !important;
    font-size: .74rem;
    line-height: 1.15;
  }
  .pedigree:not(.pedigree-compact) .ped-zwinger { font-size: .68rem; }
  .pedigree:not(.pedigree-compact) .ped-meta { font-size: .62rem; }

  /* 5 Generationen: nahe Generationen haben Platz und zeigen mehr,
     nur die beiden äussersten (engsten) werden reduziert */
  .detail-pane:has(.pedigree-compact) { page: ped5; }
  .pedigree-compact { --rowh: 1.05rem !important; font-size: .62rem; gap: 1px 3px; }
  .pedigree-compact .ped-box { padding: .05rem .28rem; }
  .pedigree-compact .ped-name { line-height: 1.1; white-space: normal; }
  .pedigree-compact .ped-zwinger { display: block; font-size: .55rem; line-height: 1.1; }
  .pedigree-compact .ped-meta { font-size: .52rem; line-height: 1.1; }
  /* Gen 4 (Spalte 5): Name + StB-Nr., ohne Zwinger */
  .pedigree-compact .ped-box[data-col="5"] .ped-zwinger { display: none; }
  /* Gen 5 (Spalte 6): nur der Name, einzeilig mit … */
  .pedigree-compact .ped-box[data-col="6"] { overflow: hidden; justify-content: center; }
  .pedigree-compact .ped-box[data-col="6"] .ped-zwinger,
  .pedigree-compact .ped-box[data-col="6"] .ped-meta { display: none; }
  .pedigree-compact .ped-box[data-col="6"] .ped-name {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .pedigree-compact .ped-common-badge { min-width: .7rem; height: .7rem; line-height: .7rem; font-size: .45rem; }

  /* ---- Listen-Druck & Stammblatt: nur #print-root ausgeben ----
     Die Seitengrösse/-ausrichtung setzt doPrint() über ein eingeschobenes
     <style> mit einfachem @page (kein `page:` auf #print-root – das würde in
     Chromium die Wiederholung der Kopfzeile auf Folgeseiten verhindern). */
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block !important; }

  #print-root { font-size: 10pt; color: #1c1c1c; }
  .print-head {
    display: grid;
    grid-template-columns: 1fr 1.4fr 1fr;
    column-gap: 4mm;
    align-items: baseline;
    border-bottom: 1.5px solid #333;
    padding-bottom: 3mm;
    margin-bottom: 4mm;
  }
  .print-head strong {
    text-align: center;
    font-family: "Fraunces", Georgia, serif;
    font-size: 14pt;
    line-height: 1.15;
  }
  .print-head > span:last-child { text-align: right; }
  .print-head .print-sub {
    grid-column: 1 / -1;
    margin-top: 1.5mm;
    font-size: 8pt;
    color: #555;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8.5pt;
  }
  .print-table th, .print-table td {
    border: 1px solid #bbb;
    padding: 1.2mm 1.8mm;
    text-align: left;
    vertical-align: top;
  }
  .print-table th { background: #eee; font-weight: 600; }
  .print-table tr { break-inside: avoid; }
  /* Kopfzeile auf jeder Druckseite wiederholen (nur Druck, nicht Excel) */
  .print-table thead { display: table-header-group; }
  .print-table tfoot { display: table-footer-group; }

  /* Listen-Tabelle: border-collapse SEPARATE – WebKit/Safari wiederholt die
     <thead>-Zeile nur bei getrennten Rahmen; Chrome ist beides recht. Rahmen
     daher je Zelle rechts+unten, Rahmen oben+links an der Tabelle. */
  .print-list {
    break-inside: auto;
    border-collapse: separate;
    border-spacing: 0;
    border-top: 1px solid #bbb;
    border-left: 1px solid #bbb;
  }
  .print-list th, .print-list td {
    border: 0;
    border-right: 1px solid #bbb;
    border-bottom: 1px solid #bbb;
  }
  .print-list thead th { border-bottom: 1.5px solid #999; }
  .print-list.has-widths { table-layout: fixed; }
  .print-list.has-widths td { overflow-wrap: anywhere; }

  /* Stammblatt */
  .stammblatt { line-height: 1.3; }
  .sb-band {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border: 1.5px solid #333;
    padding: 2mm 3mm;
    margin-bottom: 3mm;
  }
  .sb-band strong { font-size: 13pt; font-family: "Fraunces", Georgia, serif; }
  .sb-band span { font-size: 12pt; }
  .sb-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border: 1px solid #bbb;
    border-width: 1px 0 0 1px;
    margin-bottom: 3mm;
  }
  .sb-addr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 1px solid #bbb;
    border-width: 1px 0 0 1px;
    margin-bottom: 3mm;
  }
  .sb-field {
    background: #fff;
    padding: 1.2mm 2mm;
    font-size: 8.5pt;
    border: 1px solid #bbb;
    border-width: 0 1px 1px 0;
  }
  .sb-lab { display: block; font-size: 6.8pt; text-transform: uppercase; letter-spacing: .03em; color: #666; }
  .sb-val { display: block; }
  .sb-mtable {
    width: 100%;
    border-collapse: collapse;
    font-size: 8pt;
    margin-bottom: 3mm;
  }
  .sb-mtable td, .sb-mtable th { border: 1px solid #bbb; padding: 1mm 1.5mm; text-align: center; }
  .sb-mtable thead td { font-weight: 600; white-space: nowrap; }
  .sb-mtable tbody td:first-child, .sb-mtable thead td:first-child {
    text-align: left; font-weight: 600; white-space: nowrap;
  }
  .sb-ped { margin-bottom: 3mm; break-inside: avoid; }
  .sb-ped-title {
    font-weight: 600;
    font-family: "Fraunces", Georgia, serif;
    font-size: 10pt;
    margin: 2mm 0 1.5mm;
    /* Überschrift bleibt bei dem, was folgt (kein verwaister Titel am Seitenende) */
    break-after: avoid;
  }
  /* Stammblatt: dieselbe Ahnentafel-Darstellung wie im Reiter „Stammbaum",
     nur kompakter, damit sie neben dem Datenblatt Platz hat */
  #print-root .stammblatt .pedigree {
    --rowh: 1.5rem !important;
    font-size: .62rem;
    line-height: 1.12;
    gap: 1px 3px;
    break-inside: avoid;
  }
  #print-root .stammblatt .ped-box { padding: .08rem .3rem; }
  #print-root .stammblatt .ped-zwinger { display: block; font-size: .56rem; }
  #print-root .stammblatt .ped-meta { font-size: .54rem; }
  #print-root .stammblatt .ped-common-badge {
    min-width: .7rem; height: .7rem; line-height: .7rem; font-size: .45rem;
  }
  #print-root .stammblatt .ped-legend { margin-top: 2mm; font-size: .6rem; }

  /* direkte Nachkommen: Kopfzeile auf jeder Seite, kein Umbruch mitten in
     einer Zeile.  border-collapse: separate, weil WebKit die <thead>-Zeile
     nur bei getrennten Rahmen wiederholt (wie bei der Listen-Tabelle). */
  .sb-kinder {
    margin-top: 1.5mm;
    border-collapse: separate;
    border-spacing: 0;
    border-top: 1px solid #bbb;
    border-left: 1px solid #bbb;
  }
  .sb-kinder th, .sb-kinder td {
    border: 0;
    border-right: 1px solid #bbb;
    border-bottom: 1px solid #bbb;
  }
  .sb-kinder thead { display: table-header-group; }
  .sb-kinder thead th { border-bottom: 1.5px solid #999; }
  .sb-kinder tr { break-inside: avoid; page-break-inside: avoid; }
}
