/* LFS Stats Viewer - Main Stylesheet */

/* =========================================================
   CSS Custom Properties (Theme Variables)
   :root = dark theme (default)
   [data-theme="light"] = light theme overrides
   ========================================================= */
:root {
    /* Backgrounds */
    --bg-body:           #1a1a1a;
    --bg-card:           #2a2a2a;
    --bg-card-alt:       #333333;
    --bg-chat:           #222222;
    --bg-summary:        linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #1a1a2e 100%);
    --bg-heatmap-sticky: #121212;
    --bg-input:          #1a1a2e;

    /* Semi-transparent surfaces */
    --surface-04:  rgba(255,255,255,0.04);
    --surface-06:  rgba(255,255,255,0.06);
    --surface-08:  rgba(255,255,255,0.08);
    --surface-10:  rgba(255,255,255,0.10);
    --surface-15:  rgba(255,255,255,0.15);

    /* Text */
    --text-primary: #e0e0e0;
    --text-muted:   #888888;
    --text-subtle:  #999999;
    --text-faint:   #666666;
    --text-40: rgba(255,255,255,0.40);
    --text-55: rgba(255,255,255,0.55);
    --text-70: rgba(255,255,255,0.70);
    --text-80: rgba(255,255,255,0.80);
    --text-legend: #cccccc;

    /* Borders */
    --border-main:    #444444;
    --border-subtle:  rgba(255,255,255,0.08);
    --border-subtle2: rgba(255,255,255,0.10);
    --border-chat:    #333333;

    /* Graph legend */
    --graph-legend-bg:     #333333;
    --graph-legend-border: #555555;

    /* Misc */
    --drop-zone-border: #555555;
    --table-even:       #333333;
    --footer-border:    rgba(255,255,255,0.05);

    /* LFS colored names */

    /* Chart title color (matches getChartColors().chartTitleColor) */
    --chart-title-color: #FFD700;

    /* Header */
    --header-bg: linear-gradient(160deg, #0f0c29 0%, #302b63 50%, #24243e 100%);

    /* Theme toggle button */
    --toggle-bg:     #2a2a2a;
    --toggle-border: #444444;
    --toggle-hover:  #333333;
}

[data-theme="light"] {
    --bg-body:           #9c9c9c;
    --bg-card:           #e4e4e4;
    --bg-card-alt:       #d4d4d4;
    --bg-chat:           #a4a4a4;
    --bg-summary:        linear-gradient(135deg, #c8c8c8 0%, #babdc0 50%, #cfcfcf 100%);
    --bg-heatmap-sticky: #959595;
    --bg-input:          #aaaaaa;

    --surface-04:  rgba(0,0,0,0.03);
    --surface-06:  rgba(0,0,0,0.04);
    --surface-08:  rgba(0,0,0,0.06);
    --surface-10:  rgba(0,0,0,0.07);
    --surface-15:  rgba(0,0,0,0.10);

    --text-primary: #1a1a1a;
    --text-muted:   #444444;
    --text-subtle:  #555555;
    --text-faint:   #666666;
    --text-40: rgba(0,0,0,0.40);
    --text-55: rgba(0,0,0,0.50);
    --text-70: rgba(0,0,0,0.65);
    --text-80: rgba(0,0,0,0.75);
    --text-legend: #555555;

    --border-main:    #888888;
    --border-subtle:  rgba(0,0,0,0.12);
    --border-subtle2: rgba(0,0,0,0.15);
    --border-chat:    #909090;

    --graph-legend-bg:     #a0a0a0;
    --graph-legend-border: #888888;

    --drop-zone-border: #777777;
    --table-even:       #9a9a9a;
    --footer-border:    rgba(0,0,0,0.15);


    --chart-title-color: #1a1a1a;

    --header-bg: linear-gradient(160deg, #6a6a88 0%, #747498 50%, #686884 100%);

    --toggle-bg:     #aaaaaa;
    --toggle-border: #888888;
    --toggle-hover:  #9a9a9a;
}

/* =========================================================
   LFS Colored Names - text shadow for visibility
   ========================================================= */
/* LFS color classes — WCAG AA compliant */
.lfs-c0 { color: #000000; }
.lfs-c1 { color: #FF5555; }
.lfs-c2 { color: #00FF00; }
.lfs-c3 { color: #FFFF00; }
.lfs-c4 { color: #2276FF; }
.lfs-c5 { color: #FF44FF; }
.lfs-c6 { color: #00FFFF; }
.lfs-c7 { color: #FFFFFF; }
.lfs-c8 { color: #999999; }
.lfs-c9 { color: #BBBBBB; }

/* Dark theme: shadow on black text for visibility */
:root .lfs-name.lfs-c0 {
    text-shadow: 0 0 1px rgba(255,255,255,0.3), 0 0 4px rgba(255,255,255,0.3);
}

/* Light theme: shadow on white, yellow and cyan for visibility */
[data-theme="light"] .lfs-name.lfs-c7,
[data-theme="light"] .lfs-name.lfs-c3,
[data-theme="light"] .lfs-name.lfs-c6 {
    text-shadow: 0 0 1px rgba(0,0,0,0.4), 0 0 3px rgba(0,0,0,0.2);
}

/* Light theme: LFS colors — original palette */
[data-theme="light"] .lfs-c1 { color: #FF0000; }
[data-theme="light"] .lfs-c2 { color: #00FF00; }
[data-theme="light"] .lfs-c3 { color: #FFFF00; }
[data-theme="light"] .lfs-c4 { color: #0000FF; }
[data-theme="light"] .lfs-c5 { color: #FF00FF; }
[data-theme="light"] .lfs-c6 { color: #00FFFF; }
[data-theme="light"] .lfs-c7 { color: #FFFFFF; }
[data-theme="light"] .lfs-c8 { color: #666666; }
[data-theme="light"] .lfs-c9 { color: #888888; }

/* =========================================================
   Theme Toggle Button
   ========================================================= */
.theme-toggle-btn {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 9999;
    background: var(--toggle-bg);
    border: 1px solid var(--toggle-border);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    line-height: 1;
    padding: 0;
}
.theme-toggle-btn:hover {
    background: var(--toggle-hover);
    box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}

/* =========================================================
   Base Styles
   ========================================================= */
body {
    font-family: Arial, sans-serif;
    margin: 20px;
    background-color: var(--bg-body);
    color: var(--text-primary);
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 30px;
    padding: 0;
    background: var(--header-bg);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.08);
    overflow: hidden;
    position: relative;
}

.header::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, #237da0, #a855f7, #ec4899, #f59e0b);
}

.header h1 {
    margin: 0;
    color: white;
    font-size: 1.6em;
    letter-spacing: 0.5px;
}

.header-content {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: stretch;
    padding: 20px 24px;
    gap: 16px;
}

.header-logo-left {
    justify-self: start;
    align-self: stretch;
    display: flex;
    align-items: center;
}

.header-title {
    text-align: center;
    justify-self: center;
}

.header-center {
    text-align: center;
    justify-self: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.header-logo-right {
    justify-self: end;
    align-self: stretch;
    display: flex;
    align-items: center;
}

.track-subtitle {
    font-size: 15px;
    color: var(--text-55);
    margin-top: 4px;
    font-weight: 500;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.lfs-logo {
    height: 100%;
    max-height: 160px;
    width: auto;
    opacity: 0.9;
    filter: drop-shadow(0 2px 8px rgba(102,126,234,0.4));
    transition: opacity 0.2s;
    object-fit: contain;
}
.lfs-logo:hover {
    opacity: 1;
}

.custom-logo {
    height: 100%;
    max-height: 160px;
    width: auto;
    opacity: 0.9;
    filter: drop-shadow(0 2px 8px rgba(168,85,247,0.4));
    transition: opacity 0.2s;
    object-fit: contain;
}
.custom-logo:hover {
    opacity: 1;
}

.track-image {
    height: 120px;
    border-radius: 8px;
}

.race-info {
    padding: 12px 24px 8px;
    font-size: 13px;
    color: var(--text-70);
    line-height: 1.8;
}

.info-cards {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 4px 0;
}

.info-card {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 20px;
    font-size: 12.5px;
    color: rgba(255,255,255,0.8);
    white-space: nowrap;
}

.info-card .info-label {
    color: rgba(255,255,255,0.4);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mpr-download {
    color: #a78bfa !important;
    text-decoration: none;
    transition: color 0.2s;
}
.mpr-download:hover {
    color: #c4b5fd !important;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    border-bottom: 2px solid var(--border-main);
}

.tab {
    cursor: pointer;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-main);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    transition: all 0.3s;
    font-weight: 500;
    font-size: 13px;
    color: var(--text-primary);
}

.tab:hover {
    background: var(--bg-card-alt);
}

.tab.active {
    background: #237da0;
    color: white;
    border-color: #237da0;
    transform: translateY(2px);
}

/* Content */
.content {
    display: none;
    animation: fadeIn 0.3s;
}

.content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-main);
}

th {
    background: var(--bg-card-alt);
    font-weight: bold;
    position: sticky;
    top: 0;
}

tr:hover {
    background: var(--bg-card-alt);
}

tr:last-child td {
    border-bottom: none;
}

/* Compact Table */
.compact-table {
    font-size: 13px;
}

.compact-table td {
    padding: 8px;
}

/* Lap by Lap Table */
.lbl-table {
    font-size: 11px;
    width: auto;
    white-space: nowrap;
}

.lbl-table th {
    min-width: 70px;
}

.driver-name-header {
    font-size: 13px;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lbl-sticky-pos {
    position: sticky;
    left: 0;
    background: var(--bg-card);
    font-weight: bold;
    z-index: 2;
    min-width: 60px;
}

.lbl-sticky-driver {
    position: sticky;
    left: 60px;
    background: var(--bg-card);
    z-index: 2;
}

.lbl-sticky-header-pos {
    position: sticky;
    left: 0;
    background: var(--bg-card-alt);
    z-index: 3;
    min-width: 60px;
}

.lbl-sticky-header-driver {
    position: sticky;
    left: 60px;
    background: var(--bg-card-alt);
    z-index: 3;
}

.lap-cell {
    text-align: center;
    color: #000;
    min-width: 75px;
    font-size: 11px;
}

/* Position Cells */
.position {
    font-weight: bold;
    text-align: center;
}

.pos-1 { color: #FFD700; }
.pos-2 { color: #C0C0C0; }
.pos-3 { color: #CD7F32; }
.pos-4, .pos-5, .pos-6, .pos-7, .pos-8, .pos-9, .pos-10 { color: #F44336; }

/* Section Grid */
.section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(410px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.section-box {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #237da0;
    overflow-x: auto;
}

.section-box h3 {
    margin-top: 0;
    color: #237da0;
}

/* Graph Container */
#graph-container {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
}

#position-graph {
    display: block;
    margin: 0 auto;
    width: 100%;
    height: 800px;
    max-width: 100%;
}

/* Progress Graph Container */
#progress-graph-container {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
}

#progress-graph {
    display: block;
    margin: 0 auto;
    width: 100%;
    height: 700px;
    max-width: 100%;
}

/* Legend */
.legend {
    margin-top: 20px;
    padding: 15px;
    background: var(--bg-card);
    border-radius: 8px;
}

.legend h4 {
    margin-top: 0;
}

.legend-items {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-color-box {
    width: 50px;
    height: 20px;
}

/* Scrollable Container */
.scrollable-container {
    overflow-x: auto;
}

/* WR Info */
.wr-info {
    font-size: 12px;
    color: #FFD700;
    margin-bottom: 10px;
}

.wr-gap {
    color: var(--text-muted);
    font-size: 0.7em;
}



/* Highlight Colors */
.highlight-success {
    color: #4CAF50;
}

.highlight-warning {
    color: #FFA500;
}

.highlight-error {
    color: #F44336;
}

.highlight-info {
    color: #237da0;
}

/* Error Message */
.error-message {
    background: var(--bg-card);
    border-left: 4px solid #F44336;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    color: #F44336;
}

/* Links */
.link-primary {
    color: #237da0;
    text-decoration: none;
}

.link-primary:hover {
    text-decoration: underline;
}

.link-driver {
    color: #20F0C0;
    text-decoration: none;
    font-weight: bold;
}

.link-driver:hover {
    text-decoration: underline;
}

.car-link-with-image {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.car-thumbnail {
    height: 40px;
    width: auto;
    border-radius: 4px;
    vertical-align: middle;
}

/* Text Colors */
.text-success {
    color: #4CAF50;
    font-weight: bold;
}

.text-warning {
    color: #FFA500;
    font-weight: bold;
}

.text-error {
    color: #F44336;
    font-weight: bold;
}

.text-info {
    color: #2196F3;
    font-weight: bold;
}

.text-muted {
    color: var(--text-muted);
}

.text-gold {
    color: #FFD700;
}

.text-center {
    text-align: center;
}

/* Font Sizes */
.text-small {
    font-size: 12px;
}

/* Margins */
.mb-10 {
    margin-bottom: 10px;
}

.mb-15 {
    margin-bottom: 15px;
}

.mt-10 {
    margin-top: 10px;
}

.mt-20 {
    margin-top: 20px;
}

/* Padding */
.p-20 {
    padding: 20px;
}

/* Color Boxes for Legend */
.color-box-100 {
    background: #7070FF;
}

.color-box-101 {
    background: #20F0C0;
}

.color-box-102 {
    background: #A0F00F;
}

.color-box-103 {
    background: #FFFF70;
}

.color-box-105 {
    background: #FFA070;
}

.color-box-107 {
    background: #FF5090;
}

/* Empty State */
.empty-state {
    text-align: center;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    body {
        margin: 10px;
    }
    
    .section-grid {
        grid-template-columns: 1fr;
    }
    
    .header-content {
        grid-template-columns: 1fr;
        justify-items: center;
    }
    .header-logo-left, .header-logo-right {
        justify-self: center;
    }
    .lfs-logo, .custom-logo {
        height: 80px;
    }
    
    table {
        font-size: 12px;
    }
    
    th, td {
        padding: 8px;
    }
}

/* Show More Button */
.show-more-btn {
    display: block;
    margin: 15px auto 0;
    padding: 10px 20px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: solid 1px var(--border-main);
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.show-more-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.show-more-btn:active {
    transform: translateY(0);
}

/* Hidden rows */
.hidden-row {
    display: none;
}

/* Position Graph Legend */
.graph-legend {
    display: flex !important;
    justify-content: center;
    gap: 30px;
    margin-top: 15px;
    padding: 15px;
    background: var(--graph-legend-bg) !important;
    border: 2px solid var(--graph-legend-border);
    border-radius: 5px;
    font-size: 14px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background 0.2s, opacity 0.2s;
}

.legend-item:hover {
    background: var(--surface-10);
}

.legend-marker {
    font-weight: bold;
    font-size: 16px;
    min-width: 30px;
    text-align: center;
}

.pit-marker {
    color: #000000;
    background: #FFFFFF;
    border: 2px solid red;
    border-radius: 50%;
    width: 21px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
}

.dnf-marker {
    color: #FF0000;
}

.lapped-marker {
    color: var(--text-muted);
    letter-spacing: 2px;
}

.legend-text {
    color: var(--text-legend);
}

.personal-best-marker {
    color: #00FF00;
    font-size: 18px;
}

.fastest-lap-marker {
    color: #FFD700;
    font-size: 18px;
}

/* Chat Messages */
.chat-container {
    background: var(--bg-chat);
    border: 1px solid var(--border-main);
    border-radius: 8px;
    padding: 15px;
    max-height: 600px;
    overflow-y: auto;
}

.chat-count {
    text-align: right;
    font-size: 0.8em;
    color: var(--text-muted);
    margin-top: 8px;
    margin-bottom: 0;
}

.chat-message {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-chat);
    align-items: baseline;
}

.chat-message:last-child {
    border-bottom: none;
}

.chat-number {
    color: var(--text-faint);
    font-size: 11px;
    min-width: 30px;
    text-align: right;
}

.chat-driver {
    color: #FFD700;
    font-weight: bold;
    min-width: 150px;
}

.chat-text {
    color: var(--text-primary);
    flex: 1;
    word-wrap: break-word;
}

/* MPR Download Link */
.mpr-download {
    color: #4CAF50;
    text-decoration: none;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 3px;
    transition: all 0.2s;
}

.mpr-download:hover {
    color: #66BB6A;
    background: rgba(76, 175, 80, 0.1);
}

/* Host flag badges */
.flags-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    padding: 2px 0;
}
.flag-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    font-size: 11px;
    white-space: nowrap;
    color: rgba(255,255,255,0.7);
}

/* Relay/stint separator */
.relay-separator {
    color: var(--text-muted);
    margin: 0 2px;
}

/* Stint bar */
.stint-bar {
    display: flex;
    height: 24px;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}
.stint-bar div {
    transition: opacity 0.2s;
    cursor: default;
}
.stint-bar div:hover {
    opacity: 0.8;
}

/* Stints grid layout */
.stints-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(410px, 1fr));
    gap: 12px;
}

/* Allowed cars in header */
.allowed-cars-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    flex-wrap: wrap;
}
.allowed-car-img img {
    height: 70px;
    border-radius: 4px;
    transition: transform 0.2s;
}
.allowed-car-img img:hover {
    transform: scale(1.3);
}
.allowed-car-text {
    color: #ccc;
    font-size: 0.85em;
    text-decoration: none;
    padding: 2px 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}

/* Summary Card */
.summary-card {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    padding: 16px 20px;
    margin: 0 0 8px 0;
    background: var(--bg-summary);
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
}
.summary-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 10px 8px;
    background: var(--surface-04);
    border-radius: 6px;
    transition: background 0.2s;
}
.summary-stat[data-goto-tab] {
    cursor: pointer;
}
.summary-stat:hover {
    background: var(--surface-08);
}
.summary-stat .stat-icon {
    font-size: 1.4em;
    margin-bottom: 4px;
}
.summary-stat .stat-value {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--text-primary);
    line-height: 1.3;
}
.summary-stat .stat-value a {
    color: var(--text-primary);
    text-decoration: none;
}
.summary-stat .stat-value a:hover {
    text-decoration: underline;
}
.summary-stat .stat-label {
    font-size: 0.75em;
    color: var(--text-subtle);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.summary-stat .stat-detail {
    font-size: 0.8em;
    color: var(--text-legend);
    margin-top: 2px;
}
.summary-stat .stat-value.purple {
    color: #A855F7;
}
@media (max-width: 600px) {
    .summary-card {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 8px;
        padding: 10px 12px;
    }
    .summary-stat { padding: 8px 4px; }
    .summary-stat .stat-value { font-size: 1em; }
}

/* Compare */
.compare-selectors {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: var(--surface-04);
    border-radius: 8px;
}
.compare-select {
    flex: 1;
    min-width: 160px;
    padding: 8px 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--surface-15);
    border-radius: 6px;
    font-size: 0.9em;
    cursor: pointer;
}
.compare-select:focus {
    outline: none;
    border-color: #237da0;
}
.compare-vs {
    font-weight: bold;
    color: var(--text-muted);
    font-size: 0.9em;
}
.compare-btn {
    padding: 8px 20px;
    background: #237da0;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}
.compare-btn:hover {
    background: #1a6080;
}
.compare-table-wrap {
    overflow-x: auto;
    margin-bottom: 20px;
}
.compare-table {
    width: 100%;
    border-collapse: collapse;
}
.compare-table th, .compare-table td {
    padding: 8px 14px;
    text-align: center;
    border-bottom: 1px solid var(--surface-06);
}
.compare-table th {
    background: var(--surface-04);
    white-space: nowrap;
}
.compare-label {
    text-align: left !important;
    color: var(--text-subtle);
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.compare-best {
    color: #4CAF50 !important;
    font-weight: bold;
}
.compare-chart-wrap {
    height: 350px;
    margin-top: 16px;
}
@media (max-width: 600px) {
    .compare-selectors { flex-direction: column; }
    .compare-select { min-width: 100%; }
    .compare-vs { display: none; }
    .compare-chart-wrap { height: 250px; }
}

/* Custom Select (colored driver names) */
.csel {
    position: relative;
    flex: 1;
    min-width: 180px;
}
.csel-selected {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--surface-15);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    min-height: 20px;
    user-select: none;
    color: var(--text-primary);
}
.csel-selected:hover {
    border-color: #237da0;
}
.csel-arrow {
    color: var(--text-muted);
    margin-left: 8px;
    font-size: 0.8em;
}
.csel-text {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.csel-options {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-input);
    border: 1px solid var(--surface-15);
    border-radius: 0 0 6px 6px;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.csel-options.open {
    display: block;
}
.csel-option {
    padding: 6px 12px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.85em;
    transition: background 0.15s;
    color: var(--text-primary);
}
.csel-option:hover {
    background: var(--surface-10);
}
.csel-pos {
    display: inline-block;
    min-width: 28px;
    color: var(--text-muted);
    font-size: 0.85em;
}
@media (max-width: 600px) {
    .csel { min-width: 100%; }
}

/* Heatmap */
.heatmap-wrap {
    overflow-x: auto;
    margin-bottom: 12px;
}
.heatmap-table {
    border-collapse: separate;
    border-spacing: 1px;
    width: auto;
}
.heatmap-table thead th {
    background: var(--surface-06);
    padding: 4px 2px;
    font-size: 0.7em;
    color: var(--text-subtle);
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 2;
}
.heatmap-driver {
    position: sticky;
    left: 0;
    background: var(--bg-heatmap-sticky) !important;
    z-index: 3;
    white-space: nowrap;
    padding: 4px 8px !important;
    font-size: 0.8em;
    min-width: 140px;
}
thead .heatmap-driver {
    z-index: 4;
}
.heatmap-pos {
    display: inline-block;
    min-width: 24px;
    text-align: center;
    font-size: 0.8em;
    margin-right: 4px;
}
.heatmap-cell {
    width: 18px;
    min-width: 18px;
    max-width: 18px;
    height: 18px;
    padding: 0 !important;
    cursor: default;
    border-radius: 2px;
    position: relative;
}
.heatmap-cell.heatmap-fastest {
    box-shadow: inset 0 0 0 2px #A855F7;
}
.heatmap-cell.heatmap-pb {
    box-shadow: inset 0 0 0 2px #4CAF50;
}
.heatmap-cell.heatmap-pit::after {
    content: 'P';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: bold;
    color: rgba(0,0,0,0.7);
}
.heatmap-lap {
    min-width: 18px;
    max-width: 18px;
}
.heatmap-legend {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    padding: 8px 0;
    font-size: 0.8em;
    color: var(--text-subtle);
}
.heatmap-legend-fast { color: rgb(40,180,40); font-size: 1.3em; }
.heatmap-legend-mid { color: rgb(255,150,20); font-size: 1.3em; }
.heatmap-legend-slow { color: rgb(255,0,20); font-size: 1.3em; }
.heatmap-fastest-mark { color: #A855F7; font-size: 1.3em; }
.heatmap-pb-mark { color: #4CAF50; font-size: 1.3em; }
.heatmap-pit-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: #fff;
    color: #000;
    border-radius: 50%;
    font-size: 9px;
    font-weight: bold;
}
@media (max-width: 600px) {
    .heatmap-cell { width: 14px; min-width: 14px; max-width: 14px; height: 14px; }
    .heatmap-lap { min-width: 14px; max-width: 14px; }
    .heatmap-cell.heatmap-pit::after { font-size: 7px; }
}

/* Footer */
.site-footer {
    text-align: center;
    padding: 20px 10px;
    margin-top: 30px;
    color: var(--text-muted);
    font-size: 1em;
    border-top: 1px solid var(--footer-border);
}
.site-footer #exported-at {
    font-size: 0.8em;
    color: var(--text-faint);
    margin-top: 4px;
}

/* Podium colors - Results table only */
#results > table tr:has(.pos-1) { background: linear-gradient(90deg, rgba(255,215,0,0.25) 0%, transparent 100%); }
#results > table tr:has(.pos-2) { background: linear-gradient(90deg, rgba(192,192,192,0.25) 0%, transparent 100%); }
#results > table tr:has(.pos-3) { background: linear-gradient(90deg, rgba(205,127,50,0.25) 0%, transparent 100%); }
#results > table .pos-1,
#results > table .pos-2,
#results > table .pos-3 {
    color: white;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
    font-weight: bold;
}

/* File drop zone */
#file-drop-zone {
    border: 2px dashed var(--drop-zone-border);
    border-radius: 12px;
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    max-width: 500px;
    margin: 80px auto;
}
#file-drop-zone:hover,
#file-drop-zone.drag-over {
    border-color: #237da0;
    background: rgba(35, 125, 160, 0.1);
}
#file-drop-zone .drop-icon {
    font-size: 48px;
    margin-bottom: 16px;
}
#file-drop-zone h2 {
    margin: 0 0 12px 0;
    color: #fff;
}
#file-drop-zone p {
    margin: 4px 0;
    color: #ccc;
}

/* Pit stop details toggle */
.pit-details-toggle {
    cursor: pointer;
    color: #4fc3f7;
    float: right;
}
.pit-details-toggle .arrow {
    display: inline-block;
    transition: transform 0.2s;
    font-size: 0.8em;
}
.pit-details-toggle .arrow.open {
    transform: rotate(90deg);
}
.pit-details .compact-table {
    background: rgba(0,0,0,0.2);
}

.pit-details.hidden {
    display: none;
}

.pit-details {
    text-align: left;
    margin-top: 6px;
}

.hidden {
    display: none;
}

/* =========================================================
   Table Column Alignment
   ========================================================= */

/* Results: center all except Driver (col 2) and Car (col 3) */
#results th,
#results td {
    text-align: center;
}
#results td:nth-child(2),
#results th:nth-child(2),
#results td:nth-child(3),
#results th:nth-child(3) {
    text-align: left;
}

/* Overview: center all except driver (col 2) */
#overview th,
#overview td {
    text-align: center;
}
#overview tr td:nth-child(2),
#overview tr th:nth-child(2) {
    text-align: left;
}
#overview td.text-left,
#overview th.text-left {
    text-align: left;
}

/* Lap by Lap: center all */
#lbl .lbl-table th,
#lbl .lbl-table td {
    text-align: center;
}

/* Best Times: center all except driver (col 2) */
#best-times th,
#best-times td {
    text-align: center;
}
#best-times tr td:nth-child(2),
#best-times tr th:nth-child(2) {
    text-align: left;
}

/* Analysis: center all except driver (col 2), skip Lap Time Distribution */
#analysis .compact-table:not(.dist-table) th,
#analysis .compact-table:not(.dist-table) td {
    text-align: center;
}
#analysis .compact-table:not(.dist-table) tr td:nth-child(2),
#analysis .compact-table:not(.dist-table) tr th:nth-child(2) {
    text-align: left;
}

/* Incidents: center all except driver (col 2) */
#incidents th,
#incidents td {
    text-align: center;
}
#incidents tr td:nth-child(2),
#incidents tr th:nth-child(2) {
    text-align: left;
}

/* =========================================================
   Migrated Inline Styles
   (moved from stats_renderer.js — static styles only)
   ========================================================= */

/* File picker hint text */
.file-picker-hint {
    color: var(--text-muted);
    font-size: 0.85em;
}

/* Server name label in header */
.server-name-label {
    font-size: 11px;
    color: var(--text-40);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-top: 2px;
}

/* Driver summary h4 heading */
.driver-summary-heading {
    margin-top: 12px;
}

/* ── Tooltip rows ─────────────────────────────────────── */

.tooltip-header-gold {
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 8px;
    color: var(--chart-title-color);
}

.tooltip-header-white {
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 8px;
    color: #FFFFFF;
}

.tooltip-separator {
    border-top: 1px solid #444;
    margin: 8px 0 4px 0;
}

/* flex row with small gap, 3px margin */
.tooltip-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin: 3px 0;
}

