
/* ============================================================
   SHIPPERSHOP MOBILE.CSS - Mobile-First Optimization
   Target: Touch screen, 360px-430px phones
   ============================================================ */

/* ========================
   1. BASE MOBILE RESETS
   ======================== */
:root {
  --mobile-nav-h: 60px;
  --header-h: 54px;
  --primary: #7C3AED;
  --primary-dark: #5B21B6;
  --touch-min: 44px;
}

/* ========================
   PERFORMANCE CRITICAL
   ======================== */

/* GPU compositing for fixed/sticky elements */
#mobileBottomNav {
  will-change: transform;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform: translateZ(0);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.6, 1) !important;
  contain: layout style;
}

#backToTop {
  will-change: transform, opacity;
  transform: translateZ(0);
}

/* Reduce paint area for cards */
.product-card {
  contain: layout style paint;
  transform: translateZ(0);
}

/* Fix transition: none; }

/* Re-enable ONLY specific transitions we want */
.product-card     { transition: box-shadow 0.15s, transform 0.15s !important; }
.btn              { transition: background 0.15s, transform 0.12s !important; }
.header-btn       { transition: opacity 0.15s !important; }
#mobileBottomNav  { transition: transform 0.2s cubic-bezier(0.4,0,0.6,1) !important; }
#backToTop        { transition: opacity 0.2s, transform 0.2s !important; }
.modal            { transition: transform 0.28s cubic-bezier(0.32,0.72,0,1) !important; }
.modal-overlay    { transition: opacity 0.2s !important; }
.sort-btn         { transition: background 0.12s !important; }
.sidebar-item     { transition: background 0.12s !important; }
#pullInd          { transition: transform 0.15s !important; }

/* Prevent scroll jank with overscroll-behavior */
body {
  overscroll-behavior-y: contain;
}

/* Hardware accelerate scroll containers */
.province-list,
.flash-sale-grid,
.mobile-filter-bar,
.product-list-scroll {
  -webkit-overflow-scrolling: touch;
  will-change: scroll-position;
}

/* Reduce repaints on images */
img {
  /* img contain removed */
}

/* Prevent layout shift from images */
.product-card img {
  aspect-ratio: 1;
  width: 100%;
}


/* Smooth scrolling everywhere */
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

/* Better tap highlights */
a, button, [onclick] {
  -webkit-tap-highlight-color: rgba(238, 77, 45, 0.1);
}

/* Remove hover on touch */
@media (hover: none) {
  a:hover, button:hover { opacity: 1 !important; }
}

/* ========================
   2. RESPONSIVE BREAKPOINTS
   ======================== */
