/* ======================================================================
   Родословная — визуальный язык «архивной описи»:
   тёмная бумага, чернильные линии, антиква для имён.
   + светлая тема и кастомные скроллеры.
   ====================================================================== */

:root {
  --ink-900: #14161c;
  --ink-800: #1b1e26;
  --ink-700: #232732;
  --ink-600: #2f3441;
  --ink-500: #434a5c;

  --paper:   #e8e4dc;
  --paper-2: #a9a396;
  --paper-3: #6f6a60;

  --brass:   #c9a35b;
  --brass-d: #a8843f;

  --verd:    #5b87c4;
  --rose:    #c47b9c;
  --slate:   #8a8f98;
  --danger:  #c46a5c;

  --r: 3px;
  --serif: "Cormorant Garamond", "PT Serif", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "DejaVu Sans Mono", Consolas, monospace;

  /* для скроллеров */
  --scrollbar-track: var(--ink-800);
  --scrollbar-thumb: var(--ink-500);
  --scrollbar-thumb-hover: var(--ink-600);
}

/* Светлая тема */
body.light-theme {
  --ink-900: #f5f2eb;
  --ink-800: #ece8df;
  --ink-700: #e2ddd3;
  --ink-600: #cbc5b8;
  --ink-500: #b0a898;

  --paper:   #1e1b16;
  --paper-2: #4a433a;
  --paper-3: #6f685d;

  --brass:   #b8862e;
  --brass-d: #9e7524;

  --danger:  #b13e30;

  --scrollbar-track: var(--ink-800);
  --scrollbar-thumb: var(--ink-500);
  --scrollbar-thumb-hover: var(--ink-600);

  /* Цвета пола те же по смыслу, но на светлом фоне пастельные оттенки
     теряются — берём на пару тонов темнее, чтобы контраст сохранялся. */
  --verd:  #3a6ba8;   /* мужской  — синий  */
  --rose:  #a8517a;   /* женский  — розовый */
  --slate: #6a7078;   /* не указан — серый  */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* === Кастомные скроллеры === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 3px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* Firefox */
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track); }

body {
  background: var(--ink-900);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

/* ------------------------------------------------------- кнопки/поля */
.btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  background: var(--ink-700);
  color: var(--paper);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--ink-600); border-color: var(--ink-500); }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.btn-primary {
  background: var(--brass);
  border-color: var(--brass);
  color: #1a1712;
  font-weight: 600;
}
.btn-primary:hover { background: var(--brass-d); border-color: var(--brass-d); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--ink-700); }
.btn-ghost.danger { color: var(--danger); border-color: transparent; }
.btn-ghost.danger:hover { background: rgba(196,106,92,.12); }

.btn-wide { width: 100%; }
.btn-icon {
  width: 30px; height: 30px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 17px; line-height: 1;
}

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--ink-900);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brass);
}
input::placeholder { color: var(--paper-3); }
textarea { resize: vertical; min-height: 64px; }

/* ---------------------------------------------------- поле заметки */
.note-wrap { position: relative; }
#m-note {
  min-height: 90px;
  max-height: 45vh;
  line-height: 1.55;
  font-family: var(--sans);
}
.note-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
.note-expand {
  background: none;
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  color: var(--paper-2);
  font-family: var(--sans);
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
}
.note-expand:hover { background: var(--ink-700); color: var(--paper); }
.note-full {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  background: var(--ink-800);
  padding: 18px;
}
.note-full .note-head { margin-bottom: 10px; }
.note-full #m-note {
  flex: 1;
  max-height: none;
  min-height: 0;
  font-size: 15px;
}
.note-full .note-title {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--paper-2);
}

.select {
  width: auto;
  min-width: 170px;
  padding: 7px 28px 7px 10px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236f6a60'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 6px;
  cursor: pointer;
}
.error {
  padding: 9px 11px;
  margin-bottom: 12px;
  background: rgba(196,106,92,.12);
  border-left: 2px solid var(--danger);
  color: #e0a196;
  font-size: 13px;
}

/* ------------------------------------------------------------- вход */
.auth-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background-image:
    linear-gradient(rgba(255,255,255,.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.014) 1px, transparent 1px);
  background-size: 28px 28px;
}
.auth-layout {
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: 1.1fr 380px;
  align-items: stretch;
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: 0 30px 70px rgba(0,0,0,.35);
}

/* -------- левая панель: подпись продукта + декоративный мотив -------- */
.auth-brand {
  position: relative;
  overflow: hidden;
  padding: 44px 38px;
  background: var(--ink-900);
  border-right: 1px solid var(--ink-600);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.auth-brand-motif {
  position: absolute;
  top: 50%; right: -8%;
  width: 78%; height: auto;
  transform: translateY(-50%);
  opacity: .16;
  pointer-events: none;
}
.auth-brand-motif .motif-lines line {
  stroke: var(--brass);
  stroke-width: 1.5;
}
.auth-brand-motif .motif-nodes circle {
  fill: var(--ink-900);
  stroke: var(--brass);
  stroke-width: 1.5;
}
.auth-brand > * { position: relative; z-index: 1; }
.auth-features {
  list-style: none;
  margin: 26px 0 0;
  padding: 18px 0 0;
  border-top: 1px solid var(--ink-600);
  display: flex; flex-direction: column; gap: 14px;
}
.auth-features li {
  display: flex; flex-direction: column; gap: 2px;
}
.auth-features li > span:first-child {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--paper);
}
.auth-features li > span:last-child {
  font-size: 12.5px;
  color: var(--paper-3);
  line-height: 1.5;
}

/* -------------------------------------------------- карточка формы */
.auth-card {
  width: 100%;
  padding: 34px 30px;
  background: var(--ink-800);
}
.auth-card-head { display: none; }
.auth-mark {
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: .18em;
  color: var(--brass);
  margin-bottom: 8px;
}
.auth-sub {
  color: var(--paper-2);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 22px;
}

@media (max-width: 860px) {
  .auth-layout {
    grid-template-columns: 1fr;
    max-width: 380px;
    box-shadow: none;
  }
  .auth-brand { display: none; }
  .auth-card { border-top: 2px solid var(--brass); border-radius: var(--r); }
  .auth-card-head { display: block; }
}
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--ink-600);
}
.tab {
  flex: 1;
  padding: 9px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--paper-3);
  font-family: var(--sans);
  font-size: 13px;
  cursor: pointer;
}
.tab.active { color: var(--brass); border-bottom-color: var(--brass); }
.tab:hover:not(.active) { color: var(--paper-2); }

/* -------------------------------------------------------- каркас */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center;
  gap: 0 8px;
  padding: 9px 14px;
  background: var(--ink-800);
  border-bottom: 1px solid var(--ink-600);
  flex-wrap: nowrap;
  overflow: visible;
  min-height: 48px;
}
.brand {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .16em;
  color: var(--brass);
  white-space: nowrap;
  flex-shrink: 0;
}
.topbar-right {
  display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; flex-shrink: 0;
  margin-left: auto;
}

/* ---- иконки интерфейса (спрайт #ic-* в index.html) ----
   Штриховые, наследуют цвет текста кнопки — в отличие от эмодзи,
   которые рисовались шрифтом ОС и выглядели по-разному везде. */
