/* Global Mobile Performance Optimizations */

/* Mobile Menu System */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.mobile-menu-toggle:hover {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.mobile-menu-toggle i {
    font-size: 1.25rem;
    color: #1a1a2e;
}

/* Mobile menu toggle dark theme for consistency */
@media (max-width: 1023px) {
    .mobile-menu-toggle {
        background: rgba(26, 26, 46, 0.95) !important;
        border: 1px solid rgba(200, 155, 66, 0.3) !important;
        box-shadow: 0 2px 10px rgba(200, 155, 66, 0.2) !important;
    }
    
    .mobile-menu-toggle:hover {
        background: rgba(26, 26, 46, 1) !important;
        box-shadow: 0 4px 20px rgba(200, 155, 66, 0.3) !important;
    }
    
    .mobile-menu-toggle i {
        color: #C89B42 !important;
    }
}

/* Sidebar Mobile Behavior */
@media (max-width: 1023px) {
    .mobile-menu-toggle {
        display: flex !important;
    }
    
    .sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.3);
        z-index: 1000;
        /* Override glassmorphism for better visibility */
        background: linear-gradient(135deg, #1a1a2e 0%, #0f0f1e 100%) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    /* Fix text colors in mobile sidebar */
    .sidebar .user-name,
    .sidebar .nav-item,
    .sidebar .nav-title,
    .sidebar h1, 
    .sidebar h2, 
    .sidebar h3,
    .sidebar span,
    .sidebar p {
        color: rgba(255, 255, 255, 0.9) !important;
    }
    
    .sidebar .user-role {
        color: rgba(255, 255, 255, 0.7) !important;
    }
    
    .sidebar .nav-item:hover {
        background: rgba(255, 255, 255, 0.1) !important;
        color: white !important;
    }
    
    .sidebar .nav-item.active {
        background: rgba(200, 155, 66, 0.2) !important;
        color: #C89B42 !important;
    }
    
    .sidebar .nav-item i {
        color: rgba(255, 255, 255, 0.8) !important;
    }
    
    .sidebar .nav-item.active i {
        color: #C89B42 !important;
    }
    
    /* Logo text visibility */
    .sidebar .logo span {
        color: white !important;
        font-weight: 600;
    }
    
    /* Ensure sidebar footer is visible */
    .sidebar .sidebar-footer {
        background: rgba(0, 0, 0, 0.2) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: 80px;
    }
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* MOBILE OPTIMIZATION */
@media (max-width: 768px) {
    /* Controlled animations */
    *,
    *::before,
    *::after {
        animation-duration: 0.3s !important;
        transition-duration: 0.3s !important;
    }
    
    /* Disable parallax effects */
    .parallax,
    [data-parallax] {
        transform: none !important;
    }
    
    /* Simplify transitions */
    * {
        transition-duration: 0.2s !important;
    }
    
    /* Disable backdrop filters on mobile for performance */
    .glass-effect,
    [class*="backdrop"] {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: rgba(255, 255, 255, 0.95) !important;
    }
    
    /* Reduce box shadows */
    [class*="shadow"] {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    }
    
    /* Optimize images */
    img {
        will-change: auto !important;
    }
    
    /* Force hardware acceleration only on transformed elements */
    .transitioning {
        transform: translateZ(0);
        backface-visibility: hidden;
        -webkit-font-smoothing: antialiased;
    }
}

/* Ultra mobile optimizations */
@media (max-width: 480px) {
    /* Disable all non-essential animations */
    * {
        animation: none !important;
        transition: opacity 0.2s ease !important;
    }
    
    /* Remove gradients for performance */
    [class*="gradient"] {
        background-image: none !important;
    }
    
    /* Simplify borders and shadows */
    * {
        border-radius: 8px !important;
        box-shadow: none !important;
    }
}

/* Touch-friendly adjustments */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    a,
    button,
    input,
    select,
    textarea,
    [role="button"],
    [class*="clickable"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px;
    }
    
    /* Remove hover states */
    *:hover {
        transform: none !important;
        box-shadow: inherit !important;
    }
    
    /* Add active states for feedback */
    *:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
}

/* Body scroll lock when menu is open */
body.menu-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Dashboard.css specific mobile fixes */
@media (max-width: 1023px) {
    /* Override sidebar colors for dashboard.css */
    .dashboard-container .sidebar {
        background: #1a1a2e !important;
    }
    
    .dashboard-container .sidebar .user-details h3,
    .dashboard-container .sidebar .user-details p,
    .dashboard-container .sidebar .menu-item span,
    .dashboard-container .sidebar .menu-section h4 {
        color: rgba(255, 255, 255, 0.9) !important;
    }
    
    .dashboard-container .sidebar .menu-item {
        color: rgba(255, 255, 255, 0.8) !important;
    }
    
    .dashboard-container .sidebar .menu-item:hover {
        background: rgba(255, 255, 255, 0.1) !important;
        color: white !important;
    }
    
    .dashboard-container .sidebar .menu-item.active {
        background: rgba(200, 155, 66, 0.2) !important;
        color: #C89B42 !important;
    }
    
    .dashboard-container .sidebar .menu-item i {
        color: inherit !important;
    }
    
    .dashboard-container .sidebar .logout-btn {
        background: rgba(200, 155, 66, 0.2) !important;
        color: #C89B42 !important;
    }
    
    .dashboard-container .sidebar .logout-btn:hover {
        background: #C89B42 !important;
        color: white !important;
    }
}

/* Small devices adjustments */
@media (max-width: 374px) {
    .mobile-menu-toggle {
        width: 44px;
        height: 44px;
        top: 0.75rem;
        left: 0.75rem;
    }
    
    .mobile-menu-toggle i {
        font-size: 1.1rem;
    }
    
    .sidebar {
        width: 100vw !important;
        max-width: 100vw !important;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        height: 100vh;
        overflow-y: auto;
    }
    
    .nav-item {
        padding: 0.75rem 1.5rem;
    }
    
    .user-profile {
        padding: 1rem;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    .sidebar {
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    body.menu-open {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
    
    .scroll-smooth {
        scroll-behavior: auto !important;
    }
}

/* Optimize for slow connections */
@media (prefers-reduced-data: reduce) {
    /* Hide decorative images */
    [role="presentation"],
    .decorative,
    .background-image {
        display: none !important;
    }
    
    /* Simplify backgrounds */
    * {
        background-image: none !important;
    }
}

/* PWA optimizations */
@media (display-mode: standalone) {
    /* Adjust for PWA status bar */
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* Ensure content doesn't go under notch */
    .header,
    .navigation {
        padding-top: env(safe-area-inset-top);
    }
}

/* Landscape mobile specific */
@media (max-height: 600px) and (orientation: landscape) {
    /* Reduce vertical spacing */
    * {
        margin-top: 0.5rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Compact headers */
    h1, h2, h3, h4, h5, h6 {
        line-height: 1.2 !important;
    }
    
    /* Hide non-essential elements */
    .decorative,
    .hero-background,
    .large-spacing {
        display: none !important;
    }
}

/* Force GPU acceleration for smooth scrolling */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
}

/* Prevent text size adjustment on orientation change */
body {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Optimize font loading */
@media (max-width: 768px) {
    body {
        font-display: swap;
    }
}