/* ============================================================
   XL ARMS — MOBILE RESPONSIVE OVERRIDES
   Applied on all pages via <link rel="stylesheet" href="mobile.css">
   Breakpoints:
     1024px — tablet landscape
      768px — tablet portrait
      480px — large phones
      375px — small phones (iPhone SE, etc.)
   ============================================================ */

/* ── 1. BASE TOUCH TARGETS & SCROLLING ───────────────────────── */

/* Prevent text-size inflation on iOS */
html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* Smooth scroll on the whole page */
html, body {
  scroll-behavior: smooth;
}

/* Make all tap targets at least 44px tall (WCAG) */
button,
a.btn,
.nav-category,
.cart-btn, .search-btn, .account-btn,
.add-to-cart,
.btn-checkout,
.btn-continue-shopping,
.filter-toggle-btn,
.mobile-filter-close {
  min-height: 44px;
}

/* ── 2. HAMBURGER / MOBILE NAV ───────────────────────────────── */

.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  padding: 10px;
  border-radius: 6px;
  transition: background 0.2s;
}

.mobile-menu-toggle:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

/* Hamburger icon bars */
.hamburger-bar {
  display: block;
  width: 22px;
  height: 2px;
  background: currentColor;
  margin: 5px 0;
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}

/* Animated X when open */
.mobile-menu-toggle[aria-expanded="true"] .hamburger-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.mobile-menu-toggle[aria-expanded="true"] .hamburger-bar:nth-child(2) {
  opacity: 0;
}
.mobile-menu-toggle[aria-expanded="true"] .hamburger-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── 3. STOREFRONT TABLET (≤1024px) ─────────────────────────── */

@media (max-width: 1024px) {
  .products-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }

  .nav-categories {
    gap: 20px;
  }

  .nav-search-input {
    width: 160px;
  }
}

/* ── 4. STOREFRONT TABLET PORTRAIT (≤768px) ──────────────────── */

