/*
 * ARBITRAGE WORKSPACE — System B.
 *
 * A DELIBERATELY DIFFERENT PRODUCT SURFACE. The directional terminal
 * (css/livecore.css) is a near-black trading floor built around a price
 * chart. This is not that, and it must not look like it: an operator
 * glancing at a screen has to know, instantly and without reading a
 * word, which of the two trading systems they are looking at.
 *
 * So the identity is its own: a cooler slate ground, a teal/amber
 * accent pair instead of the terminal's green/red, a PAIRED layout
 * language (everything here comes in twos, because everything here IS a
 * pair), and no chart at all — an arbitrage has no direction to draw.
 *
 * THE LEG BRACKET is the signature element. Every position and every
 * candidate is rendered as two leg cards joined by a bracket, so the
 * fact that they are one trade is carried by the layout rather than by
 * a label somebody has to read.
 *
 * Nothing in this file encodes a number. Every value on the page is
 * written by js/arbitrage.js from a real backend snapshot, and anything
 * the backend did not send renders as an em dash.
 */

:root {
  color-scheme: dark;

  --ground:      #0b1016;
  --surface:     #121a23;
  --surface-2:   #18222d;
  --surface-3:   #1f2c39;
  --line:        #24323f;
  --line-soft:   #1b2631;

  --ink:         #e7eef5;
  --ink-2:       #9fb2c4;
  --ink-3:       #6b8098;

  /* Teal is the arbitrage accent. It is NOT the directional terminal's
     green, on purpose — a shared accent would make two products look
     like two tabs of one. */
  --accent:      #2fd6c3;
  --accent-dim:  #1d8d81;
  --amber:       #f0b23c;
  --up:          #3ddc97;
  --down:        #ff6b6b;
  --violet:      #9d8cff;

  --spot:        #5aa9ff;   /* the long leg  */
  --deriv:       #ff9f6b;   /* the short leg */

  --radius:      10px;
  --radius-sm:   6px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body.stale #system-bar { border-bottom-color: var(--amber); }

a { color: var(--accent); }

/* ================================================================
   SYSTEM BAR — which product am I in, and is it running?
   ================================================================ */

#system-bar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px;
  background: linear-gradient(180deg, #0e161f 0%, #0b1016 100%);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent-dim), #123b3a);
  color: #04100f; font-weight: 800; letter-spacing: .5px; font-size: 13px;
  box-shadow: inset 0 0 0 1px rgba(47,214,195,.35);
}
.brand-name { font-weight: 700; letter-spacing: .2px; }
.brand-sub { color: var(--ink-3); font-size: 11px; font-family: var(--mono); }

/* The system switcher. Two products, one shell — and the shell says so. */
.switcher {
  display: flex; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px;
}
.switcher a {
  padding: 6px 14px; border-radius: 999px;
  font-size: 12px; font-weight: 600; text-decoration: none;
  color: var(--ink-3); white-space: nowrap;
}
.switcher a.on { background: var(--surface-3); color: var(--ink); }
.switcher a:not(.on):hover { color: var(--ink-2); }

.bar-spacer { flex: 1 1 auto; }

.pill-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-family: var(--mono); letter-spacing: .3px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
  white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.pill.ok      { color: var(--up); border-color: #1d4d3a; }
.pill.ok .dot { background: var(--up); }
.pill.warn      { color: var(--amber); border-color: #5a4318; }
.pill.warn .dot { background: var(--amber); }
.pill.bad      { color: var(--down); border-color: #5a2020; }
.pill.bad .dot { background: var(--down); }
.pill.idle .dot { background: var(--ink-3); }
.pill.mode  { color: var(--accent); border-color: var(--accent-dim); font-weight: 700; }
.pill.locked { color: var(--amber); border-color: #5a4318; font-weight: 700; }

.btn {
  padding: 6px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink); font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: var(--sans);
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent-dim); border-color: var(--accent); color: #04100f; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { border-color: #5a2020; color: var(--down); }
.btn.danger:hover { background: #2a1414; }
.btn.small { padding: 3px 9px; font-size: 11px; }

/* ================================================================
   LAYOUT
   ================================================================ */

#workspace { padding: 16px 18px 40px; display: grid; gap: 16px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.panel-title { font-size: 12px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; }
.panel-meta { margin-left: auto; font-size: 11px; font-family: var(--mono); color: var(--ink-3); }
.panel-body { padding: 14px; }
.panel-body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: repeat(3, 1fr); }

/* ================================================================
   MONEY — the loudest thing on the page
   ================================================================ */

#money {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.money-cell { background: var(--surface); padding: 12px 14px; }
.money-label {
  font-size: 10px; letter-spacing: .8px; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 5px;
}
.money-value { font-family: var(--mono); font-size: 21px; font-weight: 600; letter-spacing: -.4px; }
.money-value.lg { font-size: 26px; }
.money-sub { font-size: 11px; font-family: var(--mono); color: var(--ink-3); margin-top: 3px; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--ink-3); }

/* Capital: a single bar that shows reserve / deployed / available at a
   glance, because three numbers in a row do not communicate a ratio. */
.capital-bar {
  display: flex; height: 10px; border-radius: 999px; overflow: hidden;
  background: var(--surface-3); margin: 10px 0 8px;
}
.capital-seg { height: 100%; }
.capital-seg.deployed { background: var(--accent); }
.capital-seg.available { background: var(--accent-dim); opacity: .45; }
.capital-seg.reserved { background: repeating-linear-gradient(
  45deg, #2a3a49, #2a3a49 4px, #22303d 4px, #22303d 8px); }
.capital-key { display: flex; gap: 16px; flex-wrap: wrap; font-size: 11px; font-family: var(--mono); }
.capital-key span { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.capital-key i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* ================================================================
   STRATEGY CARDS — two families, two independent switches
   ================================================================ */

.strategy-card { display: grid; gap: 10px; }
.strategy-head { display: flex; align-items: center; gap: 10px; }
.strategy-name { font-weight: 700; font-size: 14px; }
.strategy-legs { font-size: 11px; font-family: var(--mono); color: var(--ink-3); }

.toggle {
  margin-left: auto;
  position: relative; width: 46px; height: 24px; flex: none;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-3); cursor: pointer; padding: 0;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--ink-3); transition: transform .14s ease, background .14s ease;
}
.toggle.on { background: rgba(47,214,195,.18); border-color: var(--accent-dim); }
.toggle.on::after { transform: translateX(22px); background: var(--accent); }
.toggle:disabled { opacity: .45; cursor: not-allowed; }

.strategy-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-3); }
.stat-value { font-family: var(--mono); font-size: 15px; margin-top: 2px; }

/* ================================================================
   THE LEG BRACKET — the signature element
   ================================================================ */

.arb-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 12px;
}
.arb-top {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
  background: var(--surface-3);
}
.arb-id { font-family: var(--mono); font-weight: 700; letter-spacing: .4px; }
.arb-tag {
  font-size: 10px; font-family: var(--mono); letter-spacing: .5px;
  padding: 2px 7px; border-radius: 4px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
}
.arb-tag.strategy { color: var(--violet); border-color: #3a3560; }
.arb-tag.state { color: var(--accent); border-color: var(--accent-dim); }
.arb-tag.venue { color: var(--amber); border-color: #5a4318; }

.legs {
  display: grid;
  grid-template-columns: 1fr 44px 1fr;
  align-items: stretch;
}
.leg { padding: 12px 14px; display: grid; gap: 6px; align-content: start; }
.leg.spot  { border-left: 3px solid var(--spot); }
.leg.deriv { border-left: 3px solid var(--deriv); }
.leg-role {
  font-size: 10px; letter-spacing: .8px; text-transform: uppercase;
  display: flex; align-items: center; gap: 7px;
}
.leg.spot .leg-role  { color: var(--spot); }
.leg.deriv .leg-role { color: var(--deriv); }
.leg-inst { font-family: var(--mono); font-size: 14px; font-weight: 600; }
.leg-rows { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12px; }
.leg-rows dt { color: var(--ink-3); }
.leg-rows dd { margin: 0; font-family: var(--mono); text-align: right; }

/* The bracket that says "these two are ONE trade". */
.leg-bracket {
  position: relative;
  display: grid; place-items: center;
  background: var(--surface);
  border-left: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
}
.leg-bracket::before {
  content: ""; position: absolute; top: 14px; bottom: 14px; left: 50%;
  width: 1px; background: linear-gradient(180deg, var(--spot), var(--deriv));
  opacity: .5;
}
.leg-bracket span {
  position: relative; z-index: 1;
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-3); border: 1px solid var(--line);
  font-size: 13px; color: var(--accent);
}

.arb-foot {
  display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
  padding: 10px 14px; border-top: 1px solid var(--line-soft);
  font-size: 12px; font-family: var(--mono);
}
.arb-foot b { font-weight: 600; }
.arb-foot .k { color: var(--ink-3); font-family: var(--sans); font-size: 11px; }

/* ================================================================
   TABLES
   ================================================================ */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead th {
  position: sticky; top: 0;
  text-align: left; padding: 9px 12px; white-space: nowrap;
  font-size: 10px; letter-spacing: .6px; text-transform: uppercase;
  color: var(--ink-3); background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
tbody td {
  padding: 8px 12px; white-space: nowrap;
  border-bottom: 1px solid var(--line-soft); font-family: var(--mono);
}
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }
tbody tr.rejected td { color: var(--ink-3); }
tbody tr.eligible td { color: var(--ink); }
tbody tr.eligible td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.reason {
  font-size: 10px; letter-spacing: .4px;
  padding: 2px 7px; border-radius: 4px;
  background: var(--surface-3); color: var(--ink-2); border: 1px solid var(--line);
}
.reason.accepted { color: var(--accent); border-color: var(--accent-dim); }

/* ================================================================
   HEALTH
   ================================================================ */

.health-list { display: grid; gap: 1px; background: var(--line-soft); }
.health-row {
  display: grid; grid-template-columns: 200px 90px 1fr;
  gap: 12px; align-items: baseline;
  padding: 8px 14px; background: var(--surface); font-size: 12px;
}
.health-row .name { font-family: var(--mono); color: var(--ink-2); }
.health-row .detail { color: var(--ink-3); white-space: normal; }
.status { font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: .5px; }
.status.OK { color: var(--up); }
.status.DEGRADED { color: var(--amber); }
.status.UNHEALTHY { color: var(--down); }
.status.OFFLINE, .status.UNKNOWN, .status\[NA\] { color: var(--ink-3); }

/* The LIVE gate. Deliberately loud, deliberately permanent. */
#gate {
  border: 1px solid #5a4318;
  background: linear-gradient(180deg, rgba(240,178,60,.07), transparent);
}
#gate .panel-head { background: rgba(240,178,60,.08); border-bottom-color: #5a4318; }
.gate-status { font-family: var(--mono); font-weight: 800; font-size: 16px; color: var(--amber); }
.blocker { display: grid; gap: 2px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.blocker:last-child { border-bottom: 0; }
.blocker .code { font-family: var(--mono); font-size: 12px; color: var(--amber); }
.blocker .why { font-size: 12px; color: var(--ink-2); }

/* ================================================================
   SETTINGS DRAWER
   ================================================================ */

#settings {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%);
  background: var(--surface); border-left: 1px solid var(--line);
  transform: translateX(102%); transition: transform .18s ease;
  z-index: 60; display: flex; flex-direction: column;
}
#settings.open { transform: none; }
.drawer-head, .drawer-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.drawer-foot { border-bottom: 0; border-top: 1px solid var(--line); margin-top: auto; }
.drawer-body { overflow-y: auto; padding: 14px 16px; display: grid; gap: 14px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 11px; color: var(--ink-2); }
.field .bounds { font-size: 10px; font-family: var(--mono); color: var(--ink-3); }
.field input, .field select {
  background: var(--ground); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--radius-sm); padding: 7px 9px; font-family: var(--mono); font-size: 13px;
}
.field input:focus { outline: 1px solid var(--accent-dim); }
.field-group-title {
  font-size: 10px; letter-spacing: .8px; text-transform: uppercase;
  color: var(--accent); margin-top: 6px;
}
#settings-status { font-size: 11px; color: var(--ink-3); margin-right: auto; }
#settings-status.error { color: var(--down); }
#settings-status.ok { color: var(--up); }

