/*
 * The dashboard's layout. Positions are computed here from the numbers the events set:
 *   on :root   --now (Time-Line), --min, --max, --range (Amount-Scale)
 *   on a row   --x --a --l --tmin --tmax (amounts), --due --s --e (seconds), --t0s/--t0e … (waits)
 * A missing number is marked data-no-<name> on the row.
 */
:root {
  --ink: #0f172a; --muted: #64748b; --line: #e2e8f0; --bg: #f8fafc; --card: #ffffff;
  --blue: #3b82f6; --in: #b45309; --in-bg: #fde7c7; --out: #0d9488; --out-bg: #ccfbf1;
  --fail: #dc2626; --fail-bg: #fef2f2; --throttle: #a855f7; --retry: #f97316;
  --min: 0; --max: 1; --range: 1; --now: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
body { margin: 0; }
h1 { font-size: 18px; margin: 0; }
h1 small { color: var(--muted); font-weight: 500; }
h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.clock { font-variant-numeric: tabular-nums; font-weight: 600; }
.phases { display: flex; gap: 12px; list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--muted); }
.phases b { color: var(--ink); font-variant-numeric: tabular-nums; display: inline-block; }
.phases [data-phase=BEING_EXECUTED] b { color: var(--blue); }
.conn { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--line); }
.conn[data-conn=live] { background: #dcfce7; color: #166534; }
.conn[data-conn=reconnecting] { background: #fef3c7; color: #92400e; }
.picker { margin-left: auto; display: flex; gap: 12px; font-size: 13px; }
.picker label { cursor: pointer; }

main { display: grid; grid-template-columns: repeat(auto-fit, minmax(640px, 1fr)); gap: 16px; padding: 16px 20px; }
.view { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-width: 0; }
[data-text] { transform-origin: 50% 50%; }

/* ---- status chips and phases (shared by the views) ---- */
.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 5px;
  background: #eff6ff; color: #1e3a8a; white-space: nowrap; }
[data-status=SCHEDULED] .chip { background: #f1f5f9; color: var(--muted); }
[data-status=LOW_BALANCE] .chip, [data-status=CHECK_LOW_PASSED] .chip { background: #fff7ed; color: #7c2d12; }
[data-status=HIGH_BALANCE] .chip, [data-status=CHECK_HIGH_PASSED] .chip { background: #f0fdfa; color: #134e4a; }
[data-status=SWEPT_IN] .chip { background: var(--in-bg); color: #7c2d12; }
[data-status=SWEPT_OUT] .chip { background: var(--out-bg); color: #134e4a; }
[data-status$=_FAILED] .chip, [data-status$=_TIMEOUT] .chip { background: var(--fail-bg); color: #991b1b; }
[data-phase=TO_BE_EXECUTED] { color: var(--muted); }
[data-phase=BEING_EXECUTED] .duration { color: var(--blue); font-weight: 600; }

/* ---- 1. Main ---- */
table.main { width: 100%; border-collapse: collapse; font-size: 13px; }
.main th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 4px 6px; }
.main th.num { text-align: right; }
.main td { padding: 4px 6px; border-bottom: 1px solid #f1f5f9; }
.main tr[data-phase=BEING_EXECUTED] { background: #eff6ff; }
.plan { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }

/* ---- 2. Amount-Scale: left edge --min, right edge --max ---- */
.scale-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted);
  margin-left: 220px; margin-right: 210px; }
.legend { display: flex; gap: 6px; align-items: center; }
.key { display: inline-block; width: 12px; height: 8px; margin-left: 6px; border-radius: 2px; }
.key.band { background: #e0e7ff; border: 1px solid #a5b4fc; }
.key.x { width: 3px; height: 12px; background: var(--ink); }
.key.a { width: 3px; height: 12px; background: var(--in); }
.key.l { width: 3px; height: 12px; background: var(--out); }
.sc-row { display: grid; grid-template-columns: 210px 1fr 130px 70px; gap: 10px; align-items: center;
  font-size: 12px; height: 24px; border-bottom: 1px solid #f1f5f9; }
.sc-track { position: relative; height: 16px; background: #f8fafc; border-radius: 3px; }
.sc-band, .sc-mark { position: absolute; top: 0; bottom: 0; }
.sc-band {
  left: calc((var(--tmin, var(--tmax)) - var(--min)) / var(--range) * 100%);
  width: calc((var(--tmax) - var(--tmin, var(--tmax))) / var(--range) * 100%);
  min-width: 2px; background: #e0e7ff; border: 1px solid #a5b4fc; border-radius: 3px; top: 3px; bottom: 3px;
}
.sc-mark { width: 3px; margin-left: -1px; border-radius: 1px; transition: left .3s ease-out; }
.sc-mark.x { left: calc((var(--x) - var(--min)) / var(--range) * 100%); background: var(--ink); }
.sc-mark.a { left: calc((var(--a) - var(--min)) / var(--range) * 100%); background: var(--in); top: -2px; bottom: -2px; }
.sc-mark.l { left: calc((var(--l) - var(--min)) / var(--range) * 100%); background: var(--out); top: -2px; bottom: -2px; }
[data-no-x] .sc-mark.x, [data-no-a] .sc-mark.a, [data-no-l] .sc-mark.l, [data-no-tmax] .sc-band { display: none; }

/* ---- 3. Time-Line: x = seconds since the origin; the track moves left as --now grows ---- */
.tl-axis { display: flex; justify-content: space-between; margin-left: 220px; font-size: 12px; color: var(--muted);
  position: relative; }
.tl-axis-now { position: absolute; left: calc(var(--anchor) * 100%); transform: translateX(-50%);
  color: var(--ink); font-weight: 600; }
.tl-lane { display: grid; grid-template-columns: 210px 1fr; gap: 10px; align-items: center; height: 26px; font-size: 12px; }
.tl-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-viewport { position: relative; height: 100%; overflow: hidden; border-bottom: 1px solid #f1f5f9;
  background: linear-gradient(to right, transparent calc(var(--anchor) * 100% - 1px), var(--blue) 0,
              var(--blue) calc(var(--anchor) * 100% + 1px), transparent 0); }
.tl-track { position: absolute; inset: 0;
  transform: translateX(calc((var(--anchor) - var(--now) / var(--span)) * 100%));
  transition: transform var(--tick) linear; will-change: transform; }
.tl-exec { position: absolute; inset: 0; }
.tl-exec > i { position: absolute; display: block; }
.tl-bar { top: 5px; bottom: 5px; border-radius: 3px; background: #93c5fd;
  left: calc(var(--s) / var(--span) * 100%);
  width: calc((var(--e, var(--now)) - var(--s)) / var(--span) * 100%); min-width: 2px;
  transition: width var(--tick) linear; }
[data-no-s] .tl-bar { display: none; }
[data-status=SWEPT_IN] .tl-bar { background: var(--in-bg); outline: 1px solid var(--in); }
[data-status=SWEPT_OUT] .tl-bar { background: var(--out-bg); outline: 1px solid var(--out); }
[data-status$=_FAILED] .tl-bar, [data-status$=_TIMEOUT] .tl-bar { background: var(--fail-bg); outline: 1px solid var(--fail); }
.tl-due { top: 2px; bottom: 2px; width: 0; border-left: 2px dotted var(--muted); left: calc(var(--due) / var(--span) * 100%); }
.tl-wait { top: 9px; bottom: 9px; border-radius: 2px; opacity: .85; }
.tl-wait.throttle { background: var(--throttle); }
.tl-wait.retry { background: var(--retry); }
.tl-legend { margin: 8px 0 0 220px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.key.bar { background: #93c5fd; } .key.throttle { background: var(--throttle); } .key.retry { background: var(--retry); }
.key.due { width: 0; border-left: 2px dotted var(--muted); }

/* ---- 4. State-chart (the SVG of plans-core) and its count badges ---- */
.chart svg { width: 100%; height: auto; display: block; }
.sc-count circle { fill: var(--ink); stroke: #fff; stroke-width: 2; }
.sc-count text { fill: #fff; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sc-count[data-zero] { opacity: .3; }
