/* Глобальная тема: цвета страниц от системной темы (prefers-color-scheme) */
:root {
  --bg: #f0f0f2;
  --fg: #1e1f24;
  --panel-bg: #ffffff;
  --input-bg: #f6f6f8;
  --border: #d0d0d6;
  --muted: #6a6d75;
  --accent: #3d6fe0;
  --panel-trans: rgba(255, 255, 255, 0.72);
  --nav-bg: #f0f0f2;
  --nav-fg: #1e1f24;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1f24;
    --fg: #e8e8ea;
    --panel-bg: #2a2c33;
    --panel-trans: rgba(42, 44, 51, 0.72);
    --input-bg: #1e1f24;
    --border: #444;
    --muted: #9aa;
    --nav-bg: #2a2c33;
    --nav-fg: #e8e8ea;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
}
.hidden { display: none !important; }
.panel {
  max-width: 420px;
  margin: 60px auto;
  padding: 24px;
  background: var(--panel-bg);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.row { display: flex; gap: 10px; align-items: center; }
input, textarea, select, button {
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--fg);
  font-size: 14px;
}
button { cursor: pointer; background: var(--accent); border: none; color: #fff; }
button:disabled { background: #888; cursor: default; }
button.danger { background: #c0392b; }
.error { color: #ff6b6b; }
.hint { color: var(--muted); font-size: 12px; }
.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.check input { width: auto; }

/* --- Список деревьев: тёмная тема (как /person/<id>) --- */
#trees-view {
  display: flex; flex-direction: column; height: 100vh;
  background: #0A1322; color: #EDF2FA; font-family: 'Manrope', system-ui, sans-serif;
  --pv-line: #33415E; --pv-muted: #8FA0BC; --pv-gold: #D2B273; --pv-indigo: #5FA8E8;
}
.brand-mark { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.brand-mark img { width: 38px; height: 38px; border-radius: 10px; }
.brand-name { font-size: 14px; font-weight: 700; letter-spacing: .09em; }
.topbar-btn {
  background: none; border: 1px solid var(--pv-line); color: #EDF2FA; border-radius: 999px;
  padding: 8px 18px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.topbar-btn:hover { border-color: var(--pv-indigo); }
#btn-trees-import { margin-left: auto; }

.trees-layout {
  flex: 1; overflow-y: auto; display: flex; justify-content: center; padding: 60px 24px;
  background:
    radial-gradient(700px 500px at 10% -10%, rgba(95,168,232,.10), transparent 60%),
    radial-gradient(600px 500px at 90% 110%, rgba(210,178,115,.07), transparent 60%);
}
.trees-panel {
  width: 680px; max-width: 100%; border-radius: 20px; padding: 36px 40px 30px; text-align: center;
  background: linear-gradient(90deg, rgba(28,41,70,.95), rgba(17,27,52,.96));
  border: 1px solid rgba(156,200,255,.24); box-shadow: 0 20px 40px rgba(0,0,0,.4);
  height: fit-content;
}
.trees-ring {
  width: 96px; height: 96px; margin: 0 auto; border-radius: 50%;
  background: rgba(210,178,115,.08); border: 1.5px solid rgba(210,178,115,.5);
  display: flex; align-items: center; justify-content: center; color: var(--pv-gold);
}
.trees-ring svg { width: 40px; height: 40px; }
#trees-headline { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 30px; font-weight: 700; margin: 24px 0 0; }
.trees-sub { margin: 8px auto 0; max-width: 520px; color: var(--pv-muted); font-size: 13px; line-height: 1.5; }
.trees-cards { display: flex; gap: 24px; margin-top: 28px; }
.trees-card { flex: 1; border-radius: 16px; padding: 26px 28px; text-align: left; }
.trees-card.gold { background: rgba(210,178,115,.06); border: 1.5px solid rgba(210,178,115,.5); }
.trees-card.blue { background: rgba(95,168,232,.06); border: 1.5px solid rgba(95,168,232,.5); cursor: pointer; transition: transform .15s; }
.trees-card.blue:hover { transform: translateY(-3px); }
.trees-card .icobg { width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center; }
.trees-card .icobg svg { width: 24px; height: 24px; }
.trees-card.gold .icobg { background: rgba(210,178,115,.13); color: var(--pv-gold); }
.trees-card.blue .icobg { background: rgba(95,168,232,.13); color: #8FC2F5; }
.trees-card h3 { font-size: 16px; font-weight: 800; margin: 18px 0 0; }
.trees-card p { color: var(--pv-muted); font-size: 12px; line-height: 1.45; margin: 6px 0 14px; }
.trees-card .cta { font-size: 12.5px; font-weight: 700; color: #8FC2F5; }
#tree-title {
  width: 100%; background: #0C1626; border: 1px solid var(--pv-line); color: #EDF2FA;
  border-radius: 9px; padding: 10px 12px; font-size: 13px; margin-bottom: 10px;
}
#btn-create-tree {
  background: none; border: none; padding: 0; color: var(--pv-gold);
  font-size: 12.5px; font-weight: 700; cursor: pointer;
}

/* Список древ пользователя (непустое состояние) */
#tree-list { list-style: none; padding: 0; margin: 24px 0 0; text-align: left; }
#tree-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; margin-top: 10px; border-radius: 13px; cursor: pointer;
  background: #152036; border: 1px solid #31405E;
}
#tree-list li:hover { border-color: var(--pv-indigo); }
.tree-stats { color: var(--pv-muted); font-size: 13px; margin-left: auto; }
.tree-del {
  background: none; border: 1px solid var(--pv-line); color: #ff9b9b;
  border-radius: 8px; padding: 6px 8px; display: flex; align-items: center; cursor: pointer;
}
.tree-del svg { display: block; }

@media (max-width: 700px) {
  .trees-cards { flex-direction: column; }
}
.share-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.share-toggle input[type="checkbox"] { width: auto; }
.share-link {
  padding: 4px 8px;
  font-size: 12px;
  max-width: 220px;
  cursor: copy;
}

/* --- Страница входа: тёмная панель на фоне демо-древа (WebGL) --- */
#auth-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0A1322;
  font-family: 'Manrope', system-ui, sans-serif;
  --pv-line: #33415E; --pv-muted: #8FA0BC; --pv-gold: #D2B273; --pv-indigo: #5FA8E8;
}
#auth-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#auth-labels { position: absolute; top: 0; left: 0; pointer-events: none; transform-origin: 0 0; }
.auth-overlay { position: absolute; inset: 0; background: rgba(6, 11, 24, 0.72); }
#auth-view .person-topbar { position: absolute; top: 0; left: 0; right: 0; z-index: 2; }
.auth-panel {
  position: relative;
  z-index: 1;
  width: 500px;
  max-width: 94vw;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 22px;
  padding: 34px 40px;
  text-align: center;
  background: linear-gradient(180deg, rgba(35,50,82,.95), rgba(22,34,60,.94) 42%, rgba(14,23,48,.96));
  border: 1px solid rgba(210,178,115,.4);
  box-shadow: 0 18px 32px rgba(0,0,0,.53);
  color: #EDF2FA;
}
.auth-logo-ring {
  width: 84px; height: 84px; margin: 0 auto; border-radius: 22px;
  background: rgba(210,178,115,.09); border: 1.5px solid var(--pv-gold);
  display: flex; align-items: center; justify-content: center;
}
.auth-logo-ring img { width: 44px; height: 44px; }
.auth-panel h1 { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 32px; font-weight: 700; margin: 20px 0 0; text-align: center; }
.auth-sub { color: var(--pv-muted); font-size: 13px; margin-top: 6px; }
.auth-tabs {
  display: flex; position: relative; background: #0E1730; border: 1px solid var(--pv-line);
  border-radius: 10px; padding: 6px; margin-top: 24px;
}
/* Скользящий индикатор активной вкладки */
.auth-tabs::before {
  content: ''; position: absolute; top: 6px; bottom: 6px; left: 6px; width: calc(50% - 6px);
  border-radius: 8px; background: linear-gradient(180deg, #8FC2F5, #5FA8E8 50%, #2F6FB8);
  transition: transform 0.25s ease;
}
.auth-tabs.reg::before { transform: translateX(100%); }
.auth-tabs button {
  position: relative; z-index: 1;
  flex: 1; height: 40px; border: none; border-radius: 8px; background: transparent;
  color: var(--pv-muted); font-size: 13px; cursor: pointer; font-family: inherit;
  transition: color 0.2s ease;
}
.auth-tabs button.active { color: #fff; font-weight: 700; }
.auth-field {
  display: flex; align-items: center; gap: 12px; height: 46px; border-radius: 9px;
  background: #0C1626; border: 1px solid var(--pv-line); padding: 0 18px; margin-top: 12px;
}
/* Поле имени: плавное раскрытие/скрытие (окно плавно меняет высоту) */
#auth-name-wrap {
  overflow: hidden; max-height: 60px; opacity: 1;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin-top 0.25s ease, padding 0.25s ease;
}
#auth-name-wrap.collapsed {
  max-height: 0; opacity: 0; margin-top: 0; border-width: 0; padding-top: 0; padding-bottom: 0;
  pointer-events: none;
}
.auth-field svg { width: 14px; height: 14px; color: var(--pv-muted); flex-shrink: 0; }
.auth-field input {
  flex: 1; background: transparent; border: none; outline: none;
  color: #EDF2FA; font-family: inherit; font-size: 13px;
}
.auth-field input::placeholder { color: var(--pv-muted); }
/* Автозаполнение браузера: не даём белому фону перекрыть тёмные поля */
#auth-view input:-webkit-autofill,
#trees-view input:-webkit-autofill,
#person-view input:-webkit-autofill,
.import-body input:-webkit-autofill,
#auth-view input:-webkit-autofill:hover,
#auth-view input:-webkit-autofill:focus {
  -webkit-text-fill-color: #EDF2FA;
  -webkit-box-shadow: 0 0 0 1000px #0C1626 inset;
  box-shadow: 0 0 0 1000px #0C1626 inset;
  caret-color: #EDF2FA;
  transition: background-color 9999s ease-out;
}
.auth-submit {
  width: 100%; height: 46px; border: none; border-radius: 9px; margin-top: 16px;
  background: var(--pv-gold); color: #11151B; font-size: 14px; font-weight: 800;
  cursor: pointer; box-shadow: 0 5px 14px rgba(210,178,115,.2);
}
#auth-error { color: #ff9b9b; font-size: 12px; margin: 10px 0 0; }
.auth-divider { height: 1px; background: var(--pv-line); margin: 20px 0 14px; }
.auth-foot { color: var(--pv-muted); font-size: 12px; line-height: 1.5; }
/* --- Редактор --- */
html, body { height: 100%; }
#editor-view { display: flex; flex-direction: column; height: 100vh; }

.toolbar {
  padding: 10px 16px;
  background: var(--nav-bg);
  color: var(--nav-fg);
  position: relative;
}
.toolbar h2 { margin: 0; font-size: 18px; }
#btn-burger { background: transparent; color: var(--nav-fg); border: none; }

/* Сайдбар: выезжает слева, фон плавно затемняется */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  background: var(--nav-bg);
  color: var(--nav-fg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 40;
}
.sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35); }
.sidebar .check { color: var(--nav-fg); }
.sidebar-title {
  font-weight: 700;
  letter-spacing: 1px;
  padding: 6px 10px 14px;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo { display: block; width: 56px; margin: 0 auto 4px; border-radius: 14px; }
.auth-panel h1 { text-align: center; }
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: var(--nav-fg);
  border: none;
  border-radius: 8px;
  text-align: left;
  padding: 10px;
  cursor: pointer;
}
.sidebar-item:hover { background: rgba(128, 128, 128, 0.18); }
.sidebar-share input { width: auto; }
/* Нижняя пилюля: имя пользователя + выход */
.sidebar-bottom {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(128, 128, 128, 0.45);
  border-radius: 999px;
}
#sidebar-user { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menu-logout { padding: 6px 12px; border-radius: 999px; }
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 35;
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }
.status { margin-left: auto; font-size: 13px; color: var(--muted); }
.status.online { color: #6fdc8c; }
.editor-layout { position: relative; flex: 1; min-height: 0; }
.canvas-wrap { position: absolute; inset: 0; overflow: hidden; }
#gl-canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#gl-canvas.panning { cursor: grabbing; }
#labels { position: absolute; top: 0; left: 0; pointer-events: none; transform-origin: 0 0; }

/* Плавающая пилюля: матовое стекло (полупрозрачная, с blur) */
.pill {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(185, 190, 200, 0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 10;
  touch-action: none;
  user-select: none;
  cursor: grab;
  transition: left 0.15s ease, top 0.15s ease;
}
.pill.dragging { transition: none; cursor: grabbing; }
.pill.vertical { flex-direction: column; }
.pill button {
  border-radius: 999px;
  cursor: pointer;
  background: #fff;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pill button.active { box-shadow: inset 0 0 0 2px #3d6fe0; }

/* Всплывающее окно стилей — над пилюлей, возле кнопки */
.pill-popup {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--panel-bg);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  cursor: default;
}
.pill-popup .check { color: var(--fg); }

/* Тёмный фон канваса: светлый текст подписей */
body.dark-canvas .card-label { color: #e8e8ea; }
body.dark-canvas .card-role,
body.dark-canvas .card-dates { color: #b9bec8; }
body.dark-canvas .card-photo { background: rgba(255, 255, 255, 0.1); }
body.dark-canvas .card-photo svg { fill: rgba(255, 255, 255, 0.5); }

/* Винтажная тема (сепия): serif-шрифт, коричневый текст */
body.vintage-canvas .card-label { font-family: Georgia, "Times New Roman", serif; color: #3d2b1a; }
body.vintage-canvas .card-role,
body.vintage-canvas .card-dates { color: #6b4a2a; }
/* Портрет ровно в GL-рамке (рамка рисуется ветвями в WebGL, CSS-рамка не нужна) */
body.vintage-canvas .card-photo {
  width: 108px;
  height: 108px;
  margin: 10px 0 0;
  border: none;
  background: transparent;
}
body.vintage-canvas .card-photo svg { fill: rgba(107, 74, 42, 0.45); }
/* Кнопки в стиле темы: коричневые круги */
body.vintage-canvas .card-edit,
body.vintage-canvas .plus {
  background: #6b4a2a;
  color: #efe3c8;
  border: none;
  border-radius: 50%;
}

/* Свиток под портретом (винтаж): пергамент с «скрученными» концами */
.scroll {
  background: #efe3c8;
  border: 2px solid #6b4a2a;
  border-radius: 4px;
  padding: 3px 10px;
  position: relative;
  white-space: nowrap;
  color: #3d2b1a;
  font-family: Georgia, "Times New Roman", serif;
}
.scroll::before,
.scroll::after {
  content: "";
  position: absolute;
  top: -2px;
  width: 10px;
  height: calc(100% + 4px);
  background: #d8c49a;
  border: 2px solid #6b4a2a;
  border-radius: 50%;
}
.scroll::before { left: -8px; }
.scroll::after { right: -8px; }
.card-scroll { margin-top: 12px; font-size: 14px; font-weight: 600; }
.card-scroll-dates { margin-top: 8px; font-size: 12px; font-weight: 400; }

/* Плавное появление экранов при переключении (перезапускается при смене display) */
#auth-view, #trees-view, #editor-view, #person-view { animation: viewIn 0.25s ease; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
}

/* Модальное окно */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  animation: modalFade 0.18s ease;
}
.modal-body, .import-body { animation: modalPop 0.22s ease; }
@keyframes modalFade { from { opacity: 0; } }
@keyframes modalPop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
}
.modal-body { margin: 0; width: 420px; max-height: 90vh; overflow-y: auto; position: relative; }
/* Крестик закрытия — правый верхний угол окна */
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  background: var(--input-bg);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1;
}
/* Лоадер (шаг 3 импорта) */
.loader {
  width: 42px;
  height: 42px;
  margin: 16px auto;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#import-status { text-align: center; color: var(--muted); }
#import-url { width: 100%; }
#pdf-ready {
  display: block;
  text-align: center;
  padding: 10px;
  border-radius: 6px;
  background: #2e7d46;
  color: #fff;
  text-decoration: none;
}
#pdf-preview {
  width: 100%;
  background: #fff;
  border-radius: 6px;
}
/* Лоадер загрузки древа поверх канваса */
.tree-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.75);
  z-index: 15;
  color: #1e1f24;
}

