/* ============================================================
   F1 TELEMETRY SYSTEM :: TERMINAL UI STYLESHEET
   ============================================================ */

/* -- CSS Variables ------------------------------------------ */
:root {
    --bg:         #0a0a0a;
    --bg-panel:   #0d0d0d;
    --fg:         #d4d4d4;
    --fg-dim:     #999999;
    --fg-muted:   #555555;
    --amber:      #ffb000;
    --red:        #ff0040;
    --white:      #e0e0e0;
    --white-dim:  #666666;
    --blue:       #0088ff;
    --purple:     #cc44ff;
    --border:     #555555;
    --border-dim: #2a2a2a;
    --font:       'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', 'Consolas', monospace;

    /* Compound colors */
    --soft:       #ff0040;
    --medium:     #ffb000;
    --hard:       #cccccc;
    --inter:      #00ff41;
    --wet:        #0088ff;

    /* Sector colors */
    --sector-1:   #d93333;
    --sector-2:   #3366d9;
    --sector-3:   #d98c33;
}

/* -- Reset & Base ------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 13px;
}

body {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    font-variant-numeric: tabular-nums;
    min-height: 100vh;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* -- CRT Scanline Overlay (removed — caused blurry text) ---- */

/* -- Links -------------------------------------------------- */
a {
    color: var(--fg);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* -- Layout Container --------------------------------------- */
.term-container {
    max-width: 100%;
    padding: 0 12px;
}

/* -- ASCII Header / Nav ------------------------------------- */
.term-header {
    background: var(--bg);
    border-bottom: none;
    padding: 0;
    font-size: 1rem;
}

.term-header pre {
    margin: 0;
    color: var(--fg);
    line-height: 1.2;
    white-space: pre;
    overflow-x: auto;
}

.term-nav {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.term-nav a {
    color: var(--white-dim);
    padding: 2px 8px;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
}
.term-nav a:hover {
    color: var(--fg);
    text-decoration: underline;
}
.term-nav a.active {
    color: var(--bg);
    background: var(--fg);
    text-decoration: none;
}

/* -- Blinking LIVE indicator -------------------------------- */
@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}
.blink {
    animation: blink 1s infinite;
}

/* -- Blinking cursor ---------------------------------------- */
@keyframes cursor-blink {
    0%, 49% { border-right-color: var(--fg); }
    50%, 100% { border-right-color: transparent; }
}
.cursor-blink {
    border-right: 2px solid var(--fg);
    animation: cursor-blink 1s infinite;
    padding-right: 2px;
}

/* -- ASCII Panel Boxes -------------------------------------- */
.term-panel {
    border: 1px solid var(--border-dim);
    background: var(--bg-panel);
    margin-bottom: 8px;
    position: relative;
}

.term-panel-title {
    color: var(--fg);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-dim);
    background: var(--bg);
}

.term-panel-body {
    padding: 8px;
}

/* -- Breadcrumb --------------------------------------------- */
.term-breadcrumb {
    color: var(--white-dim);
    font-size: 0.85rem;
    padding: 8px 0;
}
.term-breadcrumb a {
    color: var(--fg-dim);
}
.term-breadcrumb a:hover {
    color: var(--fg);
    text-decoration: underline;
}
.term-breadcrumb .sep {
    color: var(--white-dim);
    margin: 0 4px;
}

/* -- Year Tabs ---------------------------------------------- */
.year-tab {
    display: inline-block;
    padding: 2px 8px;
    color: var(--white-dim);
    font-size: 0.85rem;
    text-transform: uppercase;
    border: 1px solid transparent;
}
.year-tab:hover {
    color: var(--fg);
    text-decoration: underline;
}
.year-tab.active {
    color: var(--bg);
    background: var(--fg);
    border-color: var(--fg);
    text-decoration: none;
}

