/* 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;
}

/* Swipe container: transparent on desktop */
#swipe-container {
    display: contents;
}
.swipe-page {
    display: contents;
}
.swipe-dots {
    display: none;
}
#swipe-page-laps {
    display: none;
}

/* Left column: charts + lap times */
#left-col {
    flex: 0 0 75%;
    min-width: 250px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Chart panels fill available space */
.chart-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100px;
    overflow: hidden;
    position: relative;
}
.chart-panel h3 {
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
}
.ghost-toggle {
    float: right;
    font-size: 11px;
    font-weight: 400;
    color: var(--text-dim);
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0;
}
.chart-panel h3::before {
    content: '\25BC';  /* ▼ */
    display: inline-block;
    margin-right: 6px;
    font-size: 10px;
    transition: transform 0.15s;
}
.chart-panel.collapsed h3::before {
    transform: rotate(-90deg);
}
.chart-panel.collapsed {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    height: auto !important;
    padding: 2px 12px !important;
}
.chart-panel.collapsed h3 {
    margin-bottom: 0;
}
.chart-panel.collapsed .chart-wrap {
    display: none;
}
.chart-panel.collapsed + .splitter-h {
    display: none;
}
.chart-wrap {
    flex: 1;
    position: relative;
    min-height: 0;
}
.chart-wrap canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

/* Speed chart bigger, delta-t smaller */
#speed-chart-panel { flex: 3; min-height: 180px; }
#delta-chart-panel { flex: 1; min-height: 100px; }

/* Extra (user-added) charts — fixed height, stacked below primary */
#extra-charts {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}
.extra-chart-panel {
    flex: 0 0 160px;
    border-top: 1px solid var(--surface2);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 0 !important;
    position: relative;
}
.extra-chart-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    flex-shrink: 0;
}
.extra-chart-header .line-color {
    width: 24px;
    height: 22px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
}
.extra-chart-header .channel-select,
.extra-chart-header .channel-select-2 {
    padding: 2px 6px;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--surface2);
    border-radius: 3px;
    font-size: 12px;
    max-width: 140px;
}
.extra-chart-header .extra-channel-plus {
    color: var(--text-dim);
    font-size: 12px;
    user-select: none;
}
.extra-chart-header .btn-configure-chart,
.extra-chart-header .btn-remove-chart {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    line-height: 1;
}
.extra-chart-header .btn-configure-chart {
    margin-left: auto;
}
.extra-chart-header .btn-remove-chart:hover { color: var(--red); }
.extra-chart-header .btn-configure-chart:hover { color: var(--accent); }
.extra-chart-header .match-y-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}
.extra-chart-header .match-y-label input { margin: 0; cursor: pointer; }
.extra-chart-header .match-y-label:hover { color: var(--text); }

/* Searchable channel combobox */
.channel-combo {
    position: relative;
    display: inline-block;
}
.channel-combo-input {
    padding: 2px 6px;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--surface2);
    border-radius: 3px;
    font-size: 12px;
    min-width: 110px;
    max-width: 180px;
}
.channel-combo-input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface);
}
.channel-combo-list {
    position: fixed;
    z-index: 100000;
    margin: 2px 0 0 0;
    padding: 0;
    list-style: none;
    background: var(--surface, #1e1e2a);
    border: 1px solid var(--surface2);
    border-radius: 3px;
    max-height: 280px;
    overflow-y: auto;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.channel-combo-item {
    padding: 4px 10px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text);
    white-space: nowrap;
}
.channel-combo-item:hover,
.channel-combo-item.active { background: var(--surface2); }
.channel-combo-item.selected { background: var(--accent); color: #fff; }
.channel-combo-empty {
    color: var(--text-dim);
    font-style: italic;
    cursor: default;
}
.channel-combo-empty:hover { background: transparent; }
.extra-chart-header .y-range-group {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--text-dim);
    font-size: 11px;
}
.extra-chart-header .y-range-label {
    user-select: none;
}
.extra-chart-header .y-range-group input[type="number"] {
    width: 50px;
    padding: 2px 4px;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--surface2);
    border-radius: 3px;
    font-size: 11px;
}
.extra-chart-header .y-range-group input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}
/* Hide spinner arrows in number inputs */
.extra-chart-header .y-range-group input[type=number]::-webkit-inner-spin-button,
.extra-chart-header .y-range-group input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.extra-chart-header .y-range-group input[type=number] { -moz-appearance: textfield; }
.extra-chart-panel .chart-wrap {
    flex: 1;
    position: relative;
    min-height: 0;
}

