/* ============================================================================
   THE LEVEL — design system for the Reserve Index dashboard
   ----------------------------------------------------------------------------
   The fund is a spirit level: it always returns to centre. Every device below
   is that idea repeated, not decoration bolted on.

   VIAL     the level capsule; bubble offset = reserve deviation from target.
            Also the logo mark. The single hero device.
   GATE     the +/- band drawn as two hard posts; a leg sits inside or breaches.
   DATUM    section head = mono label + hairline to the edge + terminal block.
   HEADROOM pool depth vs planned trade — the constraint unique to this fund.
   TRACE    real chart, fund vs never-rebalanced. Never a toy sparkline.
   FIGURE   condensed 800, tabular-nums, always signed.

   House rules kept from THE FLOOR:
     - structure with hairlines, never shadows or gaps
     - NO GREY ON DARK: the whole neutral ramp is tinted toward the vial
     - ONE accent. Semantic colour lives on figures only, never on chrome
     - nothing animates unless it is data
   Deliberately dark-only: this is an instrument surface, not a reading surface.
   ========================================================================== */

:root {
  /* ground — graphite tinted olive toward the vial, so nothing reads as grey */
  --base:    #0A0C07;
  --base2:   #0E1209;
  --panel:   #12160D;
  --panel2:  #1A2013;
  --line:    #262F1A;
  --line2:   #384428;

  /* text ramp, same tint */
  --bone:    #EFF3E2;
  --dim:     #C2CCA6;
  --dim2:    #8D9A6E;

  /* the one accent: spirit-level fluid. Chrome only — never a data colour. */
  --vial:    #D8F24B;
  --vial-12: color-mix(in srgb, var(--vial) 12%, transparent);
  --vial-25: color-mix(in srgb, var(--vial) 25%, transparent);
  --vial-40: color-mix(in srgb, var(--vial) 40%, transparent);
  --on-vial: #0A0C07;

  /* semantics: figures only. Hue-separated from the vial so they never collide. */
  --up:      #00E5A0;
  --down:    #FF5470;
  --warn:    #FFA83D;

  --display: "Saira Condensed", "Bahnschrift", "Oswald", system-ui, sans-serif;
  --body:    "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono:    "JetBrains Mono", "Cascadia Mono", Consolas, monospace;

  --pad: 14px;
  --gap: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--base);
  color: var(--bone);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* faint machinist's grid — a surface texture, not a decoration */
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: -1px -1px;
}

.shell { max-width: 1320px; margin: 0 auto; padding: 0 18px 64px; }

