.tree-app {
  --gap: 18px;
  --card-w: 168px;
  --card-h: 76px;
  --row-gap: 88px;
  --text: #1f2a36;
  --muted: #6b7c8f;
  --bg: #fafbfc;
  --line: #b6c4d2;
  --line-strong: #6b8aa8;
  color: var(--text);
  background: var(--bg);
  padding: 16px;
  /* Default sizing is "fits the viewport from here down". sizeTreeApp()
     on load + resize replaces this with the exact remaining viewport
     height so the bottom scrollbar lands inside the visible area. */
  height: calc(100vh - 7rem - 1px);
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;       /* tree-wrap is the scroll container */
}

.tree-app h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 600;
}
.tree-app .subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 16px;
}

.tree-app .toolbar {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid #e3e8ee;
  border-radius: 8px;
}
.tree-app .toolbar > * { font-size: 13px; }

.tree-app .lang-toggle {
  display: inline-flex;
  border: 1px solid #d6dee6;
  border-radius: 6px;
  overflow: hidden;
}
.tree-app .lang-toggle button {
  padding: 6px 12px;
  background: #fff;
  border: 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  border-right: 1px solid #d6dee6;
}
.tree-app .lang-toggle button:last-child { border-right: 0; }
/* Source-layer toggle is only meaningful in the Source view. */
.tree-app .chart-mode-toggle { display: none; }
.tree-app[data-view="chart"] .chart-mode-toggle { display: inline-flex; }
.tree-app .lang-toggle button.active {
  background: var(--line-strong);
  color: #fff;
}


.tree-app .toolbar input[type=search] {
  padding: 6px 10px;
  border: 1px solid #d6dee6;
  border-radius: 6px;
  min-width: 200px;
  font-size: 13px;
}

.tree-app .toolbar button.btn {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #d6dee6;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.tree-app .toolbar button.btn:hover { background: #f0f4f8; }

.tree-app .legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.tree-app .legend .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #fff;
  border: 1px solid #e3e8ee;
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
}
.tree-app .legend .chip .swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}
.tree-app .legend .chip.dim { opacity: 0.35; }

