:root {
  --bg: #0f1419;
  --panel: #171d26;
  --panel-2: #1e2631;
  --border: #2a3542;
  --text: #e6edf3;
  --muted: #9fadbd;
  --accent: #3b82f6;
  --accent-hover: #2f6fd6;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --in: #38bdf8;
  --out: #a78bfa;
  /* coverage heatmap — GitHub-contribution ramp on the dark theme */
  --cov-empty: #161b22;   /* nothing planned */
  --cov-pending: #2b3647; /* queued, not downloaded */
  --cov-fail: #c2503f;    /* failed */
  --cov-0: #16301d;       /* downloaded, 0 messages (faint tint) */
  --cov-1: #0e4429;
  --cov-2: #1a7a3e;
  --cov-3: #27b84f;
  --cov-4: #4ae168;
  /* themed scrollbars */
  --scroll-thumb: #313e4e;
  --scroll-thumb-hover: #3f5064;
}

/* Thin, theme-matched scrollbars (Firefox + WebKit) */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }
* { box-sizing: border-box; }
/* An author `display` on #login-screen/#app would otherwise beat the UA [hidden] rule. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red); font-size: 13px; }

.screen { height: 100%; }
/* The app fills the viewport; only the truck list and the grid scroll, never the page. */
body { overflow: hidden; }
#app { display: flex; flex-direction: column; }
#app-header { flex: 0 0 auto; }
.tab-panel { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; margin-bottom: 14px;
}

/* login */
#login-screen { display: grid; place-items: center; }
.login-card { width: 320px; display: flex; flex-direction: column; gap: 10px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }

input, select, button {
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type="checkbox"] { accent-color: var(--accent); }

button { background: var(--accent); border-color: transparent; cursor: pointer; font-weight: 600; }
button:hover { background: var(--accent-hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: var(--panel-2); border-color: var(--border); font-weight: 500; }
button.ghost:hover { background: var(--border); }
select { width: 100%; }

/* Date fields: paint our own value overlay, formatted to the USER's region (navigator.language),
   on top of a native date input whose own (browser-locale) text is hidden. */
.datefield { position: relative; display: block; }
.datefield .datenative { width: 100%; color: transparent; }
.datefield .datenative::-webkit-datetime-edit { color: transparent; }
.datefield .datedisp {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  pointer-events: none; font: inherit; color: var(--text); letter-spacing: .02em;
}
.datefield .datedisp.empty { color: var(--muted); }

/* Chunk-size + Download-speed sliders (discrete stops) with a live value readout. */
.ctl { margin-top: 10px; }
.ctl-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 4px; }
.ctl-val { color: var(--accent); font-weight: 600; font-size: 12px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px; padding: 0;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
input[type="range"]:focus { outline: 2px solid var(--accent); outline-offset: 3px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--border);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel);
}

/* header */
#app-header {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.brand { font-weight: 700; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }

/* Dropdown menu (Export format picker) */
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 50; min-width: 180px;
  display: flex; flex-direction: column; padding: 5px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .4);
}
.menu button {
  background: transparent; border: none; border-radius: 6px; text-align: left;
  padding: 8px 10px; font-weight: 500; color: var(--text); cursor: pointer;
}
.menu button:hover { background: var(--panel-2); }
.user { color: var(--muted); font-size: 13px; }
.small-btn { padding: 6px 10px; font-size: 13px; }

/* tabs */
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; border: none; color: var(--muted); font-weight: 600;
  padding: 7px 14px; border-radius: 7px;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--panel-2); color: var(--text); }
.tab-panel { padding: 14px; }

