/* CSS Variables for Dark Theme (default) */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #252525;
    --bg-quaternary: rgba(40, 40, 40, 0.8);
    --bg-quinary: rgba(40, 40, 40, 0.5);
    --bg-hover: rgba(91, 163, 255, 0.15);
    --bg-modal: #1a1a1a;
    --bg-modal-header: #2d2d2d;
    --bg-tab-inactive: rgba(60, 60, 60, 0.7);
    --bg-tab-active: #1a1a1a;
    --bg-tab-hover: rgba(80, 80, 80, 0.9);
    --bg-chart: rgba(40, 40, 40, 0.5);
    --bg-chart-blend: #212121;
    --bg-gold: #4a3a1a;
    --bg-silver: #3a3a3a;
    --bg-bronze: #3d2e1a;
    
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-tertiary: #999;
    --text-white: #ffffff;
    --text-accent: #5ba3ff;
    --text-time: #ffffff;
    --text-rank: #5ba3ff;
    --text-error: #ff6b6b;
    --text-success: #27ae60;
    --text-tab-active: #ffffff;
    --text-tab-hover: #ffffff;
    
    --border-primary: #404040;
    --border-secondary: #505050;
    --border-accent: #0066cc;
    --border-tab: #0066cc;
    
    --header-gradient-start: #0066cc;
    --header-gradient-end: #003366;
    --header-overlay: rgba(255, 255, 255, 0.1);
    
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-light: rgba(0, 0, 0, 0.1);
}

/* CSS Variables for Light Theme */
[data-theme="light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #f0f0f0;
    --bg-tertiary: #f8f8f8;
    --bg-quaternary: rgba(240, 240, 240, 0.95);
    --bg-quinary: rgba(240, 240, 240, 0.5);
    --bg-hover: rgba(91, 163, 255, 0.1);
    --bg-modal: #f5f5f5;
    --bg-modal-header: #f0f0f0;
    --bg-tab-inactive: rgba(230, 230, 230, 0.7);
    --bg-tab-active: #f5f5f5;
    --bg-tab-hover: rgba(220, 220, 220, 0.9);
    --bg-chart: rgba(240, 240, 240, 0.5);
    --bg-chart-blend: #f0f0f0;
    --bg-gold: #fff8e1;
    --bg-silver: #f5f5f5;
    --bg-bronze: #fff3e0;
    
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-tertiary: #888888;
    --text-white: #ffffff;
    --text-accent: #0066cc;
    --text-time: #000000;
    --text-rank: #0066cc;
    --text-error: #d32f2f;
    --text-success: #2e7d32;
    --text-tab-active: #333333;
    --text-tab-hover: #333333;
    
    --border-primary: #e0e0e0;
    --border-secondary: #d0d0d0;
    --border-accent: #0066cc;
    --border-tab: #0066cc;
    
    --header-gradient-start: #0066cc;
    --header-gradient-end: #003366;
    --header-overlay: rgba(255, 255, 255, 0.2);
    
    --shadow: rgba(0, 0, 0, 0.15);
    --shadow-light: rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-tertiary) 100%);
    padding: 20px;
    min-height: 100vh;
    animation: pageLoad 0.5s ease-out;
    transition: background 0.3s ease;
}

@keyframes pageLoad {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    border-radius: 10px;
    box-shadow: 0 10px 30px var(--shadow);
    overflow: hidden;
    padding-left: 0 !important;
    padding-right: 0 !important;
    animation: containerSlideIn 0.6s ease-out;
    transition: box-shadow 0.08s ease, filter 0.08s ease;
}

/* Blur background when modal is open */
body.modal-open .container {
    filter: blur(4px);
    transition: filter 0.08s ease;
}

/* Ensure modal content is not blurred */
body.modal-open .modal {
    filter: none;
}

@keyframes containerSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Override Bootstrap container padding */
body > .container {
    padding-left: 0;
    padding-right: 0;
}

.header {
    background: repeating-linear-gradient(
                    0deg,
                    transparent,
                    transparent 40px,
                    var(--header-overlay) 40px,
                    var(--header-overlay) 80px
                ),
                repeating-linear-gradient(
                    90deg,
                    transparent,
                    transparent 40px,
                    var(--header-overlay) 40px,
                    var(--header-overlay) 80px
                ),
                linear-gradient(135deg, var(--header-gradient-start) 0%, var(--header-gradient-end) 100%);
    color: white;
    padding: 30px;
    text-align: center;
    position: relative;
    animation: headerFadeIn 0.8s ease-out;
    transition: background 0.3s ease;
}

