/* Trading control surface — dark, dense, mobile-first.
   No webfonts, no external assets: this must render under a strict CSP. */

:root {
  --bg:        #0a0d12;
  --surface:   #131922;
  --surface-2: #1a212c;
  --border:    #26303e;
  --border-hi: #3a4759;

  --text:      #e8edf4;
  --text-dim:  #9aa7b8;
  --text-faint:#6b7889;

  --gain:      #3ddc97;
  --gain-bg:   #0e2a20;
  --loss:      #ff6b6b;
  --loss-bg:   #331417;
  --flat:      #9aa7b8;

  --paper:     #4cc2ff;
  --paper-bg:  #0d2733;
  --live:      #ffb020;
  --live-bg:   #3a2606;

  --danger:    #ff4d4d;
  --danger-bg: #400f0f;
  --warn:      #ffb020;
  --warn-bg:   #33240a;
  --ok:        #3ddc97;

  --radius: 10px;
  --tap: 48px;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo,
          Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: 96px; /* room for the sticky kill bar */
}

a { color: var(--paper); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid #6aa9ff;
  outline-offset: 2px;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1rem; }
h3 { font-size: 0.9rem; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 12px; }

/* ---------- mode banner: PAPER vs LIVE, on every page ---------- */

.modebar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 9px 12px;
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.modebar--paper {
  background: var(--paper-bg);
  color: var(--paper);
  border-bottom-color: var(--paper);
}
.modebar--live {
  background: var(--live-bg);
  color: var(--live);
  border-bottom-color: var(--live);
  background-image: repeating-linear-gradient(
    135deg, transparent 0 14px, rgba(255, 176, 32, 0.10) 14px 28px);
}
.modebar__glyph { font-size: 1rem; line-height: 1; }
.modebar__note {
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--text-dim);
}
/* On a stale snapshot the mode is a memory, not a reading. */
.modebar--stale {
  background: var(--surface-2);
  color: var(--text-dim);
  border-bottom-color: var(--border-hi);
  background-image: repeating-linear-gradient(
    135deg, transparent 0 10px, rgba(154, 167, 184, 0.10) 10px 20px);
}

/* ---------- staleness banner: the loudest thing on the page ---------- */

.stale {
  margin: 0;
  padding: 14px 12px;
  background: var(--danger-bg);
  color: #ffdede;
  border-bottom: 3px solid var(--danger);
  border-top: 3px solid var(--danger);
}
.stale--warn {
  background: var(--warn-bg);
  color: #ffe9c2;
  border-color: var(--warn);
}
.stale__head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stale__glyph { font-size: 1.3rem; line-height: 1; }
.stale__body { margin-top: 6px; font-size: 0.88rem; line-height: 1.5; }
.stale__body strong { font-family: var(--mono); }

