/*! Version: 1.8 */
:root {
  --bg: #eef1ee;
  --surface: #ffffff;
  --surface-soft: #f8faf8;
  --ink: #17201b;
  --muted: #68736d;
  --line: #d9e0dc;
  --line-strong: #bdc9c2;
  --accent: #1f6f63;
  --accent-dark: #164f47;
  --blue: #285b9d;
  --rose: #b34f65;
  --gold: #aa761d;
  --shadow: 0 22px 55px rgba(22, 36, 29, 0.16);
  --soft-shadow: 0 10px 28px rgba(22, 36, 29, 0.09);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
.file-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

button:hover,
.file-button:hover {
  border-color: var(--line-strong);
  background: #fbfcfb;
}

button:active,
.file-button:active {
  transform: translateY(1px);
}

button:disabled,
.file-button.is-disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

button.danger {
  color: #a3233f;
}

.file-button input {
  display: none;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 104px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 99, 0.13);
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: 68px minmax(0, 1fr);
}

.app-topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 300px minmax(260px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
}

.brand p,
.canvas-status span,
.empty-profile p,
.profile-header p {
  color: var(--muted);
  margin: 3px 0 0;
  font-size: 13px;
}

.global-search {
  max-width: 620px;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.mobile-top-controls,
.mobile-main-menu,
.mobile-sheet-header,
.mobile-drawer-search,
.mobile-sheet-scrim {
  display: none;
}

.auth-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 4px 4px 4px 11px;
  border: 1px solid rgba(31, 111, 99, 0.18);
  border-radius: 999px;
  background: #f3faf7;
  color: #26443b;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.auth-pill button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(238, 241, 238, 0.88), rgba(255, 253, 248, 0.82)),
    rgba(238, 241, 238, 0.94);
  backdrop-filter: blur(12px);
}

.auth-overlay[hidden] {
  display: none;
}

.auth-card {
  width: min(390px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid rgba(133, 112, 80, 0.22);
  border-radius: 18px;
  background: rgba(255, 253, 248, 0.98);
  box-shadow: 0 28px 70px rgba(22, 36, 29, 0.2);
}

.auth-card h2 {
  margin: 0;
  color: var(--ink);
  font-size: 28px;
  line-height: 1.1;
}

.auth-card p {
  margin: 6px 0 0;
  color: var(--muted);
}

.auth-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

.auth-status {
  min-height: 18px;
  color: #8a2f2f;
  font-size: 12px;
  font-weight: 700;
}

body.auth-required .app-shell {
  pointer-events: none;
  user-select: none;
}

body.role-user .admin-only {
  display: none !important;
}

.sidebar {
  min-height: 0;
  overflow: auto;
  background: rgba(248, 250, 248, 0.94);
  border-right: 1px solid var(--line);
  padding: 18px;
}

.compact-sidebar-menu {
  width: 100%;
  overflow: hidden;
  border: 1px solid rgba(217, 224, 220, 0.92);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 12px 30px rgba(22, 36, 29, 0.06);
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}

.sidebar-tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 36px;
  padding: 0 4px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  transform: none;
}

.sidebar-tab:hover {
  background: rgba(248, 250, 248, 0.82);
}

.sidebar-tab:focus-visible {
  outline: 2px solid rgba(31, 111, 99, 0.22);
  outline-offset: -2px;
}

.sidebar-tab.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
  background: #fff;
}

.sidebar-tab-panel {
  display: none;
  padding: 10px;
}

.sidebar-tab-panel.active {
  display: block;
}

.people-list {
  display: grid;
  gap: 0;
  border-top: 1px solid rgba(217, 224, 220, 0.72);
}

.person-row {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  position: relative;
  justify-content: flex-start;
  min-height: 60px;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid rgba(217, 224, 220, 0.72);
  border-radius: 0;
  background: transparent;
  gap: 10px;
  transform: none;
}

.person-row::before {
  content: "";
  position: absolute;
  inset: 0;
  background: transparent;
  pointer-events: none;
}

.person-row > * {
  position: relative;
  z-index: 1;
}

.person-row:last-child {
  border-bottom: 0;
}

.person-row:hover {
  background: transparent;
}

.person-row:hover::before {
  background: rgba(248, 250, 248, 0.78);
}

.person-row:hover .row-text strong {
  color: var(--ink);
}

.person-row.active {
  border-color: rgba(217, 224, 220, 0.72);
  background: transparent;
}

.person-row.active::before {
  background: #eef6f2;
}

.person-row.active .row-text strong {
  color: var(--ink);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  object-fit: cover;
  background: #e1f5ee;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  color: #085041;
  flex: 0 0 auto;
}

.row-text {
  min-width: 0;
  flex: 1 1 auto;
}

