/* «Древо рода» (FZ-RF 1085): одна схема дерева — карточки, связи, карточка человека с переходами по родне,
   «Все в роду», «Показать ветку», шкала времени, фон, оформление, макет, выгрузка и печать.
   Цвета панелей — переменные: тёмная тема по умолчанию, светлая — body без .dark-mode. */

body {
    --sch-panel: rgba(18, 30, 15, 0.96);
    --sch-panel-solid: #142211;
    --sch-fg: #efe3c2;
    --sch-muted: #c4b896;
    --sch-border: rgba(212, 168, 67, 0.42);
    --sch-line: rgba(212, 168, 67, 0.18);
    --sch-accent: #e8c252;
    --sch-accent-ink: #1d2414;
    --sch-hover: rgba(212, 168, 67, 0.16);
    --sch-on: rgba(212, 168, 67, 0.26);
    --sch-field: rgba(0, 0, 0, 0.22);
    --sch-shadow: 0 10px 30px rgba(0, 0, 0, 0.42);
}
body:not(.dark-mode) {
    --sch-panel: rgba(255, 252, 245, 0.97);
    --sch-panel-solid: #fffcf5;
    --sch-fg: #3b2f14;
    --sch-muted: #6b5a35;
    --sch-border: rgba(140, 100, 30, 0.35);
    --sch-line: rgba(140, 100, 30, 0.16);
    --sch-accent: #9a6f08;
    --sch-accent-ink: #fffdf6;
    --sch-hover: rgba(140, 100, 30, 0.1);
    --sch-on: rgba(212, 168, 67, 0.3);
    --sch-field: rgba(255, 255, 255, 0.9);
    --sch-shadow: 0 10px 30px rgba(60, 40, 10, 0.16);
}

/* ── Шапка страницы ── */
.drevo-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px 24px; flex-wrap: wrap; margin-bottom: 14px; }
.drevo-head h1 { font-size: clamp(1.4rem, 3vw, 2.1rem); }
.drevo-head-name { font-size: 0.75em; opacity: 0.85; }
.drevo-head-links { display: flex; gap: 6px; flex-wrap: wrap; }
.drevo-link {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 18px; font-size: 0.88rem;
    border: 1px solid var(--sch-border); color: var(--sch-accent); text-decoration: none; background: var(--sch-panel);
}
.drevo-link:hover { background: var(--sch-accent); color: var(--sch-accent-ink); }

/* ── Контейнер и фон ── */
#tree-container {
    width: 100%;
    height: 85vh;
    min-height: 520px;
    border-radius: var(--radius-xl, 28px);
    overflow: hidden;
    position: relative;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), inset 0 0 80px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(212, 168, 67, 0.25);
    background:
        radial-gradient(ellipse at 50% 30%, rgba(74, 122, 58, 0.15) 0%, transparent 70%),
        linear-gradient(135deg, #0d1a0a 0%, #142211 40%, #1e3317 70%, #0d1a0a 100%);
}
#tree-container.tree-container-fullscreen,
#tree-container:fullscreen { height: 100vh; width: 100%; border-radius: 0; }
#tree-container:-webkit-full-screen { height: 100%; width: 100%; border-radius: 0; }
/* Светлая тема сайта: фон «по теме сайта» светлеет вместе с ней */
body:not(.dark-mode) #tree-container.scheme-bg-auto {
    background:
        radial-gradient(ellipse at 50% 30%, rgba(107, 154, 74, 0.14) 0%, transparent 70%),
        linear-gradient(135deg, #f6f2e6 0%, #ede5d1 45%, #f3eddd 100%) !important; /* drevorodni-theme.css красит с !important */
    border-color: rgba(140, 100, 30, 0.3) !important;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), inset 0 0 60px rgba(120, 90, 30, 0.06) !important;
}
#tree-container.scheme-bg-light {
    background:
        radial-gradient(ellipse at 50% 30%, rgba(107, 154, 74, 0.14) 0%, transparent 70%),
        linear-gradient(135deg, #f6f2e6 0%, #ede5d1 45%, #f3eddd 100%) !important;
}
#tree-container.scheme-bg-dark {
    background:
        radial-gradient(ellipse at 50% 30%, rgba(74, 122, 58, 0.15) 0%, transparent 70%),
        linear-gradient(135deg, #0d1a0a 0%, #142211 40%, #1e3317 70%, #0d1a0a 100%) !important;
}
#tree-container.scheme-bg-parchment { background: #efe2c2 url("../tree/parchment-bg.099ae71c0e3c.png") center / cover no-repeat !important; }
#tree-container.scheme-bg-landscape { background: #6d8ea0 url("../tree/scheme-bg-landscape.9f214d4fe9d4.webp") center / cover no-repeat !important; }
#tree-container.scheme-bg-forest {
    background: linear-gradient(rgba(8, 16, 6, 0.38), rgba(8, 16, 6, 0.38)), url("../tree/scene-trees-1600.38ea43d770e4.webp") center / cover no-repeat, #142211 !important;
}
#tree-container.scheme-bg-letopis {
    background: linear-gradient(rgba(10, 8, 4, 0.4), rgba(10, 8, 4, 0.4)), url("../tree/letopis-scene-1600.39602ae65e5a.webp") center / cover no-repeat, #1c140a !important;
}
#tree-container.scheme-bg-custom {
    background-color: #1a2616 !important;
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
}

