/* Global Table Formatting (Restoring structure lost after Tailwind reset) */
table, .table {
    width: 100%;
    margin-bottom: 0 !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

table th, table td,
.table th, .table td {
    padding: 0.5rem 0.45rem !important;
    vertical-align: middle;
    border-bottom: 1px solid #e5e7eb;
    border-top: none;
    white-space: nowrap !important;
}

/* Prevent double borders at the bottom of table containers */
table tbody tr:last-child td,
table tbody tr:last-child th,
.table tbody tr:last-child td,
.table tbody tr:last-child th {
    border-bottom: none !important;
}

table thead th,
.table thead th,
thead.sticky th,
.sticky th {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    vertical-align: middle;
    border-bottom: 2px solid #e5e7eb;
    font-weight: 700;
    text-align: left;
    background-color: #f1f5f9;
    color: #0f172a;
    white-space: nowrap !important;
}

@media (min-width: 768px) {
    table, .table {
        font-size: clamp(0.78rem, 0.82vw, 0.875rem);
    }
    table th, table td,
    .table th, .table td {
        padding: 0.5rem 0.45rem !important;
        white-space: nowrap !important;
    }
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, 0.02);
}

.table-hover tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

html.dark,
body.dark-mode {
    background-color: #0f172a;
    color: #ffffff;
}

html.dark .form_div,
body.dark-mode .form_div {
    background-color: #1e293b;
    border-color: #334155;
}

/* Typography links */
html.dark a:not(.btn):not(.text-white):not([class*="text-white"]):not([class*="bg-blue"]):not([class*="bg-red"]):not([class*="tab-btn"]),
body.dark-mode a:not(.btn):not(.text-white):not([class*="text-white"]):not([class*="bg-blue"]):not([class*="bg-red"]):not([class*="tab-btn"]) {
    color: #60a5fa;
}
html.dark a:not(.btn):not(.text-white):not([class*="text-white"]):not([class*="bg-blue"]):not([class*="bg-red"]):not([class*="tab-btn"]):hover,
body.dark-mode a:not(.btn):not(.text-white):not([class*="text-white"]):not([class*="bg-blue"]):not([class*="bg-red"]):not([class*="tab-btn"]):hover {
    color: #93c5fd;
}

/* Ensure button-styled links (like Open Driver Web, Open Timelapse, Launch Visualiser) remain crisp white in dark mode */
html.dark a.text-white,
html.dark a[class*="text-white"],
html.dark a[class*="bg-blue"],
body.dark-mode a.text-white,
body.dark-mode a[class*="text-white"],
body.dark-mode a[class*="bg-blue"] {
    color: #ffffff !important;
}

/* Text Overrides */
html.dark .text-muted,
body.dark-mode .text-muted {
    color: #cbd5e1 !important;
}

/* Modals / Tables */
html.dark .modal-content,
body.dark-mode .modal-content {
    background-color: #1e293b;
    color: #ffffff;
    border-color: #334155;
}
html.dark .modal-header,
html.dark .modal-footer,
body.dark-mode .modal-header,
body.dark-mode .modal-footer {
    border-color: #334155;
}

html.dark .table th, 
html.dark .table td,
html.dark .table thead th,
html.dark table th, 
html.dark table td,
html.dark table thead th,
body.dark-mode .table th, 
body.dark-mode .table td,
body.dark-mode .table thead th,
body.dark-mode table th, 
body.dark-mode table td,
body.dark-mode table thead th {
    border-color: #334155 !important;
}

html.dark table thead th,
html.dark .table thead th,
body.dark-mode table thead th,
body.dark-mode .table thead th {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border-bottom: 2px solid #334155 !important;
}

html.dark table tfoot tr td,
html.dark .table tfoot tr td,
body.dark-mode table tfoot tr td,
body.dark-mode .table tfoot tr td {
    background-color: #0f172a !important;
    color: #ffffff;
    border-top: 2px solid #334155 !important;
}

/* Season and race links inside table */
html.dark table a,
html.dark .table a,
html.dark #results-table a,
body.dark-mode table a,
body.dark-mode .table a,
body.dark-mode #results-table a {
    color: #60a5fa !important;
    font-weight: 700 !important;
}
html.dark table a:hover,
html.dark .table a:hover,
html.dark #results-table a:hover,
body.dark-mode table a:hover,
body.dark-mode .table a:hover,
body.dark-mode #results-table a:hover {
    color: #93c5fd !important;
    text-decoration: underline !important;
}

/* Select and inputs */
html.dark select.form-control,
html.dark input.form-control,
body.dark-mode select.form-control,
body.dark-mode input.form-control {
    background-color: #334155;
    color: #ffffff;
    border-color: #475569;
}

html.dark select.form-control:disabled,
html.dark input.form-control:disabled,
body.dark-mode select.form-control:disabled,
body.dark-mode input.form-control:disabled {
    background-color: #1e293b;
    color: #94a3b8;
}


/* Tailwind Overrides for Dark Mode */
html.dark .bg-gray-50,
body.dark-mode .bg-gray-50,
html.dark .g-gray-50,
body.dark-mode .g-gray-50 {
    background-color: #0f172a !important;
}

html.dark .bg-white,
body.dark-mode .bg-white {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #ffffff !important;
}

html.dark .bg-gray-100,
body.dark-mode .bg-gray-100 {
    background-color: #0f172a !important;
    border-color: #334155 !important;
}

html.dark .bg-gray-800,
body.dark-mode .bg-gray-800 {
    background-color: #1e293b !important;
}

/* Ensure crisp white text across all dark mode elements */
html.dark .text-gray-900,
html.dark .text-gray-800,
html.dark .text-gray-700,
html.dark .text-gray-600,
body.dark-mode .text-gray-900,
body.dark-mode .text-gray-800,
body.dark-mode .text-gray-700,
body.dark-mode .text-gray-600 {
    color: #ffffff !important;
}

