// Azlani — Home · Roofing (visual) + How it works

// ── ROOFING — visual: 6 floating callouts around a central placeholder ──
const Roofing = () => {
  const tags = [
    { t: 'Active leaks', x: '8%', y: '12%' },
    { t: 'Property managers', x: '72%', y: '8%' },
    { t: 'Storm damage', x: '4%', y: '52%' },
    { t: 'Flat roofs · TPO · EPDM', x: '76%', y: '46%' },
    { t: 'Photos by SMS', x: '14%', y: '86%' },
    { t: 'Decision-makers', x: '70%', y: '82%' },
  ];
  return (
    <section id="roofing" className="section-pad" style={{ borderBottom: '1px solid var(--line)' }}>
      <div className="container">
        <FadeUp><div className="eyebrow"><span className="dot"></span> Built for commercial roofing</div></FadeUp>
        <h2 className="serif" style={{ fontSize: 'clamp(48px, 7vw, 112px)', letterSpacing: '-0.03em', margin: '24px 0 0', fontWeight: 400, maxWidth: 1200 }}>
          <RevealLines lines={['It speaks roofing.']} />
        </h2>

        <div style={{ position: 'relative', marginTop: 80, height: 'clamp(420px, 55vh, 560px)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
          {/* center label */}
          <div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', pointerEvents: 'none' }}>
            <div>
              <div className="mono" style={{ fontSize: 11, letterSpacing: '0.22em', color: 'var(--muted)', textTransform: 'uppercase' }}>Azlani knows</div>
              <div className="serif ital" style={{ fontSize: 'clamp(64px, 10vw, 168px)', color: 'var(--ember)', letterSpacing: '-0.04em', marginTop: 8 }}>roofing.</div>
            </div>
          </div>
          {/* floating tags */}
          {tags.map((tag, i) => (
            <FadeUp key={tag.t} delay={i * 0.08} style={{ position: 'absolute', left: tag.x, top: tag.y }}>
              <span className="serif" style={{
                display: 'inline-block', padding: '10px 22px',
                background: 'var(--paper)', border: '1px solid var(--line)',
                borderRadius: 100, fontSize: 'clamp(16px, 1.5vw, 22px)', fontStyle: 'italic',
                boxShadow: '0 8px 24px -8px rgba(0,0,0,0.15)',
                animation: `tagFloat 6s ease-in-out infinite ${i * 0.5}s`,
              }}>{tag.t}</span>
            </FadeUp>
          ))}
          <style>{`@keyframes tagFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }`}</style>
        </div>
      </div>
    </section>
  );
};

// ── HOW IT WORKS — pinned scrolly. 5 steps reveal in sequence as you scroll, like the phone scene.
const HowItWorks = () => {
  const sectionRef = React.useRef(null);
  const [progress, setProgress] = React.useState(0);

  React.useEffect(() => {
    const onScroll = () => {
      if (!sectionRef.current) return;
      const r = sectionRef.current.getBoundingClientRect();
      const total = r.height - window.innerHeight;
      const scrolled = -r.top;
      setProgress(Math.max(0, Math.min(1, scrolled / total)));
    };
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  const steps = [
    ['01', 'Lead arrives', 'Call or website form. Any hour.', 'A new inbound — voice or web — hits Azlani in real time. No queue, no voicemail, no missed window.'],
    ['02', 'Azlani answers', 'Instant. No queue.', 'Picks up on the first ring with a warm, on-brand greeting. Identifies the caller and the reason for the call.'],
    ['03', 'Qualifies', 'The questions an estimator would ask.', 'Property type, role, address, urgency, scope. Roofing-specific intake — flat vs. pitched, TPO/EPDM, active leak vs. inspection.'],
    ['04', 'Photos & booking', 'SMS for photos. Books the inspection.', 'Texts the caller for photos and videos of the issue, then books a slot on your calendar that fits the urgency.'],
    ['05', 'Clean handoff', 'Structured brief to your team.', 'Your estimator gets a one-page brief — contact, building, scope, photos, urgency, slot — before they leave the truck.'],
  ];

  // Lead-in (0..0.08) → 5 step slots evenly distributed → tail (0.92..1.0)
  // Each step gets ~0.168 of the bar.
  const leadIn = 0.08;
  const tail = 0.08;
  const usable = 1 - leadIn - tail;
  const stepWidth = usable / steps.length;
  const rawIdx = (progress - leadIn) / stepWidth;
  const activeStep = Math.max(0, Math.min(steps.length - 1, Math.floor(rawIdx)));

  // local progress within current step (0..1) — for slide/fade timings
  const localP = Math.max(0, Math.min(1, rawIdx - activeStep));

  return (
    <section
      ref={sectionRef}
      id="how"
      className="dark"
      style={{ height: '900vh', position: 'relative', borderBottom: '1px solid var(--line)' }}
    >
      <div style={{ position: 'sticky', top: 0, height: '100vh', overflow: 'hidden', display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
        <div className="container" style={{ width: '100%' }}>
          {/* Header */}
          <div className="eyebrow"><span className="dot"></span> How it works</div>
          <h2 className="serif" style={{
            fontSize: 'clamp(40px, 5.5vw, 80px)',
            letterSpacing: '-0.03em', margin: '20px 0 48px', fontWeight: 400, color: 'var(--bg)',
            paddingBottom: '0.08em',
          }}>
            Five steps.
          </h2>

          {/* Stage: left = step rail (vertical list), right = active step detail */}
          <div style={{
            display: 'grid',
            gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1.2fr)',
            gap: 'clamp(40px, 6vw, 96px)',
            alignItems: 'center',
            borderTop: '1px solid rgba(244,239,230,0.18)',
            paddingTop: 32,
          }}>
            {/* LEFT — step rail */}
            <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
              {steps.map(([n, title], i) => {
                const isActive = i === activeStep;
                const isPast = i < activeStep;
                return (
                  <div key={n} style={{
                    display: 'grid', gridTemplateColumns: '60px 1fr',
                    gap: 24, padding: '14px 0',
                    alignItems: 'baseline',
                    opacity: isActive ? 1 : isPast ? 0.45 : 0.28,
                    transition: 'opacity .4s ease',
                    position: 'relative',
                  }}>
                    {/* active indicator bar */}
                    <div style={{
                      position: 'absolute', left: -24, top: '50%', transform: 'translateY(-50%)',
                      width: 3, height: isActive ? 28 : 0,
                      background: 'var(--ember)',
                      transition: 'height .4s ease',
                    }}></div>
                    <div className="mono" style={{
                      fontSize: 13,
                      color: isActive ? 'var(--ember)' : 'var(--ember-soft)',
                      letterSpacing: '0.06em',
                      transition: 'color .4s ease',
                    }}>{n}</div>
                    <div className="serif" style={{
                      fontSize: isActive ? 'clamp(24px, 2.4vw, 34px)' : 'clamp(20px, 2vw, 28px)',
                      letterSpacing: '-0.015em',
                      color: 'var(--bg)',
                      transition: 'font-size .4s ease',
                      lineHeight: 1.1,
                    }}>{title}</div>
                  </div>
                );
              })}
            </div>

            {/* RIGHT — active step detail (slides between steps) */}
            <div style={{ position: 'relative', minHeight: 360 }}>
              {steps.map(([n, title, body, longBody], i) => {
                const isActive = i === activeStep;
                const isPast = i < activeStep;
                const offset = isActive ? 0 : isPast ? -40 : 40;
                const op = isActive ? 1 : 0;
                return (
                  <div key={n} style={{
                    position: 'absolute', inset: 0,
                    display: 'flex', flexDirection: 'column', justifyContent: 'center',
                    transform: `translateY(${offset}px)`,
                    opacity: op,
                    transition: 'transform .35s cubic-bezier(.7,0,.2,1), opacity .25s ease',
                  }}>
                    <div className="mono" style={{
                      fontSize: 11, letterSpacing: '0.18em', textTransform: 'uppercase',
                      color: 'var(--ember-soft)', marginBottom: 20,
                    }}>STEP {n} · OF 05</div>
                    <h3 className="serif" style={{
                      fontSize: 'clamp(48px, 5.5vw, 88px)',
                      lineHeight: 0.95,
                      letterSpacing: '-0.035em',
                      color: 'var(--ember)',
                      margin: 0,
                      fontWeight: 500,
                      paddingBottom: '0.08em',
                    }}>{title}</h3>
                    <p className="serif" style={{
                      fontSize: 'clamp(20px, 1.8vw, 26px)',
                      lineHeight: 1.3,
                      letterSpacing: '-0.015em',
                      color: 'var(--bg)',
                      margin: '20px 0 0',
                      fontWeight: 400,
                      maxWidth: 520,
                    }}>{body}</p>
                    <p style={{
                      fontSize: 16,
                      lineHeight: 1.55,
                      color: 'rgba(244,239,230,0.65)',
                      margin: '20px 0 0',
                      maxWidth: 520,
                    }}>{longBody}</p>
                  </div>
                );
              })}
            </div>
          </div>

          {/* progress chrome — match phone-scene vocabulary */}
          <div className="mono" style={{ marginTop: 56, fontSize: 12, color: 'var(--muted)', letterSpacing: '0.12em' }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', maxWidth: 360 }}>
              <span>▸ STEP {String(activeStep + 1).padStart(2, '0')}/05</span>
              <span>{Math.round(progress * 100).toString().padStart(2, '0')}%</span>
            </div>
            <div style={{ height: 1, background: 'rgba(244,239,230,0.18)', marginTop: 8, position: 'relative', maxWidth: 360 }}>
              <div style={{ position: 'absolute', inset: 0, background: 'var(--ember)', transform: `scaleX(${progress})`, transformOrigin: 'left' }}></div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
};

// DashScene unchanged from previous version (still in this file)
const DashScene = () => {
  const sectionRef = React.useRef(null);
  const [progress, setProgress] = React.useState(0);
  React.useEffect(() => {
    const onScroll = () => {
      if (!sectionRef.current) return;
      const r = sectionRef.current.getBoundingClientRect();
      const total = r.height - window.innerHeight;
      setProgress(Math.max(0, Math.min(1, -r.top / total)));
    };
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);
  const leads = [
    { time: '02:14', name: 'John Smith', tag: 'URGENT', detail: 'Active leak · warehouse · 124 Main', source: 'after-hours call' },
    { time: '06:42', name: 'Maria Chen', tag: 'NEW', detail: 'Inspection request · office building', source: 'website form' },
    { time: '07:18', name: 'D. Patel', tag: 'NEW', detail: 'Storm damage · 3-property portfolio', source: 'after-hours call' },
    { time: '08:03', name: 'R. Alvarez', tag: 'PHOTOS', detail: 'Awaiting photos · flat roof', source: 'website form' },
    { time: '08:31', name: 'Building Co', tag: 'BOOKED', detail: 'Maintenance contract · Wed 2PM', source: 'inbound call' },
    { time: '09:07', name: 'T. Nakamura', tag: 'NEW', detail: 'Replacement quote · 80k sqft', source: 'after-hours call' },
  ];
  const visible = Math.floor(progress * leads.length * 1.2);
  const tagColor = (t) => ({ URGENT: 'var(--ember)', NEW: 'var(--ink)', PHOTOS: 'var(--ink-2)', BOOKED: 'var(--ink-2)' }[t] || 'var(--ink)');
  return (
    <section ref={sectionRef} style={{ height: '260vh', position: 'relative', background: 'var(--ink)', color: 'var(--bg)', borderBottom: '1px solid var(--line)' }}>
      <div style={{ position: 'sticky', top: 0, height: '100vh', overflow: 'hidden', display: 'flex', alignItems: 'center' }}>
        <div className="container" style={{ width: '100%' }}>
          <div className="eyebrow" style={{ color: 'var(--ember-soft)' }}><span className="dot"></span> Scene 03 · your morning</div>
          <h2 className="serif" style={{ fontSize: 'clamp(40px, 5.5vw, 80px)', letterSpacing: '-0.025em', margin: '20px 0 40px', fontWeight: 400, maxWidth: 900 }}>
            You wake up to <span className="ital" style={{ color: 'var(--ember-soft)' }}>booked work.</span>
          </h2>
          <div style={{ background: 'rgba(244,239,230,0.04)', border: '1px solid rgba(244,239,230,0.18)', borderRadius: 4, overflow: 'hidden', maxWidth: 1100 }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', padding: '14px 24px', borderBottom: '1px solid rgba(244,239,230,0.18)' }} className="mono">
              <span style={{ fontSize: 11, letterSpacing: '0.12em' }}>azlani · today's intake</span>
              <span style={{ fontSize: 11, color: 'var(--ember-soft)' }}>{visible} leads</span>
            </div>
            <div style={{ minHeight: 380 }}>
              {leads.slice(0, visible).map((l, i) => (
                <div key={i} style={{ display: 'grid', gridTemplateColumns: '80px 100px 200px 1fr 160px', gap: 24, padding: '20px 24px', borderBottom: i === leads.length - 1 ? 'none' : '1px solid rgba(244,239,230,0.12)', alignItems: 'center', animation: 'rowIn .4s ease', fontSize: 14 }}>
                  <span className="mono" style={{ fontSize: 12, opacity: 0.6 }}>{l.time}</span>
                  <span style={{ display: 'inline-block', padding: '4px 10px', borderRadius: 100, background: tagColor(l.tag), color: l.tag === 'URGENT' ? 'var(--ink)' : 'var(--bg)', fontSize: 10, letterSpacing: '0.12em', fontFamily: 'Geist Mono, monospace', border: l.tag !== 'URGENT' ? '1px solid rgba(244,239,230,0.3)' : 'none', textAlign: 'center' }}>{l.tag}</span>
                  <span className="serif" style={{ fontSize: 20 }}>{l.name}</span>
                  <span style={{ opacity: 0.75 }}>{l.detail}</span>
                  <span className="mono" style={{ fontSize: 11, opacity: 0.5, textAlign: 'right' }}>{l.source}</span>
                </div>
              ))}
            </div>
          </div>
          <style>{`@keyframes rowIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }`}</style>
        </div>
      </div>
    </section>
  );
};

window.DashScene = DashScene;
window.Roofing = Roofing;
window.HowItWorks = HowItWorks;
