/* ========================================================================
   Sidebar — flush, full-height design
   ======================================================================== */

/* Mobile-first: Sidebar wrapper */
.sidebar-wrapper {
	position: relative;
}

/* Core sidebar — hidden off-screen on mobile, flush on desktop */
.sidebar {
	--sidebar-width: 240px;
	--sidebar-collapsed-width: 60px;
	/* Match app minimum text (base.css --fs-450); do not use sub-body rem here */
	--sidebar-font: var(--fs-450);
	font-family: "Inter", system-ui, sans-serif;
	font-size: var(--sidebar-font);
	letter-spacing: 0.01em;
	position: fixed;
	top: 0;
	left: 0;
	height: 100vh;
	height: 100dvh;
	width: 75vw;
	max-width: 280px;
	background-color: var(--clr-surface-1);
	color: var(--clr-text-high);
	border-right: 1px solid var(--clr-border);
	padding: 0.75rem 0.5rem;
	margin: 0;
	transition: transform 0.25s ease, width 0.25s ease;
	overflow-y: auto;
	overflow-x: hidden;
	z-index: 1000;
	transform: translateX(-100%);
	display: flex;
	flex-direction: column;

	&.active {
		transform: translateX(0);
	}

	&::-webkit-scrollbar {
		width: 4px;
	}

	&::-webkit-scrollbar-track {
		background: transparent;
	}

	&::-webkit-scrollbar-thumb {
		background-color: var(--clr-scrollbar-thumb);
		border-radius: 4px;
	}
}

/* Ensure sidebar stays hidden on small screens unless .active (desktop override at 992px) */

/* Desktop — flush, full-height */
@media (min-width: 992px) {
	.mobile-menu-toggle {
		display: none !important;
	}

	.sidebar-overlay {
		display: none !important;
	}

	.sidebar {
		width: var(--sidebar-width);
		max-width: var(--sidebar-width);
		border-radius: 0;
		box-shadow: none;
		transform: translateX(0) !important;
		padding: 0.75rem 0.5rem;
		transition: width 0.25s ease, min-width 0.25s ease,
			max-width 0.25s ease, padding 0.25s ease;
	}

}

/* ---- Brand / header ---- */
.sidebar-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	flex-shrink: 0;
	padding-inline-end: 0.25rem;
}

.sidebar-brand {
	min-width: 0;
	flex: 1 1 auto;
}

.sidebar-mobile-close {
	display: none;
	align-items: center;
	justify-content: center;
	width: 2.5rem;
	height: 2.5rem;
	min-width: 2.5rem;
	min-height: 2.5rem;
	padding: 0;
	margin-block: 0.35rem 0;
	margin-inline: 0 0.25rem;
	border: none;
	border-radius: 0.375rem;
	background: transparent;
	color: var(--clr-text-medium);
	cursor: pointer;
	flex-shrink: 0;
	transition-property: background-color, color, scale;
	transition-duration: 0.15s;
	transition-timing-function: ease;
}

.sidebar-mobile-close:hover {
	background-color: color-mix(in srgb, var(--clr-text-high) 6%, transparent);
	color: var(--clr-text-high);
}

.sidebar-mobile-close:active {
	scale: 0.96;
}

.sidebar-mobile-close:focus-visible {
	outline: 2px solid var(--clr-focus);
	outline-offset: 2px;
}

.sidebar-mobile-close i[data-lucide],
.sidebar-mobile-close svg {
	width: 1.125rem;
	height: 1.125rem;
}

@media (max-width: 991.98px) {
	.sidebar-mobile-close {
		display: inline-flex;
	}

	/* Above mobile sheets / map chrome (same band as workspace-header menus) */
	.sidebar-overlay {
		z-index: 100001;
	}

	.sidebar {
		z-index: 100002;
	}
}

@media (min-width: 992px) {
	.sidebar-mobile-close {
		display: none !important;
	}
}

.sidebar-brand-link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	text-decoration: none;
	/* Keep the logo where the old text label used to sit. */
	margin-block-start: 0.5rem;
	margin-inline-start: 1.5rem;

	&:hover {
		opacity: 1;
		color: inherit;
	}
}