#btn-add-chart {
    flex-shrink: 0;
}

.layout-controls {
    display: flex;
    gap: 6px;
    margin: 6px 12px;
    flex-shrink: 0;
    align-items: center;
}

#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-container {
    flex: 3;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
#map {
    flex: 1;
    background: #1a1a2e;
}
#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);
}

/* Device selector in header */
.device-select {
    padding: 3px 6px;
    border: 1px solid var(--surface2);
    border-radius: 4px;
    background: var(--surface2);
    color: var(--text);
    font-size: 12px;
    max-width: 180px;
}
.header-sep { width: 1px; height: 16px; background: var(--surface2); margin: 0 4px; }

/* Device management panel */
.device-entry {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg);
    border-radius: 4px;
    font-size: 12px;
}
.device-name { font-weight: 600; }
.device-mac { font-family: 'Consolas', monospace; color: var(--text-dim); }
.sub-badge {
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.sub-pro { background: var(--green); color: #000; }
.sub-free { background: var(--surface2); 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 { margin-left: auto; }
    .header-right .label { display: none; }
    .header-right .header-sep { display: none; }
    #username-display { display: none; }
    #btn-devices, #btn-sessions { display: none; }
    #tcp-buffer { 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; }
}

/* Landscape delta-T overlay (hidden by default, shown in landscape fullscreen) */
.landscape-delta {
    display: none;
}

/* Mobile landscape: swipeable fullscreen pages */
@media (max-height: 500px) and (orientation: landscape) {
    #header, #footer { display: none; }
    #h-splitter, #h-splitter2, #v-splitter { display: none !important; }

    #main {
        overflow: hidden;
        position: relative;
    }

    #swipe-container {
        display: flex !important;
        flex-direction: row;
        width: 300vw;
        height: 100%;
        transition: transform 0.3s ease;
    }

    .swipe-page {
        display: flex !important;
        flex-direction: column;
        width: 100vw;
        height: 100%;
        flex-shrink: 0;
        overflow: hidden;
    }

    /* Page 1: Speed chart */
    #left-col {
        flex: 1 !important;
        width: 100vw !important;
        height: 100% !important;
        min-width: 0 !important;
    }
    #speed-chart-panel {
        flex: 1;
        min-height: 0;
        padding: 0;
    }
    #speed-chart-panel > h3 { display: none; }
    #delta-chart-panel { display: none; }

    #swipe-page-charts {
        position: relative;
    }
    .landscape-delta {
        display: flex;
        flex-direction: column;
        align-items: center;
        position: absolute;
        top: 6px;
        right: 12px;
        z-index: 1000;
        pointer-events: none;
    }
    .landscape-delta-label {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-dim);
        font-family: 'Segoe UI', system-ui, sans-serif;
    }
    #landscape-delta-value {
        font-family: 'Consolas', monospace;
        font-size: 32px;
        font-weight: 700;
        text-shadow: 0 1px 4px rgba(0,0,0,0.7);
        line-height: 1;
    }

    /* Page 2: Map */
    #right-col {
        flex: 1 !important;
        width: 100vw !important;
        height: 100% !important;
        display: flex !important;
    }
    #map-container {
        flex: 1 !important;
        height: 100% !important;
    }
    #map { height: 100% !important; }
    #lap-times-panel { display: none !important; }

    /* Page 3: Lap times */
    #swipe-page-laps {
        display: flex !important;
        background: var(--bg);
        padding: 12px 16px;
    }
    #swipe-page-laps h3 {
        font-size: 13px;
        font-weight: 600;
        color: var(--text-dim);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 8px;
    }
    #swipe-lap-list {
        font-family: 'Consolas', monospace;
        font-size: 16px;
        overflow-y: auto;
        flex: 1;
    }

    /* Page indicator dots */
    .swipe-dots {
        display: flex !important;
        position: fixed;
        bottom: 6px;
        left: 50%;
        transform: translateX(-50%);
        gap: 8px;
        z-index: 1000;
        pointer-events: none;
    }
    .swipe-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: rgba(255,255,255,0.3);
        transition: background 0.2s;
    }
    .swipe-dot.active {
        background: rgba(255,255,255,0.9);
    }
}

