/* ==========================================================================
   1. VARIABLES & RESET & BASES
   ========================================================================== */
:root {
    /* Paleta Neon Dark */
    --bg-dark: #020617;
    --bg-card: rgba(30, 41, 59, 0.4); /* Efecto vidrio base */
    --border-color: rgba(255, 255, 255, 0.08);
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --primary: #6366f1; /* Indigo */
    --secondary: #ec4899; /* Rosa */
    --accent-gold: #fbbf24;
    --accent-red: #ef4444;
    --accent-green: #10b981;
    
    /* Sombras */
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --shadow-hover: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 10px rgba(99, 102, 241, 0.2);
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background: radial-gradient(circle at top right, #1e293b, #0f172a 60%, var(--bg-dark));
    color: var(--text-main);
    min-height: 100vh;
    margin: 0;
    line-height: 1.5;
    overflow-x: hidden; /* Evita scroll horizontal */
}

/* Scrollbar Global Personalizada */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

h1, h2, h3, h4, h5, h6 { color: #ffffff; margin-top: 0; }
a { text-decoration: none; color: inherit; }

/* ==========================================================================
   2. CONTENEDORES & TARJETAS GENERALES
   ========================================================================== */
.container {
    background: var(--bg-card) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glass);
    border-radius: 1rem;
    
    /* MODIFICACIÓN PARA PANTALLAS GRANDES */
    width: 96%;
    max-width: 1800px; 
    margin-left: auto;
    margin-right: auto;
    
    padding: 1.5rem;
    margin-bottom: 2rem;
    position: relative;
}

/* Tarjetas de Entidades (Federación/Comité) */
.card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
    min-height: 160px;
}
.card:hover {
    transform: translateY(-4px);
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: var(--shadow-hover);
}
.selectable-card { cursor: pointer; height: 100%; }
.selectable-card img { filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3)); transition: transform 0.3s ease; margin-bottom: 1rem; }
.selectable-card:hover img { transform: scale(1.1); }

/* ==========================================================================
   3. CONTENEDORES CON SCROLL (VIVO Y RECIENTES) - NUEVO
   ========================================================================== */
/* Aplicamos scroll y grid a las listas de partidos */
#live-matches-container,
#recent-results-container {
    /* Altura máxima para evitar página infinita */
    max-height: 500px; 
    overflow-y: auto;        /* Scroll vertical activado */
    overflow-x: hidden;
    
    /* Layout Grid Automático */
    display: grid;
    /* Las tarjetas tendrán mínimo 300px, si hay espacio caben más */
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
    align-content: start; /* Evita que se estiren verticalmente si son pocos */
    
    /* Estética del contenedor scrollable */
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    
    /* Scrollbar interna */
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

/* Ajuste específico para móvil */
@media (max-width: 640px) {
    #live-matches-container,
    #recent-results-container {
        grid-template-columns: 1fr; /* Una sola columna en celular */
        max-height: 60vh; /* Usamos porcentaje de pantalla en móvil */
    }
}

/* Estilos de la Scrollbar interna de estos contenedores */
#live-matches-container::-webkit-scrollbar,
#recent-results-container::-webkit-scrollbar {
    width: 6px;
}
#live-matches-container::-webkit-scrollbar-track,
#recent-results-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}
#live-matches-container::-webkit-scrollbar-thumb,
#recent-results-container::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

/* ==========================================================================
   4. ESTILOS DE CRUCES / BRACKETS
   ========================================================================== */

/* Contenedor Flex que permite centrado Y grilla */
.bracket-wrapper {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important; /* CENTRA las tarjetas si hay pocas (<4) */
    gap: 15px !important;
    width: 100%;
    padding: 10px;
}

/* --- TARJETA DE CRUCE (Diseño Unificado) --- */
.matchup-card {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.98));
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    position: relative;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.matchup-card:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.3);
}

/* --- TAMAÑOS RESPONSIVOS BRACKETS --- */

/* MÓVIL: Scroll Vertical para Brackets */
@media (max-width: 639px) {
    .matchup-card {
        width: 100% !important;
        margin-bottom: 8px;
    }
    
    .bracket-wrapper {
        display: block !important; 
        max-height: 65vh;          
        overflow-y: auto;          
        padding: 5px;
        background: rgba(0,0,0,0.2);
        border-radius: 12px;
        border: 1px solid rgba(255,255,255,0.05);
    }
}

/* TABLET: 2 por fila */
@media (min-width: 640px) and (max-width: 1023px) {
    .matchup-card { width: calc(50% - 15px) !important; }
}

/* PC ESTÁNDAR: 4 por fila */
@media (min-width: 1024px) and (max-width: 1535px) {
    .matchup-card {
        width: calc(25% - 15px) !important;
        min-width: 260px;
    }
}

/* MONITORES GRANDES (22"+): 5 por fila (MODIFICACIÓN PANTALLA GRANDE) */
@media (min-width: 1536px) {
    .matchup-card {
        width: calc(20% - 15px) !important;
        min-width: 260px;
    }
}

