/* IAMAI marketing — landing app */
const { useEffect, useRef, useState } = React;

// ── Supabase leads endpoint ────────────────────────────
const SUPABASE_URL = "https://ivclrsqwralwibfwjrho.supabase.co/rest/v1/leads";
const SUPABASE_ANON = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Iml2Y2xyc3F3cmFsd2liZndqcmhvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzY1NDA0ODIsImV4cCI6MjA5MjExNjQ4Mn0.GzcFVhWGg6oQotBd6R_fRwKmiVnV_3Q_4xbBeoHi2Ns";

// ── Reveal on scroll ───────────────────────────────────
const REVEAL_SELECTOR = '.reveal, .reveal-left, .reveal-right, .reveal-scale, .grad-line';
function useReveal() {
  useEffect(() => {
    if (!('IntersectionObserver' in window)) return;
    const root = document.documentElement;
    const els = Array.from(document.querySelectorAll(REVEAL_SELECTOR));
    requestAnimationFrame(() => {
      root.classList.add('js-reveal');
      requestAnimationFrame(() => {
        const reveal = (el) => el.classList.add('in');
        const io = new IntersectionObserver((entries) => {
          entries.forEach((e) => {
            if (e.isIntersecting) { reveal(e.target); io.unobserve(e.target); }
          });
        }, { threshold: 0.05, rootMargin: '0px 0px -40px 0px' });
        els.forEach((el) => {
          const r = el.getBoundingClientRect();
          if (r.top < window.innerHeight && r.bottom > 0) reveal(el);
          else io.observe(el);
        });
        setTimeout(() => els.forEach(reveal), 1800);
      });
    });
  }, []);
}

