/* ============================================
   SIDEBAR NAVIGATION - ENTERPRISE EDITION
   Professional collapsible sidebar with best practices
   Version: 1.0
   ============================================ */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    /* Sidebar Dimensions */
    --sidebar-width-expanded: 16rem;      /* 256px */
    --sidebar-width-collapsed: 4rem;      /* 64px */
    
    /* Sidebar Colors */
    --sidebar-bg: #1f2937;               /* gray-800 */
    --sidebar-border: #374151;           /* gray-700 */
    --sidebar-text: #d1d5db;            /* gray-300 */
    --sidebar-text-hover: #ffffff;
    --sidebar-text-active: #ffffff;
    --sidebar-link-hover-bg: #374151;    /* gray-700 */
    --sidebar-link-active-bg: #4f46e5;   /* indigo-600 */
    --sidebar-accent: #6366f1;           /* indigo-500 */
    --sidebar-divider: rgba(255, 255, 255, 0.1);
    
    /* Transitions */
    --sidebar-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-link-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Shadows */
    --sidebar-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --sidebar-active-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3), 0 4px 12px rgba(99, 102, 241, 0.2);
    
    /* Z-index */
    --sidebar-z-index: 1000;
    --tooltip-z-index: 1050;
}

/* ============================================
   MAIN SIDEBAR CONTAINER
   ============================================ */
#sidebar {
    width: var(--sidebar-width-expanded);
    height: 100vh;
    background-color: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    transition: var(--sidebar-transition);
    position: sticky;
    top: 0;
    z-index: var(--sidebar-z-index);
    box-shadow: var(--sidebar-shadow);
}

/* Collapsed State */
#sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
    min-width: var(--sidebar-width-collapsed);
}

/* ============================================
   SIDEBAR HEADER (LOGO SECTION)
   ============================================ */
.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.sidebar-header a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}

#sidebar-logo {
    height: 2.5rem;
    width: 2.5rem;
    flex-shrink: 0;
    object-fit: contain;
    transition: all 0.3s ease-in-out;
}

#sidebar-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: white;
    transition: opacity 0.3s ease-in-out, width 0.3s ease-in-out;
    white-space: nowrap;
    overflow: hidden;
}

/* Collapsed state */
#sidebar.collapsed .sidebar-header a {
    justify-content: center;
}

#sidebar.collapsed #sidebar-logo {
    height: 2rem;
    width: 2rem;
}

#sidebar.collapsed #sidebar-title {
    opacity: 0;
    width: 0;
}

/* Toggle Button */
#sidebar-toggle {
    color: #9ca3af;
    transition: all 0.3s ease;
    padding: 0.5rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    width: 2.5rem;
    height: 2.5rem;
}

#sidebar-toggle:hover {
    color: white;
    background-color: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

#sidebar-toggle:active {
    transform: scale(0.95);
}

#sidebar-toggle:focus {
    outline: none;
}

/* Desktop Toggle Icon */
#sidebar-toggle-icon {
    width: 1.25rem;
    height: 1.25rem;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar.collapsed #sidebar-toggle-icon {
    transform: rotate(180deg);
}

/* Hamburger Icon for Mobile */
#sidebar-toggle-hamburger {
    width: 1.25rem;
    height: 1rem;
    display: none;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
}

#sidebar-toggle-hamburger span {
    width: 100%;
    height: 2px;
    background-color: currentColor;
    border-radius: 2px;
    transition: all 0.3s ease;
    transform-origin: center;
}

/* Hamburger Animation when sidebar is open */
#sidebar.mobile-open #sidebar-toggle-hamburger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

#sidebar.mobile-open #sidebar-toggle-hamburger span:nth-child(2) {
    opacity: 0;
}

#sidebar.mobile-open #sidebar-toggle-hamburger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ============================================
   NAVIGATION LINKS
   ============================================ */
.sidebar-nav {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom scrollbar for nav */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Navigation container */
nav.space-y-2 > * + * {
    margin-top: 0.5rem;
}

/* ============================================
   SIDEBAR LINKS
   ============================================ */
.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--sidebar-link-transition);
    position: relative;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-link svg {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.75rem;
    flex-shrink: 0;
    transition: var(--sidebar-link-transition);
}

.sidebar-link span {
    transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
    flex: 1;
}

/* Hover State */
.sidebar-link:hover {
    background-color: var(--sidebar-link-hover-bg);
    color: var(--sidebar-text-hover);
    transform: translateX(2px);
}

