/* ============================================================
   Instagram Carousel Widget — El Rancho de Popy
   Vanilla CSS. Todas las clases usan prefijo .igw- para no
   colisionar con Bootstrap 3 / Owl Carousel del sitio.
   ============================================================ */

.igw {
  /* ---- Paleta tomada del sitio ---- */
  --igw-verde: #10221b;
  --igw-verde-2: #1b3a2e;
  --igw-oliva: #759d5d;
  --igw-rojo: #991b1e;
  --igw-crema: #f2efdf;
  --igw-gris: #8b8b8b;
  --igw-borde: #e7e4d6;

  /* ---- Layout ---- */
  --igw-gap: 18px;
  --igw-per-view: 4;
  --igw-radio: 14px;

  --igw-font: "Onest", "Jost", "Palanquin", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --igw-font-alt: "Mansalva", cursive;

  position: relative;
  font-family: var(--igw-font);
  color: var(--igw-verde);
  box-sizing: border-box;
  max-width: 100%;
  overflow-x: hidden;
}

.igw *,
.igw *::before,
.igw *::after {
  box-sizing: border-box;
}

/* ============================================================
   CABECERA
   ============================================================ */
.igw__header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.igw__avatar {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  border-radius: 50%;
  padding: 2.5px;
  background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
  display: block;
  text-decoration: none;
}

.igw__avatar img,
.igw__avatar span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 2px solid #fff;
}

.igw__avatar span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 22px;
  color: var(--igw-verde);
  background: var(--igw-crema);
}

.igw__ident {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.igw__user {
  font-weight: 700;
  font-size: 17px;
  color: var(--igw-verde);
  text-decoration: none;
  transition: color 0.2s ease;
  word-break: break-word;
}

.igw__user:hover,
.igw__user:focus {
  color: var(--igw-oliva);
  text-decoration: none;
}

.igw__meta {
  font-size: 13px;
  color: var(--igw-gris);
}

.igw__follow {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--igw-verde);
  color: #fff !important;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border: none;
  transition: background 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
}

.igw__follow:hover,
.igw__follow:focus {
  background: var(--igw-oliva);
  color: #fff !important;
  text-decoration: none;
  transform: translateY(-1px);
}

.igw__follow svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ============================================================
   VIEWPORT + TRACK  (scroll-snap nativo = swipe perfecto)
   ============================================================ */
/* El "stage" NO recorta: aloja las flechas.
   El viewport SÍ recorta: aloja el track. */
.igw__stage {
  position: relative;
}

.igw__viewport {
  position: relative;
  overflow: hidden;
  border-radius: var(--igw-radio);
}

.igw__track {
  display: flex;
  gap: var(--igw-gap);
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 2px;
}

.igw__track::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.igw.is-dragging .igw__track {
  scroll-behavior: auto;
  scroll-snap-type: none;
  cursor: grabbing;
}

.igw.is-dragging .igw__slide {
  pointer-events: none;
}

.igw__slide {
  flex: 0 0
    calc(
      (100% - (var(--igw-gap) * (var(--igw-per-view) - 1))) /
        var(--igw-per-view)
    );
  width: calc(
    (100% - (var(--igw-gap) * (var(--igw-per-view) - 1))) / var(--igw-per-view)
  );
  max-width: calc(
    (100% - (var(--igw-gap) * (var(--igw-per-view) - 1))) / var(--igw-per-view)
  );
  min-width: 0; /* clave: el iframe/embed no fuerza el ancho del slide */
  scroll-snap-align: start;
  position: relative;
}

/* ============================================================
   TARJETA DE PUBLICACIÓN
   ============================================================ */
.igw__card {
  position: relative;
  display: block;
  width: 100%;
  padding: 100% 0 0 0; /* cuadrado 1:1 y reset del padding del botón */
  margin: 0;
  border-radius: var(--igw-radio);
  overflow: hidden;
  background: var(--igw-crema);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  border: 1px solid var(--igw-borde);
  box-shadow: 0 2px 10px rgba(16, 34, 27, 0.06);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  text-align: left;
}

.igw__card:hover,
.igw__card:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 12px 26px rgba(16, 34, 27, 0.18);
  outline: none;
}

.igw__card:focus-visible {
  outline: 3px solid var(--igw-oliva);
  outline-offset: 3px;
}

.igw__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  background: var(--igw-crema);
}

.igw__card:hover .igw__img {
  transform: scale(1.07);
}