.theme-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 64px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.theme-icon::before {
    content: "🌙";
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 1;
    transform: rotate(0deg);
}

[data-theme="light"] .theme-icon::before {
    content: "☀️";
    opacity: 1;
    transform: rotate(180deg);
}

[data-theme="light"] .theme-toggle {
    background: rgba(255, 255, 255, 0.25);
}

[data-theme="light"] .theme-toggle:hover {
    background: rgba(255, 255, 255, 0.35);
}

.theme-icon {
    transform: translateX(32px);
}

[data-theme="light"] .theme-icon {
    transform: translateX(0);
}

@keyframes headerFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.header .last-updated {
    font-size: 0.9em;
    opacity: 0.9;
}

.target-time-table {
    font-size: 1em;
    font-weight: 600;
    padding: 15px 20px;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.nav-tabs {
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border-tab);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--border-accent) var(--bg-secondary); /* Firefox: thumb and track */
    flex-wrap: nowrap;
    padding: 10px 10px 0 10px;
    margin: 0;
    margin-bottom: -2px;
    border-top: none;
    border-left: none;
    border-right: none;
    position: relative;
    box-shadow: inset 0 -2px 0 var(--border-tab);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.nav-tabs::-webkit-scrollbar {
    height: 8px; /* Chrome, Safari, Opera */
}

.nav-tabs::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

.nav-tabs::-webkit-scrollbar-thumb {
    background: var(--border-accent);
    border-radius: 4px;
}

.nav-tabs::-webkit-scrollbar-thumb:hover {
    background: #0052a3;
}

.nav-tabs .nav-item {
    margin-right: 5px;
    margin-bottom: 0;
}

.nav-tabs .nav-link {
    color: var(--text-primary);
    background: var(--bg-tab-inactive);
    border: none;
    border-radius: 5px 5px 0 0;
    padding: 12px 24px;
    font-weight: 500;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s, transform 0.2s;
    margin-bottom: 0;
    box-shadow: inset 0 -2px 0 var(--border-tab);
}

.nav-tabs .nav-link:hover {
    transform: translateY(-2px);
    background: var(--bg-tab-hover);
    border-color: var(--border-secondary);
    color: var(--text-tab-hover);
    isolation: isolate;
}

.nav-tabs .nav-link.active {
    background: var(--bg-tab-active);
    color: var(--text-tab-active);
    font-weight: 600;
    border: 2px solid var(--border-tab);
    border-bottom: 5px solid var(--bg-tab-active);
    margin-bottom: -5px;
    z-index: 100;
    position: relative;
    box-shadow: none;
    animation: tabActivate 0.3s ease-out;
}

.nav-tabs .nav-link.active:hover {
    transform: none;
}

@keyframes tabActivate {
    from {
        transform: scale(0.95);
    }
    to {
        transform: scale(1);
    }
}

.nav-tabs {
    position: relative;
}

.tab-content {
    position: relative;
    z-index: 1;
}


.tab-content {
    padding: 20px;
    background: var(--bg-primary);
    border-top: none;
    transition: background 0.3s ease;
}

.tab-pane {
    display: none;
    border: none;
    opacity: 0;
    animation: none;
    transition: opacity 0s;
}

.tab-pane.placeholder-tab-pane {
    animation: none;
    transition: opacity 0s;
}