/* Карточка поверх canvas (сам прямоугольник рисует WebGL, белый полупрозрачный) */
.card-label {
  position: absolute;
  width: 180px;
  height: 270px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 10px 0;
  font-size: 16px;
  color: #1e1f24;
  pointer-events: none;
}
/* Капсула роли — над карточкой, цвет в цвет обводки (задаётся из JS) */
.card-role-capsule {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 16px;
  border-radius: 999px;
  background: #bfc7d9;
  color: #fff;
  font-size: 13px;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
/* Фото-заглушка; обводка — в цвет обводки карточки (задаётся из JS) */
.card-photo {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  border: 2px solid #bfc7d9;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0 12px;
  overflow: hidden;
  position: relative;
}
.card-photo svg { width: 54px; height: 54px; fill: rgba(0, 0, 0, 0.35); }
.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  position: absolute;
  inset: 0;
  transition: opacity 0.2s ease;
}
/* Лоадер поверх заглушки, пока грузится фото */
.photo-loading {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid rgba(0, 0, 0, 0.15);
  border-top-color: #4d99f2;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  z-index: 1;
}
.card-line { line-height: 1.3; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-surname { font-weight: 600; }
.card-dates { font-size: 13px; color: #4a4d55; margin-top: 3px; }
/* Редактирование — внутри карточки, правый верхний угол; рамка — в цвет обводки (задаётся из JS) */
.card-edit {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  background: #fff;
  color: #000;
  border: 2px solid #bfc7d9;
  border-radius: 9px;
  pointer-events: auto;
}
/* Создание родственника — по центру внизу карточки; рамка — в цвет обводки (задаётся из JS) */
.plus {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
  border-radius: 50%;
  background: #fff;
  color: #000;
  border: 2px solid #bfc7d9;
  pointer-events: auto;
}

/* --- Совместное редактирование (ссылки-приглашения) --- */
#collab-modal .share-link { max-width: 100%; width: 100%; }
.collab-params { align-items: flex-end; gap: 10px; }
.collab-params label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.collab-params input[type="number"] { width: 72px; }
#collab-list { list-style: none; padding: 0; margin: 12px 0 0; max-height: 40vh; overflow-y: auto; }
#collab-list li.collab-invite {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.collab-invite-head { display: flex; align-items: center; gap: 8px; }
.collab-invite-head .collab-copy {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: copy;
  color: var(--accent);
  font-size: 12px;
}
.collab-invite-head .collab-meta { color: var(--muted); font-size: 11px; white-space: nowrap; }
.collab-invite-head .danger, .collab-member .danger { padding: 2px 8px; font-size: 12px; }
.collab-members { list-style: none; padding: 4px 0 0 10px; margin: 0; }
.collab-member { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.collab-member span { flex: 1; }
.collab-empty { color: var(--muted); font-size: 13px; }

/* Вход гостя по приглашению */
#join-modal .modal-body { width: 380px; }
#join-modal input { width: 100%; }

/* --- Детальная страница человека (/person/<id>): тёмный двухпанельный вид --- */
#person-view {
  display: flex; flex-direction: column; height: 100vh;
  background: #0A1322; color: #EDF2FA; font-family: 'Manrope', system-ui, sans-serif;
  --pv-line: #33415E; --pv-muted: #8FA0BC; --pv-gold: #D2B273; --pv-indigo: #5FA8E8;
}
.person-topbar {
  display: flex; align-items: center; gap: 14px; height: 64px; padding: 0 16px;
  background: rgba(14,23,40,.9); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--pv-line); flex-shrink: 0;
}
#btn-person-back {
  width: 34px; height: 34px; border-radius: 11px; padding: 0; font-size: 15px;
  background: rgba(95,168,232,.14); color: #9CC8FF; border: none; cursor: pointer;
}
#person-title { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 20px; font-weight: 700; margin: 0; }
#btn-person-edit {
  margin-left: auto; background: none; border: none; color: var(--pv-indigo);
  font-size: 13px; font-weight: 600; cursor: pointer; padding: 8px 12px;
}
.person-brand {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  color: var(--pv-gold); font-size: 12px; font-weight: 700; letter-spacing: .18em;
}
#btn-person-edit:not(.hidden) ~ .person-brand { margin-left: 12px; }

