/**
 * Custom sidebar styles with responsive behavior
 */

/* Desktop sidebar - fixed position */
@media (min-width: 768px) {
    #sidebarMenu {
        transition: all 0.3s ease-in-out;
        max-height: 100vh;
        overflow: hidden;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 1090 !important; /* Force above Bootstrap sticky-top and navbar */
        width: inherit;
        max-width: inherit;
    }
}

/* Mobile sidebar - overlay behavior */
@media (max-width: 767.98px) {
    #sidebarMenu {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1100 !important; /* Force above everything including Bootstrap sticky */
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        background: var(--sidebar-gradient, linear-gradient(135deg, #1e3c72 0%, #2a5298 100%));
    }
    
    #sidebarMenu.show {
        transform: translateX(0);
    }
    
    #sidebarMenu.collapsing {
        transform: translateX(-100%);
    }
    
    /* Mobile backdrop */
    #sidebarMenu.show::before {
        content: '';
        position: fixed;
        top: 0;
        left: 280px;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
        animation: fadeIn 0.3s ease-in-out;
    }
}

/* Sidebar container */
#sidebarMenu .position-sticky {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Main navigation container with scrolling */
#sidebarMenu .flex-grow-1 {
    overflow: auto;
    flex: 1 0 auto;
    min-height: 0;
    max-height: calc(100vh - 150px);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

/* Custom scrollbar for webkit browsers */
#sidebarMenu .flex-grow-1::-webkit-scrollbar {
    width: 6px;
}

#sidebarMenu .flex-grow-1::-webkit-scrollbar-track {
    background: transparent;
}

#sidebarMenu .flex-grow-1::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

#sidebarMenu .flex-grow-1::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* User menu styles */
#user-account-menu {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 8px 8px 0 0;
    margin: 0 -0.5rem -0.5rem;
    padding: 1rem;
    flex-shrink: 0;
}

/* Active navigation item */
.nav-link.active {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
}

/* Hover effect for nav items */
.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    transition: background-color 0.2s ease;
}

/* Mobile close button styling */
@media (max-width: 767.98px) {
    .sidebar .btn-outline-light {
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(255, 255, 255, 0.3);
    }
    
    .sidebar .btn-outline-light:hover {
        background: rgba(255, 255, 255, 0.2);
        border-color: rgba(255, 255, 255, 0.5);
    }
}

/* Animation for sidebar slide */
@keyframes sidebarSlide {
    from { 
        opacity: 0; 
        transform: translateX(-20px); 
    }
    to { 
        opacity: 1; 
        transform: translateX(0); 
    }
}

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

/* Apply animation when sidebar is shown on desktop */
@media (min-width: 768px) {
    .sidebar:not(.d-none) {
        animation: sidebarSlide 0.3s ease-in-out;
    }
}

/* Hide sidebar toggle button text on small screens */
@media (max-width: 575.98px) {
    .sidebar-toggle .toggle-text {
        display: none;
    }
}

/* Responsive navigation item text */
@media (max-width: 1199.98px) {
    .nav-link {
        font-size: 0.9rem;
    }
}

/* Ensure proper spacing for sidebar sections */
.sidebar-heading {
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Dark mode support */
[data-bs-theme="dark"] #user-account-menu {
    background: rgba(255, 255, 255, 0.05);
}

[data-bs-theme="dark"] .nav-link.active {
    background-color: rgba(255, 255, 255, 0.15);
}

[data-bs-theme="dark"] .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

/* Force sidebar above all Bootstrap sticky elements */
#sidebarMenu {
    z-index: 1090 !important;
}

/* Ensure sidebar is above sticky navbar on all devices */
@media (max-width: 767.98px) {
    #sidebarMenu {
        z-index: 1100 !important;
    }
}