/* 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-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin: 0.4rem 0 0;
}

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

.stammbaum-canvas {
  height: clamp(18rem, 62dvh, 46rem);
  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;
}

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

.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;
}

.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.68rem;
  padding: 0.1rem 0.45rem;
  border-radius: 1rem;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.pedigree-card__expand {
  flex: none;
  margin-left: auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--color-accent);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
}

.pedigree-card__expand:hover {
  background: var(--color-accent);
  color: #fff;
}

/* ── 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;
}