@media (max-width: 768px) {

  /* --- HEADER --- */
  .header-top { display: none !important; } /* Ẩn hotline/email strip */

  .header-main {
    position: sticky;
    top: 0;
    z-index: 500;
    padding: 8px 0;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
  }

  .header-content {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
  }

  .logo {
    font-size: 18px !important;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .search-bar {
    flex: 1;
    order: 0 !important;
    max-width: none !important;
    margin: 0;
  }

  .search-bar input {
    height: 36px;
    font-size: 14px;
    padding: 0 10px;
    border-radius: 20px;
  }

  .search-bar button {
    width: 36px;
    height: 36px;
    border-radius: 0 20px 20px 0;
  }

  .header-actions {
    flex-wrap: nowrap !important;
    gap: 4px;
    flex-shrink: 0;
  }

  .header-btn span:not(.cart-badge) { display: none !important; }
  .header-btn {
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    padding: 0 8px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border-radius: 8px;
  }

  /* Cart badge bigger */
  .cart-badge {
    font-size: 10px !important;
    min-width: 18px;
    height: 18px;
    top: 4px !important;
    right: 2px !important;
  }

  /* --- DESKTOP NAV → HIDDEN --- */
  header > nav, .nav-menu { display: none !important; }

  /* --- BOTTOM MOBILE NAV (app-style) --- */
  #mobileBottomNav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-h);
    background: #fff;
    border-top: 1px solid #e8e8e8;
    display: flex !important;
    align-items: center;
    z-index: 1000;
    box-shadow: 0 -2px 12px rgba(0,0,0,.1);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .mnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 100%;
    cursor: pointer;
    text-decoration: none;
    color: #999;
    font-size: 10px;
    font-weight: 600;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    transition: color .2s;
  }

  .mnav-item i { font-size: 20px; transition: transform .15s; }
  .mnav-item.active { color: var(--primary); }
  .mnav-item.active i { transform: scale(1.1); }
  .mnav-item:active i { transform: scale(0.9); }

  /* Center FAB button */
  .mnav-fab {
    width: 52px;
    height: 52px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 22px;
    box-shadow: 0 4px 12px rgba(238,77,45,.5);
    margin-top: -24px;
    flex-shrink: 0;
  }
  .mnav-fab:active { transform: scale(0.92); }

  /* Badge on nav */
  .mnav-badge {
    position: absolute;
    top: 4px;
    right: 50%;
    transform: translateX(8px);
    background: var(--primary);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
  }

  /* Push content above bottom nav */
  body { padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important; }
  body.no-bottom-nav { padding-bottom: 0 !important; }

  /* --- HERO → COMPACT --- */
  .hero {
    padding: 24px 16px !important;
    min-height: auto !important;
  }

  .hero h1 { font-size: 22px !important; line-height: 1.3; }
  .hero p { font-size: 14px !important; margin-top: 8px; }

  .hero > div > div { text-align: center; }
  .hero > div > div > div { justify-content: center !important; gap: 10px; flex-wrap: wrap; }

  /* --- CATEGORIES STRIP → HORIZONTAL SCROLL --- */
  .categories-strip, .category-strip, .filter-tabs {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 8px;
    padding: 10px 12px;
    scroll-snap-type: x mandatory;
  }
  .categories-strip::-webkit-scrollbar { display: none; }

  .category-item, .filter-tab {
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  /* --- PRODUCTS GRID --- */
  .products-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    padding: 0 10px;
  }

  .product-card {
    border-radius: 10px;
  }

  .product-card img {
    height: 160px !important;
    object-fit: cover;
  }

  .product-info { padding: 8px 10px 10px !important; }
  .product-info h3 { font-size: 13px !important; line-height: 1.3; -webkit-line-clamp: 2; }
  .product-price { font-size: 15px !important; }
  .product-original { font-size: 11px !important; }

  /* Add to cart button on product card - bigger touch target */
  .btn-add-cart, .product-btn, .add-to-cart {
    min-height: var(--touch-min) !important;
    font-size: 13px !important;
    border-radius: 8px !important;
  }

  /* --- SECTION HEADERS --- */
  .section-header {
    padding: 0 12px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .section-title { font-size: 18px !important; }

  /* --- GENERAL CONTAINER --- */
  .container { padding: 0 10px !important; }

  /* --- FLASH SALE STRIP → SCROLL --- */
  .flash-sale-grid {
    display: flex !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 10px;
    padding: 10px 12px;
  }
  .flash-sale-grid::-webkit-scrollbar { display: none; }
  .flash-sale-grid .product-card {
    min-width: 150px;
    flex-shrink: 0;
  }

  /* --- BUTTONS GLOBAL --- */
  .btn {
    min-height: var(--touch-min) !important;
    padding: 10px 20px !important;
    font-size: 14px !important;
    border-radius: 10px !important;
  }

  /* --- FORMS --- */
  input, textarea, select {
    font-size: 16px !important; /* Prevent iOS zoom */
    min-height: var(--touch-min);
  }

  /* --- MODALS → SLIDE UP FROM BOTTOM --- */
  .modal-overlay {
    padding: 0 !important;
    align-items: flex-end !important;
  }

  .modal, .modal-content {
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh;
    overflow-y: auto;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Modal drag indicator */
  .modal-head::before, .modal::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(255,255,255,.4);
    border-radius: 2px;
    margin: 0 auto 8px;
  }

  /* --- CART PAGE --- */
  .cart-container { grid-template-columns: 1fr !important; gap: 16px; }
  .cart-summary { position: static !important; }
  .cart-item { flex-wrap: wrap; gap: 8px; }
  .cart-item img { width: 72px !important; height: 72px !important; }

  /* --- CHECKOUT / FORM PAGES --- */
  .checkout-container, .auth-container {
    padding: 16px !important;
    max-width: 100% !important;
  }

  /* --- PRODUCT DETAIL --- */
  .product-detail { flex-direction: column !important; }
  .product-detail-img { width: 100% !important; }
  .product-detail-info { padding: 16px !important; }

  /* --- FOOTER → COMPACT ON MOBILE --- */
  footer .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 20px;
  }

  footer { padding: 24px 12px !important; }

  /* --- COMMUNITY / POSTS --- */
  .post-card { border-radius: 0 !important; margin-bottom: 8px; }
  .vote-col { width: 36px; }

  /* --- WALLET --- */
  .wallet-card { border-radius: 16px !important; }

  /* --- TABLES → SCROLL --- */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* --- BACK TO TOP BUTTON --- */
  #backToTop {
    position: fixed;
    bottom: calc(var(--mobile-nav-h) + 12px);
    right: 14px;
    width: 42px;
    height: 42px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    z-index: 400;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(238,77,45,.4);
    transition: .2s;
  }
  #backToTop.visible { display: flex; }
  #backToTop:active { transform: scale(0.9); }

  /* --- TOAST POSITION MOBILE --- */
  .toast {
    bottom: calc(var(--mobile-nav-h) + 12px) !important;
    left: 12px !important;
    right: 12px !important;
    text-align: center;
  }

  /* --- SEARCH PAGE --- */
  .search-results { padding: 0 10px; }

  /* --- PROFILE --- */
  .profile-header { padding: 20px 12px !important; }
  .profile-grid { grid-template-columns: 1fr !important; }
  .profile-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .profile-tab { flex-shrink: 0; }

  /* --- HIDE ON MOBILE --- */
  .desktop-only, .header-top, header > nav { display: none !important; }

  /* --- SHOW ON MOBILE ONLY --- */
  .mobile-only { display: block !important; }

  /* --- SWIPE INDICATOR --- */
  .swipe-hint {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #999;
    padding: 0 12px 6px;
  }

  /* --- PRODUCT IMAGE GALLERY → SWIPE --- */
  .gallery-strip {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .gallery-strip::-webkit-scrollbar { display: none; }
  .gallery-strip img { scroll-snap-align: center; }

  /* --- STICKY BUY BUTTON ON PRODUCT PAGE --- */
  .sticky-buy-bar {
    position: fixed;
    bottom: var(--mobile-nav-h);
    left: 0;
    right: 0;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #eee;
    z-index: 200;
    display: flex;
    gap: 8px;
    box-shadow: 0 -2px 8px rgba(0,0,0,.08);
  }
  .sticky-buy-bar .btn { flex: 1; }

  /* Grid adjustments for product pages */
  .section-actions a, .section-actions button {
    font-size: 13px;
    padding: 8px 14px;
  }

  /* Admin tables */
  .admin-table { font-size: 12px; }
  .admin-table th, .admin-table td { padding: 8px 6px; }
}

