/* Palette TVClub basée sur le logo Prisme */
:root {
    --brand-color: #9d4edd; /* Violet TVClub */
    --brand-gradient: linear-gradient(135deg, #480ca8, #f72585);

    --bg-main: #0a0a0c;
    --bg-panel: #141418;
    --bg-hover: #1e1e24;
    --border-color: #2a2a35;

    --prism-blue: #3b5998;
    --prism-purple: #8e3a9a;
    --prism-coral: #f47c5d;
    --prism-peach: #f9b280;
    
    --gradient-brand: linear-gradient(135deg, var(--prism-blue) 0%, var(--prism-purple) 50%, var(--prism-coral) 100%);
    
    --text-main: #f0f0f0;
    --text-muted: #888890;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column; /* Passage en mode vertical pour le header */
    min-height: 100dvh; /* dvh pour support mobile */
}

body.player-page {
    /* overflow: hidden; Removed to allow responsive stacking and scrolling if needed */
    min-height: 100dvh;
}

/* --- HEADER SUPÉRIEUR --- */
.top-header {
    min-height: 60px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px; /* Réduit pour mobile */
    z-index: 20;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    flex-wrap: wrap; /* Autoriser le passage à la ligne sur mobile */
}

.top-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-brand);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 2px;
}

.top-header a {
    color: var(--text-muted);
    font-size: 1.2rem;
    transition: color 0.3s ease;
}

.top-header a:hover {
    color: var(--prism-coral);
}

.top-header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-avatar-img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--prism-purple);
}

.header-avatar-placeholder {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.header-admin-link {
    text-decoration: none;
}

.header-admin-badge {
    background-color: var(--prism-purple);
    color: white;
    margin-left: 5px;
}

.header-logout-link {
    margin-left: 10px;
    padding: 5px; /* Améliore la zone tactile */
}

.header-login-link {
    color: var(--text-main);
    text-decoration: none;
    font-weight: 500;
}

@media (max-width: 768px) {
    .top-header {
        padding: 5px 10px;
        gap: 10px;
        /* Flex sur deux lignes ou scrollable horizontalement */
        /* On garde la nav au centre scrollable si trop long */
    }

    .nav-center-tabs {
        order: 3; /* Passe sous le logo et profil sur petit écran */
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        /* masquer la barre de défilement */
        -ms-overflow-style: none;  /* IE and Edge */
        scrollbar-width: none;  /* Firefox */
    }
    .nav-center-tabs::-webkit-scrollbar {
        display: none;
    }
    .user-profile-link span {
        display: none; /* Cache le nom d'utilisateur pour gagner de la place */
    }
}

/* --- CONTENU PRINCIPAL --- */
.main-content {
    display: flex;
    flex-grow: 1;
    height: 100%;
    min-height: 0;
}

.user-profile-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: opacity 0.2s;
}

.user-profile-link:hover {
    opacity: 0.8;
}

.nav-center-tabs {
    display: flex;
    gap: 20px;
    height: 100%;
}

/* --- LECTEUR VIDÉO (À GAUCHE) --- */
.player-container {
    flex-grow: 1;
    background-color: #000;
    position: relative;
    display: flex;
}

.video-js {
    width: 100% !important;
    height: 100% !important;
}

.vjs-theme-fantasy .vjs-play-progress { background: var(--gradient-brand) !important; }
.vjs-theme-fantasy .vjs-volume-level { background: var(--prism-coral) !important; }
.vjs-theme-fantasy .vjs-big-play-button { background-color: rgba(142, 58, 154, 0.7) !important; }
.vjs-theme-fantasy:hover .vjs-big-play-button { background-color: var(--prism-coral) !important; }

/* Le contrôle VF / VO / VOST vit dans player-language.css. */

/* --- BARRE LATÉRALE CHAÎNES (À DROITE) --- */
.sidebar {
    width: 350px;
    background-color: var(--bg-panel);
    border-left: 1px solid var(--border-color); /* Bordure inversée */
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: -2px 0 15px rgba(0,0,0,0.3);
    min-width: 0;
}

.channel-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px 10px;
    min-width: 0;
}

.channel-list::-webkit-scrollbar { width: 6px; }
.channel-list::-webkit-scrollbar-track { background: var(--bg-panel); }
.channel-list::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
.channel-list::-webkit-scrollbar-thumb:hover { background: var(--prism-purple); }

.channel-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background: transparent;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.channel-item:hover {
    background: var(--bg-hover);
    border-color: rgba(142, 58, 154, 0.3);
}

.channel-item.active {
    background: rgba(59, 89, 152, 0.1);
    border-color: var(--prism-purple);
    box-shadow: 0 4px 15px rgba(142, 58, 154, 0.15);
}

