:root {
    /* ACTC/Racing Base Colors */
    --racing-red: #e10600;
    --racing-red-dark: #8b0000;
    --carbon-dark: #0B0E14;
    /* Más profundo, tono azul/gris oscuro */
    --carbon-light: #151a24;

    /* Timing Highlights */
    --timing-green: #00ff88;
    --timing-yellow: #ffd000;
    --timing-purple: #a855f7;
    --sector-blue: #00d4ff;

    /* Accents (Medals/Positions) */
    --accent-gold: #ffb300;
    --accent-silver: #c0c0c0;
    --accent-bronze: #cd7f32;

    /* Glassmorphism Surface Defaults */
    --glass-bg: rgba(21, 26, 36, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Rajdhani', sans-serif;
    background: var(--carbon-dark);
    color: #fff;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    -webkit-font-smoothing: antialiased;
}

/* Background Racing Pattern - Más estético y suave */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(255, 255, 255, 0.01) 2px, rgba(255, 255, 255, 0.01) 4px),
        repeating-linear-gradient(-45deg, transparent, transparent 2px, rgba(255, 255, 255, 0.01) 2px, rgba(255, 255, 255, 0.01) 4px),
        radial-gradient(ellipse at top right, rgba(225, 6, 0, 0.1), transparent 50%),
        radial-gradient(ellipse at bottom left, rgba(0, 212, 255, 0.05), transparent 50%);
    pointer-events: none;
    z-index: -1;
}

/* Decoración de Velocidad */
.speed-lines {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
    opacity: 0.05;
}

.speed-line {
    position: absolute;
    height: 1px;
    background: linear-gradient(90deg, transparent, #fff, transparent);
    animation: speed-move 3s cubic-bezier(0.25, 1, 0.5, 1) infinite;
}

@keyframes speed-move {
    0% {
        transform: translateX(-100%) scaleX(0);
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: translateX(100vw) scaleX(1.5);
        opacity: 0;
    }
}

/* --- HEADERS GLOBALES (Glassmorphism) --- */
.header {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 2px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5), inset 0 -1px 0 rgba(225, 6, 0, 0.3);
}

.header-top {
    background: linear-gradient(90deg, var(--racing-red-dark) 0%, var(--racing-red) 50%, var(--racing-red-dark) 100%);
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(225, 6, 0, 0.4);
}

.brand {
    font-family: 'Orbitron', sans-serif;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: #fff;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.4);
}

/* LIVE BADGE */
.live-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid rgba(0, 255, 136, 0.2);
    box-shadow: inset 0 0 10px rgba(0, 255, 136, 0.05);
}

.live-dot {
    width: 8px;
    height: 8px;
    background: var(--timing-green);
    border-radius: 50%;
    animation: pulse-live 1.5s ease-in-out infinite;
    box-shadow: 0 0 8px var(--timing-green);
}

@keyframes pulse-live {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

.live-text {
    font-family: 'Orbitron', sans-serif;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--timing-green);
}

/* HEADER MAIN / TITLE (común entre paginas) */
.header-main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.event-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.event-info h1 {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(16px, 3.5vw, 24px);
    font-weight: 800;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.event-info h2 {
    font-family: 'Rajdhani', sans-serif;
    font-size: clamp(12px, 2vw, 15px);
    color: #9aa0a6;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.event-groupname {
    display: inline-block;
    align-self: flex-start;
    font-family: 'Orbitron', sans-serif;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.5px;
    color: #fff;
    background: linear-gradient(135deg, var(--racing-red) 0%, var(--racing-red-dark) 100%);
    padding: 3px 10px;
    border-radius: 4px;
    margin-bottom: 6px;
    box-shadow: 0 2px 8px rgba(225, 6, 0, 0.4);
}

/* BOTONES GLOBALES */
.btn {
    padding: 10px 20px;
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    font-family: 'Orbitron', sans-serif;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Rebote suave */
    color: #fff;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:active {
    transform: scale(0.96);
}

.btn-outline {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

/* --- HOME PAGE LAYOUT --- */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    padding: 60px 20px;
    min-height: calc(100vh - 140px);
    /* Asegura que el contenido quede centrado verticalmente */
}

.title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(32px, 5vw, 42px);
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: 3px;
    text-align: center;
    color: #fff;
    text-shadow: 0 4px 15px rgba(225, 6, 0, 0.4);
}