/* ---- Tab bar ---- */
#tab-bar {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--surface2);
    flex-shrink: 0;
}
#tab-bar .tab {
    padding: 6px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: color 0.15s, border-color 0.15s;
}
#tab-bar .tab:hover { color: var(--text); }
#tab-bar .tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}
/* ---- Tab content ---- */
.tab-content {
    display: none;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}
.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* ---- Dashboard ---- */
#dashboard-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#dashboard-controls {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--surface2);
}
#dashboard-grid {
    flex: 1;
    position: relative;
    padding: 12px;
    overflow: auto;
}
.dashboard-widget {
    background: var(--surface);
    border-radius: 8px;
    padding: 0 16px 16px 16px;
    outline: 2px solid transparent;
    outline-offset: -2px;
    transition: outline-color 0.3s, box-shadow 0.15s;
    width: 250px;
    height: 200px;
    min-width: 200px;
    min-height: 140px;
    overflow: hidden;
    /* Container query context: child fonts scale relative to widget size */
    container-type: size;
    container-name: widget;
    display: flex;
    flex-direction: column;
    /* Free-form layout: each widget is absolutely positioned */
    position: absolute;
    left: 0;
    top: 0;
}
.widget-resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    background:
        linear-gradient(135deg, transparent 0 55%, var(--text-dim) 55% 65%, transparent 65% 75%, var(--text-dim) 75% 85%, transparent 85%);
    opacity: 0.6;
    transition: opacity 0.15s;
}
.dashboard-widget:hover .widget-resize-handle { opacity: 1; }
.dashboard-widget .widget-header { flex-shrink: 0; }
.dashboard-widget .widget-settings-panel { flex-shrink: 0; }
.dashboard-widget .widget-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;   /* positioning context for shape-circle indicator */
}
.dashboard-widget.dragging {
    box-shadow: 0 0 0 2px var(--accent), 0 6px 18px rgba(0,0,0,0.45);
    z-index: 1000;
}
.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: grab;
    background: var(--surface2);
    margin: 0 -16px 8px -16px;
    padding: 6px 12px;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    user-select: none;
}
.widget-header::before {
    content: '\22EE\22EE';  /* two vertical ellipses → drag-grip glyph */
    color: var(--text-dim);
    font-size: 14px;
    margin-right: 6px;
    letter-spacing: -2px;
    line-height: 1;
}
.widget-header:hover { background: #1a4a80; }
.dashboard-widget.dragging .widget-header { cursor: grabbing; background: #1a5276; }
.widget-title {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.widget-actions {
    display: flex;
    gap: 4px;
}
.widget-actions button {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    padding: 2px;
}
.widget-actions button:hover { color: var(--text); }

.widget-settings-panel {
    padding: 0 4px;
    font-size: 12px;
}
.widget-settings-panel .form-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.widget-settings-panel label {
    font-size: 12px;
    color: var(--text-dim);
}
.widget-settings-panel input[type="number"],
.widget-settings-panel input[type="text"],
.widget-settings-panel select {
    padding: 2px 4px;
    background: var(--bg);
    border: 1px solid var(--surface2);
    border-radius: 3px;
    color: var(--text);
    font-size: 12px;
    min-width: 0;
}
.widget-settings-panel input[type="number"] { width: 70px; }
.widget-settings-panel .cfg-apply { margin-top: 4px; }

/* Colour picker — force visible swatch fill across browsers */
.widget-settings-panel input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 48px;
    height: 30px;
    padding: 2px;
    border: 1px solid var(--surface2);
    border-radius: 4px;
    cursor: pointer;
    background: var(--surface2);
    flex-shrink: 0;
}
.widget-settings-panel input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border: none;
}
.widget-settings-panel input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}
.widget-settings-panel input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 3px;
}

.widget-settings-panel { overflow: hidden; }

