/* lab.css — DESIGN.md, the full design pass (slice 7).
   htmx vendored at ../static/htmx.min.js, version 2.0.11 (checked on npm 2026-09-25).
   Fonts: Barlow (UI text) + Barlow Semi Condensed (all numbers, tabular), from Google Fonts. */

@import url("https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600&family=Barlow+Semi+Condensed:wght@500;600&display=swap");

/* -------------------------------------------------------------------------------------- */
/* Tokens (DESIGN.md "Color tokens") */
/* -------------------------------------------------------------------------------------- */

:root {
  --paper: #EEF2F5;
  --ink: #1C2A3A;
  --steel: #8A9BB0;
  --gain: #0F7F74;
  --loss: #A63D2F;
  --rope: #C27F06;

  --radius: 6px;
  --gutter: 16px;
  --tap: 44px;

  --fs-0: 0.8125rem;
  --fs-1: 0.9375rem;
  --fs-2: 1.0625rem;
  --fs-3: 1.375rem;
  --fs-4: 1.75rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0F1B27;
    --ink: #E3EAF1;
    --steel: #5E7187;
    --gain: #35B3A5;
    --loss: #E0735F;
    --rope: #E2A63A;
  }
}

[data-theme="dark"] {
  --paper: #0F1B27;
  --ink: #E3EAF1;
  --steel: #5E7187;
  --gain: #35B3A5;
  --loss: #E0735F;
  --rope: #E2A63A;
}

[data-theme="light"] {
  --paper: #EEF2F5;
  --ink: #1C2A3A;
  --steel: #8A9BB0;
  --gain: #0F7F74;
  --loss: #A63D2F;
  --rope: #C27F06;
}

/* -------------------------------------------------------------------------------------- */
/* Base */
/* -------------------------------------------------------------------------------------- */

* { box-sizing: border-box; }

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Barlow", system-ui, sans-serif;
  font-size: var(--fs-1);
  line-height: 1.45;
  margin: 0;
  padding-bottom: calc(var(--tap) + 24px);
}

h1, h2, h3 {
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 12px;
}

h1 { font-size: var(--fs-4); }
h2 { font-size: var(--fs-3); margin-top: 24px; }
h3 { font-size: var(--fs-2); margin-top: 20px; }

p { margin: 0 0 12px; }

a { color: inherit; }

.page {
  max-width: 600px;
  margin: 0 auto;
  padding: var(--gutter);
  padding-bottom: 8px;
}

@media (min-width: 900px) {
  body { padding-left: 96px; padding-bottom: 0; }
}

/* -------------------------------------------------------------------------------------- */
/* Numbers — tabular, right-aligned, Barlow Semi Condensed everywhere a price/amount lives */
/* -------------------------------------------------------------------------------------- */

.num, input[inputmode="decimal"], .ladder-full text, .glyph text {
  font-family: "Barlow Semi Condensed", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

.num {
  font-weight: 500;
  line-height: 1.2;
  text-align: right;
  white-space: nowrap;
}

.gain { color: var(--gain); }
.loss { color: var(--loss); }
.steel { color: var(--steel); }

/* -------------------------------------------------------------------------------------- */
/* Rows — the account summary, trade list rows and the lab run list share this pattern */
/* -------------------------------------------------------------------------------------- */

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--steel);
  text-decoration: none;
  color: inherit;
  min-height: var(--tap);
}

a.row:focus-visible, .tab:focus-visible, .rung-input:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.account { margin-bottom: 8px; }

.net-headline {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0 6px;
}

.net-label {
  color: var(--steel);
  font-size: var(--fs-1);
}

.net-value {
  font-size: var(--fs-4);
  font-weight: 600;
}

.account-mini {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--steel);
}

.account-mini > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.account-mini span:first-child {
  color: var(--steel);
  font-size: var(--fs-0);
}

.account-mini .num {
  text-align: left;
  font-size: var(--fs-1);
}

.trade-list h2 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: var(--fs-2);
  margin-top: 20px;
  margin-bottom: 4px;
}

.section-count {
  color: var(--steel);
  font-size: var(--fs-1);
}

/* -------------------------------------------------------------------------------------- */
/* Trade list — rows, not cards: a 32x56 glyph, then symbol meta, then right-aligned P&L */
/* -------------------------------------------------------------------------------------- */

.trade-row {
  gap: 12px;
}

