// sections.jsx — All homepage sections
const { useState, useEffect, useRef } = React;

function useInView(threshold = 0.12) {
  const ref = useRef(null);
  const [visible, setVisible] = useState(false);
  useEffect(() => {
    const el = ref.current; if (!el) return;
    const obs = new IntersectionObserver(([e]) => {
      if (e.isIntersecting) { setVisible(true); obs.disconnect(); }
    }, { threshold });
    obs.observe(el);
    return () => obs.disconnect();
  }, []);
  return [ref, visible];
}

function useCountUp(target, duration = 1600, started = false) {
  const [val, setVal] = useState(0);
  useEffect(() => {
    if (!started) return;
    let start = null;
    const isNum = typeof target === 'number';
    if (!isNum) return;
    const step = (ts) => {
      if (!start) start = ts;
      const p = Math.min((ts - start) / duration, 1);
      const ease = 1 - Math.pow(1 - p, 3);
      setVal(Math.floor(ease * target));
      if (p < 1) requestAnimationFrame(step);
    };
    requestAnimationFrame(step);
  }, [started, target, duration]);
  return val;
}

function Eyebrow({ children, light }) {
  return (
    <div style={{
      fontFamily: 'var(--ff-mono)', fontSize: 11, letterSpacing: '0.12em',
      textTransform: 'uppercase', color: light ? 'rgba(255,255,255,0.35)' : 'var(--muted)',
      marginBottom: 20,
    }}>{children}</div>
  );
}

// ── Logo SVG ──────────────────────────────────────────────────────
// Tight 32×28 viewBox. Solid dot at left, then three concentric arcs.
// Each arc is the right-opening half-circle of its radius. Radii grow in
// arithmetic 5 → 8 → 11 so the stroke spacing stays visually even.
// Anchor x for each arc = (16 - r/2) so they share a center column near
// x=16 and read as one tightening wave. Endpoints (cx, cy±r) lie exactly
// on each circle so the arc geometry is mathematically clean.
function EchoLogo({ size = 28 }) {
  // Brand mark — uses the canonical Echo logo image asset.
  return (
    <img
      src="img/echo-logo.jpeg"
      alt="Echo"
      width={size}
      height={size}
      style={{ display: 'block', borderRadius: 4, objectFit: 'contain' }}
    />
  );
}

// (DemoSection removed — demo is now embedded inside the Agents section.)

// ── Problem ───────────────────────────────────────────────────────
function StatCard({ prefix = '', value, suffix = '', label, source, started }) {
  const count = useCountUp(typeof value === 'number' ? value : 0, 1800, started);
  const isNum = typeof value === 'number';
  const display = isNum ? `${prefix}${count.toLocaleString()}${suffix}` : value;

  return (
    <div style={{ background: 'var(--bg)', border: '1px solid var(--hairline)', borderRadius: 12, padding: '24px 20px', display: 'flex', flexDirection: 'column', gap: 12, transition: 'border-color 0.25s, transform 0.25s', cursor: 'default', minHeight: 168 }}
      onMouseEnter={e => { e.currentTarget.style.borderColor = 'var(--accent)'; e.currentTarget.style.transform = 'translateY(-2px)'; }}
      onMouseLeave={e => { e.currentTarget.style.borderColor = 'var(--hairline)'; e.currentTarget.style.transform = 'none'; }}
    >
      <div className="stat-value" style={{ fontFamily: 'var(--ff-display)', fontSize: 'clamp(22px, 2.4vw, 36px)', fontWeight: 400, color: 'var(--ink)', lineHeight: 1.05, letterSpacing: '-0.025em' }}>{display}</div>
      <div className="stat-label" style={{ fontSize: 12.5, color: 'var(--ink)', lineHeight: 1.45, fontWeight: 500 }}>{label}</div>
      <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.08em', color: 'var(--muted)', marginTop: 'auto', textTransform: 'uppercase' }}>{source}</div>
    </div>
  );
}

