.admin-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.admin-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(to right, var(--bs-white), var(--bs-primary));
    color: var(--bs-body-color);
    display: flex;
    align-items: center;
    padding: 0 1rem 0 0; /* Remove left padding to let brand area touch edge */
    z-index: 1050;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.admin-header.sidebar-minimized {
    left: 0;
}

.admin-header h4 {
    color: var(--bs-body-color);
}

/* Header Brand Wrapper */
.header-brand-wrapper {
    display: flex;
    align-items: center;
    width: 300px; /* Matches expanded sidebar width */
    height: 100%;
    transition: width 0.3s ease-in-out;
    flex-shrink: 0;
    background-color: transparent;
}

/* Header Logo */
.header-logo {
    flex: 1;
    height: 100%;
    background-color: transparent;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 0.5rem;
    overflow: hidden;
}

.header-logo img {
    max-width: 100%;
    height: auto;
    max-height: 50px;
}

.admin-header.sidebar-minimized .header-logo {
    display: none; /* Hide logo when minimized */
}

/* Header Toggle */
.admin-header .sidebar-toggle {
    font-size: 1.5rem;
    color: var(--bs-secondary);
    padding: 0.5rem;
    margin: 0; /* Reset margin */
    width: 50px; /* Fixed width for toggle */
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    border-radius: 0; /* Remove border radius if any */
    text-decoration: none;
    border: none;
}

/* Icon Animation */
.admin-header .sidebar-toggle i {
    transition: transform 0.3s ease-in-out;
}

.admin-header:not(.sidebar-minimized) .sidebar-toggle i {
    transform: rotate(180deg);
}

.header-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-left: 1rem; /* Add padding back to content */
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Sidebar */
.admin-sidebar {
    position: fixed;
    top: 60px; /* Starts below header */
    left: 0;
    bottom: 60px; /* Ends above footer */
    width: 300px;
    background: linear-gradient(to bottom, var(--bs-gray-100), var(--bs-gray-200));
    color: var(--bs-body-color);
    border-right: 1px solid var(--bs-border-color);
    transition: width 0.3s ease-in-out;
    z-index: 1040;
    overflow: visible;
    display: flex;
    flex-direction: column;
}

.admin-sidebar.minimized {
    width: 70px;
    overflow: hidden;
}

.sidebar-nav {
    padding: 1rem 0;
    flex: 1;
}

.sidebar-nav > .nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav .nav-item {
    position: relative;
}

.sidebar-nav .nav-link {
    color: var(--bs-gray-700);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    height: 48px; /* Fixed height for consistent alignment */
}

.sidebar-nav .nav-link:hover {
    color: var(--bs-primary);
    background-color: var(--bs-gray-200);
}

.sidebar-nav .nav-link.active {
    color: var(--bs-primary) !important;
    background-color: var(--bs-gray-200) !important;
    font-weight: bold;
}

/* Active state styling with higher specificity using theme variables */
.sidebar-nav .nav-item.active > .nav-link {
    color: var(--bs-primary) !important;
    background-color: var(--bs-gray-200) !important;
    font-weight: bold !important;
}

/* Ensure submenu active items also use the active styling */
.sidebar-nav .submenu .nav-item.active > .nav-link {
    color: var(--bs-primary) !important;
    background-color: var(--bs-gray-200) !important;
    font-weight: bold !important;
}

/* Keep icon color consistent when active */
.sidebar-nav .nav-item.active > .nav-link i,
.sidebar-nav .submenu .nav-item.active > .nav-link i {
    color: var(--bs-primary) !important;
}

.sidebar-nav .nav-link i {
    font-size: 1.25rem;
    width: 1.5rem;
    min-width: 1.5rem;
    flex-shrink: 0;
    text-align: center;
    display: flex; /* Use flex to center icon */
    align-items: center;
    justify-content: center;
    height: 100%; /* Fill height of parent */
}

.nav-text {
    flex: 1;
    transition: opacity 0.2s;
}

.submenu-indicator {
    margin-left: auto;
    font-size: 0.875rem;
    transition: transform 0.2s;
    width: 1rem;
}

.nav-item.submenu-open > .nav-link .submenu-indicator {
    transform: rotate(180deg);
}

/* Submenu - Default (Expanded Sidebar) */
.submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    background-color: rgba(0, 0, 0, 0.03);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
    
    /* Vertical Line Style */
    margin-left: 2.25rem;
    border-left: 1px solid var(--bs-border-color);
}

.nav-item.submenu-open > .submenu {
    max-height: 1500px; /* Increased to support nested submenus */
}

/* Nested Submenu Styling */
.submenu .submenu {
    margin-left: 1.75rem; /* Slightly less indentation for deeper levels */
}

.submenu .nav-link {
    padding-left: 1rem;
    font-size: 0.9rem;
    height: 40px; /* Slightly smaller height for submenus */
}

.submenu .nav-link i {
    font-size: 1rem;
}

/* Minimized Sidebar Styles */
.admin-sidebar.minimized .nav-link {
    padding: 0 !important;
    justify-content: center !important;
    gap: 0 !important;
    width: 70px; /* Ensure fixed width when minimized */
}

.admin-sidebar.minimized .nav-link i {
    margin: 0;
    width: 1.5rem !important; /* Fixed width for icon */
}

.admin-sidebar.minimized .nav-text {
    display: none !important;
}

.admin-sidebar.minimized .submenu-indicator {
    display: none !important;
}

/* Main Content */
.admin-main {
    margin-top: 60px;
    margin-left: 300px;
    transition: margin-left 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 60px);
    background-color: var(--bs-body-bg);
    padding-bottom: 60px; /* Add padding for fixed footer */
}

.admin-main.sidebar-minimized {
    margin-left: 70px;
}

.content-wrapper {
    flex: 1;
    padding: 2rem;
}

/* Footer */
.admin-footer {
    background: linear-gradient(to right, var(--bs-primary), var(--bs-white));
    border-top: 1px solid var(--bs-border-color);
    height: 60px;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: auto;
    /* Footer positioning relative to main content */
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0; /* Full width */
    transition: left 0.3s ease-in-out;
    z-index: 1050; /* Increased z-index to be above sidebar */
}

.admin-footer.sidebar-minimized {
    left: 0;
}

.footer-content {
    text-align: center;
    color: var(--bs-body-color);
    font-size: 0.875rem;
    width: 100%;
}

/* Responsive */
@media (max-width: 768px) {
    .admin-header {
        left: 0;
    }

    .admin-sidebar {
        transform: translateX(-300px);
    }

    .admin-sidebar.minimized {
        transform: translateX(-300px);
    }

    .admin-sidebar:not(.minimized).mobile-open {
        transform: translateX(0);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    }

    .admin-main {
        margin-left: 0;
    }
    
    .admin-main.sidebar-minimized {
        margin-left: 0;
    }
    
    .admin-footer {
        left: 0;
    }
    
    .admin-footer.sidebar-minimized {
        left: 0;
    }
}