/* ============================================================
   E-spotrebice — Product Gallery (vanilla, 2026)
   Replaces legacy jqzoom + fancybox + thumbs_list_frame.
   Namespace: .es-gallery (avoid conflicts with PS core styles)
   ============================================================ */

:root {
  --esg-border: #e3e6ec;
  --esg-paper: #f3f6fb;
  --esg-orange: #e8792b;
  --esg-blue: #003a78;
  --esg-ink: #1a1a1a;
  --esg-ink-2: #4a4a4a;
  --esg-radius-sm: 8px;
  --esg-radius-md: 12px;
  --esg-radius-lg: 16px;
}

/* ===== Gallery wrapper ===== */
.es-gallery {
  position: relative;
  max-width: 700px;           /* narrower box → bigger gap to right info block */
  margin: 0;                  /* left-align within parent column */
}

/* Mobile: override legacy #image-block { width:280px; margin:0 auto }
   that crops the gallery box. Use full column width — pb-left-column
   already adds 15px padding each side, so gallery hugs viewport edges
   with a small safe gutter. More room for image, thumbs, and badges. */
@media (max-width: 767px) {
  .pb-left-column #image-block {
    width: auto !important;
    margin: 0 !important;
  }
  .es-gallery {
    max-width: none;
    margin: 0;
  }
}

/* ===== Main image area (4:3 landscape box, shorter than square) ===== */
.es-gallery-main {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #fff;
  border: 0;
  border-radius: 0;
  overflow: hidden;
}

.es-gtrack {
  display: flex;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.es-gtrack::-webkit-scrollbar { display: none; }
.es-gtrack:focus { outline: none; }
.es-gtrack:focus-visible {
  outline: 2px solid var(--esg-blue);
  outline-offset: 2px;
}

.es-slide {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  cursor: zoom-in;
}
/* Square frame inside each slide: locks image rendering to a 1:1 box
   regardless of source aspect ratio. The .es-slide is 4:3 (container);
   the frame is height-locked square inside, leaving natural side gaps
   for arrows/badges. Works across breakpoints since height follows the
   container automatically. */
.es-slide-frame {
  height: 100%;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}
.es-slide img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  box-sizing: border-box;
  pointer-events: none;
  background: transparent;
}

/* ===== Arrows (absolute inside .es-gallery-main, in image whitespace) ===== */
.es-gnav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--esg-border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, background 0.15s ease, transform 0.1s ease;
  z-index: 3;
  color: var(--esg-ink);
  padding: 0;
}
.es-gallery-main:hover .es-gnav,
.es-gnav:focus-visible { opacity: 1; }
.es-gnav:hover { background: #fff; }
.es-gnav:active { transform: translateY(-50%) scale(0.95); }
.es-gnav.prev { left: 10px; }
.es-gnav.next { right: 10px; }
.es-gnav[disabled] {
  opacity: 0.3 !important;
  cursor: not-allowed;
  pointer-events: none;
}
.es-gnav svg {
  width: 18px;
  height: 18px;
  color: var(--esg-ink);
}
@media (max-width: 767px) {
  /* Mobile: always visible, smaller */
  .es-gnav { opacity: 1; width: 36px; height: 36px; }
  .es-gnav.prev { left: 6px; }
  .es-gnav.next { right: 6px; }
  .es-gnav svg { width: 16px; height: 16px; }
}

/* ===== Counter (bottom-right, decent white pill) ===== */
.es-gcounter {
  position: absolute;
  right: 16px;
  bottom: 16px;
  background: rgba(255,255,255,0.95);
  color: #4b5563;
  border: 1px solid #e5e7eb;
  font: 600 12px/1 'Inter Tight', 'Inter', system-ui, sans-serif;
  padding: 6px 14px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 3;
}

/* ===== Thumbnails ===== */
.es-gthumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  margin-top: 12px;
  padding: 4px 0;
  scrollbar-width: thin;
  scroll-behavior: smooth;
}
.es-gthumbs::-webkit-scrollbar { height: 6px; }
.es-gthumbs::-webkit-scrollbar-thumb { background: var(--esg-border); border-radius: 999px; }
.es-thumb {
  flex: 0 0 64px;
  aspect-ratio: 1 / 1;
  border: 2px solid transparent;
  border-radius: var(--esg-radius-sm);
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;
  transition: border-color 0.15s ease;
}
.es-thumb:hover { border-color: var(--esg-border); }
.es-thumb[aria-current="true"] { border-color: var(--esg-orange); }
.es-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
  pointer-events: none;
  background: transparent;
}
@media (min-width: 768px) {
  .es-thumb { flex: 0 0 72px; }
}
/* Mobile: hide thumbnail strip — gallery is opened by tapping the main image
   (fullscreen <dialog> handles the multi-image browsing). */
