/* Override Bootstrap link styles in sidebar */
#sidebar .sidebar-text,
#sidebar a.sidebar-text,
nav#sidebar .sidebar-text,
nav#sidebar a.sidebar-text,
.sidebar-text, 
.sidebar-text:hover, 
.sidebar-text:focus {
    color: #FFFFFF !important;
    text-decoration: none !important;
    transition: all 0.3s;
}

#wrapper {
    display: flex;
    width: 100%;
    align-items: stretch;
}

/* Override Bootstrap nav styles with higher specificity */
nav#sidebar,
#sidebar,
body nav#sidebar,
html body nav#sidebar {
    width: 250px;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 999;
    background: #003366 !important;
    background-color: #003366 !important;
    color: #FFFFFF !important;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar.active {
    margin-left: -250px;
}

.sidebar-header,
#sidebar .sidebar-header,
nav#sidebar .sidebar-header {
    padding: 20px;
    background: #003366 !important;
    background-color: #003366 !important;
    flex-shrink: 0;
}

.sidebar-components {
    padding: 20px 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar but keep menu scrollable*/
#sidebar .sidebar-components,
nav#sidebar .sidebar-components {
    scrollbar-width: none;           /* Firefox */
    -ms-overflow-style: none;       /* IE / old Edge */
}
#sidebar .sidebar-components::-webkit-scrollbar,
nav#sidebar .sidebar-components::-webkit-scrollbar {
    display: none;                  /* Chrome, Safari, Edge */
}

.sidebar-paragraph,
#sidebar .sidebar-paragraph {
    color: #FFFFFF !important;
    padding: 10px;
}

.dropdown-toggle::after {
    display: block;
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
}

a.right-arrow[data-toggle="collapse"] {
    position: relative;
}

/* Inventory: main label links to inventory, chevron toggles submenu */
.sidebar-inventory-row {
    display: flex;
    align-items: center;
    width: 100%;
}
.sidebar-inventory-row .dropdown-toggle::after {
    display: none;
}
.sidebar-inventory-row .sidebar-chevron {
    font-size: 0.9rem;
    transition: transform 0.2s;
}
/* Collapsed: chevron points right (">"); Expanded: rotate down ("v") */
a.sidebar-dropdown-toggle[aria-expanded="true"] .sidebar-chevron {
    transform: rotate(90deg);
}
.sidebar-inventory-row .sidebar-chevron:hover {
    color: #BBE0EF !important;
}

.sidebar-button,
#sidebar .sidebar-button,
#sidebar a.sidebar-button,
nav#sidebar .sidebar-button {
    padding: 10px;
    font-size: 1.1em;
    display: block;
    color: #FFFFFF !important;
}

.sidebar-button:hover,
#sidebar .sidebar-button:hover,
#sidebar a.sidebar-button:hover,
nav#sidebar .sidebar-button:hover {
    color: #003366 !important;
    background: #BBE0EF !important;
    background-color: #BBE0EF !important;
}

.sidebar-subitem {
    font-size: 0.9em !important;
    padding-left: 30px !important;
    background: rgba(187, 224, 239, 0.1);
}

ul.CTAs {
    padding: 20px;
}

ul.CTAs a {
    text-align: center;
    font-size: 0.9em !important;
    display: block;
    border-radius: 5px;
    margin-bottom: 5px;
}

a.nav-button,
#sidebar a.nav-button,
nav#sidebar a.nav-button {
    background: #BBE0EF !important;
    background-color: #BBE0EF !important;
    color: #003366 !important;
}

/* Ensure sidebar brand/logo uses correct color */
#sidebar .navbar-brand,
#sidebar .navbar-brand h3,
#sidebar .navbar-brand .titlefont,
nav#sidebar .navbar-brand,
nav#sidebar .navbar-brand h3,
nav#sidebar .navbar-brand .titlefont {
    color: #BBE0EF !important;
}

.bottomleft {
    bottom: 0;
    position: absolute;
    min-width: 250px;
    max-width: 250px;
}

/* ---------------------------------------------------
    CONTENT STYLE
----------------------------------------------------- */

#content {
    width: 100%;
    margin-left: 250px;
    padding: 20px;
    min-height: 100vh;
    transition: all 0.3s;
}

/* ---------------------------------------------------
    MEDIAQUERIES
----------------------------------------------------- */

@media (max-width: 768px) {
    #sidebar {
        margin-left: -250px;
    }
    #sidebar.active {
        margin-left: 0;
    }
    #sidebarCollapse span {
        display: none;
    }
    /* Hide hamburger when sidebar is open so it doesn't overlap the logo */
    body.sidebar-mobile-open .sidebar-mobile-toggle {
        display: none !important;
    }

    /* Hide chevron on small screens; close only via overlay or link */
    #sidebar .sidebar-toggle-btn,
    #sidebar #sidebarToggle {
        display: none !important;
    }
}


