:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2b59c3; --buy: #138a52; --sell: #c9302c; --warn-bg: #fff4d6; --warn: #8a5a00;
  --atm: #eef3ff; --itm: #fafaf2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1b2029; --text: #e6e9ef; --muted: #98a1b0; --line: #2c333f;
    --accent: #6f95ff; --buy: #2fbf7a; --sell: #ff6b66; --warn-bg: #3a2f12; --warn: #ffd47a;
    --atm: #1f2a44; --itm: #20231d;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; align-items: center; gap: 18px; padding: 10px 18px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 16px; }
.badge { padding: 3px 10px; border-radius: 99px; font-weight: 700; font-size: 12px; }
.badge.dry { background: #dff3e8; color: #13653d; }
.badge.live { background: var(--sell); color: #fff; }
.stat span { color: var(--muted); margin-right: 6px; font-size: 12px; }
.head-actions { margin-left: auto; display: flex; gap: 6px; }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.card.narrow { max-width: 720px; }
.layout { display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 1fr); gap: 14px; align-items: start; }
.layout > * { min-width: 0; margin-bottom: 0; }
.layout .span { grid-column: 1 / -1; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.settings-grid > * { min-width: 0; margin-bottom: 0; }
@media (max-width: 900px) { .layout, .settings-grid { grid-template-columns: minmax(0, 1fr); } }
h3 { margin: 4px 0 8px; font-size: 15px; }
.scroll { max-height: 420px; overflow: auto; }
.pills.small button { padding: 4px 12px; font-size: 13px; }
.pills.small { margin-bottom: 0; }
.row.two { gap: 10px; } .row.two > label { flex: 1; margin: 4px 0; }
.chain tr.spotrow td { background: var(--atm); color: var(--accent); font-size: 12px; padding: 4px; border-bottom: 2px solid var(--accent); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.pills button { border: 1px solid var(--line); background: none; color: var(--text); padding: 6px 12px; border-radius: 99px; cursor: pointer; }
.pills button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.row { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.row.between { justify-content: space-between; } .row.wrap { flex-wrap: wrap; align-items: end; }
.muted { color: var(--muted); font-size: 12px; }
label { display: block; margin: 8px 0; font-size: 12px; color: var(--muted); }
.row label { margin: 0; }
input, select, textarea { display: block; width: 100%; margin-top: 3px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
.row input, .row select { width: auto; display: inline-block; }
button.primary, button.secondary, button.danger { padding: 8px 14px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 14px; border: 1px solid transparent; }
button.primary { background: var(--accent); color: #fff; }
button.secondary { background: none; border-color: var(--line); color: var(--text); }
button.danger { background: var(--sell); color: #fff; }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.chain-wrap { max-height: 70vh; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: right; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
.chain th, .chain td { text-align: center; }
.chain td.strike { font-weight: 700; }
.chain tr.atm td { background: var(--atm); }
.chain td.itm { background: var(--itm); }
.chain td.pick { cursor: pointer; color: var(--accent); font-weight: 600; }
.chain td.pick:hover, .chain td.pick.sel { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }
.grid td.l, .grid th.l { text-align: left; }
.grid tbody tr.click { cursor: pointer; } .grid tbody tr.click:hover { background: var(--atm); }
.pos { color: var(--buy); } .neg { color: var(--sell); }
.ticket h3 { margin: 0 0 4px; font-size: 16px; }
.toggle { display: flex; margin: 10px 0; }
.toggle button { flex: 1; padding: 8px; border: 1px solid var(--line); background: none; color: var(--text); cursor: pointer; font-weight: 600; }
.toggle button:first-child { border-radius: 6px 0 0 6px; } .toggle button:last-child { border-radius: 0 6px 6px 0; }
.toggle .buy.active { background: var(--buy); color: #fff; border-color: var(--buy); }
.toggle .sell.active { background: var(--sell); color: #fff; border-color: var(--sell); }
.stepper { display: flex; margin-top: 3px; }
.stepper input { margin: 0; text-align: center; border-radius: 0; }
.stepper button { width: 38px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; font-size: 16px; }
.stepper button:first-child { border-radius: 6px 0 0 6px; } .stepper button:last-child { border-radius: 0 6px 6px 0; }
.actions { display: flex; gap: 8px; margin-top: 12px; } .actions button { flex: 1; }
.totals { display: flex; gap: 22px; margin: 4px 0 10px; }
.totals b { font-size: 16px; }
.banner { background: var(--warn-bg); color: var(--warn); padding: 8px 18px; font-size: 13px; }
.hidden { display: none !important; }
code { display: block; background: var(--bg); border: 1px solid var(--line); padding: 8px; border-radius: 6px; font-size: 12px; word-break: break-all; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
.modal-box { background: var(--card); border-radius: 12px; padding: 18px; width: 440px; max-width: 100%; max-height: 90vh; overflow: auto; }
.modal-box h3 { margin-top: 0; }
.summary td { text-align: left; } .summary td:first-child { color: var(--muted); width: 45%; }
.warn { background: var(--warn-bg); color: var(--warn); padding: 8px; border-radius: 6px; margin: 10px 0; font-size: 13px; }
.livewarn { background: var(--sell); color: #fff; padding: 8px; border-radius: 6px; margin: 10px 0; font-weight: 600; }
.grid td:nth-child(-n+3), .grid th:nth-child(-n+3) { text-align: left; }

/* ---------- phone layout ---------- */
@media (max-width: 700px) {
  header { gap: 10px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .brand { font-size: 15px; }
  .stat span { display: block; margin: 0; font-size: 11px; }
  html, body { overflow-x: hidden; }
  main { padding: 10px; }
  .card { padding: 12px; border-radius: 8px; }
  input, select, textarea { font-size: 16px; }   /* stops iOS zooming into fields */
  .row { flex-wrap: wrap; }
  .row label { flex: 1 1 140px; }
  .row input, .row select { width: 100%; }
  .pills { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pills button { flex: 0 0 auto; padding: 8px 14px; }
  .scroll { max-height: none; }
  .head-actions { margin-left: 0; }
  .chain th:nth-child(1), .chain tr:not(.spotrow) td:nth-child(1), .chain th:nth-child(5), .chain td:nth-child(5) { display: none; }
  .chain td { padding: 10px 6px; font-size: 15px; }
  .actions button, .toggle button { padding: 12px; }
  .totals { flex-wrap: wrap; gap: 14px; }
  /* tables become one card per row */
  table.cards thead { display: none; }
  table.cards, table.cards tbody { display: block; }
  table.cards tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.cards td { display: block; border: 0; padding: 0; text-align: left !important; }
  table.cards td::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); }
  table.cards td.title { grid-column: 1 / -1; font-weight: 600; font-size: 15px; }
  table.cards td.title::before, table.cards td.act::before { display: none; }
  table.cards td.wide { grid-column: 1 / -1; }
  table.cards td.act { grid-column: 1 / -1; }
  table.cards td.act button { width: 100%; padding: 10px; font-size: 14px; }
  table.cards td:empty { display: none; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-box { width: 100%; border-radius: 14px 14px 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}
.row.two { align-items: flex-start; margin-bottom: 0; }
.row.two > label { min-width: 0; }
.row.two select, .row.two input { display: block; width: 100%; }
.row.two .stepper input { flex: 1; min-width: 0; }

/* ---------- watchlist ---------- */
.watch-card { padding: 0 0 6px; overflow: hidden; }
.watch-card .row { padding: 0 14px; margin: 10px 0 4px; }
.tabs { display: flex; gap: 22px; overflow-x: auto; padding: 12px 16px 0; background: var(--bg); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 0 0 auto; background: none; border: 0; border-bottom: 3px solid transparent; padding: 6px 0 10px; font-size: 16px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.watch { display: flex; flex-direction: column; }
.witem { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; cursor: pointer; color: var(--text); font: inherit; }
.witem:hover, .witem:active { background: var(--atm); }
.wname { font-size: 15px; letter-spacing: .02em; }
.wname small, .wprice small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.wprice { text-align: right; font-variant-numeric: tabular-nums; }
.wprice b { font-size: 16px; font-weight: 500; }
.wspot { padding: 6px 16px; font-size: 12px; color: var(--accent); background: var(--atm); border-bottom: 2px solid var(--accent); }
.pad { padding: 14px 16px; }
#sheet .modal-box { width: 460px; }
button.armed { background: #8b0000 !important; animation: pulse .8s infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: .7; } }
.wgroup { padding: 8px 16px 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; background: var(--bg); }
#closed-head { margin: 14px 0 4px; }
table.closed td { color: var(--muted); }
.bench { display: flex; gap: 0; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.bench::-webkit-scrollbar { display: none; }
.bench:empty { display: none; }
.bench button { flex: 0 0 auto; background: none; border: 0; border-right: 1px solid var(--line); padding: 8px 18px; cursor: pointer; color: var(--text); font: inherit; font-size: 13px; text-align: left; white-space: nowrap; }
.bench button span { color: var(--muted); margin-right: 6px; }
.bench button b { font-weight: 600; font-variant-numeric: tabular-nums; }
.bench button small { font-size: 12px; margin-left: 4px; }
.bench button.active { background: var(--atm); }