.row-text strong,
.row-text small {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-text strong {
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
}

.row-text small {
  color: var(--muted);
  margin-top: 2px;
  font-size: 11px;
}

.sidebar-add-btn {
  width: 100%;
  min-height: 34px;
  margin-bottom: 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

.metric-card {
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.metric-value {
  color: var(--ink);
  font-size: 22px;
  font-weight: 650;
  line-height: 1;
}

.metric-unit,
.metric-label {
  color: var(--muted);
  font-size: 11px;
}

.metric-label {
  margin-top: 3px;
}

.metric-person-card {
  min-width: 0;
}

.metric-person-name {
  overflow: hidden;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-fold {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.fold-header {
  width: 100%;
  min-height: 26px;
  justify-content: space-between;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  transform: none;
}

.fold-header:hover {
  background: transparent;
}

.fold-header span:first-child,
.event-group-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.fold-chevron {
  color: var(--muted);
  font-size: 10px;
  transition: transform 0.18s ease;
}

.sidebar-fold.collapsed .fold-chevron {
  transform: rotate(-90deg);
}

.fold-body {
  overflow: hidden;
  max-height: 360px;
  transition: max-height 0.2s ease;
}

.sidebar-fold.collapsed .fold-body {
  max-height: 0;
}

.donut-stat {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 112px;
}

.donut-stat svg {
  width: 104px;
  height: 104px;
}

.donut-center {
  color: var(--ink);
  font-size: 20px;
  font-weight: 750;
  text-align: center;
}

.stat-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 10px;
  margin-top: 6px;
}

.stat-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.legend-swatch,
.city-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex: 0 0 auto;
}

.decade-bars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(22px, 1fr));
  align-items: end;
  gap: 6px;
  height: 118px;
  padding-top: 8px;
}

.decade-bar {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: end;
  gap: 5px;
  min-width: 0;
  height: 100%;
}

.decade-bar-fill {
  width: 100%;
  min-height: 4px;
  border-radius: 4px 4px 2px 2px;
  background: #5dcaa5;
}

.decade-bar-label {
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.city-row,
.event-row {
  border-bottom: 1px solid var(--line);
}

.city-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 27px;
  color: var(--ink);
  font-size: 12px;
}

.city-row:last-child,
.event-row:last-child {
  border-bottom: 0;
}

.city-name {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.city-name span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.city-count {
  font-size: 12px;
  font-weight: 700;
}

.archive-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.archive-label {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.archive-track {
  height: 12px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--surface-soft);
}

.archive-fill {
  height: 100%;
  border-radius: inherit;
}

.archive-value {
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}

.event-group-label {
  margin: 2px 0 8px;
}

.event-group-label:not(:first-child) {
  margin-top: 12px;
}

.event-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
}

.event-badge {
  flex: 0 0 auto;
  margin-top: 1px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eef8f5;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
}

.event-badge.memory {
  background: var(--surface-soft);
  color: var(--muted);
}

.event-name {
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
}

.event-sub {
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
}

.empty-sidebar-note {
  padding: 8px 0;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  min-width: 0;
  min-height: 0;
}

.canvas-shell {
  position: relative;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.75), transparent 28%),
    linear-gradient(135deg, #eef1ee, #e8eceb 48%, #f3f0ea);
}

/* Отключаем дорогой backdrop-filter на UI-элементах во время драга */
.card-dragging .canvas-status,
.card-dragging .canvas-tools {
  backdrop-filter: none;
}

.canvas-shell.dragging,
.canvas-shell.space-hand {
  cursor: grabbing;
}

.canvas-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(128, 143, 135, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(128, 143, 135, 0.18) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, black 20%, rgba(0, 0, 0, 0.55));
  will-change: transform;
}

.canvas-status {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 4;
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid rgba(217, 224, 220, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  box-shadow: var(--soft-shadow);
}

.canvas-status strong {
  font-size: 14px;
}

.tree-canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 3200px;
  height: 2200px;
  transform-origin: 0 0;
  will-change: transform;
}

#linksLayer,
#dragLinksLayer {
  position: absolute;
  inset: 0;
  width: 3200px;
  height: 2200px;
  overflow: visible;
  pointer-events: none;
}

#linksLayer {
  transition: opacity 0.12s ease;
}

#dragLinksLayer {
  opacity: 0;
}

.tree-canvas.has-drag-links #dragLinksLayer {
  opacity: 1;
}

#linksLayer .link-parent {
  fill: none;
  stroke: #5f8b67;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tree-canvas.drag-performance #linksLayer {
  opacity: 0.28;
}

.tree-canvas.drag-performance #linksLayer path,
.tree-canvas.drag-performance #linksLayer .junction-node {
  filter: none !important;
}

#linksLayer .link-spouse {
  fill: none;
  stroke: #f06292;
  stroke-width: 2.2;
  stroke-linecap: round;
}

