:root {
  --bg: #000;
  --panel: #07090c;
  --panel-2: #0d1117;
  --line: #1f2630;
  --line-2: #2b3440;
  --amber: #ffa028;
  --amber-dim: #b8731d;
  --text: #e6e6e6;
  --muted: #8a94a3;
  --label: #6fa8ff;
  --up: #2fd36b;
  --down: #ff4d4d;
  --flat: #c9c9c9;
  --hdr: #ff8a00;
  --hdr-text: #000;
  --accent: #ffd34d;
  --link: #8fc1ff;
  --font: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 12px/1.35 var(--font);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Top bar & command line ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  background: #050505;
  border-bottom: 1px solid var(--line-2);
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--amber); letter-spacing: 1px; white-space: nowrap; }
.brand span { color: var(--text); margin-left: 4px; font-weight: 400; }
.cmd { position: relative; flex: 1; display: flex; align-items: stretch; max-width: 900px; }
.cmd-pane {
  background: var(--amber);
  color: #000;
  font-weight: 600;
  padding: 4px 9px;
  display: grid;
  place-items: center;
}
#cmd {
  flex: 1;
  background: #111;
  border: 1px solid var(--amber-dim);
  border-left: 0;
  color: var(--accent);
  font: 600 14px var(--font);
  padding: 5px 10px;
  text-transform: uppercase;
  outline: none;
  min-width: 0;
}
#cmd::placeholder { color: #555; text-transform: none; font-weight: 400; font-size: 12px; }
#cmd:focus { border-color: var(--amber); }
.go {
  background: #1a7f37;
  border: 0;
  color: #fff;
  font-weight: 600;
  padding: 0 14px;
  cursor: pointer;
}
.go:hover { background: #22a046; }
.suggest {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  background: #0b0e13;
  border: 1px solid var(--amber-dim);
  max-height: 340px;
  overflow: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}
.suggest li { display: flex; gap: 10px; padding: 4px 10px; cursor: pointer; }
.suggest li b { color: var(--accent); min-width: 72px; }
.suggest li span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest li em { margin-left: auto; font-style: normal; color: var(--label); }
.suggest li.active, .suggest li:hover { background: #1b2230; }
.clocks { display: flex; gap: 14px; color: var(--muted); white-space: nowrap; }
.clocks b { color: var(--text); font-weight: 500; }
.clocks .open { color: var(--up); }
.clocks .closed { color: var(--down); }

/* ---- Ticker tape ---- */
.tape { overflow: hidden; background: #0a0a0a; border-bottom: 1px solid var(--line); height: 24px; }
.tape-inner { display: inline-flex; gap: 26px; padding: 4px 0; white-space: nowrap; animation: tape 90s linear infinite; }
.tape:hover .tape-inner { animation-play-state: paused; }
.tape-item { cursor: pointer; }
.tape-item b { color: var(--amber); font-weight: 500; margin-right: 6px; }
@keyframes tape { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ---- Pane grid ---- */
.grid { display: grid; gap: 3px; padding: 3px; min-height: 0; background: #000; }
.grid[data-layout='4'] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.grid[data-layout='2'] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.grid[data-layout='1'] { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.grid[data-layout='2'] .pane:nth-child(n + 3),
.grid[data-layout='1'] .pane:nth-child(n + 2) { display: none; }

.pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
}
.pane.active { border-color: var(--amber-dim); }
.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #13171d;
  border-bottom: 1px solid var(--line);
  padding: 0 0 0 0;
  height: 24px;
  flex: none;
}
.pane.active .pane-head { background: #1d1a12; }
.pane-num { background: #333; color: #fff; padding: 0 7px; height: 100%; display: grid; place-items: center; font-weight: 600; }
.pane.active .pane-num { background: var(--amber); color: #000; }
.pane-title { color: var(--amber); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pane-title small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.pane-tools { margin-left: auto; display: flex; gap: 2px; padding-right: 4px; align-items: center; }
.pane-tools .src { color: #5d6672; margin-right: 6px; white-space: nowrap; }
.pane-tools button { background: transparent; border: 1px solid transparent; color: var(--muted); cursor: pointer; padding: 0 6px; height: 18px; }
.pane-tools button:hover { color: var(--text); border-color: var(--line-2); }
.pane-body { flex: 1; min-height: 0; overflow: auto; position: relative; }
.pane-body::-webkit-scrollbar { width: 8px; height: 8px; }
.pane-body::-webkit-scrollbar-thumb { background: #2a313b; }

/* ---- Common blocks ---- */
.loading, .empty, .error { padding: 18px; color: var(--muted); }
.error { color: var(--down); }
.loading::after { content: '▌'; animation: blink 1s steps(1) infinite; margin-left: 2px; color: var(--amber); }
@keyframes blink { 50% { opacity: 0; } }

.section { padding: 6px 8px 10px; }
.section + .section { border-top: 1px solid var(--line); }
.sec-title { color: var(--hdr); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin: 2px 0 6px; display: flex; gap: 8px; align-items: baseline; }
.sec-title small { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }
.muted { color: var(--muted); }
.lbl { color: var(--label); }
.amber { color: var(--amber); }
.sens { color: #000; background: var(--amber); padding: 0 3px; font-weight: 600; margin-right: 4px; }

table.t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.t th { text-align: left; color: var(--label); font-weight: 500; border-bottom: 1px solid var(--line-2); padding: 3px 6px; position: sticky; top: 0; background: var(--panel); white-space: nowrap; }
table.t td { padding: 2px 6px; border-bottom: 1px solid #12161c; white-space: nowrap; }
table.t td.wrap { white-space: normal; }
table.t th.r, table.t td.r { text-align: right; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #141a22; }
table.t td.code { color: var(--accent); font-weight: 500; }
table.t tr.group td { color: var(--hdr); font-weight: 600; padding-top: 8px; border-bottom-color: var(--line-2); }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 14px; }
.kv div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dotted #1b2027; padding: 2px 0; }
.kv span:first-child { color: var(--label); }
.kv span:last-child { font-variant-numeric: tabular-nums; text-align: right; }

.quote-hero { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; padding: 8px; border-bottom: 1px solid var(--line); }
.quote-hero .nm { color: var(--amber); font-weight: 600; font-size: 14px; }
.quote-hero .px { font-size: 22px; font-weight: 600; }
.quote-hero .chg { font-size: 14px; }
.quote-hero .meta { color: var(--muted); }

.tabs { display: flex; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.tabs button { background: #151a21; border: 1px solid var(--line-2); color: var(--muted); padding: 1px 8px; cursor: pointer; }
.tabs button.on { background: var(--amber); color: #000; border-color: var(--amber); font-weight: 600; }
.tabs .sep { width: 10px; }
.tabs .note { margin-left: auto; color: var(--muted); }

.chart-wrap { position: absolute; inset: 31px 0 0 0; }
.chart-legend { position: absolute; top: 4px; left: 8px; z-index: 3; pointer-events: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart-legend b { color: var(--amber); }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.cols > .section { border-top: 0; border-right: 1px solid var(--line); }

/* Heatmap */
.heat { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px; }
.heat-group { display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--line); padding: 2px; flex: 1 1 auto; }
.heat-group h4 { margin: 0; padding: 1px 3px; color: var(--muted); font-weight: 500; font-size: 10px; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.heat-cells { display: flex; flex-wrap: wrap; gap: 2px; }
.heat-cell { display: flex; flex-direction: column; justify-content: center; align-items: center; color: #fff; cursor: pointer; overflow: hidden; font-size: 10px; line-height: 1.15; text-align: center; }
.heat-cell b { font-size: 11px; }
.heat-cell:hover { outline: 1px solid #fff; }

/* Sparkline + SVG charts */
svg.spark { display: block; }
.svgchart { width: 100%; display: block; }
.svgchart text { fill: var(--muted); font: 10px var(--font); }
.svgchart .grid line { stroke: #1a2028; }

.news-item { display: grid; grid-template-columns: 104px 1fr; gap: 8px; padding: 3px 8px; border-bottom: 1px solid #12161c; }
.news-item:hover { background: #10151c; }
.news-item time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.news-item .src { color: var(--label); margin-left: 6px; }

.brief { padding: 8px 12px; max-width: 820px; line-height: 1.5; }
.brief h1, .brief h2, .brief h3 { color: var(--hdr); font-size: 12px; text-transform: uppercase; margin: 12px 0 4px; }
.brief ul { margin: 2px 0; padding-left: 18px; }
.brief p { margin: 4px 0; }
.brief strong { color: var(--accent); }

.help { padding: 8px 12px; }
.help table td:first-child { color: var(--accent); white-space: nowrap; }
.help kbd { background: #222; border: 1px solid #444; padding: 0 4px; }

.bar { height: 10px; background: #1d2633; position: relative; }
.bar i { position: absolute; top: 0; bottom: 0; background: var(--amber); }
.range52 { display: flex; align-items: center; gap: 6px; }
.range52 .bar { flex: 1; min-width: 60px; }
.range52 .bar i { width: 2px; background: var(--accent); }

.consensus { display: flex; height: 16px; margin: 4px 0; }
.consensus div { display: grid; place-items: center; color: #000; font-weight: 600; font-size: 10px; }

.statusbar {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 3px 10px;
  background: #050505;
  border-top: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}
.statusbar .disclaimer { margin-left: auto; overflow: hidden; text-overflow: ellipsis; }
.layout-btns button { background: #151a21; border: 1px solid var(--line-2); color: var(--muted); cursor: pointer; padding: 0 6px; }
.layout-btns button.on { color: #000; background: var(--amber); }

@media (max-width: 900px) {
  body { overflow: auto; }
  .grid[data-layout] { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: 70vh; }
  .grid[data-layout] .pane { display: flex !important; }
  .clocks, .statusbar { display: none; }
  body { grid-template-rows: auto auto 1fr; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; }
  .tabs button { flex: none; }
}

.fnbtn { background: #151a21; border: 1px solid var(--line-2); color: var(--accent); padding: 2px 10px; margin: 2px 2px 0 0; cursor: pointer; font-weight: 600; }
.fnbtn:hover { background: var(--amber); color: #000; }
.cols > .section { min-width: 0; overflow-x: auto; }

.toast { position: absolute; top: 30px; right: 8px; z-index: 20; background: #1a7f37; color: #fff; font-weight: 600; padding: 6px 12px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6); pointer-events: none; animation: toast-in 0.15s ease-out; }
.toast.warn { background: #7a5200; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-4px); } }