@media (max-width: 768px) {

  /* --- Nav: show hamburger, hide desktop nav --- */
  .mobile-menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    order: -1;
  }

  .nav-categories {
    display: none !important;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: #0d0d0d;
    flex-direction: column;
    gap: 0;
    z-index: 1500;
    padding: 16px 0;
    overflow-y: auto;
  }

  .nav-categories.active {
    display: flex !important;
  }

  .nav-categories li {
    border-bottom: 1px solid #1f1f1f;
  }

  .nav-category {
    display: block;
    padding: 16px 24px;
    font-size: 17px;
  }

  .nav-category.deals-highlight {
    margin: 16px 24px;
    text-align: center;
    border-radius: 6px;
  }

  /* Dropdown inside mobile nav — always show */
  .nav-dropdown .dropdown-menu {
    display: none;
    position: static;
    background: #151515;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 4px 0 8px;
    min-width: unset;
  }

  .nav-dropdown.open .dropdown-menu {
    display: block;
  }

  /* --- Navbar padding --- */
  .nav-container {
    padding: 0 12px;
    gap: 8px;
  }

  /* Search bar: shrink significantly */
  .nav-search-input { width: 120px; }

  /* --- Product grid: 2 columns --- */
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  /* Reduce product card padding */
  .product-info {
    padding: 12px;
  }

  .product-image {
    height: 180px;
  }

  .product-name {
    font-size: 13px;
  }

  /* --- Storefront layout: sidebar hidden (handled by existing CSS), add-to-cart full width --- */
  .add-to-cart {
    width: 100%;
    padding: 12px;
    font-size: 14px;
  }

  /* --- Cart panel: full width on mobile --- */
  .cart-panel-content {
    max-width: 100%;
    border-radius: 0;
  }

  /* --- Filter toggle button (shown on mobile) --- */
  .filter-toggle-btn {
    display: flex !important;
    align-items: center;
    gap: 8px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 6px;
    color: #ccc;
    cursor: pointer;
    font-size: 14px;
    padding: 10px 16px;
    transition: border-color 0.2s, color 0.2s;
  }

  .filter-toggle-btn:hover {
    border-color: #dc2626;
    color: #fff;
  }

  /* Active filter count badge on the filter button */
  .filter-toggle-btn .filter-badge {
    background: #dc2626;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    line-height: 1.4;
    display: none;
  }

  .filter-toggle-btn.has-filters .filter-badge {
    display: inline;
  }

  /* --- Mobile filter drawer --- */
  .mobile-filter-drawer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2500;
    pointer-events: none;
  }

  .mobile-filter-drawer:not([hidden]) {
    pointer-events: auto;
  }

  .mobile-filter-drawer[hidden] {
    display: block !important;
    visibility: hidden;
  }

  .mobile-filter-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.65);
    opacity: 0;
    transition: opacity 0.3s;
  }

  .mobile-filter-drawer:not([hidden]) .mobile-filter-overlay {
    opacity: 1;
  }

  .mobile-filter-panel {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 90vw);
    background: #111;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .mobile-filter-drawer:not([hidden]) .mobile-filter-panel {
    transform: translateX(0);
  }

  .mobile-filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #2a2a2a;
    flex-shrink: 0;
  }

  .mobile-filter-header h3 {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    margin: 0;
  }

  .mobile-filter-close {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    line-height: 0;
    transition: color 0.2s, background 0.2s;
  }

  .mobile-filter-close:hover {
    color: #fff;
    background: #222;
  }

  .mobile-filter-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
  }

  /* Copy the sidebar inside the mobile drawer */
  .mobile-filter-body .category-sidebar {
    display: block !important;
    background: transparent;
    border: none;
    padding: 0;
    width: auto;
    max-width: none;
  }

  .mobile-filter-footer {
    padding: 16px 20px;
    border-top: 1px solid #2a2a2a;
    flex-shrink: 0;
  }

  .mobile-filter-apply {
    display: block;
    width: 100%;
    background: #dc2626;
    color: #fff;
    text-align: center;
    padding: 13px;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
  }

  .mobile-filter-apply:hover {
    background: #b91c1c;
  }

  /* Results header: row with filter btn + sort */
  .results-header {
    flex-wrap: wrap;
  }

  /* autocomplete: full width on mobile */
  .search-autocomplete {
    left: 0;
    right: 0;
    min-width: unset !important;
    width: 100vw;
    position: fixed;
    top: 60px;
    margin: 0;
    border-radius: 0 0 12px 12px;
    max-height: 70vh;
  }

  /* Modal: full-screen on mobile */
  .product-modal {
    align-items: flex-end;
  }

  .modal-panel {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .modal-details-section {
    padding: 20px 16px;
  }

  .modal-image-section {
    padding: 20px;
  }
}

/* ── 5. LARGE PHONES (≤480px) ────────────────────────────────── */

@media (max-width: 480px) {

  /* Tighter nav */
  .nav-container {
    padding: 0 10px;
  }

  /* Logo text hidden, keep icon */
  .logo span {
    display: none;
  }

  /* Product grid: 2 columns (keep! single column is too sparse for a shop) */
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .product-image {
    height: 140px;
  }

  .product-info {
    padding: 8px 10px;
  }

  .product-name {
    font-size: 12px;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .product-manufacturer {
    font-size: 11px;
  }

  .product-price {
    font-size: 14px;
  }

  .add-to-cart {
    font-size: 12px;
    padding: 10px 8px;
  }

  /* Cart panel: full screen */
  .cart-panel-content {
    max-width: 100%;
    width: 100%;
  }

  .cart-panel-header {
    padding: 14px 16px;
  }

  /* Cart ZIP row stacks better */
  .cart-zip-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .cart-zip-input {
    width: 100%;
  }

  /* Storefront main: less padding */
  .storefront-main {
    padding: 16px 0;
  }

  /* results header: wrap nicely */
  .results-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .sort-select {
    width: 100%;
  }

  /* Main nav search bar: hide, rely on search button */
  .nav-search-form {
    display: none !important;
  }
}

/* ── 6. SMALL PHONES (≤375px) ────────────────────────────────── */

@media (max-width: 375px) {
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .product-image {
    height: 120px;
  }

  .cart-item {
    gap: 10px;
  }

  .cart-item-image {
    width: 60px;
    height: 60px;
  }
}

/* ── 7. HOMEPAGE (index.html) MOBILE ────────────────────────── */

/* Hero section */
@media (max-width: 768px) {
  .hero-section, .hero {
    padding: 60px 20px;
    text-align: center;
  }

  .hero h1, .hero-title {
    font-size: clamp(28px, 7vw, 48px);
    line-height: 1.2;
  }

  .hero-subtitle, .hero p {
    font-size: 16px;
  }

  .hero-cta, .hero-buttons, .cta-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
  }

  /* Featured products grid */
  .featured-grid, .products-grid-xl, #featured-products-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px;
  }

  /* Homepage header */
  .header-main {
    padding: 0 12px;
  }

  .header-actions {
    gap: 8px;
  }

  .header-action {
    padding: 6px 8px;
    font-size: 12px;
  }

  .header-action svg {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 480px) {
  .featured-grid, .products-grid-xl, #featured-products-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
  }

  /* Nav bar tight */
  .header-top {
    display: none; /* hide the promo bar on very small screens */
  }
}

