/**
 * WooCommerce "Product Collection" block, styled on the shop listing's tiles:
 * heading row with the prev/next arrows, then bone tiles with hairline gaps,
 * name / price caption, and the ink hover bar with a text-first "Add to cart".
 * Loaded only on pages that render the block (wp_enqueue_block_style).
 */

.wp-block-woocommerce-product-collection {
  --mm-ink: var(--wp--preset--color--mm-hero, #3a3e35);
  --mm-label: #a5a096;
  --mm-tile-gap: 3px;
  width: 100%;                                               /* fill the column it sits in (Spectra columns start-align children) */
}
/* Tiles-per-view follows the strip's own width, not the screen. The strip is
   the container; the tiles read the value. */
.wp-block-woocommerce-product-collection .wc-block-product-template { container-type: inline-size; }
/* Fractional counts on purpose: part of the next tile always peeks in, so the
   strip reads as a carousel and Woo shows its arrows (it hides them when
   everything fits). */
.wp-block-woocommerce-product-collection .wc-block-product { --mm-tiles: 3.4; }
@container (max-width: 1100px) { .wp-block-woocommerce-product-collection .wc-block-product { --mm-tiles: 2.4; } }
@container (max-width: 800px)  { .wp-block-woocommerce-product-collection .wc-block-product { --mm-tiles: 1.6; } }
@container (max-width: 520px)  { .wp-block-woocommerce-product-collection .wc-block-product { --mm-tiles: 1.25; } }

/* Woo's store-notice banner is server-rendered empty and only hidden once its
   script runs — keep it out of the layout until it actually holds a notice. */
.wp-block-woocommerce-product-collection .wc-block-components-notice-banner:not([role]),
.wp-block-woocommerce-product-collection .wc-block-components-notice-banner:has(.wc-block-components-notice-banner__content > span:empty) { display: none; }

/* --- Heading row: title + arrows -------------------------------- */
.wp-block-woocommerce-product-collection > .wp-block-group {
  align-items: flex-end;
  gap: 24px;
  margin-bottom: clamp(24px, 4vh, 32px);
}
.wp-block-woocommerce-product-collection > .wp-block-group .wp-block-heading {
  margin: 0 !important;
  font-size: 48px;                                           /* same as the product / listing titles */
  font-weight: 200;
  line-height: 1.05;
  letter-spacing: -0.005em;
  color: var(--mm-ink);
}
.wc-block-next-previous-buttons { gap: 10px; }
.wc-block-next-previous-buttons__button {                    /* same control as the product carousel's arrows */
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.78);
  color: var(--mm-ink);
  cursor: pointer;
  transition: background-color 0.2s ease, opacity 0.2s ease;
}
.wc-block-next-previous-buttons__button:hover,
.wc-block-next-previous-buttons__button:focus-visible { background: #fff; }
.wc-block-next-previous-buttons__button[aria-disabled="true"] { opacity: 0.4; cursor: default; }
.wc-block-next-previous-buttons__button svg { display: none; }            /* Woo's chevron out… */
.wc-block-next-previous-buttons__button::before {                          /* …the site's arrow in */
  content: "";
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'%3E%3Cpath d='M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'%3E%3Cpath d='M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.wc-block-next-previous-buttons__button:first-child::before { transform: scaleX(-1); }   /* previous */

/* When the block's own heading has been removed (the page supplies one above
   the block), the arrows lift out of their row and sit at the right-hand end
   of that heading's line, clear of the rail. */
.wp-block-woocommerce-product-collection { position: relative; --mm-rail-w: clamp(58px, 7vw, 84px); --mm-head-gap: 24px; }
/* Same 24px the page's other sections leave between their heading row and content. */
.wp-block-group + .wp-block-woocommerce-product-collection { margin-top: var(--mm-head-gap); }
.wp-block-woocommerce-product-collection > .wp-block-group:not(:has(.wp-block-heading)) {
  position: absolute;
  right: 0;                                                  /* the section's right padding already clears the rail */
  bottom: calc(100% + var(--mm-head-gap) + 12px);
  z-index: 2;
  width: auto;
  margin: 0;
}

/* --- The strip -------------------------------------------------- */
.wp-block-woocommerce-product-collection .wc-block-product-template.is-product-collection-layout-carousel {
  gap: var(--mm-tile-gap) !important;
  padding: 0;
  margin: 0;
  scroll-snap-type: x proximity;                             /* snaps to tiles but never blocks reaching the end */
  scrollbar-width: none;
}
/* Trailing spacer: the strip runs under the fixed right rail, so leave room
   for the last tile to scroll clear of it. */
.wp-block-woocommerce-product-collection .wc-block-product-template.is-product-collection-layout-carousel::after {
  content: "";
  flex: 0 0 var(--mm-rail-w);
}
@media (max-width: 767px) {
  .wp-block-woocommerce-product-collection .wc-block-product-template.is-product-collection-layout-carousel::after { display: none; }
  /* Phones: no room beside the heading, so the arrows drop under the strip, right-aligned. */
  .wp-block-woocommerce-product-collection { display: flex; flex-direction: column; }
  .wp-block-woocommerce-product-collection > .wp-block-group:not(:has(.wp-block-heading)) {
    position: static;
    order: 2;
    align-self: flex-end;
    margin: 16px 0 0;
  }
}
.wp-block-woocommerce-product-collection .wc-block-product-template.is-product-collection-layout-carousel::-webkit-scrollbar { display: none; }

.wp-block-woocommerce-product-collection .wc-block-product {
  position: relative;
  container-type: inline-size;
  flex: 0 0 calc((100% - var(--mm-tile-gap) * (var(--mm-tiles) - 1)) / var(--mm-tiles)) !important;
  width: auto !important;
  max-width: none !important;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-content: start;                                      /* rows keep their size; a tile stretched to the strip's height leaves the gap at the bottom */
  gap: 0 14px;
  margin: 0;
  padding: 0;
  background: var(--wp--preset--color--mm-base, #f2f1ee);
  scroll-snap-align: start;
  text-align: left;
}

/* Image (the block keeps its own 1:1 ratio) */
.wp-block-woocommerce-product-collection .wc-block-product .wc-block-components-product-image {
  position: relative;                                        /* holds the hover clip */
  grid-column: 1 / -1;
  margin: 0;
  overflow: hidden;
  background: var(--wp--preset--color--mm-greige, #eae9e5);
}
.wp-block-woocommerce-product-collection .wc-block-product .wc-block-components-product-image img {
  transition: transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.wp-block-woocommerce-product-collection .wc-block-product:hover .wc-block-components-product-image img,
.wp-block-woocommerce-product-collection .wc-block-product:focus-within .wc-block-components-product-image img { transform: scale(1.045); }

/* Caption: name (and its category) left, price right centred on the name;
   the same breathing room above and below the text. */
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-post-title {
  grid-column: 1;
  grid-row: 2;
  margin: 0 !important;                                      /* block-gap margins from the editor otherwise push the category down */
  padding: 18px 0 18px 22px;
  font-size: 18px;
  font-weight: 300;
  line-height: 1.15;
  color: var(--mm-ink);
}
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-post-title a {
  color: inherit;
  text-decoration: none;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  padding-bottom: 0.18em;
  margin-bottom: -0.18em;
}
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-post-title a:hover { color: var(--wp--preset--color--mm-clay, #bc8c78); }
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-price {
  grid-column: 2;
  grid-row: 2;
  align-self: center;
  margin: 0;
  padding: 0 22px 0 0;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.15;
  color: var(--mm-ink);
  white-space: nowrap;
}
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-price * { font-size: inherit; font-weight: inherit; color: inherit; }
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-price del { color: var(--mm-label); font-weight: 300; margin-right: 6px; }

/* Category under the name (injected per product - see megmakesme_collection_title_category) */
.wp-block-woocommerce-product-collection .wc-block-product .mm-collection__cat {
  grid-column: 1;
  grid-row: 3;
  margin: 0 !important;
  padding: 0 0 18px 22px;
  font-size: 10.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--mm-label);
}
.wp-block-woocommerce-product-collection .wc-block-product:has(.mm-collection__cat) .wp-block-post-title { padding-bottom: 2px; }

/* Hover bar over the image's bottom edge: plain "Add to cart", clay pill on its own hover */
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-button {
  position: absolute;
  left: 0;
  right: 0;
  top: 100cqw;                                               /* the 1:1 image's bottom edge */
  z-index: 3;
  display: block;                                            /* Woo centres it with flex; the listing's is left-aligned */
  margin: 0;
  padding: 12px 16px;
  background: var(--mm-ink);
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translateY(calc(-100% + 12px));
  transition: transform 0.4s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0.3s ease;
}
.wp-block-woocommerce-product-collection .wc-block-product:hover .wp-block-woocommerce-product-button,
.wp-block-woocommerce-product-collection .wc-block-product:focus-within .wp-block-woocommerce-product-button {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-100%);
}
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-button .wp-block-button__link,
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-button .wc-block-components-product-button__button {
  display: inline-block;
  margin: 0;
  padding: 11px 22px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font-family: var(--mm-font);
  font-weight: 300;
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-button .wp-block-button__link:hover,
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-button .wp-block-button__link:focus-visible {
  background: var(--wp--preset--color--mm-clay, #bc8c78);
  color: #fff;
}
.wp-block-woocommerce-product-collection .wc-block-product .wc-block-components-product-button__button--placeholder { opacity: 0; }

/* PDF preview sheets in the bar (injected per product — see megmakesme_collection_button_pages):
   cover in front, cut sheet behind it peeking out right and lower, flush with the bar's bottom. */
.wp-block-woocommerce-product-collection .wc-block-product .mm-tile__pages {
  --w: clamp(40px, calc((100cqw - 190px) / 1.5), 92px);
  position: absolute;
  right: calc(18px + var(--w) * 0.5);
  bottom: 0;
  width: var(--w);
  aspect-ratio: 247 / 349;
  pointer-events: none;
}
.wp-block-woocommerce-product-collection .wc-block-product .mm-tile__page {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: top;
  background: #fff;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.14);
}
.wp-block-woocommerce-product-collection .wc-block-product .mm-tile__page { transform: translate(calc(var(--i, 0) * 50% * var(--mm-fan, 1)), calc(var(--i, 0) * 12% * var(--mm-fan, 1))); z-index: calc(10 - var(--i, 0)); }
/* the back sheet hangs a little below the bar — clip the bar so nothing spills onto the caption */
.wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-button { clip-path: inset(-400px 0 0 0); }
.wp-block-woocommerce-product-collection .wc-block-product .added_to_cart { display: none !important; }

/* --- Tablet / phone ---------------------------------------------- */
@media (max-width: 767px) {
  .wp-block-woocommerce-product-collection > .wp-block-group .wp-block-heading { font-size: clamp(32px, 9vw, 40px); }
  .wp-block-woocommerce-product-collection .wc-block-product .wp-block-post-title { padding: 14px 0 14px 14px; font-size: 15px; }
  .wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-price { padding: 0 14px 0 0; }
  .wp-block-woocommerce-product-collection .wc-block-product .mm-collection__cat { padding: 0 0 14px 14px; }
  @media (hover: none) {
    .wp-block-woocommerce-product-collection .wc-block-product .wp-block-woocommerce-product-button { opacity: 1; pointer-events: auto; transform: translateY(-100%); }
  }
}
