
:root {
    --bg: #0b111a;
    --surface: #121d2a;
    --surface2: #192737;
    --border: #26384a;
    --text: #f2f6fa;
    --muted: #8495a8;
    --green: #45d6a0;
    --orange: #ff9d42;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
}

.app {
    max-width: 1800px;
    margin: auto;
    padding: 0 35px;
}

.topbar {
    height: 82px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
}

.brand-icon {
    width: 45px;
    height: 45px;
    display: grid;
    place-items: center;
    background: var(--green);
    color: #07130f;
    font-weight: 900;
    font-size: 18px;
    transform: skew(-8deg);
}

.brand-name {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 26px;
    font-weight: 900;
    letter-spacing: 1px;
}

.brand-sub {
    color: var(--green);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 3px;
}

.live-status {
    background: #15382f;
    color: var(--green);
    padding: 9px 15px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1px;
}

.live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    background: var(--green);
    border-radius: 50%;
    margin-right: 7px;
    box-shadow: 0 0 10px var(--green);
}

.competition {
    min-height: 190px;
    margin-top: 25px;
    padding: 35px;
    background: linear-gradient(90deg, #172838, #12202d 65%, #101a25);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.competition::after {
    content: "";
    position: absolute;
    width: 350px;
    height: 350px;
    right: 100px;
    top: -180px;
    border: 1px solid #ffffff0c;
    border-radius: 50%;
    box-shadow: 0 0 0 35px #ffffff05, 0 0 0 70px #ffffff04;
}

.eyebrow, .section-kicker {
    color: var(--green);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 2px;
}

h1, h2, h3 {
    font-family: 'Barlow Condensed', sans-serif;
    margin: 8px 0;
    font-weight: 800;
}

h1 {
    font-size: clamp(35px, 5vw, 55px);
    letter-spacing: 1px;
}

h1 span {
    color: var(--green);
}

.competition p {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 2px;
}

/* MARCA RALLY */
.competition-mark {
    color: #ffffff25;
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 27px;
    font-weight: 800;
    line-height: .85;
    text-align: right;
    transform: skew(-8deg);
}

.competition-mark strong {
    color: var(--green);
    font-size: 55px;
}

/* TARJETAS DE ESTADÍSTICAS */
.stats {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 15px;
    margin: 20px 0 35px;
}

.stat-card {
    min-width: 0;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 35px;
    overflow-wrap: anywhere;
}

.refresh-value {
    color: var(--green);
}

/* ETAPAS */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 20px;
    margin-bottom: 20px;
}

h2 {
    font-size: 32px;
}

.stage-buttons {
    display: flex;
    gap: 9px;
}

.stage-btn {
    min-width: 125px;
    padding: 13px 22px;
    background: var(--surface2);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 1px;
    cursor: pointer;
    transition: .2s;
}

.stage-btn:hover {
    border-color: var(--green);
    color: var(--text);
}

.stage-btn.active {
    color: #07130f;
    background: var(--green);
    border-color: var(--green);
    box-shadow: 0 4px 18px #45d6a025;
}

/* PESTAÑAS */
.tabs {
    display: flex;
    gap: 5px;
    border-bottom: 1px solid var(--border);
}

.tab {
    background: transparent;
    color: var(--muted);
    border: 0;
    padding: 16px 22px;
    font-weight: 800;
    font-size: 11px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: var(--green);
    border-bottom-color: var(--green);
}

