/**
 * [motai_services_gallery]
 * Desktop / tablet (≥768px): altura 560px, dos columnas.
 * Mobile (<768px): altura 528px, un slide visible + flechas; panel ancho útil con márgenes L/R = inferior.
 * Tablet (768–1023px) con carrusel de escritorio (3+ slides): un slide visible; mismo criterio de panel.
 */

.motai-services-gallery {
  --motai-sg-bg: #1e3a8a;
  --motai-sg-radius: 14px;
  --motai-sg-gap: 14px;
  --motai-sg-count: 2;
  --motai-sg-slide: 0;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  /* Evita barra horizontal al expandir / hover (contenido que sobresale del carrusel) */
  overflow-x: hidden;
}

.motai-services-gallery__viewport {
  width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  /* Permite var(--motai-sg-viewport-px, 100cqw) en tarjetas y desplazamiento coherente con gap */
  container-type: inline-size;
  container-name: motai-sg;
}

.motai-services-gallery__track {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  box-sizing: border-box;
}

.motai-services-gallery__card {
  position: relative;
  border-radius: var(--motai-sg-radius);
  overflow: hidden;
  cursor: pointer;
  outline: none;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.18);
  box-sizing: border-box;
}

.motai-services-gallery__card:focus-visible {
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--motai-sg-bg);
}

.motai-services-gallery__bg {
  position: absolute;
  inset: 0;
  background-color: var(--motai-sg-bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.motai-services-gallery__shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.15) 45%, transparent 70%);
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.motai-services-gallery__footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 60px 60px;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.motai-services-gallery__label {
  margin: 0;
  font-family: "Montserrat", "Poppins", system-ui, -apple-system, sans-serif;
  font-weight: 400;
  color: #fff;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.motai-services-gallery__arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  line-height: 0;
}

/* Lucide en pie de tarjeta (junto al título) */
.motai-services-gallery__arrow svg,
.motai-services-gallery__arrow .motai-services-gallery__card-arrow-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.motai-services-gallery__arrow svg {
  stroke: currentColor;
}

/* Caja interna: vidrio (blanco 6%) + desenfoque, anclada abajo-izquierda */
.motai-services-gallery__panel {
  position: absolute;
  z-index: 3;
  left: 22px;
  right: auto;
  bottom: 24px;
  top: auto;
  width: 65%;
  max-width: calc(100% - 44px);
  padding: 22px 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 14px;
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px) saturate(180%);
  -webkit-backdrop-filter: blur(10px) saturate(180%);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease, visibility 0.35s ease;
}

.motai-services-gallery__panel h4 {
  margin: 0;
  font-weight: 400;
}

.motai-services-gallery__panel h4,
.motai-services-gallery__panel > p {
  color: #fff;
}

.motai-services-gallery__panel [data-motai-sg-cta] {
  border: 1px solid rgba(255, 255, 255, 0.45);
}

