/* Options desk. Tokens: Chalk, Ink, Indigo, Rule, Gain, Loss. Atkinson Hyperlegible Next for words;
   digits from "Desk Digits" (Source Sans 3 numerals, OFL, renamed subset) so money reads with a plain zero. */

@font-face {
  font-family: "Desk Digits";
  src: url("/static/fonts/desk-digits.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
  unicode-range: U+0030-0039;
}

@font-face {
  font-family: "Atkinson Next";
  src: url("/static/fonts/atkinson-next-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2212, U+2215;
}
@font-face {
  font-family: "Atkinson Next";
  src: url("/static/fonts/atkinson-next-latin-ext.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --chalk: #EDF0EC;
  --ink: #1A2238;
  --ink-soft: #4A5468;
  --indigo: #3346A8;
  --rule: #C7CEC8;
  --gain: #17804E;
  --loss: #C8362B;
  --loss-wash: #F3DEDB;
  --on-loss: #FFFFFF;

  --step--1: 0.8125rem;  /* 13 */
  --step-0: 0.9375rem;   /* 15 */
  --step-1: 1.125rem;    /* 18 */
  --step-2: 1.4375rem;   /* 23 */
  --step-3: 1.8125rem;   /* 29 */
  --step-4: 2.25rem;     /* 36 */

  --space: 1rem;
  --radius: 6px;
  --gutter: clamp(1rem, 4vw, 1.5rem);
  --killbar-h: 3.5rem;

  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --chalk: #141A2B;
    --ink: #E7EAF0;
    --ink-soft: #A3ABBD;
    --indigo: #8D9BF0;
    --rule: #2C3550;
    --gain: #4CC38A;
    --loss: #F0675C;
    --loss-wash: #3A2026;
    --on-loss: #141A2B;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }  /* .field, .stack etc. set display and would otherwise un-hide */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--chalk);
  color: var(--ink);
  font: 400 var(--step-0)/1.5 "Desk Digits", "Atkinson Next", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
body.has-killbar { padding-bottom: calc(var(--killbar-h) + env(safe-area-inset-bottom)); }

h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 700; }
h1 { font-size: var(--step-2); }
h2 { font-size: var(--step-1); }
p { margin: 0; }
a { color: var(--indigo); text-underline-offset: 0.18em; }
:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.soft { color: var(--ink-soft); }
.gain { color: var(--gain); }
.loss { color: var(--loss); }

#view { display: block; max-width: 72rem; margin: 0 auto; padding: var(--gutter); outline: none; }

/* ---- buttons and inputs ------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 44px; padding: 0 1.1rem;
  border: 1.5px solid var(--indigo); border-radius: var(--radius);
  background: transparent; color: var(--indigo);
  font: 700 var(--step-0)/1 inherit; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--indigo); color: var(--chalk); }
.btn.quiet { border-color: transparent; padding: 0 0.5rem; }
.btn.danger { border-color: var(--loss); color: var(--loss); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.wide { width: 100%; }

label { font-weight: 600; }
input, select {
  width: 100%; min-height: 44px; padding: 0.5rem 0.65rem;
  border: 1.5px solid var(--rule); border-radius: var(--radius);
  background: var(--chalk); color: var(--ink);
  font: inherit; font-variant-numeric: tabular-nums;
}
input:focus-visible, select:focus-visible { border-color: var(--indigo); outline-offset: 0; }
input[type="checkbox"], input[type="radio"] { width: 1.35rem; min-height: 1.35rem; height: 1.35rem; margin: 0; accent-color: var(--indigo); }

.field { display: grid; gap: 0.3rem; }
.field small { color: var(--ink-soft); font-size: var(--step--1); }
.field .with-unit { display: flex; align-items: center; gap: 0.5rem; }
.field .with-unit span { color: var(--ink-soft); white-space: nowrap; }
.field.check { grid-template-columns: auto 1fr; align-items: start; column-gap: 0.7rem; }
.field.check small { grid-column: 2; }

.segmented { display: flex; border: 1.5px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.segmented label {
  flex: 1; display: flex; align-items: center; justify-content: center; min-height: 42px;
  padding: 0 0.6rem; font-weight: 600; text-align: center; cursor: pointer;
}
.segmented label + label { border-left: 1.5px solid var(--rule); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--ink); color: var(--chalk); }
.segmented label:has(input:focus-visible) { outline: 3px solid var(--indigo); outline-offset: -3px; }

.error { color: var(--loss); font-weight: 600; }

/* ---- notice ------------------------------------------------------------ */

#notice {
  position: sticky; top: 0; z-index: 5;
  padding: 0.7rem var(--gutter); background: var(--ink); color: var(--chalk); font-weight: 600;
}
#notice.bad { background: var(--loss); color: var(--on-loss); }

/* ---- paper / live: a draft is dashed, live is solid ---------------------- */

.mode { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 4px; font-size: var(--step--1); font-weight: 700; line-height: 1.5; }
.mode.paper { border: 1.5px dashed var(--ink-soft); color: var(--ink-soft); }
.mode.live { background: var(--indigo); color: var(--chalk); border: 1.5px solid var(--indigo); }

/* ---- desk ---------------------------------------------------------------- */

.topline { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.5rem 1rem; }
.topline .who { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: baseline; }
.indices { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; margin-top: 0.4rem; font-size: var(--step--1); color: var(--ink-soft); }
.indices b { color: var(--ink); font-weight: 600; font-size: var(--step-0); }

.desk { display: grid; gap: 1.5rem; }
.desk-cols { display: grid; gap: 1.5rem; }
@media (min-width: 900px) {
  .desk-cols { grid-template-columns: minmax(20rem, 24rem) minmax(0, 40rem); justify-content: center; align-items: start; }
  .desk > header { max-width: 66rem; width: 100%; margin-inline: auto; }
}

/* Day gauge: where today's bot P&L sits between the loss limit and the same distance in profit */
.gauge { display: grid; gap: 0.45rem; padding-block: 0.25rem 0.5rem; }
.gauge-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.gauge-pnl { font-size: var(--step-3); font-weight: 800; letter-spacing: -0.01em; line-height: 1; }
.gauge-track { position: relative; height: 0.75rem; border-radius: 99px; background: linear-gradient(to right, var(--loss-wash) 50%, transparent 50%); border: 1.5px solid var(--rule); }
.gauge-track::after { content: ""; position: absolute; left: 50%; top: -0.35rem; bottom: -0.35rem; width: 1.5px; background: var(--ink-soft); }
.gauge-marker { position: absolute; top: 50%; width: 1.15rem; height: 1.15rem; border-radius: 50%; background: var(--ink); border: 3px solid var(--chalk); transform: translate(-50%, -50%); transition: left 0.6s ease; z-index: 1; }
.gauge-ends { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 1rem; font-size: var(--step--1); color: var(--ink-soft); }
.gauge .halted { color: var(--loss); font-weight: 700; }

.runs { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.run-row {
  display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 0.75rem; align-items: center;
  padding: 0.8rem 0.9rem; border-radius: var(--radius); color: inherit; text-decoration: none;
}
.run-row.paper { border: 1.5px dashed var(--ink-soft); }
.run-row.live { border: 1.5px solid var(--indigo); }
.run-row.off { opacity: 0.62; }
.run-row a.name { color: inherit; font-weight: 700; font-size: var(--step-1); text-decoration: none; }
.run-row a.name::after { content: ""; position: absolute; inset: 0; }
.run-row { position: relative; }
.run-row .meta { grid-column: 1; color: var(--ink-soft); font-size: var(--step--1); }
.run-row .right { grid-row: 1 / span 2; grid-column: 2; display: grid; justify-items: end; gap: 0.25rem; }
.run-row .pnl { font-weight: 700; font-size: var(--step-1); }
.run-row .flag { grid-column: 1 / -1; color: var(--loss); font-weight: 600; font-size: var(--step--1); }
.toggle { position: relative; z-index: 2; display: inline-flex; align-items: center; gap: 0.45rem; min-height: 44px; font-size: var(--step--1); font-weight: 600; cursor: pointer; }
.state { font-size: var(--step--1); font-weight: 600; }
.state.running { color: var(--indigo); }
.state.error { color: var(--loss); }

.day-actions { display: grid; gap: 0.6rem; }
.links { display: flex; flex-wrap: wrap; gap: 0 1.25rem; }
.links .btn.quiet { padding: 0; }

/* ---- run detail -------------------------------------------------------- */

.run-head { display: grid; gap: 0.35rem; padding-bottom: 1rem; border-bottom: 1.5px solid var(--rule); }
.run-head .title { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.run-head .pnl { font-size: var(--step-3); font-weight: 800; line-height: 1.1; }

.legs { width: 100%; border-collapse: collapse; margin-top: 0.75rem; }
.legs th { text-align: right; font-size: var(--step--1); font-weight: 600; color: var(--ink-soft); padding: 0.5rem 0 0.4rem 0.6rem; border-bottom: 1.5px solid var(--rule); }
.legs td { text-align: right; padding: 0.6rem 0 0.6rem 0.6rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.legs th:first-child, .legs td:first-child { text-align: left; padding-left: 0; }
.legs th:not(:first-child), .legs td:not(:first-child) { white-space: nowrap; }  /* numbers never break */
.legs .leg { font-weight: 700; }
.legs .leg small { display: block; font-weight: 400; color: var(--ink-soft); font-size: var(--step--1); }
.legs tr.closed td { color: var(--ink-soft); }
.leg-actions { display: flex; gap: 1.25rem; }
.linkbtn {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0; border: 0; background: none;
  color: var(--indigo); font: 600 var(--step--1)/1 inherit; text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer;
}
.linkbtn:disabled { opacity: 0.45; cursor: default; }
.legs .legpnl { display: block; font-size: var(--step--1); font-weight: 600; }
.legs td.pnlcol { display: none; }
@media (min-width: 640px) {
  .legs .legpnl { display: none; }
  .legs td.pnlcol, .legs th.pnlcol { display: table-cell; font-weight: 700; }
}
@media (max-width: 639px) { .legs th.pnlcol { display: none; } }

.rules { color: var(--ink-soft); }
details.log summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
details.log pre {
  margin: 0; padding: 0.75rem; max-height: 22rem; overflow: auto; white-space: pre-wrap;
  border: 1.5px solid var(--rule); border-radius: var(--radius); font: 400 var(--step--1)/1.5 "Desk Digits", "Atkinson Next", system-ui, sans-serif;
}
.stack { display: grid; gap: 1rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

/* ---- forms: editor, limits, login, setup ----------------------------------- */

.form { display: grid; gap: 1.75rem; max-width: 38rem; margin-inline: auto; }
.page { max-width: 44rem; margin-inline: auto; }  /* a single run: one readable column, not the full screen */
fieldset { margin: 0; padding: 0; border: 0; display: grid; gap: 1rem; min-width: 0; }
legend { padding: 0 0 0.75rem; font-size: var(--step-1); font-weight: 700; border-bottom: 1.5px solid var(--rule); width: 100%; margin-bottom: 0.25rem; }
.pair { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.live-confirm { display: grid; gap: 0.5rem; padding: 0.9rem; border: 1.5px solid var(--indigo); border-radius: var(--radius); }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }

.narrow { max-width: 26rem; margin: 8vh auto 0; display: grid; gap: 1.25rem; }
.narrow h1 { font-size: var(--step-3); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.5rem; counter-reset: step; }
.steps li { display: grid; grid-template-columns: 2rem 1fr; gap: 0.75rem; counter-increment: step; }
.steps li::before { content: counter(step); font-weight: 800; font-size: var(--step-2); line-height: 1; color: var(--ink-soft); }
.steps li.now::before { color: var(--indigo); }
.steps li.later { opacity: 0.5; }
.qr { background: #fff; padding: 0.5rem; border-radius: var(--radius); width: fit-content; }
.qr svg { display: block; width: 12rem; height: auto; }
code.secret { word-break: break-all; font-size: var(--step--1); }

/* ---- leg builder and import ------------------------------------------------- */

.leg-card { display: grid; gap: 0.9rem; padding: 0.9rem; border: 1.5px solid var(--rule); border-radius: var(--radius); }
.leg-card-head { display: flex; justify-content: space-between; align-items: center; }
.leg-card-head h3 { font-size: var(--step-0); }
.leg-card .with-unit select { width: auto; flex: 0 0 auto; }
/* stop-loss / target: type and amount share a row, so the amount keeps room for its number */
.leg-card .slt .with-unit select { flex: 1 1 auto; min-width: 0; }
.leg-card .slt .with-unit input { flex: 0 0 5.5rem; }
.leg-card label.sub { font-weight: 400; color: var(--ink-soft); font-size: var(--step--1); }
@media (max-width: 520px) { .leg-card .slt { grid-template-columns: 1fr; } }
.legs small.tgt { display: block; color: var(--ink-soft); font-size: var(--step--1); }
.import-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.import-list li { display: grid; gap: 0.15rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--rule); }
.import-list li.skipped b { color: var(--ink-soft); }
.import-list small { color: var(--ink-soft); }

/* ---- kill bar: the one bold thing --------------------------------------- */

#killbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  padding-bottom: env(safe-area-inset-bottom); background: var(--loss);
}
#kill {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 100%; height: var(--killbar-h); border: 0; overflow: hidden;
  background: var(--loss); color: var(--on-loss);
  font: 800 var(--step-1)/1 inherit; cursor: pointer;
  user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none;
}
#kill:focus-visible { outline: 3px solid var(--ink); outline-offset: -6px; }
.kill-fill { position: absolute; inset: 0; background: var(--ink); transform: scaleX(0); transform-origin: left; }
#kill.holding .kill-fill { transform: scaleX(1); transition: transform 1.5s linear; }
#kill.holding { color: var(--chalk); }
.kill-label { position: relative; }
/* Big screens: the hold button sits top right; the same layout as the phone, a little larger, never stretched edge to edge */
@media (min-width: 900px) {
  #killbar { inset: 0 0 auto auto; padding: 0.6rem var(--gutter) 0 0; background: transparent; width: auto; }
  #kill { width: 19rem; height: 3rem; border-radius: var(--radius); font-size: var(--step-0); }
  body.has-killbar { padding-bottom: 0; }
  body.has-killbar #view { padding-top: 4.25rem; }
  :root {
    --step--1: 0.875rem;
    --step-0: 1rem;
    --step-1: 1.1875rem;
    --step-2: 1.5rem;
    --step-3: 1.875rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  #kill.holding .kill-fill { transition: none; transform: scaleX(1); opacity: 0.35; }
  .gauge-marker { transition: none; }
}

/* ---- which desk, and who: the copy's label (DESK_LABEL) and view-only logins ---- */

.desk-label { display: inline-block; vertical-align: middle; padding: 0.05rem 0.5rem; border-radius: 4px; border: 1.5px solid var(--ink-soft);
  color: var(--ink-soft); font-size: var(--step--1); font-weight: 700; line-height: 1.5; text-transform: lowercase; }
.desk-label.view { text-transform: none; border-style: dashed; }
body.view-only .needs-control { display: none !important; }
body:not(.owner) .owner-only { display: none !important; }

.logins { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.logins li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem;
  padding-bottom: 0.75rem; border-bottom: 1px solid var(--rule); }
.choice { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }
.choice label { display: inline-flex; align-items: center; gap: 0.4rem; min-height: 44px; font-weight: 600; }