.channel-logo {
    width: 64px; /* Un peu plus large pour les logos rectangulaires */
    height: 44px;
    background-color: transparent; /* Mieux pour les PNG détourés */
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
    object-fit: contain; /* L'image s'adapte sans se déformer */
    padding: 2px; /* Laisse l'image respirer */
}

.channel-item.active .channel-logo {
    background: var(--gradient-brand);
    color: #fff;
    border-color: transparent;
}

.channel-info {
    flex-grow: 1;
    min-width: 0; /* Important for flex children to allow text truncation */
}
.channel-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.channel-now {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2; /* limite les titres longs sur deux lignes max */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* --- RESPONSIVE DESIGN (SMARTPHONES & TABLETTES) --- */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column; /* On passe d'un affichage ligne à un affichage colonne */
    }

    .player-container {
        width: 100%;
        flex-grow: 0;
        flex-shrink: 0;
        aspect-ratio: 16 / 9; /* Force le lecteur à garder un format vidéo parfait en haut */
        max-height: 56.25vw; /* Assure que le lecteur ne dépasse pas la hauteur d'un 16/9 sur toute la largeur */
    }

    .sidebar {
        width: 100%;
        flex-grow: 1; /* La liste des chaînes prend tout l'espace restant en bas */
        border-left: none;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.3); /* L'ombre passe en haut */
    }
}


/* --- EPG GUIDE STYLES --- */

.guide-container {
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 120px);
    overflow: hidden;
    background-color: #121212;
    flex: 1; /* Allow stretching in mobile */
}

@media (max-width: 768px) {
    .guide-container {
        height: auto;
    }
}

/* La zone de focus en haut (Hero) */
.guide-hero {
    height: 35vh; /* Prend 35% de l'écran */
    min-height: 200px;
    position: relative;
    background-color: #000;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
}

@media (max-width: 768px) {
    .guide-hero {
        height: 25vh; /* Plus petit sur mobile */
        min-height: 150px;
    }

    .hero-content {
        padding: 15px !important;
    }

    .hero-poster {
        display: none !important; /* Cache le poster sur mobile pour avoir plus de place au texte */
    }

    .hero-info {
        max-width: 100% !important;
    }

    .hero-title {
        font-size: 1.5rem !important;
    }

    .hero-meta {
        font-size: 0.9rem !important;
        margin-bottom: 10px !important;
    }

    .hero-synopsis {
        -webkit-line-clamp: 3 !important;
        font-size: 0.95rem !important;
    }
}

.hero-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-size: cover;
    background-position: center 20%;
    opacity: 0.3;
    transition: background-image 0.4s ease-in-out;
}

/* D\u00e9grad\u00e9 pour que le texte reste lisible sur l'image */
.hero-backdrop::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(90deg, #121212 10%, transparent 60%);
}

.hero-content {
    position: relative;
    z-index: 2;
    display: flex;
    padding: 30px;
    height: 100%;
    align-items: center;
}

.hero-poster {
    height: 90%;
    border-radius: 8px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.8);
    margin-right: 30px;
    border: 1px solid rgba(255,255,255,0.1);
}

.hero-info {
    max-width: 60%;
    color: white;
}

.hero-title {
    font-size: 2.5rem;
    margin: 0 0 10px 0;
    font-weight: 800;
}

.hero-meta {
    color: var(--brand-color);
    font-weight: 600;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.hero-synopsis {
    font-size: 1.1rem;
    line-height: 1.5;
    color: #ccc;
    display: -webkit-box;
    -webkit-line-clamp: 4; /* Coupe le texte apr\u00e8s 4 lignes */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* La grille inf\u00e9rieure (EPG) */
.guide-epg-wrapper {
    display: flex;
    flex: 1;
    overflow: auto;
    /* Eviter que la hauteur n'explose */
    min-height: 0;
}

/* Colonne des cha\u00eenes (Fixe \u00e0 gauche) */
.guide-channels {
    width: 120px;
    min-width: 120px;
    background-color: #1a1a1a;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: sticky;
    left: 0;
    z-index: 30;
}

@media (max-width: 768px) {
    .guide-channels {
        width: 70px;
        min-width: 70px;
    }
}

/* Pseudo element to compensate for the scrollbar height, so the last channel row aligns with the last timeline row */
.guide-channels::after {
    content: '';
    display: block;
    min-height: 15px; /* typical scrollbar height */
    flex-shrink: 0;
}

.channel-header-spacer {
    height: 40px;
    min-height: 40px;
    box-sizing: border-box;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background-color: #1a1a1a;
    z-index: 40;
}

.guide-channel-row {
    height: 80px; /* Hauteur d'une ligne de cha\u00eene */
    min-height: 80px;
    flex-shrink: 0;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border-color);
    background-color: #1a1a1a;
    text-align: center;
    padding: 5px;
    overflow: hidden;
}

.guide-channel-row strong {
    font-size: 0.9rem;
    word-break: break-all;
}

.guide-channel-logo {
    max-width: 80%;
    max-height: 50px;
    object-fit: contain;
}

/* Zone d\u00e9filante (Timeline) */
.guide-timeline-container {
    flex: 1;
    position: relative;
    background-color: #222;
    min-height: max-content;
}

/* Ligne des heures en haut */
.timeline-header {
    height: 40px;
    min-height: 40px;
    box-sizing: border-box;
    background-color: #1a1a1a;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 20; 
    display: flex;
}

.time-slot {
    position: absolute;
    top: 0;
    height: 100%;
    border-left: 1px solid #333;
    padding-left: 5px;
    color: #888;
    font-size: 0.9rem;
    line-height: 40px;
}

/* Ligne de l'heure actuelle */
.current-time-indicator {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--brand-gradient);
    z-index: 5;
    pointer-events: none; /* Pour pouvoir cliquer à travers */
}