@media (prefers-reduced-motion: no-preference) {
  .stale:not(.stale--warn) .stale__glyph { animation: pulse 1.6s ease-in-out infinite; }
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.fresh {
  padding: 7px 12px;
  font-size: 0.78rem;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

/* ---------- header + nav ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.top__title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.top__sub { font-size: 0.75rem; color: var(--text-faint); }

.nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 6px;
  scrollbar-width: thin;
}
.nav a {
  flex: 0 0 auto;
  padding: 12px 13px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  min-height: var(--tap);
  display: flex;
  align-items: center;
}
.nav a:hover { color: var(--text); }
.nav a.is-active { color: var(--text); border-bottom-color: var(--paper); }
.nav .badge { margin-left: 6px; }

.badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
  font-family: var(--mono);
}
.badge--quiet { background: var(--border-hi); color: var(--text); }

/* ---------- cards, sections ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 12px 0;
  overflow: hidden;
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card__body { padding: 13px; }
.card__body--flush { padding: 0; }

.section-title {
  margin: 20px 0 8px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.empty {
  padding: 26px 14px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.9rem;
}

/* ---------- numbers ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
}
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.stat { background: var(--surface); padding: 12px 13px; }
.stat__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
}
.stat__value {
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 1.32rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  word-break: break-all;
}
.stat__sub { font-size: 0.76rem; color: var(--text-dim); font-family: var(--mono); }
.stat__stamp {
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  color: var(--warn);
  border-top: 1px dashed var(--warn);
  padding-top: 4px;
}

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.flat { color: var(--flat); }
/* Colour is never the only signal — a sign and an arrow glyph ride along. */
.delta__arrow { font-family: var(--sans); padding-right: 2px; }

/* ---------- stale data: the warning rides on the numbers ----------
   The banner is above the fold, but a reader who scrolls past it must not see
   three-day-old figures rendered exactly like fresh ones. */

body.is-stale .stat__value,
body.is-stale .stat__sub,
body.is-stale table.data td.num,
body.is-stale table.data td .num {
  color: var(--text-faint);
  opacity: 0.72;
}
body.is-stale .stat__value .gain,
body.is-stale .stat__value .loss,
body.is-stale .stat__sub .gain,
body.is-stale .stat__sub .loss,
body.is-stale table.data td .gain,
body.is-stale table.data td .loss {
  color: var(--text-faint);
}
/* The stamp is the warning itself and must stay at full strength. */
body.is-stale .stat__stamp { color: var(--warn); opacity: 1; }
body.is-stale table.data td.num { font-style: italic; }

/* ---------- a position we have no price for ----------
   "Flat" is reassuring, and a substituted entry price renders as flat. This
   has to be readable as "we cannot see this position" from across the room. */

.nopx {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.74rem;
  font-weight: 700;
  font-style: normal;
  letter-spacing: 0.04em;
  color: var(--warn);
  text-transform: uppercase;
}
.nopx--flag {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  color: var(--warn);
}
.nopx__sub {
  display: block;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-style: normal;
  color: var(--text-faint);
  text-decoration: line-through;
}
.pill--nopx {
  color: var(--warn);
  border-color: var(--warn);
  background: var(--warn-bg);
}
tr.row--nopx td {
  background: var(--warn-bg);
  border-bottom-color: var(--warn);
}
tr.row--nopx td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
/* The dim-on-stale rule must not quietly mute this louder warning. */
body.is-stale tr.row--nopx td.num,
body.is-stale tr.row--nopx td .nopx { opacity: 1; }

.approval__amt--unknown {
  color: var(--warn);
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- tables that become cards on a phone ---------- */

.table-scroll { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
table.data th {
  text-align: left;
  padding: 9px 11px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface-2);
}
table.data td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tr:last-child td { border-bottom: 0; }
table.data td.r, table.data th.r { text-align: right; }
.sym { font-family: var(--mono); font-weight: 700; letter-spacing: 0.02em; }

@media (max-width: 640px) {
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data thead { display: none; }
  table.data tr {
    border-bottom: 1px solid var(--border);
    padding: 6px 0;
  }
  table.data tr:last-child { border-bottom: 0; }
  table.data td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    border-bottom: 0;
    padding: 4px 13px;
    text-align: right;
  }
  table.data td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
    text-align: left;
  }
  table.data td.r { text-align: right; }
}

/* ---------- pills ---------- */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--border-hi);
  color: var(--text-dim);
  white-space: nowrap;
}
.pill--open       { color: var(--gain); border-color: var(--gain); }
.pill--weakened   { color: var(--warn); border-color: var(--warn); }
.pill--broken     { color: var(--loss); border-color: var(--loss); }
.pill--target_hit { color: var(--paper); border-color: var(--paper); }
.pill--closed     { color: var(--text-faint); }
.pill--filled     { color: var(--gain); border-color: var(--gain); }
.pill--partially_filled { color: var(--gain); border-color: var(--border-hi); }
.pill--pending_approval { color: var(--warn); border-color: var(--warn); }
.pill--approved   { color: var(--paper); border-color: var(--paper); }
.pill--submitted  { color: var(--paper); border-color: var(--border-hi); }
.pill--rejected, .pill--failed, .pill--expired, .pill--canceled { color: var(--loss); border-color: var(--loss); }
.pill--buy  { color: var(--gain); border-color: var(--gain); }
.pill--sell { color: var(--loss); border-color: var(--loss); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 12px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-hi);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn--sm { min-height: 38px; padding: 7px 12px; font-size: 0.82rem; }
.btn--block { width: 100%; }
.btn--approve {
  background: var(--gain-bg);
  border-color: var(--gain);
  color: var(--gain);
  font-size: 1.02rem;
}
.btn--reject {
  background: var(--loss-bg);
  border-color: var(--loss);
  color: var(--loss);
  font-size: 1.02rem;
}
.btn--danger { background: var(--danger-bg); border-color: var(--danger); color: #ff9a9a; }
.btn--primary { background: #17324a; border-color: var(--paper); color: var(--paper); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ---------- confirm gate ----------
   The two-step lives in markup, not script, so the safety survives with
   JavaScript off. Opening the gate is the first tap; the button inside it
   names what it does and is the second. */

details.gate > summary {
  list-style: none;
  cursor: pointer;
}
details.gate > summary::-webkit-details-marker { display: none; }
details.gate > summary::marker { content: ''; }

.gate__open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-hi);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.gate__open:hover { border-color: var(--text-faint); }
details.gate[open] > .gate__open {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
}

.gate__body {
  padding: 12px 13px 13px;
  border: 1px solid var(--border-hi);
  border-top: 0;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  background: var(--bg);
}
.gate__q {
  margin: 0 0 10px;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--text-dim);
}