.sidebar-brand-logo {
	/* width: 100px; */
	height: 20px;
	/* border-radius: 4px; */
	object-fit: contain;
	flex-shrink: 0;
	outline: none;
}

.sidebar-brand-logo--collapsed {
	display: none;
	outline: none;
}

.sidebar-brand-name {
	font-size: var(--fs-450);
	font-weight: var(--fw-600);
	color: var(--clr-text-high);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* ---- Navigation ---- */
.sidebar-nav {
	list-style: none;
	padding: 0;
	margin: 2rem 0 0.25rem;
}

.sidebar-nav li {
	padding: 0.375rem 0.5rem;
	margin: 1px 0;
	border-radius: 0.375rem;
	transition: background 0.12s ease;
	cursor: pointer;
}

.sidebar-nav li:hover {
	background: color-mix(in srgb, var(--clr-text-high) 6%, transparent);
}

.sidebar-nav li a {
	display: flex;
	align-items: center;
	gap: 0.625rem;
	color: var(--clr-text-medium);
	font-size: var(--sidebar-font);
	font-weight: var(--fw-500);
	line-height: 1.4;
	text-decoration: none;

	i[data-lucide] {
		width: 16px;
		height: 16px;
		flex-shrink: 0;
	}

	span {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
}

.sidebar-nav li.sidebar-active {
	background: color-mix(in srgb, var(--clr-text-high) 10%, transparent);
}

.sidebar-nav li.sidebar-active a {
	color: var(--clr-text-high);
	font-weight: var(--fw-600);
}

/* Item with action button (e.g. Projects +) */
.sidebar-nav li.sidebar-item-with-action {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.375rem;

	>a:first-child {
		flex: 1;
		min-width: 0;
	}
}

.sidebar-action-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	min-width: 22px;
	padding: 0;
	border-radius: 0.25rem;
	background: transparent;
	border: 1px solid color-mix(in srgb, var(--clr-text-high) 14%, transparent);
	color: var(--clr-text-medium);
	transition: background 0.12s, color 0.12s, border-color 0.12s;
	flex-shrink: 0;
	text-decoration: none;

	&:hover {
		background: color-mix(in srgb, var(--clr-text-high) 6%, transparent);
		border-color: color-mix(in srgb, var(--clr-text-high) 22%, transparent);
		color: var(--clr-text-high);
	}

	i[data-lucide] {
		width: 12px;
		height: 12px;
	}
}

/* ---- Section labels ---- */
.sidebar-section-label {
	display: flex;
	align-items: center;
	padding: 0.75rem 0.5rem 0.25rem;
}

.sidebar-section-text {
	font-size: var(--sidebar-font);
	color: var(--clr-text-disabled);
}

/* ---- Pinned list ---- */
.sidebar-nav.sidebar-pinned-list {
	margin-top: 1rem;
}

.sidebar-pinned-list li a {
	font-size: var(--sidebar-font);
}

.sidebar-label-text {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* ---- Bottom nav (settings) ---- */
.sidebar-nav-bottom {
	margin-top: auto !important;
	flex-shrink: 0;
	padding-top: 0.25rem;
}

/* ========================================================================
   Collapsed state
   ======================================================================== */
@media (min-width: 992px) {
	.sidebar.collapsed {
		width: var(--sidebar-collapsed-width) !important;
		min-width: var(--sidebar-collapsed-width) !important;
		max-width: var(--sidebar-collapsed-width) !important;
		padding: 0.75rem 0.25rem !important;

		.sidebar-brand-name,
		.sidebar-section-label,
		.sidebar-action-btn {
			display: none !important;
		}

		.sidebar-brand {
			display: flex;
			justify-content: center;
			width: 100%;
			flex: 0 0 auto;
		}

		.sidebar-brand-link {
			width: 100%;
			margin-inline-start: 0;
			justify-content: center;
		}

		.sidebar-brand-logo--expanded {
			display: none;
		}

		.sidebar-brand-logo--collapsed {
			display: block;
			width: 18px;
			height: 18px;
		}

		.sidebar-header {
			justify-content: center;
			padding-inline-end: 0;
		}

		.sidebar-nav li {
			padding: 0.5rem;
			display: flex;
			justify-content: center;

			a {
				justify-content: center;
				gap: 0;

				i[data-lucide] {
					width: 18px;
					height: 18px;
				}

				span {
					display: none;
				}
			}

			&.sidebar-item-with-action {
				justify-content: center;
			}
		}

		.sidebar-pinned-list li a span.sidebar-label-text {
			display: none;
		}

		.sidebar-pinned-list li a {
			justify-content: center;
			gap: 0;

			i[data-lucide] {
				width: 18px;
				height: 18px;
			}
		}
	}
}

/* Prevent animation on page load */
html.sidebar-collapsed-on-load .sidebar {
	transition: none !important;
	width: var(--sidebar-collapsed-width, 60px) !important;
	min-width: var(--sidebar-collapsed-width, 60px) !important;
	max-width: var(--sidebar-collapsed-width, 60px) !important;
	padding: 0.75rem 0.25rem !important;

	.sidebar-brand-name,
	.sidebar-section-label,
	.sidebar-action-btn {
		display: none !important;
	}

	.sidebar-brand {
		display: flex;
		justify-content: center;
		width: 100%;
		flex: 0 0 auto;
	}

	.sidebar-brand-link {
		width: 100%;
		margin-inline-start: 0;
		justify-content: center;
	}

	.sidebar-brand-logo--expanded {
		display: none;
	}

	.sidebar-brand-logo--collapsed {
		display: block;
		width: 18px;
		height: 18px;
	}

	.sidebar-header {
		justify-content: center;
		padding-inline-end: 0;
	}

	.sidebar-nav li {
		padding: 0.5rem;
		display: flex;
		justify-content: center;

		a {
			justify-content: center;
			gap: 0;

			i[data-lucide] {
				width: 18px;
				height: 18px;
			}

			span {
				display: none;
			}
		}

		&.sidebar-item-with-action {
			justify-content: center;
		}
	}

	.sidebar-pinned-list li a span.sidebar-label-text {
		display: none;
	}

	.sidebar-pinned-list li a {
		justify-content: center;
		gap: 0;

		i[data-lucide] {
			width: 18px;
			height: 18px;
		}
	}
}

/* ========================================================================
   Mobile menu toggle & overlay
   Toggle chrome lives in the topbar (.topbar-menu-toggle); keep overlay only.
   ======================================================================== */
.mobile-menu-toggle.topbar-menu-toggle {
	/* Styles come from topbar.css — neutralize any legacy fixed-float rules */
	position: static;
	top: auto;
	left: auto;
	z-index: auto;
	box-shadow: none;
}

.mobile-menu-toggle.topbar-menu-toggle.mobile-menu-toggle--open {
	left: auto;
	color: var(--clr-text-high);
	background-color: color-mix(in srgb, var(--clr-text-high) 6%, transparent);
}

.sidebar-overlay {
	display: block;
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, 0.5);
	z-index: 999;
	opacity: 0;
	transition: opacity 0.25s ease;
	pointer-events: none;

	&.active {
		opacity: 1;
		pointer-events: auto;
	}
}

@media (prefers-reduced-motion: reduce) {

	.sidebar,
	.sidebar-overlay,
	.sidebar-mobile-close {
		transition-duration: 0.01ms !important;
	}

	.sidebar-mobile-close:active {
		scale: 1;
	}
}

/* ========================================================================
   Logout modal (shared between sidebar.css and topbar)
   ======================================================================== */
#logoutConfirmationModal {
	.modal-content {
		background-color: var(--clr-surface-1);
		border-radius: 0.75rem;
		padding: 0.25rem;
	}

	.modal-header {
		border-bottom: 1px solid var(--clr-surface-4);
		padding: 1rem;
	}

	.modal-title {
		color: var(--clr-text-high);
		font-size: 0.9rem;
		font-weight: var(--fw-600);
	}

	.modal-body {
		color: var(--clr-text-medium);
		font-size: var(--fs-450);
		padding: 1rem;
	}

	.modal-footer {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-end;
		align-items: center;
		gap: 0.5rem;
		padding: 0.75rem 1rem;
		border: none;
	}
}
