/* Sidebar Layout */
#sidebar {
    width: 64px;
    flex-shrink: 0;
    background: #0c1a0c;
    border-right: 1px solid rgba(255, 255, 255, 0.07);
    transition: width 0.3s ease;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding-top: 0.5rem;
}

#sidebar.expanded {
    width: 220px;
}

/* Custom scrollbar */
#sidebar::-webkit-scrollbar {
    width: 4px;
}

#sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.03);
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* Toggle button */
#sidebar-toggle {
    width: 100%;
    padding: 0.75rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background: none;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    cursor: pointer;
    font-size: 1.1rem;
    color: rgba(240, 237, 231, 0.65);
    margin-bottom: 0.5rem;
    transition: all 0.2s;
}

#sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--dark-text);
}

#sidebar.expanded #sidebar-toggle {
    justify-content: flex-end;
    padding-right: 1rem;
}

/* Navigation links */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0 0.5rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.65rem 0.5rem 0.65rem calc(0.5rem - 2px);
    border-radius: 6px;
    color: rgba(240, 237, 231, 0.65);
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.2s;
    border-left: 2px solid transparent;
}

#sidebar.expanded .sidebar-nav a {
    justify-content: flex-start;
    padding: 0.65rem 0.75rem 0.65rem calc(0.75rem - 2px);
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--dark-text);
    border-left-color: var(--at-40);
}

.sidebar-nav a.active {
    background: var(--at-10);
    color: var(--primary);
    font-weight: 600;
    border-left-color: var(--primary);
}

.sidebar-nav .icon {
    position: relative;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Crown badge for pro-locked items (collapsed state only) */
.crown-badge {
    position: absolute;
    top: -5px;
    right: -6px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.crown-badge svg {
    width: 8px;
    height: 8px;
}

#sidebar.expanded .crown-badge {
    display: none;
}

.sidebar-nav a.active .icon {
    filter: drop-shadow(0 0 4px var(--at-50));
}

.sidebar-nav .label {
    opacity: 0;
    visibility: hidden;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    font-size: 0.85rem;
    transition: opacity 0.15s ease-out, visibility 0s linear 0.15s, max-width 0s linear 0.15s;
}

#sidebar.expanded .sidebar-nav .label {
    opacity: 1;
    visibility: visible;
    max-width: 160px;
    transition: opacity 0.2s ease-out 0.1s, visibility 0s linear 0s, max-width 0s linear 0s;
}

.sidebar-nav-locked {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.65rem 0.5rem 0.65rem calc(0.5rem - 2px);
    border-radius: 6px;
    color: rgba(240, 237, 231, 0.4);
    cursor: not-allowed;
    white-space: nowrap;
    font-size: 0.85rem;
    border-left: 2px solid transparent;
}

#sidebar.expanded .sidebar-nav-locked {
    justify-content: flex-start;
    padding: 0.65rem 0.75rem 0.65rem calc(0.75rem - 2px);
}

.sidebar-nav-locked .icon {
    position: relative;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0.5;
}

.sidebar-nav-locked .label {
    opacity: 0;
    visibility: hidden;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.15s ease-out, visibility 0s linear 0.15s, max-width 0s linear 0.15s;
}

#sidebar.expanded .sidebar-nav-locked .label {
    opacity: 1;
    visibility: visible;
    max-width: 160px;
    transition: opacity 0.2s ease-out 0.1s, visibility 0s linear 0s, max-width 0s linear 0s;
}

.badge-upgrade {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--bg-body);
    background: var(--primary);
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 4px;
}

/* Reports section divider */
.sidebar-nav > div[style*="border-top"] {
    border-top-color: rgba(255, 255, 255, 0.07) !important;
}

.sidebar-divider {
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    margin: 0.75rem 0;
    padding-top: 0.75rem;
}

/* SVG icon sizing inside sidebar */
.sidebar-nav .icon .icon-svg,
.sidebar-nav .icon .brand-icon,
.sidebar-nav-locked .icon .icon-svg,
.sidebar-reports-btn .icon .icon-svg,
.report-link .icon .icon-svg {
    width: 20px;
    height: 20px;
    display: block;
}

