/* ==========================================================================
   BMW M High-Performance Dashboard – Lap Times
   Tailwind + custom layer. Dark #0f0f0f, M-stripes, telemetry table, M-blue glow.
   ========================================================================== */

:root {
    --m-bg: #0f0f0f;
    --m-card: #1a1a1a;
    --m-blue: #0066B2;
    --m-blue-light: #0066B1;
    --m-blue-dark: #003D78;
    --m-red: #E22718;
    --m-stripe-h: 2px;
    /* Background wash – M stripe colors, 30% opacity */
    --m-wash-light: rgba(0, 102, 177, 0.3);
    --m-wash-dark: rgba(0, 61, 120, 0.3);
    --m-wash-red: rgba(226, 39, 24, 0.3);
}

/* ---- 2px M-stripe on data cards (Light Blue | Dark Blue | Red) ---- */
.m-stripe-card {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--m-stripe-h);
    background: linear-gradient(
        90deg,
        var(--m-blue-light) 0%,
        var(--m-blue-light) 33.33%,
        var(--m-blue-dark) 33.33%,
        var(--m-blue-dark) 66.66%,
        var(--m-red) 66.66%,
        var(--m-red) 100%
    );
}

/* ---- Buttons: sharp (2px radius), M-blue glow ---- */
.m-btn-primary {
    border-radius: 2px;
    background: linear-gradient(135deg, var(--m-blue-dark) 0%, var(--m-blue) 100%);
    box-shadow: 0 0 20px rgba(0, 102, 178, 0.35);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.m-btn-primary:hover {
    box-shadow: 0 0 28px rgba(0, 102, 178, 0.5), 0 0 16px rgba(226, 39, 24, 0.2);
    transform: translateY(-1px);
}

/* ---- Selects: sharp, dark ---- */
.m-select {
    border-radius: 2px;
}

.m-select option {
    background: var(--m-bg);
    color: #fff;
}

/* ---- User dropdown: chevron rotates when open ---- */
/* ---- Full-page subtle M-stripe wash (diagonal, very low opacity) ---- */
body {
    padding-top: 0;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    /* Sharper diagonal bands: light blue (left) → dark blue → red */
    background: linear-gradient(
        135deg,
        var(--m-wash-light) 0%,
        var(--m-wash-light) 32%,
        var(--m-wash-dark) 33%,
        var(--m-wash-dark) 65%,
        var(--m-wash-red) 66%,
        var(--m-wash-red) 100%
    );
}

/* ---- Header below M-stripe ---- */

header.sticky {
    top: 0;
}

/* Navbar logo: keep PNG transparency visible (no background, no opacity on container) */
.navbar-logo-link {
    background: transparent !important;
}
.navbar-logo {
    background: transparent !important;
    vertical-align: middle;
}

.m-user-dropdown[open] .m-dropdown-chevron {
    transform: rotate(180deg);
}

/* Nav menu: active item = blue background, no red */
.nav-menu-item.active {
    background-color: #3B71DD !important;
    color: #fff !important;
}
.nav-menu-item:not(.active):hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* ---- Data card ---- */
.m-data-card {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.m-title {
    letter-spacing: 0.12em;
}

/* ---- Telemetry table: no vertical borders, zebra striping (odd/even rows) ---- */
.m-telemetry-table {
    border-spacing: 0;
}

.m-telemetry-table thead tr {
    background: rgba(0, 0, 0, 0.5);
}

.m-telemetry-table tbody tr {
    transition: background 0.2s ease;
}

/* Odd rows: slightly darker */
.m-telemetry-table tbody tr:nth-child(odd),
.m-telemetry-table tbody tr:nth-child(odd) td {
    background: var(--m-bg);
}

/* Even rows: slightly lighter for clear striping */
.m-telemetry-table tbody tr:nth-child(even),
.m-telemetry-table tbody tr:nth-child(even) td {
    background: var(--m-card);
}

.m-telemetry-table tbody tr:hover,
.m-telemetry-table tbody tr:hover td {
    background: rgba(0, 102, 178, 0.12);
}

.m-telemetry-table td {
    padding: 0.5rem 1rem;
    font-size: 0.9375rem;
    color: #D6D6D6;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    white-space: nowrap;
    vertical-align: middle;
}

.m-telemetry-table tbody tr:last-child td {
    border-bottom: none;
}

/* High-contrast racing style for data cells */
.m-telemetry-table tbody td {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

/* ---- Sort indicators (icon text ↑/↓ is set by JS) ---- */
.m-telemetry-table .m-th.sort-asc .sort-icon,
.m-telemetry-table .m-th.sort-desc .sort-icon {
    opacity: 1;
    color: var(--m-blue);
}

/* Diff styling (JS-injected): negative = faster (green), zero, positive = slower (red) */
.diff-negative {
    color: #22c55e;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.diff-positive {
    color: var(--m-red);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.diff-zero {
    color: var(--m-blue);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Diff to #1 column: green (seconds off absolute record) */
.diff-to-record {
    color: #22c55e;
    font-variant-numeric: tabular-nums;
}
.m-telemetry-table td .diff-to-record {
    color: #22c55e;
    font-size: 1rem;
}

/* Gap column: numeric times a bit bigger and bold in table */
.m-telemetry-table td .diff-negative,
.m-telemetry-table td .diff-positive,
.m-telemetry-table td .diff-zero {
    font-size: 1rem;
    font-weight: 700;
}

/* Not Driven (table + mobile): orange, bold – override table cell color */
.diff-not-driven,
.m-telemetry-table td .diff-not-driven {
    color: #f97316 !important;
    font-weight: 700;
    font-style: normal;
}

/* ---- Loading spinner ---- */
.m-spinner {
    animation: m-spin 0.7s linear infinite;
}

@keyframes m-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---- Empty / error states (JS-injected) ---- */
.m-telemetry-table .text-muted {
    color: #D6D6D6 !important;
}

.m-telemetry-table .text-danger {
    color: var(--m-red) !important;
}

.m-telemetry-table .py-5 {
    padding-top: 2.5rem !important;
    padding-bottom: 2.5rem !important;
}

/* ==========================================================================
   Mobile: hamburger menu & nav panel (solid background for readability)
   ========================================================================== */
.m-nav-panel {
    background: #0f0f0f;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.m-nav-panel:not(.hidden) {
    visibility: visible;
    opacity: 1;
}
.m-nav-backdrop {
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.m-nav-backdrop:not(.hidden) {
    visibility: visible;
    opacity: 1;
}
/* Hamburger: reliable tap on mobile (removes 300ms delay) */
.touch-manipulation {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Touch-friendly nav items (min 44px tap target) */
.m-nav-mobile-item {
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}
body.m-nav-open {
    overflow: hidden;
}

/* In-app splash: only visible when PWA (script adds .pwa-splash-visible). Hidden on normal website. */
.pwa-splash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    z-index: 99999;
    background: #0f0f0f;
    display: none;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
    overflow: hidden;
}
.pwa-splash-overlay.pwa-splash-visible {
    display: flex;
}
.pwa-splash-overlay .pwa-splash-img {
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    object-fit: contain;
    object-position: center center;
}
.pwa-splash-overlay.pwa-splash-hidden {
    opacity: 0;
    pointer-events: none;
}

/* ==========================================================================
   Mobile: results as cards (readable, less cramped)
   ========================================================================== */
.m-results-cards {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.m-results-cards .m-card-row {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: var(--m-bg);
    transition: background 0.2s ease;
}
.m-results-cards .m-card-row:nth-child(even) {
    background: var(--m-card);
}
.m-results-cards .m-card-row:active {
    background: rgba(0, 102, 178, 0.12);
}
/* Hero: one main fact (lap time or track) – big and clear */
.m-results-cards .m-card-row .m-card-hero {
    font-size: 1.125rem;
    font-weight: 700;
    color: #fff;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    margin-bottom: 0.35rem;
    line-height: 1.3;
}
/* Single line of context (e.g. track · driver) */
.m-results-cards .m-card-row .m-card-line {
    font-size: 0.8125rem;
    color: #b0b0b0;
    line-height: 1.4;
}
/* Extra line: car, class, diff – muted, one row */
.m-results-cards .m-card-row .m-card-meta {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.25rem;
}
.m-results-cards .m-card-row .m-card-meta .m-card-diff {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}
.m-results-cards .m-card-row .m-card-meta .m-card-diff.positive { color: var(--m-red); }
.m-results-cards .m-card-row .m-card-meta .m-card-diff.negative { color: #22c55e; }
.m-results-cards .m-card-row .m-card-meta .m-card-diff.zero { color: var(--m-blue); }

/* Todo: Gap: Not Driven (bold orange) or Gap: +0.432 (bold red) – in .m-card-line */
.m-results-cards .m-card-row .m-card-line .m-card-gap.not-driven {
    font-weight: 700 !important;
    color: #f97316 !important;
}
.m-results-cards .m-card-row .m-card-line .m-card-gap.has-gap {
    font-weight: 700 !important;
    color: #E22718 !important;
}
/* Mobile: hide table, show cards (no horizontal scroll) */
@media (max-width: 767px) {
    #tableWrapper {
        display: none;
    }
    #resultsCards {
        display: flex;
    }
}
@media (min-width: 768px) {
    #resultsCards {
        display: none !important;
    }
}

/* Time Attack: fastest on track (vs #1 = —) / slower — not Tailwind (classes set from JS). */
.time-attack-row--faster {
    color: #34d399 !important;
}
.time-attack-row--slower {
    color: #f87171 !important;
}
