/* Родословная Благочевских — современный минимализм */
:root {
  --bg: #fafbfc;
  --surface: #ffffff;
  --ink: #16192b;
  --ink-soft: #4b5163;
  --ink-faint: #8a90a3;
  --line: #e4e7ee;
  --accent: #3454d1;
  --accent-soft: #eaeefb;
  --c-doc: #2f9e44;      /* достоверность: архивный документ */
  --c-site: #3454d1;     /* сайт-первоисточник */
  --c-family: #e8930c;   /* семейные сведения */
  --c-research: #9c36b5; /* интернет-исследование */
  --c-hypo: #868e96;     /* гипотеза */
  --t-minay: #3454d1;
  --t-early: #7048e8;
  --t-lubna: #0d9488;
  --t-rogozikha: #e8590c;
  --t-orenburg: #c2255c;
  --t-novosibirsk: #5f6b7a;
  --t-unknown: #868e96;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(22,25,43,.06), 0 8px 24px rgba(22,25,43,.07);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
b, strong { font-weight: 650; }

/* ── шапка ─────────────────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-top {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px 6px;
}
.site-title { font-size: 19px; color: var(--ink); white-space: nowrap; }
.site-title:hover { text-decoration: none; color: var(--accent); }
.header-search { position: relative; margin-left: auto; flex: 0 1 340px; }
.header-search input {
  width: 100%; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 14px; background: var(--surface); color: var(--ink);
  outline: none;
}
.header-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-results {
  position: absolute; top: calc(100% + 6px); right: 0; left: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 60vh; overflow-y: auto; padding: 4px;
}
.search-results .sr-item {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  font: inherit; font-size: 14px; padding: 8px 10px; border-radius: 6px; cursor: pointer;
  color: var(--ink);
}
.search-results .sr-item:hover { background: var(--accent-soft); }
.search-results .sr-item small { color: var(--ink-faint); }
.search-results .sr-empty { padding: 10px; color: var(--ink-faint); font-size: 14px; }

.header-nav {
  display: flex; align-items: center; gap: 14px;
  padding: 6px 20px 10px; overflow-x: auto;
}
.view-switcher {
  display: inline-flex; background: #eef0f5; border-radius: 9px; padding: 3px; gap: 2px;
  flex: none;
}
.view-switcher a {
  padding: 5px 13px; border-radius: 7px; font-size: 14px; font-weight: 550;
  color: var(--ink-soft); white-space: nowrap;
}
.view-switcher a:hover { text-decoration: none; color: var(--ink); }
.view-switcher a.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(22,25,43,.12); }
.tree-select {
  font: inherit; font-size: 14px; padding: 5px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  max-width: 260px; flex: none;
}
.nav-links { display: flex; gap: 4px; margin-left: auto; flex: none; }
.nav-links a {
  padding: 5px 10px; font-size: 14px; color: var(--ink-soft); border-radius: 7px;
  white-space: nowrap;
}
.nav-links a:hover { background: #eef0f5; color: var(--ink); text-decoration: none; }
.nav-links a.active { color: var(--accent); font-weight: 600; }

/* ── контейнеры ────────────────────────────────────── */
.app { min-height: 62vh; }
.page { max-width: 980px; margin: 0 auto; padding: 28px 20px 60px; }
.page-wide { max-width: 1220px; }
.loading { padding: 80px 20px; text-align: center; color: var(--ink-faint); }
.view-stage { position: relative; height: calc(100vh - 108px); min-height: 420px; overflow: hidden; }
.view-toolbar {
  position: absolute; top: 12px; left: 12px; z-index: 20;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center; max-width: calc(100% - 24px);
}
.view-toolbar .tool {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 11px; font: inherit; font-size: 13px; color: var(--ink-soft);
  cursor: pointer; box-shadow: 0 1px 2px rgba(22,25,43,.06);
}
.view-toolbar .tool:hover { border-color: var(--accent); color: var(--accent); }
.view-toolbar .tool.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.legend {
  position: absolute; bottom: 12px; left: 12px; z-index: 20;
  background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 12px; font-size: 12.5px; color: var(--ink-soft);
  display: grid; gap: 3px; max-width: 300px;
}
.legend-toggle {
  justify-self: start; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 600; color: var(--ink-soft);
  padding: 4px 0 0; margin-top: 2px; display: flex; align-items: center; gap: 5px;
}
.legend-toggle::before { content: "▾"; font-size: 10px; transition: transform .15s; }
.legend.collapsed { padding: 6px 12px; }
.legend.collapsed .legend-toggle { padding: 0; margin: 0; }
.legend.collapsed .legend-toggle::before { transform: rotate(-90deg); }
.legend.collapsed > *:not(.legend-toggle) { display: none; }
/* таймлайн: тулбар справа (слева — подписи веток), легенда над осью лет */
.view-toolbar.tl-toolbar-right { left: auto; right: 12px; }
.legend.tl-legend { bottom: 46px; }
.tl-zoom {
  position: absolute; right: 12px; bottom: 46px; z-index: 20;
  display: flex; flex-direction: column; gap: 4px;
}
.tl-zoom button {
  width: 34px; height: 34px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; font-size: 20px; line-height: 1; cursor: pointer; color: var(--ink-soft);
  box-shadow: 0 1px 2px rgba(22,25,43,.06);
}
.tl-zoom button:hover { border-color: var(--accent); color: var(--accent); }
.legend .li { display: flex; align-items: center; gap: 7px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend .dash { width: 18px; border-top: 2px dashed var(--c-hypo); flex: none; }

h1 { font-size: 26px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 20px; margin: 30px 0 10px; }
h3 { font-size: 16.5px; margin: 22px 0 8px; }
.muted { color: var(--ink-faint); }
.small { font-size: 13.5px; }

/* ── карточки-плитки главной ───────────────────────── */
.stat-row { display: flex; gap: 22px; flex-wrap: wrap; margin: 18px 0 6px; }
.stat { min-width: 96px; }
.stat b { display: block; font-size: 26px; letter-spacing: -.02em; }
.stat span { font-size: 13px; color: var(--ink-faint); }
.island-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin: 16px 0; }
.island-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; display: block; color: var(--ink); position: relative;
  transition: box-shadow .15s ease, transform .15s ease;
}
.island-card:hover { text-decoration: none; box-shadow: var(--shadow); transform: translateY(-1px); }
.island-card::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px;
  border-radius: 3px; background: var(--island-color, var(--accent));
}
.island-card b { font-size: 15.5px; }
.island-card .small { margin-top: 4px; }

