/* =============================================================================
   Drivers — leaderboard and per-driver stats
   ============================================================================= */

.drv-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

.drv-header { margin-bottom: 1.75rem; }

.drv-header .page-subtitle {
    margin: 8px 0 24px;
    font-size: 15px;
    color: var(--text-secondary);
}

/* ── Toolbar ─────────────────────────────────────────────────────────────── */

.drv-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.drv-search {
    position: relative;
    display: flex;
    align-items: center;
}

.drv-search svg {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
}

.drv-search input {
    width: 240px;
    padding: 9px 14px 9px 34px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font: inherit;
    font-size: 13.5px;
}

.drv-search input::placeholder { color: var(--text-muted); }
.drv-search input:focus { border-color: var(--accent-hover); }

.drv-sort {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
}

.drv-sort-btn {
    padding: 7px 13px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.drv-sort-btn:hover { color: var(--text-primary); }

.drv-sort-btn.active {
    background: var(--accent-subtle);
    color: var(--accent-primary);
}

/* ── Leaderboard rows ────────────────────────────────────────────────────── */

.drv-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.drv-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) repeat(4, 74px) 84px;
    align-items: center;
    gap: 16px;
    padding: 18px 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    text-decoration: none;
    transition: border-color var(--transition-fast), background var(--transition-fast),
                transform var(--transition-fast);
}

.drv-row:hover { border-color: var(--border-strong); }

.drv-rank {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 17px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.drv-row:nth-child(1) .drv-rank { color: var(--pos-1); }
.drv-row:nth-child(2) .drv-rank { color: var(--pos-2); }
.drv-row:nth-child(3) .drv-rank { color: var(--pos-3); }

/* A name reads better next to a face, even a lettered one. */
.drv-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.drv-identity-text { min-width: 0; }

.drv-initials {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: var(--radius-full);
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--accent-primary);
}

.drv-name {
    display: block;
    font-size: 14.5px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.drv-sub {
    display: block;
    margin-top: 2px;
    font-size: 11.5px;
    color: var(--text-muted);
}

.drv-stat {
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.drv-stat-value {
    display: block;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 16px;
    font-weight: 400;
    color: var(--text-primary);
    line-height: 1.2;
}

.drv-stat-label {
    display: block;
    margin-top: 3px;
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.drv-stat.wins .drv-stat-value    { color: var(--pos-1); }
.drv-stat.podiums .drv-stat-value { color: var(--accent-primary); }

/* Form: last five races, newest first */
.drv-form {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}

.drv-form-pip {
    width: 8px;
    height: 22px;
    border-radius: 2px;
    background: var(--bg-elevated);
}

.drv-form-pip.p1 { background: var(--pos-1); }
.drv-form-pip.p2 { background: var(--pos-2); }
.drv-form-pip.p3 { background: var(--pos-3); }
.drv-form-pip.fin { background: var(--success); opacity: 0.55; }
.drv-form-pip.dnf { background: var(--danger); }

/* ── Detail page ─────────────────────────────────────────────────────────── */

.drv-back {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 1.25rem;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.drv-back:hover { color: var(--accent-primary); }

.drv-hero {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
}

.drv-avatar {
    width: 68px;
    height: 68px;
    border-radius: var(--radius-full);
    display: grid;
    place-items: center;
    background: var(--accent-subtle);
    color: var(--accent-primary);
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.drv-hero-info { flex: 1; min-width: 200px; }

.drv-hero-name {
    margin: 0;
    font-size: 1.7rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.drv-hero-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--text-muted);
}

/* Only appears when the driver on this page has an account here, so it
   must not leave a gap on the pages where it does not. */
.drv-hero-social:empty { display: none; }

.drv-hero-social { margin-top: 12px; }

.drv-friend {
    padding: 7px 15px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--accent-primary);
    color: var(--on-accent);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast),
                border-color var(--transition-fast), color var(--transition-fast);
}

.drv-friend:hover { background: var(--accent-secondary); }

/* Already friends: undoing that should not be the loudest thing on the page. */
.drv-friend[data-on] {
    background: transparent;
    border-color: var(--control-border);
    color: var(--text-secondary);
}

.drv-friend[data-on]:hover {
    border-color: var(--danger-border);
    color: var(--danger);
}

.drv-friend:disabled { opacity: 0.5; cursor: default; }

.drv-friend:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
}

.drv-chip {
    padding: 3px 9px;
    border-radius: var(--radius-pill);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    font-weight: 700;
    color: var(--text-secondary);
}

.drv-chip.number {
    background: var(--accent-subtle);
    border-color: var(--accent-hover);
    color: var(--accent-primary);
}

/* Stat grid */
.drv-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
    gap: 8px;
    margin-bottom: 1.25rem;
}

