/* Sidebar Container */
.sidebar {
    position: fixed;
    left: 0;
    top: var(--workspace-header-offset);
    width: 240px;
    height: calc(100vh - var(--workspace-header-offset));
    background: var(--bg-sidebar);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    /* Inset edge preserves the existing sidebar and navigation widths. */
    box-shadow: inset -1px 0 0 var(--border-warm), 2px 0 8px rgba(59, 42, 58, 0.1);
}

/* Navigation Menu */
.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 4px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-main);
    transition: all 0.2s ease;
    cursor: pointer;
}

.nav-item:hover {
    background-color: color-mix(in srgb, var(--accent-soft) 30%, transparent);
    color: var(--text-main);
}

.nav-item.active {
    background-color: var(--accent-soft);
    color: var(--accent-text);
    font-weight: var(--font-weight-semibold);
}

.nav-icon {
    font-size: 18px;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
}

.nav-icon i {
    font-size: 16px;
    width: 16px;
    text-align: center;
}

.nav-label {
    min-width: 0;
    line-height: 1.3;
    font-size: var(--font-size-base);
    font-weight: 450;
    letter-spacing: -0.01em;
}

.nav-item.active .nav-label {
    font-weight: var(--font-weight-semibold);
}

button.nav-item {
    border: none;
    background: none;
    width: 100%;
    font-family: inherit;
    text-align: left;
}

/* User Footer */
.sidebar-status {
    padding: 16px 24px;
    border-top: 1px solid var(--border-warm);
    border-bottom: 1px solid var(--border-warm);
}

.status-item {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    font-size: 13px;
}

.status-item:last-child {
    margin-bottom: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 10px;
    flex-shrink: 0;
}

.status-dot.status-active {
    background-color: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.status-dot.status-paused {
    background-color: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

.status-label {
    flex: 1;
    color: var(--text-muted);
}

.status-count {
    font-weight: 600;
    color: var(--text-main);
    font-size: 14px;
}

/* User Footer */
.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-warm);
}

.sidebar-footer > .nav-item {
    margin-bottom: 16px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    color: var(--accent-text);
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    font-size: 14px;
    font-weight: var(--font-weight-normal);
    color: var(--text-main);
}

.logout-link {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-normal);
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
}

.logout-link:hover {
    color: var(--accent-text);
}

/* Scrollbar Styling */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--text-muted) 20%, transparent);
    border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--text-muted) 30%, transparent);
}


/* Menu button: only shown below 1024px, where the sidebar becomes a drawer */
.workspace-menu-toggle {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

@media (max-width: 1023px) {
    .workspace-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        width: 44px;
        height: 44px;
        margin: 0 8px 0 -10px;
        padding: 0;
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: var(--workspace-header-text);
        font-size: 20px;
        cursor: pointer;
    }

    .workspace-menu-toggle:hover {
        background: rgba(255, 255, 255, 0.1);
    }

    .workspace-menu-toggle:focus-visible {
        outline: 2px solid var(--workspace-header-text);
        outline-offset: 2px;
    }

    /* Hidden off-screen until opened; visibility keeps closed links out of the tab order */
    .sidebar {
        width: min(280px, 85vw);
        height: calc(100dvh - var(--workspace-header-offset));
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform 0.2s ease, visibility 0.2s ease;
    }

    /* Visible immediately on open so focus can move into the menu */
    body.sidebar-open .sidebar {
        transform: none;
        visibility: visible;
        transition: transform 0.2s ease, visibility 0s;
    }

    /* Links animate colour only, so they become focusable the moment the menu opens */
    .sidebar .nav-item {
        transition: background-color 0.2s ease, color 0.2s ease;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar-backdrop:not([hidden]) {
        display: block;
        position: fixed;
        top: var(--workspace-header-offset);
        right: 0;
        bottom: 0;
        left: 0;
        background: rgba(30, 22, 32, 0.4);
        z-index: 999;
    }
}

@media (max-width: 1023px) and (prefers-reduced-motion: reduce) {
    .sidebar {
        transition: none;
    }
}