.ic {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic-caret {
  width: 13px; height: 13px;
  opacity: .65;
  transition: transform .15s ease;
}
.hmenu-trigger[aria-expanded="true"] .ic-caret { transform: rotate(180deg); }
.btn-with-ic {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

/* ---- зоны шапки ----
   Раньше всё лежало одним рядом в .topbar-right. Теперь три смысловые
   группы: что открыто | что можно сделать | помощь и аккаунт. */
.topbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.topbar-tree {
  gap: 8px;
  padding-left: 14px;
  margin-left: 10px;
  border-left: 1px solid var(--ink-600);
  min-width: 0;
}
.topbar-actions {
  gap: 6px;
  padding-left: 14px;
  margin-left: 4px;
  border-left: 1px solid var(--ink-600);
}
.topbar-end {
  margin-left: auto;
  gap: 4px;
}
.topbar-group .btn,
.topbar-group .select,
.topbar-group .lang-select {
  height: 32px;
  padding-top: 0;
  padding-bottom: 0;
}
/* Строка внутри выпадающего меню, где живёт не кнопка, а контрол
   (сейчас — выбор языка). */
.hmenu-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 16px;
  font-size: 13px;
  color: var(--paper);
  white-space: nowrap;
}
.hmenu-row .select {
  margin-left: auto;
  min-width: 108px;
  height: 28px;
  font-size: 12.5px;
}
/* п.9: единообразная высота всех кнопок и контролов в шапке */
.topbar-right .btn,
.topbar-right .select,
.topbar-right .theme-toggle,
.topbar-right .lang-select {
  height: 32px;
  padding-top: 0;
  padding-bottom: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
}
.user-email {
  font-size: 12px;
  color: var(--paper-3);
  font-family: var(--mono);
  padding: 0 6px;
}

.layout { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 302px;
  flex-shrink: 0;
  background: var(--ink-800);
  border-right: 1px solid var(--ink-600);
  overflow-y: auto;
  padding: 16px;
  transition: width 0.2s, padding 0.2s, opacity 0.2s;
}
/* Старое правило схлопывало панель в ноль вместе с кнопкой
   «Развернуть» (п.47). Актуальное правило — ниже по файлу. */
.panel { margin-bottom: 26px; }
.panel-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--paper-2);
  margin-bottom: 11px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--ink-600);
}
.hint {
  font-size: 12px;
  line-height: 1.55;
  color: var(--paper-3);
  margin-bottom: 10px;
}

/* --------------------------------------------------------- списки */
.person-list, .family-list { list-style: none; margin-top: 11px; }

.person-item, .family-item {
  padding: 9px 10px;
  margin-bottom: 5px;
  background: var(--ink-700);
  border: 1px solid transparent;
  border-left: 2px solid var(--ink-500);
  border-radius: var(--r);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.person-item:hover, .family-item:hover {
  background: var(--ink-600);
  border-color: var(--ink-500);
}
.person-item.sex-M { border-left-color: var(--verd); }
.person-item.sex-F { border-left-color: var(--rose); }
.person-item.sex-U { border-left-color: var(--slate); }

.person-name {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--paper);
}
.person-meta, .family-meta {
  font-size: 11px;
  color: var(--paper-3);
  font-family: var(--mono);
  margin-top: 2px;
}
.family-item { border-left-color: var(--brass); }
.family-title { font-size: 13px; color: var(--paper); }

.empty-list {
  padding: 12px 4px;
  color: var(--paper-3);
  font-size: 12px;
  font-style: italic;
}

/* --------------------------------------------------------- полотно */
.canvas-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.canvas-toolbar {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 14px;
  background: var(--ink-800);
  border-bottom: 1px solid var(--ink-600);
  flex-wrap: wrap;
  min-height: 40px;
}
.canvas-toolbar .select,
.canvas-toolbar .btn,
.canvas-toolbar .btn-icon {
  height: 30px;
  padding-top: 0;
  padding-bottom: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.zoom-level {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--paper-2);
  min-width: 44px;
  text-align: center;
}
.legend {
  margin-left: auto;
  display: flex; gap: 13px; flex-wrap: wrap;
  font-size: 11px;
  color: var(--paper-3);
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 9px; height: 9px; border-radius: 1px; display: inline-block; }
.sw-m { background: var(--verd); }
.sw-f { background: var(--rose); }
.sw-u { background: var(--slate); }
.line-dash {
  width: 15px; height: 0;
  border-top: 1px dashed var(--paper-3);
  display: inline-block;
}
/* Кнопка «Люди» в тулбаре — только в мобильной раскладке (см. медиазапрос
   ≤880px), на десктопе список и так открыт в боковой панели. */
.mobile-only { display: none; }

.canvas {
  flex: 1;
  overflow: hidden;
  position: relative;
  background-color: var(--ink-900);
  background-image:
    linear-gradient(rgba(255,255,255,.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.012) 1px, transparent 1px);
  background-size: 26px 26px;
  cursor: default;
  touch-action: none;
  overscroll-behavior: contain;
}
.canvas.grab { cursor: grab; }
.canvas.grabbing { cursor: grabbing; }

.viewport {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  /* will-change: transform УБРАН намеренно.
     Он выделял для #viewport постоянный GPU-слой, из-за чего браузер
     растрировал SVG ОДИН РАЗ в текущем масштабе и дальше растягивал
     готовый битмап — отсюда «мыло» при зуме 348%. Без will-change
     браузер перерисовывает вектор на каждом шаге зума и он остаётся
     чётким. transform всё равно уходит на GPU при активном жесте. */
}
/* Пока идёт активный жест (drag/zoom) — включаем GPU-слой для плавности.
   Класс вешается/снимается из JS на время взаимодействия (п.2). */
.viewport.interacting {
  will-change: transform;
}

#tree-svg {
  display: block;
  /* image-rendering: crisp-edges / optimize-contrast УБРАНЫ.
     Эти значения предназначены для пиксель-арта: они ОТКЛЮЧАЮТ
     сглаживание при масштабировании. На векторном SVG это давало
     рваные, «шакальные» края текста и линий при увеличении.
     Значение по умолчанию (auto) масштабирует вектор гладко. */
  image-rendering: auto;
}
#tree-svg image {
  image-rendering: auto;         /* фото — сглаживание, не пиксели */
}
#tree-svg text {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.canvas-hint {
  position: absolute;
  left: 14px; bottom: 12px;
  font-size: 11px;
  color: var(--paper-3);
  opacity: .5;
  pointer-events: none;
  user-select: none;
}
@media (max-width: 860px) { .canvas-hint { display: none; } }

/* Состояние «дерево пусто»: контейнер по центру канваса, клики сквозь него
   не нужны — карточка ниже сама получает их (pointer-events: auto). (п.10) */
.empty-state {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 40px 20px;
  text-align: center;
  pointer-events: none;
}
.empty-state p { font-family: var(--serif); font-size: 19px; color: var(--paper-2); }
.empty-state .muted { font-family: var(--sans); font-size: 13px; color: var(--paper-3); margin-top: 5px; }

/* --------------------------------- узлы SVG (стили — здесь, не в JS) */
.node-card {
  fill: var(--ink-700);
  stroke: var(--ink-600);
  stroke-width: 1;
  cursor: pointer;
  transition: stroke .15s;
}
.node-card:hover { stroke: var(--brass); }
/* Фокус клавиатуры на карточке дерева (п.21) */
.node-group:focus { outline: none; }
.node-group:focus .node-card { stroke: var(--brass); stroke-width: 2; }
/* Цвет пола карточки — один раз ниже, в «КАРТОЧКИ ДРЕВА» (п.11).
   (здесь был дубликат .node-accent-M/F/U, удалён) */

.node-name {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  fill: var(--paper);
  pointer-events: none;
}
.node-dates {
  font-family: var(--mono);
  font-size: 10px;
  fill: var(--paper-3);
  pointer-events: none;
}
.edge {
  stroke: var(--ink-500);
  stroke-width: 1.4;
  fill: none;
}
.edge-adopted { stroke-dasharray: 4 3; }
.union-dot { fill: var(--brass); }
.union-label {
  font-family: var(--mono);
  font-size: 9px;
  fill: var(--paper-3);
  text-anchor: middle;
  pointer-events: none;
}

/* -------------------------------------------------------- модалка */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(8,9,12,.76);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal {
  width: 100%; max-width: 440px;
  max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-top: 2px solid var(--brass);
  border-radius: var(--r);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--ink-600);
}
.modal-head h3 {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
}
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 13px 18px;
  border-top: 1px solid var(--ink-600);
}
.row { display: flex; gap: 11px; }
.row > * { flex: 1; }

.check-list { max-height: 190px; overflow-y: auto; border: 1px solid var(--ink-600); border-radius: var(--r); padding: 4px; }
.check-row {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: var(--r);
}
.check-row:hover { background: var(--ink-700); }
.check-row input { width: auto; }
.check-row span { font-family: var(--serif); font-size: 15px; }

.link-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 9px;
  margin-bottom: 4px;
  background: var(--ink-700);
  border-radius: var(--r);
  font-size: 13px;
}
.link-row .remove {
  background: none; border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
.subhead {
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--paper-2);
  margin: 16px 0 8px;
}

/* ---------------------------------------------------------- тост */
.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  padding: 11px 18px;
  background: var(--ink-700);
  border: 1px solid var(--ink-500);
  border-left: 2px solid var(--brass);
  border-radius: var(--r);
  font-size: 13px;
  z-index: 200;
  max-width: 90vw;
}
.toast.err { border-left-color: var(--danger); }

