/**
 * Mobile Responsive Styles for BiswaMart
 * Optimized for mobile browsing experience
 * Cross-browser compatible: Chrome, Safari, Edge, Firefox
 */

/* ===== CROSS-BROWSER FIXES ===== */

/* Fix product images for Safari/Edge */
.product-image {
    position: relative;
    aspect-ratio: 16/10;
    overflow: hidden;
    /* Fallback for Safari < 14 */
    height: 0;
    padding-bottom: 62.5%; /* 16:10 aspect ratio */
}

.product-image img,
.product-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    /* Safari fix */
    -webkit-object-fit: cover;
    /* Prevent distortion */
    max-width: 100%;
    display: block;
}

/* Modern browsers - use aspect-ratio */
@supports (aspect-ratio: 16/10) {
    .product-image {
        aspect-ratio: 16/10;
        height: auto;
        padding-bottom: 0;
    }
}

/* Fix image loading in all browsers */
img {
    max-width: 100%;
    height: auto;
    /* Prevent layout shift */
    vertical-align: middle;
    /* Safari render fix */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Grid display fixes for Safari */
.product-grid {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    gap: 24px;
}

.product-grid > * {
    -webkit-box-flex: 1;
    -webkit-flex: 1 1 280px;
    -ms-flex: 1 1 280px;
    flex: 1 1 280px;
    min-width: 260px;
}

/* Modern browsers use CSS Grid */
@supports (display: grid) {
    .product-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 24px;
    }
    
    .product-grid > * {
        min-width: auto;
    }
}

