/**
 * Modeser Products — shared product card (used by both the Products Grid
 * and Products Carousel widgets, and by every entry inside a product's
 * variations modal — see Base\AbstractProductsWidget::render_product_style_card()).
 */

.mdsproduct-product-card {
  position: relative;
  background-color: #f5f5f4;
  border-radius: 8px;
  overflow: hidden;
}

.mdsproduct-product-card-image-link {
  display: block;
}

.mdsproduct-product-card-image {
  position: relative;
  width: 100%;
  overflow: hidden;
  background-color: #f0f0f0;
}

/*
 * The DEFAULT image is a normal, in-flow element — it alone is what gives
 * the card (and therefore the whole grid row) its real, measured height.
 * The HOVER image is purely a decorative absolute overlay on top of it.
 * Keeping both images absolutely positioned (as an earlier version did) left
 * the card with NO in-flow content at all, so its height depended entirely
 * on `aspect-ratio` succeeding on an empty wrapper div — if that ever failed
 * to apply (a theme reset, a stacking/specificity conflict, an older
 * browser), the card silently collapsed to 0px tall while still painting
 * its content, visually spilling over/under whatever widget came next.
 */
.mdsproduct-product-card-img-default {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  transition: opacity 0.35s ease;
}

.mdsproduct-product-card-img-hover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.mdsproduct-product-card:hover .mdsproduct-product-card-img-hover {
  opacity: 1;
}

.mdsproduct-product-card:hover .mdsproduct-product-card-img-default {
  opacity: 0;
}

/* Buy Now button + title + variations icon overlay. `display: grid` with no
   explicit template gives every child the same single 1x1 cell, so each one
   can be positioned independently (justify-self/align-self + a margin
   offset) while still visually overlapping the image. The overlay itself no
   longer toggles opacity as a group — each child hides/reveals itself
   individually (below), which is what lets each one carry its own
   independent Elementor entrance animation + delay. */
.mdsproduct-product-card-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  pointer-events: none;
}

.mdsproduct-product-card-button,
.mdsproduct-product-card-title {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.mdsproduct-product-card-button,
.mdsproduct-product-card-title {
  grid-area: 1 / 1;
}

.mdsproduct-product-card:hover .mdsproduct-product-card-button,
.mdsproduct-product-card:hover .mdsproduct-product-card-title {
  pointer-events: auto;
}

/*
 * The plain opacity fade-in only applies to elements WITHOUT a custom
 * hover animation. An element WITH one (see [data-hover-animation] in
 * AbstractProductsWidget::animation_data_attrs()) relies entirely on the
 * animate.css keyframe (assets/elementor/product-card.js) for its opacity —
 * otherwise this :hover rule would already be fading it to opacity:1 by the
 * time the keyframe's own 0% frame resets it back to 0 to begin its OWN
 * entrance, producing a visible flash-then-redo instead of one clean
 * animation.
 */
.mdsproduct-product-card:hover .mdsproduct-product-card-button:not([data-hover-animation]),
.mdsproduct-product-card:hover .mdsproduct-product-card-title:not([data-hover-animation]) {
  opacity: 1;
}

/*
 * Elementor's own `.animated` class (frontend.min.css) only sets
 * animation-duration — no animation-fill-mode. Without one, the SPEC
 * DEFAULT applies once the keyframe finishes: the animated properties
 * (opacity, transform) revert to whatever the static CSS says, which here
 * is `opacity: 0` above — so the element would vanish again mid-hover, the
 * instant its entrance animation completed, even though the card is still
 * being hovered. `forwards` holds the keyframe's end state for as long as
 * the `animated` class stays on (i.e. until pointerleave removes it).
 *
 * `!important` is required specifically for the Elementor EDITOR's preview
 * iframe: it loads its own editor-preview.min.css with a blanket
 * `.animated{animation-fill-mode:none!important}` (so ITS OWN scroll-replay
 * preview of entrance animations never gets stuck mid-animation) — that
 * rule doesn't exist on the real frontend, which is why this bug only shows
 * up while editing. Our selector is already more specific than Elementor's
 * plain `.animated`, so with matching `!important` this reliably wins
 * regardless of stylesheet load order.
 */
.mdsproduct-product-card-button[data-hover-animation].animated,
.mdsproduct-product-card-title[data-hover-animation].animated {
  animation-fill-mode: forwards !important;
}

.mdsproduct-product-card-button,
.mdsproduct-product-card-title {
  justify-self: center;
  align-self: center;
}

/*
 * Offset X/Y use margin, not transform: entrance animations (zoomIn,
 * bounceInDown, slideInUp, ...) animate `transform` themselves, and a
 * CSS Animation's own transform value always wins over a plain rule's
 * while (and after, via fill-mode) it's running — a `transform: translate()`
 * here would get silently blown away by the animate.css keyframe instead of
 * combining with it. Set as plain margin values (Elementor's own generated,
 * higher-specificity {{WRAPPER}}-scoped rule overrides these directly when
 * a non-default value is set) rather than via a CSS custom property — one
 * less layer of indirection between the control and what actually moves.
 */
.mdsproduct-product-card-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background-color: rgba(15, 23, 42, 0.75);
  padding: 10px 22px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  margin-left: 0px;
  margin-top: -18px;
  transition: background-color 0.2s ease, color 0.2s ease, opacity 0.25s ease;
}