/* -------------------------------------------------------- адаптив */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- остальные стили (поиск, галерея, статистика и т.д.) ---- */
.search-input {
  width: 100%;
  padding: 7px 10px;
  margin-bottom: 10px;
  background: var(--ink-900);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  color: var(--paper);
}
#avatar-section img {
  background: var(--ink-700);
}
#gallery-container button {
  margin: 2px;
}

/* Вид древа */
.canvas-toolbar #view-mode { min-width: 150px; }
.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--ink-600);
  margin: 0 4px;
}
.focus-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 10px;
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  max-width: 260px;
  line-height: 1;
}
.focus-label {
  font-size: 11px;
  color: var(--paper-3);
  text-transform: uppercase;
  letter-spacing: .08em;
  line-height: 1;
  flex-shrink: 0;
}
.focus-name {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--brass);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.focus-name.empty { color: var(--paper-3); font-style: italic; font-size: 13px; }

.depth-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.depth-box label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  color: var(--paper-2);
}
.depth-box input {
  width: 46px;
  padding: 4px 6px;
  text-align: center;
  font-size: 13px;
  background: var(--ink-700);
  border: 1px solid var(--ink-500);
  color: var(--paper);
  border-radius: var(--r);
}
.depth-box input:focus {
  border-color: var(--brass);
  outline: none;
}
.view-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--paper-3);
  white-space: nowrap;
}

.person-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.person-body { flex: 1; min-width: 0; }
.focus-btn {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: var(--paper-3);
  font-size: 15px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, color .12s, border-color .12s;
}
.person-item:hover .focus-btn { opacity: 1; }
.focus-btn:hover {
  color: var(--brass);
  border-color: var(--ink-500);
}
.person-item.is-focus .focus-btn {
  opacity: 1;
  color: var(--brass);
  border-color: var(--brass);
}
.person-item.is-focus { background: var(--ink-600); }

.node-card.is-focus {
  stroke: var(--brass);
  stroke-width: 2;
}

@media (max-width: 860px) {
  .focus-box { max-width: 150px; }
  .depth-box .view-count { display: none; }
}

/* Статистика */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}
.stat {
  text-align: center;
  padding: 12px 6px;
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
}
.stat b {
  display: block;
  font-family: var(--serif);
  font-size: 24px;
  color: var(--brass);
  line-height: 1.1;
}
.stat span {
  font-size: 11px;
  color: var(--paper-3);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.stat-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stat-table td { padding: 7px 0; border-bottom: 1px solid var(--ink-700); }
.stat-table td:last-child {
  text-align: right;
  font-family: var(--mono);
  color: var(--brass);
  white-space: nowrap;
}

.gen-chart { display: flex; flex-direction: column; gap: 3px; }
.gen-row { display: flex; align-items: center; gap: 8px; height: 18px; }
.gen-label {
  flex: 0 0 22px;
  text-align: right;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--paper-3);
}
.gen-bar {
  height: 11px;
  min-width: 2px;
  background: var(--brass);
  opacity: .75;
  border-radius: 1px;
}
.gen-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--paper-2);
}

/* Родство и архивы */
.relation-card {
  padding: 11px 13px;
  background: var(--ink-700);
  border-left: 2px solid var(--brass);
  border-radius: var(--r);
  font-size: 14px;
  line-height: 1.5;
}
.rel-word {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--brass);
  font-weight: 600;
}
.relation-card .muted { color: var(--paper-3); font-size: 13px; }

.arch-links { display: flex; flex-direction: column; gap: 6px; }
.arch-link {
  display: block;
  padding: 9px 11px;
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
.arch-link:hover { border-color: var(--brass); background: var(--ink-600); }
.arch-link b { display: block; color: var(--brass); font-size: 14px; }
.arch-link span { font-size: 12px; color: var(--paper-3); }
.arch-links code {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--paper-2);
  background: var(--ink-900);
  padding: 1px 5px;
  border-radius: 2px;
}

@media (max-width: 860px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Контекстное меню */
.context-menu {
  position: fixed;
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  padding: 4px 0;
  min-width: 180px;
  z-index: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.context-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.context-menu li {
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--paper);
}
.context-menu li:hover {
  background: var(--ink-600);
}
.context-menu li.danger {
  color: var(--danger);
}
.context-menu li.danger:hover {
  background: rgba(196,106,92,0.15);
}

.invite-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--ink-600);
}

.person-item .menu-btn {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: var(--paper-3);
  font-size: 18px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, color .12s, border-color .12s;
}
.person-item:hover .menu-btn {
  opacity: 1;
}
.person-item .menu-btn:hover {
  color: var(--brass);
  border-color: var(--ink-500);
}

/* Расширенная статистика */
.modal-lg {
  max-width: 95vw !important;
  max-height: 95vh !important;
  width: 95vw !important;
  height: 95vh !important;
}
.modal-lg .modal-body {
  overflow-y: auto;
  max-height: calc(95vh - 120px);
}

.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.stat-card {
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  padding: 10px 6px;
  text-align: center;
}
.stat-card b {
  display: block;
  font-family: var(--serif);
  font-size: 24px;
  color: var(--brass);
  line-height: 1.2;
}
.stat-card span {
  font-size: 11px;
  color: var(--paper-3);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.stats-charts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.chart-box {
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  padding: 10px;
}
.chart-box h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--paper-2);
  margin-bottom: 6px;
  text-align: center;
}
.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}
.stats-tables {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.stats-table-wrap {
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  padding: 10px;
}
.stats-table-wrap h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--paper-2);
  margin-bottom: 6px;
}
.stats-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.stats-table-wrap td {
  padding: 4px 0;
  border-bottom: 1px solid var(--ink-600);
}
.stats-table-wrap td:last-child {
  text-align: right;
  font-family: var(--mono);
  color: var(--brass);
}

@media (max-width: 600px) {
  .stats-cards { grid-template-columns: repeat(2, 1fr); }
  .stats-charts { grid-template-columns: 1fr; }
  .stats-tables { grid-template-columns: 1fr; }
}

/* Аватары в списке */
.list-ava {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--ink-600);
  display: flex;
  align-items: center;
  justify-content: center;
}
.list-ava img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.list-ava.ph {
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 600;
  color: var(--paper-2);
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
}
.person-item.sex-M .list-ava.ph { color: var(--verd); }
.person-item.sex-F .list-ava.ph { color: var(--rose); }

/* SVG аватары */
.node-ava-ring {
  fill: none;
  stroke: var(--ink-500);
  stroke-width: 1;
}
.node-ava-ph {
  fill: var(--ink-900);
  stroke: var(--ink-500);
  stroke-width: 1;
}
.node-ava-ph.accent-M { stroke: var(--verd); }
.node-ava-ph.accent-F { stroke: var(--rose); }
.node-ava-ph.accent-U { stroke: var(--slate); }
.node-ava-txt {
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 600;
  fill: var(--paper-3);
  pointer-events: none;
}

/* Кнопка переключения темы и другие мелкие правки */
.theme-toggle {
  background: none;
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  padding: 4px 8px;
  color: var(--paper-2);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.theme-toggle:hover {
  background: var(--ink-700);
  color: var(--paper);
}

/* ======================================================================
   ВОССТАНОВЛЕНО ИЗ ПРЕДЫДУЩЕЙ РЕДАКЦИИ
   ====================================================================== */
.avatar-thumb {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--ink-600);
}
.person-info { flex: 1; min-width: 0; }

/* ======================================================================
   КАРТОЧКИ ДРЕВА
   ====================================================================== */

/* Цвет пола — единая точка правды: синий / розовый / серый.
   Применяется и к полосе мелкой карточки, и к кольцу аватара. */
.node-accent-M { fill: var(--verd); }
.node-accent-F { fill: var(--rose); }
.node-accent-U { fill: var(--slate); }

.node-ring-M { stroke: var(--verd); }
.node-ring-F { stroke: var(--rose); }
.node-ring-U { stroke: var(--slate); }

.node-ava-ph { fill: var(--ink-900); stroke-width: 1.5; }
.node-ava-ph.accent-M { stroke: var(--verd); }
.node-ava-ph.accent-F { stroke: var(--rose); }
.node-ava-ph.accent-U { stroke: var(--slate); }
.node-ava-txt { font-family: var(--serif); font-weight: 600; fill: var(--paper-3); }