/* ===== MOBILE BREAKPOINT (max-width: 768px) ===== */
@media (max-width: 768px) {
    
    /* General adjustments */
    html {
        font-size: 15px;
        overflow-x: hidden;
    }
    
    body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Container padding reduce */
    .container {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    
    /* Navbar mobile optimizations */
    .navbar {
        padding: 0.5rem 0 !important;
    }
    
    .navbar-brand {
        font-size: 1.1rem;
    }
    
    .navbar-brand img {
        height: 32px !important;
    }
    
    /* Mobile menu better touch targets */
    .navbar-nav .nav-link {
        padding: 12px 16px !important;
        font-size: 1rem;
        border-bottom: 1px solid #eee;
    }
    
    .navbar-nav .dropdown-menu {
        border: none;
        padding-left: 1rem;
        background: #f8f9fa;
    }
    
    .navbar-nav .dropdown-item {
        padding: 10px 15px;
        font-size: 0.95rem;
    }
    
    /* Search form mobile */
    .navbar form.d-flex {
        width: 100%;
        margin: 10px 0 !important;
    }
    
    .navbar form .input-group {
        width: 100%;
    }
    
    /* Hero/Slider section */
    .hero-section, .banner-section {
        padding: 2rem 0 !important;
    }
    
    .hero-title {
        font-size: 1.6rem !important;
    }
    
    .hero-subtitle {
        font-size: 0.95rem !important;
    }
    
    /* Product cards mobile - Chrome/Safari optimized */
    .product-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
        padding: 0 4px;
    }
    
    .product-card {
        margin-bottom: 0;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        background: white;
    }
    
    .product-card .product-image {
        position: relative;
        padding-bottom: 75%; /* 4:3 ratio for mobile */
        height: 0;
        overflow: hidden;
    }
    
    .product-card .product-image img,
    .product-card img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
        -webkit-object-fit: cover;
    }
    
    /* Chrome mobile image render fix */
    @supports not (aspect-ratio: 1/1) {
        .product-card .product-image {
            padding-bottom: 75%;
        }
    }
    
    .product-card .card-body {
        padding: 12px;
    }
    
    .product-card .card-title {
        font-size: 0.85rem !important;
        line-height: 1.3;
        margin-bottom: 6px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        box-orient: vertical;
        overflow: hidden;
    }
    
    .product-card .price {
        font-size: 1rem !important;
        font-weight: 700;
        color: #3b82f6;
    }
    
    .product-card .price del {
        font-size: 0.8rem;
        color: #9ca3af;
    }
    
    .product-card .category-badge {
        font-size: 0.7rem;
        padding: 2px 6px;
        margin-bottom: 4px;
    }
    
    /* Mobile buttons - bigger touch targets for Chrome */
    .product-card .btn-group,
    .product-card .product-actions {
        display: flex;
        flex-direction: column;
        gap: 6px;
        margin-top: 8px;
    }
    
    .product-card .btn {
        width: 100%;
        padding: 10px 8px !important;
        font-size: 0.8rem;
        border-radius: 8px;
        min-height: 40px; /* Touch target size */
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
    }
    
    .product-card .btn i {
        font-size: 0.75rem;
    }
    
    .product-card .add-to-cart {
        background: #3b82f6;
        color: white;
        border: none;
    }
    
    .product-card .buy-now {
        background: #10b981;
        color: white;
        border: none;
    }
    
    /* Single product page mobile */
    .product-detail {
        padding: 1rem 0 !important;
    }
    
    .product-detail .product-image {
        margin-bottom: 1.5rem;
    }
    
    .product-detail .product-image img {
        max-height: 300px;
    }
    
    .product-detail h1 {
        font-size: 1.4rem !important;
    }
    
    .product-detail .price-current {
        font-size: 1.5rem !important;
    }
    
    .product-detail .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .product-detail .action-buttons .btn {
        width: 100%;
        padding: 12px !important;
        font-size: 1rem;
    }
    
    /* Reviews section mobile */
    .reviews-section {
        padding: 1rem !important;
    }
    
    .review-card {
        padding: 12px !important;
    }
    
    .review-avatar {
        width: 36px !important;
        height: 36px !important;
        font-size: 0.9rem;
    }
    
    .review-comment-cell {
        max-width: 200px !important;
    }
    
    /* Cart page mobile */
    .cart-table {
        font-size: 0.9rem;
    }
    
    .cart-table img {
        width: 60px !important;
        height: 60px !important;
    }
    
    .cart-table .quantity-input {
        width: 50px !important;
        padding: 5px;
    }
    
    .cart-totals {
        margin-top: 1.5rem;
    }
    
    /* Checkout page mobile */
    .checkout-form .form-control,
    .checkout-form .form-select {
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 12px;
    }
    
    .checkout-form .btn {
        width: 100%;
        padding: 14px !important;
        font-size: 1rem;
    }
    
    /* Auth pages mobile */
    .auth-container {
        padding: 1rem;
    }
    
    .auth-box {
        padding: 1.5rem !important;
        width: 100%;
        max-width: 100%;
    }
    
    .auth-box h1 {
        font-size: 1.5rem !important;
    }
    
    .auth-form .form-control {
        font-size: 16px !important;
        padding: 12px;
        height: auto;
    }
    
    .auth-form .btn {
        padding: 12px !important;
        font-size: 1rem;
    }
    
    /* Form elements mobile friendly */
    input, select, textarea {
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
    
    .form-control, .form-select {
        padding: 10px 12px;
    }
    
    .btn {
        padding: 10px 16px;
        touch-action: manipulation;
    }
    
    /* Tables mobile - make them scrollable */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .data-table {
        font-size: 0.85rem;
        min-width: 600px;
    }
    
    /* Footer mobile */
    .footer {
        padding: 2rem 0 !important;
    }
    
    .footer h4 {
        font-size: 1rem;
        margin-top: 1.5rem;
    }
    
    .footer-links {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    /* Admin panel mobile */
    .admin-wrapper {
        flex-direction: column;
    }
    
    .admin-sidebar {
        width: 100% !important;
        min-height: auto !important;
        position: relative !important;
    }
    
    .admin-main {
        margin-left: 0 !important;
        padding: 1rem !important;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Pagination mobile */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .pagination .page-link {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    /* Toast notifications mobile */
    .toast-container {
        right: 10px !important;
        left: 10px !important;
        top: 10px !important;
    }
    
    .toast {
        width: 100% !important;
    }
    
    /* Loader mobile */
    .loader {
        width: 40px;
        height: 40px;
    }
    
    /* Image optimization */
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Prevent text overflow */
    .text-truncate-mobile {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
}

/* ===== SMALL MOBILE (max-width: 480px) ===== */
@media (max-width: 480px) {
    
    html {
        font-size: 14px;
    }
    
    /* Single column product grid for small phones */
    .product-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
        padding: 0 8px;
    }
    
    /* Bigger product cards for better UX */
    .product-card .product-image {
        padding-bottom: 60%; /* Taller images */
    }
    
    .product-card .card-title {
        font-size: 1rem !important;
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }
    
    .product-card .price {
        font-size: 1.1rem !important;
    }
    
    /* Bigger buttons for small screens */
    .product-card .btn {
        padding: 12px 16px !important;
        font-size: 0.9rem;
        min-height: 44px;
    }
    
    /* Two buttons side by side on small phones */
    .product-card .btn-group,
    .product-card .product-actions {
        flex-direction: row;
        gap: 8px;
    }
    
    .product-card .btn {
        flex: 1;
    }
    
    /* Hero section */
    .hero-title {
        font-size: 1.4rem !important;
    }
    
    /* Hide some elements */
    .hide-mobile {
        display: none !important;
    }
    
    /* Simplify header */
    .navbar-brand span {
        font-size: 1rem;
    }
    
    /* Bigger touch targets */
    .btn-sm-mobile {
        padding: 8px 12px !important;
        font-size: 0.9rem;
    }
    
    /* Cart quantity smaller */
    .cart-qty-btn {
        width: 30px;
        height: 30px;
        padding: 0;
    }
    
    /* Footer single column */
    .footer-links {
        grid-template-columns: 1fr;
    }
}

/* ===== TABLET (769px - 991px) ===== */
@media (min-width: 769px) and (max-width: 991px) {
    
    .product-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    
    .admin-sidebar {
        width: 200px !important;
    }
    
    .admin-main {
        margin-left: 200px !important;
    }
}

/* ===== UTILITY CLASSES ===== */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none !important;
    }
    
    .text-center-mobile {
        text-align: center !important;
    }
    
    .full-width-mobile {
        width: 100% !important;
    }
    
    .mt-2-mobile {
        margin-top: 0.5rem !important;
    }
    
    .mb-2-mobile {
        margin-bottom: 0.5rem !important;
    }
    
    .p-2-mobile {
        padding: 0.5rem !important;
    }
}

/* ===== TOUCH OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets for touch devices */
    .btn, .nav-link, .dropdown-item, a {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on touch */
    .btn:hover, .nav-link:hover {
        transform: none !important;
    }
    
    /* Better scrolling */
    .scrollable-mobile {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }
}

/* ===== SAFE AREA for NOTCH PHONES ===== */
@supports (padding-top: env(safe-area-inset-top)) {
    .header {
        padding-top: env(safe-area-inset-top);
    }
    
    .fixed-bottom {
        padding-bottom: env(safe-area-inset-bottom) !important;
    }
}

/* ===== CHROME MOBILE SPECIFIC ===== */
@media screen and (max-width: 768px) and (-webkit-min-device-pixel-ratio: 2) {
    /* Chrome on Android optimizations */
    .product-card {
        /* Hardware acceleration for smooth scrolling */
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    /* Chrome address bar & scroll fix */
    html {
        min-height: 100%;
    }
    
    body {
        min-height: 100vh;
        overflow-y: visible;
    }
    
    /* Chrome mobile form optimizations */
    input, select, textarea {
        /* Prevent Chrome zoom on focus */
        font-size: 16px !important;
    }
    
    /* Chrome mobile button active states */
    .btn:active, .product-card .btn:active {
        -webkit-transform: scale(0.98);
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    /* Chrome mobile image loading */
    .product-image img {
        /* Prevent Chrome image flicker */
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        /* Smooth image rendering */
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===== SAFARI SPECIFIC FIXES ===== */
@supports (-webkit-touch-callout: none) {
    /* Safari on iOS specific */
    .product-card {
        /* iOS tap highlight */
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
    }
    
    .btn {
        /* Remove default iOS button styling */
        -webkit-appearance: none;
        appearance: none;
    }
    
    input, select, textarea {
        /* Remove default iOS input styling */
        -webkit-appearance: none;
        appearance: none;
        border-radius: 8px;
    }
    
    /* iOS momentum scrolling */
    .product-grid, .scrollable {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== EDGE BROWSER FIXES ===== */
@supports (-ms-ime-align: auto) {
    /* Edge specific */
    .product-image img,
    .product-card img {
        /* Edge image rendering fix */
        -ms-interpolation-mode: bicubic;
    }
    
    .product-grid {
        /* Edge grid fallback */
        display: -ms-flexbox;
        display: flex;
        -ms-flex-wrap: wrap;
        flex-wrap: wrap;
    }
}

/* ===== FIREFOX FIXES ===== */
@-moz-document url-prefix() {
    .product-image img,
    .product-card img {
        /* Firefox image rendering */
        image-rendering: auto;
    }
}
