/**
 * Carrusel de Cards Responsive - Centro de Noticias DGES
 * Versión Vanilla - Sin librerías externas
 * Nomenclatura BEM - Block Element Modifier
 * Cards con imagen de fondo, título sobre la imagen
 * Responsive con configuración dinámica de columnas por resolución
 */

/* ========================================
   CONTENEDOR PRINCIPAL DEL CARRUSEL
   ======================================== */

.ndc-carousel-wrapper {
  padding: 1rem 0;
  width: 100%;
  background: transparent;
  position: relative;
  overflow: hidden;
  min-height: 220px; /* Altura mínima para el loader en mobile */
  contain: layout style paint;
}

/* Loader mientras inicializa el carrusel */
.ndc-carousel-wrapper::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 4px solid rgba(0, 124, 186, 0.2);
  border-top: 4px solid #007cba;
  border-radius: 50%;
  animation: carousel-spin 0.8s linear infinite;
  z-index: 999;
  transition: opacity 0.3s ease;
}

@keyframes carousel-spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Ocultar carrusel hasta que la versión vanilla inicialice */
.ndc-carousel-wrapper:not(.ndc-vanilla-initialized) .ndc-carousel__track {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ndc-carousel-wrapper.ndc-vanilla-initialized .ndc-carousel__track {
  opacity: 1;
}

/* Ocultar loader cuando está inicializado */
.ndc-carousel-wrapper.ndc-vanilla-initialized::before {
  opacity: 0;
  pointer-events: none;
}

.ndc-carousel-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 2rem;
  position: relative;
  overflow: visible;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.ndc-carousel__viewport {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  padding: 1.5rem 0;
  background: transparent;
  margin: 0 auto;
  contain: layout style paint;
}

.ndc-carousel__track {
  display: flex;
  align-items: stretch;
  gap: 12px; /* valor base mobile, JS compensa */
  will-change: transform;
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.320, 1);
  contain: layout style;
}

.ndc-carousel__slide {
  flex: 0 0 auto;
  background: transparent;
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}


/* ========================================
   CARDS INDIVIDUALES
   ======================================== */

.ndc-card {
  width: 100%;
  height: auto;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 16px;
  overflow: visible;
  background: transparent;
  border: none;
  padding: 0.5rem 0;
  margin: 0 auto;
  display: flex;
  justify-content: center;
}

.ndc-card__link {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: all 0.4s cubic-bezier(0.23, 1, 0.320, 1);
  display: block;
  text-decoration: none;
}

.ndc-card__link:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  transform: translateY(-4px);
}

.ndc-card__link:hover .ndc-card__image {
  transform: scale(1.05);
}

/* Mantener bordes redondeados en hover */
.ndc-card:hover .ndc-card__link,
.ndc-card__link {
  border-radius: 16px !important;
}

/* Imagen de borde en la parte inferior de cada card */
.ndc-card__link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 11px;
  background-image: url('../images/defaults/default-border-card.png');
  background-size: 100% 100%;
  background-position: bottom center;
  background-repeat: no-repeat;
  z-index: 4;
  border-radius: 0 0 16px 16px;
}

/* ========================================
   IMAGEN DE FONDO DEL CARD
   ======================================== */

.ndc-card__image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: bottom;
  z-index: 1;
  transition: transform 0.4s cubic-bezier(0.23, 1, 0.320, 1);
  background: transparent;
  display: block;
}

/* Overlay oscuro para mejor legibilidad - solo cuando existe */
.ndc-card__overlay {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  background: rgba(0, 0, 0, 0.65) !important;
  z-index: 2 !important;
  transition: opacity 0.3s ease !important;
  opacity: 1 !important;
  display: block !important;
  pointer-events: none !important;
}

.ndc-card__link:hover .ndc-card__overlay {
  opacity: 0.55 !important;
}

/* Badge SIEMPRE por encima del overlay */
.ndc-badge--recent {
  position: relative;
  z-index: 999 !important;
}

/* ========================================
   CONTENIDO DEL CARD (TÍTULO Y TEXTO)
   ======================================== */

.ndc-card__content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  padding: 1.5rem 1rem;
  background: transparent;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: center;
  align-items: center;
  justify-content: center;
}

.ndc-card__title {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.4;
  margin: 0;
  color: #ffffff;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-wrap: break-word;
  font-family: 'Poppins', sans-serif;
  letter-spacing: -0.3px;
  text-align: center;
  text-decoration: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.ndc-card__summary {
  font-size: 0.75rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.95);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  font-family: 'Roboto', sans-serif;
  display: none;
}

