/* Folder Tree Container */
.folder-tree-search-container,
folder-tree-container,
taxonomy-tree-container {
	display: flex;
	flex-direction: column;
	gap: 0.125rem;
	width: 100%;
	height: 100%;
	position: static;
	flex: 1;
}

.folder-tree-container-menu {
	display: flex;
	flex-direction: row;
	gap: 0.25rem;
	margin-bottom: 0.25rem;
	padding-bottom: 0.5rem;
	border-bottom: 1px solid var(--border);
	align-items: center;
}

.folder-tree-container-menu .container-menu-item {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	padding: 0.25rem 0.25rem;
	background-color: var(--background-step-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	color: var(--text-normal);
	font-size: 12px;
	cursor: pointer;
	transition:
		background-color 0.15s ease,
		border-color 0.15s ease;

	&:hover {
		background-color: var(--background-step-3);
		border-color: var(--primary-base);
	}

	&:active {
		background-color: var(--background-step-3);
	}

	svg {
		color: var(--text-muted);
		transition: color 0.15s ease;
	}

	&:hover svg {
		color: var(--primary-base);
	}
}

/* Custom Elements - ensure no positioning context */
folder-tree-node,
folder-tree-leaf {
	position: static;
}

/* Context Menu */
.context-menu {
	display: none;
	position: fixed;
	background-color: var(--background-step-1);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	box-shadow: 0 4px 12px var(--shadow);
	padding: 0.25rem;
	min-width: 180px;
	width: max-content;
	z-index: 1000;

	&.active {
		display: block;
		animation: contextMenuFadeIn 0.15s ease forwards;
	}
}

@keyframes contextMenuFadeIn {
	from {
		opacity: 0;
		transform: scale(0.95) translateY(-4px);
	}

	to {
		opacity: 1;
		transform: scale(1) translateY(0);
	}
}

.context-menu-item {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	width: 100%;
	padding: 0.5rem 0.75rem;
	background: none;
	border: none;
	border-radius: var(--radius-sm);
	color: var(--text-normal);
	font-size: 0.875rem;
	cursor: pointer;
	transition:
		background-color 0.15s ease,
		transform 0.1s ease;
	text-align: left;

	&:hover {
		background-color: var(--background-step-2);
		transform: translateX(2px);
	}

	&:active {
		background-color: var(--background-step-3);
		transform: translateX(1px);
	}

	svg {
		color: var(--text-muted);
		flex-shrink: 0;
		transition:
			color 0.15s ease,
			transform 0.2s ease;
	}

	&:hover svg {
		color: var(--primary-base);
		transform: scale(1.1);
	}
}

/* Tree Node (Folder) */
.tree-node {
	display: flex;
	flex-direction: column;
	width: 100%;
}

.tree-node-header {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	padding: 0.375rem 0rem;
	border-radius: var(--radius-md);
	transition: background-color 0.15s ease;
	cursor: pointer;
	user-select: none;

	&:hover {
		background-color: var(--background-step-2);

		.tree-node-label {
			color: var(--text-normal);
		}
	}
}

.tree-node-menu-trigger {
	margin-left: auto;
	padding: 0.25rem;
	background: inherit;
	border: none;
	border-radius: var(--radius-md);
	cursor: pointer;
	color: var(--text-muted);
	transition: color 0.15s ease;
	display: flex;
	align-items: center;
	justify-content: center;

	&:hover {
		color: var(--text-normal);
		background: var(--background-step-3);
	}
}

.tree-node-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0.125rem;
	background: none;
	border: none;
	cursor: pointer;
	color: var(--text-muted);
	transition: color 0.15s ease;
	flex-shrink: 0;
	position: absolute;
	pointer-events: none;

	&:hover {
		color: var(--text-normal);
	}

	.chevron-icon {
		transition: transform 0.2s ease;
	}
}

.tree-node[aria-expanded="true"] > .tree-node-header > .tree-node-toggle .chevron-icon {
	transform: rotate(90deg);
}

.tree-node-content {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	flex: 1;
	min-width: 0;
}

.folder-icon {
	flex-shrink: 0;
	color: var(--text-muted);
	transition:
		color 0.15s ease,
		transform 0.2s ease;

	/* Default state */
	&.closed {
		display: block;
	}

	&.open,
	&.selected {
		display: none;
	}
}

.tree-node-header:hover .folder-icon {
	transform: scale(1.1);
}

