/* ======================================================
   CRM Florio — Premium Sidebar
   Loaded after inline <style>, overrides by cascade order.
   ====================================================== */

/* ===== ROOT OVERRIDES ===== */
:root {
	--sidebar-width: 220px;
	--sidebar-tab-width: 36px;
}

/* ===== SIDEBAR CONTAINER ===== */
.sidebar {
	position: relative;
	width: var(--sidebar-width);
	min-width: var(--sidebar-width);
	flex-basis: var(--sidebar-width);
	flex-shrink: 0;
	background: #0d1117;
	border-right: 1px solid rgba(48, 54, 61, 0.65);
	display: flex;
	flex-direction: column;
	padding: 0;
	gap: 0;
	overflow: visible;
	z-index: 4;
	transition:
		width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
		min-width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
		flex-basis 0.4s cubic-bezier(0.4, 0, 0.2, 1),
		border-color 0.3s ease,
		box-shadow 0.3s ease;
}

/* Subtle top highlight for depth */
.sidebar::before {
	content: "";
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: 1px;
	background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
	z-index: 1;
	pointer-events: none;
}

.sidebar > * {
	opacity: 1;
	transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== BRAND HEADER ===== */
.sidebar-brand {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 14px 10px;
	flex-shrink: 0;
	gap: 10px;
	margin-bottom: 0;
	border-bottom: 1px solid rgba(48, 54, 61, 0.35);
}

.sidebar-brand__info {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
	opacity: 1;
	filter: none;
	transition: opacity 0.3s ease, transform 0.3s ease, filter 0.3s ease;
	transition-delay: 0.25s;
}

/* Hide old brand__actions — profile/logout now in footer */
.sidebar-brand__actions {
	display: none !important;
}

.sidebar-logo {
	width: 24px;
	height: 24px;
	object-fit: contain;
	filter: brightness(0) invert(1) saturate(0);
	opacity: 0.7;
}

.sidebar h1 {
	font-size: 13px;
	font-weight: 700;
	letter-spacing: 0.12em;
	color: rgba(230, 237, 243, 0.55);
	margin-bottom: 0;
	text-transform: uppercase;
}

/* ===== SCROLLABLE NAV ===== */
.sidebar-nav {
	flex: 1;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 6px 8px 12px;
	scroll-behavior: smooth;
}

/* Webkit scrollbar */
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
	background: rgba(139, 148, 158, 0.12);
	border-radius: 3px;
}
.sidebar-nav:hover::-webkit-scrollbar-thumb {
	background: rgba(139, 148, 158, 0.25);
}

/* Firefox */
.sidebar-nav {
	scrollbar-width: thin;
	scrollbar-color: rgba(139, 148, 158, 0.12) transparent;
}

/* ===== SECTION LABELS ===== */
.nav-section {
	margin-bottom: 2px;
}

.nav-section__label {
	display: block;
	font-size: 10px;
	font-weight: 600;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: rgba(139, 148, 158, 0.45);
	padding: 14px 10px 5px;
	user-select: none;
	line-height: 1;
}

.nav-section:first-child .nav-section__label {
	padding-top: 4px;
}

/* ===== NAV BUTTONS ===== */
.nav-btn {
	--nav-fade-delay: var(--nav-delay, 0s);
	width: 100%;
	text-align: left;
	padding: 7px 10px;
	border-radius: 8px;
	border: 1px solid transparent;
	background: transparent;
	color: #8b949e;
	cursor: pointer;
	font-family: inherit;
	font-size: 13px;
	font-weight: 500;
	text-transform: none;
	letter-spacing: 0.01em;
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 34px;
	line-height: 1.15;
	position: relative;
	margin-bottom: 1px;
	opacity: 1;
	transform: translateX(0);
	transform-origin: left center;
	transition:
		background 0.15s ease,
		color 0.15s ease,
		border-color 0.15s ease,
		box-shadow 0.15s ease,
		opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1) var(--nav-fade-delay),
		transform 0.35s cubic-bezier(0.4, 0, 0.2, 1) var(--nav-fade-delay);
}

