/**
 * Lot.E1 — Dashboard Styles
 * Location: dashboard/static/style.css
 * Version: 1.15.0
 *
 * Dark monitoring theme. Colors from Loxley branding:
 * Orange gradient: #ff8e20 → #ff681d (Toby logo)
 * Navy: from Loxley geometric pattern
 *
 * CHANGELOG:
 *   v1.15.0 - Session backfill scanner styles [SES-003] [DSH-022]
 *   v1.14.1 - SoC battery: larger size [DSH-021]
 *   v1.14.0 - Vertical SoC battery gauge with gradient fill [DSH-021]
 *   v1.13.0 - Power history chart + DC Bus sparklines [DSH-018]
 *   v1.12.0 - Sortable sticky headers, date filter, highlight-on-return [DSH-017]
 *   v1.11.0 - Reload-pending indicator, server reload section [DSH-014]
 *   v1.10.0 - Reports page: session table, detail panel, replay bar [SES-002]
 *   v1.9.0 - Custom cell tooltips, bus section layout for Victron [DSH-012]
 *   v1.8.0 - Cell highlight styles for highest/lowest N [DSH-010]
 *   v1.7.0 - Diverging bar styles for deviation-from-median display [DSH-010]
 *   v1.6.0 - Mode badge in header, remove source selector styles [DSH-009]
 *   v1.5.0 - Footer bar restructure, data-driven LED flash, compact versions,
 *            settings bulk controls [DSH-008]
 *   v1.4.1 - Fix footer collapse, horizontal LED layout [DSH-006]
 *   v1.4.0 - Nav bar, footer, telemetry LED styles [DSH-006]
 *   v1.3.0 - Settings page styles, gear link [DSH-005]
 *   v1.2.0 - Stale indicator, sensor group labels [DSH-002]
 *   v1.1.0 - Add pulse-glow on data update [DSH-001]
 *   v1.0.0 - Initial implementation [DSH-001]
 */

@font-face {
    font-family: 'FS Lucas Pro';
    src: url('/branding/FSLucasProXtraBd.ttf') format('truetype');
    font-weight: 800;
    font-display: swap;
}

/* ---- Reset ---- */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

[hidden] {
    display: none !important;
}

/* ---- Tokens ---- */

:root {
    --orange: #ff8e20;
    --orange-deep: #ff681d;

    --bg: #0c0e14;
    --bg-surface: #141722;
    --bg-elevated: #1c2030;
    --bg-hover: #252a3a;

    --text: #e2e4ec;
    --text-secondary: #7d839c;
    --text-muted: #4a4f66;

    --green: #34d399;
    --amber: #fbbf24;
    --red: #f87171;

    --border: rgba(255, 142, 32, 0.08);
    --border-strong: rgba(255, 142, 32, 0.20);

    --gap: 16px;
    --radius: 10px;
    --header-h: 56px;
}

/* ---- Base ---- */

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Cascadia Code',
                 ui-monospace, monospace;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ---- Header ---- */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    padding: 0 24px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.logo-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 28px;
    height: auto;
}

.title {
    font-family: 'FS Lucas Pro', 'Impact', 'Arial Black', sans-serif;
    font-weight: 800;
    font-size: 1.25rem;
    background: linear-gradient(180deg, var(--orange) 0%, var(--orange-deep) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.5px;
}

.status-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 300ms;
}