/* PANELES */
.content-panel {
    margin-top: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.hidden {
    display: none;
}

.panel-heading {
    padding: 22px 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

h3 {
    font-size: 24px;
}

.updated {
    color: var(--green);
    font-size: 10px;
    font-weight: 800;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 0 25px 17px;
    color: var(--muted);
    font-size: 10px;
}

.legend-time {
    color: var(--text);
}

.legend-penalty {
    color: var(--orange);
}

/* TABLAS */
.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

thead {
    background: var(--surface2);
}

th {
    color: var(--muted);
    text-align: left;
    font-size: 10px;
    padding: 15px;
    letter-spacing: 1px;
}

td {
    padding: 13px 15px;
    border-top: 1px solid var(--border);
    font-size: 12px;
}

tbody tr:hover {
    background: #ffffff05;
}

.timing-table {
    min-width: 1050px;
}

.timing-table th,
.timing-table td {
    text-align: center;
}

.timing-table th:nth-child(3),
.timing-table td:nth-child(3) {
    text-align: left;
}

.pe-cell {
    min-width: 95px;
}

.pe-time {
    display: block;
    color: var(--text);
    font-weight: 800;
    font-size: 12px;
}

.pe-penalty {
    display: block;
    margin-top: 5px;
    color: var(--orange);
    font-size: 10px;
    font-weight: 800;
}

.pe-no-penalty {
    color: #607184;
}

.position {
    color: var(--green);
    font-weight: 900;
}

.car-number {
    font-weight: 900;
    font-size: 14px;
}

.total-cell {
    color: var(--green);
    font-weight: 900;
    font-size: 13px;
}

.difference-cell {
    color: var(--muted);
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 35px;
}

/* HISTORIAL */
.history-list {
    padding: 25px;
    color: var(--muted);
}

/* PIE */
footer {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    padding: 30px 0;
    margin-top: 20px;
    color: var(--muted);
    font-size: 9px;
    letter-spacing: 1px;
    border-top: 1px solid var(--border);
}

footer strong {
    color: var(--green);
}

/* TABLETS Y CELULARES */
@media (max-width: 1100px) {
    .stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 800px) {
    .app {
        padding: 0 15px;
    }

    .competition {
        padding: 22px;
    }

    .competition-mark {
        display: none;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-card strong {
        font-size: 30px;
    }

    .toolbar {
        align-items: start;
        flex-direction: column;
    }

    .stage-buttons {
        width: 100%;
        gap: 6px;
    }

    .stage-btn {
        min-width: 0;
        flex: 1;
        padding: 12px 5px;
        font-size: 10px;
    }

    .tabs {
        overflow-x: auto;
    }

    .tab {
        white-space: nowrap;
        padding: 15px;
    }

    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    footer {
        flex-direction: column;
    }
}

@media (max-width: 400px) {
    .app {
        padding: 0 10px;
    }

    .stats {
        grid-template-columns: 1fr 1fr;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-card span {
        font-size: 9px;
    }

    .stat-card strong {
        font-size: 27px;
    }
}


/* IDENTIDAD Y CLASIFICACION MOVIL */
.by-maiky {
    margin-left: auto;
    color: var(--green);
    font-weight: 800;
    letter-spacing: 1px;
    text-align: right;
}

.copilot-name {
    color: var(--muted);
}

@media (max-width: 800px) {
    .topbar {
        height: auto;
        min-height: 72px;
        padding: 12px 0;
        gap: 10px;
    }

    .brand-icon {
        width: 40px;
        height: 40px;
        flex-shrink: 0;
    }

    .brand-name {
        font-size: 23px;
    }

    .brand-sub {
        font-size: 9px;
        letter-spacing: 2px;
    }

    .live-status {
        padding: 8px 10px;
        font-size: 9px;
        white-space: nowrap;
    }

    .competition {
        min-height: 145px;
        margin-top: 15px;
        padding: 20px;
    }

    .competition h1 {
        font-size: clamp(32px, 9vw, 46px);
    }

    .competition p {
        line-height: 1.5;
        letter-spacing: 1px;
    }

    .content-panel {
        border-radius: 10px;
    }

    .table-wrap {
        overflow: visible;
        padding: 0 10px 12px;
    }

    .timing-table {
        min-width: 0;
        width: 100%;
        display: block;
        white-space: normal;
    }

    .timing-table thead {
        display: none;
    }

    .timing-table tbody {
        display: grid;
        gap: 12px;
    }

    .timing-table tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0 10px;
        padding: 12px;
        background: var(--surface2);
        border: 1px solid var(--border);
        border-radius: 9px;
    }

    .timing-table tbody td {
        min-width: 0;
        padding: 10px 5px;
        border-top: 1px solid var(--border);
        text-align: left !important;
        font-size: 12px;
        overflow-wrap: anywhere;
    }

    .timing-table tbody td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 5px;
        color: var(--muted);
        font-size: 9px;
        font-weight: 800;
        letter-spacing: 1px;
    }

    .timing-table tbody td.position,
    .timing-table tbody td.car-number {
        border-top: 0;
        font-size: 18px;
    }

    .timing-table tbody td.position {
        color: var(--green);
    }

    .timing-table tbody td.crew-cell {
        grid-column: 1 / -1;
        font-size: 14px;
        line-height: 1.6;
    }

    .timing-table tbody td.pe-cell {
        background: #0b111a;
        border-radius: 5px;
        margin-top: 5px;
        padding: 10px 8px;
    }

    .timing-table .pe-time {
        font-size: 13px;
    }

    .timing-table .pe-penalty {
        font-size: 11px;
    }

    .timing-table tbody td.total-cell,
    .timing-table tbody td.difference-cell {
        margin-top: 8px;
        padding-top: 12px;
    }

    .timing-table tbody td.total-cell {
        color: var(--green);
        font-size: 15px;
    }

    .by-maiky {
        text-align: right;
        margin-left: 0;
    }

    footer {
        flex-direction: column;
        gap: 10px;
    }
}

@media (max-width: 400px) {
    .live-status {
        font-size: 8px;
        padding: 7px;
    }

    .timing-table tbody tr {
        padding: 9px;
        gap: 0 6px;
    }
}

/* TARJETAS DE CLASIFICACION PARA CELULARES */
.mobile-card-cell {
    display: none;
}

@media (max-width: 800px) {
    .timing-table tbody tr.crew-row {
        display: block;
        padding: 0;
        margin-bottom: 12px;
        background: transparent;
        border: 0;
    }

    .timing-table tbody tr.crew-row > td:not(.mobile-card-cell) {
        display: none;
    }

    .timing-table tbody tr.crew-row > td.mobile-card-cell {
        display: block;
        padding: 0;
        border: 0;
    }

    .mobile-crew-card {
        padding: 15px;
        background: var(--surface2);
        border: 1px solid var(--border);
        border-radius: 10px;
    }

    .mobile-card-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding-bottom: 11px;
        border-bottom: 1px solid var(--border);
    }

    .mobile-position {
        color: var(--green);
        font-size: 12px;
        font-weight: 900;
    }

    .mobile-car {
        color: var(--muted);
        font-size: 11px;
        font-weight: 800;
    }

    .mobile-crew-names {
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding: 13px 0;
    }

    .mobile-crew-names strong {
        color: var(--text);
        font-size: 16px;
    }

    .mobile-crew-names span {
        color: var(--muted);
        font-size: 12px;
    }

    .mobile-result {
        display: grid;
        grid-template-columns: 1.3fr 1fr;
        gap: 10px;
        padding: 13px;
        background: #0b111a;
        border-radius: 7px;
    }

    .mobile-result > div {
        display: flex;
        flex-direction: column;
        gap: 6px;
        min-width: 0;
    }

    .mobile-result span {
        color: var(--muted);
        font-size: 9px;
        font-weight: 800;
        letter-spacing: 1px;
    }

    .mobile-total strong {
        color: var(--green);
        font-size: 19px;
        overflow-wrap: anywhere;
    }

    .mobile-difference strong {
        color: var(--text);
        font-size: 14px;
        overflow-wrap: anywhere;
    }

    .mobile-times {
        margin-top: 12px;
    }

    .mobile-times summary {
        padding: 11px;
        color: var(--green);
        background: #45d6a010;
        border: 1px solid #45d6a030;
        border-radius: 6px;
        font-size: 10px;
        font-weight: 900;
        letter-spacing: 1px;
        cursor: pointer;
        list-style: none;
        text-align: center;
    }

    .mobile-times summary::-webkit-details-marker {
        display: none;
    }

    .mobile-times summary::after {
        content: "＋";
        margin-left: 8px;
    }

    .mobile-times[open] summary::after {
        content: "−";
    }

    .mobile-pe-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding-top: 10px;
    }

    .mobile-pe {
        display: flex;
        flex-direction: column;
        gap: 5px;
        min-width: 0;
        padding: 10px;
        background: #0b111a;
        border: 1px solid var(--border);
        border-radius: 6px;
    }

    .mobile-pe-name {
        color: var(--muted);
        font-size: 9px;
        font-weight: 900;
    }

    .mobile-pe strong {
        color: var(--text);
        font-size: 13px;
    }

    .mobile-pe-penalty {
        color: var(--orange);
        font-size: 11px;
        font-weight: 900;
    }

    .mobile-pe-reason {
        color: #ff7777;
        font-size: 10px;
        line-height: 1.4;
    }
}