/* ── 8. CHECKOUT PAGE MOBILE ─────────────────────────────────── */

@media (max-width: 768px) {
  .checkout-container {
    grid-template-columns: 1fr !important;
    gap: 24px;
    padding: 20px 16px;
  }

  /* Order summary: appears ABOVE the form on mobile */
  .order-summary {
    order: -1;
  }

  .checkout-section {
    padding: 20px 16px;
  }

  .section-heading {
    font-size: 18px;
  }

  .form-row {
    flex-direction: column;
    gap: 12px;
  }

  /* Card number stays in 1 row */
  .exp-inputs {
    flex-direction: row;
  }

  .form-group input,
  .form-group select {
    font-size: 16px; /* prevent iOS zoom on focus */
    padding: 12px 14px;
  }

  .btn-place-order {
    font-size: 15px;
    padding: 15px;
  }

  .summary-items {
    max-height: 200px;
    overflow-y: auto;
  }
}

@media (max-width: 480px) {
  .checkout-container {
    padding: 12px;
  }

  .checkout-section {
    padding: 16px;
    border-radius: 8px;
  }

  .summary-item {
    gap: 10px;
  }

  .summary-item-image {
    width: 44px;
    height: 44px;
  }
}

/* ── 9. SHARED UTILITY — MOBILE SEARCH OVERLAY ───────────────── */

/* Full-screen search overlay triggered by tapping the search icon on mobile */
.mobile-search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #0d0d0d;
  z-index: 3000;
  flex-direction: column;
}

.mobile-search-overlay.active {
  display: flex;
}

.mobile-search-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #222;
}

.mobile-search-input {
  flex: 1;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  padding: 10px 14px;
  outline: none;
}

.mobile-search-input:focus {
  border-color: #dc2626;
}

.mobile-search-cancel {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  padding: 8px;
  white-space: nowrap;
}

.mobile-search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

/* ── 10. FILTER TOGGLE BUTTON (DESKTOP: hidden) ──────────────── */

.filter-toggle-btn {
  display: none; /* shown only at ≤768px via rule above */
}

/* ── 11. PREVENT PULL-TO-REFRESH INTERFERENCE ───────────────── */

body {
  overscroll-behavior-y: contain;
}

/* ── 12. IMAGE TOUCH — disable hover effects on touch devices ── */

@media (hover: none) {
  .product-card:hover {
    transform: none;
    box-shadow: none;
  }

  .product-card:active {
    transform: scale(0.98);
    transition: transform 0.1s;
  }

  .product-card:hover .product-image img {
    transform: none;
  }
}

/* ── 13. MODAL BOTTOM SHEET ON MOBILE ────────────────────────── */

@media (max-width: 768px) {
  /* Product modal becomes a bottom sheet */
  .product-modal-overlay {
    align-items: flex-end !important;
  }

  .product-modal-panel, .modal-panel {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92dvh !important;
  }

  .modal-content {
    grid-template-columns: 1fr !important;
  }

  .modal-image-section {
    padding: 20px !important;
    max-height: 220px;
  }

  .modal-product-image {
    max-height: 180px !important;
  }

  .modal-details-section {
    padding: 16px !important;
    gap: 16px !important;
  }

  .modal-close-btn {
    top: 12px;
    right: 12px;
  }
}