.person-layout {
  flex: 1; display: flex; gap: 24px; padding: 24px 32px; overflow: hidden;
  background:
    radial-gradient(500px 500px at 92% -10%, rgba(210,178,115,.10), transparent 60%),
    radial-gradient(460px 460px at 25% 110%, rgba(95,168,232,.09), transparent 60%);
}

/* Левая панель (просмотр): фото, ФИО, связи */
.person-side {
  width: 330px; flex-shrink: 0; overflow-y: auto; border-radius: 20px; padding: 30px 30px 24px;
  background: linear-gradient(160deg, rgba(28,41,70,.95), rgba(22,34,60,.94) 55%, rgba(17,27,52,.96));
  border: 1px solid rgba(156,200,255,.24); position: relative;
}
.person-avatar-ring {
  width: 156px; height: 156px; margin: 0 auto; border-radius: 50%; padding: 6px;
  background: linear-gradient(135deg, #F0D9A6, #8A6D3F); flex-shrink: 0;
}
.person-photo {
  width: 100%; height: 100%; border-radius: 50%; overflow: hidden;
  border: 3px solid var(--pv-gold); background: rgba(255,255,255,.08);
  display: flex; align-items: center; justify-content: center;
}
.person-photo svg { width: 60%; height: 60%; fill: rgba(255,255,255,.5); }
.person-photo img { width: 100%; height: 100%; object-fit: cover; }
.person-head { text-align: center; }
.person-fio-view { margin: 18px 0 0; font-size: 24px; font-weight: 800; }
.person-role-view { color: var(--pv-gold); font-size: 13px; font-weight: 600; margin-top: 8px; }
.person-dates-view { display: block; color: var(--pv-muted); font-size: 12px; margin-top: 4px; }
.person-chips { display: flex; justify-content: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.person-chips .chip { padding: 5px 12px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.person-chips .chip-gold { background: var(--pv-gold); color: #1B2946; }
.person-chips .chip-line { background: rgba(210,178,115,.13); color: var(--pv-gold); }

/* Режимы: .person-edit-only видно при редактировании, .person-view-only — при просмотре */
#person-view.view-only .person-edit-only { display: none; }
#person-view:not(.view-only) .person-view-only { display: none; }

/* Связи в древе (просмотр) */
.person-rels { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--pv-line); }
.rel-title { font-size: 10.5px; letter-spacing: .14em; color: var(--pv-muted); font-weight: 700; margin-bottom: 12px; }
#person-rels-list { list-style: none; padding: 0; margin: 0; }
#person-rels-list li {
  padding: 12px 16px; border-radius: 13px; margin-bottom: 10px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08);
}
#person-rels-list b { display: block; font-size: 13px; }
#person-rels-list span { display: block; font-size: 11px; color: var(--pv-muted); margin-top: 2px; }

#btn-open-tree {
  width: 100%; height: 44px; margin-top: 12px; border-radius: 11px; border: none; cursor: pointer;
  background: linear-gradient(135deg, #8FC2F5, #5FA8E8); color: #0A1322;
  font-weight: 800; font-size: 13px;
}

/* Правая панель (просмотр): биография и события */
.person-main {
  flex: 1; min-width: 0; overflow-y: auto; border-radius: 20px; padding: 28px 32px;
  background: rgba(21,32,54,.8); border: 1px solid var(--pv-line); backdrop-filter: blur(12px);
}
.person-kicker { display: flex; align-items: center; gap: 10px; color: var(--pv-muted); font-size: 10.5px; letter-spacing: .14em; font-weight: 700; }
.person-kicker::before { content: ''; width: 26px; height: 1px; background: var(--pv-gold); }
.person-divider { height: 1px; background: var(--pv-line); margin: 22px 0; }

/* Rich-text редактор биографии */
#bio-toolbar { display: flex; gap: 6px; margin: 12px 0 8px; }
#bio-toolbar button {
  padding: 4px 10px; font-size: 14px; background: #152036;
  border: 1px solid var(--pv-line); color: #EDF2FA; border-radius: 8px; cursor: pointer;
}
.bio-editor {
  min-height: 160px; margin-top: 12px; border: 1px solid var(--pv-line); border-radius: 13px;
  padding: 12px 16px; line-height: 1.65; font-size: 13.5px; color: #C8D2E4; outline: none;
}
.bio-editor:focus { border-color: var(--pv-indigo); }
.bio-editor img { max-width: 100%; border-radius: 8px; margin: 6px 0; }
.bio-editor p + p { margin-top: 12px; }
.bio-editor b, .bio-editor strong { color: #EDF2FA; }
#person-view.view-only .bio-editor { border-color: transparent; padding: 12px 0; min-height: 0; }

/* События */
#person-events { list-style: none; padding: 0; margin: 14px 0 12px; }
#person-events li {
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px; min-height: 44px; border-radius: 13px;
  background: #152036; border: 1px solid #31405E; margin-bottom: 10px;
}
.event-date { color: var(--pv-gold); font-weight: 800; font-size: 12.5px; white-space: nowrap; min-width: 44px; }
.event-desc { flex: 1; font-size: 12.5px; padding: 10px 0; }
.event-actions button { padding: 2px 8px; font-size: 12px; background: none; border: 1px solid var(--pv-line); color: #EDF2FA; border-radius: 7px; cursor: pointer; }
.event-actions button.danger { color: #ff9b9b; }
.event-form-row { align-items: center; gap: 8px; }
.event-form-row input[type="text"] {
  background: #0C1626; border: 1px solid var(--pv-line); color: #EDF2FA;
  border-radius: 9px; padding: 8px 12px; font-size: 13px;
}
#event-date { width: 170px; }
#event-desc { flex: 1; }
.person-events-empty {
  display: flex; align-items: center; min-height: 44px; border-radius: 9px;
  background: #152036; border: 1px dashed #36466A; padding: 0 20px;
  color: var(--pv-muted); font-size: 12px;
}
#person-view .error { color: #ff9b9b; }

/* --- Режим редактирования: единая широкая панель --- */
#person-view:not(.view-only) .person-layout {
  display: block; overflow-y: auto; border-radius: 20px; padding: 30px 32px; max-width: 1312px; margin: 0 auto;
  background: linear-gradient(90deg, rgba(28,41,70,.95), rgba(22,34,60,.94) 42%, rgba(17,27,52,.96));
  border: 1px solid rgba(156,200,255,.24);
}
#person-view:not(.view-only) .person-side,
#person-view:not(.view-only) .person-main {
  width: auto; padding: 0; background: none; border: none; backdrop-filter: none; overflow: visible;
}
#person-view:not(.view-only) .person-chips,
#person-view:not(.view-only) .person-rels { display: none; }

