/**
 * ============================================================================
 * MOBILE UI ENHANCEMENTS
 * ============================================================================
 * Purpose: Adds mobile-specific styling for sidebar navigation and logout
 * Responsive breakpoint: 992px (Bootstrap's lg breakpoint)
 * Author: Senior Developer
 * Version: 1.0
 * ============================================================================
 */

/* ============================================================================
 * MOBILE USER PROFILE SECTION
 * ============================================================================
 * Beautiful gradient header shown only on mobile at top of sidebar
 * Contains user avatar, username, and email
 * -------------------------------------------------------------------------- */

.mobile-user-profile {
    margin: 0 !important;
    padding: 0 !important;
}

.mobile-profile-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin-bottom: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.mobile-profile-header .text-white {
    color: #ffffff !important;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.4;
}

.mobile-profile-header .text-white-50 {
    color: rgba(255, 255, 255, 0.85) !important;
    font-size: 0.75rem;
    line-height: 1.3;
}

.mobile-profile-header .img-sm {
    width: 42px;
    height: 42px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* ============================================================================
 * MOBILE ACCOUNT MENU SECTION
 * ============================================================================
 * Account-related menu items shown only on mobile at bottom of sidebar
 * Includes: Profile, Messages, Help, and Sign Out
 * -------------------------------------------------------------------------- */

/* Account section category header */
.mobile-account-category {
    margin-top: 1.5rem !important;
    padding: 0.75rem 35px 0.5rem !important;
    font-size: 0.75rem;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-top: 1px solid #e8e8e8;
}

/* Remove top border from first account item */
.mobile-account-item:first-of-type {
    padding-top: 0;
}

/* Account menu items */
.mobile-account-item .nav-link {
    padding: 12px 35px !important;
    transition: all 0.3s ease;
}

.mobile-account-item .nav-link:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

/* Logout link special styling */
.mobile-logout-link {
    margin-top: 0.5rem !important;
    padding: 14px 35px !important;
    border-top: 2px solid #e8e8e8 !important;
}

.mobile-logout-link:hover {
    background-color: rgba(220, 53, 69, 0.08) !important;
}

.mobile-logout-link .text-danger {
    color: #dc3545 !important;
    font-weight: 600 !important;
}

.mobile-logout-link .menu-icon.text-danger {
    color: #dc3545 !important;
    font-size: 20px;
}

/* ============================================================================
 * MOBILE SIDEBAR GENERAL STYLING
 * ============================================================================
 * Base styles for mobile offcanvas sidebar
 * Includes backdrop, spacing, and responsive behavior
 * -------------------------------------------------------------------------- */

@media (max-width: 991px) {
    /* Sidebar container - Override base styles to cover full screen */
    .sidebar-offcanvas {
        position: fixed !important;
        top: 0 !important; /* Start from very top of screen, not below navbar */
        bottom: 0 !important;
        right: -280px !important; /* Hide off-screen to the right (matches width) */
        left: auto !important;
        width: 280px !important; /* Slightly wider for better mobile UX */
        height: 100vh !important; /* Full viewport height */
        max-height: 100vh !important; /* Override the calc(100vh - 97px) from base CSS */
        background: #F4F5F7 !important; /* Match desktop sidebar color */
        box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15) !important;
        z-index: 1060 !important; /* Above navbar (1030) and backdrop (1050) */
        overflow-y: auto !important;
        overflow-x: hidden !important;
        transition: all 0.25s ease-out !important;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }
    
    /* Active state - slide in from right */
    .sidebar-offcanvas.active {
        right: 0 !important;
    }
    
    /* Navigation list */
    .sidebar-offcanvas .nav {
        margin-bottom: 0 !important;
        padding-bottom: 2rem !important;
        padding-top: 0 !important;
    }
    
    /* Ensure proper touch targets for all menu items */
    .sidebar .nav .nav-item .nav-link {
        min-height: 48px !important;
        display: flex !important;
        align-items: center !important;
        padding: 12px 35px !important;
    }
    
    /* Larger icons for better touch experience */
    .sidebar .nav .nav-item .nav-link .menu-icon {
        font-size: 20px !important;
        margin-right: 12px !important;
    }
    
    /* Remove extra spacing from nav items */
    .sidebar .nav .nav-item {
        margin: 0 !important;
    }
    
    /* Fix nav-category alignment on mobile */
    /* Match the padding of nav-links (35px) for consistent alignment */
    .sidebar .nav .nav-item.nav-category {
        margin: 0 !important;
        padding: 1rem 35px 0.5rem 35px !important; /* Match nav-link horizontal padding */
        font-size: 0.75rem !important;
        font-weight: 600 !important;
        color: #999 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
    }
}

/* ============================================================================
 * MOBILE SIDEBAR BACKDROP OVERLAY
 * ============================================================================
 * Dark overlay that appears behind sidebar when open
 * Click to close functionality
 * Covers entire screen including navbar
 * Z-index layering: content < navbar (1030) < backdrop (1050) < sidebar (1060)
 * -------------------------------------------------------------------------- */

