/**
 * Desktop Sidebar Positioning Fix
 * Ensures sidebar displays properly below navbar on desktop only
 */

/* Desktop-only sidebar positioning fix */
@media (min-width: 992px) {
    /* Ensure sidebar is positioned correctly below navbar */
    .sidebar {
        position: fixed !important;
        top: var(--header-height, 60px) !important;
        left: 0 !important;
        width: var(--sidebar-width, 260px) !important;
        height: calc(100vh - var(--header-height, 60px)) !important;
        z-index: 1000 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        background: linear-gradient(to bottom, #4b6cb7, #182848) !important;
        color: white !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1) !important;
        transition: all 0.3s ease !important;
    }

    /* Collapsed sidebar state */
    .sidebar.collapsed {
        width: 60px !important;
        overflow-x: hidden !important;
    }

    /* Main content positioning */
    .main-content {
        margin-left: var(--sidebar-width, 260px) !important;
        padding: 1.5rem !important;
        min-height: calc(100vh - var(--header-height, 60px)) !important;
        transition: margin-left 0.3s ease !important;
        width: calc(100% - var(--sidebar-width, 260px)) !important;
        position: relative !important;
    }

    /* Main content when sidebar is collapsed */
    .main-content.sidebar-collapsed,
    .sidebar.collapsed ~ .main-content {
        margin-left: 60px !important;
        width: calc(100% - 60px) !important;
    }

    /* Ensure navbar stays above sidebar */
    .navbar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: var(--header-height, 60px) !important;
        z-index: 1070 !important;
        background: linear-gradient(to right, #4b6cb7, #182848) !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
    }

    /* Body padding to account for fixed navbar */
    body {
        padding-top: var(--header-height, 60px) !important;
    }

    /* Sidebar content positioning */
    .sidebar-content {
        padding: 0 !important;
        height: 100% !important;
        overflow-y: auto !important;
    }

    /* Sidebar links styling */
    .sidebar .sidebar-link {
        display: flex !important;
        align-items: center !important;
        padding: 0.75rem 1.5rem !important;
        color: rgba(255, 255, 255, 0.8) !important;
        text-decoration: none !important;
        transition: all 0.3s ease !important;
        border-left: 3px solid transparent !important;
        font-size: 1rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
    }

    .sidebar .sidebar-link:hover {
        background-color: rgba(255, 255, 255, 0.1) !important;
        color: white !important;
        text-decoration: none !important;
    }

    .sidebar .sidebar-link.active {
        background-color: rgba(255, 255, 255, 0.15) !important;
        color: white !important;
        border-left: 3px solid white !important;
    }

    .sidebar .sidebar-link i {
        margin-right: 0.75rem !important;
        width: 20px !important;
        text-align: center !important;
        font-size: 1.1rem !important;
        flex-shrink: 0 !important;
    }

    /* Collapsed sidebar link styling */
    .sidebar.collapsed .sidebar-link {
        padding: 0.75rem 0 !important;
        justify-content: center !important;
        text-align: center !important;
        position: relative !important;
    }

    .sidebar.collapsed .sidebar-link i {
        margin-right: 0 !important;
        font-size: 1.25rem !important;
    }

    .sidebar.collapsed .sidebar-link .link-text {
        display: none !important;
    }

    /* Tooltip for collapsed sidebar */
    .sidebar.collapsed .sidebar-link:hover::after {
        content: attr(title) !important;
        position: absolute !important;
        left: 100% !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        background-color: rgba(0, 0, 0, 0.8) !important;
        color: white !important;
        padding: 8px 12px !important;
        border-radius: 4px !important;
        font-size: 0.875rem !important;
        white-space: nowrap !important;
        z-index: 1100 !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
        margin-left: 8px !important;
        pointer-events: none !important;
    }

    /* User profile section in sidebar - centered layout */
    .sidebar .user-profile {
        padding: 1.5rem !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 0.75rem !important;
    }

    .sidebar .user-profile .profile-picture,
    .sidebar .user-profile .avatar-initials {
        width: 80px !important;
        height: 80px !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 2rem !important;
        font-weight: bold !important;
        background: rgba(255, 255, 255, 0.2) !important;
        color: white !important;
        border: 3px solid rgba(255, 255, 255, 0.3) !important;
        margin-bottom: 0 !important;
    }

    .sidebar .user-profile .user-info {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 0.25rem !important;
    }

    .sidebar .user-profile .user-name,
    .sidebar .user-profile .sidebar-user-name {
        font-weight: 600 !important;
        font-size: 1rem !important;
        color: white !important;
        margin: 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 180px !important;
    }

    .sidebar .user-profile .user-role,
    .sidebar .user-profile .sidebar-user-role {
        font-size: 0.85rem !important;
        color: rgba(255, 255, 255, 0.7) !important;
        margin: 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 180px !important;
    }

    .sidebar.collapsed .user-profile {
        display: none !important;
    }

    /* Sidebar headings */
    .sidebar .sidebar-heading {
        font-size: 0.8rem !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
        padding: 1.5rem 1.5rem 0.5rem !important;
        opacity: 0.6 !important;
        color: rgba(255, 255, 255, 0.6) !important;
    }

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

    /* Sidebar dividers */
    .sidebar hr {
        border-color: rgba(255, 255, 255, 0.1) !important;
        margin: 0.5rem 1.5rem !important;
    }

    .sidebar.collapsed hr {
        display: none !important;
    }

    /* Scrollbar styling for sidebar */
    .sidebar::-webkit-scrollbar {
        width: 6px !important;
    }

    .sidebar::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1) !important;
    }

    .sidebar::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3) !important;
        border-radius: 3px !important;
    }

    .sidebar::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.5) !important;
    }

    /* Ensure proper z-index stacking */
    .navbar {
        z-index: 1070 !important;
    }

    .sidebar {
        z-index: 1000 !important;
    }

    .main-content {
        z-index: 1 !important;
    }

    /* Dropdown menus should be above sidebar */
    .dropdown-menu {
        z-index: 1080 !important;
    }

    /* Modal should be above everything */
    .modal {
        z-index: 1090 !important;
    }

    /* Ensure sidebar toggle button works properly */
    #sidebar-toggle-navbar {
        z-index: 1071 !important;
        position: relative !important;
    }
}

/* Large desktop screens */
@media (min-width: 1200px) {
    .main-content {
        padding: 2rem !important;
    }
}

/* Extra large desktop screens */
@media (min-width: 1400px) {
    .main-content {
        padding: 2.5rem !important;
    }
}

/* Ensure no interference with mobile styles */
@media (max-width: 991px) {
    /* Reset any desktop-specific styles on mobile */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 280px !important;
        height: 100vh !important;
        transform: translateX(-100%) !important;
        z-index: 1060 !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}