/* Sidebar footer with stats */
.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    margin-top: auto;
    font-size: 0.75rem;
    color: rgba(240, 237, 231, 0.65);
    display: none;
}

#sidebar.expanded .sidebar-footer {
    display: block;
}

.stat-item {
    padding: 0.5rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    opacity: 0.7;
    color: rgba(240, 237, 231, 0.4);
}

.stat-value {
    font-weight: 600;
    color: var(--primary);
}

.stat-of {
    font-weight: 400;
    color: var(--at-50);
    font-size: 0.8em;
}

/* Locked reports button */
.sidebar-reports-btn--locked {
    color: rgba(168, 180, 165, 0.6) !important;
    cursor: not-allowed;
    opacity: 0.6;
    pointer-events: none;
}

/* Reports Menu */
.sidebar-reports-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.65rem 0.5rem 0.65rem calc(0.5rem - 2px);
    border: none;
    background: none;
    border-radius: 6px;
    color: rgba(240, 237, 231, 0.65);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    position: relative;
    border-left: 2px solid transparent;
}

#sidebar.expanded .sidebar-reports-btn {
    justify-content: flex-start;
    padding: 0.65rem 0.75rem 0.65rem calc(0.75rem - 2px);
}

.sidebar-reports-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--dark-text);
    border-left-color: var(--at-40);
}

.sidebar-reports-btn .icon {
    position: relative;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-reports-btn .label {
    opacity: 0;
    visibility: hidden;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    font-size: 0.85rem;
    transition: opacity 0.15s ease-out, visibility 0s linear 0.15s, max-width 0s linear 0.15s;
}

#sidebar.expanded .sidebar-reports-btn .label {
    opacity: 1;
    visibility: visible;
    max-width: 160px;
    transition: opacity 0.2s ease-out 0.1s, visibility 0s linear 0s, max-width 0s linear 0s;
}

.sidebar-reports-btn .toggle-arrow {
    font-size: 0.7rem;
    margin-left: auto;
    transition: transform 0.2s;
    display: none;
    color: rgba(240, 237, 231, 0.4);
}

#sidebar.expanded .sidebar-reports-btn .toggle-arrow {
    display: inline;
}

.sidebar-reports-btn.expanded .toggle-arrow {
    transform: rotate(180deg);
}

.reports-menu {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s ease;
}

.sidebar-reports-btn.expanded + .reports-menu {
    grid-template-rows: 1fr;
}

.reports-menu-inner {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 0;
}

.report-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 0.5rem;
    border-radius: 6px;
    color: rgba(240, 237, 231, 0.65);
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.2s;
    font-size: 0.85rem;
    border-left: 2px solid transparent;
}

#sidebar.expanded .report-link {
    justify-content: flex-start;
    padding: 0.6rem 0.75rem;
}

.report-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--dark-text);
    border-left-color: var(--at-40);
}

.report-link.active {
    background: var(--at-10);
    color: var(--primary);
    border-left-color: var(--primary);
}

.report-link .icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.report-link .label {
    opacity: 0;
    visibility: hidden;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.15s ease-out, visibility 0s linear 0.15s, max-width 0s linear 0s;
}

#sidebar.expanded .report-link .label {
    opacity: 1;
    visibility: visible;
    max-width: 160px;
    transition: opacity 0.2s ease-out 0.1s, visibility 0s linear 0s, max-width 0s linear 0s;
}

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px !important;
        z-index: 400;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        padding-bottom: 2rem;
    }

    body.mobile-nav-open #sidebar {
        transform: translateX(0);
    }

    /* Backdrop overlay */
    body.mobile-nav-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        z-index: 399;
        pointer-events: auto;
    }

    /* Desktop toggle button hidden on mobile */
    #sidebar-toggle {
        display: none;
    }

    /* Mobile sidebar always shows labels */
    #sidebar.expanded {
        width: 280px;
    }

    .sidebar-nav .label {
        opacity: 1;
        visibility: visible;
        max-width: 160px;
    }

    .sidebar-nav-locked .label {
        opacity: 1;
        visibility: visible;
        max-width: 160px;
    }

    .sidebar-reports-btn .label {
        opacity: 1;
        visibility: visible;
        max-width: 160px;
    }

    .report-link .label {
        opacity: 1;
        visibility: visible;
        max-width: 160px;
    }
}

