/* Sidebar Styles */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --sidebar-bg: rgba(255, 255, 255, 0.8);
    --sidebar-border: 1px solid rgba(255, 255, 255, 0.5);
    --sidebar-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Main Layout */
.layout-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: var(--sidebar-border);
    display: flex;
    flex-direction: column;
    padding: 20px;
    transition: var(--sidebar-transition);
    z-index: 1000;
    box-shadow: 5px 0 30px rgba(0, 0, 0, 0.05);
}

.sidebar.hidden {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

@media (min-width: 769px) {

    /* Collapsed State */
    .sidebar.collapsed {
        width: var(--sidebar-collapsed-width);
        padding: 20px 10px;
    }
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 20px;
    transition: var(--sidebar-transition);
    width: calc(100% - var(--sidebar-width));
}

@media (min-width: 769px) {
    .sidebar.collapsed~.main-content {
        margin-left: var(--sidebar-collapsed-width);
        width: calc(100% - var(--sidebar-collapsed-width));
    }
}

.sidebar.hidden~.main-content {
    margin-left: 0;
    width: 100%;
}

/* Sidebar Elements */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 30px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--primary-color);
    font-family: var(--font-heading);
    opacity: 1;
    transition: opacity 0.2s;
}

@media (min-width: 769px) {
    .sidebar.collapsed .sidebar-logo span {
        display: none;
    }

    .sidebar.collapsed .sidebar-logo {
        justify-content: center;
        width: 100%;
    }
}

.sidebar-user {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.sidebar-user-avatar {
    width: 80px;
    height: 80px;
    font-size: 3rem;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    transition: all 0.3s;
}

@media (min-width: 769px) {
    .sidebar.collapsed .sidebar-user-avatar {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
    }
}

.sidebar-user-name {
    font-weight: bold;
    font-size: 1.1rem;
    transition: opacity 0.2s;
}

@media (min-width: 769px) {
    .sidebar.collapsed .sidebar-user-name {
        display: none;
    }
}

/* Navigation */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    border-radius: 12px;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
    white-space: nowrap;
    border: none;
    background: transparent;
    font-size: 1rem;
    font-family: var(--font-body);
    width: 100%;
    text-align: left;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.6);
    color: var(--primary-color);
    transform: translateX(5px);
}

@media (min-width: 769px) {
    .sidebar.collapsed .nav-item:hover {
        transform: none;
        /* No shift in collapsed */
        background: rgba(255, 255, 255, 0.8);
    }
}

.nav-item.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 10px rgba(108, 92, 231, 0.3);
}

.nav-icon {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

@media (min-width: 769px) {
    .sidebar.collapsed .nav-item span:not(.nav-icon) {
        display: none;
    }

    .sidebar.collapsed .nav-item {
        justify-content: center;
        padding: 12px 0;
    }
}

/* Footer Actions */
/* Footer Content within Nav */
@media (min-width: 769px) {

    .sidebar.collapsed #theme-container-sidebar,
    .sidebar.collapsed .theme-switcher,
    .sidebar.collapsed .sidebar-footer-content {
        display: none !important;
    }
}

/* Ensure bottom spacing in nav for mobile URL bar */
@media (max-width: 768px) {
    .sidebar-nav {
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }
}

/* Ensure sidebar nav scrolls above the fixed footer if needed */
.sidebar-nav {
    margin-bottom: 10px;
}

/* Collapse Toggle */
#sidebar-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-muted);
    padding: 5px;
    border-radius: 5px;
}

#sidebar-toggle:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Responsive Overlay Mode */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 10px !important;
    }

    .sidebar {
        transform: translateX(-100%);
        /* Hidden by default mobile */
    }

    .sidebar.mobile-visible {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.2);
    }

    /* Overlay backdrop */
    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
        backdrop-filter: blur(2px);
    }

    .mobile-overlay.visible {
        display: block;
    }

    /* Mobile Header Helper to open sidebar */
    #mobile-header-btn {
        display: block !important;
        /* Force show */
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 500;
        background: white;
        border-radius: 50%;
        width: 40px;
        height: 40px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        cursor: pointer;
    }
}

/* Desktop: Hide mobile trigger */
@media (min-width: 769px) {
    #mobile-header-btn {
        display: none;
    }

    .mobile-overlay {
        display: none !important;
    }
}