// site-meridian.jsx — Meridian / Newsroom page
// The pipeline as content. 560 sources, 15 detectors, three-tier confluence.

const SOURCE_CATEGORIES = [
  { id: 'intl-ai-labs',          label: 'AI labs · international',     count: 52, relevance: 'high' },
  { id: 'ats-jobs',              label: 'Hiring data · ATS',           count: 43, relevance: 'high' },
  { id: 'infrastructure-trade',  label: 'Infrastructure & trade',      count: 20, relevance: 'high' },
  { id: 'lab-blogs',             label: 'Lab blogs',                   count: 20, relevance: 'high' },
  { id: 'seniorcare-federal',    label: 'Federal seniorcare',          count: 18, relevance: 'med' },
  { id: 'hardware-supply',       label: 'Hardware supply chain',       count: 18, relevance: 'high' },
  { id: 'ferc-power',            label: 'FERC · power grid',            count: 17, relevance: 'high' },
  { id: 'private-credit',        label: 'Private credit',              count: 16, relevance: 'med' },
  { id: 'sec-filings',           label: 'SEC EDGAR',                    count: 16, relevance: 'high' },
  { id: 'china-labs',            label: 'China · AI labs',              count: 15, relevance: 'high' },
  { id: 'political-figures',     label: 'Political figures',            count: 14, relevance: 'high' },
  { id: 'policy',                label: 'Policy · regulation',          count: 13, relevance: 'high' },
  { id: 'eu-regulatory',         label: 'EU · global regulatory',       count: 10, relevance: 'high' },
  { id: 'ai-podcasts',           label: 'AI podcasts · transcript',     count: 10, relevance: 'high' },
  { id: 'papers',                label: 'Academic papers',              count: 10, relevance: 'high' },
  { id: 'nuclear',               label: 'Nuclear restart',              count: 10, relevance: 'high' },
  { id: 'mainstream',            label: 'Investigative journalism',     count: 8,  relevance: 'high' },
  { id: 'earnings',              label: 'Earnings · capex',             count: 8,  relevance: 'high' },
  { id: 'reddit-hn',             label: 'Reddit · Hacker News',         count: 8,  relevance: 'high' },
  { id: 'lobbying',              label: 'Lobbying disclosures',         count: 5,  relevance: 'high' },
  { id: 'energy',                label: 'Energy · utility',             count: 5,  relevance: 'high' },
  { id: 'congressional-trades',  label: 'Congressional trades',         count: 3,  relevance: 'high' },
];

const DETECTORS = [
  { name: 'compensation_ratio',    kind: 'base', catches: 'Exec comp > 40% of revenue',                  flag: 'Shell / nonprofit abuse' },
  { name: 'rapid_growth',          kind: 'base', catches: 'Revenue or grants 3x+ year-over-year',         flag: 'Suspicious entity growth' },
  { name: 'mission_drift',         kind: 'base', catches: 'Spending unrelated to stated purpose',         flag: 'Misuse of public funds' },
  { name: 'address_cluster',       kind: 'base', catches: 'Multiple recipients at same address',          flag: 'Shell company network' },
  { name: 'officer_overlap',       kind: 'base', catches: 'Shared officers between recipients',           flag: 'Self-dealing' },
  { name: 'new_entity_large_award',kind: 'base', catches: 'New org wins big contract fast',               flag: 'Front company' },
  { name: 'amount_outlier',        kind: 'base', catches: 'Award much larger than historical average',    flag: 'Outsized allocation' },
  { name: 'modification_creep',    kind: 'base', catches: 'Contract ceiling raised repeatedly',           flag: 'Scope creep' },
  { name: 'grant_concentration',   kind: 'base', catches: 'Single org dominates a program',                flag: 'Monopoly capture' },
  { name: 'exclusion_evasion',     kind: 'base', catches: 'New entity, same principals as excluded org',   flag: 'Banned actors reformed' },
  { name: 'fy_end_flush',          kind: 'deep', catches: 'Q4 spending surge · Sep 16 – 30, 3x+ avg',      flag: 'Budget dump' },
  { name: 'geographic_void',       kind: 'deep', catches: 'High-need areas with low funding',              flag: 'Allocation bias' },
  { name: 'timing_anomaly',        kind: 'deep', catches: 'Short gap between formation and award',         flag: 'Fast-tracked award' },
  { name: 'rapid_licensing',       kind: 'deep', catches: 'Suspicious licensing pattern',                   flag: 'Regulatory capture' },
  { name: 'revenue_grant_mismatch',kind: 'deep', catches: '990 revenue vs. actual grants disagree',         flag: 'Financial discrepancy' },
];

const TIERS = [
  { tier: '01', name: 'Informed Money',  weight: '2.0×', kinds: ['Congressional trades', 'Insider cluster buys/sells', 'Dark pool blocks', '13F accumulation'], color: 'var(--amber-400)' },
  { tier: '02', name: 'Structural',       weight: '1.5×', kinds: ['Unusual options', 'Short interest / squeeze', 'Prediction market shifts', 'Political figure actions'], color: 'var(--teal-400)' },
  { tier: '03', name: 'Confirming',       weight: '1.0×', kinds: ['Earnings · guidance', 'SEC filings', 'Macro · FRED / CPI / NFP', 'Analyst revisions', 'Social sentiment', 'Supply chain · regulatory'], color: 'var(--gray-300)' },
];