.trade-row .glyph {
  flex: 0 0 auto;
  width: 32px;
  height: 56px;
  line-height: 0;
}

.trade-row .meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.trade-row .meta strong {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-line,
.status-line {
  display: block;
  color: var(--steel);
  font-size: var(--fs-0);
}

.trade-row .net {
  flex: 0 0 auto;
  font-size: var(--fs-2);
}

.trade-row .pnl-block {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.trade-row .pnl-block .num { font-size: var(--fs-2); }

.trade-row .pnl-block .price-age,
.trade-row .pnl-block .realized-line {
  font-size: var(--fs-0);
  color: var(--steel);
}

/* -------------------------------------------------------------------------------------- */
/* Empty states + honest copy */
/* -------------------------------------------------------------------------------------- */

.empty-state {
  color: var(--steel);
  padding: 24px 0;
}

.honest-copy {
  color: var(--steel);
  font-size: var(--fs-0);
}

/* -------------------------------------------------------------------------------------- */
/* Forms — one radius (6px), inputs on --paper with a --steel hairline, 44px targets */
/* -------------------------------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 4px; }

label {
  font-size: var(--fs-0);
  color: var(--steel);
  margin-top: 10px;
}

input, select, button {
  min-height: var(--tap);
  border: 1px solid var(--steel);
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 8px 12px;
  font: inherit;
  width: 100%;
}

input[inputmode="decimal"], input[type="number"] { text-align: right; }

button {
  cursor: pointer;
  font-weight: 500;
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  width: auto;
  margin-top: 8px;
}

button[formaction], button.secondary {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--steel);
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

fieldset {
  border: 1px solid var(--steel);
  border-radius: var(--radius);
  margin: 10px 0 0;
  padding: 8px 12px 12px;
}

legend {
  font-size: var(--fs-0);
  color: var(--steel);
  padding: 0 4px;
}

fieldset label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  margin-right: 16px;
  color: var(--ink);
  min-height: var(--tap);
}

fieldset input[type="radio"] { width: auto; min-height: 0; }

.error-banner { color: var(--loss); }

/* -------------------------------------------------------------------------------------- */
/* The new-trade ladder form: TP5 at the top, the SL rope at the bottom, each rung a row */
/* -------------------------------------------------------------------------------------- */

.ladder-form .rung-row {
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

.ladder-form .rung-row label {
  margin: 0;
  font-family: "Barlow Semi Condensed", system-ui, sans-serif;
  font-weight: 600;
  color: var(--ink);
}

.ladder-form .rung-row.rail label,
.ladder-form .rung-row.rope-row label { color: var(--ink); }

.ladder-form .rung-row input { min-height: var(--tap); }

.ladder-form .rung-row.tp5 { border-color: var(--steel); }
.ladder-form .rung-row.rope-row label { color: var(--rope); }
.ladder-form .rung-row.rope-row input { border-color: var(--rope); }

/* DESIGN.md: "a rung whose price breaks the order turns brick-red" */
.ladder-form .rung-row.has-error {
  border-color: var(--loss);
  background: color-mix(in srgb, var(--loss) 10%, transparent);
}

.ladder-form .rung-row.has-error label { color: var(--loss); }

.rung-error {
  color: var(--loss);
  font-size: var(--fs-0);
  margin: 0 0 4px;
}

.optional-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--steel);
  font-size: var(--fs-0);
}

/* -------------------------------------------------------------------------------------- */
/* Sizing preview */
/* -------------------------------------------------------------------------------------- */

.sizing-preview {
  margin: 12px 0 0;
  padding: 4px 0;
}

.sizing-preview .row dt, .sizing-preview .row dd { margin: 0; }

dl.sizing-preview, dl.aggregate {
  display: grid;
  grid-template-columns: 1fr auto;
  margin: 8px 0;
}

dl.sizing-preview dt, dl.aggregate dt {
  grid-column: 1;
  color: var(--steel);
  padding: 6px 0;
  border-bottom: 1px solid var(--steel);
}

dl.sizing-preview dd, dl.aggregate dd {
  grid-column: 2;
  margin: 0;
  padding: 6px 0;
  border-bottom: 1px solid var(--steel);
}

/* -------------------------------------------------------------------------------------- */
/* Ladder SVG — glyph + full view (colors come from the tokens via svg.py's var(--x)) */
/* -------------------------------------------------------------------------------------- */

.ladder-full {
  margin: 16px 0;
  display: flex;
  justify-content: center;
}

.ladder-full svg {
  width: 100%;
  max-width: 280px;
  height: auto;
}

/* -------------------------------------------------------------------------------------- */
/* Bots */
/* -------------------------------------------------------------------------------------- */

.bot-card {
  flex-direction: column;
  align-items: stretch;
  padding: 16px 0;
  gap: 4px;
}

.bot-card h2 { margin: 0; font-size: var(--fs-2); }

.bot-card .bot-symbols {
  color: var(--steel);
  font-size: var(--fs-0);
  margin: 0 0 8px;
}

.bot-card form {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.bot-card .history-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bot-card .history-row select { width: auto; flex: 0 0 auto; }
.bot-card .history-row button { margin-top: 0; }

.event-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  font-size: var(--fs-0);
}

.event-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--steel);
  color: var(--steel);
}