/* Mobile sidebar close button */
.sidebar-mobile-close {
    display: none;
    width: 100%;
    padding: 0.75rem;
    background: none;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    color: rgba(240, 237, 231, 0.65);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    justify-content: flex-end;
    padding-right: 1rem;
}

.sidebar-mobile-close:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--dark-text);
}

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

@media (min-width: 769px) {
    .sidebar-mobile-close {
        display: none !important;
    }
}

/* On desktop: hide sidebar completely, show navbar nav instead */
@media (min-width: 769px) {
    #sidebar {
        display: none !important;
    }

    body.mobile-nav-open::after {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    #sidebar,
    .sidebar-nav a,
    .sidebar-reports-btn,
    .report-link,
    .reports-menu,
    .sidebar-nav .label,
    .sidebar-reports-btn .label,
    .report-link .label,
    #sidebar-toggle {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ============================================================
   Light Mode Overrides
   ============================================================ */

html:not(.dark-mode) #sidebar {
    background: var(--bg-section);
    border-right: 1px solid rgba(0, 0, 0, 0.07);
}

html:not(.dark-mode) #sidebar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.02);
}

html:not(.dark-mode) #sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}

html:not(.dark-mode) #sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.18);
}

html:not(.dark-mode) #sidebar-toggle {
    border-bottom: 1px solid rgba(0, 0, 0, 0.07);
    color: rgba(26, 26, 26, 0.45);
}

html:not(.dark-mode) #sidebar-toggle:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--dark-text);
}

html:not(.dark-mode) .sidebar-nav a {
    color: rgba(26, 26, 26, 0.55);
}

html:not(.dark-mode) .sidebar-nav a:hover {
    background: var(--at-08);
    color: var(--dark-text);
    border-left-color: var(--at-50);
}

html:not(.dark-mode) .sidebar-nav a.active {
    background: var(--at-12);
}

html:not(.dark-mode) .sidebar-nav a.active .icon {
    filter: drop-shadow(0 0 4px var(--at-60));
}

html:not(.dark-mode) .sidebar-nav-locked {
    color: rgba(26, 26, 26, 0.3);
}

html:not(.dark-mode) .sidebar-divider {
    border-top-color: rgba(0, 0, 0, 0.07);
}

html:not(.dark-mode) .sidebar-nav > div[style*="border-top"] {
    border-top-color: rgba(0, 0, 0, 0.07) !important;
}

html:not(.dark-mode) .sidebar-footer {
    border-top-color: rgba(0, 0, 0, 0.07);
    color: rgba(26, 26, 26, 0.5);
}

html:not(.dark-mode) .stat-label {
    color: rgba(26, 26, 26, 0.35);
}

html:not(.dark-mode) .stat-of {
    color: var(--at-65);
}

html:not(.dark-mode) .badge-upgrade {
    color: #ffffff;
}

html:not(.dark-mode) .sidebar-reports-btn {
    color: rgba(26, 26, 26, 0.55);
}

html:not(.dark-mode) .sidebar-reports-btn:hover {
    background: var(--at-08);
    color: var(--dark-text);
    border-left-color: var(--at-50);
}

html:not(.dark-mode) .sidebar-reports-btn .toggle-arrow {
    color: rgba(26, 26, 26, 0.3);
}

html:not(.dark-mode) .report-link {
    color: rgba(26, 26, 26, 0.55);
}

html:not(.dark-mode) .report-link:hover {
    background: var(--at-08);
    color: var(--dark-text);
    border-left-color: var(--at-50);
}

html:not(.dark-mode) .report-link.active {
    background: var(--at-12);
}
