/* =============================================================================
   ESTILOS COMPARTIDOS PARA category.php Y search.php
   =============================================================================
   category.css y search.css compartian el 100% de su grid/tarjetas/thumbnails
   (solo cambiaba el prefijo sp-category-/sp-search-, el ID del contenedor, y
   el nombre de 3 animaciones que ahora son genericas: sp-shared-fade-in,
   sp-shared-shimmer, sp-shared-spin). Verificado regla por regla con un
   parser CSS. La seccion de "sin resultados" con sugerencias, que solo
   existe en la busqueda, se quedo en search.css (category.php no la usa).
   ============================================================================= */

/* ============================================================
   CATEGORY.PHP - ESTILOS PROPIOS (sp-category-*)
   Replica la LÓGICA de diseño de archive-peliculas.css:
   thumbnail 16:9 con shimmer, badge de duración, preview de
   trailer en hover, y bloque de info con título, título
   original, vistas, rating y año. Todo con clases únicas para
   no depender de ningún otro stylesheet del tema.
============================================================ */

/* ============================================================
   GRID - 3 columnas en escritorio / 2 tablet / 1 móvil
============================================================ */
#taxonomy-posts-container.sp-posts-grid,
#search-posts-container.sp-posts-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 20px !important;
}

@media screen and (min-width: 769px) and (max-width: 1024px) {
    #taxonomy-posts-container.sp-posts-grid,
    #search-posts-container.sp-posts-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px !important;
    }
}

@media screen and (max-width: 768px) {
    #taxonomy-posts-container.sp-posts-grid,
    #search-posts-container.sp-posts-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }
}

/* ============================================================
   TARJETA
============================================================ */
.sp-category-item,
.sp-search-item {
    background-color: transparent;
    border: none;
    border-radius: 0;
    overflow: visible;
    cursor: pointer;
    min-width: 0;
    position: relative;
    animation: sp-shared-fade-in 0.5s ease forwards;
    opacity: 0;
}

.sp-category-item a,
.sp-search-item a {
    text-decoration: none;
    color: inherit;
    display: block;
}

.sp-category-item:nth-child(1),
.sp-search-item:nth-child(1) { animation-delay: 0.02s; }
.sp-category-item:nth-child(2),
.sp-search-item:nth-child(2) { animation-delay: 0.04s; }
.sp-category-item:nth-child(3),
.sp-search-item:nth-child(3) { animation-delay: 0.06s; }
.sp-category-item:nth-child(4),
.sp-search-item:nth-child(4) { animation-delay: 0.08s; }
.sp-category-item:nth-child(5),
.sp-search-item:nth-child(5) { animation-delay: 0.10s; }
.sp-category-item:nth-child(6),
.sp-search-item:nth-child(6) { animation-delay: 0.12s; }

@keyframes sp-shared-fade-in {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   THUMBNAIL - 16:9 con shimmer mientras carga
============================================================ */
.sp-category-thumbnail-wrapper,
.sp-search-thumbnail-wrapper {
    position: relative;
    overflow: hidden;
    padding-top: 56.25%;
    border-radius: 12px;
    background: linear-gradient(100deg, var(--sp-card-bg) 30%, #262626 50%, var(--sp-card-bg) 70%);
    background-size: 200% 100%;
    animation: sp-shared-shimmer 1.6s ease-in-out infinite;
    transition: border-radius 0.3s ease, box-shadow 0.3s var(--sp-ease, ease);
}

@keyframes sp-shared-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .sp-category-thumbnail-wrapper,
    .sp-search-thumbnail-wrapper {
        animation: none;
        background: var(--sp-card-bg);
    }
}

.sp-category-item:hover .sp-category-thumbnail-wrapper,
.sp-search-item:hover .sp-search-thumbnail-wrapper {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}

.sp-category-thumbnail-image,
.sp-search-thumbnail-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    transition: opacity 0.4s ease, transform 0.4s ease;
    border-radius: 12px;
    z-index: 1;
}

/* En hover, la imagen se oscurece (comportamiento normal) */
.sp-category-item:hover .sp-category-thumbnail-image,
.sp-search-item:hover .sp-search-thumbnail-image {
    opacity: 0.4;
    transform: scale(1.05);
}

/* Si tiene trailer, la imagen se oculta del todo y aparece el video */
.sp-category-item[data-has-trailer="true"]:hover .sp-category-thumbnail-image,
.sp-search-item[data-has-trailer="true"]:hover .sp-search-thumbnail-image {
    opacity: 0;
}

/* ============================================================
   TRAILER - reproductor ligero sin controles, igual que
   archive-peliculas.css
============================================================ */
.sp-category-trailer-container,
.sp-search-trailer-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
}

.sp-category-item[data-has-trailer="true"]:hover .sp-category-trailer-container,
.sp-search-item[data-has-trailer="true"]:hover .sp-search-trailer-container {
    opacity: 1;
    visibility: visible;
}

