/* ── The Brain · Home view ──────────────────────────────────────────────────
   One bold element (the Ask The Brain band), then a quiet briefing that reads
   top-down: pulse → hourly curve + signals → channels / regions / movers →
   market radar + pins → governance disclosure. All tokens are --tb-* (tokens.css),
   which also carries the dark palette for the whole platform. */

#app[data-view="home"] .main { background: var(--tb-bg); color: var(--tb-fg); }

.view.view-home {
  max-width: 1480px;
  padding-block: 24px 56px;
  padding-left: 28px;
  padding-right: max(28px, env(safe-area-inset-right, 0px));
}
[dir="rtl"] .view.view-home { padding-right: 28px; padding-left: max(28px, env(safe-area-inset-left, 0px)); }

.bh {
  display: flex;
  flex-direction: column;
  gap: 22px;
  font: 14.5px/1.5 var(--tb-f);
  font-variant-numeric: tabular-nums;
  color: var(--tb-fg);
  min-width: 0;
}
.bh button, .bh input { font: inherit; color: inherit; }
.bh :focus-visible { outline: 2px solid var(--tb-spice); outline-offset: 2px; }
.bh .hidden { display: none !important; }

/* ── Ask The Brain band ─────────────────────────────────────────────────── */
.bh-ask {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  color: var(--tb-on-ink);
  padding: 28px 30px 24px;
  background:
    radial-gradient(70% 120% at 100% 0%, rgba(242, 179, 61, .16), transparent 60%),
    linear-gradient(135deg, var(--tb-brand) 0%, #4E1629 55%, var(--tb-ink) 100%);
}
[dir="rtl"] .bh-ask { background:
    radial-gradient(70% 120% at 0% 0%, rgba(242, 179, 61, .16), transparent 60%),
    linear-gradient(225deg, var(--tb-brand) 0%, #4E1629 55%, var(--tb-ink) 100%); }
.bh-net { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .5; pointer-events: none; }
.bh-ask > *:not(.bh-net) { position: relative; }
.bh-askhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.bh-greet { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 420px; }
.bh-greet h2 { margin: 0; font-size: clamp(22px, 2.3vw, 30px); font-weight: 600; line-height: 1.2; text-wrap: balance; overflow-wrap: anywhere; }
.bh-greet-line { font-weight: 500; }
.bh-greet p { margin: 0; color: var(--tb-on-ink-dim); font-size: 14.5px; max-width: 62ch; }
.bh-askmark { width: 64px; height: 64px; flex: none; color: var(--tb-on-ink); }

.bh-bar {
  margin-top: 18px;
  display: flex; align-items: center; gap: 10px;
  background: var(--tb-ask-field);
  border-radius: 16px;
  padding: 7px;
  padding-inline-start: 16px;
  box-shadow: 0 14px 34px -18px rgba(0, 0, 0, .6);
}
.bh-bar svg { width: 20px; height: 20px; flex: none; stroke: var(--tb-brand-text); fill: none; stroke-width: 1.8; }
.bh .bh-bar input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--tb-fg); font-size: 16px; padding: 10px 0; }
.bh-bar input::placeholder { color: var(--tb-placeholder); }
.bh .bh-bar button { border: 0; border-radius: 12px; background: var(--tb-brand); color: #fff; font-weight: 600; padding: 11px 18px; cursor: pointer; white-space: nowrap; }
.bh .bh-bar button:hover { background: var(--tb-brand-hover); }
.bh-bar:focus-within { box-shadow: 0 0 0 2px var(--tb-spice), 0 14px 34px -18px rgba(0, 0, 0, .6); }

.bh-chips { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.bh .bh-chip {
  border: 1px solid rgba(255, 255, 255, .22);
  background: rgba(255, 255, 255, .08);
  color: var(--tb-on-ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  text-align: start;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.bh .bh-chip:hover { background: rgba(255, 255, 255, .16); }

/* Answer card */
.bh-answer {
  margin-top: 14px;
  background: var(--tb-surface);
  color: var(--tb-fg);
  border-radius: 14px;
  padding: 16px 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 16px;
  align-items: start;
}
.bh-answer-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.bh-answer h3 { margin: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.bh-answer p { margin: 0; color: var(--tb-muted); font-size: 13.5px; overflow-wrap: anywhere; }
.bh-answer-err p { color: var(--tb-bad); }
.bh-big { font-size: 26px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.bh-acts { display: flex; flex-direction: column; gap: 6px; }
.bh-thinking { display: flex; align-items: center; gap: 8px; }
.bh-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--tb-line); border-top-color: var(--tb-brand); animation: bhSpin .8s linear infinite; flex: none; }
@keyframes bhSpin { to { transform: rotate(360deg); } }
.bh-steps { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--tb-muted); }
.bh-steps li { display: inline-flex; gap: 6px; }
.bh-steps li.active { color: var(--tb-fg); font-weight: 500; }
.bh-steps li.done { color: var(--tb-good); }
.bh-sql summary { cursor: pointer; font-size: 12.5px; color: var(--tb-muted); }
.bh-sql pre { margin: 6px 0 0; padding: 10px; border-radius: var(--tb-r-sm); background: var(--tb-sunk); font: 12px/1.45 var(--mono, monospace); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow: auto; text-align: left; }

.bh .bh-btn {
  border: 1px solid var(--tb-line);
  background: var(--tb-surface);
  color: var(--tb-fg);
  border-radius: 10px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.bh .bh-btn:hover { border-color: var(--tb-brand); }
.bh .bh-btn.primary { background: var(--tb-brand); border-color: var(--tb-brand); color: #fff; }
.bh .bh-btn[disabled] { opacity: .7; cursor: default; }
.bh .bh-link { border: 0; background: none; color: var(--tb-link); font-weight: 500; font-size: 13px; cursor: pointer; padding: 0; }
.bh .bh-link[disabled] { opacity: .6; cursor: progress; }

/* ── Pulse ──────────────────────────────────────────────────────────────── */
.bh-pulsehead { display: flex; align-items: baseline; gap: 6px 12px; flex-wrap: wrap; margin-bottom: -10px; }
.bh-pulsehead:empty { display: none; }
.bh-pulsehead h2 { margin: 0; font-size: 15.5px; font-weight: 600; }
.bh-pulsehead span { font-size: 12.5px; color: var(--tb-muted); }
.bh-pulse { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.bh-pulse-full { grid-column: 1 / -1; }
.bh-kpi {
  background: var(--tb-surface);
  border: 1px solid var(--tb-line);
  border-radius: var(--tb-r-lg);
  padding: 14px 16px 12px;
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}
.bh-kpi-skel { gap: 10px; }
.bh-lab { font-size: 13px; color: var(--tb-muted); overflow-wrap: anywhere; }
.bh-val { font-size: 26px; font-weight: 600; letter-spacing: -.01em; line-height: 1.15; overflow-wrap: anywhere; }
.bh-val small { font-size: 14px; font-weight: 500; color: var(--tb-muted); margin-inline-start: 4px; }
.bh-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 8px; margin-top: 4px; min-height: 26px; }
.bh-delta { font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.bh .up { color: var(--tb-good); }
.bh .down { color: var(--tb-bad); }
.bh .flat { color: var(--tb-muted); }
.bh-spark { width: 84px; height: 26px; flex: none; direction: ltr; }
.bh-note { font-size: 12px; color: var(--tb-muted); overflow-wrap: anywhere; }
.bh-note.bh-warn { color: var(--tb-warn); }

/* ── Panels ─────────────────────────────────────────────────────────────── */
.bh-grid { display: grid; gap: 16px; }
.bh-g-main { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); }
.bh-g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.bh-g-2 { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
.bh-panel {
  background: var(--tb-surface);
  border: 1px solid var(--tb-line);
  border-radius: var(--tb-r-lg);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
  min-width: 0;
}
.bh-ph { display: flex; align-items: baseline; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; }
.bh-ph h3 { margin: 0; font-size: 15.5px; font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.bh-meta { font-size: 12.5px; color: var(--tb-muted); }

/* States */
.bh-skelwrap { display: flex; flex-direction: column; gap: 10px; }
.bh-skel {
  display: block;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--tb-sunk) 0%, var(--tb-line) 50%, var(--tb-sunk) 100%);
  background-size: 200% 100%;
  animation: bhShimmer 1.4s ease-in-out infinite;
}
@keyframes bhShimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.bh-err {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px;
  border-radius: var(--tb-r-md);
  background: var(--tb-bad-soft);
  color: var(--tb-bad);
  font-size: 13.5px;
}
.bh-empty-note { margin: 0; color: var(--tb-muted); font-size: 13.5px; }

/* Chart (always LTR, scales with its viewBox) */
.bh-legend { display: flex; gap: 6px 14px; font-size: 12.5px; color: var(--tb-muted); flex-wrap: wrap; }
.bh-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bh-legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.bh-legend i.dash { background-image: linear-gradient(90deg, transparent 55%, var(--tb-surface) 55%) !important; background-size: 6px 3px; }
.bh-chart { position: relative; direction: ltr; border-radius: var(--tb-r-sm); }
.bh-chart:focus-visible { outline: 2px solid var(--tb-spice); outline-offset: 4px; }
.bh-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.bh-chart text { fill: var(--tb-muted); font: 11px var(--tb-f); }
.bh-chart text.bh-chart-strong { fill: var(--tb-fg); font-weight: 600; }
.bh-tip {
  position: absolute;
  pointer-events: none;
  background: var(--tb-fg);
  color: var(--tb-bg);
  font-size: 12px;
  padding: 6px 9px;
  border-radius: 8px;
  white-space: nowrap;
  transform: translate(-50%, -110%);
  opacity: 0;
  transition: opacity .1s;
}
.bh-tip b { font-weight: 600; }

/* Signals */
.bh-sig { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bh-sig li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 10px;
  padding: 10px 12px;
  border-radius: var(--tb-r-md);
  background: var(--tb-sunk);
  border-inline-start: 3px solid var(--c);
}
.bh-ico { grid-row: 1 / span 2; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--c); background: var(--cs); }
.bh-sig b { font-weight: 500; font-size: 13.5px; line-height: 1.35; overflow-wrap: anywhere; }
.bh-sig small { color: var(--tb-muted); font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.bh-tag { font-size: 11.5px; padding: 0 7px; border-radius: 999px; background: var(--cs); color: var(--c); }
.bh-t-bad { --c: var(--tb-bad); --cs: var(--tb-bad-soft); }
.bh-t-warn { --c: var(--tb-warn); --cs: var(--tb-warn-soft); }
.bh-t-good { --c: var(--tb-good); --cs: var(--tb-good-soft); }
.bh-t-info { --c: var(--tb-info); --cs: var(--tb-info-soft); }

/* Share bars */
.bh-hb { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.bh-hb li { display: grid; grid-template-columns: minmax(0, 9.5em) minmax(36px, 1fr) auto; gap: 10px; align-items: center; font-size: 13px; }
.bh-hb-l { min-width: 0; overflow-wrap: anywhere; line-height: 1.3; }
.bh-track { height: 10px; background: var(--tb-bar-soft); border-radius: 999px; overflow: hidden; direction: ltr; }
[dir="rtl"] .bh-track { direction: rtl; }
.bh-fill { display: block; height: 100%; background: var(--tb-bar); border-radius: 999px; }
.bh-v { text-align: end; font-weight: 500; white-space: nowrap; }
.bh-d { font-size: 11.5px; }

/* Movers */
.bh-subh { margin: 0; font-size: 12px; font-weight: 500; color: var(--tb-muted); }
.bh-subh + .bh-movers { margin-top: -6px; }
.bh-movers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.bh-movers li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--tb-line); font-size: 13.5px; }
.bh-movers li:last-child { border-bottom: 0; }
.bh-n { min-width: 0; overflow-wrap: anywhere; }
.bh-q { color: var(--tb-muted); font-size: 12.5px; }

/* Radar */
.bh-radar { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.bh-radar li { border: 1px solid var(--tb-line); border-radius: var(--tb-r-md); padding: 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.bh-k { font-size: 12px; color: var(--tb-muted); }
.bh-radar b { font-weight: 500; font-size: 13.5px; line-height: 1.4; overflow-wrap: anywhere; }
.bh-ev { font-size: 11.5px; color: var(--tb-muted); overflow-wrap: anywhere; }
.bh-ev a { color: var(--tb-link); }
.bh-lib { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 12px; border-radius: var(--tb-r-md); background: var(--tb-sunk); font-size: 13px; overflow-wrap: anywhere; }

/* Pins */
.bh-pins { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 10px; }
.bh-pin { border: 1px solid var(--tb-line); border-radius: var(--tb-r-md); padding: 12px; display: flex; flex-direction: column; gap: 4px; background: var(--tb-surface); min-width: 0; }
.bh-pq { font-size: 12px; color: var(--tb-muted); overflow-wrap: anywhere; }
.bh-pin b { font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
.bh-pin-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; font-size: 11.5px; color: var(--tb-muted); }
.bh-pin-stale { color: var(--tb-warn); }
.bh-pin-err { color: var(--tb-bad); font-size: 12px; }
.bh .bh-x { border: 0; background: none; color: var(--tb-muted); cursor: pointer; font-size: 12px; padding: 2px 0; margin-inline-start: auto; }
.bh .bh-x:hover { color: var(--tb-bad); text-decoration: underline; }
.bh-empty {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border: 1px dashed var(--tb-line);
  border-radius: var(--tb-r-md);
  padding: 16px;
  color: var(--tb-muted);
  font-size: 13.5px;
}

/* Governance disclosure (kept visually quiet) */
.bh-gov { border-top: 1px solid var(--tb-line); padding-top: 10px; font-size: 12.5px; color: var(--tb-muted); }
.bh-gov summary { cursor: pointer; display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; list-style-position: inside; }
.bh-gov summary::-webkit-details-marker { margin-inline-end: 4px; }
.bh-conf { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--tb-sunk); color: var(--tb-muted); }
.bh-conf-high { background: var(--tb-good-soft); color: var(--tb-good); }
.bh-conf-medium { background: var(--tb-warn-soft); color: var(--tb-warn); }
.bh-conf-low { background: var(--tb-bad-soft); color: var(--tb-bad); }
.bh-gov-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 10px 24px; padding-top: 10px; }
.bh-gov-body h4 { margin: 0 0 4px; font-size: 12px; font-weight: 600; color: var(--tb-fg); }
.bh-gov-body ul { margin: 0; padding-inline-start: 18px; }
.bh-gov-body li { overflow-wrap: anywhere; }
.bh-gov-gen { grid-column: 1 / -1; margin: 0; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1240px) {
  .bh-pulse { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bh-g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .bh-g-main, .bh-g-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .view.view-home,
  [dir="rtl"] .view.view-home {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .bh-ask { padding: 20px 18px; }
  .bh-askmark { display: none; }
}
@media (max-width: 620px) {
  .bh-pulse { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bh-g-3, .bh-radar { grid-template-columns: minmax(0, 1fr); }
  .bh .bh-bar button span:first-child { display: none; }
  .bh .bh-bar button { padding: 11px 14px; }
  .bh-answer { grid-template-columns: minmax(0, 1fr); }
  .bh-acts { flex-direction: row; flex-wrap: wrap; }
  .bh-val { font-size: 22px; }
  .bh-spark { width: 64px; }
  .bh-hb li { grid-template-columns: minmax(0, 7.5em) minmax(28px, 1fr) auto; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .bh-skel, .bh-spin { animation: none; }
  .bh-tip { transition: none; }
}
