:root {
	--sidebar-width: 290px;
	--sidebar-primary: #2563eb;
	--sidebar-primary-dark: #1d4ed8;
	--sidebar-navy: #1e293b;
	--sidebar-sky: #38bdf8;
	--sidebar-gold: #f59e0b;
	--sidebar-ink: #0f172a;
	--sidebar-muted: #64748b;
	--sidebar-line: #e2e8f0;
	--sidebar-soft: #f8fafc;
}

/* Base font for whole app */
body, #sidebar {
	font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
}

/* ==========================================================================
   Global Top Navigation Bar (ส่วนหัวระบบในกรอบสีแดง)
   ========================================================================== */
.mat-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    z-index: 1040;
    background: linear-gradient(135deg, #0b1a3d 0%, #1e3a8a 50%, #2563eb 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.18);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 16px;
    color: #ffffff;
    gap: 8px;
}

.mat-navbar-brand-area {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 1 auto;
    min-width: 0;
    justify-content: flex-start;
}

.mat-brand-link {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    text-decoration: none !important;
    color: #ffffff !important;
    flex: 0 0 auto !important;
    width: auto !important;
}

.mat-sidebar-toggle-btn {
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.28);
    color: #ffffff;
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
    flex: 0 0 auto !important;
    margin: 0 2px !important;
    user-select: none;
}

.mat-sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    border-color: rgba(255, 255, 255, 0.45);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.mat-sidebar-toggle-btn:active {
    transform: translateY(0) scale(0.96);
}

.mat-sidebar-toggle-btn svg {
    display: block;
}

.mat-brand-logo {
    height: 40px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.mat-brand-title-img {
    height: 30px;
    width: auto;
    max-width: 220px;
    display: inline-block;
    vertical-align: middle;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
    flex-shrink: 0;
}

.mat-brand-divider {
    font-size: 20px;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.45);
    line-height: 1;
    display: inline-block;
    flex-shrink: 0;
}

.mat-brand-subtitle {
    font-size: 15px;
    color: #ffffff;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.mat-navbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.mat-user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.12);
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.22);
}

.mat-user-chip-name {
    font-size: 13px;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
}

.mat-role-badge {
    background: #fbbf24;
    color: #78350f;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    white-space: nowrap;
}

.mat-btn-logout {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #ffffff !important;
    background: rgba(239, 68, 68, 0.9);
    border: none;
    padding: 6px 14px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 6px;
    text-decoration: none !important;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.35);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.mat-btn-logout:hover {
    background: #dc2626;
    color: #ffffff !important;
    box-shadow: 0 4px 10px rgba(220, 38, 38, 0.5);
    transform: translateY(-1px);
}

/* Sidebar positioning with topbar */
#sidebar {
    position: fixed !important;
    top: 64px !important;
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - 64px) !important;
    z-index: 1030;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sidebar Wrapper */
#sidebar .sidebar-wrapper {
	width: var(--sidebar-width);
	height: 100% !important;
	max-height: calc(100vh - 64px) !important;
	padding: 0 0 24px;
	border-right: 1px solid #eef2f6;
	background: #ffffff;
	box-shadow: 6px 0 25px rgba(15, 23, 42, 0.04) !important;
	scrollbar-width: thin;
	scrollbar-color: #cbd5e1 transparent;
	overflow-y: auto !important;
}

#sidebar .sidebar-wrapper::-webkit-scrollbar {
	width: 5px;
}

#sidebar .sidebar-wrapper::-webkit-scrollbar-thumb {
	border-radius: 999px;
	background: #cbd5e1;
}

/* ==========================================================================
   User Info Panel (Top of Sidebar Matching Theme Screenshot)
   ========================================================================== */
.mat-user-info-panel {
    background-color: #f8fafc !important;
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.82) 0%, rgba(241, 245, 249, 0.88) 100%), url('../../images/bg_finance_chart.jpg') !important;
    background-size: cover !important;
    background-position: center right !important;
    background-repeat: no-repeat !important;
    padding: 16px 14px 14px !important;
    position: relative !important;
    border-bottom: 1px solid #e2e8f0 !important;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04) !important;
}