/* -- Schedule / Event Cards --------------------------------- */
.event-row {
    display: block;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-dim);
    color: var(--white);
    font-size: 0.85rem;
    transition: none;
}
.event-row:hover {
    background: rgba(0, 255, 65, 0.05);
    color: var(--fg);
    text-decoration: none;
}
.event-round {
    color: var(--fg);
    display: inline-block;
    min-width: 32px;
    text-align: right;
    margin-right: 12px;
}
.event-name {
    color: var(--white);
    min-width: 260px;
    display: inline-block;
}
.event-row:hover .event-name {
    color: var(--fg);
}
.event-circuit {
    color: var(--white-dim);
    min-width: 200px;
    display: inline-block;
}
.event-date {
    color: var(--white-dim);
    display: inline-block;
}
.event-sprint {
    color: var(--amber);
    font-size: 0.75rem;
    margin-left: 8px;
}
.event-future {
    cursor: default;
    opacity: 0.4;
}
.event-future:hover {
    background: none;
}

/* -- Session Cards ------------------------------------------ */
.session-row {
    display: block;
    padding: 8px;
    border-bottom: 1px solid var(--border-dim);
    color: var(--white);
}
.session-row:hover {
    background: rgba(0, 255, 65, 0.05);
    color: var(--fg);
    text-decoration: none;
}
.session-future {
    cursor: default;
    opacity: 0.4;
}
.session-future:hover {
    background: none;
}
.session-status {
    font-size: 0.75rem;
    text-transform: uppercase;
    padding: 1px 6px;
}
.session-status.completed {
    color: var(--fg);
}
.session-status.started {
    color: var(--amber);
}
.session-status.scheduled {
    color: var(--white-dim);
}

/* -- Canvas Wrapper ----------------------------------------- */
#trackCanvas, #replayCanvas, #trackCanvasA, #trackCanvasB {
    background: #000;
    border: 1px solid var(--border-dim);
    display: block;
}

/* -- Driver Badge ------------------------------------------- */
.driver-badge {
    display: inline-block;
    padding: 2px 8px;
    font-weight: 700;
    font-size: 0.75rem;
    cursor: pointer;
    background: transparent !important;
    border: 1px solid var(--border-dim);
    font-family: var(--font);
    transition: none;
}
.driver-badge:hover {
    text-decoration: underline;
}

/* Visibility-toggle driver badges (session page driver selector) */
.driver-toggle {
    opacity: 0.3;
}
.driver-toggle.active {
    opacity: 1;
    border-color: currentColor;
}

/* -- Layer Toggle Buttons ----------------------------------- */
.layer-btn {
    background: transparent;
    border: 1px solid var(--border-dim);
    color: var(--white-dim);
    padding: 2px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    font-family: var(--font);
    text-transform: uppercase;
    border-radius: 0;
    transition: none;
}
.layer-btn:hover {
    color: var(--fg);
    border-color: var(--fg-dim);
    text-decoration: underline;
}
.layer-btn.active {
    background: var(--fg);
    border-color: var(--fg);
    color: #000;
    text-decoration: none;
}

/* -- Playback Controls -------------------------------------- */
.playback-btn {
    background: transparent;
    border: 1px solid var(--border-dim);
    color: var(--fg);
    padding: 4px 12px;
    font-family: var(--font);
    font-size: 0.8rem;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 0;
    transition: none;
    text-decoration: none;
    display: inline-block;
}
.playback-btn:hover {
    border-color: var(--fg);
    text-decoration: underline;
}
.playback-btn.active {
    background: var(--fg);
    border-color: var(--fg);
    color: #000;
    text-decoration: none;
}

