/**
 * Widget Before & After (Focus Gallery)
 *
 * @package Martina
 */

.w-ba {
  display: grid;
  gap: 18px;
  overflow-x: clip; /* evita scrollbar “fantasma” */
}

/* Filtri (in alto) */
.w-ba__stage {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: center;
  padding: 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.w-ba__media {
  border-radius: 16px;
  overflow: hidden;
  background: var(--color-gray-100);
  position: relative;
  /* aspect-ratio: 4 / 5;  */
  max-height: 50vh; /* Limita altezza in desktop per stare in viewport */
}

@media (min-width: 901px) {
  .w-ba__media {
    max-width: 400px; /* Limita anche la larghezza per desktop */
    max-height: 500px; /* Altezza massima fissa per desktop */
    margin: 0 auto;
  }
}

.w-ba__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.01);
  transition: opacity 420ms ease, transform 520ms cubic-bezier(0.22, 1, 0.36, 1), filter 520ms ease;
}

.w-ba__meta {
  padding: 8px 6px;
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.w-ba__title {
  margin: 0 0 10px;
  font-size: 1.4rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--theme-text);
}

.w-ba__desc {
  margin: 0 0 14px;
  color: var(--theme-muted);
  line-height: 1.7;
  max-width: 58ch;
}

.w-ba__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  font-weight: 700;
  color: var(--color-text-primary);
  background: rgba(var(--color-primary-rgb), 0.6);
  border: 1px solid var(--color-border);
  transition: transform 220ms ease, background-color 220ms ease;
  cursor: pointer;
}

.w-ba__cta:hover {
  background: rgba(var(--color-primary-rgb), 0.85);
  transform: translateY(-1px);
}

.w-ba__thumbs {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap; /* Mai wrap: orizzontale sempre */
}

.w-ba__thumb {
  text-align: center;
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: transform 220ms ease, background-color 220ms ease, opacity 220ms ease;
}

.w-ba__thumb:hover {
  background: rgba(var(--color-primary-rgb), 0.25);
  transform: translateY(-1px);
}

.w-ba__thumb.is-active {
  background: rgba(var(--color-primary-rgb), 0.35);
  border-color: rgba(0, 0, 0, 0.1);
}

.w-ba__thumbLabel {
  font-weight: 700;
  color: var(--theme-text);
  line-height: 1.2;
}

/* Overlay su immagine: darken + descrizione */
.w-ba__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 420ms ease, transform 520ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  display: grid;
  align-content: center;
  padding: 22px;
}

.w-ba.is-open .w-ba__overlay {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.w-ba__overlayInner {
  max-width: 60ch;
  margin: 0 auto;
  text-align: center;
  color: #fff;
}

.w-ba__overlayTitle {
  margin: 0 0 10px;
  font-size: clamp(20px, 2.4vw, 28px);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.w-ba__overlayDesc {
  margin: 0;
  line-height: 1.7;
  opacity: 0.92;
}

.w-ba__overlayClose {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.25);
  cursor: pointer;
}

.w-ba__overlayClose::before,
.w-ba__overlayClose::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 2px;
  background: rgba(255,255,255,0.85);
  transform-origin: center;
}

.w-ba__overlayClose::before { transform: translate(-50%, -50%) rotate(45deg); }
.w-ba__overlayClose::after { transform: translate(-50%, -50%) rotate(-45deg); }

/* Transition state (when switching active item) */
.w-ba.is-switching .w-ba__image {
  opacity: 0;
  transform: scale(1.03);
  filter: blur(6px);
}

@media (max-width: 900px) {
  .w-ba__thumbs {
    justify-content: flex-start;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding: 6px 10vw 10px;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    overscroll-behavior-x: contain;
    flex-wrap: nowrap; /* Forza orizzontale su mobile */
  }
  .w-ba__thumbs::-webkit-scrollbar {
    display: none;
  }
  .w-ba__thumb {
    flex: 0 0 auto;
    white-space: nowrap; /* Evita che il testo vada a capo */
    scroll-snap-align: center;
    opacity: 0.72;
  }
  .w-ba__thumb.is-active {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .w-ba__image,
  .w-ba__thumb,
  .w-ba__cta,
  .w-ba__overlay {
    transition: none;
  }
  .w-ba.is-switching .w-ba__image {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

