:root {
  --bg: #f7f5f0; --card: #fff; --text: #2b2a27; --muted: #77736a; --line: #c9c3b6;
  --accent: #5a7a4f; --m: #4a6fa5; --f: #b0587a; --danger: #b04a3a;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1c1a; --card: #272623; --text: #ece8df; --muted: #a29d92; --line: #4a4740;
          --accent: #8fb383; --m: #8fb0e0; --f: #e09ab6; --danger: #e08070; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, sans-serif; }
a { color: var(--accent); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: .2em 0; } h2 { font-size: 1.05rem; margin: 0 0 .5em; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
       padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.top nav { display: flex; gap: 14px; align-items: center; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin: 12px 0; }
.narrow { max-width: 380px; margin: 40px auto; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.actions { display: flex; gap: 14px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 12px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.grid .wide { grid-column: 1 / -1; }
@media (max-width: 600px) { .grid { grid-template-columns: 1fr; } }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
input, select, textarea, button { font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
button { background: var(--accent); color: #fff; border: 0; cursor: pointer; }
button.link { background: none; color: var(--accent); padding: 0; }
.danger, button.danger { color: var(--danger); }
.inline { display: inline; }
.muted { color: var(--muted); }
.flash { background: var(--card); border-left: 4px solid var(--accent); padding: 8px 12px; margin: 8px 0; }
.flash.error { border-color: var(--danger); }
.people { list-style: none; padding: 0; margin: 0; }
.people li { padding: 4px 0; display: flex; gap: 8px; align-items: baseline; }
.people li .muted { white-space: nowrap; }
.sex-M { border-left: 3px solid var(--m); padding-left: 8px; }
.sex-F { border-left: 3px solid var(--f); padding-left: 8px; }
.notes { white-space: pre-wrap; }
.search input { min-width: 260px; }

/* Древо: CSS org-chart из вложенных ul/li */
.tree-wrap { overflow-x: auto; padding: 12px 0 24px; }
.tree, .tree ul { display: flex; justify-content: center; padding: 18px 0 0; margin: 0; position: relative; list-style: none; }
.tree { padding-top: 0; }
.tree li { position: relative; padding: 18px 6px 0; text-align: center; }
.tree li::before, .tree li::after { content: ""; position: absolute; top: 0; right: 50%; width: 50%; height: 18px; border-top: 1px solid var(--line); }
.tree li::after { right: auto; left: 50%; border-left: 1px solid var(--line); }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:only-child { padding-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border: 0 none; }
.tree li:last-child::before { border-right: 1px solid var(--line); border-radius: 0 6px 0 0; }
.tree li:first-child::after { border-radius: 6px 0 0 0; }
.tree ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 18px; border-left: 1px solid var(--line); }
.tree > li { padding-top: 0; }
.node { display: inline-flex; flex-direction: column; min-width: 120px; padding: 6px 10px; background: var(--card);
        border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--text); }
.node small { color: var(--muted); }
/* Предки: корень снизу — переворачиваем дерево по вертикали, текст обратно */
.tree.up { transform: scaleY(-1); }
.tree.up .node { transform: scaleY(-1); }
