/**
 * Modern Menu System CSS
 * Version: 1.2.0 - Feather SVG icons with currentColor support
 * Mobile-First Design
 */

/* ============================================================================
   SIDEBAR BASE
   ============================================================================ */

.sidebar {
    position: fixed;
    top: var(--header-height, 60px);
    left: 0;
    width: var(--sidebar-width, 260px);
    height: calc(100vh - var(--header-height, 60px));
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    z-index: 999;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(-100%);
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

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

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Active state (visible) */
.sidebar.active {
    transform: translateX(0);
}

/* Collapsed state (only icons visible) */
.sidebar.collapsed {
    width: 64px;
}

.sidebar.collapsed .sidebar-text,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .sidebar-section-chevron,
.sidebar.collapsed .sidebar-badge {
    opacity: 0;
    pointer-events: none;
}

.sidebar.collapsed .sidebar-submenu {
    display: none !important;
}

/* Ensure section icons align with regular link icons when collapsed */
.sidebar.collapsed .sidebar-section-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.6rem;
    margin: 0.25rem;
    gap: 0;
    border: none;
    background: transparent;
    border-radius: 8px;
}

.sidebar.collapsed .sidebar-section-header:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.sidebar.collapsed .sidebar-section-header.active {
    background: transparent;
    color: var(--primary-color) !important;
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

/* Force icon color in collapsed active state */
.sidebar.collapsed .sidebar-section-header.active .sidebar-section-icon {
    color: var(--primary-color);
}

.sidebar.collapsed .sidebar-section-header.active .sidebar-section-icon svg {
    stroke: var(--primary-color);
}

.sidebar.collapsed .sidebar-link {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.6rem;
    margin: 0.25rem;
    gap: 0;
    border: none;
    border-radius: 8px;
}

.sidebar.collapsed .sidebar-link:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.sidebar.collapsed .sidebar-link.active {
    color: var(--primary-color);
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

/* Force icon color in collapsed active state */
.sidebar.collapsed .sidebar-link.active .sidebar-icon {
    color: var(--primary-color);
}

.sidebar.collapsed .sidebar-link.active .sidebar-icon svg,
.sidebar.collapsed .sidebar-link.active .sidebar-icon-img svg {
    stroke: var(--primary-color);
}

/* ============================================================================
   SIDEBAR HEADER
   ============================================================================ */

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: var(--bg-secondary);
    color: var(--primary-color);
}

.sidebar-toggle span[data-icon] {
    font-size: 18px;
}

/* ============================================================================
   SIDEBAR NAVIGATION
   ============================================================================ */

.sidebar-nav {
    padding: 0.5rem 0;
}

.sidebar-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* ============================================================================
   MENU ITEMS
   ============================================================================ */

.sidebar-item,
.sidebar-subitem {
    margin: 0 0.5rem 0.25rem 0.5rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 1rem;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid transparent; /* Consistent padding for all states */
    will-change: transform; /* Fix rendering artifacts */
    line-height: 1.5; /* Consistent line height */
    min-height: auto; /* No minimum height enforcement */
}

.sidebar-link:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: translateX(2px);
    border: 2px solid transparent; /* Maintain border on hover */
}

.sidebar-link.active {
    background: transparent;
    color: var(--primary-color);
    font-weight: 500;
    border: 2px solid var(--primary-color);
}

/* Ensure icon color in active state */
.sidebar-link.active .sidebar-icon {
    color: var(--primary-color);
}

.sidebar-link.active .sidebar-icon svg,
.sidebar-link.active .sidebar-icon-img svg {
    stroke: var(--primary-color);
}

.sidebar-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    font-size: 24px;
    color: currentColor; /* Inherit from parent (.sidebar-link) */
}

.sidebar-icon svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
}

.sidebar-icon .mdi {
    font-size: 24px;
    width: 24px;
    height: 24px;
    line-height: 24px;
}

.sidebar-icon [data-icon] {
    color: currentColor;
}

/* Legacy image icon support (for backward compatibility) */
.sidebar-icon-img {
    padding: 0;
    color: inherit; /* Inherit color from parent for currentColor in SVGs */
}

