/* ==========================================================================
   Sidebar Navigation Styles
   ========================================================================== */

/* Core Sidebar Structure */
#sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--navbar-height));
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    margin: 0;
    padding: 0;
    overflow: hidden;
    contain: layout style;
}

/* Scrollable nav container */
#sidebar .nav {
    padding-top: 20px;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 40px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    height: 100%;
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
}

/* Custom scrollbar styling for webkit browsers */
#sidebar .nav::-webkit-scrollbar {
    width: 6px;
}

#sidebar .nav::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar .nav::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

#sidebar .nav::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

#sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Sidebar Navigation Links */
#sidebar .nav-link {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    white-space: nowrap;
    color: var(--primary-color);
    text-transform: capitalize;
    margin-bottom: 2px;
    font-weight: 500;
    font-size: 14px;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    text-decoration: none;
    border-radius: 0;
}

/* Remove all dropdown indicators */
#sidebar .nav-link::after,
#sidebar .nav-link.dropdown-toggle::after,
#sidebar .dropdown-toggle::after {
    display: none !important;
}

#sidebar .nav-link i {
    margin-right: 24px !important; /* Much more space between icon and text */
    font-size: 1.4em; /* Slightly smaller for better proportion */
    color: var(--primary-color);
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.8;
}

#sidebar .nav-link span {
    display: block;
    font-weight: 500;
    text-transform: capitalize;
}

#sidebar .nav-link:hover {
    background-color: rgba(0, 123, 255, 0.05);
    text-decoration: none;
    border-left-color: var(--primary-color);
}

/* Collapsed Sidebar States */
#sidebar.collapsed .nav-link span {
    display: none;
}

#sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px 0;
    width: 100%;
    margin: 2px 0;
    border-left: none;
}

#sidebar.collapsed .nav-link i {
    margin-right: 0 !important;
    font-size: 1.5em;
    width: auto;
    text-align: center;
}

/* Hamburger Controller - Fixed at bottom */
#sidebar .sidebar-footer {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background-color: inherit;
    border-top: 1px solid var(--light-border);
    z-index: 10;
}

#sidebar .sidebar-footer button {
    background: transparent;
    border: none;
    color: var(--primary-color);
    font-size: 1.2rem;
}

/* Sidebar Dropdowns */
#sidebar .nav-item .dropdown-menu {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 0;
    margin-top: 0;
    position: static !important;
    float: none !important;
    box-shadow: none !important;
    transform: none !important;
    width: 100%;
}

/* Collapsed sidebar dropdown positioning */
#sidebar.collapsed .nav-item .dropdown-menu {
    position: fixed !important;
    left: var(--sidebar-collapsed-width) !important;
    top: auto !important;
    width: 250px !important;
    z-index: 1050 !important;
}

/* Ensure dropdowns don't overflow viewport */
#sidebar .nav-item .dropdown-menu {
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

#sidebar .nav-item .dropdown-item {
    color: var(--primary-color) !important;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    font-size: 14px;
    font-weight: 400;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    position: relative;
}

#sidebar .nav-item .dropdown-item i {
    width: 20px;
    text-align: center;
    margin-right: 16px;
    font-size: 12px;
    opacity: 0.8;
    flex-shrink: 0;
}

#sidebar .nav-item .dropdown-item:hover {
    background-color: var(--primary-color);
    color: var(--primary-text) !important;
}

#sidebar .nav-item .dropdown-item:hover i {
    color: var(--primary-text) !important;
}

/* CLEAN NAVIGATION APPROACH */
.dynamic-sidebar .nav-item.has-children {
    display: list-item;
}