/* Text widget */
.widget-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
}
.widget-text .widget-value {
    font-family: 'Consolas', monospace;
    font-size: 30cqmin;
    font-weight: 700;
    text-align: center;
    line-height: 1;
}
.widget-text .widget-unit {
    font-size: 8cqmin;
    color: var(--text-dim);
    text-align: center;
    display: block;
    line-height: 1;
    margin-top: 4cqmin;
}

/* Fuel widget — tank level (big), tracking state, secondary stats,
   action buttons, and a scrollable history log. */
.widget-fuel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    min-height: 0;
    padding: 4px 8px 6px;
    gap: 4px;
    font-family: 'Consolas', monospace;
}
.widget-fuel .fuel-setup-warning {
    background: rgba(255, 160, 0, 0.15);
    border: 1px solid rgba(255, 160, 0, 0.4);
    border-radius: 4px;
    color: #ffa000;
    font-size: 11px;
    padding: 4px 6px;
    margin-bottom: 6px;
    text-align: center;
}
.widget-fuel .fuel-tank-row {
    text-align: center;
    line-height: 1;
}
.widget-fuel .widget-value.fuel-tank {
    font-size: 22cqmin;
    font-weight: 700;
    color: #4fc3f7;
    line-height: 1;
}
.widget-fuel .fuel-tank-unit {
    font-size: 6cqmin;
    color: var(--text-dim);
    line-height: 1;
    margin-top: 1cqmin;
}
.widget-fuel .fuel-laps-left-row {
    text-align: center;
    font-size: 9cqmin;
    color: var(--text-dim);
    line-height: 1.1;
    margin-top: 1cqmin;
}
.widget-fuel .fuel-laps-left {
    color: #9ccc65;
    font-weight: 700;
    font-size: 11cqmin;
}
.widget-fuel .fuel-laps-left-basis {
    margin-left: 6px;
    font-size: 7cqmin;
    color: var(--text-dim);
    font-style: italic;
}
.widget-fuel .fuel-tracking-state {
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    line-height: 1.3;
    margin-top: 2px;
}
.widget-fuel .fuel-tracking-state.tracking-on {
    color: #4caf50;
}
.widget-fuel .fuel-secondary-row {
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    line-height: 1.4;
    margin-top: 2px;
}
.widget-fuel .fuel-secondary-row .fuel-sep {
    margin: 0 4px;
    color: var(--surface2);
}
.widget-fuel .fuel-rate,
.widget-fuel .fuel-per-lap,
.widget-fuel .fuel-used-mini {
    color: #ffb300;
    font-weight: 600;
}
.widget-fuel .fuel-per-lap {
    color: #ffd54f;
}
.widget-fuel .fuel-used-mini {
    color: #ff7043;
}
.widget-fuel .fuel-rate-unit {
    color: var(--text-dim);
    font-weight: 400;
    margin-left: 2px;
    margin-right: 2px;
}
.widget-fuel .fuel-actions {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin: 4px 0 2px;
}
.widget-fuel .fuel-actions .btn {
    padding: 3px 8px;
    font-size: 11px;
    flex: 1;
    min-width: 0;
}
.widget-fuel .fuel-actions .fuel-btn-reset-all {
    background: #5a1a1a;
    color: #ffd6d6;
}
.widget-fuel .fuel-actions .fuel-btn-reset-all:hover {
    background: #7a2020;
}
.widget-fuel .fuel-history-label {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 2px;
}
.widget-fuel .fuel-history {
    flex: 1 1 auto;
    min-height: 40px;
    max-height: 100%;
    overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--surface2);
    border-radius: 3px;
    padding: 4px 6px;
    margin: 0;
    font-family: 'Consolas', monospace;
    font-size: 10px;
    line-height: 1.4;
    color: var(--text);
    white-space: pre;
}

/* Gauge widget */
.widget-gauge {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 0;
    gap: 4cqmin;
}
.widget-gauge svg {
    flex: 1;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    min-height: 0;
    display: block;
}
.widget-gauge .gauge-value {
    font-family: 'Consolas', monospace;
    font-size: 14cqmin;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}
.widget-gauge .gauge-range {
    font-size: 6cqmin;
    color: var(--text-dim);
    line-height: 1.2;
    flex-shrink: 0;
}

/* Graph widget */
.widget-graph {
    flex: 1;
    position: relative;
    min-height: 0;
}
.widget-graph canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100% !important;
    height: 100% !important;
}