/* Approve and reject are far apart and full-width so neither is hit by
   accident on a phone. */
.decide {
  display: grid;
  grid-template-columns: 1fr;
  gap: 26px;
  padding: 16px 13px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
@media (min-width: 620px) {
  .decide { grid-template-columns: 1fr 1fr; gap: 28px; }
  .decide .btn { min-height: 56px; }
}
.decide .btn { min-height: 58px; }

/* ---------- forms ---------- */

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.field .hint { font-size: 0.78rem; color: var(--text-faint); margin-top: 4px; text-transform: none; letter-spacing: 0; }
input[type="text"], input[type="password"], input[type="number"],
input[type="search"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-hi);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-family: var(--mono);
}
select { font-family: var(--sans); }
textarea { min-height: 84px; font-family: var(--sans); resize: vertical; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}
.filters .field { margin-bottom: 0; flex: 1 1 150px; }

/* ---------- alerts ---------- */

.alert {
  padding: 11px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border-hi);
  margin: 12px 0;
  font-size: 0.9rem;
}
.alert--ok    { border-color: var(--gain); background: var(--gain-bg); color: #b8f5db; }
.alert--error { border-color: var(--loss); background: var(--loss-bg); color: #ffc9c9; }
.alert--warn  { border-color: var(--warn); background: var(--warn-bg); color: #ffe4b5; }

/* ---------- approvals ---------- */

.approval { border-color: var(--border-hi); }
.approval__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  padding: 13px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.approval__sym { font-family: var(--mono); font-size: 1.24rem; font-weight: 800; }
.approval__amt { margin-left: auto; font-family: var(--mono); font-size: 1.16rem; font-weight: 700; }

.expiry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  font-family: var(--mono);
  font-size: 0.88rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.expiry--ok   { color: var(--text-dim); }
.expiry--soon { color: var(--warn); background: var(--warn-bg); }
.expiry--gone { color: var(--loss); background: var(--loss-bg); }

.kv { display: grid; grid-template-columns: 1fr; gap: 1px; background: var(--border); }
@media (min-width: 620px) { .kv { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.kv > div { background: var(--surface); padding: 10px 13px; }
.kv dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.kv dd { margin: 3px 0 0; font-family: var(--mono); font-size: 1rem; font-weight: 650; }

.prose {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text);
  overflow-wrap: anywhere;
}
.prose--dim { color: var(--text-dim); }

/* Only text the agent wrote keeps its own line breaks. Static copy must not,
   or the template's own source indentation renders as leading whitespace. */
.prose--pre { white-space: pre-wrap; }

ul.conds, ul.links { margin: 6px 0 0; padding-left: 20px; }
ul.conds li, ul.links li { margin-bottom: 5px; line-height: 1.5; overflow-wrap: anywhere; }
ul.links a { color: var(--paper); overflow-wrap: anywhere; }

.evidence-host { color: var(--text-faint); font-size: 0.78rem; font-family: var(--mono); }

details.more { border-top: 1px solid var(--border); }
details.more > summary {
  padding: 12px 13px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--text-dim);
  min-height: var(--tap);
  display: flex;
  align-items: center;
}
details.more > summary:hover { color: var(--text); }
details.more > div { padding: 0 13px 13px; }

/* ---------- review log ---------- */

.review {
  border-left: 3px solid var(--border-hi);
  padding: 2px 0 2px 12px;
  margin: 0 0 14px;
}
.review--broken { border-left-color: var(--loss); }
.review--weakened { border-left-color: var(--warn); }
.review--open { border-left-color: var(--gain); }
.review__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 0.76rem;
  color: var(--text-faint);
  margin-bottom: 5px;
  font-family: var(--mono);
}

/* ---------- kill switch bar ---------- */

.killbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom, 0px));
  background: rgba(10, 13, 18, 0.97);
  border-top: 1px solid var(--border-hi);
  backdrop-filter: blur(6px);
}
.killbar__inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.killbar__state {
  flex: 1 1 auto;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.3;
}
.killbar__state b { display: block; font-size: 0.86rem; color: var(--text); }
.killbar .btn { flex: 0 0 auto; }
.killbar--engaged {
  background: var(--danger-bg);
  border-top: 3px solid var(--danger);
}
.killbar--engaged .killbar__state { color: #ffd0d0; }
.killbar--engaged .killbar__state b { color: #fff; }

/* The confirm step is one extra tap, never a typed phrase: in an emergency
   speed matters more than ceremony. */
.killconfirm {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
}
.killconfirm .btn { flex: 1 1 auto; }
.killconfirm > details.gate { flex: 1 1 auto; }

/* The bar is pinned to the bottom edge, so its gate has to open upwards or the
   confirm button lands off-screen. */
.killbar details.gate { display: flex; flex-direction: column-reverse; }
.killbar .gate__body {
  border: 1px solid var(--border-hi);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}
.killbar details.gate[open] > .gate__open {
  border-radius: 0 0 var(--radius) var(--radius);
  border-top-color: transparent;
  border-bottom-color: var(--border-hi);
}
[hidden] { display: none !important; }

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

.login-wrap {
  max-width: 380px;
  margin: 8vh auto;
  padding: 0 16px;
}
.login-brand { text-align: center; margin-bottom: 18px; }
.login-brand .mark {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}
.login-brand p { color: var(--text-faint); font-size: 0.82rem; margin: 6px 0 0; }

/* ---------- misc ---------- */

.foot {
  padding: 18px 12px 8px;
  color: var(--text-faint);
  font-size: 0.75rem;
  text-align: center;
}
.noscript {
  padding: 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--surface); color: var(--text); padding: 12px 16px;
}
.skip-link:focus { left: 0; }

/* ---------- utilities ----------
   These exist so no element needs a style attribute: the pages then render
   correctly even under a CSP with no 'unsafe-inline' in style-src. */

.u-sm { font-size: 0.86rem; }
.u-xs { font-size: 0.8rem; }
.u-mt { margin-top: 12px; }
.u-mb { margin-bottom: 10px; }
.u-top { border-top: 1px solid var(--border); }
.u-bot { border-bottom: 1px solid var(--border); }
.u-dial { border-top: 1px solid var(--border); padding-top: 14px; }
.field--auto { flex: 0 0 auto; }
.stat__value--sm { font-size: 0.95rem; }
.approval__head--plain { background: transparent; border-bottom: 0; }