.tab-pane.active,
.tab-pane.show {
    display: block;
    opacity: 1;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Hide borders on elements under active tab */
.tab-pane * {
    border-top: none !important;
}

.tab-content > * {
    border-top: none !important;
}

.table-container {
    overflow-x: auto;
    border-radius: 8px;
    overflow: hidden;
    animation: tableFadeIn 0.5s ease-out;
}

.iracing-links {
    margin-top: 20px;
    padding: 15px 20px;
    background: var(--bg-quaternary);
    border-radius: 8px;
    border: 1px solid var(--border-primary);
    animation: tableFadeIn 0.5s ease-out;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.iracing-links h3 {
    color: var(--text-primary);
    font-size: 1.1em;
    margin-bottom: 10px;
    font-weight: 600;
    transition: color 0.3s ease;
}

.iracing-links ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.iracing-links li {
    margin-bottom: 8px;
    animation: slideInRow 0.4s ease-out backwards;
}

.iracing-links li:nth-child(1) {
    animation-delay: 0.05s;
}

.iracing-links li:nth-child(2) {
    animation-delay: 0.1s;
}

.iracing-links li:nth-child(3) {
    animation-delay: 0.15s;
}

.iracing-links li:nth-child(n+4) {
    animation-delay: 0.2s;
}

.iracing-links a {
    color: var(--text-accent);
    text-decoration: none;
    transition: color 0.2s, transform 0.2s;
    display: inline-block;
}

.iracing-links a:hover {
    color: #7bb3ff;
    text-decoration: underline;
    transform: translateX(5px);
}

/* Driver link styling */
.driver-row {
    cursor: pointer;
    transition: background-color 0.2s;
}

.driver-row:hover {
    background-color: var(--bg-hover) !important;
}

/* Override existing hover styles for driver rows */
tbody tr.driver-row:hover {
    background-color: var(--bg-hover) !important;
}

/* Driver statistics modal */
.driver-stats-modal {
    background: var(--bg-modal);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    animation: modalFadeIn 0.4s ease-out;
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.driver-stats-modal .modal-header {
    background: var(--bg-modal-header);
    border-bottom: 1px solid var(--border-primary);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.driver-stats-modal .modal-title {
    color: var(--text-primary);
    font-weight: 600;
    transition: color 0.3s ease;
}

.driver-stats-modal .modal-body {
    background: var(--bg-modal);
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--border-accent) var(--bg-modal); /* Firefox: thumb and track */
    transition: background 0.3s ease;
}

/* Custom scrollbar for modal body - Webkit browsers (Chrome, Safari, Edge) */
.driver-stats-modal .modal-body::-webkit-scrollbar {
    width: 8px;
}

.driver-stats-modal .modal-body::-webkit-scrollbar-track {
    background: var(--bg-modal);
    border-radius: 4px;
}

.driver-stats-modal .modal-body::-webkit-scrollbar-thumb {
    background: var(--border-accent);
    border-radius: 4px;
}

.driver-stats-modal .modal-body::-webkit-scrollbar-thumb:hover {
    background: #0052a3;
}

/* Custom scrollbar for modal dialog scrollable container */
.driver-stats-modal .modal-dialog-scrollable {
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--border-accent) var(--bg-modal); /* Firefox: thumb and track */
}

.driver-stats-modal .modal-dialog-scrollable::-webkit-scrollbar {
    width: 8px;
}

.driver-stats-modal .modal-dialog-scrollable::-webkit-scrollbar-track {
    background: var(--bg-modal);
    border-radius: 4px;
}

.driver-stats-modal .modal-dialog-scrollable::-webkit-scrollbar-thumb {
    background: var(--border-accent);
    border-radius: 4px;
}

.driver-stats-modal .modal-dialog-scrollable::-webkit-scrollbar-thumb:hover {
    background: #0052a3;
}

.driver-stats-modal .modal-footer {
    background: var(--bg-modal-header);
    border-top: 1px solid var(--border-primary);
    transition: background 0.3s ease, border-color 0.3s ease;
}

/* Close button styling for driver stats modal */
.driver-stats-modal .btn-close {
    filter: brightness(0) invert(1);
    opacity: 0.8;
    transition: opacity 0.3s ease, filter 0.3s ease;
}

[data-theme="light"] .driver-stats-modal .btn-close {
    filter: brightness(0);
    opacity: 0.5;
}

.driver-stats-modal .btn-close:hover {
    opacity: 1;
}

.driver-stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
    animation: fadeIn 0.5s ease-out;
}

/* Default 3-column layout ordering */
.stat-item.stat-order-1 { order: 1; } /* Tracks Participated */
.stat-item.stat-order-3 { order: 2; } /* Total Laps */
.stat-item.stat-order-5 { order: 3; } /* Average Laps per Track */
.stat-item.stat-order-2 { order: 4; } /* Best Position */
.stat-item.stat-order-4 { order: 5; } /* Worst Position */
.stat-item.stat-order-6 { order: 6; } /* Average Position */

.stat-item {
    background: var(--bg-quaternary);
    padding: 12px 15px;
    border-radius: 6px;
    border: 1px solid var(--border-primary);
    animation: slideInRow 0.4s ease-out backwards;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.stat-item:nth-child(1) { animation-delay: 0.05s; }
.stat-item:nth-child(2) { animation-delay: 0.1s; }
.stat-item:nth-child(3) { animation-delay: 0.15s; }
.stat-item:nth-child(4) { animation-delay: 0.2s; }
.stat-item:nth-child(5) { animation-delay: 0.25s; }
.stat-item:nth-child(6) { animation-delay: 0.3s; }

.stat-label {
    display: block;
    color: var(--text-tertiary);
    font-size: 0.85em;
    margin-bottom: 5px;
    transition: color 0.3s ease;
}

.stat-value {
    display: block;
    color: var(--text-accent);
    font-size: 1.2em;
    font-weight: 600;
    transition: color 0.3s ease;
}

.stat-note {
    display: block;
    color: var(--text-tertiary);
    font-size: 0.8em;
    margin-top: 3px;
    transition: color 0.3s ease;
}

.stats-section-title {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.1em;
    transition: color 0.3s ease;
}

.driver-stats-modal .table-container {
    margin-top: 10px;
    animation: tableFadeIn 0.5s ease-out;
}

.driver-stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1em;
    border-radius: 8px;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-modal);
    color: var(--text-primary);
    transition: background 0.3s ease, color 0.3s ease;
}

