:root {
    --pluto-bg: #000000;
    --pluto-sidebar-bg: #0f0f0f;
    --pluto-accent: #ffeb00;
    --pluto-blue: #007bff;
    --pluto-text: #ffffff;
    --pluto-text-muted: #aaaaaa;
    --pluto-item-hover: rgba(255, 255, 255, 0.1);
    --pluto-item-active: rgba(255, 255, 255, 0.2);
    --sidebar-width: 260px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--pluto-bg);
    color: var(--pluto-text);
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    height: 60px;
    background: rgba(0,0,0,0.95);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid #222;
    z-index: 1000;
    justify-content: space-between;
    gap: 15px;
}

.logo {
    font-size: 22px;
    font-weight: 900;
    letter-spacing: -1px;
    color: white;
    cursor: pointer;
    flex-shrink: 0;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-grow: 1;
    justify-content: flex-end;
}

.nav-item {
    color: #ccc;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    padding: 8px 12px;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-item:hover, .nav-item.active {
    color: white;
}

.nav-item.active {
    border-bottom: 2px solid var(--pluto-blue);
}

.nav-divider {
    width: 1px;
    height: 15px;
    background: #444;
    margin: 0 5px;
}

.manage-btn { color: #00ff88 !important; }

/* Soporte por Internet con Latido Constante */
.support-btn { 
    color: var(--pluto-accent) !important; 
    font-weight: 800 !important;
    animation: support-heartbeat 2s infinite;
    border: 1px solid rgba(255, 235, 0, 0.3);
    border-radius: 4px;
    padding: 5px 10px !important;
}

@keyframes support-heartbeat {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; box-shadow: 0 0 10px rgba(255, 235, 0, 0.2); }
    100% { transform: scale(1); opacity: 1; }
}

.desktop-only { display: block; }

.menu-toggle {
    display: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
}

/* Contador de canales al final a la derecha */
#channelCounterVisor {
    padding: 8px 15px;
    background: rgba(0, 123, 255, 0.1);
    border-radius: 20px;
    margin-left: 10px;
    font-size: 10px;
    color: var(--pluto-blue);
    font-weight: 800;
    text-transform: uppercase;
    border: 1px solid rgba(0, 123, 255, 0.3);
    order: 10;
}

/* Buscador */
.search-container {
    display: flex;
    align-items: center;
    background: #1a1a1a;
    border-radius: 20px;
    padding: 5px 15px;
    flex: 1;
    max-width: 300px;
    border: 1px solid #333;
    transition: all 0.3s;
    opacity: 0;
    width: 0;
    pointer-events: none;
    position: absolute;
    left: 10px;
    right: 10px;
    z-index: 2000;
}

.search-container.active {
    opacity: 1;
    width: calc(100% - 20px);
    pointer-events: all;
}

.search-container input {
    background: none;
    border: none;
    color: white;
    padding: 5px;
    width: 100%;
    outline: none;
}

.search-trigger {
    color: #ccc;
    cursor: pointer;
    font-size: 16px;
    padding: 10px;
}

.nav-mobile-visible { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}

/* Loader */
#loadingOverlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease-out;
}

.loader {
    width: 40px; height: 40px;
    border: 4px solid #FFF;
    border-bottom-color: var(--pluto-blue);
    border-radius: 50%;
    animation: rotation 1s linear infinite;
}

@keyframes rotation { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Estructura Principal */
#appContainer {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
}

/* Reproductor */
#playerSection {
    width: 100%;
    background: #000;
    position: relative;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    flex-shrink: 0;
}

#videoPlayer { width: 100%; height: 100%; object-fit: contain; }

/* Sección Inferior */
#contentSection {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: #0a0a0a;
    position: relative;
}

/* Sidebar rediseñado: 40% Categorías, 60% Canales */
#categoriesSidebar {
    width: 240px; /* Ancho fijo para categorías */
    background: #000;
    overflow-y: auto;
    border-right: 1px solid #1a1a1a;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 500;
    padding-top: 50px;
    flex-shrink: 0;
    position: relative;
}

