// hero-section.jsx — Full-bleed photo hero with floating UI cards
const { useState: useStateH, useEffect: useEffectH, useRef: useRefH } = React;

// ── Hero Logo (cream version for photo overlay) ────────────────────
function HeroLogo({ 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' }}
    />
  );
}

// ── Floating live ticker (bottom-left of hero) ─────────────────────
function LiveTicker() {
  const rows = [
    { id: 'P-0441', patient: 'J. Martinez',       type: 'new patient',        agent: 'Intake',  action: 'intake complete · EHR posted',      statusColor: '#4ADE80', time: '3m ago' },
    { id: 'BAL-882',patient: 'R. Thompson',        type: 'AR · $4,200 due',    agent: 'Ledger',  action: 'payment reminder sent',              statusColor: '#6EE7B7', time: '8m ago' },
    { id: 'APT-119', patient: 'M. Chen',           type: 'infusion · Thu 10am',agent: 'Cal',     action: 'follow-up booked via SMS',           statusColor: '#4ADE80', time: '14m ago' },
    { id: 'CNS-057', patient: 'D. Okafor',         type: 'consent · missing',  agent: 'Docs',    action: 'form flagged · reminder sent',       statusColor: '#FCD34D', time: '21m ago' },
    { id: 'BAL-883', patient: 'L. Singh',          type: 'AR · $8,200 overdue',agent: 'Ledger',  action: 'balance collected · posted to AR',   statusColor: '#4ADE80', time: '29m ago' },
    { id: 'P-0442',  patient: 'A. Williams',       type: 'new patient',        agent: 'Intake',  action: 'ID verified · prior auth cleared',   statusColor: '#4ADE80', time: '36m ago' },
    { id: 'APT-120', patient: 'K. Patel',          type: 'annual checkup',     agent: 'Cal',     action: 'slot confirmed · SMS sent',          statusColor: '#4ADE80', time: '43m ago' },
    { id: 'BAL-884', patient: 'T. Rivera',         type: 'AR · $2,600 due',    agent: 'Ledger',  action: 'payment plan set up',                statusColor: '#6EE7B7', time: '51m ago' },
  ];

  const Row = ({ row }) => (
    <span style={{
      display: 'inline-flex', alignItems: 'center', gap: 12,
      padding: '0 24px',
      borderRight: '1px solid rgba(110,231,183,0.12)',
      fontFamily: 'var(--ff-mono)', fontSize: 11.5, lineHeight: 1,
      whiteSpace: 'nowrap',
    }}>
      <span style={{ color: '#6EE7B7', fontWeight: 700, letterSpacing: '0.06em', fontSize: 11 }}>{row.id}</span>
      <span style={{ color: 'rgba(244,240,232,0.88)', letterSpacing: '0.01em' }}>{row.patient}</span>
      <span style={{ color: 'rgba(244,240,232,0.48)', fontSize: 10.5 }}>{row.type}</span>
      <span style={{ display: 'inline-flex', alignItems: 'center', gap: 5 }}>
        <span style={{ width: 5, height: 5, borderRadius: '50%', background: row.statusColor, boxShadow: `0 0 5px ${row.statusColor}` }} />
        <span style={{ color: row.statusColor, fontWeight: 600, fontSize: 10.5 }}>{row.agent}</span>
        <span style={{ color: 'rgba(244,240,232,0.65)' }}>→ {row.action}</span>
      </span>
      <span style={{ color: 'rgba(244,240,232,0.3)', fontSize: 10 }}>{row.time}</span>
    </span>
  );

  return (
    <div className="loadboard-ticker" style={{
      position: 'relative', width: '100%',
      background: 'rgba(4, 14, 10, 0.90)',
      border: '1px solid rgba(110,231,183,0.18)',
      borderRadius: 12, overflow: 'hidden',
      boxShadow: '0 24px 60px rgba(0,0,0,0.35), inset 0 1px 0 rgba(110,231,183,0.06)',
    }}>
      <div style={{
        position: 'absolute', left: 0, top: 0, bottom: 0, zIndex: 2,
        display: 'flex', alignItems: 'center', gap: 8, padding: '0 20px',
        background: 'linear-gradient(90deg, rgba(4,14,10,1) 65%, rgba(4,14,10,0) 100%)',
        fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', fontWeight: 600, color: '#6EE7B7',
      }}>
        <span style={{ position: 'relative', display: 'inline-flex', width: 7, height: 7 }}>
          <span style={{ position: 'absolute', inset: -2, borderRadius: '50%', background: 'rgba(110,231,183,0.35)', animation: 'pulse 1.6s ease-in-out infinite' }} />
          <span style={{ position: 'absolute', inset: 0, borderRadius: '50%', background: '#6EE7B7', boxShadow: '0 0 8px #6EE7B7' }} />
        </span>
        Live · Clinic
      </div>
      <div style={{
        position: 'absolute', right: 0, top: 0, bottom: 0, width: 80, zIndex: 2,
        background: 'linear-gradient(270deg, rgba(4,14,10,1) 0%, rgba(4,14,10,0) 100%)',
        pointerEvents: 'none',
      }} />
      <div className="loadboard-track" style={{
        display: 'inline-flex', alignItems: 'center',
        padding: '14px 0 14px 155px',
        animation: 'loadBoardScroll 80s linear infinite',
        willChange: 'transform',
      }}>
        {rows.map((r, i) => <Row key={`a-${i}`} row={r} />)}
        {rows.map((r, i) => <Row key={`b-${i}`} row={r} />)}
      </div>
    </div>
  );
}