.driver-stats-table thead {
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    transition: background 0.3s ease;
}

.driver-stats-table thead tr:first-child th:first-child {
    border-top-left-radius: 8px;
}

.driver-stats-table thead tr:first-child th:last-child {
    border-top-right-radius: 8px;
}

.driver-stats-table thead th {
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-accent);
    font-weight: 600;
    padding: 15px;
    text-align: left;
    font-size: 1em;
    transition: color 0.3s ease, border-color 0.3s ease;
}

.driver-stats-table tbody tr {
    transition: background-color 0.2s, transform 0.2s;
    animation: slideInRow 0.4s ease-out backwards;
}

.driver-stats-table tbody tr:nth-child(1) { animation-delay: 0.05s; }
.driver-stats-table tbody tr:nth-child(2) { animation-delay: 0.1s; }
.driver-stats-table tbody tr:nth-child(3) { animation-delay: 0.15s; }
.driver-stats-table tbody tr:nth-child(4) { animation-delay: 0.2s; }
.driver-stats-table tbody tr:nth-child(5) { animation-delay: 0.25s; }
.driver-stats-table tbody tr:nth-child(6) { animation-delay: 0.3s; }
.driver-stats-table tbody tr:nth-child(7) { animation-delay: 0.35s; }
.driver-stats-table tbody tr:nth-child(n+8) { animation-delay: 0.4s; }

.driver-stats-table tbody tr:nth-child(even) {
    background-color: var(--bg-secondary);
}

.driver-stats-table tbody tr:nth-child(odd) {
    background-color: var(--bg-tertiary);
}

.driver-stats-table tbody tr:hover {
    background-color: var(--bg-hover) !important;
}

.driver-stats-table tbody td {
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-primary);
    padding: 15px;
    transition: color 0.3s ease, border-color 0.3s ease;
}

.driver-stats-table tbody tr:last-child td:first-child {
    border-bottom-left-radius: 8px;
}

.driver-stats-table tbody tr:last-child td:last-child {
    border-bottom-right-radius: 8px;
}

.driver-stats-table .driver {
    text-align: left;
    width: 40%;
}

.driver-stats-table .rank {
    text-align: center;
    width: 15%;
}

.driver-stats-table th.rank {
    text-align: center;
}

.driver-stats-table td.rank {
    text-align: center;
}

.driver-stats-table .time {
    text-align: center;
    width: 25%;
}

.driver-stats-table th.time {
    text-align: center;
}

.driver-stats-table td.time {
    text-align: center;
}

.driver-stats-table .total-laps {
    text-align: center;
    width: 20%;
}

/* Remove medals and special styling from driver stats table - no medals at all */
.driver-stats-table tbody tr:nth-child(1) {
    background-color: var(--bg-tertiary) !important;
    font-weight: 400 !important;
}

