/* =============================================================================
   OPTIONS TERMINAL
   ========================================================================== */
html, body.app { height: 100%; }
body.app { display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }

/* ---------- top bar ---------- */
.app-nav {
  flex: none; height: 56px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(8,10,17,0.9); backdrop-filter: blur(10px);
  z-index: 40;
}
.app-nav .brand-name { font-size: 16px; }
.term-tag { font-size: 9.5px; letter-spacing: 0.18em; color: var(--accent);
  border: 1px solid var(--accent-line); border-radius: var(--r-xs); padding: 2px 6px; margin-left: 8px; }
.app-nav-mid { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); }
.app-nav-right { display: flex; align-items: center; gap: 12px; }
.app-net { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2);
  height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-pill); }
.net-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.feed-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-4); }
.feed-dot.live { background: var(--up); box-shadow: 0 0 8px var(--up); }
.feed-dot.sim { background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
#connectBtn.connected { background: rgba(255,255,255,0.05); color: var(--text); border: 1px solid var(--line-2); box-shadow: none; }

/* ---------- body grid ---------- */
.app-body {
  flex: 1 1 auto; min-height: 0; min-width: 0;
  display: grid; grid-template-columns: 232px minmax(0, 1fr) 376px;
  grid-auto-rows: minmax(0, auto);
  gap: 1px; background: var(--line);
}
.rail, .chain-panel, .ticket-panel { background: var(--bg); min-height: 0; min-width: 0; display: flex; flex-direction: column; }

/* ---------- rail ---------- */
.rail-head, .rail-foot { flex: none; padding: 13px 16px; font-size: 11px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-3); }
.rail-head { border-bottom: 1px solid var(--line); }
.rail-list { flex: 1 1 auto; overflow-y: auto; padding: 6px; }
.rail-item {
  width: 100%; display: grid; grid-template-columns: 1fr auto; grid-auto-rows: auto;
  gap: 2px 8px; align-items: center; text-align: left;
  padding: 9px 11px; border-radius: var(--r-sm); transition: background .14s;
}
.rail-item:hover { background: rgba(255,255,255,0.03); }
.rail-item.active { background: var(--accent-soft); }
.rail-item .ri-sym { font-weight: 600; font-size: 13.5px; }
.rail-item .ri-px { font-size: 12px; color: var(--text-2); text-align: right; }
.rail-item .ri-d { font-size: 11px; grid-column: 2; }
.rail-foot { border-top: 1px solid var(--line); display: flex; justify-content: space-between; text-transform: none; letter-spacing: 0; }
.rail-foot span { color: var(--text); }

/* ---------- chain ---------- */
.mkt-header { flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px; border-bottom: 1px solid var(--line); }
.mh-left { display: flex; align-items: baseline; gap: 10px; }
.mh-sym { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.mh-name { font-size: 13px; color: var(--text-3); }
.mh-right { display: flex; align-items: baseline; gap: 12px; }
.mh-spot { font-size: 20px; font-weight: 500; }
.mh-right .delta { font-size: 14px; }

/* price chart */
.chart-wrap { flex: none; padding: 11px 16px 12px; border-bottom: 1px solid var(--line); }
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.chart-ranges { display: flex; gap: 3px; }
.chart-ranges button { padding: 4px 10px; border-radius: var(--r-xs); font-size: 11.5px;
  color: var(--text-3); border: 1px solid transparent; transition: all .14s; }
.chart-ranges button:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.chart-ranges button.active { background: var(--accent-soft); color: var(--accent); }
.chart-src { font-size: 10.5px; letter-spacing: 0.02em; color: var(--text-4); }
#priceChart { width: 100%; height: 158px; display: block; cursor: crosshair; }

.chain-title { flex: none; padding: 12px 16px 2px; font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-3); }

.expiry-tabs { flex: none; display: flex; gap: 4px; padding: 8px 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.exp-tab { display: inline-flex; align-items: baseline; gap: 6px; padding: 7px 13px; border-radius: var(--r-pill);
  font-size: 12.5px; color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; transition: all .15s; }
.exp-tab:hover { border-color: var(--line-2); color: var(--text); }
.exp-tab.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.exp-tab .exp-d { font-size: 10px; opacity: 0.6; }

.chain-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: auto; }
.chain-table { width: 100%; min-width: 440px; border-collapse: collapse; font-size: 12.5px; }
.chain-table thead th { position: sticky; top: 0; background: var(--bg-2); z-index: 1;
  padding: 9px 12px; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-3); font-weight: 500; text-align: right; border-bottom: 1px solid var(--line); }
.chain-table th.side-lbl.call { text-align: left; color: var(--up); }
.chain-table th.side-lbl.put { color: var(--text-2); }
.chain-table th.strike-col { text-align: center; }
.crow { border-bottom: 1px solid rgba(255,255,255,0.03); }
.crow .c { padding: 8px 12px; text-align: right; cursor: pointer; transition: background .1s; }
.crow .call-cell:first-child { text-align: left; }
.crow .c.dim { color: var(--text-3); }
.crow .c.call-cell:not(.dim) { color: var(--up); }
.crow .c.put-cell:not(.dim) { color: var(--text); }
.crow .c.itm { background: rgba(255,255,255,0.02); }
.crow .strike { text-align: center; color: var(--text-2); font-weight: 600; background: rgba(255,255,255,0.02); cursor: default; }
.crow:hover .call-cell, .crow:hover .put-cell { background: rgba(255,255,255,0.03); }
.crow .call-cell:hover, .crow .put-cell:hover { background: var(--accent-soft) !important; color: var(--accent) !important; }
.crow.atm .strike { color: var(--accent); background: var(--accent-soft); }
.crow.sel { background: rgba(87,235,208,0.05); }