// ── Section-level styles (kept inside this file so styles.css below :root stays untouched) ──
const SECTION_STYLES = `
  .grad-line {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent) 30%, var(--steel) 70%, transparent);
    opacity: 0.2;
    max-width: var(--max-w);
    margin: 0 auto;
  }

  /* Section header helpers */
  .s-head { max-width: var(--max-w); margin: 0 auto 40px; padding: 0 var(--px); text-align: center; }
  .s-eyebrow {
    display: inline-flex; align-items: center; gap: 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ice);
    margin-bottom: 18px;
  }
  .s-eyebrow::before {
    content: ""; display: inline-block;
    width: 28px; height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent));
  }
  .s-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(28px, 4.4vw, 40px);
    letter-spacing: -0.02em;
    line-height: 1.05;
    color: var(--fg);
    margin: 0 0 14px;
    text-wrap: balance;
  }
  .s-title .it {
    font-style: italic;
    background: linear-gradient(135deg, var(--accent), var(--ice));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }
  .s-sub {
    color: var(--fg2);
    font-size: 15px;
    line-height: 1.55;
    max-width: 560px;
    margin: 0 auto;
  }

  /* Industries strip */
  .industries {
    padding: 48px var(--px);
    display: flex; justify-content: center; flex-wrap: wrap;
    gap: 8px;
    max-width: var(--max-w);
    margin: 0 auto;
  }
  .industry-pill {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--fg3);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 16px;
    background: transparent;
    cursor: default;
    transition: color 0.3s, border-color 0.3s, background 0.3s;
  }
  .industry-pill:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(107, 163, 214, 0.08);
  }

  /* Portfolio grid (Section B) */
  .pc-section { padding: 80px 0; }
  .pc-grid {
    max-width: var(--max-w); margin: 0 auto; padding: 0 var(--px);
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  }
  @media (max-width: 900px) { .pc-grid { grid-template-columns: repeat(2, 1fr); } }
  @media (max-width: 600px) { .pc-grid { grid-template-columns: 1fr; } }
  .pc {
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: var(--surface);
    transition: transform 0.4s cubic-bezier(0.16,1,0.3,1), box-shadow 0.4s, border-color 0.4s;
    display: flex; flex-direction: column;
  }
  .pc:hover {
    transform: translateY(-10px) scale(1.01);
    box-shadow: 0 24px 72px rgba(0,0,0,0.35);
    border-color: rgba(107,163,214,0.15);
  }
  .pc-top {
    height: 110px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 18px;
    text-align: center;
  }
  .pc-top h3 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 500;
    font-style: italic;
    font-size: 24px;
    letter-spacing: -0.02em;
    color: #fff;
  }
  .pc-body { padding: 16px 18px 18px; }
  .pc-tag {
    font-family: var(--font-mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    margin-bottom: 8px;
  }
  .pc-sub {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 16px;
    color: var(--fg);
    margin: 0 0 14px;
    line-height: 1.3;
  }
  .pc-pills { display: flex; flex-wrap: wrap; gap: 6px; }
  .pc-pill {
    font-family: var(--font-mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--fg2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 3px 8px;
  }
  .pc-foot { margin-top: 28px; text-align: center; }
  .pc-foot .btn-ghost {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--fg2);
    font-family: var(--font-body);
    font-size: 14px;
    text-decoration: none;
    transition: color 0.3s, border-color 0.3s, transform 0.3s;
  }
  .pc-foot .btn-ghost:hover { color: var(--accent); border-color: var(--accent); transform: translateY(-2px); }

  /* Services 3-up (Section C) */
  .svc3-section { padding: 80px 0; }
  .svc3-grid {
    max-width: var(--max-w); margin: 0 auto; padding: 0 var(--px);
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  }
  @media (max-width: 900px) { .svc3-grid { grid-template-columns: 1fr; } }
  .svc3 {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 28px 24px;
    overflow: hidden;
    transition: transform 0.4s cubic-bezier(0.16,1,0.3,1);
  }
  .svc3::before {
    content: "";
    position: absolute; top: 0; left: 0;
    width: 0; height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--steel));
    transition: width 0.5s cubic-bezier(0.16,1,0.3,1);
  }
  .svc3:hover { transform: translateY(-8px); }
  .svc3:hover::before { width: 100%; }
  .svc3-num {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 48px;
    line-height: 1;
    background: linear-gradient(135deg, var(--accent), var(--ice));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    opacity: 0.6;
    margin-bottom: 18px;
  }
  .svc3-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 22px;
    color: var(--fg);
    margin: 0 0 10px;
  }
  .svc3-desc {
    color: var(--fg2);
    font-size: 14px;
    line-height: 1.55;
    margin: 0;
  }

  /* How it works (Section D) */
  .how-section { padding: 80px 0; }
  .how-strip {
    max-width: var(--max-w); margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    overflow: hidden;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
  @media (max-width: 900px) { .how-strip { grid-template-columns: 1fr; } }
  .how-step {
    position: relative;
    padding: 32px 28px;
    border-right: 1px solid var(--line);
    overflow: hidden;
  }
  .how-step:last-child { border-right: none; }
  @media (max-width: 900px) {
    .how-step { border-right: none; border-bottom: 1px solid var(--line); }
    .how-step:last-child { border-bottom: none; }
  }
  .how-step::before {
    content: "";
    position: absolute; top: 0; left: 0;
    width: 0; height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--steel));
    transition: width 0.5s cubic-bezier(0.16,1,0.3,1);
  }
  .how-step:hover::before { width: 100%; }
  .how-num {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 56px;
    line-height: 1;
    color: var(--fg3);
    opacity: 0.5;
    margin-bottom: 16px;
  }
  .how-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 20px;
    color: var(--fg);
    margin: 0 0 8px;
  }
  .how-desc {
    color: var(--fg2);
    font-size: 14px;
    line-height: 1.55;
    margin: 0 0 16px;
  }
  .how-tag {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--ice);
  }

  /* Pricing (Section E) */
  .price-section { padding: 80px 0; }
  .price-grid {
    max-width: 780px; margin: 0 auto; padding: 0 var(--px);
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  }
  @media (max-width: 720px) { .price-grid { grid-template-columns: 1fr; } }
  .tier2 {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 32px 28px;
    display: flex; flex-direction: column;
  }
  .tier2-pop { border-color: var(--accent); }
  .tier2-pop::before {
    content: "Most popular";
    position: absolute; top: -10px; left: 20px;
    font-family: var(--font-mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    background: linear-gradient(135deg, var(--accent), var(--steel));
    color: var(--bg);
    padding: 4px 12px;
    border-radius: 999px;
    font-weight: 700;
  }
  .tier2-name {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 18px;
    color: var(--fg);
    margin: 0 0 4px;
  }
  .tier2-sub {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--fg3);
    margin-bottom: 22px;
  }
  .tier2-price {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 44px;
    line-height: 1;
    background: linear-gradient(135deg, var(--accent), var(--ice));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
  }
  .tier2-period {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--fg3);
    margin-bottom: 22px;
  }
  .tier2-features {
    list-style: none; padding: 0; margin: 0 0 24px;
    display: flex; flex-direction: column; gap: 10px;
  }
  .tier2-features li {
    font-size: 14px;
    color: var(--fg);
    display: flex; align-items: flex-start; gap: 8px;
  }
  .tier2-features li::before {
    content: "→";
    color: var(--accent);
    flex-shrink: 0;
  }
  .tier2-cta {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%;
    padding: 12px 16px;
    border-radius: 999px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent), var(--steel));
    color: var(--bg);
    text-decoration: none;
    transition: transform 0.3s, box-shadow 0.3s;
    margin-top: auto;
  }
  .tier2-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px -4px rgba(107,163,214,0.3);
  }
  .price-foot {
    max-width: 600px; margin: 24px auto 0; padding: 0 var(--px);
    text-align: center;
    color: var(--fg3);
    font-size: 13px;
  }

  /* Founders (Section F) */
  .founders2-section { padding: 80px 0; }
  .founders2-grid {
    max-width: 780px; margin: 0 auto; padding: 0 var(--px);
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  }
  @media (max-width: 720px) { .founders2-grid { grid-template-columns: 1fr; } }
  .founder2 {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 28px 24px;
  }
  .founder2-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
  .fb-avatar {
    width: 48px; height: 48px;
    border-radius: 14px;
    background: rgba(107,163,214,0.12);
    color: var(--ice);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-style: italic;
    font-size: 22px;
    border: 1px solid rgba(107,163,214,0.2);
  }
  .founder2-name {
    font-family: var(--font-display);
    font-size: 20px;
    color: var(--fg);
    margin: 0;
  }
  .founder2-role {
    font-size: 12px;
    color: var(--accent);
    margin-top: 2px;
  }
  .founder2-bio {
    color: var(--fg2);
    font-size: 14px;
    line-height: 1.6;
    margin: 0;
  }

  /* CTA (Section G) */
  .cta-section { padding: 0 0 80px; }
  .cta-block-new {
    position: relative;
    overflow: hidden;
    max-width: var(--max-w); margin: 0 auto;
    background: linear-gradient(135deg, var(--accent), var(--steel));
    border-radius: 16px;
    padding: 64px 44px;
    text-align: center;
  }
  .cta-block-new::before {
    content: "";
    position: absolute;
    top: -120px; right: -120px;
    width: 320px; height: 320px;
    background: radial-gradient(circle, rgba(255,255,255,0.12), transparent 70%);
    pointer-events: none;
  }
  .cta-block-new-h {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(28px, 4.6vw, 38px);
    color: var(--bg);
    margin: 0 0 16px;
    line-height: 1.1;
    position: relative;
  }
  .cta-block-new-h .it { font-style: italic; }
  .cta-block-new-p {
    font-size: 15px;
    color: rgba(11, 14, 24, 0.55);
    max-width: 440px;
    margin: 0 auto 28px;
    line-height: 1.55;
    position: relative;
  }
  .cta-block-new-row {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 12px;
    margin-bottom: 28px;
    position: relative;
  }
  .cta-btn-solid {
    background: var(--bg);
    color: var(--accent);
    padding: 12px 22px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
    transition: transform 0.3s;
  }
  .cta-btn-solid:hover { transform: translateY(-2px); }
  .cta-btn-outline {
    background: transparent;
    color: rgba(11,14,24,0.65);
    padding: 12px 22px;
    border-radius: 999px;
    border: 1px solid rgba(11,14,24,0.2);
    font-weight: 500;
    font-size: 14px;
    text-decoration: none;
    transition: color 0.3s, border-color 0.3s;
  }
  .cta-btn-outline:hover { color: var(--bg); border-color: var(--bg); }

  /* Email gate inside CTA */
  .cta-gate { max-width: 460px; margin: 0 auto 28px; position: relative; }
  .cta-gate-label {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(11,14,24,0.5);
    margin-bottom: 10px;
  }
  .cta-gate-form {
    display: flex; gap: 8px;
    background: rgba(255,255,255,0.6);
    border-radius: 999px;
    padding: 4px;
  }
  @media (max-width: 520px) {
    .cta-gate-form { flex-direction: column; background: transparent; padding: 0; gap: 8px; }
  }
  .cta-gate-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 12px 16px;
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--bg);
    outline: none;
    min-width: 0;
  }
  @media (max-width: 520px) {
    .cta-gate-input { background: rgba(255,255,255,0.6); border-radius: 999px; }
  }
  .cta-gate-input::placeholder { color: rgba(11,14,24,0.4); }
  .cta-gate-btn {
    background: var(--bg);
    color: var(--accent);
    border: none;
    padding: 12px 20px;
    border-radius: 999px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.3s, opacity 0.3s;
    white-space: nowrap;
  }
  .cta-gate-btn:hover:not(:disabled) { transform: translateY(-1px); }
  .cta-gate-btn:disabled { opacity: 0.5; cursor: not-allowed; }
  .cta-gate-success {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    padding: 14px 18px;
    background: rgba(255,255,255,0.6);
    border-radius: 999px;
    color: var(--bg);
    font-size: 14px;
    font-weight: 500;
  }
  .cta-gate-error {
    margin-top: 10px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: rgba(11,14,24,0.55);
  }

  .cta-meta-row {
    display: inline-flex; flex-wrap: wrap; justify-content: center;
    gap: 24px;
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(11,14,24,0.35);
    position: relative;
  }

  /* Cal.com embed below the gradient block */
  .cta-cal-wrap {
    max-width: var(--max-w); margin: 24px auto 0; padding: 0 var(--px);
  }
  .cta-cal-wrap > div {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    overflow: hidden;
  }

  /* Footer */
  .foot-new {
    border-top: 1px solid var(--line);
    padding: 40px 0;
    text-align: center;
  }
  .foot-new-inner {
    max-width: var(--max-w); margin: 0 auto; padding: 0 var(--px);
    display: flex; flex-direction: column; align-items: center; gap: 16px;
  }
  .foot-new-tag {
    color: var(--fg3);
    font-size: 12px;
    max-width: 480px;
    line-height: 1.6;
    margin: 0;
  }
  .foot-new-meta {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--fg3);
    display: inline-flex; gap: 24px; flex-wrap: wrap; justify-content: center;
  }

  /* Reveal */
  .js-reveal .reveal {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.7s cubic-bezier(0.16,1,0.3,1), transform 0.7s cubic-bezier(0.16,1,0.3,1);
  }
  .js-reveal .reveal.in { opacity: 1; transform: none; }
`;

