/*
 * News Reels Feed — Frontend CSS
 * Versión: 1.0.0
 * Mobile-first, optimizado para CLS mínimo
 */

/* ═══════════════════════════════════════════════
   Variables CSS (sobrescritas desde PHP si el usuario las personaliza)
═══════════════════════════════════════════════ */
:root {
  --nrf-primary:      #e63946;
  --nrf-bg:           #0d0d0d;
  --nrf-surface:      #1a1a1a;
  --nrf-text:         #f0f0f0;
  --nrf-text-muted:   #999;
  --nrf-tag-bg:       rgba(230, 57, 70, 0.85);
  --nrf-overlay:      linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.3) 60%, transparent 100%);
  --nrf-radius:       12px;
  --nrf-radius-sm:    6px;
  --nrf-font:         'Georgia', 'Times New Roman', serif;
  --nrf-font-ui:      system-ui, -apple-system, sans-serif;
  --nrf-transition:   0.25s ease;
  --nrf-card-aspect:  9 / 16;
  --nrf-max-width:    480px;
  --nrf-shadow:       0 8px 32px rgba(0,0,0,0.5);
}

/* ═══════════════════════════════════════════════
   Reset parcial dentro del plugin
═══════════════════════════════════════════════ */
.nrf-feed-vertical *,
.nrf-grid-wrap *,
.nrf-slider-wrap *,
.nrf-modal * {
  box-sizing: border-box;
}

/* ═══════════════════════════════════════════════
   Mensaje vacío
═══════════════════════════════════════════════ */
.nrf-empty {
  text-align: center;
  color: var(--nrf-text-muted);
  padding: 2rem;
  font-family: var(--nrf-font-ui);
}

/* ═══════════════════════════════════════════════
   FEED VERTICAL
═══════════════════════════════════════════════ */
.nrf-feed-vertical {
  width: 100%;
  max-width: var(--nrf-max-width);
  margin: 0 auto;
  background: var(--nrf-bg);
  border-radius: var(--nrf-radius);
  overflow: hidden;
}

.nrf-feed-track {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ═══════════════════════════════════════════════
   TARJETA DEL FEED VERTICAL
═══════════════════════════════════════════════ */
.nrf-reel-card {
  position: relative;
  width: 100%;
  background: var(--nrf-surface);
  border-radius: var(--nrf-radius);
  overflow: hidden;
  margin-bottom: 12px;
  box-shadow: var(--nrf-shadow);
  transition: transform var(--nrf-transition);
}

.nrf-reel-card:hover {
  transform: translateY(-2px);
}

.nrf-reel-card.is-featured::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--nrf-primary);
  border-radius: var(--nrf-radius);
  pointer-events: none;
  z-index: 5;
}

/* Media (imagen/video) */
.nrf-card-media {
  position: relative;
  width: 100%;
  aspect-ratio: var(--nrf-card-aspect);
  background: #111;
  overflow: hidden;
}

/* Reservar espacio antes de cargar la imagen (evita CLS) */
.nrf-card-media::before {
  content: '';
  display: block;
  padding-top: 177.78%; /* fallback para aspect-ratio en navegadores viejos */
}

@supports (aspect-ratio: 9/16) {
  .nrf-card-media::before { display: none; }
}

.nrf-card-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--nrf-transition), transform 0.4s ease;
}

.nrf-card-thumb.nrf-lazy:not([src*="data-src"]) {
  opacity: 0;
}

.nrf-card-thumb.nrf-lazy-loaded {
  opacity: 1;
}

.nrf-reel-card:hover .nrf-card-thumb {
  transform: scale(1.03);
}

/* Overlay degradé */
.nrf-card-overlay {
  position: absolute;
  inset: 0;
  background: var(--nrf-overlay);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
  pointer-events: none;
}

/* Botón play */
.nrf-play-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255,255,255,0.4);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: all;
  transition: background var(--nrf-transition), transform var(--nrf-transition);
  z-index: 3;
}

.nrf-play-btn:hover {
  background: var(--nrf-primary);
  border-color: var(--nrf-primary);
  transform: translate(-50%, -50%) scale(1.1);
}

.nrf-play-btn:focus-visible {
  outline: 3px solid var(--nrf-primary);
  outline-offset: 3px;
}

/* Cuando el embed está activo, ocultar el poster y el botón play */
.nrf-reel-card.nrf-playing .nrf-card-thumb,
.nrf-reel-card.nrf-playing .nrf-card-overlay {
  opacity: 0;
  pointer-events: none;
}

