/* --- VARIABLES --- */
:root {
    --bg-app: #000000;
    --bg-sidebar: #111111;
    --bg-surface: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #888888;
    --accent: #0055ff;
    --danger: #ff3333;
}

* { box-sizing: border-box; }
a { text-decoration: none; color: inherit; }

body {
    margin: 0;
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    height: 100vh;
    overflow: hidden;
}

/* --- LOADER --- */
.loader-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: #000; z-index: 9999;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.6s ease-out, visibility 0.6s;
}
.loader-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-logo { font-family: 'Inter', sans-serif; font-weight: 900; font-size: 60px; letter-spacing: -3px; color: white; animation: heartbeat 1.5s infinite ease-in-out; }
.loader-logo span { color: var(--accent); }
@keyframes heartbeat { 0% { transform: scale(1); text-shadow: 0 0 0 rgba(0, 85, 255, 0); } 50% { transform: scale(1.05); text-shadow: 0 0 30px rgba(0, 85, 255, 0.6); } 100% { transform: scale(1); text-shadow: 0 0 0 rgba(0, 85, 255, 0); } }

/* --- LAYOUT GLOBAL --- */
.app-container { display: flex; height: 100%; width: 100%; }
.sidebar { width: 80px; background: var(--bg-sidebar); display: flex; flex-direction: column; align-items: center; padding: 30px 0; border-right: 1px solid #222; z-index: 100; }
.logo { font-weight: 900; font-size: 24px; margin-bottom: 50px; letter-spacing: -2px; color: white; }
.menu-items { display: flex; flex-direction: column; gap: 40px; width: 100%; align-items: center; }
.menu-link { color: var(--text-secondary); font-size: 20px; transition: 0.3s; height: 50px; width: 50px; display: grid; place-items: center; border-radius: 12px; }
.menu-link:hover { color: white; background: var(--bg-surface); }
.menu-link.active { color: var(--accent); background: rgba(0, 85, 255, 0.1); box-shadow: 0 0 15px rgba(0, 85, 255, 0.1); }

.main-content { flex: 1; display: flex; flex-direction: column; background: var(--bg-app); position: relative; overflow-y: auto; }
.page-header { padding: 30px 40px; background: linear-gradient(to bottom, rgba(0,0,0,0.9), transparent); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 50; pointer-events: none; }
.page-header h1 { margin: 0; font-size: 28px; font-weight: 300; letter-spacing: -1px; text-transform: uppercase; }
.page-header .meta { font-size: 12px; color: var(--text-secondary); font-weight: 600; margin-left: 10px; }

/* --- VIDEO STAGE (HOME) --- */
.video-stage { 
    width: 100%; height: 80vh; 
    position: relative; background: black; flex-shrink: 0; overflow: hidden; 
}
.video-js { width: 100%; height: 100%; }
.video-js .vjs-control-bar { display: none !important; }
.video-js .vjs-tech { pointer-events: none; }

/* HUD Datos */
.minimal-hud {
    position: absolute; bottom: 30px; left: 30px;
    display: flex; gap: 30px; z-index: 20;
    background: rgba(10,10,10,0.8); backdrop-filter: blur(10px);
    padding: 15px 25px; border-radius: 8px; border: 1px solid #333;
    transition: opacity 0.3s;
}
.map-container { width: 80px; border-right: 1px solid #444; padding-right: 15px; display: flex; align-items: center;}
.data-metrics { display: flex; gap: 20px; }
.metric-value { font-size: 24px; font-weight: 700; line-height: 1; color: white; }
.metric-label { font-size: 10px; color: var(--text-secondary); font-weight: 600; display: block; margin-top: 4px; }

/* CONTROLES PERSONALIZADOS */
.custom-controls {
    position: absolute;
    bottom: 0; left: 0; width: 100%;
    padding: 30px 40px;
    background: linear-gradient(to top, rgba(0,0,0,0.95), transparent);
    display: flex; justify-content: space-between; align-items: center;
    z-index: 60; 
    opacity: 0; 
    transition: opacity 0.3s ease;
}
.video-stage:hover .custom-controls { opacity: 1; }

.controls-left { display: flex; gap: 25px; align-items: center; }
.control-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white; 
    font-size: 24px; 
    cursor: pointer; transition: 0.2s;
    width: 55px; height: 55px; 
    display: grid; place-items: center; border-radius: 50%;
    backdrop-filter: blur(5px);
}
.control-btn:hover { color: var(--accent); background: white; opacity: 1; transform: scale(1.1); border-color: white;}

/* REGLA ESPECÍFICA: BOTONES GIGANTES EN FULLSCREEN */
.custom-controls.fullscreen-mode .control-btn {
    width: 80px; 
    height: 80px;
    font-size: 35px;
    border-width: 2px;
}

.live-indicator-dot { font-size: 14px; font-weight: bold; color: #ff3333; background: rgba(255, 51, 51, 0.15); padding: 8px 15px; border-radius: 6px; margin-left: 15px; border: 1px solid rgba(255,0,0,0.2); }

/* --- SECCIÓN CÁMARAS (RAIL) --- */
.camera-section { padding: 30px 40px; background: #050505; border-top: 1px solid #222; }
.section-header { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.section-header h3 { margin: 0; font-size: 12px; color: var(--text-secondary); letter-spacing: 2px; }
.camera-rail { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.cam-card { position: relative; height: 120px; border-radius: 8px; overflow: hidden; cursor: pointer; border: 2px solid transparent; transition: all 0.3s ease; }
.cam-bg { width: 100%; height: 100%; background-size: cover; background-position: center; background-color: #222; transition: transform 0.5s; }
.cam-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(to top, rgba(0,0,0,0.9), transparent); display: flex; justify-content: space-between; align-items: flex-end; padding: 15px; box-sizing: border-box; }
.cam-name { font-weight: 700; font-size: 14px; text-transform: uppercase; }
.cam-overlay i { color: var(--text-secondary); }
.cam-card:hover { border-color: #444; }
.cam-card:hover .cam-bg { transform: scale(1.1); }
.cam-card.active { border-color: var(--accent); box-shadow: 0 0 20px rgba(0, 85, 255, 0.2); }
.cam-card.active .cam-name { color: var(--accent); }
.cam-card.active .cam-overlay i { color: var(--accent); }

/* --- FULLSCREEN BEHAVIOR --- */
.camera-section.fullscreen-active {
    position: absolute;
    bottom: 0; left: 0; width: 100%;
    background: linear-gradient(to top, #000 40%, transparent);
    border: none;
    z-index: 50; 
    padding-bottom: 30px; 
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.custom-controls.fullscreen-mode {
    bottom: 180px; /* Subimos los controles para que no toquen las cámaras */
    background: none; 
    padding-bottom: 0;
}

/* OCULTACIÓN POR INACTIVIDAD */
.video-js.vjs-user-inactive .camera-section.fullscreen-active,
.video-js.vjs-user-inactive .custom-controls.fullscreen-mode,
.video-js.vjs-user-inactive .minimal-hud {
    opacity: 0;
    transform: translateY(30px);
    pointer-events: none;
}

.video-js.vjs-user-active .camera-section.fullscreen-active,
.video-js.vjs-user-active .custom-controls.fullscreen-mode,
.video-js.vjs-user-active .minimal-hud {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

/* --- MULTIVIEW --- */
.multiview-grid {
    display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
    gap: 4px; height: 100%; padding: 4px; box-sizing: border-box;
}
.mv-cell { position: relative; background: #111; border: 1px solid #222; overflow: hidden; }
.mv-cell:hover { border-color: var(--accent); }
.mv-label { 
    position: absolute; top: 10px; left: 10px; z-index: 10;
    background: black; color: white; padding: 2px 8px; font-size: 10px; font-weight: bold;
}

/* --- GUIDE --- */
.epg-container { padding: 20px 40px; }
.epg-row { display: flex; border-bottom: 1px solid #222; padding: 15px 0; align-items: center; transition: 0.2s; }
.epg-row:hover { background: #0a0a0a; }
.ch-logo { width: 60px; font-weight: 900; color: var(--text-secondary); font-size: 14px; text-align: center; }
.prog-bar { flex: 1; margin-left: 20px; position: relative; height: 40px; display: flex; gap: 2px; }
.prog-block { background: #222; height: 100%; border-radius: 4px; padding: 0 10px; display: flex; flex-direction: column; justify-content: center; cursor: pointer; }
.prog-block:hover { background: #333; }
.prog-block.live { background: var(--bg-surface); border-left: 3px solid var(--accent); }
.prog-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prog-time { font-size: 10px; color: var(--text-secondary); }

/* --- SETTINGS --- */
.settings-container { max-width: 600px; margin: 40px auto; width: 100%; padding: 0 20px; }
.setting-group { margin-bottom: 40px; }
.group-title { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; border-bottom: 1px solid #222; padding-bottom: 10px; margin-bottom: 20px; letter-spacing: 1px; }
.setting-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.setting-label { font-size: 16px; font-weight: 400; }
.switch { position: relative; display: inline-block; width: 40px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #333; transition: .4s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(20px); }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #000; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* =========================================
   📱 MOBILE RESPONSIVE FIX (DEFINITIVO)
   ========================================= */

@media (max-width: 768px) {

    /* 1. LAYOUT VERTICAL */
    .app-container {
        flex-direction: column !important;
        height: 100vh;
        overflow: hidden;
    }

    /* 2. MENÚ ABAJO (BOTTOM BAR) */
    .sidebar {
        width: 100% !important;
        height: 60px !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        flex-direction: row !important;
        justify-content: space-around;
        border-right: none !important;
        border-top: 1px solid #222;
        background: #000;
        z-index: 9999;
        padding: 0 !important;
    }
    .sidebar .logo { display: none; }
    .menu-items { flex-direction: row !important; width: 100%; height: 100%; gap: 0 !important; }
    .menu-link { width: 100% !important; height: 100% !important; border-radius: 0 !important; }
    .menu-link.active { box-shadow: inset 0 -3px 0 var(--accent); background: transparent; }

    /* 3. CONTENIDO PRINCIPAL */
    .main-content {
        width: 100% !important;
        height: calc(100vh - 60px) !important; /* Pantalla menos barra abajo */
        padding-bottom: 60px;
        overflow-y: auto;
    }

    /* 4. CABECERA */
    .page-header {
        position: relative !important; /* Vital para que no flote sobre el vídeo */
        background: #000 !important;
        padding: 15px 20px !important;
    }
    .page-header h1 { font-size: 18px !important; }

    /* 5. VÍDEO (El arreglo del vacío negro) */
    .video-stage {
        width: 100% !important;
        height: auto !important; /* MACHACAMOS EL 80VH */
        aspect-ratio: 16/9 !important; /* Proporción panorámica obligatoria */
        background: #000;
        flex-shrink: 0;
    }

    /* UI del Vídeo */
    .minimal-hud { transform: scale(0.7); transform-origin: bottom left; left: 10px !important; bottom: 10px !important; }
    .custom-controls { opacity: 1 !important; padding: 5px 10px !important; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); }
    .control-btn { width: 35px !important; height: 35px !important; font-size: 14px !important; }

    /* 6. RAIL DE CÁMARAS (Scroll Lateral) */
    .camera-section { padding: 15px !important; background: #050505; }
    .camera-rail {
        display: flex !important;
        grid-template-columns: none !important;
        overflow-x: auto !important;
        gap: 15px !important;
        padding-bottom: 10px;
    }
    .cam-card { min-width: 140px !important; height: 80px !important; flex-shrink: 0; }

    /* 7. MULTIVIEW (Vertical) */
    .multiview-grid { display: flex; flex-direction: column; height: auto; padding-bottom: 60px; }
    .mv-cell { aspect-ratio: 16/9; width: 100%; height: auto; }
}