.tree-app .tree-wrap {
  position: relative;
  /* x-scroll exists for programmatic scrollLeft; native h-bar is invisible
     in this layout (Chromium clipping quirk) so we render a custom one. */
  overflow-x: auto;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e3e8ee;
  border-radius: 8px;
  padding: 28px 20px;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  scrollbar-width: auto;
}
.tree-app .tree-wrap::-webkit-scrollbar         { width: 14px; height: 14px; }
.tree-app .tree-wrap::-webkit-scrollbar-track   { background: #eef2f6; }
.tree-app .tree-wrap::-webkit-scrollbar-thumb   { background: #94a2b1; border-radius: 7px; border: 3px solid #eef2f6; }
.tree-app .tree-wrap::-webkit-scrollbar-thumb:hover { background: #6b7c8f; }
.tree-app .tree-wrap::-webkit-scrollbar-corner  { background: #eef2f6; }

/* Always-visible custom horizontal scrollbar. Position: fixed bypasses any
   parent overflow:hidden (the javaxt-express panel between .content and
   us clips its own children, so a sibling-of-wrap hbar disappears). JS
   keeps left/top/width in sync with the tree-wrap's bounding box. */
.hbar {
  position: fixed;
  height: 14px;
  background: #eef2f6;
  border: 1px solid #d6dee6;
  border-radius: 7px;
  cursor: pointer;
  z-index: 50;
}
.hbar .hbar-thumb {
  position: absolute;
  top: 1px; bottom: 1px;
  min-width: 30px;
  background: #94a2b1;
  border-radius: 5px;
  cursor: grab;
}
.hbar:hover .hbar-thumb     { background: #6b7c8f; }
.hbar.dragging              { cursor: grabbing; }
.hbar.dragging .hbar-thumb  { cursor: grabbing; background: #4a5a6a; }
.hbar.hidden                { display: none; }
/* Chart view replaces native scrolling with pan/zoom transform. */
.tree-app .tree-wrap.pan-zoom {
  overflow: hidden;
  padding: 0;
  cursor: grab;
  user-select: none;
}
.tree-app .tree-wrap.pan-zoom.dragging { cursor: grabbing; }
.tree-app .tree-canvas {
  position: relative;
  margin: 0 auto;
}
/* In pan-zoom mode the canvas is positioned absolutely and transformed. */
.tree-app .tree-wrap.pan-zoom .tree-canvas {
  position: absolute;
  left: 0; top: 0;
  margin: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.tree-app svg.lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.tree-app svg.lines path {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.5;
}
.tree-app svg.lines path.spouse { stroke: var(--line-strong); stroke-dasharray: 4 3; }

.tree-app .person {
  position: absolute;
  width: var(--card-w);
  min-height: var(--card-h);
  background: #fff;
  border: 1px solid #d6dee6;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  cursor: pointer;
  overflow: hidden;
  transition: transform 120ms, box-shadow 120ms, opacity 200ms;
  z-index: 1;
  box-sizing: border-box;
}
.tree-app .person:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.tree-app .person.selected {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 2px rgba(107,138,168,0.3);
}
/* Dim states (branch filter + pedigree highlight). We apply opacity to the
   card's *children*, not the card itself, because `opacity:0.25` on the
   .person container would also fade its white background and let the SVG
   spouse lines below bleed through. Container border is softened instead. */
.tree-app .person.dim,
.tree-app .person.pedigree-dim {
  border-color: #ebeff3;
  box-shadow: none;
}
.tree-app .person.dim > *,
.tree-app .person.pedigree-dim > * {
  opacity: 0.25;
  transition: opacity 200ms;
}
.tree-app .person.search-hit {
  border-color: #d99000;
  box-shadow: 0 0 0 2px rgba(217,144,0,0.35);
}
.tree-app .person .branch-bar {
  height: 4px;
  width: 100%;
}
.tree-app .person .body {
  padding: 7px 10px 8px;
}
.tree-app .person .name {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.25;
  color: var(--text);
}
.tree-app .person.cyrillic .name { font-family: "Segoe UI", "PT Sans", system-ui, sans-serif; }
.tree-app .person .dates {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}
.tree-app .person .src {
  display: flex;
  gap: 3px;
  margin-top: 5px;
  font-size: 9px;
  color: var(--muted);
}
.tree-app .person .src .badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 8px;
  background: #eef2f6;
  color: var(--muted);
}
.tree-app .person .src .badge.doc { background: #e7f1e9; color: #3a7848; }
.tree-app .person .src .badge.img { background: #e7eef7; color: #3a5878; }
.tree-app .person .src .badge.lo  { background: #fdeee2; color: #a85d23; }

.tree-app .gender-marker {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 10px;
  color: var(--muted);
}

/* Bio side panel */
.tree-app .bio-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 380px;
  max-width: 90vw;
  background: #fff;
  border-left: 1px solid #d6dee6;
  box-shadow: -4px 0 16px rgba(0,0,0,0.08);
  transform: translateX(100%);
  transition: transform 200ms;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.tree-app .bio-panel.open { transform: translateX(0); }
.tree-app .bio-panel header {
  padding: 14px 16px;
  border-bottom: 1px solid #e3e8ee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tree-app .bio-panel header .branch-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 8px;
  color: #fff;
  font-weight: 500;
}
.tree-app .bio-panel button.close {
  background: transparent;
  border: 0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}
.tree-app .bio-panel .content {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}
.tree-app .bio-panel .name-block .name {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 2px;
}
.tree-app .bio-panel .name-block .alt {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 2px;
}
.tree-app .bio-panel .meta {
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.5;
}
.tree-app .bio-panel .meta dt {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 10px;
}
.tree-app .bio-panel .meta dd {
  margin: 2px 0 0;
}
.tree-app .bio-panel .relations {
  margin-top: 16px;
  font-size: 13px;
}
.tree-app .bio-panel .relations h4 {
  margin: 12px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
.tree-app .bio-panel .relations a {
  color: var(--line-strong);
  text-decoration: none;
  cursor: pointer;
}
.tree-app .bio-panel .relations a:hover { text-decoration: underline; }
.tree-app .bio-panel .src-info {
  margin-top: 16px;
  padding: 10px 12px;
  background: #f6f9fc;
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
}

.tree-app .bio-panel .branch-link {
  margin-top: 16px;
  font-size: 13px;
}
.tree-app .bio-panel .branch-link a {
  color: var(--line-strong);
  text-decoration: none;
  font-weight: 500;
}
.tree-app .bio-panel .branch-link a:hover { text-decoration: underline; }

.tree-app .empty-state {
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

/* Hybrid view: small hollow circle at each spouse-line midpoint where
   children descend from. Mirrors the Chart view's junction circles. */
.tree-app .hybrid-junction {
  position: absolute;
  box-sizing: border-box;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid var(--line-strong);
  transform: translate(-50%, -50%);
  z-index: 2;
  pointer-events: none;
}

/* Chart skeleton view: small square markers + diagonal connectors. */
.tree-app .skel-marker {
  position: absolute;
  box-sizing: border-box;
  cursor: pointer;
  z-index: 2;
}
.tree-app .skel-marker.filled {
  background: #1f2a36;
  border: 1px solid #0d1620;
}
.tree-app .skel-marker.hollow {
  background: transparent;
  border: 1.5px solid #1f2a36;
}
.tree-app .skel-marker:hover {
  box-shadow: 0 0 0 2px rgba(217,144,0,0.55);
}
/* Topology mismatch: a connected node pair that v14.json says aren't related. */
.tree-app .skel-marker.suspect {
  box-shadow: 0 0 0 3px rgba(220,50,50,0.65);
}
/* Detected on the chart but not matched to any v14 person yet. */
.tree-app .skel-marker.unassigned {
  opacity: 0.45;
  border-color: #a85d23;
}
/* Junction circle (line anchor — like the hollow dots in the pptx). */
.tree-app .skel-junction {
  position: absolute;
  box-sizing: border-box;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid #4a5a6a;
  transform: translate(-50%, -50%);
  z-index: 2;
  pointer-events: none;
}
.tree-app .skel-label {
  position: absolute;
  font-size: 10px;
  line-height: 1.1;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
  background: rgba(255,255,255,0.85);
  padding: 1px 3px;
  border-radius: 3px;
  z-index: 3;
}
.tree-app .skel-label.unmatched {
  color: #a85d23;
  background: rgba(253,238,226,0.85);
}
.tree-app svg.skel-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.tree-app svg.skel-lines line {
  stroke: #4a5a6a;
  stroke-width: 1.2;
  stroke-linecap: round;
}
/* Source-view diagnostic readout — pinned to the bottom-right of the wrap so
   it stays put while the canvas pans/zooms underneath it. Semi-transparent
   so the chart shows through. */
.tree-app .source-stats {
  position: absolute;
  right: 10px;
  bottom: 50px;
  padding: 5px 9px;
  background: rgba(255,255,255,0.82);
  border: 1px solid #d6dee6;
  border-radius: 4px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
  pointer-events: none;
  z-index: 10;
  max-width: 60%;
}

/* ----- Source-view underlay -----------------------------------------------
   Original handwritten chart image, positioned at the same (padding,padding)
   origin as the skeleton's coordinate system and sized to chart_w × chart_h
   scaled by the wireframe's SCALE so every marker lines up with its pencil
   stroke. The three .mode-* classes on .tree-canvas switch which layer(s)
   are visible — toggling is pure CSS so pan/zoom state is preserved. */
.tree-app .chart-underlay {
  position: absolute;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  z-index: 0;
}
.tree-app .tree-canvas.mode-skeleton .chart-underlay { display: none; }
.tree-app .tree-canvas.mode-image .skel-marker,
.tree-app .tree-canvas.mode-image .skel-label,
.tree-app .tree-canvas.mode-image .skel-junction,
.tree-app .tree-canvas.mode-image svg.skel-lines { display: none; }
/* Overlay: image + skeleton drawn in red, no labels. */
.tree-app .tree-canvas.mode-overlay .skel-label { display: none; }
.tree-app .tree-canvas.mode-overlay .skel-marker.filled {
  background: #e0241b;
  border-color: #b01a13;
}
.tree-app .tree-canvas.mode-overlay .skel-marker.hollow {
  background: transparent;
  border-color: #e0241b;
}
.tree-app .tree-canvas.mode-overlay .skel-marker.unassigned {
  opacity: 0.6;
  border-color: #e0241b;
}
.tree-app .tree-canvas.mode-overlay .skel-junction {
  background: #e0241b;
  border-color: #b01a13;
}
.tree-app .tree-canvas.mode-overlay svg.skel-lines line {
  stroke: #e0241b;
  stroke-width: 1.5;
}

@media (max-width: 720px) {
  .tree-app .bio-panel { width: 100%; }
}