#dragLinksLayer .link-parent {
  fill: none;
  stroke: #1f6f63;
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#dragLinksLayer .link-spouse {
  fill: none;
  stroke: #d81b60;
  stroke-width: 3.2;
  stroke-linecap: round;
}

#dragLinksLayer .link-spouse-former {
  stroke-dasharray: 7 7;
}

#dragLinksLayer .junction-node {
  fill: #dcefe6;
  stroke: #1f6f63;
  stroke-width: 2.6;
}

#linksLayer .link-spouse-former {
  stroke-dasharray: 7 7;
}

#linksLayer .junction-node {
  fill: #fbf8ef;
  stroke: #5f8b67;
  stroke-width: 2;
}

#linksLayer .junction-family {
  fill: #fbf8ef;
}

#linksLayer .junction-split {
  fill: #eef5ef;
}

#linksLayer .link-parent.is-active {
  stroke: #1f6f63;
  stroke-width: 3.2;
  opacity: 1;
}

#linksLayer .link-spouse-current.is-active {
  stroke: #d81b60;
  stroke-width: 3;
  opacity: 1;
}

#linksLayer .link-spouse-former.is-active {
  stroke: #d81b60;
  stroke-width: 3;
  opacity: 1;
}

#linksLayer .junction-node.is-active {
  fill: #dcefe6;
  stroke: #1f6f63;
  stroke-width: 2.4;
}

#linksLayer .is-muted {
  opacity: 1;
}

#nodesLayer {
  position: absolute;
  inset: 0;
}

.tree-node {
  position: absolute;
  width: 284px;
  min-height: 172px;
  background:
    linear-gradient(90deg, rgba(31, 111, 99, 0.08), transparent 26%),
    linear-gradient(180deg, #fffdf8, #f7f2e8);
  border: 1px solid #d7ccb8;
  border-radius: 8px;
  padding: 14px;
  cursor: pointer;
  touch-action: none;
  transition: border-color 0.18s ease;
  will-change: transform, left, top;
}

.tree-node.dragging-card {
  transition: none !important;
  z-index: 100;
  cursor: grabbing;
}

.card-dragging .tree-node:not(.dragging-card) {
  pointer-events: none;
}

.card-dragging .node-menu,
.card-dragging .floating-toolbar {
  opacity: 0 !important;
  pointer-events: none !important;
}

.tree-node:hover,
.tree-node.selected {
  border-color: var(--accent);
  transform: none;
}

.tree-node.selected::before {
  content: "";
  position: absolute;
  inset: -5px;
  border: 2px solid rgba(31, 111, 99, 0.28);
  border-radius: 12px;
  pointer-events: none;
}

.node-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.node-head .avatar {
  width: 76px;
  height: 90px;
  border-radius: 7px;
  background: #e3e5dd;
  border: 1px solid rgba(84, 96, 82, 0.14);
  color: #43514a;
  font-size: 17px;
  letter-spacing: 0.03em;
}

.node-body {
  min-width: 0;
  padding-right: 20px;
}

.node-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
  line-height: 1.12;
  font-size: 18px;
  color: #152119;
  overflow-wrap: anywhere;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
  flex: 0 0 auto;
  background: #a9b0aa;
  box-shadow: inset 0 0 0 1px rgba(23, 32, 27, 0.08);
}

.status-dot.alive {
  background: #4f9c75;
  box-shadow: 0 0 0 3px rgba(79, 156, 117, 0.14), 0 0 11px rgba(79, 156, 117, 0.36);
}

.status-dot.passed {
  background: #aeb4af;
}

.node-dates,
.node-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.node-dates {
  color: #48564f;
  font-weight: 650;
}

.node-note {
  margin-top: 10px;
  color: #59635d;
  font-size: 11px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.node-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  margin-left: 90px;
}

.tag {
  border-radius: 999px;
  background: #eef2ef;
  color: #4f5c55;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 750;
}

.tag.alive {
  background: #e3f5ef;
  color: var(--accent);
}

.tag.passed {
  background: #f7e7eb;
  color: var(--rose);
}

.node-menu {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 6;
}

.node-menu-trigger {
  min-width: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 8px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  opacity: 0.72;
}

.node-menu-trigger:hover,
.node-menu.is-open .node-menu-trigger {
  color: var(--ink);
  opacity: 1;
}

