/* ==========================================================================
   Mobile Performance Optimizations for SOMASUQ
   ========================================================================== */

/* Hardware Acceleration */
@media (max-width: 768px) {
    
    /* GPU Acceleration for Animations */
    .btn,
    .card,
    .modal,
    .dropdown-menu,
    .navbar-collapse,
    .sidebar,
    .image-gallery-slide,
    .form-control:focus,
    .form-select:focus {
        transform: translateZ(0) !important;
        backface-visibility: hidden !important;
        perspective: 1000px !important;
    }
    
    /* Optimize Scrolling */
    .overflow-auto,
    .table-responsive,
    .modal-body,
    .sidebar,
    .navbar-collapse {
        -webkit-overflow-scrolling: touch !important;
        scroll-behavior: smooth !important;
    }
    
    /* Reduce Repaints */
    .card-img-top,
    .avatar,
    .img-thumbnail {
        will-change: transform !important;
    }
    
    /* Optimize Transitions */
    .btn,
    .card,
    .form-control,
    .form-select {
        transition-property: transform, box-shadow, background-color, border-color !important;
        transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
    
    /* Contain Layout Shifts */
    .card {
        contain: layout style paint !important;
    }
    
    .img-responsive,
    .img-fluid {
        contain: layout !important;
    }
    
    /* Optimize Font Rendering */
    body,
    .btn,
    .form-control,
    .form-select,
    .card-title,
    .card-text {
        text-rendering: optimizeSpeed !important;
        -webkit-font-smoothing: antialiased !important;
        -moz-osx-font-smoothing: grayscale !important;
    }
    
    /* Reduce Motion for Better Performance */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
            scroll-behavior: auto !important;
        }
    }
    
    /* Critical Resource Hints */
    .preload-critical {
        content-visibility: auto !important;
        contain-intrinsic-size: 200px !important;
    }
    
    /* Lazy Loading Optimization */
    .lazy-load {
        content-visibility: auto !important;
        contain-intrinsic-size: 300px 200px !important;
    }
    
    /* Optimize Images */
    img {
        image-rendering: -webkit-optimize-contrast !important;
        image-rendering: crisp-edges !important;
    }
    
    .img-responsive,
    .img-fluid {
        max-width: 100% !important;
        height: auto !important;
        vertical-align: middle !important;
    }
    
    /* Optimize Tables */
    .table-responsive {
        contain: layout style !important;
    }
    
    .table {
        table-layout: fixed !important;
    }
    
    .table td,
    .table th {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }
    
    /* Optimize Forms */
    .form-control,
    .form-select {
        contain: layout style !important;
    }
    
    /* Optimize Modals */
    .modal {
        contain: layout style paint !important;
    }
    
    .modal-backdrop {
        will-change: opacity !important;
    }
    
    /* Optimize Dropdowns */
    .dropdown-menu {
        contain: layout style paint !important;
        will-change: transform, opacity !important;
    }
    
    /* Battery Optimization */
    @media (prefers-reduced-motion: reduce) {
        .carousel,
        .image-gallery-mobile {
            animation-play-state: paused !important;
        }
    }
    
    /* Network-aware Loading */
    @media (max-width: 768px) {
        /* Reduce image quality for slow connections */
        .slow-connection img {
            image-rendering: pixelated !important;
        }
        
        /* Disable animations for slow connections */
        .slow-connection * {
            animation: none !important;
            transition: none !important;
        }
        
        /* Reduce shadows for better performance */
        .low-performance .card,
        .low-performance .btn,
        .low-performance .modal-content {
            box-shadow: none !important;
        }
        
        /* Simplify gradients */
        .low-performance .btn-primary,
        .low-performance .btn-success,
        .low-performance .btn-warning,
        .low-performance .btn-danger {
            background: var(--bs-primary) !important;
        }
    }
    
    /* Memory Optimization */
    .offscreen {
        content-visibility: hidden !important;
    }
    
    .onscreen {
        content-visibility: visible !important;
    }
    
    /* Intersection Observer Optimization */
    .observe-visibility {
        content-visibility: auto !important;
        contain-intrinsic-size: 1px 300px !important;
    }
    
    /* Critical Above-the-fold Content */
    .above-fold {
        content-visibility: visible !important;
        contain: none !important;
    }
    
    /* Below-the-fold Content */
    .below-fold {
        content-visibility: auto !important;
        contain-intrinsic-size: 1px 500px !important;
    }
    
    /* Optimize Animations */
    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: translateY(0); }
    }
    
    @keyframes slideIn {
        from { transform: translateX(-100%); }
        to { transform: translateX(0); }
    }
    
    @keyframes scaleIn {
        from { transform: scale(0.9); opacity: 0; }
        to { transform: scale(1); opacity: 1; }
    }
    
    /* Use efficient animations */
    .fade-in {
        animation: fadeIn 0.3s ease-out !important;
    }
    
    .slide-in {
        animation: slideIn 0.3s ease-out !important;
    }
    
    .scale-in {
        animation: scaleIn 0.2s ease-out !important;
    }
    
    /* Optimize Touch Targets */
    .btn,
    .form-control,
    .form-select,
    .nav-link,
    .dropdown-item {
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* Optimize Focus States */
    .btn:focus,
    .form-control:focus,
    .form-select:focus,
    .nav-link:focus {
        outline: 2px solid var(--bs-primary) !important;
        outline-offset: 2px !important;
    }
    
    /* Optimize Hover States for Touch */
    @media (hover: none) {
        .btn:hover,
        .card:hover,
        .nav-link:hover {
            transform: none !important;
            box-shadow: none !important;
        }
    }
    
    /* Optimize Loading States */
    .loading {
        pointer-events: none !important;
        opacity: 0.7 !important;
    }
    
    .loading::after {
        content: '' !important;
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        width: 20px !important;
        height: 20px !important;
        margin: -10px 0 0 -10px !important;
        border: 2px solid transparent !important;
        border-top-color: var(--bs-primary) !important;
        border-radius: 50% !important;
        animation: spin 1s linear infinite !important;
    }
    
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    /* Optimize Error States */
    .error-state {
        background: #f8d7da !important;
        color: #721c24 !important;
        border: 1px solid #f5c6cb !important;
        border-radius: 8px !important;
        padding: 1rem !important;
        text-align: center !important;
    }
    
    /* Optimize Success States */
    .success-state {
        background: #d4edda !important;
        color: #155724 !important;
        border: 1px solid #c3e6cb !important;
        border-radius: 8px !important;
        padding: 1rem !important;
        text-align: center !important;
    }
    
    /* Optimize Empty States */
    .empty-state {
        text-align: center !important;
        padding: 3rem 1rem !important;
        color: #6c757d !important;
    }
    
    .empty-state i {
        font-size: 3rem !important;
        margin-bottom: 1rem !important;
        opacity: 0.5 !important;
    }
    
    /* Optimize Skeleton Loading */
    .skeleton {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%) !important;
        background-size: 200% 100% !important;
        animation: skeleton-loading 1.5s infinite !important;
    }
    
    @keyframes skeleton-loading {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    .skeleton-text {
        height: 1rem !important;
        border-radius: 4px !important;
        margin-bottom: 0.5rem !important;
    }
    
    .skeleton-title {
        height: 1.5rem !important;
        border-radius: 4px !important;
        margin-bottom: 1rem !important;
        width: 60% !important;
    }
    
    .skeleton-avatar {
        width: 50px !important;
        height: 50px !important;
        border-radius: 50% !important;
    }
    
    .skeleton-image {
        width: 100% !important;
        height: 200px !important;
        border-radius: 8px !important;
    }
}

