/* =========================================
   1. ESTILOS GENERALES
   ========================================= */
body { 
    margin: 0; 
    background: #000; 
    color: white; 
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 
    
    /* Scroll permitido en toda la página */
    overflow-x: hidden; 
    overflow-y: auto; 
    min-height: 100vh;
    
    display: flex; 
    flex-direction: column; 
}

/* =========================================
   2. HEADER & NAVEGACI??N
   ========================================= */
header { 
    background: #141414; 
    padding: 15px; 
    border-bottom: 1px solid #333; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    z-index: 60;
}

.logo { color: #e50914; font-weight: bold; font-size: 1.4em; text-transform: uppercase; }

.btn-logout { 
    background: #333; color: #ddd; border: 1px solid #555; padding: 8px 15px; 
    border-radius: 4px; cursor: pointer; font-size: 0.85em; 
}
.btn-logout:hover { background: #e50914; color: white; border-color: #e50914; }

.main-area { 
    display: flex; 
    flex-direction: column; 
    flex: 1;
}

/* =========================================
   3. REPRODUCTOR DE VIDEO (PEGAJOSO / STICKY)
   ========================================= */
.video-container { 
    width: 100%; 
    background: #000; 
    
    /* Sticky: Mantiene el video visible al bajar */
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    
    z-index: 50; 
    display: flex; 
    justify-content: center; 
    border-bottom: 1px solid #222;
    outline: none; /* Quita el borde azul al enfocar en TV */
}

/* Efecto de foco sutil en el contenedor del video para saber que estás ahí */
.video-container:focus {
    border-bottom: 2px solid #e50914;
}

video { 
    width: 100%; 
    max-height: 40vh; 
    aspect-ratio: 16/9; 
    background: #000; 
    outline: none; 
    object-fit: contain; 
}

/* Ocultar controles conflictivos */
video.is-live::-webkit-media-controls-timeline,
video::-webkit-media-controls-fullscreen-button { display: none !important; }

#videoOverlay { 
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.9); z-index: 60; display: none; 
    flex-direction: column; justify-content: center; align-items: center; 
}
.btn-action { background: #e50914; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; margin-top: 10px; font-weight: bold; text-decoration: none; }

/* =========================================
   4. CATEGOR??AS
   ========================================= */
.categories { 
    display: flex; gap: 10px; padding: 15px; overflow-x: auto; 
    background: #111; border-bottom: 1px solid #222; 
    white-space: nowrap; scrollbar-width: none; 
    position: sticky;
    top: 40vh; 
    z-index: 40;
}
.cat-btn { background: transparent; border: 1px solid #444; color: #aaa; padding: 8px 16px; border-radius: 20px; cursor: pointer; font-size: 0.9rem; }
.cat-btn.active { background: #e50914; color: white; border-color: #e50914; }

/* =========================================
   5. GRID DE CANALES
   ========================================= */
.content-area { 
    padding: 0; 
    padding-bottom: 100px; 
    overflow: visible; 
}

.search-container { padding: 15px 15px 0 15px; }
#buscador { width: 100%; padding: 12px; border-radius: 8px; border: 1px solid #333; background: #1a1a1a; color: white; outline: none; box-sizing: border-box; }

#gridCanales {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    padding: 15px;
    width: 100%;
    box-sizing: border-box;
}

/* =========================================
   6. TARJETAS
   ========================================= */
.channel-card, .folder-card {
    background: #1a1a1a; border-radius: 8px; overflow: hidden; 
    transition: transform 0.1s; cursor: pointer; position: relative; 
    border: 3px solid transparent; 
}

.channel-card:focus, .folder-card:focus {
    transform: scale(1.1);
    border-color: #e50914;
    z-index: 20;
    box-shadow: 0 10px 30px rgba(0,0,0,0.9);
    outline: none; 
}

.channel-card img { width: 100%; height: 100px; object-fit: cover; background: #222; }
.channel-info { padding: 8px; display: flex; justify-content: space-between; align-items: center; background: linear-gradient(to top, rgba(0,0,0,0.9), transparent); }
.channel-name { color: #fff; font-size: 0.85rem; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 85%; }
.star-btn { font-size: 1.2rem; filter: drop-shadow(0 0 2px black); }

.folder-card { display: flex; flex-direction: column; align-items: center; justify-content: center; background: #2a2a2a; border: 1px solid #444; aspect-ratio: 16/9; }
.folder-icon { font-size: 2rem; margin-bottom: 5px; }
.folder-name { font-weight: bold; color: white; text-align: center; font-size: 0.9rem; }
.folder-count { font-size: 0.7rem; color: #aaa; margin-top: 5px; }
.lock-badge { position: absolute; top: 5px; right: 5px; background: rgba(0, 0, 0, 0.8); color: #e50914; padding: 2px 6px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; border: 1px solid #e50914; z-index: 15; }

/* BARRA DE ZAPPING */
.zap-bar {
    position: absolute; bottom: 60px; left: 0; right: 0; height: 130px;
    background: linear-gradient(to top, rgba(0,0,0,0.95) 10%, rgba(0,0,0,0.5) 50%, transparent 100%);
    display: flex; align-items: center; justify-content: flex-start; gap: 15px; padding: 0 20px; 
    overflow-x: auto; z-index: 60; opacity: 0; transition: opacity 0.3s; transform: translateY(20px); pointer-events: none;
}
.zap-bar.visible { opacity: 1; transform: translateY(0); pointer-events: none; }
.zap-card { pointer-events: auto !important; min-width: 140px; height: 80px; position: relative; border-radius: 8px; overflow: hidden; cursor: pointer; border: 2px solid rgba(255,255,255,0.2); background: #111; flex-shrink: 0; }
.zap-card:focus { border-color: #e50914; transform: scale(1.15); outline: none; z-index: 100; opacity: 1 !important; }
.zap-card.active { border-color: #e50914; opacity: 0.5; }
.zap-card img { width: 100%; height: 100%; object-fit: cover; }
.zap-title { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.8); color: white; font-size: 0.75rem; padding: 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#customFsBtn { position: absolute; bottom: 10px; right: 10px; z-index: 80; background: rgba(0, 0, 0, 0.6); border: 1px solid rgba(255,255,255,0.3); color: white; border-radius: 4px; padding: 5px 10px; cursor: pointer; font-size: 1.2rem; display: flex; align-items: center; justify-content: center; }

/* FIX PANTALLA COMPLETA */
.video-container:fullscreen, .video-container:-webkit-full-screen { background: black; display: flex; align-items: center; justify-content: center; position: fixed; top: 0; left:0; width: 100%; height: 100%; z-index: 999; }
.video-container:fullscreen video, .video-container:-webkit-full-screen video { max-height: 100vh !important; height: 100% !important; width: 100% !important; object-fit: contain; }

/* =========================================
   7. INDICADOR DE CALIDAD
   ========================================= */
.quality-badge {
    position: absolute; top: 15px; right: 60px;
    background: rgba(0, 0, 0, 0.6); color: #fff; padding: 4px 8px;
    border-radius: 4px; font-size: 0.75rem; font-weight: bold;
    border: 1px solid rgba(255, 255, 255, 0.3); z-index: 55; pointer-events: none;
    backdrop-filter: blur(2px); transition: all 0.3s ease;
    text-transform: uppercase; font-family: monospace; 
}
.quality-badge.high-def {
    border-color: #46d369; color: #46d369;
    background: rgba(0, 0, 0, 0.8); box-shadow: 0 0 10px rgba(70, 211, 105, 0.2);
}

/* =========================================
   8. ICONO PLAY/PAUSE (NUEVO)
   ========================================= */
.state-icon {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0.5); /* Empieza peque??o */
    font-size: 5rem; color: white; opacity: 0; 
    pointer-events: none;
    text-shadow: 0 0 10px rgba(0,0,0,0.8);
    transition: all 0.2s ease-out;
    z-index: 70;
}
.state-icon.animate {
    transform: translate(-50%, -50%) scale(1.2); /* Crece de golpe */
    opacity: 1;
}

/* --- NUEVO: ESTILO PARA CANALES SIN LOGO --- */
.img-placeholder {
    width: 100%;
    height: 100px;
    background: linear-gradient(45deg, #222, #333); /* Fondo elegante */
    color: #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: bold;
    font-size: 0.85rem;
    padding: 10px;
    box-sizing: border-box;
    text-transform: uppercase;
    border-bottom: 1px solid #444;
}

/* --- SOLUCIÓN ANTI-PARPADEO --- */
.poster-container {
    width: 100%;
    height: 100px; /* Misma altura que tenías antes */
    background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* El texto que siempre está detrás (Marca de agua) */
.poster-text {
    position: absolute;
    z-index: 1; 
    color: #666;
    font-weight: bold;
    font-size: 0.9em;
    text-align: center;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
    text-transform: uppercase;
    word-wrap: break-word;
}

/* La imagen va encima. Si falla, se vuelve invisible */
.poster-img {
    position: relative;
    z-index: 2; /* Encima del texto */
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: transparent;
    transition: opacity 0.3s ease;
}

/* Clase para ocultar suavemente la imagen rota */
.poster-img.broken {
    opacity: 0;
}