/* -- Select / Input Elements -------------------------------- */
select, input[type="text"] {
    background: #000;
    border: 1px solid var(--border-dim);
    color: var(--fg);
    padding: 4px 8px;
    font-family: var(--font);
    font-size: 0.8rem;
    border-radius: 0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
select:focus, input[type="text"]:focus {
    border-color: var(--fg);
}

/* -- Lap Table ---------------------------------------------- */
.lap-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.lap-table th {
    color: var(--fg-dim);
    text-transform: uppercase;
    text-align: left;
    padding: 4px 6px;
    border-bottom: 1px solid var(--border-dim);
    font-weight: normal;
    letter-spacing: 0.05em;
}
.lap-table th.right {
    text-align: right;
}
.lap-table td {
    padding: 3px 6px;
    border-bottom: 1px solid rgba(0, 255, 65, 0.05);
    color: var(--white);
}
.lap-table td.right {
    text-align: right;
}

.lap-row {
    cursor: pointer;
}
.lap-row:hover {
    background: rgba(0, 255, 65, 0.08);
}
.lap-row.fastest td {
    color: var(--purple);
}
.lap-row.selected {
    background: rgba(0, 255, 65, 0.1);
}

/* -- Sector Colors ------------------------------------------ */
.sector-best    { color: var(--purple) !important; }
.sector-personal { color: var(--fg) !important; }
.sector-normal  { color: var(--amber) !important; }

/* -- Telemetry Bar ------------------------------------------ */
.telemetry-bar-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.telemetry-label {
    color: var(--fg-dim);
    text-transform: uppercase;
    font-size: 0.75rem;
    min-width: 80px;
    letter-spacing: 0.05em;
}
.telemetry-bar-track {
    flex: 1;
    height: 10px;
    background: #111;
    border: 1px solid var(--border-dim);
    position: relative;
    overflow: hidden;
}
.telemetry-bar {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 0;
}
.telemetry-bar.speed    { background: var(--blue); }
.telemetry-bar.throttle { background: var(--fg); }
.telemetry-bar.brake    { background: var(--red); }
.telemetry-value {
    color: var(--white);
    font-size: 0.8rem;
    min-width: 64px;
    text-align: right;
}

/* -- Telemetry Data Grid ------------------------------------ */
.data-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    border-bottom: 1px solid rgba(0, 255, 65, 0.05);
    font-size: 0.8rem;
}
.data-label {
    color: var(--fg-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.data-value {
    color: var(--white);
}

/* -- Speed Histogram ---------------------------------------- */
.histogram {
    display: flex;
    align-items: flex-end;
    gap: 1px;
    height: 48px;
}
.histogram-bar {
    flex: 1;
    background: var(--fg-dim);
    min-width: 2px;
}

/* -- Tire Compound Colors ----------------------------------- */
.compound-soft         { background: var(--soft); color: #fff; }
.compound-medium       { background: var(--medium); color: #000; }
.compound-hard         { background: var(--hard); color: #000; }
.compound-intermediate { background: var(--inter); color: #000; }
.compound-wet          { background: var(--wet); color: #fff; }

.compound-text-soft         { color: var(--soft); }
.compound-text-medium       { color: var(--medium); }
.compound-text-hard         { color: var(--hard); }
.compound-text-intermediate { color: var(--inter); }
.compound-text-wet          { color: var(--wet); }

/* -- Strategy Timeline -------------------------------------- */
.stint-bar-container {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 8px;
    position: relative;
}
.stint-bar {
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    position: relative;
    min-width: 20px;
    border-radius: 0;
}
.stint-detail {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    padding: 3px 0;
    border-bottom: 1px solid rgba(0, 255, 65, 0.05);
}
.stint-compound-tag {
    display: inline-block;
    min-width: 56px;
    text-align: center;
    padding: 1px 4px;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 0;
}

.pit-marker {
    width: 2px;
    background: var(--red);
    position: absolute;
    top: -4px;
    bottom: -4px;
}

.pit-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    padding: 2px 0;
}
.pit-row .pit-lap {
    color: var(--white-dim);
}
.pit-row .pit-time {
    color: var(--amber);
}

/* -- Weather Panel ------------------------------------------ */
.weather-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(0, 255, 65, 0.05);
    font-size: 0.85rem;
}
.weather-row:last-child {
    border-bottom: none;
}
.weather-label {
    color: var(--fg-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.weather-value-text {
    color: var(--white);
}
.weather-rain-yes {
    color: var(--blue);
}

/* -- Compare View ------------------------------------------- */
.compare-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.compare-divider {
    display: none; /* handled by grid gap */
}

/* -- Flex Layout Utilities ---------------------------------- */
.flex-row {
    display: flex;
    flex-direction: row;
}
.flex-col {
    display: flex;
    flex-direction: column;
}
.flex-wrap {
    flex-wrap: wrap;
}
.flex-1 {
    flex: 1;
}
.gap-2 { gap: 2px; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.ml-auto { margin-left: auto; }

.w-full { width: 100%; }
.overflow-y-auto { overflow-y: auto; }
.max-h-320 { max-height: 320px; }

.text-amber { color: var(--amber); }
.text-red { color: var(--red); }
.text-green { color: var(--fg); }
.text-muted { color: var(--white-dim); }
.text-white { color: var(--white); }
.text-dim { color: var(--fg-dim); }

.uppercase { text-transform: uppercase; }
.font-bold { font-weight: 700; }

/* -- Seek Slider -------------------------------------------- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border-dim);
    border-radius: 0;
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 10px;
    height: 16px;
    background: var(--fg);
    cursor: pointer;
    border-radius: 0;
}
input[type="range"]::-moz-range-thumb {
    width: 10px;
    height: 16px;
    background: var(--fg);
    cursor: pointer;
    border: none;
    border-radius: 0;
}

/* -- Scrollbar ---------------------------------------------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #000;
}
::-webkit-scrollbar-thumb {
    background: var(--border-dim);
    border-radius: 0;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--fg-dim);
}

/* -- Conditions Labels -------------------------------------- */
.conditions-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    align-items: center;
}
.conditions-labels .cond-item {
    font-size: 0.75rem;
    white-space: nowrap;
}
.conditions-labels .cond-label {
    color: var(--fg-muted);
}
.conditions-labels .cond-value {
    color: var(--fg-dim);
}
.conditions-labels .cond-rain-yes {
    color: var(--blue);
    font-weight: bold;
}

/* -- Position Indicators ------------------------------------ */
.position-indicator {
    font-size: 0.6rem;
    font-weight: 700;
    margin-right: 2px;
    vertical-align: middle;
}
.position-p1 { color: #ffd700; }
.position-p2 { color: #c0c0c0; }
.position-p3 { color: #cd7f32; }

/* -- Live Telemetry HUD ------------------------------------- */
.live-telemetry {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 0.8rem;
    padding: 4px 8px;
    border: 1px solid var(--border-dim);
    background: var(--bg-panel);
    margin-top: 4px;
}
.live-telemetry .live-label {
    color: var(--fg-muted);
    text-transform: uppercase;
    font-size: 0.7rem;
}
.live-telemetry .live-value {
    color: var(--fg);
    font-weight: 700;
}
.live-telemetry .live-brake-on {
    color: var(--red);
    font-weight: 700;
}
.live-telemetry .live-brake-off {
    color: var(--fg-muted);
}

/* -- Race Tower -------------------------------------------- */
.tower-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
.tower-table th {
    color: var(--fg-muted); text-transform: uppercase; padding: 3px 4px;
    border-bottom: 1px solid var(--border-dim); font-weight: normal;
    font-size: 0.65rem; letter-spacing: 0.05em; white-space: nowrap;
    text-align: left;
}
.tower-table td {
    padding: 2px 4px; border-bottom: 1px solid rgba(42,42,42,0.5);
    white-space: nowrap; vertical-align: middle;
}
.tower-row { transition: background 0.1s; }
.tower-row:hover { background: rgba(255,255,255,0.03); }
.tower-pos { font-weight: 700; text-align: center; min-width: 20px; }
.tower-pos-1 { color: #ffd700; }
.tower-pos-2 { color: #c0c0c0; }
.tower-pos-3 { color: #cd7f32; }
.tower-team-bar {
    display: inline-block; width: 3px; height: 14px; border-radius: 1px;
    margin-right: 4px; vertical-align: middle;
}
.tower-abbrev { font-weight: 700; font-size: 0.75rem; }
.tower-speed { color: var(--fg); width: 4ch; text-align: right; }
.tower-gear { color: var(--fg-dim); text-align: center; width: 2ch; }
.tower-pit { color: var(--amber); text-align: center; }
.tower-sector { font-size: 0.7rem; font-weight: 700; }
.tower-lap { color: var(--fg-dim); text-align: center; }
.tower-tire {
    display: inline-block; width: 14px; height: 14px; border-radius: 50%;
    text-align: center; line-height: 14px; font-size: 0.55rem; font-weight: 700;
}
.tower-bar-container {
    display: flex; gap: 1px; width: 48px; height: 8px; align-items: stretch;
}
.tower-thr-bar { background: rgba(0,200,0,0.7); transition: width 0.15s; }
.tower-brk-bar { background: rgba(255,0,64,0.8); transition: width 0.15s; }
.tower-row-out { opacity: 0.35; }
.tower-row-out .tower-pos { color: var(--fg-dim); }

/* -- Responsive --------------------------------------------- */
@media (max-width: 768px) {
    .compare-grid {
        grid-template-columns: 1fr;
    }
    .event-name, .event-circuit {
        min-width: auto;
        display: block;
    }
    .event-row {
        padding: 8px;
    }
    .session-grid {
        grid-template-columns: 1fr;
    }
    .main-layout {
        flex-direction: column;
    }
    .main-layout .left-col,
    .main-layout .right-col {
        width: 100%;
    }
    .term-container {
        padding: 0 6px;
    }
    .term-header pre {
        display: none;
    }
    .term-footer {
        flex-direction: column;
        gap: 4px;
    }
}

/* -- Session grid ------------------------------------------- */
.session-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}

/* -- Main session layout (legacy 2-col, kept for compare) --- */
.main-layout {
    display: flex;
    gap: 12px;
}
.main-layout .left-col {
    flex: 3;
    min-width: 0;
}
.main-layout .right-col {
    flex: 2;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* -- Session Page Wrapper ----------------------------------- */
.term-container:has(.session-page) {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}
.term-container:has(.session-page) > main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.session-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* -- Session Compact Header --------------------------------- */
.session-compact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
    border-bottom: 1px solid var(--border-dim);
    margin-bottom: 2px;
    flex-shrink: 0;
}

/* -- Session 3-Column Layout (viewport-filling, tmux-style) - */
.session-layout {
    display: grid;
    grid-template-columns: 280px 4px 1fr 4px 260px;
    grid-template-rows: 1fr auto;
    gap: 0;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}
.session-left {
    grid-column: 1;
    grid-row: 1;
    overflow-y: auto;
    min-height: 0;
    padding-right: 4px;
}
.session-center {
    grid-column: 3;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.session-right {
    grid-column: 5;
    grid-row: 1;
    min-height: 0;
    padding-left: 4px;
    display: flex;
    flex-direction: column;
}
.pane-resize-handle:first-of-type { grid-column: 2; grid-row: 1; }
.pane-resize-handle:last-of-type  { grid-column: 4; grid-row: 1; }
.session-bottom {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-shrink: 0;
}

/* Track panel fills center column vertically */
.track-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.track-panel .term-panel-body {
    flex: 1;
    min-height: 0;
}

/* -- Session Top Bar ---------------------------------------- */
.session-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-dim);
}
.session-topbar .topbar-title {
    color: var(--fg-dim);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
}
.session-topbar .topbar-version {
    color: var(--fg-muted);
    font-size: 0.65rem;
}

/* -- Column Headers ----------------------------------------- */
.col-header {
    color: var(--fg-dim);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 0;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.col-header .col-label {
    color: var(--fg);
    font-weight: 700;
}
.col-header .col-sub {
    color: var(--fg-muted);
    font-size: 0.65rem;
}

/* -- Driver Cards ------------------------------------------- */
.driver-card {
    background: #111;
    border-bottom: 1px solid var(--border-dim);
    border-left: 3px solid #555;
    padding: 6px 8px;
    margin-bottom: 1px;
    cursor: pointer;
    transition: background 0.1s;
}
.driver-card:hover {
    background: #1a1a1a;
}
.driver-card.selected {
    background: #1a1a1a;
    border-left-width: 4px;
}
.driver-card.driver-out {
    opacity: 0.35;
}
.driver-card-row1 {
    display: flex;
    align-items: center;
    gap: 6px;
}
.driver-card .card-eye {
    color: var(--fg-dim);
    font-size: 0.55rem;
    cursor: pointer;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    transition: background 0.1s;
}
.driver-card .card-eye:hover {
    background: rgba(255,255,255,0.1);
}
.driver-card .card-eye.hidden {
    opacity: 0.2;
    color: var(--fg-muted);
}
.driver-card .card-pos {
    font-weight: 700;
    font-size: 0.8rem;
    min-width: 20px;
    text-align: center;
}
.driver-card .card-pos-1 { color: #ffd700; }
.driver-card .card-pos-2 { color: #c0c0c0; }
.driver-card .card-pos-3 { color: #cd7f32; }
.driver-card .card-abbr {
    font-weight: 700;
    font-size: 0.8rem;
    min-width: 32px;
}
.driver-card .card-gap {
    color: var(--fg-muted);
    font-size: 0.7rem;
    flex: 1;
}
.driver-card .card-tire-wrap {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-left: auto;
}
.driver-card .card-tire {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    text-align: center;
    line-height: 14px;
    font-size: 0.55rem;
    font-weight: 700;
}
.driver-card .card-tire-age {
    color: var(--fg-muted);
    font-size: 0.6rem;
}
.driver-card .card-pits {
    color: var(--amber);
    font-size: 0.6rem;
    font-weight: 700;
    min-width: 2ch;
    text-align: right;
}
.driver-card-row2 {
    display: flex;
    gap: 8px;
    font-size: 0.6rem;
    color: var(--fg-muted);
    margin-top: 3px;
    flex-wrap: wrap;
}
.driver-card-row2 .val {
    color: var(--fg-dim);
}
.driver-card-row2 .drs-on {
    color: #00cc66;
    font-weight: 700;
}
.driver-card-row2 .drs-off {
    color: var(--fg-muted);
}
.driver-card-row3 {
    font-size: 0.6rem;
    color: var(--fg-dim);
    margin-top: 2px;
    font-family: var(--font);
    letter-spacing: 0;
}

/* -- System Log --------------------------------------------- */
.system-log {
    background: #0a0a0a;
    border: 1px solid var(--border-dim);
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 4px;
}
.log-entry {
    font-size: 0.65rem;
    padding: 2px 4px;
    border-bottom: 1px solid rgba(42,42,42,0.3);
    line-height: 1.5;
    word-break: break-word;
}
.log-entry .log-time {
    color: var(--fg-muted);
}
.log-entry .log-cat {
    font-weight: 700;
    margin: 0 4px;
    font-size: 0.6rem;
}
.log-entry .log-msg {
    color: var(--fg-dim);
}
.log-info .log-cat { color: #00cccc; }
.log-trace .log-cat { color: #555; }
.log-alert .log-cat { color: #ffaa00; }
.log-alert .log-msg { color: #ffaa00; }

/* -- Telemetry HUD ------------------------------------------ */
.telem-hud {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 4px 12px;
    border-top: 1px solid var(--border-dim);
    background: #0a0a0a;
    min-height: 48px;
    flex-wrap: wrap;
}
.hud-driver-label {
    color: var(--fg-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}
.hud-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}
.hud-section .hud-label {
    color: var(--fg-muted);
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.hud-section .hud-value {
    color: var(--fg);
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1;
    width: 6ch;
    text-align: right;
}
.hud-gear {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.hud-gear .hud-label {
    color: var(--fg-muted);
    font-size: 0.6rem;
    text-transform: uppercase;
}
.hud-gear .hud-gear-num {
    color: var(--fg);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    width: 2ch;
    text-align: center;
}
.hud-inputs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 160px;
}
.hud-input-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
}
.hud-input-row .hud-input-label {
    color: var(--fg-muted);
    min-width: 24px;
    text-transform: uppercase;
}
.hud-input-row .hud-ascii-bar {
    font-family: var(--font);
    letter-spacing: 0;
    font-size: 0.6rem;
}
.hud-input-row .hud-pct {
    color: var(--fg-dim);
    width: 4ch;
    text-align: right;
}
.hud-thr-char { color: #00cc66; }
.hud-brk-char { color: var(--red); }
.hud-empty-char { color: #333; }
.hud-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 12px;
}
.hud-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.hud-stat .hud-stat-label {
    color: var(--fg-muted);
    font-size: 0.55rem;
    text-transform: uppercase;
}
.hud-stat .hud-stat-value {
    color: var(--fg);
    font-size: 0.85rem;
    font-weight: 700;
    width: 9ch;
    text-align: center;
}

/* -- Session Status Bar ------------------------------------- */
.session-statusbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
    margin-top: 2px;
    color: var(--fg-muted);
    font-size: 0.6rem;
    border-top: 1px solid var(--border-dim);
    flex-shrink: 0;
}

/* -- Sector Timing Boxes ------------------------------------ */
.sector-timing {
    display: flex;
    gap: 8px;
    margin: 4px 0;
}
.sector-time-box {
    flex: 1;
    background: #111;
    border: 1px solid var(--border-dim);
    padding: 4px 8px;
    text-align: center;
    font-size: 0.7rem;
}
.sector-time-box .stb-label {
    color: var(--fg-muted);
    font-size: 0.6rem;
    text-transform: uppercase;
}
.sector-time-box .stb-value {
    color: var(--fg);
    font-weight: 700;
    font-size: 0.85rem;
}

/* -- Responsive: 3-column collapse -------------------------- */
@media (max-width: 1200px) {
    .term-container:has(.session-page) {
        height: auto;
        overflow: visible;
    }
    .session-page {
        height: auto;
        overflow: visible;
    }
    .session-layout {
        display: flex;
        flex-direction: column;
        height: auto;
        overflow: visible;
    }
    .pane-resize-handle { display: none; }
    /* Map first in narrow layout — fill available viewport */
    --session-ui-reserve: 80px; /* header + playback controls */
    .session-center { order: 1; min-height: calc(100dvh - var(--session-ui-reserve)); }
    .session-left   { order: 2; }
    .session-right  { order: 3; }
    .session-bottom { order: 4; }
    .session-left,
    .session-center,
    .session-right {
        max-height: none;
        overflow-y: visible;
    }
}

/* -- Side Nav (vertical icon bar) --------------------------- */
.side-nav {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 44px;
    background: #0a0a0a;
    border-right: 1px solid var(--border-dim);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0;
    gap: 2px;
    z-index: 100;
}
.side-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: var(--fg-muted);
    font-size: 0.7rem;
    font-weight: 700;
    text-decoration: none;
    border-radius: 2px;
    cursor: pointer;
}
.side-nav-icon:hover {
    color: var(--fg);
    background: rgba(255,255,255,0.06);
    text-decoration: none;
}
.side-nav-icon.active {
    color: var(--fg);
    background: rgba(255,255,255,0.1);
}
.side-nav-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 4px;
    border-radius: 2px;
    text-decoration: none;
}
.side-nav-logo:hover {
    background: rgba(255,255,255,0.06);
    text-decoration: none;
}
.side-nav-logo img {
    max-width: 36px;
    height: auto;
    object-fit: contain;
    image-rendering: pixelated;
}
.side-nav-brand {
    color: var(--fg-dim);
    cursor: default;
    pointer-events: none;
    font-size: 0.55rem;
}
.side-nav-spacer {
    flex: 1;
}
/* Offset content for side nav */
body.has-side-nav .term-container {
    margin-left: 44px;
}
@media (max-width: 1200px) {
    .side-nav { display: none; }
    body.has-side-nav .term-container { margin-left: 0; }
}

/* -- Session Loading Overlay -------------------------------- */
.session-loading {
    position: absolute;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: opacity 0.3s;
    max-height: 100dvh;
}
.session-loading.hidden { opacity: 0; pointer-events: none; }
.loading-text { color: var(--fg-muted); font-size: 0.85rem; letter-spacing: 0.1em; text-align: left; }
@keyframes dots { from { width: 0ch; } to { width: 3ch; } }
.loading-dots { display: inline-block; width: 3ch; text-align: left; }
.loading-dots::after { content: '...'; display: inline-block; overflow: hidden; width: 0ch; animation: dots 1.5s infinite steps(3, end); vertical-align: bottom; }

/* Hide main footer on session pages — statusbar serves as footer */
.term-container:has(.session-page) > .term-footer { display: none; }

/* -- Pane Resize Handles ------------------------------------ */
.pane-resize-handle {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.15s;
    flex-shrink: 0;
}
.pane-resize-handle:hover,
.pane-resize-handle.active {
    background: var(--fg-muted);
}

/* -- Empty State -------------------------------------------- */
.empty-state {
    color: var(--white-dim);
    padding: 16px 8px;
    text-align: center;
    font-size: 0.85rem;
    border: 1px solid var(--border-dim);
}

/* -- Schedule grid ------------------------------------------ */
.schedule-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 8px;
}

/* -- Analysis Page ------------------------------------------ */
.analysis-composites {
    margin-bottom: 8px;
}
.composite-row {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-dim);
}
.composite-row select {
    flex: 1;
    min-width: 0;
}
.composite-color-bar {
    width: 3px;
    min-height: 28px;
    flex-shrink: 0;
}
.composite-remove {
    background: none;
    border: 1px solid var(--border-dim);
    color: var(--white-dim);
    cursor: pointer;
    padding: 2px 6px;
    font-family: inherit;
    font-size: 0.75rem;
}
.composite-remove:hover {
    border-color: #ff4444;
    color: #ff4444;
}
/* Analysis page fills viewport via the same pattern as session-page */
.term-container:has(.analysis-page) {
    display: flex;
    flex-direction: column;
    height: 100dvh;
}
.term-container:has(.analysis-page) > main {
    flex: 1;
    min-height: 0;
    display: flex;
}
.term-container:has(.analysis-page) > .term-footer { display: none; }
.analysis-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
.analysis-layout {
    display: grid;
    grid-template-columns: 60fr 40fr;
    grid-template-rows: 1fr;
    gap: 8px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.analysis-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
    overflow-y: auto;
}
.analysis-charts {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-height: 0;
}
.analysis-chart-panel {
    border: 1px solid var(--border-dim);
    background: var(--bg);
    position: relative;
    flex: 1;
    min-height: 0;
}
.analysis-chart-label {
    position: absolute;
    top: 2px;
    left: 6px;
    color: var(--white-dim);
    font-size: 0.65rem;
    text-transform: uppercase;
    z-index: 1;
    pointer-events: none;
}
.analysis-right {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
    overflow-y: auto;
}
.analysis-right .term-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.analysis-right .term-panel-body {
    flex: 1;
    min-height: 0;
}
.analysis-summary-table {
    width: 100%;
    font-size: 0.75rem;
    border-collapse: collapse;
}
.analysis-summary-table th {
    text-align: left;
    color: var(--white-dim);
    font-weight: 400;
    padding: 2px 4px;
    border-bottom: 1px solid var(--border-dim);
}
.analysis-summary-table td {
    padding: 2px 4px;
}
.analysis-summary-table tr:nth-child(even) td {
    background: var(--bg-panel);
}
.analysis-summary-table .fastest {
    color: #00ff41;
}
.analysis-metric-toggles {
    display: flex;
    gap: 4px;
    padding: 4px 0;
    flex-wrap: wrap;
}
.analysis-legend {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 4px 0;
}
.analysis-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--white-dim);
}
.analysis-legend-swatch {
    width: 14px;
    height: 3px;
    display: inline-block;
}
/* uPlot dark theme overrides */
.uplot { font-family: 'JetBrains Mono', monospace; }
.uplot .u-wrap { background: var(--bg) !important; }
.u-legend { display: none !important; }
.u-cursor-x { border-color: #00ff4180 !important; }
.u-cursor-y { display: none !important; }
.u-cursor-pt { display: none !important; }
@media (max-width: 768px) {
    .analysis-layout {
        grid-template-columns: 1fr;
    }
}