/* Only takes effect once an icon is actually rendered next to the text
   (see AbstractProductsWidget::buttonInnerHtml()) — `gap` has no visible
   effect on a single-child flex container, so this is safe to leave on
   unconditionally rather than toggling a class. */
.mdsproduct-product-card-button-icon {
  display: inline-flex;
  align-items: center;
  font-size: 1em;
  line-height: 1;
}

.mdsproduct-product-card-button-icon svg {
  width: 1em;
  height: 1em;
  fill: currentColor;
}

.mdsproduct-product-card-button:hover {
  background-color: rgba(15, 23, 42, 0.95);
  color: #ffffff;
}

.mdsproduct-product-card-title {
  display: inline-block;
  color: #ffffff;
  background-color: rgba(15, 23, 42, 0.6);
  padding: 8px 16px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: 0px;
  margin-top: 18px;
}

/* Variations modal — deliberately a simple, non-Elementor-configurable
   default: it's a utility view for picking a variation, not a design
   surface. Rendered once per card (right after that card, outside its
   `overflow: hidden` box — a `position: fixed` element nested inside an
   `overflow: hidden` ancestor would otherwise be clipped to it). */
.mdsproduct-variations-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.mdsproduct-variations-modal.is-open {
  display: flex;
}

.mdsproduct-variations-modal-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
}

.mdsproduct-variations-modal-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  max-height: 85vh;
  overflow-y: auto;
  background-color: #ffffff;
  border-radius: 10px;
  padding: 32px;
}

.mdsproduct-variations-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background-color: #f0f0f0;
  color: #333333;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.mdsproduct-variations-modal-close:hover {
  background-color: #e2e2e2;
}

.mdsproduct-variations-modal-heading {
  margin: 0 0 20px 0;
  padding-right: 40px;
  font-size: 20px;
  font-weight: 600;
  color: #1a1a1a;
}

/*
 * --mdsproduct-modal-columns comes from the widget's own responsive
 * "Columns" control (per-instance, per-breakpoint); --mdsproduct-modal-count
 * is set inline per-modal from the actual variation count
 * (render_variations_modal()). Using min() of the two means the grid never
 * defines more column TRACKS than there are cards to fill them — 2
 * variations in a "Columns: 3" grid renders as 2 real (stretched-to-fill)
 * columns, not 2 filled + 1 empty one.
 */
.mdsproduct-variations-modal-grid {
  display: grid;
  grid-template-columns: repeat(min(var(--mdsproduct-modal-columns, 3), var(--mdsproduct-modal-count, 3)), 1fr);
  gap: 20px;
}

/* One variation entry: image on top, title below, Buy Now button below
   that — a plain stacked layout, always visible (this is a "browse and
   pick a variation" screen, not a hover-reveal card). */
.mdsproduct-variation-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.mdsproduct-variation-card-image {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 8px;
  background-color: #f0f0f0;
}

.mdsproduct-variation-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.mdsproduct-variation-card-title {
  font-size: 14px;
  font-weight: 500;
  color: #1a1a1a;
}

.mdsproduct-variation-card-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 6px;
  background-color: #0f172a;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.mdsproduct-variation-card-button:hover {
  background-color: #1e293b;
  color: #ffffff;
}

body.mdsproduct-modal-open {
  overflow: hidden;
}
