/* ============================================================================
 * styles.css — строгое, сдержанное оформление генеалогического дерева.
 * ==========================================================================*/
:root {
  --bg:          #eceae4;   /* фон сцены — приглушённый пергамент */
  --panel:       #ffffff;
  --ink:         #23262b;   /* основной текст */
  --ink-soft:    #5d626b;
  --ink-faint:   #8a8f98;
  --line:        #b9b2a4;   /* линии связей */
  --line-strong: #8d8478;
  --border:      #d6d2c8;
  --accent:      #4a5568;   /* строгий сине-серый акцент */
  --male:        #3f5a7a;   /* сдержанные гендерные акценты */
  --female:      #8a4f63;
  --shadow:      0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.07);
  --shadow-lg:   0 8px 40px rgba(0,0,0,.22);
  --serif:       Georgia, 'Times New Roman', 'PT Serif', serif;
  --sans:        'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  --header-h:    64px;      /* высота шапки; на телефоне две строки (см. @media) */
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Шапка ---------- */
.app-header {
  position: fixed; inset: 0 0 auto 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 64px; padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark {
  font-size: 26px; color: var(--accent);
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 4px; flex: none;
}
.brand-text h1 {
  font-family: var(--serif); font-size: 20px; font-weight: 600;
  margin: 0; letter-spacing: .3px; line-height: 1.1;
}
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--ink-faint); }

.header-tools { display: flex; align-items: center; gap: 12px; }

