/* Bracket: a one-person NIFTY options terminal. Operate surface: dense, familiar controls, numbers first.
   World: IBM Plex Sans with tabular figures, a cool paper shell, buy ink-blue / sell signal-orange, and one
   signature element, the bracket rail (stop, entry, live price, target on one scale). */
@font-face { font-family: Plex; src: url(vendor/fonts/plex-400.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: Plex; src: url(vendor/fonts/plex-500.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: Plex; src: url(vendor/fonts/plex-600.woff2) format('woff2'); font-weight: 600; font-display: swap; }

:root {
  --paper: #ffffff; --shell: #f4f6fa; --field: #f1f3f7; --rule: #e3e6ec; --rule-strong: #cfd4dc;
  --ink: #14171c; --slate: #586170; --faint: #6b7483;
  --buy: #2456d6; --buy-ink: #ffffff; --sell: #c2410c; --sell-ink: #ffffff;
  --up: #0c8446; --dn: #cf2638; --warn: #9a5b00; --warn-bg: #fff5e0;
  --sl: #cf2638; --tg: #0c8446; --en: #2456d6;
  --buy-wash: #eaf0fd; --sell-wash: #fdeee7; --up-wash: #e6f4ec; --dn-wash: #fbe9eb;
  --scrim: rgba(17, 22, 31, .42);
  --shadow: 0 8px 28px rgba(17, 22, 31, .16), 0 2px 6px rgba(17, 22, 31, .08);
  --r-sm: 6px; --r: 10px; --r-lg: 16px;
  --t-11: .6875rem; --t-12: .78rem; --t-14: .875rem; --t-16: 1rem; --t-18: 1.15rem; --t-21: 1.32rem; --t-26: 1.62rem;
  --nav-h: 60px; --top-h: 52px; --act-h: 64px; --leg-h: 44px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #121418; --shell: #181b21; --field: #1e2229; --rule: #282d36; --rule-strong: #39404b;
  --ink: #e9ebef; --slate: #a3abb8; --faint: #949daa;
  --buy: #5b8cff; --buy-ink: #0b1430; --sell: #ff7a45; --sell-ink: #2a0e02;
  --up: #3ac27f; --dn: #ff6170; --warn: #e7a83e; --warn-bg: #2b2212;
  --sl: #ff6170; --tg: #3ac27f; --en: #5b8cff;
  --buy-wash: #18233e; --sell-wash: #331d14; --up-wash: #14281e; --dn-wash: #301a1d;
  --scrim: rgba(0, 0, 0, .55);
  --shadow: 0 10px 32px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { margin: 0; min-height: 100%; background: var(--paper); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink);
  font: 400 var(--t-14)/1.4 Plex, system-ui, sans-serif; overscroll-behavior-y: none; -webkit-font-smoothing: antialiased; }
::selection { background: var(--buy-wash); color: var(--ink); }
:focus-visible { outline: 2px solid var(--buy); outline-offset: 2px; border-radius: var(--r-sm); }
h1, h2, h3 { margin: 0; font-weight: 600; }
b { font-weight: 600; }
.num, input[type=number] { font-variant-numeric: tabular-nums; }
.sub { color: var(--slate); font-size: var(--t-12); }
.up { color: var(--up); } .dn { color: var(--dn); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:disabled { cursor: default; opacity: .4; }
input { font: inherit; color: var(--ink); caret-color: var(--buy); background: var(--field); border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 10px 12px; width: 100%; min-width: 0; min-height: 44px; transition: border-color .15s, background .15s; }
input:focus { outline: none; border-color: var(--buy); background: var(--paper); }
input::placeholder { color: var(--slate); }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
input:disabled { color: var(--faint); }
input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 42px; min-width: 42px; height: 24px; min-height: 0; padding: 0; border-radius: 12px; border: 0;
  background: var(--rule-strong); position: relative; cursor: pointer; transition: background .2s; }
input[type=checkbox]::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .2s cubic-bezier(.2,.8,.2,1); }
input[type=checkbox]:checked { background: var(--buy); }
input[type=checkbox]:checked::after { transform: translateX(18px); }

/* ---------- shell ---------- */
#banner { position: sticky; top: 0; z-index: 40; background: var(--warn-bg); color: var(--warn); padding: 10px 16px; font-size: var(--t-14); font-weight: 500; border-bottom: 1px solid var(--rule); }
#banner a { color: inherit; font-weight: 600; }
#top { height: var(--top-h); display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 16px;
  position: sticky; top: 0; background: var(--paper); z-index: 20; border-bottom: 1px solid var(--rule); }