.subtitle {
    font-size: clamp(14px, 3vw, 18px);
    color: #a0aec0;
    margin-bottom: 50px;
    text-align: center;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.buttons {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

.live-count {
    margin-top: 40px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 1px;
    text-align: center;
    font-family: 'Rajdhani', sans-serif;
    font-weight: 600;
}

.live-count.has-events {
    color: var(--timing-green);
    text-shadow: 0 0 10px rgba(0, 255, 136, 0.3);
}

/* HOME PAGE BIG BUTTONS */
.btn-big {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 250px;
    height: 160px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    text-decoration: none;
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
    color: #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.btn-live {
    background: linear-gradient(135deg, rgba(0, 255, 136, 0.1) 0%, rgba(0, 0, 0, 0.6) 100%);
    border-color: rgba(0, 255, 136, 0.3);
}

.btn-live:hover {
    background: linear-gradient(135deg, rgba(0, 255, 136, 0.2) 0%, rgba(0, 0, 0, 0.8) 100%);
    border-color: var(--timing-green);
    box-shadow: 0 10px 40px rgba(0, 255, 136, 0.2);
    transform: translateY(-4px);
}

.btn-results {
    background: linear-gradient(135deg, rgba(225, 6, 0, 0.1) 0%, rgba(0, 0, 0, 0.6) 100%);
    border-color: rgba(225, 6, 0, 0.3);
}

.btn-results:hover {
    background: linear-gradient(135deg, rgba(225, 6, 0, 0.2) 0%, rgba(0, 0, 0, 0.8) 100%);
    border-color: var(--racing-red);
    box-shadow: 0 10px 40px rgba(225, 6, 0, 0.2);
    transform: translateY(-4px);
}

.btn-icon {
    font-size: 40px;
    margin-bottom: 12px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}


/* --- TABLA LIVE TIMING (INDEX) --- */
.table-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 10px;
    padding-bottom: 70px;
    /* Compensa el footer fijo */
}

.table-wrapper {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    overflow-x: auto;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6);
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

th {
    background: rgba(15, 20, 28, 0.95);
    backdrop-filter: blur(8px);
    color: #8b929c;
    padding: 14px 10px;
    text-transform: uppercase;
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 10px;
    letter-spacing: 1px;
    white-space: nowrap;
    border-bottom: 2px solid rgba(225, 6, 0, 0.5);
    position: relative;
    /* Para el sticky en móviles */
}

td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    white-space: nowrap;
    font-weight: 600;
    color: #e2e8f0;
    background-color: transparent;
    /* Importante para el sticky */
    transition: background-color 0.2s;
}

tr:nth-child(even) td {
    background-color: rgba(255, 255, 255, 0.015);
}

tr:hover td {
    background-color: rgba(225, 6, 0, 0.08);
    /* Hover glow */
}

/* Celda de Posición (Móviles Sticky Left) */
.pos-cell {
    font-family: 'Orbitron', sans-serif;
    font-weight: 800;
    font-size: 14px;
    min-width: 40px;
}

tr:nth-child(1) .pos-cell {
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 179, 0, 0.4);
}

tr:nth-child(2) .pos-cell {
    color: var(--accent-silver);
    text-shadow: 0 0 10px rgba(192, 192, 192, 0.4);
}

tr:nth-child(3) .pos-cell {
    color: var(--accent-bronze);
    text-shadow: 0 0 10px rgba(205, 127, 50, 0.4);
}

.car-number {
    font-family: 'Orbitron', sans-serif;
    font-weight: 800;
    font-size: 14px;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    padding: 3px 8px;
    border-radius: 4px;
    border-left: 2px solid var(--racing-red);
}

.driver-name {
    text-align: left;
    font-weight: 700;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #fff;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.marca {
    font-size: 10px;
    color: #718096;
    font-weight: 700;
    text-transform: uppercase;
}