.mat-user-info-flex {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mat-user-avatar {
    width: 44px !important;
    height: 44px !important;
    border-radius: 50%;
    background: #ffffff !important;
    border: 2px solid #2563eb !important;
    box-shadow: 0 3px 8px rgba(37, 99, 235, 0.2);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0;
    overflow: hidden;
}

.mat-user-avatar i {
    font-size: 24px !important;
    color: #1e3a8a !important;
    line-height: 1 !important;
}

.mat-user-details {
    overflow: hidden;
    min-width: 0;
    flex: 1;
}

.mat-user-name {
    font-size: 14.5px !important;
    font-weight: 700 !important;
    color: #0f172a !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
    line-height: 1.25;
}

.mat-user-role-label {
    display: inline-block;
    background: #fef3c7 !important;
    border: 1px solid #fcd34d !important;
    color: #92400e !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    padding: 1px 8px !important;
    border-radius: 10px !important;
    margin-bottom: 4px;
    line-height: 1.3;
}

.mat-user-dept {
    font-size: 12px !important;
    color: #64748b !important;
    font-weight: 500 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

/* =========================================
   Sidebar Menu List
========================================= */
#sidebar .sidebar-menu {
	padding: 0;
}

#sidebar .sidebar-wrapper .menu {
	padding: 0 8px;
	margin: 0;
}

/* Section Title */
#sidebar .sidebar-wrapper .menu .sidebar-title {
	margin: 16px 8px 6px;
	padding: 0 4px;
	font-size: 11px !important;
	font-weight: 700 !important;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	color: #64748b;
	display: flex;
	align-items: center;
	gap: 6px;
}

#sidebar .sidebar-wrapper .menu .sidebar-title::before {
	content: "";
	width: 4px;
	height: 10px;
	border-radius: 2px;
	background: #3b82f6;
}

/* Sidebar Item & Link */
#sidebar .sidebar-wrapper .menu .sidebar-item {
	margin-top: 2px;
	list-style: none;
}

#sidebar .sidebar-wrapper .menu .sidebar-item > .sidebar-link {
	position: relative;
	min-height: 42px;
	margin: 0;
	padding: 8px 12px !important;
	border: 1.5px solid transparent;
	border-radius: 10px;
	font-size: 13px;
	font-weight: 500;
	color: #334155;
	display: flex;
	align-items: center;
	transition: all 0.2s ease;
	text-decoration: none;
}

/* Icon Box */
#sidebar .sidebar-wrapper .menu .sidebar-item > .sidebar-link > i {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	flex: 0 0 30px;
	border-radius: 8px;
	background: #f1f5f9;
	font-size: 15px !important;
	color: #475569;
	margin-right: 10px;
	transition: all 0.2s ease;
}

#sidebar .sidebar-wrapper .menu .sidebar-item > .sidebar-link > span {
	font-size: 13px !important;
	font-weight: 500 !important;
	line-height: 1.35;
	color: inherit;
	flex: 1;
}

/* Hover State */
#sidebar .sidebar-wrapper .menu .sidebar-item > .sidebar-link:hover {
	background: #f8fafc;
	border-color: #e2e8f0;
	color: #1d4ed8;
	transform: translateX(2px);
}

#sidebar .sidebar-wrapper .menu .sidebar-item > .sidebar-link:hover > i {
	background: #eff6ff;
	color: #2563eb;
}

/* Active State */
#sidebar .sidebar-wrapper .menu .sidebar-item.active > .sidebar-link {
	border-color: transparent;
	background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
	color: #ffffff !important;
	box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
	transform: none;
}

#sidebar .sidebar-wrapper .menu .sidebar-item.active > .sidebar-link > i {
	background: rgba(255, 255, 255, 0.22);
	color: #ffffff !important;
}

#sidebar .sidebar-wrapper .menu .sidebar-item.active > .sidebar-link > span {
	font-weight: 600 !important;
	color: #ffffff !important;
}

