:root {
    --bg: #0d0d0d;
    --bg-2: #161616;
    --bg-3: #1e1e1e;
    --border: #2a2a2a;
    --text: #f0f0f0;
    --dim: #666;
    --accent: #e10600;
    --green: #00c853;
    --yellow: #ffd600;
    --purple: #d500f9;
    --blue: #2979ff;
    --header-h: 60px;
    --nav-h: 44px;
}

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

html, body { height: 100%; }

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    overflow: hidden;
}

/* ── HEADER ── */
.header {
    height: var(--header-h);
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 20px;
}

.event-name {
    font-size: 1.2em;
    font-weight: 700;
    color: var(--text);
}

.session-name {
    font-size: 0.85em;
    color: var(--dim);
    margin-top: 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
}
.race-countdown {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.2;
}
.race-countdown.hidden { display: none; }
.countdown-label { display: block; font-size: 0.7em; color: var(--dim); text-transform: uppercase; letter-spacing: 0.05em; text-align: center; white-space: nowrap; }
.countdown-value { display: block; font-size: 1.4em; font-weight: 700; font-variant-numeric: tabular-nums; color: #fff; }

/* ── Streckenstatus Flagge ───────────────────────────────────────────────── */

.track-status-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}
.track-status-label {
    font-size: 0.7em;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
.track-flag {
    width: 100px;
    height: 26px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.95em;
    position: relative;
    overflow: hidden;
    background: var(--bg-3);
    border: 1px solid var(--border);
}
.track-flag[data-state="0"] { background: #1db954; border-color: #1db954; color: #fff; }
.track-flag[data-state="1"] { background: #f5c400; border-color: #f5c400; color: #000; }
.track-flag[data-state="2"] { background: #f5c400; border-color: #f5c400; color: #000; }
.track-flag[data-state="3"] { background: #e10600; border-color: #e10600; color: #fff; }
.track-flag[data-state="4"] {
    background: #e5007d;
    border-color: #e5007d;
    color: #fff;
}

.track-info {
    font-size: 0.85em;
    color: #fff;
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.4;
}

.weather-display {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.85em;
    color: #fff;
    text-align: right;
    line-height: 1.4;
    min-width: 90px;
}
.weather-display.hidden { display: none; }
.weather-main { display: flex; gap: 8px; }
.weather-temp { }
.weather-wind { }
.weather-desc { }

.pill {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: 600;
    white-space: nowrap;
}

.pill--connected { background: #1a3a1a; color: var(--green); }
.pill--disconnected { background: #3a1a1a; color: var(--accent); }
.pill--connecting { background: #2a2a1a; color: var(--yellow); }

/* ── TABS ── */
.tab-nav {
    height: var(--nav-h);
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 4px;
    padding: 6px 16px 0;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--dim);
    padding: 6px 18px;
    cursor: pointer;
    font-size: 0.9em;
    border-bottom: 2px solid transparent;
    border-radius: 4px 4px 0 0;
    transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

/* ── TAB CONTENT ── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── LEADERBOARD TABLE ── */
.table-wrap {
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}
.table-wrap::-webkit-scrollbar { height: 4px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }

.timing-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.95em;
}

.timing-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-3);
    color: var(--dim);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8em;
    letter-spacing: 0.05em;
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.timing-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.timing-table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}

.timing-table tbody tr:hover { background: var(--bg-3); }

/* Columns */
.col-pos { width: 44px; text-align: center; }
.col-delta { width: 28px; text-align: center; }
.col-car { width: 56px; }
.col-best, .col-last, .col-gap, .col-interval { font-variant-numeric: tabular-nums; }
.col-laps { }

.cell-pos {
    font-size: 1.1em;
    font-weight: 700;
    text-align: center;
}

.cell-pos.p1 { color: #ffd700; }
.cell-pos.p2 { color: #c0c0c0; }
.cell-pos.p3 { color: #cd7f32; }

.cell-car {
    font-weight: 700;
    font-size: 1.15em;
    color: var(--text);
}

.cell-team { width: 180px; max-width: 180px; }
.cell-team > div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.team-name-row { min-width: 0; }
.team-name-row .team-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }

.cell-best { color: #fff; font-weight: 600; }

.best-overall { color: var(--purple) !important; }

.interval-time { font-size: 0.8em; color: var(--text-muted, #aaa); }

.last-improved { color: var(--green); font-weight: 600; }

.delta-up { color: var(--green); font-size: 0.65em; vertical-align: middle; margin-left: 2px; }
.delta-down { color: var(--accent); font-size: 0.65em; vertical-align: middle; margin-left: 2px; }

.empty-state {
    text-align: center;
    color: var(--dim);
    padding: 40px;
}

/* ── SECTORS TAB ── */
#sectors-container {
    padding: 0;
}

.sectors-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}

.sectors-table th {
    background: var(--bg-3);
    color: var(--dim);
    font-size: 0.8em;
    text-transform: uppercase;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.sectors-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

.sector-best { background: #2a0036; color: var(--purple); font-weight: 700; }

/* ── OVERLAY ── */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.overlay.hidden { display: none; }

.overlay-panel {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: min(700px, 95vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.overlay-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-3);
}

.overlay-car-no {
    font-size: 1.6em;
    font-weight: 800;
    color: #fff;
    margin-right: 12px;
}

.overlay-team { font-size: 1.15em; color: var(--text); font-weight: 700; }
.overlay-car-info { font-size: 0.85em; color: var(--text-muted, #aaa); margin-top: 2px; }

#detail-mfr-logo img { height: 28px; width: auto; margin-right: 12px; vertical-align: middle; }

.overlay-header-info {
    display: flex;
    align-items: center;
    gap: 4px;
}

.overlay-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.star-btn {
    background: none;
    border: none;
    color: var(--dim);
    cursor: pointer;
    font-size: 1.4em;
    line-height: 1;
    padding: 4px 8px;
    transition: color 0.15s;
}

.star-btn:hover { color: var(--yellow); }
.star-btn.star-active { color: var(--yellow); }

.close-btn {
    background: none;
    border: none;
    color: var(--dim);
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
    padding: 4px 8px;
}

.close-btn:hover { color: var(--text); }

.overlay-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.overlay-body h3 {
    margin-bottom: 12px;
    font-size: 0.9em;
    text-transform: uppercase;
    color: var(--dim);
    letter-spacing: 0.05em;
}

.detail-stats {
    display: flex;
    gap: 24px;
    margin-bottom: 16px;
    font-size: 0.9em;
    color: var(--dim);
}

.detail-stats strong {
    color: var(--text);
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.history-table th {
    color: var(--dim);
    font-size: 0.8em;
    text-transform: uppercase;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.history-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

.history-best { color: var(--purple); font-weight: 700; }

.delta-negative { color: var(--green); }
.delta-positive { color: var(--accent); }

/* ── STATUS BAR ── */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 28px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 20px;
    font-size: 0.78em;
    color: var(--dim);
    z-index: 10;
}

.dim { color: var(--dim); }
.track-info .dim { color: #fff; }

main {
    height: calc(100dvh - var(--header-h) - var(--nav-h) - 28px);
    overflow: auto;
}

.cell-class { padding-left: 4px; padding-right: 4px; }
.col-class { width: 160px; white-space: nowrap; padding-left: 4px; padding-right: 8px; }

.class-badge {
    display: inline-block;
    padding: 1px 6px;
    background: #1a2a3a;
    border-radius: 3px;
    font-size: 0.78em;
    color: #7eb8f7;
    white-space: nowrap;
}

/* SP 9 family (GT3) – rot */
.class-badge[data-class^="SP 9"]  { background: #3a0a0a; color: #ff5555; }
/* SP 10 (GT4) – orange */
.class-badge[data-class^="SP 10"] { background: #3a1a00; color: #ff8c00; }
/* SP 8 – gelb */
.class-badge[data-class^="SP 8"]  { background: #2a2000; color: #ffd600; }
/* SP 7 – grün */
.class-badge[data-class^="SP 7"]  { background: #0a2a0a; color: #00c853; }
/* SP 6 – türkis */
.class-badge[data-class^="SP 6"]  { background: #0a2a2a; color: #00bcd4; }
/* SP 5 – lila */
.class-badge[data-class^="SP 5"]  { background: #1a0a2a; color: #d500f9; }
/* SP 4 / SP 3 / SP 2 – blau (Standard) */
.class-badge[data-class^="SP 4"],
.class-badge[data-class^="SP 3"],
.class-badge[data-class^="SP 2"]  { background: #1e3a5f; color: #7eb8f7; }
/* Cup-Klassen – gold */
.class-badge[data-class*="Cup"]   { background: #2a2200; color: #ffc107; }

.team-name { font-size: 0.92em; color: #b0b8c8; margin-top: 3px; font-weight: 600; }
.pro-badge { font-size: 0.75em; color: var(--dim); vertical-align: middle; margin-left: 4px; }
.car-model  { font-size: 0.78em; }

/* ── MANUFACTURER BADGES ── */
.mfr-logo {
    height: 32px;
    width: auto;
    max-width: 80px;
    object-fit: contain;
    flex-shrink: 0;
}

.mfr-logo--invert { filter: invert(1); }

.team-name-row {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 3px;
}

.mfr-badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.72em;
    font-weight: 800;
    letter-spacing: 0.06em;
    white-space: nowrap;
    background: #1a1a1a;
    color: #888;
    text-transform: uppercase;
}

.mfr-porsche      { color: #c8a84b; }
.mfr-bmw          { color: #1c69d4; }
.mfr-mercedes-amg { color: #00adef; }
.mfr-mercedes     { color: #00adef; }
.mfr-audi         { color: #dd0a30; }
.mfr-ferrari      { color: #ff2800; }
.mfr-lamborghini  { color: #c4a840; }
.mfr-ford         { color: #5b9bd5; }
.mfr-mclaren      { color: #ff8000; }
.mfr-aston-martin { color: #00a89c; }
.mfr-toyota       { color: #eb0a1e; }
.mfr-hyundai      { color: #7fb3e8; }
.mfr-volkswagen   { color: #7eb8f7; }
.mfr-subaru       { color: #6fa8dc; }
.mfr-cupra        { color: #c8823a; }
.mfr-ktm          { color: #ff6600; }
.mfr-opel         { color: #e2001a; }
.mfr-dacia        { color: #6ba8e5; }
.mfr-renault      { color: #ffcc00; }
.mfr-honda        { color: #e40521; }
.mfr-seat         { color: #999; }
.mfr-alfa         { color: #cc2222; }
.mfr-mini         { color: #8ab4f8; }
.mfr-bentley      { color: #5b7940; }
.mfr-chevrolet    { color: #d4af37; }
.mfr-nissan       { color: #c3122f; }
.mfr-ginetta      { color: #e87722; }
.mfr-hwa          { color: #aaa; }

.col-status { width: 46px; text-align: center; padding: 0 4px; }
.cell-status { text-align: center; padding: 0 4px; }

.status-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.75em;
    font-weight: 700;
    white-space: nowrap;
}
.status-pit    { background: var(--accent); color: #fff; }
.status-dnf    { color: #fff; }
.status-finish { background: #fff; color: #000; }


.cell-mfr { text-align: center; vertical-align: middle; padding: 0 8px; white-space: nowrap; }

@media (max-width: 700px) {
    /* Header kompakter */
    .header { padding: 0 12px; gap: 8px; }
    .track-info { display: none; }
    .event-name { font-size: 1em; }


    /* Tab-Nav scrollbar wenn nötig */
    .tab-nav { overflow-x: auto; gap: 2px; padding: 6px 8px 0; }
    .tab-btn { padding: 6px 12px; font-size: 0.85em; white-space: nowrap; }

    /* Tabelle horizontal scrollbar statt Spalten ausblenden */
    .timing-table { width: max-content; min-width: 100%; }
    .timing-table td, .timing-table th { padding: 7px 6px; }
    .cell-team { width: auto; max-width: 140px; }
    .col-class { width: auto; }
    .class-badge { font-size: 0.72em; padding: 1px 4px; }

    /* Overlay: mehr Platz auf kleinen Screens */
    .overlay-panel { max-height: 95dvh; }
    .overlay-body { padding: 14px; }

    /* Status bar kleiner */
    .status-bar { font-size: 0.72em; padding: 0 10px; gap: 12px; }
}

@media (max-width: 700px) and (orientation: portrait) {
    .event-name, .session-name, .track-info { display: none; }
    .header-left > div:first-child { display: none; }
    .header-left { gap: 12px; }
    .header { padding: 0 10px; }
}

/* ── Klassen-Filter Dropdown ─────────────────────────────────────────────── */

.filterable-th {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.filterable-th:hover { color: #fff; }
.filter-active { color: var(--accent) !important; }

.class-dropdown {
    position: absolute;
    z-index: 1000;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 0;
    min-width: 160px;
    max-height: 500px;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.class-dropdown.hidden { display: none; }

.class-dropdown-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.9em;
}
.class-dropdown-option:hover { background: var(--bg-2); }
.class-dropdown-option input { cursor: pointer; accent-color: var(--accent); }