/* Contenedor iframe */
.nrf-embed-container {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
}

.nrf-embed-container.nrf-embed-visible {
  display: block;
}

.nrf-embed-container iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

/* Etiqueta categoría */
.nrf-tag {
  display: inline-block;
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--nrf-tag-bg);
  color: #fff;
  font-family: var(--nrf-font-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 4;
}

/* Duración */
.nrf-duration {
  display: inline-block;
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-family: var(--nrf-font-ui);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 4;
}

/* ═══════════════════════════════════════════════
   INFORMACIÓN TEXTUAL (info)
═══════════════════════════════════════════════ */
.nrf-card-info {
  padding: 14px 16px;
  background: var(--nrf-surface);
}

.nrf-card-title {
  margin: 0 0 4px;
  font-family: var(--nrf-font);
  font-size: clamp(15px, 3.5vw, 18px);
  font-weight: 700;
  line-height: 1.3;
  color: var(--nrf-text);
}

.nrf-card-title-link {
  color: inherit;
  text-decoration: none;
}

.nrf-card-title-link:hover {
  color: var(--nrf-primary);
}

.nrf-card-subtitle {
  margin: 0 0 6px;
  font-family: var(--nrf-font-ui);
  font-size: 13px;
  color: var(--nrf-text-muted);
}

.nrf-card-desc {
  margin: 0 0 10px;
  font-family: var(--nrf-font-ui);
  font-size: 13px;
  line-height: 1.5;
  color: var(--nrf-text-muted);
}

.nrf-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-family: var(--nrf-font-ui);
  font-size: 11px;
  color: var(--nrf-text-muted);
}

.nrf-card-source {
  font-weight: 700;
  color: var(--nrf-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Botón CTA */
.nrf-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--nrf-primary);
  color: #fff;
  font-family: var(--nrf-font-ui);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: var(--nrf-radius-sm);
  transition: background var(--nrf-transition), transform var(--nrf-transition);
}

.nrf-cta-btn:hover {
  background: #c1121f;
  color: #fff;
  transform: translateX(2px);
}

.nrf-cta-btn:focus-visible {
  outline: 3px solid var(--nrf-primary);
  outline-offset: 3px;
}

.nrf-cta-btn.nrf-cta-sm {
  font-size: 11px;
  padding: 5px 10px;
}

/* ═══════════════════════════════════════════════
   BOTÓN "CARGAR MÁS" / PAGINACIÓN
═══════════════════════════════════════════════ */
.nrf-load-more-wrap {
  text-align: center;
  padding: 24px 16px;
}

.nrf-load-more-btn {
  background: transparent;
  border: 2px solid var(--nrf-primary);
  color: var(--nrf-primary);
  font-family: var(--nrf-font-ui);
  font-size: 14px;
  font-weight: 700;
  padding: 10px 28px;
  border-radius: 100px;
  cursor: pointer;
  transition: background var(--nrf-transition), color var(--nrf-transition);
}

.nrf-load-more-btn:hover {
  background: var(--nrf-primary);
  color: #fff;
}

.nrf-load-more-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.nrf-infinite-sentinel {
  height: 40px;
}

/* ═══════════════════════════════════════════════
   GRID
═══════════════════════════════════════════════ */
.nrf-grid-wrap {
  width: 100%;
  position: relative;
}

.nrf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

@media (min-width: 480px) {
  .nrf-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }
}

@media (min-width: 768px) {
  .nrf-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

.nrf-grid-item {
  position: relative;
  background: var(--nrf-surface);
  border-radius: var(--nrf-radius-sm);
  overflow: hidden;
  transition: transform var(--nrf-transition), box-shadow var(--nrf-transition);
}

.nrf-grid-item:hover {
  transform: scale(1.03);
  box-shadow: var(--nrf-shadow);
}

.nrf-grid-thumb-btn {
  position: relative;
  width: 100%;
  aspect-ratio: 9/16;
  background: #111;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: block;
  overflow: hidden;
}

.nrf-grid-thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
  display: block;
}

.nrf-grid-item:hover .nrf-grid-thumb-btn img {
  transform: scale(1.06);
}

.nrf-grid-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.85);
  background: rgba(0,0,0,0.25);
  opacity: 0;
  transition: opacity var(--nrf-transition);
}

.nrf-grid-item:hover .nrf-grid-play-icon {
  opacity: 1;
}

.nrf-featured-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 14px;
  z-index: 4;
}

.nrf-grid-meta {
  padding: 8px 10px;
}

.nrf-grid-title {
  margin: 0;
  font-family: var(--nrf-font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--nrf-text);
  line-height: 1.3;
}