/* Navegación móvil (oculta en escritorio / tablet) */
.motai-services-gallery__nav {
  display: none;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.motai-services-gallery__nav-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #e2e8f0;
  color: #334155;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.motai-services-gallery__nav-btn:hover,
.motai-services-gallery__nav-btn:focus-visible {
  background: #cbd5e1;
  color: #0f172a;
  outline: none;
}

.motai-services-gallery__nav-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Lucide (arrow-left / arrow-right en navegación del carrusel) */
.motai-services-gallery__nav-btn .motai-services-gallery__nav-icon,
.motai-services-gallery__nav-btn svg.motai-lucide-svg {
  width: 22px;
  height: 22px;
  display: block;
}

.motai-services-gallery__nav-btn svg {
  stroke: currentColor;
}

/* ——— Desktop y tablet: 560px, dos columnas ——— */
@media (min-width: 768px) {
  .motai-services-gallery__viewport {
    overflow-x: hidden;
    overflow-y: visible;
  }

  .motai-services-gallery__track {
    gap: var(--motai-sg-gap);
    height: 560px;
    min-height: 560px;
    max-height: 560px;
    transition: none;
    transform: none;
    width: 100%;
  }

  .motai-services-gallery__card {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    max-height: 100%;
    height: 100%;
    align-self: stretch;
    /* Sin scale: evita que la tarjeta “crezca” visualmente y coma el hueco del gap */
    transition: flex 0.4s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.35s ease;
  }

  /* Clic: .is-expanded (solo una; el JS cierra el resto) */
  .motai-services-gallery__card.is-expanded {
    flex: 1.5 1 0;
    z-index: 2;
  }

  .motai-services-gallery__card.is-expanded .motai-services-gallery__shade {
    opacity: 0.85;
  }

  .motai-services-gallery__card.is-expanded .motai-services-gallery__footer {
    opacity: 0;
    transform: translateY(8px);
  }

  .motai-services-gallery__card.is-expanded .motai-services-gallery__panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
  }

  .motai-services-gallery__track:has(.motai-services-gallery__card.is-expanded) .motai-services-gallery__card:not(.is-expanded) {
    flex: 1 1 0;
  }

  /* Hover solo si ninguna tarjeta está abierta por clic (evita dos paneles) */
  @media (hover: hover) and (pointer: fine) {
    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)) .motai-services-gallery__card:hover {
      flex: 1.5 1 0;
      z-index: 2;
    }

    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)) .motai-services-gallery__card:hover .motai-services-gallery__shade {
      opacity: 0.85;
    }

    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)) .motai-services-gallery__card:hover .motai-services-gallery__footer {
      opacity: 0;
      transform: translateY(8px);
    }

    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)) .motai-services-gallery__card:hover .motai-services-gallery__panel {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
      pointer-events: auto;
    }

    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)):has(.motai-services-gallery__card:hover) .motai-services-gallery__card:not(:hover) {
      flex: 1 1 0;
    }
  }

  /* Más de 2 slides en escritorio: ver 2 a la vez + desplazamiento (misma lógica que móvil) */
  .motai-services-gallery--carousel-desktop .motai-services-gallery__viewport {
    overflow: hidden;
  }

  .motai-services-gallery--carousel-desktop .motai-services-gallery__track {
    gap: var(--motai-sg-gap);
    width: max-content;
    max-width: none;
    /* --motai-sg-expand-nudge (px): JS desplaza el track cuando la tarjeta expandida es la de la derecha (evita clip). */
    transform: translateX(
      calc(
        var(--motai-sg-slide) * -1 * (var(--motai-sg-viewport-px, 100cqw) + var(--motai-sg-gap)) / var(--motai-sg-per-view-desktop, 2) + var(--motai-sg-expand-nudge, 0px)
      )
    );
    transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }

  /* Carrusel +2 slides: ancho fijo solo en tarjetas no expandidas (antes .is-expanded quedaba igual y no se veía el panel). */
  .motai-services-gallery--carousel-desktop
    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded))
    .motai-services-gallery__card,
  .motai-services-gallery--carousel-desktop
    .motai-services-gallery__track:has(.motai-services-gallery__card.is-expanded)
    .motai-services-gallery__card:not(.is-expanded) {
    flex: 0 0 calc((var(--motai-sg-viewport-px, 100cqw) - var(--motai-sg-gap)) / var(--motai-sg-per-view-desktop, 2));
    width: calc((var(--motai-sg-viewport-px, 100cqw) - var(--motai-sg-gap)) / var(--motai-sg-per-view-desktop, 2));
    min-width: 0;
  }

  /*
   * Expandida: NO usar flex-basis 0 aquí — con track width:max-content el ítem puede colapsar a 0px.
   * Tamaño explícito en cqw + sin encoger.
   */
  .motai-services-gallery--carousel-desktop .motai-services-gallery__card.is-expanded {
    --motai-sg-cell: calc((var(--motai-sg-viewport-px, 100cqw) - var(--motai-sg-gap)) / var(--motai-sg-per-view-desktop, 2));
    flex: 0 0 calc(var(--motai-sg-cell) * 1.38);
    width: calc(var(--motai-sg-cell) * 1.38);
    min-width: var(--motai-sg-cell);
    max-width: none;
    z-index: 4;
  }

  @media (hover: hover) and (pointer: fine) {
    /* Hover en carrusel: mismo criterio que .is-expanded (evita ancho 0). */
    .motai-services-gallery--carousel-desktop
      .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded))
      .motai-services-gallery__card:hover {
      --motai-sg-cell: calc((var(--motai-sg-viewport-px, 100cqw) - var(--motai-sg-gap)) / var(--motai-sg-per-view-desktop, 2));
      flex: 0 0 calc(var(--motai-sg-cell) * 1.38);
      width: calc(var(--motai-sg-cell) * 1.38);
      min-width: var(--motai-sg-cell);
      max-width: none;
      z-index: 3;
    }

    .motai-services-gallery--carousel-desktop
      .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)):has(.motai-services-gallery__card:hover)
      .motai-services-gallery__card:not(:hover) {
      flex: 0 0 calc((var(--motai-sg-viewport-px, 100cqw) - var(--motai-sg-gap)) / var(--motai-sg-per-view-desktop, 2));
      width: calc((var(--motai-sg-viewport-px, 100cqw) - var(--motai-sg-gap)) / var(--motai-sg-per-view-desktop, 2));
    }

    .motai-services-gallery--carousel-desktop
      .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded))
      .motai-services-gallery__card:hover
      .motai-services-gallery__shade {
      opacity: 0.85;
    }

    .motai-services-gallery--carousel-desktop
      .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded))
      .motai-services-gallery__card:hover
      .motai-services-gallery__footer {
      opacity: 0;
      transform: translateY(8px);
    }

    .motai-services-gallery--carousel-desktop
      .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded))
      .motai-services-gallery__card:hover
      .motai-services-gallery__panel {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
      pointer-events: auto;
    }
  }

  .motai-services-gallery--carousel-desktop .motai-services-gallery__nav {
    display: flex;
  }
}

