/* market-pulse screener. No external assets: system fonts only. */
:root {
  --bg: #0b0d10;
  --surface: #12161b;
  --raised: #171c23;
  --border: #232a33;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --up: #3ddc97;
  --down: #ff6b6b;
  --warn: #f5a524;
  --accent: #3ddc97;
  --accent-ink: #06231a;
  --key: #9fb3c8;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --s5: 48px;
  --r: 10px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
}
h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input { font: inherit; color: inherit; }

.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding-inline: var(--s3); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: var(--s2); top: -48px; z-index: 10;
  background: var(--accent); color: var(--accent-ink); padding: var(--s1) var(--s2); border-radius: 6px;
}
.skip:focus { top: var(--s2); }

/* ---- Masthead: the one allowed glow ---- */
.masthead {
  border-bottom: 1px solid var(--border);
  background: radial-gradient(600px 160px at 0% 0%, rgba(61, 220, 151, 0.10), transparent 70%);
}
.masthead-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3);
  padding-top: var(--s4); padding-bottom: var(--s3);
}
.wordmark {
  font: 600 28px/1.1 var(--mono);
  letter-spacing: -0.02em;
}
.wordmark::before { content: "\25B2"; color: var(--accent); font-size: 0.6em; margin-right: 0.45em; vertical-align: 0.25em; }
.tagline { color: var(--muted); margin-top: var(--s1); max-width: 62ch; }
.badge {
  flex: none;
  font: 500 13px/1 var(--mono);
  color: var(--warn);
  border: 1px solid rgba(245, 165, 36, 0.45);
  background: rgba(245, 165, 36, 0.08);
  padding: var(--s1) 12px;
  border-radius: 999px;
  white-space: nowrap;
  margin-top: 4px;
}
.badge.live { color: var(--accent); border-color: rgba(61, 220, 151, 0.45); background: rgba(61, 220, 151, 0.08); }

/* ---- Price tape ---- */
.tape { border-bottom: 1px solid var(--border); background: var(--surface); }
.tape-row { display: flex; align-items: center; gap: var(--s2); min-height: 48px; }
.tape-label {
  flex: none; display: flex; align-items: center; gap: var(--s1);
  font: 400 13px/1 var(--sans); color: var(--muted);
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.tape.on .pulse { background: var(--accent); }
.tape-list {
  display: flex; gap: var(--s3); overflow-x: auto; scrollbar-width: thin;
  padding: 12px 0; flex: 1; min-width: 0;
  font: 13px/1 var(--mono); font-variant-numeric: tabular-nums;
}
.tape-list li { flex: none; display: flex; gap: var(--s1); align-items: baseline; }
.tape-sym { color: var(--muted); }
.tape-px { color: var(--text); transition: color 600ms ease; }
.tape-px.up { color: var(--up); }
.tape-px.down { color: var(--down); }
.tape-px::after { display: inline-block; width: 1em; text-align: center; font-size: 10px; content: ""; }
.tape-px.up::after { content: "\25B2"; }
.tape-px.down::after { content: "\25BC"; }
.tape-status { color: var(--muted); font-size: 13px; padding: 12px 0; }

/* ---- Question form ---- */
main { padding-top: var(--s4); padding-bottom: var(--s5); }
.ask { margin-bottom: var(--s4); }
.ask-label { display: block; font-weight: 600; margin-bottom: var(--s1); }
.ask-row { display: flex; gap: var(--s1); }
.ask-row input {
  flex: 1; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 12px var(--s2); font: 16px/1.4 var(--mono);
}
.ask-row input::placeholder { color: var(--muted); }
.ask-row input:focus-visible { outline-offset: 0; border-color: var(--accent); border-radius: var(--r); }
#run {
  flex: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--r);
  padding: 12px var(--s3); font-weight: 600;
}
#run:hover { background: #5ae6a9; }
#run[aria-busy="true"] { opacity: 0.75; cursor: progress; }
.ask-note { color: var(--muted); font-size: 13px; margin-top: var(--s1); }
a { color: var(--accent); text-underline-offset: 2px; }

.examples { display: grid; grid-template-columns: 3fr 2fr; gap: var(--s2) var(--s3); margin-top: var(--s2); }
.example-title { color: var(--muted); font-size: 13px; margin-bottom: var(--s1); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s1); }
.chip {
  cursor: pointer; text-align: left;
  background: var(--raised); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; font: 13px/1.35 var(--mono); color: var(--text);
}
.chip:hover { border-color: #3a4552; }
.chip[aria-current="true"] { border-color: var(--accent); color: var(--accent); }
.chips.refusals .chip:hover { border-color: rgba(245, 165, 36, 0.5); }
.chips.refusals .chip[aria-current="true"] { border-color: var(--warn); color: var(--warn); }

/* ---- Section chrome ---- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); flex-wrap: wrap; margin-bottom: 12px; }
.section-head h2 { font-size: 17px; font-weight: 600; }
.section-meta { display: flex; flex-wrap: wrap; gap: 4px var(--s2); color: var(--muted); font: 13px/1.4 var(--mono); font-variant-numeric: tabular-nums; }
.section-meta b { color: var(--text); font-weight: 500; }

/* ---- Trace: question -> spec -> SQL ---- */
.trace { margin-bottom: var(--s4); }
.steps {
  display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.1fr) minmax(0, 1.3fr);
  gap: var(--s3); counter-reset: none;
}
.step {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: var(--s2); min-width: 0;
  display: flex; flex-direction: column;
}
/* connector between stages: a short line with the accent at its head */
.step + .step::before {
  content: ""; position: absolute; left: calc(-1 * var(--s3) - 1px); top: 26px;
  width: var(--s3); height: 1px; background: var(--border);
}
.step + .step::after {
  content: ""; position: absolute; left: -7px; top: 22px;
  border: 4px solid transparent; border-left: 6px solid var(--accent);
}
.step h3 { display: flex; align-items: center; gap: var(--s1); font-size: 15px; font-weight: 600; }
.step-n {
  display: inline-grid; place-items: center; width: 22px; height: 22px; flex: none;
  border: 1px solid var(--border); border-radius: 6px;
  font: 12px/1 var(--mono); color: var(--accent);
}
.step-note { color: var(--muted); font-size: 13px; margin-top: 4px; }
.step-body { margin-top: 12px; flex: 1; min-width: 0; }
.placeholder { color: var(--muted); font-size: 14px; }

