:root {
  --bg: #0b0e14;
  --panel: #121722;
  --panel-2: #171d2b;
  --line: #232b3d;
  --line-soft: #1a2130;
  --text: #e6ebf5;
  --muted: #8b97ad;
  --faint: #5d6879;
  --buy: #2ecc8f;
  --sell: #ff6b81;
  --warn: #ffb454;
  --bad: #ff5f6d;
  --accent: #5aa9ff;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.brand { font-weight: 650; letter-spacing: -0.01em; font-size: 15px; }
.brand span { color: var(--faint); font-weight: 400; margin-left: 8px; font-size: 12px; }
.topbar .spacer { flex: 1; }

.stat { font-size: 12px; color: var(--muted); white-space: nowrap; }
.stat b { color: var(--text); font-family: var(--mono); font-weight: 550; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 6px; background: var(--faint); }
.dot.live { background: var(--buy); box-shadow: 0 0 0 3px rgba(46,204,143,.15); }
.dot.err  { background: var(--bad); box-shadow: 0 0 0 3px rgba(255,95,109,.15); }

/* ---------- controls ---------- */

button, .btn {
  font: inherit; font-size: 13px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 14px; cursor: pointer;
  transition: border-color .12s, background .12s;
}
button:hover { border-color: #3a465f; background: #1c2333; }
button.primary { background: var(--accent); border-color: var(--accent); color: #05101f; font-weight: 600; }
button.primary:hover { background: #7bbcff; border-color: #7bbcff; }
button:disabled { opacity: .45; cursor: not-allowed; }

.toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); margin: 0; }

/* ---------- layout ---------- */

.wrap { padding: 20px 22px 60px; max-width: 1720px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  margin-bottom: 18px;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 16px; border-bottom: 1px solid var(--line-soft);
}
.panel-title { font-size: 12px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 600; }
.panel-body { padding: 16px; }

textarea {
  width: 100%; min-height: 132px; resize: vertical;
  background: #0d121c; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  tab-size: 12;
}
textarea:focus { outline: none; border-color: var(--accent); }
textarea::placeholder { color: var(--faint); }

.row-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- summary ---------- */

.summary { display: flex; flex-wrap: wrap; gap: 0; border-top: 1px solid var(--line-soft); }
.sum-cell { padding: 12px 18px; border-right: 1px solid var(--line-soft); min-width: 128px; }
.sum-cell:last-child { border-right: none; }
.sum-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); }
.sum-value { font-family: var(--mono); font-size: 16px; font-weight: 600; margin-top: 3px; }
.sum-value small { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 5px; }

/* ---------- table ---------- */

/* 'clip' rather than the default: pairing 'visible' with 'overflow-x: auto'
   makes the browser compute overflow-y to 'auto' as well, adding a stray
   vertical scrollbar around the table. This scrolls sideways only. */
.table-scroll { overflow-x: auto; overflow-y: clip; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }

/* Deliberately NOT sticky. A pinned header floats above the rows, and any
   error in its offset lands it on top of the first trade — the one row you can
   least afford to lose. It sits in the flow, right under the panel title. */
