/* ================================================================ */
/* Season Statistics - Page-Specific Styles                         */
/* ================================================================ */

/* Table Shell */
table.matrix-table,
.matrix-table {
    border-collapse: separate !important;
    border-spacing: 0 !important;
    table-layout: fixed !important;
    width: max-content !important;
    min-width: 100% !important;
}

/* ---------------------------------------------------------------- */
/* Sticky Driver Column (Header & Body)                             */
/* ---------------------------------------------------------------- */

/* Constrain Driver/Name Column */
col.matrix-driver-col,
th.matrix-driver-th,
td.matrix-driver-td,
.matrix-driver-col,
.matrix-driver-th,
.matrix-driver-td {
    width: 13rem !important;
    min-width: 11rem !important;
    max-width: 14rem !important;
}

/* Top-Left Corner Header ("Driver") */
html.dark table.matrix-table thead tr th.matrix-driver-th,
body.dark-mode table.matrix-table thead tr th.matrix-driver-th,
table.matrix-table thead tr th.matrix-driver-th,
html.dark th.matrix-driver-th,
body.dark-mode th.matrix-driver-th,
th.matrix-driver-th,
.matrix-driver-th {
    position: sticky !important;
    left: 0 !important;
    top: 0 !important;
    z-index: 50 !important;
    background-color: #212529 !important;
    color: #ffffff !important;
    white-space: nowrap !important;
    padding: 0.5rem 0.6rem !important;
    border-left: 1px solid #4b5563 !important;
    border-right: 1px solid #4b5563 !important;
    border-bottom: 1px solid #4b5563 !important;
    /* Solid -1px left shadow paints over subpixel scaling gaps without shifting layout */
    box-shadow: -1px 0 0 #212529, 3px 0 6px -2px rgba(0, 0, 0, 0.25) !important;
}

html.dark table.matrix-table thead tr th.matrix-driver-th,
body.dark-mode table.matrix-table thead tr th.matrix-driver-th,
html.dark th.matrix-driver-th,
body.dark-mode th.matrix-driver-th {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border-left: 1px solid #334155 !important;
    border-right: 1px solid #334155 !important;
    border-bottom: 1px solid #334155 !important;
    z-index: 50 !important;
    box-shadow: -1px 0 0 #0f172a, 3px 0 6px -2px rgba(0, 0, 0, 0.25) !important;
}

/* Driver Column Body Cells ("Norris", "Verstappen", etc.) */
html.dark table.matrix-table tbody tr td.matrix-driver-td,
body.dark-mode table.matrix-table tbody tr td.matrix-driver-td,
table.matrix-table tbody tr td.matrix-driver-td,
html.dark td.matrix-driver-td,
body.dark-mode td.matrix-driver-td,
td.matrix-driver-td,
.matrix-driver-td {
    position: sticky !important;
    left: 0 !important;
    z-index: 25 !important;
    background-color: #ffffff !important;
    color: #111827 !important;
    white-space: nowrap !important;
    padding: 0.5rem 0.6rem !important;
    border-left: 1px solid #e5e7eb !important;
    border-right: 1px solid #e5e7eb !important;
    border-bottom: 1px solid #e5e7eb !important;
    /* Solid -1px left shadow paints over subpixel scaling gaps without shifting layout */
    box-shadow: -1px 0 0 #ffffff, 3px 0 6px -2px rgba(0, 0, 0, 0.2) !important;
}

html.dark table.matrix-table tbody tr td.matrix-driver-td,
body.dark-mode table.matrix-table tbody tr td.matrix-driver-td,
html.dark td.matrix-driver-td,
body.dark-mode td.matrix-driver-td {
    background-color: #1e293b !important;
    color: #f8fafc !important;
    border-left: 1px solid #334155 !important;
    border-right: 1px solid #334155 !important;
    border-bottom: 1px solid #334155 !important;
    z-index: 25 !important;
    box-shadow: -1px 0 0 #1e293b, 3px 0 6px -2px rgba(0, 0, 0, 0.2) !important;
}

.matrix-driver-td a {
    color: #2563eb !important; /* Tailwind blue-600 */
    font-weight: 600;
    text-decoration: none;
}

.matrix-driver-td a:hover {
    color: #1d4ed8 !important; /* Tailwind blue-700 */
    text-decoration: underline !important;
}

html.dark .matrix-driver-td a,
body.dark-mode .matrix-driver-td a {
    color: #38bdf8 !important; /* Tailwind sky-400 */
}

html.dark .matrix-driver-td a:hover,
body.dark-mode .matrix-driver-td a:hover {
    color: #7dd3fc !important; /* Tailwind sky-300 */
}