html.dark .text-gray-500,
html.dark .text-gray-400,
body.dark-mode .text-gray-500,
body.dark-mode .text-gray-400 {
    color: #cbd5e1 !important;
}

html.dark .border-gray-200,
html.dark .border-gray-300,
body.dark-mode .border-gray-200,
body.dark-mode .border-gray-300 {
    border-color: #334155 !important;
}

html.dark .hover\:bg-gray-100:hover,
body.dark-mode .hover\:bg-gray-100:hover {
    background-color: #334155 !important;
}

html.dark .hover\:bg-gray-50:hover,
body.dark-mode .hover\:bg-gray-50:hover {
    background-color: #334155 !important;
}

/* Win / Loss / Delta Highlighting */
.pos-ahead, .delta-negative {
    color: #059669;
    font-weight: 700;
}

html.dark .pos-ahead,
html.dark .delta-negative,
body.dark-mode .pos-ahead,
body.dark-mode .delta-negative {
    color: #4ade80 !important; /* emerald-400 vivid green */
    font-weight: 700 !important;
}

.pos-behind, .delta-positive {
    color: #dc2626;
    font-weight: 700;
}

html.dark .pos-behind,
html.dark .delta-positive,
body.dark-mode .pos-behind,
body.dark-mode .delta-positive {
    color: #f87171 !important; /* red-400 vivid red */
    font-weight: 700 !important;
}



/* Dark Mode Table Stripes */
html.dark .table-striped tbody tr:nth-of-type(odd),
body.dark-mode .table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(255, 255, 255, 0.03) !important;
}



/* Dark mode table hover */
html.dark .table-hover tbody tr:hover,
body.dark-mode .table-hover tbody tr:hover {
    background-color: #334155 !important;
}

/* Global Select2 Disabled State Styling (Both Light and Dark Mode) */
.select2-container--disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
}
.select2-container--disabled .select2-selection {
    background-color: rgba(128, 128, 128, 0.1) !important;
}

/* Support for Tailwind html.dark class */
html.dark .select2-container--default .select2-selection--single,
body.dark-mode .select2-container--default .select2-selection--single {
    background-color: #374151 !important;
    color: #ffffff !important;
    border-color: #4b5563 !important;
}
html.dark .select2-container--default .select2-selection--single .select2-selection__rendered,
body.dark-mode .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #ffffff !important;
}
html.dark .select2-container--default .select2-selection--single .select2-selection__placeholder,
body.dark-mode .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #9ca3af !important;
}
html.dark .select2-container--default .select2-selection--single .select2-selection__arrow b,
body.dark-mode .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #f3f4f6 transparent transparent transparent !important;
}
html.dark .select2-dropdown,
body.dark-mode .select2-dropdown {
    background-color: #1f2937 !important;
    color: #ffffff !important;
    border-color: #4b5563 !important;
}
html.dark .select2-search--dropdown .select2-search__field,
body.dark-mode .select2-search--dropdown .select2-search__field {
    background-color: #374151 !important;
    color: #ffffff !important;
    border-color: #4b5563 !important;
    border-radius: 0.375rem !important;
}
html.dark .select2-results__option,
body.dark-mode .select2-results__option {
    color: #ffffff !important;
    background-color: transparent !important;
}
html.dark .select2-container--default .select2-results__option[aria-selected=true],
html.dark .select2-container--default .select2-results__option--selected,
body.dark-mode .select2-container--default .select2-results__option[aria-selected=true],
body.dark-mode .select2-container--default .select2-results__option--selected {
    background-color: #374151 !important;
    color: #60a5fa !important;
    font-weight: 600 !important;
}
html.dark .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable,
body.dark-mode .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: #2563eb !important;
    color: #ffffff !important;
}

/* ==========================================================================
   Sleek Custom Scrollbars (Webkit & Firefox)
   ========================================================================== */

/* Firefox-only fallback so Chrome/Edge don't disable Webkit scrollbars */
@supports (-moz-appearance:none) {
    * {
        scrollbar-width: thin;
        scrollbar-color: #4b5563 transparent;
    }
    
    html.dark *,
    body.dark-mode * {
        scrollbar-color: #4b5563 #111827;
    }
}

/* Width / Height */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

/* Track */
::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 9999px;
}

html.dark ::-webkit-scrollbar-track,
body.dark-mode ::-webkit-scrollbar-track {
    background: transparent;
}

/* Handle / Thumb */
::-webkit-scrollbar-thumb {
    background: #64748b; /* Slate 500 - visible in light mode */
    border-radius: 9999px;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: #475569; /* Slate 600 */
}

html.dark ::-webkit-scrollbar-thumb,
body.dark-mode ::-webkit-scrollbar-thumb {
    background: #4b5563; /* Gray 600 - sleek in dark mode */
}

html.dark ::-webkit-scrollbar-thumb:hover,
body.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Hide scrollbar arrows/buttons in WebKit */
::-webkit-scrollbar-button {
    display: none;
    width: 0;
    height: 0;
}

/* -----------------------------------------------------------------
 * H2H Mobile Cards: Round Number Chip Dark-Mode Background Fill
 * ----------------------------------------------------------------- */
html.dark #results-cards summary span.bg-gray-800,
body.dark-mode #results-cards summary span.bg-gray-800,
html.dark .result-details summary span.bg-gray-800,
body.dark-mode .result-details summary span.bg-gray-800,
html.dark .round-chip,
body.dark-mode .round-chip {
    background-color: #000000 !important;
    border: 1px solid #374151 !important;
    color: #ffffff !important;
}