.node-menu-popover {
  position: absolute;
  top: 36px;
  right: 0;
  display: none;
  min-width: 260px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.node-menu.is-open .node-menu-popover {
  display: grid;
  gap: 4px;
}

.node-menu-popover button {
  width: 100%;
  justify-content: flex-start;
  min-height: 34px;
  border-color: transparent;
  padding: 0 10px;
  text-align: left;
  white-space: nowrap;
}

.node-menu-popover button:hover {
  background: #eef8f5;
  border-color: transparent;
}

.add-relative-trigger {
  color: var(--accent);
  font-weight: 800;
}

.canvas-tools {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 4;
  display: flex;
  gap: 8px;
  padding: 7px;
  border: 1px solid rgba(217, 224, 220, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
  box-shadow: var(--soft-shadow);
}

.canvas-tools button {
  min-width: 40px;
}

.zoom-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid rgba(217, 224, 220, 0.95);
  border-radius: 8px;
  background: rgba(247, 250, 248, 0.92);
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.profile-panel {
  position: fixed;
  top: 82px;
  right: 16px;
  bottom: 16px;
  width: min(420px, calc(100vw - 32px));
  z-index: 8;
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  transform: translateX(calc(100% + 32px));
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.profile-panel.is-open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.empty-profile {
  border: 1px dashed #c6d0ca;
  border-radius: 8px;
  padding: 18px;
  background: var(--surface-soft);
}

.empty-profile h2 {
  margin: 0 0 8px;
}

.profile-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  margin-bottom: 15px;
}

.profile-header h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.profile-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.profile-actions button.icon {
  min-width: 36px;
  padding: 0;
}

.mode-switch,
.tabs,
.panel-actions,
.gallery-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-switch {
  margin-bottom: 14px;
}

.mode-switch button,
.tabs button {
  min-height: 34px;
  padding: 0 11px;
}

.mode-switch .active,
.tabs .active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.photo-carousel {
  border-radius: 8px;
  overflow: hidden;
  background: #e8ede9;
  aspect-ratio: 4 / 3;
  position: relative;
  margin-bottom: 14px;
}

.photo-carousel img,
.photo-placeholder {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 750;
}

.carousel-nav {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: flex;
  justify-content: space-between;
}

.carousel-nav button {
  min-width: 38px;
  min-height: 34px;
  background: rgba(255, 255, 255, 0.9);
}

.details-grid,
.form-grid {
  display: grid;
  gap: 12px;
}

.detail {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.detail small,
label,
.field span {
  display: block;
  color: #4a5750;
  font-size: 12px;
  font-weight: 750;
}

.detail small {
  margin-bottom: 3px;
}

.detail span {
  white-space: pre-wrap;
}

.status-only {
  display: flex;
  align-items: center;
  min-height: 20px;
}

.status-only .status-dot {
  width: 10px;
  height: 10px;
}

.tabs {
  margin: 16px 0;
}

.field {
  display: grid;
  gap: 7px;
}

.status-field {
  align-items: start;
}

.field-hint {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
}

.status-toggle {
  width: max-content;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.status-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.status-switch {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid #cbd3ce;
  background: #d9ddda;
  position: relative;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.status-switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 7px rgba(22, 36, 29, 0.2);
  transition: transform 0.16s ease;
}

.status-toggle input[type="checkbox"]:checked + .status-switch {
  border-color: rgba(79, 156, 117, 0.45);
  background: #4f9c75;
}

.status-toggle input[type="checkbox"]:checked + .status-switch::before {
  transform: translateX(20px);
}

.dropzone {
  border: 1px dashed #aebbb3;
  border-radius: 8px;
  min-height: 116px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 16px;
  background: var(--surface-soft);
}

.dropzone.dragover {
  border-color: var(--accent);
  background: #eef8f5;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.thumb {
  position: relative;
  aspect-ratio: 1;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}

.thumb button {
  position: absolute;
  right: 4px;
  top: 4px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
}

.panel-actions {
  margin-top: 18px;
}

.hidden {
  display: none !important;
}

.modal-open {
  overflow: hidden;
}

.person-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(18, 28, 23, 0.38);
  backdrop-filter: blur(8px);
}

.person-modal-overlay[hidden] {
  display: none;
}

.person-modal {
  width: min(620px, calc(100vw - 48px));
  max-height: min(760px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(217, 203, 181, 0.78);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(255, 253, 248, 0.98), rgba(247, 242, 232, 0.98));
  box-shadow:
    0 34px 90px rgba(18, 28, 23, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.94);
}

.person-modal-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 16px 20px 14px;
  border-bottom: 1px solid rgba(217, 203, 181, 0.7);
  background: rgba(255, 255, 255, 0.55);
}

.person-modal-kicker {
  margin-bottom: 4px;
  color: var(--card-accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.person-modal-header h2 {
  margin: 0;
  color: var(--card-ink);
  font-size: 24px;
  line-height: 1.12;
}

.person-modal-header p {
  margin: 4px 0 0;
  color: var(--card-muted);
}

.person-modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.person-modal-actions .icon {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
}

.person-modal-body {
  overflow: auto;
  padding: 16px 20px 18px;
}

.modal-photo-editor {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.modal-section-label {
  color: #66716b;
  font-size: 12px;
  font-weight: 850;
}

.modal-tabs-row {
  position: relative;
  z-index: 1;
  margin: 0 0 12px;
  padding: 4px;
  border: 1px solid rgba(217, 203, 181, 0.64);
  border-radius: 10px;
  background: rgba(247, 242, 232, 0.74);
}

.modal-tabs {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
}

.modal-tabs button {
  min-width: 0;
  justify-content: center;
  border-color: transparent;
  background: transparent;
}

.modal-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 10px;
}

.modal-photo-editor,
.modal-tabs-row,
.modal-tab-panel,
.modal-form-actions {
  grid-column: 1 / -1;
}

.modal-tab-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.modal-tab-panel .modal-wide-field,
.modal-tab-panel label:has(textarea),
.modal-tab-panel .status-field {
  grid-column: 1 / -1;
}

.modal-form textarea {
  min-height: 104px;
}

.modal-form-actions {
  justify-content: flex-end;
  padding-top: 10px;
  border-top: 1px solid rgba(217, 203, 181, 0.62);
}

.modal-photo-carousel {
  width: 100%;
  height: clamp(172px, 30vw, 220px);
  min-height: 0;
  max-height: none;
  aspect-ratio: auto;
  margin-bottom: 0;
  border: 1px solid rgba(217, 203, 181, 0.64);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.55), rgba(247, 242, 232, 0.35)),
    #f2eee6;
}

.modal-photo-frame {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0;
}

.modal-photo-frame img {
  width: 100%;
  height: 100%;
  max-height: none;
  display: block;
  border-radius: inherit;
  object-fit: cover;
  box-shadow: none;
}

.modal-photo-counter {
  position: absolute;
  left: 12px;
  top: 10px;
  z-index: 1;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(23, 32, 27, 0.72);
  color: #fff;
  font-size: 11px;
  font-weight: 850;
}

.modal-photo-remove {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--card-ink);
}

.modal-photo-carousel .carousel-arrow {
  position: absolute;
  top: 50%;
  z-index: 3;
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--card-ink);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%);
}

