/**
 * Enterprise Mobile Responsiveness Enhancements
 * Version: 1.0.0
 *
 * Layered on top of existing styles to upgrade mobile UX
 * to enterprise e-commerce standards without breaking existing design.
 *
 * Breakpoints:
 *   xs: 0–575.98px   (phones)
 *   sm: 576–767.98px  (large phones)
 *   md: 768–991.98px  (tablets)
 *   lg: 992–1199.98px (small desktops)
 *   xl: 1200–1399.98px
 *   xxl: 1400px+
 */

/* ============================================
   1. TOUCH TARGET FIX (Critical)
   Override site.css's 28px !important back to
   44px minimum on mobile for accessibility.
   ============================================ */
@media (max-width: 991.98px) {
    .btn,
    .nav-link,
    .dropdown-item,
    .mobile-nav-link,
    a.action-btn,
    button.action-btn {
        min-height: 28px !important;
    }

    .enterprise-mobile-header .action-btn {
        width: 44px;
        height: 44px;
    }

    .qty-control button {
        width: 44px;
        height: 44px;
        font-size: 1.125rem;
    }

    .qty-control input {
        height: 44px;
        width: 52px;
        font-size: 1rem;
    }

    .cart-item-remove {
        width: 44px;
        height: 44px;
    }
}

/* ============================================
   2. TOUCH-DEVICE HOVER FIX
   Disable transform hover effects on touch
   to prevent jittery scroll behavior.
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    .product-card:hover,
    .enterprise-product-card:hover,
    .user-product-card:hover,
    .category-card:hover,
    .merchant-card:hover,
    .stat-card:hover {
        transform: none;
    }

    .enterprise-product-card:hover {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    }

    .enterprise-product-card:hover .product-card-image img {
        transform: none;
    }

    /* Make wishlist button always visible on touch */
    .product-card-wishlist {
        opacity: 1 !important;
    }

    /* Make quick-view overlay invisible on touch (use tap instead) */
    .product-card-overlay {
        display: none !important;
    }
}

/* ============================================
   3. LAYOUT SHIFT PREVENTION
   Ensure images don't cause CLS when loading.
   ============================================ */
.product-card-image,
.cart-item-image,
.merchant-avatar {
    contain: layout style;
}

.product-card-image img,
.cart-item-image img {
    background-color: #f3f4f6;
}

/* ============================================
   4. PRODUCT GRID — ENHANCED MOBILE
   ============================================ */
@media (max-width: 575.98px) {
    .product-grid {
        gap: 0.625rem;
    }

    .enterprise-product-card .product-card-body {
        padding: 0.75rem;
    }

    .enterprise-product-card .product-card-title {
        font-size: 0.8125rem;
        -webkit-line-clamp: 2;
        line-height: 1.35;
    }

    .enterprise-product-card .product-card-desc {
        display: none;
    }

    .enterprise-product-card .product-card-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding-top: 0.5rem;
    }

    .enterprise-product-card .product-current-price {
        font-size: 1rem;
    }

    .enterprise-product-card .product-card-actions {
        width: 100%;
    }

    .enterprise-product-card .product-btn {
        flex: 1;
        padding: 0.5rem 0.375rem;
        font-size: 0.6875rem;
        text-align: center;
        justify-content: center;
    }

    .product-card-badges .product-badge {
        font-size: 0.5625rem;
        padding: 0.1875rem 0.5rem;
    }

    .product-category-tag {
        font-size: 0.5625rem;
        padding: 0.125rem 0.375rem;
    }
}

/* ============================================
   5. PRODUCT DETAIL — MOBILE ENHANCEMENTS
   ============================================ */

/* Sticky bottom purchase bar on mobile */
.mobile-purchase-bar {
    display: none;
}