/* «Пилюля» с датами жизни на крупной карточке */
.node-datepill {
  fill: var(--ink-900);
  stroke: var(--ink-600);
  stroke-width: 1;
}
.node-age {
  font-family: var(--sans);
  fill: var(--paper-3);
  letter-spacing: .4px;
}

/* ---------------------------------------------------------------
   Кнопки на карточке («⋯» и «+»).
   Обе лежат ВНУТРИ границ карточки, поэтому не срезаются на
   экспорте в PDF/PNG. По умолчанию приглушены, проявляются
   при наведении на карточку.
   --------------------------------------------------------------- */
.node-btn { cursor: pointer; opacity: .28; transition: opacity .15s; }
.node-group:hover .node-btn { opacity: 1; }
.node-btn:hover .node-btn-bg { fill: var(--brass); }
.node-btn:hover .node-btn-glyph { fill: #1a1712; }

.node-btn-bg {
  fill: var(--ink-600);
  stroke: var(--ink-500);
  stroke-width: 1;
}
.node-btn-glyph {
  fill: var(--paper);
  font-family: var(--sans);
  font-weight: 600;
  pointer-events: none;
}

/* На печати элементы управления деревом не нужны вовсе: кнопки карточек,
   оверлей «добавить связь» и его «пилюли», подсказка канваса (п.13).
   (Экспорт в файл и так идёт через print.js, который вырезает их из DOM.) */
@media print {
  .node-btn,
  .relation-overlay-layer,
  .rel-overlay-html,
  .rel-pill-html,
  .canvas-hint {
    display: none !important;
  }
}

/* ======================================================================
   ОВЕРЛЕЙ «ДОБАВИТЬ СВЯЗЬ»
   ====================================================================== */

/* Пока меню открыто, остальные карточки уходят на второй план,
   чтобы взгляд держался на выбранной персоне. */
.node-group.is-dimmed { opacity: .22; transition: opacity .2s; }
.node-group.is-active .node-card {
  stroke: var(--brass);
  stroke-width: 2;
}

.rel-line {
  stroke: var(--paper-3);
  stroke-width: 1.6;
  fill: none;
}

.rel-pill { transition: transform .12s; }
.rel-pill-bg {
  stroke-width: 1.5;
  fill: var(--ink-700);
  stroke: var(--ink-500);
}
.rel-pill-tx {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  fill: var(--paper);
  pointer-events: none;
}

/* Зелёные — как в макете: действие «добавить». */
.rel-pill-add .rel-pill-bg,
.rel-pill-opt .rel-pill-bg {
  fill: rgba(122, 176, 122, .16);
  stroke: rgba(122, 176, 122, .55);
}
.rel-pill-add .rel-pill-tx,
.rel-pill-opt .rel-pill-tx { fill: #7ab07a; }

.rel-pill-add:hover .rel-pill-bg,
.rel-pill-opt:hover .rel-pill-bg {
  fill: rgba(122, 176, 122, .30);
  stroke: #7ab07a;
}

/* Розовая — «Назад». */
.rel-pill-back .rel-pill-bg {
  fill: rgba(196, 106, 92, .14);
  stroke: rgba(196, 106, 92, .45);
}
.rel-pill-back .rel-pill-tx { fill: var(--danger); }
.rel-pill-back:hover .rel-pill-bg {
  fill: rgba(196, 106, 92, .26);
  stroke: var(--danger);
}

body.light-theme .rel-pill-add .rel-pill-bg,
body.light-theme .rel-pill-opt .rel-pill-bg {
  fill: rgba(60, 140, 60, .14);
  stroke: rgba(60, 140, 60, .5);
}
body.light-theme .rel-pill-add .rel-pill-tx,
body.light-theme .rel-pill-opt .rel-pill-tx { fill: #2f7a2f; }

/* ======================================================================
   ПУСТОЕ ДРЕВО
   ====================================================================== */
.empty-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 30px 34px;
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  pointer-events: auto; /* клики работают, пока контейнер выше их пропускает */
}
.empty-card:hover {
  border-color: var(--brass);
  background: var(--ink-600);
}
.empty-card .ava {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: var(--ink-900);
  border: 2px solid var(--slate);
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; color: var(--paper-3);
}
.empty-card .cap {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--paper-2);
}

/* ======================================================================
   ПЕРЕИМЕНОВАНИЕ ДРЕВА (инлайн, как в Google Docs)
   ====================================================================== */
.tree-name-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 1;
  min-width: 0;
}
.tree-name {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--paper);
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: text;
  max-width: 200px;
  min-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-name:hover { border-color: var(--ink-600); }
.tree-name.editing {
  border-color: var(--brass);
  background: var(--ink-900);
  outline: none;
  cursor: text;
  white-space: pre;
  overflow: visible;
  text-overflow: clip;
}
.tree-name-pencil {
  opacity: 0;
  color: var(--paper-3);
  width: 14px;
  height: 14px;
  transition: opacity .15s;
  pointer-events: none;
}
.tree-name-wrap:hover .tree-name-pencil { opacity: 1; }

/* ======================================================================
   ЛЕВАЯ ПАНЕЛЬ: кнопка сворачивания теперь ВНУТРИ панели
   ====================================================================== */
.sidebar { position: relative; }

.sidebar-collapse {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 5;
  width: 26px; height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 13px;
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  color: var(--paper-2);
  cursor: pointer;
}
.sidebar-collapse:hover { color: var(--paper); border-color: var(--ink-500); }

/* Кнопка сворачивания в правом верхнем углу панели не должна наезжать
   на заголовок первого блока (п.22). */
.sidebar > .panel:first-child .panel-title {
  padding-right: 40px;
}
@media (max-width: 420px) {
  .sidebar-collapse { display: none; }
}

/* В свёрнутом виде панель превращается в узкую полосу,
   но кнопка «развернуть» остаётся доступной. */
.sidebar.collapsed {
  width: 40px;
  min-width: 40px;
  padding: 0;
  overflow: hidden;
}
.sidebar.collapsed .panel { display: none; }
.sidebar.collapsed .sidebar-collapse { right: 7px; }

/* ======================================================================
   РЕЖИМ ПРОСМОТРА (все панели свёрнуты, редактирование выключено)
   ====================================================================== */
body.view-mode .sidebar,
body.view-mode #btn-add-person,
body.view-mode #btn-delete-tree,
body.view-mode #btn-import,
body.view-mode #btn-share { display: none !important; }

body.view-mode .canvas-wrap { border-left: none; }

.viewmode-exit {
  position: fixed;
  top: 12px; right: 12px;
  z-index: 60;
}

/* ======================================================================
   ЖУРНАЛ ИЗМЕНЕНИЙ
   ====================================================================== */
.log-list { display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow-y: auto; }

.log-row {
  display: grid;
  grid-template-columns: 50px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-left: 3px solid transparent;
  border-radius: var(--r);
  transition: background .12s;
}
.log-row:hover { background: rgba(255,255,255,.04); }
.log-row:nth-child(odd) { background: rgba(255,255,255,.02); }
.log-row:hover:nth-child(odd) { background: rgba(255,255,255,.05); }
body.light-theme .log-row:nth-child(odd) { background: rgba(0,0,0,.025); }
body.light-theme .log-row:hover { background: rgba(0,0,0,.04); }

.log-row.act-create { border-left-color: #7ab07a; }
.log-row.act-update { border-left-color: var(--brass); }
.log-row.act-delete { border-left-color: var(--danger); }

.log-time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--paper-3);
  white-space: nowrap;
}
.log-text { font-size: 13px; color: var(--paper); line-height: 1.4; }
.log-user { color: var(--paper-3); font-size: 12px; }

.log-actions {
  display: flex; gap: 4px; align-items: center;
  opacity: 0; transition: opacity .15s;
}
.log-row:hover .log-actions { opacity: 1; }

