// Hero — typographic display, voice waveform, specialty switcher, phone mockup
const SPECIALTIES = [
  { id: "dental",     label: "Dental",       headline: ["Every implant call", "answered."],           blurb: "Recover after-hours and overflow calls into booked consults — written straight to Dentrix or Modento, in seconds.",  slots: 4, slotLabel: "dental" },
  { id: "derm",       label: "Dermatology",  headline: ["Every cosmetic inquiry", "qualified."],      blurb: "Specialty-specific intake captures concern, history, and insurance — so the chair is filled by patients who fit the visit.", slots: 2, slotLabel: "derm" },
  { id: "primary",    label: "Primary care", headline: ["Every new patient,", "doctor-approved."],    blurb: "A 30-second tap on the physician's phone keeps the scheduling decision where it belongs — with the doctor.",          slots: 3, slotLabel: "primary care" },
  { id: "aesthetics", label: "Aesthetics",   headline: ["Every consult booked", "before the next clinic."], blurb: "Patients comparing providers don't wait. Samika answers in under two rings and books while interest is hot.",   slots: 3, slotLabel: "aesthetics" },
];

function Waveform({ active }) {
  // 28 bars, animated heights using staggered CSS animations
  const bars = Array.from({ length: 28 }, (_, i) => i);
  return (
    <div className="wave" aria-hidden>
      {bars.map(i => (
        <span key={i} style={{
          animationDelay: `${(i * 60) % 1200}ms`,
          animationDuration: `${900 + ((i*73)%600)}ms`,
          opacity: active ? 1 : 0.35,
        }} />
      ))}
      <style>{`
        .wave { display:flex; gap:3px; align-items:center; height:36px; }
        .wave span {
          display:block; width:3px; border-radius:2px;
          background: var(--ink-800);
          height: 30%;
          animation: waveBar 1s ease-in-out infinite alternate;
        }
        @keyframes waveBar {
          from { height: 14%; }
          to   { height: 92%; }
        }
      `}</style>
    </div>
  );
}