@media (max-width: 991.98px) {
    .mobile-purchase-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1040;
        background: #ffffff;
        border-top: 1px solid #e5e7eb;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
        padding: 0.75rem 1rem;
        gap: 0.625rem;
        align-items: center;
    }

    .mobile-purchase-bar .purchase-price {
        font-size: 1.25rem;
        font-weight: 700;
        color: #059669;
        white-space: nowrap;
        min-width: 0;
        flex-shrink: 0;
    }

    .mobile-purchase-bar .purchase-actions {
        display: flex;
        gap: 0.5rem;
        flex: 1;
    }

    .mobile-purchase-bar .purchase-actions .btn {
        flex: 1;
        padding: 0.75rem 0.5rem;
        font-size: 0.875rem;
        font-weight: 600;
        border-radius: 10px;
        white-space: nowrap;
    }

    /* Reserve space for sticky bar */
    .product-detail {
        padding-bottom: 80px !important;
    }

    /* Tighter gallery on mobile */
    .product-gallery {
        padding: 0.75rem 0.5rem;
    }

    .product-detail .row.gx-5 {
        --bs-gutter-x: 0;
    }

    /* Tighter product info spacing */
    .product-detail .col-lg-6.d-flex {
        padding-top: 1rem;
    }

    /* Collapsible sections */
    .detail-collapse-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem 0;
        border-bottom: 1px solid #e5e7eb;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .detail-collapse-header h5 {
        margin: 0;
        font-size: 1rem;
        font-weight: 600;
    }

    .detail-collapse-header .collapse-icon {
        transition: transform 0.2s ease;
        color: #6b7280;
    }

    .detail-collapse-header[aria-expanded="true"] .collapse-icon {
        transform: rotate(180deg);
    }
}

/* ============================================
   6. CART — MOBILE ENHANCEMENTS
   ============================================ */
