// why-echo.jsx — "Why Echo" pillar section + AgentsWithDemo merged section
const { useState: useStateW, useEffect: useEffectW, useRef: useRefW } = React;

// ── Visual: Systems-Native diagram ──────────────────────────────
function SystemsVisual() {
  return (
    <div style={{ background: 'var(--bg)', border: '1px solid var(--hairline)', borderRadius: 12, padding: 28, position: 'relative', overflow: 'hidden', minHeight: 280 }}>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
        {/* Echo agents row */}
        <div style={{ display: 'flex', gap: 8 }}>
          {['Docs', 'Triage', 'Cal', 'Ledger'].map((n, i) => (
            <div key={n} style={{ flex: 1, padding: '10px 8px', borderRadius: 8, background: 'var(--accent-dim)', border: '1px solid var(--accent)', textAlign: 'center', fontFamily: 'var(--ff-mono)', fontSize: 10, fontWeight: 600, color: 'var(--accent)', letterSpacing: '0.06em' }}>{n}</div>
          ))}
        </div>
        {/* connectors */}
        <div style={{ display: 'flex', justifyContent: 'space-around', height: 22 }}>
          {[0,1,2,3].map(i => (
            <div key={i} style={{ width: 1, height: '100%', background: 'linear-gradient(var(--accent), transparent)' }} />
          ))}
        </div>
        {/* Your System API row */}
        <div style={{ background: 'var(--surface)', border: '1px solid var(--hairline)', borderRadius: 10, padding: '14px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
          <div>
            <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, letterSpacing: '0.1em', color: 'var(--muted)', marginBottom: 4 }}>YOUR INFRASTRUCTURE</div>
            <div style={{ fontFamily: 'var(--ff-display)', fontSize: 18, fontWeight: 500, color: 'var(--ink)' }}>Your System API</div>
          </div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '4px 10px', borderRadius: 12, background: 'rgba(29,219,184,0.15)', border: '1px solid rgba(29,219,184,0.4)' }}>
            <span style={{ width: 6, height: 6, borderRadius: '50%', background: '#1DDBB8' }} />
            <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, color: '#0a8569', fontWeight: 600 }}>READ + WRITE</span>
          </div>
        </div>
        {/* Endpoint chips */}
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 6 }}>
          {['LOADS', 'CUSTOMERS', 'AR', 'BILLING', 'DOCS', 'SCHEDULE'].map(label => (
            <div key={label} style={{ padding: '6px 8px', background: 'var(--bg)', border: '1px solid var(--hairline)', borderRadius: 6, textAlign: 'center', fontFamily: 'var(--ff-mono)', fontSize: 9, color: 'var(--muted)', letterSpacing: '0.08em' }}>{label}</div>
          ))}
        </div>
      </div>
      <div style={{ position: 'absolute', top: 14, right: 14, fontFamily: 'var(--ff-mono)', fontSize: 9, color: 'var(--muted)', letterSpacing: '0.1em' }}>AZURE TENANT · YOUR DATA</div>
    </div>
  );
}