// ── Logo ───────────────────────────────────────────────
function LogoMark({ size = 32 }) {
  return (
    <img
      src="logo.png"
      alt="IAMAI"
      className="brand-mark"
      style={{ width: size, height: size, borderRadius: Math.round(size * 0.26) }}
    />
  );
}

// ── Nav ────────────────────────────────────────────────
function Nav() {
  const [mobileOpen, setMobileOpen] = useState(false);
  const handleLinkClick = () => setMobileOpen(false);

  useEffect(() => {
    if (!mobileOpen) return;
    const onKey = (e) => { if (e.key === 'Escape') setMobileOpen(false); };
    document.addEventListener('keydown', onKey);
    return () => document.removeEventListener('keydown', onKey);
  }, [mobileOpen]);

  useEffect(() => {
    document.body.style.overflow = mobileOpen ? 'hidden' : '';
    return () => { document.body.style.overflow = ''; };
  }, [mobileOpen]);

  return (
    <nav className="nav">
      <div className="container nav-row">
        <a href="#top" className="brand" onClick={handleLinkClick}>
          <LogoMark />
          <b>IAMAI</b>
        </a>
        <div className="nav-links">
          <a href="#work">Work</a>
          <a href="#services">What you get</a>
          <a href="#pricing">Pricing</a>
          <a href="#founders">About</a>
        </div>
        <a href="#contact" className="nav-cta">
          <span className="dot"></span>
          Book a free visit
        </a>
        <button
          className={"hamburger" + (mobileOpen ? " is-open" : "")}
          onClick={() => setMobileOpen(!mobileOpen)}
          aria-label={mobileOpen ? 'Close menu' : 'Open menu'}
          aria-expanded={mobileOpen}
        >
          <span className="hamburger-line" />
          <span className="hamburger-line" />
          <span className="hamburger-line" />
        </button>
      </div>

      <div className={"mobile-menu" + (mobileOpen ? " is-open" : "")}>
        <div className="mobile-menu-inner">
          <a href="#work" onClick={handleLinkClick}>Work</a>
          <a href="#services" onClick={handleLinkClick}>What you get</a>
          <a href="#pricing" onClick={handleLinkClick}>Pricing</a>
          <a href="#founders" onClick={handleLinkClick}>About</a>
          <a href="#contact" className="mobile-menu-cta" onClick={handleLinkClick}>
            <span className="dot"></span>
            Book a free visit
          </a>
        </div>
      </div>
      {mobileOpen && (
        <div className="mobile-overlay" onClick={() => setMobileOpen(false)} aria-hidden="true" />
      )}
    </nav>
  );
}

