/* ========================================
   MODERN SIDEBAR - NEXUS STYLE DESIGN
======================================== */

.sidebar {
    width: 280px;
    background: #1a1b23;
    border-right: 1px solid #2a2d3a;
    transition: width 0.3s ease, transform 0.3s ease;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    max-height: 100vh; /* Ensure it doesn't exceed viewport height */
}

.sidebar.collapsed {
    width: 80px;
}

/* Sidebar Header */
.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid #2a2d3a;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #1a1b23;
    color: white;
    flex-shrink: 0;
    min-height: 80px;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 1rem;
}

.brand-logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.2rem;
    flex-shrink: 0;
    font-family: 'Inter', sans-serif;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.brand-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
}

.brand-text {
    transition: opacity 0.3s ease, width 0.3s ease;
    min-width: 0;
    flex: 1;
    opacity: 1; /* Make sure it's visible by default */
    width: auto; /* Make sure it has width by default */
}

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

.brand-name {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: white;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px; /* Ensure it doesn't overflow */
    display: block; /* Ensure it displays */
}

.brand-type {
    font-size: 0.8rem;
    color: #9ca3af;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px; /* Ensure it doesn't overflow */
    display: block; /* Ensure it displays */
    margin-top: 2px; /* Add small spacing */
}

/* Search Section */
.sidebar-search {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #2a2d3a;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    background: #252730;
    border: 1px solid #2a2d3a;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    transition: all 0.2s ease;
}

.search-container.focused {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-container i {
    color: #6b7280;
    font-size: 0.9rem;
    margin-right: 0.5rem;
}

.search-input {
    background: none;
    border: none;
    color: white;
    font-size: 0.9rem;
    flex: 1;
    outline: none;
    font-family: 'Inter', sans-serif;
}

.search-input::placeholder {
    color: #6b7280;
}

.search-shortcut {
    font-size: 0.75rem;
    color: #6b7280;
    background: #1f2937;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Inter', sans-serif;
}

.sidebar.collapsed .sidebar-search {
    display: none;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 1rem 0 2rem 0; /* Extra bottom padding to ensure all items are visible */
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #374151 transparent;
    min-height: 0; /* Allow flex item to shrink */
    max-height: calc(100vh - 200px); /* Reserve space for header and footer */
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: #374151;
    border-radius: 2px;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section:last-child {
    margin-bottom: 2rem; /* Extra margin for last section to ensure visibility */
    padding-bottom: 1rem; /* Additional padding at bottom */
}

.nav-section-title {
    padding: 0 1.5rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: opacity 0.3s ease;
    font-family: 'Inter', sans-serif;
}

.sidebar.collapsed .nav-section-title {
    opacity: 0;
    height: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

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

.nav-item {
    margin: 0 1rem 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: #f9fafb;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
    position: relative;
    font-size: 0.9rem;
    font-family: 'Inter', sans-serif;
    min-height: 44px; /* Minimum height for touch targets */
    flex-wrap: nowrap; /* Keep icon and text on same line */
}

.nav-link:hover {
    background-color: #252730;
    color: white;
    transform: translateX(2px);
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
    color: white;
    border-left: 3px solid #6366f1;
    border-radius: 0 8px 8px 0;
    margin-left: 0.75rem;
    padding-left: 1.25rem;
}

.nav-link.active .nav-icon {
    color: #6366f1;
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.75rem;
    flex-shrink: 0;
    transition: color 0.2s ease;
    font-size: 1rem;
}

.nav-text {
    flex: 1;
    transition: opacity 0.3s ease;
    white-space: normal; /* Allow text wrapping */
    overflow: visible; /* Don't hide overflow */
    text-overflow: initial; /* Remove ellipsis */
    line-height: 1.3; /* Better line spacing for wrapped text */
    word-wrap: break-word; /* Break long words if needed */
    min-width: 0; /* Allow flex shrinking */
}

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

/* Dashboard-style navigation items */
.dashboard-nav-item {
    padding: 1rem !important;
    margin-bottom: 0.5rem;
    border-radius: 10px;
    transition: all 0.3s ease;
    background: transparent;
    border: none;
}

.dashboard-nav-item:hover {
    background: #252730 !important;
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.dashboard-nav-item.active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6) !important;
    color: white !important;
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.3);
}

.nav-icon-container {
    width: 40px;
    height: 40px;
    background: #374151;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.dashboard-nav-item:hover .nav-icon-container {
    background: #4b5563;
}

.dashboard-nav-item.active .nav-icon-container {
    background: rgba(255, 255, 255, 0.2);
}

.nav-subtitle {
    font-size: 0.75rem;
    opacity: 0.8;
    line-height: 1.2;
    margin-top: 2px;
}

.dashboard-nav-item.active .nav-subtitle {
    color: rgba(255, 255, 255, 0.8) !important;
}

.sidebar.collapsed .dashboard-nav-item {
    justify-content: center;
}

.sidebar.collapsed .nav-subtitle {
    display: none !important;
}

/* Dropdown Navigation */
.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle::after {
    content: '\f054';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 0.7rem;
    margin-left: auto;
    transition: transform 0.2s ease;
    color: #9ca3af;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
}


.nav-dropdown.open .nav-dropdown-toggle::after,
.nav-dropdown.expanded .nav-dropdown-toggle::after {
    transform: rotate(90deg);
}

.nav-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    padding-left: 2.5rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease, padding-top 0.3s ease;
    opacity: 0;
}