/* ---------- ticket ---------- */
.ticket-panel { border-left: none; }
.ticket { flex: 1 1 auto; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.ticket-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ticket-sides button { padding: 10px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--line); color: var(--text-2); transition: all .14s; }
.ticket-sides button:hover { border-color: var(--line-2); color: var(--text); }
.ticket-sides button[data-side="buyCall"].active, .ticket-sides button[data-side="buyPut"].active { background: var(--up-soft); border-color: rgba(47,224,160,0.4); color: var(--up); }
.ticket-sides button[data-side="sellCall"].active, .ticket-sides button[data-side="sellPut"].active { background: var(--down-soft); border-color: rgba(255,93,110,0.4); color: var(--down); }

.ticket-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ticket-row label { font-size: 12.5px; color: var(--text-3); }
.ticket-row select { flex: 1; max-width: 190px; height: 38px; padding: 0 12px; text-align: right;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 13px; }
.qty { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.qty button { width: 34px; height: 38px; background: var(--surface); font-size: 16px; color: var(--text-2); }
.qty button:hover { background: var(--surface-2); color: var(--text); }
.qty input { width: 60px; height: 38px; text-align: center; background: var(--bg); border: none; border-inline: 1px solid var(--line); font-size: 14px; }
.qty input::-webkit-outer-spin-button, .qty input::-webkit-inner-spin-button { -webkit-appearance: none; }

.ticket-metrics { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 6px 14px; }
.tm-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.tm-row:last-of-type { border-bottom: none; }
.tm-l { color: var(--text-3); }
.tm-v { color: var(--text); font-weight: 500; }
.tm-v.up { color: var(--up); }
.tm-v.down { color: var(--down); }
.tm-greeks { display: flex; justify-content: space-between; gap: 8px; padding: 12px 2px 4px; margin-top: 4px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-3); }
.tm-greeks b { color: var(--text); font-weight: 600; margin-left: 3px; }

.payoff-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px; }
.payoff-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); margin-bottom: 6px; }
#payoff { width: 100%; display: block; }

.place-btn { width: 100%; height: 48px; font-size: 14.5px; }
.ticket-note { text-align: center; font-size: 11px; color: var(--text-4); }

/* ---------- positions ---------- */
.positions { flex: none; height: 232px; border-top: 1px solid var(--line); display: flex; flex-direction: column; background: var(--bg-2); }
.pos-summary { flex: none; display: flex; gap: 0; border-bottom: 1px solid var(--line); }
.ps { flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 14px 20px; border-right: 1px solid var(--line); }
.ps:last-child { border-right: none; }
.ps-l { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.ps-v { font-size: 18px; font-weight: 600; }
.ps-v.up { color: var(--up); } .ps-v.down { color: var(--down); }
.pos-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: auto; }
.pos-table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 12.5px; }
.pos-table thead th { position: sticky; top: 0; background: var(--bg-2); text-align: right; padding: 10px 16px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); font-weight: 500; border-bottom: 1px solid var(--line); }
.pos-table thead th:first-child, .pos-table thead th:nth-child(2) { text-align: left; }
.prow td { padding: 10px 16px; text-align: right; border-bottom: 1px solid rgba(255,255,255,0.03); }
.prow td:first-child, .prow td:nth-child(2) { text-align: left; }
.prow .p-sym { font-weight: 600; }
.close-x { color: var(--text-4); font-size: 12px; padding: 4px 6px; border-radius: var(--r-xs); }
.close-x:hover { color: var(--down); background: var(--down-soft); }
.pos-empty td { text-align: center !important; color: var(--text-4); padding: 34px; font-size: 13px; }

/* ---------- toast ---------- */
.toast-host { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { padding: 12px 16px; border-radius: var(--r-md); font-size: 13px; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text);
  box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(10px); transition: all .3s var(--ease); max-width: 320px; }
.toast.in { opacity: 1; transform: none; }
.toast.up { border-color: rgba(47,224,160,0.4); }
.toast.down { border-color: rgba(255,93,110,0.4); }
.toast.muted { color: var(--text-2); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  body.app { overflow-x: hidden; overflow-y: visible; height: auto; }
  .app-body { grid-template-columns: minmax(0, 1fr); }
  .positions { min-width: 0; }
  .rail { flex-direction: column; }
  .rail-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); max-height: 200px; }
  .ticket-panel { order: 3; }
  .positions { height: auto; }
}
@media (max-width: 620px) {
  .app-nav-mid { display: none; }
  .app-net { display: none; }
  .pos-summary { flex-wrap: wrap; }
  .ps { min-width: 50%; }
  /* chain -> exact 3-column grid rows (Calls | Strike | Puts), no table quirks */
  .chain-scroll { overflow-x: hidden; }
  .chain-table th:nth-child(2), .chain-table th:nth-child(3),
  .chain-table th:nth-child(5), .chain-table th:nth-child(6),
  .crow .c.dim { display: none; }
  .chain-table, .chain-table thead, .chain-table tbody { display: block; width: 100%; min-width: 0; }
  .chain-table thead tr, .crow { display: grid; grid-template-columns: minmax(0,1fr) 84px minmax(0,1fr); align-items: center; }
  .chain-table thead th, .crow .c { padding: 12px 14px; font-size: 13.5px; }
  .pos-scroll { overflow-x: auto; }
}