/* Les lignes de programmes */
.timeline-rows {
    position: relative;
}

.epg-row {
    height: 80px;
    min-height: 80px;
    flex-shrink: 0;
    box-sizing: border-box;
    position: relative;
    border-bottom: 1px solid var(--border-color);
}

/* Les blocs de programme */
.epg-program {
    position: absolute;
    top: 2px;
    bottom: 2px;
    background-color: #333;
    border-radius: 4px;
    border: 1px solid #444;
    padding: 8px;
    overflow: hidden;
    cursor: pointer;
    white-space: nowrap;
    /* On ajoute une transition douce et on prépare le z-index */
    transition: all 0.2s ease-out;
    z-index: 1;
}

.epg-program:hover {
    background-color: #444;
    /* On utilise la couleur de la marque (fallback violet par défaut) */
    border-color: var(--brand-color, #9d4edd);
    /* L'effet "Pop" : on l'agrandit légèrement et on ajoute une ombre lumineuse */
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5), 0 0 10px var(--brand-color, rgba(157, 78, 221, 0.4));
    z-index: 10; /* Il passe au-dessus de tous les autres blocs */
}

.epg-program.slate {
    background: repeating-linear-gradient(
        45deg,
        #222,
        #222 10px,
        #2a2a2a 10px,
        #2a2a2a 20px
    );
    color: #666;
}

.epg-program-title {
    font-weight: bold;
    font-size: 1rem;
    color: #eee;
    text-overflow: ellipsis;
    overflow: hidden;
}

.epg-program-time {
    font-size: 0.8rem;
    color: #999;
    margin-top: 4px;
}



/* Barre de navigation des jours */
.guide-date-nav {
    background-color: #1a1a1a;
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    justify-content: center;
}

.date-tabs {
    display: flex;
    gap: 10px;
    overflow-x: auto;
}

.date-tab-btn {
    background: transparent;
    color: #888;
    border: 1px solid #444;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.date-tab-btn:hover {
    color: #fff;
    border-color: #888;
}