/* ── попап персоны ─────────────────────────────────── */
.popup-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(22,25,43,.42);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 14px; overflow-y: auto;
}
.person-popup {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  max-width: 640px; width: 100%; padding: 24px 26px 20px; position: relative;
  margin-bottom: 6vh;
}
.person-popup .close-btn {
  position: absolute; top: 12px; right: 12px; border: 0; background: #eef0f5;
  width: 32px; height: 32px; border-radius: 8px; font-size: 16px; cursor: pointer; color: var(--ink-soft);
}
.person-popup .close-btn:hover { background: var(--line); }
.person-popup .back-btn {
  position: absolute; top: 12px; right: 52px; border: 0; background: #eef0f5;
  height: 32px; padding: 0 10px; border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--ink-soft);
}
.person-popup h2 { margin: 0 26px 2px 0; font-size: 21px; }
.person-popup .p-sub { color: var(--ink-faint); font-size: 13.5px; margin-bottom: 14px; }
.p-badges { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.badge {
  font-size: 12px; padding: 3px 9px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent); font-weight: 550;
}
.badge.tree-badge { background: color-mix(in srgb, var(--island-color, var(--accent)) 12%, white); color: var(--island-color, var(--accent)); }
.fact-list { margin: 12px 0; display: grid; gap: 7px; }
.fact { display: flex; gap: 9px; font-size: 14.5px; align-items: baseline; }
.fact .f-label { color: var(--ink-faint); flex: none; width: 78px; font-size: 13px; }
.conf-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; vertical-align: 1px; }
.conf-document { background: var(--c-doc); }
.conf-site { background: var(--c-site); }
.conf-family { background: var(--c-family); }
.conf-research { background: var(--c-research); }
.conf-hypothesis { background: transparent; border: 1.5px dashed var(--c-hypo); }
.rel-group { margin: 12px 0; }
.rel-group .rg-title { font-size: 13px; color: var(--ink-faint); margin-bottom: 4px; }
.rel-list { display: flex; flex-direction: column; gap: 3px; }
.rel-list .rel {
  background: none; border: 0; font: inherit; font-size: 14.5px; text-align: left;
  color: var(--accent); cursor: pointer; padding: 2px 0; width: fit-content;
}
.rel-list .rel:hover { text-decoration: underline; }
.rel-list .rel small, .rel .muted { color: var(--ink-faint); }
.p-notes { background: #f6f7fa; border-radius: 8px; padding: 10px 13px; font-size: 14px; margin: 12px 0; display: grid; gap: 6px; }
.p-military { border: 1px solid var(--line); border-left: 3px solid #b02a37; border-radius: 8px; padding: 10px 13px; margin: 12px 0; font-size: 14px; }
.p-military pre { white-space: pre-wrap; font: 13px/1.5 ui-monospace, Menlo, monospace; margin: 6px 0 0; color: var(--ink-soft); }
.p-photos { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.p-photos figure { margin: 0; max-width: 46%; }
.p-photos img { max-width: 100%; border-radius: 8px; display: block; }
.p-photos figcaption { font-size: 12px; color: var(--ink-faint); margin-top: 4px; }
.p-sources { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; font-size: 13px; color: var(--ink-soft); }
.p-sources .src { margin: 4px 0; padding-left: 14px; text-indent: -14px; }
.p-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.p-actions a, .p-actions button {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
}
.p-actions a:hover, .p-actions button:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.provenance-box { font-size: 12.5px; color: var(--ink-faint); margin-top: 10px; }

/* ── роспись ───────────────────────────────────────── */
.rospis .r-line { padding: 2px 0 2px 0; font-size: 15px; }
.rospis .r-person { cursor: pointer; color: var(--ink); }
.rospis .r-person:hover { color: var(--accent); }
.rospis .r-num { color: var(--accent); font-weight: 600; margin-right: 6px; }
.rospis .r-ab { color: var(--ink-faint); font-size: 12.5px; margin-left: 7px; }
.rospis .r-marriage { color: var(--ink-soft); }
.rospis .gen-title { margin: 26px 0 8px; font-size: 17px; font-weight: 650; }

/* ── вертикальное древо ────────────────────────────── */
.vtree { padding: 18px 14px 60px; max-width: 900px; margin: 0 auto; }
.vt-node { position: relative; }
.vt-row {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 7px 10px; border-radius: 8px; cursor: pointer; position: relative;
}
.vt-row:hover { background: var(--accent-soft); }
.vt-toggle {
  flex: none; width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); font-size: 11px; line-height: 1; cursor: pointer; color: var(--ink-soft);
  align-self: center;
}
.vt-toggle:hover { border-color: var(--accent); color: var(--accent); }
.vt-toggle.leaf { visibility: hidden; }
.vt-name { font-weight: 550; overflow-wrap: anywhere; }
.vt-years { color: var(--ink-faint); font-size: 13.5px; white-space: nowrap; }
.vt-spouse { color: var(--ink-soft); font-size: 13.5px; overflow-wrap: anywhere; }
.vt-count { color: var(--ink-faint); font-size: 12.5px; background: #eef0f5; padding: 1px 8px; border-radius: 12px; }
.vt-children { margin-left: 22px; border-left: 1.5px solid var(--line); padding-left: 8px; }

/* ── древо (SVG) и таймлайн ────────────────────────── */
.stage-svg { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: none; outline: none; }
.stage-svg:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-soft); }
.stage-svg:active { cursor: grabbing; }
.tree-card { cursor: pointer; }
.tree-card rect { fill: var(--surface); stroke: var(--line); stroke-width: 1; rx: 8px; }
.tree-card:hover rect { stroke: var(--accent); stroke-width: 1.5; }
.tree-card.spouse-card rect { fill: #f6f7fa; }
.tree-card text { fill: var(--ink); font-size: 12.5px; }
.tree-card .t-years { fill: var(--ink-faint); font-size: 11px; }
.tree-card.direct-line rect { stroke: var(--accent); stroke-width: 2; fill: var(--accent-soft); }
.tree-edge { stroke: #c9cedb; stroke-width: 1.3; fill: none; }
.tree-edge.uncertain { stroke-dasharray: 5 4; stroke: var(--c-hypo); }
.tree-collapse { cursor: pointer; }
.tree-collapse circle { fill: var(--surface); stroke: var(--ink-faint); }
.tree-collapse text { fill: var(--ink-soft); font-size: 10.5px; text-anchor: middle; }
.hypo-edge { stroke: var(--c-hypo); stroke-width: 1.5; stroke-dasharray: 6 5; fill: none; }
.tl-dot { cursor: pointer; }
.tl-dot:hover { stroke: var(--ink); stroke-width: 1.5; }
.tl-link { fill: none; stroke-width: 1.2; opacity: .62; }
.tl-link.tl-spouse { stroke-dasharray: 5 4; opacity: .5; stroke-width: 1.1; }
/* при наведении на точку остаются видимыми только ЕЁ связи */
.tl-links.tl-focus .tl-link { opacity: .05; }
.tl-links.tl-focus .tl-link.on { opacity: .95; stroke-width: 1.8; }
.tl-links.tl-focus .tl-link.tl-spouse.on { opacity: .85; stroke-width: 1.4; }
/* режим прослеживания ветки: не-ветка приглушена, ветка — ярко */
.tl-dots.tl-dim .tl-dot { opacity: .12; }
.tl-dots.tl-dim .tl-dot.branch { opacity: 1; stroke: #16192b; stroke-width: 2; }
.tl-plate {
  position: absolute; z-index: 30; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 9px 12px; min-width: 176px; max-width: 210px;
}
.tl-plate .tp-name { font-weight: 650; font-size: 14px; line-height: 1.25; }
.tl-plate .tp-sub { font-size: 12px; color: var(--ink-faint); margin: 2px 0 8px; }
.tl-plate .tp-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tl-plate button {
  font: inherit; font-size: 12.5px; padding: 5px 10px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
}
.tl-plate button[data-more] { background: var(--accent); border-color: var(--accent); color: #fff; }
.tl-plate button:hover { filter: brightness(.97); }
/* плашка наведения — поверх закреплённой, только для чтения имени */
.tl-plate-hover { z-index: 36; pointer-events: none; box-shadow: 0 2px 10px rgba(22,25,43,.14); }
.tl-axis text { fill: var(--ink-faint); font-size: 11px; }
.tl-axis line { stroke: var(--line); }
.tl-gen-label { fill: var(--ink-faint); font-size: 10.5px; }
.tl-island-label { fill: var(--ink-soft); font-size: 12.5px; font-weight: 600; }
.chart-tooltip {
  position: fixed; z-index: 90; background: var(--ink); color: #fff;
  padding: 6px 10px; border-radius: 7px; font-size: 12.5px; pointer-events: none;
  max-width: 260px; box-shadow: var(--shadow);
}
/* подписи мест на карте живут в markerPane ПОВЕРХ кружков — без этого
   правила они перехватывают мышь, и наведение на маркер не срабатывает */
.map-label, .map-label * { pointer-events: none !important; }
.map-tooltip {
  position: fixed; z-index: 90; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 12px; font-size: 13px; max-width: 300px;
}
.map-tooltip .mt-place { font-weight: 650; margin-bottom: 2px; }
.map-tooltip .mt-list { max-height: 220px; overflow-y: auto; margin-top: 6px; display: grid; gap: 2px; }
.map-tooltip .mt-list button {
  background: none; border: 0; font: inherit; font-size: 13px; color: var(--accent);
  cursor: pointer; text-align: left; padding: 1px 0;
}
.map-tooltip .mt-list button:hover { text-decoration: underline; }
.map-tooltip .mt-inferred { color: var(--ink-faint); font-size: 12px; margin-top: 4px; }

/* ── контентные страницы ───────────────────────────── */
.article p { margin: 10px 0; }
.article blockquote {
  margin: 12px 0; padding: 10px 16px; border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: 0 8px 8px 0; color: var(--ink-soft); font-size: 14.5px;
}
.mil-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 12px 0;
}
.mil-card .mc-head { font-weight: 650; }
.mil-card .mc-meta { font-size: 13.5px; color: var(--ink-soft); margin: 4px 0; }
.mil-card pre { white-space: pre-wrap; font: 12.5px/1.5 ui-monospace, Menlo, monospace; color: var(--ink-soft); margin: 8px 0 0; }
.src-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 16px; margin: 10px 0; }
.src-card .s-type { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
img.doc-image { max-width: 100%; border-radius: 10px; box-shadow: var(--shadow); }

@media (max-width: 640px) {
  .header-top { padding: 8px 12px 4px; gap: 10px; }
  .site-title { font-size: 16px; }
  .header-nav { padding: 4px 12px 8px; gap: 8px; }
  .nav-links { margin-left: 0; }
  .page { padding: 20px 14px 50px; }
  .view-stage { height: calc(100vh - 118px); }
  .p-photos figure { max-width: 100%; }
}
