:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c222b;
  --line: #2a313c;
  --text: #d7dde5;
  --muted: #8b95a3;
  --up: #26a69a;
  --down: #ef5350;
  --accent: #58a6ff;
  --sig: #f2c94c;
  --warn: #f0a33a;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }

/* slim scrollbars close to the background: Chromium / Edge / Safari ... */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139, 149, 163, 0.16); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(139, 149, 163, 0.34); }
/* ... and Firefox (no ::-webkit-scrollbar there) */
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: rgba(139, 149, 163, 0.22) transparent; }
}
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.screen { height: 100vh; display: flex; flex-direction: column; }

header {
  display: flex; align-items: center; gap: 18px; padding: 8px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: .3px; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 4px; font-size: 13px; }
.muted { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.badge { padding: 1px 8px; border-radius: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.badge.pre, .badge.post { background: #3a2f12; color: var(--warn); }
.badge.rth { background: #12382f; color: var(--up); }
.badge.closed { background: #3d1f22; color: var(--down); }
.badge.sim, .badge.day { background: #1f2d40; color: var(--accent); }

/* bars before / after per timeframe */
.windows { display: flex; align-items: center; gap: 14px; margin-left: auto; flex-wrap: wrap; font-size: 12px; }
.windows label { color: var(--text); white-space: nowrap; }
.windows input { width: 54px; margin-left: 4px; padding: 1px 4px; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px; font: 12px var(--mono); }
.windows input:focus { outline: none; border-color: var(--accent); }
.windows input.bad { border-color: var(--down); }
button.quiet { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); border-radius: 6px;
  padding: 2px 8px; font-size: 12px; cursor: pointer; }
button.quiet:hover { color: var(--text); border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: var(--panel-2); color: var(--muted); border: 0; padding: 3px 10px; cursor: pointer; font-size: 12px; }
.seg button.on { background: var(--accent); color: #08111d; font-weight: 600; }

main {
  flex: 1; min-height: 0; display: grid; gap: 10px; padding: 10px;
  grid-template-columns: minmax(330px, 420px) minmax(0, 1fr);
}
section { min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 0; }
.panel h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }

/* left: the signals */
.col-left { display: flex; flex-direction: column; }
#search { width: 100%; padding: 6px 8px; margin-bottom: 8px; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.table-wrap { flex: 1; overflow: auto; min-height: 0; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.list th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-weight: 500; text-align: left;
  padding: 4px 5px; border-bottom: 1px solid var(--line); cursor: pointer; white-space: nowrap; font-size: 12px; }
.list td { padding: 3px 5px; border-bottom: 1px solid #1f252e; white-space: nowrap; }
.list td.n, .list th.n { text-align: right; }
.list td.n { color: var(--muted); }
.list td.t { font-weight: 600; }
.list td.ts { font-family: var(--mono); font-size: 12px; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--panel-2); }
.list tr.sel { background: #1f2d40; }
.list tr.unknown { opacity: .5; }
.list .badge { font-size: 10px; padding: 0 6px; }
.foot { color: var(--muted); font-size: 12px; padding-top: 6px; }

/* right: the three charts */
.col-charts { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.sig-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; padding: 0 2px; }
.t-title { font-size: 18px; font-weight: 700; }
.t-stats { display: flex; gap: 12px; align-items: baseline; color: var(--muted); font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.t-stats b { color: var(--text); font-weight: 600; }
.t-stats .sig-name { color: var(--sig); font-weight: 600; }
.charts { flex: 1; min-height: 0; display: grid; gap: 10px; }
/* grid: the first chart on top across the width, the others side by side below; rows: one below the other */
.charts.grid { grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); grid-template-rows: var(--grid-rows, minmax(0, 1fr) minmax(0, 1.25fr)); }
.charts.grid > .chart-panel:first-child { grid-column: 1 / -1; }
.charts.rows { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(var(--n, 3), minmax(0, 1fr)); }
.chart-panel { display: flex; flex-direction: column; padding: 8px 10px; }
.chart-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; font-size: 12px; }
.chart-head b { font-size: 13px; }
.chart-head .info { color: var(--muted); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-head .cut { color: var(--warn); }
.chart-wrap { position: relative; flex: 1; min-height: 110px; }
.chart-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.chart-wrap canvas.dragging { cursor: grabbing; }
.tip { position: absolute; display: none; pointer-events: none; background: rgba(14, 17, 22, .92); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font: 12px var(--mono); white-space: pre; z-index: 2; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 11px; flex-wrap: wrap; padding: 0 2px; }
.sw { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; }
.sw.sig { width: 3px; height: 12px; background: var(--sig); }
.sw.sig.dash { background: repeating-linear-gradient(var(--sig) 0 3px, transparent 3px 5px); }
.sw.rth { background: #263040; height: 8px; }
.sw.day { width: 2px; height: 12px; background: #4a5566; }
.legend .hint { margin-left: auto; }

/* full screen: one chart alone (Esc leaves) */
.fs-btn { margin-left: auto; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 5px; line-height: 0; cursor: pointer; flex-shrink: 0; }
.fs-btn:hover { color: var(--text); border-color: var(--accent); }
.panel:fullscreen, .panel.maximized { position: fixed; inset: 0; z-index: 100; width: 100vw; height: 100vh; max-height: none;
  margin: 0; border-radius: 0; border: 0; padding: 12px 16px; display: flex; flex-direction: column; background: var(--panel); }
.panel:fullscreen::backdrop { background: var(--bg); }
.empty { color: var(--muted); padding: 8px 0; }

@media (max-width: 1100px) {  /* the page scrolls instead of squeezing the charts */
  .screen { height: auto; }
  main { flex: none; grid-template-columns: 1fr; }
  .col-left { max-height: 45vh; }
  .charts.grid, .charts.rows { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(var(--n, 3), 360px); }
  .charts.grid > .chart-panel:first-child { grid-column: auto; }
}