#top-title { font-size: var(--t-18); letter-spacing: -.01em; }
#top-right { display: flex; align-items: center; gap: 2px; }
#feed { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-12); color: var(--slate); padding: 4px 8px; border-radius: 12px; background: var(--shell); }
#feed-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
#feed[data-s=live] #feed-dot { background: var(--up); box-shadow: 0 0 0 3px var(--up-wash); }
#feed[data-s=live] { color: var(--up); }
.iconbtn { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 50%; color: var(--slate); }
.iconbtn:active { background: var(--field); }
.iconbtn.sm { width: 36px; height: 36px; } .iconbtn.sm svg { width: 20px; height: 20px; }

main { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.view { display: none; } .view.on { display: block; }
#tabs { position: fixed; inset: auto 0 0 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--shell); border-top: 1px solid var(--rule); z-index: 30; }
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: var(--t-11); color: var(--slate); font-weight: 500; }
#tabs button svg { width: 22px; height: 22px; }
#tabs button.on { color: var(--buy); }
#tabs button.on svg { stroke-width: 2.1; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 60px; border-bottom: 1px solid var(--rule); background: var(--paper); }
.row:active { background: var(--shell); }
.row .l { flex: 1; min-width: 0; }
.row .nm { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r { text-align: right; white-space: nowrap; }
.row .px { font-weight: 600; font-variant-numeric: tabular-nums; }
.row .sub { margin-top: 2px; }
.link { font: inherit; color: inherit; text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; padding: 4px 0; margin: -4px 0; text-align: left; }
.link:active { color: var(--buy); text-decoration-color: var(--buy); }
.kind { font-size: var(--t-11); color: var(--slate); background: var(--field); border-radius: 4px; padding: 1px 5px; margin-left: 6px; font-weight: 500; vertical-align: 1px; }
.status { font-size: var(--t-11); font-weight: 600; border-radius: 4px; padding: 2px 6px; white-space: nowrap; }
.status.ok { color: var(--up); background: var(--up-wash); } .status.bad { color: var(--dn); background: var(--dn-wash); }
.status.pend { color: var(--warn); background: var(--warn-bg); } .status.dry { color: var(--buy); background: var(--buy-wash); }
.add { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: var(--buy); border: 1px solid var(--rule-strong); }
.add svg { width: 18px; height: 18px; }
.add.on { background: var(--buy); color: var(--buy-ink); border-color: var(--buy); }
.row-actions { display: flex; gap: 8px; padding: 0 16px 12px; border-bottom: 1px solid var(--rule); background: var(--shell); padding-top: 10px; }
.row-actions .btn { flex: 1; min-height: 40px; }
.row-actions .iconbtn { width: 40px; height: 40px; border-radius: var(--r-sm); border: 1px solid var(--rule-strong); }
.row.open { background: var(--shell); border-bottom-color: transparent; }
.empty { padding: 40px 28px; color: var(--slate); text-align: center; line-height: 1.55; }
.empty b { color: var(--ink); }
.searchbar { padding: 10px 12px; position: sticky; top: var(--top-h); background: var(--paper); z-index: 10; border-bottom: 1px solid var(--rule); }
.search { display: flex; align-items: center; gap: 8px; background: var(--field); border-radius: var(--r); padding: 0 12px; color: var(--faint); }
.search input { background: transparent; border: 0; padding-left: 0; }
.search input:focus { background: transparent; }
.search:focus-within { box-shadow: 0 0 0 2px var(--buy); }
.group-h { font-size: var(--t-12); font-weight: 600; color: var(--slate); padding: 14px 16px 6px; background: var(--paper); }
.list.flush .row { padding-left: 0; padding-right: 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: var(--r-sm); font-weight: 600; letter-spacing: .005em; transition: filter .15s, transform .1s; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.buy { background: var(--buy); color: var(--buy-ink); } .btn.sell { background: var(--sell); color: var(--sell-ink); }
.btn.primary { background: var(--buy); color: var(--buy-ink); }
.btn.ghost { border: 1px solid var(--rule-strong); color: var(--ink); background: var(--paper); }
.btn.danger { border: 1px solid var(--dn); color: var(--dn); background: var(--paper); }
.btn.block { width: 100%; min-height: 52px; font-size: var(--t-16); }
.btn small { font-weight: 500; opacity: .85; font-size: var(--t-12); }
.seg { display: inline-flex; background: var(--field); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button { padding: 6px 10px; min-height: 32px; border-radius: 4px; font-size: var(--t-12); font-weight: 500; color: var(--slate); }
.seg button.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg.full { display: flex; } .seg.full button { flex: 1; min-height: 38px; font-size: var(--t-14); }
.tabs-inline { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--rule); overflow-x: auto; scrollbar-width: none; }
.tabs-inline button { padding: 10px 12px; font-weight: 500; color: var(--slate); border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs-inline button.on { color: var(--buy); border-bottom-color: var(--buy); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button, .quick button { border: 1px solid var(--rule-strong); border-radius: 16px; padding: 6px 12px; min-height: 32px; font-size: var(--t-12); font-weight: 500; color: var(--slate); }
.chips button.on { border-color: var(--buy); color: var(--buy); background: var(--buy-wash); }
.chips button b, .quick button b { color: var(--ink); font-weight: 600; }

/* ---------- chart ---------- */
#ch-head { display: flex; justify-content: space-between; align-items: flex-end; padding: 12px 16px 4px; gap: 12px; }
#ch-sym { font-weight: 600; font-size: var(--t-16); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-id { min-width: 0; }
.ch-quote { text-align: right; white-space: nowrap; }
#ch-ltp { font-size: var(--t-21); font-weight: 600; letter-spacing: -.01em; line-height: 1.1; }
#ch-chg { font-size: var(--t-12); font-weight: 500; }
#ch-tools { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; gap: 8px; }
#ch-wrap { position: relative; }
#chart { height: calc(100svh - var(--top-h) - var(--nav-h) - var(--act-h) - 112px - var(--leg-h) - env(safe-area-inset-bottom)); min-height: 300px; touch-action: none; }
#v-chart.has-bk #chart { height: calc(100svh - var(--top-h) - var(--nav-h) - var(--act-h) - 112px - var(--leg-h) - 238px - env(safe-area-inset-bottom)); min-height: 220px; }
/* the candle readout: its own strip above the chart, so it never covers candles or the price axis */
#ch-legend { height: var(--leg-h); box-sizing: border-box; padding: 4px 12px 5px; font-size: var(--t-12); color: var(--slate); font-variant-numeric: tabular-nums;
  display: flex; flex-direction: column; justify-content: center; gap: 2px; border-top: 1px solid var(--rule); white-space: nowrap; overflow: hidden; }
#ch-legend[data-pinned="1"] { background: var(--field); }
#ch-legend:empty { visibility: hidden; }
.lg-meta { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.lg-meta .when { color: var(--ink); font-weight: 600; }
.lg-note { margin-left: auto; color: var(--faint); overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.lg-ohlc { display: flex; justify-content: space-between; gap: 8px; }
.lg-ohlc b { color: var(--ink); font-weight: 500; }
#ch-zoom { position: absolute; left: 46px; bottom: 34px; z-index: 3; display: flex; background: var(--paper); border-radius: var(--r-sm);
  box-shadow: 0 1px 2px rgba(17,22,31,.12), 0 0 0 1px var(--rule); overflow: hidden; }
#ch-zoom button { min-width: 38px; height: 32px; padding: 0 10px; font-size: var(--t-16); font-weight: 600; color: var(--ink); }
#ch-zoom button + button { border-left: 1px solid var(--rule); }
#ch-zoom button[data-z=reset] { font-size: var(--t-12); color: var(--slate); }
#ch-zoom button:active { background: var(--field); }
.actionbar { display: flex; gap: 10px; padding: 10px 12px; position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--paper);
  border-top: 1px solid var(--rule); z-index: 5; }
.actionbar .btn { flex: 1; min-height: 46px; font-size: var(--t-16); }
#ch-setups .row { min-height: 0; }

/* ---------- the bracket (signature: the rail) ---------- */
.bracket { padding: 12px 16px 14px; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); background: var(--shell); }
.bk-top { display: flex; align-items: center; gap: 8px; }
.bk-state { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-12); font-weight: 600; }
.bk-state::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.bk-state[data-s=live] { color: var(--up); } .bk-state[data-s=live]::before { background: var(--up); box-shadow: 0 0 0 3px var(--up-wash); }
.bk-state[data-s=arm] { color: var(--warn); } .bk-state[data-s=arm]::before { background: var(--warn); }
.bk-state[data-s=err] { color: var(--dn); } .bk-state[data-s=err]::before { background: var(--dn); }
.bk-state[data-s=done] { color: var(--slate); }
.bk-pnl { margin-left: auto; font-weight: 600; font-size: var(--t-16); font-variant-numeric: tabular-nums; }
.bk-sym { font-weight: 600; margin: 6px 0 2px; display: flex; justify-content: space-between; gap: 8px; }
.bk-sym .sub { font-weight: 400; }
.rail { position: relative; height: 72px; margin: 10px 4px 4px; }
.rail-track { position: absolute; left: 0; right: 0; top: 22px; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--dn-wash), var(--field) 45%, var(--field) 55%, var(--up-wash)); }
.rail-fill { position: absolute; top: 22px; height: 6px; border-radius: 3px; transition: left .25s ease-out, width .25s ease-out; }
.rail-fill.gain { background: var(--up); } .rail-fill.loss { background: var(--dn); }
.rail-tick { position: absolute; top: 16px; width: 2px; height: 18px; margin-left: -1px; border-radius: 1px; }
.rail-tick.sl { background: var(--sl); } .rail-tick.tg { background: var(--tg); } .rail-tick.en { background: var(--en); }
.rail-lbl { position: absolute; top: 36px; transform: translateX(-50%); font-size: var(--t-11); white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--slate); }
.rail-lbl b { display: block; font-weight: 600; color: var(--ink); font-size: var(--t-12); }
.rail-lbl.edge-l { transform: none; text-align: left; } .rail-lbl.edge-r { transform: translateX(-100%); text-align: right; }
.rail-lbl.sl b { color: var(--sl); } .rail-lbl.tg b { color: var(--tg); } .rail-lbl.en b { color: var(--en); }
.rail-now { position: absolute; top: 0; transform: translateX(-50%); transition: left .25s ease-out; display: flex; flex-direction: column; align-items: center; }
.rail-now span { font-size: var(--t-11); font-weight: 600; background: var(--ink); color: var(--paper); border-radius: 4px; padding: 1px 5px; font-variant-numeric: tabular-nums; }
.rail-now i { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid var(--ink); }
.rail-h { position: absolute; top: 4px; width: 44px; height: 46px; margin-left: -22px; z-index: 2; touch-action: none; cursor: ew-resize; display: grid; place-items: center; }
.rail-h i { width: 14px; height: 14px; border-radius: 50%; background: var(--paper); border: 2px solid currentColor; box-shadow: 0 1px 3px rgba(17,22,31,.25); margin-top: -12px; transition: transform .12s; }
.rail-h.sl { color: var(--sl); } .rail-h.tg { color: var(--tg); } .rail-h.en { color: var(--en); }
.rail-h.on i { transform: scale(1.35); background: currentColor; }
.bk-legs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.bk-legs.one { grid-template-columns: 1fr; }
.bk-leg { display: flex; align-items: center; justify-content: space-between; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 4px 4px 4px 10px; }
.bk-leg .k { font-size: var(--t-11); color: var(--slate); } .bk-leg .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.bk-leg.sl .v { color: var(--sl); } .bk-leg.tg .v { color: var(--tg); } .bk-leg.en .v { color: var(--en); }
.bk-leg .ed { display: flex; }
.bk-leg .ed button { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 4px; color: var(--slate); }
.bk-leg .ed button:active { background: var(--field); }
.bk-leg .ed svg { width: 18px; height: 18px; }
.bk-last { font-size: var(--t-12); color: var(--slate); margin-top: 8px; }
.bk-acts { display: flex; gap: 8px; margin-top: 10px; }
.bk-acts .btn { flex: 1; min-height: 40px; font-size: var(--t-14); white-space: nowrap; }