/* Extra Small Devices Performance */
@media (max-width: 575.98px) {
    
    /* Further optimize for very small screens */
    .card {
        contain: layout !important;
    }
    
    /* Reduce complexity */
    .btn {
        border-radius: 6px !important;
    }
    
    .card {
        border-radius: 8px !important;
    }
    
    /* Optimize typography */
    body {
        font-size: 14px !important;
        line-height: 1.4 !important;
    }
    
    h1, h2, h3, h4, h5, h6 {
        line-height: 1.2 !important;
    }
    
    /* Optimize spacing */
    .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
    
    .row {
        margin-left: -0.375rem !important;
        margin-right: -0.375rem !important;
    }
    
    .col,
    [class*="col-"] {
        padding-left: 0.375rem !important;
        padding-right: 0.375rem !important;
    }
}

/* High Performance Mode */
.high-performance {
    /* Disable all animations */
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
    
    /* Remove shadows */
    .card,
    .btn,
    .modal-content,
    .dropdown-menu {
        box-shadow: none !important;
    }
    
    /* Simplify gradients */
    .btn-primary { background: #007bff !important; }
    .btn-success { background: #28a745 !important; }
    .btn-warning { background: #ffc107 !important; }
    .btn-danger { background: #dc3545 !important; }
    
    /* Remove border radius */
    .btn,
    .card,
    .form-control,
    .form-select {
        border-radius: 0 !important;
    }
}

/* Low Power Mode */
@media (prefers-reduced-motion: reduce) {
    .low-power {
        /* Minimal animations only */
        * {
            animation-duration: 0.1s !important;
            transition-duration: 0.1s !important;
        }
        
        /* Disable auto-playing content */
        .carousel,
        .image-gallery-mobile {
            animation-play-state: paused !important;
        }
        
        /* Reduce visual effects */
        .card,
        .btn {
            box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
        }
    }
}