.scrim {
  position: fixed; inset: 0; background: rgba(4,8,12,.6);
  opacity: 0; pointer-events: none; transition: opacity .18s ease; z-index: 55;
}
.scrim.on { opacity: 1; pointer-events: auto; }

/* ================================================================
   MISC
   ================================================================ */

.empty {
  padding: 26px 14px; text-align: center; color: var(--ink-3); font-size: 13px;
}
.empty b { color: var(--ink-2); display: block; margin-bottom: 4px; font-weight: 600; }

.note {
  font-size: 11px; color: var(--ink-3); line-height: 1.5;
  border-left: 2px solid var(--line); padding-left: 10px;
}

#toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 80; }
.toast {
  background: var(--surface-3); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 12px;
  max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.bad { border-left-color: var(--down); }
.toast.warn { border-left-color: var(--amber); }

.export-links { display: flex; flex-wrap: wrap; gap: 8px; }
.export-links a {
  font-size: 11px; font-family: var(--mono); text-decoration: none;
  padding: 5px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
}
.export-links a:hover { border-color: var(--accent-dim); color: var(--accent); }
.export-links a .n { color: var(--ink-3); }

/* ================================================================
   RESPONSIVE — one column on a phone, and the leg bracket stacks
   ================================================================ */

@media (max-width: 1100px) {
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  #system-bar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .bar-spacer { display: none; }
  #workspace { padding: 12px 12px 36px; }
  .legs { grid-template-columns: 1fr; }
  .leg-bracket {
    border-left: 0; border-right: 0;
    border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft);
    min-height: 34px;
  }
  .leg-bracket::before { top: 50%; bottom: auto; left: 14px; right: 14px; width: auto; height: 1px;
    background: linear-gradient(90deg, var(--spot), var(--deriv)); }
  .strategy-stats { grid-template-columns: repeat(2, 1fr); }
  .health-row { grid-template-columns: 1fr; gap: 2px; }
  .money-value { font-size: 18px; }
  .money-value.lg { font-size: 22px; }
}

/* ---------------------------------------------------------------------
   Execution route badges. The pair is one position, so the two legs'
   routes sit inside the same card header rather than in a separate
   table that the eye has to join back up.
   --------------------------------------------------------------------- */
.arb-tag.route {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.arb-tag.route.ok {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
}
.arb-tag.route.warn {
  background: color-mix(in srgb, var(--warn, #d9a441) 16%, transparent);
  border-color: color-mix(in srgb, var(--warn, #d9a441) 42%, transparent);
  color: var(--warn, #d9a441);
}
.arb-tag.route.bad {
  background: color-mix(in srgb, var(--bad, #e0554e) 16%, transparent);
  border-color: color-mix(in srgb, var(--bad, #e0554e) 42%, transparent);
  color: var(--bad, #e0554e);
}