// ── Floating stats card (bottom-right) ─────────────────────────────
function HeroStatsCard() {
  return (
    <div style={{
      background: 'rgba(244, 240, 232, 0.94)',
      backdropFilter: 'blur(20px) saturate(180%)',
      WebkitBackdropFilter: 'blur(20px) saturate(180%)',
      border: '1px solid rgba(20, 52, 43, 0.12)',
      borderRadius: 14,
      padding: '18px 22px',
      display: 'flex', gap: 28,
      boxShadow: '0 24px 60px rgba(0,0,0,0.18)',
    }}>
      {[
        { k: 'AR cycle',     v: '14 days', d: 'vs. 45-day avg' },
        { k: 'No-show rate', v: '< 5%',   d: 'with reminders' },
        { k: 'Consents',     v: '100%',   d: 'filed before tx' },
      ].map((s, i) => (
        <div key={i} style={{ display: 'flex', flexDirection: 'column', gap: 2, borderLeft: i > 0 ? '1px solid rgba(20,52,43,0.10)' : 'none', paddingLeft: i > 0 ? 24 : 0 }}>
          <div style={{ fontFamily: 'var(--ff-display)', fontSize: 26, fontWeight: 500, color: 'var(--forest)', letterSpacing: '-0.02em', lineHeight: 1 }}>{s.v}</div>
          <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, letterSpacing: '0.1em', color: 'var(--muted)', textTransform: 'uppercase', marginTop: 4 }}>{s.k}</div>
          <div style={{ fontSize: 11, color: 'var(--muted)' }}>{s.d}</div>
        </div>
      ))}
    </div>
  );
}