.live-dot.live {
    background: var(--green);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

.live-dot.stale {
    background: var(--amber);
    box-shadow: 0 0 6px rgba(251, 191, 36, 0.4);
}

/* ---- Mode Badge ---- */

.mode-badge {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 2px 8px;
    border-radius: 3px;
    background: var(--bg-elevated);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.mode-badge:empty {
    display: none;
}

.mode-badge-alt {
    color: var(--orange);
    border-color: var(--orange);
    background: rgba(255, 142, 32, 0.1);
}

/* Drive-state badge (DSH-004): shown only while the tractor is driving. */
.tick-badge {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 2px 8px;
    border-radius: 3px;
    color: var(--green, #34d399);
    border: 1px solid var(--green, #34d399);
    background: rgba(52, 211, 153, 0.12);
    animation: tick-pulse 1.6s ease-in-out infinite;
}

@keyframes tick-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ---- Reload Indicator ---- */

.reload-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    padding: 3px 10px;
    border-radius: 4px;
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.3);
    transition: background 200ms;
}

.reload-indicator:hover {
    background: rgba(251, 191, 36, 0.15);
}

.reload-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--amber);
    box-shadow: 0 0 6px rgba(251, 191, 36, 0.4);
    animation: pulse 2s ease-in-out infinite;
}

.reload-label {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--amber);
}

/* ---- Reload Section (Settings) ---- */

.reload-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.reload-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.reload-status-pending {
    color: var(--amber);
    font-weight: 600;
}

.reload-status-restarting {
    color: var(--orange);
    font-weight: 600;
}

/* ---- Layout ---- */

.grid {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gap);
    padding: var(--gap) 24px 24px;
    max-width: 1440px;
    margin: 0 auto;
}

.panel-bms {
    grid-column: 1 / -1;
}

/* ---- Panel ---- */

.panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.panel h2 {
    font-family: 'FS Lucas Pro', 'Impact', 'Arial Black', sans-serif;
    font-weight: 800;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--orange);
    margin-bottom: 16px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.panel-header h2 {
    margin-bottom: 0;
}

/* ---- Overvoltage Badge ---- */

.overvolt-badge {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 4px 12px;
    border-radius: 4px;
    background: var(--red);
    color: #fff;
    animation: flash 1s ease-in-out infinite;
}

@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ---- BMS Cell Bars ---- */

.pack-group {
    margin-bottom: 16px;
}

.pack-group:last-child {
    margin-bottom: 0;
}

.pack-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 8px;
}

.pack-label h3 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pack-summary {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    gap: 16px;
}

.pack-summary strong {
    color: var(--text);
    font-weight: 600;
}

.cell-bars {
    display: flex;
    gap: 3px;
    height: 88px;
}

.cell-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
    cursor: default;
}

.bar-track {
    flex: 1;
    width: 100%;
    background: var(--bg-elevated);
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}

.bar-center {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border-strong);
    z-index: 1;
}

.bar-fill {
    position: absolute;
    left: 0;
    right: 0;
    border-radius: 2px;
    transition: height 300ms ease, top 300ms ease, bottom 300ms ease, background-color 300ms ease;
}

.bar-num {
    font-size: 0.55rem;
    color: var(--text-muted);
    line-height: 1;
}

/* ---- Cell Highlights (highest/lowest N) ---- */

.cell-bar.hl-high .bar-track {
    box-shadow: inset 0 0 0 1px rgba(255, 142, 32, 0.35);
}

.cell-bar.hl-high .bar-num {
    color: var(--orange);
}

.cell-bar.hl-low .bar-track {
    box-shadow: inset 0 0 0 1px rgba(99, 148, 255, 0.35);
}

.cell-bar.hl-low .bar-num {
    color: #6394ff;
}

/* ---- Cell Tooltip ---- */

