.tree-wrap {
	max-height: 30vh;
	overflow: auto;
	padding: 8px;
	background: #fff;
}

.tree-root,
.tree-root ul {
	list-style: none;
	margin: 0;
	padding-left: 0;
}

.tree-root ul {
	margin-left: 12px;
	padding-left: 12px;
	border-left: 1px solid #e0cdb9;
}

.tree-node {
	margin: 3px 0;
}

details > summary {
	display: flex;
	align-items: center;
	gap: 3px;
	cursor: pointer;
	list-style: none;
}

details > summary::-webkit-details-marker {
	display: none;
}

.tree-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 16px;
	height: 16px;
	flex: 0 0 16px;
	color: #6c5a49;
}

.tree-toggle::before {
	content: "";
	display: block;
	width: 0;
	height: 0;
	border-top: 5px solid transparent;
	border-bottom: 5px solid transparent;
	border-left: 6px solid currentColor;
	transition: transform 0.12s ease;
}

details[open] > summary .tree-toggle::before {
	transform: rotate(90deg);
}

.tree-item {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	max-width: 100%;
	min-width: 0;
	padding: 7px 8px;
	border-radius: 6px;
	background: transparent;
	color: var(--text-strong, #3f3428);
	font-weight: 700;
	cursor: grab;
	user-select: none;
}

.tree-item:hover,
.tree-item.selected {
	background: var(--panel-hover, #f5eadc);
}

.tree-item:active {
	cursor: grabbing;
}

.tree-item.synthetic {
	color: var(--synthetic, #8b5d2a);
}

.tree-item-label {
	display: inline-flex;
	align-items: baseline;
	gap: 0.35em;
	flex: 1 1 auto;
	min-width: 0;
	max-width: 100%;
	white-space: normal;
}

.tree-item-name {
	min-width: 0;
	overflow-wrap: normal;
	word-break: normal;
}

.tree-item-meta {
	flex: 0 0 auto;
	font-size: 0.85em;
	color: var(--muted, #8a8173);
	white-space: nowrap;
}

#wiki-sync-territory-tree .tree-item {
	display: inline-grid;
	grid-template-columns: auto minmax(0, max-content);
	grid-template-rows: auto auto;
	align-items: center;
	justify-content: start;
	justify-items: start;
	width: max-content;
	max-width: 100%;
	column-gap: 7px;
	/* Zeilenabstand + Padding einheitlich wie die anderen WikiSync-Listen (Siedlungen-Referenz). */
	row-gap: 7px;
	padding: 6px 8px;
}

#wiki-sync-territory-tree .drag-handle {
	grid-column: 1;
	grid-row: 1 / span 2;
	align-self: center;
}

#wiki-sync-territory-tree .tree-item-name {
	grid-column: 2;
	grid-row: 1;
	line-height: 1.22;
}

#wiki-sync-territory-tree .tree-item-name::after {
	content: "";
	display: inline-block;
	width: 13px;
	height: 13px;
	margin-left: 7px;
	vertical-align: -2px;
	border: 2px solid #6a7f3a;
	border-radius: 50%;
	background: #fffaf4;
	box-sizing: border-box;
	color: #6a7f3a;
}

#wiki-sync-territory-tree .tree-item:has(.tree-map-status--children-only) .tree-item-name::after {
	background: linear-gradient(to right, #6a7f3a 0 50%, #fffaf4 50% 100%);
}

#wiki-sync-territory-tree .tree-item:has(.tree-map-status--own-only) .tree-item-name::after {
	background: linear-gradient(to right, #fffaf4 0 50%, #6a7f3a 50% 100%);
}

#wiki-sync-territory-tree .tree-item:has(.tree-map-status--all) .tree-item-name::after {
	background: #6a7f3a;
}

#wiki-sync-territory-tree .tree-item-meta {
	grid-column: 2;
	grid-row: 2;
	font-size: 0.78em;
	font-weight: 600;
	line-height: 1.2;
	white-space: normal;
}

#wiki-sync-territory-tree .tree-map-status {
	display: none;
}

.tree-map-status,
.legend-map-status {
	position: relative;
	width: 13px;
	height: 13px;
	flex: 0 0 13px;
	border: 2px solid #6a7f3a;
	border-radius: 50%;
	background: #fffaf4;
	box-sizing: border-box;
	color: #6a7f3a;
	overflow: hidden;
}

.tree-map-status--own-only::before,
.tree-map-status--children-only::before,
.legend-map-status--children-only::before,
.legend-map-status--own-only::before {
	content: "";
	position: absolute;
	top: 1px;
	bottom: 1px;
	background: currentColor;
}

.tree-map-status--children-only::before,
.legend-map-status--children-only::before {
	left: 1px;
	right: 50%;
	border-radius: 999px 0 0 999px;
}

.tree-map-status--own-only::before,
.legend-map-status--own-only::before {
	left: 50%;
	right: 1px;
	border-radius: 0 999px 999px 0;
}

.tree-map-status--all,
.legend-map-status--all {
	background: currentColor;
}

.tree-separator {
	margin: 9px 0 6px 0;
	padding: 0 8px;
	color: var(--muted-2, #806c59);
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.04em;
}

.tree-root ul .tree-separator {
	display: none;
}

.tree-separator::before,
.tree-separator::after {
	content: "---";
	color: #c6aa8c;
}

.tree-separator::before {
	margin-right: 6px;
}

.tree-separator::after {
	margin-left: 6px;
}

.drag-handle {
	flex: 0 0 auto;
	font-size: 12px;
	color: #7a6652;
	letter-spacing: -1px;
}
