/**
 * VCR Rankings - Hot Lap Leaderboard
 * Pagina /rankings - filtri, tabs categoria, hero pista, tabella tempi.
 */

/* ============ Layout shell ============ */
.vcr-rankings {
    --rk-bg: #0d1117;
    --rk-bg-2: #161b22;
    --rk-bg-3: #21262d;
    --rk-border: #30363d;
    --rk-text: #c9d1d9;
    --rk-text-dim: #8b949e;
    --rk-accent: #f78166;
    --rk-accent-2: #ffd24a;
    --rk-vcr: #ff5252;
    --rk-radius: 10px;
    --rk-dock-space: 0px;

    color: var(--rk-text);
    background: var(--rk-bg);
    border-radius: 0;
    padding: 24px clamp(24px, 4vw, 56px);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    min-height: 320px;
    box-sizing: border-box;

    /* Breakout from theme post-content max-width: extend to viewport edges
     * but respect body padding on the right (used by [vcr_widget_dock]). */
    width: calc(100vw - var(--rk-dock-space));
    max-width: calc(100vw - var(--rk-dock-space));
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw + var(--rk-dock-space));
    overflow-x: hidden;
    transition: width .3s ease, max-width .3s ease, margin-right .3s ease;
}
.vcr-rankings *,
.vcr-rankings *::before,
.vcr-rankings *::after { box-sizing: border-box; }

/* Reserve room when the widget dock is mounted (desktop only).
 * vcr-dock-active = 48px collapsed bar
 * vcr-dock-expanded = 172px expanded sidebar */
@media (min-width: 769px) {
    body.vcr-rankings-page.vcr-dock-active,
    body.vcr-rankings-page.vcr-dock-expanded {
        padding-right: 0 !important;
    }

    body.vcr-dock-active .vcr-rankings {
        --rk-dock-space: 48px;
    }
    body.vcr-dock-expanded .vcr-rankings {
        --rk-dock-space: 172px;
    }
}

.vcr-rk__loading,
.vcr-rk__board-loading {
    display: flex; align-items: center; gap: 10px;
    color: var(--rk-text-dim);
    padding: 40px 0;
    justify-content: center;
}

.vcr-rk__spinner {
    width: 22px; height: 22px;
    border: 3px solid var(--rk-border);
    border-top-color: var(--rk-accent);
    border-radius: 50%;
    animation: vcr-rk-spin 0.8s linear infinite;
}
@keyframes vcr-rk-spin { to { transform: rotate(360deg); } }

.vcr-rk__error {
    background: #3a1414;
    border: 1px solid #6e2020;
    color: #ffb4b4;
    padding: 12px 16px;
    border-radius: 8px;
}

.vcr-rk__topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.vcr-rk__title {
    margin: 0 !important;
    padding: 0 !important;
    color: var(--rk-text) !important;
    font-size: 24px !important;
    font-weight: 800 !important;
}
.vcr-rk__subtitle {
    margin: 4px 0 0;
    color: var(--rk-text-dim);
    font-size: 13px;
}
.vcr-rk__nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px solid var(--rk-accent);
    background: rgba(247,129,102,0.12);
    color: #ffd7cc !important;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none !important;
    white-space: nowrap;
}
.vcr-rk__nav-btn:hover {
    background: var(--rk-accent);
    color: #0d1117 !important;
}

/* ============ Filtri ============ */
.vcr-rk__filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 18px;
    align-items: end;
    background: var(--rk-bg-2);
    border: 1px solid var(--rk-border);
    border-radius: var(--rk-radius);
    padding: 14px 16px;
    margin-bottom: 12px;
}

.vcr-rk__filter {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 130px;
}
.vcr-rk__filter > span {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--rk-text-dim);
}
.vcr-rk__filter select {
    background: var(--rk-bg-3);
    color: var(--rk-text);
    border: 1px solid var(--rk-border);
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 14px;
    min-width: 120px;
    cursor: pointer;
}
.vcr-rk__filter select:focus {
    outline: none;
    border-color: var(--rk-accent);
}