/* Al colapsar, se desliza hacia la derecha (hacia los canales) */
#categoriesSidebar.collapsed { 
    transform: translateX(100%);
    position: absolute;
    right: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
}

.category-item {
    padding: 12px 20px;
    cursor: pointer;
    font-size: 13px;
    color: var(--pluto-text-muted);
    transition: all 0.2s;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.category-item:hover { color: white; background: var(--pluto-item-hover); }
.category-item.active { color: var(--pluto-blue); background: rgba(0, 123, 255, 0.1); border-right: 3px solid var(--pluto-blue); }

.toggle-sidebar {
    position: absolute;
    left: 10px; top: 10px;
    z-index: 600;
    background: rgba(40, 40, 40, 0.8);
    color: white;
    border: 1px solid #444;
    width: 32px; height: 32px;
    border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; backdrop-filter: blur(4px);
}

/* Lista de Canales: Ajustada para ser pegada al sidebar y reducida un 25% */
#channelsGrid { 
    flex: 1;
    background: #0f0f0f; 
    overflow-y: auto; 
    padding: 15px;
    padding-top: 50px;
    max-width: 450px; /* Reducción de ancho solicitada */
}

#channelContainer { display: flex; flex-direction: column; gap: 5px; list-style: none; padding: 0; margin: 0; }
#channelContainer li {
    background: #161616; padding: 10px 15px; border-radius: 4px; cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
    transition: all 0.2s; border-left: 3px solid transparent;
}
#channelContainer li:hover { background: #222; }
#channelContainer li.active { background: #2a2a2a; border-left-color: var(--pluto-blue); }

.channel-left { display: flex; align-items: center; gap: 12px; overflow: hidden; }
.channel-play-icon { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; color: #444; font-size: 12px; }
li:hover .channel-play-icon, li.active .channel-play-icon { color: var(--pluto-blue); }
.channel-info-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.channel-name { font-size: 13px; font-weight: 600; color: #eee; }
.channel-cat-tag { font-size: 9px; color: #666; text-transform: uppercase; }
.status-dot { width: 6px; height: 6px; background: #333; border-radius: 50%; }
li.active .status-dot { background: var(--pluto-blue); box-shadow: 0 0 8px var(--pluto-blue); }

/* Reproductor Controls */
.player-controls {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.9));
    padding: 15px 20px;
    opacity: 0; transition: opacity 0.3s; z-index: 20;
}
#playerSection:hover .player-controls, .player-controls.visible { opacity: 1; }

/* Nuevos Botones Centrales */
#centralControls {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 40px;
    z-index: 25;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

#centralControls.visible {
    opacity: 1;
    pointer-events: all;
}

.central-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: white;
    width: 15vh;
    height: 15vh;
    min-width: 60px;
    min-height: 60px;
    max-width: 130px;
    max-height: 130px;
    border-radius: 50%;
    font-size: 6vh;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: transform 0.2s, background 0.2s, opacity 0.3s;
    box-shadow: 0 0 40px rgba(0,0,0,0.4);
}

#centralControls {
    gap: 5vh;
}

@media (max-width: 768px) {
    .central-btn {
        width: 12vh;
        height: 12vh;
        font-size: 5vh;
    }
    #centralControls {
        gap: 3vh;
    }
}

.central-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.central-btn:active {
    transform: scale(0.9);
}

/* Spinner de carga moderno */
#playerLoader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.modern-spinner {
    width: 80px;
    height: 80px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top: 5px solid var(--pluto-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.5);
}

#loaderCountdown {
    position: absolute;
    font-size: 24px;
    font-weight: bold;
    color: white;
    text-shadow: 0 0 10px rgba(0,0,0,1);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Ocultar etiquetas al estar activo el reproductor */
#channelNameOverlay {
    transition: opacity 0.3s, transform 0.3s;
    z-index: 20;
}

#channelNameOverlay.hidden {
    opacity: 0;
}
.controls-row { display: flex; align-items: center; gap: 15px; }
.progress-container { flex: 1; height: 4px; background: rgba(255,255,255,0.2); cursor: pointer; border-radius: 2px; }
.progress-bar { width: 0%; height: 100%; background: var(--pluto-blue); }
.control-btn { background: none; border: none; color: white; font-size: 18px; cursor: pointer; transition: transform 0.1s; }
.control-btn:active { transform: scale(0.9); }

