/* ============================================
	 App Layout + Sidebar
	 ============================================ */

.app-layout {
	display: flex;
	min-height: 100vh;
	width: 100%;
}

.sidebar {
	width: 220px;
	background-color: var(--card-bg);
	border-right: 1px solid var(--border-color);
	display: flex;
	flex-direction: column;
	transition: width var(--transition-base);
	position: relative;
	z-index: 100;
	flex-shrink: 0;
}

.sidebar-header {
	padding: var(--space-4);
	border-bottom: 1px solid var(--border-color);
	display: flex;
	justify-content: space-between;
	align-items: center;
	height: 52px;
}

.sidebar-brand {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	min-width: 0;
	overflow: hidden;
}

.sidebar-logo-icon {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(37, 99, 235, 0.2));
}

.sidebar-header h2 {
	margin: 0;
	font-size: 14px;
	font-weight: 600;
	color: var(--text-primary);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	letter-spacing: -0.01em;
}

.sidebar-toggle {
	background: transparent;
	border: none;
	cursor: pointer;
	padding: var(--space-1);
	color: var(--text-secondary);
	font-size: 14px;
	border-radius: var(--radius-sm);
	transition: background-color var(--transition-fast);
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
}

.sidebar-toggle:hover {
	background-color: var(--gray-100);
	border-color: transparent;
}

.sidebar-nav {
	flex: 1;
	overflow-y: auto;
	padding: var(--space-2) 0;
}

.sidebar-menu {
	list-style: none;
	margin: 0;
	padding: 0;
}

.sidebar-menu li {
	margin: 0;
	padding: 0 var(--space-2);
}

.sidebar-link {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: var(--space-2) var(--space-3);
	color: var(--text-secondary);
	text-decoration: none;
	transition: color var(--transition-fast), background-color var(--transition-fast);
	cursor: pointer;
	border-radius: var(--radius-md);
	font-size: 14px;
	font-weight: 400;
	margin-bottom: 1px;
}

.sidebar-link:hover {
	background-color: var(--gray-100);
	color: var(--text-primary);
}

.sidebar-link.active {
	background-color: var(--blue-50);
	color: var(--primary);
	font-weight: 500;
}

:root[data-theme='dark'] .sidebar-link:hover {
	background-color: rgba(30, 58, 110, 0.18);
	color: #dbeafe;
}

:root[data-theme='dark'] .sidebar-link.active {
	background-color: rgba(30, 58, 110, 0.32);
	color: #bfdbfe;
	box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.25);
}

.sidebar-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 16px;
	height: 16px;
	flex-shrink: 0;
}

.sidebar-icon svg {
	width: 16px;
	height: 16px;
}

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

.sidebar.collapsed { width: 56px; }

.sidebar.collapsed .sidebar-brand h2,
.sidebar.collapsed .sidebar-text {
	opacity: 0;
	width: 0;
	overflow: hidden;
}

.sidebar.collapsed .sidebar-icon { margin-right: 0; }

.sidebar.collapsed .sidebar-link {
	justify-content: center;
	padding: var(--space-2);
}

/* ── Sidebar footer (user + logout) ── */
.sidebar-footer {
	padding: var(--space-3) var(--space-3);
	border-top: 1px solid var(--border-color);
	display: flex;
	align-items: center;
	gap: var(--space-2);
	flex-shrink: 0;
}

.sidebar-user {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	flex: 1;
	min-width: 0;
}

.sidebar-avatar {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: var(--primary);
	color: white;
	font-size: 11px;
	font-weight: 600;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	letter-spacing: 0;
}

.sidebar-username {
	font-size: 12px;
	font-weight: 500;
	color: var(--text-secondary);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	transition: opacity var(--transition-fast), width var(--transition-fast);
}

.sidebar-logout-btn {
	background: transparent;
	border: none;
	cursor: pointer;
	color: var(--text-secondary);
	padding: var(--space-1);
	border-radius: var(--radius-sm);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 28px;
	height: 28px;
	transition: color var(--transition-fast), background-color var(--transition-fast);
}