// ── Visual: Multi-channel device stack ────────────────────────────
function ChannelsVisual() {
  return (
    <div style={{ background: 'var(--bg)', border: '1px solid var(--hairline)', borderRadius: 12, padding: 24, minHeight: 280, display: 'flex', flexDirection: 'column', gap: 10 }}>
      {/* SMS row */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '12px 14px', background: 'var(--surface)', borderRadius: 10, border: '1px solid var(--hairline)' }}>
        <div style={{ width: 32, height: 32, borderRadius: 8, background: '#34C759', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="white"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z"/></svg>
        </div>
        <div style={{ flex: 1 }}>
          <div style={{ fontSize: 12, fontWeight: 600, color: 'var(--ink)' }}>SMS</div>
          <div style={{ fontSize: 11, color: 'var(--muted)' }}>Field teams, mobile workers</div>
        </div>
        <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, color: 'var(--accent)', letterSpacing: '0.08em' }}>DOCS · CAL</div>
      </div>
      {/* Teams row */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '12px 14px', background: 'var(--surface)', borderRadius: 10, border: '1px solid var(--hairline)' }}>
        <div style={{ width: 32, height: 32, borderRadius: 8, background: '#5059C9', display: 'flex', alignItems: 'center', justifyContent: 'center', fontWeight: 700, color: 'white', fontSize: 14 }}>T</div>
        <div style={{ flex: 1 }}>
          <div style={{ fontSize: 12, fontWeight: 600, color: 'var(--ink)' }}>Microsoft Teams</div>
          <div style={{ fontSize: 11, color: 'var(--muted)' }}>Operations, dock supervisors</div>
        </div>
        <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, color: 'var(--accent)', letterSpacing: '0.08em' }}>CAL · LEDGER</div>
      </div>
      {/* Email row */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '12px 14px', background: 'var(--surface)', borderRadius: 10, border: '1px solid var(--hairline)' }}>
        <div style={{ width: 32, height: 32, borderRadius: 8, background: '#0078D4', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="white"><path d="M22 6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6zm-2 0l-8 5-8-5h16zm0 12H4V8l8 5 8-5v10z"/></svg>
        </div>
        <div style={{ flex: 1 }}>
          <div style={{ fontSize: 12, fontWeight: 600, color: 'var(--ink)' }}>Email</div>
          <div style={{ fontSize: 11, color: 'var(--muted)' }}>Customer service inbox</div>
        </div>
        <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, color: 'var(--accent)', letterSpacing: '0.08em' }}>TRIAGE</div>
      </div>
      {/* Call out */}
      <div style={{ marginTop: 'auto', paddingTop: 14, borderTop: '1px solid var(--hairline)', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
        <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, color: 'var(--muted)', letterSpacing: '0.1em' }}>RUNS INSIDE TEAMS</span>
        <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, color: 'var(--ink)', fontWeight: 600 }}>NO NEW LICENSES</span>
      </div>
    </div>
  );
}

// ── Visual: Decision Log ──────────────────────────────────────────
function DecisionLogVisual() {
  const entries = [
    { agent: 'DOCS',   action: 'Posted POD #4421 to your system',           t: '11:42:08', conf: '0.97', kind: 'auto' },
    { agent: 'TRIAGE', action: 'Sent rate quote to ops@apexlogistics.com',   t: '11:39:14', conf: '0.92', kind: 'auto' },
    { agent: 'CAL',    action: 'Booked door 7 · Heartland · Thu 14:00',      t: '11:36:51', conf: '0.99', kind: 'auto' },
    { agent: 'LEDGER', action: 'Detention package submitted · 3h 34m',       t: '11:31:02', conf: '0.95', kind: 'auto' },
    { agent: 'DOCS',   action: 'Escalated POD #4418 · illegible signature',  t: '11:28:46', conf: '0.61', kind: 'esc' },
  ];
  return (
    <div style={{ background: 'var(--bg)', border: '1px solid var(--hairline)', borderRadius: 12, minHeight: 280, overflow: 'hidden' }}>
      <div style={{ padding: '12px 16px', borderBottom: '1px solid var(--hairline)', background: 'var(--surface)', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
          <span style={{ width: 6, height: 6, borderRadius: '50%', background: '#1DDBB8', animation: 'pulse 2s ease-in-out infinite' }} />
          <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, color: 'var(--muted)', letterSpacing: '0.1em' }}>ECHO · LIVE DECISION LOG</span>
        </div>
        <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, color: 'var(--muted)' }}>04 / 30 / 2026</span>
      </div>
      <div style={{ display: 'flex', flexDirection: 'column' }}>
        {entries.map((e, i) => (
          <div key={i} style={{ padding: '11px 16px', borderBottom: i < entries.length - 1 ? '1px solid var(--hairline)' : 'none', display: 'grid', gridTemplateColumns: '54px 1fr auto', gap: 12, alignItems: 'center' }}>
            <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, color: 'var(--accent)', fontWeight: 600, letterSpacing: '0.05em' }}>{e.agent}</span>
            <span style={{ fontSize: 12, color: 'var(--ink)', lineHeight: 1.4 }}>{e.action}</span>
            <span style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
              <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, color: e.kind === 'esc' ? '#C45A00' : 'var(--muted)', padding: '2px 6px', border: `1px solid ${e.kind === 'esc' ? '#C45A00' : 'var(--hairline)'}`, borderRadius: 4 }}>{e.conf}</span>
              <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, color: 'var(--muted)' }}>{e.t}</span>
            </span>
          </div>
        ))}
      </div>
    </div>
  );
}