.drv-stat-card {
    padding: 16px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    text-align: center;
}

.drv-stat-card .v {
    display: block;
    font-size: 26px;
    font-weight: 600;
    line-height: 1.1;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.drv-stat-card .l {
    display: block;
    margin-top: 5px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.9px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.drv-stat-card.gold .v   { color: var(--pos-1); }
.drv-stat-card.brand .v  { color: var(--accent-primary); }
.drv-stat-card.purple .v { color: var(--lap-fastest); }
.drv-stat-card.danger .v { color: var(--danger); }

/* Two-column body */
.drv-cols {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

@media (min-width: 900px) {
    .drv-cols { grid-template-columns: 1fr 1fr; }
}

.drv-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    padding: 1.25rem;
}

.drv-card-title {
    margin: 0 0 1rem;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Personal bests */
.drv-pb {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-secondary);
}

.drv-pb:last-child { border-bottom: none; }

.drv-pb-track {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: capitalize;
}

.drv-pb-time {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-primary);
    font-variant-numeric: tabular-nums;
}

/* History */
.drv-hist {
    display: grid;
    grid-template-columns: 44px 1fr auto auto auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 0;
    border: none;
    border-bottom: 1px solid var(--border-secondary);
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    /* The track cell already ellipsises; without this the last few pixels
       leak out and give the whole list a horizontal scrollbar. */
    overflow: hidden;
}

.drv-hist:hover { background: var(--bg-elevated); }

.drv-hist-item:last-child .drv-hist { border-bottom: none; }

.drv-hist-chev {
    /* An inline span ignores width, so the glyph decided the column size and
       pushed the row wider than the card. */
    display: block;
    width: 14px;
    font-size: 15px;
    line-height: 1;
    text-align: center;
    color: var(--text-faint);
    transition: transform var(--transition-fast);
}

.drv-hist[aria-expanded="true"] .drv-hist-chev {
    transform: rotate(90deg);
    color: var(--accent-primary);
}

/* ── Expanded session ────────────────────────────────────────────────────── */

.drv-sess {
    padding: 4px 0 14px;
    overflow-x: auto;
}

.drv-sess[hidden] { display: none; }

.drv-sess-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.drv-sess-table th {
    padding: 6px 10px;
    text-align: left;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-primary);
    white-space: nowrap;
}

.drv-sess-table td {
    padding: 6px 10px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-secondary);
}

.drv-sess-table tr:last-child td { border-bottom: none; }

.drv-sess-table .p { font-weight: 700; color: var(--text-primary); }
.drv-sess-table .n,
.drv-sess-table .t { text-align: right; font-variant-numeric: tabular-nums; }

/* The driver whose page this is, so they can find themselves in a full grid. */
.drv-sess-table tr.is-me td {
    background: var(--accent-subtle);
    color: var(--text-primary);
    font-weight: 600;
}