.dynamic-sidebar .nav-item.has-children > .nav-link {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    color: var(--primary-color);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.dynamic-sidebar .nav-item.has-children > .nav-link:hover {
    background-color: rgba(0, 123, 255, 0.1);
    border-left-color: var(--primary-color);
}

.dynamic-sidebar .nav-item.has-children > .nav-link i {
    margin-right: 24px;
    width: 20px;
    font-size: 1.4em;
}

/* Hide dropdown content - ONLY SIDEBAR DROPDOWNS, NOT TOP NAVBAR DROPDOWNS */
#sidebar.dynamic-sidebar .nav-children,
#sidebar.dynamic-sidebar .dropdown-menu,
#sidebar.dynamic-sidebar .collapsed-hover-menu,
#sidebar .nav-item.has-children .nav-children,
#sidebar .nav-item.has-children .dropdown-menu,
#sidebar .nav-item.has-children .collapsed-hover-menu,
.collapsed-hover-menu,
.collapsed-hover-item {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    position: static !important;
    transform: none !important;
    opacity: 0 !important;
}

/* DON'T INTERFERE WITH BOOTSTRAP DROPDOWNS AT ALL - LET BOOTSTRAP HANDLE THEM */
/* FORCE BOOTSTRAP DROPDOWNS TO WORK - OVERRIDE ANY CONFLICTING RULES */

/* REMOVED - Let Bootstrap handle top navbar dropdowns naturally */

/* REMOVED - Let Bootstrap handle dropdown items naturally */

/* Hover states */
.selector-container .dropdown .dropdown-menu.show .dropdown-item:hover,
.portal-selector .dropdown .dropdown-menu.show .dropdown-item:hover,
.org-selector .dropdown .dropdown-menu.show .dropdown-item:hover,
button#portalDropdown + .dropdown-menu.show .dropdown-item:hover,
button#orgDropdown + .dropdown-menu.show .dropdown-item:hover,
.top-navbar .dropdown-menu.show .dropdown-item:hover,
.navbar .dropdown-menu.show .dropdown-item:hover,
.navbar-center .dropdown-menu.show .dropdown-item:hover,
.navbar-right .dropdown-menu.show .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
    color: var(--primary-text) !important;
}

/* ONLY show dropdown menus for items that actually have children AND on hover */
#sidebar .nav-item.has-children:hover .dropdown-menu,
#sidebar .nav-item.has-children:hover .nav-children,
#sidebar.dynamic-sidebar .nav-item.has-children:hover .dropdown-menu,
#sidebar.dynamic-sidebar .nav-item.has-children:hover .nav-children {
    display: block !important;
    visibility: visible !important;
    height: auto !important;
    max-height: 400px !important;
    overflow-y: auto !important;
    opacity: 1 !important;
    position: static !important;
    transform: none !important;
}

/* Show dropdown items on hover */
#sidebar .nav-item.has-children:hover .dropdown-menu .dropdown-item,
#sidebar .nav-item.has-children:hover .nav-children .nav-link,
#sidebar.dynamic-sidebar .nav-item.has-children:hover .dropdown-menu .dropdown-item,
#sidebar.dynamic-sidebar .nav-item.has-children:hover .nav-children .nav-link {
    display: flex !important;
    visibility: visible !important;
}

/* FORCE ALL NAVIGATION LINKS TO WORK - OVERRIDE ALL BLOCKING RULES */
#sidebar .nav-link,
#sidebar .dropdown-item,
#sidebar .nav-link.dropdown-toggle,
#sidebar.dynamic-sidebar .nav-link,
#sidebar.dynamic-sidebar .dropdown-item,
#sidebar.dynamic-sidebar .nav-link.dropdown-toggle {
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* REMOVE ALL VISUAL EXPANSION EFFECTS */
#sidebar .nav-item,
#sidebar .nav-link,
#sidebar .dropdown-item,
#sidebar.dynamic-sidebar .nav-item,
#sidebar.dynamic-sidebar .nav-link,
#sidebar.dynamic-sidebar .dropdown-item {
    transition: none !important;
    transform: none !important;
    animation: none !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