.log-actions .btn {
  width: 32px; height: 32px;
  padding: 0; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; font-size: 15px;
  background: var(--ink-700); border: 1px solid var(--ink-600);
  color: var(--paper-2); transition: background .12s, color .12s;
}
.log-actions .btn:hover { background: var(--ink-600); color: var(--paper); }
.log-actions .btn.danger:hover { background: var(--danger); color: #fff; }

.log-day {
  font-family: var(--sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--paper-3);
  margin: 14px 0 4px;
  padding-left: 10px;
}

/* ======================================================================
   МОДАЛКА ЭКСПОРТА GEDCOM
   ====================================================================== */

/* ---------- Автокомплит населённых пунктов ---------- */
.place-dropdown {
  z-index: 120; /* над модалкой, без космических значений (п.15) */
  max-height: 220px;
  overflow-y: auto;
  background: var(--ink-800);
  border: 1px solid var(--ink-500);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  padding: 4px 0;
}
body.light-theme .place-dropdown {
  background: #fff;
  border-color: #d0d0d0;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.place-dropdown-item {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--paper);
  cursor: pointer;
  transition: background .1s;
}
.place-dropdown-item:hover,
.place-dropdown-item.active {
  background: var(--ink-600);
}
body.light-theme .place-dropdown-item:hover,
body.light-theme .place-dropdown-item.active {
  background: #e8e4dc;
}

.export-note {
  font-size: 13px;
  line-height: 1.6;
  color: var(--paper-2);
  background: var(--ink-900);
  border-left: 2px solid var(--brass);
  padding: 12px 14px;
  border-radius: var(--r);
  margin-bottom: 14px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  cursor: pointer;
}
.check-row input { width: auto; }

/* ======================================================================
   КАРТОЧКА ПЕРСОНЫ В РЕЖИМЕ ЧТЕНИЯ (п.24)
   ====================================================================== */
.view-card { display: flex; gap: 18px; align-items: flex-start; }

.view-ava {
  flex: 0 0 auto;
  width: 96px; height: 96px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--ink-900);
  border: 2px solid var(--ink-600);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif);
  font-size: 30px;
  color: var(--paper-3);
}
.view-ava img { width: 100%; height: 100%; object-fit: cover; }

.view-facts { flex: 1; min-width: 0; }

.view-row {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--ink-600);
}
.view-row:last-child { border-bottom: none; }

.view-label {
  font-size: 12px;
  color: var(--paper-3);
  text-transform: uppercase;
  letter-spacing: .6px;
}
.view-value {
  font-size: 14px;
  color: var(--paper);
  word-break: break-word;
}

/* ======================================================================
   ФОРМА ПЕРСОНЫ (п.16)
   ====================================================================== */

/* б) аватар */
.pf-avatar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.pf-ava-img {
  width: 76px; height: 76px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--ink-900);
  border: 2px solid var(--ink-600);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  color: var(--paper-3);
  flex: 0 0 auto;
}
.pf-ava-img img { width: 100%; height: 100%; object-fit: cover; }

.pf-name-hint { margin-top: 4px; font-size: 11px; }

/* г/з) радиокнопки в строку */
.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 4px 0;
}
.radio-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  margin: 0;
}
.radio-row input { width: auto; margin: 0; }

/* д) свич режима даты */
.date-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.date-mode {
  font-family: var(--sans);
  font-size: 12px;
  padding: 5px 11px;
  border: 1px solid var(--ink-600);
  background: transparent;
  color: var(--paper-2);
  border-radius: var(--r);
  cursor: pointer;
}
.date-mode:hover { border-color: var(--ink-500); color: var(--paper); }
.date-mode.active {
  background: var(--brass);
  border-color: var(--brass);
  color: #1a1712;
  font-weight: 600;
}

.date-approx {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--paper-2);
  cursor: pointer;
  margin: 0;
}
.date-approx input { width: auto; margin: 0; }
/* Чекбокс осмыслен только в свободной форме — в остальных случаях гасим. */
.date-approx.disabled { opacity: .4; cursor: not-allowed; }

/* л) повторяемые факты */
.fact-group { margin-bottom: 14px; }
.fact-group > label {
  display: block;
  font-size: 12px;
  color: var(--paper-3);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 5px;
}
.fact-rows { display: flex; flex-direction: column; gap: 6px; }

.fact-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.fact-row input { flex: 1; min-width: 0; }
.fact-row .fact-detail { flex: 1.1; }
.fact-row .fact-date { flex: 0 0 118px; }

.fact-del {
  flex: 0 0 auto;
  width: 30px; height: 34px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  color: var(--paper-3);
  border-color: transparent;
}
.fact-del:hover { color: var(--danger); border-color: var(--danger); }

.fact-add {
  margin-top: 6px;
  font-size: 12px;
  padding: 5px 10px;
}

/* ж) поиск персоны для связи */
.rel-search { display: flex; gap: 6px; }
.rel-search input { flex: 1; min-width: 0; }
.rel-search .btn { flex: 0 0 auto; font-size: 16px; }

/* Режим выбора персоны на дереве */
body.picking-person .canvas { cursor: crosshair; }
body.picking-person .node-group:hover .node-card {
  stroke: var(--brass);
  stroke-width: 2.5;
}
body.picking-person .node-btn { display: none; }

.pick-banner {
  position: fixed;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--ink-700);
  border: 1px solid var(--brass);
  border-radius: var(--r);
  font-size: 14px;
  color: var(--paper);
  box-shadow: 0 6px 24px rgba(0,0,0,.35);
}

/* Широкая модалка формы: два столбца на просторных экранах */
.modal.modal-lg .modal-body { max-height: 72vh; }

@media (min-width: 980px) {
  .modal.modal-lg .modal-body .row { gap: 12px; }
}

/* ======================================================================
   ПЕРЕКЛЮЧАТЕЛЬ ЯЗЫКА (п.5)
   ====================================================================== */
.lang-select {
  width: auto;
  min-width: 92px;
  padding: 4px 26px 4px 8px;
  font-size: 13px;
}

/* ======================================================================
   СОЮЗЫ В КАРТОЧКЕ ПЕРСОНЫ
   Панель семей убрана из интерфейса, но править брак и развод нужно —
   делаем это прямо из карточки человека.
   ====================================================================== */
.union-list { display: flex; flex-direction: column; gap: 6px; }

.union-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: var(--ink-900);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
}
.union-row:hover { border-color: var(--ink-500); }

.union-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.union-partner {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--paper);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.union-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--paper-3);
}

.union-edit {
  flex: 0 0 auto;
  font-size: 12px;
  padding: 4px 10px;
  opacity: 0;
  transition: opacity .15s;
}
.union-row:hover .union-edit { opacity: 1; }
/* На тач-устройствах ховера нет — кнопка должна быть видна всегда. */
@media (hover: none) { .union-edit { opacity: 1; } }

/* ... существующие стили ... */

/* Выравнивание чек-боксов в настройках */
.field.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
}
.field.check-field label {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.field.check-field input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* Кнопка выхода из просмотра поверх всего */
.viewmode-exit {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 9999; /* выше всех */
}

/* Кнопка сворачивания панели всегда видна */
.sidebar-collapse {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
}
.sidebar.collapsed .sidebar-collapse {
  /* остаётся видимой */
}

/* Модальное окно не закрывается по клику на фон */
.modal-backdrop {
  /* Клик сквозь убран полностью: поле модалки экранирует клики по дереву
     (п.1). Закрытие по фону не предусмотрено — только крестик/кнопки. */
}
.modal {
  pointer-events: auto; /* внутри модалки клики работают */
}
/* ======================================================================
   ИСПРАВЛЕНИЯ РАСКЛАДКИ
   ====================================================================== */

/* п.47: свёрнутая панель остаётся полосой с кнопкой «Развернуть».
   Правило идёт последним, чтобы гарантированно перекрыть ранние. */
.sidebar.collapsed {
  width: 44px !important;
  min-width: 44px !important;
  padding: 0 !important;
  overflow: visible !important;
  opacity: 1 !important;
}
.sidebar.collapsed .panel { display: none; }
.sidebar.collapsed .sidebar-collapse {
  right: 9px;
  opacity: 1;
  visibility: visible;
}

/* п.48: кнопка выхода из просмотра больше не липнет к правому верхнему
   углу, где перекрывает панель инструментов. Уводим её вниз по центру —
   там пусто в любом режиме. */
.viewmode-exit {
  position: fixed !important;
  top: auto !important;
  bottom: 20px;
  left: 50%;
  right: auto !important;
  transform: translateX(-50%);
  z-index: 70;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .35);
}