// ── Industries strip (Section A) ───────────────────────
const INDUSTRIES = [
  "Print shops", "Auto body", "Gyms & fitness", "Food & pastry",
  "Retail & fashion", "Healthcare", "Salons",
];
function IndustriesStrip() {
  return (
    <section className="industries reveal" aria-label="Industries we build for" data-animate>
      {INDUSTRIES.map((t) => (
        <span className="industry-pill" key={t} data-animate-child>{t}</span>
      ))}
    </section>
  );
}

// ── Portfolio grid (Section B) ─────────────────────────
const PROJECTS = [
  { title: "O'Sweet",       tag: "Pastry · Morocco",   sub: "CEO P&L + Staff Payroll + E-commerce", grad: "linear-gradient(145deg, #1a1235 0%, #2d1b4a 100%)", accent: "#a78bfa", pills: ["Dashboard", "E-commerce", "Payroll"] },
  { title: "PrintTrack",    tag: "Print shop · LA",    sub: "Pipeline + Invoicing + 3 Portals",     grad: "linear-gradient(145deg, #101c33 0%, #1a3060 100%)", accent: "#6BA3D6", pills: ["Pipeline", "Invoices", "3 portals"] },
  { title: "CNK Collision", tag: "Auto body · LA",     sub: "Shop CRM + ETA Alerts",                grad: "linear-gradient(145deg, #2a1212 0%, #4a1e1e 100%)", accent: "#f87171", pills: ["Vehicle CRM", "Alerts"] },
  { title: "A&M Fitness",   tag: "Training · NoHo",    sub: "CRM + Student Portal + Website",       grad: "linear-gradient(145deg, #1a1508 0%, #3d2a0a 100%)", accent: "#fbbf24", pills: ["CRM", "Portal", "Website"] },
  { title: "MediTrack",     tag: "Healthcare",         sub: "Intake CRM + Compliance Audit",        grad: "linear-gradient(145deg, #0c1a30 0%, #153060 100%)", accent: "#60a5fa", pills: ["Intake CRM", "Audit log"] },
  { title: "Pica Loca",     tag: "Street food · LA",   sub: "Bilingual Landing Page + Menu",        grad: "linear-gradient(145deg, #3D2A0A 0%, #6B4D1A 100%)", accent: "#facc15", pills: ["EN/ES", "Menu"] },
];
function Portfolio() {
  return (
    <section id="work" className="pc-section" data-animate>
      <header className="s-head reveal">
        <div className="s-eyebrow">Portfolio</div>
        <h2 className="s-title">7 systems. 7 industries. <span className="it">One studio.</span></h2>
        <p className="s-sub">Each one built by the same two people who'll build yours.</p>
      </header>

      <div className="pc-grid reveal">
        {PROJECTS.map((p, i) => (
          <article className="pc" key={p.title} style={{ transitionDelay: `${i * 60}ms` }} data-animate-child>
            <div className="pc-top" style={{ background: p.grad }}>
              <h3>{p.title}</h3>
            </div>
            <div className="pc-body">
              <div className="pc-tag" style={{ color: p.accent }}>{p.tag}</div>
              <p className="pc-sub">{p.sub}</p>
              <div className="pc-pills">
                {p.pills.map((pill) => <span className="pc-pill" key={pill}>{pill}</span>)}
              </div>
            </div>
          </article>
        ))}
      </div>

      <div className="pc-foot reveal">
        <a href="/portfolio" className="btn-ghost">View full portfolio →</a>
      </div>
    </section>
  );
}