/* Шапка: аватар + имя/мета + замена фото */
#person-view:not(.view-only) .person-head { display: flex; align-items: flex-start; gap: 28px; text-align: left; }
#person-view:not(.view-only) .person-avatar-ring { width: 132px; height: 132px; margin: 0; }
#person-view:not(.view-only) .person-fio-view { margin-top: 12px; font-size: 24px; }
#person-view:not(.view-only) .person-head-meta { color: var(--pv-muted); font-size: 14px; margin-top: 6px; }
#person-view:not(.view-only) .person-head-meta #person-role-view { margin: 0; font-size: inherit; }
#person-view:not(.view-only) .person-head-meta #person-role-view::after { content: ' · '; color: var(--pv-muted); }
#person-view:not(.view-only) .person-dates-view { display: inline; margin: 0; font-size: inherit; }
.upload-btn {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; height: 38px; padding: 0 18px;
  border-radius: 9px; background: rgba(210,178,115,.09); border: 1px solid var(--pv-gold);
  color: var(--pv-gold); font-size: 12px; font-weight: 600; cursor: pointer;
}
.person-saved { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--pv-muted); font-size: 12px; }
.person-saved::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #74B58A; }

/* Тулбар биографии в режиме редактирования — бар над редактором */
#person-view:not(.view-only) #bio-toolbar {
  margin: 12px 0 0; gap: 0; background: #1B2742;
  border: 1px solid var(--pv-line); border-bottom: none; border-radius: 10px 10px 0 0; padding: 6px 16px;
}
#person-view:not(.view-only) #bio-toolbar button { background: none; border: none; padding: 6px 12px; }
#person-view:not(.view-only) .bio-editor { margin-top: 0; border-radius: 0 0 10px 10px; }