function PhoneMock({ specialty }) {
  // Doctor approval card — the unique Samika angle.
  const intake = {
    primary:    { name: "Marisol Rivera", reason: "New patient — persistent fatigue, 3 weeks", urgency: "Routine", duration: "45 min" },
    dental:     { name: "Marisol Rivera", reason: "Implant consult — molar #19", urgency: "Standard", duration: "60 min" },
    derm:       { name: "Marisol Rivera", reason: "Mole evaluation — back, recently changed", urgency: "Standard", duration: "30 min" },
    aesthetics: { name: "Marisol Rivera", reason: "Botox consultation — first-time", urgency: "Standard", duration: "45 min" },
  }[specialty] || {};

  return (
    <div className="phone">
      <div className="phone__notch" />
      <div className="phone__screen">
        <div className="phone__statusbar">
          <span>9:41</span>
          <span className="phone__signals">●●● 5G ▮▮▮</span>
        </div>
        <div className="phone__notif">
          <div className="phone__notif-head">
            <span className="phone__app">
              <span className="phone__appdot" /> Samika
            </span>
            <span className="phone__time">now</span>
          </div>
          <div className="phone__row">
            <div className="phone__label">Patient</div>
            <div className="phone__value">{intake.name}</div>
          </div>
          <div className="phone__row">
            <div className="phone__label">Reason</div>
            <div className="phone__value">{intake.reason}</div>
          </div>
          <div className="phone__row phone__row--split">
            <div>
              <div className="phone__label">Visit</div>
              <div className="phone__value">{intake.duration}</div>
            </div>
            <div>
              <div className="phone__label">Urgency</div>
              <div className="phone__value">{intake.urgency}</div>
            </div>
          </div>
          <div className="phone__actions">
            <button className="phone__btn phone__btn--accept">Accept &amp; book</button>
            <button className="phone__btn phone__btn--ask">Ask follow-up</button>
            <button className="phone__btn phone__btn--decline">Redirect</button>
          </div>
          <div className="phone__hint">Tap to confirm · 28 sec to act</div>
        </div>
        <div className="phone__transcript">
          <div className="phone__t-line"><span className="phone__t-tag">Samika</span> "I'll share this with Dr. Patel and confirm within the hour."</div>
        </div>
      </div>

      <style>{`
        .phone {
          position: relative;
          width: 296px;
          height: 600px;
          background: #0E0C0A;
          border-radius: 44px;
          padding: 12px;
          box-shadow: 0 40px 80px -30px rgba(0,0,0,0.45),
                      0 0 0 1px rgba(255,255,255,0.04) inset,
                      0 0 0 8px rgba(31,29,26,0.04);
        }
        .phone__notch {
          position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
          width: 96px; height: 26px; background: #0E0C0A; border-radius: 0 0 14px 14px;
          z-index: 2;
        }
        .phone__screen {
          width: 100%; height: 100%;
          background: linear-gradient(180deg, #1B1814 0%, #2A241D 100%);
          border-radius: 34px;
          padding: 50px 16px 16px;
          color: var(--cream-100);
          display: flex; flex-direction: column;
          font-family: var(--font-sans);
        }
        .phone__statusbar {
          display: flex; justify-content: space-between;
          font-size: 12px; color: rgba(247,241,228,0.7);
          padding: 0 6px 14px;
        }
        .phone__notif {
          background: rgba(247,241,228,0.06);
          border: 1px solid rgba(247,241,228,0.12);
          backdrop-filter: blur(12px);
          border-radius: 18px;
          padding: 16px;
          animation: notifIn 0.6s ease-out;
        }
        @keyframes notifIn {
          from { opacity: 0; transform: translateY(8px); }
          to { opacity: 1; transform: translateY(0); }
        }
        .phone__notif-head {
          display: flex; justify-content: space-between; align-items: center;
          margin-bottom: 14px;
        }
        .phone__app {
          font-family: var(--font-display); font-style: italic;
          font-size: 15px; display: flex; align-items: center; gap: 6px;
        }
        .phone__appdot { width:6px;height:6px;border-radius:50%;background:#7CC7A1; }
        .phone__time { font-size: 11px; color: rgba(247,241,228,0.55); font-family: var(--font-mono); }
        .phone__row { padding: 8px 0; border-top: 1px solid rgba(247,241,228,0.08); }
        .phone__row:first-of-type { border-top: 0; padding-top: 0; }
        .phone__row--split { display: flex; gap: 16px; }
        .phone__row--split > div { flex: 1; }
        .phone__label { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(247,241,228,0.5); margin-bottom: 3px; }
        .phone__value { font-size: 13px; color: var(--cream-100); line-height: 1.35; }
        .phone__actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
        .phone__btn {
          padding: 11px;
          border-radius: 10px;
          border: 0;
          font-size: 13px;
          font-weight: 500;
          cursor: pointer;
          font-family: inherit;
        }
        .phone__btn--accept { background: var(--cream-100); color: var(--ink-900); }
        .phone__btn--ask { background: rgba(247,241,228,0.1); color: var(--cream-100); border: 1px solid rgba(247,241,228,0.18); }
        .phone__btn--decline { background: transparent; color: rgba(247,241,228,0.6); }
        .phone__hint { text-align: center; font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; color: rgba(247,241,228,0.4); margin-top: 10px; }
        .phone__transcript {
          margin-top: auto;
          padding: 12px;
          background: rgba(247,241,228,0.04);
          border-radius: 12px;
          font-size: 11.5px;
          color: rgba(247,241,228,0.7);
          line-height: 1.4;
        }
        .phone__t-tag { display: inline-block; font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: #7CC7A1; margin-right: 6px; }
      `}</style>
    </div>
  );
}