/* PREVENT ANY HOVER/CLICK VISUAL EFFECTS ON NAV ITEMS */
#sidebar .nav-item:hover,
#sidebar .nav-item:focus,
#sidebar .nav-item:active,
#sidebar .nav-link:hover,
#sidebar .nav-link:focus,
#sidebar .nav-link:active {
    transform: none !important;
    transition: none !important;
    animation: none !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    background-color: rgba(0, 123, 255, 0.05) !important;
    border-left-color: var(--primary-color) !important;
}

/* Remove ripple effects and click animations */
#sidebar .nav-link .ripple,
#sidebar .nav-link.clicked,
#sidebar .nav-link.active {
    display: none !important;
    opacity: 0 !important;
}

/* Ensure consistent nav item heights and prevent wrapping */
#sidebar .nav-item {
    width: 100% !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    flex-basis: auto !important;
    display: block !important;
}

#sidebar .nav-link {
    height: auto !important;
    min-height: 48px !important;
    max-height: 48px !important;
    overflow: hidden !important;
    width: 100% !important;
    flex-shrink: 0 !important;
    display: flex !important;
}

/* FORCE DROPDOWN VISIBILITY ON HOVER */
#sidebar .nav-item.has-children:hover .dropdown-menu,
#sidebar .nav-item.has-children:hover .nav-children {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    position: static !important;
    transform: none !important;
    transition: none !important;
}

#sidebar .nav-item.has-children:hover .dropdown-item,
#sidebar .nav-item.has-children:hover .nav-children .nav-link {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* HOVER EXPANSION DISABLED - ALL LINKS SHOULD NAVIGATE NORMALLY */

/* Also hide the broken dropdown items that are still showing - HIGHER SPECIFICITY */
#sidebar .nav-item.has-children .dropdown-menu .dropdown-item,
#sidebar .nav-item.has-children .nav-children .nav-link,
#sidebar.dynamic-sidebar .nav-item.has-children .dropdown-menu .dropdown-item,
#sidebar.dynamic-sidebar .nav-item.has-children .nav-children .nav-link {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* Force dropdown items to be hidden when parent dropdown is closed - SIDEBAR ONLY */
#sidebar .dynamic-sidebar .nav-children .nav-link,
#sidebar .dynamic-sidebar .dropdown-menu .dropdown-item,
#sidebar .nav-children .nav-link,
#sidebar .dropdown-menu .dropdown-item {
    display: none !important;
}

/* Only show dropdown items when parent has show/open class - SIDEBAR ONLY */
#sidebar .dynamic-sidebar .nav-item.show .nav-children .nav-link,
#sidebar .dynamic-sidebar .nav-item.open .nav-children .nav-link,
#sidebar .dynamic-sidebar .nav-item.show .dropdown-menu .dropdown-item,
#sidebar .dynamic-sidebar .nav-item.open .dropdown-menu .dropdown-item,
#sidebar .nav-item.show .nav-children .nav-link,
#sidebar .nav-item.open .nav-children .nav-link,
#sidebar .nav-item.show .dropdown-menu .dropdown-item,
#sidebar .nav-item.open .dropdown-menu .dropdown-item {
    display: flex !important;
}

/* Custom scrollbar for dropdown menus */
.nav-children::-webkit-scrollbar,
.dropdown-menu::-webkit-scrollbar {
    width: 4px;
}

.nav-children::-webkit-scrollbar-track,
.dropdown-menu::-webkit-scrollbar-track {
    background: transparent;
}

.nav-children::-webkit-scrollbar-thumb,
.dropdown-menu::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.nav-children::-webkit-scrollbar-thumb:hover,
.dropdown-menu::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}



/* Level-based indentation for proper hierarchy with GENEROUS spacing */
.nav-item.level-0 > .nav-link {
    padding: 16px 24px !important; /* More generous padding */
    font-size: 15px;
    font-weight: 500;
    color: var(--primary-color);
}

