/* ==========================================================================
   Shop category-card grid — components/category-grid.css
   Enqueued by inc/shop-category-grid.php only when the grid renders.

   Matches the client reference: dark ground, square category image, label
   beneath, responsive grid capping at 6 per row. Brand colours come from the
   theme's tokens (navy #092246 ground, gold #f4c430 accent) rather than new
   hardcoded values.
   ========================================================================== */

.cat-grid {
  --catg-ground: #092246;
  --catg-accent: #f4c430;
  --catg-text:   #ffffff;

  background: var(--catg-ground);
  padding: clamp(28px, 4vw, 56px) clamp(16px, 4vw, 48px);
}

.cat-grid__list {
  --catg-gap: clamp(12px, 1.6vw, 24px);

  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: var(--container-max, 1280px);

  /* Flexbox, not grid: an incomplete final row must CENTER (justify-content),
     which a grid's fixed tracks can't do — 8 cards in a 6-wide grid leaves the
     2 stragglers hard-left with a gap. flex-wrap + centre handles any count
     (7, 8, 10…), which matters now that empty categories can drop the total. */
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--catg-gap);
}

.cat-grid__item {
  margin: 0;
  /* Shared flex behaviour; the per-row basis is set by the variant below.
     grow 0 keeps a lone final-row tile at one column's width (so it centres via
     the list's justify-content) rather than stretching across the row. */
  flex: 0 1 auto;
}

/* Home instance (6-card cap): 3 across on desktop, so 6 cards make two even
   rows of 3. N bases + (N-1) gaps = 100%, so rows fill edge-to-edge while the
   flex-wrap + justify-content:center safety net centres any short final row. */
.cat-grid--six .cat-grid__item {
  flex-basis: calc((100% - 2 * var(--catg-gap)) / 3);
}

/* Shop instance (8-card cap): 4 across on desktop, so 8 cards are two even rows
   of 4 rather than 6 + 2. Same flex-wrap/centre from the list, so if auto-hide
   ever drops the Shop grid to 7 it shows 4 + 3 centred, not a ragged row. */
.cat-grid--four .cat-grid__item {
  flex-basis: calc((100% - 3 * var(--catg-gap)) / 4);
}

.cat-grid__card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-decoration: none;
  color: var(--catg-text);
}

/* Square image tile. aspect-ratio keeps every card identical regardless of the
   thumbnail's own dimensions; the image covers it. */
.cat-grid__media {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: var(--radius-md, 8px);
  background: rgba(255, 255, 255, 0.06);
}

.cat-grid__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}

.cat-grid__card:hover .cat-grid__img,
.cat-grid__card:focus-visible .cat-grid__img {
  transform: scale(1.05);
}

/* No thumbnail set yet: a branded tile with a gold rule, never a broken image.
   The label still names the category, so the card is usable meanwhile. */
.cat-grid__card.is-placeholder .cat-grid__media {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0));
}

.cat-grid__card.is-placeholder .cat-grid__media::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 22%;
  width: 34px;
  height: 3px;
  transform: translateX(-50%);
  background: var(--catg-accent);
  border-radius: 2px;
}

.cat-grid__label {
  font-family: var(--font-heading);
  font-size: clamp(0.85rem, 1vw, 1rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  text-align: center;
}

.cat-grid__card:hover .cat-grid__label,
.cat-grid__card:focus-visible .cat-grid__label {
  color: var(--catg-accent);
}

.cat-grid__card:focus-visible {
  outline: 2px solid var(--catg-accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm, 4px);
}

/* ── Responsive step-down ──────────────────────────────────────────────────
   Only the flex-basis divisor changes per breakpoint (N bases + N-1 gaps =
   100%); wrapping + centring stay from the base rule. Never 1, so labels stay
   scannable on phones.
     home  (--six):  3 → 2       (drops to 2-up on tablet)
     shop (--four):  4 → 3 → 2   (already 4 at desktop) */

/* --six: 2-up from tablet down. Cards are a square image + short label, so 2-up
   stays legible to the smallest phones — no 1-up step (single oversized squares
   + excess scroll), matching how --four also bottoms out at 2. */
@media (max-width: 768px) {
  .cat-grid--six .cat-grid__item { flex-basis: calc((100% - 1 * var(--catg-gap)) / 2); }
}

/* --four (Shop page) ladder — unchanged; selectors just no longer shared with
   --six, which now has its own step above. */
@media (max-width: 720px) {
  .cat-grid--four .cat-grid__item { flex-basis: calc((100% - 2 * var(--catg-gap)) / 3); }
}

@media (max-width: 460px) {
  .cat-grid--four .cat-grid__item { flex-basis: calc((100% - 1 * var(--catg-gap)) / 2); }
}