// ── What You Get (Section C) ──────────────────────────
const SERVICES = [
  { num: "01", title: "Your dashboard",  desc: "One screen for everything — orders, revenue, customers, alerts. Know what's happening without asking anyone." },
  { num: "02", title: "Client portal",   desc: "Your customers check their own status, upload files, view invoices. They stop calling five times a day." },
  { num: "03", title: "Automations",     desc: "Notifications when orders move. Alerts when stock runs low. Follow-ups that send themselves." },
];
function WhatYouGet() {
  return (
    <section id="services" className="svc3-section" data-animate>
      <header className="s-head reveal">
        <div className="s-eyebrow">What you get</div>
        <h2 className="s-title">Everything your shop needs. <span className="it">Nothing it doesn't.</span></h2>
        <p className="s-sub">We sit in your shop, see what's broken, and build exactly what fixes it.</p>
      </header>

      <div className="svc3-grid">
        {SERVICES.map((s, i) => (
          <article className="svc3 reveal" key={s.num} style={{ transitionDelay: `${i * 80}ms` }}>
            <div className="svc3-num">{s.num}</div>
            <h3 className="svc3-title">{s.title}</h3>
            <p className="svc3-desc">{s.desc}</p>
          </article>
        ))}
      </div>
    </section>
  );
}

