/* ============================================================
   RALLY MASTER - PÁGINA PÚBLICA DE RESULTADOS (SOLO LECTURA)
   Estilos independientes, no dependen de la app principal.
   ============================================================ */

:root {
    --bg: #0b0f1a;
    --bg-card: #131a2b;
    --bg-secondary: #1a2338;
    --border: #26304a;
    --text: #e6ebf5;
    --text-muted: #8b96ad;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-blue: #3b82f6;
    --accent-cyan: #22d3ee;
    --accent-amber: #f59e0b;
    --font-mono: 'Consolas', 'Menlo', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.public-header {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.public-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-logo { font-size: 2rem; }
.brand h1 { font-size: 1.3rem; font-weight: 800; letter-spacing: 0.5px; }
.brand p { font-size: 0.8rem; color: var(--text-muted); }

.live-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.live-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-green);
    animation: pulse 1.5s infinite;
}

.live-indicator.offline .live-dot { background: var(--accent-red); animation: none; }
.live-indicator.offline { border-color: rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.1); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ===== Main ===== */
.public-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
    width: 100%;
    flex: 1;
}

/* ===== Tabs ===== */
.public-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.public-tab {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
}

.public-tab:hover { border-color: var(--accent-blue); color: var(--text); }
.public-tab.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}

.public-view { display: none; }
.public-view.active { display: block; }

/* ===== Category selector ===== */
.category-selector {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.cat-chip {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
}

.cat-chip:hover { transform: translateY(-1px); }
.cat-chip.active { border-width: 2px; }

/* ===== Tables ===== */
.table-responsive { overflow-x: auto; }

.public-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
    font-size: 0.9rem;
}

.public-table thead th {
    background: var(--bg-secondary);
    padding: 0.75rem 0.8rem;
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.public-table tbody td {
    padding: 0.7rem 0.8rem;
    border-bottom: 1px solid rgba(38, 48, 74, 0.5);
    white-space: nowrap;
}

.public-table tbody tr:hover { background: rgba(59, 130, 246, 0.05); }
.public-table tbody tr.leader-row { background: rgba(34, 197, 94, 0.06); }
.public-table tbody tr.dnf-row { opacity: 0.6; }

.time-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--accent-green); font-weight: 700; }
.text-red { color: var(--accent-red); }
.text-cyan { color: var(--accent-cyan); font-weight: 600; }

.badge-car-number {
    display: inline-block;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
}

.badge-category {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
}

.podium-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-weight: 800;
    font-size: 0.85rem;
}
.podium-1 { background: #f59e0b; color: #1a1a1a; }
.podium-2 { background: #94a3b8; color: #1a1a1a; }
.podium-3 { background: #b45309; color: #fff; }

.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
}
.status-OK { background: rgba(34,197,94,0.15); color: var(--accent-green); }
.status-REENG { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.status-DNF { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.status-DNS { background: rgba(139,150,173,0.15); color: var(--text-muted); }
.status-DSQ { background: rgba(239,68,68,0.25); color: var(--accent-red); }

/* ===== Botón desplegable de tiempos ===== */
.expand-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    vertical-align: middle;
    margin-right: 0.35rem;
}
.expand-btn:hover { border-color: var(--accent-blue); color: var(--accent-blue); }
.expand-btn.open { transform: rotate(90deg); color: var(--accent-blue); border-color: var(--accent-blue); }

.car-times-row td {
    background: var(--bg-secondary);
    padding: 0.6rem 1rem !important;
}

.car-times-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.car-time-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem 0.7rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 70px;
}
.car-time-label {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.car-time-value {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--accent-green);
}
.car-time-value.scratch { color: var(--accent-cyan); }

/* Matrix cells */
.matrix-cell { text-align: center; font-family: var(--font-mono); font-size: 0.8rem; }
.matrix-scratch { color: var(--accent-cyan); font-weight: 700; }
.matrix-stage-header { text-align: center !important; background: var(--bg-secondary) !important; }

/* ===== Footer ===== */
.public-footer {
    border-top: 1px solid var(--border);
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ============================================================
   VISTA MÓVIL (TARJETAS)
   En pantallas pequeñas se muestran tarjetas compactas en lugar
   de tablas con scroll horizontal.
   ============================================================ */

/* Contenedor de tarjetas (solo visible en móvil) */
.mobile-cards { display: none; }

/* Tarjeta de piloto */
.mobile-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.9rem 1rem;
    margin-bottom: 0.75rem;
    position: relative;
}

.mobile-card.leader { border-color: rgba(34,197,94,0.5); background: rgba(34,197,94,0.06); }
.mobile-card.dnf { opacity: 0.6; }

.mobile-card-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
}

.mobile-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    border-radius: 8px;
    font-weight: 800;
    font-size: 1rem;
    font-family: var(--font-mono);
    background: var(--bg-secondary);
    color: var(--text);
}
.mobile-rank.r1 { background: #f59e0b; color: #1a1a1a; }
.mobile-rank.r2 { background: #94a3b8; color: #1a1a1a; }
.mobile-rank.r3 { background: #b45309; color: #fff; }

.mobile-driver { flex: 1; min-width: 0; }
.mobile-driver .name { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mobile-driver .vehicle { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mobile-car-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.9rem;
}

.mobile-card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.mobile-stat {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 0.45rem 0.6rem;
    text-align: center;
}
.mobile-stat .label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.mobile-stat .value { font-family: var(--font-mono); font-weight: 700; font-size: 0.85rem; margin-top: 0.15rem; }
.mobile-stat .value.green { color: var(--accent-green); }
.mobile-stat .value.red { color: var(--accent-red); }
.mobile-stat .value.cyan { color: var(--accent-cyan); }

.mobile-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.mobile-cat-badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .public-header-inner { flex-direction: column; align-items: flex-start; }
    .brand h1 { font-size: 1.1rem; }
    .public-main { padding: 0.75rem; }
    .public-tabs { position: sticky; top: 0; background: var(--bg); padding: 0.5rem 0; z-index: 5; }
    .public-tab { flex: 1; text-align: center; padding: 0.6rem 0.4rem; font-size: 0.8rem; }

    /* Ocultar tablas en móvil, mostrar tarjetas */
    .public-table { display: none; }
    .mobile-cards { display: block; }
    .category-selector { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 0.3rem; }
    .cat-chip { flex-shrink: 0; }
}

@media (max-width: 480px) {
    .mobile-card-grid { grid-template-columns: repeat(2, 1fr); }
    .brand h1 { font-size: 1rem; }
    .live-indicator { font-size: 0.7rem; padding: 0.3rem 0.7rem; }
}