@media (max-width: 767px) {
  .es-gthumbs { display: none; }
}
/* Tablet: hide thumbs ALSO for color-picker products (drez/batéria flow). */
@media (min-width: 768px) and (max-width: 991px) {
  .primary_block.has-color-picker .es-gthumbs { display: none; }
}

/* ===== FULLSCREEN DIALOG ===== */
dialog.es-fs {
  width: min(1400px, 92vw);
  height: min(900px, 88vh);
  max-width: 92vw;
  max-height: 88vh;
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: #ffffff;
  color: var(--esg-ink);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  overflow: hidden;
}
dialog.es-fs::backdrop { background: rgba(40,45,55,0.55); }

.es-fs-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.es-fs-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid var(--esg-border);
  color: var(--esg-ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 4;
  padding: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}
.es-fs-close:hover { background: var(--esg-paper); }
.es-fs-close:active { transform: scale(0.95); }
.es-fs-close svg { width: 22px; height: 22px; }

.es-fs-track {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  scroll-behavior: smooth;
  background: #fff;
}
.es-fs-track::-webkit-scrollbar { display: none; }

.es-fs-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5%;
  box-sizing: border-box;
}
.es-fs-slide img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  background: transparent;
}
@media (max-width: 640px) {
  .es-fs-slide { padding: 3%; }
}

.es-fs-nav {
  position: absolute;
  top: calc(50% - 60px);
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid var(--esg-border);
  color: var(--esg-blue);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 4;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  padding: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}
.es-fs-nav:hover { background: var(--esg-paper); }
.es-fs-nav:active { transform: translateY(-50%) scale(0.95); }
.es-fs-nav[disabled] {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}
.es-fs-nav.prev { left: 24px; }
.es-fs-nav.next { right: 24px; }
.es-fs-nav svg { width: 22px; height: 22px; }

.es-fs-counter {
  position: absolute;
  left: 50%;
  bottom: calc(112px + 12px);
  transform: translateX(-50%);
  color: var(--esg-ink-2);
  font: 600 13px/1 'Inter Tight', 'Inter', system-ui, sans-serif;
  background: rgba(255,255,255,0.92);
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--esg-border);
  pointer-events: none;
}

.es-fs-thumbs {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 16px;
  background: #fff;
  border-top: 1px solid var(--esg-border);
  scrollbar-width: thin;
  scroll-behavior: smooth;
  justify-content: safe center;
}
/* Fallback: nudge edges with margin auto so flex container scrolls cleanly when overflowing */
.es-fs-thumbs > .es-fs-thumb:first-child { margin-left: auto; }
.es-fs-thumbs > .es-fs-thumb:last-child { margin-right: auto; }
.es-fs-thumbs::-webkit-scrollbar { height: 6px; }
.es-fs-thumbs::-webkit-scrollbar-thumb { background: var(--esg-border); border-radius: 999px; }
.es-fs-thumb {
  flex: 0 0 72px;
  aspect-ratio: 1 / 1;
  border: 2px solid transparent;
  border-radius: var(--esg-radius-sm);
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;
  transition: border-color 0.15s ease;
}
.es-fs-thumb:hover { border-color: var(--esg-border); }
.es-fs-thumb[aria-current="true"] { border-color: var(--esg-orange); }
.es-fs-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
  pointer-events: none;
  background: transparent;
}
@media (min-width: 768px) {
  .es-fs-thumb { flex: 0 0 84px; }
}
@media (max-width: 640px) {
  .es-fs-nav { display: none; }
  .es-fs-close { top: 12px; right: 12px; }
  .es-fs-counter { bottom: calc(104px + 8px); }
  .es-fs-thumbs { padding: 12px; }
  .es-fs-thumb { flex: 0 0 60px; }
}

