/* Trading Agent · Paper — responsive UI. Light by default, dark via prefers-color-scheme. */

/* Self-hosted variable fonts (SIL Open Font License, see web/fonts/). No third-party requests. */
@font-face { font-family: "Bricolage Grotesque"; src: url("/static/fonts/bricolage-grotesque.woff2") format("woff2-variations");
  font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Hanken Grotesk"; src: url("/static/fonts/hanken-grotesk.woff2") format("woff2-variations");
  font-weight: 100 900; font-display: swap; }

:root {
  --bg: #EEF1F5;
  --surface: #FFFFFF;
  --ink: #142033;
  --ink-2: #4A576B;
  --ink-3: #6E7A8E;
  --line: #DCE2EA;
  --deck: #16233B;           /* the navy hero panel */
  --deck-ink: #F2F5FA;
  --deck-ink-2: #A8B5CA;
  --deck-line: #2B3B58;
  --gain: #0B7A55;
  --loss: #B4322A;
  --gain-bg: #E3F3EC;
  --loss-bg: #F8E6E4;
  --amber: #E0A21B;
  --amber-ink: #3A2A05;
  --accent: #3D63E0;
  --ok: #0B7A55;
  --warn: #9A6400;
  --fail: #B4322A;
  --radius-lg: 18px;
  --radius-sm: 8px;
  --gutter: 16px;
  --display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --text: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0C1422;
    --surface: #131D2F;
    --ink: #E6EBF3;
    --ink-2: #A9B4C6;
    --ink-3: #8390A6;
    --line: #23304A;
    --deck: #1A2742;
    --deck-ink: #EEF2F8;
    --deck-ink-2: #9FADC4;
    --deck-line: #30406090;
    --gain: #3CCB92;
    --loss: #F2766B;
    --gain-bg: #10392C;
    --loss-bg: #44201E;
    --amber: #E8B13A;
    --accent: #7D9BFF;
    --ok: #3CCB92;
    --warn: #E8B13A;
    --fail: #F2766B;
    color-scheme: dark;
  }
  .btn.primary { background: var(--accent); border-color: var(--accent); color: #0C1422; }
  .tabs a[aria-current="page"] { background: var(--accent); color: #0C1422; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--text);
  font-feature-settings: "tnum" 1, "lnum" 1;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--display); font-weight: 650; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 50; background: var(--surface); padding: 8px 12px; }

/* ---------- paper band: the hatched strip that never lets you forget this is simulated ---------- */
.paper-band {
  background:
    repeating-linear-gradient(135deg, var(--amber) 0 10px, color-mix(in srgb, var(--amber) 78%, #fff) 10px 20px);
  color: var(--amber-ink);
  font-weight: 600;
  font-size: 0.82rem;
  padding: calc(6px + env(safe-area-inset-top)) var(--gutter) 6px;
  text-align: center;
}
.paper-band span { background: var(--amber); padding: 1px 8px; border-radius: 4px; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--display); font-weight: 750; font-size: 1.05rem; }
.brand svg { width: 30px; height: 30px; }
.brand-tile { fill: var(--deck); }
.brand-line { fill: none; stroke: var(--amber); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.tabs { display: none; gap: 4px; margin-left: 12px; }
.tabs a { text-decoration: none; padding: 7px 14px; border-radius: 999px; color: var(--ink-2); font-weight: 500; }
.tabs a:hover { color: var(--ink); background: var(--surface); }
.tabs a[aria-current="page"] { background: var(--deck); color: var(--deck-ink); }
.source { margin-left: auto; }
.source select {
  appearance: none; -webkit-appearance: none;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236E7A8E' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center / 11px;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 34px 7px 14px; font-size: 0.88rem; font-weight: 500; cursor: pointer;
}
.synthetic-note {
  margin: 12px var(--gutter) 0; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1.5px dashed var(--amber); color: var(--ink-2); font-size: 0.88rem;
}

/* ---------- layout ---------- */
main { padding: 16px var(--gutter) 28px; max-width: 1240px; margin: 0 auto; outline: none; }
.stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.col { display: grid; gap: 16px; align-content: start; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 14px; }
.muted { color: var(--ink-3); }
.small { font-size: 0.84rem; }
.section-title { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 2px 10px; }

/* ---------- the deck: session track + today's P&L ---------- */
.deck {
  background: var(--deck); color: var(--deck-ink);
  border-radius: 22px; padding: 20px 18px 18px;
  display: grid; gap: 22px;
}
.deck .muted { color: var(--deck-ink-2); }
.session-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.session-head h1 { font-size: 1.3rem; font-weight: 650; }
.session-status { display: flex; align-items: flex-start; gap: 8px; margin-top: 4px; color: var(--deck-ink-2); }
.session-status .dot { margin-top: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--deck-ink-2); flex: none; }
.dot.live { background: var(--gain); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gain) 25%, transparent); }
.dot.amber { background: var(--amber); }
.clock { font-family: var(--display); font-size: 1.6rem; font-weight: 650; line-height: 1; letter-spacing: -0.02em; }