/* ── FIGURE ───────────────────────────────────────────────────────────────── */
.fig {
  font-family: var(--display);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1;
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.warn { color: var(--warn); }

/* ── header ───────────────────────────────────────────────────────────────── */
.top {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 0 16px;
  border-bottom: 1px solid var(--line2);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: 21px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
}
.brand h1 span { color: var(--dim2); font-weight: 600; }
.top .spacer { flex: 1; }

.chip {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  border: 1px solid var(--line2);
  padding: 4px 9px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.chip b { color: var(--bone); font-weight: 600; }
.chip.live { border-color: var(--vial-40); color: var(--vial); }
.chip.sim { border-color: var(--line2); color: var(--warn); }

/* the pulse is data — it says the feed is alive — so it is allowed to move */
.pulse { width: 6px; height: 6px; background: var(--vial); border-radius: 50%; }
.pulse.beat { animation: beat 2.4s ease-in-out infinite; }
@keyframes beat { 0%,100% { opacity: 1 } 50% { opacity: .28 } }
@media (prefers-reduced-motion: reduce) { .pulse.beat { animation: none } }

/* ── DATUM: section head ──────────────────────────────────────────────────── */
.datum {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 30px 0 12px;
}
.datum::before {
  content: "";
  width: 7px; height: 7px;
  background: var(--vial);
  flex: none;
}
.datum h2 {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0;
  white-space: nowrap;
}
.datum .rule { flex: 1; height: 1px; background: var(--line2); }
.datum .aside {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  color: var(--dim2);
  text-transform: uppercase;
  white-space: nowrap;
}

/* ── plates ───────────────────────────────────────────────────────────────── */
.plate {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: var(--pad);
}
.grid { display: grid; gap: var(--gap); }
.g-hero { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ── VIAL: the hero device ────────────────────────────────────────────────── */
.vial-wrap { padding: 10px 2px 2px; }
.vial {
  position: relative;
  height: 92px;
  background: var(--base2);
  border: 1px solid var(--line2);
  overflow: hidden;
}
/* the two halves, held apart so the split is legible at a glance */
.vial .fill-res {
  position: absolute; inset: 0 auto 0 0;
  background: repeating-linear-gradient(135deg, var(--vial-12) 0 6px, transparent 6px 12px), var(--vial-12);
  border-right: 1px solid var(--vial-40);
}
.vial .fill-bas {
  position: absolute; inset: 0 0 0 auto;
  background: color-mix(in srgb, var(--bone) 7%, transparent);
}
/* the band: where the boundary is allowed to sit */
.vial .datum-l, .vial .datum-r {
  position: absolute; top: 0; bottom: 0; width: 2px; background: var(--vial);
  opacity: .85;
}
.vial .datum-l::after, .vial .datum-r::after {
  content: ""; position: absolute; top: 0; left: 2px; width: 5px; height: 5px; background: var(--vial);
}
.vial .datum-r::after { left: -5px; }
.vial .centre {
  position: absolute; top: 0; bottom: 0; width: 1px; left: 50%;
  background: repeating-linear-gradient(var(--dim2) 0 4px, transparent 4px 9px);
}
/* the bubble: it rides the boundary between reserve and basket */
.vial .bubble {
  position: absolute;
  top: 14px; bottom: 14px;
  width: 54px;
  margin-left: -27px;
  border: 2px solid var(--vial);
  border-radius: 32px;
  background: var(--vial-25);
  box-shadow: inset 0 0 0 1px var(--base2);
  transition: left .5s cubic-bezier(.2,.7,.3,1);
}
.vial .bubble::after {
  content: ""; position: absolute; left: 50%; top: 6px; bottom: 6px; width: 1px;
  background: var(--vial);
}
.vial .bubble.off {
  border-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 22%, transparent);
}
.vial .bubble.off::after { background: var(--warn); }
.vial-scale {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em;
  color: var(--dim2); text-transform: uppercase; margin-top: 8px;
}
.vial-scale b { color: var(--vial); font-weight: 500; }

/* a signed delta chip — lets a big figure stay bone while its sign still reads */
.delta {
  font-family: var(--mono); font-size: 11px; font-variant-numeric: tabular-nums;
  border: 1px solid var(--line2); padding: 2px 6px; margin-left: 8px;
  display: inline-block; vertical-align: 4px;
}
.delta.up { color: var(--up); border-color: color-mix(in srgb, var(--up) 40%, transparent); }
.delta.down { color: var(--down); border-color: color-mix(in srgb, var(--down) 40%, transparent); }

.readout { display: flex; align-items: flex-end; gap: 26px; flex-wrap: wrap; margin-bottom: 14px; }
.readout .lab {
  font-family: var(--mono); font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--dim2); display: block; margin-bottom: 5px;
}
.readout .big { font-size: 46px; }
.readout .mid { font-size: 26px; }

/* ── tiles ────────────────────────────────────────────────────────────────── */
.tile { background: var(--panel); border: 1px solid var(--line); padding: 12px 13px; }
.tile .lab {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .15em;
  text-transform: uppercase; color: var(--dim2); display: block; margin-bottom: 7px;
}
.tile .val { font-size: 25px; }
.tile .sub { font-family: var(--mono); font-size: 11px; color: var(--dim2); margin-top: 5px; }

/* ── legs table ───────────────────────────────────────────────────────────── */
.tbl-wrap { border: 1px solid var(--line); background: var(--panel); overflow-x: auto; }
table.legs { width: 100%; border-collapse: collapse; min-width: 940px; }
table.legs th {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--dim2); font-weight: 500;
  text-align: right; padding: 10px 12px; background: var(--panel2);
  border-bottom: 1px solid var(--line2); white-space: nowrap;
}
table.legs th:first-child, table.legs td:first-child { text-align: left; }
table.legs td {
  padding: 11px 12px; border-bottom: 1px solid var(--line);
  text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
table.legs tr:last-child td { border-bottom: 0; }
table.legs tbody tr { cursor: pointer; }
table.legs tbody tr:hover { background: var(--panel2); }
table.legs tbody tr.sel { background: var(--vial-12); }
table.legs tbody tr.reserve td { color: var(--vial); }
.sym { font-family: var(--display); font-weight: 800; font-size: 16px; letter-spacing: .04em; }
.kind { font-family: var(--mono); font-size: 9.5px; color: var(--dim2); letter-spacing: .08em; text-transform: uppercase; }

/* ── GATE: drift against the band ─────────────────────────────────────────── */
.gate { position: relative; width: 168px; height: 22px; margin-left: auto; }
.gate .axis { position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--line2); }
.gate .mid { position: absolute; top: 2px; bottom: 2px; left: 50%; width: 1px; background: var(--dim2); }
.gate .post { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--vial-40); }
.gate .bar { position: absolute; top: 6px; height: 10px; background: var(--dim); }
.gate .bar.breach { background: var(--warn); }