/* переключатель языка */
.lang-switch {
  display: flex; flex: none;
  border: 1px solid var(--border); border-radius: 4px; overflow: hidden;
}
.lang-switch button {
  padding: 8px 10px; font-size: 12px; letter-spacing: .5px;
  background: var(--panel); border: none; cursor: pointer;
  color: var(--ink-soft);
  transition: background .12s, color .12s;
}
.lang-switch button + button { border-left: 1px solid var(--border); }
.lang-switch button:hover { background: #f0eee8; }
.lang-switch button.active { background: var(--accent); color: #fff; }
/* селектор вида дерева */
.mode-switch { flex: none; }
.mode-switch select {
  padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--panel); color: var(--ink-soft); cursor: pointer;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.mode-switch select:hover { background: #f0eee8; }
.mode-switch select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(74,85,104,.12); }

/* чип выбранного «центра» дерева */
.center-chip {
  flex: none; max-width: 220px; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis;
  padding: 8px 10px; font-size: 12px;
  border: 1px solid var(--accent); border-radius: 999px;
  background: var(--accent); color: #fff; cursor: pointer;
  transition: opacity .12s;
}
.center-chip:hover { opacity: .85; }

/* кнопка «Сделать центром дерева» в карточке */
.center-btn {
  display: block; width: 100%; margin: 10px 0 2px;
  padding: 9px 12px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); color: var(--ink-soft); cursor: pointer;
  transition: background .12s, border-color .12s;
}
.center-btn:hover:not(:disabled) { background: #f0eee8; border-color: var(--accent); }
.center-btn.active { background: #eef2f7; color: var(--accent); cursor: default; }

/* веерная диаграмма предков (fan chart) */
.fan-sector {
  stroke-width: 1.5; cursor: pointer;
  /* #links целиком pointer-events:none (чтобы линии в карточных режимах не
     перехватывали клики); секторы веера явно включают события обратно, поэтому
     реальный клик мышью по сектору срабатывает, а пустые места пропускают клик
     сквозь (панорама/сброс выделения). */
  pointer-events: auto;
  transition: fill-opacity .12s, filter .12s;
}
.fan-sector:hover { filter: brightness(0.94); }
.fan-sector.sel { stroke: var(--accent); stroke-width: 3; }
.fan-ph { stroke-dasharray: 4 3; }
.fan-dead { opacity: .78; }
.fan-label {
  fill: var(--ink); pointer-events: none;
  text-anchor: middle; dominant-baseline: middle;
  font-family: inherit;
}
.fan-label-name { font-weight: 600; }
/* в веерном режиме подписи поколений слева не нужны */
body.fan-mode #genLabels { display: none; }

.search-box { position: relative; }
.search-box input {
  width: 280px; max-width: 46vw;
  padding: 9px 12px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 4px;
  background: #fbfaf7; color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(74,85,104,.12); }

.search-results {
  position: absolute; top: calc(100% + 6px); right: 0; left: 0; z-index: 50;
  margin: 0; padding: 6px; list-style: none;
  max-height: 320px; overflow: auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: var(--shadow-lg);
}
.search-results li {
  padding: 8px 10px; border-radius: 4px; cursor: pointer;
  font-size: 13px; display: flex; flex-direction: column;
}
.search-results li:hover, .search-results li.active { background: #f0eee8; }
.search-results .sr-name { font-weight: 600; }
.search-results .sr-sub { font-size: 11px; color: var(--ink-faint); }
.search-results .sr-empty { color: var(--ink-faint); cursor: default; }

/* ---------- Сцена ---------- */
.stage {
  position: fixed; inset: var(--header-h, 64px) 0 0 0;
  overflow: hidden; cursor: grab;
  background:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,.05) 1px, transparent 0) 0 0 / 26px 26px,
    var(--bg);
  touch-action: none;
}
.stage.grabbing { cursor: grabbing; }
.viewport { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.links { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.cards { position: absolute; top: 0; left: 0; }

/* ---------- Карточка человека ---------- */
.card {
  position: absolute;
  width: 210px; height: 150px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 5px solid var(--ink-faint);   /* пол читается издалека */
  border-radius: 6px;
  box-shadow: var(--shadow);
  display: flex; gap: 12px; padding: 12px;
  cursor: pointer; overflow: visible;       /* кнопки ▲/▼ и бейджи не режутся */
  transition: box-shadow .15s, transform .15s, border-color .15s;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.card.male   { border-top-color: var(--male); }
.card.female { border-top-color: var(--female); }
.card.dimmed { opacity: .28; filter: grayscale(.4); }
.card.highlight { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(74,85,104,.25), var(--shadow-lg); }
.card.highlight-path { border-color: var(--accent); }

/* пробанд — владелец древа */
.card.root {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(74,85,104,.22), var(--shadow);
}
.card.root::after {
  content: var(--probandLabel, 'ПРОБАНД');
  position: absolute; top: -9px; right: 8px;
  font-size: 9px; letter-spacing: 1px;
  background: var(--accent); color: #fff;
  padding: 1px 6px; border-radius: 3px;
}

/* умершие */
.card.dead { background: #f6f4ef; }
.card.dead .card-photo img { filter: grayscale(1) sepia(.15); }
.card.dead .card-monogram { filter: grayscale(.6); }

/* заглушки без данных */
.card.placeholder { opacity: .55; border-style: dashed; border-top-style: solid; background: #f6f4ef; }

.card-photo {
  flex: none; width: 70px; height: 90px;
  border-radius: 4px; overflow: hidden;
  background: #ece9e2; border: 1px solid var(--border);
  display: grid; place-items: center;
}
.card-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-monogram {
  width: 100%; height: 100%; display: grid; place-items: center;
  font-family: var(--serif); font-size: 26px; color: #fff;
  background: linear-gradient(160deg, #9a9488, #7d7768);
}
.card.male   .card-monogram { background: linear-gradient(160deg, #5b7596, #3f5a7a); }
.card.female .card-monogram { background: linear-gradient(160deg, #a86b7d, #8a4f63); }

.card-info { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.card-name {
  font-family: var(--serif); font-size: 14px; line-height: 1.22;
  font-weight: 600; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-maiden { font-size: 11px; color: var(--ink-faint); font-style: italic; }
.card-dates {
  margin-top: auto; font-size: 12px; color: var(--ink-soft);
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
}
.card-dead-mark { color: var(--ink-faint); }
.card-place {
  font-size: 11px; color: var(--ink-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-badge {
  position: absolute; top: 8px; right: 8px;
  font-size: 10px; color: var(--ink-faint);
}

/* ---------- Линии связей (SVG) ---------- */
.link-path   { fill: none; stroke: var(--line); stroke-width: 1.6; }
.link-halo   { fill: none; stroke: var(--bg); stroke-width: 4.5; }      /* «мост» на пересечениях */
.link-spouse { stroke: var(--line-strong); stroke-width: 5; }
.link-spouse-gap { fill: none; stroke: var(--bg); stroke-width: 2.4; pointer-events: none; } /* просвет «=» */
.link-joint  { fill: var(--line-strong); stroke: none; }                /* узел семьи */
.link-dimmed { opacity: .25; }
.link-active { stroke: var(--accent); stroke-width: 2.4; }
.link-spouse.link-active { stroke-width: 5; }

/* ---------- Подписи поколений ---------- */
#genLabels { position: absolute; left: 0; top: 0; z-index: 20; pointer-events: none; }
.gen-label {
  position: absolute; left: 10px; transform: translateY(-50%);
  white-space: nowrap;
  font-size: 11px; letter-spacing: .5px; text-transform: uppercase;
  color: var(--ink-faint);
  background: rgba(255,255,255,.72); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 8px;
  backdrop-filter: blur(2px);
}

/* ---------- Легенда ---------- */
.legend-btn {
  position: absolute; left: 18px; bottom: 18px; z-index: 31;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--ink-soft); font-size: 16px; cursor: pointer;
  box-shadow: var(--shadow);
}
.legend-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.legend {
  position: absolute; left: 18px; bottom: 62px; z-index: 31;
  width: 330px; max-width: 82vw;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-lg);
  padding: 14px 16px; font-size: 12.5px; line-height: 1.5;
}
.legend[hidden] { display: none; }
.legend h4 { margin: 0 0 8px; font-family: var(--serif); font-size: 14px; }
.lg-row { display: flex; align-items: center; gap: 8px; margin: 5px 0; color: var(--ink-soft); }
.lg-swatch {
  flex: none; width: 22px; height: 14px;
  border: 1px solid var(--border); border-radius: 3px; background: var(--panel);
}
.lg-male   { border-top: 4px solid var(--male); }
.lg-female { border-top: 4px solid var(--female); }
.lg-dead   { background: #f6f4ef; }
.lg-ph     { border-style: dashed; background: #f6f4ef; }
.lg-line   {
  flex: none; width: 22px; height: 5px;
  background: linear-gradient(180deg, var(--line-strong) 0 30%, var(--bg) 30% 70%, var(--line-strong) 70% 100%);
}
.lg-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }

/* ---------- Уровни детализации (LOD) ---------- */
/* средний план: только имя и даты, крупнее */
.zoom-far .card-maiden, .zoom-far .card-place, .zoom-far .card-badge { display: none; }
.zoom-far .card-name { font-size: 21px; -webkit-line-clamp: 2; }
.zoom-far .card-dates { font-size: 15px; }
/* дальний план: цветные плитки — читается структура ветвей */
.zoom-tiny .card-info, .zoom-tiny .card-photo, .zoom-tiny .card-badge,
.zoom-tiny .collapse-btn { display: none; }
.zoom-tiny .card        { background: #a8a196; border-color: transparent; }
.zoom-tiny .card.male   { background: var(--male); }
.zoom-tiny .card.female { background: var(--female); }
.zoom-tiny .card.dead   { opacity: .55; }
.zoom-tiny .card.root   { outline: 8px solid var(--accent); }
.zoom-tiny .card.root::after { display: none; }
/* производительность: без transition/hover на отдалении */
.zoom-far .card, .zoom-tiny .card { transition: none; }
.zoom-far .card:hover, .zoom-tiny .card:hover { transform: none; box-shadow: var(--shadow); }

/* ---------- Управление масштабом ---------- */
.zoom-controls {
  position: absolute; right: 18px; bottom: 18px; z-index: 30;
  display: flex; flex-direction: column; gap: 6px;
}
.zoom-controls button {
  width: 40px; height: 40px; font-size: 18px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--border); border-radius: 5px;
  cursor: pointer; box-shadow: var(--shadow);
  display: grid; place-items: center;
  transition: background .12s, color .12s;
}
.zoom-controls button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.hint {
  position: absolute; left: 62px; bottom: 18px; z-index: 30;
  font-size: 12px; color: var(--ink-faint);
  background: rgba(255,255,255,.7); padding: 6px 10px; border-radius: 4px;
  border: 1px solid var(--border); backdrop-filter: blur(2px);
  transition: opacity .4s;
}

/* ---------- Панель деталей ---------- */
.detail {
  position: fixed; top: 0; right: 0; z-index: 60;
  width: 420px; max-width: 92vw; height: 100%;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(0); transition: transform .25s ease;
  overflow-y: auto; overflow-x: hidden;
}
.detail[hidden] { display: block; transform: translateX(100%); pointer-events: none; }
.detail-close {
  position: absolute; top: 14px; right: 14px; z-index: 2;
  width: 34px; height: 34px; border-radius: 4px;
  background: #f3f1ec; border: 1px solid var(--border); cursor: pointer;
  font-size: 15px; color: var(--ink-soft);
}
.detail-close:hover { background: #e7e4dc; }
.scrim {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(20,20,22,.28);
}
.scrim[hidden] { display: none; }
/* на десктопе панель не блокирует дерево — можно кликать родственников подряд */
@media (min-width: 721px) { .scrim { display: none !important; } }

.detail-body { padding: 28px 26px 60px; }
.detail-hero { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 18px; }
.detail-photo {
  flex: none; width: 128px; height: 164px; border-radius: 6px; overflow: hidden;
  background: #ece9e2; border: 1px solid var(--border); display: grid; place-items: center;
}
.detail-photo img { width: 100%; height: 100%; object-fit: cover; }
.detail-photo .card-monogram { font-size: 40px; }
.detail-title { font-family: var(--serif); font-size: 21px; font-weight: 600; margin: 2px 0 4px; line-height: 1.2; }
.detail-sub { font-size: 13px; color: var(--ink-faint); }

.detail-section { margin-top: 22px; }
.detail-section h3 {
  font-family: var(--serif); font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px; color: var(--accent);
  margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.fact { display: flex; gap: 10px; padding: 5px 0; font-size: 13.5px; }
.fact-key { flex: none; width: 116px; color: var(--ink-faint); }
.fact-val { color: var(--ink); }

/* биография — факты, свободный текст и заметки; длинное сворачивается */
.bio-block {
  padding: 10px 12px;
  background: #fbfaf7; border: 1px solid var(--border); border-radius: 5px;
}
.fact-empty .fact-val { color: var(--ink-faint); font-style: italic; }
.bio-text {
  margin-top: 12px; padding: 12px 14px;
  background: #fbfaf7; border: 1px solid var(--border); border-radius: 5px;
  font-family: var(--serif); font-size: 14.5px; line-height: 1.6; color: var(--ink);
}
.bio-text p { margin: 0 0 10px; white-space: pre-wrap; }
.bio-text p:last-child { margin-bottom: 0; }
.bio-text a, .note-text a { color: var(--accent); }
.bio-empty { margin-top: 12px; font-size: 13px; line-height: 1.5; color: var(--ink-faint); font-style: italic; }
.bio-notes { margin-top: 14px; }
.bio-notes .note-block:last-child { margin-bottom: 0; }
.bio-notes .note-text { font-size: 13.5px; line-height: 1.55; }
/* сворачиваемый длинный текст: первые строки с затуханием и кнопка «Читать полностью» */
.clamp-wrap { position: relative; }
.clamp-wrap.is-clamped .clamp-body {
  max-height: var(--clamp-h, 12.5em); overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 70%, transparent);
  mask-image: linear-gradient(#000 70%, transparent);
}
.clamp-toggle {
  display: inline-block; margin-top: 6px; padding: 3px 0;
  border: none; background: none; cursor: pointer;
  font-family: var(--sans); font-size: 12.5px; color: var(--accent);
  text-decoration: underline dotted; text-underline-offset: 3px;
}
.clamp-toggle:hover { color: var(--ink); }

/* открытые ссылки */
.link-list { display: flex; flex-direction: column; gap: 6px; }
.ext-link {
  display: block; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 5px;
  background: #fbfaf7; font-size: 13px;
  color: var(--accent); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ext-link:hover { background: #f0eee8; }

/* исходные данные — сворачиваемый блок */
.source-data {
  border: 1px solid var(--border); border-radius: 5px;
  background: #fbfaf7; padding: 0 12px 10px;
}
.source-data summary {
  cursor: pointer; padding: 10px 0;
  font-family: var(--serif); font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px; color: var(--accent);
}
.source-data summary:hover { color: var(--ink); }
.source-sub {
  margin: 14px 0 6px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; color: var(--ink-faint);
}

/* блок «добавить информацию» */
.add-info { margin-top: 26px; }
.add-info-btn {
  width: 100%; padding: 12px;
  background: var(--panel); color: var(--accent);
  border: 1px dashed var(--accent); border-radius: 6px;
  font-size: 14px; cursor: pointer;
  transition: background .12s;
}
.add-info-btn:hover { background: #f0eee8; }
.add-info-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.add-info-hint { font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; margin: 0 0 4px; }
.add-info-form input, .add-info-form textarea {
  padding: 9px 11px; font-size: 13px; font-family: var(--sans);
  border: 1px solid var(--border); border-radius: 4px;
  background: #fbfaf7; color: var(--ink); resize: vertical;
}
.add-info-form textarea { min-height: 150px; line-height: 1.5; overflow-y: hidden; }
.add-info-form textarea.is-scrollable { overflow-y: auto; }
.add-info-form input:disabled, .add-info-form textarea:disabled { color: var(--ink-faint); }
.add-info-status {
  margin: 2px 0 0; font-size: 12.5px; line-height: 1.45;
  color: #3a6b46;
}
.add-info-status.is-error { color: #a03b2e; }

/* прикрепление файлов */
.file-attach {
  display: block; padding: 10px 12px; text-align: center;
  border: 1px dashed var(--border); border-radius: 5px;
  background: #fbfaf7; color: var(--ink-soft);
  font-size: 13px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.file-attach:hover { background: #f0eee8; border-color: var(--accent); }
.file-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.file-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; font-size: 12.5px;
  border: 1px solid var(--border); border-radius: 4px; background: #fbfaf7;
}
.file-list .file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .file-size { flex: none; color: var(--ink-faint); font-size: 11px; }
.file-list .file-remove {
  flex: none; width: 20px; height: 20px; padding: 0;
  border: none; background: none; color: var(--ink-faint);
  font-size: 12px; cursor: pointer; border-radius: 3px;
}
.file-list .file-remove:hover { background: #e7e4dc; color: var(--ink); }

.rel-list { display: flex; flex-direction: column; gap: 6px; }
.rel-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 5px;
  background: #fbfaf7; cursor: pointer; font-size: 13px;
}
.rel-item:hover { background: #f0eee8; }
.rel-item .rel-role { font-size: 11px; color: var(--ink-faint); }
.rel-item .rel-name { font-weight: 600; }

.note-block {
  padding: 10px 12px; margin-bottom: 10px;
  background: #fbfaf7; border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 4px;
}
.note-head { font-size: 11px; color: var(--ink-faint); margin-bottom: 5px; }
.note-text { font-size: 13px; line-height: 1.5; color: var(--ink); white-space: pre-wrap; }

.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gallery figure { margin: 0; cursor: pointer; min-width: 0; }
.gallery img {
  width: 100%; max-width: 100%; aspect-ratio: 3/4; object-fit: cover;
  border: 1px solid var(--border); border-radius: 4px; background: #ece9e2;
  display: block; transition: transform .12s;
}
.gallery img:hover { transform: scale(1.03); }
.gallery figcaption { font-size: 10px; color: var(--ink-faint); margin-top: 3px; line-height: 1.25; overflow-wrap: anywhere; }
.empty-note { font-size: 13px; color: var(--ink-faint); font-style: italic; }

/* документы (PDF, DOCX…) с расшифровками */
.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc-item {
  padding: 10px 12px; background: #fbfaf7;
  border: 1px solid var(--border); border-left: 3px solid var(--line-strong); border-radius: 4px;
}
.doc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; min-width: 0; }
.doc-ext {
  flex: none; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 700; letter-spacing: .5px;
  background: var(--accent); color: #fff;
}
.doc-name { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.doc-notes { margin-top: 4px; }
.doc-link {
  display: inline-block; margin-top: 8px; font-size: 12.5px; color: var(--accent);
  text-decoration: none; border-bottom: 1px dotted var(--accent);
}
.doc-link:hover { color: var(--ink); border-bottom-color: var(--ink); }
.doc-links { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.doc-link-orig { color: var(--ink-faint); border-bottom-color: var(--border); font-size: 12px; }

/* ---------- Просмотр изображения (lightbox) ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(15,15,17,.86);
  display: grid; place-items: center; padding: 32px;
}
.lightbox[hidden] { display: none; }
/* Снимок и подпись — одна колонка; подпись ограничена по высоте и прокручивается,
   картинка ужимается так, чтобы блок с подписью всегда помещался на экране. */
.lightbox .lb-box {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  max-width: 92vw; max-height: calc(100vh - 64px);
}
.lightbox img {
  max-width: 92vw; max-height: 86vh; min-height: 0; flex: 1 1 auto; object-fit: contain;
  box-shadow: var(--shadow-lg); border-radius: 4px;
}
.lightbox .lb-cap {
  flex: 0 0 auto; max-height: 26vh; overflow-y: auto; box-sizing: border-box;
  width: min(92vw, 760px); padding: 10px 14px; border-radius: 6px;
  background: rgba(255,255,255,.08); color: #e8e6e0;
  font-size: 13px; line-height: 1.45; text-align: left; white-space: pre-line;
}
.lightbox .lb-cap[hidden] { display: none; }
.lightbox .lb-cap a { color: #cfe3ff; word-break: break-all; }
.lightbox .lb-close { position: absolute; top: 20px; right: 24px; font-size: 30px; color: #fff; cursor: pointer; background: none; border: none; }

/* ---------- Экран загрузки ---------- */
.loader {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
.loader[hidden] { display: none; }
.loader-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 34px 36px; width: 460px; max-width: 92vw;
  text-align: center;
}
.loader-card h2 { font-family: var(--serif); font-weight: 600; font-size: 19px; margin: 14px 0 6px; }
.loader-msg { color: var(--ink-faint); font-size: 13px; min-height: 18px; }
.spinner {
  width: 38px; height: 38px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
.loader-card.error .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.manual-load { margin-top: 20px; text-align: left; border-top: 1px solid var(--border); padding-top: 18px; }
.manual-hint { font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; }
.manual-hint code { background: #f0eee8; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.file-pick { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; font-size: 13px; }
.file-pick span { font-weight: 600; }
.file-pick em { color: var(--ink-faint); font-weight: 400; }
.btn-primary {
  margin-top: 8px; width: 100%; padding: 11px;
  background: var(--accent); color: #fff; border: none; border-radius: 5px;
  font-size: 14px; cursor: pointer;
}
.btn-primary:disabled { background: #b6bac2; cursor: not-allowed; }

/* ---------- Кнопки collapse/expand ветвей ---------- */
.collapse-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 26px;
  min-width: 26px;
  height: 18px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 16px;
  cursor: pointer;
  z-index: 2;
  white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s;
}
/* расширенная зона клика (невидимая) */
.collapse-btn::before { content: ''; position: absolute; inset: -10px; }
.collapse-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.collapse-up   { top: -10px; }
.collapse-down { bottom: -10px; }

.collapse-btn.is-collapsed {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  min-width: 32px;
  width: auto;
  font-size: 9px;
}

/* ---------- Адаптивность ---------- */
/* ---------- Мобильные экраны (телефоны, до 720 px) ----------
   Шапка в две строки: 1) знак + название + языки, 2) вид дерева · «Родство» ·
   поиск. Все элементы шапки становятся прямыми flex-детьми (display: contents),
   порядок задаётся order, разрыв строки — псевдоэлементом на всю ширину. */
@media (max-width: 720px) {
  :root { --header-h: 102px; }
  .app-header {
    height: auto; min-height: var(--header-h); box-sizing: border-box;
    flex-wrap: wrap; align-content: center; gap: 8px 8px; padding: 8px 12px;
  }
  .header-tools { display: contents; }
  .brand { order: 1; flex: 1 1 0; min-width: 0; gap: 8px; }
  .brand-mark { width: 34px; height: 34px; font-size: 20px; }
  .brand-text { min-width: 0; }
  .brand-text h1 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand-text p { display: none; }
  .center-chip { order: 2; flex: 0 1 auto; max-width: 44vw; padding: 7px 10px; }
  .app-header:has(.center-chip) .brand-text { display: none; }   /* место — чипу «центра» */
  .lang-switch { order: 3; }
  .lang-switch button { padding: 8px 7px; font-size: 11px; }
  .app-header::after { content: ''; order: 4; flex: 1 1 100%; height: 0; margin: -8px 0 0; }
  .mode-switch { order: 5; flex: 1 1 110px; min-width: 0; }
  .mode-switch select { width: 100%; box-sizing: border-box; padding: 8px 8px; font-size: 13px; }
  .kin-btn { order: 6; padding: 0 10px; height: 36px; white-space: nowrap; }
  .app-header .search-box { order: 7; flex: 1 1 90px; min-width: 0; position: static; }
  .app-header .search-box input { width: 100%; max-width: none; box-sizing: border-box; padding: 8px 10px; }
  .app-header .search-results { left: 12px; right: 12px; top: calc(100% + 4px); max-height: 50vh; }
  .search-results li { padding: 10px 10px; }
  .stage { inset: var(--header-h) 0 0 0; }
  .hint { display: none; }
  .gen-label { font-size: 10px; left: 6px; opacity: .85; }
  .zoom-controls { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .zoom-controls button { width: 42px; height: 42px; }
  .legend-btn { left: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }

  /* панель деталей — на весь экран, компактнее */
  .detail { width: 100%; max-width: none; border-left: none; }
  .detail-body { padding: 18px 16px calc(40px + env(safe-area-inset-bottom, 0px)); }
  .detail-close { top: 10px; right: 10px; width: 38px; height: 38px; }
  .detail-hero { gap: 14px; margin-bottom: 14px; }
  .detail-photo { width: 104px; height: 134px; }
  .detail-title { font-size: 19px; padding-right: 44px; }
  .fact-key { width: 96px; }
  .bio-text { font-size: 14px; }
  .gallery { gap: 6px; }

  /* поля ввода не меньше 16 px — иначе iOS приближает страницу при фокусе */
  .add-info-form input, .add-info-form textarea, .search-box input, .kin-panel input { font-size: 16px; }
  .add-info-btn, .center-btn, .kin-detail-btn, .btn-primary, .file-attach { min-height: 44px; }

  /* просмотр изображения */
  .lightbox { padding: 12px; }
  .lightbox .lb-box { max-width: 100vw; max-height: calc(100vh - 24px); }
  .lightbox img { max-width: 96vw; max-height: 70vh; }
  .lightbox .lb-cap { width: 96vw; max-height: 24vh; font-size: 12.5px; }
  .lightbox .lb-close { top: 8px; right: 12px; width: 44px; height: 44px; }
}
@media (max-width: 380px) {
  .kin-btn { font-size: 12px; padding: 0 8px; }
  .lang-switch button { padding: 8px 6px; font-size: 10.5px; }
  .gallery { grid-template-columns: repeat(2, 1fr); }
}
}
.add-info-mail-link { color: #2f5f7a; text-decoration: underline; white-space: nowrap; }

/* ---------- Режим «Родство» ---------- */
.kin-btn {
  flex: none; height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit; font-size: 13px; cursor: pointer;
}
.kin-btn:hover { background: #f0eee8; }
body.kin-mode .kin-btn { background: var(--accent); color: #fff; border-color: var(--accent); }
.kin-panel {
  position: fixed; top: 72px; right: 16px; z-index: 60; width: 380px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 14px 16px 16px; font-size: 13px;
}
.kin-panel[hidden] { display: none; }
.kin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.kin-head h3 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 16px; }
.kin-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--ink-faint); }
.kin-hint { margin: 0 0 10px; color: var(--ink-faint); font-size: 12px; line-height: 1.4; }
.kin-field { display: block; margin-bottom: 10px; }
.kin-field > span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); margin-bottom: 4px; }
.kin-field .search-box input { width: 100%; box-sizing: border-box; }
.kin-field input.kin-set { border-color: var(--accent); background: #f4f6fa; }
.kin-panel .search-results { max-height: 220px; }
.kin-actions { display: flex; gap: 8px; margin: 4px 0 10px; }
.kin-actions button {
  flex: 1; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel);
  font: inherit; font-size: 13px; cursor: pointer;
}
.kin-actions .kin-show { background: var(--accent); color: #fff; border-color: var(--accent); }
.kin-actions button:hover { filter: brightness(.96); }
.kin-result { border-top: 1px solid var(--border); padding-top: 10px; line-height: 1.45; }
.kin-result[hidden] { display: none; }
.kin-line { margin-bottom: 6px; }
.kin-line .kin-term { color: var(--accent); font-weight: 600; }
.kin-sub { margin: 10px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); }
.kin-path { margin: 0; padding-left: 18px; }
.kin-path li { margin: 2px 0; }
.kin-rel { color: var(--ink-faint); font-size: 12px; }
.kin-step { background: none; border: none; padding: 0; font: inherit; color: var(--ink); cursor: pointer; text-decoration: underline dotted; }
.kin-step:hover { color: var(--accent); }
body.kin-mode .card.kin-end { box-shadow: 0 0 0 3px var(--accent), var(--shadow-lg); }
.kin-detail-btn { margin-top: 6px; }
@media (max-width: 720px) {
  .kin-panel { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-width: none; border-radius: 12px 12px 0 0; max-height: 70vh; overflow-y: auto; }
}