.nav-dropdown.open .nav-submenu,
.nav-dropdown.expanded .nav-submenu {
    max-height: calc(100vh - 300px) !important; /* Dynamic height based on viewport */
    opacity: 1 !important;
    padding-top: 0.25rem !important;
    overflow-y: auto !important; /* Enable scrolling for long submenus */
    overflow-x: hidden !important;
    scrollbar-width: thin;
    scrollbar-color: #374151 transparent;
    display: block !important; /* Force display */
}


/* Submenu scrollbar styling */
.nav-submenu::-webkit-scrollbar {
    width: 4px;
}

.nav-submenu::-webkit-scrollbar-track {
    background: transparent;
}

.nav-submenu::-webkit-scrollbar-thumb {
    background: #374151;
    border-radius: 2px;
}

.sidebar.collapsed .nav-submenu {
    display: none;
}

.nav-submenu .nav-link {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    color: #e5e7eb;
    min-height: 40px; /* Minimum height for submenu items */
    white-space: normal; /* Allow text wrapping in submenus */
    line-height: 1.3;
}

.nav-submenu .nav-link:hover {
    color: white;
    background-color: #1f2937;
    transform: translateX(4px);
}

.nav-submenu .nav-link.active {
    color: #6366f1;
    background-color: rgba(99, 102, 241, 0.1);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid #2a2d3a;
    background: #1a1b23;
    flex-shrink: 0; /* Prevent footer from shrinking */
    min-height: 70px; /* Set minimum height for footer */
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.sidebar-user:hover {
    background-color: #252730;
}

.sidebar.collapsed .sidebar-user {
    justify-content: center;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid #374151;
}

.user-avatar.placeholder {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    border: 2px solid #6366f1;
}

.user-info {
    flex: 1;
    min-width: 0;
    transition: opacity 0.3s ease;
}

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

.user-name {
    font-weight: 600;
    color: white;
    font-size: 0.9rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    color: #9ca3af;
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 1050;
        transition: transform 0.3s ease;
        width: 280px; /* Ensure full width on mobile */
        min-width: 280px; /* Prevent shrinking */
        height: 100vh;
        max-height: 100vh;
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
        width: 280px !important; /* Force full width when open */
    }
    
    /* Ensure nav scrolling works on mobile */
    .sidebar-nav {
        max-height: calc(100vh - 160px); /* Account for header and footer on mobile */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }
    
    /* Force all text elements to be visible when mobile sidebar is open */
    .sidebar.mobile-open .nav-text {
        opacity: 1 !important;
        width: auto !important;
        overflow: visible !important;
        white-space: normal !important; /* Allow wrapping on mobile */
        text-overflow: initial !important;
        line-height: 1.3 !important;
    }
    
    .sidebar.mobile-open .brand-text {
        opacity: 1 !important;
        width: auto !important;
        overflow: visible !important;
    }
    
    .sidebar.mobile-open .user-info {
        opacity: 1 !important;
        width: auto !important;
        overflow: visible !important;
    }
    
    .sidebar.mobile-open .nav-section-title {
        opacity: 1 !important;
        height: auto !important;
        padding: 0 1.5rem 0.5rem !important;
        margin: 0 !important;
    }
    
    /* Ensure submenus work properly on mobile - only when dropdown is open */
    .sidebar.mobile-open .nav-dropdown.open .nav-submenu,
    .sidebar.mobile-open .nav-dropdown.expanded .nav-submenu {
        max-height: calc(100vh - 350px) !important;
        overflow-y: auto !important;
        display: block !important;
        opacity: 1 !important;
        padding-top: 0.25rem !important;
    }
    
    /* Hide closed submenus on mobile */
    .sidebar.mobile-open .nav-dropdown:not(.open):not(.expanded) .nav-submenu {
        max-height: 0 !important;
        opacity: 0 !important;
        overflow: hidden !important;
        padding-top: 0 !important;
    }
    
    .sidebar.collapsed {
        width: 280px;
        transform: translateX(-100%);
    }
    
    .sidebar.collapsed.mobile-open {
        transform: translateX(0);
    }
    
    /* Make sure collapsed elements are visible on mobile */
    .sidebar.collapsed .nav-text {
        opacity: 1;
        width: auto;
    }
    
    .sidebar.collapsed .nav-section-title {
        opacity: 1;
        height: auto;
        padding: 0 1.5rem 0.5rem;
        margin: 0;
    }
    
.sidebar.collapsed .nav-submenu {
    display: none !important; /* Hide submenus when sidebar is collapsed on mobile */
    max-height: 0 !important;
    overflow: hidden !important;
}    /* Only show submenus when both mobile-open and dropdown is open */
    .sidebar.collapsed.mobile-open .nav-dropdown.open .nav-submenu,
    .sidebar.collapsed.mobile-open .nav-dropdown.expanded .nav-submenu {
        display: block !important;
        max-height: calc(100vh - 400px) !important;
        overflow-y: auto !important;
        opacity: 1 !important;
        padding-top: 0.25rem !important;
    }
    
    .sidebar.collapsed.mobile-open .nav-dropdown:not(.open):not(.expanded) .nav-submenu {
        display: none !important;
        max-height: 0 !important;
        overflow: hidden !important;
        opacity: 0 !important;
    }
    
    .sidebar.collapsed .brand-text {
        opacity: 1;
        width: auto;
        overflow: visible;
    }
    
    .sidebar.collapsed .user-info {
        opacity: 1;
        width: auto;
    }
    
    .sidebar.collapsed .sidebar-header {
        justify-content: flex-start;
        padding: 1.5rem;
    }
    
    .sidebar.collapsed .sidebar-search {
        display: block;
    }
    
    /* Ensure brand name and type are visible on mobile */
    .brand-name,
    .brand-type {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }
    
    /* Fix sidebar header on mobile */
    .sidebar-header {
        min-height: 80px;
        padding: 1.5rem;
    }
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* Prevent body scroll when mobile sidebar is open */
body.sidebar-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

@media (max-width: 768px) {
    body.sidebar-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
    
    /* Improve mobile touch targets */
    .nav-link {
        min-height: 48px;
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
    }
    
    .nav-submenu .nav-link {
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    /* Better mobile dropdown arrow positioning */
    .nav-dropdown-toggle::after {
        font-size: 0.8rem;
        width: 18px;
        height: 18px;
    }
}

/* ========================================
   TREEVIEW FUNCTIONALITY
======================================== */

/* Treeview styles for collapsible menu items */
.has-treeview > .nav-link {
    cursor: pointer;
}

.has-treeview > .nav-link .right {
    transition: transform 0.3s ease;
    margin-left: auto;
}

.has-treeview.menu-open > .nav-link .right {
    transform: rotate(-90deg);
}

/* Treeview submenu */
.nav-treeview {
    display: none;
    padding-left: 0;
    margin: 0;
    list-style: none;
    background: rgba(0, 0, 0, 0.1);
}

/* Show treeview when parent has menu-open class */
.has-treeview.menu-open > .nav-treeview {
    display: block;
}

.nav-treeview .nav-item {
    border-bottom: none;
}

.nav-treeview .nav-link {
    padding: 0.75rem 1rem 0.75rem 3rem;
    color: #b8c7ce;
    font-size: 0.9rem;
    border-radius: 0;
    border-left: 3px solid transparent;
    transition: all 0.3s ease;
}

.nav-treeview .nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #ffffff;
    border-left-color: #6366f1;
}

.nav-treeview .nav-link.active {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
    border-left-color: #6366f1;
}

.nav-treeview .nav-link .nav-icon {
    width: 16px;
    height: 16px;
    margin-right: 0.75rem;
    opacity: 0.7;
}

/* Collapsed sidebar treeview handling */
.sidebar.collapsed .has-treeview .nav-treeview {
    display: none !important;
}

.sidebar.collapsed .has-treeview > .nav-link .right {
    display: none;
}