// 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: '45 days',  label: 'Average AR cycle, private-pay regenerative.',  source: 'MGMA · 2024' },
    { value: '23%',      label: 'High-ticket plans uncollected past 60 days.',  source: 'Kareo · specialty practice' },
    { value: '40%',      label: 'No-shows with no reminder in the prior 48hrs.', source: 'Accenture Health · 2024' },
    { value: '1 in 4',   label: 'Consent doc errors in specialty audits.',      source: 'OIG · 2023' },
  ];
  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 }}>
            Private-pay clinic back-offices run on manual intake, paper chases, and slow AR.
          </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 = {
  Intake: <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75"/></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>,
  Cal:    <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="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></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="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 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 · INTAKE · AUTHORIZATION',    name: 'Intake', domain: 'Patient Intake',           tagline: 'Collects intake forms, verifies ID, checks prior auth, and posts the record to your EHR.',          outcome: 'Intake complete before the first appointment.',         href: 'agents/intake.html' },
    { num: '02 · AR · COLLECTIONS',          name: 'Ledger', domain: 'AR & Collections',         tagline: 'Tracks balances, sends reminders, posts cash, and flags overdue accounts before they age.',            outcome: 'AR cycle cut from 45 days to under 14.',                href: 'agents/ledger.html' },
    { num: '03 · SCHEDULING · TREATMENT',    name: 'Cal',    domain: 'Treatment Scheduling',     tagline: 'Books follow-ups, sends HIPAA-compliant SMS reminders, and keeps the treatment calendar full.',        outcome: 'Every follow-up booked. Calendar stays full.',          href: 'agents/cal.html' },
    { num: '04 · CONSENT · COMPLIANCE',      name: 'Docs',   domain: 'Consent Documentation',    tagline: 'Sends consents, tracks signatures, and files documents in your EHR before treatment.',                 outcome: 'Every consent signed and filed before treatment.',      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/intake.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: 'HIPAA-compliant deployment inside your Azure subscription. Agents connect to your EHR, billing, and scheduling via secure APIs. Patient data never leaves your environment.',
      items: ['Azure AD / Entra SSO', 'EHR API access', 'Azure OpenAI (your tenant)', 'HIPAA-compliant'],
    },
    {
      tag: 'Step 02 · Configure',
      title: 'Assign agents to channels',
      body: 'Each agent runs in Teams, SMS, or email. Set escalation rules, approval thresholds, and override controls.',
      items: ['Teams / SMS / Email', 'Escalation thresholds', 'Human-in-the-loop controls', 'Role-based overrides'],
    },
    {
      tag: 'Step 03 · Operate',
      title: 'Atlas keeps watch',
      body: 'Every action is logged and auditable. Atlas shows what each agent did, why, and when.',
      items: ['Streaming 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: 'Patient intake',        today: 'Front desk emails forms, chases responses, keys data by hand',     echo: 'Intake collects, verifies, posts to EHR before first visit' },
    { workflow: 'AR collections',        today: 'Biller sends reminders manually, often delayed or skipped',         echo: 'Ledger tracks every balance and sends reminders on cadence' },
    { workflow: 'Treatment scheduling',  today: 'Coordinator calls or texts patients one-by-one for follow-ups',     echo: 'Cal books follow-ups and reschedules via SMS' },
    { workflow: 'Consent tracking',      today: 'Paper chase. Missing consents found day-of treatment',              echo: 'Docs flags missing consents 24h before treatment' },
    { workflow: 'Collections aging',     today: 'Overdue accounts surface in monthly AR review, too late',           echo: 'Ledger flags every balance before it hits 30 days' },
  ];
  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: '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',
    },
  ];
  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 brokerage.
          </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 front-desk or AR staff?',
      a: 'No. Echo takes the repetitive work off your intake coordinators and AR team: insurance verification, claims follow-up, patient communications. Your team gets back to patient care.',
    },
    {
      q: 'Does it integrate with my EHR or PMS?',
      a: 'Yes. Echo works with the major EHR and PMS platforms via API. Read-write access stays in your tenant. Your patient 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 compliance audit trail.',
    },
    {
      q: 'Who owns the patient data?',
      a: 'You do. Echo runs inside your Microsoft Azure tenant. Patient records, claims, and intake forms 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 clinic 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 clinic 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 regenerative health clinics.<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="health" />
        <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 });
