:root {
  /* Webull-style dark palette */
  --bg: #0e0f13;
  --panel: #17181d;
  --panel-2: #1f2027;
  --head: #1c1d23;
  --line: #26272e;
  --line-2: #33353d;
  --text: #e7e8eb;
  --dim: #8d909b;
  --faint: #5d606a;
  --accent: #2f7bff;
  --accent-dim: #24406f;
  --accent-bg: #15233d;
  --blue: #2f7bff;
  --up: #00b97b;
  --up-2: #0c3d2c;
  --dn: #f6465d;
  --dn-2: #4a1c24;
  --warn: #f0b90b;
  --mono: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 12.5px/1.45 var(--sans); font-variant-numeric: tabular-nums; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.dim { color: var(--dim); }
.up { color: var(--up); } .dn { color: var(--dn); } .accent { color: var(--accent); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  height: 38px; padding: 0 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 6px; }
.logo { background: var(--accent); color: #fff; font-weight: 700; padding: 2px 7px; border-radius: 4px; letter-spacing: .5px; }
.brand-sub { color: var(--text); letter-spacing: 2px; font-weight: 600; }
.clock { color: var(--text); font-weight: 600; min-width: 98px; }
.pill { padding: 2px 10px; border-radius: 12px; background: var(--panel-2); color: var(--dim); white-space: nowrap; font-size: 11.5px; }
.pill.rth { background: var(--up-2); color: var(--up); }
.pill.globex { background: var(--accent-bg); color: var(--blue); }
.pill.closed { background: var(--dn-2); color: var(--dn); }
.next-event { color: var(--warn); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 38vw; }
.spacer { flex: 1; }
.status { color: var(--dim); white-space: nowrap; }
.status.busy { color: var(--accent); }
.status.err { color: var(--dn); }
.btn {
  height: 28px; padding: 0 12px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 4px;
  cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--dn); }
.btn.warn { background: #3a2e05; color: var(--warn); border-color: #6b5408; font-weight: 600; }
.connect p { margin: 6px 0 10px; line-height: 1.55; }
.connect ol { margin: 0; padding-left: 20px; }
.connect li { margin: 0 0 14px; line-height: 1.55; }
.connect a { color: var(--accent); text-decoration: underline; }
.code-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.code-row input { flex: 1; margin: 0 !important; }
#connect input, #connect textarea { display: block; width: 100%; padding: 6px 8px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 4px; color: var(--text); }
#connect textarea { font: 11px var(--mono); white-space: pre; resize: vertical; }
#connectResult.ok { color: var(--up); } #connectResult.err { color: var(--dn); }
.btn .key { display: inline-block; padding: 0 3px; margin-right: 3px; border: 1px solid currentColor; font-size: 10px; line-height: 13px; }
.btn.spin { opacity: .7; pointer-events: none; }

.tape { height: 34px; background: var(--panel); border-bottom: 1px solid var(--line); overflow: hidden; position: relative; }
.tape-track { display: inline-flex; white-space: nowrap; height: 100%; align-items: center; animation: tape linear infinite; }
.tape:hover .tape-track { animation-play-state: paused; }
.tk { padding: 0 18px; border-right: 1px solid var(--line); font-size: 12.5px; }
.tk b { color: var(--text); font-weight: 600; margin-right: 4px; }
.tape-msg { line-height: 34px; padding: 0 12px; color: var(--dim); }
@keyframes tape { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.conn-help { margin: 0 0 8px; padding: 10px 12px; border: 1px solid var(--accent-dim); background: var(--accent-bg); border-radius: 6px; line-height: 1.55; }
.conn-help b { color: var(--text); }

/* ---------- grid / panels ---------- */
.grid {
  display: grid; grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 8px; padding: 8px; align-items: stretch;
}
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; }
.span-7 { grid-column: span 7; } .span-12 { grid-column: span 12; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.panel.tall { height: 560px; }
.ph {
  display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 3px 10px;
  background: var(--head); border-bottom: 1px solid var(--line);
  color: var(--text); font-weight: 600; font-size: 13px; letter-spacing: .2px; white-space: nowrap;
}
.fn { background: var(--accent-bg); color: var(--accent); padding: 1px 6px; border-radius: 3px; font-size: 10.5px; font-weight: 700; }
.ph-sub { color: var(--dim); font-weight: 400; font-size: 11.5px; letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; }
.ph-tools { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.pb { padding: 6px 8px; min-height: 0; }
.pb.flush { padding: 0; flex: 1; }
.pb.scroll { overflow: auto; flex: 1; }
.mini {
  height: 24px; padding: 0 9px; font-size: 11.5px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 4px;
  color: var(--dim); cursor: pointer;
}
.mini:hover { color: var(--text); border-color: var(--accent); }
.mini.on { color: #fff; background: var(--accent); border-color: var(--accent); }
.mini.accent { color: var(--accent); border-color: var(--accent-dim); }
.mini.search { width: 140px; cursor: text; color: var(--text); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th {
  text-align: right; color: var(--dim); font-weight: 400; font-size: 11px;
  padding: 3px 6px; border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
.tbl td { text-align: right; padding: 6px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl tr.row { cursor: pointer; }
.tbl tr.row:hover td { background: var(--panel-2); }
.tbl tr.sel td { background: var(--accent-bg); }
.tbl tr.sel td:first-child { box-shadow: inset 2px 0 var(--accent); }
.sym { color: var(--text); font-weight: 700; }
.sym small { color: var(--faint); font-weight: 400; margin-left: 4px; }
.last { font-weight: 600; }
.tag {
  display: inline-block; padding: 0 5px; font-size: 10.5px; border: 1px solid var(--line-2); color: var(--dim);
}
.tag.up2 { background: var(--up-2); color: #b9ffd9; border-color: var(--up); }
.tag.up1 { color: var(--up); border-color: var(--up-2); }
.tag.dn2 { background: var(--dn-2); color: #ffd0d3; border-color: var(--dn); }
.tag.dn1 { color: var(--dn); border-color: var(--dn-2); }
.tag.flat { color: var(--warn); border-color: #5c4c10; }
.lvl { color: var(--dim); font-size: 11px; }
.lvl b { font-weight: 500; color: var(--text); }
.lvl .brk { color: var(--warn); }
.rangebar { position: relative; width: 60px; height: 6px; background: var(--line-2); border-radius: 3px; display: inline-block; vertical-align: middle; }
.rangebar i { position: absolute; top: -2px; width: 3px; height: 10px; background: var(--accent); }
.stale { color: var(--faint); }
.spark { display: block; }

.detail { margin-top: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); font-size: 12.5px; }
.detail h4 { margin: 0 0 6px; font-weight: 600; font-size: 13px; color: var(--text); }
.detail p { margin: 3px 0; color: #d6d6d6; }

/* ---------- brief ---------- */
.brief h5 { margin: 12px 0 4px; font-weight: 600; font-size: 11px; color: var(--accent); letter-spacing: .6px; }
.brief h5:first-child { margin-top: 0; }
.brief .toneline { font-size: 13px; font-weight: 600; }
.brief ul { margin: 0; padding-left: 14px; font-family: var(--sans); }
.brief li { margin: 2px 0; }
.brief .fline { font-size: 12px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.brief .theme { margin: 4px 0 6px; }
.brief .theme b { color: var(--text); }
.ai-out { white-space: pre-wrap; font-size: 12.5px; padding: 10px; border: 1px solid var(--accent-dim); border-radius: 6px; background: var(--accent-bg); margin-bottom: 8px; }

/* ---------- news ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 1px solid transparent; color: var(--dim); padding: 1px 6px; cursor: pointer; font-size: 11px; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: #fff; background: var(--accent); border-radius: 3px; }
.tabs button .n { opacity: .7; margin-left: 3px; }
.news-item { display: grid; grid-template-columns: 54px 1fr; gap: 6px; padding: 7px 2px; border-bottom: 1px solid var(--line); }
.news-item .t { color: var(--dim); font-size: 11px; }
.news-item .t .d { display: block; color: var(--faint); font-size: 10px; }
.news-item .h { font-family: var(--sans); font-size: 12.5px; line-height: 1.35; }
.news-item.hi .h { font-weight: 600; }
.news-item.hi .t { color: var(--dn); }
.news-item.new { background: var(--accent-bg); }
.news-item .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; font-size: 10.5px; color: var(--faint); }
.news-item .meta .src { color: var(--blue); }
.news-item .meta .ft { color: var(--accent); opacity: .75; }
.news-item .meta .flag { color: var(--dn); font-weight: 600; }
.news-item .meta .flag.mid { color: #ff9f2e; }
.news-item .meta .flag.pend { color: var(--blue); font-weight: 500; }
.news-item .meta .flag.low { color: var(--dim); font-weight: 400; }
.tier { display: inline-block; padding: 0 5px; border-radius: 3px; font-size: 10px; font-weight: 700; line-height: 15px; }
.tier.hi { background: var(--dn-2); color: #ff8a97; }
.tier.mid { background: #4a3210; color: #ffb35c; }
.tier.low { background: var(--panel-2); color: var(--dim); }
.tier.pend { background: var(--accent-bg); color: var(--blue); }
.ai-out.err { border-color: var(--dn-2); background: #2a1216; color: #ffb3bb; }
.ai-out.stale { opacity: .6; }
.ai-hint { margin-bottom: 8px; padding: 8px 10px; border: 1px dashed var(--line-2); border-radius: 6px; color: var(--dim); }
.closed-note { margin-bottom: 6px; padding: 6px 10px; border-radius: 6px; background: var(--dn-2); color: #ffc2c8; font-size: 12px; }
.wk-sum { margin-bottom: 8px; font-size: 12.5px; }
.wk-day { display: grid; grid-template-columns: 112px 1fr; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.wk-day.today .wk-date { color: var(--accent); }
.wk-date { font-weight: 700; font-size: 11.5px; letter-spacing: .4px; color: var(--text); padding-top: 1px; }
.wk-ev { padding: 1px 0; }
.wk-ev.hi .wk-n { font-weight: 600; }
.wk-ev.mid { color: #c9cbd2; }
.wk-ev.past { opacity: .45; }
.wk-ev.none, .wk-ev.hol { color: var(--dim); }
.wk-ev.earn { color: var(--warn); }
.wk-t { display: inline-block; min-width: 44px; color: var(--dim); }
.est { font-size: 10px; padding: 0 4px; border: 1px dashed var(--line-2); border-radius: 3px; color: var(--dim); }
.update-note { padding: 8px 10px; border-radius: 6px; background: #3a2e05; color: #ffe08a; }

/* ---------- earnings / calendar ---------- */
.egroup h5 { margin: 10px 0 3px; font-weight: 600; font-size: 11.5px; color: var(--accent); }
.egroup h5:first-child { margin-top: 0; }
.egroup .none { color: var(--faint); font-size: 11px; padding: 2px 0 4px; }
.star { color: var(--warn); }
.cal-row.past td { color: var(--faint); }
.cal-row.soon td { background: var(--accent-bg); }
.cal-row.today td:first-child { box-shadow: inset 2px 0 var(--accent); }
.impact { display: inline-block; width: 8px; height: 8px; margin-right: 4px; }
.impact.High { background: var(--dn); } .impact.Medium { background: #ff9f2e; } .impact.Low { background: var(--warn); }

/* ---------- indices ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.tile { padding: 7px 9px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; }
.tile .l { color: var(--dim); font-weight: 600; font-size: 11px; display: flex; justify-content: space-between; }
.tile .v { font-size: 14px; font-weight: 600; }
.tile .c { font-size: 11px; }

/* ---------- breadth & sectors ---------- */
.ad-sum { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; padding: 4px 2px 8px; font-size: 11px; }
.ad-n { font-size: 20px; font-weight: 700; }
.ad-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line); margin-bottom: 8px; }
.ad-bar .a { background: var(--up); } .ad-bar .u { background: var(--faint); } .ad-bar .d { background: var(--dn); }
.ad-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ad-h { font-weight: 700; font-size: 11px; padding: 2px 0 4px; }
.ad-cols .tbl td, .sect-t td { padding: 4px 5px; }
.sect-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.sect { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.sect-h { display: flex; justify-content: space-between; gap: 6px; padding: 5px 8px; font-weight: 600; border-bottom: 1px solid var(--line); }
.sect-t td { border-bottom: 1px solid var(--line); }
.sect-t tr:last-child td { border-bottom: 0; }

/* ---------- misc ---------- */
.msg { color: var(--faint); padding: 10px 2px; }
.msg.err { color: var(--dn); }
.skeleton { color: var(--faint); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.statusbar {
  display: flex; gap: 16px; flex-wrap: wrap; padding: 4px 10px; border-top: 1px solid var(--line);
  color: var(--faint); font-size: 11px;
}
.statusbar .err { color: var(--dn); }

/* ---------- modal ---------- */
.modal { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 8px; padding: 0; width: min(920px, 96vw); max-height: 92vh; }
.modal.small { width: min(440px, 94vw); }
.modal::backdrop { background: rgba(0,0,0,.7); }
.modal form { display: flex; flex-direction: column; max-height: 92vh; }
.modal-h { display: flex; align-items: center; gap: 8px; padding: 10px 14px; color: var(--text); font-weight: 600; border-bottom: 1px solid var(--line); }
.modal-h .mini { margin-left: auto; }
.modal-b { overflow: auto; padding: 8px 12px; }
.modal-f { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line); }
fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 0 0 10px; padding: 8px 10px; }
legend { color: var(--accent); padding: 0 4px; }
legend .dim { font-size: 11px; }
label { display: block; color: var(--dim); margin: 4px 0; }
label.row { display: flex; gap: 6px; align-items: center; }
fieldset input:not([type=checkbox]), fieldset select, fieldset textarea {
  display: block; width: 100%; margin-top: 2px; padding: 6px 8px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 4px; color: var(--text);
}
textarea { resize: vertical; font: 11.5px var(--mono); white-space: pre; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.checks label { display: flex; gap: 5px; align-items: center; margin: 0; color: var(--text); }
.hint { color: var(--faint); margin: 4px 0 0; font-size: 11px; }
code { color: var(--accent); }
.keys div { padding: 3px 0; } .keys b { display: inline-block; min-width: 90px; color: var(--accent); }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .span-4, .span-5, .span-7 { grid-column: span 12; }
  .next-event { display: none; }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 6px 10px; }
  .status, .brand-sub { display: none; }
  .panel.tall { height: 480px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ph { flex-wrap: wrap; padding-top: 5px; padding-bottom: 5px; }
  .ph-sub { white-space: normal; }
  .ad-sum { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ad-cols { grid-template-columns: 1fr; }
}
