/**
 * YouTube Gallery Manager - CSS
 * Versión 1.4
 * Estilos para la galería de videos con modal integrado
 */

/* ===========================
   CONTENEDOR PRINCIPAL
   =========================== */
.youtube-gallery-container {
    width: 100%;
    margin: 20px auto;
    padding: 0;
}

/* ===========================
   SPINNER DE CARGA
   =========================== */
.youtube-gallery-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 40px 20px;
}

.youtube-gallery-loading .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0, 85, 184, 0.2);
    border-top-color: #0055B8;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

.youtube-gallery-loading p {
    color: #666;
    font-size: 16px;
    margin: 0;
}

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

/* ===========================
   MENSAJES DE ERROR
   =========================== */
.youtube-gallery-error {
    padding: 30px 20px;
    text-align: center;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    margin: 20px 0;
}

.youtube-gallery-error p {
    margin: 10px 0;
    color: #856404;
    font-size: 16px;
}

.youtube-gallery-error .error-detail {
    font-size: 14px;
    color: #666;
    margin-top: 5px;
}

.youtube-gallery-error .retry-button {
    margin-top: 15px;
    padding: 10px 20px;
    background: #0055B8;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.youtube-gallery-error .retry-button:hover {
    background: #003d82;
}

/* ===========================
   ITEMS DE LA GALERÍA
   =========================== */
.youtube-gallery-item {
    position: relative;
    transition: transform 0.3s ease;
}

.youtube-gallery-item:hover {
    transform: translateY(-5px);
}

.youtube-thumbnail-wrapper {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.3s ease;
}

.youtube-gallery-item:hover .youtube-thumbnail-wrapper {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.youtube-gallery-item a {
    text-decoration: none;
    display: block;
}

.youtube-gallery-item img {
    display: block;
    opacity: 1;
}

/* ===========================
   TÍTULOS
   =========================== */
.youtube-gallery-title {
    display: block;
    margin: 10px 0 0 0;
    padding: 0;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    transition: color 0.3s ease;
}

.youtube-gallery-item:hover .youtube-gallery-title {
    opacity: 0.8;
}

/* ===========================
   DURACIÓN DEL VIDEO
   =========================== */
.video-duration {
    font-feature-settings: "tnum";
    letter-spacing: 0.5px;
}

/* ===========================
   OVERLAY DEL MODAL
   =========================== */
.youtube-modal-overlay {
    backdrop-filter: blur(5px);
}

/* ===========================
   BOTÓN CERRAR MODAL
   =========================== */
.youtube-modal-close {
    font-family: Arial, sans-serif;
    line-height: 1;
}

.youtube-modal-close:hover {
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}

.youtube-modal-close:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* ===========================
   RESPONSIVE - TABLETS
   =========================== */
@media only screen and (max-width: 1024px) and (min-width: 769px) {
    .youtube-gallery-grid.grid .youtube-gallery-item {
        flex: 1 1 calc(50% - 20px) !important;
        max-width: calc(50% - 20px) !important;
    }
}

/* ===========================
   RESPONSIVE - MÓVILES
   =========================== */
@media only screen and (max-width: 768px) {
    .youtube-gallery-container {
        margin: 10px auto;
    }
    
    .youtube-gallery-grid.grid {
        flex-direction: column !important;
        gap: 15px !important;
    }
    
    .youtube-gallery-grid.grid .youtube-gallery-item {
        flex: 1 1 100% !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
    }
    
    .youtube-gallery-grid.carousel {
        gap: 15px !important;
    }
    
    .youtube-gallery-grid.carousel .youtube-gallery-item {
        width: 280px !important;
        flex: 0 0 280px !important;
    }
    
    .youtube-gallery-title {
        font-size: 16px !important;
        padding: 8px 0 !important;
    }
    
    .youtube-thumbnail-wrapper {
        border-radius: 6px !important;
    }
    
    /* Modal en móviles */
    .youtube-modal-wrapper {
        width: 95% !important;
        padding-top: 60px !important;
    }
    
    .youtube-modal-close {
        width: 44px !important;
        height: 44px !important;
        font-size: 28px !important;
        top: -25px !important;
    }
}

/* ===========================
   RESPONSIVE - MÓVILES PEQUEÑOS
   =========================== */
@media only screen and (max-width: 480px) {
    .youtube-gallery-loading {
        min-height: 150px;
        padding: 30px 15px;
    }
    
    .youtube-gallery-loading .spinner {
        width: 40px;
        height: 40px;
        border-width: 3px;
    }
    
    .youtube-gallery-loading p {
        font-size: 14px;
    }
    
    .youtube-gallery-grid.carousel .youtube-gallery-item {
        width: 250px !important;
        flex: 0 0 250px !important;
    }
    
    .youtube-gallery-title {
        font-size: 14px !important;
    }
    
    .video-duration {
        font-size: 11px !important;
        padding: 2px 5px !important;
    }
    
    /* Modal responsive extremo */
    .youtube-modal-wrapper {
        width: 98% !important;
    }
}

/* ===========================
   ACCESIBILIDAD
   =========================== */
.youtube-video-link:focus {
    outline: 3px solid #0055B8;
    outline-offset: 2px;
}

.youtube-gallery-item a:focus .youtube-thumbnail-wrapper {
    box-shadow: 0 0 0 3px rgba(0, 85, 184, 0.5);
}

/* Reducir movimiento para usuarios con preferencias de accesibilidad */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===========================
   MODO OSCURO (Opcional)
   =========================== */
@media (prefers-color-scheme: dark) {
    .youtube-gallery-loading p {
        color: #ccc;
    }
    
    .youtube-gallery-error {
        background: #3a3a1f;
        border-color: #8a7c00;
    }
    
    .youtube-gallery-error p {
        color: #ffd966;
    }
    
    .youtube-gallery-error .error-detail {
        color: #aaa;
    }
}

/* ===========================
   MEJORAS VISUALES
   =========================== */
/* Suavizar la aparición de imágenes */
.youtube-gallery-item img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Prevenir selección de texto en la galería */
.youtube-gallery-item {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Permitir selección de títulos */
.youtube-gallery-title {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Scrollbar personalizada para carousel */
.youtube-gallery-grid.carousel::-webkit-scrollbar {
    height: 8px;
}

.youtube-gallery-grid.carousel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.youtube-gallery-grid.carousel::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.youtube-gallery-grid.carousel::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ===========================
   COMPATIBILIDAD CON TEMAS
   =========================== */
.youtube-gallery-container * {
    box-sizing: border-box;
}

/* Resetear estilos que puedan venir del tema */
.youtube-gallery-item h3.youtube-gallery-title {
    background: none;
    border: none;
    padding-left: 0;
    padding-right: 0;
    margin-left: 0;
    margin-right: 0;
}