.nav-item.level-0 > .nav-link i {
    margin-right: 24px !important; /* Much more space between icon and text */
    width: 20px;
    font-size: 1.4em;
}

.nav-item.level-1 > .nav-link {
    padding: 14px 24px 14px 56px !important; /* More generous padding and proper indentation */
    font-size: 14px;
    font-weight: 400;
    color: #6c757d;
    position: relative;
}

.nav-item.level-1 > .nav-link i {
    margin-right: 20px !important; /* More space between icon and text */
    width: 18px;
    font-size: 1.2em;
}

.nav-item.level-1 > .nav-link::before {
    content: '';
    position: absolute;
    left: 40px;
    top: 50%;
    width: 8px;
    height: 1px;
    background: #dee2e6;
    transform: translateY(-50%);
}

.nav-item.level-2 > .nav-link {
    padding: 12px 24px 12px 80px !important; /* More generous padding and deeper indentation */
    font-size: 13px;
    font-weight: 400;
    color: #6c757d;
    position: relative;
}

.nav-item.level-2 > .nav-link i {
    margin-right: 18px !important; /* More space between icon and text */
    width: 16px;
    font-size: 1.1em;
}

.nav-item.level-2 > .nav-link::before {
    content: '';
    position: absolute;
    left: 64px;
    top: 50%;
    width: 8px;
    height: 1px;
    background: #dee2e6;
    transform: translateY(-50%);
}

/* Hover effects for all levels */
.nav-item.level-1 > .nav-link:hover {
    color: #495057;
    background-color: rgba(0, 123, 255, 0.05);
    border-left-color: var(--primary-color);
}

.nav-item.level-2 > .nav-link:hover {
    color: #495057;
    background-color: rgba(0, 123, 255, 0.05);
    border-left-color: var(--primary-color);
}

/* Expand/collapse arrows */
.nav-item.has-children > .nav-link::after {
    content: '\f107';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    margin-left: auto;
    transition: transform 0.2s ease;
    opacity: 0.6;
}

/* Arrow rotation for items with children */
.nav-item.has-children:hover > .nav-link::after {
    transform: rotate(180deg);
    opacity: 1;
}

/* Collapsed sidebar hover menus - FIXED */
#sidebar.collapsed .nav-item.has-children {
    position: relative;
}

#sidebar.collapsed .collapsed-hover-menu {
    display: none;
    position: absolute;
    left: var(--sidebar-collapsed-width);
    top: 0;
    width: 280px;
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1050;
    opacity: 0;
    transition: opacity 0.2s ease;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    padding: 8px 0;
}

#sidebar.collapsed .nav-item.has-children:hover .collapsed-hover-menu {
    display: block !important;
    opacity: 1 !important;
    animation: slideIn 0.2s ease;
}

.collapsed-hover-menu .hover-menu-item {
    display: block;
    padding: 14px 24px !important; /* Much more generous padding */
    color: #495057;
    text-decoration: none;
    font-size: 14px;
    font-weight: 400;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.collapsed-hover-menu .hover-menu-item:hover {
    background-color: #f8f9fa;
    color: #007bff;
    border-left-color: var(--primary-color);
}

.collapsed-hover-menu .hover-menu-item i {
    margin-right: 20px !important; /* Much more space between icon and text */
    width: 18px;
    text-align: center;
    font-size: 1.2em;
    opacity: 0.8;
}

.collapsed-hover-menu .collapsed-hover-header {
    padding: 12px 24px;
    font-weight: 600;
    color: var(--primary-color);
    border-bottom: 1px solid #dee2e6;
    margin-bottom: 8px;
    font-size: 15px;
}

.collapsed-hover-menu .collapsed-hover-header i {
    margin-right: 16px;
    font-size: 1.3em;
}

.collapsed-hover-menu .sub-item {
    padding-left: 48px !important;
    font-size: 13px;
    color: #6c757d;
}

/* Dynamic Sidebar Specific Styles */
.dynamic-sidebar {
    position: relative;
}

.dynamic-sidebar .nav-system-indicator {
    font-size: 9px;
    color: #6c757d;
    text-align: center;
}

.dynamic-sidebar .dynamic-nav-indicator {
    text-align: center;
    margin-bottom: 10px;
}

/* Simple dropdown menu container */
.dynamic-sidebar .dropdown-menu,
#sidebar .nav-children {
    background-color: rgba(0, 123, 255, 0.02);
    border: none;
    border-left: 3px solid var(--primary-color, #007bff);
    margin: 0;
    padding: 0;
    width: 100%;
    z-index: var(--z-dropdown);
    position: static !important;
    display: none;
    pointer-events: none; /* Disable when hidden */
    transform: none !important;
    transition: all 0.2s ease;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    flex-shrink: 0 !important;
}

/* Enable pointer events when dropdown is shown */
.dynamic-sidebar .dropdown-menu.show,
#sidebar .nav-children.show {
    pointer-events: auto;
}

