/* =====================================================================
   MANUAL TRADING DESK -- its own stylesheet, deliberately.

   This page does not share a stylesheet with LiveCore, Breakout or the
   arbitrage workspace. It is a different product with a different
   audience (one operator, on a phone, mid-decision) and a different
   language direction, and inheriting their cascade would mean every
   future change to either page could silently reshape this one.

   RTL IS STRUCTURAL, NOT A FILTER. The document is `dir="rtl"`, so
   logical properties do the work -- `inline-start`/`inline-end`,
   `margin-inline`, `padding-inline` -- and nothing here hardcodes left
   or right. The only exceptions are the chart and the numbers, which are
   explicitly `dir="ltr"`: a price, a quantity and a time axis read
   left-to-right in every language, and mirroring them would make them
   wrong rather than localised.

   MOBILE FIRST. The base layout is one column sized for a phone held in
   one hand, because that is where this desk is used. The only media
   query widens it; nothing is hidden at small sizes, since on this page
   everything shown is something the operator needs to see before
   committing money.

   NO THEME TOGGLE. This is a single-purpose dark instrument panel, and
   it commits to that: every colour is painted explicitly, so it does
   not borrow anything from the host or the browser.
   ===================================================================== */

:root {
  /* Ground and panels: a blue-biased near-black, so the teal accent and
     the red both sit on a surface that is related to them rather than on
     a neutral grey that would make both look pasted on. */
  --bg: #0a0f14;
  --panel: #111922;
  --raised: #16212c;
  --line: #22303d;
  --line-soft: #1a2530;

  --text: #e8eef4;
  --muted: #8da0b3;
  --faint: #5d7084;

  /* Semantic, and separate from the accent. Protection state and P&L
     sign are the two things on this page that must read at a glance
     without being decoded, so they get the strongest colours. */
  --good: #2bbfa8;
  --good-dim: #16413c;
  --bad: #e4545f;
  --bad-dim: #45202a;
  --warn: #e3a13c;
  --warn-dim: #41311a;
  --info: #5aa9e6;
  --info-dim: #1b2f42;

  --long: #2bbfa8;
  --short: #e4545f;

  --radius: 10px;
  --radius-sm: 6px;
  --gap: 14px;

  --font: "Segoe UI", "Noto Sans Hebrew", "Arial Hebrew", Arial,
          system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", "Courier New",
          monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  /* Room for the sticky close bar, so the last section is never trapped
     underneath it. */
  padding-bottom: 92px;
}

/* ------------------------------------------------------------ chrome */

.top {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(10, 15, 20, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.top-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  max-width: 820px;
  margin-inline: auto;
}

.brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 0;
}

.brand small {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
}

.mode-chip {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--info-dim);
  background: var(--info-dim);
  color: #a8d4f5;
  white-space: nowrap;
}

.mode-chip.is-live {
  border-color: var(--bad-dim);
  background: var(--bad-dim);
  color: #ffc9ce;
}

nav.pages {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 0 10px 8px;
  max-width: 820px;
  margin-inline: auto;
  scrollbar-width: none;
}

nav.pages::-webkit-scrollbar { display: none; }

nav.pages a {
  flex: 0 0 auto;
  font-size: 12.5px;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  white-space: nowrap;
}

nav.pages a:hover { color: var(--text); background: var(--raised); }

nav.pages a[aria-current="page"] {
  color: var(--text);
  background: var(--raised);
  border-color: var(--line);
  font-weight: 600;
}

main {
  max-width: 820px;
  margin-inline: auto;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ----------------------------------------------------------- sections */

section.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--raised);
}

.card-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.card-head .hint {
  font-size: 11.5px;
  color: var(--faint);
  margin-inline-start: auto;
  text-align: end;
}

.card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* -------------------------------------------------- the headline number */

/* NET P&L is the largest thing on the page. That is a deliberate
   information-design choice: gross P&L on a leveraged swap is a
   flattering fiction, so the number the operator keeps is the number
   that gets the size. */
.pnl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 16px 12px 14px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--line);
}

.pnl .label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.pnl .value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 40px;
  font-weight: 700;
  line-height: 1.1;
  direction: ltr;
  unicode-bidi: isolate;
}

.pnl .value.up { color: var(--good); }
.pnl .value.down { color: var(--bad); }
.pnl .value.flat { color: var(--muted); }

.pnl .sub {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--faint);
  direction: ltr;
  unicode-bidi: isolate;
}

.pnl .estimate {
  font-size: 11px;
  color: var(--warn);
  text-align: center;
}

/* --------------------------------------------------- protection banner */

.protection {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--raised);
  font-size: 13px;
}

.protection .dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.protection strong { font-weight: 700; }

.protection .meta {
  margin-inline-start: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  direction: ltr;
  unicode-bidi: isolate;
  text-align: end;
}

