/* ==========================================================================
   dashboard.css — Estilos del Monitor V4
   ========================================================================== */

/* ── Variables de Color ─────────────────────────────────────────────────── */
:root {
    --bg-color: #e2e8f0; 
    --panel-bg: #ffffff; 
    --text-main: #1e293b; 
    --text-muted: #64748b;
    --border: #cbd5e1; 
    --blue: #0284c7; 
    --light-blue: #f0f9ff; 
    --green: #10b981;
    --red: #ef4444; 
    --orange: #f97316; 
    --indigo: #4338ca; 
    --hover-row: #f0f9ff;
}

body.dark-mode {
    --bg-color: #0f172a; 
    --panel-bg: #1e293b; 
    --text-main: #f1f5f9; 
    --text-muted: #94a3b8;
    --border: #334155; 
    --blue: #38bdf8; 
    --light-blue: #0c4a6e; 
    --hover-row: rgba(56,189,248,.1);
}

/* ── Estilos Generales ──────────────────────────────────────────────────── */
body { 
    font-family: 'Segoe UI', Tahoma, Verdana, sans-serif; 
    background: var(--bg-color); 
    color: var(--text-main); 
    margin: 0; 
    padding: 0; 
    height: 100vh; 
    display: flex; 
    overflow: hidden; 
    transition: background .3s, color .3s; 
    
    /* Reglas añadidas para evitar sombreado/selección de texto */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ── Pantalla de Inicio (Overlay) ───────────────────────────────────────── */
#start-overlay { 
    position: fixed; 
    inset: 0; 
    background: var(--bg-color); 
    z-index: 9999; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
    align-items: center; 
    gap: 20px; 
}

.btn-start { 
    background: var(--blue); 
    color: #fff; 
    border: none; 
    padding: 20px 40px; 
    font-size: 24px; 
    font-weight: 900; 
    border-radius: 14px; 
    cursor: pointer; 
    box-shadow: 0 8px 30px rgba(2,132,199,.4); 
    transition: transform .2s, box-shadow .2s; 
}

.btn-start:hover { 
    transform: scale(1.06); 
    box-shadow: 0 12px 40px rgba(2,132,199,.6); 
}

/* ── Diseño de Paneles ──────────────────────────────────────────────────── */
.panel-izquierdo { 
    width: 62%; 
    display: flex; 
    flex-direction: column; 
    background: var(--panel-bg); 
    border-right: 3px solid var(--blue); 
    box-shadow: 2px 0 10px rgba(0,0,0,.1); 
    z-index: 10; 
    transition: all .4s; 
}

.panel-derecho { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    background: var(--bg-color); 
    padding: 10px; 
    transition: all .4s; 
}

/* ── Encabezado (Header) ────────────────────────────────────────────────── */
.header-section { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background: var(--panel-bg); 
    padding: 10px 18px; 
    border-bottom: 2px solid var(--border); 
    flex-wrap: wrap; 
    gap: 6px; 
}

.header-section h1 { 
    margin: 0; 
    color: var(--blue); 
    font-size: 16px; 
    font-weight: 900; 
    text-transform: uppercase; 
    letter-spacing: .5px; 
}

.clock-badge { 
    font-size: 13px; 
    font-weight: bold; 
    color: var(--blue); 
    background: var(--light-blue); 
    padding: 4px 10px; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
}

.theme-btn { 
    background: transparent; 
    border: none; 
    font-size: 20px; 
    cursor: pointer; 
    padding: 0 8px; 
    transition: transform .2s; 
}

.theme-btn:hover { 
    transform: scale(1.15); 
}

/* ── Estado de Salud (Health) ───────────────────────────────────────────── */
#health-pill { 
    display: inline-flex; 
    align-items: center; 
    gap: 6px; 
    background: var(--light-blue); 
    border: 1px solid var(--border); 
    border-radius: 20px; 
    padding: 3px 10px; 
    font-size: 11px; 
    font-weight: 700; 
    color: var(--blue); 
}

#health-dot { 
    width: 8px; 
    height: 8px; 
    border-radius: 50%; 
    background: var(--green); 
    box-shadow: 0 0 6px var(--green); 
    animation: blink 2s infinite; 
}

#health-dot.warn { 
    background: var(--orange); 
    box-shadow: 0 0 6px var(--orange); 
}

#health-dot.danger { 
    background: var(--red);    
    box-shadow: 0 0 6px var(--red); 
}

/* ── Tablas ─────────────────────────────────────────────────────────────── */
.tabla-container { 
    flex: 1; 
    overflow-y: auto; 
    padding: 10px; 
}

