:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #d9dee6;
  --line2: #e8ecf1;
  --head-bg: #f2f4f7;
  --gap-bg: #fbf1c7;
  --sub-bg: #dbe8f7;
  --sub-t: #2a5d9f;
  --pos-bg: #d7f2dd;
  --pos-t: #146c2e;
  --neg-bg: #fbdde1;
  --neg-t: #c4162a;
  --ltp-t: #1f6fb8;
  --atm-bg: #fff4c2;
  --call: #14874a;
  --put: #d32f3f;
  --teal: #0e7c8c;
  --input-bg: #ffffff;
  --btn-bg: #ffffff;
  --btn-hover: #eef1f5;
}
:root[data-theme="dark"] {
  --bg: #15181e;
  --card: #1d2129;
  --text: #e3e7ee;
  --muted: #9aa3b2;
  --line: #333a46;
  --line2: #2a303a;
  --head-bg: #232833;
  --gap-bg: #3b3520;
  --sub-bg: #22344d;
  --sub-t: #9cc3f5;
  --pos-bg: #173a24;
  --pos-t: #7fe0a0;
  --neg-bg: #43202a;
  --neg-t: #ff9aa6;
  --ltp-t: #7db8f0;
  --atm-bg: #4a4218;
  --call: #4cc684;
  --put: #ff7884;
  --input-bg: #262b35;
  --btn-bg: #262b35;
  --btn-hover: #2f3541;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, "Segoe UI", Arial, sans-serif; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; }
.hidden { display: none !important; }
select, input { background: var(--input-bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px; font: inherit; }
.btn { background: var(--btn-bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 4px 10px; cursor: pointer; font: inherit; }
.btn:hover { background: var(--btn-hover); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; font-weight: 700; }
.btn.icon { padding: 4px 8px; }

/* ---------- top bar */
.top { background: var(--card); border-bottom: 1px solid var(--line); padding: 8px 12px; position: sticky; top: 0; z-index: 20; }
.row1, .row2 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.row2 { margin-top: 6px; }
.brand { font-size: 17px; margin-right: 6px; }
select.assetSel { background: var(--teal); color: #fff; border-color: var(--teal); font-weight: 700; min-width: 160px; padding: 5px 8px; cursor: pointer; }
select.assetSel option { background: #fff; color: #111; font-weight: 400; }
.exp { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
.exp > span:first-child { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .5px; }
.exp select { border: 0; font-weight: 700; font-size: 14px; background: transparent; }
.dte { font-size: 11px; color: var(--muted); font-weight: 700; border-left: 1px solid var(--line); padding-left: 8px; }
.dte b { color: var(--text); font-size: 14px; }
.k { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .5px; }
.chip { border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-size: 12px; font-weight: 600; }
.big { font-size: 20px; }
.chg.up { color: var(--call); font-weight: 700; }
.chg.dn { color: var(--put); font-weight: 700; }
.atmv { color: #c56a00; font-size: 17px; }
.strv { color: var(--teal); font-size: 17px; }
.sep { width: 1px; align-self: stretch; background: var(--line); }
.live { color: var(--call); font-weight: 700; font-size: 12px; }
.live.off { color: var(--muted); }
.pill { padding: 3px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; background: var(--head-bg); color: var(--muted); }
.pill.ok { background: #d7f2dd; color: #146c2e; }
.pill.bad { background: #fbdde1; color: #c4162a; }
.pill.warn { background: #fff1c2; color: #7a5a00; }

.msg { margin: 8px 12px 0; padding: 6px 10px; border-radius: 4px; font-weight: 700; }
.msg.err { background: var(--neg-bg); color: var(--neg-t); }
.msg.warn { background: var(--atm-bg); color: var(--text); }

/* ---------- panels */
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(620px, 1fr)); gap: 12px; padding: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 6px; min-width: 0; display: flex; flex-direction: column; }
.card.CALL { border-color: color-mix(in srgb, var(--call) 55%, var(--line)); }
.card.PUT { border-color: color-mix(in srgb, var(--put) 55%, var(--line)); }
.ptitle { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; background: var(--head-bg); border-bottom: 1px solid var(--line); border-radius: 6px 6px 0 0; }
.side { background: none; border: 0; font: inherit; font-weight: 800; font-size: 14px; cursor: pointer; padding: 0; }
.CALL .side { color: var(--call); }
.PUT .side { color: var(--put); }
.side:hover { text-decoration: underline; }
.legs { display: inline-flex; align-items: center; gap: 4px; }
.leg { width: 44px; text-align: center; font-weight: 700; padding: 2px 2px; border-radius: 4px; }
.leg.b { background: var(--pos-bg); color: var(--pos-t); border-color: color-mix(in srgb, var(--pos-t) 35%, transparent); }
.leg.s { background: var(--neg-bg); color: var(--neg-t); border-color: color-mix(in srgb, var(--neg-t) 35%, transparent); }
.leg.z { color: var(--muted); }
.addleg { border: 1px solid var(--line); background: var(--btn-bg); border-radius: 4px; font-weight: 800; cursor: pointer; padding: 1px 7px; font-size: 13px; }
.addleg.s { color: var(--neg-t); }
.addleg.b { color: var(--pos-t); }
.addleg:disabled { opacity: .35; cursor: default; }
.rlabel { color: var(--muted); font-size: 11px; }
.ptools { margin-left: auto; display: inline-flex; gap: 2px; }
.ptools button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.ptools button:hover { background: var(--btn-hover); color: var(--text); }

.tbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.tbar label { display: inline-flex; align-items: center; gap: 3px; font-size: 10px; font-weight: 700; color: var(--muted); }
.tbar select { font-size: 11px; padding: 1px 2px; width: 66px; }
.tbar select[data-f="cnt"] { width: 50px; }
.tbar input[type="checkbox"] { margin: 0; }
.tbar .mini { font-size: 10px; padding: 1px 6px; font-weight: 600; }

.scroll { overflow: auto; height: 68vh; min-height: 160px; resize: vertical; }
.card.collapsed .tbar, .card.collapsed .scroll { display: none; }

/* fixed-width grid like the MCX app — never stretch columns to fill the card */
table.rt { border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; width: max-content; }
.rt td, .rt th.sub { width: 84px; min-width: 84px; max-width: 84px; overflow: hidden; text-overflow: clip; }
.rt th, .rt td { border-right: 1px solid var(--line2); border-bottom: 1px solid var(--line2); padding: 3px 8px; white-space: nowrap; text-align: right; }
.rt thead th { position: sticky; z-index: 3; background: var(--head-bg); font-weight: 700; }
.rt thead tr:first-child th { top: 0; height: 26px; }
.rt thead tr:nth-child(2) th { top: 26px; }
.rt th.gh { background: var(--gap-bg); text-align: center; font-size: 13px; }
.rt th.sub { background: var(--sub-bg); color: var(--sub-t); font-size: 10px; text-align: center; padding: 2px 6px; }
.rt th.fx, .rt td.fx { position: sticky; z-index: 2; }
.rt thead th.fx { z-index: 4; }
.rt .c0 { left: 0; width: 88px !important; min-width: 88px !important; max-width: 88px !important; padding-left: 4px !important; padding-right: 4px !important; }
.rt .c1 { left: 88px; width: 76px !important; min-width: 76px !important; max-width: 76px !important; border-right: 2px solid var(--line); }
.rt td.fx { background: var(--card); }
.rt td.c0 { font-weight: 600; text-align: left; }
.rt td.c1 { color: var(--ltp-t); }
.rt td.c1.stale { color: var(--muted); font-style: italic; }
.rt td.c1.dead { color: var(--muted); }
.rt td.st { color: var(--muted) !important; font-style: italic; }
.rt input.fs { width: 100%; border: 1px solid var(--line); border-radius: 3px; padding: 0 2px; font: inherit; font-weight: 700; background: var(--input-bg); color: var(--text); }
.rt input.fs { -moz-appearance: textfield; }
.rt input.fs::-webkit-inner-spin-button, .rt input.fs::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.rt tr.atm td.fx { background: var(--atm-bg); }
.rt tr.atm td.c0 { font-weight: 800; }
.rt td.p { background: var(--pos-bg); color: var(--pos-t); }
/* credit (negative) = plain white cell, debit (positive) = green */
.rt td.n { background: var(--card); color: var(--text); }
.rt td.e { color: var(--muted); text-align: center; }
.rt td.pv { color: var(--muted); }
.rt tbody tr:hover td { filter: brightness(0.96); }

.foot { padding: 0 14px 14px; }
.rt td:not(.fx):not(.e):not(.pv) { cursor: pointer; }

/* ratio card */
.pop { position: fixed; z-index: 50; width: 290px; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 12px 14px 10px; font-size: 13px; }
.pop hr { border: 0; border-top: 1px solid var(--line2); margin: 8px 0; }
.pop .px { position: absolute; top: 4px; right: 6px; border: 0; background: none; font-size: 18px; color: var(--muted); cursor: pointer; }
.pop .plegs { display: flex; flex-direction: column; gap: 5px; }
.pop .pl { display: flex; align-items: center; gap: 8px; }
.pop .tag { font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 3px; min-width: 36px; text-align: center; }
.pop .tag.b { background: var(--pos-bg); color: var(--pos-t); }
.pop .tag.s { background: var(--neg-bg); color: var(--neg-t); }
.pop .pnote, .pop .psub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.pop .psub { margin-top: 0; text-align: right; }
.pop .pr { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 2px 0; }
.pop .pr span { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .4px; }
.pop .pr b { font-size: 14px; text-align: right; }
.pop .pr small { font-size: 10px; color: var(--muted); font-weight: 600; }
.pop .up { color: var(--call); }
.pop .dn { color: var(--put); }
.pop .perr { color: var(--muted); font-weight: 600; cursor: help; }
.pop .pbtn { width: 100%; margin-top: 8px; padding: 7px; border: 1px dashed var(--line); border-radius: 6px; background: none; color: #c77800; font: inherit; font-weight: 600; cursor: pointer; }
.pop .pbtn:hover { background: var(--btn-hover); }

dialog.unlockDlg { width: min(360px, 92vw); }
dialog.unlockDlg input { width: 100%; padding: 7px 9px; font-size: 14px; }

/* chart window */
dialog.chartDlg { width: min(1200px, 96vw); padding: 12px 14px; }
.chead { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.clegs { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-weight: 700; }
.clegs .tag { font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 3px; margin-right: 4px; }
.clegs .tag.b { background: var(--pos-bg); color: var(--pos-t); }
.clegs .tag.s { background: var(--neg-bg); color: var(--neg-t); }
.ctools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.seg button { border: 0; background: var(--btn-bg); color: var(--text); padding: 3px 9px; font: inherit; font-size: 12px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--teal); color: #fff; font-weight: 700; }
.clast { font-weight: 800; font-size: 15px; min-width: 90px; text-align: right; }
.clast.up { color: var(--call); }
.clast.dn { color: var(--put); }
.chart { height: min(62vh, 560px); width: 100%; margin: 6px 0; position: relative; }
.ctip { position: absolute; z-index: 5; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.15); padding: 6px 9px; font-size: 12px; min-width: 170px; }
.ctip .tt { color: var(--muted); font-weight: 700; font-size: 11px; margin-bottom: 3px; }
.ctip div:not(.tt) { display: flex; justify-content: space-between; gap: 12px; }
.ctip span { color: var(--muted); font-weight: 700; font-size: 11px; }
.ctip .up { color: var(--call); }
.ctip .dn { color: var(--put); }

dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 8px; width: min(720px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3, dialog h4 { margin: 4px 0 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.drow { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.drow.end { justify-content: flex-end; }
.err { color: var(--neg-t); margin-top: 8px; white-space: pre-wrap; word-break: break-word; }
code { background: var(--head-bg); padding: 0 4px; border-radius: 3px; }
@media (max-width: 680px) {
  .panels { grid-template-columns: 1fr; padding: 8px; }
  .grid2 { grid-template-columns: 1fr; }
}