#channelNameOverlay {
    position: absolute;
    top: 15px; left: 15px; z-index: 20;
    background: rgba(0,0,0,0.5); padding: 5px 12px;
    border-radius: 4px; backdrop-filter: blur(4px);
    font-size: 13px; border: 1px solid #333;
}

/* Desktop */
@media (min-width: 1024px) {
    #appContainer { flex-direction: row; }
    #playerSection { flex: 1; height: 100%; }
    #contentSection { flex: none; width: auto; display: flex; }
    
    /* Ampliación del reproductor al ocultar categorías */
    #appContainer:has(#categoriesSidebar.collapsed) #playerSection {
        flex: 1.5;
    }
}

/* Tablet / Mobile */
@media (max-width: 1023px) {
    .menu-toggle { display: block; }
    .nav-mobile-visible { display: flex !important; align-items: center; gap: 10px; }
    .desktop-only { display: none !important; }
    
    .search-container.active { 
        max-width: none; width: calc(100% - 20px); opacity: 1; pointer-events: all;
        transition: all 0.3s; left: 10px; right: 10px; display: flex !important;
    }
    
    .nav-links {
        display: none; position: absolute; top: 60px; right: 0; background: #111;
        width: 250px; flex-direction: column; padding: 10px 0;
        border-left: 1px solid #222; border-bottom: 1px solid #222;
        box-shadow: -5px 10px 20px rgba(0,0,0,0.5); z-index: 1500;
    }
    .nav-links.show { display: flex; }
    .nav-item { width: 100%; padding: 15px 20px; border-bottom: 1px solid #222; }
    .nav-item.active { border-bottom: none; border-left: 4px solid var(--pluto-blue); background: #1a1a1a; }

    #playerSection { width: 100%; height: auto; max-height: 50vh; }
    #contentSection { flex: 1; flex-direction: row; overflow: hidden; display: flex; }
    
    /* Móvil 50/50 por defecto debajo del reproductor */
    #categoriesSidebar { 
        width: 50%; height: 100%; position: relative; left: 0; top: 0; z-index: 800;
    }
    #categoriesSidebar.collapsed { transform: translateX(-100%); position: absolute; }
    
    #channelsGrid { width: 50%; max-width: none; flex: 1; padding: 10px; padding-top: 50px; }
    
    .player-controls.visible { opacity: 1 !important; }
    .toggle-sidebar { top: 10px; left: 10px; z-index: 900; display: flex !important; }
}

@media (max-width: 480px) {
    #categoriesSidebar { width: 50%; }
    #channelsGrid { width: 50%; }
    
    /* Al colapsar en móvil, los canales ocupan el 100% */
    #contentSection:has(#categoriesSidebar.collapsed) #channelsGrid {
        width: 100%;
        max-width: none;
    }
}

/* Tablet Horizontal */
@media (max-width: 1024px) and (orientation: landscape) {
    #appContainer { flex-direction: row; }
    #playerSection { flex: 1; height: 100%; max-height: none; }
    #contentSection { flex: none; width: auto; display: flex; }
    #categoriesSidebar { width: 200px; }
    #channelsGrid { width: 300px; }
}

/* Start Overlay */
#startOverlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.95);
    z-index: 10001; display: flex; flex-direction: column; justify-content: center; align-items: center;
    cursor: pointer; text-align: center; padding: 20px;
}

.logo-heartbeat {
    width: 100px; height: auto; margin-bottom: 25px; animation: heartbeat 1.5s infinite;
}

@keyframes heartbeat {
    0% { transform: scale(1); }
    15% { transform: scale(1.1); }
    30% { transform: scale(1); }
    45% { transform: scale(1.05); }
    60% { transform: scale(1); }
}

#startOverlay h2 { font-size: 24px; font-weight: 900; letter-spacing: 1px; }
#startOverlay p { color: #aaa; margin-top: 10px; font-size: 14px; }
.free-color { color: white; }
.tv-color { color: var(--pluto-blue); }