/* Simple submenu styling - Level 2 Items */
#sidebar .nav-children .nav-link,
#sidebar .dropdown-menu .dropdown-item {
    display: flex;
    align-items: center;
    padding: 16px 24px 16px 40px !important;
    color: var(--text-color) !important;
    text-decoration: none;
    font-size: 15px;
    font-weight: 400;
    border: none;
    background: none;
    width: 100%;
    border-left: 3px solid transparent;
    text-align: left;
    transition: all 0.2s ease;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
    flex-shrink: 0 !important;
    flex-wrap: nowrap !important;
}

/* Simple submenu item icons */
#sidebar .nav-children .nav-link i,
#sidebar .dropdown-menu .dropdown-item i {
    margin-right: 16px !important;
    width: 18px;
    text-align: center;
    font-size: 14px;
    opacity: 0.8;
    flex-shrink: 0;
}

.dynamic-sidebar .dropdown-menu .dropdown-item::before {
    content: '';
    position: absolute;
    left: 24px;
    top: 50%;
    width: 8px;
    height: 1px;
    background: #dee2e6;
    transform: translateY(-50%);
}

/* Simple 2nd level hover effects */
#sidebar .nav-children .nav-link:hover,
#sidebar .dropdown-menu .dropdown-item:hover {
    background-color: rgba(0, 123, 255, 0.1) !important;
    text-decoration: none;
    border-left-color: var(--primary-color) !important;
    color: var(--primary-color) !important;
}

.dynamic-sidebar .dropdown-menu .dropdown-item:active {
    background-color: rgba(0, 123, 255, 0.15);
    border-left-color: var(--primary-color, #007bff);
    color: var(--primary-color, #007bff);
}

/* Simple 3rd level submenu styling - Grandchildren */
.dynamic-sidebar .nav-submenu,
#sidebar .nav-submenu {
    list-style: none;
    margin: 0;
    padding: 0;
    background: rgba(0, 123, 255, 0.01);
    border-left: 2px solid #e9ecef;
    margin-left: 20px;
}

.dynamic-sidebar .nav-submenu .nav-grandchild .dropdown-item,
#sidebar .nav-submenu .nav-grandchild .dropdown-item {
    display: flex;
    align-items: center;
    padding: 14px 20px 14px 30px !important;
    font-size: 14px;
    font-weight: 400;
    color: #6c757d !important;
    position: relative;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    text-decoration: none;
}

/* Simple 3rd level icons */
.dynamic-sidebar .nav-submenu .nav-grandchild .dropdown-item i,
#sidebar .nav-submenu .nav-grandchild .dropdown-item i {
    margin-right: 14px !important;
    width: 16px;
    text-align: center;
    font-size: 13px;
    opacity: 0.8;
    flex-shrink: 0;
}