/* ---------------------------------------------------------------- */
/* Round Headers (R1, R2, Sprints, Total Points)                   */
/* ---------------------------------------------------------------- */

html.dark table.matrix-table thead tr th.matrix-round-th,
body.dark-mode table.matrix-table thead tr th.matrix-round-th,
table.matrix-table thead tr th.matrix-round-th,
.matrix-round-th {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    width: 3rem !important;
    min-width: 3rem !important;
}

html.dark table.matrix-table thead tr th.matrix-sprint-th,
body.dark-mode table.matrix-table thead tr th.matrix-sprint-th,
table.matrix-table thead tr th.matrix-sprint-th,
.matrix-sprint-th {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    width: 3rem !important;
    min-width: 3rem !important;
}

/* Top Header Round, Sprint & Total Cells */
table.matrix-table thead tr th.matrix-round-th,
.matrix-round-th,
table.matrix-table thead tr th.matrix-sprint-th,
.matrix-sprint-th,
table.matrix-table thead tr th.matrix-total-th,
.matrix-total-th {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    background-color: #212529 !important;
    color: #ffffff !important;
    border-bottom: 1px solid #4b5563 !important;
    border-left: 1px solid #4b5563 !important;
}

table.matrix-table thead tr th.matrix-round-th a,
.matrix-round-th a,
table.matrix-table thead tr th.matrix-sprint-th a,
.matrix-sprint-th a {
    color: #3b82f6 !important; /* blue-500 */
    text-decoration: none !important;
}

table.matrix-table thead tr th.matrix-round-th a:hover,
.matrix-round-th a:hover,
table.matrix-table thead tr th.matrix-sprint-th a:hover,
.matrix-sprint-th a:hover {
    color: #60a5fa !important; /* blue-400 */
    text-decoration: underline !important;
}

html.dark table.matrix-table thead tr th.matrix-round-th,
body.dark-mode table.matrix-table thead tr th.matrix-round-th,
html.dark .matrix-round-th,
body.dark-mode .matrix-round-th,
html.dark table.matrix-table thead tr th.matrix-sprint-th,
body.dark-mode table.matrix-table thead tr th.matrix-sprint-th,
html.dark .matrix-sprint-th,
body.dark-mode .matrix-sprint-th,
html.dark table.matrix-table thead tr th.matrix-total-th,
body.dark-mode table.matrix-table thead tr th.matrix-total-th,
html.dark .matrix-total-th,
body.dark-mode .matrix-total-th {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border-bottom: 1px solid #334155 !important;
    border-left: 1px solid #334155 !important;
}

html.dark table.matrix-table thead tr th.matrix-round-th a,
body.dark-mode table.matrix-table thead tr th.matrix-round-th a,
html.dark table.matrix-table thead tr th.matrix-sprint-th a,
body.dark-mode table.matrix-table thead tr th.matrix-sprint-th a {
    color: #60a5fa !important; /* blue-400 */
}

html.dark table.matrix-table thead tr th.matrix-round-th a:hover,
body.dark-mode table.matrix-table thead tr th.matrix-round-th a:hover,
html.dark table.matrix-table thead tr th.matrix-sprint-th a:hover,
body.dark-mode table.matrix-table thead tr th.matrix-sprint-th a:hover {
    color: #93c5fd !important; /* blue-300 */
    text-decoration: underline !important;
}

/* Total Points Column (Header & Body) */
table.matrix-table thead tr th.matrix-total-th,
.matrix-total-th {
    width: 5.5rem !important;
    min-width: 5.5rem !important;
    max-width: 5.5rem !important;
    color: #ffffff !important;
    text-align: center !important;
}

table.matrix-table tbody tr td.matrix-total-td,
.matrix-total-td {
    width: 5.5rem !important;
    min-width: 5.5rem !important;
    max-width: 5.5rem !important;
    text-align: center !important;
}

/* ---------------------------------------------------------------- */
/* Fastest Lap Styling (Purple Edge)                                */
/* ---------------------------------------------------------------- */
table.matrix-table tbody tr td.matrix-fl-cell,
td.matrix-fl-cell {
    box-shadow: inset 0 0 0 2px #9333ea !important; /* Tailwind purple-600 */
}

html.dark table.matrix-table tbody tr td.matrix-fl-cell,
body.dark-mode table.matrix-table tbody tr td.matrix-fl-cell,
html.dark td.matrix-fl-cell,
body.dark-mode td.matrix-fl-cell {
    box-shadow: inset 0 0 0 2px #c084fc !important; /* Tailwind purple-400 */
}

