:root {
  --bg: #0c0c0d;
  --bg-elev: #141416;
  --bg-elev-2: #1b1b1e;
  --line: #2a2a2e;
  --line-2: #3a3a40;
  --txt: #ececec;
  --muted: #8b8b93;
  --faint: #5c5c64;
  --orange: #f26522;
  --orange-dim: rgba(242, 101, 34, 0.14);
  --green: #3ddc84;
  --green-dim: rgba(61, 220, 132, 0.12);
  --red: #ff5a5f;
  --red-dim: rgba(255, 90, 95, 0.12);
  --blue: #6ea8fe;
  --yellow: #f5c518;
  --call: #3ddc84;
  --put: #ff8a65;
  --itm: rgba(110, 168, 254, 0.07);
  --mono: "IBM Plex Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--txt); font-family: var(--sans); }
button, input, select { font-family: inherit; }
button { cursor: pointer; }

.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #161618, #101012);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 170px; }
.logo {
  width: 22px; height: 22px; border-radius: 4px;
  background: conic-gradient(from 210deg, var(--orange), #ffb347, var(--orange));
}
.brand h1 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: 0.04em; }
.brand h1 span { color: var(--orange); }
.brand small { color: var(--muted); font-size: 10px; display: block; margin-top: -2px; }

.search-wrap { position: relative; }
.search-wrap input {
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--txt);
  padding: 7px 12px 7px 30px; border-radius: 4px; width: 160px; font-size: 13px;
}
.search-wrap input:focus { outline: 1px solid var(--orange); border-color: var(--orange); }
.search-wrap .ico { position: absolute; left: 9px; top: 8px; color: var(--faint); font-size: 12px; }

.metrics { display: flex; gap: 18px; margin-left: auto; }
.metric { text-align: right; }
.metric .k { font-size: 10px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.metric .v { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--line); background: var(--bg-elev); flex-shrink: 0;
}
.tabs button {
  background: none; border: 0; color: var(--muted); padding: 9px 18px; font-size: 12px;
  letter-spacing: 0.06em; text-transform: uppercase; border-bottom: 2px solid transparent;
}
.tabs button.on { color: var(--txt); border-bottom-color: var(--orange); }
.tabs button:hover { color: var(--txt); }

.stage { flex: 1; min-height: 0; display: flex; }

.panel { display: none; flex: 1; min-height: 0; }
.panel.on { display: flex; }

/* POSITIONS */
.pos-layout { display: grid; grid-template-columns: 1fr 340px; flex: 1; min-height: 0; }
.pos-main { overflow: auto; border-right: 1px solid var(--line); }
.side { overflow: auto; background: var(--bg-elev); padding: 12px; }