/* ===== Override legacy product.css conflicts ===== */
.pb-left-column .es-gallery img { background: transparent !important; }
.pb-left-column .es-gallery {
  background: transparent;
}

/* ============================================================
   CLS PREVENTION: hide energylabels at original location.
   The displayProductLeftColumn hook renders <p class="energylabels">
   as a direct child of .pb-left-column BEFORE JS moves it into the
   gallery corner. Hiding it via CSS means initial paint has the
   correct layout — no shift when JS reparents it.
   Selector becomes invalid the instant JS moves it (no longer a
   direct child of .pb-left-column), so it appears naturally.
   ============================================================ */
.pb-left-column > .energylabels { display: none; }

/* ============================================================
   LABELS STACK — top-left vertical stack inside gallery
   Supports: sale (-XX%), NEW, energy class, custom (productlabels)
   Designed to grow — add more children, they stack with 8px gap
   ============================================================ */
.es-gallery-main .labels-corner {
  position: absolute;
  top: 16px;
  left: 16px;
  right: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  z-index: 4;
  pointer-events: none;
  max-width: calc(100% - 32px);
}
.es-gallery-main .labels-corner > * {
  pointer-events: auto;
  flex: 0 0 auto;
  align-self: flex-start;
}

/* --- Sale / NEW wrapper: flex item sized to its label content --- */
.es-gallery-main .labels-corner .new-box,
.es-gallery-main .labels-corner .sale-box {
  display: inline-block !important;
  position: static !important;
  width: auto !important;
  height: auto !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  overflow: visible !important;
  background: transparent !important;
  padding: 0 !important;
  margin: 0 !important;
  text-align: left !important;
  z-index: auto !important;
  top: auto !important;
  right: auto !important;
}

/* --- Modern pill style for SALE / NEW labels --- */
.es-gallery-main .labels-corner .new-label,
.es-gallery-main .labels-corner .sale-label {
  position: static !important;
  display: inline-block !important;
  padding: 6px 14px !important;
  border-radius: 999px !important;
  font: 700 13px/1 'Inter Tight', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif !important;
  color: #fff !important;
  background-image: none !important;
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
  height: auto !important;
  margin: 0 !important;
  text-align: center !important;
  text-indent: 0 !important;
  text-shadow: none !important;
  text-transform: none !important;
  white-space: nowrap !important;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08) !important;
  top: auto !important;
  right: auto !important;
  left: auto !important;
}
.es-gallery-main .labels-corner .new-label {
  background: #16a34a !important;
}
.es-gallery-main .labels-corner .sale-label {
  background: #dc2626 !important;
}
/* Voucher promo banners (wider, can wrap) */
.es-gallery-main .labels-corner .sale-label[style*="200px"] {
  white-space: normal !important;
  max-width: 240px !important;
  font-size: 11px !important;
  line-height: 1.3 !important;
  padding: 6px 12px !important;
}

/* --- Energy label (moved by JS into corner) --- */
.es-gallery-main .labels-corner .energylabels {
  margin: 0 !important;
  padding: 0 !important;
  display: inline-block !important;
  width: auto !important;
  position: static !important;
}
.es-gallery-main .labels-corner .energylabels span.energy_label,
#product .es-gallery-main .labels-corner .energylabels span.energy_label {
  position: static !important;
  display: inline-flex !important;
  align-items: center;
  background: #fff;
  border: 1px solid var(--esg-border);
  border-radius: 6px;
  padding: 3px 6px;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  margin: 0 !important;
}
.es-gallery-main .labels-corner .energylabels a img {
  display: block;
  height: 24px !important;
  width: auto !important;
}