.vcr-rk__filter--toggle {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.vcr-rk__filter--toggle input { accent-color: var(--rk-vcr); cursor: pointer; }
.vcr-rk__badge-vcr {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    letter-spacing: 0.08em;
    background: rgba(255,82,82,0.12);
    color: #ff8a8a;
    border: 1px solid #6b2424;
    font-weight: 700;
    text-transform: uppercase;
}
.vcr-rk__filter--toggle input:checked + .vcr-rk__badge-vcr {
    background: var(--rk-vcr);
    color: #fff;
    border-color: var(--rk-vcr);
}

/* ============ Track picker ============ */
.vcr-rk__track-bar {
    margin-bottom: 12px;
}
.vcr-rk__filter--track {
    width: 100%;
    max-width: 420px;
    min-width: 220px;
}
.vcr-rk__filter--track select { font-size: 16px; padding: 10px 12px; }

/* ============ Hero pista (compatto) ============ */
.vcr-rk__hero {
    background: var(--rk-bg-2);
    border: 1px solid var(--rk-border);
    border-radius: var(--rk-radius);
    padding: 12px 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.vcr-rk__hero-name {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    flex: 1 1 auto;
    min-width: 180px;
}
.vcr-rk__hero-media {
    display: flex;
    gap: 10px;
    flex: 0 0 auto;
    align-items: center;
}
.vcr-rk__hero-pic, .vcr-rk__hero-layout {
    background: var(--rk-bg-3);
    border-radius: 6px;
    overflow: hidden;
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.vcr-rk__hero-pic { width: 170px; }
.vcr-rk__hero-layout { width: 130px; background: #fff; padding: 6px; border: 1px solid rgba(255,255,255,.85); }
.vcr-rk__hero-pic img,
.vcr-rk__hero-layout img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}
.vcr-rk__hero-layout img { background: #fff; }
@media (max-width: 720px) {
    .vcr-rk__hero { padding: 10px 12px; }
    .vcr-rk__hero-pic { width: 140px; height: 80px; }
    .vcr-rk__hero-layout { width: 110px; height: 80px; }
    .vcr-rk__hero-name { font-size: 16px; }
}

/* ============ Tabs categoria ============ */
.vcr-rk__tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--rk-border);
    padding-bottom: 0;
}
.vcr-rk__tab {
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    color: var(--rk-text-dim);
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    transition: background 0.15s, color 0.15s;
}
.vcr-rk__tab:hover { background: var(--rk-bg-2); color: var(--rk-text); }
.vcr-rk__tab.is-active {
    background: var(--rk-bg-2);
    color: var(--rk-accent);
    border-color: var(--rk-border);
    border-bottom-color: var(--rk-bg-2);
    margin-bottom: -1px;
}

/* ============ Meta + tabella ============ */
.vcr-rk__meta {
    display: flex;
    gap: 8px;
    align-items: center;
    color: var(--rk-text-dim);
    font-size: 13px;
    margin: 12px 4px;
}
.vcr-rk__meta-count { font-weight: 700; color: var(--rk-text); }
.vcr-rk__meta-sep { opacity: 0.5; }

.vcr-rk__empty {
    padding: 40px;
    text-align: center;
    color: var(--rk-text-dim);
    font-style: italic;
    background: var(--rk-bg-2);
    border-radius: 8px;
}

.vcr-rk__table-wrap {
    width: 100%;
    overflow-x: hidden;
}

.vcr-rk__table {
    width: 100%;
    border-collapse: collapse;
    background: var(--rk-bg-2);
    border-radius: var(--rk-radius);
    overflow: hidden;
    font-size: 14px;
    table-layout: auto;
}
.vcr-rk__table th,
.vcr-rk__table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--rk-border);
    white-space: nowrap;
}
.vcr-rk__td-driver,
.vcr-rk__td-car,
.vcr-rk__th-driver,
.vcr-rk__th-car {
    white-space: normal;
    word-break: break-word;
}

.vcr-rk__table thead th {
    background: var(--rk-bg-3);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--rk-text-dim);
    font-weight: 700;
    border-bottom: 2px solid var(--rk-border);
    position: sticky;
    top: 0;
}
.vcr-rk__table tbody tr:hover { background: rgba(255,255,255,0.03); }
.vcr-rk__table tbody tr:last-child td { border-bottom: none; }