.driver-stats-table tbody tr:nth-child(2) {
    background-color: var(--bg-secondary) !important;
    font-weight: 400 !important;
}

.driver-stats-table tbody tr:nth-child(3) {
    background-color: var(--bg-tertiary) !important;
    font-weight: 400 !important;
}

/* Prevent medal styling on all cells in driver stats table */
.driver-stats-table tbody tr:nth-child(1) td,
.driver-stats-table tbody tr:nth-child(2) td,
.driver-stats-table tbody tr:nth-child(3) td,
.driver-stats-table tbody tr:nth-child(1) td:first-child,
.driver-stats-table tbody tr:nth-child(2) td:first-child,
.driver-stats-table tbody tr:nth-child(3) td:first-child {
    text-indent: 0 !important;
    overflow: visible !important;
    position: static !important;
}

.driver-stats-table tbody tr:nth-child(1) td::before,
.driver-stats-table tbody tr:nth-child(2) td::before,
.driver-stats-table tbody tr:nth-child(3) td::before,
.driver-stats-table tbody tr:nth-child(1) td:first-child::before,
.driver-stats-table tbody tr:nth-child(2) td:first-child::before,
.driver-stats-table tbody tr:nth-child(3) td:first-child::before {
    content: none !important;
}

.driver-stats-modal .btn-secondary {
    background: var(--border-primary);
    border-color: var(--border-secondary);
    color: var(--text-primary);
    transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.driver-stats-modal .btn-secondary:hover {
    background: var(--border-secondary);
    border-color: var(--border-secondary);
    color: var(--text-white);
}

/* Time progression charts */
.time-progression-charts {
    margin-top: 20px;
    animation: fadeIn 0.5s ease-out;
}

.progression-chart-container {
    padding: 12px 0;
    background: var(--bg-quaternary);
    border-radius: 8px;
    border: 1px solid var(--border-primary);
    height: 300px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideInRow 0.4s ease-out backwards;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.progression-chart-container:nth-child(1) { animation-delay: 0.05s; }
.progression-chart-container:nth-child(2) { animation-delay: 0.1s; }
.progression-chart-container:nth-child(3) { animation-delay: 0.15s; }
.progression-chart-container:nth-child(4) { animation-delay: 0.2s; }
.progression-chart-container:nth-child(5) { animation-delay: 0.25s; }
.progression-chart-container:nth-child(n+6) { animation-delay: 0.3s; }

.chart-title {
    color: var(--text-primary);
    font-size: 1em;
    font-weight: 600;
    margin-bottom: 15px;
    text-align: center;
    flex-shrink: 0;
    animation: fadeIn 0.3s ease-out 0.2s backwards;
    transition: color 0.3s ease;
}

.progression-chart {
    width: 100% !important;
    max-width: 100% !important;
    height: 250px !important;
    max-height: 250px !important;
    min-height: 250px !important;
    background: transparent !important;
    border-radius: 4px;
    position: relative;
    flex: 1;
    overflow: hidden;
    transition: background 0.3s ease;
}

@keyframes tableFadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1em;
    border-radius: 8px;
    overflow: hidden;
}

thead {
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    transition: background 0.3s ease;
}

thead tr:first-child th:first-child {
    border-top-left-radius: 8px;
}

thead tr:first-child th:last-child {
    border-top-right-radius: 8px;
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-accent);
    font-size: 1em;
    transition: color 0.3s ease, border-color 0.3s ease;
}

td {
    padding: 15px;
    border-bottom: 1px solid var(--border-primary);
    color: var(--text-primary);
    transition: color 0.3s ease, border-color 0.3s ease;
}

tbody tr {
    transition: background-color 0.2s, transform 0.2s;
    animation: slideInRow 0.4s ease-out backwards;
}

