/* ==================== SIDEBAR ==================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-hairline);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width 0.2s ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 20px;
    border-bottom: 1px solid var(--border-hairline);
    min-height: 32px;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    min-width: 0;
}

.sidebar-logo .logo-image {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex-shrink: 0;
}

.sidebar-logo .logo-text {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.sidebar-collapse-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: var(--border-radius-xs);
    flex-shrink: 0;
    transition: var(--transition-fast);
}

.sidebar-collapse-btn:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

/* ==================== NAV ==================== */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item,
.nav-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 10px;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.87rem;
    font-weight: 500;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: var(--transition-fast);
    white-space: nowrap;
}

.nav-item:hover,
.nav-group-header:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.nav-item.active,
.nav-subitem.active {
    background: linear-gradient(135deg, rgba(139, 108, 247, 0.22), rgba(79, 140, 255, 0.14));
    color: var(--text-primary);
    box-shadow: inset 0 0 0 1px rgba(139, 108, 247, 0.3);
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: inherit;
}

.nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-chevron {
    flex-shrink: 0;
    color: var(--text-faint);
    transition: transform 0.2s ease;
}

.nav-group.open > .nav-group-header .nav-chevron {
    transform: rotate(180deg);
}

.nav-group-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 0 0 40px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease;
}

.nav-group.open .nav-group-body {
    max-height: 240px;
    padding: 2px 0 6px 40px;
}

.nav-subitem {
    display: block;
    padding: 5px 10px;
    border-radius: var(--border-radius-xs);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.83rem;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.nav-subitem:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

/* ==================== FOOTER ==================== */
.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--border-hairline);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--border-radius-sm);
}

.user-avatar-fallback {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-logout {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
}

.user-logout:hover {
    color: var(--error-color);
}

.sidebar-login {
    justify-content: flex-start;
}

/* ==================== COMPACT STATE (default on desktop) ====================
   The sidebar is icon-only by default. Hovering it temporarily expands it as
   an overlay (main content doesn't reflow). Clicking the collapse button
   "pins" it open persistently (body.sidebar-pinned) until clicked again. */
@media (min-width: 901px) {
    .sidebar {
        width: var(--sidebar-width-collapsed);
    }

    .sidebar-header {
        justify-content: center;
        padding: 22px 12px;
    }

    .sidebar-collapse-btn {
        display: none;
    }

    .nav-item,
    .nav-group-header {
        justify-content: center;
        padding: 5px 10px;
    }

    .sidebar-user {
        justify-content: center;
    }

    .logo-text,
    .nav-label,
    .nav-chevron {
        display: none;
    }

    .nav-group-body,
    .user-meta {
        display: none;
    }

    /* Pinned (persisted) or actively hovered: full expanded sidebar */
    body.sidebar-pinned .sidebar,
    .sidebar:hover {
        width: var(--sidebar-width);
    }

    body.sidebar-pinned .sidebar-header,
    .sidebar:hover .sidebar-header {
        justify-content: space-between;
        padding: 22px 20px;
    }

    body.sidebar-pinned .sidebar-collapse-btn,
    .sidebar:hover .sidebar-collapse-btn {
        display: flex;
    }

    body.sidebar-pinned .nav-item,
    body.sidebar-pinned .nav-group-header,
    .sidebar:hover .nav-item,
    .sidebar:hover .nav-group-header {
        justify-content: flex-start;
        padding: 5px 10px;
    }

    body.sidebar-pinned .sidebar-user,
    .sidebar:hover .sidebar-user {
        justify-content: flex-start;
    }

    body.sidebar-pinned .logo-text,
    body.sidebar-pinned .nav-label,
    body.sidebar-pinned .nav-chevron,
    .sidebar:hover .logo-text,
    .sidebar:hover .nav-label,
    .sidebar:hover .nav-chevron {
        display: initial;
    }

    body.sidebar-pinned .nav-group-body,
    body.sidebar-pinned .user-meta,
    .sidebar:hover .nav-group-body,
    .sidebar:hover .user-meta {
        display: flex;
    }
}

/* ==================== MOBILE ==================== */
.mobile-sidebar-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1100;
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border-hairline);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
}

.mobile-sidebar-toggle span {
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-backdrop.visible {
    display: block;
}

@media (max-width: 900px) {
    .mobile-sidebar-toggle {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    }

    /* The compact/hover-expand behavior only applies above the mobile
       breakpoint (see the min-width: 901px block above) - on mobile the
       sidebar is always shown at full width via .mobile-open, using its
       normal (unhidden) styles, just with a slightly larger touch target. */
    .nav-item,
    .nav-group-header {
        padding: 10px 12px;
    }
}
