/**
 * Apolo12 PWA Mobile Optimization & Performance
 * This file should be included after Bootstrap and before custom styles
 */

/* ============================================
   1. PERFORMANCE: Lazy Loading Images
   ============================================ */

img[loading="lazy"] {
    background-color: #f0f0f0;
}

/* Placeholder animation */
.image-loading {
    animation: skeleton-loading 1s infinite;
}

@keyframes skeleton-loading {
    0% {
        background-color: #e0e0e0;
    }
    50% {
        background-color: #f0f0f0;
    }
    100% {
        background-color: #e0e0e0;
    }
}

/* ============================================
   2. MOBILE FIRST: Responsive Improvements
   ============================================ */

/* Safe area for notch devices */
@supports (padding: max(0px)) {
    body {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .navbar {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }

    .container {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }
}

/* Improve touch targets (minimum 44x44px on mobile) */
@media (max-width: 768px) {
    button, a, input[type="button"], input[type="submit"], .btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Better spacing for mobile */
    .section145 {
        padding: 24px 0 !important;
    }

    .container {
        max-width: 100%;
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Optimize product grid on mobile */
    .row > [class^="col-"] {
        padding-left: 6px;
        padding-right: 6px;
    }

    /* Smooth scroll for mobile */
    html {
        scroll-behavior: smooth;
    }

    /* Prevent horizontal overflow */
    body {
        overflow-x: hidden;
    }

    /* Welcome page carousel spacing like seeall on mobile */
    .featured-slider .owl-item {
        padding: 0 6px;
    }

    .featured-slider .item {
        display: flex;
        justify-content: center;
    }

    .featured-slider .product-item {
        width: 100% !important;
        max-width: 100% !important;
        padding: 10px !important;
        margin-bottom: 0 !important;
        min-height: auto !important;
        box-shadow: 0 3px 18px rgba(0, 0, 0, 0.06) !important;
        border-radius: 18px !important;
    }

    .featured-slider .product-item img,
    .featured-slider .product-image {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        object-fit: cover !important;
        border-radius: 14px !important;
        max-height: 220px !important;
    }

    .featured-slider .product-text-dt {
        padding-top: 10px !important;
    }

    .featured-slider .product-text-dt h4 {
        font-size: 1rem !important;
        line-height: 1.3 !important;
        margin-bottom: 8px !important;
        min-height: 48px !important;
        overflow: hidden !important;
    }

    .featured-slider .product-text-dt .btn,
    .featured-slider .product-text-dt button {
        width: 100% !important;
        font-size: 0.82rem !important;
        padding: 8px 0 !important;
    }

    .featured-slider .owl-nav .owl-prev,
    .featured-slider .owl-nav .owl-next {
        top: 36% !important;
        height: 28px !important;
        width: 28px !important;
        font-size: 16px !important;
        padding: 0 !important;
        border-radius: 8px !important;
    }

    .featured-slider .owl-nav .owl-prev {
        left: 4px !important;
    }

    .featured-slider .owl-nav .owl-next {
        right: 4px !important;
    }

    .featured-slider .owl-nav button {
        background: #fff !important;
        color: #2b2f4c !important;
        border: 1px solid #e5e5e5 !important;
    }

    .featured-slider .owl-nav button:hover {
        background: #f55d2c !important;
        color: #fff !important;
    }
    
    
        .featured-slider .owl-nav {
        display: none !important;
    }
}

/* ============================================
   3. SMOOTH SCROLLING & TRANSITIONS
   ============================================ */

html {
    scroll-behavior: smooth;
}

/* Remove transitions during page load for perceived performance */
html.page-loading * {
    animation-duration: 0 !important;
    transition-duration: 0 !important;
}

/* Use GPU acceleration for smooth animations */
.product-item,
.product-card,
.btn,
.modal .modal-content {
    will-change: transform;
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   4. OPTIMIZED TYPOGRAPHY
   ============================================ */

@media (min-width: 1024px) {
    h1 {
        font-size: 2.5rem;
    }
    h2 {
        font-size: 2rem;
    }
    h3 {
        font-size: 1.5rem;
    }
}

@media (max-width: 768px) {
    h1 {
        font-size: 1.75rem;
    }
    h2 {
        font-size: 1.5rem;
    }
    h3 {
        font-size: 1.25rem;
    }

    body {
        font-size: 14px;
    }
}

/* ============================================
   5. REDUCED MOTION FOR ACCESSIBILITY
   ============================================ */

@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;
    }
}

/* ============================================
   6. DARK MODE SUPPORT (Optional)
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* This is optional - implement if desired */
    body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }

    .card, .modal-content {
        background-color: #2d2d2d;
        color: #e0e0e0;
    }

    .navbar {
        background-color: #1a1a1a;
    }
}