/* --- PARTES INTERNAS DE LA TARJETA --- */
.matchup-header {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem 0.5rem 0.5rem 2.5rem;
    display: flex; justify-content: space-between;
    font-size: 0.7rem; color: var(--text-muted);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.matchup-content {
    padding: 0.75rem;
    display: flex; flex-direction: column; gap: 0.6rem;
    flex-grow: 1;
}

.matchup-team {
    display: flex; align-items: center; padding: 0.35rem;
    border-radius: 6px; background: rgba(255,255,255,0.02);
    transition: background 0.2s;
}

.matchup-team img {
    width: 28px; height: 28px; object-fit: contain; margin-right: 0.6rem;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5));
}

.team-name {
    font-weight: 600; font-size: 0.85rem; color: var(--text-main);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}

/* Equipo Ganador */
.winner-text .team-name, .winner-text .font-bold {
    color: #4ade80 !important; font-weight: 800 !important;
    text-shadow: 0 0 8px rgba(74, 222, 128, 0.25);
}

/* ==========================================================================
   5. BADGES Y ELEMENTOS UI
   ========================================================================== */
.match-id-badge {
    position: absolute; top: 0; left: 0;
    background: #4f46e5; color: white;
    font-size: 10px; font-weight: 800; padding: 2px 10px;
    border-bottom-right-radius: 8px; z-index: 10;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.3); font-family: monospace;
}

.live-badge {
    position: absolute; top: 8px; right: 8px;
    background: rgba(0, 0, 0, 0.7); border: 1px solid rgba(239, 68, 68, 0.6);
    border-radius: 999px; padding: 2px 8px;
    font-size: 0.65rem; font-weight: bold; color: #ef4444;
    display: flex; align-items: center; gap: 5px;
    z-index: 20; box-shadow: 0 0 10px rgba(239, 68, 68, 0.2);
}
.live-dot {
    width: 6px; height: 6px; background-color: #ef4444;
    border-radius: 50%; animation: livePulse 1.5s infinite;
}
@keyframes livePulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

.stream-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px;
    font-size: 10px; text-decoration: none;
    transition: all 0.2s; background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1); color: #94a3b8;
}
.stream-btn:hover {
    background: rgba(255, 255, 255, 0.1); transform: translateY(-1px); color: white;
}

.penalties-score {
    font-size: 0.7rem; color: #94a3b8; margin-left: 6px; font-family: monospace;
}

/* ==========================================================================
   6. DETALLE DEL PARTIDO (Responsive & Tablas de Eventos)
   ========================================================================== */

/* Límite de altura GARANTIZADO para todas las tablas (Goles, Tarjetas, Faltas, Penales) */
/* El ":has(> table)" atrapa a CUALQUIER contenedor directo de una tabla sin importar su clase */
#match-details .overflow-x-auto,
#match-details div:has(> table) {
    max-height: 350px; 
    overflow-y: auto;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
    border-radius: 0.5rem;
}

/* Mantenemos los encabezados fijos al scrollear hacia abajo dentro de estas tablas */
#match-details div:has(> table) th {
    position: sticky;
    top: 0;
    z-index: 20;
    background-color: rgba(15, 23, 42, 0.95);
}

/* Scrollbar personalizada para las tablas del detalle de partido */
#match-details .overflow-x-auto::-webkit-scrollbar,
#match-details div:has(> table)::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
#match-details .overflow-x-auto::-webkit-scrollbar-track,
#match-details div:has(> table)::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}
#match-details .overflow-x-auto::-webkit-scrollbar-thumb,
#match-details div:has(> table)::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

@media (max-width: 640px) {
    #match-details .flex-col.md\:flex-row {
        flex-direction: row !important; flex-wrap: nowrap !important;
        align-items: flex-start !important; justify-content: center !important;
    }
    #match-score-details { font-size: 2.5rem !important; }
    #home-club-logo-details, #away-club-logo-details {
        width: 60px !important; height: 60px !important; padding: 5px !important;
    }
    #home-club-name-details, #away-club-name-details {
        font-size: 0.8rem !important; margin-top: 5px !important;
    }
}

/* ==========================================================================
   7. TABLAS, RESULTADOS Y UTILS
   ========================================================================== */
.responsive-table {
    width: 100%; overflow-x: auto;
    border-radius: 0.5rem; border: 1px solid var(--border-color);
    background: rgba(15, 23, 42, 0.6);
    /* Scroll vertical para listas de partidos de liga */
    max-height: 400px; overflow-y: auto; scrollbar-width: thin;
    /* Suaviza el desplazamiento táctil en celulares */
    -webkit-overflow-scrolling: touch; 
}

/* --- TABLA GLOBAL (RESTAURADA A SU DISEÑO ORIGINAL) --- */
table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0; 
    min-width: 100%; /* Vuelve a ocupar el espacio de su contenedor */
}

th, td { 
    padding: 0.75rem 1rem; /* Padding original relajado */
    border-bottom: 1px solid var(--border-color); 
}

th { background-color: rgba(15, 23, 42, 0.95); font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); position: sticky; top: 0; z-index: 10; }
td { color: var(--text-main); font-size: 0.875rem; }
tr:hover { background-color: rgba(255, 255, 255, 0.05); }