.modal-photo-carousel.has-many-photos:hover .carousel-arrow,
.modal-photo-carousel.has-many-photos .carousel-arrow:focus-visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-photo-carousel .carousel-arrow-left {
  left: 12px;
}

.modal-photo-carousel .carousel-arrow-right {
  right: 12px;
}

.modal-photo-meta {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
  pointer-events: none;
}

.modal-add-photo {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px dashed rgba(133, 112, 80, 0.34);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(247, 242, 232, 0.46));
  color: #59645e;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
  position: relative;
  overflow: hidden;
  transform: translateY(0);
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.modal-add-photo::after {
  content: "Нажмите или перетащите файл";
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%) translateX(8px);
  color: rgba(89, 100, 94, 0.64);
  font-size: 11px;
  font-weight: 750;
  opacity: 0;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.modal-add-photo span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(31, 111, 99, 0.08);
  color: var(--card-accent);
  font-size: 14px;
  line-height: 1;
  transition: transform 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.modal-add-photo strong {
  font-size: 13px;
  font-weight: 850;
}

.modal-add-photo:hover,
.modal-add-photo.dragover {
  border-color: rgba(31, 111, 99, 0.52);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(238, 248, 245, 0.72));
  color: var(--card-ink);
  transform: translateY(-1px);
  box-shadow:
    0 8px 22px rgba(31, 111, 99, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.modal-add-photo:hover::after,
.modal-add-photo.dragover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.modal-add-photo:hover span,
.modal-add-photo.dragover span {
  background: var(--card-accent);
  color: #fff;
  transform: scale(1.05);
}

.modal-photo-meta > span {
  min-width: 46px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--card-ink);
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.modal-photo-dots {
  display: flex;
  gap: 5px;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
}

.modal-photo-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(104, 115, 109, 0.38);
}

.modal-photo-dots .active {
  background: var(--card-accent);
}

