/* Family tree: generations as rows, people as cards, partners side by side, links drawn by one SVG.
   One column = --col-w, one row = --row-h; apps/tree/layout.py computes the same units. Tokens only. */
.tree-page { --col-w: 188px; --row-h: 136px; --card-h: 88px; --partner-gap: 20px; }
@media (min-width: 1024px) { .tree-page { --col-w: 240px; } }
.tree-toggle { display: flex; gap: var(--space-2); }
.tree-toggle .btn[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* Wide screens show the tree; phones show the list. ?view= always wins. */
.tree-section--list { display: none; }
@media (max-width: 479px) {
  .tree-section--tree { display: none; }
  .tree-section--list { display: block; }
}
.tree-page.tree-page--tree .tree-section--tree { display: block; }
.tree-page.tree-page--tree .tree-section--list { display: none; }
.tree-page.tree-page--list .tree-section--tree { display: none; }
.tree-page.tree-page--list .tree-section--list { display: block; }

/* The tree scrolls inside its own box; the page never scrolls sideways. */
.tree-scroll { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: var(--space-5) var(--space-3); border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--card-line); box-shadow: var(--shadow); }
.tree-canvas { --cols: 1; --rows: 1; position: relative; width: calc(var(--cols) * var(--col-w)); height: calc(var(--rows) * var(--row-h)); margin: 0 auto; }
.tree-links { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.tree-links path { fill: none; stroke: var(--line-strong); stroke-width: 2; }
.tree-row { display: grid; grid-template-columns: repeat(var(--cols), var(--col-w)); height: var(--row-h); position: relative; }
.tree-unit { display: flex; align-items: flex-start; justify-content: center; height: var(--card-h); padding: 0 var(--space-1); }
.tree-unit--partners { gap: var(--partner-gap); }
.tree-unit--partners .tree-person:not(:first-child)::before { content: ""; position: absolute; left: calc(var(--partner-gap) * -1 - 1px); top: 50%; width: calc(var(--partner-gap) + 2px); border-top: 2px solid var(--line-strong); }
.tree-person { position: relative; flex: 1 1 0; min-width: 0; height: var(--card-h); display: flex; align-items: center; gap: var(--space-1); padding: var(--space-2) var(--space-1) var(--space-2) var(--space-2); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.tree-person--memory { border-style: dashed; }
.tree-person__main { flex: 1; display: flex; align-items: center; gap: var(--space-2); min-width: 0; color: var(--text); text-decoration: none; min-height: var(--tap); }
.tree-person__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
/* Names wrap onto a second line instead of being cut; the menu sits beside them, never on top */
.tree-person__name { font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.tree-person__years { font-size: var(--step-small); }
.tree-person__memory { font-size: var(--step-small); color: var(--muted); }

/* The "..." menu */
.tree-menu { position: relative; flex: none; align-self: flex-start; }
.tree-menu__button { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; min-height: var(--tap); padding: 0 var(--space-2); border-radius: var(--radius-sm); cursor: pointer; list-style: none; color: var(--muted); font-weight: 700; }
.tree-menu__button::-webkit-details-marker { display: none; }
.tree-menu[open] .tree-menu__button { background: var(--accent-soft); color: var(--accent-strong); }
.tree-menu__list { position: absolute; z-index: 5; right: 0; top: 100%; min-width: 11rem; padding: var(--space-1); border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-pop); }
.tree-menu__list a { display: flex; align-items: center; min-height: var(--tap); padding: 0 var(--space-3); color: var(--text); text-decoration: none; border-radius: var(--radius-sm); white-space: nowrap; }
.tree-menu__list a:hover { background: var(--accent-soft); }

/* Not placed yet: the menu sits in the row instead of over a card */
.tree-unplaced__list { display: grid; gap: var(--space-2); }
.tree-unplaced__item { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: var(--tap); }
.tree-unplaced__name { display: flex; align-items: center; gap: var(--space-2); min-width: 0; overflow-wrap: anywhere; }
.tree-unplaced__item .tree-menu { position: relative; top: auto; right: auto; flex: none; }
.tree-unplaced__item .tree-menu__button { border: 1px solid var(--line-strong); min-height: var(--tap); padding: 0 var(--space-4); color: var(--text); font-weight: 600; background: var(--surface); }

/* List view */
.tree-detail__head { display: flex; align-items: center; gap: var(--space-3); }
.tree-detail__head h2, .tree-detail__head p { margin: 0; }
.tree-relations { display: grid; gap: var(--space-3); }
@media (min-width: 640px) { .tree-relations { grid-template-columns: repeat(2, 1fr); } }
.tree-relgroup__title { margin: 0 0 var(--space-1); font-size: var(--step-small); color: var(--muted); }
.tree-relgroup p { margin: 0; }
.tree-relgroup__list { display: grid; gap: var(--space-1); }
.tree-relgroup__list a { display: inline-flex; align-items: center; min-height: var(--tap); }
.tree-everyone__title { margin-top: var(--space-4); }
.tree-everyone { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tree-everyone .btn[aria-current="true"] { border-color: var(--accent); color: var(--accent-strong); }

/* Forms and the link list */
.tree-years-fields { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.tree-link-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: var(--tap); }
