:root {
  --bg: #0a0a0a;
  --panel: #171717;
  --panel-2: #262626;
  --line: #2e2e2e;
  --line-soft: #242424;
  --text: #fafafa;
  --text-2: #a3a3a3;
  --muted: #737373;
  --brand: #b72025; /* logo only; the interface accent is blue */
  --brand-text: #e5575c; /* the brand red, lightened to read on dark */
  --accent: #3b82f6;
  --flow: #3b82f6;
  --calls: #10b981;
  --puts: #f59e0b;
  --price: #fafafa;
  --buy: #10b981;
  --sell: #fb2c36;
  --warn: #f59e0b;
  --row-hl: rgba(59, 130, 246, 0.16);
  --chip-on: color-mix(in srgb, var(--accent) 20%, var(--panel));
  --seg-on: #404040;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f5f5f5;
  --line: #e5e5e5;
  --line-soft: #f0f0f0;
  --text: #0a0a0a;
  --text-2: rgba(29, 26, 34, 0.88);
  --muted: #737373;
  --brand-text: #b72025;
  --accent: #2570ea;
  --flow: #2962ff;
  --calls: #009966;
  --puts: #dd7400;
  --price: #0a0a0a;
  --buy: #009966;
  --sell: #dc2626;
  --warn: #dd7400;
  --row-hl: rgba(37, 112, 234, 0.1);
  --chip-on: #eff6ff;
  --seg-on: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); font-weight: 400; }