.protection.ok { border-color: var(--good-dim); background: var(--good-dim); }
.protection.ok .dot { background: var(--good); }
.protection.ok strong { color: #8fe6d8; }

.protection.danger {
  border-color: var(--bad);
  background: var(--bad-dim);
}
.protection.danger .dot { background: var(--bad); }
.protection.danger strong { color: #ffc9ce; }

.protection.warn { border-color: var(--warn-dim); background: var(--warn-dim); }
.protection.warn .dot { background: var(--warn); }
.protection.warn strong { color: #f3cf96; }

/* An unprotected leveraged position is the worst state this software can
   produce. It pulses, because a static red line is something an operator
   can look past. */
.protection.danger { animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(228, 84, 95, 0.0); }
  50% { box-shadow: 0 0 0 4px rgba(228, 84, 95, 0.18); }
}

@media (prefers-reduced-motion: reduce) {
  .protection.danger { animation: none; }
}

/* ------------------------------------------------------------- figures */

.figures {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
}

.fig {
  background: var(--panel);
  padding: 10px 12px;
  min-width: 0;
}

.fig .k {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}

.fig .v {
  display: block;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 600;
  direction: ltr;
  unicode-bidi: isolate;
  overflow-wrap: anywhere;
}

.fig .v.sm { font-size: 13px; }
.fig .v.long { color: var(--long); }
.fig .v.short { color: var(--short); }
.fig .v.up { color: var(--good); }
.fig .v.down { color: var(--bad); }
.fig .v.muted { color: var(--muted); }

/* ------------------------------------------------- protective orders */

.exits {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.exit {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: var(--bg);
}

.exit .t {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 5px;
}

.exit .px {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 700;
  direction: ltr;
  unicode-bidi: isolate;
}

.exit.sl .px { color: var(--bad); }
.exit.tp .px { color: var(--good); }

.exit .st {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.exit .st.ok { color: var(--good); }
.exit .st.no { color: var(--bad); }
.exit .st.pend { color: var(--warn); }
.exit .st.unk { color: var(--muted); }

.exit .basis {
  font-size: 10.5px;
  color: var(--faint);
  font-family: var(--mono);
  direction: ltr;
  unicode-bidi: isolate;
}

/* --------------------------------------------------------------- chart */

.tf-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tf {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  min-height: 36px;
}

.tf[aria-pressed="true"] {
  background: var(--raised);
  border-color: var(--info);
  color: var(--text);
}

.tf:focus-visible, .btn:focus-visible, textarea:focus-visible,
nav.pages a:focus-visible, .link:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

#chart-host {
  width: 100%;
  height: 300px;
  direction: ltr;              /* a time axis is not mirrored */
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.chart-note {
  font-size: 11px;
  color: var(--faint);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 11.5px;
  color: var(--muted);
}

.legend span { display: inline-flex; align-items: center; gap: 5px; }

.legend i {
  width: 14px;
  height: 2px;
  border-radius: 2px;
  display: inline-block;
}

/* ---------------------------------------------------------- paste form */

textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  direction: ltr;              /* the instruction is JSON, always LTR */
  unicode-bidi: isolate;
}

textarea::placeholder { color: var(--faint); }

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  flex: 1 1 140px;
  min-height: 46px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--info); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  background: var(--good-dim);
  border-color: var(--good);
  color: #9ff0e2;
}

.btn.danger {
  background: var(--bad-dim);
  border-color: var(--bad);
  color: #ffd2d6;
}

.btn.ghost { background: transparent; }

/* --------------------------------------------------------- the message */

.msg {
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--raised);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.err { border-color: var(--bad); background: var(--bad-dim); color: #ffd2d6; }
.msg.ok { border-color: var(--good-dim); background: var(--good-dim); color: #9ff0e2; }
.msg.warn { border-color: var(--warn-dim); background: var(--warn-dim); color: #f3cf96; }
.msg[hidden] { display: none; }

/* A rejected instruction quotes the exact field at fault, and the field
   name is LTR even inside a Hebrew sentence. */
.msg code {
  font-family: var(--mono);
  font-size: 12px;
  direction: ltr;
  unicode-bidi: isolate;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 4px;
  border-radius: 3px;
}

/* ------------------------------------------------------------ journal */

details.journal { border-top: 1px solid var(--line-soft); }

details.journal > summary {
  cursor: pointer;
  padding: 11px 14px;
  font-size: 12.5px;
  color: var(--muted);
  list-style: none;
}

details.journal > summary::-webkit-details-marker { display: none; }
details.journal > summary::after { content: " ▾"; }
details.journal[open] > summary::after { content: " ▴"; }

.journal-list {
  margin: 0;
  padding: 0 14px 14px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.journal-list li {
  border-inline-start: 2px solid var(--line);
  padding-inline-start: 9px;
  font-size: 12px;
}

.journal-list li.e-protected { border-inline-start-color: var(--good); }
.journal-list li.e-unprotected { border-inline-start-color: var(--bad); }
.journal-list li.e-closed { border-inline-start-color: var(--info); }

.journal-list .when {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--faint);
  direction: ltr;
  unicode-bidi: isolate;
}

/* -------------------------------------------------------- sticky close */

/* The close button is the one control that must be reachable without
   scrolling, from any position on the page, at any moment. */
.close-bar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 50;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: rgba(10, 15, 20, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

.close-bar-inner {
  max-width: 820px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.close-bar .btn { flex: 1 1 auto; min-height: 52px; font-size: 15px; }

.close-bar .state {
  font-size: 11px;
  color: var(--faint);
  font-family: var(--mono);
  direction: ltr;
  unicode-bidi: isolate;
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 18px 10px;
}

.spin {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--info);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spin { animation-duration: 3s; }
}

.link {
  color: var(--info);
  font-size: 12px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
}

/* --------------------------------------------------------- wider screens */

@media (min-width: 680px) {
  html, body { font-size: 15.5px; }
  .figures { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #chart-host { height: 380px; }
  .pnl .value { font-size: 50px; }
  .btn { flex: 0 1 auto; min-width: 170px; }
}