/* Bar widget */
.widget-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
    min-height: 0;
}
.widget-bar-header {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    flex-shrink: 0;
}
.widget-bar .bar-value {
    font-family: 'Consolas', monospace;
    font-size: 18cqmin;
    font-weight: 700;
    line-height: 1;
}
.widget-bar .bar-unit {
    font-size: 7cqmin;
    color: var(--text-dim);
}
.widget-bar .bar-track {
    background: var(--surface2);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    flex: 1;
    min-height: 0;
}
.widget-bar-horizontal .bar-track { width: 100%; }
.widget-bar-horizontal .bar-fill {
    height: 100%;
    width: 0%;
    transition: width 0.2s ease-out;
}
.widget-bar-vertical { align-items: center; }
.widget-bar-vertical .bar-track {
    width: 12cqmin;
    min-width: 24px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.widget-bar-vertical .bar-fill {
    width: 100%;
    height: 0%;
    transition: height 0.2s ease-out;
}
.widget-bar .bar-range {
    display: flex;
    justify-content: space-between;
    font-size: 5cqmin;
    color: var(--text-dim);
    font-family: 'Consolas', monospace;
    flex-shrink: 0;
}
.widget-bar-vertical .bar-range { display: none; }

/* Map widget — Leaflet container fills the body */
.widget-map {
    flex: 1;
    min-height: 0;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    overflow: hidden;
}
.widget-web {
    flex: 1;
    min-height: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 4px;
    background: #000;
}
.widget-web-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12px;
    font-size: 12px;
    color: var(--text-dim);
}
.widget-notes {
    flex: 1;
    width: 100%;
    min-height: 0;
    resize: none;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--surface2);
    border-radius: 4px;
    padding: 6px 8px;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    outline: none;
}
.widget-notes:focus {
    border-color: var(--accent);
}
.widget-map .leaflet-container {
    background: #1a1a2e;
    width: 100%;
    height: 100%;
}

/* Indicator widget — solid colored block with label */
.widget-indicator {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    padding: 8px;
    min-height: 0;
    transition: background 0.15s;
}
/* Circle variant — for steering-wheel-button style indicators.
   The block is locked to aspect-ratio 1 (always a true circle, never an
   ellipse) and absolute-centred in its body via the inset:0 + margin:auto
   pattern. Sizes itself to the smaller of the body's width and height.
   container-type:size makes cqmin inside refer to the circle itself, so
   label/value text scales with the circle's diameter (not the parent
   widget). */
.widget-indicator.shape-circle {
    position: absolute;
    inset: 0;
    margin: auto;
    aspect-ratio: 1;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    flex: 0 0 auto;       /* override .widget-indicator's flex:1 */
    border-radius: 50%;
    padding: 6%;          /* proportional padding so text fits */
    overflow: hidden;
    box-shadow: inset 0 -3px 8px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.3);
    container-type: size;
    container-name: indicator;
}
/* Text sized off the circle's diameter (cqmin = smaller of width/height) */
.widget-indicator.shape-circle .indicator-label {
    font-size: 22cqmin;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 90%;
}
.widget-indicator.shape-circle .indicator-value {
    font-size: 14cqmin;
    line-height: 1;
    margin-top: 4cqmin;
}

/* Composite item hosting a transparent-background indicator: kill the
   default dark box + border so only the colored shape sits on the image.
   The hover toolbar / resize handle still appear so the user can interact. */
.composite-item.item-transparent {
    background: transparent;
    border-color: transparent;
}
.composite-item.item-transparent:hover {
    /* Faint outline on hover so the user can find an OFF / invisible item */
    border-color: rgba(255,255,255,0.3);
    box-shadow: none;
}
.widget-indicator .indicator-label {
    font-family: 'Consolas', monospace;
    font-size: 22cqmin;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.35);
    letter-spacing: 1px;
    line-height: 1;
}
.widget-indicator .indicator-value {
    font-family: 'Consolas', monospace;
    font-size: 8cqmin;
    color: rgba(255,255,255,0.85);
    margin-top: 4cqmin;
    line-height: 1;
}