thead th {
  background: var(--panel-2);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 600; text-align: right;
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
thead th.l { text-align: left; }
thead th.grp { border-left: 1px solid var(--line); }

tbody td {
  padding: 10px 12px; border-bottom: 1px solid var(--line-soft);
  text-align: right; font-family: var(--mono); font-size: 13px; white-space: nowrap;
}
tbody td.l { text-align: left; font-family: var(--sans); }
tbody td.grp { border-left: 1px solid var(--line-soft); }
tbody tr:hover td { background: #151b28; }
tbody tr.failed td { background: rgba(255,95,109,.045); }

.idx { color: var(--faint); font-size: 12px; }

.instr { font-family: var(--mono); font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em; }
.instr a { color: var(--text); text-decoration: none; border-bottom: 1px dotted var(--faint); }
.instr a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.instr-sub { font-family: var(--sans); font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.side { display: inline-block; min-width: 50px; text-align: center; padding: 4px 9px; border-radius: 6px; font-family: var(--sans); font-size: 11.5px; font-weight: 700; letter-spacing: .04em; }
.side.BUY  { background: rgba(46,204,143,.14); color: var(--buy);  border: 1px solid rgba(46,204,143,.32); }
.side.SELL { background: rgba(255,107,129,.13); color: var(--sell); border: 1px solid rgba(255,107,129,.32); }

.size { font-weight: 650; font-size: 14px; }
.size small { color: var(--faint); font-size: 10.5px; font-weight: 400; margin-left: 3px; }

.qsize { color: var(--faint); font-size: 11px; margin-left: 5px; }
.bid { color: var(--buy); }
.ask { color: var(--sell); }
.dim { color: var(--muted); }
.faint { color: var(--faint); }

.edge.good { color: var(--buy); }
.edge.bad  { color: var(--bad); }
.edge.flat { color: var(--muted); }

.target { font-weight: 650; color: var(--accent); }
.filled { color: var(--buy); font-weight: 650; font-family: var(--sans); font-size: 12px; }

.msg { display: block; font-family: var(--sans); font-size: 11.5px; margin-top: 4px; text-align: left; }
.msg.warn { color: var(--warn); }
.msg.err  { color: var(--bad); }

/* ---------- run control ---------- */

button.run {
  font-size: 14px; font-weight: 750; letter-spacing: .06em;
  padding: 9px 26px; border-radius: 8px;
  background: var(--buy); border-color: var(--buy); color: #04170f;
}
button.run:hover:not(:disabled) { background: #48e0a5; border-color: #48e0a5; }
button.run.stopping { background: var(--bad); border-color: var(--bad); color: #1b0206; }
button.run:disabled { background: var(--panel-2); border-color: var(--line); color: var(--faint); }

/* ---------- trade history submenu ---------- */

button.disclose {
  background: none; border: none; padding: 0 6px 0 0; margin: 0;
  color: var(--faint); font-size: 11px; cursor: pointer; line-height: 1;
}
button.disclose:hover { color: var(--accent); background: none; border: none; }

tr.history-row td { padding: 0; border-bottom: 1px solid var(--line); }
.history { background: #0d121c; padding: 12px 16px 14px 34px; }
.history-head { font-size: 11.5px; color: var(--muted); margin-bottom: 9px; font-weight: 600; }
.history-empty { font-size: 12.5px; color: var(--faint); padding: 4px 0; }

.history-table { width: auto; min-width: 640px; }
.history-table th {
  background: none; border-bottom: 1px solid var(--line-soft);
  padding: 5px 14px 5px 0; font-size: 10px;
}
.history-table td {
  padding: 5px 14px 5px 0; border-bottom: none;
  font-size: 12px; text-align: right;
}
.history-table td.l, .history-table th.l { text-align: left; }
.history-table .side { min-width: 40px; padding: 2px 6px; font-size: 10.5px; }

.empty { padding: 46px 20px; text-align: center; color: var(--faint); }
.empty h3 { color: var(--muted); font-weight: 550; margin: 0 0 6px; font-size: 14px; }

.banner { margin: 0 0 16px; padding: 11px 15px; border-radius: 9px; font-size: 13px; border: 1px solid; }
.banner.err  { background: rgba(255,95,109,.09); border-color: rgba(255,95,109,.32); color: #ffb3ba; }
.banner.warn { background: rgba(255,180,84,.08); border-color: rgba(255,180,84,.3); color: var(--warn); }
.banner.hidden { display: none; }

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 352px; background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 30px 28px; }
.login-card h1 { font-size: 17px; margin: 0 0 4px; font-weight: 650; }
.login-card p.sub { color: var(--faint); font-size: 12.5px; margin: 0 0 24px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; background: #0d121c; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  font: inherit; font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.login-card button { width: 100%; margin-top: 10px; padding: 10px; }
.login-err { margin-top: 14px; font-size: 12.5px; color: var(--bad); min-height: 17px; }

@media (max-width: 720px) {
  .wrap { padding: 14px 12px 40px; }
  .topbar { gap: 12px; padding: 10px 14px; flex-wrap: wrap; }
}