.cell-tooltip {
    position: fixed;
    z-index: 100;
    transform: translate(-50%, -100%);
    pointer-events: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    display: flex;
    gap: 8px;
    align-items: baseline;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.cell-tooltip .tip-voltage {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.cell-tooltip .tip-dev {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.cell-tooltip .tip-nodata {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.cell-tooltip small {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 1px;
}

/* ---- Victron Bus Sections ---- */

.bus-section {
    margin-bottom: 12px;
}

.bus-section:last-child {
    margin-bottom: 0;
}

.bus-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 6px;
    padding-left: 2px;
}

/* ---- Victron Metrics ---- */

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.metric {
    background: var(--bg-elevated);
    border-radius: 6px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.metric-hero {
    grid-column: 1 / -1;
    text-align: center;
    padding: 16px;
}

.metric-hero .metric-value {
    font-size: 2.5rem;
    color: var(--orange);
}

.metric-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.metric-unit {
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* ---- Power History Chart ---- */

.power-chart-wrap {
    grid-column: 1 / -1;
    height: 80px;
    background: var(--bg);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.power-chart-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ---- DC Bus Sparklines ---- */

.metric-spark {
    position: relative;
    overflow: hidden;
    min-height: 64px;
}

.spark-wrap {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 28px;
    pointer-events: none;
}

.spark-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ---- SoC Battery Gauge ---- */

.soc-battery {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 52px;
    border-radius: 5px;
    border: 1.5px solid rgba(74, 79, 102, 0.35);
    overflow: hidden;
    pointer-events: none;
}

.soc-battery::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 5px;
    background: rgba(74, 79, 102, 0.35);
    border-radius: 3px 3px 0 0;
    z-index: 1;
}

.soc-battery canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.soc-metric {
    padding-right: 44px;
    min-height: 72px;
}

/* ---- Temperature Sensors ---- */

.sensor-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sensor-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-elevated);
    border-radius: 4px;
}

.sensor-name {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.sensor-value {
    font-size: 0.9rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.humidity {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 8px;
}

.sensor-group-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 6px 12px 2px;
}

.sensor-group-label:first-child {
    padding-top: 0;
}

/* ---- System Status ---- */

.process-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.process-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border-radius: 6px;
}

.process-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-live { background: var(--green); box-shadow: 0 0 6px rgba(52, 211, 153, 0.4); }
.dot-stale { background: var(--amber); }
.dot-offline { background: var(--text-muted); }

.process-name {
    font-size: 0.85rem;
    text-transform: capitalize;
}

.process-age {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* ---- Pulse Glow (data update indicator) ---- */

@keyframes glow {
    0%   { box-shadow: 0 0 0 0 rgba(255, 142, 32, 0.0); }
    20%  { box-shadow: 0 0 6px 1px rgba(255, 142, 32, 0.35); }
    100% { box-shadow: 0 0 0 0 rgba(255, 142, 32, 0.0); }
}

.glow {
    animation: glow 600ms ease-out;
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

/* ---- Navigation ---- */

.nav {
    display: flex;
    gap: 4px;
}

.nav-link {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 4px;
    transition: color 200ms, background 200ms;
}

.nav-link:hover {
    color: var(--text);
    background: var(--bg-elevated);
}

.nav-link.active {
    color: var(--orange);
    background: var(--bg-elevated);
}

/* ---- Footer ---- */

.footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    z-index: 40;
}

.footer-bar {
    display: flex;
    align-items: center;
    padding: 6px 24px;
    gap: 12px;
}

.footer-versions-toggle {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 3px 10px;
    cursor: pointer;
    transition: color 200ms, border-color 200ms;
    white-space: nowrap;
}

.footer-versions-toggle:hover {
    color: var(--text-secondary);
    border-color: var(--border-strong);
}

.footer-arrow {
    font-size: 0.55rem;
}

.footer-versions {
    padding: 6px 24px 8px;
    border-top: 1px solid var(--border);
}

/* ---- Telemetry LEDs ---- */

.telemetry-leds {
    display: flex;
    gap: 16px;
}

.led-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.led {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.led-green {
    background: var(--green);
    box-shadow: 0 0 6px rgba(52, 211, 153, 0.4);
}

.led-orange {
    background: var(--amber);
    box-shadow: 0 0 4px rgba(251, 191, 36, 0.3);
}

.led-red {
    background: var(--red);
    box-shadow: 0 0 4px rgba(248, 113, 113, 0.3);
}

.led-offline {
    background: var(--text-muted);
}

.led-flash .led {
    animation: led-ping 400ms ease-out;
}

@keyframes led-ping {
    0%   { box-shadow: 0 0 10px 3px rgba(52, 211, 153, 0.6); }
    100% { box-shadow: 0 0 6px rgba(52, 211, 153, 0.4); }
}

.led-name {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}

.led-age {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ---- Version List ---- */

.version-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
}

.ver-row {
    display: flex;
    gap: 4px;
    white-space: nowrap;
}

.ver-name {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.ver-value {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ---- Settings Page ---- */

.settings-main {
    max-width: 720px;
    margin: 0 auto;
    padding: var(--gap) 24px 24px;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.settings-help {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.settings-group {
    margin-bottom: 16px;
}

.settings-group:last-child {
    margin-bottom: 0;
}

.settings-group-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

/* ---- Service Controls ---- */

.bulk-actions {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
}

/* ---- Service Table ---- */

.svc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.svc-table th {
    text-align: left;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-strong);
}

.svc-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.svc-name {
    font-weight: 600;
    text-transform: capitalize;
}

.svc-pid {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 4px;
}

.svc-actions {
    display: flex;
    gap: 6px;
}

/* ---- Buttons ---- */

.btn {
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 150ms;
}

.btn:hover:not(:disabled) {
    border-color: var(--orange);
    color: var(--orange);
}

.btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-stop:hover:not(:disabled) {
    border-color: var(--red);
    color: var(--red);
}

/* ---- Settings Select ---- */

.settings-select {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 5px 10px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    background: var(--bg-elevated);
    color: var(--text);
    cursor: pointer;
}

.settings-select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.settings-input {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 5px 10px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    background: var(--bg-elevated);
    color: var(--text);
    width: 80px;
}

.settings-input:focus {
    outline: none;
    border-color: var(--orange);
}

.threshold-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.threshold-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ---- Backfill scanner ---- */

.backfill-controls {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.backfill-dates {
    display: flex;
    gap: 10px;
}

.backfill-date-label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.backfill-date-label input {
    width: 140px;
}

.backfill-result {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.82rem;
    white-space: pre-line;
    line-height: 1.5;
}

.backfill-scanning {
    background: rgba(255, 142, 32, 0.1);
    color: var(--orange);
}

.backfill-success {
    background: rgba(52, 211, 153, 0.1);
    color: #34d399;
}

.backfill-empty {
    background: rgba(74, 79, 102, 0.15);
    color: var(--text-muted);
}

.backfill-error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* ---- Checkboxes ---- */

.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 4px;
    transition: background 150ms;
}

.checkbox-row:hover {
    background: var(--bg-elevated);
}

.checkbox-row input[type="checkbox"] {
    accent-color: var(--orange);
    width: 16px;
    height: 16px;
}

/* ---- Utilities ---- */

.no-data {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 12px;
    text-align: center;
}

/* ---- Reports Page ---- */

.reports-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--gap) 24px 24px;
}

.filter-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-date {
    width: 130px;
    font-size: 0.75rem;
    padding: 4px 6px;
}

.filter-date-sep {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.btn-filter-clear {
    font-size: 1rem;
    line-height: 1;
    padding: 2px 8px;
}

/* ---- Session Table ---- */

.session-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.session-table thead {
    position: sticky;
    top: var(--header-h);
    z-index: 10;
}

.session-table thead th {
    text-align: left;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-strong);
    background: var(--bg-surface);
}

.session-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.session-row {
    cursor: pointer;
    transition: background 150ms;
}

.session-row:hover {
    background: var(--bg-hover);
}

.session-row.expanded {
    background: var(--bg-elevated);
}

.td-date {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.td-name {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.td-actions {
    white-space: nowrap;
}

.text-muted {
    color: var(--text-muted);
    font-style: italic;
}

/* ---- Type Badge ---- */

.type-badge {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 2px 8px;
    border-radius: 3px;
    background: var(--bg-elevated);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.type-charge {
    color: #60a5fa;
    border-color: rgba(96, 165, 250, 0.3);
    background: rgba(96, 165, 250, 0.08);
}

.type-mobile {
    color: var(--orange);
    border-color: rgba(255, 142, 32, 0.3);
    background: rgba(255, 142, 32, 0.08);
}

/* ---- Status Badge ---- */

.status-badge {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.status-completed {
    color: var(--green);
}

.status-active {
    color: var(--orange);
}

.status-interrupted {
    color: var(--amber);
}

/* ---- Session Detail (expanded row) ---- */

.session-detail-row {
    background: var(--bg-elevated);
}

.session-detail-row td {
    padding: 0 12px 16px;
    border-bottom: 1px solid var(--border-strong);
}

.session-detail {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 0 4px;
}

.detail-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.detail-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 100px;
    flex-shrink: 0;
}

.detail-value {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.detail-input {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    background: var(--bg);
    color: var(--text);
    width: 200px;
}

.detail-input-wide {
    width: 400px;
}

.detail-input:focus {
    outline: none;
    border-color: var(--orange);
}

/* ---- Detail Stats Grid ---- */

.detail-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 4px;
}

.detail-stat {
    background: var(--bg);
    border-radius: 6px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-stat-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.detail-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.btn-save:hover:not(:disabled) {
    border-color: var(--green);
    color: var(--green);
}

.btn-replay {
    text-decoration: none;
    display: inline-block;
}

/* ---- Stats Bar ---- */

.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 0.85rem;
}
.stats-table thead th {
    text-align: right;
    padding: 6px 12px;
    color: #8b8fa3;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}
.stats-table thead th:first-child {
    text-align: left;
}
.stats-table tbody td {
    padding: 8px 12px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.04));
}
.stats-table tbody td:first-child {
    text-align: left;
}


/* ---- Session ID Chip ---- */

.td-id {
    white-space: nowrap;
}

.session-id-chip {
    font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
    font-size: 0.65rem;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 2px 6px;
    cursor: pointer;
    transition: color 150ms, border-color 150ms;
}

.session-id-chip:hover {
    color: var(--orange);
    border-color: rgba(255, 142, 32, 0.3);
}

.session-id-chip.copied {
    color: var(--green);
    border-color: rgba(52, 211, 153, 0.3);
}

/* ---- Sortable Headers ---- */

.th-sortable {
    cursor: pointer;
    user-select: none;
    transition: color 150ms;
    white-space: nowrap;
}

.th-sortable:hover {
    color: var(--text-secondary);
}

.th-sort-active {
    color: var(--orange);
}

/* ---- Session Highlight (return from replay) ---- */

@keyframes session-flash {
    0%   { background: rgba(255, 142, 32, 0.20); }
    50%  { background: rgba(255, 142, 32, 0.08); }
    100% { background: transparent; }
}

.session-highlight {
    animation: session-flash 2s ease-out;
}

/* ---- Replay Loading Overlay ---- */

.replay-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(17, 19, 23, 0.85);
    backdrop-filter: blur(4px);
    border-radius: 8px;
}
.replay-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #8b8fa3;
    font-size: 0.95rem;
}
.replay-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #2a2d35;
    border-top-color: #ff8e20;
    border-radius: 50%;
    animation: replay-spin 0.8s linear infinite;
}
@keyframes replay-spin {
    to { transform: rotate(360deg); }
}

/* ---- Replay Bar ---- */

.replay-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 24px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-strong);
}

.replay-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.replay-badge {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 2px 8px;
    border-radius: 3px;
    color: var(--orange);
    border: 1px solid var(--orange);
    background: rgba(255, 142, 32, 0.1);
}

.replay-session-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.replay-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.replay-controls button {
    font-family: inherit;
    font-size: 0.85rem;
    padding: 2px 10px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 150ms;
    line-height: 1.4;
}

.replay-controls button:hover {
    border-color: var(--orange);
    color: var(--orange);
}

.replay-slider {
    flex: 1;
    min-width: 100px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg);
    border-radius: 2px;
    outline: none;
}

.replay-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--orange);
    cursor: pointer;
}