@media (max-width: 767.98px) {
    .cart-item {
        padding: 1rem;
        gap: 0.75rem;
        position: relative;
    }

    .cart-item-product {
        width: 100%;
    }

    .cart-item-image {
        width: 72px;
        height: 72px;
        border-radius: 10px;
    }

    .cart-item-title {
        font-size: 0.875rem;
        white-space: normal;
        -webkit-line-clamp: 2;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .cart-item-remove {
        position: absolute;
        top: 0.75rem;
        right: 0.75rem;
    }

    .cart-items-card {
        border-radius: 12px;
    }

    .cart-page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .cart-page-header .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   7. CHECKOUT — MOBILE FORM OPTIMIZATION
   ============================================ */
@media (max-width: 767.98px) {
    .checkout-container {
        padding: 0;
    }

    .checkout-container .form-control,
    .checkout-container .form-select {
        font-size: 16px;
        padding: 0.75rem 1rem;
        border-radius: 10px;
        min-height: 48px;
    }

    .checkout-container .form-label {
        font-size: 0.875rem;
        font-weight: 600;
        margin-bottom: 0.375rem;
    }

    .checkout-container .mb-3 {
        margin-bottom: 1rem !important;
    }

    .payment-method-card {
        padding: 1rem;
    }

    .payment-method-card .payment-icon {
        width: 40px;
        height: 40px;
    }

    .checkout-stepper {
        padding: 0 0.5rem;
    }

    .checkout-stepper li::after {
        width: 24px;
        margin: 0 0.375rem;
    }
}

/* ============================================
   8. NAVIGATION — MOBILE SEARCH ENHANCEMENT
   ============================================ */
@media (max-width: 991.98px) {
    .mobile-search-bar .search-input-group input {
        font-size: 16px;
        padding: 0.625rem 0.875rem;
        min-height: 28px;
    }

    .mobile-search-bar .search-input-group button {
        padding: 0.625rem 1rem;
        min-height: 28px;
    }

    .mobile-nav-link {
        padding: 0.875rem 1rem;
        min-height: 48px;
    }
}

/* ============================================
   9. FILTER BAR — MOBILE OPTIMIZATION
   ============================================ */
@media (max-width: 575.98px) {
    .filter-bar {
        flex-direction: column;
        padding: 0.75rem;
        gap: 0.5rem;
        border-radius: 10px;
        margin-bottom: 1rem;
    }

    .filter-bar .search-input {
        width: 100%;
        min-width: unset;
    }

    .filter-bar .search-input input {
        font-size: 16px;
        padding: 0.75rem;
        min-height: 28px;
    }

    .filter-bar .sort-select {
        width: 100%;
        min-width: unset;
    }

    .filter-bar .sort-select select {
        font-size: 16px;
        padding: 0.75rem 2.5rem 0.75rem 0.75rem;
        min-height: 28px;
    }

    .filter-bar .btn {
        width: 100%;
    }

    .mobile-filter-btn {
        min-height: 48px;
        font-size: 0.9375rem;
        border-radius: 10px;
    }

    .shop-header h1 {
        font-size: 1.375rem;
    }

    .shop-header .results-count {
        font-size: 0.8125rem;
    }
}

/* ============================================
   10. TABLES — RESPONSIVE SCROLL CONTAINERS
   ============================================ */
.table-responsive-enterprise {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: -ms-autohiding-scrollbar;
}

@media (max-width: 767.98px) {
    .table-responsive-enterprise {
        border: 1px solid #e5e7eb;
        border-radius: 8px;
    }

    .table-responsive-enterprise table {
        min-width: 600px;
    }

    .table-responsive-enterprise::after {
        content: '← Scroll →';
        display: block;
        text-align: center;
        padding: 0.375rem;
        font-size: 0.6875rem;
        color: #9ca3af;
        background: #f9fafb;
        border-top: 1px solid #e5e7eb;
    }
}

/* ============================================
   11. FOOTER — MOBILE IMPROVEMENTS
   ============================================ */
@media (max-width: 575.98px) {
    .footer-main {
        padding: 2rem 0 !important;
    }

    .footer-main .row > [class*="col-"] {
        text-align: center;
    }

    .footer-brand {
        justify-content: center;
    }

    .footer-contact {
        text-align: center;
    }

    .footer-social {
        justify-content: center;
    }

    .footer-links {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0 1rem;
    }

    .footer-links li {
        margin-bottom: 0.25rem;
    }

    .footer-main form.d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }

        .footer-main form.d-flex input {
            font-size: 16px;
            min-height: 28px;
        }

        .footer-main form.d-flex button {
            min-height: 28px;
        }

    .trust-item {
        font-size: 0.6875rem;
    }
}

/* ============================================
   12. HOME PAGE — MOBILE HERO & SECTIONS
   ============================================ */
@media (max-width: 575.98px) {
    .enterprise-hero {
        padding: 2.5rem 0;
    }

    .hero-title {
        font-size: 1.75rem !important;
        line-height: 1.25;
    }

    .hero-subtitle {
        font-size: 0.9375rem;
    }

    .hero-actions {
        flex-direction: column;
    }

    .hero-btn {
        width: 100%;
        justify-content: center;
        padding: 0.875rem 1.25rem;
    }

    .hero-stats {
        gap: 1rem;
        justify-content: space-around;
    }

    .hero-stat-value {
        font-size: 1.5rem;
    }

    .hero-stat-label {
        font-size: 0.75rem;
    }

    .section {
        padding: 2.5rem 0;
    }

    .section-title {
        font-size: 1.375rem;
    }

    .section-subtitle {
        font-size: 0.875rem;
    }

    .section-header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
}

/* ============================================
   13. MY ORDERS — MOBILE CARD LAYOUT
   ============================================ */
@media (max-width: 575.98px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.625rem;
    }

    .stat-card {
        padding: 0.875rem 0.75rem;
    }

    .stat-card .stat-value {
        font-size: 1.25rem;
    }

    .stat-card .stat-label {
        font-size: 0.6875rem;
    }
}

/* ============================================
   14. BREADCRUMB — MOBILE FIX
   ============================================ */
