/* 
------------------------------- Sidebar styles ------------------------------- 
*/
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--bg-secondary);
    border-right: none;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    padding: var(--spacing-lg) 20px;
    transition: width var(--transition-medium), transform var(--transition-medium), padding var(--transition-medium);
    overflow-x: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    padding: var(--spacing-lg) 10px;
}

/* Force expanded state if html has the class (prevents FOUC) */
html.sidebar-expanded .sidebar.collapsed {
    width: var(--sidebar-width) !important;
    padding: var(--spacing-lg) 20px !important;
}

html.sidebar-expanded .sidebar.collapsed .sidebar-logo {
    opacity: 1 !important;
    pointer-events: auto !important;
}

html.sidebar-expanded .sidebar.collapsed .sidebar-brand {
    display: block !important;
}

html.sidebar-expanded .sidebar.collapsed .nav-link {
    justify-content: flex-start !important;
    padding: 12px 4px !important;
}

html.sidebar-expanded .sidebar.collapsed .nav-link span {
    display: block !important;
}

html.sidebar-expanded .sidebar.collapsed .nav-link i {
    margin-right: var(--spacing-sm) !important;
}

/* Correction for theme switch in expanded mode override */
html.sidebar-expanded .sidebar.collapsed .theme-switch {
    width: 48px !important;
    margin: 0 !important;
}

html.sidebar-expanded .sidebar.collapsed .slider:before {
    width: 16px !important;
    height: 16px !important;
    font-size: 10px !important;
    left: 3px !important;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
}

.sidebar-logo {
    height: 40px;
    width: auto;
    display: block;
    transition: opacity var(--transition-medium), transform var(--transition-medium);
}

.sidebar.collapsed .sidebar-logo {
    opacity: 0;
    pointer-events: none;
}

.sidebar.collapsed .sidebar-brand {
    display: none;
}

.burger-menu {
    display: block;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: var(--spacing-sm);
    transition: color var(--transition-fast);
}

.sidebar.collapsed .burger-menu {
    margin: 0 auto;
}

.burger-menu:hover {
    color: var(--accent-primary);
}

.sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.nav-links {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.nav-bottom {
    margin-top: auto !important;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 4px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-fast);
    font-weight: 500;
    white-space: nowrap;
}

.nav-link i {
    width: 24px;
    min-width: 24px;
    margin-right: var(--spacing-sm);
    text-align: center;
    font-size: var(--font-size-sm);
}

.nav-link span {
    font-size: var(--font-size-sm);
}

.nav-link:hover,
.nav-link.active {
    background-color: var(--bg-tertiary);
    color: var(--accent-primary);
    box-shadow: inset 0 0 0 1px var(--border-color);
    /* Subtle inner border on hover */
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px;
}

.sidebar.collapsed .nav-link span {
    display: none;
}

.sidebar.collapsed .nav-link i {
    margin-right: 0;
}

.sidebar.collapsed .nav-link:hover,
.sidebar.collapsed .nav-link.active {
    transform: none;
}

/* Mobile Backdrop Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition-medium);
    pointer-events: none;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

.mobile-toggle {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1100;
    background-color: var(--accent-primary);
    border: none;
    border-radius: 50%;
    color: white;
    width: 56px;
    height: 56px;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(var(--accent-primary-rgb), 0.4);
    transition: all var(--transition-fast);
}

.mobile-toggle:hover {
    background-color: var(--accent-primary);
    color: white;
}

@media (max-width: 992px) {
    .sidebar {
        width: auto;
        min-width: 220px;
        height: auto;
        max-height: calc(100vh - 120px);
        display: flex;
        flex-direction: column;
        top: auto;
        left: auto;
        bottom: 90px;
        right: 24px;
        border-radius: var(--border-radius-lg);
        transform: scale(0.95) translateY(10px);
        transform-origin: bottom right;
        opacity: 0;
        pointer-events: none;
        background-color: var(--bg-secondary);
        box-shadow: var(--shadow-elevated);
        z-index: 1101;
        padding: var(--spacing-sm);
        border: 1px solid var(--border-color);
        transition: opacity var(--transition-fast), transform var(--transition-fast);
    }

    .sidebar.active {
        transform: scale(1) translateY(0);
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-header {
        display: none;
    }

    .sidebar-content {
        overflow-y: auto;
        max-height: 100%;
    }

    .nav-links {
        gap: 4px;
    }

    .mobile-toggle {
        display: flex;
    }

    .theme-switch-wrapper {
        padding-left: 16px;
        margin-top: 24px;
        padding-top: 24px;
    }
}

/* 
------------------------------- Theme Toggle Switch -------------------------------
*/
.theme-switch-wrapper {
    display: flex;
    align-items: center;
    margin-top: 24px;
    padding: 12px 4px;
    color: var(--text-secondary);
}

.theme-switch {
    display: inline-block;
    height: 24px;
    position: relative;
    width: 44px;
    margin: 0;
}

.theme-switch input {
    display: none;
}

.slider {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    background-color: var(--text-secondary);
    bottom: 3px;
    content: "\f185";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--bg-primary);
    height: 16px;
    left: 6px;
    position: absolute;
    transition: transform .3s ease;
    width: 16px;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
}

input:checked+.slider:before {
    transform: translateX(16px);
    background-color: var(--bg-secondary);
    content: "\f186";
    color: var(--accent-primary);
}

.theme-icon {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
    margin-right: var(--spacing-sm);
    color: var(--text-secondary);
}

.sidebar.collapsed .theme-switch-wrapper {
    justify-content: center;
    padding: 12px;
}

.sidebar.collapsed .theme-switch {
    margin: 0 auto;
    width: 36px;
    height: 20px;
}

.sidebar.collapsed .slider:before {
    height: 12px;
    width: 12px;
    bottom: 3px;
    left: 3px;
    font-size: 6px;
}

.sidebar.collapsed .theme-switch input:checked+.slider:before {
    transform: translateX(6px) !important;
}

.sidebar.collapsed .theme-switch-wrapper span {
    display: none;
}

.sidebar.collapsed .theme-icon {
    display: none;
}