:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --pos: #2a78d6;      /* diverging pole: gain */
  --neg: #e34948;      /* diverging pole: loss */
  --good: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  --grid: #e8e7e3;
  --s1: #2a78d6;       /* series 1: simulated */
  --s2: #eb6834;       /* series 2: announced */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --pos: #3987e5;
    --neg: #e66767;
    --grid: #2a2a28;
    --s1: #3987e5;
    --s2: #d95926;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
  --pos: #3987e5; --neg: #e66767; --grid: #2a2a28; --s1: #3987e5; --s2: #d95926;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; letter-spacing: .2px; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs button {
  border: 0; background: none; color: var(--text-2); padding: 8px 12px; border-radius: 6px; cursor: pointer; font: inherit; white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #1a1a19; font-size: 11px; font-weight: 700; text-align: center; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 2px; font-size: 15px; }
.sub { margin: 0 0 12px; color: var(--muted); font-size: 12.5px; }
.grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } .top { flex-wrap: wrap; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .hint { color: var(--text-2); font-size: 12px; }

.btn { border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 7px 14px; border-radius: 7px; cursor: pointer; font: inherit; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--text-2); border-color: var(--border); font-weight: 500; }
.btn.small { padding: 3px 8px; font-size: 12px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
select, input, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px;
}
textarea { width: 100%; resize: vertical; }
.alert-form .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-top: 8px; }
.alert-form label, .bt-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-2); }
.preview { margin: 10px 0 0; padding: 8px 10px; background: var(--surface-2); border-radius: 6px; font-size: 12px; white-space: pre-wrap; min-height: 1em; }
.preview:empty { display: none; }
.bt-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; }
.bt-form label.check { flex-direction: row; align-items: center; gap: 6px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
td.num, th.num { text-align: right; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
.txt { max-width: 520px; white-space: pre-wrap; color: var(--text-2); }
.empty { color: var(--muted); padding: 18px 4px; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.WIN::before, .pill.opened::before { background: var(--good); }
.pill.LOSS::before, .pill.unmatched::before { background: var(--crit); }
.pill.BE::before, .pill.PENDING::before { background: var(--warn); }
.pill.OPEN::before, .pill.applied::before { background: var(--accent); }
.dir-long { color: var(--pos); font-weight: 600; }
.dir-short { color: var(--neg); font-weight: 600; }
.r-pos { color: var(--text); font-weight: 600; }
.r-neg { color: var(--text); font-weight: 600; }
.r-pos::before { content: "▲ "; color: var(--pos); font-size: 10px; }
.r-neg::before { content: "▼ "; color: var(--neg); font-size: 10px; }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 11px; }
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; display: flex; justify-content: flex-end; }
.drawer-inner { width: min(620px, 100%); height: 100%; overflow-y: auto; background: var(--surface); padding: 20px; position: relative; }
.drawer .close { position: absolute; right: 14px; top: 14px; }
.timeline { list-style: none; padding: 0; margin: 12px 0; }
.timeline li { border-left: 2px solid var(--border); padding: 0 0 12px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .when { color: var(--muted); font-size: 12px; }
dl.levels { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 10px 0; }
dl.levels dt { color: var(--muted); }
dl.levels dd { margin: 0; font-variant-numeric: tabular-nums; }
.prose ol { padding-left: 20px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.kpi-group { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 8px; }
.group-title { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 8px; }
.group-title h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-2); }
.group-title .sub { margin: 0; }
.group-title .btn { margin-left: auto; }
.note { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; color: var(--text-2); font-size: 12.5px; margin-bottom: 16px; }
.pill.EXPIRED::before, .pill.NOT_FILLED::before, .pill.SKIPPED::before { background: var(--muted); }
.pill.CLOSED::before { background: var(--text-2); }
.cell-sub { display: block; color: var(--muted); font-size: 11.5px; font-weight: 400; }
.create-form { display: grid; gap: 10px; margin-top: 12px; }
.create-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-2); }
.create-form label.check { flex-direction: row; align-items: center; gap: 6px; }
.create-form .row { display: flex; gap: 10px; align-items: center; }
.quote { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; max-height: 180px; overflow: auto; }
td.actions { white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }

.trading-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.trading-head > div { flex: 1; min-width: 240px; }
.trading-head .sub { margin: 4px 0 0; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span { width: 42px; height: 24px; border-radius: 12px; background: var(--border); position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { left: 21px; }
.btn.danger { background: var(--crit); border-color: var(--crit); }
.badge.on { background: var(--good); color: #fff; }
.log { font-size: 12.5px; max-height: 360px; overflow: auto; }
.log-row { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); align-items: baseline; }
.log-row .when { color: var(--muted); white-space: nowrap; }
.log-row .lvl { font-weight: 600; text-transform: uppercase; font-size: 11px; min-width: 42px; color: var(--text-2); }
.log-row.error .lvl { color: var(--crit); }
.log-row.warn .lvl { color: #b07800; }
.log-row.trade .lvl { color: var(--accent); }

code.key { display: block; padding: 10px 12px; font-size: 13px; word-break: break-all; user-select: all; }
