/* ---------- reset & tokens ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

:root {
  --bg: #0b0f14;
  --bg-raised: #121822;
  --bg-raised-2: #171f2c;
  --border: #263041;
  --text: #e6edf5;
  --text-dim: #93a2b8;
  --text-faint: #78879d; /* ~5.3:1 on --bg, clears WCAG AA 4.5:1 for normal text */
  --accent: #4c9aff;
  --accent-dim: #2a4a72;
  --warn-bg: #3a2c12;
  --warn-border: #7a5a1e;
  --warn-text: #f2c26b;
  --info-bg: #12283a;
  --info-border: #1e4a6b;
  --info-text: #8fc8ef;
  --ok: #4caf7d;
  --stale: #e0a840;
  --error: #e0605c;
  --scroll-thumb: #2b3646;

  --series-0: #4c9aff;
  --series-1: #ff8a65;
  --series-2: #7fd48a;
  --series-3: #e57373;
  --series-4: #ba68c8;
  --series-5: #4dd0e1;
  --series-6: #ffd54f;
  --series-7: #f06292;
  --series-8: #b0958a;
  --series-9: #90a4ae;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.4;
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- banner ---------- */
.synthetic-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn-text);
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 500;
}
.synthetic-banner .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn-text);
  flex: none;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.app-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.last-updated { color: var(--text-faint); font-size: 11.5px; }

/* Feedback for the "Reload latest data" button. The common outcome is "nothing changed",
   because the button only re-reads what the daily scheduled job published — it cannot pull
   from the upstream sources itself. So it has to SAY that, rather than appearing inert. */
.reload-status {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.reload-status[hidden] { display: none !important; }
.reload-status--ok {
  color: #7fd48a;
  background: rgba(127, 212, 138, 0.10);
  border-color: rgba(127, 212, 138, 0.35);
}
.reload-status--idle {
  color: #9aa7b8;
  background: rgba(154, 167, 184, 0.10);
  border-color: rgba(154, 167, 184, 0.28);
}
.reload-status--error {
  color: #e57373;
  background: rgba(229, 115, 115, 0.10);
  border-color: rgba(229, 115, 115, 0.38);
}

/* ---------- layout ---------- */
.layout {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 46px);
}
.left-rail {
  width: 300px;
  flex: none;
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  max-height: calc(100vh - 46px);
  position: sticky;
  top: 0;
}
.main-area {
  flex: 1;
  min-width: 0;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rail-section { margin-bottom: 16px; }
.rail-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 6px;
  cursor: default;
}
details.rail-section > summary.rail-section-title { cursor: pointer; }
.rail-hint { color: var(--text-faint); font-size: 11px; margin-bottom: 6px; }
.rail-cols-label {
  display: grid;
  grid-template-columns: 1fr 60px;
  font-size: 10.5px;
  color: var(--text-faint);
  padding: 0 4px 2px 26px;
}