/* ═══════════════════════════════════════════════
   MODAL VISOR
═══════════════════════════════════════════════ */
.nrf-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nrf-modal[hidden] {
  display: none;
}

.nrf-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  cursor: pointer;
}

.nrf-modal-inner {
  position: relative;
  z-index: 1;
  width: min(92vw, 400px);
  max-height: 90vh;
  border-radius: var(--nrf-radius);
  overflow: hidden;
  background: var(--nrf-surface);
  display: flex;
  flex-direction: column;
  animation: nrfModalIn 0.25s ease;
}

@keyframes nrfModalIn {
  from { opacity: 0; transform: scale(0.92) translateY(16px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.nrf-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  background: rgba(0,0,0,0.5);
  border: 0;
  color: #fff;
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--nrf-transition);
}

.nrf-modal-close:hover {
  background: var(--nrf-primary);
}

.nrf-modal-content {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Contenido del modal (misma estructura que feed card) */
.nrf-modal-content .nrf-reel-card {
  border-radius: 0;
  margin-bottom: 0;
  box-shadow: none;
}

/* ═══════════════════════════════════════════════
   CARRUSEL / SLIDER
═══════════════════════════════════════════════ */
.nrf-slider-wrap {
  position: relative;
  overflow: hidden;
  padding: 0 36px;
}

.nrf-slider-track {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.nrf-slider-track::-webkit-scrollbar { display: none; }

.nrf-slider-item {
  flex: 0 0 160px;
  scroll-snap-align: start;
  border-radius: var(--nrf-radius-sm);
  overflow: hidden;
  background: var(--nrf-surface);
}

.nrf-slider-thumb {
  position: relative;
  width: 160px;
  aspect-ratio: 9/16;
  overflow: hidden;
  background: #111;
}

.nrf-slider-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.nrf-slider-info {
  padding: 8px 10px;
}

.nrf-slider-title {
  margin: 0 0 6px;
  font-family: var(--nrf-font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--nrf-text);
  line-height: 1.3;
}

.nrf-slider-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: 0;
  width: 32px;
  height: 48px;
  cursor: pointer;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background var(--nrf-transition);
}

.nrf-slider-arrow:hover { background: var(--nrf-primary); }

.nrf-slider-prev { left: 0; }
.nrf-slider-next { right: 0; }

/* ═══════════════════════════════════════════════
   PÁGINA DE ARCHIVO
═══════════════════════════════════════════════ */
.nrf-archive-page {
  padding: 24px 16px;
  max-width: 560px;
  margin: 0 auto;
}

.nrf-archive-header {
  margin-bottom: 24px;
}

.nrf-archive-title {
  font-family: var(--nrf-font);
  font-size: clamp(24px, 6vw, 36px);
  font-weight: 700;
  color: var(--nrf-text);
  margin: 0 0 8px;
}

.nrf-archive-desc {
  color: var(--nrf-text-muted);
  font-size: 14px;
  margin: 0 0 16px;
}

/* Filtros por categoría */
.nrf-cat-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.nrf-cat-btn {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 100px;
  border: 1.5px solid rgba(255,255,255,0.15);
  color: var(--nrf-text-muted);
  font-family: var(--nrf-font-ui);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--nrf-transition);
  background: transparent;
}

.nrf-cat-btn:hover,
.nrf-cat-btn.active {
  background: var(--nrf-primary);
  border-color: var(--nrf-primary);
  color: #fff;
}

/* ═══════════════════════════════════════════════
   SINGLE REEL (plantilla individual)
═══════════════════════════════════════════════ */
.nrf-single-page {
  padding: 24px 16px;
  max-width: 560px;
  margin: 0 auto;
}

.nrf-single-page .nrf-reel-card {
  max-width: 100%;
}

/* ═══════════════════════════════════════════════
   RESPONSIVE (escritorio)
═══════════════════════════════════════════════ */
@media (min-width: 768px) {
  .nrf-feed-vertical {
    max-width: 420px;
  }

  .nrf-archive-page,
  .nrf-single-page {
    max-width: 520px;
  }
}

@media (min-width: 1024px) {
  .nrf-archive-page,
  .nrf-single-page {
    max-width: 600px;
  }

  .nrf-slider-item {
    flex: 0 0 180px;
  }

  .nrf-slider-thumb {
    width: 180px;
  }
}

/* ═══════════════════════════════════════════════
   ACCESIBILIDAD / REDUCIR MOVIMIENTO
═══════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .nrf-reel-card,
  .nrf-card-thumb,
  .nrf-play-btn,
  .nrf-cta-btn,
  .nrf-grid-item,
  .nrf-modal-inner {
    transition: none;
    animation: none;
  }
}

/* ═══════════════════════════════════════════════
   ESTADO DE CARGA
═══════════════════════════════════════════════ */
.nrf-loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.nrf-loading-spinner::after {
  content: '';
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--nrf-primary);
  border-radius: 50%;
  animation: nrfSpin 0.7s linear infinite;
}