table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0 6px; 
}

th { 
    background: transparent; 
    color: var(--text-muted); 
    font-size: 10px; 
    text-transform: uppercase; 
    letter-spacing: 1px; 
    font-weight: 800; 
    padding: 0 10px; 
    text-align: left; 
}

td { 
    background: var(--panel-bg); 
    padding: 9px; 
    vertical-align: middle; 
    border-top: 1px solid var(--border); 
    border-bottom: 1px solid var(--border); 
}

td:first-child { 
    border-left: 1px solid var(--border); 
    border-radius: 8px 0 0 8px; 
}

td:last-child { 
    border-right: 1px solid var(--border); 
    border-radius: 0 8px 8px 0; 
}

tr:hover td { 
    background: var(--hover-row); 
}

tbody:not(.show-all) tr.sin-api {
    display: none;
}
/* Ocultar filas CERRADAS por defecto — el operador las activa con "Ver Cerradas" */
tbody:not(.show-all) tr.row-closed {
    display: none;
}

/* ── Elementos de Texto en Tablas ───────────────────────────────────────── */
.track-name { 
    font-weight: 900; 
    color: var(--text-main); 
    font-size: 13px; 
}

.race-num { 
    background: var(--border); 
    color: var(--text-main); 
    padding: 2px 7px; 
    border-radius: 4px; 
    font-weight: bold; 
    font-size: 11px; 
}

.dist-txt { 
    font-size: 10px; 
    font-weight: bold; 
    display: block; 
    margin-top: 3px; 
}

.hora-destacada { 
    font-size: 13px; 
    font-weight: 800; 
    color: var(--blue); 
    display: block; 
}

/* ── Estados Especiales de Filas ────────────────────────────────────────── */
.row-closed td { 
    opacity: .55; 
    filter: grayscale(80%); 
}

.row-alerta-neutral td { 
    background: rgba(234,179,8,.08) !important; 
}

.row-alerta-neutral td:first-child { 
    border-left: 4px solid #eab308 !important; 
}

/* Fila urgente — tiempo en 0 */
tr.row-urgente td {
    background: rgba(239,68,68,.08) !important;
    border-top-color: rgba(239,68,68,.3) !important;
    border-bottom-color: rgba(239,68,68,.3) !important;
}

tr.row-urgente td:first-child {
    border-left-color: rgba(239,68,68,.6) !important;
}

tr.row-urgente td:last-child {
    border-right-color: rgba(239,68,68,.6) !important;
}

body.dark-mode tr.row-urgente td {
    background: rgba(239,68,68,.13) !important;
}

/* Fila OFF Reciente — gris tope lista, 15s visibles */
tr.row-off-reciente td {
    background: rgba(100,116,139,.07) !important;
    border-top-color: rgba(100,116,139,.2) !important;
    border-bottom-color: rgba(100,116,139,.2) !important;
}

tr.row-off-reciente td:first-child {
    border-left: 3px solid #64748b !important;
    border-radius: 8px 0 0 8px;
}

tr.row-off-reciente td:last-child {
    border-right-color: rgba(100,116,139,.2) !important;
}

body.dark-mode tr.row-off-reciente td {
    background: rgba(100,116,139,.12) !important;
}

/* ── Badges y Etiquetas ─────────────────────────────────────────────────── */
.badge {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    display: inline-block;
}