/* CHACO SPORTS - IDENTIDAD AZUL */
:root {
    --bg: #071b35;
    --surface: #0c2440;
    --surface2: #12365d;
    --border: #24496e;
    --text: #f2f7ff;
    --muted: #9bb9d8;
    --green: #38a5ff;
    --orange: #ff9d42;
}

/* CLASIFICACION MOVIL CON COLUMNAS FIJAS */
@media (max-width: 800px) {
    .table-wrap {
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }

    .timing-table {
        display: table !important;
        width: max-content;
        min-width: 1050px;
        table-layout: fixed;
        border-collapse: separate;
        border-spacing: 0;
        white-space: nowrap;
    }

    .timing-table thead {
        display: table-header-group !important;
    }

    .timing-table tbody {
        display: table-row-group !important;
    }

    .timing-table tbody tr {
        display: table-row !important;
        background: var(--surface) !important;
        border: 0 !important;
    }

    .timing-table tbody td {
        display: table-cell !important;
        padding: 12px 10px;
        border-top: 1px solid var(--border);
        background: var(--surface);
        vertical-align: middle;
    }

    .timing-table tbody td::before {
        content: none !important;
        display: none !important;
    }

    .timing-table th,
    .timing-table td {
        text-align: center !important;
    }

    /* PRIMERAS TRES COLUMNAS FIJAS */
    .timing-table th:nth-child(1),
    .timing-table td:nth-child(1) {
        position: sticky;
        left: 0;
        z-index: 4;
        min-width: 48px;
        width: 48px;
        background: #102d4c;
    }

    .timing-table th:nth-child(2),
    .timing-table td:nth-child(2) {
        position: sticky;
        left: 48px;
        z-index: 4;
        min-width: 55px;
        width: 55px;
        background: #102d4c;
    }

    .timing-table th:nth-child(3),
    .timing-table td:nth-child(3) {
        position: sticky;
        left: 103px;
        z-index: 4;
        min-width: 155px;
        width: 155px;
        max-width: 155px;
        text-align: left !important;
        white-space: normal;
        background: #102d4c;
        box-shadow: 5px 0 10px #00000035;
    }

    .timing-table thead th:nth-child(-n+3) {
        z-index: 6;
        background: #194675;
    }

    .timing-table td.pe-cell {
        min-width: 105px;
    }

    .timing-table td.total-cell {
        min-width: 125px;
        color: #38a5ff;
        font-size: 14px;
    }

    .timing-table td.difference-cell {
        min-width: 100px;
    }

    /* Desactivar tarjetas anteriores */
    .mobile-card-cell {
        display: none !important;
    }

    .timing-table tbody tr.crew-row > td:not(.mobile-card-cell) {
        display: table-cell !important;
    }

    .timing-table tbody tr.crew-row > td.mobile-card-cell {
        display: none !important;
    }
}