/* ---------------------------------------------------------------- */
/* Pole Position Indicator ('P' Badge in Top-Right Corner)          */
/* ---------------------------------------------------------------- */
.pole-badge {
    position: absolute !important;
    top: 2px !important;
    right: 2px !important;
    width: 12px !important;
    height: 12px !important;
    line-height: 12px !important;
    background-color: #f59e0b !important; /* amber-500 gold */
    color: #000000 !important;
    font-size: 8px !important;
    font-weight: 900 !important;
    border-radius: 9999px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4) !important;
    z-index: 5 !important;
    pointer-events: none !important;
}

html.dark .pole-badge,
body.dark-mode .pole-badge {
    background-color: #fbbf24 !important; /* bright gold */
    color: #000000 !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6) !important;
}

/* ---------------------------------------------------------------- */
/* Position Medals: Retired (DNF), Disqualified (DSQ), Non-Starter (DNS) */
/* ---------------------------------------------------------------- */
.pos-retired {
    background-color: #dc2626 !important; /* red-600 */
    color: #ffffff !important;
}

html.dark .pos-retired,
body.dark-mode .pos-retired {
    background-color: #450a0a !important; /* red-950 deep dark red, blends with dark bg */
    color: #f87171 !important; /* red-400 */
}

.pos-dsq {
    background-color: #111827 !important; /* Black flag */
    color: #f9fafb !important;
    font-weight: 800 !important;
}

html.dark .pos-dsq,
body.dark-mode .pos-dsq {
    background-color: #030712 !important;
    color: #f3f4f6 !important;
    border: 1px solid #4b5563 !important;
    font-weight: 800 !important;
}

.pos-dns {
    background-color: #e2e8f0 !important; /* slate-200 */
    color: #475569 !important; /* slate-600 */
}

html.dark .pos-dns,
body.dark-mode .pos-dns {
    background-color: #0f172a !important;
    color: #64748b !important; /* slate-500 */
    border: 1px dashed #334155 !important;
}

/* ---------------------------------------------------------------- */
/* Alternate History Sandbox Styles                                 */
/* ---------------------------------------------------------------- */

/* Sprint Column Pattern Overlay */
.sprint-col-overlay {
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 6px,
        rgba(0, 0, 0, 0.08) 6px,
        rgba(0, 0, 0, 0.08) 12px
    ) !important;
}

html.dark .sprint-col-overlay,
body.dark-mode .sprint-col-overlay {
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 6px,
        rgba(255, 255, 255, 0.08) 6px,
        rgba(255, 255, 255, 0.08) 12px
    ) !important;
}

/* Dropped round columns */
th.dropped-round-th {
    opacity: 0.45 !important;
    background-color: #374151 !important;
    text-decoration: line-through !important;
}

html.dark th.dropped-round-th,
body.dark-mode th.dropped-round-th {
    background-color: #1f2937 !important;
    opacity: 0.4 !important;
}

td.dropped-round-td {
    opacity: 0.25 !important;
    filter: grayscale(1) !important;
    background-color: #f3f4f6 !important;
}

html.dark td.dropped-round-td,
body.dark-mode td.dropped-round-td {
    background-color: #111827 !important;
}

/* Tool cursor interactions */
table.tool-toggle_race th.matrix-round-th:hover,
table.tool-toggle_race th.matrix-sprint-th:hover {
    cursor: pointer !important;
    background-color: #dc2626 !important; /* Red highlight */
    color: #ffffff !important;
    transition: background-color 0.15s ease-in-out;
}

table.tool-edit_result td[data-round]:hover {
    cursor: pointer !important;
    outline: 2px solid #2563eb !important;
    outline-offset: -2px;
    position: relative;
    z-index: 5;
}

/* Edited cell indicator */
.edited-cell {
    position: relative !important;
}

.edited-cell::after {
    content: '' !important;
    position: absolute !important;
    bottom: 2px !important;
    right: 2px !important;
    width: 7px !important;
    height: 7px !important;
    border-radius: 9999px !important;
    background-color: #3b82f6 !important; /* blue-500 dot */
    border: 1px solid #ffffff !important;
    box-shadow: 0 0 5px rgba(59, 130, 246, 0.8) !important;
    z-index: 6 !important;
}

html.dark .edited-cell::after,
body.dark-mode .edited-cell::after {
    border-color: #1e293b !important;
}

/* Compare Mode: Deltas */
.delta-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.72rem;
    font-weight: 800;
    margin-left: 0.4rem;
    line-height: 1;
}

.delta-up {
    color: #10b981 !important; /* green-500 */
}