.nav-btn[hidden] { display: none !important; }

/* Override inline rule that sets span font-size:16px */
.nav-btn span {
	font-size: inherit;
}

.nav-btn:not(:disabled):hover {
	background: rgba(177, 186, 196, 0.06);
	color: #c9d1d9;
	border-color: transparent;
}

.nav-btn:focus-visible {
	outline: 2px solid rgba(0, 212, 255, 0.4);
	outline-offset: -2px;
}

.nav-btn.active {
	color: #e6edf3;
	background: rgba(0, 212, 255, 0.06);
	border-color: transparent;
	box-shadow: inset 3px 0 0 #00d4ff;
	font-weight: 600;
}

.nav-btn.active .nav-icon {
	opacity: 1;
	color: #00d4ff;
}

/* ===== NAV ICONS (CSS mask-image) ===== */
.nav-icon {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
	display: inline-block;
	background: currentColor;
	-webkit-mask-size: 16px 16px;
	mask-size: 16px 16px;
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
	-webkit-mask-position: center;
	mask-position: center;
	opacity: 0.5;
	transition: opacity 0.15s ease, color 0.15s ease;
}

.nav-btn:hover .nav-icon { opacity: 0.8; }

/* — Icon definitions — */
.nav-icon[data-icon="home"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'/%3E%3Cpath d='M9 22V12h6v10'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="calendar"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="tools"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="chart"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 20V10M12 20V4M6 20v-6'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="leads"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Ccircle cx='12' cy='12' r='6'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="form"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2'/%3E%3Crect x='8' y='2' width='8' height='4' rx='1'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="users"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='9' cy='7' r='4'/%3E%3Cpath d='M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="building"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='2' width='16' height='20' rx='2'/%3E%3Cpath d='M9 22v-4h6v4M8 6h.01M16 6h.01M12 6h.01M8 10h.01M16 10h.01M12 10h.01M8 14h.01M16 14h.01M12 14h.01'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="mail"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='4' width='20' height='16' rx='2'/%3E%3Cpath d='m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="calc"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='2' width='16' height='20' rx='2'/%3E%3Cpath d='M8 6h8M8 10h8M8 14h4M8 18h4'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="chat"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}
.nav-icon[data-icon="briefcase"] {
	--i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='7' width='20' height='14' rx='2'/%3E%3Cpath d='M16 7V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v2'/%3E%3C/svg%3E");
	-webkit-mask-image: var(--i); mask-image: var(--i);
}

/* Astelio avatar icon — uses actual image instead of mask */
.nav-icon--astelio {
	width: 18px;
	height: 18px;
	border-radius: 50%;
	object-fit: contain;
	background: transparent;
	-webkit-mask-image: none;
	mask-image: none;
	opacity: 0.75;
	transition: opacity 0.15s ease;
}
.nav-btn:hover .nav-icon--astelio,
.nav-btn.active .nav-icon--astelio {
	opacity: 1;
	filter: drop-shadow(0 0 4px rgba(96, 165, 250, 0.5));
}

/* ===== BADGE ===== */
.nav-btn--with-badge { position: relative; }

.nav-btn__badge {
	position: absolute;
	top: 4px;
	right: 6px;
	min-width: 16px;
	height: 16px;
	padding: 0 4px;
	background: #da3633;
	border-radius: 8px;
	font-size: 10px;
	font-weight: 700;
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
	pointer-events: none;
}

.nav-btn__badge:empty,
.nav-btn__badge[data-count="0"] { display: none; }

/* ===== CONTABILITÀ LOGOS ===== */
.nav-btn__label {
	font-size: 13px;
	font-weight: 500;
	letter-spacing: 0.01em;
	flex: 0 0 auto;
	white-space: nowrap;
}

.nav-btn__logo {
	width: 20px;
	height: 20px;
	object-fit: contain;
	opacity: 0.6;
	filter: brightness(0) invert(1) saturate(0);
	flex: 0 0 auto;
	margin-left: auto;
}

.nav-btn__logo--taskpro {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 7px;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: #0d1117;
	background: linear-gradient(135deg, #e6edf3 0%, #b1bac4 100%);
	border-radius: 5px;
	border: none;
	filter: none;
	opacity: 0.75;
	box-shadow: none;
}

.nav-btn__tag {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 7px;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	color: #8b949e;
	padding: 1px 4px;
	border-radius: 999px;
	border: 1px solid rgba(48, 54, 61, 0.8);
	margin-left: auto;
	line-height: 1;
	opacity: 0.7;
	flex: 0 0 auto;
	white-space: nowrap;
}

/* ===== ACCORDION ===== */
.nav-accordion {
	display: flex;
	flex-direction: column;
}

.nav-accordion[hidden] { display: none !important; }

.nav-accordion__toggle {
	display: flex;
	justify-content: flex-start;
	align-items: center;
}

.nav-accordion__arrow {
	font-size: 10px;
	transition: transform 0.2s ease;
	opacity: 0.3;
	margin-left: auto;
	line-height: 1;
}

.nav-accordion.is-open .nav-accordion__arrow {
	transform: rotate(90deg);
}

.nav-accordion__content {
	display: none;
	flex-direction: column;
	padding-left: 26px;
	margin-top: 1px;
	gap: 1px;
}

.nav-accordion.is-open .nav-accordion__content {
	display: flex;
}

.nav-btn--sub {
	font-size: 12px;
	padding: 5px 10px;
	border-left: 2px solid rgba(48, 54, 61, 0.5);
	margin-left: 0;
	min-height: 28px;
	opacity: 0.7;
	border-radius: 0 8px 8px 0;
}

.nav-btn--sub:not(:disabled):hover {
	border-left-color: rgba(0, 212, 255, 0.4);
	opacity: 1;
}

.nav-btn--sub.active {
	border-left-color: #00d4ff;
	opacity: 1;
	box-shadow: none;
	background: rgba(0, 212, 255, 0.06);
}

/* ===== SIDEBAR FOOTER ===== */
.sidebar-footer {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 10px 12px;
	border-top: 1px solid rgba(48, 54, 61, 0.35);
}

.sidebar-footer__item {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 7px 10px;
	border: none;
	border-radius: 8px;
	background: transparent;
	color: #8b949e;
	cursor: pointer;
	font-family: inherit;
	font-size: 12px;
	font-weight: 500;
	transition: background 0.15s ease, color 0.15s ease;
	white-space: nowrap;
}

.sidebar-footer__item:hover {
	background: rgba(177, 186, 196, 0.08);
	color: #c9d1d9;
}

.sidebar-footer__item:focus-visible {
	outline: 2px solid rgba(0, 212, 255, 0.4);
	outline-offset: -2px;
}

/* Profile button — takes remaining width */
#profileButton {
	flex: 1;
}

#profileButton.is-active {
	background: rgba(0, 212, 255, 0.06);
	color: #e6edf3;
}