function Problem() {
  const [ref, visible] = useInView(0.12);
  const stats = [
    { value: '10+ days',   label: 'To close month-end in Oracle.',          source: 'BlackLine · Close benchmark 2025' },
    { value: '40+ hrs',    label: 'Per vendor keyed into Fusion AP.',        source: 'Ardent Partners · 2024' },
    { value: '$148K/yr',   label: 'On disconnected finance point tools.',    source: 'Gartner · Finance ops 2025' },
    { value: '60%',        label: 'Of audit prep gathering GRC evidence.',   source: 'ISACA · Audit benchmark' },
  ];
  return (
    <section className="plate-section" style={{ padding: '40px 0' }}>
      <div ref={ref} className="glass-plate glass-plate--rounded plate-pad" style={{ maxWidth: 1240, margin: '0 auto', padding: '52px 56px' }}>
        <Eyebrow>The problem</Eyebrow>
        <div className="problem-header" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 48, marginBottom: 56, alignItems: 'end' }}>
          <h2 style={{ fontFamily: 'var(--ff-display)', fontSize: 'clamp(32px, 3.6vw, 50px)', fontWeight: 400, lineHeight: 1.1, letterSpacing: '-0.02em' }}>
            Where time<br />
            <em style={{ fontStyle: 'italic', fontWeight: 300, color: 'var(--muted)' }}>and money leak.</em>
          </h2>
          <p style={{ fontSize: 15, color: 'var(--muted)', lineHeight: 1.6, maxWidth: 420 }}>
            Fusion, NetSuite, and JD Edwards are powerful. Your team still handles the manual work between those systems and the business: onboarding, reconciliation, support, compliance.
          </p>
        </div>
        <div className="problem-stats stats-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14 }}>
          {stats.map((s, i) => <StatCard key={i} {...s} started={visible} />)}
        </div>
      </div>
    </section>
  );
}

// ── Agent glyphs ──────────────────────────────────────────────────
const glyphs = {
  Docs:   <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="3" width="18" height="13" rx="2"/><path d="M7 8h4M7 11h6"/><path d="M8 21h8M12 16v5"/></svg>,
  Triage: <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><polyline points="22,6 12,13 2,6"/></svg>,
  Audit:  <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>,
  Ledger: <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/></svg>,
};