/* Simple 3rd level hover effects */
.dynamic-sidebar .nav-submenu .nav-grandchild .dropdown-item:hover,
#sidebar .nav-submenu .nav-grandchild .dropdown-item:hover {
    background-color: rgba(0, 123, 255, 0.08) !important;
    border-left-color: var(--primary-color) !important;
    color: var(--primary-color) !important;
}

.dynamic-sidebar .dropdown-menu .dropdown-item i {
    margin-right: 16px;
    width: 14px;
    text-align: center;
    font-size: 12px;
    opacity: 0.8;
    flex-shrink: 0;
}



.dynamic-sidebar .nav-item.has-children.show > .nav-link,
.dynamic-sidebar .nav-item.has-children.open > .nav-link {
    background-color: rgba(0, 123, 255, 0.1);
    border-left-color: var(--primary-color, #007bff);
    color: var(--primary-color, #007bff);
}

/* Dropdown toggle styling */
.dynamic-sidebar .dropdown-toggle::after {
    margin-left: auto;
    transition: transform 0.2s ease;
    opacity: 0.6;
}

.dynamic-sidebar .nav-item.has-children.show .dropdown-toggle::after,
.dynamic-sidebar .nav-item.has-children.open .dropdown-toggle::after {
    transform: rotate(180deg);
    opacity: 1;
}

/* Legacy Sidebar CSS Removed */

.sidebar-footer {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
}

.sidebar-footer .user-info {
    margin-bottom: 10px;
}

/* Transition effects for switching between navigation systems */
.navigation-transition {
    transition: opacity 0.3s ease;
}

.navigation-transition.loading {
    opacity: 0.5;
}

/* Content adjustments for sidebar states */
/* Collapsed sidebar content adjustments */
#sidebar.collapsed + #content,
body.sidebar-collapsed #content {
    margin-left: var(--sidebar-collapsed-width) !important;
    width: calc(100% - var(--sidebar-collapsed-width)) !important;
}

/* Collapsed sidebar content wrapper adjustments */
#sidebar.collapsed + .content-wrapper,
body.sidebar-collapsed .content-wrapper {
    margin-left: var(--sidebar-collapsed-width) !important;
    width: calc(100% - var(--sidebar-collapsed-width)) !important;
}

/* Dark Theme Sidebar Adjustments */
body.dark-theme #sidebar {
    background-color: var(--dark-bg);
    border-right-color: rgba(255, 255, 255, 0.1);
}

body.dark-theme #sidebar .nav-item .dropdown-menu {
    background-color: var(--dark-bg);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-theme #sidebar .nav-item .dropdown-item,
body.dark-theme #sidebar .nav-item .dropdown-item i {
    color: var(--primary-text) !important;
}

body.dark-theme #sidebar .nav-item .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Dark theme improvements for collapsed dropdowns */
body.dark-theme #sidebar.collapsed .nav-item .dropdown-menu {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.1);
}

/* Dark theme scrollbar adjustments */
body.dark-theme #sidebar .nav {
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

body.dark-theme #sidebar .nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
}

body.dark-theme #sidebar .nav::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

body.dark-theme .nav-children {
    background: rgba(255, 255, 255, 0.05);
}

body.dark-theme .nav-item.level-1 > .nav-link::before,
body.dark-theme .nav-item.level-2 > .nav-link::before {
    background: rgba(255, 255, 255, 0.2);
}

body.dark-theme #sidebar.collapsed .collapsed-hover-menu {
    background: #2c3e50;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

body.dark-theme .collapsed-hover-menu .hover-menu-item {
    color: #e9ecef;
}