.stat-strip { display: flex; align-items: center; gap: 16px; font-size: 13px; }
.stat b { color: var(--text); font-size: 15px; }
.stat.failed b { color: var(--amber); }
.run-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.run-dot.idle { background: #475569; }
.run-dot.running { background: var(--green); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* layout: three splitter-divided regions — flat panes separated by thin lines, no cards */
#tab-dashboard.tab-panel { padding: 0; }
.dash { display: flex; height: 100%; min-height: 0; overflow: hidden; }
.sidebar { width: 320px; flex: 0 0 auto; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.content { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.right-panel { width: 380px; flex: 0 0 auto; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* Flat panes: inner padding + a thin divider between stacked panes, no panel box.
   Default is NO shrink (flex:0 0 auto) so fixed panes like Backfill keep their height and never
   overflow onto their neighbours; only the explicitly-flexing panes below grow/shrink. */
.pane { padding: 12px 14px; min-height: 0; flex: 0 0 auto; }
.sidebar .pane + .pane { border-top: 1px solid var(--border); }
.trucks-pane { flex: 1 1 auto; display: flex; flex-direction: column; }
.activity-pane { flex: 0 0 auto; height: 160px; display: flex; flex-direction: column; }
.grid-pane { flex: 1 1 auto; display: flex; flex-direction: column; }
/* Centre the WHOLE coverage block (title, legend, caption, badges, grid) as one column, capped to
   the grid's own width (set in JS) and centred via align-self, so the heading sits over the grid. */
.grid-inner { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-self: center; max-width: 100%; }

/* Splitters: a thin line with a wider invisible grab strip; brightens on hover/drag. */
.splitter { flex: 0 0 auto; position: relative; z-index: 5; background: transparent; }
.splitter.v { width: 9px; cursor: col-resize; }
.splitter.h { height: 9px; cursor: row-resize; }
.splitter::before { content: ''; position: absolute; background: var(--border); transition: background .12s; }
.splitter.v::before { top: 0; bottom: 0; left: 4px; width: 1px; }
.splitter.h::before { left: 0; right: 0; top: 4px; height: 1px; }
.splitter:hover::before, .splitter.dragging::before { background: var(--accent); }
.splitter.v:hover::before, .splitter.v.dragging::before { width: 2px; left: 3px; }
.splitter.h:hover::before, .splitter.h.dragging::before { height: 2px; top: 3px; }

/* right panel: filtered message list (top) + full selected message (bottom) */
.msglist-pane { flex: 0 0 auto; height: 320px; display: flex; flex-direction: column; }
.msgdetail-pane { flex: 1 1 auto; display: flex; flex-direction: column; }
.msglist { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin-top: 6px; }
.msg-item { display: grid; grid-template-columns: auto auto auto 1fr; gap: 8px; align-items: baseline;
  padding: 5px 6px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 5px; }
.msg-item:hover { background: var(--panel-2); }
.msg-item.sel { background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--accent); }
.msg-item .when { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg-item .who { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
.msg-item .line1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; min-width: 0; }
.msgdetail { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin-top: 6px; }
.msgdetail .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.msgdetail .meta b { color: var(--text); font-weight: 600; }
.msgdetail .body { white-space: pre-wrap; font-size: 13.5px; line-height: 1.5; }

.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.tight { margin: 8px 0; }
.grow, .filter.grow { flex: 1; }
label { font-size: 13px; }
.sidebar label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }

.filter { width: 100%; margin-bottom: 8px; }
.chk { display: inline-flex; align-items: center; gap: 6px; flex-direction: row !important; }

.truck-list { flex: 1 1 auto; min-height: 60px; overflow-y: auto; border-top: 1px solid var(--border); padding-top: 6px; }
/* Dim the fleet checkboxes — the bright accent-blue was too loud for the dark grid. */
.truck-row input[type="checkbox"], #select-all { accent-color: #44566c; opacity: .85; }
.truck-row input[type="checkbox"]:hover, #select-all:hover { opacity: 1; }
.truck-list .truck-row { display: flex; flex-direction: row; align-items: center; gap: 8px; padding: 4px 2px; border-radius: 5px; margin-bottom: 0; }
.truck-row:hover { background: var(--panel-2); }
.truck-row .gar { font-weight: 700; min-width: 34px; font-variant-numeric: tabular-nums; }
.truck-row .plate { color: var(--muted); font-size: 12.5px; }

.progress { height: 8px; background: var(--panel-2); border-radius: 5px; overflow: hidden; margin: 10px 0 6px; }
#progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width .3s; }

.log { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin-top: 6px; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; }
.log div { padding: 1px 0; border-bottom: 1px solid rgba(255,255,255,.03); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log .err { color: var(--red); }
.log .ok { color: var(--muted); }

/* table */
.table-wrap { overflow-x: auto; max-height: calc(100vh - 220px); overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); padding: 8px; border-bottom: 1px solid var(--border); }
td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
td.when { white-space: nowrap; color: var(--muted); }
td.msg { white-space: pre-wrap; max-width: 640px; }
.dir { font-weight: 700; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.dir.T { color: var(--out); background: rgba(167,139,250,.12); }
.dir.R { color: var(--in); background: rgba(56,189,248,.12); }

/* chunk coverage grid */
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw.c0 { background: var(--cov-0); }
.sw.c1 { background: var(--cov-1); }
.sw.c2 { background: var(--cov-2); }
.sw.c3 { background: var(--cov-3); }
.sw.c4 { background: var(--cov-4); }
.sw.pending { background: var(--cov-pending); }
.sw.failed { background: var(--cov-fail); }

.year-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.year-badge {
  padding: 4px 11px; border-radius: 7px; font-size: 12px; font-weight: 600; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.year-badge:hover { color: var(--text); border-color: var(--accent); }
.year-badge.active { background: var(--accent); color: #fff; border-color: transparent; }
.year-badge .yb-count { opacity: .7; font-weight: 500; margin-left: 4px; }

/* Fixed month-header row that does NOT scroll with the grid body. */
.cov-head-wrap { margin-top: 10px; overflow: hidden; flex: 0 0 auto; }
#cov-head { display: block; }
.cov-wrap { overflow: auto; flex: 1 1 auto; min-height: 0; position: relative; }
#cov-canvas { display: block; }
.cov-tip {
  position: fixed; pointer-events: none; z-index: 50; white-space: nowrap;
  background: #0b0f14; border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; font-size: 12px; color: var(--text);
}

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