const GAPS = [
  { title: 'Municipal water utilities',  note: 'City water reports, rate filings, usage data. Top priority next quarter.' },
  { title: 'County · city meeting agendas', note: 'Council and commission minutes. The best stories start there.' },
  { title: 'NDA tracking',               note: 'FOIA denials database. State open-records litigation.' },
  { title: 'State legislatures · 50 states', note: 'Currently federal only. LegiScan or equivalent next.' },
  { title: 'Property assessment',        note: 'Enterprise zones. PILOT deals. Scraper exists, not running.' },
  { title: 'Sustainability report diffs',note: 'Annual report monitoring, diff against site-level data.' },
  { title: 'Local newspaper ingest',     note: 'Papers nobody outside the county reads.' },
  { title: 'PACER · court filings',      note: 'Sealed cases. FOIA litigation. Environmental suits.' },
  { title: 'Satellite change detection', note: 'Physical evidence. Construction starts. Reservoir levels.' },
];

function MeridianPage() {
  return (
    <main>
      <PageHeader
        kicker="Meridian · The intake floor"
        title={<span>How the<br/><span style={{ color: 'var(--teal-400)' }}>file</span> gets built.</span>}
        subtitle="The bureau runs a continuous-intake pipeline. Five hundred and sixty public sources, polled around the clock, scored locally, audited for anomalies. Everything below is a real component. Drew does not invent a number. The machine surfaces it."
      />

      {/* LIVE COUNTERS — animated count-up */}
      <section className="section" style={{ paddingTop: 56 }}>
        <div className="container">
          <Reveal>
            <Bureau>Live counters</Bureau>
          </Reveal>
          <Reveal delay={80}>
            <div className="meridian-counters">
              {[
                { label: 'Sources enabled',        big: 560,   sub: 'of 618 in registry' },
                { label: 'Signals scored · 24h',   big: 789,   sub: 'by Qwen 3 27B · local' },
                { label: 'Anomaly detectors',      big: 15,    sub: '10 base · 5 deep' },
                { label: 'Cadence · daily',        big: 290,   sub: 'plus 128 every 6h' },
                { label: 'Cadence · 15-minute',    big: 11,    sub: 'options · darkpool · politics' },
                { label: 'Categories tracked',     big: 84,    sub: 'top 22 shown below' },
              ].map((c) => (
                <div className="counter" key={c.label}>
                  <Kicker color="var(--gray-400)">{c.label}</Kicker>
                  <div className="counter-big t-cond">
                    <CountInt to={c.big} />
                  </div>
                  <span className="t-mono counter-sub">{c.sub}</span>
                </div>
              ))}
            </div>
          </Reveal>
        </div>
      </section>

      {/* SOURCE REGISTRY — top 22 categories as a list */}
      <section className="section section--lg" style={{ background: 'var(--ink-870)', borderTop: '1px solid rgba(236,231,220,0.06)', borderBottom: '1px solid rgba(236,231,220,0.06)' }}>
        <div className="container">
          <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', flexWrap: 'wrap', gap: 24 }}>
            <Reveal>
              <div>
                <Bureau>Source registry · top 22</Bureau>
                <h2 className="t-cond" style={{ margin: '16px 0 0', fontSize: 'clamp(40px, 5vw, 64px)', letterSpacing: '-0.02em', textTransform: 'uppercase', lineHeight: 0.95 }}>
                  Where the numbers come from.
                </h2>
              </div>
            </Reveal>
            <Reveal delay={80}>
              <div className="legend">
                <span className="legend-key"><span className="legend-bar" style={{ background: 'var(--amber-400)' }} /> Deep Cut relevance · high</span>
                <span className="legend-key"><span className="legend-bar" style={{ background: 'var(--gray-500)' }} /> medium</span>
              </div>
            </Reveal>
          </div>

          <Reveal delay={140}>
            <ol className="src-list">
              {SOURCE_CATEGORIES.map((c, i) => {
                const max = SOURCE_CATEGORIES[0].count;
                const pct = (c.count / max) * 100;
                const accent = c.relevance === 'high' ? 'var(--amber-400)' : 'var(--gray-500)';
                return (
                  <li key={c.id} className="src-row">
                    <span className="src-num">{String(i + 1).padStart(2, '0')}</span>
                    <span className="src-name">{c.label}</span>
                    <span className="src-bar-wrap">
                      <span className="src-bar" style={{ width: `${pct}%`, background: accent }} />
                    </span>
                    <span className="src-count t-cond">{c.count}</span>
                  </li>
                );
              })}
            </ol>
            <div className="src-foot">
              <Kicker>Long tail · 62 more categories</Kicker>
              <Kicker color="var(--gray-300)">Total · 618 sources / 84 categories</Kicker>
            </div>
          </Reveal>
        </div>
      </section>

      {/* DETECTORS WALL */}
      <section className="section section--lg">
        <div className="container">
          <Reveal>
            <Bureau>Sentinel · 15 anomaly detectors</Bureau>
          </Reveal>
          <Reveal delay={80}>
            <h2 className="t-cond" style={{ margin: '16px 0 36px', fontSize: 'clamp(40px, 5vw, 64px)', letterSpacing: '-0.02em', textTransform: 'uppercase', lineHeight: 0.95 }}>
              The pattern detectors<br/><span style={{ color: 'var(--red-400)' }}>that find the story.</span>
            </h2>
          </Reveal>
          <Reveal delay={140}>
            <div className="detector-grid">
              {DETECTORS.map((d) => (
                <div key={d.name} className={`detector detector--${d.kind}`}>
                  <div className="detector-head">
                    <span className="detector-kind">{d.kind === 'base' ? 'Base' : 'Deep'}</span>
                    <span className="detector-name t-mono">{d.name}</span>
                  </div>
                  <div className="detector-catches">{d.catches}</div>
                  <div className="detector-flag">↳ {d.flag}</div>
                </div>
              ))}
            </div>
          </Reveal>
        </div>
      </section>

      {/* CONFLUENCE — three tiers */}
      <section className="section section--lg" style={{ background: 'var(--ink-870)', borderTop: '1px solid rgba(236,231,220,0.06)' }}>
        <div className="container">
          <Reveal>
            <Bureau>Confluence · the three-tier signal taxonomy</Bureau>
          </Reveal>
          <Reveal delay={80}>
            <p className="t-bodyL" style={{ marginTop: 18, maxWidth: 760 }}>
              No file is opened on a single signal. The pipeline only flags a story when independent signal types, from different information sources, point in the same direction. Minimum weighted score of six. Must include at least one Tier 1.
            </p>
          </Reveal>

          <Reveal delay={140}>
            <div className="tier-grid">
              {TIERS.map((t) => (
                <div key={t.tier} className="tier" style={{ borderTopColor: t.color }}>
                  <div className="tier-head">
                    <span className="tier-num t-cond" style={{ color: t.color }}>{t.tier}</span>
                    <div>
                      <Kicker color={t.color}>Tier {t.tier} · {t.weight} weight</Kicker>
                      <h3 className="t-cond tier-name">{t.name}</h3>
                    </div>
                  </div>
                  <ul className="tier-kinds">
                    {t.kinds.map(k => <li key={k}>{k}</li>)}
                  </ul>
                </div>
              ))}
            </div>
          </Reveal>
        </div>
      </section>

      {/* CADENCE STRIP */}
      <section className="section">
        <div className="container">
          <Reveal>
            <Bureau>Cadence · pipeline cycle</Bureau>
          </Reveal>
          <Reveal delay={80}>
            <div className="cadence-strip">
              {[
                ['5m',  3,  'MSI components'],
                ['15m', 11, 'Options · darkpool · politics'],
                ['30m', 7,  'Congressional · exchange flows'],
                ['1h',  66, 'Market data · breaking'],
                ['6h',  128,'High-priority news · gov data'],
                ['1d',  290,'News · filings · reports'],
                ['1w',  76, 'Research papers · bulk datasets'],
                ['Stream', 1, 'WebSocket market feed'],
              ].map(([when, n, note]) => (
                <div key={when} className="cadence">
                  <div className="cadence-when t-cond">{when}</div>
                  <div className="cadence-n t-mono">{n} sources</div>
                  <div className="cadence-note">{note}</div>
                </div>
              ))}
            </div>
          </Reveal>
        </div>
      </section>

      {/* GAPS — honest about what's missing */}
      <section className="section section--lg" style={{ background: 'var(--paper)', color: 'var(--ink-900)' }}>
        <div className="container">
          <Reveal>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 10 }}>
              <span style={{ display: 'inline-block', width: 18, height: 1.5, background: 'var(--red-600)' }} />
              <span className="t-mono" style={{ fontSize: 11, letterSpacing: '0.32em', textTransform: 'uppercase', color: 'var(--ink-500)' }}>What we don&rsquo;t cover yet</span>
            </span>
          </Reveal>
          <Reveal delay={80}>
            <h2 className="t-cond" style={{ margin: '20px 0 0', fontSize: 'clamp(40px, 5vw, 68px)', letterSpacing: '-0.02em', textTransform: 'uppercase', lineHeight: 0.95, maxWidth: 980 }}>
              Holes in the net.<br/>
              <span style={{ color: 'var(--ink-500)' }}>Named, not hidden.</span>
            </h2>
          </Reveal>
          <Reveal delay={140}>
            <ol className="gap-list">
              {GAPS.map((g, i) => (
                <li key={g.title} className="gap-row">
                  <span className="gap-num t-mono">{String(i + 1).padStart(2, '0')}</span>
                  <div>
                    <h3 className="t-cond gap-title">{g.title}</h3>
                    <p className="gap-note t-serif">{g.note}</p>
                  </div>
                </li>
              ))}
            </ol>
          </Reveal>
        </div>
      </section>
    </main>
  );
}

Object.assign(window, { MeridianPage });