/* --- productlabels module (moved into corner by JS) --- */
.es-gallery-main .labels-corner .product_labels {
  position: static !important;
  display: inline-flex !important;
  flex-direction: column;
  gap: 8px;
  margin: 0 !important;
  padding: 0 !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  width: auto !important;
  height: auto !important;
  transform: none !important;
}
.es-gallery-main .labels-corner .product_labels .productlabel {
  position: static !important;
  display: inline-flex !important;
  align-items: center;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  padding: 0;
  background: transparent;
  box-shadow: none;
}
.es-gallery-main .labels-corner .product_labels .productlabel img {
  display: block;
  max-height: 40px;
  max-width: 120px;
  width: auto !important;
  height: auto !important;
  object-fit: contain;
}
.es-gallery-main .labels-corner .product_labels .productlabel.noimage {
  padding: 6px 14px;
  border-radius: 999px;
  font: 700 13px/1 'Inter Tight', 'Inter', system-ui, sans-serif;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

/* --- productlabels OUTSIDE corner (fallback): hide empty imgs --- */
.es-gallery-main .product_labels img[src=""],
.es-gallery-main .product_labels img:not([src]) {
  display: none;
}

/* ============================================================
   ProductLabels — corner stack constrained to 110px (variant B)
   Hook moved out of .labels-corner, positioned directly in
   .es-gallery-main per the label's grid_position field.
   ============================================================ */
.es-gallery-main .product_labels {
  position: absolute !important;
  z-index: 4;
  max-width: 130px !important;
  margin: 0 !important;
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.es-gallery-main .product_labels > * {
  pointer-events: auto;
}

/* Grid-position variations (override module's default positioning) */
.es-gallery-main .product_labels.top-left {
  top: 16px; left: 16px; right: auto; bottom: auto;
  align-items: flex-start; transform: none;
}
.es-gallery-main .product_labels.top-right {
  top: 16px; right: 16px; left: auto; bottom: auto;
  align-items: flex-end; transform: none;
}
.es-gallery-main .product_labels.bottom-left {
  bottom: 16px; left: 16px; right: auto; top: auto;
  align-items: flex-start; transform: none;
}
.es-gallery-main .product_labels.bottom-right {
  bottom: 16px; right: 16px; left: auto; top: auto;
  align-items: flex-end; transform: none;
}
.es-gallery-main .product_labels.top-center {
  top: 16px; left: 50%; right: auto; bottom: auto;
  transform: translateX(-50%); align-items: center;
}
.es-gallery-main .product_labels.bottom-center {
  bottom: 16px; left: 50%; right: auto; top: auto;
  transform: translateX(-50%); align-items: center;
}
.es-gallery-main .product_labels.center-left {
  top: 50%; left: 16px; right: auto; bottom: auto;
  transform: translateY(-50%); align-items: flex-start;
}
.es-gallery-main .product_labels.center-right {
  top: 50%; right: 16px; left: auto; bottom: auto;
  transform: translateY(-50%); align-items: flex-end;
}
.es-gallery-main .product_labels.center-center {
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  align-items: center;
}

/* Individual label sizing — cap to 110px square */
.es-gallery-main .product_labels .productlabel {
  display: block;
  max-width: 110px;
  width: auto;
  margin: 0;
  padding: 0;
  background: transparent;
}
.es-gallery-main .product_labels .productlabel img {
  display: block;
  max-width: 110px;
  max-height: 110px;
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.18));
}

/* Mobile — even more compact */
@media (max-width: 767px) {
  .es-gallery-main .product_labels {
    max-width: 80px !important;
    gap: 6px;
  }
  .es-gallery-main .product_labels .productlabel,
  .es-gallery-main .product_labels .productlabel img {
    max-width: 70px;
    max-height: 70px;
  }
  .es-gallery-main .product_labels.top-left,
  .es-gallery-main .product_labels.top-right,
  .es-gallery-main .product_labels.top-center { top: 10px; }
  .es-gallery-main .product_labels.bottom-left,
  .es-gallery-main .product_labels.bottom-right,
  .es-gallery-main .product_labels.bottom-center { bottom: 10px; }
  .es-gallery-main .product_labels.top-left,
  .es-gallery-main .product_labels.bottom-left,
  .es-gallery-main .product_labels.center-left { left: 10px; }
  .es-gallery-main .product_labels.top-right,
  .es-gallery-main .product_labels.bottom-right,
  .es-gallery-main .product_labels.center-right { right: 10px; }
}
