/* FINAL FIX for overlapping user info in sidebar - Production Ready */

/* Critical: Force sidebar structure */
.sidebar {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: var(--sidebar-width, 380px) !important;
    overflow: hidden !important;
    z-index: 1000 !important;
}

/* Logo at top */
.sidebar-logo {
    flex: 0 0 60px !important;
    display: flex !important;
    align-items: center !important;
    padding: 0 1.5rem !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

/* Navigation container - MUST scroll with bottom space reserved */
.sidebar-nav {
    position: relative !important;
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    /* CRITICAL: Reserve space at bottom for user section */
    padding-bottom: 200px !important;
    max-height: calc(100vh - 60px) !important;
}

/* Force scrollbar styling */
.sidebar-nav::-webkit-scrollbar {
    width: 4px !important;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05) !important;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 136, 0.3) !important;
    border-radius: 2px !important;
}

/* CRITICAL: User section MUST be at absolute bottom */
.sidebar-user {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 160px !important;
    padding: 1rem 1.5rem !important;
    background: linear-gradient(to top,
        #0a0a0f 0%,
        #0a0a0f 50%,
        rgba(10, 10, 15, 0.98) 70%,
        rgba(10, 10, 15, 0.95) 85%,
        rgba(10, 10, 15, 0.9) 95%,
        transparent 100%) !important;
    border-top: 2px solid rgba(0, 255, 136, 0.3) !important;
    z-index: 1005 !important;
    box-shadow: 
        0 -5px 20px rgba(0, 0, 0, 0.8),
        0 -10px 40px rgba(0, 0, 0, 0.6),
        0 -15px 60px rgba(0, 0, 0, 0.4) !important;
}

/* Ensure user info layout */
.user-info {
    display: flex !important;
    align-items: center !important;
    gap: 0.75rem !important;
    margin-bottom: 0.75rem !important;
    position: relative !important;
    z-index: 1006 !important;
}

/* Avatar styling */
.user-avatar {
    flex: 0 0 40px !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #00ff88 0%, #00cc6a 100%) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: #0a0a0f !important;
    font-weight: 700 !important;
    font-size: 1.1rem !important;
    box-shadow: 0 2px 8px rgba(0, 255, 136, 0.3) !important;
}

/* User details container */
.user-details {
    flex: 1 !important;
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
}

/* User text styling */
.user-name {
    font-size: 0.95rem !important;
    color: #ffffff !important;
    font-weight: 600 !important;
    margin: 0 !important;
    line-height: 1.2 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 160px !important;
}

.user-email {
    font-size: 0.75rem !important;
    color: rgba(255, 255, 255, 0.6) !important;
    margin: 0 !important;
    line-height: 1.2 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 160px !important;
}

.user-role {
    font-size: 0.7rem !important;
    color: #00ff88 !important;
    margin: 0 !important;
    font-weight: 500 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
}

/* Action buttons container */
.user-actions {
    display: flex !important;
    gap: 0.5rem !important;
    position: relative !important;
    z-index: 1007 !important;
}

/* Action button styling */
.user-action-btn {
    flex: 1 !important;
    padding: 0.5rem 0.75rem !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 8px !important;
    color: rgba(255, 255, 255, 0.8) !important;
    font-size: 0.8rem !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.4rem !important;
}

.user-action-btn:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: #00ff88 !important;
    color: #00ff88 !important;
    transform: translateY(-1px) !important;
}

/* Settings button */
.settings-btn {
    background: rgba(255, 255, 255, 0.03) !important;
}

.settings-btn:hover {
    background: rgba(0, 255, 136, 0.1) !important;
}

/* Logout button */
.logout-btn {
    background: rgba(255, 68, 68, 0.08) !important;
    border-color: rgba(255, 68, 68, 0.2) !important;
}

.logout-btn:hover {
    background: rgba(255, 68, 68, 0.15) !important;
    border-color: #ff4444 !important;
    color: #ff4444 !important;
}

/* Collapsed sidebar adjustments */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width, 80px) !important;
}

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

.sidebar.collapsed .user-action-btn span {
    display: none !important;
}

.sidebar.collapsed .user-action-btn {
    padding: 0.6rem !important;
    min-width: 40px !important;
}

.sidebar.collapsed .sidebar-user {
    padding: 1rem !important;
    height: 140px !important;
}

.sidebar.collapsed .user-actions {
    flex-direction: column !important;
    align-items: center !important;
}

/* Toggle button position */
.sidebar-toggle {
    position: absolute !important;
    right: -15px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 1008 !important;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease !important;
    }
    
    .sidebar.open {
        transform: translateX(0) !important;
    }
    
    .sidebar-nav {
        padding-bottom: 180px !important;
    }
    
    .sidebar-user {
        height: 150px !important;
    }
}

/* Force last nav section to have space */
.nav-section:last-child {
    margin-bottom: 20px !important;
    padding-bottom: 10px !important;
}

/* Ensure AI Agent item specifically has clearance */
.nav-item a[href="/ai-agent.html"] {
    display: flex !important;
    align-items: center !important;
    margin-bottom: 5px !important;
}

/* Emergency override for any overlapping elements */
.sidebar-nav > * {
    position: relative !important;
    z-index: 1 !important;
}

.sidebar-user > * {
    position: relative !important;
    z-index: 10 !important;
}

/* Debug helper - adds visible boundary */
.sidebar-user::before {
    content: '' !important;
    position: absolute !important;
    top: -30px !important;
    left: 0 !important;
    right: 0 !important;
    height: 30px !important;
    background: linear-gradient(to bottom, 
        transparent 0%, 
        rgba(10, 10, 15, 0.5) 50%,
        rgba(10, 10, 15, 0.9) 100%) !important;
    pointer-events: none !important;
    z-index: 1004 !important;
}