/* Active State */
.sidebar-link.active {
    background: linear-gradient(135deg, var(--sidebar-link-active-bg) 0%, #5b48db 100%);
    color: var(--sidebar-text-active);
    box-shadow: inset 4px 0 0 0 var(--sidebar-accent);
    font-weight: 600;
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, #818cf8 0%, #6366f1 100%);
    border-radius: 0 2px 2px 0;
}

/* ============================================
   COLLAPSED SIDEBAR STYLES
   ============================================ */
#sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 0.75rem 0.5rem;
}

#sidebar.collapsed .sidebar-link svg {
    margin-right: 0;
}

#sidebar.collapsed .sidebar-link span {
    opacity: 0;
    width: 0;
    transform: translateX(-10px);
}

#sidebar.collapsed .sidebar-link:hover {
    background-color: var(--sidebar-link-hover-bg);
    transform: scale(1.1);
    border-radius: 0.5rem;
}

#sidebar.collapsed .sidebar-link.active {
    background: var(--sidebar-link-active-bg);
    transform: scale(1.1);
    border-radius: 0.5rem;
    box-shadow: var(--sidebar-active-shadow);
}

#sidebar.collapsed .sidebar-link.active::before {
    display: none;
}

#sidebar.collapsed .sidebar-link.active::after {
    content: '';
    position: absolute;
    right: -2px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--sidebar-accent);
    border-radius: 2px 0 0 2px;
}

/* ============================================
   TOOLTIPS FOR COLLAPSED STATE
   ============================================ */
#sidebar.collapsed .sidebar-link::before {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 0.75rem);
    top: 50%;
    transform: translateY(-50%);
    background: #374151;
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease-in-out;
    pointer-events: none;
    z-index: var(--tooltip-z-index);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

#sidebar.collapsed .sidebar-link::after {
    content: '';
    position: absolute;
    left: calc(100% + 0.25rem);
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 5px 5px 5px 0;
    border-color: transparent #374151 transparent transparent;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease-in-out;
    pointer-events: none;
    z-index: var(--tooltip-z-index);
}

#sidebar.collapsed .sidebar-link:hover::before,
#sidebar.collapsed .sidebar-link:hover::after {
    opacity: 1;
    visibility: visible;
}

#sidebar.collapsed .sidebar-link.active::before {
    content: attr(data-tooltip);
}

/* ============================================
   ADMIN SECTION DIVIDER
   ============================================ */
.sidebar-divider {
    margin: 1.25rem 1rem 0.625rem;
    padding: 0.5rem 0;
    border-top: 1px solid var(--sidebar-divider);
}

.sidebar-divider span {
    font-size: 0.6875rem;
    font-weight: 600;
    color: #9ca3af;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    transition: opacity 0.3s ease-in-out;
}

#sidebar.collapsed .sidebar-divider {
    border-top: 2px solid rgba(255, 255, 255, 0.2);
    margin: 1.25rem 1rem;
    padding: 0;
}

#sidebar.collapsed .sidebar-divider span {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.admin-menu-section {
    margin-top: 0.625rem;
}

/* ============================================
   SIDEBAR FOOTER (USER SECTION)
   ============================================ */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
    transition: var(--sidebar-link-transition);
}

.sidebar-user-avatar {
    width: 2rem;
    height: 2rem;
    background-color: #4b5563;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-user-avatar span {
    font-size: 0.875rem;
    font-weight: 500;
    color: white;
}

.sidebar-user-info {
    margin-left: 0.75rem;
    flex: 1;
    min-width: 0;
    transition: opacity 0.3s ease-in-out;
}

.sidebar-user-info p {
    font-size: 0.875rem;
    font-weight: 500;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

#sidebar.collapsed .sidebar-user-info {
    opacity: 0;
    width: 0;
}

/* Logout Button */
.sidebar-logout {
    width: 100%;
    text-align: left;
    font-size: 0.875rem;
    color: var(--sidebar-text);
    display: flex;
    align-items: center;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: var(--sidebar-link-transition);
    background: transparent;
    border: none;
    cursor: pointer;
}

.sidebar-logout:hover {
    color: white;
    background-color: rgba(239, 68, 68, 0.1);
}

.sidebar-logout svg {
    width: 1rem;
    height: 1rem;
    margin-right: 0.5rem;
    flex-shrink: 0;
    transition: var(--sidebar-link-transition);
}

