/**
 * 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(0); /* CHANGED: Sidebar visible by default */
    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) - kept for compatibility */
.sidebar.active {
    transform: translateX(0);
}

/* Collapsed state (only icons visible) */
.sidebar.collapsed {
    width: 64px;
    transform: translateX(0); /* Stay visible, just narrower */
}

.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;
}

/* Collapsed items: center icons, remove outer margin */
.sidebar.collapsed .sidebar-item,
.sidebar.collapsed .sidebar-subitem {
    margin: 0.1rem 0;
}

.sidebar.collapsed .sidebar-section-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.3rem;
    margin: 0 auto;
    gap: 0;
    border: none;
    background: transparent;
    border-radius: 5px;
    width: 32px;
    height: 32px;
}

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

.sidebar.collapsed .sidebar-section-header.active {
    background: var(--bg-tertiary);
    color: var(--text-primary) !important;
}

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

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

.sidebar.collapsed .sidebar-link {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.3rem;
    margin: 0 auto;
    gap: 0;
    border: none;
    border-radius: 5px;
    width: 32px;
    height: 32px;
}

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

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

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

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

/* ============================================================================
   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.collapsed .sidebar-header {
    justify-content: center;
    padding: 0.75rem 0;
}

.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: 8px 0.4rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.6rem;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 5px;
    transition: background 0.15s, color 0.15s;
    border: none;
    line-height: 1.3;
    min-height: auto;
    font-size: 0.8125rem;
}

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

.sidebar-link.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
}

.sidebar-link:hover .sidebar-icon {
    opacity: 0.9;
}

.sidebar-link.active .sidebar-icon {
    color: var(--text-primary);
    opacity: 1;
}

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

.sidebar-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    font-size: 16px;
    color: var(--text-muted);
    opacity: 0.5;
}

.sidebar-icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 1.2;
    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.8125rem;
    font-weight: normal;
    line-height: 1.3;
    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.4rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-color);
}

.sidebar-section:first-child {
    border-top: none;
    padding-top: 0;
}

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

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

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

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

.sidebar-section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.6rem;
    cursor: pointer;
    border-radius: 5px;
    transition: background 0.15s, color 0.15s;
    user-select: none;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    line-height: 1.3;
    min-height: auto;
    font-size: 0.8125rem;
}

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

.sidebar-section-header:hover .sidebar-section-icon {
    opacity: 0.9;
}

.sidebar-section-header.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
}

.sidebar-section-header.active .sidebar-section-icon {
    color: var(--text-primary);
    opacity: 1;
}

.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: 16px;
    height: 16px;
    font-size: 16px;
    color: var(--text-muted);
    opacity: 0.5;
}

.sidebar-section-icon svg {
    width: 16px;
    height: 16px;
    stroke-width: 1.2;
    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.8125rem;
    font-weight: normal;
    text-transform: none;
    letter-spacing: normal;
    line-height: 1.3;
    color: currentColor;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.3s;
}

.sidebar-section-chevron {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.3s ease, opacity 0.3s;
    font-size: 0.625rem;
    background: none;
    border-radius: 3px;
    padding: 0;
    cursor: pointer;
    margin-left: 0.25rem;
}

.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.15rem 0 0.25rem 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: 6px 0.4rem;
}

.sidebar-subitem .sidebar-link {
    padding-left: 2.25rem;
    padding-right: 0.6rem;
    font-size: 0.8125rem;
}

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

@media (max-width: 768px) {
    .sidebar {
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        transform: translateX(0);
        width: 64px; /* Default: collapsed on mobile */
    }
    
    /* Collapsed sidebar on mobile: show icons only (64px) */
    .sidebar.collapsed {
        width: 64px;
    }
    
    /* Expanded sidebar on mobile: wider but not full width */
    .sidebar:not(.collapsed) {
        width: 240px; /* Reduced from 280px to prevent overlap */
        z-index: 999; /* Ensure sidebar is above content when expanded */
    }
    
    /* 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);
        width: 260px; /* Default width on desktop */
    }
    
    .sidebar.collapsed {
        width: 64px;
    }
    
    /* Default: Main content with expanded sidebar */
    .main {
        margin-left: 260px;
        width: calc(100% - 260px);
    }
    
    /* Footer sits outside .layout-container — match via body class, not sibling */
    .footer {
        margin-left: 260px;
    }

    body.sidebar-collapsed .footer {
        margin-left: 64px;
    }
    
    /* Collapsed sidebar adjustments */
    .sidebar.collapsed ~ .main {
        margin-left: 64px;
        width: calc(100% - 64px);
    }
}

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

@media (min-width: 1200px) {
    .sidebar {
        width: 260px;
    }
}

/* ============================================================================
   MAIN CONTENT ADJUSTMENTS
   ============================================================================
   All adjustments are handled in the responsive sections above.
   ============================================================================ */

/* Mobile: Adjust content for sidebar */
@media (max-width: 768px) {
    /* Default: Main content with collapsed sidebar (icon-only) */
    .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);
    }
    
    /* Footer stays at icon-rail width (expanded sidebar overlays) */
    .footer {
        margin-left: 64px;
    }

    body.sidebar-collapsed .footer {
        margin-left: 64px;
    }
    
    /* When sidebar is collapsed: give space for icon-only sidebar */
    .sidebar.collapsed ~ .main {
        margin-left: 64px;
        width: calc(100% - 64px);
    }
    
    /* When sidebar is expanded: overlay mode (no margin on main) */
    .sidebar:not(.collapsed) ~ .main {
        margin-left: 64px; /* Keep space for sidebar */
        width: calc(100% - 64px);
    }
}

/* Extra small mobile: Even smaller sidebar */
@media (max-width: 480px) {
    .sidebar {
        width: 56px; /* Default: collapsed */
    }
    
    .sidebar.collapsed {
        width: 56px;
    }
    
    /* Expanded sidebar on extra small screens */
    .sidebar:not(.collapsed) {
        width: 220px; /* Smaller than tablet */
    }
    
    /* Default spacing */
    .main {
        margin-left: 56px;
        width: calc(100% - 56px);
    }
    
    .footer {
        margin-left: 56px;
    }

    body.sidebar-collapsed .footer {
        margin-left: 56px;
    }
    
    /* Collapsed state */
    .sidebar.collapsed ~ .main {
        margin-left: 56px;
        width: calc(100% - 56px);
    }
    
    /* Expanded state */
    .sidebar:not(.collapsed) ~ .main {
        margin-left: 56px; /* Keep minimal space */
        width: calc(100% - 56px);
    }
}

/* ============================================================================
   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;
    }
}