function AgentCard({ num, name, domain, tagline, outcome, href, delay = 0 }) {
  const [hovered, setHovered] = useState(false);
  return (
    <a href={href} onMouseEnter={() => setHovered(true)} onMouseLeave={() => setHovered(false)} style={{
      background: 'var(--bg)', border: `1px solid ${hovered ? 'var(--accent)' : 'var(--hairline)'}`,
      borderRadius: 12, padding: '28px 24px', display: 'flex', flexDirection: 'column', gap: 16,
      cursor: 'pointer', textDecoration: 'none', color: 'inherit',
      transform: hovered ? 'translateY(-3px)' : 'none',
      boxShadow: hovered ? '0 12px 40px var(--accent-glow)' : 'none',
      transition: 'all 0.28s cubic-bezier(0.4,0,0.2,1)',
    }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
        <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.1em', color: 'var(--muted)' }}>{num}</span>
        <span style={{ display: 'flex', alignItems: 'center', gap: 8, color: hovered ? 'var(--accent)' : 'var(--muted)', transition: 'color 0.28s' }}>
          {glyphs[name]}
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" style={{ transform: hovered ? 'translate(2px, -2px)' : 'none', transition: 'transform 0.28s' }}><path d="M7 17L17 7M7 7h10v10"/></svg>
        </span>
      </div>
      <div>
        <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.1em', color: 'var(--muted)', textTransform: 'uppercase', marginBottom: 6 }}>{domain}</div>
        <div style={{ fontFamily: 'var(--ff-display)', fontSize: 34, fontWeight: 400, letterSpacing: '-0.02em', lineHeight: 1 }}>{name}</div>
      </div>
      <p style={{ fontSize: 13, color: 'var(--muted)', lineHeight: 1.6, margin: 0 }}>{tagline}</p>
      <div style={{ marginTop: 'auto', paddingTop: 14, borderTop: '1px solid var(--hairline)', display: 'flex', alignItems: 'flex-start', gap: 8 }}>
        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" style={{ flexShrink: 0, marginTop: 2 }}><polyline points="9 18 15 12 9 6"/></svg>
        <span style={{ fontSize: 12, color: 'var(--ink)', fontWeight: 500, lineHeight: 1.5 }}>{outcome}</span>
      </div>
    </a>
  );
}

function Agents() {
  const agents = [
    { num: '01 · ONBOARDING',  name: 'Docs',   domain: 'Vendor & Customer Onboarding',  tagline: 'Parses W-9s and vendor packets. Posts to Fusion AP or NetSuite with read-back validation.', outcome: 'Every new vendor and customer live in Oracle the same day.',                href: 'agents/docs.html' },
    { num: '02 · AR · CLOSE',  name: 'Ledger', domain: 'AR Cash App & Month-End Close', tagline: 'Matches remittances to open Oracle AR invoices, applies cash, flags disputes, and closes in Fusion GL.',                       outcome: '95%+ auto-applied to Oracle AR. Close in 2 days.',  href: 'agents/ledger.html' },
    { num: '03 · COMPLIANCE',  name: 'Audit',  domain: 'Audit & Evidence',              tagline: 'Pulls SOC 2, SOX, and audit evidence from Oracle GRC and Azure AD. Flags expiring controls, drafts responses same day.',     outcome: 'Same-day auditor response. 60% audit prep saved.',  href: 'agents/audit.html' },
    { num: '04 · SUPPORT',     name: 'Triage', domain: 'Finance Support Triage',        tagline: 'Classifies inbound finance tickets, pulls the Oracle record, and routes with a draft reply in under 60 seconds.', outcome: 'Every ticket classified and drafted in under 60 seconds.', href: 'agents/triage.html' },
  ];
  return (
    <section id="agents" style={{ padding: '60px 0' }}>
      <div style={{ maxWidth: 1160, margin: '0 auto', padding: '0 40px' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', marginBottom: 32 }}>
          <div>
            <Eyebrow>Meet the agents</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>
          <a href="agents/docs.html" style={{ fontFamily: 'var(--ff-mono)', fontSize: 11, letterSpacing: '0.08em', color: 'var(--muted)', display: 'flex', alignItems: 'center', gap: 7, borderBottom: '1px solid var(--hairline)', paddingBottom: 2, textTransform: 'uppercase', transition: 'all 0.2s' }}
            onMouseEnter={e => { e.currentTarget.style.color = 'var(--ink)'; e.currentTarget.style.borderColor = 'var(--ink)'; }}
            onMouseLeave={e => { e.currentTarget.style.color = 'var(--muted)'; e.currentTarget.style.borderColor = 'var(--hairline)'; }}
          >
            All agents
            <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round"><path d="M5 12h14M12 5l7 7-7 7"/></svg>
          </a>
        </div>
        <div className="agents-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14 }}>
          {agents.map((a, i) => <AgentCard key={a.name} {...a} delay={i * 70} />)}
        </div>
      </div>
    </section>
  );
}

// ── How It Works ──────────────────────────────────────────────────
function HowItWorks() {
  const steps = [
    {
      tag: 'Step 01 · Connect',
      title: 'Point Echo at your Oracle stack',
      body: 'Azure AD SSO and read-write access to Fusion Cloud, NetSuite, or JD Edwards via Oracle REST APIs. Provisioned in your Azure tenant.',
      items: ['Azure AD / Entra SSO', 'Oracle REST API access', 'Azure OpenAI (your tenant)', 'No data egress'],
    },
    {
      tag: 'Step 02 · Configure',
      title: 'Assign agents to channels',
      body: 'Each agent connects to its channel: Teams, Slack, or email. Set escalation rules, approval thresholds, and per-workflow overrides.',
      items: ['Teams / Slack / Email', 'Escalation thresholds', 'Human-in-the-loop controls', 'Role-based overrides'],
    },
    {
      tag: 'Step 03 · Operate',
      title: 'Atlas keeps watch',
      body: 'Every action logged with Oracle module, confidence score, and outcome. The Atlas dashboard gives finance and compliance a full audit trail.',
      items: ['Live audit log', 'Atlas dashboard', 'Oracle module tracking', '24/7 operation'],
    },
  ];
  return (
    <section id="how-it-works" 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' }}>
        <Eyebrow>Deployment</Eyebrow>
        <h2 style={{ fontFamily: 'var(--ff-display)', fontSize: 'clamp(32px, 3.6vw, 50px)', fontWeight: 400, letterSpacing: '-0.02em', lineHeight: 1.1, marginBottom: 60, maxWidth: 480 }}>
          Operational in weeks,<br /><em style={{ fontStyle: 'italic', fontWeight: 300 }}>not months.</em>
        </h2>
        <div className="how-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', borderTop: '1px solid var(--hairline)' }}>
          {steps.map((s, i) => (
            <div key={i} className={`how-step${i < 2 ? ' how-step--bordered' : ''}`} style={{ padding: '36px', borderRight: i < 2 ? '1px solid var(--hairline)' : 'none' }}>
              <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.1em', color: 'var(--accent)', textTransform: 'uppercase', marginBottom: 20 }}>{s.tag}</div>
              <h3 style={{ fontFamily: 'var(--ff-display)', fontSize: 22, fontWeight: 400, marginBottom: 12, letterSpacing: '-0.01em' }}>{s.title}</h3>
              <p style={{ fontSize: 13, color: 'var(--muted)', lineHeight: 1.7, marginBottom: 24 }}>{s.body}</p>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 7 }}>
                {s.items.map(d => (
                  <div key={d} style={{ display: 'flex', alignItems: 'center', gap: 9 }}>
                    <div style={{ width: 4, height: 4, borderRadius: '50%', background: 'var(--accent)', flexShrink: 0 }}></div>
                    <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.06em', color: 'var(--muted)', textTransform: 'uppercase' }}>{d}</span>
                  </div>
                ))}
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ── Comparison ────────────────────────────────────────────────────
function Comparison() {
  const [ref, visible] = useInView(0.08);
  const rows = [
    { workflow: 'Vendor onboarding', today: 'AP keys W-9, banking, and vendor record into Oracle AP by hand', echo: 'Docs extracts and posts to Fusion AP same day' },
    { workflow: 'Cash application',  today: 'AR manually matches remittances against Oracle AR open items',   echo: 'Ledger matches and posts to Oracle AR automatically' },
    { workflow: 'Month-end close',   today: '7-day Fusion GL scramble across finance and ops',                echo: 'Ledger closes in 2 days with pre-reconciled AR' },
    { workflow: 'Support triage',    today: 'CSR looks up Oracle record, routes manually with no context',    echo: 'Triage pulls Oracle context, routes with draft reply in 60s' },
    { workflow: 'Audit evidence',    today: 'Compliance pulls Oracle GRC logs and screenshots manually',      echo: 'Audit pulls Oracle GRC + Azure AD, packages same day' },
  ];
  return (
    <section 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' }}>
        <Eyebrow>Today vs. Echo</Eyebrow>
        {/* (Pillar section is 04 · Why Echo) */}
        <h2 style={{ fontFamily: 'var(--ff-display)', fontSize: 'clamp(32px, 3.6vw, 50px)', fontWeight: 400, letterSpacing: '-0.02em', lineHeight: 1.1, marginBottom: 52, maxWidth: 480 }}>
          What changes when<br /><em style={{ fontStyle: 'italic', fontWeight: 300, color: 'var(--muted)' }}>agents go to work.</em>
        </h2>
        <div ref={ref} className="compare-table" style={{ border: '1px solid var(--hairline)', borderRadius: 12, overflow: 'hidden' }}>
          <div className="compare-header" style={{ display: 'grid', gridTemplateColumns: '180px 1fr 1fr', background: 'var(--surface)' }}>
            {[['WORKFLOW', false], ['TODAY', false], ['WITH ECHO', true]].map(([h, accent]) => (
              <div key={h} style={{ padding: '12px 18px', fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.12em', color: accent ? 'var(--accent)' : 'var(--muted)', borderRight: h !== 'WITH ECHO' ? '1px solid var(--hairline)' : 'none', borderBottom: '1px solid var(--hairline)' }}>{h}</div>
            ))}
          </div>
          {rows.map((r, i) => (
            <div key={i} className="compare-row" style={{
              display: 'grid', gridTemplateColumns: '180px 1fr 1fr',
              borderBottom: i < rows.length - 1 ? '1px solid var(--hairline)' : 'none',
              opacity: visible ? 1 : 0,
              transform: visible ? 'none' : 'translateX(-10px)',
              transition: `opacity 0.5s cubic-bezier(0,0,0.2,1) ${i * 70}ms, transform 0.5s cubic-bezier(0,0,0.2,1) ${i * 70}ms`,
            }}>
              <div className="compare-cell compare-cell--label" style={{ padding: '16px 18px', borderRight: '1px solid var(--hairline)', fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.07em', color: 'var(--muted)', textTransform: 'uppercase', display: 'flex', alignItems: 'center' }}>{r.workflow}</div>
              <div className="compare-cell compare-cell--today" data-mobile-label="TODAY" style={{ padding: '16px 18px', borderRight: '1px solid var(--hairline)', fontSize: 13, color: 'var(--muted)', lineHeight: 1.55, display: 'flex', alignItems: 'center' }}>{r.today}</div>
              <div className="compare-cell compare-cell--echo" data-mobile-label="WITH ECHO" style={{ padding: '16px 18px', fontSize: 13, color: 'var(--ink)', lineHeight: 1.55, display: 'flex', alignItems: 'center', gap: 10 }}>
                <span style={{ width: 5, height: 5, borderRadius: '50%', background: 'var(--accent)', flexShrink: 0 }}></span>
                {r.echo}
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ── Vertical Teasers ──────────────────────────────────────────────
// Cross-links to Echo's other industry verticals. Each card carries
// its own accent so the section reads as "same shape, different domain"
// at a glance — no need to read every word.
function VerticalCard({ tag, accent, name, sub, body, href }) {
  const [hovered, setHovered] = useState(false);
  return (
    <a
      href={href}
      onMouseEnter={() => setHovered(true)}
      onMouseLeave={() => setHovered(false)}
      style={{
        position: 'relative',
        background: 'var(--bg)',
        border: `1px solid ${hovered ? accent : 'var(--hairline)'}`,
        borderRadius: 12,
        padding: '26px 24px 22px',
        display: 'flex',
        flexDirection: 'column',
        gap: 14,
        cursor: 'pointer',
        textDecoration: 'none',
        color: 'inherit',
        transform: hovered ? 'translateY(-3px)' : 'none',
        boxShadow: hovered ? `0 14px 40px ${accent}33` : 'none',
        transition: 'border-color 0.28s, transform 0.28s, box-shadow 0.28s',
        overflow: 'hidden',
      }}
    >
      {/* Accent corner bar — sits flush against top-left, signature mark */}
      <span style={{
        position: 'absolute', top: 0, left: 0,
        width: 44, height: 3, background: accent,
        borderTopLeftRadius: 12,
      }} />
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
        <span style={{
          display: 'inline-flex', alignItems: 'center', gap: 8,
          fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.12em',
          color: 'var(--muted)', textTransform: 'uppercase',
        }}>
          <span style={{ width: 7, height: 7, borderRadius: '50%', background: accent, flexShrink: 0 }} />
          {tag}
        </span>
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke={hovered ? accent : 'var(--muted)'} strokeWidth="2" strokeLinecap="round" style={{ transform: hovered ? 'translate(2px, -2px)' : 'none', transition: 'transform 0.28s, stroke 0.28s' }}>
          <path d="M7 17L17 7M7 7h10v10"/>
        </svg>
      </div>
      <div>
        <div style={{ fontFamily: 'var(--ff-display)', fontSize: 24, fontWeight: 400, letterSpacing: '-0.015em', lineHeight: 1.15, marginBottom: 6 }}>{name}</div>
        <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.08em', color: 'var(--muted)', textTransform: 'uppercase' }}>{sub}</div>
      </div>
      <p style={{ fontSize: 13, color: 'var(--muted)', lineHeight: 1.6, margin: 0 }}>{body}</p>
      <div style={{ marginTop: 'auto', paddingTop: 12, borderTop: '1px solid var(--hairline)', display: 'flex', alignItems: 'center', gap: 7 }}>
        <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 11, letterSpacing: '0.08em', color: hovered ? accent : 'var(--ink)', textTransform: 'uppercase', fontWeight: 600, transition: 'color 0.28s' }}>
          View
        </span>
        <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke={hovered ? accent : 'var(--ink)'} strokeWidth="2.4" strokeLinecap="round" style={{ transform: hovered ? 'translateX(3px)' : 'none', transition: 'transform 0.28s, stroke 0.28s' }}>
          <path d="M5 12h14M12 5l7 7-7 7"/>
        </svg>
      </div>
    </a>
  );
}

function VerticalTeasers() {
  const verticals = [
    {
      tag: 'Carriers',
      accent: '#60A5FA',
      name: 'Carriers',
      sub: 'LTL · Truckload · 3PL fleets',
      body: 'Email, PODs, dispatch, and detention claims handled inside Teams and TruckMate.',
      href: '/',
    },
    {
      tag: 'Freight Brokers',
      accent: '#F59E0B',
      name: 'Freight Brokers & 3PLs',
      sub: 'Brokers · Tender-to-cash',
      body: 'Load posting, carrier check-calls, and settlement on autopilot.',
      href: '/freight',
    },
    {
      tag: 'Regen Health',
      accent: '#10B981',
      name: 'Regenerative Health Clinics',
      sub: 'Patient intake · Claims · AR',
      body: 'Intake, eligibility, and claims for regenerative and aesthetic clinics.',
      href: '/health',
    },
  ];
  return (
    <section 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' }}>
        <Eyebrow>More verticals</Eyebrow>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 48, marginBottom: 48, alignItems: 'end' }} className="problem-header">
          <h2 style={{ fontFamily: 'var(--ff-display)', fontSize: 'clamp(32px, 3.6vw, 50px)', fontWeight: 400, lineHeight: 1.1, letterSpacing: '-0.02em' }}>
            Echo runs on<br />other stacks too.
          </h2>
          <p style={{ fontSize: 15, color: 'var(--muted)', lineHeight: 1.6, maxWidth: 420 }}>
            One playbook. Carriers, brokerage, and clinics.
          </p>
        </div>
        <div className="verticals-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 14 }}>
          {verticals.map(v => <VerticalCard key={v.href} {...v} />)}
        </div>
      </div>
    </section>
  );
}

// ── FAQ ───────────────────────────────────────────────────────────
// Single-open accordion. Click a question to expand its answer; opening
// a new one closes the rest. Chevron rotates 180° on the open row.
function FaqItem({ q, a, open, onToggle, isLast }) {
  return (
    <div style={{
      borderBottom: isLast ? 'none' : '1px solid var(--hairline)',
    }}>
      <button
        onClick={onToggle}
        aria-expanded={open}
        style={{
          width: '100%',
          display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 24,
          padding: '22px 4px',
          background: 'none', border: 'none', cursor: 'pointer',
          textAlign: 'left',
          color: 'inherit',
          transition: 'color 0.2s',
        }}
        onMouseEnter={e => e.currentTarget.style.color = 'var(--accent)'}
        onMouseLeave={e => e.currentTarget.style.color = ''}
      >
        <span style={{
          fontFamily: 'var(--ff-display)', fontSize: 18, fontWeight: 400,
          letterSpacing: '-0.005em', lineHeight: 1.35,
          color: open ? 'var(--accent)' : 'var(--ink)',
          transition: 'color 0.2s',
        }}>{q}</span>
        <span style={{
          flexShrink: 0,
          width: 28, height: 28, borderRadius: '50%',
          border: `1px solid ${open ? 'var(--accent)' : 'var(--hairline)'}`,
          display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
          color: open ? 'var(--accent)' : 'var(--muted)',
          transition: 'border-color 0.25s, color 0.25s',
        }}>
          <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" style={{ transform: open ? 'rotate(180deg)' : 'none', transition: 'transform 0.28s cubic-bezier(0.4,0,0.2,1)' }}>
            <path d="M6 9l6 6 6-6"/>
          </svg>
        </span>
      </button>
      <div style={{
        maxHeight: open ? 280 : 0,
        opacity: open ? 1 : 0,
        overflow: 'hidden',
        transition: 'max-height 0.4s cubic-bezier(0.16,1,0.3,1), opacity 0.3s ease, padding 0.3s ease',
        paddingBottom: open ? 22 : 0,
      }}>
        <p style={{
          fontSize: 14.5, color: 'var(--muted)', lineHeight: 1.7,
          maxWidth: 720, paddingRight: 52,
        }}>{a}</p>
      </div>
    </div>
  );
}

function FAQ() {
  const [openIdx, setOpenIdx] = useState(-1);
  const items = [
    {
      q: 'How long does Echo take to deploy?',
      a: 'Your first agent goes live in 2 to 3 weeks. The full suite is running within 6.',
    },
    {
      q: 'Does Echo replace my finance staff?',
      a: 'No. Echo takes the repetitive work off your AR, AP, and audit teams: invoice matching, vendor onboarding, audit evidence pulls. Your team gets back to closing the books and handling exceptions.',
    },
    {
      q: 'Does it integrate with Oracle Fusion or NetSuite?',
      a: 'Yes. Echo reads and writes through your existing Fusion or NetSuite APIs. Read-write access stays in your tenant. Your data never leaves your systems.',
    },
    {
      q: 'What if an agent gets it wrong?',
      a: 'Every action needs human approval by default, and you set the confidence threshold. Atlas logs every decision with full context, so your audit team gets the trail they have been asking for.',
    },
    {
      q: 'Who owns the data?',
      a: 'You do. Echo runs inside your Microsoft Azure tenant. Your GL entries, vendor records, and customer master data stay where they already live.',
    },
    {
      q: 'What does it cost?',
      a: 'Pricing is per agent. One flat rate per agent per month. Book a demo for the number on your volume.',
    },
  ];
  return (
    <section id="faq" 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 className="faq-grid" style={{ display: 'grid', gridTemplateColumns: '320px 1fr', gap: 64, alignItems: 'start' }}>
          <div>
            <Eyebrow>Frequently asked</Eyebrow>
            <h2 style={{ fontFamily: 'var(--ff-display)', fontSize: 'clamp(32px, 3.2vw, 44px)', fontWeight: 400, letterSpacing: '-0.02em', lineHeight: 1.1, marginBottom: 20 }}>
              What finance teams<br /><em style={{ fontStyle: 'italic', fontWeight: 300, color: 'var(--muted)' }}>usually ask.</em>
            </h2>
            <p style={{ fontSize: 14, color: 'var(--muted)', lineHeight: 1.65 }}>
              Don't see your question? Book a call and we'll answer it directly.
            </p>
          </div>
          <div>
            {items.map((it, i) => (
              <FaqItem
                key={i}
                q={it.q}
                a={it.a}
                open={openIdx === i}
                onToggle={() => setOpenIdx(openIdx === i ? -1 : i)}
                isLast={i === items.length - 1}
              />
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

// ── Solutions row (footer vertical nav) ───────────────────────────
function SolutionsRow({ current }) {
  const items = [
    { href: '/', label: 'Carriers', key: 'carriers' },
    { href: '/erp', label: 'Oracle ERP', key: 'erp' },
    { href: '/freight', label: 'Freight & Logistics', key: 'freight' },
    { href: '/health', label: 'Regenerative Health', key: 'health' },
  ];
  return (
    <div style={{ borderTop: '1px solid var(--hairline)', padding: '16px 0 18px', display: 'flex', alignItems: 'center', gap: 16, flexWrap: 'wrap' }}>
      <style>{`.echo-solutions-link{color:var(--muted);text-decoration:none;border-bottom:1px solid transparent;transition:color 200ms ease,border-color 200ms ease}.echo-solutions-link:hover{color:var(--ink);border-bottom-color:var(--ink)}`}</style>
      <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, color: 'var(--muted)', letterSpacing: '0.14em', textTransform: 'uppercase' }}>Verticals</span>
      <div style={{ display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
        {items.map((v, i) => (
          <span key={v.key} style={{ display: 'inline-flex', alignItems: 'center', gap: 10 }}>
            {v.key === current ? (
              <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 11, color: 'var(--muted-soft)', letterSpacing: '0.08em', textTransform: 'uppercase' }}>{v.label}</span>
            ) : (
              <a href={v.href} className="echo-solutions-link" style={{ fontFamily: 'var(--ff-mono)', fontSize: 11, letterSpacing: '0.08em', textTransform: 'uppercase' }}>{v.label}</a>
            )}
            {i < items.length - 1 && <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 11, color: 'var(--hairline)' }}>·</span>}
          </span>
        ))}
      </div>
    </div>
  );
}

// ── Footer ────────────────────────────────────────────────────────
function Footer() {
  return (
    <footer className="plate-section" style={{ padding: '40px 0 60px' }}>
      <div className="glass-plate glass-plate--rounded plate-pad-footer" style={{ maxWidth: 1240, margin: '0 auto', padding: '48px 56px 32px' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', gap: 32, flexWrap: 'wrap', marginBottom: 32 }}>
          <div>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 14 }}>
              <EchoLogo size={26} />
              <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 13, fontWeight: 500, letterSpacing: '0.05em' }}>Echo</span>
            </div>
            <p style={{ fontFamily: 'var(--ff-display)', fontSize: 16, color: 'var(--ink)', lineHeight: 1.5, maxWidth: 320, fontWeight: 400, letterSpacing: '-0.01em' }}>
              AI agents for Oracle ERP teams.<br/>
              <span style={{ color: 'var(--muted)', fontStyle: 'italic', fontWeight: 300 }}>Built on your stack. Owned by you.</span>
            </p>
          </div>
          <a href="#book" data-open-book-call className="echo-cta echo-cta--primary">
            Get a demo
          </a>
        </div>
        <SolutionsRow current="erp" />
        <div style={{ borderTop: '1px solid var(--hairline)', paddingTop: 20, display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: 12 }}>
          <span style={{ display: 'inline-flex', alignItems: 'center', gap: 14, flexWrap: 'wrap', fontFamily: 'var(--ff-mono)', fontSize: 10, color: 'var(--muted)', letterSpacing: '0.07em' }}>
            <span>© 2026 ELITE CAPITAL INC.</span>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 8 }}>
              <a href="/privacy.html" className="echo-solutions-link">Privacy</a>
              <span style={{ color: 'var(--hairline)' }}>·</span>
              <a href="/terms.html" className="echo-solutions-link">Terms</a>
              <span style={{ color: 'var(--hairline)' }}>·</span>
              <a href="/security.html" className="echo-solutions-link">Security</a>
              <span style={{ color: 'var(--hairline)' }}>·</span>
              <a href="mailto:jay@echoagents.io" className="echo-solutions-link">Contact</a>
            </span>
          </span>
          <div style={{ display: 'flex', alignItems: 'center', gap: 14, flexWrap: 'wrap' }}>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7, fontFamily: 'var(--ff-mono)', fontSize: 10, color: 'var(--muted)', letterSpacing: '0.07em' }}>
              <span style={{ width: 6, height: 6, borderRadius: '50%', background: '#7DC9A8', boxShadow: '0 0 6px rgba(125,201,168,0.6)', animation: 'pulse 2.4s ease-in-out infinite' }} />
              All systems operational
            </span>
            <span style={{ display: 'inline-flex', alignItems: 'baseline', gap: 6, fontFamily: 'var(--ff-mono)', fontSize: 10, color: 'var(--muted)', letterSpacing: '0.07em' }}>
              SOC 2
              <span style={{ fontSize: 9, opacity: 0.7 }}>(Type II in progress)</span>
            </span>
          </div>
        </div>
      </div>
    </footer>
  );
}

Object.assign(window, { EchoLogo, Problem, Agents, HowItWorks, Comparison, VerticalTeasers, FAQ, Footer });
