/* =======================================================================
 * Racehall CRM — Frontend leaderboard (modern redesign)
 * Pure visual layer. No markup, class names, or behavior changed.
 * ===================================================================== */

.racehall-leaderboard {
    --rh-bg: #0a0a0a;
    --rh-surface: #0a0a0a;
    --rh-soft: #171717;
    --rh-border: #2a2a2a;
    --rh-border-2: #1f1f1f;
    --rh-ink: #ffffff;
    --rh-muted: #9ca3af;
    --rh-accent: #dc2626;
    --rh-accent-2: #7f1d1d;
    --rh-accent-ink: #ffffff;
    --rh-gold: #f59e0b;
    --rh-silver: #9ca3af;
    --rh-bronze: #92400e;
    --rh-success: #ef4444;
    --rh-shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --rh-shadow: 0 6px 20px -8px rgba(0, 0, 0, .6), 0 2px 6px -2px rgba(0, 0, 0, .4);
    --rh-shadow-lg: 0 18px 40px -14px rgba(220, 38, 38, .5);
    --rh-radius: 16px;
    --rh-radius-sm: 10px;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
    color: var(--rh-ink);
    max-width: 100%;
    margin: 0 auto 2.5rem;
    padding: 28px;
    background: var(--rh-surface);
    border: 1px solid var(--rh-border);
    border-radius: var(--rh-radius);
    box-shadow: var(--rh-shadow);
}

/* ---- Title --------------------------------------------------------- */
.racehall-lb-title {
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    margin: 0 0 1.25rem;
    color: #ffffff !important;
    text-transform: uppercase;
    line-height: 1.15;
}

/* ---- Filter form --------------------------------------------------- */
.racehall-filter-form {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 14px 16px;
    background: var(--rh-soft);
    border: 1px solid var(--rh-border-2);
    border-radius: var(--rh-radius-sm);
}

.racehall-filter-form label {
    font-weight: 600;
    font-size: .85rem;
    color: var(--rh-muted);
}

.racehall-filter-form input[type="text"] {
    padding: 9px 14px;
    border: 1px solid var(--rh-border);
    border-radius: 8px;
    font-size: .9rem;
    width: 160px;
    background: var(--rh-soft);
    color: var(--rh-ink);
    transition: border-color .15s ease, box-shadow .15s ease;
    box-shadow: var(--rh-shadow-sm);
}

.racehall-filter-form input[type="text"]::placeholder {
    color: #9ca3af;
}

.racehall-filter-form input[type="text"]:focus {
    outline: none;
    border-color: var(--rh-accent);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, .15);
}

.racehall-filter-form button {
    padding: 9px 20px;
    background: linear-gradient(135deg, var(--rh-accent), var(--rh-accent-2));
    color: var(--rh-accent-ink);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: .88rem;
    font-weight: 600;
    box-shadow: var(--rh-shadow-sm);
    transition: transform .15s ease, box-shadow .2s ease;
}

.racehall-filter-form button:hover {
    transform: translateY(-1px);
    box-shadow: var(--rh-shadow-lg);
}

.racehall-filter-form button:active {
    transform: translateY(0);
}

.racehall-clear {
    font-size: .82rem;
    color: var(--rh-muted);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--rh-border);
    background: var(--rh-soft);
    transition: all .15s ease;
}

.racehall-clear:hover {
    color: var(--rh-accent);
    border-color: var(--rh-accent);
    text-decoration: none;
}

/* ---- Filter badge -------------------------------------------------- */
.racehall-filter-badge {
    font-size: .82rem;
    color: var(--rh-muted);
    margin: 0 0 .85rem;
    padding: 8px 14px;
    /* background: linear-gradient(135deg, rgba(220, 38, 38, .08), rgba(127, 29, 29, .08)); */
    border: 1px solid rgba(220, 38, 38, .15);
    border-radius: 999px;
    display: inline-block;
}

.racehall-filter-badge strong {
    color: var(--rh-ink);
    font-weight: 700;
}

/* ---- Leaderboard tabs (Best Lap / Total Time / Score) ----------- */
.racehall-lb-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0 0 18px;
    border-bottom: 2px solid var(--rh-border);
}

.racehall-lb-tab {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--rh-muted);
    font-family: inherit;
    font-size: .82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 12px 20px;
    cursor: pointer;
    position: relative;
    transition: color .15s ease;
    margin-bottom: -2px;
    border-bottom: 2px solid transparent;
}

.racehall-lb-tab:hover {
    color: var(--rh-ink);
}

.racehall-lb-tab.is-active {
    color: #000000;
    border-bottom-color: var(--rh-accent);
}

