/* =====================================================================
   Mobile UX layer — loaded AFTER app.css. Isolated, phase-based.
   CSS only + hooks for mobile-ux.js. Desktop (>768px) untouched.
   ===================================================================== */

/* ---------- Back-to-top (all viewports, thumb-reachable on mobile) ---------- */
.back-to-top {
  position: fixed;
  left: 18px;
  right: auto;
  bottom: calc(var(--mobile-bottom-nav-h, 74px) + 18px + env(safe-area-inset-bottom, 0px));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(151, 164, 204, .28);
  background: rgba(17, 24, 47, .82);
  color: #cfe3ff;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .38);
  display: grid;
  place-items: center;
  font-size: 18px;
  z-index: 1180;
  opacity: 0;
  transform: translateY(14px) scale(.9);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.back-to-top.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.back-to-top:active { transform: scale(.92); }
@media (min-width: 769px) {
  .back-to-top { bottom: 24px; left: 24px; right: auto; }
}

/* ---------- WhatsApp FAB auto-hide while scrolling down ---------- */
.whatsapp-fab {
  transition: transform .28s cubic-bezier(.4, 0, .2, 1), opacity .28s ease;
}
.whatsapp-fab.fab-hidden {
  transform: translateY(160%) scale(.85);
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 768px) {
  /* ---------- PHASE 1: layout correctness & consistency ---------- */

  /* Consistent radius across primary surfaces */
  :root { --mobile-card-radius: 20px; }

  /* Tap feedback for interactive surfaces (instant, <100ms feel) */
  .product-card,
  .pinned-product-card,
  .stat-card,
  .trust-item,
  .btn,
  .header-wallet-chip,
  .mobile-bottom-nav a {
    -webkit-tap-highlight-color: transparent;
  }
  .product-card:active,
  .pinned-product-card:active,
  .btn:active,
  .header-wallet-chip:active {
    transform: scale(.985);
  }
  .product-card,
  .pinned-product-card,
  .btn,
  .header-wallet-chip {
    transition: transform .12s ease, box-shadow .18s ease, border-color .18s ease;
  }

  /* Respect reduced-motion */
}

@media (prefers-reduced-motion: reduce) {
  .whatsapp-fab,
  .back-to-top,
  .product-card,
  .pinned-product-card,
  .btn { transition: none !important; }
  html { scroll-behavior: auto !important; }
}

/* =====================================================================
   PHASE 2 — Product browsing
   ===================================================================== */

/* Category chips: hidden on desktop (keep desktop layout untouched) */
.category-chips { display: none; }

@media (max-width: 768px) {
  /* ---- Sticky search so it's always reachable while browsing ---- */
  .products-header {
    position: sticky;
    top: 0;
    z-index: 60;
    background: rgba(9, 13, 28, .86);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    margin-inline: calc(var(--mobile-page-gutter, 14px) * -1);
    padding: 10px var(--mobile-page-gutter, 14px) 8px;
    border-bottom: 1px solid rgba(151, 164, 204, .12);
  }
  .products-search-inline { width: 100%; }

  /* ---- Category chips: horizontal snap scroller ---- */
  .category-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    padding: 2px var(--mobile-page-gutter, 14px) 2px;
    margin-inline: calc(var(--mobile-page-gutter, 14px) * -1);
    scrollbar-width: none;
    position: sticky;
    top: 62px;
    z-index: 55;
  }
  .category-chips::-webkit-scrollbar { display: none; }
  .category-chip {
    flex: 0 0 auto;
    scroll-snap-align: start;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    color: #cdd7f0;
    background: rgba(20, 28, 52, .7);
    border: 1px solid rgba(151, 164, 204, .18);
    text-decoration: none;
    transition: transform .12s ease, background .18s ease, border-color .18s ease;
  }
  .category-chip:active { transform: scale(.95); }
  .category-chip.is-active {
    color: #04121f;
    background: linear-gradient(135deg, #22e0d0, #4da6ff);
    border-color: transparent;
  }

  /* ---- Compact product cards: fit ~2 per screen, less endless scroll ---- */
  .product-card-image-wrapper,
  html[data-theme="dark"] .product-card-image-wrapper {
    height: 120px !important;
    min-height: 120px !important;
    margin: 10px 10px 0 !important;
    padding: 10px !important;
    display: grid !important;
    place-items: center !important;
    overflow: hidden !important;
  }

  /* Logo must fully fit the compact box (percentage max-height doesn't resolve
     inside the grid/contained wrapper, so pin an absolute px cap → no clipping). */
  .product-card-image-wrapper .product-card-image,
  html[data-theme="dark"] .product-card-image-wrapper .product-card-image,
  html[data-theme="dark"] .product-card-image {
    width: auto !important;
    height: auto !important;
    max-width: 82% !important;
    max-height: 96px !important;
    object-fit: contain !important;
    object-position: center !important;
    margin: auto !important;
  }
  .product-card-body { padding: 12px 14px 14px !important; gap: 6px; }
  .product-card-title {
    font-size: 15px !important;
    line-height: 1.25;
    margin-bottom: 2px;
  }
  .product-card-desc,
  html[data-theme="dark"] .product-card-desc {
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    font-size: 12.5px !important;
    line-height: 1.4 !important;
    margin: 2px 0 4px !important;
  }
  .product-card-actions-inline {
    display: flex !important;
    grid-template-columns: none !important;
    flex-direction: row !important;
    gap: 16px !important;
    margin: 2px 0 4px !important;
  }
  .product-card-details-link { font-size: 12px !important; }
  .product-sales-count { font-size: 11.5px !important; margin: 0 0 2px !important; }
  .product-card-meta { margin-top: 4px !important; }
  .product-price-amount { font-size: 19px !important; }
  .product-price-usd { font-size: 10.5px !important; }
  .btn-buy.btn-block,
  .btn-out-of-stock.btn-block {
    min-height: 46px !important;
    margin-top: 8px !important;
    border-radius: 14px !important;
  }
}

/* =====================================================================
   PHASE 3 — Purchase & wallet flow
   ===================================================================== */

/* Per-item copy button on delivered credentials (all viewports) */
.delivered-item-row { position: relative; }
.delivered-item-row code { padding-right: 44px !important; }
.delivered-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid rgba(151, 164, 204, .22);
  background: rgba(24, 231, 255, .10);
  color: #7fe9ff;
  font-size: 15px;
  cursor: pointer;
  transition: transform .12s ease, background .18s ease, color .18s ease;
}
.delivered-copy-btn:active { transform: scale(.9); }
.delivered-copy-btn.is-copied {
  background: rgba(16, 185, 129, .18);
  color: #34d399;
  border-color: rgba(16, 185, 129, .4);
}
.delivered-copy-btn.is-copied .bi::before { content: "\F26E"; } /* bi-check-lg */