/* -------------------------------------------------------------------------------------- */
/* Lab (runs) + sparkline */
/* -------------------------------------------------------------------------------------- */

.sparkline {
  margin: 12px 0;
}

.sparkline svg { width: 100%; height: auto; display: block; }

.trades-table-wrap {
  overflow-x: auto;
  margin: 12px 0;
  -webkit-overflow-scrolling: touch;
}

.trades-table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  margin: 0;
  font-size: var(--fs-0);
}

.trades-table th, .trades-table td {
  text-align: left;
  padding: 8px 4px;
  border-bottom: 1px solid var(--steel);
}

.trades-table th { color: var(--steel); font-weight: 500; }

.trades-table td.num { text-align: right; }

/* Below 640px the wide table would need horizontal scroll even to see the Result column
   (DESIGN.md quality floor: no horizontal scroll at 360px) -- render trade rows as cards
   instead, Result right-aligned and visible without scrolling. */
.mobile-only { display: none; }

@media (max-width: 640px) {
  .desktop-only { display: none; }
  .mobile-only { display: block; }
}

.trades-cards {
  list-style: none;
  margin: 12px 0;
  padding: 0;
}

.trade-card {
  padding: 10px 0;
  border-bottom: 1px solid var(--steel);
}

.trade-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.trade-card-top .num { font-size: var(--fs-1); }
.trade-card .honest-copy { margin: 2px 0 0; }

/* -------------------------------------------------------------------------------------- */
/* Logout — quiet, top-right of every authenticated page (DESIGN.md: everything but the ladder
   stays quiet: hairlines, no shadows). */
/* -------------------------------------------------------------------------------------- */

.logout-form {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 4px;
}

.logout-btn {
  width: auto;
  min-height: var(--tap);
  padding: 0 12px;
  margin: 0;
  background: transparent;
  color: var(--steel);
  border-color: transparent;
  font-size: var(--fs-0);
}

.logout-btn:hover, .logout-btn:focus-visible {
  color: var(--ink);
  border-color: var(--steel);
}

/* -------------------------------------------------------------------------------------- */
/* Login page */
/* -------------------------------------------------------------------------------------- */

.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-page h1 { margin-bottom: 24px; }

/* -------------------------------------------------------------------------------------- */
/* Bottom tab bar -> left rail at >=900px (DESIGN.md Layout) */
/* -------------------------------------------------------------------------------------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--paper);
  border-top: 1px solid var(--steel);
  z-index: 10;
}

.tab {
  flex: 1;
  text-align: center;
  padding: 12px 0;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  text-decoration: none;
  font-size: var(--fs-0);
  border-top: 2px solid transparent;
}

.tab[aria-current="page"] {
  font-weight: 600;
  color: var(--gain);
  border-top-color: var(--gain);
}

@media (min-width: 900px) {
  .tabbar {
    top: 0;
    bottom: 0;
    right: auto;
    width: 96px;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--steel);
  }

  .tab {
    padding: 16px 0;
    border-top: none;
    border-left: 2px solid transparent;
  }

  .tab[aria-current="page"] {
    border-top-color: transparent;
    border-left-color: var(--gain);
  }
}

/* -------------------------------------------------------------------------------------- */
/* Motion — only the rope answers a state change (200ms ease-out); reduced-motion disables it */
/* -------------------------------------------------------------------------------------- */

.rope {
  transition: y1 200ms ease-out, y2 200ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .rope { transition: none; }
  * { scroll-behavior: auto !important; }
}
