/* FEAT-4: Stammbaum — Bildschirm- und Druckstile.
   Bewusst eigene Datei statt index.css: index.css wird parallel von
   FEAT-1/2/5 bearbeitet (geteilter Arbeitsbaum), und die Druckregeln
   bleiben hier gekapselt. */

/* ── Werkzeugleiste ───────────────────────────────────────────── */

.stammbaum-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 0.75rem 0 0.5rem;
}

.stammbaum-toolbar__spacer {
  flex: 1;
}

.stammbaum-zoombtn {
  min-width: 44px;
  padding: 0.5rem 0.6rem;
  font-size: 1.1rem;
  line-height: 1;
}

.stammbaum-inzucht {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.stammbaum-inzucht b {
  color: var(--color-text);
}

.stammbaum-hints {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 1rem;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

/* ── Würfe-Panel + Layout (STAMMBAUM-LITTERS) ────────────────── */

.stammbaum-layout {
  display: flex;
  align-items: stretch;
  gap: 0;
}

/* Desktop: Würfe-Panel links vom Baum. */
.stammbaum-litters-panel {
  flex: none;
  width: 148px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem 0.5rem 0;
  border-right: 1px solid var(--color-border);
  margin-right: 0;
}

.stammbaum-litters-panel__title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.stammbaum-litters-panel__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow-y: auto;
  max-height: calc(clamp(18rem, 62dvh, 46rem) - 3rem);
}

.stammbaum-litters-panel__link {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.3rem 0.45rem;
  border-radius: 0.4rem;
  text-decoration: none;
  color: inherit;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-size: 0.8rem;
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.stammbaum-litters-panel__link:hover {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.stammbaum-litters-panel__name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stammbaum-litters-panel__born {
  color: var(--color-text-muted);
  font-size: 0.72rem;
}

/* Mobil (≤520px): Panel als kompakter horizontaler Streifen ÜBER dem Baum. */
@media (max-width: 520px) {
  .stammbaum-layout {
    flex-direction: column;
  }

  .stammbaum-litters-panel {
    width: auto;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    overflow-x: auto;
  }

  .stammbaum-litters-panel__title {
    flex: none;
    white-space: nowrap;
  }

  .stammbaum-litters-panel__list {
    flex-direction: row;
    flex-wrap: nowrap;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0.4rem;
  }

  .stammbaum-litters-panel__link {
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
  }

  .stammbaum-litters-panel__born {
    color: var(--color-text-muted);
  }

  /* Canvas behält explizite Höhe in column-Richtung. */
  .stammbaum-canvas {
    flex: 0 0 auto;
  }
}

/* ── Zeichenfläche ────────────────────────────────────────────── */

.stammbaum-canvas {
  flex: 1 1 auto;
  min-width: 0;
  height: clamp(18rem, 72dvh, 58rem);
  border: 1px solid var(--color-border);
  border-radius: 0.6rem;
  background:
    radial-gradient(var(--color-border) 1px, transparent 1px) 0 0 / 22px 22px,
    var(--color-surface);
  overflow: hidden;
  /* Pinch/Pan gehören d3-zoom, nicht dem Browser-Scrolling. */
  touch-action: none;
}

.stammbaum-canvas .rd3t-tree-container {
  width: 100%;
  height: 100%;
}

.stammbaum-canvas .rd3t-link {
  stroke: var(--color-border);
  stroke-width: 1.5;
}

/* ── Ahnenkarten (foreignObject-HTML) ─────────────────────────── */

.pedigree-card {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.6rem;
  box-shadow: 0 1px 2px rgb(59 48 38 / 10%);
  overflow: hidden;
  cursor: pointer;
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--color-text);
}

.pedigree-card:hover:not(.pedigree-card--root):not(.pedigree-card--unknown) {
  background: var(--color-accent-soft);
}

.pedigree-card--root {
  border: 2px solid var(--color-accent);
  cursor: default;
}

.pedigree-card--unknown {
  justify-content: center;
  border-style: dashed;
  background: transparent;
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 0.85rem;
  cursor: default;
}

/* Verweis-Knoten der Geschwister-Verpaarung: Vater & Mutter aus demselben
   Wurf — der Vorfahren-Ast verweist auf die Vaterlinie statt ihn zu doppeln. */
.pedigree-card--sibling {
  border-style: dashed;
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
  cursor: default;
}

.pedigree-card--sibling__icon {
  flex: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--color-accent);
}

.pedigree-card--sibling__body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.pedigree-card--sibling__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pedigree-card--sibling__hint {
  font-size: 0.72rem;
  font-style: italic;
  color: var(--color-text-muted);
}

.pedigree-card__photo {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--color-accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.pedigree-card__avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.pedigree-card__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.pedigree-card__name {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.pedigree-card__nametext {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
  text-decoration: none;
}

.pedigree-card__nametext:hover {
  text-decoration: underline;
}

.pedigree-card__sex--male {
  color: #3a6ea5;
}

.pedigree-card__sex--female {
  color: #b5527d;
}

.pedigree-card__sex--unknown {
  color: var(--color-text-muted);
}

.pedigree-chip {
  align-self: flex-start;
  max-width: 100%;
  font-size: 0.62rem;
  padding: 0.1rem 0.45rem;
  border-radius: 1rem;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
  line-height: 1.3;
}

.pedigree-card__year {
  font-size: 0.72rem;
  color: var(--color-text-muted);
}

.pedigree-card__expand {
  flex: none;
  margin-left: auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: var(--color-accent);
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 5px rgb(0 0 0 / 28%);
}

.pedigree-card__expand:hover,
.pedigree-card__expand:focus-visible {
  opacity: 0.82;
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ── Druckansicht (Ahnentafel als CSS-Grid, Hunde-Zertifikat-Optik) ──
   Am Bildschirm unsichtbar; @media print blendet App-Chrome und die
   interaktive Ansicht aus und zeigt stattdessen die Tafel.
   (:has-Scoping, damit der Druck ANDERER Seiten unberührt bleibt.) */

.stammbaum-print {
  display: none;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  body:has(.stammbaum-print) .app-header,
  body:has(.stammbaum-print) .app-nav,
  body:has(.stammbaum-print) .stammbaum-screen {
    display: none !important;
  }

  .stammbaum-print {
    display: flex;
    flex-direction: column;
    height: 100%;
    color: #000;
  }
}

.stammbaum-print__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4mm;
  border-bottom: 2pt solid #333;
  padding-bottom: 2mm;
  margin-bottom: 3mm;
}

.stammbaum-print__head h1 {
  font-size: 16pt;
  margin: 0;
}

.stammbaum-print__meta {
  font-size: 9pt;
  color: #444;
  margin: 0;
}

.stammbaum-print__grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: auto repeat(16, minmax(0, 1fr));
  gap: 1.5mm;
  min-height: 0;
}

.stammbaum-print__gen {
  font-size: 8pt;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
  align-self: end;
  padding-bottom: 0.5mm;
}

.stammbaum-print__cell {
  border: 0.5pt solid #999;
  border-radius: 1mm;
  padding: 1mm 2mm;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.5mm;
  font-size: 9pt;
  break-inside: avoid;
}

/* Hintere Generationen: kleinere Schrift, damit 16 Zellen passen. */
.stammbaum-print__cell--g3 {
  font-size: 8pt;
}

.stammbaum-print__cell--g4 {
  font-size: 7pt;
  padding: 0.5mm 1mm;
}

.stammbaum-print__cell--empty {
  border-style: dashed;
  border-color: #ccc;
}

.stammbaum-print__cell--unknown {
  color: #888;
  font-style: italic;
}

.stammbaum-print__name {
  font-weight: 600;
}

.stammbaum-print__sub {
  font-size: 0.85em;
  color: #444;
}

.stammbaum-print__geno {
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.8em;
  color: #555;
}

/* FEEDBACK: Rechtsklick-Kontextmenü auf einer Ahnenkarte. */
.stammbaum-context-menu {
  position: fixed;
  z-index: 150;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  min-width: 11rem;
  background: var(--color-bg, #fff);
  border: 1px solid var(--color-border, #ddd);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(43, 33, 25, 0.22);
}

.stammbaum-context-menu__item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  font-size: 0.9rem;
  color: var(--color-text);
  padding: 0.5rem 0.7rem;
  border-radius: 5px;
  cursor: pointer;
}

.stammbaum-context-menu__item:hover,
.stammbaum-context-menu__item:focus-visible {
  background: var(--color-accent, #2563eb);
  color: #fff;
  outline: none;
}