/* Folder expanded state */
.tree-node[aria-expanded="true"] > .tree-node-header .folder-icon {
	&.closed {
		display: none;
	}

	&.open {
		display: block;
		color: var(--primary-base);
		animation: folderBounce 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
	}
}

@keyframes folderBounce {
	0% {
		transform: scale(0.8) rotate(-10deg);
		opacity: 0.5;
	}

	50% {
		transform: scale(1.15) rotate(5deg);
	}

	100% {
		transform: scale(1) rotate(0deg);
		opacity: 1;
	}
}

/* Folder active/selected state */
.tree-node[aria-current="page"] > .tree-node-header .folder-icon {
	&.closed,
	&.open {
		display: none;
	}

	&.selected {
		display: block;
		color: var(--primary-base);
	}
}

.tree-node-label {
	font-size: 1rem;
	color: var(--text-muted);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	transition: color 0.15s ease;
}

.tree-node-children {
	display: grid;
	grid-template-rows: 0fr;
	transition: grid-template-rows 0.3s ease;
	pointer-events: none;
}

.tree-node-children-inner {
	overflow: hidden;
	margin-left: 0;
	padding-left: 0;
	border-left: none;
	opacity: 0;
	transition:
		opacity 0.25s ease,
		margin-left 0.3s ease,
		padding-left 0.3s ease,
		border-left 0.3s ease;
}

.tree-node[aria-expanded="true"] > .tree-node-children {
	grid-template-rows: 1fr;
	pointer-events: auto;
}

.tree-node[aria-expanded="true"] > .tree-node-children .tree-node-children-inner {
	opacity: 1;
	margin-left: 0.75rem;
	padding-left: 0.75rem;
	border-left: 1px solid var(--border);
}

/* Tree Leaf (Page) */
.tree-leaf {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.375rem 0;
	border-radius: var(--radius-md);
	transition:
		background-color 0.15s ease,
		color 0.15s ease,
		transform 0.1s ease;
	cursor: pointer;
	user-select: none;
	text-decoration: none;
	color: var(--text-muted);

	&:hover {
		background-color: var(--background-step-2);
		color: var(--text-normal);
		transform: translateX(3px);

		.leaf-icon {
			color: var(--text-normal);
			transform: scale(1.1) rotate(-5deg);
		}

		.draft-badge {
			background-color: var(--warning-flat-hover);
			transform: scale(1.05);
		}
	}

	&:focus-visible {
		outline: 2px solid var(--primary-base);
		outline-offset: -2px;
	}

	&[aria-current="page"] {
		color: var(--text-normal);

		.leaf-icon {
			color: var(--text-normal);

			&.default {
				display: none;
			}

			&.active {
				display: block;
				color: var(--primary-base);
			}
		}
	}
}

.leaf-icon {
	flex-shrink: 0;
	color: var(--text-muted);
	transition:
		color 0.15s ease,
		transform 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);

	&.active {
		display: none;
	}
}

.tree-leaf-label {
	font-size: 1rem;
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Badges */
.leaf-badge {
	font-size: 0.625rem;
	padding: 0.125rem 0.375rem;
	border-radius: var(--radius-sm);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.025em;
}

.draft-badge {
	background-color: var(--warning-flat);
	color: var(--warning-base);
	transition:
		background-color 0.15s ease,
		transform 0.2s ease;
	animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
	0%,
	100% {
		opacity: 1;
	}

	50% {
		opacity: 0.8;
	}
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
	/* Disable all animations */
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}

	/* Remove transforms on hover/interaction */
	.context-menu-item:hover,
	.context-menu-item:active,
	.context-menu-item:hover svg,
	.tree-node-toggle .chevron-icon,
	.tree-node-header:hover .folder-icon,
	.tree-node-children,
	.tree-node-children-inner,
	.tree-leaf:hover,
	.tree-leaf:hover .leaf-icon,
	.tree-leaf:hover .draft-badge {
		transform: none;
	}

	.draft-badge,
	.context-menu.active,
	.tree-node[aria-expanded="true"] > .tree-node-header .folder-icon.open {
		animation: none;
	}

	.folder-icon,
	.leaf-icon {
		transition: color 0.01ms;
	}

	.tree-node[aria-expanded="true"] > .tree-node-header > .tree-node-toggle .chevron-icon {
		transform: rotate(90deg);
	}
}
