.profile-dropdown {
    position: relative;
    cursor: pointer;
}

.profile-dropdown .dropdown-toggle::after {
    display: inline-block;
    margin-left: 0.35em;
    vertical-align: 0.255em;
    font-size: 0.75rem;
    color: #64748b;
    transition: transform 0.15s ease;
}

/* 
   We use Bootstrap's native '.show' class OR our custom '.is-hovered' class 
   to trigger the display. This prevents them from conflicting!
*/
@media (min-width: 576px) {
    .profile-dropdown.is-hovered .dropdown-menu,
    .profile-dropdown .dropdown-menu.show {
        display: block;
        margin-top: 0;
        animation: fadeInMenu 0.15s ease;
    }

    .profile-dropdown.is-hovered .dropdown-toggle::after,
    .profile-dropdown .dropdown-toggle.show::after {
        transform: rotate(180deg);
    }
}

/* Uncommented and active dropdown container configurations */
.profile-dropdown .dropdown-menu {
    position: absolute;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
    border-radius: 0.5rem;
    padding: 0.35rem;
    min-width: 140px;
    right: 0 !important;
    left: auto !important;
    background-color: #ffffff;
}

.profile-dropdown .dropdown-item {
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}

    .profile-dropdown .dropdown-item:hover {
        background-color: #f1f5f9;
        color: #ef4444;
    }

@keyframes fadeInMenu {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Sidebar Layout - White Theme with Green Accents */
#sidebar {
    width: 250px;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background-color: #ffffff; /* Clean white background */
    border-right: 1px solid #e5e7eb; /* Subtle right border */
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    color: #4b5563; /* Slate text color */
    display: flex;
    flex-direction: column;
}

#sidebar .sidebar-logo {
    height: 70px; /* Taller area for logo + subtitle */
    display: flex;
    align-items: center;
    padding: 0 0.85rem;
    border-bottom: 1px solid #e5e7eb;
}

#sidebar .logo-img {
    height: 42px;
    margin-right: 0.5rem;
}

#sidebar .logo-text-wrapper {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

#sidebar .logo-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #1f2937; /* Dark slate/black */
    white-space: nowrap;
}

#sidebar .logo-subtitle {
    font-size: 0.68rem;
    font-weight: 600;
    color: #0d6efd; /* Blue color matching 'Monitoring System' styling */
    white-space: nowrap;
}

#sidebar .nav-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

#sidebar .nav-item-header {
    padding: 1.25rem 1.25rem 0.25rem 1.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    font-weight: 700;
}

#sidebar .nav-link-custom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1.25rem;
    color: #4b5563;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    cursor: pointer;
    border-left: 3px solid transparent;
}

#sidebar .nav-link-custom:hover {
    background-color: #f3f4f6; /* Gray hover background */
    color: #111827;
}

#sidebar .nav-item-custom.active > .nav-link-custom {
    background-color: #f0fdf4; /* Mint green active background */
    color: #15803d; /* Dark green active text */
    border-left-color: #8cc63f; /* Signature qube green left border */
    font-weight: 600;
}

#sidebar .submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
    background-color: #f9fafb; /* Light-gray submenu list background */
}

#sidebar .submenu.show {
    display: block;
}

#sidebar .submenu-link {
    display: flex;
    align-items: center;
    padding: 0.55rem 1.25rem 0.55rem 2.5rem;
    color: #4b5563;
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

#sidebar .submenu-link:hover {
    color: #111827;
    background-color: #f3f4f6;
}

#sidebar .submenu-item.active > .submenu-link {
    color: #15803d;
    font-weight: 600;
    background-color: #e8f5e9; /* Active sub-item background */
}

#sidebar .menu-icon {
    margin-right: 0.75rem;
    font-size: 1.1rem;
    color: #6b7280; /* Gray base menu icons */
}

#sidebar .nav-item-custom.active .menu-icon,
#sidebar .submenu-item.active .menu-icon {
    color: #8cc63f; /* Green highlight active icon */
}

#sidebar .arrow-icon {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
    color: #9ca3af;
}

#sidebar .nav-link-custom.expanded .arrow-icon {
    transform: rotate(90deg);
}

/* Top Bar Layout */
#topbar {
    position: fixed;
    top: 0;
    right: 0;
    left: 250px;
    height: 60px;
    background-color: #fff;
    border-bottom: 1px solid #e5e7eb;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Main Content Wrapper */
#main-wrapper {
    margin-left: 250px;
    padding-top: 60px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: #f3f4f6;
}

main[role="main"] {
    padding: 0 !important;
    margin: 0 !important;
}

/* Sidebar Toggle Mechanics */
body.sidebar-collapsed #sidebar {
    transform: translateX(-250px);
}

body.sidebar-collapsed #topbar {
    left: 0;
}

body.sidebar-collapsed #main-wrapper {
    margin-left: 0;
}

/* Scrollbar customization for sidebar */
#sidebar::-webkit-scrollbar {
    width: 6px;
}
#sidebar::-webkit-scrollbar-track {
    background: transparent;
}
#sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}
#sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   Mobile Responsive Styles
   ========================================================================== */
@media (max-width: 767.98px) {
    /* Hide sidebar by default on mobile */
    #sidebar {
        transform: translateX(-250px);
        z-index: 1050;
    }

    /* Show sidebar when toggled on mobile */
    body.sidebar-show #sidebar {
        transform: translateX(0);
    }

    /* Topbar spans full width on mobile */
    #topbar {
        left: 0;
        z-index: 1040;
    }

    /* Main content has no left margin on mobile */
    #main-wrapper {
        margin-left: 0;
    }

    /* Add backdrop when sidebar is open on mobile */
    body.sidebar-show::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1045;
        transition: opacity 0.3s ease;
    }

    /* Adjust sidebar toggle behavior on mobile */
    body.sidebar-collapsed #sidebar {
        transform: translateX(-250px);
    }

    body.sidebar-collapsed #topbar {
        left: 0;
    }

    body.sidebar-collapsed #main-wrapper {
        margin-left: 0;
    }
}

/* Desktop: sidebar always visible, toggle collapses it */
@media (min-width: 768px) {
    #sidebar {
        transform: translateX(0);
    }

    body.sidebar-collapsed #sidebar {
        transform: translateX(-250px);
    }

    body.sidebar-collapsed #topbar {
        left: 0;
    }

    body.sidebar-collapsed #main-wrapper {
        margin-left: 0;
    }
}