/* ——— Mobile: 528px, carrusel un slide ——— */
@media (max-width: 767px) {
  .motai-services-gallery__viewport {
    overflow: hidden;
    height: 528px;
    min-height: 528px;
    max-height: 528px;
    border-radius: var(--motai-sg-radius);
  }

  .motai-services-gallery__track {
    height: 100%;
    gap: var(--motai-sg-gap);
    width: max-content;
    max-width: none;
    transform: translateX(calc(var(--motai-sg-slide) * -1 * (var(--motai-sg-viewport-px, 100cqw) + var(--motai-sg-gap))));
    transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }

  .motai-services-gallery__card {
    flex: 0 0 var(--motai-sg-viewport-px, 100cqw);
    width: var(--motai-sg-viewport-px, 100cqw);
    min-width: 0;
    height: 100%;
    min-height: 528px;
    transform: none !important;
    transition: box-shadow 0.25s ease;
  }

  .motai-services-gallery__nav {
    display: flex;
  }

  .motai-services-gallery__card.is-expanded .motai-services-gallery__shade {
    opacity: 0.85;
  }

  .motai-services-gallery__card.is-expanded .motai-services-gallery__footer {
    opacity: 0;
    transform: translateY(8px);
  }

  .motai-services-gallery__card.is-expanded .motai-services-gallery__panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
  }

  @media (hover: hover) and (pointer: fine) {
    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)) .motai-services-gallery__card:hover .motai-services-gallery__shade {
      opacity: 0.85;
    }

    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)) .motai-services-gallery__card:hover .motai-services-gallery__footer {
      opacity: 0;
      transform: translateY(8px);
    }

    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)) .motai-services-gallery__card:hover .motai-services-gallery__panel {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
      pointer-events: auto;
    }
  }

  /* Márgenes laterales = inferior (18px) respecto a la tarjeta */
  .motai-services-gallery__panel {
    left: 18px;
    right: 18px;
    bottom: 18px;
    width: auto;
    max-width: none;
    max-height: min(68%, 320px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
  }
}

/**
 * Tablet: carrusel con 3+ slides — una tarjeta por vista (alineado con motai-service-gallery.js getPerView).
 * Panel con márgenes L/R = inferior; sin ensanchar tarjetas al hover/expandido (misma lógica que móvil).
 */
@media (min-width: 768px) and (max-width: 1023px) {
  .motai-services-gallery--carousel-desktop .motai-services-gallery__viewport {
    overflow: hidden;
    height: 560px;
    min-height: 560px;
    max-height: 560px;
    border-radius: var(--motai-sg-radius);
  }

  .motai-services-gallery--carousel-desktop .motai-services-gallery__track {
    gap: var(--motai-sg-gap);
    width: max-content;
    max-width: none;
    height: 100%;
    transform: translateX(calc(var(--motai-sg-slide) * -1 * (var(--motai-sg-viewport-px, 100cqw) + var(--motai-sg-gap))));
    transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }

  .motai-services-gallery--carousel-desktop
    .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded))
    .motai-services-gallery__card,
  .motai-services-gallery--carousel-desktop
    .motai-services-gallery__track:has(.motai-services-gallery__card.is-expanded)
    .motai-services-gallery__card:not(.is-expanded),
  .motai-services-gallery--carousel-desktop .motai-services-gallery__card.is-expanded {
    flex: 0 0 var(--motai-sg-viewport-px, 100cqw);
    width: var(--motai-sg-viewport-px, 100cqw);
    min-width: 0;
    height: 100%;
    max-width: none;
    z-index: 2;
  }

  .motai-services-gallery--carousel-desktop .motai-services-gallery__card.is-expanded {
    z-index: 4;
  }

  @media (hover: hover) and (pointer: fine) {
    .motai-services-gallery--carousel-desktop
      .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded))
      .motai-services-gallery__card:hover {
      flex: 0 0 var(--motai-sg-viewport-px, 100cqw);
      width: var(--motai-sg-viewport-px, 100cqw);
      min-width: 0;
      max-width: none;
      z-index: 3;
    }

    .motai-services-gallery--carousel-desktop
      .motai-services-gallery__track:not(:has(.motai-services-gallery__card.is-expanded)):has(.motai-services-gallery__card:hover)
      .motai-services-gallery__card:not(:hover) {
      flex: 0 0 var(--motai-sg-viewport-px, 100cqw);
      width: var(--motai-sg-viewport-px, 100cqw);
    }
  }

  /* Márgenes laterales = inferior (22px) respecto a la tarjeta */
  .motai-services-gallery--carousel-desktop .motai-services-gallery__panel {
    left: 22px;
    right: 22px;
    bottom: 22px;
    width: auto;
    max-width: none;
    max-height: min(68%, 320px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
  }
}