/* п.49: чекбокс и его подпись на одной оси. */
.field label > input[type="checkbox"],
.field label > input[type="radio"] {
  width: auto;
  margin: 0 8px 0 0;
  vertical-align: middle;
  position: relative;
  top: -1px;
}
.field label:has(> input[type="checkbox"]),
.field label:has(> input[type="radio"]) {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.field label:has(> input[type="checkbox"]) > input,
.field label:has(> input[type="radio"]) > input {
  margin: 0;
  flex: 0 0 auto;
}

/* Ошибка под полем формы */
.field-error {
  margin-top: 5px;
  font-size: 12px;
  color: var(--danger);
}

/* Текст в модалке подтверждения (п.50) */
.confirm-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--paper);
  margin: 4px 0 8px;
}

/* ======================================================================
   ПРЕВЬЮ ФОТО ДО СОЗДАНИЯ ПЕРСОНЫ (п.25)
   ====================================================================== */
.staged-thumb {
  position: relative;
  width: 84px; height: 84px;
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--ink-900);
}
.staged-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Выбранный аватар выделяем рамкой — видно, какое фото главное. */
.staged-thumb.is-avatar {
  border-color: var(--brass);
  box-shadow: 0 0 0 2px var(--brass) inset;
}
.staged-thumb.is-avatar::after {
  content: "★";
  position: absolute;
  left: 4px; bottom: 2px;
  font-size: 13px;
  color: var(--brass);
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
}

.staged-del {
  position: absolute;
  top: 2px; right: 2px;
  width: 20px; height: 20px;
  padding: 0;
  line-height: 1;
  font-size: 14px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  color: #fff;
  cursor: pointer;
}
.staged-del:hover { background: var(--danger); }

/* Списки родителей и детей в карточке чтения (п.42) */
.rel-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.rel-chip {
  font-family: var(--serif);
  font-size: 14px;
  padding: 5px 12px;
  background: var(--ink-900);
  border: 1px solid var(--ink-600);
  border-radius: 14px;
  color: var(--paper);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.rel-chip:hover {
  border-color: var(--brass);
  background: var(--ink-700);
}

/* ======================================================================
   РЕДАКТОР СВЯЗЕЙ В ФОРМЕ ПРАВКИ (п.41)
   ====================================================================== */
.rel-edit-group { margin-bottom: 12px; }

.rel-edit-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--paper-3);
  margin-bottom: 5px;
}

.rel-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--ink-900);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  margin-bottom: 4px;
}
.rel-edit-row:hover { border-color: var(--ink-500); }

.rel-edit-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rel-edit-tag {
  flex: 0 0 auto;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 9px;
  background: var(--ink-700);
  color: var(--paper-3);
}

.rel-edit-del {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: var(--paper-3);
  border-color: transparent;
}
.rel-edit-del:hover { color: var(--danger); border-color: var(--danger); }

/* ======================================================================
   ПРОСМОТР ВЕРСИЙ И ОТКАТ (п.51)
   ====================================================================== */
/* Подсветка карточек, изменённых после выбранного момента */
.snap-changed .node-card {
  stroke: var(--brass);
  stroke-width: 2.5;
}
.snap-changed { filter: drop-shadow(0 0 6px rgba(201, 163, 91, .5)); }

.snap-what { color: var(--paper-3); font-size: 12px; }

.version-list { display: flex; flex-direction: column; gap: 4px; max-height: 46vh; overflow-y: auto; }

.version-row {
  padding: 8px 10px;
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  background: var(--ink-900);
}
.version-row:hover { border-color: var(--brass); }

/* Просмотр чужого древа админом из /admin (только чтение, см. loadAdminTree
   в app.js) — прячем создание/переименование/удаление, сервер такие
   запросы от админа всё равно отклонит (403), но лучше не показывать
   элементы, которые не сработают. */
body.admin-view-mode #btn-new-tree,
body.admin-view-mode .tree-name-pencil,
body.admin-view-mode #btn-delete-tree,
body.admin-view-mode #btn-import,
body.admin-view-mode #btn-add-person,
body.admin-view-mode #empty-add,
body.admin-view-mode .node-btn-add {
  display: none !important;
}
body.admin-view-mode .tree-name-wrap { cursor: default; }
body.admin-view-mode::after {
  content: "Режим администратора: только просмотр";
  position: fixed;
  top: 8px; left: 50%; transform: translateX(-50%);
  z-index: 500;
  background: var(--brass);
  color: var(--ink-900);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--r);
  pointer-events: none;
}

/* Просмотр состояния на момент времени поверх обычного древа (п.51):
   карточки и панорамирование/зум — те же, что в обычном режиме,
   меняется только нижняя панель с двумя действиями. */
.history-preview-bar {
  position: fixed;
  left: 50%; bottom: 22px;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px;
  padding: 10px 14px 10px 18px;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-top: 2px solid var(--brass);
  border-radius: var(--r);
  box-shadow: 0 8px 28px rgba(0,0,0,.35);
  z-index: 90;
  max-width: calc(100vw - 40px);
}
.history-preview-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
  color: var(--paper);
  white-space: nowrap;
}
.history-preview-icon { font-size: 15px; }
.history-preview-actions { display: flex; gap: 8px; flex-shrink: 0; }

body.history-preview-mode .sidebar,
body.history-preview-mode #btn-add-person {
  pointer-events: none;
  opacity: .5;
}
body.history-preview-mode .canvas-hint { visibility: hidden; }

@media (max-width: 720px) {
  .history-preview-bar {
    left: 12px; right: 12px; bottom: 12px;
    transform: none;
    max-width: none;
    flex-direction: column;
    align-items: stretch;
  }
  .history-preview-actions { justify-content: flex-end; }
}

/* ======================================================================
   HTML-ОВЕРЛЕЙ МЕНЮ СВЯЗЕЙ
   Заменяет SVG-кнопки: overflow:hidden на .canvas больше не обрезает.
   ====================================================================== */
/* Контейнер лежит ВНУТРИ #viewport и наследует его трансформацию,
   поэтому кнопки едут вместе с деревом при перетаскивании и зуме.
   Размеры нулевые: позиционируем детей абсолютно от точки 0,0
   в системе координат схемы. */
.rel-overlay-html {
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 20;
}

.rel-pill-html {
  position: absolute;
  pointer-events: auto;
  min-width: 160px;
  padding: 10px 18px;
  border-radius: 22px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  border: 1.5px solid;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
  z-index: 21;
}

.rel-pill-html.rel-pill-add {
  background: rgba(122,176,122,.14);
  border-color: rgba(122,176,122,.5);
  color: #7ab07a;
}
.rel-pill-html.rel-pill-add:hover {
  background: rgba(122,176,122,.28);
  border-color: #7ab07a;
}

.rel-pill-html.rel-pill-opt {
  background: rgba(122,176,122,.14);
  border-color: rgba(122,176,122,.5);
  color: #7ab07a;
}
.rel-pill-html.rel-pill-opt:hover {
  background: rgba(122,176,122,.28);
  border-color: #7ab07a;
}

.rel-pill-html.rel-pill-back {
  background: rgba(196,106,92,.12);
  border-color: rgba(196,106,92,.4);
  color: var(--danger);
}
.rel-pill-html.rel-pill-back:hover {
  background: rgba(196,106,92,.24);
  border-color: var(--danger);
}

body.light-theme .rel-pill-html.rel-pill-add,
body.light-theme .rel-pill-html.rel-pill-opt {
  background: rgba(60,140,60,.12);
  border-color: rgba(60,140,60,.45);
  color: #2f7a2f;
}

.rel-line-html {
  position: absolute;
  background: var(--paper-3);
  opacity: .5;
  pointer-events: none;
  z-index: 20;
}

/* п.9: галерея редактирования (в форме правки персоны) */
.gallery-edit-item {
  display: inline-flex; flex-direction: column; gap: 4px;
  width: 110px; padding: 6px; border-radius: 6px;
  background: var(--ink-700); border: 1px solid var(--ink-600);
  vertical-align: top;
}
.gallery-edit-img {
  width: 98px; height: 98px; object-fit: cover; border-radius: 4px; display: block;
}
.gallery-edit-note {
  width: 100%; font-size: 11px; padding: 3px 5px;
  background: var(--ink-800); border: 1px solid var(--ink-600);
  border-radius: 3px; color: var(--paper); outline: none;
}
.gallery-edit-note:focus { border-color: var(--brass); }
.gallery-edit-note::placeholder { color: var(--paper-3); }
.gallery-edit-btns {
  display: flex; gap: 2px; justify-content: space-between;
}
.gallery-edit-btn { font-size: 11px !important; padding: 1px 5px !important; }