@media (max-width: 575.98px) {
    .user-breadcrumb .breadcrumb {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
        overflow-x: auto;
        flex-wrap: nowrap;
        white-space: nowrap;
    }

    .user-breadcrumb .breadcrumb-item {
        flex-shrink: 0;
    }
}

/* ============================================
   15. MODAL & DROPDOWN — MOBILE FIXES
   ============================================ */
@media (max-width: 575.98px) {
    .mini-cart-dropdown {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        min-width: 100% !important;
        max-height: 70vh;
        border-radius: 16px 16px 0 0 !important;
        transform: none !important;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.15) !important;
    }

    .enterprise-dropdown-menu:not(.mini-cart-dropdown) {
        width: calc(100vw - 2rem);
        max-width: 320px;
    }
}

/* ============================================
   16. ALERT MESSAGES — MOBILE SPACING
   ============================================ */
@media (max-width: 575.98px) {
    .user-alert {
        font-size: 0.8125rem;
        padding: 0.75rem 1rem;
    }

    .user-alert .btn-close {
        padding: 0.875rem;
    }
}

/* ============================================
   17. ROLE CONTEXT BANNER — MOBILE
   ============================================ */
@media (max-width: 575.98px) {
    .role-context-banner .container {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem !important;
    }

    .role-context-banner .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   18. PAGINATION — MOBILE OPTIMIZATION
   ============================================ */
@media (max-width: 575.98px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }

    .pagination .page-link {
        min-width: 40px;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.375rem;
        font-size: 0.8125rem;
    }

    .page-item {
        padding: 2px;
    }
}

/* ============================================
   19. SPACING UTILITIES — MOBILE OVERRIDES
   ============================================ */
@media (max-width: 575.98px) {
    .container.py-4 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    .container.mt-4 {
        margin-top: 0.75rem !important;
    }

    .gx-5 {
        --bs-gutter-x: 1rem;
    }
}

/* ============================================
   20. SMOOTH SCROLLING & PERFORMANCE
   ============================================ */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .product-card:hover,
    .enterprise-product-card:hover,
    .category-card:hover,
    .merchant-card:hover {
        transform: none !important;
        transition: none !important;
    }
}

/* Optimize scroll performance */
.mobile-nav-drawer,
.mobile-cat-drawer,
.mobile-nav-body,
.mobile-cat-body,
.category-sidebar-body,
.mini-cart-body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ============================================
   21. STORE PAGES — MOBILE GRID
   ============================================ */
@media (max-width: 575.98px) {
    .merchant-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.625rem;
    }

    .merchant-card {
        padding: 1rem 0.75rem;
        border-radius: 12px;
    }

    .merchant-avatar {
        width: 56px;
        height: 56px;
    }

    .merchant-name {
        font-size: 0.8125rem;
    }

    .merchant-desc {
        font-size: 0.6875rem;
        -webkit-line-clamp: 1;
    }

    .category-grid {
        gap: 0.625rem;
    }

    .category-card {
        padding: 1rem 0.75rem;
        border-radius: 12px;
    }

    .category-icon {
        width: 48px;
        height: 48px;
        border-radius: 12px;
    }

    .category-icon i {
        font-size: 1.25rem;
    }

    .category-name {
        font-size: 0.8125rem;
    }

    .category-count {
        font-size: 0.6875rem;
    }
}

/* ============================================
   22. SAFE AREA SUPPORT (iOS notch)
   ============================================ */
@supports (padding: env(safe-area-inset-bottom)) {
    .mobile-purchase-bar {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }

    .cart-layout {
        padding-bottom: calc(140px + env(safe-area-inset-bottom));
    }

    .enterprise-mobile-header {
        padding-top: env(safe-area-inset-top);
    }
}

/* ============================================
   23. PRINT STYLES — HIDE MOBILE CHROME
   ============================================ */
@media print {
    .enterprise-mobile-header,
    .mobile-search-bar,
    .mobile-nav-backdrop,
    .mobile-nav-drawer,
    .mobile-purchase-bar,
    .mobile-filter-btn,
    .mobile-cat-overlay {
        display: none !important;
    }
}