/* flex row with small gap, 4px margin */
.tooltip-row-lg {
    display: flex;
    gap: 6px;
    align-items: center;
    margin: 4px 0;
}

/* Position-change arrows */
.tooltip-arrow-neutral {
    min-width: 16px;
    display: inline-block;
}
.tooltip-arrow-up {
    color: #00FF00;
    min-width: 16px;
    display: inline-block;
}
.tooltip-arrow-down {
    color: #FF4444;
    min-width: 16px;
    display: inline-block;
}

/* Pit icon (active / empty placeholder) */
.tooltip-pit-icon {
    min-width: 18px;
    display: inline-block;
    text-align: center;
}
.tooltip-pit-empty {
    min-width: 18px;
    display: inline-block;
}

/* Driver color swatch (background set inline) */
.tooltip-color-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* Static position text (used when posColor is fixed #888) */
.tooltip-pos-text {
    color: #888;
    min-width: 28px;
}

/* Driver name cells */
.tooltip-driver-name {
    flex: 1;
}
.tooltip-driver-name-wide {
    flex: 1;
    min-width: 150px;
}

/* Gap / best time cells */
.tooltip-gap-text {
    color: #AAA;
    font-size: 10px;
    min-width: 60px;
    text-align: right;
}
.tooltip-gap-wide {
    color: #CCC;
    text-align: right;
    min-width: 80px;
}

/* Stint driver label inside driver name */
.tooltip-stint-driver {
    color: #AAA;
    font-size: 10px;
}

/* Pit count label */
.tooltip-pit-count {
    color: #CCC;
    font-size: 10px;
}

/* ── Pit details panel (inline in HTML) ───────────────── */

.pit-summary-info {
    margin-bottom: 6px;
}
.pit-summary-pos-badge {
    margin-right: 6px;
}
.pit-details-table {
    margin: 0;
    font-size: 0.85em;
}

/* ── Compare tool ─────────────────────────────────────── */

.csel-placeholder {
    color: var(--text-muted);
}
.compare-empty {
    color: var(--text-muted);
    text-align: center;
}

/* ── Lap-time distribution section ───────────────────── */

.dist-section {
    margin-bottom: 20px;
}
.dist-table-mb {
    margin-bottom: 15px;
}
.dist-discarded-val {
    color: var(--text-muted);
}
.dist-col-note {
    font-size: 12px;
    color: var(--text-muted);
    padding-left: 20px;
}
.dist-fastest-val {
    color: #4CAF50;
}
.dist-slowest-val {
    color: #F44336;
}
.dist-histogram {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 5px;
}
.dist-histogram-title {
    margin: 0 0 10px 0;
    color: #FFD700;
}
.dist-histogram-subtitle {
    margin: 0 0 15px 0;
    font-size: 11px;
    color: var(--text-muted);
}
.dist-bucket {
    margin-bottom: 10px;
}
.dist-bucket-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.dist-bucket-label {
    width: 140px;
}
.dist-bucket-range {
    font-size: 11px;
    color: var(--text-primary);
    line-height: 1.2;
}
.dist-bucket-pct {
    font-size: 9px;
    color: var(--text-faint);
    line-height: 1;
}
.dist-bar-track {
    flex: 1;
    background: var(--bg-body);
    height: 24px;
    border-radius: 3px;
    position: relative;
}
.dist-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
    background: linear-gradient(90deg, #667eea, #764ba2);
}
.dist-bar-count {
    width: 40px;
    text-align: right;
    font-size: 12px;
    color: #fff;
}

/* ── Section spacing helpers ──────────────────────────── */

.section-grid-mt {
    margin-top: 20px;
}
.best-sectors-heading {
    margin-top: 30px;
}
