:root {
  --bg: #0d1117; --panel: #131a23; --line: #1e2835; --text: #d7dee8; --muted: #8392a6;
  --blue: #4cc2ff; --gold: #f2b84b; --green: #3ecf8e; --red: #ff6b6b; --violet: #b18cff;
  --tabh: 58px; --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { padding-bottom: calc(var(--tabh) + var(--safe-b)); }
button, select, input { font: inherit; color: var(--text); background: #1a2330; border: 1px solid #2a3647; border-radius: 10px; padding: 8px 12px; min-height: 40px; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; }
input[type=checkbox] { min-height: 0; width: 20px; height: 20px; vertical-align: middle; accent-color: var(--blue); }
a { color: var(--blue); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.spacer { flex: 1; }
.pos { color: var(--green); } .neg { color: var(--red); }

/* header */
#top { position: sticky; top: 0; z-index: 20; background: rgba(13,17,23,.96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); padding: 8px 10px 6px; padding-top: max(8px, env(safe-area-inset-top)); }
.row1, .row2 { display: flex; align-items: center; gap: 8px; }
.row2 { margin-top: 6px; }
.row2 button, .row2 select { min-height: 38px; padding: 6px 10px; }
.brand { font-size: 18px; letter-spacing: .2px; } .brand b { color: var(--blue); }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .6px; border-radius: 999px; padding: 3px 8px; min-height: 0; border: 1px solid; }
.badge.paper { color: var(--green); border-color: var(--green); }
.badge.synth { color: var(--gold); border-color: var(--gold); background: transparent; }
.badge.real { color: var(--blue); border-color: var(--blue); background: transparent; }
.clock b { font-size: 18px; font-variant-numeric: tabular-nums; }
.kill { background: #3a1418; border-color: var(--red); color: #ffb3b3; font-weight: 700; padding: 6px 10px; }
.kill.on { background: var(--red); color: #fff; }
.play { background: #11324a; border-color: var(--blue); min-width: 92px; font-weight: 600; }
.feed { font-size: 12px; color: var(--muted); white-space: nowrap; }
.feed.bad { color: var(--gold); }
#progress { height: 3px; margin: 6px -10px -6px; background: transparent; }
#progress div { height: 100%; width: 0; background: var(--blue); transition: width .2s; }
.banner { margin: 8px 10px 0; padding: 10px 12px; border-radius: 10px; background: #2a2412; border: 1px solid #5c4b1c; color: #f4dc9d; font-size: 14px; }
.banner.err { background: #2c1518; border-color: #6b2a31; color: #ffc9c9; }

/* views */
#grid { padding: 8px 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 14px; margin-bottom: 10px; }
.view { display: none; } .view.on { display: block; }
h2 { font-size: 15px; margin: 4px 0 8px; font-weight: 650; } h2 small { color: var(--muted); font-weight: 400; font-size: 12px; }
h3 { font-size: 16px; margin: 14px 0 8px; }

/* alerts + watchlist */
.alerts { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scroll-snap-type: x mandatory; }
.alert { flex: 0 0 auto; scroll-snap-align: start; text-align: left; min-width: 150px; background: #1d1a12; border: 1px solid #4d3f19; border-radius: 12px; padding: 8px 10px; }
.alert b { color: var(--gold); font-size: 16px; } .alert .r { font-size: 20px; font-weight: 700; display: block; }
.alert small { color: var(--muted); display: block; }
.alert.late { border-color: #6b2a31; background: #22151a; } .alert.late b { color: var(--red); }
.alert.done { opacity: .55; }
.alert.sel { outline: 2px solid var(--blue); }
.list { display: flex; flex-direction: column; }
.wrow { display: grid; grid-template-columns: 28px 1fr auto auto; gap: 8px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); background: none; border-radius: 0; border-left: 0; border-right: 0; border-top: 0; text-align: left; min-height: 52px; width: 100%; }
.wrow.sel { background: #172435; }
.wrow .rk { color: var(--muted); font-size: 12px; text-align: right; }
.wrow .tk { font-weight: 650; } .wrow .tk small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.wrow .ratio { font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; min-width: 56px; }
.wrow .ratio.hot { color: var(--gold); }
.wrow .px { font-variant-numeric: tabular-nums; text-align: right; color: var(--muted); font-size: 13px; min-width: 64px; }
.st { font-size: 10px; font-weight: 700; border-radius: 6px; padding: 1px 5px; margin-left: 4px; vertical-align: middle; letter-spacing: .3px; }
.st.WARMUP, .st.PENDING { background: #26303e; color: #aab6c6; } .st.STALE { background: #4a3a10; color: var(--gold); }
.st.ERROR, .st.HALT { background: #4a1a20; color: #ffb3b3; } .st.LATE { background: #3a1d24; color: #ff9b9b; } .st.R201 { background: #2c2142; color: var(--violet); } .st.ALERT { background: #3d3212; color: var(--gold); }

/* chart */
.chartwrap { position: relative; height: 54vh; min-height: 300px; max-height: 520px; touch-action: pan-y; }
#chart { width: 100%; height: 100%; display: block; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 4px; align-items: center; }
.lg { display: inline-block; width: 14px; height: 3px; margin-right: -6px; }
.lg.l-today { background: var(--blue); } .lg.l-base { background: var(--gold); } .lg.l-band { background: rgba(242,184,75,.35); height: 8px; } .lg.l-alert { background: var(--red); width: 3px; height: 12px; }

/* why */
.why .calc { font-size: 20px; margin: 8px 0 10px; font-variant-numeric: tabular-nums; }
.why .calc small { display: block; font-size: 13px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; font-size: 14px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.num { color: var(--blue); text-decoration: underline dotted; cursor: pointer; background: none; border: 0; padding: 0; min-height: 0; font: inherit; }

/* ticket */
#ticket { display: flex; flex-direction: column; gap: 10px; }
#ticket label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#ticket label input, #ticket label select { font-size: 17px; min-height: 46px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid #2a3647; border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 44px; background: #1a2330; }
.seg button.on { background: #11324a; color: #fff; font-weight: 650; }
.seg button[data-v=SELL].on, .seg button[data-v=SELL_SHORT].on { background: #3a1418; }
.quote { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.check { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: #13281f; color: var(--green); }
.check.fail { background: #2c1518; color: #ffb3b3; }
.approve { background: #11563a; border-color: var(--green); color: #eafff4; font-weight: 700; min-height: 50px; font-size: 16px; }
.result { font-size: 14px; min-height: 20px; } .result.ok { color: var(--green); } .result.bad { color: var(--red); }
.fine { font-size: 12px; color: var(--muted); margin: 0; }

/* orders, positions, audit */
.subtabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; }
.subtabs button { min-height: 36px; padding: 6px 12px; border-radius: 999px; background: transparent; white-space: nowrap; }
.subtabs button.on { background: #11324a; border-color: var(--blue); }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; background: #101720; }
.card .h { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.card .h b { font-size: 16px; } .card .meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.card .acts { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.card .acts input { width: 110px; min-height: 38px; }
.sts { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: #26303e; }
.sts.FILLED { background: #13281f; color: var(--green); } .sts.REJECTED, .sts.CANCELED, .sts.EXPIRED { background: #2c1518; color: #ffb3b3; }
.sts.HELD, .sts.PARTIAL { background: #3d3212; color: var(--gold); } .sts.NEW, .sts.PENDING_TRIGGER { background: #11324a; color: var(--blue); }
.bar { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.inline { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: 6px 0; }
.log { font-size: 13px; border-bottom: 1px solid var(--line); padding: 7px 0; word-break: break-word; }
.log .t { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 6px; } .log .ty { font-weight: 650; margin-right: 6px; font-size: 12px; }
.log .hs { color: #5b6b80; font-family: ui-monospace, monospace; font-size: 11px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; } th { color: var(--muted); font-weight: 500; }
td.r, th.r { text-align: right; }
.tablewrap { overflow-x: auto; }
ul.tight { padding-left: 20px; margin: 6px 0; } ul.tight li { margin: 4px 0; }

/* bottom tabs */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); background: rgba(13,17,23,.98); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
#tabs button { border: 0; border-radius: 0; background: transparent; min-height: var(--tabh); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 12px; color: var(--muted); position: relative; }
#tabs button .ico { font-size: 20px; line-height: 1; }
#tabs button.on { color: var(--blue); }
.dot { position: absolute; top: 8px; right: calc(50% - 22px); width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.foot { font-size: 12px; color: var(--muted); padding: 4px 14px 14px; }

/* modals: bottom sheets on phones */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; }
.modal .box { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 18px 18px 0 0; width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; padding: 16px 16px calc(18px + var(--safe-b)); }
.modal .close { position: absolute; right: 10px; top: 10px; min-height: 36px; width: 36px; padding: 0; border-radius: 50%; font-size: 20px; }
.modal h3:first-of-type { margin-top: 4px; padding-right: 40px; }
.choices { display: grid; gap: 8px; }
.choice { text-align: left; padding: 12px; border-radius: 12px; display: flex; flex-direction: column; gap: 2px; }
.choice b { color: var(--blue); } .choice span { font-size: 13px; color: var(--muted); }
#dForm { display: flex; flex-direction: column; gap: 10px; }
#dKeys { display: flex; flex-direction: column; gap: 10px; }
#dForm label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#dForm input, #dForm select { font-size: 16px; min-height: 44px; }
details summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
details label { margin-top: 8px; }
code { font-family: ui-monospace, monospace; font-size: 12px; background: #1a2330; padding: 1px 4px; border-radius: 4px; }

/* wide screens: everything at once, no bottom tabs */
@media (min-width: 1000px) {
  body { padding-bottom: 0; }
  #tabs { display: none; }
  #grid { display: grid; grid-template-columns: 340px 1fr 340px; grid-template-rows: auto auto; gap: 10px; align-items: start; }
  .view { display: block; margin: 0; }
  #v-watch { grid-row: 1 / span 2; max-height: calc(100vh - 130px); overflow: auto; position: sticky; top: 110px; }
  #v-chart { grid-column: 2; }
  #v-ticket { grid-column: 3; }
  #v-orders { grid-column: 2 / span 2; }
  .chartwrap { height: 46vh; }
  .modal { align-items: center; }
  .modal .box { border-radius: 18px; }
}
@media (max-width: 360px) { .row2 #btnEnd { display: none; } }
.brand, .clock, .row2 button, .row2 select { white-space: nowrap; }
html, body { overflow-x: hidden; max-width: 100%; }
.row1 { min-width: 0; } .row2 { min-width: 0; }
@media (max-width: 520px) {
  .brand { font-size: 17px; }
  .badge { font-size: 10px; padding: 2px 6px; }
  .clock b { font-size: 16px; } .clock small { display: none; }
  .row1 { gap: 6px; }
  .row2 { gap: 6px; }
  .row2 .feed { display: none; }
  .play { min-width: 82px; }
  .kill { padding: 6px 8px; }
}
.two > label, #ticket label > * { min-width: 0; width: 100%; }

#sCode { width: 100%; font: 13px/1.45 ui-monospace, Menlo, Consolas, monospace; color: var(--text); background: #0b1016; border: 1px solid #2a3647; border-radius: 10px; padding: 10px; min-height: 260px; resize: vertical; tab-size: 4; white-space: pre; overflow: auto; }
#sForm { display: flex; flex-direction: column; gap: 10px; }
.filebtn { display: inline-flex; align-items: center; border: 1px solid #2a3647; border-radius: 10px; padding: 8px 12px; min-height: 40px; cursor: pointer; color: var(--text); font-size: 15px; }
.sigchip { font-size: 11px; color: var(--violet); }
.kvx { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; margin-top: 8px; }
.kvx > div:nth-child(odd) { color: var(--muted); }

/* sheet header: always visible while the sheet scrolls; Back sits under the left thumb, ✕ top right */
.modal .box { padding-top: 0; }
.sheethead { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; margin: 0 -16px 8px; padding: 10px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.sheethead .back { min-height: 44px; padding: 8px 14px; font-weight: 650; color: var(--blue); background: #11324a; border-color: var(--blue); }
.sheethead .sheettitle { flex: 1; text-align: center; font-weight: 650; color: var(--muted); font-size: 14px; }
.sheethead .x { min-height: 44px; width: 44px; padding: 0; border-radius: 50%; font-size: 18px; }
.modal h3:first-of-type { padding-right: 0; }
.backbig { width: 100%; min-height: 50px; margin-top: 14px; font-weight: 650; background: transparent; }
body.sheet-open { overflow: hidden; }