/* ===== REDISEÑO CHACO RALLY LIVE ===== */
:root {
    --bg: #080808;
    --surface: #111111;
    --surface2: #191919;
    --border: #303030;
    --text: #f5f5f5;
    --muted: #999999;
    --green: #168cff;
    --orange: #ff922e;
}

body {
    background: var(--bg);
    color: var(--text);
}

.topbar {
    min-height: 68px;
    padding: 8px 22px;
    background: #000;
    border-bottom: 1px solid #292929;
}

.brand-logo {
    display: block;
    width: 205px;
    max-height: 58px;
    object-fit: contain;
}

.competition {
    min-height: 125px;
    margin: 14px 0;
    padding: 18px 25px;
    background: linear-gradient(110deg, #111, #191919 65%, #080808);
    border: 1px solid #303030;
    border-radius: 10px;
}

.stats {
    gap: 10px;
    margin: 12px 0 18px;
}

.stat-card {
    padding: 12px 15px;
    min-height: 75px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.toolbar {
    margin-top: 12px;
    padding: 12px 0;
}

.tab.active,
.stage-btn.active {
    color: #fff;
    border-color: #168cff;
    background: #12365a;
}

.content-panel {
    margin-top: 12px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
}

.timing-table th {
    background: #202020;
    color: #fff;
}

.timing-table td,
.timing-table th {
    border-color: #303030;
}

.timing-table tbody tr:nth-child(even) {
    background: #151515;
}

.timing-table tbody tr:hover {
    background: #202a35;
}

footer {
    border-top: 1px solid var(--border);
    color: #888;
}

@media (max-width: 800px) {
    .topbar {
        min-height: 58px;
        padding: 7px 12px;
    }

    .brand-logo {
        width: 165px;
        max-height: 45px;
    }

    .competition {
        min-height: 95px;
        margin: 10px 0;
        padding: 13px;
    }

    .stats {
        gap: 7px;
    }

    .stat-card {
        padding: 9px;
        min-height: 65px;
    }

    .content-panel {
        padding: 10px;
    }
}