/* --- FIX: SÓLO APLICA A LA TABLA DE FECHAS/PARTIDOS --- */
/* Aislamos el truco del scroll para que solo afecte a las listas de partidos */
.responsive-table table { 
    min-width: 550px; 
}
.responsive-table th, .responsive-table td { 
    padding: 0.5rem 0.5rem; 
    white-space: nowrap; 
}

/* Tablas compactas (Goleadores, Tarjetas, Faltas) */
.stats-vertical-scroll {
    max-height: 350px; overflow-y: auto;
    border-radius: 0.5rem; background-color: rgba(31, 41, 55, 0.4);
}

/* --- FIX: PROTECCIÓN EXTRA PARA TABLAS COMPACTAS --- */
/* Forzamos que retomen su diseño original por si heredan la clase de partidos */
.stats-vertical-scroll table {
    min-width: 100% !important;
}
.stats-vertical-scroll th, .stats-vertical-scroll td {
    white-space: normal !important; 
    padding: 0.75rem 1rem !important; 
}

/* Sticky Columns para Posiciones */
.standings-scroll-wrapper {
    max-height: 450px; overflow: auto;
    border-radius: 0.5rem; background-color: #111827; position: relative;
}
.col-sticky-1 {
    position: sticky; left: 0; z-index: 30;
    background-color: #1e293b; border-right: 1px solid rgba(75, 85, 99, 0.4);
}
.col-sticky-2 {
    position: sticky; left: 40px; z-index: 30;
    background-color: #1e293b; border-right: 2px solid rgba(75, 85, 99, 0.5);
}
thead th.col-sticky-1, thead th.col-sticky-2 { z-index: 40; background-color: #0f172a; }

/* Utilidades */
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Contenedor Fases */
.bracket-phase-container {
    width: 100%; max-width: 1400px;
    display: flex; flex-direction: column; align-items: center;
    background: rgba(255, 255, 255, 0.01);
    border-radius: 16px; padding: 1rem 0; margin-bottom: 2rem;
}
.bracket-phase-container h3 {
    text-align: center; font-size: 1.3rem; color: var(--primary);
    margin-bottom: 1rem; text-transform: uppercase;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1); padding-bottom: 0.5rem; display: inline-block;
}

/* Match Card General (Listas) */
.match-card-content {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem; width: 100%; cursor: pointer; padding: 0.5rem;
    border-radius: 0.5rem; transition: background-color 0.2s;
}
.match-card-content:hover { background-color: rgba(255, 255, 255, 0.03); }
.match-card-team { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }
.match-card-team.home { justify-content: flex-start; }
.match-card-team.away { justify-content: flex-end; text-align: right; }
.team-name-small { font-size: 0.875rem; font-weight: 600; color: #f1f5f9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-display { font-family: 'Inter', monospace; font-size: 1.5rem; font-weight: 800; color: #ffffff; min-width: 60px; text-align: center; }

/* Badges de estado */
.badge { padding: 0.25rem 0.6rem; border-radius: 9999px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; }
.badge-live { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); border: 1px solid rgba(239, 68, 68, 0.3); animation: pulse-live 2s infinite; }
.badge-completed { background: rgba(16, 185, 129, 0.15); color: var(--accent-green); border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-scheduled { background: rgba(245, 158, 11, 0.15); color: var(--accent-gold); border: 1px solid rgba(245, 158, 11, 0.3); }

/* Login Button */
.login-btn-glass {
    background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.5rem 1.25rem; border-radius: 9999px; color: white; font-weight: 600; transition: 0.3s;
}
.login-btn-glass:hover { background: var(--primary); border-color: transparent; }

/* Toast */
#messageBox {
    position: fixed; bottom: 20px; right: 20px; padding: 1rem 1.5rem; border-radius: 0.5rem;
    color: white; font-weight: 500; z-index: 2000; opacity: 0; visibility: hidden; transform: translateY(20px); transition: 0.3s;
}
#messageBox.show { opacity: 1; visibility: visible; transform: translateY(0); }
#messageBox.success { background-color: var(--accent-green); }
#messageBox.error { background-color: var(--accent-red); }

/* ==========================================================================
   AJUSTE PARA MONITORES GRANDES (22 PULGADAS O MÁS)
   ========================================================================== */

/* Limita el ancho del panel principal y lo centra */
.main-content {
    max-width: 1152px; 
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

/* Agrupa los botones de eventos para que no queden tan separados */
.event-buttons-row {
    max-width: 896px; 
    margin-left: auto;
    margin-right: auto;
    justify-content: center; 
}

/* ==========================================================================
   8. ALERTA FLOTANTE (NO STREAM TOAST)
   ========================================================================== */
.no-stream-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glass);
    color: var(--text-main);
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none; /* Evita clics accidentales en el cartel */
}

/* Estado activo del toast */
.no-stream-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.no-stream-toast i {
    color: var(--accent-red);
    font-size: 1.25rem;
}

.no-stream-toast span {
    font-weight: 500;
    font-size: 0.95rem;
}