:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --green: #3fb950;
  --red: #f85149;
  --blue: #58a6ff;
  --yellow: #d29922;
  --accent: #238636;
  --accent-hover: #2ea043;
}

* { box-sizing: border-box; }

.topbar.hidden { display: none; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

button {
  font-family: inherit;
  font-size: 12px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
}
button:hover { background: #2a313a; }
button.primary { background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-hover); }
button.danger { background: #6e1212; border-color: #8e1d1d; color: #ffd7d5; }
button.danger:hover { background: #8b1717; }
button.buy { background: #3fb95022; border-color: var(--green); color: var(--green); }
button.sell { background: #f8514922; border-color: var(--red); color: var(--red); }
button.small { padding: 2px 6px; font-size: 11px; }

input, select {
  font-family: inherit;
  font-size: 12px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.brand { font-weight: 600; font-size: 14px; letter-spacing: 0.3px; }
.spots { display: flex; gap: 18px; flex: 1; }
.spot { display: flex; flex-direction: column; }
.spot .name { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.spot .px { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }

.capital {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-3);
}
.capital .px { font-variant-numeric: tabular-nums; font-weight: 600; }
.capital .label,
.day-pnl .label {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.day-pnl { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.pnl { font-variant-numeric: tabular-nums; font-weight: 600; }
.pnl.pos { color: var(--green); }
.pnl.neg { color: var(--red); }

.conn { font-size: 18px; color: var(--red); transition: color 0.2s; }
.conn.ok { color: var(--green); }

.tabs { display: flex; gap: 4px; }
.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
}
.tab-btn:hover { background: var(--bg-3); color: var(--text); }
.tab-btn.active {
  background: var(--bg-3);
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
}
.layout.hidden { display: none; }

/* ── Layout ─────────────────────────────────────────────────────────── */

.layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  min-height: calc(100vh - 50px);
}

.panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.panel-header h2 { margin: 0; font-size: 13px; font-weight: 600; }
.panel-header .muted { color: var(--muted); font-size: 11px; font-weight: normal; }

/* ── Option Chain tab: chain + selected-legs tray ───────────────────── */

.chain-row,
.sim-col { display: grid; gap: 12px; }
.chain-row { grid-template-columns: minmax(0, 1fr) 340px; }
.chain-row.hidden,
.sim-col.hidden { display: none; }

.tab-count {
  font-size: 10px;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}

.tray-panel { align-self: start; max-height: calc(100vh - 90px); }
.tray-list {
  overflow: auto;
  padding: 6px 0;
  min-height: 80px;
}
.tray-leg {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 5px 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.tray-leg:hover { background: var(--bg-3); }
.tray-leg .side { font-weight: 600; font-size: 11px; }
.tray-leg .side.buy { color: var(--green); }
.tray-leg .side.sell { color: var(--red); }
.tray-leg .exp { color: var(--muted); font-size: 11px; }

table.chain button.buy.on { background: var(--green); color: #0d1117; }
table.chain button.sell.on { background: var(--red); color: #0d1117; }

.builder-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.builder-controls label { flex-direction: row; align-items: center; gap: 6px; }
.builder .panel-header > .builder-controls { flex: 1; min-width: 0; flex-wrap: nowrap; }

/* Expiry chips; overflow goes behind the "+N ▾" button's popover. */
.expiry-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.exp-chips {
  display: flex;
  gap: 6px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.exp-chip {
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  background: var(--bg-3);
  color: var(--muted);
}
.exp-chip:hover { color: var(--text); }
.exp-chip.active { background: var(--blue); border-color: var(--blue); color: #0d1117; font-weight: 600; }
.exp-chip[hidden], .exp-pop[hidden] { display: none; }
.exp-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 6px;
  padding: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 18px #000a;
}
.builder-controls select { min-width: 110px; }

.chain-wrap {
  flex: 1;
  overflow: auto;
  /* Page is single-screen; cap chain to viewport minus topbar/header/padding
     so only this card scrolls, not the page. */
  max-height: calc(100vh - 200px);
}

table.chain {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
table.chain th, table.chain td {
  padding: 4px 8px;
  text-align: right;
  border-bottom: 1px solid #21262d;
}
table.chain thead th {
  position: sticky;
  top: 0;
  background: var(--bg-2);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
  z-index: 2;
}
table.chain td.strike-col {
  background: var(--bg-3);
  font-weight: 600;
  text-align: center;
}
table.chain .ltp { font-weight: 500; }
table.chain tr.atm td.strike-col {
  background: #d2992233;
  color: var(--yellow);
}
/* OI bars grow outward from the strike column: calls leftward, puts rightward. */
table.chain td.oi {
  position: relative;
  width: 18%;
  color: var(--text);
  font-size: 11px;
}
table.chain td.oi span { position: relative; z-index: 1; }
table.chain td.pe-oi,
table.chain th.oi-head { text-align: left; }
table.chain .oi-bar {
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 0;
  border-radius: 2px;
}
table.chain td.ce-oi .oi-bar { right: 0; background: #f8514955; }
table.chain td.pe-oi .oi-bar { left: 0; background: #3fb95055; }
table.chain .strike-actions {
  display: flex;
  gap: 4px;
  justify-content: center;
}

/* ── Simulation tab: Legs + ready-made Strategies row ──────────────── */

.sim-row { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 12px; align-items: start; }
@media (max-width: 1200px) { .sim-row { grid-template-columns: 1fr; } }

.st-exp {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}
.st-groups { padding: 8px 12px 12px; display: grid; gap: 10px; }
.st-group h3 {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}
.st-group h3.bullish { color: var(--green); }
.st-group h3.bearish { color: var(--red); }
.st-group h3.directional { color: var(--blue); }
.st-group h3.neutral { color: var(--yellow); }
.st-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.st-tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 6px 6px 5px;
  border-radius: 6px;
  background: var(--bg-3);
  text-align: center;
}
.st-tile:hover { border-color: var(--blue); }
.st-tile.active { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue) inset; }
.st-tile svg { width: 100%; height: 38px; }
.st-tile .name { font-size: 10.5px; line-height: 1.2; color: var(--text); }

/* ── Simulation tab: basket ────────────────────────────────────────── */

.basket-body-wrap {
  flex: 1;
  overflow: auto;
}
.strike-step {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.strike-step span { min-width: 52px; text-align: center; }
.strike-step button { padding: 0 5px; }
.basket-mult {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.basket-mult .label { margin-right: 4px; }
.basket-mult input { width: 48px; text-align: center; }

table.basket-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
table.basket-table th, table.basket-table td {
  padding: 5px 8px;
  text-align: left;
  font-size: 12px;
  border-bottom: 1px solid #21262d;
}
table.basket-table th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-2);
  position: sticky;
  top: 0;
}
table.basket-table td.side-buy { color: var(--green); font-weight: 600; }

/* Click-to-flip Side / Type cells in the legs table. */
table.basket-table button.flip {
  min-width: 48px;
  padding: 2px 8px;
  font-weight: 600;
  background: transparent;
  border: 1px dashed var(--border);
}
table.basket-table button.flip:hover { border-style: solid; background: var(--bg-3); }
table.basket-table button.flip.side-buy { color: var(--green); }
table.basket-table button.flip.side-sell { color: var(--red); }
table.chain td.greek { color: var(--muted); font-size: 11.5px; }
table.basket-table td.side-sell { color: var(--red); font-weight: 600; }

.qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.qty-stepper input {
  width: 50px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.basket-actions {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-3);
}
.basket-actions input { flex: 1; }
.empty-basket { color: var(--muted); padding: 16px; font-style: italic; text-align: center; }

/* ── Payoff ────────────────────────────────────────────────────────── */

.payoff-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.payoff-stats .stat {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
.payoff-stats .stat .label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.payoff-stats .stat .value {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.payoff-stats .stat .value.pos { color: var(--green); }
.payoff-stats .stat .value.neg { color: var(--red); }
.payoff-stats .stat .be-pct { color: var(--muted); font-weight: 500; font-size: 11px; }
.payoff-stats .empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 6px;
}
/* P&L-on-date control: slider + picker for the blue line. */
.time-ctl {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.time-ctl[hidden] { display: none; }
.time-ctl .label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.time-ctl .time-key {
  width: 16px;
  height: 0;
  border-top: 2px solid var(--blue);
}
.time-ctl input[type="range"] {
  flex: 1;
  min-width: 160px;
  accent-color: var(--blue);
  padding: 0;
  border: none;
  background: transparent;
}
.time-ctl input[type="datetime-local"] { color-scheme: dark; }

/* Scenario sliders: per underlying, IV shift (vol pts) and spot move (%). */
.scenario-ctl {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}
.scenario-ctl[hidden] { display: none; }
.scn-rows { flex: 1; display: grid; gap: 6px; }
.scn-row {
  display: grid;
  grid-template-columns: 64px 22px minmax(120px, 1fr) 130px 34px minmax(120px, 1fr) 130px;
  align-items: center;
  gap: 8px;
}
.scn-row .ul { font-weight: 600; font-size: 11px; }
.scn-row .label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.scn-row input[type="range"] { padding: 0; border: none; background: transparent; }
.scn-row input[data-scn="iv"] { accent-color: var(--yellow); }
.scn-row input[data-scn="spot"] { accent-color: #bc8cff; }
.scn-row .val { font-size: 11px; font-variant-numeric: tabular-nums; }
.scn-row .val.shifted { color: var(--text); font-weight: 600; }
.time-ctl #t-label { font-size: 11px; font-variant-numeric: tabular-nums; }

.payoff-chart-wrap {
  flex: 1;
  padding: 10px 12px 14px;
}
.payoff-canvas-box { position: relative; height: 420px; }
.payoff-canvas-box[hidden],
.payoff-3d[hidden],
.oi-legend[hidden],
.seg[hidden] { display: none; }
.payoff-3d { height: 560px; }

/* Segmented toggle (3D surface: at expiry / on date). */
.seg { display: inline-flex; margin-left: 12px; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 4px 0 0 4px; }
.seg button:last-child { border-radius: 0 4px 4px 0; border-left: none; }
.seg button.active { background: var(--blue); border-color: var(--blue); color: #0d1117; font-weight: 600; }

/* Underlying tag on legs in a NIFTY + SENSEX basket. */
.ul-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.3px;
}

.oi-legend {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  cursor: pointer;
}
.oi-legend input { margin: 0; }
.oi-legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-left: 4px;
}
.oi-legend .swatch.ce { background: #f8514988; }
.oi-legend .swatch.pe { background: #3fb95088; }

/* Leg pins: overlay on the chart; chips hang from the x-axis on stems.
   The overlay ignores the pointer so chart tooltips still work; chips opt back in. */
.strike-rail { position: absolute; inset: 0; pointer-events: none; }
.rail-stem {
  position: absolute;
  width: 0;
  border-left: 1px solid;
}
.rail-stem.buy { border-color: var(--green); }
.rail-stem.sell { border-color: var(--red); }
/* Chip: solid side colour, "Buy 22400C" + lots box, notch pointing up at
   the stem, expiry tab hanging under its left edge. */
.rail-chip {
  position: absolute;
  pointer-events: auto;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 7px 3px 9px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  cursor: grab;
  user-select: none;
  touch-action: none;
  z-index: 1;
  box-shadow: 0 1px 3px #0008;
}
.rail-chip::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top: 0;
  border-bottom-color: inherit;
}
.rail-chip.buy { background: #2ea043; border-color: #2ea043; }
.rail-chip.sell { background: #da3633; border-color: #da3633; }
.rail-chip .chip-lots {
  min-width: 16px;
  padding: 0 3px;
  border: 1px solid #ffffffb3;
  border-radius: 3px;
  font-size: 10.5px;
  line-height: 14px;
  text-align: center;
}
.rail-chip .chip-exp {
  position: absolute;
  top: 100%;
  left: 0;
  padding: 1px 5px;
  border-radius: 0 0 3px 3px;
  background: #0d1117;
  border: 1px solid var(--border);
  border-top: 0;
  color: var(--text);
  font-size: 10px;
  font-weight: 500;
}
.rail-chip.dragging { cursor: grabbing; z-index: 2; box-shadow: 0 0 0 3px #ffffff33, 0 2px 6px #000a; }
.payoff-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-style: italic;
}

/* ── Strategies ────────────────────────────────────────────────────── */

#strategies-list {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.strategy-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.strategy-card .head {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #1c2128;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.strategy-card .head .title { font-weight: 600; flex: 1; }
.strategy-card .head .pnl-box { display: flex; gap: 12px; font-size: 11px; }
.strategy-card .head .pnl-box .label { color: var(--muted); margin-right: 4px; }
.strategy-card.closed .head { background: #1a1d22; opacity: 0.65; }

table.legs {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
table.legs th, table.legs td {
  padding: 5px 10px;
  text-align: right;
  font-size: 12px;
  border-bottom: 1px solid #21262d;
}
table.legs th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
  background: #1c2128;
}
table.legs td.sym { text-align: left; font-family: SFMono-Regular, Menlo, monospace; font-size: 11px; }
table.legs td.side-buy { color: var(--green); }
table.legs td.side-sell { color: var(--red); }
table.legs tr.closed { opacity: 0.5; }

.strategy-actions {
  padding: 6px 12px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  background: #1a1d22;
  border-top: 1px solid var(--border);
}

/* ── Liquidity popover (☰ buttons) ─────────────────────────────────── */

.liq-btn { padding: 0 6px; line-height: 16px; color: var(--muted); }
.liq-btn:hover { color: var(--text); }
table.chain th.liq-head { text-align: center; }
.liq-pop {
  position: fixed;
  z-index: 50;
  min-width: 200px;
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 18px #000a;
  font-size: 12px;
}
.liq-pop[hidden] { display: none; }
.liq-title { font-size: 11px; color: var(--muted); margin-bottom: 6px; white-space: nowrap; }
.liq-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}
.liq-row span { color: var(--muted); }
.liq-row b.pos { color: var(--green); }
.liq-row b.neg { color: var(--red); }
.liq-pop .muted { color: var(--muted); font-weight: normal; }

/* ── Modals ─────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 720px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.modal-card.small { width: 380px; }
.modal-card.small .modal-body input { width: 100%; padding: 8px 10px; font-size: 14px; }
.modal-card.small .modal-body label { margin-top: 10px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 14px; }
.close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}
.close-btn:hover { color: var(--text); }
.modal-body { padding: 14px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* ── Analysis view ──────────────────────────────────────────────────── */

/* OI and Volume side by side; stack on narrow screens. */
.an-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .an-row { grid-template-columns: 1fr; } }
/* Half-width cards: let the expiry chips drop under the title when tight. */
.an-card .panel-header { flex-wrap: wrap; }
.an-exp { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.an-chart { position: relative; height: 300px; padding: 10px 12px 12px; }
#an-note { font-size: 11px; }

/* ── History view ───────────────────────────────────────────────────── */

.history-filters {
  display: flex;
  gap: 8px;
  align-items: center;
}
.history-filters label {
  flex-direction: row;
  align-items: center;
  gap: 4px;
}
.history-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.history-chart-panel { min-height: 280px; }
.history-chart-wrap {
  flex: 1;
  padding: 10px 12px 14px;
  min-height: 240px;
}
.history-chart-wrap canvas { max-height: 240px; }

.history-table-wrap {
  overflow: auto;
  max-height: 380px;
}
table.history-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
table.history-table th, table.history-table td {
  padding: 6px 10px;
  text-align: left;
  font-size: 12px;
  border-bottom: 1px solid #21262d;
}
table.history-table th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
table.history-table tr.row-clickable { cursor: pointer; }
table.history-table tr.row-clickable:hover { background: #1c2128; }
table.history-table td.action-OPEN  { color: var(--blue); }
table.history-table td.action-ADD   { color: var(--blue); }
table.history-table td.action-REDUCE,
table.history-table td.action-CLOSE { color: var(--yellow); }
table.history-table td.side-BUY  { color: var(--green); font-weight: 600; }
table.history-table td.side-SELL { color: var(--red); font-weight: 600; }

#fills-search { width: 220px; }
#detail-body table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
#detail-body th, #detail-body td { padding: 4px 8px; border-bottom: 1px solid #21262d; text-align: left; }
#detail-body th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
#detail-body .leg-section { margin-bottom: 14px; }
#detail-body .leg-section h4 { margin: 4px 0 4px 0; font-size: 12px; font-family: SFMono-Regular, Menlo, monospace; }

/* ── auth ─────────────────────────────────────────────────────────── */
.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
}
.user-pill img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-2);
}
.user-pill #user-email { color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  background: #0b0e13;
}
.login-overlay.hidden { display: none; }

/* Left rail — brand pitch on a deep gradient. */
.login-overlay .login-pitch {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 56px;
  background:
    radial-gradient(900px 600px at 20% 10%, rgba(31, 111, 235, 0.22), transparent 60%),
    radial-gradient(700px 500px at 80% 90%, rgba(63, 185, 80, 0.18), transparent 60%),
    linear-gradient(160deg, #0d1117 0%, #161b22 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text);
  overflow: hidden;
}
.login-overlay .login-pitch::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  mask-image: radial-gradient(ellipse at 30% 30%, #000 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 30% 30%, #000 30%, transparent 75%);
}
.login-overlay .login-brand {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.login-overlay .login-brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}
.login-overlay .login-pitch h1 {
  position: relative;
  z-index: 1;
  font-size: 44px;
  line-height: 1.08;
  margin: 0 0 18px 0;
  font-weight: 700;
  letter-spacing: -1px;
}
.login-overlay .accent-text {
  background: linear-gradient(135deg, #58a6ff 0%, #3fb950 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-overlay .lede {
  position: relative;
  z-index: 1;
  font-size: 15px;
  color: var(--muted);
  line-height: 1.55;
  margin: 0 0 32px 0;
  max-width: 460px;
}
.login-overlay .features {
  position: relative;
  z-index: 1;
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 14px;
  font-size: 14px;
}
.login-overlay .features li {
  display: flex;
  align-items: center;
  gap: 12px;
}
.login-overlay .features .check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(46, 160, 67, 0.18);
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.login-overlay .pitch-foot {
  position: relative;
  z-index: 1;
  margin-top: 48px;
  font-size: 12px;
  color: var(--muted);
}

/* Right rail — sign-in card. */
.login-overlay .login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px;
  background: var(--bg);
}
.login-overlay .login-card-inner {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-overlay .login-card h2 {
  font-size: 26px;
  margin: 0 0 8px 0;
  font-weight: 600;
  letter-spacing: -0.3px;
}
.login-overlay .login-card p {
  margin: 0 0 28px 0;
  font-size: 14px;
  color: var(--muted);
}
.login-overlay .google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 12px 18px;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: box-shadow 0.15s ease, background 0.15s ease;
}
.login-overlay .google-btn:hover {
  background: #f8faff;
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.15), 0 4px 12px rgba(60, 64, 67, 0.1);
}
.login-overlay .legal {
  margin-top: 22px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.55;
}
.login-overlay .login-footer {
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .login-overlay {
    grid-template-columns: 1fr;
  }
  .login-overlay .login-pitch {
    padding: 32px;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }
  .login-overlay .login-pitch h1 { font-size: 30px; }
  .login-overlay .login-card { padding: 32px; }
}