.q-quote { font: 15px/1.5 var(--mono); overflow-wrap: anywhere; }
.q-quote::before { content: "\201C"; color: var(--muted); }
.q-quote::after { content: "\201D"; color: var(--muted); }
.q-explain { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }
.q-explain strong { color: var(--text); font-weight: 500; }

pre.code {
  margin: 0; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 12px; overflow: auto; max-height: 360px;
  font: 12.5px/1.55 var(--mono); tab-size: 2; white-space: pre;
}
pre.sql { white-space: pre-wrap; overflow-wrap: anywhere; }
.j-key { color: var(--key); }
.j-str { color: var(--accent); }
.j-num { color: var(--warn); }
.j-lit { color: var(--muted); font-style: italic; }
.j-pun { color: #7a8594; }

.s-kw { color: var(--key); font-weight: 600; }
.s-col { color: var(--text); }
.s-fn { color: var(--muted); }
.ph {
  color: var(--warn); font-weight: 600; border-radius: 3px; padding: 0 1px;
}
.ph sub { font-size: 0.72em; font-weight: 400; vertical-align: -0.2em; margin-left: 1px; }

.params { margin-top: 12px; }
.params-title { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.params ol { display: flex; flex-wrap: wrap; gap: 6px; }
.param {
  display: inline-flex; gap: 6px; align-items: baseline;
  background: var(--raised); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px var(--s1); font: 12.5px/1.4 var(--mono); font-variant-numeric: tabular-nums;
}
.param-i { color: var(--warn); }
.param-v { color: var(--text); }
.params-none { color: var(--muted); font-size: 13px; }
/* hovering a bound value lights up its placeholder, and vice versa */
.ph.lit, .param.lit { background: rgba(245, 165, 36, 0.16); }
.param.lit { border-color: rgba(245, 165, 36, 0.5); }

.blocked { color: var(--muted); font-size: 14px; border-left: 2px solid var(--warn); padding-left: 12px; }

/* ---- Results ---- */
.results-body {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  overflow: hidden;
}
.empty { color: var(--muted); padding: var(--s3); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
th, td { padding: 10px var(--s2); text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
thead th { color: var(--muted); font-weight: 500; font-size: 13px; background: var(--raised); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: 14px; }
td.sym { font: 600 14px var(--mono); color: var(--text); }
td.name { color: var(--text); }
td.sector { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat, .na { color: var(--muted); }
th.sorted::after { content: " \2193"; color: var(--accent); }
th.sorted.asc::after { content: " \2191"; }
/* keep the symbol visible while scrolling sideways on small screens */
th:first-child, td:first-child { position: sticky; left: 0; background: var(--surface); }
thead th:first-child { background: var(--raised); }

.refusal { padding: var(--s3); display: flex; gap: var(--s2); align-items: flex-start; border-left: 3px solid var(--warn); }
.refusal-icon {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid rgba(245, 165, 36, 0.5); color: var(--warn); font: 600 13px/1 var(--mono);
}
.refusal h3 { font-size: 15px; font-weight: 600; }
.refusal p { color: var(--muted); margin-top: 4px; max-width: 72ch; }
.refusal p.reason { color: var(--text); }
.error { padding: var(--s3); border-left: 3px solid var(--down); }
.error p + p { color: var(--muted); margin-top: 4px; }

.loading { color: var(--muted); padding: var(--s3); }

/* ---- Footer ---- */
.footer { padding-bottom: var(--s4); color: var(--muted); font-size: 13px; }
.footer p { border-top: 1px solid var(--border); padding-top: var(--s3); }

/* ---- Responsive ---- */
@media (max-width: 1000px) {
  .steps { grid-template-columns: 1fr; gap: var(--s2); }
  .step + .step::before { left: 27px; top: calc(-1 * var(--s2) - 1px); width: 1px; height: var(--s2); }
  .step + .step::after { left: 23px; top: -7px; border: 4px solid transparent; border-top: 6px solid var(--accent); }
}
@media (max-width: 720px) {
  .wrap { padding-inline: var(--s2); }
  .masthead-row { flex-direction: column; gap: 12px; padding-top: var(--s3); }
  .wordmark { font-size: 22px; }
  .examples { grid-template-columns: 1fr; }
  .ask-row { flex-direction: column; }
  #run { width: 100%; }
  th, td { padding: 8px 12px; }
  .tape-label #tape-source { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