// ── Visual: Autonomy level selector ───────────────────────────────
// 4 stacked rows showing each granular approval level. One row is
// highlighted as the current setting. No dollar thresholds. The point
// is approval-level granularity, set per agent and per workflow.
function HITLVisual() {
  const levels = [
    { key: 'read',    label: 'READ-ONLY',                desc: 'Logs everything, takes no action' },
    { key: 'suggest', label: 'SUGGEST',                  desc: 'Drafts replies, waits for approval' },
    { key: 'auto',    label: 'AUTO-EXECUTE',             desc: 'Runs without approval, alerts on completion' },
    { key: 'audit',   label: 'AUTO-EXECUTE + AUDIT',     desc: 'Runs and posts audit trail' },
  ];
  const current = 'auto';
  return (
    <div style={{ background: 'var(--bg)', border: '1px solid var(--hairline)', borderRadius: 12, padding: 24, minHeight: 280, display: 'flex', flexDirection: 'column', gap: 14 }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
        <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, letterSpacing: '0.1em', color: 'var(--muted)' }}>AUTONOMY LEVEL</div>
        <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, letterSpacing: '0.1em', color: 'var(--accent)' }}>DOCS · PODS</div>
      </div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
        {levels.map(l => {
          const active = l.key === current;
          return (
            <div key={l.key} style={{
              display: 'flex', alignItems: 'center', gap: 12,
              padding: '12px 14px',
              borderRadius: 8,
              background: active ? 'var(--accent-dim)' : 'var(--surface)',
              border: `1px solid ${active ? 'var(--accent)' : 'var(--hairline)'}`,
            }}>
              <span style={{
                width: 14, height: 14, borderRadius: '50%',
                border: `1.5px solid ${active ? 'var(--accent)' : 'var(--muted)'}`,
                background: active ? 'var(--accent)' : 'transparent',
                flexShrink: 0,
                boxShadow: active ? 'inset 0 0 0 3px var(--bg)' : 'none',
              }} />
              <div style={{ display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0, flex: 1 }}>
                <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.08em', color: active ? 'var(--accent)' : 'var(--ink)', fontWeight: 600 }}>{l.label}</div>
                <div style={{ fontSize: 11.5, color: 'var(--muted)', lineHeight: 1.4 }}>{l.desc}</div>
              </div>
              {active && (
                <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, letterSpacing: '0.1em', color: 'var(--accent)', textTransform: 'uppercase', fontWeight: 600, flexShrink: 0 }}>Current</span>
              )}
            </div>
          );
        })}
      </div>
    </div>
  );
}

// ── Why Echo Section ──────────────────────────────────────────────
function WhyEcho() {
  const pillars = [
    {
      eyebrow: '01 · NATIVE TO YOUR TMS',
      title: 'Lives in your tenant.',
      sub: 'Direct API access. Your data stays put.',
      body: 'Echo deploys inside your Azure subscription. Agents read and write to TruckMate (or your TMS) through the same APIs your developers would use.',
      Visual: SystemsVisual,
    },
    {
      eyebrow: '02 · IN YOUR CHANNELS',
      title: 'Lives in Teams, Outlook, and SMS.',
      sub: 'Zero new apps to learn.',
      body: 'Dispatchers work in Teams. CS works in Outlook. Drivers text. Agents show up in the channels you already use.',
      Visual: ChannelsVisual,
    },
    {
      eyebrow: '03 · AUDITABLE',
      title: 'Every action, traceable.',
      sub: 'One timeline your compliance team can query.',
      body: 'Every decision logged with the input, the confidence score, and the action taken. Queryable in Teams, exportable, SOC 2 ready.',
      Visual: DecisionLogVisual,
    },
    {
      eyebrow: '04 · HUMAN-IN-THE-LOOP',
      title: 'You set the autonomy.',
      sub: 'Per agent, per workflow.',
      body: 'Read-only, suggest-only, or full execute. Echo respects the approval level you choose.',
      Visual: HITLVisual,
    },
  ];

  return (
    <section id="why-echo" className="plate-section" style={{ padding: '40px 0' }}>
      <div className="glass-plate glass-plate--rounded plate-pad" style={{ maxWidth: 1240, margin: '0 auto', padding: '52px 56px' }}>
        <div style={{ marginBottom: 48, maxWidth: 720 }}>
          <Eyebrow>Why Echo</Eyebrow>
          <h2 style={{ fontFamily: 'var(--ff-display)', fontSize: 'clamp(32px, 3.6vw, 50px)', fontWeight: 400, letterSpacing: '-0.025em', lineHeight: 1.05, color: 'var(--ink)', marginBottom: 20 }}>
            Four reasons Echo<br /><em style={{ fontStyle: 'italic', fontWeight: 300, color: 'var(--muted)' }}>isn't another wrapper.</em>
          </h2>
          <p style={{ fontSize: 15, color: 'var(--muted)', lineHeight: 1.7, maxWidth: 480 }}>
            Tenant-native. Channel-native. Built for how LTL carriers run today.
          </p>
        </div>

        <div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
          {pillars.map((p, i) => (
            <PillarRow key={i} index={i} pillar={p} />
          ))}
        </div>

        <FreightNativeRow />
      </div>
    </section>
  );
}

