// Premium top bar — sharp, light, high-contrast.
// Shows REAL data:
// • CH score + bracket (from CHVault.axes())
// • HCR balance (from /api/v1/healthcoin/wallet)
// • HCC balance (from /api/v1/hcc/wallet)
// • Member identity + sign-out
//
// No glassmorphism over a light body, no fake random-walk ticker — three
// crisp metric pills, bold display typography, single hairline divider.
const Topbar = ({ onSignOut, user }) => {
const ctx = (window.useChData && window.useChData()) || null;
const ready = ctx && ctx.phase === 'ready';
const ch = ready && ctx.bundle.axes ? ctx.bundle.axes.ch : null;
const wallet = ready ? ctx.bundle.wallet : null;
const [hccWallet, setHccWallet] = React.useState(null);
React.useEffect(() => {
let dead = false;
(async () => {
try {
const r = await fetch(window.CHVault.apiRoot + '/api/v1/hcc/wallet', { credentials: 'include', headers: { 'Accept': 'application/json' } });
if (!r.ok) return;
const j = await r.json();
if (!dead) setHccWallet(j);
} catch {}
})();
return () => { dead = true; };
}, []);
const num = (x, d = 2) => {
const n = Number(x);
return Number.isFinite(n) ? n.toLocaleString(undefined, { maximumFractionDigits: d }) : '—';
};
const hcr = wallet ? (wallet.balance ?? wallet.hcr_balance ?? wallet.amount) : null;
const hcrUsd = wallet ? (wallet.balance_usd ?? wallet.usd_value) : null;
const hcc = hccWallet ? (hccWallet.balance_hcc ?? (hccWallet.balance_pulses != null ? hccWallet.balance_pulses / 100_000_000 : null)) : null;
const initials = ((user && (user.display_name || user.email || '?')) + '')
.split(/\s+|@|\./).filter(Boolean).slice(0, 2)
.map(s => s[0].toUpperCase()).join('') || 'U';
const bracket = ch == null ? '—'
: ch >= 76 ? 'EXCELLENT'
: ch >= 60 ? 'GOOD'
: ch >= 40 ? 'EMERGING'
: ch >= 20 ? 'AT-RISK'
: 'CRITICAL';
const bracketTint = ch == null ? '#9AA7B5'
: ch >= 76 ? '#117A4D'
: ch >= 60 ? '#2F9E6B'
: ch >= 40 ? '#B08D3C'
: ch >= 20 ? '#B23A2E'
: '#7A1F18';
// ── Styles (sharp, no glassmorphism) ──
const wrap = {
display: 'grid',
gridTemplateColumns: 'auto 1fr auto',
alignItems: 'center',
gap: 24,
padding: '14px 32px',
background: '#FFFFFF',
borderBottom: '1px solid #E5E2DA',
boxShadow: '0 1px 0 rgba(8,12,18,0.02), 0 4px 12px -8px rgba(8,12,18,0.08)',
position: 'sticky', top: 0, zIndex: 50,
};
const brand = {
display: 'flex', alignItems: 'center', gap: 10,
fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 16, color: '#0E1424',
letterSpacing: '-0.01em',
};
const search = {
display: 'flex', alignItems: 'center', gap: 10,
maxWidth: 380, justifySelf: 'center', width: '100%',
background: '#FAF7F1',
border: '1px solid #E5E2DA',
borderRadius: 10,
padding: '9px 14px',
color: '#7A8290',
fontFamily: 'var(--font-mono)', fontSize: 12,
};
const right = { display: 'flex', alignItems: 'center', gap: 10 };
// Premium metric pill — sharp, high-contrast.
const metric = (label, value, value2, tint, href) => {
const inner = (