// ── Floating SMS preview (right side, mid) ─────────────────────────
function HeroSMSPreview() {
  return (
    <div style={{
      background: 'rgba(244, 240, 232, 0.96)',
      backdropFilter: 'blur(20px) saturate(180%)',
      WebkitBackdropFilter: 'blur(20px) saturate(180%)',
      border: '1px solid rgba(20, 52, 43, 0.10)',
      borderRadius: 14,
      padding: 16,
      width: 280,
      boxShadow: '0 28px 72px rgba(0,0,0,0.28), 0 4px 12px rgba(0,0,0,0.12)',
      display: 'flex', flexDirection: 'column', gap: 10,
    }}>
      {/* header */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 10, paddingBottom: 10, borderBottom: '1px solid rgba(20,52,43,0.08)' }}>
        <div style={{ width: 32, height: 32, borderRadius: '50%', background: '#0EA5E9', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#fff', fontFamily: 'var(--ff-display)', fontSize: 14, fontWeight: 500 }}>V</div>
        <div style={{ flex: 1 }}>
          <div style={{ fontSize: 12, fontWeight: 600, color: 'var(--forest)' }}>Intake</div>
          <div style={{ fontFamily: 'var(--ff-mono)', fontSize: 9, color: 'var(--muted)', letterSpacing: '0.08em', textTransform: 'uppercase' }}>Teams · 9:04 AM</div>
        </div>
        <span style={{ width: 6, height: 6, borderRadius: '50%', background: '#5DA88A' }} />
      </div>
      {/* msg */}
      <div style={{ background: 'var(--surface)', borderRadius: 10, padding: '10px 12px', fontSize: 12, color: 'var(--ink)', lineHeight: 1.5 }}>
        Intake complete · <span style={{ fontFamily: 'var(--ff-mono)', color: '#0EA5E9', fontWeight: 600 }}>P-0441</span>.<br />
        Forms signed, ID verified, prior auth clear.<br />
        Post to EHR?
      </div>
      {/* reply */}
      <div style={{ alignSelf: 'flex-end', background: 'var(--forest)', color: '#F4F0E8', borderRadius: 10, padding: '7px 12px', fontSize: 12, fontWeight: 500 }}>Post it</div>
      {/* result */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 10px', background: 'rgba(93, 168, 138, 0.12)', border: '1px solid rgba(93, 168, 138, 0.3)', borderRadius: 8 }}>
        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#3A8068" strokeWidth="2.5" strokeLinecap="round"><polyline points="20 6 9 17 4 12"/></svg>
        <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, color: '#1F5444', letterSpacing: '0.04em' }}>Patient record posted · EHR updated · P-0441</span>
      </div>
    </div>
  );
}