/* Section headers (Main Menu, Inventory, etc.) */
.sidebar-section-header {
    padding: 12px 20px 6px;
    margin-top: 8px;
}
.sidebar-section-header:first-of-type { margin-top: 0; }
.sidebar-section-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.6) !important;
}

/* Link with icon + label */
.sidebar-link {
    display: flex;
    align-items: center;
    padding: 10px 20px;
}
.sidebar-icon {
    width: 24px;
    min-width: 24px;
    margin-left: 6px;
    margin-right: 12px;
    font-size: 1.1rem;
}
.sidebar-subitem .sidebar-icon { margin-right: 12px; }

/* Toggle button in header */
.sidebar-toggle-btn {
    background: transparent;
    border: none;
    color: #BBE0EF !important;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
}
.sidebar-toggle-btn:hover { color: #fff !important; background: rgba(187, 224, 239, 0.2); }
.sidebar-header .navbar-brand { margin-right: 0; }

/* Minimized sidebar */
#sidebar.sidebar-minimized {
    width: 72px;
    overflow: visible;
}
#sidebar.sidebar-minimized .sidebar-brand-text,
#sidebar.sidebar-minimized .sidebar-section-label,
#sidebar.sidebar-minimized .sidebar-label,
#sidebar.sidebar-minimized .sidebar-user-info,
#sidebar.sidebar-minimized .dropdown-toggle::after {
    display: none !important;
}
#sidebar.sidebar-minimized .sidebar-header { justify-content: center; padding: 16px 8px; }
#sidebar.sidebar-minimized .sidebar-toggle-btn { margin: 0; }
#sidebar.sidebar-minimized .sidebar-toggle-icon { transform: none; }
#sidebar.sidebar-minimized .sidebar-link,
#sidebar.sidebar-minimized .sidebar-user-toggle {
    justify-content: center;
    padding: 10px;
}
#sidebar.sidebar-minimized .sidebar-icon { margin-right: 0; }
#sidebar.sidebar-minimized .sidebar-section-header {
    padding: 8px 0;
    margin: 4px 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
#sidebar.sidebar-minimized .sidebar-user-card {
    flex-direction: column;
    padding: 12px 8px;
}
#sidebar.sidebar-minimized .sidebar-user-avatar { margin-bottom: 0; }

/* Content margin when sidebar minimized */
body.sidebar-minimized #content { margin-left: 72px; }
#content { margin-left: 250px; transition: margin-left 0.3s; }

/* User card at bottom */
.sidebar-user-card {
    flex-shrink: 0;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    border-top: 1px solid rgba(187, 224, 239, 0.2);
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #BBE0EF;
    color: #003366;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-size: 1.25rem;
}
.sidebar-user-info { display: flex; flex-direction: column; }
.sidebar-user-name { font-weight: 600; font-size: 0.95rem; }
.sidebar-user-role { font-size: 0.75rem; opacity: 0.9; }

/* ---------------------------------------------------
    MEDIAQUERIES - Mobile & Tablet
----------------------------------------------------- */
@media (max-width: 768px) {
    #sidebar {
        margin-left: -250px;
        transition: margin-left 0.3s;
        z-index: 1000;
    }
    #sidebar.sidebar-minimized {
        width: 250px;
        margin-left: -250px;
    }
    #sidebar.sidebar-minimized .sidebar-brand-text,
    #sidebar.sidebar-minimized .sidebar-section-label,
    #sidebar.sidebar-minimized .sidebar-label,
    #sidebar.sidebar-minimized .sidebar-user-info { display: block !important; }
    #sidebar.sidebar-minimized .sidebar-toggle-icon { transform: none; }
    #sidebar.sidebar-minimized .sidebar-link,
    #sidebar.sidebar-minimized .sidebar-user-toggle { justify-content: flex-start; padding: 10px 20px; }
    #sidebar.sidebar-minimized .sidebar-icon { margin-right: 12px; margin-left: 6px; }
    #sidebar.sidebar-minimized .sidebar-section-header { padding: 12px 20px 6px; margin: 8px 0 4px; border-bottom: none; }
    #sidebar.sidebar-minimized .sidebar-user-card { flex-direction: row; padding: 16px 20px; }
    #sidebar.sidebar-minimized .sidebar-user-avatar { margin-bottom: 0; }

    #sidebar.active {
        margin-left: 0;
    }
    #sidebar.sidebar-minimized.active {
        margin-left: 0;
        width: 250px;
    }

    #content {
        margin-left: 0 !important;
    }
    body.sidebar-minimized #content {
        margin-left: 0 !important;
    }

    .sidebar-mobile-toggle {
        display: block;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 999;
        background: #003366;
        color: #BBE0EF;
        border: none;
        width: 44px;
        height: 44px;
        border-radius: 8px;
        font-size: 1.5rem;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    }
    .sidebar-mobile-toggle:hover { color: #fff; background: #004080; }
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: 998;
    }
    .sidebar-overlay.active {
        display: block;
    }
}

@media (min-width: 769px) {
    .sidebar-mobile-toggle,
    .sidebar-overlay { display: none !important; }
}