/* ---------- series list ---------- */
.series-list { display: flex; flex-direction: column; }
.group-header {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin: 10px 0 3px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.group-header:first-child { margin-top: 0; border-top: none; padding-top: 0; }

/* Collapsible group headers. The rail carries ~60 series now; without collapsing, the
   markets and rates most often reached for sit far above the fold. */
.group-header {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}
.group-header:hover { color: var(--text); }
.group-header:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
.group-caret { width: 9px; flex: none; font-size: 9px; opacity: 0.75; }
.group-title { flex: 1; }
.group-count {
  font-weight: 600;
  font-size: 9.5px;
  opacity: 0.5;
  letter-spacing: 0;
  flex: none;
}

.rail-filter-wrap { position: relative; margin: 6px 0 4px; }
.rail-filter {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 22px 4px 7px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.rail-filter:focus { outline: none; border-color: var(--accent); }
/* Chrome draws its own search clear affordance; ours is the only one, for consistency. */
.rail-filter::-webkit-search-cancel-button { display: none; }
.rail-filter-clear {
  position: absolute;
  right: 3px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px;
  padding: 0; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  background: none; border: none; border-radius: 3px;
  cursor: pointer; font-size: 14px;
}
.rail-filter-clear:hover { color: var(--text); background: var(--bg-raised); }

.rail-empty {
  padding: 10px 4px;
  font-size: 11.5px;
  color: var(--text-dim);
}

.s-row {
  display: grid;
  grid-template-columns: 20px 1fr 40px;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
}
.s-row:hover { background: var(--bg-raised); }
.s-row.disabled { opacity: 0.45; cursor: not-allowed; }
.s-row .s-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.3px;
}
.s-row .denom-cb { justify-self: center; }
.s-row .swatch {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; margin-right: 5px; flex: none;
  visibility: hidden;
}
.s-row.plotted .swatch { visibility: visible; }
.s-row .s-label-wrap { display: flex; align-items: center; overflow: hidden; }

/* ---------- data health ---------- */
.data-health-body { max-height: 320px; overflow-y: auto; }
.dh-row {
  display: grid;
  grid-template-columns: 1fr 46px 60px;
  gap: 6px;
  padding: 3px 4px;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.dh-row .dh-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
.dh-status { font-weight: 600; text-align: center; border-radius: 3px; padding: 1px 4px; font-size: 10px; }
.dh-status.ok { color: var(--ok); }
.dh-status.stale { color: var(--stale); }
.dh-status.error { color: var(--error); }
.dh-age { color: var(--text-faint); text-align: right; }

/* ---------- main controls ---------- */
.chart-wrap {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px 4px;
}
.chart { width: 100%; height: 560px; }
/* Two stacked panels need more vertical room than one. Without this, splitting a 560px
   chart in half leaves each panel ~215px, which is too short to read a derivative
   against its own zero line. Toggled from render() whenever the transform panel is up. */
.chart.split { height: 820px; }

.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
.control-group { display: flex; align-items: center; gap: 6px; }
.control-label { color: var(--text-dim); font-size: 11.5px; margin-right: 2px; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: var(--bg-raised-2); color: var(--text); }
.seg-btn.active { background: var(--accent-dim); color: #fff; }
.seg-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn {
  background: var(--bg-raised-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-small { padding: 3px 8px; font-size: 11.5px; }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.chk-inline { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.chk-inline input[disabled] { cursor: not-allowed; }
.num-inline { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-faint); }
.num-inline input {
  width: 52px; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 4px; padding: 2px 5px; font-size: 12px;
}
.axis-note { font-size: 10.5px; color: var(--text-faint); max-width: 220px; }

.share-hint { font-size: 11px; color: var(--text-faint); margin-left: auto; }

/* ---------- banners inside main ---------- */
[hidden] { display: none !important; }
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12px;
}
.banner-warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); }
.banner-info { background: var(--info-bg); border: 1px solid var(--info-border); color: var(--info-text); }

/* ---------- series transform controls ---------- */
.series-controls { display: flex; flex-direction: column; gap: 5px; }
.sc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  flex-wrap: wrap;
}
.sc-row .swatch { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.sc-row .sc-label { font-weight: 600; min-width: 90px; }
.sc-row select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 6px; font-size: 12px;
}
.sc-empty { color: var(--text-faint); font-size: 12px; padding: 6px 2px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .layout { flex-direction: column; }
  .left-rail { width: 100%; max-height: none; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .chart { height: 420px; }
  .chart.split { height: 640px; }
}

/* ---------- manual y-axis bounds ---------- */
.axis-num {
  width: 62px;
  padding: 3px 6px;
  font-size: 11.5px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid #263041;
  border-radius: 4px;
}
.axis-num::placeholder { color: #66748a; }
.axis-num:focus { outline: none; border-color: #4c9aff; }

/* ---------- derivation panel ---------- */
/* Net liquidity is the one series that is computed rather than published, and an
   arithmetic error there is invisible on the chart. Showing the working is the point. */
.derivation {
  margin: 0 0 10px 0;
  border: 1px solid #263041;
  border-radius: 6px;
  background: rgba(76, 154, 255, 0.04);
  font-size: 12px;
}
.derivation-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; border-bottom: 1px solid #1c2532;
  font-weight: 600; color: #c8d4e4;
}
.derivation-body { padding: 10px 12px 12px; }
.deriv-formula {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px; color: #7fd48a;
  padding: 6px 0 10px; letter-spacing: 0.01em;
}
.deriv-row {
  display: grid;
  grid-template-columns: 18px 1fr 110px 96px;
  gap: 8px; align-items: baseline;
  padding: 3px 0; color: #b6c2d3;
}
.deriv-sign { color: #93a2b8; font-family: ui-monospace, monospace; }
.deriv-val {
  text-align: right; font-family: ui-monospace, monospace; color: #e6edf3;
}
.deriv-date { text-align: right; color: #78879d; font-size: 11px; }
.deriv-total {
  border-top: 1px solid #263041; margin-top: 6px; padding-top: 7px; font-weight: 600;
}
.deriv-total .deriv-val { color: #7fd48a; }
.deriv-note {
  margin: 9px 0 0; color: #9aa7b8; font-size: 11.5px; line-height: 1.5;
}
