/* ==========================================================================
   Kinetic Seven - SportsPress Compatibility Styles (REVISION 2)
   Fix for table layouts, text colors, zebras, and single match layout
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Global Overrides (Link Colors & Backgrounds)
   -------------------------------------------------------------------------- */
/* Reset any blue link styling to use theme colors */
.sportspress a,
.sportspress a:link,
.sportspress a:visited,
.sp-template a,
.sp-template a:link,
.sp-template a:visited {
    color: var(--k-text-primary, #ffffff) !important;
    text-decoration: none !important;
    transition: color 0.3s ease;
}

.sportspress a:hover,
.sp-template a:hover {
    color: var(--k-primary, #e62117) !important;
}

/* --------------------------------------------------------------------------
   1. Tables Base (League Tables, Player Stats, Event Lists)
   -------------------------------------------------------------------------- */
.sportspress table,
.sp-template table {
    width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    background: var(--k-surface-0, #0a0a0a) !important;
    table-layout: auto !important;
    border-radius: 0;
    overflow: hidden;
    margin-bottom: 20px;
}

/* Cell padding & vertical align */
.sportspress td,
.sportspress th {
    padding: 14px 10px !important;
    vertical-align: middle !important;
    text-align: center !important;
    border-bottom: 1px solid var(--k-surface-3, #2a2a2a) !important;
}

/* Left align just the names */
.sportspress th.data-name,
.sportspress td.data-name {
    text-align: left !important;
}

/* Headers style */
.sportspress h4,
.sp-template h4,
.sportspress .sp-table-caption,
.sp-template .sp-table-caption {
    text-align: center !important;
    text-transform: uppercase;
    font-family: var(--k-font-display, 'Space Grotesk', sans-serif);
    margin-bottom: 15px;
    width: 100%;
    display: block;
}

.sportspress th,
.sp-template th {
    background-color: var(--k-primary, #990000) !important;
    color: #ffffff !important;
    font-family: var(--k-font-display, 'Space Grotesk', sans-serif) !important;
    font-size: 0.95rem !important;
    text-transform: uppercase;
    font-weight: 800 !important;
    letter-spacing: 0.05em;
    border: none !important;
    text-align: center !important;
}

/* Permitir centrado en incidencias */
.sportspress table.sp-event-performance th.data-name,
.sportspress table.sp-event-performance th.data-name * {
    text-align: center !important;
}

/* Zebra Stripes (Pares e Impares) para TODO tipo de tabla SP */
.sportspress tbody tr:nth-child(odd) td,
.sportspress tbody tr.odd td,
.sp-template tbody tr:nth-child(odd) td {
    background-color: rgba(255, 255, 255, 0.03) !important;
}

.sportspress tbody tr:nth-child(even) td,
.sportspress tbody tr.even td,
.sp-template tbody tr:nth-child(even) td {
    background-color: transparent !important;
}

/* Fila Destacada (Ej. Equipo propio o jugador en listas) */
.sportspress tbody tr.sp-highlight td,
.sp-template tbody tr.sp-highlight td {
    background-color: rgba(230, 33, 23, 0.15) !important;
}
.sportspress tbody tr.sp-highlight td a,
.sportspress tbody tr.sp-highlight td {
    color: var(--k-kinetic-pink, #ffb4a8) !important;
    font-weight: 800 !important;
}

/* Highlight specific columns like Points */
.sportspress td.data-pts {
    font-weight: 900 !important;
    color: var(--k-kinetic-pink, #ffb4a8) !important;
    font-size: 1.1rem !important;
}

.sportspress time,
.sportspress .sp-result {
    font-family: var(--k-font-display, 'Epilogue', sans-serif);
    font-weight: 800;
}

/* --------------------------------------------------------------------------
   2. Event Blocks (Non-table match cards)
   -------------------------------------------------------------------------- */
.sp-template-event-blocks .sp-event-block {
    display: flex;
    flex-direction: column;
    padding: 20px !important;
    border-radius: 0;
    margin-bottom: 15px;
    background-color: var(--k-surface-2, #1c1b1b) !important;
    border: 1px solid var(--k-surface-3, #2a2a2a) !important;
    border-left: 4px solid var(--k-surface-3, #2a2a2a) !important;
    transition: all 0.3s ease;
}

/* Zebra para bloques pares/impares si no son tablas */
.sp-template-event-blocks .sp-event-block:nth-child(odd),
.sp-template-event-blocks .sp-event-block:nth-child(even) {
    background-color: var(--k-surface-2, #1c1b1b) !important;
}

.sp-template-event-blocks .sp-event-block:hover {
    border-left-color: var(--k-primary, #e62117) !important;
    background-color: var(--k-surface-3, #2a2a2a) !important;
}

/* Time & Result in small blocks */
.sp-template-event-blocks time,
.sp-event-blocks .sp-result {
    color: var(--k-kinetic-pink, #ffb4a8) !important;
    font-size: 1.2rem;
}

/* --------------------------------------------------------------------------
   2.1 New Custom Event Block Layout (Option B)
   -------------------------------------------------------------------------- */
.sp-template-event-blocks .sp-k-event-meta {
    text-align: center;
    font-family: var(--k-font-display, 'Space Grotesk', sans-serif);
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px dashed var(--k-surface-3, #2a2a2a);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sp-template-event-blocks .sp-k-event-meta span,
.sp-template-event-blocks .sp-k-event-meta time,
.sp-template-event-blocks .sp-k-event-meta a {
    display: inline-flex !important;
    font-size: 0.65rem !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    font-weight: 500 !important;
}

.sp-template-event-blocks .sp-k-event-meta [style*="display:none"],
.sp-template-event-blocks .sp-k-event-meta [style*="display: none"] {
    display: none !important;
}

.sp-template-event-blocks .sp-k-event-meta a {
    color: rgba(255, 255, 255, 0.5) !important;
    transition: color 0.3s ease;
}

.sp-template-event-blocks .sp-k-event-meta a:hover {
    color: #ffffff !important;
}

.sp-template-event-blocks .sp-k-event-meta .sp-meta-sep {
    color: var(--k-surface-3, #2a2a2a);
    font-size: 0.7rem;
}

.sp-template-event-blocks .sp-k-event-matchup {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.sp-template-event-blocks .sp-k-team {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 15px;
}

.sp-template-event-blocks .sp-k-team-home {
    justify-content: flex-end;
    text-align: right;
}

.sp-template-event-blocks .sp-k-team-away {
    justify-content: flex-start;
    text-align: left;
}

.sp-template-event-blocks .sp-k-team .sp-team-name {
    font-family: var(--k-font-display, 'Space Grotesk', sans-serif);
    font-size: 1.3rem;
    font-weight: 800;
    color: #ffffff;
    line-height: 1.2;
}

.sp-template-event-blocks .sp-k-team img {
    max-width: 60px !important;
    height: auto !important;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
    margin: 0 !important;
}

.sp-template-event-blocks .sp-k-result {
    padding: 0 25px;
    flex: 0 0 auto;
    text-align: center;
}

.sp-template-event-blocks .sp-k-result h5.sp-event-results {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1;
}

/* Make entire event card clickable */
.sp-template-event-blocks .sp-post td {
    position: relative;
    transition: transform 0.3s ease, background 0.3s ease;
}

.sp-template-event-blocks .sp-post td:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
}

.sp-template-event-blocks .sp-event-results a::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
}

.sp-template-event-blocks .sp-k-team a,
.sp-template-event-blocks .sp-k-event-meta a {
    position: relative;
    z-index: 2;
}

.sp-template-event-blocks .sp-k-result .sp-result {
    font-size: 1.8rem;
    font-weight: 900;
    color: #ffffff !important;
    background: var(--k-primary, #e62117) !important;
    padding: 6px 15px !important;
    border-radius: 0;
}

/* Mobile responsive for custom blocks */
@media screen and (max-width: 768px) {
    .sp-template-event-blocks .sp-k-event-matchup {
        flex-direction: column;
        gap: 15px;
    }
    
    .sp-template-event-blocks .sp-k-team {
        width: 100%;
        justify-content: center !important;
        flex-direction: column;
        text-align: center !important;
        gap: 8px;
    }
    
    .sp-template-event-blocks .sp-k-team-home {
        flex-direction: column-reverse; /* Logo Arriba, Nombre Abajo para el equipo local */
    }
    
    .sp-template-event-blocks .sp-k-team .sp-team-name {
        font-size: 1.1rem;
    }
    
    .sp-template-event-blocks .sp-k-result {
        padding: 5px 0;
    }

    .sp-template-event-blocks .sp-k-result .sp-result {
        font-size: 1.4rem;
        padding: 4px 12px !important;
    }

    .sp-template-event-blocks .sp-k-event-meta {
        margin-top: 10px;
        padding-top: 10px;
        gap: 4px 8px;
    }
}

/* --------------------------------------------------------------------------
   3. Single Match / Event - Hero Banner (El problema del detalle cortado)
   -------------------------------------------------------------------------- */
/* Reset the specific event logos table to Flexbox to act as a proper Hero */
.sportspress table.sp-event-logos {
    display: block !important;
    width: 100% !important;
    background: var(--k-surface-2, #1c1b1b) !important;
    padding: 40px 20px !important;
    border-radius: 0;
    border: 1px solid var(--k-surface-3, #2a2a2a) !important;
    border-top: 5px solid var(--k-primary, #990000) !important;
    margin: 20px auto 40px auto !important;
    box-sizing: border-box;
}

.sportspress table.sp-event-logos tbody {
    display: block !important;
    width: 100% !important;
}

.sportspress table.sp-event-logos tr {
    display: flex !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: stretch !important;
    width: 100% !important;
    flex-wrap: nowrap !important;
}

/* 3 Equal columns for: Logo 1 | Result | Logo 2 */
.sportspress table.sp-event-logos td {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    width: 33.33% !important;
    border: none !important;
    padding: 0 10px !important;
    background: transparent !important;
    white-space: normal !important;
}

/* Result box in the middle */
.sportspress table.sp-event-logos td.sp-event-results {
    width: 33.33% !important;
    color: #ffffff !important; /* Force all text to white */
}

.sportspress table.sp-event-logos td.sp-event-results .sp-result,
.sportspress table.sp-event-logos td.sp-event-results h5.sp-result {
    display: inline-block !important;
    font-size: 3rem !important;
    font-weight: 900 !important;
    color: var(--k-surface-1, #131313) !important;
    background: var(--k-kinetic-pink, #ffb4a8) !important;
    padding: 10px 30px !important;
    border-radius: 0 !important;
    line-height: 1 !important;
    margin-bottom: 15px !important;
    margin-top: 15px !important;
}

.sportspress table.sp-event-logos td.sp-event-results time,
.sportspress table.sp-event-logos td.sp-event-results a {
    font-size: 1.1rem !important;
    color: #ffffff !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    display: block !important;
    margin-top: 5px;
}

/* Team Logos & Names */
.sportspress table.sp-event-logos img {
    max-width: 120px !important;
    height: auto !important;
    filter: drop-shadow(0px 8px 16px rgba(0,0,0,0.5)) !important;
    margin-bottom: 10px !important;
}

.sportspress table.sp-event-logos td.sp-event-logo a,
.sportspress table.sp-event-logos td.sp-event-logo > a {
    font-family: var(--k-font-display, 'Space Grotesk', sans-serif) !important;
    font-size: 1.6rem !important;
    font-weight: 900 !important;
    text-transform: uppercase !important;
    color: #ffffff !important;
    text-align: center !important;
    word-break: break-word !important;
    white-space: normal !important;
    line-height: 1.2 !important;
    display: block !important; /* Ensure it behaves smoothly if it is wrapped in breaks */
}

/* --------------------------------------------------------------------------
   4. Force Framework Layout Container (Content Centering)
   -------------------------------------------------------------------------- */
#k-app-wrapper.k-elementor-fw-grid #k-main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
}

/* Media Query for Mobile Hero Match */
@media screen and (max-width: 768px) {
    .sportspress table.sp-event-logos tr {
        flex-direction: column !important;
        gap: 30px !important;
    }
    
    .sportspress table.sp-event-logos td {
        width: 100% !important;
    }

    .sportspress table.sp-event-logos td.sp-event-results {
        order: -1 !important; /* Move result/time to top on mobile */
    }
}

/* ==========================================================================
   5. SINGLE MATCH BRUTALIST OVERRIDES (FORCING ALL TEMPLATES)
   ========================================================================== */
.single-sp_event .sp-template-event-logos table,
.single-sp_event .sp-template-event-details,
.single-sp_event .sp-template-event-blocks .sp-event-block,
.single-sp_event .sp-event-blocks {
    background: var(--k-surface-2, #1c1b1b) !important;
    border: 1px solid var(--k-surface-3, #2a2a2a) !important;
    border-top: 5px solid var(--k-primary, #990000) !important;
    border-radius: 0 !important;
}

/* Forzar color blanco a la fecha, links y cualquier texto del header */
.single-sp_event .sp-event-results time,
.single-sp_event .sp-event-results a,
.single-sp_event .sp-event-details time,
.single-sp_event .sp-event-block time,
.single-sp_event .sp-event-block a,
.single-sp_event .sp-event-date time {
    color: #ffffff !important;
    font-family: var(--k-font-display, 'Space Grotesk', sans-serif) !important;
    text-transform: uppercase !important;
    font-weight: 700 !important;
}

/* Nombres de los clubes en header: Uppercase & 900 weight */
.single-sp_event .sp-event-logo a,
.single-sp_event .sp-event-logo > a,
.single-sp_event h4.sp-event-title a,
.single-sp_event .sp-team-name a {
    font-family: var(--k-font-display, 'Space Grotesk', sans-serif) !important;
    font-size: 1.6rem !important;
    font-weight: 900 !important;
    text-transform: uppercase !important;
    color: #ffffff !important;
    text-align: center !important;
}

/* Hacer que el resultado principal resalte con el color Pink */
.single-sp_event .sp-result,
.single-sp_event h5.sp-result,
.single-sp_event .sp-event-results .sp-result {
    display: inline-block !important;
    font-size: 3rem !important;
    font-weight: 900 !important;
    color: var(--k-surface-1, #131313) !important;
    background: var(--k-kinetic-pink, #ffb4a8) !important;
    padding: 10px 30px !important;
    border-radius: 0 !important;
    line-height: 1 !important;
}

/* Centrar nombres de los clubes en encabezados de tabla (incidencias) */
.single-sp_event table.sp-event-performance th,
.single-sp_event table.sp-event-performance th.data-name {
    text-align: center !important;
}

/* Centrar títulos faltantes (h3, h4, caption) en todas estas secciones */
.single-sp_event .sp-template h3,
.single-sp_event .sp-template h4,
.single-sp_event h4,
.single-sp_event h4.sp-table-caption,
.single-sp_event h3.sp-table-caption {
    text-align: center !important;
    text-transform: uppercase;
    font-family: var(--k-font-display, 'Space Grotesk', sans-serif) !important;
    width: 100% !important;
    display: block !important;
    margin-bottom: 20px !important;
}

/* Recuadro sutil para las Incidencias y listas inferiores */
.single-sp_event .sp-template-event-performance,
.single-sp_event .sp-template-event-timeline,
.single-sp_event .sp-template-event-lists {
    background: var(--k-surface-1, #131313) !important;
    border: 1px solid var(--k-surface-3, #2a2a2a) !important;
    padding: 25px !important;
    margin-bottom: 30px !important;
}

/* ==========================================================================
   6. MOBILE VIEW OPTIMIZATIONS (No-scroll, Centered Layout)
   ========================================================================== */
@media screen and (max-width: 768px) {
    /* 1. Prevent Horizontal Scroll Systematically */
    body, html, .sportspress, .sp-template {
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* 2. Tables Base Scaling - Reduce widths, paddings, and font sizes */
    .sportspress table,
    .sp-template table {
        width: 100% !important;
        table-layout: auto !important;
        word-break: break-word !important; /* Wrap long team / player names */
    }

    /* Extreme padding reduction to fit 7-8 columns (GD, Pts, etc.) */
    .sportspress th,
    .sp-template th {
        font-size: 0.65rem !important; /* Smaller header text */
        padding: 6px 2px !important;
        letter-spacing: 0 !important;
        white-space: nowrap !important; /* Keep headers on one line */
    }

    .sportspress td,
    .sp-template td {
        font-size: 0.75rem !important;
        padding: 8px 4px !important;
        white-space: nowrap !important; /* Keep numbers on one line */
        word-break: normal !important;
    }

    /* Allow only the name column to wrap and take up space */
    .sportspress td.data-name,
    .sp-template td.data-name,
    .sportspress th.data-name,
    .sp-template th.data-name {
        white-space: normal !important;
        word-break: break-word !important;
        width: 100%; /* Force it to take maximum available space */
    }

    /* 3. Club column: hide text names, show only crests, left-aligned (ONLY for League Tables) */
    .sp-template-league-table th.data-name {
        text-align: left !important;
    }

    .sp-template-league-table td.data-name {
        text-align: left !important;
        font-size: 0 !important;       /* Hides the bare text-node (team name) */
        line-height: 0 !important;      /* Collapse any residual line-height */
    }

    /* Keep logo visible at proper size */
    .sp-template-league-table td.data-name .team-logo {
        font-size: 1rem !important;     /* Restore font context for children */
        line-height: normal !important;
        display: inline-block !important;
        vertical-align: middle !important;
    }

    /* 4. Adjust Logos Inside Tables */
    .sportspress td.data-name img,
    .sp-template td.data-name img {
        display: inline-block !important;
        margin: 0 !important;
        max-width: 24px !important;     /* Compact size for mobile */
        height: auto !important;
        vertical-align: middle !important;
    }

    /* Hide any anchor-wrapped team name text too (ONLY for League Tables) */
    .sp-template-league-table td.data-name > a {
        font-size: 0 !important;
        line-height: 0 !important;
    }

    .sp-template-league-table td.data-name > a .team-logo {
        font-size: 1rem !important;
        line-height: normal !important;
    }

    /* 4.5 Restore player names in single event boxscores */
    .sportspress table.sp-event-performance td.data-name,
    .sp-template table.sp-event-performance td.data-name,
    .sportspress table.sp-event-performance td.data-name > a,
    .sp-template table.sp-event-performance td.data-name > a {
        font-size: 0.75rem !important;
        line-height: normal !important;
    }

    /* 5. Emphasize Points slightly but keep sizes manageable */
    .sportspress td.data-pts {
        font-size: 0.85rem !important;
    }

    /* 6. Reduce rank/position column space */
    .sportspress th.data-rank,
    .sportspress td.data-rank {
        padding: 8px 1px !important;
        font-size: 0.7rem !important;
        width: 1% !important; /* Forces it to be as small as possible */
    }
}
