/* RACE Live Timing — Light Mode */
@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@600;700;800;900&family=Inter:wght@400;500;600;700&display=swap');

:root {
    --race-red: #E63946;
    --race-red-hover: #D32F3F;
    --race-navy: #06080D;
    --bg-primary: #FFFFFF;
    --bg-secondary: #F8FAFC;
    --bg-tertiary: #F1F5F9;
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --pos-up: #2563EB;
    --pos-down: #D97706;
    --gold: #D4A017;
    --silver: #9CA3AF;
    --bronze: #B87333;
    --font-heading: 'Barlow Condensed', sans-serif;
    --font-body: 'Inter', sans-serif;
}

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

body.live-page {
    font-family: var(--font-body);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.4;
}

/* === LIVE HEADER === */
.live-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.live-header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--race-red);
    color: #fff;
    padding: 4px 12px;
    border-radius: 20px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fff;
    animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.75); }
}

.live-event-name {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 18px;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: -0.01em;
}

.live-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

.live-elapsed {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 24px;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
}

.live-lang-toggle {
    display: flex;
    gap: 2px;
}

.live-lang-toggle button {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.live-lang-toggle button:first-child { border-radius: 4px 0 0 4px; }
.live-lang-toggle button:last-child { border-radius: 0 4px 4px 0; }
.live-lang-toggle button.active {
    background: var(--race-red);
    color: #fff;
    border-color: var(--race-red);
}

/* === CATEGORY PILLS === */
.cat-pills {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 52px;
    z-index: 99;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.cat-pills::-webkit-scrollbar { display: none; }

.cat-pills-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 8px 16px;
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

.cat-pill {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.cat-pill:hover {
    border-color: var(--race-red);
    color: var(--race-red);
}

.cat-pill.active {
    background: var(--race-red);
    color: #fff;
    border-color: var(--race-red);
}

.cat-pill .status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
}
.cat-pill .status-dot.active { background: #10B981; animation: pulse-dot 1.5s infinite; }
.cat-pill .status-dot.pending { background: var(--text-muted); }
.cat-pill .status-dot.finished { background: var(--race-red); }

/* === RESULTS TABLE === */
.live-container {
    max-width: 1400px;
    margin: 16px auto;
    padding: 0 16px;
}

.live-table-wrap {
    background: var(--bg-primary);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow-x: auto;
}

.live-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.live-table thead th {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
    text-align: left;
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--bg-primary);
}

.live-table thead th:first-child { text-align: center; width: 48px; }
.live-table thead th.col-time,
.live-table thead th.col-gap,
.live-table thead th.col-gap-prev,
.live-table thead th.col-best,
.live-table thead th.col-speed { text-align: right; }

.live-table tbody tr {
    border-bottom: 1px solid var(--bg-tertiary);
    transition: background-color 0.8s ease;
}

.live-table tbody tr:hover { background: var(--bg-secondary); }

.live-table tbody td {
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
}

/* Position column */
.pos-cell {
    text-align: center;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 16px;
    min-width: 48px;
}

.pos-cell.pos-1 { color: var(--gold); }
.pos-cell.pos-2 { color: var(--silver); }
.pos-cell.pos-3 { color: var(--bronze); }

.pos-arrow {
    font-size: 10px;
    margin-left: 2px;
}
.pos-arrow.up { color: var(--pos-up); }
.pos-arrow.down { color: var(--pos-down); }

/* Flag + country */
.country-cell {
    font-size: 16px;
}
.country-code {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    margin-left: 2px;
    vertical-align: middle;
}

/* Rider name */
.rider-name {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary);
    text-transform: uppercase;
}
.rider-club {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

/* Laps */
.laps-cell {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 13px;
}
.laps-cell .done { color: var(--text-primary); }
.laps-cell .total { color: var(--text-muted); }

/* Time cells */
.time-cell {
    text-align: right;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
}

.gap-cell {
    text-align: right;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
}

.best-lap-cell {
    text-align: right;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
}

.speed-cell {
    text-align: right;
    font-size: 12px;
    color: var(--text-muted);
}

.checkpoint-cell {
    font-size: 11px;
    color: var(--text-muted);
}

/* Follow rider */
.follow-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    opacity: 0.3;
    transition: opacity 0.2s;
    padding: 0 4px;
}
.follow-btn:hover { opacity: 0.7; }
.follow-btn.followed { opacity: 1; }

tr.followed-row { background: rgba(37, 99, 235, 0.04) !important; }

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.status-badge.dns { background: var(--bg-tertiary); color: var(--text-muted); }
.status-badge.dnf { background: #FEE2E2; color: #DC2626; }
.status-badge.lapped { background: #FEF3C7; color: #92400E; }

tr.status-dns { opacity: 0.45; }
tr.status-dnf { opacity: 0.6; }

/* Position change animations */
@keyframes flash-up {
    0% { background-color: rgba(37, 99, 235, 0.15); }
    100% { background-color: transparent; }
}
@keyframes flash-down {
    0% { background-color: rgba(217, 119, 6, 0.12); }
    100% { background-color: transparent; }
}
tr.pos-changed-up { animation: flash-up 2s ease-out; }
tr.pos-changed-down { animation: flash-down 2s ease-out; }

/* === COUNTDOWN / PRE-RACE === */
.pre-race-panel {
    text-align: center;
    padding: 60px 20px;
}
.pre-race-panel h2 {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.pre-race-countdown {
    font-family: var(--font-heading);
    font-size: 48px;
    font-weight: 900;
    color: var(--race-red);
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
}
.pre-race-label {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 8px;
}

/* === LAST UPDATED === */
.live-footer {
    max-width: 1400px;
    margin: 8px auto;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-muted);
}

/* === SPLIT DETAIL ROW === */
.split-row { background: #F0F4FF !important; }
.split-cell { padding: 0 12px 12px 60px !important; }
.split-detail { max-width: 400px; }
.split-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.split-table th { font-size: 10px; text-transform: uppercase; color: var(--text-muted); padding: 4px 8px; text-align: left; letter-spacing: 0.06em; border-bottom: 1px solid var(--border); }
.split-table td { padding: 4px 8px; }
.best-lap-row { background: #FEF3C7; }
.best-lap-row td { font-weight: 600; color: #92400E; }
tr.expanded { background: #F0F4FF; }
tr[data-rider] { cursor: pointer; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .live-header-inner {
        flex-wrap: wrap;
        gap: 8px;
    }
    .live-event-name { font-size: 14px; }
    .live-elapsed { font-size: 20px; }
    .live-table tbody td { padding: 6px 8px; font-size: 12px; }
    .pos-cell { font-size: 14px; }
    .rider-name { font-size: 12px; }
    .time-cell { font-size: 12px; }

    /* Mobile: hide secondary columns */
    .live-table .col-flag,
    .live-table .col-dorsal,
    .live-table .col-gap-prev,
    .live-table .col-best,
    .live-table .col-checkpoint,
    .live-table .col-speed { display: none; }
}

@media (max-width: 480px) {
    .cat-pills-inner { padding: 6px 8px; }
    .cat-pill { padding: 4px 10px; font-size: 11px; }
    .live-container { padding: 0 8px; margin: 8px auto; }

    .live-table .col-gap { display: none; }
}

/* ============================
   XCR TEAM RELAY (public live + overlay)
   ============================ */
.live-team-table .col-box { text-align: center; width: 52px; }
.live-team-table .col-leg { text-align: center; width: 72px; }
.live-team-table .col-team { min-width: 160px; }
.live-team-table .col-leg-time { text-align: right; width: 84px; font-variant-numeric: tabular-nums; }
.live-team-table .col-current {
    font-size: 12px;
    color: #475569;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.xcr-team-row td { padding: 8px 10px; }
.xcr-leg-time {
    font-family: var(--font-mono, monospace);
    font-size: 12px;
    font-weight: 600;
}
.xcr-sub-asterisk {
    color: #D97706;
    font-weight: 700;
    margin-left: 2px;
    cursor: help;
}

/* Overlay mode=relay */
.ov-panel-relay .ov-cols-relay .ov-col-laps { flex: 0 0 70px; text-align: center; }
.ov-row-relay .ov-row-detail { font-size: 11px; opacity: 0.8; }

@media (max-width: 900px) {
    .live-team-table .col-current,
    .live-team-table .col-box { display: none; }
}
@media (max-width: 600px) {
    /* Collapse leg-3 + leg-4 columns on phones */
    .live-team-table th:nth-child(9),
    .live-team-table td:nth-child(9),
    .live-team-table th:nth-child(10),
    .live-team-table td:nth-child(10) { display: none; }
}
@media (max-width: 480px) {
    /* Further collapse leg-1 + leg-2 when screen is tiny */
    .live-team-table th:nth-child(7),
    .live-team-table td:nth-child(7),
    .live-team-table th:nth-child(8),
    .live-team-table td:nth-child(8) { display: none; }
}

/* ============================
   NEUTRALIZATION (spec §4.4)
   ============================ */
.neutral-banner {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #FEF3C7;
    color: #92400E;
    padding: 4px 10px;
    border-radius: 14px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    user-select: none;
    border: 1px solid #FDE68A;
    transition: background 0.15s ease;
}
.neutral-banner:hover { background: #FDE68A; }
.neutral-banner-dot {
    animation: neutral-banner-pulse 1.5s ease-in-out infinite;
    font-size: 10px;
}
@keyframes neutral-banner-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

.neutral-expand {
    background: #FFFBEB;
    border-bottom: 1px solid #FDE68A;
    padding: 12px 0;
}
.neutral-expand-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
}
.neutral-expand h4 {
    font-family: var(--font-heading);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #92400E;
    margin: 0 0 6px 0;
}
.neutral-expand ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.neutral-expand li {
    padding: 4px 0;
    border-bottom: 1px dashed #FDE68A;
    font-size: 13px;
}
.neutral-expand li:last-child { border-bottom: none; }
.neutral-expand-times {
    color: var(--text-muted);
    font-family: 'Inter', monospace;
    font-size: 12px;
    margin-left: 8px;
}

/* Race cancelled banner — sits above the live-header in the DOM and pushes
   it down. (Header has its own sticky positioning; we leave that alone.) */
.race-cancelled-banner {
    background: #DC2626;
    color: #fff;
    text-align: center;
    padding: 12px 16px;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 18px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.4);
    animation: race-cancel-pulse 2s ease-in-out infinite;
    z-index: 110;
    position: relative;
}
@keyframes race-cancel-pulse {
    0%, 100% { background: #DC2626; }
    50% { background: #B91C1C; }
}