/* п.10: сетка фото (в модалке альбома и в карточке просмотра) */
.photo-grid {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.photo-grid-inline { margin-top: 8px; }
.photo-grid-item {
  width: 120px; border-radius: 6px; overflow: hidden;
  background: var(--ink-700); cursor: pointer;
  border: 2px solid transparent; transition: border-color .15s, transform .1s;
}
.photo-grid-item:hover {
  border-color: var(--brass); transform: scale(1.03);
}
.photo-grid-item img {
  width: 120px; height: 120px; object-fit: cover; display: block;
}
.photo-grid-caption {
  font-size: 11px; color: var(--paper-3); padding: 3px 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* п.10: иконка фото на карточке древа */
.node-photo-icon {
  opacity: 0.85; transition: opacity .15s;
}
.node-photo-icon:hover { opacity: 1; }

/* ===== Lightbox (полноэкранный просмотр одного фото) ===== */
.lb-wrap {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  /* Занимает всю высоту modal-body */
  min-height: calc(90vh - 80px);
}
.lb-stage {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  flex: 1; width: 100%;
}
.lb-img {
  display: block; margin: 0 auto;
  max-width: calc(100% - 120px);   /* место для стрелок */
  max-height: calc(90vh - 130px);   /* шапка + подпись */
  width: auto; height: auto;
  object-fit: contain; border-radius: 6px;
}
.lb-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 2;
  width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid var(--ink-500); background: rgba(20,22,28,.8);
  color: var(--paper); font-size: 28px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s, color .15s;
  backdrop-filter: blur(4px); line-height: 1;
}
.lb-arrow:hover {
  background: var(--ink-600); border-color: var(--brass); color: var(--brass);
}
.lb-prev { left: 4px; }
.lb-next { right: 4px; }
.lb-footer {
  text-align: center; padding-top: 8px; flex-shrink: 0;
}
.lb-caption {
  font-family: var(--serif); font-size: 15px; color: var(--paper-2);
}
.lb-counter {
  font-family: var(--mono); font-size: 12px; color: var(--paper-3);
  margin-top: 2px;
}
/* ======================================================================
   ДОСТУПНОСТЬ ОТКЛЮЧЁННЫХ ПОЛЕЙ
   ====================================================================== */
select:disabled,
input:disabled,
textarea:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--ink-800);
  border-color: var(--ink-600);
}

/* ======================================================================
   АВТОКОМПЛИТ НАСЕЛЁННЫХ ПУНКТОВ
   Раньше стили задавались инлайном прямо в JS с жёстко прописанным
   белым фоном (#ffffff) и тёмным текстом — в тёмной теме выпадашка
   выглядела инородным белым пятном. Теперь всё через переменные темы.
   ====================================================================== */