/* Dropdown Arrow for Submenu */
#sidebar .sidebar-wrapper .menu .sidebar-item.has-sub > .sidebar-link {
	padding-right: 32px !important;
}

#sidebar .sidebar-wrapper .menu .sidebar-item.has-sub > .sidebar-link::after {
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
	width: 14px;
	height: 14px;
	opacity: 0.6;
	transition: transform 0.2s ease;
}

#sidebar .sidebar-wrapper .menu .sidebar-item.has-sub.active > .sidebar-link::after,
#sidebar .sidebar-wrapper .menu .sidebar-item.has-sub.submenu-open > .sidebar-link::after {
	transform: translateY(-50%) rotate(180deg);
}

/* Submenu container */
#sidebar .sidebar-wrapper .menu .submenu {
	position: relative;
	margin: 3px 0 5px 22px;
	padding: 4px 0 4px 12px;
	border-left: 2px solid #e2e8f0;
	list-style: none;
}

#sidebar .sidebar-wrapper .menu .submenu .submenu-item a {
	position: relative;
	margin: 1px 0;
	padding: 6px 10px;
	border-radius: 6px;
	font-size: 12px !important;
	font-weight: 400 !important;
	line-height: 1.4;
	color: #64748b;
	display: block;
	text-decoration: none;
	transition: all 0.2s ease;
}

#sidebar .sidebar-wrapper .menu .submenu .submenu-item a:hover {
	color: #1d4ed8;
	background: #eff6ff;
	font-weight: 500 !important;
	padding-left: 12px;
}

#sidebar .sidebar-wrapper .menu .submenu .submenu-item.active a {
	color: #1d4ed8;
	background: #dbeafe;
	font-weight: 600 !important;
}

/* Separator Line */
#sidebar .sidebar-wrapper .menu hr {
	margin: 10px 8px !important;
	border: 0;
	border-top: 1px solid #f1f5f9;
	opacity: 1 !important;
}

/* Logout Button */
#sidebar .sidebar-wrapper .menu .logout-item {
	margin-top: 10px !important;
}

#sidebar .sidebar-wrapper .menu .logout-item > .sidebar-link {
	border: 1.5px solid #fee2e2;
	background: #fff8f8;
	color: #dc2626 !important;
}

#sidebar .sidebar-wrapper .menu .logout-item > .sidebar-link > i {
	background: #fee2e2;
	color: #dc2626;
}

#sidebar .sidebar-wrapper .menu .logout-item > .sidebar-link:hover {
	border-color: #fca5a5;
	background: #fef2f2;
	color: #b91c1c !important;
	box-shadow: 0 4px 12px rgba(239, 68, 68, 0.12);
}

#main {
	margin-top: 64px !important;
	margin-left: var(--sidebar-width);
	transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media screen and (min-width: 1200px) {
	body.sidebar-collapsed #sidebar,
	#sidebar:not(.active) {
		left: calc(var(--sidebar-width) * -1) !important;
	}

	body.sidebar-collapsed #main,
	#sidebar:not(.active) ~ #main {
		margin-left: 0 !important;
		max-width: 100vw !important;
	}
}

@media screen and (max-width: 1199px) {
	#sidebar {
		left: calc(var(--sidebar-width) * -1) !important;
		transition: left 0.3s ease;
	}

	#sidebar.active {
		left: 0 !important;
	}

	#sidebar.active::after {
		content: "";
		position: fixed;
		inset: 64px 0 0 0;
		z-index: 9;
		background: rgba(15, 23, 42, 0.32);
		backdrop-filter: blur(2px);
	}

	#main {
		margin-left: 0 !important;
	}

	.mat-brand-subtitle,
	.mat-brand-divider {
		display: none !important;
	}
}

@media screen and (max-width: 768px) {
	.mat-user-chip {
		display: none !important;
	}
}

@media (prefers-reduced-motion: reduce) {
	#sidebar .sidebar-wrapper,
	#sidebar .sidebar-link,
	#sidebar .sidebar-link i,
	#sidebar .sidebar-link::after {
		transition: none !important;
	}
}
