.heirloom-tree-root {
	display: block;
	position: relative;
	width: 100%;
	height: calc(100vh - 120px);
	min-height: 600px;
}

.heirloom-tree-loading {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	background: var(--surface-muted, #f4efe4);
	color: var(--text-muted, #6e6152);
	font-family: var(--font-sans, Inter, sans-serif);
	font-size: 14px;
	border-radius: 12px;
}

.heirloom-tree-spinner {
	width: 28px;
	height: 28px;
	border: 3px solid rgba(184, 134, 62, 0.2);
	border-top-color: var(--primary, #3f5d45);
	border-radius: 50%;
	animation: heirloom-tree-spin 0.8s linear infinite;
}

@keyframes heirloom-tree-spin {
	to { transform: rotate(360deg); }
}

.heirloom-tree {
	position: relative;
	width: 100%;
	height: 100%;
	min-height: 600px;
	overflow: hidden;
	background-color: var(--surface-muted, #f4efe4);
	background-image: 
		radial-gradient(circle at 1px 1px, rgba(195, 178, 143, 0.25) 1px, transparent 0);
	background-size: 24px 24px;
	border: 1px solid var(--border, #ddd0b8);
	border-radius: 12px;
	user-select: none;
	-webkit-user-select: none;
	font-family: var(--font-sans, Inter, -apple-system, sans-serif);
}

/* Header & Controls Toolbar */
.heirloom-tree__header {
	position: absolute;
	top: 14px;
	left: 14px;
	right: 14px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	z-index: 10;
	pointer-events: none;
}

.heirloom-tree__header-left,
.heirloom-tree__header-right {
	display: flex;
	align-items: center;
	gap: 10px;
	pointer-events: auto;
}

/* View Mode Switcher Pills */
.heirloom-tree__view-toggle {
	display: inline-flex;
	align-items: center;
	background: var(--surface, #ffffff);
	border: 1px solid var(--border, #ddd0b8);
	border-radius: 999px;
	padding: 3px;
	box-shadow: 0 2px 8px rgba(43, 35, 24, 0.08);
}

.heirloom-tree__view-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 14px;
	border-radius: 999px;
	border: none;
	background: transparent;
	color: var(--text-muted, #6e6152);
	font-family: var(--font-sans, Inter, sans-serif);
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.02em;
	cursor: pointer;
	transition: all 0.15s ease;
}

.heirloom-tree__view-btn svg {
	width: 14px;
	height: 14px;
}

.heirloom-tree__view-btn:hover {
	color: var(--ink, #2b2318);
}

.heirloom-tree__view-btn.is-active {
	background: var(--primary, #3f5d45);
	color: #ffffff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Centered-On Search Selector */
.heirloom-tree__search-wrap {
	position: relative;
	display: flex;
	align-items: center;
	background: var(--surface, #ffffff);
	border: 1px solid var(--border, #ddd0b8);
	border-radius: 999px;
	padding: 4px 14px 4px 12px;
	box-shadow: 0 2px 8px rgba(43, 35, 24, 0.08);
	gap: 8px;
}

.heirloom-tree__search-icon {
	color: var(--text-muted, #8c8577);
	display: flex;
	align-items: center;
}

.heirloom-tree__search-input {
	border: none;
	background: transparent;
	font-family: var(--font-serif, 'Playfair Display', serif);
	font-size: 14px;
	font-weight: 600;
	color: var(--ink, #2b2318);
	width: 190px;
	outline: none;
}

.heirloom-tree__search-input::placeholder {
	font-family: var(--font-sans, Inter, sans-serif);
	font-size: 12px;
	font-weight: 400;
	color: var(--text-muted, #8c8577);
}

.heirloom-tree__search-dropdown {
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	width: 260px;
	max-height: 280px;
	overflow-y: auto;
	background: var(--surface, #ffffff);
	border: 1px solid var(--border, #ddd0b8);
	border-radius: 10px;
	box-shadow: 0 8px 24px rgba(43, 35, 24, 0.14);
	display: flex;
	flex-direction: column;
	padding: 4px;
	z-index: 50;
}

.heirloom-tree__search-item {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-radius: 6px;
	border: none;
	background: transparent;
	text-align: left;
	cursor: pointer;
	color: var(--ink, #2b2318);
	font-family: var(--font-sans, Inter, sans-serif);
	transition: background-color 0.15s ease;
}

.heirloom-tree__search-item:hover,
.heirloom-tree__search-item.is-selected {
	background-color: var(--surface-muted, #f4efe4);
}

.heirloom-tree__search-item-info {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.heirloom-tree__search-item-name {
	font-family: var(--font-serif, 'Playfair Display', serif);
	font-size: 13px;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.heirloom-tree__search-item-years {
	font-size: 11px;
	color: var(--text-muted, #8c8577);
}

.heirloom-tree__search-clear {
	background: transparent;
	border: none;
	color: var(--text-muted, #8c8577);
	cursor: pointer;
	font-size: 16px;
	line-height: 1;
	padding: 0 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: color 0.15s ease;
}

.heirloom-tree__search-clear:hover {
	color: var(--ink, #2b2318);
}

.heirloom-tree__search-thumb {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
	border: 1px solid var(--border, #ddd0b8);
}

.heirloom-tree__search-empty {
	padding: 12px 14px;
	font-size: 12px;
	color: var(--text-muted, #8c8577);
	text-align: center;
}

/* Viewport & Canvas */
.heirloom-tree__viewport {
	position: absolute;
	inset: 0;
	overflow: hidden;
	cursor: grab;
	touch-action: none;
}

.heirloom-tree__viewport.is-dragging {
	cursor: grabbing;
}

.heirloom-tree__canvas {
	position: absolute;
	top: 0;
	left: 0;
	transform-origin: 0 0;
	will-change: transform;
}

.heirloom-tree__lines {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 1;
	pointer-events: none;
	overflow: visible;
}

.heirloom-tree__cards {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 2;
}

/* Connecting Lines */
.heirloom-tree__line {
	stroke: var(--border, #c3b28f);
	stroke-width: 1.75;
	stroke-linecap: round;
	stroke-linejoin: round;
	fill: none;
	transition: stroke 0.2s ease;
}

.heirloom-tree__line.is-highlighted {
	stroke: var(--primary, #3f5d45);
	stroke-width: 2.25;
}

.heirloom-tree__tie {
	stroke: var(--accent, #b8863e);
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
	fill: none;
}

.heirloom-tree__tie-dot {
	fill: var(--accent, #b8863e);
}

/* Multi-partner relationship lines, dots & descent lines (Ancestry-style stepped colors) */
.heirloom-tree__tie--rel-0 {
	stroke: #7396a6;
}
.heirloom-tree__tie-dot--rel-0 {
	fill: #7396a6;
}
.heirloom-tree__line--rel-0 {
	stroke: #7396a6;
}

.heirloom-tree__tie--rel-1 {
	stroke: #c47d62;
}
.heirloom-tree__tie-dot--rel-1 {
	fill: #c47d62;
}
.heirloom-tree__line--rel-1 {
	stroke: #c47d62;
}

.heirloom-tree__tie--rel-2 {
	stroke: #80638e;
}
.heirloom-tree__tie-dot--rel-2 {
	fill: #80638e;
}
.heirloom-tree__line--rel-2 {
	stroke: #80638e;
}

.heirloom-tree__tie--rel-3 {
	stroke: #4f8a70;
}
.heirloom-tree__tie-dot--rel-3 {
	fill: #4f8a70;
}
.heirloom-tree__line--rel-3 {
	stroke: #4f8a70;
}

.heirloom-tree__label-bg {
	fill: var(--surface-muted, #f4efe4);
	stroke: var(--border, #ddd0b8);
	stroke-width: 0.75;
	opacity: 0.96;
}

.heirloom-tree__label-text {
	font-family: var(--font-sans, Inter, sans-serif);
	font-size: 10.5px;
	font-weight: 600;
	fill: var(--text-muted, #736b5e);
	letter-spacing: 0.01em;
	pointer-events: none;
}

/* Ancestry-Style Person Card */
.heirloom-tree__card {
	position: absolute;
	display: flex;
	align-items: center;
	box-sizing: border-box;
	padding: 0 12px;
	background: var(--surface, #ffffff);
	border: 1px solid var(--border, #ddd0b8);
	border-radius: 8px;
	text-decoration: none;
	color: var(--ink, #2b2318);
	box-shadow: 0 2px 6px rgba(43, 35, 24, 0.06);
	transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
	cursor: pointer;
	overflow: visible;
}

.heirloom-tree__card:hover {
	border-color: var(--accent, #b8863e);
	box-shadow: 0 4px 14px rgba(43, 35, 24, 0.12);
	transform: translateY(-1px);
	z-index: 20;
}

/* Card Targeted & Focus State */
.heirloom-tree__card.is-root {
	border-color: var(--primary, #3f5d45);
	box-shadow: 0 3px 10px rgba(63, 93, 69, 0.14);
}

.heirloom-tree__card.is-targeted {
	z-index: 30 !important;
	border-color: var(--accent, #b8863e);
	box-shadow: 0 6px 18px rgba(43, 35, 24, 0.16);
}

/* Avatar / Portrait */
.heirloom-tree__card-avatar {
	flex-shrink: 0;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	object-fit: cover;
	border: 1px solid var(--border, #ddd0b8);
	margin-right: 10px;
	background-color: var(--surface-muted, #ede8db);
}

.heirloom-tree__card-avatar--placeholder {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background-size: cover;
	background-position: center;
}

.heirloom-tree__card-avatar--placeholder.is-male {
	background-color: #dce7ea;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 80'%3E%3Crect width='80' height='80' fill='%23dce7ea'/%3E%3Ccircle cx='40' cy='31' r='13' fill='%236f8f9e'/%3E%3Cpath d='M16 72c3-14 14-21 24-21s21 7 24 21' fill='%236f8f9e'/%3E%3C/svg%3E");
}

.heirloom-tree__card-avatar--placeholder.is-female {
	background-color: #f3dede;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 80'%3E%3Crect width='80' height='80' fill='%23f3dede'/%3E%3Ccircle cx='40' cy='31' r='13' fill='%23a8767e'/%3E%3Cpath d='M16 72c3-14 14-21 24-21s21 7 24 21' fill='%23a8767e'/%3E%3C/svg%3E");
}

.heirloom-tree__card-avatar--placeholder.is-unknown {
	background-color: var(--surface-muted, #ede8db);
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 80'%3E%3Crect width='80' height='80' fill='%23ede8db'/%3E%3Ccircle cx='40' cy='31' r='13' fill='%23b8aa93'/%3E%3Cpath d='M16 72c3-14 14-21 24-21s21 7 24 21' fill='%23b8aa93'/%3E%3C/svg%3E");
}

/* Card Content */
.heirloom-tree__card-content {
	display: flex;
	flex-direction: column;
	min-width: 0;
	flex: 1;
	overflow: hidden;
	padding-right: 22px;
}

.heirloom-tree__card-name {
	font-family: var(--font-serif, 'Playfair Display', serif);
	font-size: 13.5px;
	font-weight: 600;
	color: var(--ink, #2b2318);
	line-height: 1.25;
	margin: 0 0 2px 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.heirloom-tree__card-married {
	font-weight: 400;
	color: var(--text-muted, #8c8577);
	font-size: 11.5px;
}

.heirloom-tree__card-dates {
	font-family: var(--font-sans, Inter, sans-serif);
	font-size: 11.5px;
	color: var(--text-muted, #6e6152);
	margin: 0;
	line-height: 1.25;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.heirloom-tree__card-relation {
	font-family: var(--font-sans, Inter, sans-serif);
	font-size: 11px;
	font-weight: 600;
	color: var(--primary, #3f5d45);
	margin: 2px 0 0 0;
	line-height: 1.2;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.heirloom-tree__card-actions {
	position: absolute;
	top: 6px;
	right: 6px;
	z-index: 25;
}

.heirloom-tree__card-menu-btn {
	width: 24px;
	height: 24px;
	border-radius: 50%;
	border: 1px solid transparent;
	background: transparent;
	color: var(--text-muted, #736b5e);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: all 0.15s ease;
	opacity: 0.75;
	padding: 0;
}

.heirloom-tree__card:hover .heirloom-tree__card-menu-btn,
.heirloom-tree__card:focus-within .heirloom-tree__card-menu-btn,
.heirloom-tree__card-menu-btn.is-active {
	opacity: 1;
	color: var(--ink, #2b2318);
}

.heirloom-tree__card-menu-btn:hover,
.heirloom-tree__card-menu-btn.is-active {
	background: var(--surface-muted, #ede8db);
	color: var(--ink, #2b2318);
	border-color: var(--border, #ddd0b8);
}

.heirloom-tree__card-menu {
	position: absolute;
	top: calc(100% + 4px);
	right: 0;
	min-width: 160px;
	background: var(--surface, #ffffff);
	border: 1px solid var(--border, #ddd0b8);
	border-radius: 8px;
	box-shadow: 0 8px 24px rgba(43, 35, 24, 0.16);
	display: none;
	flex-direction: column;
	padding: 4px;
	z-index: 100;
}

.heirloom-tree__card-menu.is-open {
	display: flex;
}

.heirloom-tree__menu-item {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 7px 10px;
	border-radius: 6px;
	border: none;
	background: transparent;
	color: var(--ink, #2b2318);
	font-family: var(--font-sans, Inter, sans-serif);
	font-size: 12px;
	font-weight: 500;
	text-decoration: none;
	cursor: pointer;
	text-align: left;
	width: 100%;
	box-sizing: border-box;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.heirloom-tree__menu-item svg {
	flex-shrink: 0;
	color: var(--text-muted, #8c8577);
}

.heirloom-tree__menu-item:hover {
	background-color: var(--surface-muted, #f4efe4);
	color: var(--primary, #3f5d45);
}

.heirloom-tree__menu-item:hover svg {
	color: var(--primary, #3f5d45);
}

/* Ancestry Spouses / Partners Button & Dropdown Popover */
.heirloom-tree__popovers {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 500;
	pointer-events: auto;
}

.heirloom-tree__partners-btn {
	position: absolute;
	top: 6px;
	left: 6px;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: rgba(35, 30, 24, 0.65);
	color: #ffffff;
	border: 1px solid rgba(255, 255, 255, 0.4);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	z-index: 25;
	padding: 0;
	transition: background-color 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.heirloom-tree__partners-btn svg {
	pointer-events: none;
}

.heirloom-tree__partners-btn:hover {
	background: var(--primary, #3f5d45);
	border-color: #ffffff;
	transform: scale(1.1);
}

.heirloom-tree__partners-popover {
	position: absolute;
	width: 295px;
	background: #ffffff;
	border: 1px solid var(--border, #ddd0b8);
	border-radius: 10px;
	box-shadow: 0 10px 32px rgba(43, 35, 24, 0.22);
	z-index: 500;
	padding: 14px 16px;
	box-sizing: border-box;
	animation: heirloom-fade-in 0.15s ease-out;
}

.heirloom-tree__partners-popover::before {
	content: '';
	position: absolute;
	top: -6px;
	left: 14px;
	width: 10px;
	height: 10px;
	background: #ffffff;
	border-left: 1px solid var(--border, #ddd0b8);
	border-top: 1px solid var(--border, #ddd0b8);
	transform: rotate(45deg);
	z-index: 1;
}

.heirloom-tree__partners-popover-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 12px;
	padding-bottom: 8px;
	border-bottom: 1px solid var(--surface-muted, #ede8db);
}

.heirloom-tree__partners-popover-title {
	font-family: var(--font-sans, Inter, sans-serif);
	font-size: 14px;
	font-weight: 700;
	color: var(--ink, #2b2318);
	margin: 0;
}

.heirloom-tree__partners-popover-close {
	background: transparent;
	border: none;
	font-size: 18px;
	line-height: 1;
	color: var(--text-muted, #8c8577);
	cursor: pointer;
	padding: 2px 5px;
	border-radius: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.heirloom-tree__partners-popover-close:hover {
	color: var(--ink, #2b2318);
	background: var(--surface-muted, #ede8db);
}

.heirloom-tree__partners-list {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.heirloom-tree__partner-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 4px 0;
}

.heirloom-tree__partner-info {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
	flex: 1;
}

.heirloom-tree__partner-thumb {
	width: 38px;
	height: 38px;
	border-radius: 6px;
	object-fit: cover;
	flex-shrink: 0;
	border: 1px solid var(--border, #ddd0b8);
	background-color: var(--surface-muted, #ede8db);
}

.heirloom-tree__partner-names {
	min-width: 0;
	flex: 1;
}

.heirloom-tree__partner-name {
	font-family: var(--font-sans, Inter, sans-serif);
	font-size: 13.5px;
	font-weight: 700;
	color: #0b6794;
	line-height: 1.25;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.heirloom-tree__partner-sub {
	font-size: 11.5px;
	color: var(--text-muted, #8c8577);
	margin-top: 2px;
}

/* Ancestry Toggle Switch */
.heirloom-tree__toggle {
	position: relative;
	display: inline-block;
	width: 44px;
	height: 24px;
	flex-shrink: 0;
}

.heirloom-tree__toggle input {
	opacity: 0;
	width: 0;
	height: 0;
	position: absolute;
}

.heirloom-tree__toggle-slider {
	position: absolute;
	cursor: pointer;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: #cbd5e1;
	transition: background-color 0.2s ease;
	border-radius: 24px;
}

.heirloom-tree__toggle-slider:before {
	position: absolute;
	content: "";
	height: 18px;
	width: 18px;
	left: 3px;
	bottom: 3px;
	background-color: #ffffff;
	transition: transform 0.2s ease;
	border-radius: 50%;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.heirloom-tree__toggle input:checked + .heirloom-tree__toggle-slider {
	background-color: #19779b;
}

.heirloom-tree__toggle input:checked + .heirloom-tree__toggle-slider:before {
	transform: translateX(20px);
}

.heirloom-tree__toggle input:disabled + .heirloom-tree__toggle-slider {
	opacity: 0.6;
	cursor: not-allowed;
}

/* Branch Expand Button (Ancestry + / > badge) */
.heirloom-tree__expand {
	position: absolute;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	border: 1px solid var(--border, #ddd0b8);
	background: var(--surface, #ffffff);
	color: var(--ink, #2b2318);
	font-size: 12px;
	font-weight: 700;
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	box-shadow: 0 2px 5px rgba(43, 35, 24, 0.1);
	transition: all 0.15s ease;
	z-index: 5;
}

.heirloom-tree__expand:hover {
	background: var(--primary, #3f5d45);
	color: #ffffff;
	border-color: var(--primary, #3f5d45);
	transform: scale(1.1);
}

.heirloom-tree__expand--right {
	right: -11px;
	top: 50%;
	transform: translateY(-50%);
}

.heirloom-tree__expand--right:hover {
	transform: translateY(-50%) scale(1.1);
}

.heirloom-tree__expand--up {
	top: -11px;
	left: 50%;
	transform: translateX(-50%);
}

.heirloom-tree__expand--up:hover {
	transform: translateX(-50%) scale(1.1);
}

.heirloom-tree__expand--down {
	bottom: -11px;
	left: 50%;
	transform: translateX(-50%);
}

.heirloom-tree__expand--down:hover {
	transform: translateX(-50%) scale(1.1);
}

/* Bottom Navigation / Zoom Controls */
.heirloom-tree__controls {
	position: absolute;
	right: 18px;
	bottom: 18px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	z-index: 10;
}

.heirloom-tree__control {
	width: 36px;
	height: 36px;
	padding: 0;
	border-radius: 50%;
	border: 1px solid var(--border, #ddd0b8);
	background: var(--surface, #ffffff);
	color: var(--ink, #2b2318);
	font-size: 15px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 2px 8px rgba(43, 35, 24, 0.08);
	transition: all 0.15s ease;
}

.heirloom-tree__control:hover {
	border-color: var(--primary, #3f5d45);
	color: var(--primary, #3f5d45);
	transform: translateY(-1px);
	box-shadow: 0 4px 12px rgba(43, 35, 24, 0.14);
}

/* Full Width Container on Family Tree Page */
.family-tree-main {
	padding: 16px 20px 24px;
	max-width: 1600px;
	margin: 0 auto;
	width: 100%;
}

.family-tree-wrapper {
	width: 100%;
	height: calc(100vh - 120px);
	min-height: 600px;
}