/* Typos Timing (Monospaced Share Tech o similar via Rajdhani nums) */
.timing {
    font-family: 'Orbitron', monospace;
    font-weight: 600;
    font-size: 12px;
    color: var(--timing-green);
    letter-spacing: 0.5px;
}

.timing-best {
    color: var(--timing-purple);
    font-weight: 800;
}

.gap {
    font-family: 'Orbitron', monospace;
    color: #cbd5e1;
    font-size: 11px;
}

.sector {
    font-family: 'Orbitron', monospace;
    color: var(--sector-blue);
    font-size: 11px;
}

.diff-positive {
    color: #fc8181;
}

.diff-negative {
    color: #68d391;
}

/* Sticky Columns para Mobile (POS, NUM, PILOTO) */
@media (max-width: 768px) {
    th:nth-child(1),
    td:nth-child(1),
    /* POS */
    th:nth-child(2),
    td:nth-child(2),
    /* NUM */
    th:nth-child(3),
    td:nth-child(3)

    /* PILOTO */
        {
        position: sticky;
        z-index: 5;
    }

    th:nth-child(1),
    td:nth-child(1) {
        left: 0;
    }

    th:nth-child(2),
    td:nth-child(2) {
        left: 40px;
    }

    /* Ajustar dependiendo del ancho num */
    th:nth-child(3),
    td:nth-child(3) {
        left: 80px;
        box-shadow: 4px 0 10px -2px rgba(0, 0, 0, 0.5);
        /* Sombra para marcar el scroll */
    }

    /* Fondos solidos para las celdas sticky y evitar que se vea el scroll por debajo */
    td:nth-child(1),
    td:nth-child(2),
    td:nth-child(3) {
        background-color: var(--carbon-light);
    }

    tr:nth-child(even) td:nth-child(1),
    tr:nth-child(even) td:nth-child(2),
    tr:nth-child(even) td:nth-child(3) {
        background-color: #1a202c;
    }
}


/* --- BANDERAS / FLAGS --- */
.flag-container {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.3);
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.flag-icon {
    width: 60px;
    height: 40px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
}

/* Efecto Brillo / Reflection sobre Bandera */
.flag-icon::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 40%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: flag-shine 3s infinite;
}

@keyframes flag-shine {
    0% {
        left: -100%;
    }

    20%,
    100% {
        left: 200%;
    }
}