@keyframes nrfSpin {
  to { transform: rotate(360deg); }
}


/* ═══════════════════════════════════════════════
   FIXES v1.1
═══════════════════════════════════════════════ */

/* Imagen: src directo, sin lazy trick */
.nrf-card-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 1;           /* visible siempre */
  transition: transform 0.4s ease;
}

/* Placeholder cuando no hay imagen */
.nrf-thumb-placeholder {
  position: absolute;
  inset: 0;
  background: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Embed: oculto por defecto, visible cuando .nrf-embed-visible */
.nrf-embed-container {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  background: #000;
}
.nrf-embed-container.nrf-embed-visible {
  display: block;
}
.nrf-embed-container iframe {
  width: 100% !important;
  height: 100% !important;
  border: 0;
  display: block;
}

/* Spinner */
.nrf-spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--nrf-primary);
  border-radius: 50%;
  animation: nrfSpin 0.7s linear infinite;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
}

/* Ocultar poster+overlay cuando está reproduciendo */
.nrf-reel-card.nrf-playing .nrf-card-thumb,
.nrf-reel-card.nrf-playing .nrf-card-overlay {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

/* ═══════════════════════════════════════════════
   VISOR TIPO REELS
═══════════════════════════════════════════════ */
#nrf-viewer {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
}
#nrf-viewer[hidden] { display: none; }

#nrf-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.95);
  cursor: pointer;
}

#nrf-viewer-inner {
  position: relative;
  z-index: 1;
  width: min(100vw, 420px);
  height: 100dvh;          /* dvh = dynamic viewport height (móvil) */
  height: 100vh;           /* fallback */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Track con scroll snapping vertical */
#nrf-viewer-track {
  flex: 1;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#nrf-viewer-track::-webkit-scrollbar { display: none; }

/* Cada slide ocupa exactamente la pantalla */
.nrf-viewer-item {
  scroll-snap-align: start;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Card dentro del visor */
#nrf-viewer .nrf-reel-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: 0;
  margin: 0;
  box-shadow: none;
  height: 100%;
}

#nrf-viewer .nrf-card-media {
  flex: 1;
  min-height: 0;
  position: relative;
  aspect-ratio: unset;    /* en el visor ocupa el espacio disponible */
}

#nrf-viewer .nrf-card-media::before { display: none; }

#nrf-viewer .nrf-card-info {
  flex-shrink: 0;
  max-height: 40%;
  overflow-y: auto;
  scrollbar-width: thin;
  background: var(--nrf-surface);
  padding: 16px;
}

/* Botón cerrar */
#nrf-viewer-close {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 10;
  background: rgba(0,0,0,0.6);
  border: 0;
  color: #fff;
  font-size: 18px;
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
  backdrop-filter: blur(4px);
}
#nrf-viewer-close:hover { background: var(--nrf-primary); }

/* Flechas de navegación */
#nrf-viewer-nav {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

#nrf-viewer-prev,
#nrf-viewer-next {
  background: rgba(0,0,0,0.5);
  border: 1.5px solid rgba(255,255,255,0.2);
  color: #fff;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
  backdrop-filter: blur(4px);
}
#nrf-viewer-prev:hover,
#nrf-viewer-next:hover { background: var(--nrf-primary); border-color: var(--nrf-primary); }
#nrf-viewer-prev:disabled,
#nrf-viewer-next:disabled { opacity: 0.3; cursor: default; }

/* En desktop, el visor aparece como panel lateral derecho */
@media (min-width: 768px) {
  #nrf-viewer-inner {
    width: 400px;
    height: 100vh;
    border-radius: 0;
    margin-left: auto;
    margin-right: auto;
  }

  #nrf-viewer-backdrop {
    background: rgba(0,0,0,0.85);
  }
}

/* Swipe hint en móvil (flecha animada) */
.nrf-viewer-item:first-child .nrf-card-media::after {
  content: '↕ Desliza para ver más';
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  pointer-events: none;
  animation: nrfFadeOut 3s forwards 1.5s;
}

@keyframes nrfFadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}