.racehall-lb-tab:focus-visible {
    outline: 2px solid var(--rh-accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.racehall-lb-panel[hidden] {
    display: none;
}

@media (max-width: 480px) {
    .racehall-lb-tab {
        flex: 1 1 33%;
        padding: 10px 6px;
        font-size: .72rem;
        letter-spacing: .04em;
    }
}

/* ---- Table --------------------------------------------------------- */
.racehall-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .95rem;
    background: var(--rh-surface);
    border: 1px solid var(--rh-border);
    border-radius: var(--rh-radius-sm);
    overflow: hidden;
    box-shadow: var(--rh-shadow-sm);
}

.racehall-table thead th {
    background: var(--rh-soft);
    color: var(--rh-muted);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    border-bottom: 1px solid var(--rh-border);
}

.racehall-table tbody tr {
    transition: background .12s ease, transform .12s ease;
}

.racehall-table tbody tr:not(:last-child) {
    border-bottom: 1px solid var(--rh-border-2);
}

.racehall-table tbody tr:hover {
    background: var(--rh-soft);
}

/* Leader row — soft gold highlight + slow shimmer */
.racehall-table tbody tr.racehall-first {
    /* Three-stop gradient at 200% width gives the shimmer animation
       something to slide. The 'translate' part of the entrance animation
       still works because we animate background-position, not background-image. */
    background: linear-gradient(90deg,
            rgba(245, 158, 11, .12) 0%,
            rgba(245, 158, 11, .35) 50%,
            rgba(245, 158, 11, .12) 100%);
    background-size: 200% 100%;
    position: relative;
    animation:
        racehall-row-in 0.45s ease-out var(--rh-row-delay, 0ms) backwards,
        racehall-shimmer 4s ease-in-out 0.6s infinite;
}

.racehall-table tbody tr.racehall-first:hover {
    background: linear-gradient(90deg,
            rgba(245, 158, 11, .20) 0%,
            rgba(245, 158, 11, .45) 50%,
            rgba(245, 158, 11, .20) 100%);
    background-size: 200% 100%;
}

.racehall-table tbody tr.racehall-first td:first-child {
    box-shadow: inset 3px 0 0 var(--rh-gold);
}

/* ---- Row entrance animation (staggered) -------------------------- */
@keyframes racehall-row-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes racehall-shimmer {
    0% {
        background-position: -100% 0;
    }

    50% {
        background-position: 100% 0;
    }

    100% {
        background-position: 100% 0;
    }
}

/* All non-leader rows just fade in. The first-place rule above adds
   the shimmer on top of the same entrance keyframes. */
.racehall-table tbody tr:not(.racehall-first) {
    animation: racehall-row-in 0.45s ease-out var(--rh-row-delay, 0ms) backwards;
}

/* Respect reduced-motion users — skip animations entirely. */
@media (prefers-reduced-motion: reduce) {

    .racehall-table tbody tr,
    .racehall-table tbody tr.racehall-first,
    .racehall-table tbody tr:not(.racehall-first) {
        animation: none;
    }
}

.racehall-table td {
    padding: 14px 16px;
    color: var(--rh-ink);
    vertical-align: middle;
}

.racehall-table tbody tr:not(:last-child) td {
    border-bottom: 1px solid var(--rh-border-2);
}

/* Rank cell — medal emojis get a subtle circular badge feel via size */
.racehall-rank {
    font-weight: 700;
    font-size: 1.15rem;
    min-width: 48px;
    color: var(--rh-muted);
    font-variant-numeric: tabular-nums;
}

.racehall-table tbody tr.racehall-first .racehall-rank,
.racehall-table tbody tr:nth-child(2) .racehall-rank,
.racehall-table tbody tr:nth-child(3) .racehall-rank {
    font-size: 1.4rem;
    line-height: 1;
}

/* Time cell */
.racehall-time {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: .92rem;
    font-weight: 700;
    color: var(--rh-success);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

/* ---- Empty / count states ----------------------------------------- */
.racehall-empty {
    font-size: .92rem;
    color: var(--rh-muted);
    margin: 1rem 0;
    padding: 28px 20px;
    text-align: center;
    background: var(--rh-soft);
    border: 1px dashed var(--rh-border);
    border-radius: var(--rh-radius-sm);
}

.racehall-count {
    font-size: .82rem;
    color: var(--rh-muted);
    margin-top: .9rem;
    text-align: right;
    font-style: italic;
}

/* ---- Responsive --------------------------------------------------- */
@media (max-width: 640px) {
    .racehall-leaderboard {
        padding: 20px 16px;
        border-radius: 12px;
        margin: 0 auto 1.5rem;
    }

    .racehall-lb-title {
        font-size: 1.5rem;
    }

    .racehall-filter-form {
        padding: 12px;
        gap: 8px;
    }

    .racehall-filter-form input[type="text"] {
        flex: 1 1 140px;
        width: auto;
    }

    .racehall-table {
        font-size: .85rem;
    }

    .racehall-table thead th,
    .racehall-table td {
        padding: 10px 10px;
    }

    .racehall-rank {
        min-width: 36px;
    }
}

/* ---- Dark mode support (respects user preference) ----------------- */
@media (prefers-color-scheme: dark) {
    .racehall-leaderboard {
        --rh-surface: #0a0a0a;
        --rh-soft: #171717;
        --rh-border: #2a2a2a;
        --rh-border-2: #1f1f1f;
        --rh-ink: #fafafa;
        --rh-muted: #9ca3af;
        --rh-success: #34d399;
    }

    .racehall-filter-form input[type="text"] {
        background: #171717;
        color: var(--rh-ink);
    }

    .racehall-clear {
        background: #171717;
    }

    .racehall-table tbody tr.racehall-first {
        background: linear-gradient(90deg, rgba(245, 158, 11, .15), rgba(245, 158, 11, .03));
    }
}