// ── Main hero ──────────────────────────────────────────────────────
function Hero({ heroImage = 'hero-truck-corridor' }) {
  // (Scroll-coupled parallax state removed — value was unused but the listener
  // was firing setState on every scroll frame, re-rendering the hero subtree
  // and causing lag.)

  return (
    <section style={{ position: 'relative', minHeight: '100vh', overflow: 'hidden' }}>
      {/* Text-legibility scrim */}
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none', zIndex: 1,
        background: 'linear-gradient(90deg, rgba(5,11,9,0.60) 0%, rgba(5,11,9,0.40) 25%, rgba(5,11,9,0.15) 50%, rgba(5,11,9,0) 70%)',
      }} />

      {/* (Speed lines removed for Health — calmer hero, no motion streaks.) */}
      {/* ── Content ─────────────────────────── */}
      <div className="hero-content" style={{
        position: 'relative', zIndex: 2,
        minHeight: '100svh',
        maxWidth: 1280, margin: '0 auto',
        padding: '0 48px',
        display: 'flex', flexDirection: 'column',
        justifyContent: 'flex-start',
        color: '#F4F0E8',
      }}>

        {/* Zone 1: Headline + subtext */}
        <div className="hero-inner" style={{ paddingTop: 'clamp(72px, 15vh, 180px)' }}>
          <div className="hero-grid" style={{ display: 'block' }}>
          <h1 style={{
            fontFamily: 'var(--ff-display)',
            fontSize: 'clamp(44px, 6vw, 88px)',
            fontWeight: 300,
            letterSpacing: '-0.04em',
            lineHeight: 1.0,
            color: '#F4F0E8',
            marginBottom: 28,
            textShadow: '0 2px 30px rgba(0,0,0,0.35)',
            maxWidth: '14ch',
          }}>
            <span style={{ animation: 'heroUp 1s cubic-bezier(0.16,1,0.3,1) 0.18s both', display: 'block' }}>
              Meet{' '}
              <span style={{ color: '#6EE7B7', textShadow: '0 2px 24px rgba(16,185,129,0.55), 0 2px 30px rgba(0,0,0,0.5)' }}>
                Echo,
              </span>
              {' '}your AI
            </span>
            <span style={{ animation: 'heroUp 1s cubic-bezier(0.16,1,0.3,1) 0.26s both', display: 'block' }}>
              Workforce for{' '}
              <span style={{ color: '#6EE7B7', textShadow: '0 2px 24px rgba(16,185,129,0.55), 0 2px 30px rgba(0,0,0,0.5)' }}>
                Clinics.
              </span>
            </span>
          </h1>

          <p style={{
            animation: 'heroUp 1s cubic-bezier(0.16,1,0.3,1) 0.5s both',
            fontSize: 18,
            lineHeight: 1.6,
            color: 'rgba(244,240,232,0.95)',
            maxWidth: 540,
            marginBottom: 0,
            fontWeight: 400,
            textShadow: '0 1px 16px rgba(0,0,0,0.85), 0 2px 40px rgba(0,0,0,0.6)',
          }}>
            Four agents for patient intake, AR collections, treatment scheduling, and consent compliance. 24/7, inside the tools you already use.
          </p>
          </div>
        </div>

          {/* CTA row */}
          <div style={{ animation: 'heroUp 1s cubic-bezier(0.16,1,0.3,1) 0.62s both', marginTop: 40, display: 'flex', alignItems: 'center', gap: 14, flexWrap: 'wrap' }}>
            <a href="#book" data-open-book-call className="echo-cta echo-cta--primary" style={{ fontSize: 16, padding: '15px 28px', flexShrink: 0 }}>
              See Echo run
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12h14M12 5l7 7-7 7"/></svg>
            </a>
            <a href="#agents" className="echo-cta echo-cta--ghost" style={{ fontSize: 16, padding: '15px 28px' }}>
              View agents
            </a>
          </div>

          {/* Trust bar — directly under buttons */}
          <div style={{ animation: 'heroUp 1s cubic-bezier(0.16,1,0.3,1) 0.72s both', marginTop: 36, display: 'flex' }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 22, flexWrap: 'wrap', background: 'rgba(8,12,18,0.90)', backdropFilter: 'blur(12px)', WebkitBackdropFilter: 'blur(12px)', borderRadius: 12, padding: '8px 16px', border: '1px solid rgba(96,165,250,0.18)' }}>
            <span className="trust-built-on-label" style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.18em', color: 'rgba(244,240,232,0.65)', fontWeight: 500, textTransform: 'uppercase' }}>Built on</span>

            {/* Microsoft */}
            <div style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
              <svg width="15" height="15" viewBox="0 0 23 23" aria-hidden="true">
                <rect width="10" height="10" fill="#F25022"/>
                <rect x="12" width="10" height="10" fill="#7FBA00"/>
                <rect y="12" width="10" height="10" fill="#00A4EF"/>
                <rect x="12" y="12" width="10" height="10" fill="#FFB900"/>
              </svg>
              <span style={{ fontFamily: "'Segoe UI', 'Helvetica Neue', sans-serif", fontSize: 13.5, color: '#F4F0E8', fontWeight: 400, letterSpacing: '-0.005em' }}>Microsoft</span>
            </div>

            {/* Microsoft Teams */}
            <div style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
              <svg width="16" height="16" viewBox="0 0 32 32" aria-hidden="true">
                <rect x="3" y="6" width="20" height="20" rx="2.5" fill="#5059C9"/>
                <path d="M8 11 H18 M13 11 V21" stroke="#fff" strokeWidth="2.4" strokeLinecap="round"/>
                <circle cx="24.5" cy="11" r="4.5" fill="#7B83EB"/>
              </svg>
              <span style={{ fontFamily: "'Segoe UI', 'Helvetica Neue', sans-serif", fontSize: 13.5, color: '#F4F0E8', fontWeight: 400, letterSpacing: '-0.005em' }}>Teams</span>
            </div>

            {/* athenahealth */}
            <div className="trust-logo-secondary" style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
              <svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true">
                <rect width="24" height="24" rx="5" fill="#F57F2E"/>
                <text x="12" y="17" textAnchor="middle" fontFamily="Helvetica, Arial, sans-serif" fontSize="15" fontWeight="700" fill="#fff">a</text>
              </svg>
              <span style={{ fontFamily: "'Helvetica Neue', sans-serif", fontSize: 13.5, color: '#F4F0E8', fontWeight: 400, letterSpacing: '-0.005em' }}>athenahealth</span>
            </div>

            {/* +100 More Apps */}
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}>
              <svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" style={{ flexShrink: 0 }}>
                <rect x="3" y="3" width="11" height="11" rx="2.5" fill="rgba(244,240,232,0.18)" stroke="rgba(244,240,232,0.32)" strokeWidth="1"/>
                <rect x="7.5" y="7.5" width="11" height="11" rx="2.5" fill="#6EE7B7" stroke="#6EE7B7" strokeWidth="1"/>
              </svg>
              <span style={{ fontFamily: "'Helvetica Neue', sans-serif", fontSize: 13, color: '#6EE7B7', fontWeight: 600, letterSpacing: '-0.005em' }}>+100</span>
              <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.14em', color: 'rgba(244,240,232,0.75)', fontWeight: 500, textTransform: 'uppercase' }}>more apps</span>
            </span>

            {/* HIPAA chip — hidden on mobile */}
            <span className="trust-logo-secondary" style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.14em', color: 'rgba(244,240,232,0.85)', fontWeight: 500, padding: '5px 10px', border: '1px solid rgba(244,240,232,0.30)', borderRadius: 4 }}>HIPAA · BAA AVAILABLE</span>
            {/* SOC 2 chip — always visible */}
            <span style={{ fontFamily: 'var(--ff-mono)', fontSize: 10, letterSpacing: '0.14em', color: 'rgba(244,240,232,0.85)', fontWeight: 500, padding: '5px 10px', border: '1px solid rgba(244,240,232,0.30)', borderRadius: 4 }}>SOC 2</span>
          </div>
          </div>{/* end trust bar outer */}
      </div>{/* end hero-content */}

      <style>{`
        @keyframes loadBoardScroll {
          0%   { transform: translateX(0); }
          100% { transform: translateX(-50%); }
        }
        .loadboard-ticker:hover .loadboard-track { animation-play-state: paused; }
        @keyframes floatY {
          0%, 100% { transform: translateY(0); }
          50% { transform: translateY(-10px); }
        }
        @keyframes heroBreathe {
          0%, 100% { filter: brightness(1) saturate(1); }
          50%      { filter: brightness(1.08) saturate(1.1); }
        }
        .hero-bg { animation: heroBreathe 14s ease-in-out infinite; }

        @keyframes beamSweep {
          0%   { transform: translateX(-30%); opacity: 0; }
          15%  { opacity: 0.9; }
          50%  { opacity: 1; }
          85%  { opacity: 0.6; }
          100% { transform: translateX(30%); opacity: 0; }
        }
        .hero-beam { animation: beamSweep 9s ease-in-out infinite; }

        @keyframes hazeDrift {
          0%, 100% { transform: translate3d(0,0,0); }
          50%      { transform: translate3d(2%, -1%, 0); }
        }
        .hero-haze { animation: hazeDrift 18s ease-in-out infinite; }

        @keyframes streakRun {
          0%   { transform: translateX(-110%) skewX(-12deg); opacity: 0; }
          12%  { opacity: 0.45; }
          80%  { opacity: 0.45; }
          100% { transform: translateX(110vw) skewX(-12deg); opacity: 0; }
        }
        .streak {
          position: absolute;
          height: 2px;
          width: 220px;
          background: linear-gradient(90deg, transparent 0%, rgba(96,165,250,0.45) 35%, rgba(255,255,255,0.85) 60%, rgba(96,165,250,0.35) 80%, transparent 100%);
          filter: blur(1.4px);
          will-change: transform, opacity;
          mix-blend-mode: screen;
        }
        .streak-1 { top: 28%; left: 0; animation: streakRun 5.4s linear infinite; animation-delay: 0.2s; opacity: 0; }
        .streak-2 { top: 52%; left: 0; animation: streakRun 7.2s linear infinite; animation-delay: 2.4s; width: 320px; height: 1.5px; opacity: 0; }
        .streak-3 { top: 71%; left: 0; animation: streakRun 4.6s linear infinite; animation-delay: 4.1s; width: 180px; opacity: 0; }

        @media (prefers-reduced-motion: reduce) {
          .hero-bg, .hero-beam, .hero-haze, .streak { animation: none !important; }
        }
        @media (max-width: 980px) {
          .hero-grid { grid-template-columns: 1fr !important; }
          .hero-card-col { display: none !important; }
        }
      `}</style>
    </section>
  );
}

Object.assign(window, { Hero, HeroLogo });
