// 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: '5-8%',    label: 'Overcharge on the avg carrier invoice.',   source: 'FreightAudit.com benchmark' },
    { value: '60 days', label: 'Claim window. Most brokers miss it.',     source: 'NMFTA claims rules' },
    { value: '2 days',  label: 'Avg email response, mid-size brokers.',    source: 'Industry benchmark 2025' },
    { value: '40+ hrs', label: 'To onboard one shipper in TMS.',           source: 'Ardent Partners 2024' },
  ];
  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 }}>
            Freight back-office runs on manual invoice review, untracked claims, and inbox triage.
          </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 = {
  Recover: <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>,
  Quote:   <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="18" rx="3"/><path d="M12 7v10M9.5 9.5c0-1.2 1.1-2 2.5-2s2.5 0.8 2.5 2c0 1-0.8 1.6-2.5 2-1.7 0.4-2.5 1-2.5 2 0 1.2 1.1 2 2.5 2s2.5-0.8 2.5-2"/></svg>,
  Docs:    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><polyline points="16 11 18 13 22 9"/></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 · AP · CARRIER AUDIT',        name: 'Recover', domain: 'Invoice Audit',                tagline: 'Audits every carrier invoice against booked rate and tariff. Flags overcharges before AP pays.',   outcome: 'Recovers 5-8% of every carrier invoice.',            href: 'agents/recover.html' },
    { num: '02 · CUSTOMER SERVICE · EMAIL',  name: 'Triage',  domain: 'Email Triage',                 tagline: 'Classifies every inbound email, pulls the shipment record, and drafts a reply.',                     outcome: 'Every customer email answered in under 4 minutes.',   href: 'agents/triage.html' },
    { num: '03 · PRICING · QUOTING',         name: 'Quote',   domain: 'Rate Quotes & Contract Lookup',tagline: 'Parses rate requests, pulls contract pricing or spot rates, and returns a quote in minutes.',         outcome: 'Every rate request quoted in under 5 minutes.',       href: 'agents/quote.html' },
    { num: '04 · ONBOARDING · PLATFORM',     name: 'Docs',    domain: 'Shipper Onboarding',           tagline: 'Reads new shipper applications, creates the TMS account, and sends the welcome email.',              outcome: 'Every new shipper onboarded same day.',               href: 'agents/docs.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/recover.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 stack',
      body: 'Azure AD SSO and read-write TMS access (TruckMate, McLeod, TMW), provisioned in your tenant.',
      items: ['Azure AD / Entra SSO', 'Your TMS API access', 'Azure OpenAI (your tenant)', 'No data egress'],
    },
    {
      tag: 'Step 02 · Configure',
      title: 'Assign agents to channels',
      body: 'Each agent connects to Teams, SMS, or email. Set escalation rules, thresholds, and overrides.',
      items: ['Teams / SMS / Email', 'Escalation thresholds', 'Human-in-the-loop controls', 'Role-based overrides'],
    },
    {
      tag: 'Step 03 · Operate',
      title: 'Atlas keeps watch',
      body: 'Every agent action is logged. Atlas shows what each agent did, why, and when.',
      items: ['Live audit log', 'Atlas dashboard', 'SLA 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: 'Invoice audit',       today: 'AP spot-checks. Most overcharges clear undetected.',     echo: 'Recover audits every invoice against booked rate before payment' },
    { workflow: 'Customer emails',     today: 'CSR reads, looks up shipment, types reply. 2-day avg.',  echo: 'Triage classifies, pulls status, sends draft reply in 4 minutes' },
    { workflow: 'Rate quotes',         today: 'Pricing team builds each quote by hand. Hours per lane.',echo: 'Quote pulls contract or spot rate, returns a quote in 5 minutes' },
    { workflow: 'Shipper onboarding',  today: 'Manual verification and data entry across 3 systems',    echo: 'Docs verifies and creates the account same day' },
    { workflow: 'Win rate',            today: 'Lost to faster brokers. No visibility on why.',          echo: 'Quote tracks every quote, posts win rate by lane each week' },
  ];
  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: 'Oracle ERP',
      accent: '#0EA5E9',
      name: 'Oracle ERP',
      sub: 'Fusion · NetSuite · JD Edwards',
      body: 'Agents that close the books faster inside Fusion and NetSuite.',
      href: '/erp',
    },
    {
      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, finance, 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 broker staff?',
      a: 'No. Echo takes the repetitive work off your dispatchers and ops team: load posting, carrier check-calls, settlement audits. Your team gets back to building customer relationships.',
    },
    {
      q: 'Does it integrate with my TMS or load board?',
      a: 'Yes. Echo works with McLeod, Aljex, Tai, DAT, and Truckstop via API. 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 for your audit trail.',
    },
    {
      q: 'Who owns the data?',
      a: 'You do. Echo runs inside your Microsoft Azure tenant. Your loads, carrier 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 freight brokers<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 freight brokers and 3PLs.<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="freight" />
        <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 });