.modal-details {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(18px);
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 40;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    height: 100dvh;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: 56px minmax(0, 1fr);
  }

  .app-topbar {
    position: relative;
    z-index: 95;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 8px 10px;
    backdrop-filter: none;
  }

  .brand {
    gap: 9px;
    overflow: hidden;
    padding-right: 54px;
  }

  .brand > div:last-child {
    min-width: 0;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 18px;
  }

  .brand h1 {
    overflow: hidden;
    font-size: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand p {
    max-width: 42vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
  }

  .mobile-top-controls {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 6px;
    position: fixed;
    top: 9px;
    right: 10px;
    z-index: 90;
    justify-content: flex-end;
    width: 132px;
  }

  .mobile-top-controls button {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 850;
  }

  .mobile-top-controls #mobileSearchBtn {
    display: none;
  }

  .mobile-main-menu {
    display: none;
  }

  .global-search {
    display: none;
    position: fixed;
    top: 66px;
    left: 12px;
    right: 12px;
    z-index: 72;
    max-width: none;
    padding: 8px;
    border: 1px solid rgba(217, 224, 220, 0.95);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 12px 30px rgba(22, 36, 29, 0.14);
  }

  body.mobile-search-open .global-search {
    display: block;
  }

  .top-actions {
    display: none;
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 72;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    border: 1px solid rgba(217, 224, 220, 0.95);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 18px 42px rgba(22, 36, 29, 0.18);
  }

  body.mobile-actions-open .top-actions {
    display: flex;
  }

  .top-actions > button,
  .top-actions > .file-button {
    flex: 1 1 calc(50% - 8px);
  }

  .auth-pill {
    width: 100%;
    justify-content: space-between;
  }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    max-height: min(72dvh, 560px);
    padding: 14px 14px calc(16px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -18px 42px rgba(22, 36, 29, 0.18);
    transform: translateY(calc(100% + 8px));
    transition: transform 0.22s ease;
  }

  body.mobile-people-open .sidebar {
    transform: translateY(0);
  }

  .mobile-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
  }

  .mobile-sheet-header strong {
    font-size: 16px;
  }

  .mobile-sheet-header button {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    font-size: 20px;
  }

  .mobile-drawer-search {
    display: block;
    margin-bottom: 10px;
  }

  .compact-sidebar-menu {
    margin-top: 0;
  }

  .workspace {
    grid-column: 1;
    grid-row: 2;
    min-height: 0;
    height: 100%;
  }

  .canvas-status {
    top: 12px;
    left: 12px;
    max-width: calc(100vw - 24px);
    padding: 8px 10px;
  }

  .mobile-sheet-scrim {
    position: fixed;
    inset: 0;
    z-index: 60;
    border: 0;
    border-radius: 0;
    background: rgba(18, 28, 23, 0.28);
    cursor: default;
    transform: none;
  }

  body.mobile-people-open .mobile-sheet-scrim,
  body.mobile-actions-open .mobile-sheet-scrim,
  body.mobile-search-open .mobile-sheet-scrim {
    display: block;
  }

  .profile-panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-height: calc(100vh - 24px);
  }

  .person-modal-overlay {
    padding: 10px;
    align-items: end;
  }

  .person-modal {
    width: 100%;
    max-height: calc(100vh - 20px);
    border-radius: 16px 16px 0 0;
  }

  .person-modal-header {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .person-modal-actions {
    justify-content: flex-end;
  }

  .person-modal-body {
    padding: 16px 18px 20px;
  }

  .modal-tabs-row {
    margin: -16px -18px 14px;
    padding: 12px 18px 10px;
  }

  .modal-form,
  .modal-details {
    grid-template-columns: 1fr;
  }

  .canvas-tools {
    position: fixed;
    right: auto;
    left: 50%;
    bottom: 12px;
    z-index: 40;
    gap: 6px;
    padding: 5px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: translateX(-50%);
  }

  .canvas-tools button {
    width: 40px;
    flex: 0 0 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
  }

  #fitBtn,
  #autoLayoutBtn {
    font-size: 0;
  }

  #fitBtn::after {
    content: "⛶";
    font-size: 18px;
  }

  #autoLayoutBtn::after {
    content: "🪄";
    font-size: 18px;
  }

  .zoom-indicator {
    min-width: 48px;
    height: 40px;
    font-size: 12px;
  }
}

/* Новый дизайн карточек людей: чистая ID-карточка для семейного дерева */
:root {
  --card-bg: #fffdf8;
  --card-bg-soft: #f7f2e8;
  --card-border: #d9cbb5;
  --card-ink: #17201b;
  --card-muted: #68736d;
  --card-accent: #1f6f63;
  --card-warm: #aa761d;
}