body.dark-theme .collapsed-hover-menu .hover-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Desktop sidebar - maintain fixed positioning */
@media (min-width: 768px) {
    #sidebar {
        /* Keep fixed positioning for proper layout */
        position: fixed !important;
        top: var(--navbar-height) !important;
        left: 0 !important;
        width: var(--sidebar-width) !important;
        height: calc(100vh - var(--navbar-height)) !important;
        z-index: var(--z-sidebar) !important;
        transform: none !important;
        background-color: var(--surface-color) !important;
        border-right: 1px solid var(--border-color) !important;
        overflow-y: hidden !important;
    }
    
    #sidebar.collapsed {
        width: var(--sidebar-collapsed-width) !important;
    }
    
    #sidebar .nav {
        padding-top: 20px !important;
        padding-bottom: 40px !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        height: 100% !important;
        overflow-y: auto !important;
        width: 100% !important;
    }
    
    /* Remove mobile show behavior on desktop */
    #sidebar.show {
        transform: none !important;
    }
    
    /* CRITICAL FIX: Hide sidebar overlay on desktop */
    .sidebar-overlay {
        display: none !important;
    }
}

/* Mobile Responsive */
@media (max-width: 767px) {
    /* Hide sidebar by default on mobile */
    #sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease !important;
        z-index: var(--z-sidebar) !important;
        padding: 0 !important;
        margin: 0 !important;
        background-color: var(--surface-color) !important;
        overflow-y: hidden !important;
        border: none !important;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.3) !important;
    }
    
    /* Show sidebar when toggled */
    #sidebar.show {
        transform: translateX(0) !important;
    }
    
    /* Mobile sidebar overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: var(--z-sidebar-overlay);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .sidebar-overlay.show {
        opacity: 1;
        visibility: visible;
    }
    

    
    /* Adjust sidebar content for mobile - this is what scrolls */
    #sidebar .nav {
        padding-top: 0 !important; /* No top padding since we have mobile header */
        padding-bottom: 120px !important; /* Extra space for comfortable scrolling on mobile */
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        height: auto !important; /* Auto height to work with sticky header */
        overflow-y: visible !important; /* Let the sidebar container handle scroll */
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        align-items: stretch !important;
    }
    
    /* Mobile sidebar header styling */
    #sidebar .sidebar-mobile-header {
        position: sticky;
        top: 0;
        background-color: var(--surface-color);
        z-index: 10;
        border-bottom: 1px solid var(--border-color);
        padding: 1rem;
        margin: 0;
        display: flex;
        flex-direction: column;
        position: relative;
    }
    
    /* Mobile sidebar logo styling */
    .mobile-sidebar-logo {
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom: 1rem;
        padding: 0.5rem 0;
    }
    
    .mobile-sidebar-logo-img {
        max-width: 280px;
        max-height: 80px;
        height: auto;
        object-fit: contain;
    }
    
    /* Theme-based logo visibility */
    .mobile-sidebar-logo-img.light-theme-logo {
        display: block;
    }
    
    .mobile-sidebar-logo-img.dark-theme-logo {
        display: none;
    }
    
    body.dark-theme .mobile-sidebar-logo-img.light-theme-logo {
        display: none;
    }
    
    body.dark-theme .mobile-sidebar-logo-img.dark-theme-logo {
        display: block;
    }
    
    .mobile-sidebar-controls {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 1rem;
        width: 100%;
    }
    
    .mobile-portal-org-selectors {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 1rem;
        width: 100%;
    }
    
    .mobile-selector {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }
    
    .mobile-selector label {
        font-weight: 600;
        color: var(--text-color);
        font-size: 0.875rem;
        margin-bottom: 0.25rem;
    }
    
    .mobile-selector select {
        width: 100% !important;
        padding: 0.375rem 0.5rem !important;
        height: 32px !important;
        border: 2px solid var(--border-color) !important;
        border-radius: 6px !important;
        background-color: var(--surface-color) !important;
        color: var(--text-color) !important;
        font-size: 0.8rem !important;
        font-weight: 500 !important;
        appearance: none !important;
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23374151' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m6 8 4 4 4-4'/%3e%3c/svg%3e") !important;
        background-position: right 0.5rem center !important;
        background-repeat: no-repeat !important;
        background-size: 1em 1em !important;
        padding-right: 2.5rem !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
    }
    
    .mobile-selector select:focus {
        outline: none !important;
        border-color: var(--primary-color) !important;
        box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1) !important;
    }
    
    .sidebar-close-btn {
        position: absolute !important;
        top: 1rem !important;
        right: 1rem !important;
        background: rgba(0, 0, 0, 0.1) !important;
        border: 2px solid var(--border-color) !important;
        font-size: 1.25rem !important;
        color: var(--text-color) !important;
        cursor: pointer !important;
        padding: 0.5rem !important;
        min-width: 36px !important;
        height: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 6px !important;
        transition: all 0.2s ease !important;
        flex-shrink: 0 !important;
        font-weight: bold !important;
        z-index: 20 !important;
    }
    
    .sidebar-close-btn:hover {
        background-color: var(--danger-color) !important;
        color: white !important;
        border-color: var(--danger-color) !important;
        transform: scale(1.05) !important;
    }
    
    /* Dark theme mobile selector styling */
    body.dark-theme .mobile-selector select {
        background-color: var(--dark-input-bg) !important;
        border-color: var(--dark-border) !important;
        color: var(--dark-text) !important;
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m6 8 4 4 4-4'/%3e%3c/svg%3e") !important;
    }
    
    body.dark-theme .mobile-selector select:focus {
        border-color: var(--primary-color) !important;
        box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1) !important;
    }
    
    body.dark-theme .mobile-selector label {
        color: var(--dark-text) !important;
    }
    
    body.dark-theme .sidebar-close-btn {
        background: rgba(255, 255, 255, 0.1) !important;
        border-color: var(--dark-border) !important;
        color: var(--dark-text) !important;
    }
    
    body.dark-theme .sidebar-close-btn:hover {
        background-color: var(--danger-color) !important;
        color: white !important;
        border-color: var(--danger-color) !important;
    }
    
    body.dark-theme .sidebar-mobile-header {
        background-color: var(--surface-color) !important;
        border-bottom-color: var(--dark-border) !important;
    }
    
    /* Mobile sidebar footer adjustments */
    #sidebar .sidebar-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        background-color: inherit;
        border-top: 1px solid var(--light-border);
        z-index: 10000;
    }
    
    /* Hide collapsed states on mobile */
    #sidebar.collapsed {
        width: 100% !important;
    }
    
    /* Mobile navigation links */
    #sidebar .nav-link {
        padding: 16px 24px;
        font-size: 16px;
    }
    
    #sidebar .nav-link i {
        font-size: 1.2em;
        margin-right: 16px !important;
    }
    
    /* Mobile dropdown menus */
    #sidebar .nav-item .dropdown-menu {
        position: static !important;
        width: 100% !important;
        box-shadow: none !important;
        border-left: 3px solid var(--primary-color);
        margin-left: 20px;
        background-color: rgba(0, 0, 0, 0.02);
    }
    
    /* Dark theme mobile adjustments */
    body.dark-theme #sidebar .sidebar-footer {
        border-top-color: rgba(255, 255, 255, 0.1);
    }
    
    body.dark-theme #sidebar .nav-item .dropdown-menu {
        background-color: rgba(255, 255, 255, 0.05);
        border-left-color: var(--primary-color);
    }
}

/* Animation keyframes */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* MOBILE SIDEBAR STYLING */
.sidebar-mobile-header {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
}

.mobile-sidebar-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.mobile-portal-org-selectors {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.mobile-selector {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.mobile-selector label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mobile-selector .form-select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--primary-text);
    border-radius: 6px;
    padding: 0.5rem;
    font-size: 0.875rem;
}

.sidebar-close-btn {
    background: none;
    border: none;
    color: var(--primary-text);
    font-size: 1.25rem;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ff4757;
}

.mobile-sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.mobile-logout-form {
    margin: 0;
}

.logout-link {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s ease;
}

.logout-link:hover {
    color: #ff4757;
}