/* ── Общие кнопки и панели ── */
.scheme-btn {
    height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--sch-border);
    background: var(--sch-panel); color: var(--sch-accent); display: inline-flex; align-items: center; gap: 8px;
    font-weight: 600; font-size: 0.9rem; box-shadow: var(--sch-shadow); cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}
.scheme-btn:hover, .scheme-btn[aria-expanded="true"] { background: var(--sch-accent); color: var(--sch-accent-ink); }
.scheme-btn:active { transform: scale(0.97); }
.scheme-btn:focus-visible, .scheme-nav-btn:focus-visible, .scheme-action:focus-visible, .pc-chip:focus-visible { outline: 3px solid var(--sch-accent); outline-offset: 2px; }
.scheme-btn--icon { width: 40px; padding: 0; justify-content: center; }
.scheme-btn-sub { display: none; }

.scheme-top {
    position: absolute; top: 12px; left: 12px; right: 12px; z-index: 210;
    display: flex; gap: 8px; align-items: flex-start; pointer-events: none;
}
.scheme-top > * { pointer-events: auto; }
.scheme-toolbar { margin-left: auto; }
.tree-top-buttons-list { display: flex; gap: 6px; align-items: center; }

/* Поиск человека (C2) */
.tree-search { position: relative; width: 270px; max-width: 40%; }
.tree-search-icon { position: absolute; left: 14px; top: 13px; color: var(--sch-muted); font-size: 0.85rem; pointer-events: none; }
.tree-search-input {
    width: 100%; height: 40px; padding: 0 14px 0 36px; border-radius: 20px; border: 1px solid var(--sch-border);
    background: var(--sch-panel); color: var(--sch-fg); font-size: 0.9rem; outline: none; box-shadow: var(--sch-shadow);
}
.tree-search-input::placeholder { color: var(--sch-muted); }
.tree-search-input:focus { border-color: var(--sch-accent); box-shadow: 0 0 0 3px rgba(232, 194, 82, 0.25); }
.tree-search-list {
    list-style: none; margin: 6px 0 0; padding: 4px 0; background: var(--sch-panel); border: 1px solid var(--sch-border);
    border-radius: 12px; box-shadow: var(--sch-shadow); max-height: 320px; overflow-y: auto;
}
.tree-search-list[hidden] { display: none; }
.tree-search-item { display: flex; flex-direction: column; padding: 8px 14px; cursor: pointer; color: var(--sch-fg); line-height: 1.25; }
.tree-search-item small { color: var(--sch-muted); font-size: 0.75rem; }
.tree-search-item.is-active, .tree-search-item:hover { background: var(--sch-hover); }
.tree-search-empty { padding: 8px 14px; color: var(--sch-muted); font-size: 0.85rem; }

/* Меню инструментов */
.scheme-menu {
    position: absolute; top: 60px; right: 12px; width: 350px; max-height: calc(100% - 76px); overflow: auto; z-index: 290;
    background: var(--sch-panel); color: var(--sch-fg); border: 1px solid var(--sch-border); border-radius: 16px; box-shadow: var(--sch-shadow);
    animation: scheme-pop 0.14s ease-out;
}
.scheme-menu[hidden], .scheme-drawer[hidden] { display: none; }
@keyframes scheme-pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.scheme-menu-head {
    display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 8px 8px 16px;
    font-weight: 700; color: var(--sch-accent); border-bottom: 1px solid var(--sch-line);
    position: sticky; top: 0; background: var(--sch-panel-solid); z-index: 2;
}
.scheme-menu-head small { color: var(--sch-muted); font-weight: 600; margin-left: 4px; }
.scheme-menu-close {
    width: 36px; height: 36px; flex: none; border: 0; border-radius: 50%; background: transparent; color: var(--sch-muted); font-size: 1rem; cursor: pointer;
}
.scheme-menu-close:hover { background: var(--sch-hover); color: var(--sch-fg); }
.scheme-menu-section { padding: 12px 16px; border-bottom: 1px solid var(--sch-line); }
.scheme-menu-section:last-child { border-bottom: 0; }
.scheme-menu-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--sch-muted); font-weight: 700; margin-bottom: 8px; }
.scheme-menu-note { font-size: 0.8rem; color: var(--sch-muted); margin: 8px 0 0; line-height: 1.35; }
.scheme-toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.scheme-toggle {
    display: inline-flex; align-items: center; gap: 6px; border-radius: 18px; border: 1px solid var(--sch-border); padding: 6px 12px;
    background: transparent; color: var(--sch-muted); font-size: 0.85rem; cursor: pointer;
}
.scheme-toggle i { opacity: 0.6; }
.scheme-toggle.is-on { background: var(--sch-on); color: var(--sch-fg); border-color: var(--sch-accent); }
.scheme-toggle.is-on i { opacity: 1; color: var(--sch-accent); }
.scheme-toggle:not(.is-on) { text-decoration: line-through; text-decoration-color: rgba(196, 184, 150, 0.6); }
.scheme-seg { display: flex; gap: 4px; background: var(--sch-field); padding: 4px; border-radius: 12px; border: 1px solid var(--sch-line); }
.scheme-seg button {
    flex: 1; border: 0; background: transparent; color: var(--sch-muted); padding: 7px 8px; border-radius: 9px; font-size: 0.84rem; font-weight: 600; cursor: pointer;
}
.scheme-seg button:hover { color: var(--sch-fg); background: var(--sch-hover); }
.scheme-seg button.is-active, .scheme-seg button.active { background: var(--sch-accent); color: var(--sch-accent-ink); }
.scheme-action {
    display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px 12px; margin: 0; border-radius: 10px; border: 0;
    background: transparent; color: var(--sch-fg); text-align: left; font-size: 0.92rem; cursor: pointer;
}
.scheme-action:hover { background: var(--sch-hover); }
.scheme-action i { width: 20px; text-align: center; color: var(--sch-accent); }
.scheme-action small { margin-left: auto; color: var(--sch-muted); font-size: 0.75rem; }
.scheme-action[disabled] { opacity: 0.45; cursor: default; }
.scheme-check input { margin: 0 4px 0 2px; }
[data-feature-locked="1"] { opacity: 0.58; filter: grayscale(0.25); }
[data-feature-locked="1"]::after { content: ' 🔒'; font-size: 0.8em; }
.scheme-bg-swatch[data-feature-locked="1"]::after { content: none; }

