/* ESMÉRA — Product modal v2
 * Dedicated source of truth for product-card triggers, modal gallery, buybox
 * and image zoom. Kept independent from Header/search/cart styling.
 */

html.esv-product-modal-active {
  overscroll-behavior: none;
}

body.esv-product-modal-open {
  overscroll-behavior: none;
}

/* The product modal is a full-viewport takeover at every breakpoint: the
 * backdrop (.esv-product-modal-backdrop — position: fixed; inset: 0;
 * z-index: 410) sits above the header (z-index 120) and covers it entirely.
 * A previous desktop-only block lifted the header to z-index 420, made it a
 * solid passive bar above the scrim, and reserved header-height padding on the
 * backdrop — which left the header visibly stacked on top of the modal on
 * desktop. Removed so desktop matches the intended full-screen takeover. The
 * scroll-lock header-state guard in EsmeraHeader.tsx is unrelated and stays. */

/* Product cards open the same modal from media, title or CTA. */
.esv-product-media-wrap {
  position: relative;
  min-width: 0;
}

.esv-product-media-wrap > .esv-product-media {
  margin: 0;
}

.esv-product-modal-trigger {
  appearance: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.esv-product-modal-trigger-media {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: zoom-in;
}

.esv-product-modal-trigger-media:focus-visible {
  outline: 1px solid rgba(243, 240, 232, .88);
  outline-offset: -8px;
}

.esv-product-modal-trigger-title {
  width: 100%;
  color: inherit;
  line-height: inherit;
  text-align: left;
}

.esv-product-modal-trigger-title:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.esv-product-card h3 .esv-product-modal-trigger-title {
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
}

/* Modal shell */
.esv-product-modal-backdrop {
  position: fixed;
  z-index: 410;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(18px, 2.4vw, 38px);
  background: rgba(17, 18, 16, .76);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 1;
  transition: opacity 260ms cubic-bezier(.4, 0, .2, 1);
}

.esv-product-modal {
  --esv-modal-buybox-w: clamp(380px, 27vw, 440px);
  --esv-modal-w: min(1440px, 96vw, calc(132dvh + var(--esv-modal-buybox-w)));
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--esv-modal-buybox-w);
  width: var(--esv-modal-w);
  height: auto;
  overflow: hidden;
  border: 1px solid rgba(243, 240, 232, .12);
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .22);
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
  transition:
    opacity 260ms cubic-bezier(.4, 0, .2, 1),
    transform 260ms cubic-bezier(.4, 0, .2, 1);
}

.esv-product-modal-backdrop[data-phase="opening"],
.esv-product-modal-backdrop[data-phase="closing"] {
  opacity: 0;
}

.esv-product-modal-backdrop[data-phase="opening"] .esv-product-modal,
.esv-product-modal-backdrop[data-phase="closing"] .esv-product-modal {
  opacity: 0;
  transform: translate3d(0, 10px, 0) scale(.995);
}

.esv-product-modal-backdrop[data-phase="closing"] {
  pointer-events: none;
}

.esv-product-modal-close,
.esv-product-zoom-close {
  appearance: none;
  position: absolute;
  z-index: 8;
  top: 16px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(38, 39, 36, .18);
  border-radius: 50%;
  background: rgba(243, 240, 232, .88);
  color: var(--ink);
  cursor: pointer;
  transition:
    background-color 180ms ease,
    transform 180ms var(--ease-esmera);
}

.esv-product-modal-close:hover,
.esv-product-zoom-close:hover {
  background: var(--bg);
  transform: rotate(2deg);
}

/* Canonical gallery stage. Ratio belongs to the brand, not to each file. */
.esv-product-modal-gallery-frame {
  --esv-stage-inset: clamp(20px, 2.4vw, 48px);
  position: relative;
  width: 100%;
  height: auto;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 3 / 2;
  justify-self: stretch;
  overflow: hidden;
  background: var(--bg);
  --esv-gallery-pair-gap: 0px;
}

.esv-product-modal-gallery-frame.is-compact {
  display: none;
}