/* Logged-in user row highlight */
.vcr-rk__table tbody tr.is-current-user {
    background: linear-gradient(90deg, rgba(247,129,102,0.18), rgba(247,129,102,0.04) 60%, transparent);
    box-shadow: inset 3px 0 0 var(--rk-accent);
}
.vcr-rk__table tbody tr.is-current-user:hover {
    background: linear-gradient(90deg, rgba(247,129,102,0.25), rgba(247,129,102,0.06) 60%, transparent);
}
.vcr-rk__table tbody tr.is-current-user .vcr-rk__td-driver {
    color: #fff;
}
.vcr-rk__table tbody tr.is-current-user .vcr-rk__td-driver::after {
    content: "YOU";
    display: inline-block;
    margin-left: 8px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--rk-accent);
    color: #1a1a1a;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    vertical-align: middle;
}

.vcr-rk__th-pos    { width: 44px;  text-align: center !important; }
.vcr-rk__th-best   { font-variant-numeric: tabular-nums; }
.vcr-rk__th-gap    { font-variant-numeric: tabular-nums; }
.vcr-rk__th-split  { font-variant-numeric: tabular-nums; width: 64px; }

.vcr-rk__td-pos {
    text-align: center;
    font-weight: 700;
    color: var(--rk-text-dim);
}
.vcr-rk__td-pos--p1 { color: #ffd24a; }
.vcr-rk__td-pos--p2 { color: #c0c0c0; }
.vcr-rk__td-pos--p3 { color: #cd7f32; }

.vcr-rk__td-best {
    font-weight: 700;
    color: #fff;
    font-variant-numeric: tabular-nums;
}
.vcr-rk__td-gap {
    color: var(--rk-text-dim);
    font-variant-numeric: tabular-nums;
}
.vcr-rk__td-split { font-variant-numeric: tabular-nums; }

.vcr-rk__td-driver { font-weight: 600; color: var(--rk-text); }
.vcr-rk__mobile-car-inline { display: none; }
.vcr-rk__td-driver .vcr-rk__driver-vcr {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--rk-vcr);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    vertical-align: middle;
}

.vcr-rk__td-cond--wet { color: #4cc4ff; font-weight: 600; }
.vcr-rk__td-cond--dry { color: var(--rk-text-dim); }

.vcr-rk__td-sess--R { color: #ff8a8a; font-weight: 600; }
.vcr-rk__td-sess--Q { color: #f6c84a; font-weight: 600; }
.vcr-rk__td-sess--FP{ color: var(--rk-text-dim); }

.vcr-rk__td-plat {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--rk-text-dim);
    font-weight: 700;
}

.vcr-rk__mobile-details {
    display: none;
}

/* ============ Responsive: hide non-essential columns progressively ============
   Column order:
   1=#  2=Driver  3=Plat  4=Car  5=Best  6=Gap  7=S1  8=S2  9=S3  10=Cond  11=Sess  12=Date
*/
@media (max-width: 1280px) {
    /* hide Date */
    .vcr-rk__table th:nth-child(12),
    .vcr-rk__table td:nth-child(12) { display: none; }
}
@media (max-width: 1100px) {
    /* hide Cond */
    .vcr-rk__table th:nth-child(10),
    .vcr-rk__table td:nth-child(10) { display: none; }
}
@media (max-width: 960px) {
    /* hide Plat + Sess */
    .vcr-rk__table th:nth-child(3),
    .vcr-rk__table td:nth-child(3),
    .vcr-rk__table th:nth-child(11),
    .vcr-rk__table td:nth-child(11) { display: none; }
}
@media (max-width: 780px) {
    /* Mobile: show Ranking, Driver(+Car), Best Lap.
       Details open below the row on click/tap. */
    .vcr-rk__table th:nth-child(7),
    .vcr-rk__table td:nth-child(7),
    .vcr-rk__table th:nth-child(8),
    .vcr-rk__table td:nth-child(8),
    .vcr-rk__table th:nth-child(9),
    .vcr-rk__table td:nth-child(9),
    .vcr-rk__table th:nth-child(3),
    .vcr-rk__table td:nth-child(3),
    .vcr-rk__table th:nth-child(4),
    .vcr-rk__table td:nth-child(4),
    .vcr-rk__table th:nth-child(6),
    .vcr-rk__table td:nth-child(6),
    .vcr-rk__table th:nth-child(10),
    .vcr-rk__table td:nth-child(10),
    .vcr-rk__table th:nth-child(11),
    .vcr-rk__table td:nth-child(11),
    .vcr-rk__table th:nth-child(12),
    .vcr-rk__table td:nth-child(12) { display: none; }

    /* Mobile layout: do not use table column calculation.
       Each row becomes a 3-column grid: Ranking | Driver(+Car) | Best Lap. */
    .vcr-rk__table,
    .vcr-rk__table thead,
    .vcr-rk__table tbody {
        display: block;
        width: 100%;
    }
    .vcr-rk__table thead tr,
    .vcr-rk__table tbody tr[data-rk-row] {
        display: grid;
        grid-template-columns: 38px minmax(0, 1fr) 96px;
        align-items: start;
        width: 100%;
    }
    .vcr-rk__table th,
    .vcr-rk__table td {
        display: none !important;
        border-bottom: 1px solid var(--rk-border);
    }
    .vcr-rk__table th:nth-child(1),
    .vcr-rk__table td:nth-child(1),
    .vcr-rk__table th:nth-child(2),
    .vcr-rk__table td:nth-child(2),
    .vcr-rk__table th:nth-child(5),
    .vcr-rk__table td:nth-child(5) {
        display: block !important;
        min-width: 0;
    }
    .vcr-rk__table th:nth-child(1),
    .vcr-rk__table td:nth-child(1) {
        grid-column: 1;
        width: 38px;
        text-align: center !important;
        padding-left: 4px;
        padding-right: 4px;
    }
    .vcr-rk__table th:nth-child(2),
    .vcr-rk__table td:nth-child(2) {
        grid-column: 2;
        width: auto;
    }
    .vcr-rk__table th:nth-child(5),
    .vcr-rk__table td:nth-child(5) {
        grid-column: 3;
        width: 96px;
        text-align: right;
    }
    .vcr-rk__td-best {
        font-size: 13px;
        white-space: nowrap;
        vertical-align: top;
    }
    .vcr-rk__td-driver {
        vertical-align: top;
        overflow-wrap: anywhere;
    }
    .vcr-rk__mobile-car-inline {
        display: block;
        margin-top: 2px;
        color: var(--rk-text-dim);
        font-size: 11px;
        font-weight: 500;
        line-height: 1.25;
    }

    .vcr-rk__table tbody tr[data-rk-row] {
        cursor: pointer;
    }
    .vcr-rk__table tbody tr[data-rk-row].is-expanded {
        background: rgba(255,255,255,0.04);
    }
    .vcr-rk__table tbody tr[data-rk-row] .vcr-rk__td-driver::before {
        content: "⌄";
        display: inline-block;
        margin-right: 6px;
        color: var(--rk-text-dim);
        transform: translateY(-1px);
    }
    .vcr-rk__table tbody tr[data-rk-row].is-expanded .vcr-rk__td-driver::before {
        content: "⌃";
    }

    .vcr-rk__mobile-details:not([hidden]) {
        display: block;
        width: 100%;
    }
    .vcr-rk__mobile-details td {
        display: block !important;
        padding: 0 8px 12px 8px;
        background: rgba(255,255,255,0.03);
        border-bottom: 1px solid var(--rk-border);
        width: 100% !important;
        max-width: none !important;
        text-align: left !important;
        white-space: normal !important;
    }
    .vcr-rk__mobile-details-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding: 10px;
        border-radius: 8px;
        background: rgba(0,0,0,0.18);
    }
    .vcr-rk__mobile-detail-item {
        display: flex;
        flex-direction: column;
        gap: 2px;
        min-width: 0;
    }
    .vcr-rk__mobile-detail-label {
        color: var(--rk-text-dim);
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: .06em;
    }
    .vcr-rk__mobile-detail-item strong {
        color: var(--rk-text);
        font-size: 12px;
        font-weight: 700;
    }
}
@media (max-width: 720px) {
    .vcr-rankings { padding: 16px 12px; }
    .vcr-rk__filter { min-width: 110px; }
    .vcr-rk__filter select { min-width: 100px; font-size: 13px; }
    .vcr-rk__hero-name { font-size: 17px; }
    .vcr-rk__table { font-size: 13px; }
    .vcr-rk__table th, .vcr-rk__table td { padding: 9px 5px; }
}
@media (max-width: 540px) {
    .vcr-rk__mobile-details-grid {
        grid-template-columns: 1fr 1fr;
    }
}