.track { position: relative; padding-top: 30px; }
.track-bar {
  position: relative; height: 12px; border-radius: 999px; overflow: hidden;
  background: color-mix(in srgb, var(--deck-ink) 10%, transparent);
}
.seg { position: absolute; top: 0; bottom: 0; }
.seg.or { background: color-mix(in srgb, var(--accent) 45%, transparent); }
.seg.cutoff { background: color-mix(in srgb, var(--amber) 45%, transparent); }
.seg.sq { background: repeating-linear-gradient(135deg, var(--amber) 0 4px, transparent 4px 8px); }
.seg.elapsed { left: 0; background: color-mix(in srgb, var(--deck-ink) 28%, transparent); }
.now { position: absolute; top: 0; height: 48px; width: 0; }
.now::after { content: ""; position: absolute; left: -1px; top: 24px; bottom: 0; width: 2px; background: var(--deck-ink); border-radius: 2px; }
.now span {
  position: absolute; top: 0; transform: translateX(-50%);
  background: var(--deck-ink); color: var(--deck); font-weight: 600; font-size: 0.78rem;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.track-ends { display: flex; justify-content: space-between; margin-top: 8px; font-size: 0.8rem; color: var(--deck-ink-2); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 0.8rem; color: var(--deck-ink-2); }
.legend i { display: inline-block; width: 14px; height: 8px; border-radius: 3px; margin-right: 6px; vertical-align: 1px; }
.legend .k-or { background: color-mix(in srgb, var(--accent) 60%, transparent); }
.legend .k-cut { background: color-mix(in srgb, var(--amber) 55%, transparent); }
.legend .k-sq { background: repeating-linear-gradient(135deg, var(--amber) 0 3px, transparent 3px 6px); }

.pnl { display: grid; gap: 14px; }
.pnl-figure { font-family: var(--display); font-weight: 750; font-size: clamp(2.4rem, 9vw, 3.4rem); line-height: 1; letter-spacing: -0.03em; }
.pnl-figure.gain { color: var(--gain); }
.pnl-figure.loss { color: var(--loss); }
.pnl-label { font-size: 0.88rem; color: var(--deck-ink-2); margin-bottom: 6px; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; border-top: 1px solid var(--deck-line); padding-top: 14px; }
.facts div span { display: block; font-size: 0.78rem; color: var(--deck-ink-2); }
.facts div b { font-weight: 600; font-size: 0.98rem; }

/* ---------- limits ---------- */
.limits { display: grid; gap: 16px; }
.meter-label { display: flex; justify-content: space-between; gap: 10px; font-size: 0.9rem; margin-bottom: 6px; }
.meter { height: 10px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 8%, transparent); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 999px; background: var(--ink-2); transition: width .4s ease; }
.meter.hot > i { background: var(--loss); }
.pips { display: flex; gap: 5px; }
.pips i { width: 22px; height: 10px; border-radius: 3px; background: color-mix(in srgb, var(--ink) 10%, transparent); }
.pips i.on { background: var(--ink); }
.pip-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 0.9rem; }
.pip-row > span:last-child { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; }
.flag { display: flex; gap: 8px; align-items: flex-start; font-size: 0.82rem; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 12px; }
.flag svg { flex: none; width: 16px; height: 16px; margin-top: 2px; stroke: var(--warn); fill: none; stroke-width: 2; }