.replay-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--orange);
    cursor: pointer;
    border: none;
}

.replay-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    min-width: 50px;
}

.replay-speed {
    font-family: inherit;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}

.replay-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.replay-nav a {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 200ms;
}

.replay-nav a:hover {
    color: var(--text);
}

.replay-nav button {
    font-family: inherit;
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 150ms;
}

.replay-nav button:hover {
    border-color: var(--green);
    color: var(--green);
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
    .grid {
        grid-template-columns: 1fr;
        padding: var(--gap) 12px 12px;
    }

    .settings-main {
        padding: var(--gap) 12px 12px;
    }

    .reports-main {
        padding: var(--gap) 12px 12px;
    }

    .header {
        padding: 0 12px;
    }

    .metric-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .process-list {
        grid-template-columns: 1fr;
    }

    .cell-bars {
        height: 64px;
    }

    .power-chart-wrap {
        height: 60px;
    }

    .bulk-actions {
        flex-wrap: wrap;
    }

    .footer-bar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 6px 12px;
    }

    .telemetry-leds {
        flex-wrap: wrap;
        gap: 8px;
    }

    .nav-link {
        padding: 6px 10px;
        font-size: 0.65rem;
    }

    .session-table {
        font-size: 0.7rem;
    }

    .detail-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .detail-input-wide {
        width: 200px;
    }

    .replay-bar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 12px;
    }

    .replay-controls {
        flex-wrap: wrap;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---- Charging panel (DSH-025) ---- */

.panel-charging {
    grid-column: 1 / -1;
}

.charging-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 720px) {
    .charging-grid {
        grid-template-columns: 1fr;
    }
}