/* ============================================
   7. PRINT OPTIMIZATION
   ============================================ */

@media print {
    .navbar, .footer, .side-cart, #pwa-install-btn {
        display: none;
    }

    body {
        background: white;
        color: black;
    }

    img {
        max-width: 100%;
    }
}

/* ============================================
   8. HIGH DPI SCREENS (Retina)
   ============================================ */

@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* ============================================
   9. FOCUS VISIBLE FOR ACCESSIBILITY
   ============================================ */

*:focus-visible {
    outline: 2px solid #ff6a00;
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 2px solid #ff6a00;
}

/* ============================================
   10. PREVENT ZOOM ON INPUT FOCUS (iOS)
   ============================================ */

@supports (font-size: clamp(1rem, 1vw, 2rem)) {
    input[type="text"],
    input[type="email"],
    input[type="phone"],
    input[type="number"],
    textarea,
    select {
        font-size: clamp(1rem, 2.5vw, 1.125rem);
    }
}

input[type="text"],
input[type="email"],
input[type="phone"],
input[type="number"],
textarea,
select {
    font-size: 16px; /* Prevent iOS zoom on focus */
}

/* ============================================
   11. NETWORK STATUS INDICATOR (Optional)
   ============================================ */

.offline-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #ef4444;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 12px;
    display: none;
    z-index: 9999;
}

.offline-indicator.show {
    display: block;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   12. LOADING STATES
   ============================================ */

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #ff6a00;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* ============================================
   13. BUTTON RIPPLE EFFECT (Mobile UX)
   ============================================ */

@supports (background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0) 70%)) {
    .btn:active::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 5px;
        height: 5px;
        background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0) 70%);
        border-radius: 50%;
        transform: translate(-50%, -50%);
        animation: ripple 0.6s ease-out;
    }
}

@keyframes ripple {
    0% {
        width: 5px;
        height: 5px;
        opacity: 1;
    }
    100% {
        width: 100px;
        height: 100px;
        opacity: 0;
    }
}

/* ============================================
   14. GRID & FLEX ADJUSTMENTS FOR MOBILE
   ============================================ */

@media (max-width: 768px) {
    .d-lg-flex {
        flex-direction: column !important;
    }

    .justify-content-between {
        justify-content: center;
        gap: 12px;
    }

    .row > .col-md-6,
    .row > .col-lg-4,
    .row > .col-lg-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ============================================
   15. FONT LOADING OPTIMIZATION
   ============================================ */

@font-face {
    font-display: swap;
}

/* ============================================
   16. PRODUCT GRID: Force 2 products per row on mobile
   ============================================ */

/* Force 2 products per row on small screens */
@media (max-width: 768px) {
    .all-product-grid .product-list-view .row {
        display: flex !important;
        flex-wrap: wrap !important;
        margin-left: -8px !important;
        margin-right: -8px !important;
    }

    .all-product-grid .product-list-view .product-card,
    .all-product-grid .product-list-view .product-item-container {
        box-sizing: border-box !important;
        flex: 0 0 50% !important;
        max-width: 50% !important;
        width: 50% !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .all-product-grid .product-list-view .product-card {
        padding-bottom: 8px !important;
        min-width: 0 !important;
    }

    .all-product-grid .product-list-view .product-item {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin-bottom: 12px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: flex-start !important;
        overflow: hidden !important;
        min-width: 0 !important;
    }

    .all-product-grid .product-list-view .product-item img,
    .all-product-grid .product-list-view img.product-image {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
        max-height: 210px !important;
        border-radius: 12px !important;
    }

    .all-product-grid .product-list-view .product-text-dt {
        width: 100% !important;
        padding-top: 12px !important;
    }

    .all-product-grid .product-list-view .product-text-dt h4,
    .all-product-grid .product-list-view .product-price,
    .all-product-grid .product-list-view .btn {
        width: 100% !important;
    }

    .all-product-grid .product-list-view .qty-cart {
        flex-wrap: wrap !important;
        justify-content: space-between !important;
        gap: 10px !important;
        width: 100% !important;
        align-items: center !important;
    }

    .all-product-grid .product-list-view .qty-cart .quantity.buttons_added {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        width: auto !important;
        display: flex !important;
        gap: 6px !important;
    }

    .all-product-grid .product-list-view .qty-cart .cart-icon {
        margin-left: 0 !important;
        align-self: flex-end !important;
        flex: 0 0 auto !important;
        padding: 8px 10px !important;
        background: rgba(255, 255, 255, 0.95) !important;
        border-radius: 12px !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05) !important;
    }
}

/* ============================================
   17. CUSTOM SCROLLBAR
   ============================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #ff6a00;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #ee0979;
}