/* ============================================
   24. AUTH FORMS — MOBILE OPTIMIZATION
   Prevent iOS zoom on input focus (requires
   font-size ≥ 16px) and improve touch targets.
   ============================================ */
@media (max-width: 575.98px) {
    .card .form-control,
    .card .form-select {
        font-size: 16px;
    }

    .card .form-control-lg {
        font-size: 16px;
        padding: 0.75rem 1rem;
    }

    .card .card-body {
        padding: 1.5rem 1.25rem;
    }

    .card .btn.w-100.py-3,
    .card .btn.w-100 {
        min-height: 52px;
        font-size: 1rem;
    }
}

/* ============================================
   25. MERCHANT DASHBOARD — MOBILE
   ============================================ */
@media (max-width: 767.98px) {
    .merchant-page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .merchant-page-header .page-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
    }

    .merchant-page-header .page-actions .btn {
        flex: 1;
        text-align: center;
        font-size: 0.8125rem;
        padding: 0.5rem;
    }

    .merchant-card .card-footer .d-flex.gap-2 .btn {
        min-width: 44px;
        min-height: 28px;
    }
}

@media (max-width: 575.98px) {
    .merchant-page-header .page-heading {
        font-size: 1.25rem;
    }

    .merchant-page-header .page-subtitle {
        font-size: 0.8125rem;
    }
}

/* ============================================
   26. ADMIN DASHBOARD — MOBILE
   ============================================ */
@media (max-width: 767.98px) {
    .admin-card .card-body .d-flex.gap-2 {
        flex-wrap: wrap;
    }

    .admin-card .card-body .d-flex.gap-2 .btn {
        flex: 1;
        min-width: 120px;
    }
}

/* ============================================
   27. ULTRA-SMALL SCREENS (320px)
   iPhone SE, Galaxy Fold, etc.
   ============================================ */
@media (max-width: 359.98px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .enterprise-product-card .product-card-body {
        padding: 0.5rem;
    }

    .enterprise-product-card .product-card-title {
        font-size: 0.75rem;
    }

    .enterprise-product-card .product-current-price {
        font-size: 0.875rem;
    }

    .enterprise-product-card .product-card-actions {
        flex-direction: column;
    }

    .enterprise-product-card .product-btn {
        width: 100%;
        font-size: 0.625rem;
    }

    .hero-title {
        font-size: 1.5rem !important;
    }

    .hero-btn {
        font-size: 0.875rem;
        padding: 0.75rem 1rem;
    }

    .mobile-purchase-bar .purchase-price {
        font-size: 1rem;
    }

    .mobile-purchase-bar .purchase-actions .btn {
        font-size: 0.8125rem;
        padding: 0.625rem 0.375rem;
    }

    .order-card-body {
        padding: 0.75rem;
    }

    .stat-card {
        padding: 0.625rem 0.5rem;
    }
}

/* ============================================
   28. FORM FIELD IMPROVEMENTS — ALL SCREENS
   Ensure consistent input sizing and prevent
   iOS zoom on all form pages.
   ============================================ */
@media (max-width: 767.98px) {
    input[type="email"],
    input[type="text"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="search"],
    input[type="url"],
    input[type="date"],
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* ============================================
   29. CARD ACTIONS — MOBILE STACKING
   Ensure card action rows wrap properly.
   ============================================ */
@media (max-width: 575.98px) {
    .card-header .d-flex.justify-content-between {
        flex-direction: column;
        gap: 0.5rem;
    }

    .card-header .d-flex.justify-content-between > .btn,
    .card-header .d-flex.justify-content-between > .badge {
        align-self: flex-start;
    }
}

/* ============================================
   30. REFUND PAGES — MOBILE
   ============================================ */
@media (max-width: 575.98px) {
    .list-group-item .d-flex.justify-content-between {
        flex-direction: column;
        gap: 0.5rem;
    }

    .list-group-item .text-end {
        text-align: left !important;
    }
}