.charging-state {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.charging-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-muted);
    flex: none;
}

.charging-dot-active {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
}

.charging-dot-scheduled { background: var(--amber); }
.charging-dot-off { background: var(--text-muted); }

.charging-window {
    margin-top: 10px;
    font-size: 0.95rem;
    color: var(--text);
}

.charging-next {
    margin-top: 4px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.charging-note {
    margin-top: 14px;
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.charging-recent-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.charging-recent-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.charging-recent-row:last-child { border-bottom: none; }

.charging-recent-when { color: var(--text-secondary); }
.charging-recent-soc { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.charging-recent-dur { color: var(--text); font-variant-numeric: tabular-nums; }
.charging-recent-kwh {
    color: var(--green);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ---- Settings: scheduled charging ---- */

.charge-times {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.charge-time-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.charge-time-label .settings-input {
    width: 150px;
    box-sizing: border-box;
}

.charge-save-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 8px;
}

.charge-save-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.charge-save-ok { color: var(--green); }
.charge-save-err { color: var(--red); }

/* === Controller page (MOT-002) === */
.conn-badge {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 3px 10px;
    border-radius: 999px;
    text-transform: uppercase;
}
.conn-badge.conn-on { background: rgba(52, 211, 153, 0.16); color: var(--green); }
.conn-badge.conn-off { background: rgba(248, 113, 113, 0.16); color: var(--red); }

.state-badge { font-weight: 700; padding: 1px 8px; border-radius: 6px; }
.state-badge.state-run { color: var(--green); }
.state-badge.state-stop { color: var(--text-secondary); }
.state-badge.state-fault { color: var(--red); }
.state-badge.state-warn { color: var(--amber); }

.panel-controller.offline { opacity: 0.5; }
.panel-controller.offline .metric-value { color: var(--text-muted); }

.motor-faults { margin-top: 10px; font-size: 0.85rem; color: var(--green); }
.motor-faults.has-fault { color: var(--red); font-weight: 700; }

.metric-minmax {
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 0.62rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}