.date-tab-btn.active {
    background: var(--brand-gradient, #9d4edd);
    color: #fff;
    border-color: transparent;
    font-weight: bold;
}

/* --- TABS --- */
.tvclub-tab-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 1.1rem;
    padding: 10px 15px; /* Better touch target (>= 44px) */
    height: 100%;
    display: flex;
    align-items: center;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.tvclub-tab-btn:hover { color: #fff; }
.tvclub-tab-btn.active {
    color: #fff;
    font-weight: bold;
    border-bottom: 3px solid var(--brand-color);
}

/* Conteneur principal des onglets */
.tabs-container {
    position: relative;
    width: 100vw;
    height: calc(100dvh - 120px); /* Utilisation de 100dvh pour exclure la barre d'adresse mobile */
    display: flex;
    flex-direction: column;
}

/* Astuce SPA pour ne pas couper la vidéo */
.tab-content {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}
.tab-content.active {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

/* --- PROFILE MODAL --- */
.tvclub-modal {
    display: none; /* Caché par défaut */
    position: fixed;
    z-index: 1000;
    left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}
.tvclub-modal-content {
    background-color: #121212;
    margin: 5% auto;
    padding: 30px;
    border: 1px solid #333;
    border-radius: 10px;
    width: 80%;
    max-width: 900px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}
.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.close-modal:hover { color: #fff; }

/* --- FOOTER --- */
.tvclub-footer {
    height: 60px;
    background-color: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    z-index: 20;
    margin-top: auto;
    flex-shrink: 0; /* Ensures footer doesn't get collapsed by flex */
}

@media (max-width: 768px) {
    .tabs-container {
        /* Laisse flexbox gérer la hauteur au lieu de forcer calc(100vh - 120px) */
        height: auto;
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    .tab-content {
        position: relative; /* Change de absolute à relative sur mobile si nécessaire pour le scroll normal */
        visibility: hidden;
        display: none;
    }

    .tab-content.active {
        visibility: visible;
        display: flex;
        flex-direction: column;
        flex: 1;
        opacity: 1;
        pointer-events: auto;
        z-index: 10;
    }
}

/* ------------------------------------------------------------------
   PLAYER LAYOUT CLEAN FIX
------------------------------------------------------------------ */
#tab-player,
#tab-player.tab-content.active {
    overflow-y: auto !important; /* Allow scroll if content is taller than screen on mobile */
    overflow-x: hidden !important;
}

#tab-player .main-content {
    height: 100% !important;
    min-height: 0 !important;
    overflow: visible !important;
}

#tab-player .player-container {
    min-width: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #000 !important;
    --player-aspect-ratio: 16 / 9;
}

/*
 * La hauteur vient de la zone disponible.
 * La largeur suit le ratio. Donc pas de scroll vertical.
 */
#tab-player .player-container .video-js {
    position: relative !important;
    height: 100% !important;
    width: auto !important;
    max-width: 100% !important;
    aspect-ratio: var(--player-aspect-ratio) !important;
    flex: 0 0 auto !important;
    background: #000 !important;
}

/*
 * Empêche Video.js de réintroduire un padding-top fluid/ratio.
 */
#tab-player .player-container .video-js.vjs-fluid,
#tab-player .player-container .video-js.vjs-16-9,
#tab-player .player-container .video-js.vjs-4-3 {
    padding-top: 0 !important;
}

#tab-player .player-container .video-js video,
#tab-player .player-container .video-js .vjs-tech,
#tab-player .player-container .video-js .softcrypt-canvas {
    width: 100% !important;
    height: 100% !important;
    object-fit: fill !important;
}

.video-js.vjs-fullscreen,
.video-js:-webkit-full-screen,
.video-js:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    aspect-ratio: auto !important;
}

/* Badge styles for VM/VF/VOST */
.version-badge {
    font-size: 0.65rem;
    padding: 0.25em 0.4em;
}

/* ------------------------------------------------------------------
   Player polish 2026-07-25 — conservation stricte du ratio d'affichage
------------------------------------------------------------------ */
#tab-player .player-container {
    position: relative !important;
    min-width: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    background: #000 !important;
}

/* Video.js constitue la scène noire disponible. Le média est ajusté dedans. */
#tab-player .player-container .video-js {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    aspect-ratio: auto !important;
    flex: 1 1 auto !important;
    overflow: hidden !important;
    background: #000 !important;
}

/*
 * Les dimensions sont calculées par player.js à partir du DAR de la chaîne.
 * object-fit:fill est volontaire ici : l'élément lui-même possède déjà le
 * bon rectangle 4:3 ou 16:9, y compris pour le PAL 720x576 à pixels non carrés.
 */
#tab-player .player-container .video-js video,
#tab-player .player-container .video-js .vjs-tech,
#tab-player .player-container .video-js .softcrypt-canvas {
    position: absolute !important;
    top: 50% !important;
    right: auto !important;
    bottom: auto !important;
    left: 50% !important;
    width: var(--player-media-width, 100%) !important;
    height: var(--player-media-height, 100%) !important;
    max-width: 100% !important;
    max-height: 100% !important;
    transform: translate(-50%, -50%) !important;
    object-fit: fill !important;
    background: #000 !important;
}

#tab-player .player-container .video-js .vjs-poster {
    background-color: #000 !important;
    background-size: contain !important;
}

.video-js.vjs-fullscreen,
.video-js:-webkit-full-screen,
.video-js:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    aspect-ratio: auto !important;
    background: #000 !important;
}

/* --- Fondations lecteur PVR : sidebar stable et accessible --- */
.channel-item {
    width: 100%;
    color: inherit;
    font: inherit;
    text-align: left;
    appearance: none;
    -webkit-appearance: none;
}

.channel-item:focus-visible {
    outline: 2px solid var(--brand-color, #c44cff);
    outline-offset: 2px;
    border-color: var(--brand-color, #c44cff);
}

.channel-logo-image {
    display: block;
}

.channel-logo-initials {
    flex: 0 0 64px;
}

.channel-episode-title {
    font-size: 0.9em;
    font-style: italic;
    color: var(--text-muted);
}