@keyframes slideInRow {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

tbody tr:nth-child(1) {
    animation-delay: 0.05s;
}

tbody tr:nth-child(2) {
    animation-delay: 0.1s;
}

tbody tr:nth-child(3) {
    animation-delay: 0.15s;
}

tbody tr:nth-child(n+4) {
    animation-delay: 0.2s;
}

tbody tr:nth-child(even) {
    background-color: var(--bg-secondary);
}

tbody tr:nth-child(odd) {
    background-color: var(--bg-tertiary);
}

tbody tr:last-child td:first-child {
    border-bottom-left-radius: 8px;
}

tbody tr:last-child td:last-child {
    border-bottom-right-radius: 8px;
}

tbody tr:nth-child(1) {
    background-color: var(--bg-gold);
    font-weight: 600;
}

tbody tr:nth-child(1) td:first-child {
    position: relative;
    text-indent: -9999px;
    overflow: hidden;
}

tbody tr:nth-child(1) td:first-child::before {
    content: "🥇";
    font-size: 0.9em;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    text-indent: 0;
    line-height: 1;
}

tbody tr:nth-child(2) {
    background-color: var(--bg-silver);
}

tbody tr:nth-child(2) td:first-child {
    position: relative;
    text-indent: -9999px;
    overflow: hidden;
}

tbody tr:nth-child(2) td:first-child::before {
    content: "🥈";
    font-size: 0.9em;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    text-indent: 0;
    line-height: 1;
}

tbody tr:nth-child(3) {
    background-color: var(--bg-bronze);
}

tbody tr:nth-child(3) td:first-child {
    position: relative;
    text-indent: -9999px;
    overflow: hidden;
}

tbody tr:nth-child(3) td:first-child::before {
    content: "🥉";
    font-size: 0.9em;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    text-indent: 0;
    line-height: 1;
}

tbody tr:nth-child(35) {
    border-bottom: 3px solid var(--text-error);
}

tbody tr:nth-child(36) {
    border-top: 3px solid var(--text-error);
}

.rank {
    width: 40px;
    padding: 15px 4px 15px 15px;
    text-align: left;
}

th.rank {
    font-weight: 600;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

td.rank {
    font-weight: 600;
    color: var(--text-rank);
    vertical-align: middle;
    transition: color 0.3s ease;
}

.driver {
    min-width: 300px;
    padding: 15px;
}

th.driver {
    font-weight: 600;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

td.driver {
    font-weight: 400;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.time {
    width: 80px;
    padding: 15px 8px;
    text-align: center;
}

th.time {
    font-weight: 600;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

td.time {
    font-weight: 600;
    color: var(--text-time);
    transition: color 0.3s ease;
}

.time-loss {
    width: 80px;
    padding: 15px 8px;
    text-align: center;
}

th.time-loss {
    font-weight: 600;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

td.time-loss {
    font-weight: 400;
    color: var(--text-error);
    transition: color 0.3s ease;
}

.total-laps {
    width: 80px;
    padding: 15px 8px;
    text-align: center;
}

th.total-laps {
    font-weight: 600;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

td.total-laps {
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.pos-change {
    text-align: left;
    font-weight: 600;
    width: 40px;
    padding: 15px 15px 15px 4px;
}

th.pos-change-header {
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    padding: 8px 15px;
    font-size: 0.85em;
    transition: color 0.3s ease;
}

th.rank-sub {
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    padding: 8px 15px;
    font-size: 0.85em;
    transition: color 0.3s ease;
}

.no-data {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.no-data h2 {
    margin-bottom: 10px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--border-accent);
    animation: pulse 1.5s ease-in-out infinite;
    transition: color 0.3s ease;
}

.loading::after {
    content: "...";
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.footer {
    background: repeating-linear-gradient(
                    0deg,
                    transparent,
                    transparent 40px,
                    var(--header-overlay) 40px,
                    var(--header-overlay) 80px
                ),
                repeating-linear-gradient(
                    90deg,
                    transparent,
                    transparent 40px,
                    var(--header-overlay) 40px,
                    var(--header-overlay) 80px
                ),
                linear-gradient(135deg, var(--header-gradient-start) 0%, var(--header-gradient-end) 100%);
    color: white;
    padding: 15px;
    text-align: center;
    position: relative;
    animation: footerFadeIn 0.8s ease-out;
    transition: background 0.3s ease;
}

@keyframes footerFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.footer p {
    margin: 0;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .header {
        padding: 20px 15px;
    }
    
    .theme-toggle {
        top: 10px;
        right: 10px;
        width: 56px;
        height: 28px;
    }
    
    .theme-icon {
        width: 24px;
        height: 24px;
        font-size: 1em;
        transform: translateX(28px);
    }
    
    [data-theme="light"] .theme-icon {
        transform: translateX(0);
    }
    
    .header h1 {
        font-size: 1.8em;
    }
    
    .header h5 {
        font-size: 0.9em;
    }
    
    .nav-tabs {
        padding: 8px 5px 0 5px;
    }
    
    .nav-tabs .nav-link {
        padding: 10px 15px;
        font-size: 0.9em;
    }
    
    .tab-content {
        padding: 15px 10px;
    }
    
    table {
        font-size: 0.8em;
    }
    
    th, td {
        padding: 6px 4px;
    }
    
    .rank, .pos-change {
        width: 35px;
        padding-left: 2px;
        padding-right: 2px;
    }
    
    .rank {
        text-align: center;
    }
    
    .time, .time-loss, .total-laps {
        padding-left: 4px;
        padding-right: 4px;
    }
    
    .driver {
        min-width: auto;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding-left: 4px;
        padding-right: 4px;
    }
    
    .driver-stats-table {
        font-size: 0.85em;
    }
    
    .driver-stats-table .driver {
        max-width: none;
        width: 50% !important;
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
        line-height: 1.3;
    }
    
    .driver-stats-table .rank {
        width: 12% !important;
    }
    
    .driver-stats-table .time {
        width: 20% !important;
    }
    
    .driver-stats-table .total-laps {
        width: 18% !important;
    }
    
    .driver-stats-summary {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-bottom: 15px;
    }
    
    .stat-item.stat-order-1 { order: 1; }
    .stat-item.stat-order-2 { order: 2; }
    .stat-item.stat-order-3 { order: 3; }
    .stat-item.stat-order-4 { order: 4; }
    .stat-item.stat-order-5 { order: 5; }
    .stat-item.stat-order-6 { order: 6; }
    
    .stat-item {
        padding: 12px 10px;
        border-radius: 4px;
    }
    
    .stat-label {
        font-size: 0.75em;
        margin-bottom: 5px;
    }
    
    .stat-value {
        font-size: 1.1em;
    }
    
    .target-time-table {
        padding: 10px 15px;
        font-size: 0.9em;
    }
    
    .footer {
        padding: 12px;
        font-size: 0.85em;
    }
}

@media (max-width: 480px) {
    body {
        padding: 5px;
    }
    
    .header {
        padding: 15px 10px;
    }
    
    .theme-toggle {
        top: 8px;
        right: 8px;
        width: 52px;
        height: 26px;
    }
    
    .theme-icon {
        width: 22px;
        height: 22px;
        font-size: 0.9em;
        transform: translateX(26px);
    }
    
    [data-theme="light"] .theme-icon {
        transform: translateX(0);
    }
    
    .header h1 {
        font-size: 1.5em;
    }
    
    .nav-tabs .nav-link {
        padding: 8px 12px;
        font-size: 0.85em;
    }
    
    table {
        font-size: 0.7em;
    }
    
    th, td {
        padding: 5px 2px;
    }
    
    .rank, .pos-change {
        width: 30px;
        padding-left: 1px;
        padding-right: 1px;
    }
    
    .rank {
        text-align: center;
    }
    
    .time, .time-loss, .total-laps {
        padding-left: 3px;
        padding-right: 3px;
    }
    
    .driver {
        min-width: auto;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding-left: 3px;
        padding-right: 3px;
    }
    
    .driver-stats-table {
        font-size: 0.8em;
    }
    
    .driver-stats-table .driver {
        max-width: none;
        width: 55% !important;
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
        line-height: 1.3;
    }
    
    .driver-stats-table .rank {
        width: 10% !important;
    }
    
    .driver-stats-table .time {
        width: 20% !important;
    }
    
    .driver-stats-table .total-laps {
        width: 15% !important;
    }
    
    .driver-stats-summary {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 12px;
    }
    
    .stat-item.stat-order-1 { order: 1; }
    .stat-item.stat-order-2 { order: 2; }
    .stat-item.stat-order-3 { order: 3; }
    .stat-item.stat-order-4 { order: 4; }
    .stat-item.stat-order-5 { order: 5; }
    .stat-item.stat-order-6 { order: 6; }
    
    .stat-item {
        padding: 6px 8px;
        border-radius: 4px;
    }
    
    .stat-label {
        font-size: 0.7em;
        margin-bottom: 2px;
    }
    
    .stat-value {
        font-size: 0.9em;
    }
}