/* Per-widget threshold breach: solid red background for the whole widget */
.dashboard-widget.widget-breach {
    background: #6b1a1a !important;
    outline-color: var(--red) !important;
}
.dashboard-widget.widget-breach .widget-header {
    background: #8b1a1a !important;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}
.modal-content {
    background: var(--surface);
    border-radius: 8px;
    padding: 20px;
    min-width: 400px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-content h3 {
    font-size: 16px;
    margin-bottom: 16px;
}
.modal-content .form-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.modal-content .form-row label {
    font-size: 13px;
    color: var(--text-dim);
    min-width: 80px;
}
.modal-content .form-row input,
.modal-content .form-row select {
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--surface2);
    border-radius: 4px;
    color: var(--text);
    font-size: 13px;
    flex: 1;
}
/* Composite (image-background) widget */
.composite-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
}
.composite-bg {
    display: block;
    width: 100%;
    height: 100%;
    /* object-fit set inline by build code (contain | cover | fill) */
}
.composite-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;   /* re-enabled per-item below */
}

/* Items placed on top of the background image. Position/size set inline
   from item.rx/ry/rw/rh by _layoutItem(). */
.composite-item {
    position: absolute;
    pointer-events: auto;
    cursor: grab;
    background: rgba(15, 25, 50, 0.85);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 4px;
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
    user-select: none;
}
.composite-item:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(233, 69, 96, 0.25);
}
.composite-item.dragging { cursor: grabbing; opacity: 0.85; }
.composite-item-body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;   /* positioning context for shape-circle indicator */
}
.composite-item-tools {
    position: absolute;
    top: 2px;
    right: 2px;
    display: none;
    gap: 2px;
    z-index: 2;
}
.composite-item:hover .composite-item-tools { display: flex; }
.composite-item-tools button {
    background: rgba(0,0,0,0.7);
    color: #eee;
    border: none;
    border-radius: 3px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    font-size: 11px;
    padding: 0;
    line-height: 1;
}
.composite-item-tools button:hover { background: var(--accent); }
/* Per-item threshold breach: solid red background, like .widget-breach.
   Indicator items keep their own background colour (set inline on
   .widget-indicator); the red ring around them still signals the breach. */
.composite-item.item-breach {
    background: #6b1a1a !important;
    border-color: var(--red) !important;
    box-shadow: 0 0 0 2px rgba(255, 82, 82, 0.5);
}
.composite-item.item-breach .widget-text,
.composite-item.item-breach .widget-bar,
.composite-item.item-breach .widget-graph,
.composite-item.item-breach .widget-gauge { color: #fff; }

.composite-item.resizing { opacity: 0.85; }

/* Resize handle: small triangle in bottom-right, only visible on hover */
.composite-item-resize {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    background:
        linear-gradient(135deg,
            transparent 0%, transparent 50%,
            rgba(255,255,255,0.5) 50%, rgba(255,255,255,0.5) 60%,
            transparent 60%, transparent 70%,
            rgba(255,255,255,0.5) 70%, rgba(255,255,255,0.5) 80%,
            transparent 80%);
    opacity: 0;
    transition: opacity 0.12s;
    z-index: 2;
}
.composite-item:hover .composite-item-resize { opacity: 1; }

/* Inside an item, the value text needs to scale down to fit the small box */
.composite-item .widget-value { font-size: clamp(11px, 5vw, 32px); }
.composite-item .widget-unit { font-size: 10px; }
.composite-item .widget-text { padding: 2px 4px; }
.composite-item .gauge-value { font-size: 14px; }
.composite-item .gauge-range { font-size: 9px; }
.composite-item .bar-value { font-size: 11px; }
.composite-item .bar-unit  { font-size: 10px; }
.composite-item .bar-range { font-size: 9px; }
.composite-item .indicator-label { font-size: 11px; }
.composite-item .indicator-value { font-size: 11px; }
/* Circle indicators inside items: scale text with the circle, not item */
.composite-item .widget-indicator.shape-circle .indicator-label { font-size: 22cqmin; }
.composite-item .widget-indicator.shape-circle .indicator-value { font-size: 14cqmin; }
.composite-empty {
    display: flex;
    align-items: center;
    justify-content: center;
}
.composite-placeholder {
    color: var(--text-dim);
    font-size: 12px;
    text-align: center;
    padding: 12px;
}
