:root {
  --bg: #fbfbfa; --panel: #ffffff; --ink: #18181b; --dim: #71717a; --line: #ececea; --faint: #a1a1aa;
  --accent: #ea580c; --accent-soft: #fff4ec; --up: #b91c1c; --down: #15803d; --chip: #f4f4f3;
  --exp: #2563eb; /* exposure margin series */ --exp-soft: #fdba74; /* exposure share in the margin bar */
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
[data-theme="dark"] {
  --bg: #0b0b0c; --panel: #151517; --ink: #f4f4f5; --dim: #a1a1aa; --line: #26262a; --faint: #71717a;
  --accent: #fb923c; --accent-soft: #2a1a0e; --up: #f87171; --down: #4ade80; --chip: #1f1f22;
  --exp: #60a5fa; --exp-soft: #c2410c;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 "IBM Plex Sans", system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
.top { display: flex; align-items: center; gap: 28px; padding: 0 32px; min-height: 60px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 600; font-size: 15px; color: var(--ink); display: flex; align-items: center; gap: 8px; letter-spacing: -.3px; }
.brand .dim { color: var(--dim); font-weight: 500; }
.logo { background: var(--ink); color: var(--bg); width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
nav { display: flex; gap: 24px; flex: 1; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; align-self: stretch; }
nav::-webkit-scrollbar { display: none; }
nav a { white-space: nowrap; }
nav a { color: var(--dim); padding: 19px 0 17px; font-size: 14px; border-bottom: 2px solid transparent; }
nav a:hover { color: var(--ink); }
nav a.on { color: var(--ink); font-weight: 500; border-bottom-color: var(--accent); }
/* phones: logo and theme button on one row, the menu below as a single row you can swipe */
@media (max-width: 700px) {
  .top { gap: 10px; justify-content: space-between; }
  nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; }
  nav::-webkit-scrollbar { display: none; }
  nav a { white-space: nowrap; padding: 10px 0; }
  .top { padding: 8px 16px; }
}
.asof { max-width: 1280px; margin: 0 auto; padding: 10px 32px 0; font-size: 12px; color: var(--faint); }
.asof b { color: var(--ink); font-weight: 600; }
main { max-width: 1280px; margin: 0 auto; padding: 24px 32px 48px; }
footer { max-width: 1280px; margin: 40px auto; padding: 0 32px; color: var(--faint); font-size: 12px; }
h1 { font-size: 26px; font-weight: 600; letter-spacing: -.3px; margin: 0 0 6px; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 14px; }
.lede { color: var(--dim); font-size: 14px; margin: 0 0 22px; max-width: 760px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(320px, 1fr); gap: 28px; align-items: start; }
.grid2 > * { min-width: 0; } /* wide tables scroll inside their card instead of widening the page */
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } main { padding: 16px; } .asof { padding: 10px 16px 0; } }
label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 4px; font-weight: 500; }
input, select { width: 100%; height: 40px; padding: 0 10px; border: 1px solid #e4e4e2; border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; font-size: 14px; }
[data-theme="dark"] input, [data-theme="dark"] select { border-color: var(--line); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form { display: grid; grid-template-columns: 1.15fr 1.25fr 1.35fr 1.1fr .8fr 1.15fr .8fr; gap: 10px; align-items: end; }
@media (max-width: 1100px) { .form { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 560px) { .form { grid-template-columns: 1fr 1fr; } }
.formfoot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.formfoot #fInfo { flex: 1; margin: 0; min-width: 200px; font-family: var(--mono); }
button { font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
#fAdd { background: var(--ink); border-color: var(--ink); color: var(--bg); height: 40px; }
.drop { display: inline-flex; align-items: center; gap: 6px; margin: 0; border: 1px dashed transparent; border-radius: 8px; padding: 6px 8px; cursor: pointer; font-size: 13px; color: var(--accent); }
.drop:hover, .drop.over { border-color: var(--accent); }
.drop { position: relative; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }  /* the whole box opens the file picker */
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop b { font-weight: 500; }
a.btn { display: inline-block; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: #fff; font-weight: 600; white-space: nowrap; }
a.btn:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border: none; font-size: 18px; color: var(--dim); }
.seg { display: inline-flex; border: 1px solid #e4e4e2; border-radius: 8px; overflow: hidden; width: 100%; height: 40px; }
[data-theme="dark"] .seg { border-color: var(--line); }
.seg button { border: none; border-radius: 0; flex: 1; padding: 0 6px; background: var(--panel); color: var(--dim); font-size: 13px; font-weight: 500; }
.seg.pill { background: var(--chip); border: 0; padding: 3px; gap: 2px; }
.seg.pill button { background: transparent; border-radius: 6px; }
.seg.pill button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg button.on.buy { background: var(--down); color: #fff; }
.seg button.on.sell { background: var(--up); color: #fff; }
[data-theme="dark"] .seg button.on.buy, [data-theme="dark"] .seg button.on.sell { color: #0b0b0c; }
.seg button.on.neutral { background: var(--ink); color: var(--bg); }
.hint { font-size: 12px; color: var(--dim); margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--faint); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.sort { cursor: pointer; user-select: none; }
th.sort:hover { color: var(--ink); }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: 13px; }
tr:last-child td { border-bottom: none; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 5px; }
.tag.b { background: color-mix(in srgb, var(--down) 15%, transparent); color: var(--down); }
.tag.s { background: color-mix(in srgb, var(--up) 15%, transparent); color: var(--up); }
.x { border: none; background: none; color: var(--faint); padding: 6px; display: inline-flex; }
.side { display: inline-block; width: 18px; font-size: 11px; font-weight: 600; }
.side.b { color: var(--down); } .side.s { color: var(--up); }

#posTable tr.off td:not(:first-child):not(.eff):not(:last-child) { opacity: .45; }
#posTable .lotin { width: 64px; height: 30px; padding: 0 6px; text-align: right; font: inherit; }
#posTable .lotsz { font-size: 12px; color: var(--dim); }
#sfPlan th, #sfPlan td { padding-left: 5px; padding-right: 5px; }
#sfPlan .cutin { width: 56px; height: 30px; padding: 0 6px; text-align: right; font: inherit; }
#sfPlan tr.off td:not(:nth-child(3)) { opacity: .5; }
#sfPlan td.ct { white-space: normal; min-width: 110px; line-height: 1.3; }
#posTable td.ct { white-space: normal; min-width: 110px; line-height: 1.3; }
#posTable td.eff { font-size: 12.5px; white-space: nowrap; }
#posTable th, #posTable td { padding-left: 5px; padding-right: 5px; }
#posTable th:first-child, #posTable td:first-child { padding-left: 2px; }
.moved { font-size: 13.5px; margin: 2px 0 10px; }
.x:hover { color: var(--up); }
.total { font-size: 36px; font-weight: 500; letter-spacing: -1px; font-family: var(--mono); margin: 4px 0 14px; }
.split { display: flex; gap: 2px; height: 6px; border-radius: 3px; overflow: hidden; margin-bottom: 4px; }
.sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 8px; vertical-align: 1px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin-top: 14px; font-size: 14px; }
.kv .v { font-family: var(--mono); text-align: right; }
.kv .sub { color: var(--dim); padding-left: 12px; font-size: 13px; }
.benefit { margin-top: 16px; padding: 14px 0 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--dim); }
.benefit b { color: var(--down); font-family: var(--mono); font-weight: 500; }
.up { color: var(--up); } .down { color: var(--down); } .muted { color: var(--dim); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
@media (max-width: 700px) { .stats { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .l { font-size: 12px; color: var(--dim); }
.stat .n { font-size: 22px; font-weight: 700; font-family: var(--mono); letter-spacing: -.5px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { max-width: 240px; }
.chips { display: inline-flex; gap: 2px; background: var(--chip); border-radius: 8px; padding: 3px; }
.chips button { padding: 5px 12px; font-size: 13px; font-weight: 500; border-radius: 6px; border: 0; background: transparent; color: var(--dim); }
.chips button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
#chart { height: 280px; }
#schart, #pchart { height: 170px; }
.chart-title { font-size: 12.5px; color: var(--dim); margin: 18px 0 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chart-title .key { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--ink); margin-left: 6px; }
.chart-title .key:first-child { margin-left: 0; }
.chart-title .key-span { border-top: 2px dashed var(--dim); }
/* price moves: green when price rises (the opposite of margin, where rising is red) */
.gain { color: var(--down); } .loss { color: var(--up); }
.stat .s { font-size: 13px; font-family: var(--mono); margin-top: 2px; }
.scroll { overflow-x: auto; }
.empty { color: var(--dim); text-align: center; padding: 30px; }
code { font-family: var(--mono); font-size: 13px; background: var(--chip); padding: 2px 6px; border-radius: 5px; }
.api td:first-child { font-family: var(--mono); font-size: 13px; }
.bar { height: 6px; border-radius: 3px; background: var(--accent); opacity: .7; }
/* corporate action tag (bonus, split...): price and margin per lot jump without a change in risk */
.ca { display: inline-block; font-size: 11px; font-weight: 600; line-height: 1.5; padding: 0 6px; border-radius: 6px; vertical-align: middle;
      color: var(--exp); background: color-mix(in srgb, var(--exp) 12%, transparent); white-space: nowrap; }

.expiry-filter { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
/* wide data tables: headings wrap, tighter cells, symbol column pinned, fade where more columns are off-screen */
table.compact th { white-space: normal; vertical-align: bottom; line-height: 1.25; padding: 8px 7px; }
table.compact td { padding: 8px 7px; vertical-align: top; }
table.compact .tags { font-size: 11px; margin-top: 2px; white-space: nowrap; }
table.pin1 th:first-child, table.pin1 td:first-child { position: sticky; left: 0; z-index: 1; background: var(--panel); }
.scroll.more { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
               mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); }

/* calculator: BOD / Latest SPAN file switch */
.basis { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: -6px 0 22px; font-size: 13px; color: var(--dim); }
.basis .chips button:disabled { opacity: .45; cursor: not-allowed; }

/* on/off switch (a checkbox underneath: same keyboard and form behaviour) */
input.switch { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 34px; height: 20px;
  padding: 0; border: 0; box-sizing: border-box;
  margin: 0; border-radius: 999px; background: var(--dim); cursor: pointer; transition: background .15s; }
input.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
input.switch:checked { background: var(--accent); }
input.switch:checked::after { transform: translateX(14px); }
input.switch:focus { outline: none; }
input.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* switching SPAN file: the page stays as it is until the other file's contracts are in */
body.busy #result, body.busy #posTable { opacity: .55; transition: opacity .15s; }
body.busy { cursor: progress; }
