/* VBOX Telemetry Web UI */

:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --surface2: #0f3460;
    --accent: #e94560;
    --text: #eee;
    --text-dim: #999;
    --green: #00e676;
    --red: #ff5252;
    --orange: #ffa726;
    --blue: #42a5f5;
    --splitter: #0f3460;
    --splitter-hover: #e94560;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

/* Layout: header, telemetry strip, main, footer */
body {
    display: flex;
    flex-direction: column;
}

/* ---- Header (single row: status + telemetry) ---- */
#header {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 16px;
    padding: 4px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--surface2);
    flex-shrink: 0;
}
.status-badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.status-badge.connected { background: var(--green); color: #000; }
.status-badge.disconnected { background: var(--red); color: #fff; }
.stat { font-size: 12px; color: var(--text-dim); font-family: 'Consolas', monospace; }
.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
}
.header-right .label { font-size: 11px; color: var(--text-dim); }
.latency-value {
    font-family: 'Consolas', monospace;
    font-size: 14px;
    font-weight: 700;
}
.latency-good { color: var(--green); }
.latency-warn { color: var(--orange); }
.latency-bad { color: var(--red); }

/* ---- Telemetry items (inline in header) ---- */
.telem-item {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 38px;
    min-width: 60px;
}
.telem-label {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
}
.telem-value {
    font-family: 'Consolas', monospace;
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}
.telem-unit {
    font-size: 10px;
    color: var(--text-dim);
}
.delta-ahead { color: var(--green); }
.delta-behind { color: var(--red); }
.delta-neutral { color: var(--text-dim); }

/* ---- Main area ---- */
#main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left column: charts + lap times */
#left-col {
    flex: 0 0 75%;
    min-width: 250px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chart panels fill available space */
.chart-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100px;
    overflow: hidden;
}
.chart-panel h3 {
    flex-shrink: 0;
}
.chart-wrap {
    flex: 1;
    position: relative;
    min-height: 0;
}
.chart-wrap canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

/* Lap times panel — matches delta chart panel (both flex:1 in their columns) */
#lap-times-panel {
    flex: 1;
    overflow-y: auto;
    border-top: 1px solid var(--surface2);
    min-height: 60px;
}

/* Right column: map */
#right-col {
    flex: 1;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Map — matches speed chart panel (both flex:1 in their columns) */
#map-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
#map {
    flex: 1;
}
#map-controls {
    padding: 6px 12px;
    background: var(--surface);
    font-size: 13px;
    display: flex;
    gap: 16px;
    align-items: center;
    flex-shrink: 0;
}
#map-controls label {
    cursor: pointer;
    user-select: none;
}

/* ---- Splitters ---- */
.splitter {
    flex-shrink: 0;
    background: var(--splitter);
    transition: background 0.15s;
}
.splitter:hover, .splitter.active {
    background: var(--splitter-hover);
}

/* Vertical splitter (between left and right columns) */
.splitter-v {
    width: 6px;
    cursor: col-resize;
}

/* Horizontal splitter (between speed and delta charts) */
.splitter-h {
    height: 6px;
    cursor: row-resize;
}

/* Panels */
.panel {
    padding: 10px 12px;
}
.panel h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

/* Lap times */
#lap-times-list {
    font-family: 'Consolas', monospace;
    font-size: 14px;
    overflow-y: auto;
}
.lap-entry {
    padding: 2px 0;
}
.lap-fastest {
    color: var(--green);
    font-weight: 700;
}

/* ---- Footer ---- */
#footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--surface);
    border-top: 1px solid var(--surface2);
    flex-shrink: 0;
}
.footer-left, .footer-center, .footer-ref, .footer-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
#vbo-status {
    font-family: 'Consolas', monospace;
    font-size: 13px;
    color: var(--text-dim);
}

/* Buttons */
.btn {
    padding: 5px 14px;
    border: 1px solid var(--surface2);
    border-radius: 4px;
    background: var(--surface2);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.btn:hover:not(:disabled) { background: #1a4a80; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-sm { padding: 3px 10px; font-size: 12px; }

/* Circuit & reference selects */
#circuit-select, #ref-vbo-select, #ref-lap-select {
    padding: 4px 8px;
    border: 1px solid var(--surface2);
    border-radius: 4px;
    background: var(--surface2);
    color: var(--text);
    font-size: 13px;
    max-width: 240px;
}
#ref-lap-select { max-width: 120px; }
.ref-checkbox { font-size: 12px; color: var(--text-dim); cursor: pointer; user-select: none; }
#footer label {
    font-size: 13px;
    color: var(--text-dim);
}

/* Prevent text selection while dragging splitters */
body.resizing {
    user-select: none;
    -webkit-user-select: none;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 3px; }

/* ---- Mobile layout ---- */
@media (max-width: 768px) {
    #header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 4px 8px;
    }
    .telem-item { height: auto; min-width: 50px; }
    .telem-value { font-size: 14px; }
    .header-right { display: none; }
    .stat { display: none; }

    #main {
        flex-direction: column;
        overflow-y: auto;
    }
    #left-col {
        flex: none !important;
        width: 100% !important;
        min-width: 0;
        min-height: 0;
    }
    .chart-panel { min-height: 200px; }
    .splitter-v { display: none; }
    #right-col {
        flex: none;
        width: 100%;
        min-width: 0;
        height: 300px;
    }
    #lap-times-panel { max-height: 100px; }

    #footer {
        flex-wrap: wrap;
        gap: 6px;
        padding: 6px 8px;
    }
    #footer .footer-center { order: 3; width: 100%; justify-content: center; }
}

/* Mobile landscape: fullscreen speed chart */
@media (max-width: 900px) and (orientation: landscape) {
    #header, #footer { display: none; }
    #main {
        flex-direction: row;
        overflow: hidden;
    }
    #left-col {
        flex: 1 !important;
        width: 100% !important;
        min-width: 0;
    }
    #speed-chart-panel {
        flex: 1;
        min-height: 0;
    }
    #h-splitter,
    #delta-chart-panel,
    #lap-times-panel,
    .splitter-v,
    #right-col { display: none; }
}