.place-autocomplete-box {
  position: absolute;
  left: 0;
  top: 100%;
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  margin-top: 3px;
  background: var(--ink-800);
  border: 1px solid var(--ink-500);
  border-radius: var(--r);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .38);
  z-index: 120; /* над модалкой, без космических значений (п.15) */
}
.place-autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--paper);
  border-bottom: 1px solid var(--ink-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.place-autocomplete-item:last-child { border-bottom: none; }
.place-autocomplete-item:hover,
.place-autocomplete-item.is-active {
  background: var(--ink-600);
  color: var(--brass);
}
.place-autocomplete-loading {
  padding: 7px 12px;
  font-size: 12px;
  color: var(--paper-3);
  font-style: italic;
}

body.light-theme .place-autocomplete-box {
  background: #ffffff;
  border-color: #cbd5e1;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .12);
}
body.light-theme .place-autocomplete-item {
  color: #1e293b;
  border-bottom-color: #f1f5f9;
}
body.light-theme .place-autocomplete-item:hover,
body.light-theme .place-autocomplete-item.is-active {
  background: #f1f5f9;
  color: #8a6a2a;
}
body.light-theme .place-autocomplete-loading { color: #64748b; }

/* ======================================================================
   БЕЗОПАСНОСТЬ: восстановление пароля, 2FA, список сессий
   ====================================================================== */
.link-btn {
  display: inline-block;
  margin-top: 10px;
  background: none;
  border: none;
  color: var(--paper-3);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: var(--brass); }

.modal-note {
  font-size: 13px;
  color: var(--paper-3);
  margin: 6px 0 12px;
  line-height: 1.45;
}

.sec-session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 4px;
}
.sec-session {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  background: var(--ink-800);
}
.sec-session.is-current {
  border-color: var(--brass);
  background: rgba(201, 163, 91, .08);
}
.sec-session-main { min-width: 0; }
.sec-device {
  font-size: 14px;
  color: var(--paper);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sec-meta {
  font-size: 12px;
  color: var(--paper-3);
  margin-top: 2px;
  font-family: var(--mono);
}
.sec-badge {
  font-size: 11px;
  color: var(--brass);
  border: 1px solid var(--brass);
  border-radius: 10px;
  padding: 1px 8px;
  font-family: var(--sans);
  white-space: nowrap;
}
.sec-revoke { flex-shrink: 0; font-size: 12px; }
.sec-actions { margin-top: 14px; }

body.light-theme .modal-note { color: #64748b; }
body.light-theme .link-btn { color: #64748b; }
body.light-theme .link-btn:hover { color: #8a6a2a; }
body.light-theme .sec-session { background: #fff; border-color: #e2e8f0; }
body.light-theme .sec-device { color: #1e293b; }
body.light-theme .sec-meta { color: #64748b; }

/* ======================================================================
   ВЫПАДАЮЩИЕ МЕНЮ В ШАПКЕ (группировка кнопок, чтобы всё влезало)
   ====================================================================== */
.hmenu {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}
.hmenu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.hmenu-trigger .caret {
  font-size: 10px;
  opacity: .7;
  transition: transform .15s ease;
}
.hmenu-trigger[aria-expanded="true"] .caret {
  transform: rotate(180deg);
}
.hmenu-trigger .account-icon { font-size: 15px; }

.hmenu-panel {
  position: fixed;
  min-width: 190px;
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: var(--r);
  padding: 5px 0;
  z-index: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  display: flex;
  flex-direction: column;
}

.hmenu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--paper);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  text-decoration: none;
}
.hmenu-item .ic { opacity: .75; }
.hmenu-item:hover .ic { opacity: 1; }
.hmenu-item:hover { background: var(--ink-600); }
.hmenu-item.danger { color: var(--danger); }
.hmenu-item.danger:hover { background: rgba(196, 106, 92, .15); }

.hmenu-sep {
  height: 1px;
  background: var(--ink-600);
  margin: 5px 0;
}
.hmenu-email {
  padding: 6px 16px 8px;
  font-size: 12px;
  color: var(--paper-3);
  font-family: var(--mono);
  word-break: break-all;
  max-width: 240px;
}

body.light-theme .hmenu-panel {
  background: #fff;
  border-color: #e2e8f0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
body.light-theme .hmenu-item { color: #1e293b; }
body.light-theme .hmenu-item:hover { background: #f1f5f9; }
body.light-theme .hmenu-sep { background: #e2e8f0; }
body.light-theme .hmenu-email { color: #64748b; }

/* ======================================================================
   АДАПТИВ ШАПКИ — БЕЗ ГОРИЗОНТАЛЬНОГО СКРОЛЛА
   Размещён в конце файла намеренно: базовое правило .tree-name-wrap
   { display:inline-flex } идёт ниже по каскаду, поэтому медиазапросы
   должны быть ещё ниже, иначе display:none не срабатывает.
   Все селекторы усилены #id / !important, чтобы гарантированно
   перебить базовые стили при любой специфичности.
   ====================================================================== */

/* ≤1200px: имя древа дублирует выпадающий селектор — убираем его,
   подпись «Помощь» сворачиваем до иконки. */
@media (max-width: 1200px) {
  .tree-name-wrap { display: none !important; }
  .hide-narrow { display: none; }
}

/* ≤1040px: главная кнопка и триггеры меню — только иконки.
   Подписи прячем ТОЛЬКО у триггеров в шапке: внутри выпадающих
   панелей текст обязан остаться, иначе меню превратится в набор
   безымянных иконок — ровно то, от чего мы уходили. */
@media (max-width: 1040px) {
  .topbar { gap: 0 6px; padding: 9px 10px; }
  .topbar-tree, .topbar-actions { padding-left: 10px; margin-left: 4px; }
  #tree-select { min-width: 110px !important; max-width: 150px; }
  #btn-add-person-top > span,
  #btn-tree-menu > span,
  #btn-view-menu > span { display: none; }
  #btn-add-person-top { padding-left: 11px; padding-right: 11px; }
}

/* ≤880px: список людей становится выезжающей панелью поверх схемы
   (как панель слоёв в мобильном Figma): канвас сразу на весь экран,
   список открывается кнопкой в тулбаре и не толкает раскладку. */
@media (max-width: 880px) {
  .layout { position: relative; overflow: hidden; }
  .sidebar {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: min(85vw, 320px);
    max-height: none;
    z-index: 400;
    border-right: 1px solid var(--ink-600);
    border-bottom: none;
    box-shadow: 4px 0 28px rgba(0,0,0,.45);
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar:not(.collapsed) { transform: translateX(0); }
  .sidebar.collapsed {
    width: min(85vw, 320px) !important;
    min-width: 0 !important;
    padding: 16px !important;
  }
  .sidebar-collapse { display: none; } /* открывается снаружи, кнопкой в тулбаре */
  #sidebar-backdrop {
    position: absolute; inset: 0;
    background: rgba(8, 9, 12, .55);
    z-index: 390;
  }
  #sidebar-backdrop[hidden] { display: none; }
  .mobile-only { display: inline-flex !important; }
  .legend { display: none; }
  .brand { font-size: 15px; letter-spacing: .08em; }
  #tree-select { min-width: 90px !important; max-width: 130px; }
  .topbar-group .btn-ghost { padding-left: 8px; padding-right: 8px; }
}

/* ≤640px: бренд убираем, разделители зон тоже — остаются селектор
   древа, «+ человек», «Древо», «Вид», помощь и аккаунт. */
@media (max-width: 640px) {
  .topbar { gap: 0 4px; padding: 7px 8px; }
  .brand { display: none !important; }
  .topbar-tree, .topbar-actions {
    border-left: none;
    padding-left: 0;
    margin-left: 0;
  }
  #tree-select { min-width: 76px !important; max-width: 112px; font-size: 12px; }
  .topbar-group .btn-ghost { padding-left: 7px; padding-right: 7px; }
}

/* ≤420px: самый минимум — «Вид» уезжает в меню «Древо» по смыслу
   не переносим, просто скрываем: настройки отображения доступны
   после поворота экрана или на большом устройстве. */
@media (max-width: 420px) {
  #menu-view-wrap { display: none; }
  #tree-select { min-width: 68px !important; max-width: 96px; }
}

/* ======================================================================
   ВВОДНЫЙ ТУР (onboarding.js)
   Подсвечиваем НАСТОЯЩИЙ элемент интерфейса дыркой в затемнении, а не
   его копию: так подсказка всегда показывает актуальную вёрстку и не
   расходится с приложением после правок.
   ====================================================================== */
body.tour-open { overflow: hidden; }

.tour-root {
  position: fixed;
  inset: 0;
  z-index: 3000;
  /* Сам контейнер кликов не ловит — иначе на шагах, где нужно нажать
     подсвеченную кнопку, он перехватывал бы их вместо приложения.
     Ловят только затемнение и подсказка (ниже). */
  pointer-events: none;
}
.tour-mask {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 14, .72);
  pointer-events: auto;
}
.tour-pop, .tour-ring { pointer-events: auto; }
.tour-ring { pointer-events: none; }
body.light-theme .tour-mask { background: rgba(28, 32, 40, .55); }

.tour-ring {
  position: fixed;
  border: 2px solid var(--brass);
  border-radius: 6px;
  box-shadow: 0 0 0 3px rgba(201, 163, 91, .22);
  pointer-events: none;
  transition: left .22s ease, top .22s ease, width .22s ease, height .22s ease;
}

.tour-pop {
  position: fixed;
  width: 340px;
  max-width: calc(100vw - 24px);
  background: var(--ink-800);
  border: 1px solid var(--ink-500);
  border-radius: 8px;
  padding: 16px 18px 14px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
  transition: left .22s ease, top .22s ease;
}
.tour-pop-center {
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%);
  width: 420px;
}
body.light-theme .tour-pop {
  background: #fff;
  border-color: #dfd9cc;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .18);
}

.tour-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.tour-step {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .06em;
  color: var(--brass);
}
.tour-skip {
  background: none;
  border: none;
  color: var(--paper-3);
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
}
.tour-skip:hover { color: var(--paper); text-decoration: underline; }

.tour-title {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  color: var(--paper);
  margin-bottom: 7px;
  line-height: 1.25;
}
.tour-text {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--paper-2);
  margin-bottom: 16px;
}

.tour-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.tour-dots { display: flex; gap: 5px; }
.tour-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-500);
}
.tour-dot.is-on { background: var(--brass); }
.tour-nav { display: flex; gap: 8px; flex-shrink: 0; }
.tour-nav .btn {
  height: 32px;
  padding: 0 16px;
  white-space: nowrap;   /* «Пропустить шаг» не должно ломаться на две строки */
}

@media (max-width: 620px) {
  .tour-pop, .tour-pop-center { width: calc(100vw - 24px); }
  .tour-pop-center { width: calc(100vw - 24px); }
}

/* Список горячих клавиш (Помощь → Горячие клавиши) */
.keys-list { display: flex; flex-direction: column; gap: 2px; }
.keys-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px solid var(--ink-700);
  font-size: 13.5px;
  color: var(--paper-2);
}
.keys-row:last-child { border-bottom: none; }
.keys-row kbd {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--paper);
  background: var(--ink-700);
  border: 1px solid var(--ink-500);
  border-radius: 3px;
  padding: 3px 8px;
  text-align: center;
}

/* Иконки в местах, где раньше стояли эмодзи */
.ic-ava-ph { width: 30px; height: 30px; color: var(--paper-3); stroke-width: 1.4; }
.ic-empty { width: 42px; height: 42px; color: var(--brass); stroke-width: 1.3; }
.sidebar-collapse .ic { transition: transform .18s ease; }
.sidebar-collapse.is-collapsed .ic { transform: rotate(180deg); }
.history-preview-icon .ic { width: 15px; height: 15px; }
.gallery-edit-btn .ic { width: 13px; height: 13px; }
.log-snapshot .ic, .log-undo .ic { width: 15px; height: 15px; }

/* Шаг, который выполняет сам пользователь: строка ожидания под текстом */
.tour-wait {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: -6px 0 14px;
  padding: 9px 11px;
  border-radius: var(--r);
  background: rgba(201, 163, 91, .10);
  border: 1px solid rgba(201, 163, 91, .28);
  font-size: 12.5px;
  color: var(--paper-2);
}
.tour-wait-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--brass);
  flex-shrink: 0;
  animation: tour-pulse 1.1s ease-in-out infinite;
}
@keyframes tour-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.7); }
}
.tour-wait.is-done {
  background: rgba(122, 163, 110, .14);
  border-color: rgba(122, 163, 110, .45);
  color: #8fc17f;
}
.tour-wait.is-done .tour-wait-dot {
  background: #8fc17f;
  animation: none;
}
@media (prefers-reduced-motion: reduce) {
  .tour-wait-dot { animation: none; }
}

/* Счётчик «древо растёт» в подсказке тура */
.tour-score {
  display: flex;
  gap: 16px;
  margin: -4px 0 12px;
  font-size: 12.5px;
  color: var(--paper-3);
}
.tour-score b {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--brass);
  margin-right: 4px;
}
.tour-pop.is-celebrate .tour-score {
  justify-content: center;
  gap: 26px;
  margin: 2px 0 16px;
  padding: 12px 0;
  border-top: 1px solid var(--ink-600);
  border-bottom: 1px solid var(--ink-600);
}
.tour-pop.is-celebrate .tour-score b { font-size: 22px; }
.tour-pop.is-celebrate .tour-title { text-align: center; }
.tour-pop.is-celebrate .tour-text { text-align: center; }

/* Итоговый шаг тура: показываем построенное древо, а не прячем его */
.tour-root.is-celebrate .tour-mask { background: rgba(8, 10, 14, .32); }
body.light-theme .tour-root.is-celebrate .tour-mask { background: rgba(28, 32, 40, .22); }
.tour-pop.is-celebrate { width: 420px; }