/* Поля: строки с подписями */
.person-fields { margin-top: 26px; }
.section-label { font-size: 11px; font-weight: 700; letter-spacing: .14em; color: var(--pv-muted); }
.pf-row { display: flex; gap: 30px; margin-top: 14px; flex-wrap: wrap; }
.pf-col { flex: 1; min-width: 140px; font-size: 11px; font-weight: 700; letter-spacing: .1em; color: var(--pv-muted); text-transform: uppercase; }
.pf-col input, .pf-col select {
  display: block; width: 100%; height: 40px; margin-top: 8px; border-radius: 8px;
  background: #0C1626; border: 1px solid var(--pv-line); color: #EDF2FA;
  font-size: 14px; padding: 0 16px; outline: none; box-sizing: border-box;
  text-transform: none; letter-spacing: normal; font-weight: 400;
}
.pf-col input::placeholder { color: var(--pv-muted); }
.pf-col input:focus, .pf-col select:focus { border-color: var(--pv-indigo); }
.pf-row.dates { align-items: flex-end; gap: 22px; }
.pf-row .check { font-size: 12px; color: var(--pv-muted); padding-bottom: 11px; }

/* Кнопки действий */
.person-actions { display: flex; gap: 16px; margin-top: 22px; }
.save-btn {
  min-width: 150px; height: 38px; border: none; border-radius: 9px;
  background: var(--pv-indigo); color: #fff; font-size: 13px; font-weight: 700; cursor: pointer;
}
.cancel-btn {
  min-width: 110px; height: 38px; border-radius: 9px; background: #1F2C46;
  border: 1px solid var(--pv-line); color: #EDF2FA; font-size: 13px; cursor: pointer;
}
.delete-btn {
  margin-left: auto; min-width: 150px; height: 38px; border-radius: 9px;
  background: rgba(198,107,93,.09); border: 1px solid #C66B5D; color: #C66B5D;
  font-size: 13px; cursor: pointer;
}