table.data { width: 100%; border-collapse: collapse; font-size: 12px; }
table.data th {
  text-align: left; font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: #121214; z-index: 2;
}
table.data td { padding: 6px 10px; border-bottom: 1px solid #1f1f22; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12px; }
table.data tr.und-row td { background: #18181b; font-family: var(--sans); font-weight: 600; cursor: pointer; }
table.data tr.und-row:hover td { background: #1f1f24; }
table.data tr.leg td { color: #cfcfd4; }
table.data tr.leg:hover td { background: #16161a; }
.badge {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 3px;
  letter-spacing: 0.04em; font-family: var(--sans); font-weight: 600;
}
.badge.C { background: var(--green-dim); color: var(--green); }
.badge.P { background: rgba(255,138,101,.15); color: var(--put); }
.badge.STK { background: var(--orange-dim); color: var(--orange); }
.qty-long { color: var(--green); }
.qty-short { color: var(--red); }

/* TRADE / CHAIN */
.trade-layout { display: grid; grid-template-rows: auto 1fr auto; flex: 1; min-height: 0; }
.trade-head {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: var(--bg-elev); flex-wrap: wrap;
}
.und-chip { display: flex; align-items: baseline; gap: 10px; }
.und-chip .sym { font-size: 20px; font-weight: 650; }
.und-chip .px { font-family: var(--mono); font-size: 18px; }
.und-chip .chg { font-family: var(--mono); font-size: 12px; }
.trade-head label { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.trade-head input[type="number"], .trade-head select {
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--txt);
  padding: 4px 6px; border-radius: 3px; width: 78px; font-family: var(--mono); font-size: 12px;
}
.exp-list { overflow: auto; }
.chain-wrap { width: 100%; }

.exp-row {
  display: grid; grid-template-columns: 28px 1fr 80px 70px 90px 90px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
  align-items: center; font-size: 13px;
}
.exp-row:hover { background: #151518; }
.exp-row.open { background: #18161a; }
.exp-row .dte { color: var(--orange); font-family: var(--mono); font-size: 12px; }
.exp-row .ivx { font-family: var(--mono); color: var(--blue); }
.exp-row .em { font-family: var(--mono); color: var(--muted); font-size: 12px; }

.chain {
  width: 100%; min-width: 720px; table-layout: fixed; border-collapse: collapse; font-size: 11.5px; font-family: var(--mono);
}
.chain th {
  font-family: var(--sans); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); font-weight: 500; padding: 6px 6px; border-bottom: 1px solid var(--line);
  background: #101012; position: sticky; top: 0;
}
.chain td { padding: 3px 6px; border-bottom: 1px solid #1c1c20; text-align: right; }
.chain td.strike {
  text-align: center; font-weight: 700; color: var(--txt); background: #141416;
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
}
.chain tr.atm td.strike {
  background: #1c1a14;
  box-shadow: inset 0 0 0 1px rgba(245, 197, 24, 0.28);
}
.chain .held-long { color: var(--green); font-weight: 700; margin: 0 5px; }
.chain .held-short { color: var(--red); font-weight: 700; margin: 0 5px; }
.chain tr.itm-call td.call-side { background: var(--itm); }
.chain tr.itm-put td.put-side { background: var(--itm); }
.chain td.click {
  cursor: pointer; color: #d0d0d4;
}
.chain td.click:hover { background: var(--orange-dim); color: var(--orange); }
.chain td.oi, .chain td.vol { color: var(--faint); }
.chain .sel-buy { outline: 1px solid var(--green); background: var(--green-dim) !important; }
.chain .sel-sell { outline: 1px solid var(--red); background: var(--red-dim) !important; }

.ticket {
  border-top: 1px solid var(--line); background: #121214; padding: 10px 12px;
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start;
}
.ticket-legs { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-family: var(--mono); }
.ticket-actions { display: flex; gap: 8px; align-items: center; }
.btn {
  background: var(--bg-elev-2); border: 1px solid var(--line-2); color: var(--txt);
  padding: 7px 12px; border-radius: 4px; font-size: 12px;
}
.btn:hover { border-color: #666; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #111; font-weight: 650; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #5a2a2c; }

/* SIM */
.sim-layout { display: grid; grid-template-columns: 280px 1fr 320px; flex: 1; min-height: 0; }
.sim-controls, .sim-risk { overflow: auto; background: var(--bg-elev); padding: 14px; }
.sim-chart { display: flex; flex-direction: column; min-width: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.sim-chart header { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.chart-box { flex: 1; min-height: 280px; padding: 8px 10px; }
.slat { margin-bottom: 14px; }
.slat h3 { margin: 0 0 8px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.slider-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.slider-row label { width: 72px; font-size: 12px; color: var(--muted); }
.slider-row input[type="range"] { flex: 1; accent-color: var(--orange); }
.slider-row .val { width: 64px; text-align: right; font-family: var(--mono); font-size: 12px; }
.scope { display: flex; gap: 4px; flex-wrap: wrap; }
.scope button { font-size: 11px; padding: 4px 8px; }
.scope button.on { background: var(--orange-dim); border-color: var(--orange); color: var(--orange); }

.risk-card {
  background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 10px; margin-bottom: 8px;
}
.risk-card .title { font-size: 12px; font-weight: 600; margin-bottom: 6px; display: flex; justify-content: space-between; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 12px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-family: var(--mono); text-align: right; }

/* IMPORT */
.import-wrap { flex: 1; overflow: auto; padding: 24px; max-width: 980px; }
.drop {
  border: 1px dashed var(--line-2); border-radius: 8px; padding: 36px; text-align: center;
  background: var(--bg-elev); color: var(--muted);
}
.drop.hot { border-color: var(--orange); background: var(--orange-dim); color: var(--txt); }
.help { color: var(--muted); font-size: 13px; line-height: 1.55; }
.help code { background: #1c1c20; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.warn { color: var(--yellow); font-size: 12px; }

/* MANUAL ADD */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-grid label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-grid input, .form-grid select {
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--txt);
  padding: 6px 8px; border-radius: 3px; font-family: var(--mono);
  width: 100%; min-width: 0;
}

.footer-note {
  font-size: 10px; color: var(--faint); padding: 6px 12px; border-top: 1px solid var(--line);
}

.status-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.status-dot.live { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.syn { background: var(--yellow); }

.empty { padding: 40px; text-align: center; color: var(--muted); }
.tiny { font-size: 11px; color: var(--muted); }

@media (max-width: 640px) {
  .exp-row { grid-template-columns: 24px minmax(0, 1fr) auto; }
  .exp-row .ivx, .exp-row .em { display: none; }
}