/* Фон: образцы */
.scheme-bg-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.scheme-bg-swatch {
    display: flex; flex-direction: column; gap: 4px; align-items: stretch; border: 0; background: transparent; padding: 0;
    color: var(--sch-muted); font-size: 0.7rem; line-height: 1.15; text-align: center; cursor: pointer;
}
.scheme-bg-swatch span {
    display: flex; align-items: center; justify-content: center; height: 46px; border-radius: 10px; border: 2px solid var(--sch-line);
    background-size: cover; background-position: center; color: var(--sch-accent); font-size: 1.1rem;
}
.scheme-bg-swatch:hover span { border-color: var(--sch-border); }
.scheme-bg-swatch.is-active { color: var(--sch-fg); font-weight: 700; }
.scheme-bg-swatch.is-active span { border-color: var(--sch-accent); box-shadow: 0 0 0 2px var(--sch-accent); }
.sw-auto span { background: linear-gradient(135deg, #f3eddd 0 50%, #142211 50% 100%); }
.sw-light span { background: linear-gradient(135deg, #f6f2e6, #ede5d1); }
.sw-dark span { background: linear-gradient(135deg, #0d1a0a, #1e3317); }
.sw-parchment span { background-image: url("../tree/parchment-bg.099ae71c0e3c.png"); }
.sw-landscape span { background-image: url("../tree/scheme-bg-landscape.9f214d4fe9d4.webp"); }
.sw-forest span { background-image: url("../tree/scene-trees-640.f23bcaf78db5.webp"); }
.sw-letopis span { background-image: url("../tree/letopis-scene-640.320cc770b218.webp"); }
.sw-custom span { border-style: dashed; background-color: var(--sch-field); }

/* ── «Все в роду» ── */
.scheme-drawer {
    position: absolute; top: 60px; left: 12px; bottom: 12px; width: 320px; z-index: 255; display: flex; flex-direction: column;
    background: var(--sch-panel); color: var(--sch-fg); border: 1px solid var(--sch-border); border-radius: 16px; box-shadow: var(--sch-shadow);
    animation: scheme-pop 0.14s ease-out; overflow: hidden;
}
.scheme-drawer-tools { padding: 10px 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--sch-line); }
.scheme-input {
    width: 100%; height: 38px; border-radius: 10px; border: 1px solid var(--sch-border); background: var(--sch-field);
    color: var(--sch-fg); padding: 0 12px; font-size: 0.9rem; outline: none;
}
.scheme-input:focus { border-color: var(--sch-accent); }
.people-list { list-style: none; margin: 0; padding: 0 8px 12px; overflow: auto; flex: 1; }
.people-gen {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--sch-muted); font-weight: 700;
    padding: 12px 8px 4px; position: sticky; top: 0; background: var(--sch-panel-solid); z-index: 1;
}
.people-row {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border-radius: 10px; border: 0;
    background: transparent; color: var(--sch-fg); text-align: left; cursor: pointer;
}
.people-row:hover, .people-row:focus-visible { background: var(--sch-hover); outline: none; }
.people-row.is-current { background: var(--sch-on); }
.people-name { display: block; font-weight: 600; font-size: 0.9rem; line-height: 1.2; }
.people-row small { display: block; color: var(--sch-muted); font-size: 0.75rem; }
.people-empty { padding: 16px 8px; color: var(--sch-muted); font-size: 0.9rem; }
.sch-ava {
    flex: none; width: 34px; height: 34px; border-radius: 50%; overflow: hidden; display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 700; color: #fff; background: #6b8a5a; border: 2px solid var(--sch-border);
}
.sch-ava.is-f { background: #b47d4a; }
.sch-ava img { width: 100%; height: 100%; object-fit: cover; }
.sch-me { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 6px; background: var(--sch-accent); color: var(--sch-accent-ink); font-size: 0.7rem; font-weight: 700; }

/* ── Карточка человека ── */
.tree-node-popup {
    position: absolute; top: 60px; right: 12px; bottom: 12px; width: 350px; z-index: 270; overflow: auto; padding: 0;
    background: var(--sch-panel); color: var(--sch-fg); border: 1px solid var(--sch-border); border-radius: 16px; box-shadow: var(--sch-shadow);
    animation: scheme-pop 0.14s ease-out;
}
.tree-node-popup-head {
    display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 14px; position: sticky; top: 0; z-index: 2;
    background: var(--sch-panel-solid); border-bottom: 1px solid var(--sch-line);
}
.tree-node-popup-name { flex: 1; font-weight: 700; font-size: 1.02rem; color: var(--sch-accent); line-height: 1.25; }
.pc-back, .tree-node-popup-close {
    width: 36px; height: 36px; flex: none; border: 0; border-radius: 50%; background: transparent; color: var(--sch-muted); cursor: pointer; font-size: 1rem;
}
.pc-back:hover, .tree-node-popup-close:hover { background: var(--sch-hover); color: var(--sch-fg); }
.pc-back[hidden] { display: none; }
.pc-hero { display: flex; gap: 14px; padding: 14px 16px 8px; align-items: center; }
.pc-photo {
    flex: none; width: 84px; height: 84px; border-radius: 50%; overflow: hidden; border: 3px solid var(--sch-accent);
    display: flex; align-items: center; justify-content: center; font-size: 1.7rem; font-weight: 700; color: #fff; background: #6b8a5a;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.pc-photo.is-f { background: #b47d4a; }
.pc-photo img { width: 100%; height: 100%; object-fit: cover; }
.pc-years { font-weight: 700; font-size: 1rem; }
.pc-place { font-size: 0.84rem; color: var(--sch-muted); margin-top: 2px; }
.pc-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.pc-badges span { padding: 1px 8px; border-radius: 10px; font-size: 0.72rem; background: var(--sch-on); color: var(--sch-fg); }
.pc-section { padding: 10px 16px; border-top: 1px solid var(--sch-line); }
.pc-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--sch-muted); font-weight: 700; margin-bottom: 8px; }
.pc-group + .pc-group { margin-top: 10px; }
.pc-group-label { font-size: 0.78rem; color: var(--sch-muted); margin-bottom: 4px; }
.pc-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pc-chip {
    display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 10px 3px 3px; border-radius: 20px;
    border: 1px solid var(--sch-border); background: var(--sch-field); color: var(--sch-fg); font-size: 0.82rem; cursor: pointer; text-align: left;
}
.pc-chip:hover { border-color: var(--sch-accent); background: var(--sch-hover); }
.pc-chip .sch-ava { width: 26px; height: 26px; font-size: 0.66rem; border-width: 1px; }
.pc-chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-chip small { color: var(--sch-muted); font-size: 0.72rem; margin-left: 2px; }
.pc-none { font-size: 0.85rem; color: var(--sch-muted); }
.pc-focus { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pc-focus button {
    display: flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 8px; border-radius: 10px;
    border: 1px solid var(--sch-border); background: transparent; color: var(--sch-fg); font-size: 0.84rem; cursor: pointer;
}
.pc-focus button i { color: var(--sch-accent); }
.pc-focus button:hover, .pc-focus button.is-active { background: var(--sch-on); border-color: var(--sch-accent); }
.pc-actions { padding-top: 6px; padding-bottom: 8px; }
.tree-node-popup-item {
    display: flex; align-items: center; padding: 8px 8px; border-radius: 10px; color: var(--sch-fg); text-decoration: none; font-size: 0.92rem;
}
.tree-node-popup-item i { width: 22px; text-align: center; color: var(--sch-accent); }
.tree-node-popup-item:hover { background: var(--sch-hover); color: var(--sch-fg); }
.tree-node-popup-item.disabled { opacity: 0.5; pointer-events: none; }
.tree-node-popup-item .pc-count { margin-left: auto; padding: 0 8px; border-radius: 10px; background: var(--sch-on); font-size: 0.78rem; font-weight: 700; }
.pc-add { display: flex; flex-wrap: wrap; gap: 6px; }
.pc-add .tree-node-popup-item { border: 1px dashed var(--sch-accent); border-radius: 18px; padding: 5px 12px; font-size: 0.85rem; }
.pc-add .tree-node-popup-item i { width: auto; }
#pc-add.is-empty { display: none; }
/* Карточка открыта — навигация и мини-карта уходят левее, чтобы их не закрывать */
#tree-container.has-card .scheme-nav { right: 374px; }
#tree-container.has-card .tree-minimap { right: 426px; }
#tree-container.has-drawer .tree-hint { display: none; }
#tree-container.has-drawer .draw-panel { left: 344px; }

/* ── Навигация и мини-карта ── */
.scheme-nav { position: absolute; right: 12px; bottom: 12px; z-index: 200; display: flex; flex-direction: column; gap: 6px; }
.scheme-nav-btn {
    width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--sch-border); background: var(--sch-panel); color: var(--sch-accent);
    display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; box-shadow: var(--sch-shadow); font-size: 0.95rem;
}
.scheme-nav-btn:hover { background: var(--sch-accent); color: var(--sch-accent-ink); }
.scheme-nav-btn[disabled] { opacity: 0.45; cursor: default; background: var(--sch-panel); color: var(--sch-accent); }
.tree-minimap {
    position: absolute; right: 64px; bottom: 12px; width: 160px; height: 100px; z-index: 150; background: var(--sch-panel);
    border: 1px solid var(--sch-border); border-radius: 10px; overflow: hidden; cursor: pointer; touch-action: none; user-select: none; box-shadow: var(--sch-shadow);
}
.tree-minimap canvas { display: block; width: 100%; height: 100%; }
.tree-minimap-viewport {
    position: absolute; left: 0; top: 0; width: 0; height: 0; border: 2px solid var(--sch-accent);
    background: rgba(232, 194, 82, 0.16); box-sizing: border-box; pointer-events: none;
}

/* ── Подсказки, статус, «Показать ветку» ── */
.tree-hint {
    position: absolute; left: 12px; bottom: 12px; max-width: calc(100% - 320px); z-index: 10; pointer-events: none;
    background: var(--sch-panel); color: var(--sch-muted); padding: 7px 12px; border-radius: 10px; font-size: 11px;
    border: 1px solid var(--sch-line); transition: opacity 0.6s;
}
.tree-hint.is-faded { opacity: 0; }
#tree-container .tree-hint { background: var(--sch-panel) !important; color: var(--sch-muted) !important; border-color: var(--sch-line); border-radius: 10px !important; }
.tree-save-status {
    position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 265; display: flex; align-items: center; flex-wrap: wrap;
    gap: 8px 10px; max-width: min(520px, calc(100% - 24px)); padding: 8px 14px; border-radius: 12px; background: var(--sch-panel);
    color: var(--sch-fg); border: 1px solid var(--sch-border); box-shadow: var(--sch-shadow); font-size: 0.86rem;
}
.tree-save-status[hidden] { display: none; }
.tree-save-status.is-ok { border-color: rgba(127, 176, 105, 0.9); }
.tree-save-status.is-error { border-color: rgba(229, 115, 94, 0.95); }
.tree-save-status.is-preview { border-color: var(--sch-accent); border-width: 2px; }
.tree-save-status-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tree-save-status-actions:empty { display: none; }
.tree-save-status-btn {
    min-height: 32px; padding: 4px 12px; border-radius: 8px; border: 1px solid var(--sch-border); background: transparent;
    color: var(--sch-accent); cursor: pointer; font-size: 0.85rem;
}
.tree-save-status-btn:hover { background: var(--sch-hover); }
.tree-save-status-btn.is-primary { background: var(--sch-accent); color: var(--sch-accent-ink); border-color: var(--sch-accent); font-weight: 600; }
.scheme-focus-bar {
    position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 240; display: flex; align-items: center; gap: 10px;
    padding: 5px 5px 5px 14px; border-radius: 22px; background: var(--sch-panel); color: var(--sch-fg); border: 1px solid var(--sch-accent);
    box-shadow: var(--sch-shadow); font-size: 0.88rem; max-width: calc(100% - 24px);
}
.scheme-focus-bar[hidden] { display: none; }
.scheme-focus-bar i { color: var(--sch-accent); }
.scheme-focus-bar button {
    border: 0; border-radius: 18px; padding: 6px 12px; background: var(--sch-accent); color: var(--sch-accent-ink); font-weight: 600; cursor: pointer; white-space: nowrap;
}
#tree-container.has-card .scheme-focus-bar { left: calc(50% - 181px); }

/* «Показать ветку»: остальные приглушены */
#tree-svg.focus-mode .person-node:not(.in-focus) { opacity: 0.14; }
#tree-svg.focus-mode .link-item:not(.in-focus) { opacity: 0.07; }
#tree-svg.focus-mode .slots-layer { display: none; }
.person-node, .link-item { transition: opacity 0.25s; }

/* Шкала времени */
.time-axis line { stroke: rgba(232, 194, 82, 0.32); stroke-width: 1.5; stroke-dasharray: 4 8; }
.time-axis line.is-century { stroke: rgba(232, 194, 82, 0.6); stroke-dasharray: none; }
.time-axis text {
    fill: #f0dba0; stroke: rgba(10, 18, 8, 0.75); stroke-width: 4px; paint-order: stroke; font: 700 22px 'Raleway', 'Segoe UI', system-ui, sans-serif;
}
body:not(.dark-mode) #tree-container.scheme-bg-auto .time-axis line,
#tree-container.scheme-bg-light .time-axis line,
#tree-container.scheme-bg-parchment .time-axis line { stroke: rgba(120, 85, 20, 0.35); }
body:not(.dark-mode) #tree-container.scheme-bg-auto .time-axis text,
#tree-container.scheme-bg-light .time-axis text,
#tree-container.scheme-bg-parchment .time-axis text { fill: #6b4f0e; stroke: rgba(255, 252, 245, 0.9); }

/* ── Карточки, линии, пустые места (были на странице, C2–C3, ОН2) ── */
#tree-svg { width: 100%; height: 100%; cursor: grab; touch-action: none; /* палец: перетаскивание и щипок уходят в d3.zoom */ }
#tree-svg:active { cursor: grabbing; }
.person-node { cursor: pointer; }
.person-node rect { rx: 14; ry: 14; transition: filter 0.25s ease; }
.person-node:hover rect { filter: brightness(1.2) drop-shadow(0 8px 20px rgba(218, 165, 32, 0.2)); }
.person-node text { font-family: 'Raleway', 'Segoe UI', system-ui, sans-serif; }
.person-node:focus { outline: none; }
.person-node:focus-visible rect { stroke: #e8c252; stroke-width: 4; }
.person-node.selected rect { stroke: #e8c252; stroke-width: 4; }
.person-node.is-current > rect,
.person-node.is-current .node-glow-rect { stroke: #e8c252; stroke-width: 5; }
.tree-selection-rect { fill: none; stroke: #e8c252; stroke-width: 2; stroke-dasharray: 6, 4; pointer-events: none; }
.link-parent { stroke-width: 2.5; fill: none; }
.link-spouse { stroke-width: 3; fill: none; stroke-dasharray: 8, 4; }
.link-selected { stroke-width: 4 !important; opacity: 1; }
.node-me-badge rect { fill: #e8c252; stroke: rgba(20, 34, 17, 0.9); stroke-width: 1.5; }
.node-same-badge rect { fill: #8fc1e3; stroke: rgba(20, 34, 17, 0.9); stroke-width: 1.5; }
.node-same-badge text, .node-me-badge text { fill: #1d2414; font-size: 12px; font-weight: 700; pointer-events: none; }
@keyframes tree-found-pulse { 0%, 100% { stroke-opacity: 1; stroke-width: 5; } 50% { stroke-opacity: 0.35; stroke-width: 8; } }
.person-node.is-found > rect,
.person-node.is-found .node-glow-rect { stroke: #ff9f1c; stroke-width: 5; animation: tree-found-pulse 0.9s ease-in-out 3; }
.slot-node { cursor: pointer; }
.slot-node .slot-rect { fill: rgba(20, 34, 17, 0.45); stroke-width: 2; stroke-dasharray: 7, 5; }
.slot-node:hover .slot-rect, .slot-node:focus-visible .slot-rect { fill: rgba(212, 168, 67, 0.18); stroke-width: 3; }
.slot-node:focus { outline: none; }
.slot-node .slot-label { fill: #e8c252; font: 600 17px 'Raleway', 'Segoe UI', system-ui, sans-serif; pointer-events: none; }
.slot-node .slot-sub { fill: #c4b896; font: 13px 'Raleway', 'Segoe UI', system-ui, sans-serif; pointer-events: none; }
.slot-link { fill: none; stroke-width: 2; stroke-dasharray: 6, 6; opacity: 0.7; pointer-events: none; }

/* Легенда — в меню «Вид» */
#tree-container .scheme-menu .tree-legend { background: transparent !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; color: var(--sch-fg) !important; padding: 12px 16px !important; position: static !important; }
#tree-container .scheme-menu .tree-legend .scheme-menu-title { color: var(--sch-muted); }
.tree-legend .legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.84rem; color: var(--sch-fg); padding: 2px 0; }
.legend-line { width: 28px; height: 3px; border-radius: 2px; flex: none; }
.legend-line-spouse { background: none; border-bottom: 2px dashed #c62828; height: 0; }
.legend-line-dashed { background: none; border-bottom: 3px dashed #6b9a4a; height: 0; }

/* ОН1/ОН2: подсказка для телефона и «места кончились» */
.tree-hint-mobile {
    display: none; position: absolute; left: 8px; right: 8px; top: 60px; background: var(--sch-panel); color: var(--sch-fg);
    padding: 8px 40px 8px 12px; border-radius: 10px; font-size: 13px; line-height: 1.35; z-index: 140; pointer-events: none; border: 1px solid var(--sch-border);
}
.tree-hint-mobile.is-hidden { display: none !important; }
.tree-hint-mobile-close {
    position: absolute; top: 0; right: 0; width: 40px; height: 100%; min-height: 36px; border: 0; background: transparent; color: inherit;
    font-size: 16px; pointer-events: auto; cursor: pointer;
}
.tree-slots-note {
    position: absolute; left: 12px; bottom: 60px; max-width: 420px; z-index: 140; background: var(--sch-panel); color: var(--sch-fg);
    border: 1px solid var(--sch-border); border-radius: 10px; padding: 8px 12px; font-size: 13px;
}
.tree-slots-note[hidden] { display: none; }
.tree-slots-note a { color: var(--sch-accent); font-weight: 600; }

/* Панель рисования */
.draw-panel {
    position: absolute; bottom: 60px; left: 12px; z-index: 250; min-width: 230px; background: var(--sch-panel); color: var(--sch-fg);
    border: 1px solid var(--sch-border); border-radius: 14px; box-shadow: var(--sch-shadow); font-size: 12px;
}
.draw-panel-header {
    display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--sch-line);
    font-weight: 700; color: var(--sch-accent);
}
.draw-panel-close { background: none; border: none; color: var(--sch-muted); cursor: pointer; padding: 2px 6px; }
.draw-panel-close:hover { color: var(--sch-accent); }
.draw-panel-body { padding: 10px 12px; }
.draw-panel-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.draw-panel-row:last-child { margin-bottom: 0; }
.draw-panel-row span:first-child { min-width: 60px; }
.draw-panel-row-checkbox { cursor: pointer; }
.draw-panel-row input[type="color"] { width: 36px; height: 28px; cursor: pointer; border: 1px solid var(--sch-border); border-radius: 4px; }
.draw-panel-row input[type="range"] { flex: 1; }
#draw-width-value { min-width: 20px; }
.draw-tool-btns { display: flex; gap: 4px; flex-wrap: wrap; }
.draw-tool-btn {
    width: 34px; height: 34px; padding: 0; border: 1px solid var(--sch-border); border-radius: 8px; background: var(--sch-field);
    color: var(--sch-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.draw-tool-btn:hover { color: var(--sch-accent); border-color: var(--sch-accent); }
.draw-tool-btn.active { background: var(--sch-on); color: var(--sch-accent); border-color: var(--sch-accent); }

/* Окно ввода текста */
.draw-text-modal { position: absolute; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; pointer-events: auto; }
.draw-text-modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); }
.draw-text-modal-box {
    position: relative; background: var(--sch-panel-solid); border: 1px solid var(--sch-border); border-radius: 12px; padding: 20px;
    min-width: 280px; box-shadow: var(--sch-shadow);
}
.draw-text-modal-label { display: block; color: var(--sch-accent); font-weight: 600; margin-bottom: 10px; }
.draw-text-modal-input {
    width: 100%; padding: 10px 12px; margin-bottom: 14px; border: 1px solid var(--sch-border); border-radius: 8px; background: var(--sch-field);
    color: var(--sch-fg); font-size: 16px; box-sizing: border-box;
}
.draw-text-modal-input:focus { outline: none; border-color: var(--sch-accent); }
.draw-text-modal-btns { display: flex; gap: 10px; justify-content: flex-end; }

/* Состояние схемы: загрузка, ошибка, пустое дерево */
.tree-status { position: absolute; inset: 0; z-index: 150; display: flex; align-items: center; justify-content: center; padding: 16px; pointer-events: none; }
.tree-status[hidden] { display: none; }
.tree-status-box {
    pointer-events: auto; max-width: 420px; width: 100%; text-align: center; background: var(--sch-panel); color: var(--sch-fg);
    border: 1px solid var(--sch-border); border-radius: 16px; padding: 22px 20px; box-shadow: var(--sch-shadow);
}
.tree-status-icon { font-size: 2rem; color: var(--sch-accent); margin-bottom: 10px; }
.tree-status-title { font-size: 1.15rem; font-weight: 600; margin-bottom: 6px; }
.tree-status-text { opacity: 0.85; font-size: 0.95rem; }
.tree-status-actions { margin-top: 14px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.tree-status-actions .btn { min-height: 44px; }

/* Светлая тема: карточки людей (атрибуты в SVG тёмные по умолчанию) */
body:not(.dark-mode) .card-grad-m stop:first-child { stop-color: #e8f1e1; }
body:not(.dark-mode) .card-grad-m stop:last-child { stop-color: #cfe2c1; }
body:not(.dark-mode) .card-grad-f stop:first-child { stop-color: #f8e9e2; }
body:not(.dark-mode) .card-grad-f stop:last-child { stop-color: #efd3c8; }
body:not(.dark-mode) .node-fio { fill: #1d2414; stroke: #ffffff; }
body:not(.dark-mode) .node-dates { fill: #6b4f0e; }
body:not(.dark-mode) .node-photo-ring { stroke: rgba(80, 60, 20, 0.75); }
body:not(.dark-mode) .node-photo-placeholder { fill: rgba(120, 90, 30, 0.12); stroke: rgba(80, 60, 20, 0.6); }
body:not(.dark-mode) .person-node.selected rect,
body:not(.dark-mode) .person-node:focus-visible rect { stroke: #b8860b; }
body:not(.dark-mode) .tree-selection-rect { stroke: #b8860b; }
body:not(.dark-mode) .slot-node .slot-rect { fill: rgba(255, 252, 245, 0.75); }
body:not(.dark-mode) .slot-node:hover .slot-rect,
body:not(.dark-mode) .slot-node:focus-visible .slot-rect { fill: rgba(212, 168, 67, 0.22); }
body:not(.dark-mode) .slot-node .slot-label { fill: #6b4f0e; }
body:not(.dark-mode) .slot-node .slot-sub { fill: #7a6a45; }
body:not(.dark-mode) .tree-minimap-viewport { border-color: #b8860b; background: rgba(184, 134, 11, 0.14); }

/* ── Телефон: поиск сверху, инструменты — полосой снизу, меню и карточка — панелями снизу ── */
@media (max-width: 768px) {
    .drevo-head { margin-bottom: 10px; }
    .drevo-head-sub { display: none; }
    .drevo-head-links { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; width: 100%; }
    .drevo-link { flex: none; min-height: 40px; }
    #tree-container { height: 74vh; height: 74dvh; min-height: 460px; }

    .scheme-top { position: static; }
    .tree-search { position: absolute; top: 8px; left: 8px; right: 60px; width: auto; max-width: none; z-index: 211; }
    .tree-search-input { height: 44px; font-size: 1rem; }
    .tree-search-icon { top: 15px; }
    .tree-search-item { padding: 12px 14px; font-size: 1rem; }
    #btn-people-drawer { position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; padding: 0; justify-content: center; z-index: 211; }
    #btn-people-drawer span { display: none; }
    .scheme-toolbar { position: absolute; left: 8px; right: 8px; bottom: 8px; margin: 0; z-index: 211; }
    .tree-top-buttons-list {
        justify-content: space-around; gap: 2px; padding: 4px; background: var(--sch-panel); border: 1px solid var(--sch-border);
        border-radius: 18px; box-shadow: var(--sch-shadow);
    }
    .tree-top-buttons-list .scheme-btn {
        flex: 1 1 0; min-width: 0; height: 52px; flex-direction: column; justify-content: center; gap: 3px; padding: 0 4px;
        font-size: 0.68rem; border: 0; box-shadow: none; background: transparent; border-radius: 14px;
    }
    .tree-top-buttons-list .scheme-btn i { font-size: 1.05rem; }
    .tree-top-buttons-list .scheme-btn:hover { background: var(--sch-hover); color: var(--sch-accent); }
    .tree-top-buttons-list .scheme-btn[aria-expanded="true"] { background: var(--sch-accent); color: var(--sch-accent-ink); }
    .tree-top-buttons-list .scheme-btn--icon { width: auto; }
    .scheme-btn-sub { display: inline; }

    .scheme-menu { left: 8px; right: 8px; top: auto; bottom: 72px; width: auto; max-height: calc(100% - 140px); }
    .scheme-drawer { left: 8px; right: 8px; top: 60px; bottom: 72px; width: auto; }
    .scheme-bg-grid { grid-template-columns: repeat(4, 1fr); }
    .scheme-action, .scheme-toggle, .scheme-seg button { min-height: 44px; }
    .people-row { min-height: 48px; }

    .scheme-nav { right: 8px; bottom: 76px; }
    #btn-zoom-in, #btn-zoom-out { display: none; }
    .scheme-nav-btn { width: 44px; height: 44px; }
    .tree-minimap { display: none; }
    #tree-container.has-card .scheme-nav { right: 8px; }
    .tree-hint { display: none; }
    .tree-hint-mobile { display: block; }
    .tree-save-status { left: 8px; right: 8px; bottom: 76px; transform: none; max-width: none; font-size: 0.95rem; }
    .tree-save-status-btn { min-height: 44px; padding: 8px 14px; font-size: 0.95rem; }
    .scheme-focus-bar, #tree-container.has-card .scheme-focus-bar { top: 60px; left: 8px; right: 8px; transform: none; justify-content: space-between; }
    .tree-slots-note { left: 8px; right: 8px; bottom: 140px; max-width: none; }
    .draw-panel, #tree-container.has-drawer .draw-panel { left: 8px; right: 8px; bottom: 72px; min-width: 0; max-height: 50vh; overflow: auto; }
    .draw-tool-btn { width: 44px; height: 44px; }
    .draw-panel-row input[type="color"] { width: 44px; height: 44px; }
    .draw-panel-row input[type="range"] { min-height: 44px; }
    .tree-node-popup-item { padding: 10px 10px; font-size: 1rem; line-height: 1.4; }
    /* ОН2: карточка человека — панель снизу экрана с именем и ✕ (живёт прямо в body, выше кружка чата) */
    .tree-node-popup.as-sheet {
        position: fixed; left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; z-index: 1090; max-height: 78vh;
        padding: 0 0 calc(8px + env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; border-width: 1px 0 0;
        box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.5); background: var(--sch-panel-solid);
    }
    .tree-node-popup.as-sheet .pc-photo { width: 64px; height: 64px; font-size: 1.3rem; }
}