.b-open { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.b-closed { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.b-hold { background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }
.b-shield { background: #e0e7ff; color: #4338ca; border: 1px solid #c7d2fe; }
.b-neutral {
    background: repeating-linear-gradient(45deg, #fef08a, #fef08a 5px, #fde047 5px, #fde047 10px);
    color: #854d0e;
    border: 1px solid #eab308;
    animation: pulse-neutral 1.5s infinite;
}

body.dark-mode .b-neutral {
    background: repeating-linear-gradient(45deg, #ca8a04, #ca8a04 5px, #a16207 5px, #a16207 10px);
    color: #fff;
}

/* Badge urgente — hora en 0, carrera abierta */
.badge.b-urgente {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    color: #fff;
    animation: pulso-badge-rojo 0.8s ease-in-out infinite;
}

.badge.b-urgente-corta {
    background: linear-gradient(135deg, #f97316, #c2410c);
    color: #fff;
    animation: pulso-badge-naranja 1s ease-in-out infinite;
}

/* ── Píldora compacta RB (debajo del widget TVG en tabla) ───────── */
.rb-mini-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border-radius: 6px;
    padding: 3px 7px;
    margin-top: 5px;
    font-size: 10px;
    font-weight: 900;
    color: #fff;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.rb-pill-label {
    font-size: 9px;
    opacity: .9;
    letter-spacing: .3px;
    border-right: 1px solid rgba(255,255,255,.35);
    padding-right: 5px;
}
.rb-pill-status {
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .5px;
}

/* Badges Racebets Backup */
.badge.b-rb-link {
    background: linear-gradient(135deg, #f97316, #ea580c);
    color: #fff;
    border: 1px solid #fb923c;
    font-weight: 900;
    font-size: 10px;
    animation: none;
}
.badge.b-rb-backup {
    background: linear-gradient(135deg, #7c3aed, #5b21b6);
    color: #fff;
    border: 1px solid #a78bfa;
    font-weight: 900;
    font-size: 10px;
    animation: pulse-rb 1s infinite alternate;
}
@keyframes pulse-rb {
    from { box-shadow: 0 0 0 0 rgba(124,58,237,.5); }
    to   { box-shadow: 0 0 0 5px rgba(124,58,237,0); }
}
.badge.b-off-reciente {
    background: #64748b;
    color: #fff;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 4px;
    animation: pulso-gris 1.5s ease-in-out infinite;
}

.status-badge {
    font-size: 10px;
    font-weight: 900;
    color: var(--text-muted);
    padding: 3px 5px;
    border-radius: 6px;
    border: 1px solid var(--border);
    text-align: center;
}

/* ── Chips de Filtro de Países ──────────────────────────────────────────── */
.chip-pais {
    border: 1.5px solid var(--border);
    background: var(--panel-bg);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 20px;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    letter-spacing: .3px;
}

.chip-pais:hover {
    border-color: var(--blue);
    color: var(--blue);
    transform: translateY(-1px);
}

.chip-pais.chip-activo {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
    box-shadow: 0 2px 8px rgba(2,132,199,.35);
}

body.dark-mode .chip-pais.chip-activo {
    background: var(--blue);
    color: #fff;
}

/* ── Gráficos Circulares ────────────────────────────────────────────────── */
.circular-container { display: flex; align-items: center; gap: 8px; }
.circular-chart { display: block; width: 52px; height: 52px; min-width: 52px; }
.circle-bg { fill: none; stroke: var(--border); stroke-width: 3.5; }
.circle { fill: none; stroke-width: 3.5; stroke-linecap: round; transition: stroke-dasharray .5s ease-out; }
.percentage { fill: var(--text-main); font-size: 13px; font-weight: 900; text-anchor: middle; font-family: sans-serif; }
.mtp-label { fill: var(--text-muted); font-size: 7px; text-anchor: middle; font-family: sans-serif; }

.circ-green .circle { stroke: var(--green); }
.circ-orange .circle { stroke: var(--orange); animation: pulse 2s infinite; }
.circ-red .circle { stroke: var(--red); animation: pulse 1s infinite; }
.circ-gray .circle { stroke: var(--text-muted); }

/* ── Controles y Botones ────────────────────────────────────────────────── */
.ctrl-wrap { display: flex; flex-direction: column; align-items: center; gap: 5px; }

.btn-stream {
    background: #8b5cf6;
    color: #fff;
    border: none;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 900;
    font-size: 10px;
    width: 100%;
    transition: .15s;
}
.btn-stream:hover { filter: brightness(1.15); transform: translateY(-1px); }

.btn-time-group { display: flex; flex-direction: column; gap: 3px; }
.btn-row { display: flex; gap: 3px; }

.btn-t {
    border: none;
    padding: 4px 7px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 900;
    font-size: 9px;
    color: #fff;
    transition: .12s;
    box-shadow: 0 2px 5px rgba(0,0,0,.15);
}
.btn-t:hover:not(:disabled) { filter: brightness(1.18); transform: translateY(-1px); }
.btn-t:active { transform: translateY(1px) scale(.97); }
.btn-t.add { background: var(--blue); }
.btn-t.sub { background: var(--orange); }
.btn-t:disabled { opacity: .5; cursor: not-allowed; }

.btn-action-group { display: flex; gap: 4px; margin-top: 2px; }

.btn-action {
    display: flex;
    align-items: center;
    gap: 4px;
    border: none;
    padding: 7px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 900;
    font-size: 10px;
    color: #fff;
    transition: .15s;
    box-shadow: 0 3px 8px rgba(0,0,0,.2);
    white-space: nowrap;
}
.btn-action:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-2px); }
.btn-action:active { transform: translateY(1px) scale(.97); }
.btn-action:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-action.open { background: linear-gradient(135deg,#10b981,#059669); }
.btn-action.close { background: linear-gradient(135deg,#ef4444,#dc2626); }
.btn-action.auto { background: linear-gradient(135deg,#0284c7,#0369a1); }
.btn-action.confirm-ok { animation: flash-ok .5s ease; }
.btn-action.confirm-err { animation: flash-err .5s ease; }

/* Botón AUTO activo (control manual en curso) */
.btn-action.auto.auto-activo {
    background: linear-gradient(135deg, #f97316, #ea580c);
    animation: pulso-auto 1.2s ease-in-out infinite;
}

/* ── Panel de Video ─────────────────────────────────────────────────────── */
.video-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    border-radius: 12px;
    padding: 10px;
    border: 1px solid var(--border);
}

.grid { display: grid; gap: 10px; flex: 1; min-height: 0; }
.grid.items-2 { grid-template-columns: repeat(1,1fr); grid-template-rows: repeat(2,1fr); }
.grid.items-4 { grid-template-columns: repeat(2,1fr); grid-template-rows: repeat(2,1fr); }
.grid.items-6 { grid-template-columns: repeat(2,1fr); grid-template-rows: repeat(3,1fr); }

.video-slot {
    background: #000;
    border: 2px solid var(--blue);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.slot-header {
    background: var(--panel-bg);
    padding: 5px;
    display: flex;
    justify-content: center;
    border-bottom: 1px solid var(--border);
}

select {
    background: var(--panel-bg);
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 3px 7px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    outline: none;
    cursor: pointer;
    width: 100%;
}

iframe { flex: 1; border: none; width: 100%; background: #000; }

/* ── Panel de Configuración ─────────────────────────────────────────────── */
.config-panel {
    background: var(--light-blue);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 7px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.config-label { font-size: 11px; font-weight: 700; color: var(--blue); }

.config-input {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 12px;
    font-weight: bold;
    background: var(--panel-bg);
    color: var(--text-main);
    width: 50px;
    text-align: center;
}

.btn-cfg {
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 900;
    cursor: pointer;
}
.btn-cfg:hover { filter: brightness(1.1); }

/* ── Animaciones (Keyframes) ────────────────────────────────────────────── */
@keyframes pulse { 
    0%, 100% { opacity: 1; } 
    50% { opacity: .5; } 
}

@keyframes blink { 
    0%, 100% { opacity: 1; } 
    50% { opacity: .3; } 
}

@keyframes pulse-neutral { 
    0%, 100% { transform: scale(1); } 
    50% { transform: scale(1.08); } 
}

@keyframes flash-ok { 
    0%, 100% { filter: brightness(1); } 
    50% { filter: brightness(1.6) drop-shadow(0 0 8px #10b981); } 
}

@keyframes flash-err { 
    0%, 100% { filter: brightness(1); } 
    50% { filter: brightness(1.5) drop-shadow(0 0 8px #ef4444); } 
}

@keyframes pulso-auto {
    0%, 100% { box-shadow: 0 0 0 0 rgba(249,115,22,.7); filter: brightness(1); }
    50% { box-shadow: 0 0 0 7px rgba(249,115,22,.0); filter: brightness(1.25); }
}

@keyframes pulso-badge-rojo {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.8); transform: scale(1); }
    50% { box-shadow: 0 0 0 5px rgba(239,68,68,0); transform: scale(1.06); }
}

@keyframes pulso-badge-naranja {
    0%, 100% { box-shadow: 0 0 0 0 rgba(249,115,22,.8); transform: scale(1); }
    50% { box-shadow: 0 0 0 5px rgba(249,115,22,0); transform: scale(1.06); }
}

@keyframes pulso-gris {
    0%, 100% { opacity: 1; }
    50% { opacity: .5; }
}

/* ── Media Queries (Responsivo) ─────────────────────────────────────────── */
@media(max-width: 1024px) {
    body { 
        flex-direction: column; 
        overflow-y: auto; 
        height: auto; 
    }
    .panel-izquierdo { 
        width: 100%; 
        border-right: none; 
        border-bottom: 4px solid var(--blue); 
        min-height: 55vh; 
        flex: none; 
    }
    .panel-derecho { 
        width: 100%; 
        flex: none; 
    }
    .tabla-container { 
        overflow-x: auto; 
    }
    table { 
        min-width: 600px; 
    }
}

@media(max-width: 600px) {
    .header-section { 
        flex-direction: column; 
    }
    .btn-action .label { 
        display: none; 
    }
}