@media (max-width: 768px) {
  /* Bottom-sheet for ALL modals on phones (not just <=575) */
  .modal.show .modal-dialog {
    min-height: 100dvh;
    display: flex;
    align-items: flex-end;
    margin: 0;
    max-width: 100%;
    width: 100%;
  }
  .modal.show .modal-content {
    width: 100%;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    padding-top: 10px;
  }
  /* Grab handle */
  .modal.show .modal-content::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 5px;
    border-radius: 999px;
    background: rgba(151, 164, 204, .38);
    z-index: 5;
  }
  /* One-thumb sticky footer actions */
  .modal-footer,
  .order-items-modal .modal-footer {
    flex-direction: column-reverse !important;
    align-items: stretch !important;
    position: sticky;
    bottom: 0;
    gap: 10px;
    background: rgba(9, 13, 28, .96);
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .modal-footer .btn,
  .modal-footer button,
  .order-items-modal .modal-footer .btn {
    width: 100% !important;
    min-height: 50px !important;
    justify-content: center !important;
    border-radius: 14px !important;
    font-size: 15px;
  }

  /* Bigger delivered-item copy target on phones */
  .delivered-copy-btn { width: 40px; height: 40px; font-size: 17px; }
  .delivered-item-row code { padding-right: 50px !important; }

  /* Top-up preset amount chips: thumb-friendly */
  .amt-presets { gap: 10px; }
  .amt-chip {
    min-height: 46px;
    min-width: 72px;
    font-size: 15px;
    border-radius: 14px;
  }
}

/* =====================================================================
   PHASE 4 — Navigation polish
   ===================================================================== */
@media (max-width: 1024px) {
  /* Active bottom-nav item: pill highlight + top accent for clear orientation */
  .mobile-bottom-nav a {
    position: relative;
    transition: color .18s ease, transform .12s ease;
  }
  .mobile-bottom-nav a.active {
    color: #6ee7ff;
  }
  .mobile-bottom-nav a.active::before {
    content: "";
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 26px;
    height: 3px;
    border-radius: 999px;
    background: linear-gradient(90deg, #22e0d0, #4da6ff);
  }
  .mobile-bottom-nav a.active i { transform: translateY(-1px); }
  .mobile-bottom-nav a:active { transform: scale(.92); }

  /* Smoother drawer slide */
  .sidebar {
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
    will-change: transform;
  }
  .sidebar-overlay { transition: opacity .24s ease; }
}

/* =====================================================================
   PHASE 5 — Perceived performance & feel
   ===================================================================== */
@media (max-width: 768px) {
  /* Prevent iOS/Android auto text inflation on rotate */
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

  /* Fixed aspect for product images → no layout shift while lazy-loading */
  .product-card-image { aspect-ratio: auto; }
  .product-card-image-wrapper { contain: layout paint; }

  /* Momentum scrolling for horizontal rows */
  [data-chip-scroll],
  .category-chips { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }

  /* Skip repaint work for far-offscreen product cards (keeps scroll smooth) */
  .products-grid .product-card { content-visibility: auto; contain-intrinsic-size: 480px; }
}

/* =====================================================================
   PHASE 6 — Data-dense screens (stack the one table without a wrapper)
   Other tables already stack via .table-wrapper/.table-responsive/.glass-table.
   ===================================================================== */
@media (max-width: 640px) {
  .gift-history { overflow: visible; }
  .gift-table { width: 100%; min-width: 0; border-collapse: separate; border-spacing: 0 12px; }
  .gift-table thead { display: none; }
  .gift-table tbody, .gift-table tr, .gift-table td { display: block; width: 100%; }
  .gift-table tr {
    padding: 14px;
    margin-bottom: 12px;
    border: 1px solid rgba(151, 164, 204, .18);
    border-radius: 16px;
    background: rgba(10, 16, 32, .86);
  }
  .gift-table td {
    display: grid;
    grid-template-columns: minmax(84px, 36%) minmax(0, 1fr);
    gap: 10px;
    padding: 7px 0;
    border: 0;
    color: #eef6ff;
    word-break: break-word;
  }
  .gift-table td::before {
    content: attr(data-label);
    color: #97a4cc;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
  }
}