/* ---------- sheets ---------- */
.sheet { position: fixed; inset: 0; background: var(--scrim); z-index: 50; display: flex; align-items: flex-end; animation: fade .18s ease-out; }
.sheet-body { width: 100%; max-height: 92svh; overflow-y: auto; background: var(--paper); border-radius: var(--r-lg) var(--r-lg) 0 0; padding: 4px 16px 0;
  box-shadow: var(--shadow); animation: rise .22s cubic-bezier(.2,.8,.2,1); overscroll-behavior: contain; }
.sheet-body.small { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-body, .rail-now, .rail-fill { animation: none; transition: none; } }
.grab { width: 36px; height: 4px; border-radius: 2px; background: var(--rule-strong); margin: 6px auto 8px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
.sheet-head h2 { font-size: var(--t-18); letter-spacing: -.01em; }
.sheet-head .iconbtn { margin: -6px -10px 0 0; }
.sheet-body h3 { font-size: var(--t-14); margin: 22px 0 8px; }
.side { display: flex; background: var(--field); border-radius: var(--r-sm); padding: 3px; margin-bottom: 14px; }
.side button { flex: 1; min-height: 40px; border-radius: 4px; font-weight: 600; color: var(--slate); }
.side button[data-v=BUY].on { background: var(--buy); color: var(--buy-ink); }
.side button[data-v=SELL].on { background: var(--sell); color: var(--sell-ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; min-width: 0; }
.lbl { font-size: var(--t-12); color: var(--slate); font-weight: 500; display: flex; justify-content: space-between; gap: 6px; white-space: nowrap; }
.lbl i { font-style: normal; color: var(--faint); font-weight: 400; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.stepper { display: flex; align-items: stretch; background: var(--field); border-radius: var(--r-sm); border: 1px solid transparent; }
.stepper:focus-within { border-color: var(--buy); background: var(--paper); }
.stepper input { text-align: center; background: transparent; border: 0; padding: 10px 2px; font-weight: 600; font-size: var(--t-16); }
.stepper input:focus { background: transparent; }
.stepper button { width: 40px; display: grid; place-items: center; color: var(--slate); }
.stepper button svg { width: 18px; height: 18px; }
.stepper button:active { color: var(--ink); background: var(--rule); }
.field.sl .stepper input { color: var(--sl); } .field.tg .stepper input { color: var(--tg); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 10px; }
.quick:empty { display: none; }
.risk { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 12px; border-radius: var(--r-sm); background: var(--shell); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.risk .rr { font-weight: 600; }
.risk[data-bad="1"] .rr { color: var(--dn); }
.risk[data-good="1"] .rr { color: var(--up); }
.note { font-size: var(--t-12); color: var(--slate); padding: 8px 12px; border-radius: var(--r-sm); background: var(--shell); margin-bottom: 8px; line-height: 1.45; }
.note.warn, .note[data-warn="1"] { color: var(--warn); background: var(--warn-bg); }
.trail { border: 1px solid var(--rule); border-radius: var(--r); margin: 8px 0 4px; }
.trail summary { list-style: none; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; cursor: pointer; font-weight: 500; }
.trail summary::-webkit-details-marker { display: none; }
.trail[open] summary { border-bottom: 1px solid var(--rule); margin-bottom: 12px; }
.trail > *:not(summary) { margin-left: 14px; margin-right: 14px; }
.trail .chips { margin-bottom: 12px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; cursor: pointer; }
.toggle span { display: flex; flex-direction: column; gap: 2px; }
.toggle small { color: var(--slate); font-size: var(--t-12); }
.sheet-body > .toggle { border-bottom: 1px solid var(--rule); }
.sheet-foot { position: sticky; bottom: 0; background: var(--paper); padding: 8px 0 calc(12px + env(safe-area-inset-bottom)); margin-top: 8px; border-top: 1px solid var(--rule); }
.toggle.compact { padding: 4px 0 10px; }
#o-dry:checked { background: var(--warn); }
.hint { font-size: var(--t-12); color: var(--dn); padding: 0 0 8px; line-height: 1.45; }
.hint.lock { color: var(--warn); }

/* ---------- modal + toast ---------- */
.modal { position: fixed; inset: 0; background: var(--scrim); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 24px; animation: fade .15s ease-out; }
.modal-box { background: var(--paper); border-radius: var(--r-lg); padding: 20px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
#m-text { white-space: pre-wrap; margin-bottom: 16px; line-height: 1.5; }
#m-input { margin-bottom: 16px; font-size: var(--t-18); font-weight: 600; }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; }
#toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--act-h) + env(safe-area-inset-bottom)); z-index: 70;
  background: var(--ink); color: var(--paper); padding: 12px 14px; border-radius: var(--r); box-shadow: var(--shadow); white-space: pre-wrap; animation: rise .2s ease-out; line-height: 1.45; }

/* ---------- positions ---------- */
.pnl-head { padding: 20px 16px 16px; border-bottom: 1px solid var(--rule); background: var(--shell); }
.pnl-head .k { color: var(--slate); font-size: var(--t-12); font-weight: 500; }
.pnl-head .v { font-size: var(--t-26); font-weight: 600; letter-spacing: -.015em; margin-top: 2px; }
.pnl-head .s { font-size: var(--t-12); color: var(--slate); margin-top: 4px; line-height: 1.6; }
.pnl-parts { color: var(--faint); }

/* ---------- levels ---------- */
#lv { padding: 0 16px 24px; }
.lv-sec { padding: 14px 0; border-bottom: 1px solid var(--rule); }
.lv-sec:last-child { border-bottom: 0; }
.lv-h { font-size: var(--t-14); font-weight: 600; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.lv-h .sub { font-weight: 400; }
.lv-verdict { font-weight: 600; font-size: var(--t-18); padding: 12px 14px; border-radius: var(--r); background: var(--shell); margin: 2px 0 10px; letter-spacing: -.01em; }
.lv-verdict small { display: block; font-size: var(--t-12); font-weight: 500; color: var(--slate); margin-top: 2px; letter-spacing: 0; }
.lv-verdict[data-v=buyers] { background: var(--up-wash); color: var(--up); }
.lv-verdict[data-v=sellers] { background: var(--dn-wash); color: var(--dn); }
.lv-why { font-size: var(--t-14); line-height: 1.6; }
.lv-why div { display: flex; gap: 8px; }
.lv-why i { font-style: normal; width: 14px; flex: none; text-align: center; }
.lv-why .ctx { color: var(--slate); font-size: var(--t-12); margin-top: 6px; display: block; }
.lv-row { display: grid; grid-template-columns: 64px 1fr 72px; padding: 8px 0; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
.lv-row:last-child { border-bottom: 0; }
.lv-row span:nth-child(2) { font-weight: 500; }
.lv-row span:last-child { text-align: right; }
.lv-row[data-c=ltp] { color: var(--buy); font-weight: 600; }
.lv-mk { padding: 9px 0; border-bottom: 1px solid var(--rule); }
.lv-mk:last-child { border-bottom: 0; }
.lv-mk .v { display: flex; justify-content: space-between; gap: 8px; font-weight: 500; }
.lv-mk .v span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.lv-mk[data-tone=up] .v span:last-child { color: var(--up); } .lv-mk[data-tone=down] .v span:last-child { color: var(--dn); }
.lv-mk[data-tone=warn] .v span:last-child { color: var(--warn); }
.lv-m { font-size: var(--t-12); color: var(--slate); line-height: 1.5; margin-top: 2px; }
.lv-m[data-warn="1"] { color: var(--warn); }
.lv-fresh { color: #fff; background: var(--dn); padding: 10px 12px; border-radius: var(--r-sm); font-weight: 600; margin-bottom: 8px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .62; } }
@media (prefers-reduced-motion: reduce) { .lv-fresh { animation: none; } }
.lv-hv { display: grid; grid-template-columns: 1fr 48px 64px 48px; font-size: var(--t-14); padding: 7px 0; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
.lv-hv span:not(:first-child) { text-align: right; }
.lv-hv span:first-child { font-weight: 500; }
.lv-hvsum { font-weight: 600; margin-bottom: 4px; }
.lv-sectors { margin-top: 10px; border-top: 1px solid var(--rule); }
.lv-sector { display: grid; grid-template-columns: 1fr 40px 92px 56px; align-items: center; width: 100%; text-align: left; padding: 10px 0; min-height: 44px; border-bottom: 1px solid var(--rule); gap: 6px; }
.lv-sector .nm { font-weight: 500; }
.lv-sector span:not(.nm) { text-align: right; }
.lv-sector[aria-expanded=true] { border-bottom-color: transparent; }
.lv-sector-rows { padding: 0 0 8px 12px; border-bottom: 1px solid var(--rule); background: var(--paper); }
.lv-sector-rows .lv-hv { font-size: var(--t-12); padding: 5px 0; }
.lv-hvsum[data-tone=up] { color: var(--up); } .lv-hvsum[data-tone=down] { color: var(--dn); }
.lv-idea-h { font-weight: 600; font-size: var(--t-16); } .lv-idea-h[data-state=idea] { color: var(--up); }
.lv-check { font-size: var(--t-14); padding: 3px 0; display: flex; gap: 8px; }
.lv-check svg { width: 16px; height: 16px; margin-top: 2px; }
.lv-check[data-ok="1"] { color: var(--up); } .lv-check[data-ok="0"] { color: var(--slate); }
.lv-plan { background: var(--shell); border-radius: var(--r-sm); padding: 10px 12px; margin: 10px 0 8px; font-variant-numeric: tabular-nums; line-height: 1.5; }
.lv-foot { font-size: var(--t-12); color: var(--slate); padding-top: 14px; }

/* ---------- wide screens: keep the phone column, centred ---------- */
@media (min-width: 620px) {
  body { max-width: 460px; margin: 0 auto; border-left: 1px solid var(--rule); border-right: 1px solid var(--rule); min-height: 100vh; }
  #tabs { left: 50%; right: auto; width: 460px; transform: translateX(-50%); }
  .sheet-body { max-width: 460px; margin: 0 auto; }
  #toast { left: 50%; right: auto; width: 436px; transform: translateX(-50%); }
  html { background: var(--shell); }
}

/* ---------- armed entries ---------- */
#or-armed { border-bottom: 1px solid var(--rule); }
.armed { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--rule); background: var(--warn-bg); }
.armed:last-child { border-bottom: 0; }
.armed .l { flex: 1; min-width: 0; }
.armed .nm { font-weight: 600; }
.armed .nm i { font-style: normal; color: var(--warn); margin-right: 6px; }
.armed.done { background: var(--paper); }
.armed.done .nm { font-weight: 500; color: var(--slate); }
#o-armbox { padding: 0 0 6px; }

/* ---------- 15-minute setup ---------- */
.su-card { border: 1px solid var(--rule-strong); border-radius: var(--r); padding: 12px; margin-bottom: 8px; }
.su-card.go { border-color: var(--up); background: var(--up-wash); }
.su-h { font-weight: 600; font-size: var(--t-16); margin-bottom: 2px; }
.su-card.go .su-h { color: var(--up); }
.su-checks { margin: 8px 0; }
.su-watch { font-size: var(--t-14); padding: 8px 10px; border-radius: var(--r-sm); background: var(--warn-bg); color: var(--warn); margin-bottom: 6px; }
.su-row { grid-template-columns: 1fr auto 80px; gap: 8px; }

/* ---------- small phones ---------- */
.opts { margin-top: 4px; }
.opts .toggle { border-top: 1px solid var(--rule); }
.sheet-foot .hint { padding-top: 2px; }
.bk-sym > span:first-child { min-width: 0; }
.bk-acts { flex-wrap: wrap; }
@media (max-width: 480px) {
  /* the bracket panel: stop and target stacked, Exit now on its own row */
  .bk-legs { grid-template-columns: 1fr; gap: 6px; }
  .bk-sym { flex-direction: column; gap: 0; }
  .bk-acts .btn { flex: 1 1 auto; min-width: 0; padding: 0 12px; }
  .bk-acts .btn.sell { flex-basis: 100%; }
}
@media (max-width: 360px) {
  :root { --t-14: .84rem; }
  .row, .bracket, .pnl-head, #lv, .searchbar, #ch-head { padding-left: 12px; padding-right: 12px; }
  .row { gap: 8px; }
  .sheet-body { padding-left: 12px; padding-right: 12px; }
  .grid2 { gap: 8px; }
  .stepper button { width: 32px; }
  .stepper input { font-size: var(--t-14); }
  .seg button { padding: 6px 7px; }
  #ch-iv button { padding: 6px 6px; }
  .tabs-inline button { padding: 10px 8px; }
  .quick button, .chips button { padding: 5px 9px; }
  .lv-sector { grid-template-columns: 1fr 34px 84px 50px; }
  .lv-hv { grid-template-columns: 1fr 42px 60px 44px; font-size: var(--t-12); }
}
/* short screens (small phones, landscape): the chart gives up height first, never the controls */
@media (max-height: 640px) {
  #chart { min-height: 220px; }
  .sheet-body { max-height: 96svh; }
}

/* ---------- the levels table: label, price and distance in aligned columns ---------- */
.lvt { font-variant-numeric: tabular-nums; }
.lvt-r { display: grid; grid-template-columns: minmax(0, 1fr) 96px 84px; align-items: baseline; column-gap: 8px; padding: 8px 6px; border-bottom: 1px solid var(--rule); }
.lvt-r:last-child { border-bottom: 0; }
.lvt-r span:nth-child(1) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvt-r span:nth-child(2) { text-align: right; font-weight: 500; }
.lvt-r span:nth-child(3) { text-align: right; }
.lvt-h { font-size: var(--t-12); color: var(--slate); font-weight: 500; padding-top: 0; padding-bottom: 6px; }
.lvt-h span:nth-child(2) { font-weight: 500; }
.lvt-r[data-c=ltp] { background: var(--buy-wash); color: var(--buy); font-weight: 600; border-radius: var(--r-sm); border-bottom-color: transparent; }
.lvt-r[data-c=ltp] span:nth-child(2) { font-weight: 600; }
@media (max-width: 360px) { .lvt-r { grid-template-columns: minmax(0, 1fr) 84px 68px; padding-left: 4px; padding-right: 4px; } }

/* ---------- in-trade bar, real vs dry, costs ---------- */
.actionbar .btn.intrade { flex: 1; justify-content: space-between; padding: 0 16px; }
.actionbar .btn.intrade b { font-variant-numeric: tabular-nums; }
.actionbar .btn.waiting { background: var(--shell); color: var(--ink); border: 1px solid var(--rule-strong); }
.mode { display: flex; background: var(--field); border-radius: var(--r-sm); padding: 3px; margin-bottom: 8px; }
.mode button { flex: 1; min-height: 38px; border-radius: 4px; font-weight: 600; color: var(--slate); }
.mode button[data-v=real].on { background: var(--sell); color: var(--sell-ink); }
.mode button[data-v=dry].on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.mode-note { font-size: var(--t-12); color: var(--slate); margin: -2px 0 8px; }
.mode-note b { color: var(--sell); }
.bracket.dry .rail-track { background: repeating-linear-gradient(90deg, var(--field) 0 6px, transparent 6px 10px); }
.bracket.dry .rail-fill { opacity: .55; }
.bracket.dry .bk-state[data-s=live] { color: var(--slate); }
.bracket.dry .bk-state[data-s=live]::before { background: var(--slate); box-shadow: none; }
.risk .net { display: block; font-size: var(--t-12); color: var(--slate); margin-top: 2px; }
.cost-warn { font-size: var(--t-12); color: var(--warn); background: var(--warn-bg); border-radius: var(--r-sm); padding: 8px 12px; margin-bottom: 8px; }
.today { font-size: var(--t-12); color: var(--slate); margin-top: 2px; }
#m-yes.danger-fill { background: var(--dn); color: #fff; }
.btn.block.dryrun { background: var(--shell); color: var(--ink); border: 1px dashed var(--rule-strong); }
#ch-bracket .bk-acts .btn.sell { display: none; }
@media (min-width: 620px) { .bk-legs { grid-template-columns: 1fr 1fr; } .bk-acts .btn { flex: 1; } .bk-acts .btn.sell { flex-basis: auto; } }
.bk-hint { font-size: var(--t-12); color: var(--slate); margin-top: 4px; }


/* positions: the charges as a two-column table, amounts right-aligned to the paisa */
.chg-t { margin-top: 10px; border-top: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
.chg-r { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--rule); color: var(--ink); }
.chg-r span:last-child { text-align: right; white-space: nowrap; font-weight: 500; }
.chg-r.part { padding: 4px 0 4px 12px; color: var(--slate); border-bottom-style: dashed; }
.chg-r.part span:last-child { font-weight: 400; }
.chg-r.sum { font-weight: 600; }
.chg-r.sum span:last-child { font-weight: 600; }
.chg-r i { display: block; font-style: normal; font-weight: 400; font-size: var(--t-12); color: var(--slate); }
.chg-foot { margin-top: 8px; }