.sidebar-icon-img img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    display: block;
}

/* Ensure SVG icons use currentColor */
.sidebar-icon-img svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
}

.sidebar-icon-img .mdi {
    font-size: 24px;
    width: 24px;
    height: 24px;
    line-height: 24px;
}

.sidebar-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.95rem;
    font-weight: normal;
    line-height: 1.5;
    transition: opacity 0.3s;
}

.sidebar-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--primary-color);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 10px;
    transition: opacity 0.3s;
}

.sidebar-link.active .sidebar-badge {
    background: var(--primary-color);
    color: white;
}

/* ============================================================================
   SECTIONS (Collapsible Groups)
   ============================================================================ */

.sidebar-section {
    margin: 0 0.5rem 0.25rem 0.5rem;
}

/* Nested sections (Sections within sections) */
.sidebar-section-nested {
    margin-left: 0;
}

.sidebar-section-nested .sidebar-section-header {
    padding-left: 2rem;
}

.sidebar-section-depth-2 .sidebar-section-header {
    padding-left: 3rem;
}

.sidebar-section-depth-3 .sidebar-section-header {
    padding-left: 4rem;
}

.sidebar-section-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 1rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    user-select: none;
    border: 2px solid transparent;
    background: transparent;
    color: var(--text-secondary); /* Same as .sidebar-link */
    will-change: transform; /* Fix rendering artifacts */
    line-height: 1.5; /* Same as .sidebar-link */
    min-height: auto; /* Same as .sidebar-link */
}

.sidebar-section-header:hover {
    background: var(--bg-secondary);
    color: var(--text-primary); /* Same as .sidebar-link:hover */
    transform: translateX(2px);
    border: 2px solid transparent; /* Maintain border on hover */
}

.sidebar-section-header.active {
    background: transparent;
    color: var(--primary-color);
    font-weight: 500;
    border: 2px solid var(--primary-color);
}

/* Ensure icon color in active state */
.sidebar-section-header.active .sidebar-section-icon {
    color: var(--primary-color);
}

.sidebar-section-header.active .sidebar-section-icon svg {
    stroke: var(--primary-color);
}

.sidebar-section-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    font-size: 24px; /* Same as .sidebar-icon */
    color: currentColor; /* Inherit from parent (.sidebar-section-header) */
}

.sidebar-section-icon svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
}

.sidebar-section-icon .mdi {
    font-size: 24px;
    width: 24px;
    height: 24px;
    line-height: 24px;
}

.sidebar-section-icon [data-icon] {
    color: currentColor;
}

.sidebar-section-title {
    flex: 1;
    font-size: 0.95rem; /* Same as .sidebar-text */
    font-weight: normal; /* Same as .sidebar-text */
    text-transform: none; /* Same as .sidebar-text */
    letter-spacing: normal; /* Same as .sidebar-text */
    line-height: 1.5; /* Same as .sidebar-text */
    color: currentColor; /* Inherit from parent (.sidebar-section-header) */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.3s;
}

.sidebar-section-chevron {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.4rem;
    height: 1.4rem;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.3s ease, background 0.2s ease, opacity 0.3s;
    font-size: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    padding: 0.2rem;
    cursor: pointer;
    margin-left: 0.5rem;
}

.sidebar-section-chevron:hover {
    background: var(--bg-tertiary);
}

/* Rotate chevron when section is expanded */
.sidebar-section-header.expanded .sidebar-section-chevron {
    transform: rotate(180deg);
}

/* Hide chevron when sidebar is collapsed */
.sidebar.collapsed .sidebar-section-chevron {
    display: none;
}

/* ============================================================================
   SUBMENU
   ============================================================================ */