// ── Freight-native sub-row ───────────────────────────────────────
// Compact row of 4 mini-cards underneath the main pillars. Visually
// secondary: smaller fonts, lighter weight, simple bordered cards.
// 1 row × 4 cols on desktop, 2×2 on mobile.
function FreightNativeRow() {
  const cards = [
    {
      eyebrow: '01 · AR',
      title: 'Detention recovery, automated',
      body: 'Echo watches every load and files the billable detention with GPS proof attached.',
    },
    {
      eyebrow: '02 · OPS',
      title: 'ELD-aware dispatch',
      body: 'Live GPS from Samsara or Motive starts the detention clock the second a truck stops.',
    },
    {
      eyebrow: '03 · COMPLIANCE',
      title: 'Hours-of-service alerts',
      body: 'Echo tracks driver clocks against FMCSA rules and warns dispatch before a violation.',
    },
    {
      eyebrow: '04 · FUEL TAX',
      title: 'IFTA quarterly prep',
      body: 'Echo turns fuel receipts and per-state mileage into a quarterly IFTA-ready report.',
    },
  ];
  return (
    <div style={{ marginTop: 40, paddingTop: 32, borderTop: '1px solid var(--hairline)' }}>
      <div style={{ marginBottom: 22 }}>
        <h3 style={{ fontFamily: 'var(--ff-display)', fontSize: 22, fontWeight: 400, letterSpacing: '-0.015em', color: 'var(--ink)', margin: 0 }}>
          Built for North American carriers.
        </h3>
      </div>
      <div className="freight-native-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 12 }}>
        {cards.map((c, i) => (
          <div key={i} style={{
            background: 'var(--bg)',
            border: '1px solid var(--hairline)',
            borderRadius: 10,
            padding: '18px 18px',
            display: 'flex', flexDirection: 'column', gap: 8,
          }}>
            <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9.5, letterSpacing: '0.12em', color: 'var(--accent)', textTransform: 'uppercase', fontWeight: 600 }}>{c.eyebrow}</div>
            <h4 style={{ fontFamily: 'var(--ff-display)', fontSize: 15, fontWeight: 500, letterSpacing: '-0.01em', lineHeight: 1.25, color: 'var(--ink)', margin: 0 }}>{c.title}</h4>
            <p style={{ fontSize: 12.5, color: 'var(--muted)', lineHeight: 1.55, margin: 0 }}>{c.body}</p>
          </div>
        ))}
      </div>
      <style>{`
        @media (max-width: 1024px) {
          .freight-native-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
        }
        @media (max-width: 480px) {
          .freight-native-grid { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </div>
  );
}

function PillarRow({ index, pillar }) {
  const reverse = index % 2 === 1;
  const { Visual } = pillar;
  return (
    <div className={`pillar-row ${reverse ? 'pillar-row--reverse' : ''}`} style={{
      display: 'grid',
      gridTemplateColumns: reverse ? '1fr 0.85fr' : '0.85fr 1fr',
      gap: 0,
      border: '1px solid var(--hairline)',
      borderRadius: 16,
      overflow: 'hidden',
      background: 'var(--surface)',
      minHeight: 360,
    }}>
      {/* Text panel */}
      <div className="pillar-text" style={{
        order: reverse ? 2 : 1,
        padding: 'clamp(28px, 4vw, 48px)',
        display: 'flex',
        flexDirection: 'column',
        justifyContent: 'center',
        gap: 18,
        borderRight: reverse ? 'none' : '1px solid var(--hairline)',
        borderLeft: reverse ? '1px solid var(--hairline)' : 'none',
      }}>
        <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 11, letterSpacing: '0.12em', color: 'var(--accent)', fontWeight: 500, textTransform: 'uppercase' }}>{pillar.eyebrow}</div>
        <h3 style={{ fontFamily: 'var(--ff-display)', fontSize: 'clamp(24px, 2.4vw, 32px)', fontWeight: 400, letterSpacing: '-0.025em', lineHeight: 1.05, color: 'var(--ink)' }}>
          {pillar.title}
        </h3>
        <p style={{ fontFamily: 'var(--ff-display)', fontStyle: 'italic', fontSize: 18, color: 'var(--muted)', fontWeight: 300, lineHeight: 1.4 }}>{pillar.sub}</p>
        <p style={{ fontSize: 14, color: 'var(--ink)', lineHeight: 1.7, maxWidth: 440 }}>{pillar.body}</p>
      </div>

      {/* Visual panel */}
      <div className="pillar-visual" style={{ order: reverse ? 1 : 2, padding: 'clamp(24px, 3vw, 40px)', background: 'var(--surface)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
        <div style={{ width: '100%', maxWidth: 480 }}>
          <Visual />
        </div>
      </div>
    </div>
  );
}

// ── Agents + Demo (merged, side-by-side) ──────────────────────────
// Order MUST match window.ECHO_SURFACES (Teams · SMS · Email · Slack).
function AgentsAndDemo() {
  const [active, setActive] = useStateW(0);
  const agents = [
    { id: 'triage', num: '01', name: 'Triage', domain: 'Email Triage',            channel: 'Teams',   accent: '#5059C9', tagline: 'Classifies every inbound email (rate, T&T, pickup, claim) and routes to the right action.',         outcome: 'Every email triaged. Intent classified.',        href: 'agents/triage.html' },
    { id: 'docs',   num: '02', name: 'Docs',   domain: 'Documents & AR',           channel: 'Teams',   accent: '#5B5FC7', tagline: 'Reads inbound PODs and BOLs, extracts the data, posts to TMS same shift.',                          outcome: 'Every POD posted the same shift.',              href: 'agents/docs.html' },
    { id: 'cal',    num: '03', name: 'Cal',    domain: 'Scheduling & Dispatch',    channel: 'SMS',     accent: '#30C15A', tagline: 'Takes dock bookings by SMS or Teams and books them into TMS and OpenDock.',                            outcome: 'Every booking in your TMS. Automatically.',     href: 'agents/cal.html' },
    { id: 'ledger', num: '04', name: 'Ledger', domain: 'AR & Accessorial',         channel: 'Teams',   accent: '#A855F7', tagline: 'Pulls GPS and timestamps to substantiate detention, then files the package to AR in Teams.',         outcome: 'Every detention charge documented and billed.', href: 'agents/ledger.html' },
  ];

  return (
    <section id="agents" className="plate-section" style={{ padding: '40px 0' }}>
      <div className="glass-plate glass-plate--rounded plate-pad" style={{ maxWidth: 1240, margin: '0 auto', padding: '52px 56px' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', marginBottom: 44, gap: 40, flexWrap: 'wrap' }}>
          <div>
            <Eyebrow>The agents · Live</Eyebrow>
            <h2 style={{ fontFamily: 'var(--ff-display)', fontSize: 'clamp(32px, 3.6vw, 50px)', fontWeight: 400, letterSpacing: '-0.025em', lineHeight: 1.05 }}>
              Four agents.<br />One unified back-office.
            </h2>
          </div>
        </div>

        {/* Two-column: cards left, live demo right */}
        <div className="agents-demo-grid" style={{
          display: 'grid',
          gridTemplateColumns: '380px 1fr',
          gap: 32,
          alignItems: 'stretch',
        }}>
          {/* LEFT — selectable agent cards stacked vertically */}
          <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
            {agents.map((a, i) => (
              <SelectableAgentCard key={a.id} a={a} active={i === active} onSelect={() => setActive(i)} />
            ))}
          </div>

          {/* RIGHT — live demo, controlled by the cards */}
          <div style={{ display: 'flex', flexDirection: 'column', minWidth: 0 }}>
            <HeroDemo activeIdx={active} onSelect={setActive} hideTabs={true} />
          </div>
        </div>

        <style>{`
          @media (max-width: 1024px) {
            .agents-demo-grid { grid-template-columns: 1fr !important; }
          }
        `}</style>
      </div>
    </section>
  );
}

function SelectableAgentCard({ a, active, onSelect }) {
  const [h, setH] = useStateW(false);
  const isHot = active || h;

  // The whole card is a real <a> link to the agent's dedicated page.
  // Hovering the card auto-selects this agent's demo (no click needed) so
  // primary click behavior is "open the page" — what users expect.
  const accent = a.accent || 'var(--accent)';
  return (
    <a href={a.href}
      onMouseEnter={() => { setH(true); onSelect(); }}
      onMouseLeave={() => setH(false)}
      onFocus={() => onSelect()}
      style={{
        background: active ? `${accent}14` : 'var(--bg)',
        border: `1px solid ${isHot ? accent : 'var(--hairline)'}`,
        borderLeft: `3px solid ${isHot ? accent : 'var(--hairline)'}`,
        borderRadius: 12, padding: '20px 22px',
        display: 'flex', flexDirection: 'column', gap: 10,
        cursor: 'pointer', textAlign: 'left', color: 'inherit',
        textDecoration: 'none',
        boxShadow: active ? `0 12px 40px ${accent}33` : (h ? '0 8px 24px rgba(0,0,0,0.06)' : 'none'),
        transition: 'all 0.28s cubic-bezier(0.4,0,0.2,1)',
        fontFamily: 'inherit',
      }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7, fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.1em', color: active ? accent : 'var(--muted)' }}>
          <span style={{ width: 6, height: 6, borderRadius: '50%', background: accent, opacity: active ? 1 : 0.55, transition: 'opacity 0.25s' }} />
          {a.num} · {a.channel.toUpperCase()}
        </span>
        {active && <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontFamily: 'var(--ff-mono)', fontSize: 9, letterSpacing: '0.12em', color: accent, textTransform: 'uppercase' }}>
          <span style={{ width: 6, height: 6, borderRadius: '50%', background: accent, animation: 'pulse 1.6s ease-in-out infinite', display: 'inline-block' }}></span>
          Live
        </span>}
      </div>
      <div style={{ display: 'flex', alignItems: 'baseline', gap: 12 }}>
        <div style={{ fontFamily: 'var(--ff-display)', fontSize: 30, fontWeight: 500, letterSpacing: '-0.02em', lineHeight: 1, color: 'var(--ink)' }}>{a.name}</div>
        <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9.5, letterSpacing: '0.1em', color: 'var(--muted)', textTransform: 'uppercase' }}>{a.domain}</div>
      </div>
      <p style={{ fontSize: 12.5, color: 'var(--muted)', lineHeight: 1.55, margin: 0 }}>{a.tagline}</p>
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', paddingTop: 10, borderTop: '1px solid var(--hairline)', gap: 12 }}>
        <span style={{ fontSize: 11.5, color: 'var(--ink)', fontWeight: 500, lineHeight: 1.4, display: 'flex', alignItems: 'center', gap: 7, minWidth: 0 }}>
          <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke={accent} strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" style={{ flexShrink: 0 }}><polyline points="9 18 15 12 9 6"/></svg>
          <span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{a.outcome}</span>
        </span>
        <span style={{
          fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.08em',
          color: isHot ? accent : 'var(--muted)',
          textTransform: 'uppercase',
          display: 'inline-flex', alignItems: 'center', gap: 5, flexShrink: 0,
          transition: 'color 0.2s',
        }}>
          View {a.name}
          <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" style={{ transform: isHot ? 'translateX(3px)' : 'none', transition: 'transform 0.25s' }}><path d="M5 12h14M12 5l7 7-7 7"/></svg>
        </span>
      </div>
    </a>
  );
}

Object.assign(window, { WhyEcho, AgentsAndDemo });