.sidebar-footer__avatar {
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: linear-gradient(135deg, #6592ff 0%, #8a4ef9 50%, #ed7ad0 100%);
	flex-shrink: 0;
	display: block;
}

/* Logout button */
.sidebar-footer__logout {
	padding: 7px 8px;
	flex-shrink: 0;
}

.sidebar-footer__logout:hover {
	background: rgba(218, 54, 51, 0.12);
	color: #f85149;
}

.sidebar-footer__icon {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
}

/* ===== CONTENT AREA ===== */
.content {
	flex: 1;
	background: radial-gradient(ellipse at top, #111b21 0%, #010409 55%);
	transition: margin-left 0.25s ease;
}

#appFrame {
	border: none;
	width: 100%;
	height: 100%;
	background: transparent;
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ===== SIDEBAR TOGGLE (desktop tab) ===== */
.sidebar-toggle {
	position: absolute;
	top: 50%;
	right: calc(-1 * var(--sidebar-tab-width) / 2 - 4px);
	translate: 50% -50%;
	width: 8px;
	height: 56px;
	padding: 0;
	min-width: 0;
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0;
	border: 1px solid rgba(48, 54, 61, 0.4);
	border-radius: 999px;
	background: rgba(139, 148, 158, 0.12);
	color: #8b949e;
	cursor: pointer;
	box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);
	z-index: 5;
	transition: width 0.25s cubic-bezier(.4,0,.2,1), height 0.25s cubic-bezier(.4,0,.2,1), background 0.25s ease, border-color 0.25s ease, opacity 0.25s ease;
	opacity: 0.6;
	overflow: hidden;
}

.sidebar-toggle:hover {
	width: 10px;
	height: 64px;
	background: rgba(0, 212, 255, 0.15);
	border-color: rgba(0, 212, 255, 0.25);
	opacity: 1;
	color: #c9d1d9;
	box-shadow: 0 0 12px rgba(0, 212, 255, 0.08);
}

.sidebar-toggle:focus-visible {
	outline: 2px solid rgba(0, 212, 255, 0.4);
	outline-offset: 2px;
}

.sidebar-toggle__label { display: none; }

.sidebar-toggle__arrow {
	width: 0;
	height: 0;
	border: none;
	transform: none;
	transition: none;
}

.layout.sidebar-collapsed .sidebar-toggle__arrow {
	transform: none;
}

.layout.sidebar-collapsed .sidebar-toggle {
	opacity: 0.75;
	background: rgba(0, 212, 255, 0.12);
	border-color: rgba(0, 212, 255, 0.2);
}

/* ===== COLLAPSED STATE ===== */
.layout.sidebar-collapsed .sidebar {
	width: 0;
	min-width: 0;
	flex-basis: 0;
	border-right: none;
}

.layout.sidebar-collapsed .sidebar > :not(.sidebar-brand) {
	opacity: 0;
	pointer-events: none;
}

.layout.sidebar-collapsed .sidebar-brand {
	/* Keep brand for toggle tab positioning */
	padding: 14px 0;
	border-bottom: none;
}

.layout.sidebar-collapsed .sidebar-brand__info {
	opacity: 0;
	pointer-events: none;
	transform: translateX(-10px);
	filter: brightness(0.4);
	transition-delay: 0s;
}

.layout.sidebar-collapsed .nav-btn {
	opacity: 0;
	pointer-events: none;
	transform: translateX(-16px);
	transition-delay: 0s;
}

/* Prevent flash during opening */
.layout.sidebar-opening .nav-btn {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: none;
	--nav-fade-delay: 0s;
}

.layout.sidebar-opening .sidebar-brand__info {
	opacity: 0;
	pointer-events: none;
}

/* ===== MOBILE HAMBURGER ===== */
.mobile-hamburger {
	display: none;
	position: fixed;
	top: 12px;
	left: 12px;
	width: 48px;
	height: 48px;
	border-radius: 12px;
	border: 1px solid rgba(255, 255, 255, 0.12);
	background: rgba(13, 17, 23, 0.96);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	z-index: 1100;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
	cursor: pointer;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 5px;
	padding: 0;
}

.mobile-hamburger__line {
	display: block;
	width: 20px;
	height: 2px;
	background: #e6edf3;
	border-radius: 2px;
	transition: transform 0.2s ease, opacity 0.2s ease;
}

.mobile-hamburger.is-open .mobile-hamburger__line:nth-child(1) {
	transform: translateY(7px) rotate(45deg);
}
.mobile-hamburger.is-open .mobile-hamburger__line:nth-child(2) {
	opacity: 0;
}
.mobile-hamburger.is-open .mobile-hamburger__line:nth-child(3) {
	transform: translateY(-7px) rotate(-45deg);
}

@media (max-width: 768px) {
	.mobile-hamburger {
		display: flex;
	}
}