.sp-category-trailer-iframe,
.sp-search-trailer-iframe {
    width: 100%;
    height: 100%;
    border: none;
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.sp-category-trailer-container.loading::after,
.sp-search-trailer-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #fff;
    border-radius: 50%;
    animation: sp-shared-spin 0.8s linear infinite;
    z-index: 5;
}

@keyframes sp-shared-spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ============================================================
   BADGES sobre el thumbnail
============================================================ */
.sp-category-type-badge,
.sp-search-type-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    font-weight: 500;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 4px;
    z-index: 10;
    pointer-events: none;
    letter-spacing: 0.3px;
    backdrop-filter: blur(2px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.sp-category-duration-badge,
.sp-search-duration-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.85);
    color: #ffffff;
    font-weight: 500;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 4px;
    z-index: 10;
    pointer-events: none;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    letter-spacing: 0.3px;
    backdrop-filter: blur(2px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ============================================================
   INFO DEBAJO DE LA TARJETA
============================================================ */
.sp-category-content-info,
.sp-search-content-info {
    padding: 10px 4px 0 4px;
}

.sp-category-content-title,
.sp-search-content-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--sp-text-color);
    margin: 0 0 4px 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    max-height: 40px;
}

.sp-category-content-meta,
.sp-search-content-meta {
    margin-bottom: 3px;
}

.sp-category-content-original-title,
.sp-search-content-original-title {
    font-size: 13px;
    color: var(--sp-text-dark);
    font-weight: 400;
    transition: color 0.2s;
}

.sp-category-item:hover .sp-category-content-original-title,
.sp-search-item:hover .sp-search-content-original-title {
    color: var(--sp-text-light);
}

.sp-category-content-stats,
.sp-search-content-stats {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--sp-text-dark);
    flex-wrap: wrap;
}

.sp-category-content-views,
.sp-search-content-views,
.sp-category-content-rating,
.sp-search-content-rating,
.sp-category-content-year,
.sp-search-content-year {
    font-size: 13px;
    color: var(--sp-text-dark);
}

.sp-category-content-rating,
.sp-search-content-rating {
    color: #ffd700;
    font-weight: 500;
}

/* ============================================================
   RESPONSIVE
============================================================ */
@media screen and (max-width: 768px) {
    .sp-category-thumbnail-wrapper,
    .sp-search-thumbnail-wrapper,
    .sp-category-thumbnail-image,
    .sp-search-thumbnail-image {
        border-radius: 8px;
    }

    .sp-category-content-title,
    .sp-search-content-title {
        font-size: 13px;
        max-height: 36px;
    }

    .sp-category-content-original-title,
    .sp-search-content-original-title,
    .sp-category-content-views,
    .sp-search-content-views,
    .sp-category-content-rating,
    .sp-search-content-rating,
    .sp-category-content-year,
    .sp-search-content-year {
        font-size: 12px;
    }

    .sp-category-type-badge,
    .sp-search-type-badge,
    .sp-category-duration-badge,
    .sp-search-duration-badge {
        font-size: 11px;
        padding: 1px 6px;
    }
}

/* En dispositivos táctiles, desactivar el hover del trailer */
@media (hover: none) {
    .sp-category-trailer-container,
    .sp-search-trailer-container {
        display: none !important;
    }

    .sp-category-thumbnail-image,
    .sp-search-thumbnail-image {
        opacity: 1 !important;
        transform: none !important;
    }
}

@media screen and (max-width: 480px) {
    .sp-category-content-info,
    .sp-search-content-info {
        padding: 8px 2px 0 2px;
    }

    .sp-category-content-title,
    .sp-search-content-title {
        font-size: 12px;
        max-height: 34px;
    }

    .sp-category-content-original-title,
    .sp-search-content-original-title {
        font-size: 11px;
    }

    .sp-category-content-stats,
    .sp-search-content-stats {
        font-size: 11px;
        gap: 4px;
    }

    .sp-category-content-views,
    .sp-search-content-views,
    .sp-category-content-rating,
    .sp-search-content-rating,
    .sp-category-content-year,
    .sp-search-content-year {
        font-size: 11px;
    }

    .sp-category-type-badge,
    .sp-search-type-badge,
    .sp-category-duration-badge,
    .sp-search-duration-badge {
        font-size: 10px;
        padding: 1px 5px;
        border-radius: 3px;
    }
}

@media screen and (max-width: 360px) {
    .sp-category-content-title,
    .sp-search-content-title {
        font-size: 11px;
        max-height: 30px;
    }

    .sp-category-content-original-title,
    .sp-search-content-original-title,
    .sp-category-content-views,
    .sp-search-content-views,
    .sp-category-content-rating,
    .sp-search-content-rating,
    .sp-category-content-year,
    .sp-search-content-year {
        font-size: 10px;
    }
}