.sidebar-logout-btn:hover {
	color: var(--danger);
	background: var(--red-50);
	border-color: transparent;
}

.sidebar.collapsed .sidebar-username {
	opacity: 0;
	width: 0;
	overflow: hidden;
}

.sidebar.collapsed .sidebar-logout-btn {
	display: none;
}

.sidebar.collapsed .sidebar-footer {
	justify-content: center;
	padding: var(--space-3) var(--space-2);
}

.main-content {
	flex: 1;
	overflow-y: auto;
	background-color: var(--bg-page);
	min-width: 0;
	animation: pageIn 0.18s ease;
}

@keyframes pageIn {
	from { opacity: 0; transform: translateY(5px); }
	to   { opacity: 1; transform: translateY(0); }
}

.main-content > div {
	max-width: 1280px;
	margin: 0 auto;
	padding: var(--space-6);
}

@media (min-width: 1600px) {
	.sidebar { width: 250px; }
	.main-content > div {
		max-width: 1440px;
		padding: var(--space-8);
	}
}

@media (min-width: 2200px) {
	.sidebar { width: 280px; }
	.sidebar-link { font-size: 15px; padding: var(--space-3) var(--space-4); }
	.sidebar-avatar { width: 32px; height: 32px; font-size: 13px; }
	.sidebar-username { font-size: 13px; }
	.main-content > div {
		max-width: 1800px;
		padding: var(--space-10);
	}
}

/* ── Mobile topbar (hidden on desktop) ── */
.mobile-topbar {
	display: none;
}

/* ── Sidebar backdrop ── */
.sidebar-backdrop {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.4);
	z-index: 999;
	animation: backdropFadeIn 150ms ease;
}

.sidebar-backdrop.visible {
	display: block;
}

@keyframes backdropFadeIn {
	from { opacity: 0; }
	to   { opacity: 1; }
}

@media (max-width: 768px) {
	/* Sidebar: oculta por defecto, se muestra con .mobile-open */
	.sidebar {
		position: fixed;
		left: 0;
		top: 0;
		bottom: 0;
		z-index: 1000;
		transform: translateX(-100%);
		width: 220px !important;
		transition: transform var(--transition-base), box-shadow var(--transition-base);
		box-shadow: none;
	}

	.sidebar.mobile-open {
		transform: translateX(0);
		box-shadow: var(--shadow-lg);
	}

	/* Anular collapsed en móvil para que el contenido se vea bien cuando se abre */
	.sidebar.collapsed {
		width: 220px !important;
	}

	.sidebar.collapsed .sidebar-brand h2,
	.sidebar.collapsed .sidebar-text {
		opacity: 1;
		width: auto;
		overflow: visible;
	}

	.sidebar.collapsed .sidebar-link {
		justify-content: flex-start;
		padding: var(--space-2) var(--space-3);
	}

	.main-content {
		margin-left: 0;
	}

	/* Topbar móvil */
	.mobile-topbar {
		display: flex;
		align-items: center;
		gap: var(--space-3);
		padding: 0 var(--space-4);
		height: 52px;
		background: var(--card-bg);
		border-bottom: 1px solid var(--border-color);
		position: sticky;
		top: 0;
		z-index: 50;
		flex-shrink: 0;
	}

	.mobile-menu-btn {
		background: transparent;
		border: none;
		padding: var(--space-2);
		border-radius: var(--radius-md);
		color: var(--text-secondary);
		cursor: pointer;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 36px;
		height: 36px;
		flex-shrink: 0;
		transition: background-color var(--transition-fast), color var(--transition-fast);
	}

	.mobile-menu-btn:hover {
		background: var(--gray-100);
		color: var(--text-primary);
		border-color: transparent;
	}

	.mobile-topbar-title {
		font-size: 15px;
		font-weight: 600;
		color: var(--text-primary);
	}
}