.bandera-VERDE {
    background: linear-gradient(135deg, #00c853, #009624);
    border: 2px solid #00e676;
}

.bandera-AMARILLA {
    background: linear-gradient(135deg, #ffd600, #ffab00);
    border: 2px solid #ffff00;
    color: #000;
}

.bandera-ROJA {
    background: linear-gradient(135deg, #ff1744, #d50000);
    border: 2px solid #ff5252;
}

.bandera-A_CUADROS {
    background: repeating-conic-gradient(#111 0% 25%, #eee 0% 50%) 50% / 14px 14px;
    border: 2px solid #aaa;
}

.bandera-FIN_SESION,
.bandera-OTRA_6 {
    background: linear-gradient(135deg, #424242, #212121);
    border: 2px solid #757575;
}

.flag-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 12px;
    font-weight: 800;
    color: #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* BANNERS ESTADO (A Cuadros, Timeout) */
.status-banner {
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    color: #fff;
    padding: 12px;
    text-align: center;
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(12px, 3vw, 16px);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    border-top: 2px solid rgba(255, 255, 255, 0.1);
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.status-timeout {
    background: rgba(230, 81, 0, 0.8);
    border-color: #ff9800;
    color: #fff;
}


/* --- FOOTER STATUS BAR --- */
.status-bar {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--glass-border);
    padding: 10px 16px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

.status-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Orbitron', sans-serif;
    color: #fff;
    font-weight: 700;
    letter-spacing: 1px;
}

.sync-time {
    font-family: 'Orbitron', monospace;
    color: #a0aec0;
}

.results-btn-mini {
    background: linear-gradient(135deg, var(--racing-red) 0%, var(--racing-red-dark) 100%);
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    text-decoration: none;
    font-family: 'Orbitron', sans-serif;
    font-size: 10px;
    font-weight: 700;
    border: 1px solid #ff4d4d;
    transition: all 0.2s;
}

.results-btn-mini:hover {
    background: var(--racing-red);
    box-shadow: 0 0 15px rgba(225, 6, 0, 0.5);
    transform: translateY(-2px);
}

/* Modificadores Mobile de Elementos Frecuentes */
@media (max-width: 650px) {
    .header-main {
        padding: 10px;
        flex-direction: column;
        align-items: flex-start;
    }

    .flag-container {
        align-self: stretch;
        justify-content: space-between;
        margin-top: 5px;
    }

    table {
        font-size: 11px;
    }

    th {
        padding: 10px 6px;
        font-size: 9px;
    }

    td {
        padding: 10px 6px;
    }

    .driver-name {
        font-size: 10px;
        max-width: 100px;
    }

    .car-number {
        font-size: 11px;
        padding: 2px 4px;
    }

    .pos-cell {
        font-size: 12px;
        min-width: 30px;
    }

    .timing {
        font-size: 11px;
    }

    .sector,
    .gap {
        font-size: 10px;
    }

    .status-bar {
        flex-direction: column;
        gap: 8px;
        padding: 8px;
    }

    .status-left {
        justify-content: space-between;
        width: 100%;
    }

    .results-btn-mini {
        width: 100%;
        text-align: center;
        padding: 8px;
    }

    .scroll-indicator {
        display: block;
        text-align: center;
        padding: 6px;
        font-size: 10px;
        color: #a0aec0;
        animation: fade 2s infinite;
    }
}

/* --- HISTORIAL / RESULTADOS PAGE (Acordeones y Cards) --- */
.accordion {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.accordion-item {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    overflow: hidden;
}

.accordion-header {
    background: rgba(255, 255, 255, 0.03);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border-left: 4px solid var(--racing-red);
    transition: background 0.3s;
}

.accordion-header:hover,
.accordion-item.open .accordion-header {
    background: rgba(225, 6, 0, 0.1);
}

.accordion-header h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.count-badge {
    background: var(--racing-red);
    color: #fff;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

.accordion-item.open .accordion-content {
    max-height: 2000px;
    /* Suficiente para expandir */
}

.accordion-inner {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.result-card {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 16px;
    transition: border-color 0.2s, background 0.2s;
}

.result-card:hover {
    border-color: rgba(225, 6, 0, 0.5);
    background: rgba(225, 6, 0, 0.05);
}

.result-title {
    font-family: 'Rajdhani', sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
    line-height: 1.2;
}

.result-date {
    color: #a0aec0;
    font-size: 12px;
    margin-bottom: 12px;
}

.result-downloads {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.download-btn {
    flex: 1;
    text-align: center;
    padding: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    text-decoration: none;
    font-size: 11px;
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.download-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.download-btn.pdf {
    border-color: rgba(255, 107, 107, 0.3);
    color: #ff6b6b;
}

.download-btn.pdf:hover {
    background: rgba(255, 107, 107, 0.1);
    border-color: #ff6b6b;
}

.download-btn.excel {
    border-color: rgba(105, 240, 174, 0.3);
    color: #69f0ae;
}

.download-btn.excel:hover {
    background: rgba(105, 240, 174, 0.1);
    border-color: #69f0ae;
}

/* Animacion highlight para la tabla */
@keyframes row-highlight {
    0% {
        background: rgba(225, 6, 0, 0.4);
    }

    100% {
        background: transparent;
    }
}

.row-updated td {
    animation: row-highlight 1.5s ease-out;
}

/* Loading State (Spinner) */
.no-data {
    text-align: center;
    padding: 40px 10px;
    font-family: 'Orbitron', sans-serif;
    font-size: 12px;
    color: #718096;
}

.no-data::before {
    content: '⏳';
    display: block;
    font-size: 30px;
    margin-bottom: 10px;
    animation: spin 2s linear infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}