// ── How It Works (Section D) ──────────────────────────
const HOW_STEPS = [
  { num: "01", title: "Ibrahim visits your shop", desc: "No slides. No jargon. He watches how you work and spots what's slow.", tag: "In person · free" },
  { num: "02", title: "Demo in 48 hours",         desc: "A working demo with your name on it. Real screens, real data, real logins.", tag: "Your brand · your data" },
  { num: "03", title: "Live in one week",         desc: "We deploy, train your team, and keep monitoring. Pause anytime.", tag: "You're in control" },
];
function HowItWorks() {
  return (
    <section className="how-section">
      <header className="s-head">
        <div className="s-eyebrow">How it works</div>
        <h2 className="s-title">Three steps. <span className="it">One week.</span></h2>
      </header>

      <div className="how-strip">
        {HOW_STEPS.map((s) => (
          <div className="how-step" key={s.num}>
            <div className="how-num">{s.num}</div>
            <h3 className="how-title">{s.title}</h3>
            <p className="how-desc">{s.desc}</p>
            <div className="how-tag">{s.tag}</div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ── Pricing (Section E) ────────────────────────────────
const TIERS_NEW = [
  {
    name: "Setup — Basic",
    sub: "System install on your business",
    price: "$799",
    period: "One-time",
    features: ["Custom dashboard", "Client portal + logins", "Domain + hosting", "Branded emails", "Training + guide"],
    pop: false,
  },
  {
    name: "Setup + Website",
    sub: "Everything in Basic + full website",
    price: "$1,399",
    period: "One-time",
    features: ["Everything in Basic", "Mobile-friendly website", "Google Business sync", "SEO + contact form", "Photo gallery"],
    pop: true,
  },
];
function Pricing() {
  return (
    <section id="pricing" className="price-section" data-animate>
      <header className="s-head reveal">
        <div className="s-eyebrow">Pricing</div>
        <h2 className="s-title">No surprises. <span className="it">No hidden fees.</span></h2>
        <p className="s-sub">One-time setup. Monthly maintenance to keep you growing.</p>
      </header>

      <div className="price-grid">
        {TIERS_NEW.map((t, i) => (
          <article className={"tier2 " + (i === 0 ? "reveal-left" : "reveal-right") + (t.pop ? " tier2-pop" : "")} key={t.name}>
            <h3 className="tier2-name">{t.name}</h3>
            <div className="tier2-sub">{t.sub}</div>
            <div className="tier2-price">{t.price}</div>
            <div className="tier2-period">{t.period}</div>
            <ul className="tier2-features">
              {t.features.map((f) => <li key={f}>{f}</li>)}
            </ul>
            <a href="#contact" className="tier2-cta">Get started →</a>
          </article>
        ))}
      </div>

      <p className="price-foot reveal">
        + Monthly maintenance to keep your system running and evolving. Pause anytime.
      </p>
    </section>
  );
}

// ── Founders (Section F) ──────────────────────────────
function Founders() {
  return (
    <section id="founders" className="founders2-section" data-animate>
      <header className="s-head reveal">
        <div className="s-eyebrow">Who we are</div>
        <h2 className="s-title">Two brothers. <span className="it">Zero middle-managers.</span></h2>
        <p className="s-sub">The person you meet is the person who builds your system.</p>
      </header>

      <div className="founders2-grid">
        <article className="founder2 reveal-left">
          <div className="founder2-head">
            <div className="fb-avatar">I</div>
            <div>
              <h3 className="founder2-name">Ibrahim</h3>
              <div className="founder2-role">Co-founder · Face-to-face</div>
            </div>
          </div>
          <p className="founder2-bio">
            Ibrahim visits your shop, understands your workflow, and translates your reality into a system that fits. He shows up, sets you up, and makes sure it works.
          </p>
        </article>

        <article className="founder2 reveal-right">
          <div className="founder2-head">
            <div className="fb-avatar">O</div>
            <div>
              <h3 className="founder2-name">Oussama</h3>
              <div className="founder2-role">Co-founder · Engineering &amp; AI</div>
            </div>
          </div>
          <p className="founder2-bio">
            Oussama designs and builds every dashboard, portal, and automation. The reason your system ships in days and works the way your business works.
          </p>
        </article>
      </div>
    </section>
  );
}

// ── CTA (Section G) ───────────────────────────────────
function CTA() {
  const [email, setEmail] = useState("");
  const [status, setStatus] = useState("idle"); // idle | sending | sent | error

  const submit = async () => {
    if (!email.includes("@") || status === "sending") return;
    setStatus("sending");
    try {
      const res = await fetch(SUPABASE_URL, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "apikey": SUPABASE_ANON,
          "Authorization": "Bearer " + SUPABASE_ANON,
          "Prefer": "return=minimal",
        },
        body: JSON.stringify({
          email: email,
          source: "cta-email-gate",
        }),
      });
      if (!res.ok) throw new Error("insert failed");
      setStatus("sent");
    } catch {
      setStatus("error");
      setTimeout(() => setStatus("idle"), 3000);
    }
  };

  return (
    <section id="contact" className="cta-section" data-animate>
      <div className="cta-block-new reveal-scale">
        <h2 className="cta-block-new-h">
          Show us what's <span className="it">slowing you down.</span>
        </h2>
        <p className="cta-block-new-p">
          A free visit. No commitment. Ibrahim sees what's broken and shows you what a system would look like.
        </p>

        <div className="cta-gate">
          {status === "sent" ? (
            <div className="cta-gate-success">
              <span aria-hidden="true">✓</span>
              <span>Sent — Ibrahim will reach out within 24 hours.</span>
            </div>
          ) : (
            <>
              <div className="cta-gate-label">Get a free visit — enter your email</div>
              <div className="cta-gate-form">
                <input
                  type="email"
                  className="cta-gate-input"
                  placeholder="you@yourshop.com"
                  value={email}
                  onChange={(e) => setEmail(e.target.value)}
                  disabled={status === "sending"}
                  onKeyDown={(e) => { if (e.key === "Enter") submit(); }}
                  aria-label="Email address"
                />
                <button
                  type="button"
                  className="cta-gate-btn"
                  disabled={!email.includes("@") || status === "sending"}
                  onClick={submit}
                >
                  {status === "sending" ? "Sending…" : "Get a free visit"}
                </button>
              </div>
              {status === "error" && (
                <p className="cta-gate-error">Something went wrong — try again or WhatsApp us.</p>
              )}
            </>
          )}
        </div>

        <div className="cta-block-new-row">
          <a
            href="https://wa.me/17739394430"
            target="_blank"
            rel="noopener noreferrer"
            className="cta-btn-outline"
          >
            WhatsApp us
          </a>
          <button
            type="button"
            className="cta-btn-solid"
            data-cal-link="oussama-el-kamla-cqgmi0/30min"
            data-cal-config='{"layout":"month_view"}'
          >
            Or pick a time →
          </button>
        </div>

        <div className="cta-meta-row">
          <span>Miami · EN / ES</span>
          <span>Response &lt; 24h</span>
          <span>By a founder</span>
        </div>
      </div>

      <div className="cta-cal-wrap">
        <div
          id="cal-inline"
          data-cal-link="oussama-el-kamla-cqgmi0/30min"
          data-cal-config='{"layout":"month_view"}'
          style={{ width: "100%", minHeight: 400, overflow: "hidden" }}
        ></div>
      </div>
    </section>
  );
}

// ── Footer (Section H) ────────────────────────────────
function Footer() {
  return (
    <footer className="foot-new">
      <div className="foot-new-inner">
        <div className="brand">
          <LogoMark />
          <b>IAMAI</b>
        </div>
        <p className="foot-new-tag">
          Two founders. One system at a time. Built for the businesses that keep your city running.
        </p>
        <div className="foot-new-meta">
          <span>© 2026 IAMAI Studio</span>
          <span>Miami</span>
        </div>
      </div>
    </footer>
  );
}

// ── Sticky Mobile CTA ─────────────────────────────────
function StickyMobileCTA() {
  const [visible, setVisible] = useState(false);

  useEffect(() => {
    const contact = document.getElementById("contact");
    if (!contact) return;

    const onScroll = () => {
      const contactTop = contact.getBoundingClientRect().top;
      const windowH = window.innerHeight;
      setVisible(window.scrollY > windowH * 0.8 && contactTop > windowH * 0.5);
    };

    window.addEventListener("scroll", onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  return (
    <div className={"sticky-cta" + (visible ? " is-visible" : "")}>
      <a href="#contact" className="sticky-cta-btn">
        <span className="dot"></span>
        Book a free visit →
      </a>
    </div>
  );
}

// ── App ───────────────────────────────────────────────
function App() {
  useReveal();
  useEffect(() => {
    var s = document.createElement('script');
    s.src = 'animations.js';
    s.onload = function () { window.initScrollAnimations && window.initScrollAnimations(); };
    document.body.appendChild(s);
  }, []);

  return (
    <>
      <style dangerouslySetInnerHTML={{ __html: SECTION_STYLES }} />
      <div id="top" />
      <div className="atmosphere" aria-hidden="true"></div>
      <div className="grid-overlay" aria-hidden="true"></div>
      <div className="grain" aria-hidden="true"></div>
      <Nav />
      <main>
        <CinematicHero />
        <IndustriesStrip />
        <div className="grad-line" />
        <Portfolio />
        <div className="grad-line" />
        <WhatYouGet />
        <HowItWorks />
        <div className="grad-line" />
        <Pricing />
        <div className="grad-line" />
        <Founders />
        <CTA />
      </main>
      <Footer />
      <StickyMobileCTA />
    </>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<App />);