/* ---------- equity chart ---------- */
.chart { position: relative; width: 100%; height: 220px; touch-action: pan-y; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .base-line { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .series { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .axis { fill: var(--ink-3); font-size: 11px; font-family: var(--text); }
.chart .cross { stroke: var(--ink-3); stroke-width: 1; }
.chart .hover-dot { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--surface);
  font-size: 0.8rem; padding: 6px 9px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%);
}

/* ---------- positions with price ladder ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.pos { padding: 14px 0; display: grid; gap: 12px; }
.pos:first-child { padding-top: 2px; }
.pos-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.sym { font-family: var(--display); font-weight: 650; font-size: 1.05rem; }
.exch { font-size: 0.75rem; color: var(--ink-3); margin-left: 6px; font-weight: 500; }
.signed { font-weight: 600; }
.signed.gain { color: var(--gain); }
.signed.loss { color: var(--loss); }
.ladder { position: relative; height: 34px; }
.ladder .rail { position: absolute; left: 0; right: 0; top: 10px; height: 6px; border-radius: 999px; overflow: hidden; display: flex; }
.ladder .rail .l { background: color-mix(in srgb, var(--loss) 28%, transparent); }
.ladder .rail .g { background: color-mix(in srgb, var(--gain) 28%, transparent); flex: 1; }
.ladder .mk { position: absolute; top: 6px; width: 2px; height: 14px; background: var(--ink-2); transform: translateX(-1px); border-radius: 2px; }
.ladder .last { position: absolute; top: 5px; width: 16px; height: 16px; border-radius: 50%; transform: translateX(-8px); background: var(--surface); border: 3px solid var(--ink); }
.ladder .lbl { position: absolute; top: 22px; font-size: 0.74rem; color: var(--ink-3); white-space: nowrap; }
.ladder .lbl.s { left: 0; }
.ladder .lbl.t { right: 0; }
.ladder .lbl.e { transform: translateX(-50%); }

/* ---------- health ---------- */
.checks .chk { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: start; padding: 10px 0; }
.chk svg { width: 20px; height: 20px; }
.chk .name { font-weight: 600; }
.chk .detail { color: var(--ink-3); font-size: 0.85rem; }
.badge { font-size: 0.75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.badge.OK { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.badge.DEGRADED { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.badge.FAIL { color: var(--fail); background: color-mix(in srgb, var(--fail) 13%, transparent); }
.overall { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- scanner ---------- */
.cand { display: grid; grid-template-columns: 34px 1fr; gap: 4px 12px; padding: 14px 0; }
.cand .rank { grid-row: span 2; font-family: var(--display); font-weight: 750; font-size: 1.4rem; color: var(--ink-3); line-height: 1.2; }
.cand-top { display: flex; align-items: center; gap: 12px; }
.score { flex: 1; max-width: 220px; height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 8%, transparent); overflow: hidden; }
.score i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.score-n { font-size: 0.85rem; color: var(--ink-2); min-width: 2.6em; text-align: right; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 4px 16px; font-size: 0.86rem; }
.metrics span { color: var(--ink-3); margin-right: 4px; }
details.rej > summary { cursor: pointer; padding: 12px 0; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details.rej > summary::-webkit-details-marker { display: none; }
details.rej > summary::after { content: "Show"; font-weight: 500; color: var(--accent); }
details.rej[open] > summary::after { content: "Hide"; }
.rej-item { padding: 10px 0; }
.reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.reasons span { font-size: 0.78rem; background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink-2); padding: 3px 9px; border-radius: 999px; }

/* ---------- trades ---------- */
.trade { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; }
.trade .sub { color: var(--ink-3); font-size: 0.84rem; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stat span { display: block; font-size: 0.8rem; color: var(--ink-3); }
.stat b { font-family: var(--display); font-weight: 650; font-size: 1.35rem; }
.table-wrap { display: none; overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th { text-align: left; font-weight: 600; color: var(--ink-3); padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px 9px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; }
.status { font-weight: 600; font-size: 0.78rem; }
.status.FILLED { color: var(--gain); }
.status.REJECTED { color: var(--loss); }
.status.CANCELLED, .status.PENDING { color: var(--ink-3); }

/* ---------- system ---------- */
.kite-ok { display: flex; gap: 10px; align-items: center; }
.kite-ok svg { width: 22px; height: 22px; flex: none; }
.copy { user-select: all; overflow-wrap: anywhere; font-weight: 600; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; font-size: 0.92rem; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; text-align: right; }

/* ---------- empty / error / buttons ---------- */
.empty { padding: 22px 4px; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }
code { font-size: 0.85em; background: color-mix(in srgb, var(--ink) 7%, transparent); padding: 1px 6px; border-radius: 5px; }
.btn { white-space: nowrap; border: 1px solid var(--line); background: var(--surface); padding: 9px 16px; border-radius: 999px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--deck); color: var(--deck-ink); border-color: var(--deck); }
.btn:disabled { opacity: .6; cursor: progress; }
.error { border: 1px solid var(--loss); background: var(--loss-bg); color: var(--ink); padding: 14px 16px; border-radius: var(--radius-sm); }
.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem; z-index: 40;
}
.skeleton { height: 120px; border-radius: var(--radius-lg); background: color-mix(in srgb, var(--ink) 6%, transparent); }

dialog { border: 0; border-radius: 18px; padding: 24px; width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 18, 32, .55); }
dialog form { display: grid; gap: 12px; }
dialog p { color: var(--ink-2); font-size: 0.92rem; }
dialog input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.login-error { color: var(--loss) !important; }

/* ---------- bottom tabs (phones) ---------- */
.bottom-tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottom-tabs a { display: grid; justify-items: center; gap: 2px; padding: 6px 0; text-decoration: none; font-size: 0.72rem; font-weight: 600; color: var(--ink-3); border-radius: 12px; }
.bottom-tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottom-tabs a[aria-current="page"] { color: var(--ink); }
.bottom-tabs a[aria-current="page"] svg { stroke-width: 2.4; }

/* ---------- wider screens ---------- */
@media (min-width: 760px) {
  :root { --gutter: 28px; }
  body { padding-bottom: 0; }
  .bottom-tabs { display: none; }
  .tabs { display: flex; }
  .toast { bottom: 24px; }
  .deck { grid-template-columns: 1.35fr 1fr; padding: 26px 28px; gap: 32px; align-items: end; }
  .pnl { border-left: 1px solid var(--deck-line); padding-left: 32px; }
  .today { grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); align-items: start; }
  .today .span-all { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .system { grid-template-columns: 1fr 1fr; }
  .chart { height: 260px; }
  .panel { padding: 22px; }
  .table-wrap { display: block; margin: 0 -22px; padding: 0 22px; }
  .order-list { display: none; }
  .top { padding-inline: max(var(--gutter), calc((100% - 1240px) / 2 + var(--gutter))); }
  .synthetic-note { margin-inline: max(var(--gutter), calc((100% - 1240px) / 2 + var(--gutter))); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