/* ── HEADROOM: how much of the trade the pool can take ────────────────────── */
.head { width: 118px; margin-left: auto; }
.head .track { height: 6px; background: var(--panel2); border: 1px solid var(--line2); position: relative; }
.head .fillbar { position: absolute; inset: 0 auto 0 0; background: var(--up); }
.head .fillbar.tight { background: var(--warn); }
.head .fillbar.bad { background: var(--down); }
.head .cap { font-family: var(--mono); font-size: 10px; color: var(--dim2); margin-top: 4px; text-align: right; }

/* ── TRACE: the real chart ────────────────────────────────────────────────── */
.trace { position: relative; }
.trace canvas { display: block; width: 100%; height: 320px; }
.legend { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 10px; }
.legend div {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--dim); display: flex; align-items: center; gap: 8px;
}
.legend i { width: 16px; height: 2px; display: block; }
.tip {
  position: absolute; pointer-events: none; opacity: 0;
  background: var(--base2); border: 1px solid var(--line2); padding: 8px 10px;
  font-family: var(--mono); font-size: 11px; white-space: nowrap; z-index: 5;
}
.tip.on { opacity: 1; }
.tip .d { color: var(--dim2); font-size: 10px; letter-spacing: .1em; }

/* ── candles ──────────────────────────────────────────────────────────────── */
.candles canvas { display: block; width: 100%; height: 210px; }

/* ── plan queue ───────────────────────────────────────────────────────────── */
.qrow {
  display: grid;
  grid-template-columns: 74px 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 11px 12px; border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 12px;
}
.qrow:last-child { border-bottom: 0; }
.side {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase;
  border: 1px solid var(--line2); padding: 3px 7px; text-align: center;
}
.side.sell { color: var(--down); border-color: color-mix(in srgb, var(--down) 45%, transparent); }
.side.buy { color: var(--up); border-color: color-mix(in srgb, var(--up) 45%, transparent); }
.qrow .flow { color: var(--bone); }
.qrow .flow em { color: var(--dim2); font-style: normal; }
.qrow .note { color: var(--dim2); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; }

.empty {
  padding: 26px 14px; text-align: center; color: var(--dim2);
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase;
}

/* ── notes ────────────────────────────────────────────────────────────────── */
.note-plate {
  border: 1px solid var(--line2);
  border-left: 2px solid var(--vial);
  background: var(--panel);
  padding: 12px 14px;
  color: var(--dim);
  font-size: 13px;
}
.note-plate b { color: var(--bone); font-weight: 600; }

footer {
  margin-top: 42px; padding-top: 16px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em;
  color: var(--dim2); text-transform: uppercase;
  display: flex; gap: 18px; flex-wrap: wrap;
}

@media (max-width: 1040px) {
  .g-hero, .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .shell { padding: 0 12px 48px; }
  .g-hero, .g-4 { grid-template-columns: 1fr; }
  .readout .big { font-size: 36px; }
}