/* ========================
   3. EXTRA SMALL (< 360px)
   ======================== */
@media (max-width: 360px) {
  .products-grid { gap: 8px !important; }
  .product-card img { height: 130px !important; }
  .header-btn { min-width: 36px; padding: 0 6px !important; }
  .mnav-item { font-size: 9px; }
  .mnav-item i { font-size: 18px; }
}

/* ========================
   4. LANDSCAPE PHONE
   ======================== */
@media (max-width: 768px) and (orientation: landscape) {
  .hero { padding: 16px !important; }
  .hero h1 { font-size: 18px !important; }
  #mobileBottomNav { height: 50px; }
  body { padding-bottom: 50px !important; }
}

/* ========================
   5. TABLET (769-1024px)
   ======================== */
@media (min-width: 769px) and (max-width: 1024px) {
  .products-grid { grid-template-columns: repeat(3, 1fr) !important; }
  .container { padding: 0 16px !important; }
  #mobileBottomNav { display: none !important; }
  .mobile-only { display: none !important; }
}

/* ========================
   6. DESKTOP
   ======================== */
@media (min-width: 1025px) {
  #mobileBottomNav, #backToTop { display: none !important; }
  .mobile-only { display: none !important; }
}

/* ========================
   7. PWA / SAFE AREAS
   ======================== */
@supports (padding: max(0px)) {
  #mobileBottomNav {
    padding-bottom: max(env(safe-area-inset-bottom), 0px);
    height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
  }
  body { padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important; }
}

/* ========================
   8. TOUCH INTERACTION STATES
   ======================== */
.product-card:active { transform: scale(0.97); }
.btn:active { transform: scale(0.97); }
.mnav-item:active { background: rgba(238,77,45,.06); }

/* ========================
   9. LOADING SKELETON
   ======================== */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}

/* ========================
   10. TYPOGRAPHY MOBILE
   ======================== */
@media (max-width: 768px) {
  h1 { font-size: 22px !important; }
  h2 { font-size: 18px !important; }
  h3 { font-size: 16px !important; }
  p { font-size: 14px; line-height: 1.6; }
  body { font-size: 14px; }
}


/* ========================
   MOBILE NAV - v3 Classes
   ======================== */

/* Nav hidden state (JS adds/removes) */
#mobileBottomNav.nav-hidden {
  transform: translateY(100%) !important;
}

/* Pull indicator */
#pullIndicator {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--primary, #7C3AED);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 9999;
  transform: translateY(-100%);
  will-change: transform;
  transition: transform 0.15s;
  pointer-events: none;
}

/* Back to top visible state */
#backToTop {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}
#backToTop.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Cart badge in bottom nav */
#navCartBadge {
  position: absolute;
  top: 2px; right: 8px;
  background: #7C3AED;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

/* Profile avatar in nav */
#navProfileIcon img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}


/* ========================
   AUTH PAGES - No bottom nav
   (login, register pages have .auth-page div)
   ======================== */
body:has(.auth-page) #mobileBottomNav,
body:has(.auth-page) #backToTop,
body:has(.auth-page) #pullIndicator {
  display: none !important;
}

body:has(.auth-page) {
  padding-bottom: 0 !important;
}

/* Make sure auth form is fully scrollable */
.auth-page {
  padding-bottom: 30px !important;
}