.sidebar-logout span {
    transition: opacity 0.3s ease-in-out;
}

#sidebar.collapsed .sidebar-logout {
    justify-content: center;
}

#sidebar.collapsed .sidebar-logout svg {
    margin-right: 0;
}

#sidebar.collapsed .sidebar-logout span {
    opacity: 0;
    width: 0;
}

/* ============================================
   MAIN CONTENT ADJUSTMENT
   ============================================ */
#main-content {
    flex: 1;
    background-color: #f3f4f6;
    transition: var(--sidebar-transition);
    margin-left: 0 !important;
    min-height: 100vh;
}

/* Mobile Overlay */
#mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#mobile-overlay.active {
    opacity: 1;
}

/* Mobile Hamburger Button (Outside Sidebar) */
#mobile-hamburger {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1100;
    background: white;
    border: none;
    border-radius: 0.5rem;
    padding: 0.75rem;
    width: 3rem;
    height: 3rem;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    opacity: 1;
    transform: scale(1) translateX(0);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s ease, box-shadow 0.2s ease;
}

#mobile-hamburger:hover {
    background: #f3f4f6;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    transform: scale(1.05) translateX(0);
}

#mobile-hamburger:active {
    transform: scale(0.95) translateX(0);
}

#mobile-hamburger span {
    display: block;
    width: 1.5rem;
    height: 2px;
    background-color: #1f2937;
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* Hide hamburger when sidebar is open */
#mobile-hamburger.hidden {
    opacity: 0;
    transform: scale(0.8) translateX(-20px);
    pointer-events: none;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    /* Show mobile hamburger button */
    #mobile-hamburger {
        display: flex;
    }
    
    /* Show hamburger icon, hide desktop arrow icon */
    #sidebar-toggle-icon {
        display: none;
    }
    
    #sidebar-toggle-hamburger {
        display: flex;
    }
    
    /* Sidebar mobile styles */
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    }
    
    #sidebar.mobile-open {
        transform: translateX(0);
    }
    
    /* Reset collapsed state on mobile */
    #sidebar.collapsed {
        width: 280px;
        min-width: 280px;
        transform: translateX(-100%);
    }
    
    #sidebar.collapsed.mobile-open {
        transform: translateX(0);
    }
    
    /* Ensure all text is visible on mobile */
    #sidebar.collapsed .sidebar-link,
    #sidebar.collapsed .sidebar-dropdown-toggle {
        justify-content: flex-start;
        padding: 0.75rem 1rem;
    }
    
    #sidebar.collapsed .sidebar-link svg,
    #sidebar.collapsed .sidebar-dropdown-toggle svg:first-of-type {
        margin-right: 0.75rem;
    }
    
    #sidebar.collapsed .sidebar-link span,
    #sidebar.collapsed .sidebar-dropdown-toggle span,
    #sidebar.collapsed .sidebar-dropdown-arrow {
        opacity: 1 !important;
        width: auto !important;
        transform: translateX(0) !important;
    }
    
    #sidebar.collapsed .sidebar-user-info {
        opacity: 1;
        width: auto;
        margin-left: 0.75rem;
    }
    
    #sidebar.collapsed .sidebar-logout {
        justify-content: flex-start;
    }
    
    #sidebar.collapsed .sidebar-logout svg {
        margin-right: 0.5rem;
    }
    
    #sidebar.collapsed .sidebar-logout span {
        opacity: 1;
        width: auto;
    }
    
    #sidebar.collapsed .sidebar-divider span {
        opacity: 1;
        width: auto;
    }
    
    #sidebar.collapsed #sidebar-title {
        opacity: 1;
        width: auto;
    }
    
    #sidebar.collapsed #sidebar-logo {
        opacity: 1 !important;
    }
    
    /* Hide tooltips on mobile */
    #sidebar .sidebar-link::before,
    #sidebar .sidebar-link::after,
    #sidebar .sidebar-dropdown-toggle::before,
    #sidebar .sidebar-dropdown-toggle::after {
        display: none !important;
    }
    
    /* Main content adjustment */
    #main-content {
        margin-left: 0 !important;
        width: 100%;
    }
    
    /* Dropdown menu on mobile - allow toggle functionality */
    #sidebar.collapsed:not(.mobile-open) .sidebar-dropdown-menu {
        max-height: 0 !important;
        overflow: hidden;
    }
    
    /* When sidebar is open on mobile, allow dropdown to work normally */
    #sidebar.mobile-open .sidebar-dropdown-menu,
    #sidebar .sidebar-dropdown-menu {
        display: block !important;
        max-height: 0;
        overflow: hidden;
    }
    
    #sidebar.mobile-open .sidebar-dropdown-menu.show,
    #sidebar .sidebar-dropdown-menu.show {
        max-height: 500px !important;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    #sidebar,
    .sidebar-link,
    #sidebar-toggle-icon,
    .sidebar-link svg,
    .sidebar-link span {
        transition: none !important;
    }
}

