/* ============================================================
   SIDEBAR NAVIGATION SYSTEM
   Persistent left sidebar on desktop, hamburger menu on mobile
   Works with theme system - uses CSS variables
   ============================================================ */

/* ============================================================
   CSS VARIABLES FOR SIDEBAR
   ============================================================ */
:root {
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 0px;
    --mobile-header-height: 56px;
    --sidebar-transition: 0.3s ease;
}

/* ============================================================
   MOBILE HEADER BAR (visible only on mobile)
   ============================================================ */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-header-height);
    background: var(--card-background);
    border-bottom: 2px solid rgba(var(--primary-rgb), 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 1001;
    padding: 0 1rem;
    align-items: center;
    justify-content: space-between;
}

.hamburger-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.hamburger-btn:hover {
    background: var(--faded-bg);
    color: var(--primary-color);
}

.mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-color);
}

.mobile-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.mobile-actions {
    display: flex;
    gap: 0.5rem;
}

.mobile-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    color: var(--primary-color);
    background: rgba(var(--primary-rgb), 0.1);
    text-decoration: none;
    transition: all 0.2s ease;
}

.mobile-action-btn:hover {
    background: var(--primary-color);
    color: white;
}

/* ============================================================
   SIDEBAR OVERLAY (mobile only)
   ============================================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1002;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--sidebar-transition), visibility var(--sidebar-transition);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================================
   SIDEBAR (Main Navigation)
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--card-background);
    border-right: 2px solid rgba(var(--primary-rgb), 0.2);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
    z-index: 1003;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform var(--sidebar-transition);
}

/* Admin mode accent */
.sidebar.admin-mode {
    border-right: 3px solid var(--primary-color);
}

/* Portal mode accent */
.sidebar.portal-mode {
    border-right: 3px solid var(--primary-color);
}

/* ============================================================
   SIDEBAR HEADER
   ============================================================ */
.sidebar-header {
    padding: 1.25rem;
    border-bottom: 1px solid rgba(var(--primary-rgb), 0.15);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.sidebar-logo {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary-color);
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.25);
    flex-shrink: 0;
}

.sidebar-title {
    flex: 1;
    min-width: 0;
}

.sidebar-title a {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s ease;
}

.sidebar-title a:hover {
    color: var(--primary-color);
}

.mode-badge {
    display: inline-block;
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

.mode-badge.admin-badge {
    background: var(--primary-color);
}

.mode-badge.portal-badge {
    background: var(--primary-color);
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--muted-text);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.sidebar-close:hover {
    background: var(--faded-bg);
    color: var(--primary-color);
}

/* ============================================================
   SIDEBAR NAVIGATION LINKS
   ============================================================ */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: var(--faded-bg);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
}

.sidebar-link.active {
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    color: var(--muted-text);
    transition: color 0.2s ease;
}

.sidebar-link:hover i,
.sidebar-link.active i {
    color: var(--primary-color);
}

/* ============================================================
   SIDEBAR GROUPS (Collapsible)
   ============================================================ */
.sidebar-group {
    margin-bottom: 0.25rem;
}

.sidebar-group-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    color: var(--text-color);
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.sidebar-group-header:hover {
    background: var(--faded-bg);
    color: var(--primary-color);
}

.sidebar-group-header i:first-child {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    color: var(--muted-text);
    transition: color 0.2s ease;
}

.sidebar-group-header:hover i:first-child {
    color: var(--primary-color);
}

.sidebar-group-header span {
    flex: 1;
}

.group-arrow {
    font-size: 0.75rem;
    color: var(--muted-text);
    transition: transform 0.2s ease;
}

.sidebar-group.expanded .group-arrow {
    transform: rotate(180deg);
}

.sidebar-group-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: rgba(var(--primary-rgb), 0.03);
}

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

.sidebar-group-content a {
    display: block;
    padding: 0.6rem 1.25rem 0.6rem 3rem;
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.sidebar-group-content a:hover {
    background: var(--faded-bg);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    padding-left: 3.25rem;
}

.sidebar-section-label {
    padding: 0.5rem 1.25rem 0.25rem 3rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--muted-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================================
   SIDEBAR FOOTER
   ============================================================ */
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(var(--primary-rgb), 0.15);
    flex-shrink: 0;
}

.sidebar-mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    transition: all 0.2s ease;
}

.sidebar-mode-btn.portal-btn {
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary-color);
    border: 1px solid rgba(var(--primary-rgb), 0.3);
}

.sidebar-mode-btn.portal-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
}

.sidebar-mode-btn.admin-btn {
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary-color);
    border: 1px solid rgba(var(--primary-rgb), 0.3);
}

.sidebar-mode-btn.admin-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
}

/* ============================================================
   MAIN CONTENT AREA ADJUSTMENT
   ============================================================ */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left var(--sidebar-transition);
    padding: 1.5rem;
}

.main-content .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0;
}

/* ============================================================
   RESPONSIVE: MOBILE (< 768px)
   ============================================================ */
@media (max-width: 767px) {
    /* Show mobile header */
    .mobile-header {
        display: flex;
    }
    
    /* Show overlay */
    .sidebar-overlay {
        display: block;
    }
    
    /* Hide sidebar by default, slide in when open */
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    /* Show close button in sidebar */
    .sidebar-close {
        display: block;
    }
    
    /* Content takes full width, add top padding for mobile header */
    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: calc(var(--mobile-header-height) + 1rem);
    }
    
    .main-content .container {
        max-width: 100%;
    }
    
    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
    }
}

/* ============================================================
   RESPONSIVE: TABLET (768px - 1024px)
   ============================================================ */
@media (min-width: 768px) and (max-width: 1024px) {
    :root {
        --sidebar-width: 220px;
    }
    
    .sidebar-link,
    .sidebar-group-header {
        padding: 0.65rem 1rem;
        font-size: 0.9rem;
    }
    
    .sidebar-group-content a {
        padding: 0.5rem 1rem 0.5rem 2.5rem;
        font-size: 0.85rem;
    }
}

/* ============================================================
   SCROLLBAR STYLING FOR SIDEBAR
   ============================================================ */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

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

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(var(--primary-rgb), 0.2);
    border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--primary-rgb), 0.4);
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
/* Hide elements visually but keep them accessible */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