@media (max-width: 900px) {
  .person-layout { flex-direction: column; overflow-y: auto; }
  .person-side { width: 100%; overflow: visible; }
  .person-main { overflow: visible; }
}

/* --- Краткая информация о карточке (двойной клик, панель справа) --- */
.card-info {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  max-width: 90vw;
  height: 100vh;
  height: 100dvh;
  z-index: 15;
  background: var(--panel-bg, #fff);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  animation: card-info-in 0.2s ease-out;
}
@keyframes card-info-in {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.card-info h3 { margin: 0; padding-right: 30px; }
.card-info h4 { margin: 8px 0 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.card-info-role { color: var(--muted); margin: 0; }
.card-info-dates { color: var(--muted); margin: 0; font-size: 13px; }
.card-info-bio {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.5;
  max-height: 40vh;
}
.card-info-bio img { max-width: 100%; border-radius: 8px; }
.card-info-bio:empty::before { content: "—"; color: var(--muted); }
#card-info-events {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  max-height: 24vh;
  flex: 0 1 auto;
  min-height: 0;
}
#card-info-events li { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
#card-info-events li:last-child { border-bottom: none; }
#card-info-events .event-date { margin-right: 8px; }
#btn-card-info-more { margin-top: auto; }

/* --- Мастер импорта (тёмная тема) --- */
#import-modal { font-family: 'Manrope', system-ui, sans-serif; }
.import-body {
  width: 540px; max-width: 94vw; max-height: 90vh; overflow-y: auto; border-radius: 22px;
  padding: 32px; position: relative;
  background: linear-gradient(180deg, rgba(35,50,82,.97), rgba(22,34,60,.96) 42%, rgba(14,23,48,.98));
  border: 1px solid rgba(210,178,115,.4); box-shadow: 0 18px 32px rgba(0,0,0,.53);
  color: #EDF2FA;
  --pv-line: #33415E; --pv-muted: #8FA0BC; --pv-gold: #D2B273; --pv-indigo: #5FA8E8;
}
.import-body h1 { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 28px; font-weight: 700; margin: 18px 0 0; }
.import-body .subtitle { color: var(--pv-muted); font-size: 13px; line-height: 1.5; margin-top: 8px; max-width: 420px; }
.step-pill {
  display: inline-block; padding: 0 16px; height: 26px; line-height: 24px; border-radius: 999px;
  background: rgba(210,178,115,.11); border: 1px solid var(--pv-gold);
  color: var(--pv-gold); font-size: 11px; font-weight: 800;
}
.import-close {
  position: absolute; top: 24px; right: 24px; width: 34px; height: 34px; border-radius: 50%;
  background: #1F2C46; border: none; color: var(--pv-muted); cursor: pointer; font-size: 14px;
}
.import-body .options { display: flex; gap: 24px; margin-top: 26px; }
.import-body .option {
  flex: 1; border-radius: 14px; padding: 24px; text-align: left; cursor: pointer;
  background: #1B2742; border: 1px solid var(--pv-line); transition: transform .15s;
}
.import-body .option:hover { transform: translateY(-2px); }
.import-body .option.selected { border: 1.5px solid var(--pv-gold); }
.import-body .option .icobg { width: 44px; height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center; }
.import-body .option .icobg svg { width: 22px; height: 22px; }
#import-kod-pamyati .icobg { background: rgba(95,168,232,.11); color: var(--pv-indigo); }
#import-gedcom .icobg { background: rgba(210,178,115,.11); color: var(--pv-gold); }
.import-body .option h3 { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 18px; font-weight: 700; margin: 18px 0 0; }
.import-body .option p { color: var(--pv-muted); font-size: 12px; line-height: 1.4; margin: 6px 0 0; }
.import-body .note { color: var(--pv-muted); font-size: 12px; text-align: center; margin-top: 22px; }
.import-divider { height: 1px; background: var(--pv-line); margin: 18px 0 20px; }
.import-footer { display: flex; justify-content: space-between; }
.import-body .cancel-btn {
  min-width: 110px; height: 38px; border-radius: 9px; background: #1F2C46;
  border: 1px solid var(--pv-line); color: #EDF2FA; font-size: 13px; cursor: pointer;
}
.import-body .next-btn {
  min-width: 150px; height: 38px; border-radius: 9px; background: var(--pv-gold);
  border: none; color: #11151B; font-size: 13px; font-weight: 800; cursor: pointer;
}
#import-url {
  width: 100%; margin-top: 18px; background: #0C1626; border: 1px solid var(--pv-line);
  color: #EDF2FA; border-radius: 9px; padding: 10px 12px; font-size: 13px;
}
#import-file { margin-top: 18px; font-size: 12px; color: var(--pv-muted); }
#import-error { color: #ff9b9b; font-size: 12px; margin: 10px 0 0; }
#import-step-3 { text-align: center; }
#import-step-3 .loader { margin: 26px auto 10px; border-color: rgba(143,160,188,.3); border-top-color: var(--pv-gold); }
#import-status { color: var(--pv-muted); font-size: 13px; }