/* Focus visible for keyboard navigation */
.sidebar-link:focus-visible,
#sidebar-toggle:focus-visible {
    outline: 2px solid var(--sidebar-accent);
    outline-offset: 2px;
}

/* ============================================
   DROPDOWN MENU STYLES
   ============================================ */
.sidebar-dropdown {
    position: relative;
}

.sidebar-dropdown-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.75rem 1rem;
    color: var(--sidebar-text);
    background: transparent;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: var(--sidebar-link-transition);
    position: relative;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-dropdown-toggle svg:first-of-type {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.sidebar-dropdown-toggle span {
    flex: 1;
    transition: opacity 0.2s ease-in-out;
}

.sidebar-dropdown-arrow {
    width: 1rem;
    height: 1rem;
    margin-left: auto;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

/* Arrow rotation when dropdown is active */
.sidebar-dropdown.active .sidebar-dropdown-arrow {
    transform: rotate(180deg);
}

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

.sidebar-dropdown.active .sidebar-dropdown-toggle {
    color: var(--sidebar-text-hover);
}

/* Dropdown Menu */
.sidebar-dropdown-menu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: 0.5rem;
}

.sidebar-dropdown-menu.show {
    max-height: 500px;
}

.sidebar-dropdown-item {
    display: flex;
    align-items: center;
    padding: 0.625rem 1rem 0.625rem 2.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: var(--sidebar-link-transition);
    margin-top: 0.25rem;
}

.sidebar-dropdown-item svg {
    width: 1rem;
    height: 1rem;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.sidebar-dropdown-item:hover {
    background-color: var(--sidebar-link-hover-bg);
    color: var(--sidebar-text-hover);
    transform: translateX(2px);
}

.sidebar-dropdown-item.active {
    background-color: rgba(99, 102, 241, 0.2);
    color: var(--sidebar-text-active);
    font-weight: 600;
}

/* Collapsed Sidebar Dropdown (Desktop only) */
@media (min-width: 769px) {
    #sidebar.collapsed .sidebar-dropdown-toggle {
        justify-content: center;
        padding: 0.75rem 0.5rem;
    }

    #sidebar.collapsed .sidebar-dropdown-toggle svg:first-of-type {
        margin-right: 0;
    }

    #sidebar.collapsed .sidebar-dropdown-toggle span,
    #sidebar.collapsed .sidebar-dropdown-arrow {
        opacity: 0;
        width: 0;
    }

    #sidebar.collapsed .sidebar-dropdown-menu {
        display: none;
    }
    
    /* Collapsed Dropdown Tooltip (Desktop only) */
    #sidebar.collapsed .sidebar-dropdown-toggle::before {
        content: attr(data-tooltip);
        position: absolute;
        left: calc(100% + 0.75rem);
        top: 50%;
        transform: translateY(-50%);
        background: #374151;
        color: white;
        padding: 0.5rem 0.75rem;
        border-radius: 0.5rem;
        font-size: 0.75rem;
        font-weight: 500;
        white-space: nowrap;
        opacity: 0;
        visibility: hidden;
        transition: all 0.2s ease-in-out;
        pointer-events: none;
        z-index: var(--tooltip-z-index);
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    }

    #sidebar.collapsed .sidebar-dropdown-toggle::after {
        content: '';
        position: absolute;
        left: calc(100% + 0.25rem);
        top: 50%;
        transform: translateY(-50%);
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 5px 5px 5px 0;
        border-color: transparent #374151 transparent transparent;
        opacity: 0;
        visibility: hidden;
        transition: all 0.2s ease-in-out;
        pointer-events: none;
        z-index: var(--tooltip-z-index);
    }

    #sidebar.collapsed .sidebar-dropdown-toggle:hover::before,
    #sidebar.collapsed .sidebar-dropdown-toggle:hover::after {
        opacity: 1;
        visibility: visible;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    #sidebar {
        display: none;
    }
    
    #main-content {
        margin-left: 0 !important;
    }
}