function Hero({ heroVariant, ctaLabel, secondaryCtaLabel }) {
  const [spec, setSpec] = React.useState("primary");
  const current = SPECIALTIES.find(s => s.id === spec);
  const isCentered = heroVariant === "centered";

  if (isCentered) {
    return (
      <section className="hero hero--centered">
        <div className="container hero__inner">
          <div className="hero__top hero__top--center">
            <div className="tag">
              <span className="tag-dot" />
              HIPAA · BAA available · SOC-2 in progress
            </div>
          </div>

          <h1 className="display h-xl hero__headline hero__headline--center">
            {current.headline[0]} <span className="serif">{current.headline[1]}</span>
          </h1>

          <p className="lede hero__lede--center">
            Samika is the AI patient access system for specialty and primary care clinics. It answers every inbound call, runs a structured intake, and books the appointment directly into your PMS — with the physician in the loop on every new patient.
          </p>

          <div className="hero__cta-row hero__cta-row--center">
            <a href="#book" className="btn btn--primary">{ctaLabel || "Book a demo"} <span className="arrow">→</span></a>
            <a href="#demo" className="btn btn--ghost">{secondaryCtaLabel || "Hear a sample call"}</a>
          </div>
          <div className="hero__scarcity hero__scarcity--center">
            <span className="hero__scarcity-dot" />
            Pilot open · <strong>{current.slots} {current.slotLabel} practices</strong> accepted this month
          </div>

          <div className="hero__switcher hero__switcher--center">
            <span className="eyebrow">For:</span>
            <div className="hero__switcher-tabs">
              {SPECIALTIES.map(s => (
                <button key={s.id}
                  className={`switch ${spec === s.id ? "switch--on" : ""}`}
                  onClick={() => setSpec(s.id)}>
                  {s.label}
                </button>
              ))}
            </div>
          </div>

          <div className="hero__waveline">
            <Waveform active />
            <span className="hero__live-text">A patient is calling — answered in 1.2s</span>
          </div>
        </div>

        <style>{`
          .hero--centered { padding: 80px 0 100px; text-align: center; }
          .hero--centered .hero__inner { gap: 32px; align-items: center; display: flex; flex-direction: column; }
          .hero__top--center { justify-content: center; }
          .hero__headline--center { margin: 16px auto 0; max-width: 16ch; }
          .hero__lede--center { margin: 0 auto; max-width: 56ch; }
          .hero__calc--center { width: 100%; max-width: 560px; text-align: left; }
          .hero__cta-row--center { justify-content: center; display: flex; gap: 12px; }
          .hero__switcher--center { justify-content: center; padding-top: 16px; border-top: 1px solid var(--line); margin-top: 8px; }
          .hero__waveline { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 8px; }
          .hero__live-text { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-600); }
        `}</style>
      </section>
    );
  }

  return (
    <section className="hero">
      <div className="container hero__inner">
        <div className="hero__top">
          <div className="tag">
            <span className="tag-dot" />
            HIPAA · BAA available · SOC-2 in progress
          </div>
          <div className="hero__live">
            <Waveform active />
            <span className="hero__live-text">A patient is calling — answered in 1.2s</span>
          </div>
        </div>

        <div className="hero__grid">
          <div className="hero__left">
            <h1 className="display h-xl hero__headline">
              {current.headline[0]}<br />
              <span className="serif">{current.headline[1]}</span>
            </h1>

            <div className="hero__lede-block">
              <p className="lede">
                Samika is the AI patient access system for specialty and primary care clinics. It answers every inbound call, runs a structured intake, and books the appointment directly into your PMS — with the physician in the loop on every new patient.
              </p>

              <div className="hero__cta-row">
                <a href="#book" className="btn btn--primary">{ctaLabel || "Book a demo"} <span className="arrow">→</span></a>
                <a href="#demo" className="btn btn--ghost">{secondaryCtaLabel || "Hear a sample call"}</a>
              </div>
              <div className="hero__scarcity">
                <span className="hero__scarcity-dot" />
                Pilot open · <strong>{current.slots} {current.slotLabel} practices</strong> accepted this month
              </div>

              <div className="hero__switcher">
                <span className="eyebrow">For:</span>
                <div className="hero__switcher-tabs">
                  {SPECIALTIES.map(s => (
                    <button key={s.id}
                      className={`switch ${spec === s.id ? "switch--on" : ""}`}
                      onClick={() => setSpec(s.id)}>
                      {s.label}
                    </button>
                  ))}
                </div>
              </div>

              <p className="hero__blurb">{current.blurb}</p>
            </div>
          </div>

          <div className="hero__phone-stage">
            <div className="hero__phone-glow" />
            <PhoneMock specialty={spec} />
            <div className="hero__phone-caption">
              <div className="eyebrow">Physician approval loop</div>
              <div>30 seconds · doctor decides · before booking</div>
            </div>
          </div>
        </div>
      </div>

      <style>{`
        .hero { padding: 56px 0 80px; }
        .hero__inner { display: flex; flex-direction: column; gap: 48px; }
        .hero__top { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
        .tag-dot { width: 6px; height: 6px; border-radius: 50%; background: #7CC7A1; }
        .hero__live { display: flex; align-items: center; gap: 12px; }
        .hero__live-text { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-600); }

        .hero__headline {
          margin: 8px 0 0;
          max-width: 18ch;
        }
        .hero__grid {
          display: grid;
          grid-template-columns: 1.05fr 0.95fr;
          gap: 80px;
          align-items: start;
          margin-top: 8px;
        }
        .hero__left { display: flex; flex-direction: column; gap: 40px; }
        .hero__lede-block { display: flex; flex-direction: column; gap: 28px; }
        .hero__cta-row { display: flex; gap: 12px; flex-wrap: wrap; }
        .hero__switcher { display: flex; gap: 16px; align-items: center; padding-top: 8px; border-top: 1px solid var(--line); }
        .hero__switcher-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
        .switch {
          background: transparent;
          border: 0;
          padding: 8px 14px;
          border-radius: var(--radius-pill);
          font-size: 14px;
          color: var(--ink-500);
          cursor: pointer;
          transition: all .2s;
          font-family: inherit;
        }
        .switch:hover { color: var(--ink-900); }
        .switch--on { background: var(--ink-900); color: var(--cream-100); }
        .hero__blurb { color: var(--ink-600); margin: 0; max-width: 48ch; font-size: 15px; line-height: 1.5; }

        .hero__scarcity {
          display: flex; align-items: center; gap: 8px;
          font-size: 13px; color: var(--ink-600);
        }
        .hero__scarcity strong { color: var(--ink-900); font-weight: 600; }
        .hero__scarcity-dot {
          width: 7px; height: 7px; border-radius: 50%;
          background: #7CC7A1;
          box-shadow: 0 0 0 3px rgba(124,199,161,0.22);
          flex-shrink: 0;
          animation: pulse-dot 2.4s ease-in-out infinite;
        }
        @keyframes pulse-dot {
          0%, 100% { box-shadow: 0 0 0 3px rgba(124,199,161,0.22); }
          50%       { box-shadow: 0 0 0 6px rgba(124,199,161,0.08); }
        }
        .hero__scarcity--center { justify-content: center; }

        .hero__phone-stage {
          position: relative;
          display: flex;
          flex-direction: column;
          align-items: center;
          gap: 28px;
          justify-self: end;
        }
        .hero__phone-glow {
          position: absolute;
          inset: 40px -40px -40px -40px;
          background: radial-gradient(60% 60% at 50% 50%, rgba(31,29,26,0.06), transparent 70%);
          pointer-events: none;
        }
        .hero__phone-caption {
          text-align: center;
          font-size: 13px;
          color: var(--ink-600);
          max-width: 280px;
          padding-top: 8px;
          border-top: 1px solid var(--line);
        }
        .hero__phone-caption .eyebrow { display: block; margin-bottom: 6px; }

        @media (max-width: 1000px) {
          .hero__grid { grid-template-columns: 1fr; gap: 48px; }
          .hero__phone-stage { justify-self: center; }
        }
      `}</style>
    </section>
  );
}

window.Hero = Hero;