/* Capa oscura + texto */
.igw__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 14px;
  background: linear-gradient(
    to top,
    rgba(16, 34, 27, 0.88) 0%,
    rgba(16, 34, 27, 0.45) 38%,
    rgba(16, 34, 27, 0) 68%
  );
  opacity: 0;
  transition: opacity 0.35s ease;
  color: #fff;
}

.igw__card:hover .igw__overlay,
.igw__card:focus-visible .igw__overlay {
  opacity: 1;
}

.igw__caption {
  font-size: 13px;
  line-height: 1.45;
  margin: 0 0 6px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.igw__date {
  font-size: 11.5px;
  opacity: 0.85;
  letter-spacing: 0.3px;
}

/* Badge de tipo de post (video / álbum) */
.igw__badge {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(16, 34, 27, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}

.igw__badge svg {
  width: 15px;
  height: 15px;
  fill: #fff;
}

/* Icono central que aparece al pasar el mouse */
.igw__zoom {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
  pointer-events: none;
}

.igw__zoom svg {
  width: 20px;
  height: 20px;
  fill: var(--igw-verde);
}

.igw__card:hover .igw__zoom,
.igw__card:focus-visible .igw__zoom {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ============================================================
   MODO EMBED (iframes oficiales de Instagram)
   ============================================================ */
.igw--embed .igw__card {
  padding-top: 0;
  height: 540px;
  background: #fff;
  cursor: default;
  display: flex;
  flex-direction: column;
}

.igw--embed .igw__card:hover {
  transform: none;
  box-shadow: 0 2px 10px rgba(16, 34, 27, 0.06);
}

.igw__embed-wrap {
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: var(--igw-radio);
  min-width: 0;
}

.igw__iframe {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  min-width: 100% !important;
  border: 0;
  display: block;
}

/* En modo embed, el iframe de Instagram tiene un ancho intrínseco.
   Estas reglas lo fuerzan a respetar el ancho del slide en mobile. */
.igw--embed .igw__slide,
.igw--embed .igw__card,
.igw--embed .igw__embed-wrap {
  min-width: 0 !important;
  max-width: 100% !important;
}

.igw--embed .igw__iframe,
.igw--embed iframe {
  width: 100% !important;
  min-width: 100% !important;
  max-width: 100% !important;
  border: 0 !important;
}

/* Fuerza 1 item por slide en modo embed en mobile */
@media (max-width: 767px) {
  .igw--embed .igw__slide {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .igw--embed .igw__card,
  .igw--embed .igw__embed-wrap {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
}

/* ============================================================
   FLECHAS
   ============================================================ */
.igw__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: #fff;
  box-shadow: 0 4px 16px rgba(16, 34, 27, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  padding: 0;
  transition: background 0.25s ease, opacity 0.25s ease, transform 0.25s ease;
}

.igw__nav svg {
  width: 17px;
  height: 17px;
  fill: var(--igw-verde);
  transition: fill 0.25s ease;
}

.igw__nav:hover:not(:disabled) {
  background: var(--igw-verde);
}

.igw__nav:hover:not(:disabled) svg {
  fill: #fff;
}

.igw__nav:disabled {
  opacity: 0;
  pointer-events: none;
}

.igw__nav--prev {
  left: 10px;
}

.igw__nav--next {
  right: 10px;
}

/* ============================================================
   DOTS
   ============================================================ */
.igw__dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  flex-wrap: wrap;
  padding: 0;
  list-style: none;
}

.igw__dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: none;
  padding: 0;
  background: #cfd6cd;
  cursor: pointer;
  transition: width 0.3s ease, background 0.3s ease;
}

.igw__dot.is-active {
  width: 26px;
  background: var(--igw-oliva);
}

/* ============================================================
   SKELETON / CARGA
   ============================================================ */
.igw__skeleton {
  position: absolute;
  inset: 0;
  border-radius: var(--igw-radio);
  background: linear-gradient(
    100deg,
    #eceade 25%,
    #f7f5ea 45%,
    #eceade 65%
  );
  background-size: 320% 100%;
  animation: igw-shimmer 1.4s ease-in-out infinite;
}

@keyframes igw-shimmer {
  0% {
    background-position: 130% 0;
  }
  100% {
    background-position: -30% 0;
  }
}

/* ============================================================
   MENSAJE DE ERROR / VACÍO
   ============================================================ */
.igw__msg {
  text-align: center;
  padding: 36px 20px;
  background: var(--igw-crema);
  border-radius: var(--igw-radio);
  color: var(--igw-verde);
  font-size: 15px;
  line-height: 1.6;
}

.igw__msg a {
  color: var(--igw-rojo);
  font-weight: 700;
  text-decoration: underline;
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
.igw-lb {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(10, 18, 14, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  font-family: var(--igw-font, sans-serif);
}

.igw-lb.is-open {
  opacity: 1;
  visibility: visible;
}

.igw-lb__box {
  position: relative;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  width: 100%;
  max-width: 940px;
  max-height: 88vh;
  display: flex;
  transform: scale(0.94);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.igw-lb.is-open .igw-lb__box {
  transform: scale(1);
}

.igw-lb__media {
  flex: 1 1 60%;
  background: #10221b;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  max-height: 88vh;
  overflow: hidden;
}

.igw-lb__media img,
.igw-lb__media video {
  width: 100%;
  height: 100%;
  max-height: 88vh;
  object-fit: contain;
  display: block;
}

.igw-lb__info {
  flex: 0 0 340px;
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: #fff;
}

.igw-lb__user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: #10221b;
  text-decoration: none;
  margin-bottom: 16px;
}

.igw-lb__user img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
}

.igw-lb__text {
  font-size: 14px;
  line-height: 1.65;
  color: #37453f;
  white-space: pre-line;
  flex: 1 1 auto;
  margin-bottom: 18px;
  word-wrap: break-word;
}

.igw-lb__date {
  font-size: 12px;
  color: #8b8b8b;
  margin-bottom: 16px;
}

.igw-lb__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 999px;
  background: linear-gradient(45deg, #f09433, #dc2743, #bc1888);
  color: #fff !important;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: filter 0.25s ease;
}

.igw-lb__link:hover {
  filter: brightness(1.1);
  color: #fff !important;
  text-decoration: none;
}

.igw-lb__link svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.igw-lb__close,
.igw-lb__arrow {
  position: absolute;
  border: none;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
  transition: background 0.2s ease;
  padding: 0;
}

.igw-lb__close svg,
.igw-lb__arrow svg {
  width: 16px;
  height: 16px;
  fill: #10221b;
}

.igw-lb__close:hover,
.igw-lb__arrow:hover {
  background: #fff;
}

.igw-lb__close {
  top: 12px;
  right: 12px;
}

.igw-lb__arrow--prev {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.igw-lb__arrow--next {
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

body.igw-lb-open {
  overflow: hidden;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1199px) {
  .igw {
    --igw-per-view: var(--igw-pv-lg, 3);
  }
  .igw--embed .igw__card {
    height: 500px;
  }
}

@media (max-width: 991px) {
  .igw {
    --igw-per-view: var(--igw-pv-md, 2);
    --igw-gap: 14px;
  }
}

@media (max-width: 767px) {
  .igw {
    --igw-per-view: var(--igw-pv-sm, 1.35);
    --igw-gap: 12px;
    --igw-radio: 12px;
  }

  .igw__header {
    justify-content: center;
    text-align: center;
    gap: 12px;
  }

  .igw__follow {
    margin-left: 0;
    width: 100%;
    justify-content: center;
  }

  .igw__nav {
    width: 38px;
    height: 38px;
  }

  .igw__nav--prev {
    left: 6px;
  }

  .igw__nav--next {
    right: 6px;
  }

  .igw__overlay {
    opacity: 1;
    background: linear-gradient(
      to top,
      rgba(16, 34, 27, 0.85) 0%,
      rgba(16, 34, 27, 0) 55%
    );
  }

  .igw__caption {
    -webkit-line-clamp: 2;
    font-size: 12px;
  }

  .igw-lb {
    padding: 0;
  }

  .igw-lb__box {
    flex-direction: column;
    max-height: 100vh;
    height: 100%;
    border-radius: 0;
  }

  .igw-lb__media {
    flex: 0 0 auto;
    max-height: 52vh;
  }

  .igw-lb__info {
    flex: 1 1 auto;
    padding: 18px;
  }

  .igw--embed .igw__card {
    height: 460px;
  }
}

/* Respeta usuarios con animaciones reducidas */
@media (prefers-reduced-motion: reduce) {
  .igw__track {
    scroll-behavior: auto;
  }
  .igw__img,
  .igw__card,
  .igw__overlay,
  .igw-lb,
  .igw-lb__box {
    transition: none !important;
  }
  .igw__skeleton {
    animation: none;
  }
}