.spacer { flex: 1; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  height: 48px; padding: 0 16px;
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.01em; font-size: 15px; }
.brand b { color: var(--brand-text); font-weight: 700; }
.brand small { font-weight: 600; letter-spacing: 0.08em; color: var(--text-2); font-size: 12px; border-left: 1px solid var(--line); padding-left: 8px; }
.logo { width: 27px; height: 15px; flex: none; fill: var(--brand); }
.ticker-picker input {
  width: 220px; height: 32px; padding: 0 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  font-weight: 500;
}
.ticker-picker input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.pill {
  padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; border: 1px solid var(--line); color: var(--text-2);
}
.pill::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: 1px; }
.pill.live::before { background: var(--buy); box-shadow: 0 0 0 3px color-mix(in srgb, var(--buy) 25%, transparent); }
.pill.delayed::before, .pill.backfilling::before { background: var(--warn); }
.pill.down::before { background: var(--sell); }
.clock { font-family: var(--mono); color: var(--text-2); font-size: 12px; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) clamp(360px, 24vw, 960px);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "trend chart flow";
  gap: 8px; padding: 0 8px 8px; background: var(--bg);
  height: calc(100vh - 48px);
}
.layout.no-flow { grid-template-columns: 230px minmax(0, 1fr); grid-template-areas: "trend chart"; }
.trending { grid-area: trend; }
.chart-area { grid-area: chart; }
.flow { grid-area: flow; }
.trending, .chart-area, .flow { background: var(--panel); min-height: 0; min-width: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.panel-title { font-weight: 600; font-size: 14px; color: var(--text); padding: 10px 12px 6px; }
.panel-title .muted { font-size: 11px; margin-left: 4px; }

/* ---------- trending ---------- */
.trending { display: flex; flex-direction: column; }
.trend-list { overflow-y: auto; padding: 0 6px 8px; }
.tile {
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto auto; gap: 1px 8px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.tile:hover { background: var(--panel-2); }
.tile { position: relative; }
.tile .rm {
  position: absolute; top: 4px; right: 4px; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 4px;
  background: var(--panel); color: var(--muted); font-size: 13px; line-height: 18px; cursor: pointer; opacity: 0;
}
.tile:hover .rm, .tile .rm:focus-visible { opacity: 1; }
.tile .rm:hover { color: var(--sell); }
.watch-add { display: flex; gap: 6px; padding: 0 12px 8px; }
.watch-add input {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 12px; text-transform: uppercase;
}
.watch-add input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.tile.active { background: var(--chip-on); }
.tile.active .sym { color: var(--accent); }
.tile .sym { font-weight: 700; font-size: 12.5px; }
.tile .hv { font-family: var(--mono); font-weight: 600; text-align: right; }
.tile .px { color: var(--text-2); font-size: 11.5px; font-family: var(--mono); }
.tile .chg { font-size: 11.5px; text-align: right; font-family: var(--mono); }
.tile svg { grid-column: 1 / -1; width: 100%; height: 26px; display: block; }
.tile .score { grid-column: 1 / -1; height: 3px; background: var(--line-soft); border-radius: 2px; position: relative; overflow: hidden; }
.tile .score i { position: absolute; top: 0; bottom: 0; background: var(--flow); border-radius: 2px; }
.up { color: var(--buy); }
.down { color: var(--sell); }

/* ---------- chart ---------- */
.chart-area { display: flex; flex-direction: column; }
.toolbar { position: relative; z-index: 30; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); }
.seg { display: inline-flex; padding: 2px; background: var(--panel-2); border-radius: 8px; }
.seg button { background: none; border: 0; border-radius: 7px; padding: 3px 9px; cursor: pointer; color: var(--text-2); font-size: 12px; font-weight: 500; }
.seg button.on { background: var(--seg-on); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.ctl { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.ctl select, .flow-head select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; font-size: 12px;
}
.grid-pick { position: relative; display: inline-flex; }
.grid-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; cursor: pointer; display: inline-flex; }
.grid-btn:hover, .grid-btn[aria-expanded="true"] { background: var(--chip-on); }
.grid-icon { display: inline-grid; grid-template-columns: repeat(6, 1fr); grid-auto-rows: 1fr; gap: 1px; width: 18px; height: 14px; }
.grid-icon i { background: var(--text-2); border-radius: 1px; }
.grid-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; width: 148px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); }
.grid-menu[hidden] { display: none; }
.grid-table { display: grid; grid-template-columns: repeat(3, 40px); grid-auto-rows: 32px; gap: 4px; }
.grid-table button { background: none; border: 1px solid var(--line); border-radius: 3px; padding: 0; cursor: pointer; }
.grid-table button.on { background: color-mix(in srgb, var(--flow) 35%, transparent); border-color: var(--flow); }
.grid-label { margin: 8px 0; font-size: 12px; color: var(--text-2); text-align: center; font-family: var(--mono); }
.grid-five { width: 100%; display: flex; align-items: center; gap: 8px; background: none; border: 1px solid var(--line); border-radius: 4px; padding: 5px 8px; cursor: pointer; color: var(--text-2); font-size: 12px; }
.grid-five:hover, .grid-five.on { border-color: var(--flow); color: var(--text); }
.chart-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); gap: 1px; background: var(--line); overflow: hidden; }
.pane { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--panel); }
.pane.active::after { content: ""; position: absolute; inset: 0; border: 1px solid var(--accent); pointer-events: none; z-index: 4; }
.chart { position: absolute; inset: 0; display: flex; flex-direction: column; }
.chart > div { flex: 1; min-height: 0; position: relative; }
.chart > .pane-price { flex: 1.1; }
.chart > .pane-flow { flex: 1; border-top: 1px solid var(--line-soft); }
.chart-legend {
  position: absolute; z-index: 3; top: 8px; left: 12px; display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-2); pointer-events: none;
  background: color-mix(in srgb, var(--panel) 80%, transparent); padding: 2px 6px; border-radius: 4px;
}
.chart-legend b { color: var(--text); font-family: var(--mono); font-weight: 600; margin-left: 4px; }
.chart-legend .sw { margin-right: 5px; }
.chart-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); z-index: 2; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.sw-price { background: var(--price); height: 2px; vertical-align: 3px; }
.sw-flow { background: var(--flow); }
.sw-calls { background: var(--calls); }
.sw-puts { background: var(--puts); }


