/* ================================================================
   CATEGORY PAGE — MOBILE
   Loaded last on categories.php, and every rule lives inside a
   max-width query, so this file cannot affect the desktop layout.

   Why this file exists: category.css is ~4,000 lines carrying ten
   overlapping breakpoints (700 / 760 / 860 / 900 / 940 / 1024 / 1040
   px) that all set .category-layout and .product-grid. Which one won
   depended on source order, and on a phone the filter panel was still
   rendered inline ABOVE the products, so a shopper had to scroll past
   the whole filter tree before seeing a single item.

   This replaces that with the app-style pattern: a compact sticky
   header, a two-up product grid, and the filters in a slide-in drawer.
   ================================================================ */

/* ---------------------------------------------------------- backdrop */
.cm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(8, 15, 30, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.cm-backdrop[hidden] { display: none; }
.cm-backdrop.on { opacity: 1; }

/* the button that opens the drawer - hidden on desktop */
.cm-filter-btn { display: none; }

@media (max-width: 860px) {

  /* ---------------------------------------------- page shell */
  .category-page {
    padding-bottom: 24px;
    /* clear the sticky mobile header */
    scroll-margin-top: 96px;
  }
  .category-layout.container {
    padding-left: 12px !important;
    padding-right: 12px !important;
    gap: 0 !important;
  }
  /* Force a single column. category.css has a late "240px 1fr" rule
     (max-width:900px) that would otherwise leave a ~120px dead gutter
     beside every product on a phone. The sidebar is fixed (drawer), so
     only this column is actually used. */
  .category-layout {
    grid-template-columns: 1fr !important;
  }
  /* when the sticky toolbar catches an anchor scroll / scrollIntoView
     the target must land BELOW the bar, not under it */
  html { scroll-padding-top: 84px; }

  /* ---------------------------------------------- category strip:
     becomes a swipeable app-style shelf. On a phone the 16 big image
     cards must not stack into an 8-row grid that buries the products;
     they scroll horizontally as compact tiles instead. */
  .category-strip {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    grid-template-columns: none !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    gap: 10px !important;
    /* Stays inside the 12px container gutters so it can never widen the
       page. Left padding aligns the first tile with the products grid;
       right padding is a touch smaller so the next tile peeks in and
       hints that the shelf swipes. */
    width: auto !important;
    margin: 0 !important;
    padding: 10px 8px 14px 12px !important;
  }
  .category-strip::-webkit-scrollbar { height: 0; display: none; }
  .category-strip .category-card {
    flex: 0 0 124px !important;
    width: 124px !important;
    min-width: 124px !important;
    height: 148px !important;
    min-height: 0 !important;
    border-radius: 16px !important;
    scroll-snap-align: start;
  }
  .category-strip .category-info {
    min-height: 48px;
    width: calc(100% - 10px);
    margin: auto 5px 5px;
    padding: 7px 8px;
    border-radius: 11px;
    gap: 5px;
  }
  .category-strip .category-info h3 { font-size: 11px; }
  .category-strip .category-info .cat-desc { font-size: 8.5px; }
  .category-strip .category-info .category-arrow {
    width: 24px;
    height: 24px;
    min-width: 24px;
    font-size: 12px;
  }

  /* ---------------------------------------------- sticky header */
  .product-toolbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 400 !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    margin: 0 -12px 12px !important;
    padding: 10px 12px !important;
    background: rgba(255, 255, 255, 0.88) !important;
    -webkit-backdrop-filter: blur(18px) saturate(160%) !important;
    backdrop-filter: blur(18px) saturate(160%) !important;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08) !important;
    border-radius: 0 !important;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06) !important;
  }
  .product-toolbar .product-count {
    font-size: 11.5px !important;
    color: #64748b !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1 1 auto;
    min-width: 0;
  }
  .product-toolbar .product-count strong { color: #0f172a; }
  .product-toolbar .toolbar-actions {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex: 0 0 auto;
  }

  /* the drawer trigger becomes a real button, 44px tall */
  .cm-filter-btn {
    display: inline-flex !important;
    align-items: center;
    gap: 7px;
    height: 44px;
    padding: 0 15px;
    border-radius: 999px;
    border: 1px solid rgba(7, 159, 52, 0.28);
    background: rgba(7, 159, 52, 0.10);
    color: #067a29;
    font-size: 13px;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
  }
  .cm-filter-btn:active { transform: scale(0.97); }
  .cm-filter-btn i { font-size: 12px; }

  /* sort sits next to it, full-height pill */
  .product-toolbar #sortSelect {
    height: 44px !important;
    border-radius: 999px !important;
    /* 16px, not 12.5: a focused select below 16px makes the browser zoom the
       whole page, and it never zooms back. */
    font-size: 16px !important;
    font-weight: 700 !important;
    max-width: 42vw !important;
    padding: 0 30px 0 13px !important;
    background-color: #fff !important;
    border: 1px solid rgba(15, 23, 42, 0.12) !important;
  }
  /* grid/list switch is noise on a phone */
  .product-toolbar .view-button { display: none !important; }

  /* ---------------------------------------------- the drawer */
  .category-sidebar.cm-drawer {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    z-index: 950 !important;
    width: min(86vw, 360px) !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    border-radius: 0 18px 18px 0 !important;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.28) !important;
    transform: translateX(-102%) !important;
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }
  .category-sidebar.cm-drawer.open { transform: translateX(0) !important; }
  .cm-drawer[hidden] { display: none; }

  /* head: close / title / clear */
  .cm-drawer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px 12px 8px;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
    flex: 0 0 auto;
  }
  .cm-drawer-head h2 {
    flex: 1;
    margin: 0;
    font-size: 16px;
    font-weight: 900;
    color: #0f172a;
    text-align: center;
  }
  .cm-drawer-close,
  .cm-drawer-clear {
    /* 44px, not 40: below that the close/clear targets are hard to hit
       with a thumb and fail the WCAG 2.5.5 / iOS 44pt guidance. */
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #334155;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    display: grid;
    place-items: center;
  }
  .cm-drawer-clear { color: #be123c; border-color: #fecdd3; background: #fff1f2; }
  .cm-drawer-close:active,
  .cm-drawer-clear:active { transform: scale(0.96); }

  /* ---- scrolling body ------------------------------------------------
     #advFilters carries BOTH .adv-filters (the desktop glass panel) and
     .cm-drawer-body. An earlier version set `overflow: visible` on
     .adv-filters to undo the desktop sticky panel, but that same element
     is the drawer's scroll area - so the flag killed the scroll and the
     whole filter list was clipped with no way to reach the bottom. The
     desktop rules are reset individually here instead, and min-height:0
     lets the flex child actually shrink and scroll. */
  .cm-drawer .cm-drawer-body,
  .cm-drawer .adv-filters {
    flex: 1 1 auto;
    min-height: 0 !important;
    max-height: none !important;
    position: static !important;
    top: auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    /* the panel is a glass card on desktop; inside a white sheet that
       would be a box in a box, so it becomes plain */
    background: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
  /* a scrollbar you cannot grab is worse than none */
  .cm-drawer .cm-drawer-body::-webkit-scrollbar { width: 6px; }
  .cm-drawer .cm-drawer-body::-webkit-scrollbar-thumb {
    background: #cbd5e1; border-radius: 6px;
  }
  /* room for the last row so the foot button never covers a filter */
  .cm-drawer .cm-drawer-body { padding-bottom: 14px !important; }

  /* the panel injects its own "Filters / Clear All" head, which would sit
     directly under the drawer's own head - hide the duplicate */
  .cm-drawer .adv-filters .af-head { display: none !important; }

  /* ---- accordion blocks ------------------------------------------- */
  .cm-drawer .af-block { padding: 0 !important; border-bottom: 1px solid #eef2f7 !important; }
  .cm-drawer .af-block > h4 {
    min-height: 48px !important;             /* thumb-sized header */
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
    font-size: 12.5px !important;
    letter-spacing: 0.05em !important;
    color: #475569 !important;
    cursor: pointer !important;
    -webkit-tap-highlight-color: transparent;
  }
  .cm-drawer .af-block > h4::after { margin-left: auto !important; }
  .cm-drawer .af-block > *:not(h4) { padding: 0 14px 14px !important; }

  /* ---- no nested scroll areas ---------------------------------------
     .af-list.scroll caps at 190px with its own scrollbar, so a drag on a
     sub-list would trap the gesture and the outer list would not move.
     Let the drawer body be the only scroller. */
  .cm-drawer .af-list.scroll {
    max-height: none !important;
    overflow: visible !important;
  }

  /* ---- touch targets ------------------------------------------------ */
  .cm-drawer .af-row {
    min-height: 46px !important;
    font-size: 13.5px !important;
    padding: 10px 0 !important;
  }
  .cm-drawer .af-row input[type=checkbox] { width: 20px !important; height: 20px !important; }
  .cm-drawer .af-reset {
    min-height: 46px !important;
    font-size: 13.5px !important;
  }
  .cm-drawer .af-quick {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .cm-drawer .af-quick button {
    min-height: 46px !important;
    font-size: 13px !important;
    border-radius: 11px !important;
  }

  /* ---- price range: thumb-sized sliders ----------------------------- */
  .cm-drawer .af-inputs { gap: 8px !important; margin-bottom: 12px !important; }
  .cm-drawer .af-inputs input {
    min-height: 46px !important;
    /* 16px: these are type="number", so the numeric keypad zooms the page
       below that. */
    font-size: 16px !important;
    text-align: center;
  }
  .cm-drawer .af-range { height: 40px !important; margin-top: 6px !important; }
  .cm-drawer .af-range input[type=range] { top: 10px !important; height: 20px !important; }
  .cm-drawer .af-range input[type=range]::-webkit-slider-thumb {
    width: 22px !important; height: 22px !important; border-width: 3px !important;
  }
  .cm-drawer .af-range input[type=range]::-moz-range-thumb {
    width: 22px !important; height: 22px !important; border-width: 3px !important;
  }
  .cm-drawer .af-prices { font-size: 12.5px !important; }

  /* ---- applied-count chips on the drawer trigger -------------------- */
  .cm-filter-btn[data-active="1"] {
    background: #079f34 !important;
    border-color: #079f34 !important;
    color: #fff !important;
  }

  /* foot: the apply button stays reachable with one thumb */
  .cm-drawer-foot {
    flex: 0 0 auto;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #e2e8f0;
    background: #fff;
  }
  .cm-drawer-apply {
    width: 100%;
    height: 48px;
    min-height: 48px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(90deg, #1d4ed8, #1e40af, #079f34);
    color: #fff;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 800;
    cursor: pointer;
  }
  .cm-drawer-apply:active { transform: scale(0.99); }

  /* lock the page behind the drawer */
  body.cm-locked { overflow: hidden; }

  /* ---------------------------------------------- two-up grid */
  .products-section { padding: 0; }
  .section-top-row { flex-wrap: wrap; gap: 8px; }
  .section-top-row h2 { font-size: 16px !important; }

  .product-grid,
  .product-grid.list-view {
    display: grid !important;
    gap: 10px !important;
    padding: 0 !important;
  }
  /* the column count is owned by compare.css so there is one answer;
     this file only tunes the gap and the card padding */

  /* ---------------------------------------------- compact card

     Unchanged: this is the two-up-era sizing, still correct at 641-860px
     where a three-up card is ~200px wide and there is room to spare. The
     phone-specific compaction lives in the 640px query at the end of this
     file, because a three-up card at ~113px (a 390px phone) needs quite
     different proportions and applying them here also changed tablets. */
  .product-card {
    padding: 9px !important;
    border-radius: 12px !important;
  }
  .product-image {
    height: 118px !important;
    margin: 8px 0 7px !important;
    border-radius: 9px !important;
  }
  .product-card h3 {
    font-size: 11.5px !important;
    line-height: 1.3 !important;
    margin-bottom: 4px !important;
    -webkit-line-clamp: 2;
  }
  .product-price {
    font-size: 14.5px !important;
    min-height: 20px !important;
    gap: 4px !important;
  }
  .product-price del { font-size: 10px !important; }
  .rating,
  .product-card .rating {
    font-size: 10px !important;
    min-height: 14px !important;
    gap: 4px !important;
  }
  .rating small { font-size: 9.5px !important; }
  .stock,
  .product-card .stock {
    font-size: 10px !important;
    min-height: 14px !important;
    gap: 5px !important;
  }
  .product-card .card-buy {
    margin-top: 8px !important;
    padding: 9px 4px !important;
    font-size: 11.5px !important;
    border-radius: 8px !important;
  }
  .compare-check,
  .product-card .compare-check { font-size: 10px !important; margin-top: 6px !important; }
  .compare-check input { width: 16px !important; height: 16px !important; }

  /* Nested inside the 860px query on purpose: a nested @media is valid
     CSS and keeps this group alongside the other phone rules, while still
     gating the values at the width they were measured for. */
  @media (max-width: 640px) {

  /* ============================================================
     PHONE CARD PROPORTIONS - three-up, ~90-130px wide

     Kept out of the 860px block above on purpose. Three-up starts at 860px,
     but a tablet at 768px still gets a ~239px card and does not need phone
     proportions: measured before this split, 768px was picking up a 3-line
     title and a square image where it had had 2 lines and a 201x150 box.
     640px is where a three-up card drops under ~150px and the compaction
     is actually needed.

     Each value, and what it was costing at 390px (card 113px wide):
       .product-image  118px tall -> square with the card's own width, so a
                      portrait photo is no longer letterboxed in a tall box
       .store-logo      44px     -> 26px. It was the tallest block on the
                      card after the image, and taller than the price.
       title            2 lines  -> 3. ~197px of title text was landing in
                      a 36px box and being cut mid-line. The min-height has
                      to move too: compare.css reserves a fixed 36px slot
                      for 2 lines x 18px, and that caps the box however many
                      lines the clamp allows.
       price            41px     -> one row; 14.5px plus a struck-through
                      original did not fit across 99px and wrapped.

     Result: 395px tall (1:3.5 of its width) -> ~313px (1:2.8).

     These are single, non-duplicated rules. The previous version declared
     .product-label, .wishlist and .multi-store twice inside the same block,
     with the older pair later in the file, so the wishlist stayed at 28px
     and part of the compaction did nothing.
     ============================================================ */
  .product-card {
    padding: 5px !important;
    border-radius: 11px !important;
  }

  .product-image {
    height: auto !important;
    /* 16:9 - the standard product-tile ratio. The image is the single
       tallest thing on the card: at a 90-130px card width a square box was
       97px of the 313px total. 16:9 keeps the whole product visible
       (object-fit: contain) while giving back ~30px of card length. */
    aspect-ratio: 16 / 9 !important;
    margin: 4px 0 !important;
    border-radius: 8px !important;
    overflow: hidden;
  }
  .product-image img,
  .product-image > a > img {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    object-fit: contain !important;
    display: block;
  }

  .product-card h3,
  .products-section .product-card h3 {
    font-size: 11px !important;
    line-height: 14px !important;
    /* 3 lines x 14px: every card reserves the same slot, so the prices
       below still line up across the row */
    min-height: 42px !important;
    height: auto !important;
    margin: 0 0 3px !important;
    -webkit-line-clamp: 3 !important;
    -webkit-box-orient: vertical !important;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .product-price {
    font-size: 13px !important;
    min-height: 0 !important;
    gap: 3px !important;
    flex-wrap: nowrap !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    margin: 0 0 2px !important;
  }
  .product-price strong { font-size: 13px !important; }
  .product-price del { font-size: 9px !important; }

  .rating,
  .product-card .rating {
    font-size: 9.5px !important;
    min-height: 0 !important;
    gap: 3px !important;
    margin: 0 !important;
    white-space: nowrap;
    overflow: hidden;
  }
  .rating small { font-size: 8.5px !important; }

  .stock,
  .product-card .stock {
    font-size: 9.5px !important;
    min-height: 0 !important;
    gap: 3px !important;
    margin: 0 0 1px !important;
    white-space: nowrap;
  }

  /* A 26px logo block in a 97px-wide card was 30px of the height for a mark
     with no text beside it. 20px still identifies the store. */
  .product-card .store-logo {
    width: 20px !important;
    height: 20px !important;
    margin: 0 0 1px !important;
    border-radius: 6px !important;
    flex: 0 0 20px !important;
  }
  .product-card .store-logo img {
    width: 100% !important;
    height: 100% !important;
  }

  .compare-check,
  .product-card .compare-check {
    font-size: 9.5px !important;
    margin: 1px 0 !important;
    gap: 4px !important;
  }
  .compare-check input { width: 14px !important; height: 14px !important; }

  /* the corner chips sit over the image, so they shrink with it */
  .product-label {
    top: 4px !important;
    left: 4px !important;
    padding: 2px 5px !important;
    font-size: 8.5px !important;
    border-radius: 5px !important;
  }
  .product-card .wishlist {
    top: 4px !important;
    right: 4px !important;
    width: 20px !important;
    height: 20px !important;
    font-size: 10px !important;
  }
  .product-card .multi-store {
    top: 4px !important;
    left: 4px !important;
    padding: 2px 5px !important;
    font-size: 8.5px !important;
  }

  /* Buy now stays a full-width 32px touch target */
  .product-card .card-buy {
    margin: 3px 0 0 !important;
    padding: 7px 2px !important;
    font-size: 11px !important;
    min-height: 32px !important;
    border-radius: 8px !important;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  }


  /* ---------------------------------------------- paging */
  .pagination,
  .pager { gap: 6px !important; }
  .pagination button,
  .pager button {
    min-width: 40px !important;
    min-height: 40px !important;
  }

  /* ---------------------------------------------- search row above
     the results: toggles on one line, then search + category select
     side by side, then the store chips. */
  .compare-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 2px; }
  .compare-tools .switch-row.mini { flex: 0 1 auto; font-size: 11px; min-height: 36px; }
  #searchInput,
  #subCategoryFilter {
    flex: 1 1 40% !important;
    min-width: 0 !important;
    width: auto !important;
    min-height: 42px;
    font-size: 13px;
  }
  #platformFilter .pf-chip { min-height: 34px; padding: 5px 11px; font-size: 11.5px; }
}

/* ------------------------------------------------ very small phones
   Kept as a separate top-level query rather than nested inside the 860px
   block, so minifiers and older parsers do not trip over nesting. */
@media (max-width: 380px) {
  .product-toolbar { gap: 6px !important; padding: 8px 10px !important; }
  .cm-filter-btn { padding: 0 11px !important; font-size: 12px !important; height: 42px !important; }
  .product-toolbar #sortSelect {
    height: 42px !important;
    font-size: 16px !important;
    max-width: 38vw !important;
  }
  /* the image is square now (see the 860px block), so it shrinks with the
     card instead of carrying a fixed height that was taller than the column */
  .product-grid,
  .product-grid.list-view { gap: 8px !important; }
  /* the column count is owned by compare.css */
}

/* ------------------------------------------------------- tablets */
/* the grid's own breakpoint for three-up lives in compare.css, so that the
   drawer rules here and the column rules there cannot disagree */


/* --------------------------------------------------------- dark */
html.dark .product-toolbar {
  background: rgba(15, 23, 42, 0.9);
  border-bottom-color: rgba(255, 255, 255, 0.1);
}
html.dark .product-toolbar .product-count { color: #94a3b8; }
html.dark .product-toolbar .product-count strong { color: #e2e8f0; }
html.dark .cm-filter-btn {
  background: rgba(7, 159, 52, 0.18);
  border-color: rgba(7, 159, 52, 0.4);
  color: #4ade80;
}
html.dark .product-toolbar #sortSelect {
  background-color: #111c33;
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.16) !important;
}
html.dark .category-sidebar.cm-drawer,
html.dark .cm-drawer-head,
html.dark .cm-drawer-foot { background: #0d1526; }
html.dark .cm-drawer-head,
html.dark .cm-drawer-foot { border-color: rgba(255, 255, 255, 0.1); }
html.dark .cm-drawer-head h2 { color: #f1f5f9; }
html.dark .cm-drawer-close,
html.dark .cm-drawer-clear {
  background: #16233a; color: #cbd5e1; border-color: rgba(255, 255, 255, 0.12);
}