.ndc-card__meta {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.9);
  margin-top: 0.5rem;
  font-family: 'Roboto', sans-serif;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* Desktop - 4 cards */
@media (min-width: 1400px) {
  .ndc-card__title {
    font-size: 0.92rem;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }
  
  .ndc-carousel__slide {
    width: calc(25% - 12px);
  }
  
  .ndc-carousel__track {
    gap: 24px;
  }
}

/* Desktop Medio - 4 cards (reducido a 3 en pantalla estrecha) */
@media (max-width: 1399px) and (min-width: 1024px) {
  .ndc-card__title {
    font-size: 0.8rem;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }
  
  .ndc-carousel__track {
    gap: 20px;
  }
  
  .ndc-carousel__slide {
    width: calc(33.333% - 8px);
  }
}

/* Tablet - 2 cards */
@media (max-width: 1023px) and (min-width: 768px) {
  .ndc-card__title {
    font-size: 0.96rem;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }
  
  .ndc-card-meta {
    font-size: 0.65rem;
  }
  
  .ndc-carousel__track {
    gap: 16px;
  }
  
  .ndc-carousel__slide {
    width: calc(50% - 6px);
  }
}

/* Mobile - 1 card */
@media (max-width: 767px) {
  .ndc-carousel-wrapper {
    padding: 0.5rem 0;
  }
  
  .ndc-carousel-container {
    padding: 0 0.5rem;
  }
  
  .ndc-card__title {
    font-size: 1.04rem;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }
  
  .ndc-card-meta {
    font-size: 0.65rem;
  }
  
  .ndc-card-content {
    padding: 1.2rem 1rem;
  }
  
  .ndc-carousel__track {
    gap: 12px;
  }
  
  .ndc-carousel__slide {
    width: 100%;
  }
  
  .ndc-carousel__button {
    width: 44px !important;
    height: 44px !important;
  }
}

/* Mobile pequeño - 1 card */
@media (max-width: 480px) {
  .ndc-carousel-wrapper {
    padding: 0.5rem 0;
  }
  
  .ndc-carousel-container {
    padding: 0 0.25rem;
  }
  
  .ndc-card__title {
    font-size: 0.92rem;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }
  
  .ndc-card-meta {
    font-size: 0.6rem;
  }
  
  .ndc-card-content {
    padding: 1rem 0.85rem;
  }
  
  .ndc-carousel__button {
    width: 38px;
    height: 38px;
  }
}

/* ========================================
   ACCESIBILIDAD
   ======================================== */

.ndc-card__link:focus {
  outline: 3px solid #007cba;
  outline-offset: 2px;
}

/* Respeta preferencias de usuario */
@media (prefers-reduced-motion: reduce) {
  .ndc-card__link,
  .ndc-card__image,
  .ndc-carousel__button,
  .ndc-carousel__track {
    transition: none;
  }
}

/* Botones (flechas) */
.ndc-carousel__button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
  padding: 0 !important;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background-color: #004582;
  color: #fff; /* para el ícono con mask */
  opacity: 0.9;
  border: none;
  z-index: 10;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
  box-sizing: border-box;
}

.ndc-carousel__button:hover { opacity: 1; background-color: #0066B2; }
.ndc-carousel__button:focus { outline: 3px solid #007cba; outline-offset: 2px; }

.ndc-carousel__button--prev { left: 10px; }
.ndc-carousel__button--next { right: 10px; }

/* Íconos mediante máscara para compatibilidad */
.ndc-carousel__button::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  background-color: currentColor;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  -webkit-mask-position: center;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: contain;
}

.ndc-carousel__button--prev::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M10.5 1.5 3.5 8l7 6.5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M10.5 1.5 3.5 8l7 6.5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.ndc-carousel__button--next::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M5.5 1.5 12.5 8l-7 6.5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M5.5 1.5 12.5 8l-7 6.5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Paginación (bullets) */
.ndc-carousel__pagination {
  position: relative;
  margin-top: 10px;
  display: flex;
  gap: 0px !important;
  justify-content: center;
  align-items: center;
}

.ndc-carousel__pagination__bullet {
  width: 4px !important;
  height: 4px !important;
  border-radius: 50%;
  background: #007cba;
  border: 2px solid #007cba;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  /* WCAG AA: Área clickeable mínimo 44×44px */
  padding: 20px !important;
  margin: 2px !important;
  box-sizing: border-box;
}

.ndc-carousel__pagination__bullet:hover { transform: scale(1.25); }
.ndc-carousel__pagination__bullet--active { box-shadow: 0 0 0 4px rgba(0, 124, 186, 0.3); }