/* ---------- flow table ---------- */
.flow { display: flex; flex-direction: column; position: relative; }
.flow-head { display: flex; align-items: center; gap: 12px; padding: 4px 12px 4px 0; flex-wrap: wrap; }
.toggle { display: inline-flex; gap: 5px; align-items: center; font-size: 12px; color: var(--text-2); cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.on { background: var(--chip-on); border-color: var(--accent); }
.btn.link { background: none; border: 0; color: var(--accent); }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 4px 12px 8px; border-bottom: 1px solid var(--line-soft); }
.chips { display: inline-flex; gap: 4px; }
.chips button { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; font-size: 11.5px; cursor: pointer; color: var(--text-2); }
.chips button.on { background: var(--chip-on); border-color: var(--accent); color: var(--text); font-weight: 600; }
.filter-more { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 6px 12px 8px; border-bottom: 1px solid var(--line-soft); font-size: 12px; color: var(--muted); }
.filter-more input { width: 76px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 2px 6px; }
.cols-menu {
  position: absolute; right: 12px; top: 38px; z-index: 20; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; display: grid; grid-template-columns: repeat(3, auto); gap: 4px 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35); font-size: 12px;
}
.cols-menu label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.history-banner { display: flex; gap: 12px; align-items: center; padding: 4px 12px; background: color-mix(in srgb, var(--warn) 14%, transparent); font-size: 12px; }
.table-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-x: auto; }
.thead, .trow { display: flex; white-space: nowrap; }
.thead { position: sticky; top: 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; background: var(--panel); min-width: max-content; }
.thead .cell { padding: 6px 8px; }
.tbody { position: relative; flex: 1; overflow-y: auto; overflow-x: hidden; min-width: max-content; outline: none; }
.tspacer { width: 1px; }
.trow { position: absolute; left: 0; right: 0; height: 24px; align-items: center; font-family: var(--mono); font-size: 12px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.trow:hover { background: var(--panel-2); }
.trow.hl { background: var(--row-hl); }
.trow.cancelled { opacity: 0.45; text-decoration: line-through; }
.cell { padding: 0 8px; overflow: hidden; text-overflow: ellipsis; flex: none; }
.cell.r { text-align: right; }
.buy { color: var(--buy); font-weight: 600; }
.sell { color: var(--sell); font-weight: 600; }
.cp-c { color: var(--calls); font-weight: 600; }
.cp-p { color: var(--puts); font-weight: 600; }
.flag { display: inline-block; padding: 0 5px; border: 1px solid var(--line); border-radius: 3px; font-size: 10.5px; margin-right: 3px; color: var(--text-2); font-family: var(--font); }
.big { font-weight: 700; }
.new-chip {
  position: absolute; top: 34px; left: 50%; transform: translateX(-50%); z-index: 5;
  background: var(--accent); color: #fff; border: 0; border-radius: 999px; padding: 4px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}

/* ---------- narrow screens ---------- */
@media (hover: none) { .tile .rm { opacity: 1; } }
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(340px, 55vh) auto minmax(320px, 60vh); grid-template-areas: "chart" "trend" "flow"; height: auto; }
  .layout.no-flow { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(340px, 55vh) auto; grid-template-areas: "chart" "trend"; }
  .trend-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); max-height: 260px; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 8px; }
  .brand .word, .clock { display: none; }
  .brand small { border-left: 0; padding-left: 0; }
  .ticker-picker input { width: 120px; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "chart" "trend" "flow"; }
  .chart-grid { grid-template-columns: minmax(0, 1fr); grid-auto-rows: 300px; overflow: auto; }
  .pane { grid-column: 1 / -1 !important; }
  .toolbar, .filter-bar { padding-left: 16px; padding-right: 16px; }
}

/* ChartIQ: the app legend replaces panel titles. */
.chart .stx-panel-title, .chart .stx-btn-panel { display: none !important; }