.sidebar-submenu {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-submenu.expanded {
    max-height: 1000px;
}

.sidebar-subitem {
    margin: 0 0 0.25rem 0;
}

.sidebar-subitem .sidebar-link {
    padding-left: 2.75rem;
    padding-right: 1rem;
    font-size: 0.9rem;
    margin-right: 0.5rem; /* Prevent border from being cut off on hover */
}

.sidebar-subitem .sidebar-link:hover {
    transform: translateX(2px);
    margin-right: 0.5rem; /* Keep consistent margin to prevent cutoff */
}

/* ============================================================================
   MOBILE RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
    .sidebar {
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        transform: translateX(0); /* Always visible on mobile! */
    }
    
    /* Collapsed sidebar on mobile: show icons only (64px) */
    .sidebar.collapsed {
        width: 64px;
    }
    
    /* Expanded sidebar on mobile: full width (280px) */
    .sidebar:not(.collapsed) {
        width: 280px;
    }
    
    /* NO OVERLAY on mobile - sidebar is part of layout, not an overlay */
    .sidebar::before {
        display: none !important;
    }
}

/* ============================================================================
   DESKTOP (Tablet and up)
   ============================================================================ */

@media (min-width: 769px) {
    .sidebar {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        width: 64px;
    }
}

/* ============================================================================
   LARGE SCREENS
   ============================================================================ */

@media (min-width: 1200px) {
    .sidebar {
        width: 280px;
    }
    
    .sidebar-link {
        padding: 0.5rem 1.25rem;
        border: 2px solid transparent; /* Ensure border consistency on large screens */
    }
    
    .sidebar-link.active {
        border: 2px solid var(--primary-color); /* Ensure active border on large screens */
    }
    
    .sidebar-section-header {
        padding: 0.5rem 1.25rem;
        border: 2px solid transparent; /* Ensure border consistency on large screens */
    }
    
    .sidebar-section-header.active {
        border: 2px solid var(--primary-color); /* Ensure active border on large screens */
    }
}

/* ============================================================================
   MAIN CONTENT ADJUSTMENTS
   ============================================================================ */

/* Adjust main content when sidebar is active (desktop) */
@media (min-width: 769px) {
    .sidebar.active ~ .main,
    .sidebar:not(.collapsed) ~ .main {
        margin-left: var(--sidebar-width, 260px);
        width: calc(100% - var(--sidebar-width, 260px));
        transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* Adjust when collapsed */
    .sidebar.collapsed ~ .main {
        margin-left: 64px;
        width: calc(100% - 64px);
    }
}

/* Mobile: Adjust content for sidebar */
@media (max-width: 768px) {
    /* When sidebar is collapsed: give space for icon-only sidebar */
    .sidebar.collapsed ~ .main {
        margin-left: 64px;
        width: calc(100% - 64px);
        transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* When sidebar is expanded: full width (sidebar is overlay) */
    .sidebar.active:not(.collapsed) ~ .main {
        margin-left: 0;
        width: 100%;
    }
    
    /* Default: show collapsed sidebar */
    .sidebar:not(.active) ~ .main {
        margin-left: 64px;
        width: calc(100% - 64px);
    }
}

/* ============================================================================
   DARK MODE SPECIFIC
   ============================================================================ */

[data-theme="dark"] .sidebar {
    border-right-color: var(--border-color);
}

[data-theme="dark"] .sidebar-link:hover {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .sidebar-section-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Sidebar Item Animations - DISABLED for instant page loading */
/* Staggered animations look nice but slow down perceived performance */
.sidebar-item,
.sidebar-section {
    /* animation: slideIn 0.3s ease-out backwards; */ /* Removed for instant loading */
    animation: none;
}

/* Animation delays removed for instant loading
.sidebar-item:nth-child(1) { animation-delay: 0.05s; }
.sidebar-item:nth-child(2) { animation-delay: 0.1s; }
.sidebar-item:nth-child(3) { animation-delay: 0.15s; }
.sidebar-section:nth-child(1) { animation-delay: 0.05s; }
.sidebar-section:nth-child(2) { animation-delay: 0.1s; }
*/

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

.sidebar-link:focus,
.sidebar-section-header:focus {
    outline: none; /* Remove outline to prevent double border appearance */
    /* Border is already set on .active state */
}

@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar-link,
    .sidebar-section-header,
    .sidebar-submenu,
    .sidebar-section-chevron {
        transition: none !important;
        animation: none !important;
    }
}