.delta-down {
    color: #ef4444 !important; /* red-500 */
}

.delta-equal {
    color: #9ca3af !important; /* gray-400 */
}

/* Active Toggle Buttons */
.btn-toggle-active {
    background-color: #2563eb !important;
    border-color: #2563eb !important;
    color: #ffffff !important;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3) !important;
}

.btn-toggle-active i {
    color: #ffffff !important;
}

/* ---------------------------------------------------------------- */
/* Mobile Viewport Optimizations                                    */
/* ---------------------------------------------------------------- */

@media (max-width: 640px) {
    /* Compact driver column on small screens */
    table.matrix-table thead tr th.matrix-driver-th,
    th.matrix-driver-th,
    table.matrix-table tbody tr td.matrix-driver-td,
    td.matrix-driver-td {
        padding-left: 0.45rem !important;
        padding-right: 0.45rem !important;
        font-size: 0.75rem !important;
    }

    /* Subtle elevated divider shadow when scrolling horizontally */
    table.matrix-table thead tr th.matrix-driver-th,
    th.matrix-driver-th {
        box-shadow: 2px 0 5px rgba(0, 0, 0, 0.35) !important;
    }

    table.matrix-table tbody tr td.matrix-driver-td,
    td.matrix-driver-td {
        box-shadow: 2px 0 5px rgba(0, 0, 0, 0.25) !important;
    }

    /* Slightly more compact cells on mobile */
    table.matrix-table thead tr th.matrix-round-th,
    table.matrix-table thead tr th.matrix-sprint-th {
        width: 2.5rem !important;
        min-width: 2.5rem !important;
        padding: 0.35rem 0.2rem !important;
        font-size: 0.72rem !important;
    }

    /* Compact points column on mobile */
    table.matrix-table thead tr th.matrix-total-th,
    .matrix-total-th,
    table.matrix-table tbody tr td.matrix-total-td,
    .matrix-total-td {
        width: 4.25rem !important;
        min-width: 4.25rem !important;
        max-width: 4.25rem !important;
        padding-left: 0.35rem !important;
        padding-right: 0.35rem !important;
        font-size: 0.75rem !important;
    }
}

/* ---------------------------------------------------------------- */
/* Edit Result Popover Modal & Select Optimizations                */
/* ---------------------------------------------------------------- */

#sandbox-edit-popover .modal-content-wrapper {
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
}

#edit-position-select,
#edit-status-select {
    max-height: 220px;
    font-size: 0.875rem !important;
}

#edit-position-select option,
#edit-status-select option {
    padding: 6px 10px;
    font-size: 0.85rem;
}

html.dark #edit-position-select option,
html.dark #edit-status-select option,
body.dark-mode #edit-position-select option,
body.dark-mode #edit-status-select option {
    background-color: #1e293b;
    color: #f8fafc;
}

/* ---------------------------------------------------------------- */
/* Modals Z-Index & Modal Sizing                                    */
/* ---------------------------------------------------------------- */

#sandbox-custom-points-modal,
#sandbox-edit-popover {
    z-index: 1000 !important;
}

#sandbox-custom-points-modal .modal-content-wrapper,
#sandbox-edit-popover .modal-content-wrapper {
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    overflow-x: hidden !important;
}

#custom-points-inputs-grid {
    overflow-x: hidden !important;
}

/* Global scrollbars from dark_mode.css apply here now */

/* Hide spin buttons so numbers aren't truncated by native up/down arrows */
.custom-point-input::-webkit-inner-spin-button,
.custom-point-input::-webkit-outer-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
}

.custom-point-input {
    -moz-appearance: textfield !important;
}

/* ---------------------------------------------------------------- */
/* Laps by Position Grid                                           */
/* ---------------------------------------------------------------- */

.laps-pos-th {
    min-width: 44px;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.laps-pos-cell {
    min-width: 44px;
    text-align: center;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    padding: 0.4rem 0.35rem !important;
    white-space: nowrap;
    transition: background-color 0.15s ease;
}

.laps-pos-zero {
    color: #9ca3af;
    opacity: 0.35;
}

html.dark .laps-pos-zero,
body.dark-mode .laps-pos-zero {
    color: #6b7280;
    opacity: 0.3;
}

.laps-pos-total-th {
    min-width: 56px;
    text-align: center;
}

.laps-pos-total-td {
    min-width: 56px;
    text-align: center;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.82rem;
    font-weight: 700;
    background-color: rgba(243, 244, 246, 0.6);
}

html.dark .laps-pos-total-td,
body.dark-mode .laps-pos-total-td {
    background-color: rgba(31, 41, 55, 0.6);
}