.mobile-sidebar-backdrop {
    position: fixed;
    top: 0; /* Start from very top of screen */
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6); /* Slightly darker for better contrast */
    z-index: 1050; /* Above navbar (1030) but below sidebar (1060) */
    animation: fadeIn 0.3s ease;
    display: block;
}

/* Hide backdrop on desktop */
@media (min-width: 992px) {
    .mobile-sidebar-backdrop {
        display: none !important;
    }
}

/* ============================================================================
 * ANIMATIONS
 * ============================================================================
 * Smooth animations for sidebar entry and backdrop fade
 * -------------------------------------------------------------------------- */

/* Fade in animation for backdrop */
@keyframes fadeIn {
    from { 
        opacity: 0; 
    }
    to { 
        opacity: 1; 
    }
}

/* Slide in animation for menu items (staggered) */
@media (max-width: 991px) {
    .sidebar-offcanvas.active .nav-item {
        animation: slideInRight 0.3s ease forwards;
        opacity: 0;
    }
    
    /* Staggered animation delays for smooth cascade effect */
    .sidebar-offcanvas.active .nav-item:nth-child(1)  { animation-delay: 0.05s; }
    .sidebar-offcanvas.active .nav-item:nth-child(2)  { animation-delay: 0.08s; }
    .sidebar-offcanvas.active .nav-item:nth-child(3)  { animation-delay: 0.11s; }
    .sidebar-offcanvas.active .nav-item:nth-child(4)  { animation-delay: 0.14s; }
    .sidebar-offcanvas.active .nav-item:nth-child(5)  { animation-delay: 0.17s; }
    .sidebar-offcanvas.active .nav-item:nth-child(6)  { animation-delay: 0.20s; }
    .sidebar-offcanvas.active .nav-item:nth-child(7)  { animation-delay: 0.23s; }
    .sidebar-offcanvas.active .nav-item:nth-child(8)  { animation-delay: 0.26s; }
    .sidebar-offcanvas.active .nav-item:nth-child(9)  { animation-delay: 0.29s; }
    .sidebar-offcanvas.active .nav-item:nth-child(10) { animation-delay: 0.32s; }
    .sidebar-offcanvas.active .nav-item:nth-child(11) { animation-delay: 0.35s; }
    .sidebar-offcanvas.active .nav-item:nth-child(12) { animation-delay: 0.38s; }
    .sidebar-offcanvas.active .nav-item:nth-child(13) { animation-delay: 0.41s; }
    .sidebar-offcanvas.active .nav-item:nth-child(14) { animation-delay: 0.44s; }
    .sidebar-offcanvas.active .nav-item:nth-child(15) { animation-delay: 0.47s; }
}

/* Slide in from right animation */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================================================
 * DESKTOP OVERRIDES
 * ============================================================================
 * Ensure mobile-only elements are properly hidden on desktop
 * IMPORTANT: Reset all mobile positioning to prevent desktop conflicts
 * -------------------------------------------------------------------------- */

@media (min-width: 992px) {
    /* Hide all mobile-only elements */
    .mobile-user-profile,
    .mobile-account-category,
    .mobile-account-item {
        display: none !important;
    }
    
    /* CRITICAL: Reset all mobile sidebar modifications on desktop */
    /* This prevents conflicts with sidebar-icon-only and other desktop modes */
    .sidebar-offcanvas,
    .sidebar {
        position: relative !important;
        top: auto !important;
        bottom: auto !important;
        right: auto !important;
        left: auto !important;
        height: auto !important;
        max-height: none !important;
        transform: none !important;
        -webkit-transform: none !important;
    }
    
    /* Reset offcanvas-specific positioning */
    .sidebar-offcanvas {
        /* Width is controlled by base CSS - DO NOT override with auto */
        box-shadow: none !important;
        z-index: 11 !important; /* Default sidebar z-index from base CSS */
        overflow-y: visible !important;
        overflow-x: visible !important;
        transition: width 0.25s ease, background 0.25s ease !important;
    }
}

/* ============================================================================
 * ACCESSIBILITY ENHANCEMENTS
 * ============================================================================
 * Ensure proper focus states and keyboard navigation
 * -------------------------------------------------------------------------- */

/* Focus states for keyboard navigation */
.sidebar .nav .nav-item .nav-link:focus {
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .mobile-profile-header {
        border-bottom: 2px solid #fff;
    }
    
    .mobile-logout-link {
        border-top-width: 3px !important;
    }
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .sidebar-offcanvas.active .nav-item,
    .mobile-sidebar-backdrop {
        animation: none;
        opacity: 1;
        transform: none;
    }
}

/* ============================================================================
 * END OF MOBILE ENHANCEMENTS
 * ============================================================================
 */