.tree-node {
  width: 380px;
  height: 228px;
  padding: 0;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(31, 111, 99, 0.42);
  background: linear-gradient(135deg, #fffefa 0%, #fffdf8 58%, #f8f4ec 100%);
  box-shadow:
    0 14px 32px rgba(52, 45, 31, 0.11),
    inset 0 1px 0 rgba(255, 255, 255, 0.96);
  cursor: grab;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease;
  touch-action: none;
  will-change: transform;
}

.tree-node.dragging-card {
  cursor: grabbing;
  z-index: 5;
  transition: none !important;
  box-shadow:
    0 10px 22px rgba(31, 111, 99, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.96);
}

.tree-node:hover,
.tree-node.selected {
  transform: none;
  border-color: rgba(31, 111, 99, 0.74);
  box-shadow:
    0 18px 40px rgba(31, 111, 99, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.96);
}

.tree-node.selected::before {
  content: "";
  position: absolute;
  inset: -4px;
  border: 1px solid rgba(31, 111, 99, 0.18);
  border-radius: 22px;
  pointer-events: none;
}

.tree-node::after {
  content: none;
}

.node-head {
  display: grid;
  grid-template-columns: 166px minmax(0, 1fr);
  gap: 18px;
  height: 228px;
  padding: 10px;
  align-items: stretch;
}

.node-head .avatar {
  width: 166px;
  height: 208px;
  min-height: 100%;
  border-radius: 12px;
  object-fit: cover;
  background:
    linear-gradient(135deg, #e9ece7, #dfe5df);
  border: 1px solid rgba(84, 96, 82, 0.12);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.34),
    0 8px 20px rgba(22, 36, 29, 0.08);
  color: #43514a;
  font-size: 22px;
  letter-spacing: 0;
}

.node-body {
  min-width: 0;
  padding: 18px 16px 14px 0;
  overflow: hidden;
}

.node-name {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.08;
  color: #17201b;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.tree-node > .status-dot {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 4;
  width: 9px;
  height: 9px;
  box-shadow:
    0 0 0 8px rgba(255, 253, 248, 0.96),
    0 3px 10px rgba(22, 36, 29, 0.12),
    0 0 11px rgba(79, 156, 117, 0.36);
}

.node-dates {
  margin-top: 18px;
  color: #17201b;
  font-size: 17px;
  font-weight: 760;
  line-height: 1.18;
}

.node-birth-name {
  margin-top: 8px;
  color: #68736d;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-dates span {
  display: block;
}

.node-age {
  margin-top: 8px;
  color: var(--card-muted);
  font-size: 15px;
  font-weight: 650;
}

.node-meta {
  margin-top: 14px;
  padding: 0;
  background: transparent;
  color: var(--card-muted);
  font-size: 14px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-divider {
  height: 1px;
  margin-top: 11px;
  background: rgba(104, 115, 109, 0.18);
}

.node-note {
  margin-top: 7px;
  color: var(--card-muted);
  font-size: 11.5px;
  line-height: 1.32;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.node-tags {
  margin: 0 16px 15px 170px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  border-radius: 999px;
  background: rgba(170, 118, 29, 0.1);
  color: #7b5415;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 850;
}

.node-menu {
  top: 10px;
  right: 10px;
  z-index: 4;
}

.node-menu-trigger {
  min-width: 30px;
  min-height: 30px;
  border-radius: 999px;
  border-color: rgba(217, 224, 220, 0.65);
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(10px);
  color: rgba(23, 32, 27, 0.58);
}

.node-menu-trigger:hover,
.node-menu.is-open .node-menu-trigger {
  background: #ffffff;
  color: var(--card-ink);
}

#linksLayer path {
  stroke-linecap: round;
  stroke-linejoin: round;
}

.person-row .avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

/* Bottom action menu: keep person data readable, expose actions outside the card. */
.tree-node {
  overflow: visible;
  z-index: 1;
}

.tree-node.selected {
  z-index: 2;
}

.tree-node.is-menu-open {
  z-index: 80;
}

.tree-node.dragging-card {
  z-index: 90;
}

.node-head {
  overflow: hidden;
  border-radius: inherit;
}

.node-body {
  padding-right: 18px;
  padding-bottom: 20px;
}

/* Floating Toolbar */
.floating-toolbar {
  position: absolute;
  bottom: calc(100% + 14px);
  left: 50%;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(133, 112, 80, 0.16);
  border-radius: 12px;
  box-shadow: 
    0 12px 34px rgba(22, 36, 29, 0.15), 
    0 4px 12px rgba(22, 36, 29, 0.08);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateX(-50%) scale(var(--inverse-zoom, 1));
  transform-origin: bottom center;
  transition: opacity 0.18s ease, visibility 0.18s;
  will-change: transform, opacity;
}

.tree-node.selected .floating-toolbar,
.tree-node.is-menu-open .floating-toolbar {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

/* Hide toolbar during card drag */
.tree-node.dragging-card .floating-toolbar {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
  transition: none;
}

/* Hide toolbar during canvas pan */
.canvas-shell.dragging .floating-toolbar {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
  transition: none;
}

/* Hide toolbar at very low zoom */
.tree-canvas.zoom-hide-toolbar .floating-toolbar {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

/* Flipped variant — toolbar below card, nose pointing up */
.floating-toolbar.is-flipped {
  bottom: auto;
  top: calc(100% + 14px);
  transform-origin: top center;
}

.floating-toolbar.is-flipped::before {
  top: auto;
  bottom: 100%;
  border-width: 0 9px 9px 9px;
  border-color: transparent transparent rgba(133, 112, 80, 0.16) transparent;
}

.floating-toolbar.is-flipped::after {
  top: auto;
  bottom: calc(100% - 1px);
  border-width: 0 8px 8px 8px;
  border-color: transparent transparent rgba(255, 255, 255, 0.98) transparent;
}

.floating-toolbar::before,
.floating-toolbar::after {
  content: "";
  position: absolute;
  left: 50%;
  border-style: solid;
  transform: translateX(-50%);
  pointer-events: none;
}

.floating-toolbar::before {
  top: 100%;
  border-width: 9px 9px 0 9px;
  border-color: rgba(133, 112, 80, 0.16) transparent transparent transparent;
}

.floating-toolbar::after {
  top: calc(100% - 1px);
  border-width: 8px 8px 0 8px;
  border-color: rgba(255, 255, 255, 0.98) transparent transparent transparent;
}

.toolbar-btn {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #4a5750;
  font-size: 19px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.toolbar-btn:hover,
.toolbar-btn:focus-visible,
.node-menu.is-open .toolbar-btn.node-menu-trigger {
  background: rgba(31, 111, 99, 0.08);
  color: var(--card-accent);
}

.floating-toolbar .node-menu {
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  z-index: auto;
}

.floating-toolbar .node-menu-popover {
  top: calc(100% + 14px);
  right: auto;
  left: 50%;
  transform: translateX(-50%);
  transform-origin: top center;
}

.floating-toolbar .node-menu.is-above .node-menu-popover {
  top: auto;
  bottom: calc(100% + 14px);
  transform-origin: bottom center;
}

.floating-toolbar .node-menu.is-left-aligned .node-menu-popover {
  left: 0;
  transform: none;
  transform-origin: top left;
}

.floating-toolbar .node-menu.is-above.is-left-aligned .node-menu-popover {
  transform-origin: bottom left;
}

.node-menu-popover {
  top: calc(100% + 8px);
  right: 0;
  z-index: 120;
  width: min(340px, calc(100vw - 36px));
  min-width: 300px;
  max-height: calc(100vh - 156px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
  border: 1px solid rgba(133, 112, 80, 0.22);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.98);
  box-shadow:
    0 24px 58px rgba(52, 45, 31, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  transform: none;
  transform-origin: right top;
}

.node-add-popover {
  width: 248px;
  min-width: 248px;
}

.node-more-menu .node-menu-popover {
  width: 240px;
  min-width: 240px;
}

.node-add-popover .node-menu-section-primary {
  grid-template-columns: 1fr;
}

.node-menu.is-above .node-menu-popover {
  top: auto;
  bottom: calc(100% + 8px);
  transform-origin: right bottom;
}

.node-menu.is-left-aligned .node-menu-popover {
  right: auto;
  left: 0;
  transform-origin: left top;
}

.node-menu.is-above.is-left-aligned .node-menu-popover {
  transform-origin: left bottom;
}

.node-menu:hover .node-menu-popover {
  display: none;
}

.node-menu.is-open .node-menu-popover {
  display: grid;
  gap: 7px;
}

.node-menu-section {
  display: grid;
  gap: 4px;
  padding-top: 7px;
  border-top: 1px solid rgba(133, 112, 80, 0.16);
}

.node-menu-section-primary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.node-menu-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.node-menu-title {
  grid-column: 1 / -1;
  padding: 3px 7px;
  color: rgba(104, 115, 109, 0.82);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.node-menu-item {
  width: 100%;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 6px 8px;
  border-color: transparent;
  border-radius: 11px;
  color: #24312a;
  font-size: 13px;
  font-weight: 750;
  text-align: left;
}

.node-menu-section-primary .node-menu-item {
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 6px;
  min-height: 36px;
}

.node-menu-item:hover {
  background: rgba(31, 111, 99, 0.09);
}

.node-menu-section-primary .node-menu-item:hover {
  background: rgba(31, 111, 99, 0.11);
}

.node-menu-item.danger {
  color: #8a2f2f;
}

.node-menu-item.danger:hover {
  background: rgba(138, 47, 47, 0.08);
}

.node-menu-icon {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(31, 111, 99, 0.08);
  color: var(--card-accent);
  font-size: 14px;
  font-weight: 900;
}

.node-menu-section-primary .node-menu-icon {
  width: 24px;
  height: 24px;
  font-size: 13px;
}

.node-menu-item.danger .node-menu-icon {
  background: rgba(138, 47, 47, 0.08);
  color: #8a2f2f;
}

.node-menu-item strong,
.node-menu-item small {
  display: block;
  min-width: 0;
}

.node-menu-section-primary .node-menu-item small {
  display: none;
}

.node-menu-section-primary .node-menu-item strong {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

.node-menu-item strong {
  overflow: hidden;
  color: inherit;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-menu-item small {
  margin-top: 2px;
  color: rgba(104, 115, 109, 0.82);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
}