.drv-pos {
    display: grid;
    place-items: center;
    height: 26px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.drv-pos.p1 { background: var(--pos-1); color: var(--bg-primary); }
.drv-pos.p2 { background: var(--pos-2); color: var(--bg-primary); }
.drv-pos.p3 { background: var(--pos-3); color: var(--bg-primary); }
.drv-pos.dnf { background: var(--danger-subtle); color: var(--danger); }

.drv-hist-track {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: capitalize;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.drv-hist-meta {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.drv-hist-lap {
    font-size: 12.5px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.drv-tag {
    display: inline-block;
    padding: 1px 6px;
    margin-left: 6px;
    border-radius: 4px;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.drv-tag.q   { background: var(--info-subtle); color: var(--info); }
.drv-tag.p   { background: var(--bg-elevated); color: var(--text-muted); }
.drv-tag.wet { background: var(--info-subtle); color: var(--info); }
.drv-tag.src { background: var(--bg-tertiary); color: var(--text-muted);
               border: 1px solid var(--border-primary); }
.drv-tag.src.matchmaking { color: var(--accent-primary);
                           border-color: var(--accent-hover); }

/* ── Loading / empty ─────────────────────────────────────────────────────── */

.drv-skeleton {
    height: 70px;
    border-radius: var(--radius-lg);
    background: linear-gradient(90deg,
        var(--bg-secondary) 0%, var(--bg-tertiary) 50%, var(--bg-secondary) 100%);
    background-size: 200% 100%;
    animation: drv-shimmer 1.3s ease-in-out infinite;
}

.drv-skeleton + .drv-skeleton { margin-top: 8px; }
.drv-skeleton-tall { height: 120px; }

@keyframes drv-shimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

.drv-empty,
.drv-error {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.drv-error { color: var(--danger); }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 780px) {
    .drv-page { padding: 1.5rem 1rem 3rem; }

    /* Drop the per-stat columns; keep name, wins and form. */
    .drv-row { grid-template-columns: 34px minmax(0, 1fr) 56px 68px; }
    .drv-stat.podiums,
    .drv-stat.races,
    .drv-stat.avg { display: none; }

    /* Keep each row one line tall. */
    .drv-sub {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .drv-toolbar { flex-direction: column; align-items: stretch; }
    .drv-search input { width: 100%; }
    .drv-sort { overflow-x: auto; }

    .drv-hero-name { font-size: 1.35rem; }
}

/* =============================================================================
   Driver page — tidier hierarchy
   Appended last so it wins over the rules above.
   ============================================================================= */

/* Four headline tiles, always on one row down to tablet. */
.drv-stats-grid {
    grid-template-columns: repeat(4, 1fr);
    margin-bottom: 10px;
}

.drv-stat-card { padding: 18px 14px; }
.drv-stat-card .v { font-size: 30px; }

/* Supporting numbers: one quiet strip instead of six more big tiles. */
.drv-facts {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin-bottom: 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.drv-fact {
    flex: 1 1 0;
    min-width: 92px;
    padding: 12px 10px;
    text-align: center;
    border-right: 1px solid var(--border-secondary);
}

.drv-fact:last-child { border-right: none; }

.drv-fact .fv {
    display: block;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.drv-fact .fl {
    display: block;
    margin-top: 2px;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.7px;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Card heads carry a hint or a control on the right. */
.drv-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.9rem;
}

.drv-card-head .drv-card-title { margin: 0; }

.drv-card-hint {
    font-size: 11px;
    color: var(--text-muted);
}

/* Races / All toggle */
.drv-hist-toggle {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
}

.drv-hist-toggle button {
    padding: 4px 11px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
}

.drv-hist-toggle button:hover { color: var(--text-primary); }

.drv-hist-toggle button.active {
    background: var(--accent-subtle);
    color: var(--accent-primary);
}

/* Non-race sessions get a neutral chip, not a podium colour. */
.drv-pos.sess {
    background: transparent;
    border: 1px solid var(--border-primary);
    color: var(--text-muted);
    font-weight: 700;
}

/* The two columns were badly unbalanced: a short PB list next to a very long
   session list left a large empty gap. Cap the long one and let it scroll. */
.drv-cols { align-items: start; }

.drv-card > div[id="drv-history"] {
    max-height: 420px;
    overflow-y: auto;
}

.drv-pb:last-of-type { border-bottom: none; }

@media (max-width: 780px) {
    .drv-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .drv-fact { flex-basis: 33.333%; }
    .drv-card > div[id="drv-history"] { max-height: none; }
}