.esv-product-modal-gallery {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

.esv-product-modal-slide {
  position: absolute;
  inset: 0;
  display: grid;
  width: 100%;
  height: 100%;
  visibility: hidden;
  pointer-events: none;
}

.esv-product-modal-slide.is-active {
  visibility: visible;
  pointer-events: auto;
}

@media (min-width: 1024px) {
  .esv-product-modal-slide {
    opacity: 0;
    transition:
      opacity 240ms cubic-bezier(.4, 0, .2, 1),
      visibility 0s linear 240ms;
  }

  .esv-product-modal-slide.is-active {
    opacity: 1;
    transition-delay: 0s;
  }
}

@media (prefers-reduced-motion: reduce) {
  .esv-product-modal-slide {
    transition: none;
  }
}

.esv-product-modal-slide.is-single {
  grid-template-columns: minmax(0, 1fr);
}

.esv-product-modal-slide.is-pair {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--esv-gallery-pair-gap);
}

.esv-product-modal-slide.is-mounted {
  grid-template-columns: 50%;
  justify-content: center;
}

.esv-product-modal-image {
  appearance: none;
  box-sizing: border-box;
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  padding: var(--esv-stage-inset);
  overflow: hidden;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.esv-product-modal-image img {
  position: absolute;
  inset: var(--esv-stage-inset);
  display: block;
  width: calc(100% - (2 * var(--esv-stage-inset)));
  height: calc(100% - (2 * var(--esv-stage-inset)));
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  object-position: center;
}

.esv-product-modal-image > span {
  position: absolute;
  z-index: 2;
  right: 16px;
  bottom: 14px;
  padding: 6px 8px;
  border: 1px solid rgba(243, 240, 232, .28);
  background: rgba(17, 18, 16, .46);
  color: var(--ink-inverse);
  font-size: 9px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: .10em;
  text-transform: uppercase;
  opacity: .82;
  transition: opacity 180ms ease;
}

.esv-product-modal-gallery-controls {
  position: absolute;
  z-index: 4;
  bottom: 18px;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 8px;
  border: 1px solid rgba(243, 240, 232, .26);
  background: rgba(17, 18, 16, .46);
  color: var(--ink-inverse);
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.esv-product-modal-gallery-controls button {
  appearance: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.esv-product-modal-gallery-controls span {
  min-width: 54px;
  font-size: 9px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: .12em;
  text-align: center;
}

.esv-product-modal-gallery-mobile-counter {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .esv-product-modal-image:hover > span {
    opacity: 1;
  }
}

/* Buybox */
.esv-product-modal-buybox {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  contain: size;
  border-left: 1px solid var(--line);
}

.esv-product-modal-buybox-scroll {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  padding: clamp(54px, 5vw, 78px) clamp(34px, 4vw, 64px) 30px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.esv-product-modal-buybox-footer {
  position: sticky;
  z-index: 4;
  bottom: 0;
  flex: 0 0 auto;
  padding: 12px clamp(34px, 4vw, 64px) clamp(18px, 2vw, 24px);
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.esv-product-modal-heading h2 {
  max-width: 12ch;
  margin: 16px 0 10px;
  font-size: clamp(34px, 3.1vw, 52px);
  font-weight: 300;
  line-height: .98;
  letter-spacing: -.035em;
}

.esv-product-modal-subtitle {
  max-width: 34ch;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.esv-product-modal-price {
  display: block;
  margin-top: 22px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
}

.esv-product-modal-installment {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
}

.esv-product-modal-installment strong {
  color: inherit;
  font-weight: 500;
}

.esv-product-modal-description {
  max-width: 44ch;
  margin: 30px 0 0;
  font-size: 13px;
  line-height: 1.65;
}

.esv-product-modal-facts {
  margin: 32px 0 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.esv-product-modal-facts > div {
  display: grid;
  grid-template-columns: minmax(92px, .72fr) minmax(0, 1.28fr);
  gap: 20px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.esv-product-modal-facts dt,
.esv-product-modal-facts dd {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
}

.esv-product-modal-facts dt {
  color: var(--muted);
  letter-spacing: .055em;
  text-transform: uppercase;
}

.esv-product-modal-facts dd {
  text-align: right;
}

.esv-product-modal-variant {
  display: block;
  margin-top: 30px;
}

.esv-product-modal-variant > span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.esv-product-modal-variant select {
  width: 100%;
  min-height: 46px;
  padding: 0 34px 0 0;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  outline: none;
}

.esv-product-modal-add {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 0 20px;
  border: 0;
  border-bottom: 0;
  background: var(--ink);
  color: var(--bg);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 180ms ease;
}

.esv-product-modal-add:hover {
  background: rgba(38, 39, 36, .88);
}

.esv-product-modal-add:focus-visible {
  outline: 1px solid var(--bg);
  outline-offset: -4px;
}

.esv-product-modal-add span:last-child {
  transition: transform 180ms var(--ease-esmera);
}

.esv-product-modal-add:hover span:last-child {
  transform: translate3d(2px, -2px, 0);
}

.esv-product-modal-recommendations {
  margin-top: 44px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.esv-product-modal-recommendations h3 {
  margin: 0 0 18px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: .14em;
}

.esv-product-modal-related-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 12px;
}

.esv-product-modal-related-card {
  appearance: none;
  display: flex;
  min-width: 0;
  padding: 0;
  flex-direction: column;
  align-items: stretch;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.esv-product-modal-related-media,
.esv-product-modal-related-skeleton > span {
  --esv-related-card-ratio: 4 / 5;
  display: block;
  width: 100%;
  aspect-ratio: var(--esv-related-card-ratio);
  overflow: hidden;
  background: var(--bg-alt);
}

.esv-product-modal-related-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  transition: transform 260ms var(--ease-esmera);
}

.esv-product-modal-related-card strong,
.esv-product-modal-related-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.esv-product-modal-related-card strong {
  margin-top: 9px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.3;
}

.esv-product-modal-related-card small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.3;
}

.esv-product-modal-related-card:focus-visible {
  outline: 1px solid currentColor;
  outline-offset: 3px;
}

.esv-product-modal-related-skeleton {
  min-width: 0;
}

.esv-product-modal-related-skeleton i {
  display: block;
  width: 84%;
  height: 8px;
  margin-top: 9px;
  background: var(--line);
}

.esv-product-modal-related-skeleton i:last-child {
  width: 54%;
  margin-top: 5px;
}

@media (hover: hover) and (pointer: fine) {
  .esv-product-modal-related-card:hover img {
    transform: scale(1.02);
  }
}

/* Full-screen image zoom */
.esv-product-zoom {
  position: fixed;
  z-index: 520;
  inset: 0;
  display: grid;
  place-items: stretch;
  background: rgba(11, 12, 10, .97);
  color: var(--ink-inverse);
  animation: esv-product-backdrop-in 160ms ease both;
}

.esv-product-zoom-dialog {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  padding: clamp(54px, 6vh, 78px) clamp(28px, 7vw, 118px) clamp(72px, 9vh, 104px);
}

.esv-product-zoom-close {
  border-color: rgba(243, 240, 232, .24);
  background: rgba(17, 18, 16, .62);
  color: var(--ink-inverse);
}

.esv-product-zoom-close:hover {
  background: rgba(243, 240, 232, .12);
}

.esv-product-zoom-stage {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}

.esv-product-zoom-stage img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  animation: esv-product-image-in 260ms var(--ease-esmera) both;
}

.esv-product-zoom-controls {
  position: absolute;
  right: 0;
  bottom: 24px;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.esv-product-zoom-controls button {
  appearance: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.esv-product-zoom-controls span {
  min-width: 44px;
  font-size: 10px;
  letter-spacing: .12em;
  text-align: center;
}

.esv-product-viewer-dialog {
  isolation: isolate;
}

.esv-product-viewer-stage {
  position: relative;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: zoom-in;
}

.esv-product-viewer-stage.is-zoomed {
  cursor: grab;
}

.esv-product-viewer-stage.is-zoomed:active {
  cursor: grabbing;
}

.esv-product-viewer-stage .esv-product-viewer-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  transform-origin: center;
  will-change: transform;
  transition: transform 120ms ease-out;
  pointer-events: none;
  -webkit-user-drag: none;
  animation: esv-product-viewer-image-in 260ms var(--ease-esmera) both;
}

.esv-product-viewer-toolbar {
  position: absolute;
  z-index: 6;
  right: 24px;
  bottom: 24px;
  display: flex;
  align-items: center;
  min-height: 44px;
  border: 1px solid rgba(243, 240, 232, .22);
  background: rgba(17, 18, 16, .62);
  color: var(--ink-inverse);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.esv-product-viewer-toolbar button {
  appearance: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 18px;
  cursor: pointer;
}

.esv-product-viewer-toolbar button:disabled {
  opacity: .3;
  cursor: default;
}

.esv-product-viewer-toolbar span {
  min-width: 52px;
  font-size: 10px;
  letter-spacing: .08em;
  text-align: center;
}

.esv-product-viewer-toolbar button:focus-visible,
.esv-product-zoom-controls button:focus-visible,
.esv-product-zoom-close:focus-visible {
  outline: 1px solid rgba(243, 240, 232, .9);
  outline-offset: -4px;
}

@keyframes esv-product-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes esv-product-image-in {
  from {
    opacity: 0;
    transform: scale(.988);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 1023.98px),
  (max-width: 1180px) and (orientation: portrait) {
  .esv-product-modal-gallery-frame {
    aspect-ratio: 1 / 1;
  }

  .esv-product-modal-gallery-frame.is-desktop {
    display: none;
  }

  .esv-product-modal-gallery-frame.is-compact {
    display: block;
  }

  .esv-product-modal {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    width: min(920px, 100%);
    height: auto;
    max-height: 94dvh;
    overflow-y: auto;
  }

  .esv-product-modal-buybox {
    overflow: visible;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .esv-product-modal-buybox-scroll {
    overflow: visible;
  }

  .esv-product-modal-buybox-footer {
    padding-bottom: 30px;
  }

  .esv-product-modal-related-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@keyframes esv-product-viewer-image-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 767px) {
  .esv-product-modal-gallery-frame {
    --esv-stage-inset: 14px;
  }

  .esv-product-modal-backdrop {
    place-items: stretch;
    padding: 0;
    background: var(--bg);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .esv-product-modal {
    display: block;
    width: 100%;
    height: 100dvh;
    max-height: none;
    overflow-y: auto;
    border: 0;
    box-shadow: none;
  }

  .esv-product-modal-close {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
    background: rgba(243, 240, 232, .9);
  }

  .esv-product-modal-gallery {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }

  .esv-product-modal-gallery::-webkit-scrollbar {
    display: none;
  }

  .esv-product-modal-slide,
  .esv-product-modal-slide.is-active {
    position: relative;
    inset: auto;
    flex: 0 0 100%;
    display: grid;
    visibility: visible;
    pointer-events: auto;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }

  .esv-product-modal-gallery-controls {
    display: none;
  }

  .esv-product-modal-gallery-mobile-counter {
    position: absolute;
    z-index: 5;
    bottom: 12px;
    left: 50%;
    display: block;
    min-width: 60px;
    padding: 7px 8px;
    border: 1px solid rgba(243, 240, 232, .26);
    background: rgba(17, 18, 16, .46);
    color: var(--ink-inverse);
    font-size: 9px;
    font-weight: 500;
    line-height: 1;
    letter-spacing: .12em;
    text-align: center;
    pointer-events: none;
    transform: translateX(-50%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .esv-product-modal-image > span {
    right: 10px;
    bottom: 10px;
    font-size: 8px;
  }

  .esv-product-modal-buybox {
    min-height: auto;
  }

  .esv-product-modal-buybox-scroll {
    padding: 40px var(--page-x) 24px;
  }

  .esv-product-modal-buybox-footer {
    padding: 10px var(--page-x) max(24px, env(safe-area-inset-bottom));
  }

  .esv-product-modal-related-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 12px;
  }

  .esv-product-modal-heading h2 {
    max-width: 11ch;
    font-size: clamp(34px, 10vw, 46px);
  }

  .esv-product-modal-facts > div {
    grid-template-columns: minmax(86px, .7fr) minmax(0, 1.3fr);
  }

  .esv-product-zoom-dialog {
    padding: max(62px, calc(env(safe-area-inset-top) + 52px)) 14px
      max(76px, calc(env(safe-area-inset-bottom) + 66px));
  }

  .esv-product-zoom-close {
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
  }

  .esv-product-viewer-toolbar {
    right: auto;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 14px;
  }

  .esv-product-viewer .esv-product-zoom-controls {
    right: 14px;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: auto;
  }

  .esv-product-viewer .esv-product-zoom-controls button {
    width: 40px;
    height: 44px;
  }

  .esv-product-viewer .esv-product-zoom-controls span {
    min-width: 36px;
  }
}

@media (max-width: 429px) {
  .esv-product-modal-buybox-scroll,
  .esv-product-modal-buybox-footer {
    padding-inline: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .esv-product-modal-backdrop {
    transition-duration: 80ms;
  }

  .esv-product-modal {
    transform: none;
    transition: opacity 80ms linear;
  }

  .esv-product-modal-image img,
  .esv-product-modal-close,
  .esv-product-modal-add span,
  .esv-product-zoom,
  .esv-product-zoom-stage img {
    animation: none;
    transition: none;
  }

  .esv-product-modal-backdrop[data-phase="opening"] .esv-product-modal,
  .esv-product-modal-backdrop[data-phase="closing"] .esv-product-modal {
    transform: none;
  }

  .esv-product-viewer-stage .esv-product-viewer-image {
    transition: none;
  }
}
