// Pillars Scaling Systems — solar landing page
// (CSS fade-up reveals via IntersectionObserver, gradient gold/silver headers,
//  conic Button1, GlareCard, starBG background, Inter font @600).
// Drop into vite-source/src/components/Landing.jsx and render from App.jsx.

const { useState, useRef, useEffect, useCallback, memo } = React;

// CSS-driven fade-up reveal — observes when an element scrolls in, then adds .is-revealed.
// Replaces motion/react usage to avoid the React-version split with esm.sh.
function Reveal({ as: Tag = "div", delay = 0, className = "", children, ...rest }) {
  const ref = useRef(null);
  const [shown, setShown] = useState(false);
  useEffect(() => {
    if (!ref.current) return;
    const obs = new IntersectionObserver(([e]) => {
      if (e.isIntersecting) { setShown(true); obs.disconnect(); }
    }, { threshold: 0.12, rootMargin: "0px 0px -40px 0px" });
    obs.observe(ref.current);
    return () => obs.disconnect();
  }, []);
  return (
    <Tag
      ref={ref}
      style={{ transitionDelay: shown ? `${delay}s` : "0s" }}
      className={"reveal " + (shown ? "is-revealed " : "") + className}
      {...rest}
    >
      {children}
    </Tag>
  );
}
window.Reveal = Reveal;

// ------- Button1 (gold gradient + shimmer sweep + pulse glow) -------
function Button1({ children = "Claim My Metro", icon = true, size = "md", onClick }) {
  const sizeClass = size === "lg"
    ? "h-16 px-12 text-lg rounded-xl gap-3"
    : "h-12 px-6 text-sm rounded-lg gap-2";
  return (
    <button onClick={onClick} className={"group relative inline-flex items-center justify-center overflow-hidden font-bold tracking-wide text-slate-950 bg-gradient-to-b from-yellow-200 via-amber-400 to-yellow-600 ring-1 ring-amber-200/70 animate-[ctapulse_2.4s_ease-in-out_infinite] transition-transform duration-200 hover:-translate-y-0.5 hover:from-yellow-100 hover:via-amber-300 hover:to-yellow-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-amber-200 cursor-pointer " + sizeClass}>
      <span aria-hidden className="pointer-events-none absolute inset-y-0 left-0 w-1/3 bg-gradient-to-r from-transparent via-white/75 to-transparent animate-[shimmer_3.2s_ease-in-out_infinite] group-hover:animate-[shimmer_1.6s_ease-in-out_infinite]" />
      <span className="relative z-10 inline-flex items-center gap-2">
        {children}
        {icon && (
          <svg width={size === "lg" ? 16 : 13} height={size === "lg" ? 16 : 13} viewBox="0 0 24 24" fill="currentColor"><path d="M5 21l16-9L5 3v18z"/></svg>
        )}
      </span>
    </button>
  );
}
window.Button1 = Button1;

// ------- GlareCard (3D tilt + foil) — port of vite glare-card.jsx -------
function GlareCard({ children, className = "" }) {
  const ref = useRef(null);
  const stateRef = useRef({ glare: { x: 50, y: 50 }, bg: { x: 50, y: 50 }, rot: { x: 0, y: 0 } });
  const inside = useRef(false);

  const cs = {
    "--m-x": "50%", "--m-y": "50%", "--r-x": "0deg", "--r-y": "0deg",
    "--bg-x": "50%", "--bg-y": "50%", "--duration": "300ms",
    "--foil-size": "100%", "--opacity": "0", "--radius": "20px", "--easing": "ease",
  };
  const bgs = {
    "--step": "5%",
    "--foil-svg": `url("data:image/svg+xml,%3Csvg width='26' height='26' viewBox='0 0 26 26' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2.99994 3.419C2.99994 3.419 21.6142 7.43646 22.7921 12.153C23.97 16.8695 3.41838 23.0306 3.41838 23.0306' stroke='white' stroke-width='5' stroke-miterlimit='3.86874' stroke-linecap='round'/%3E%3C/svg%3E")`,
    "--rainbow":
      "repeating-linear-gradient(0deg,#FFD86B calc(var(--step)*1),#E8C76A calc(var(--step)*2),#D4AF37 calc(var(--step)*3),#A88323 calc(var(--step)*4),#D4AF37 calc(var(--step)*5),#E8C76A calc(var(--step)*6),#FFD86B calc(var(--step)*7)) 0% var(--bg-y)/200% 700% no-repeat",
    "--diagonal":
      "repeating-linear-gradient(128deg,#0e152e 0%,hsl(220,30%,40%) 3.8%,hsl(220,30%,40%) 4.5%,hsl(220,30%,40%) 5.2%,#0e152e 10%,#0e152e 12%) var(--bg-x) var(--bg-y)/300% no-repeat",
    "--shade":
      "radial-gradient(farthest-corner circle at var(--m-x) var(--m-y),rgba(255,255,255,0.1) 12%,rgba(255,255,255,0.15) 20%,rgba(255,255,255,0.25) 120%) var(--bg-x) var(--bg-y)/300% no-repeat",
    backgroundBlendMode: "hue, hue, hue, overlay",
  };
  const apply = () => {
    if (!ref.current) return;
    const { glare, bg, rot } = stateRef.current;
    ref.current.style.setProperty("--m-x", glare.x + "%");
    ref.current.style.setProperty("--m-y", glare.y + "%");
    ref.current.style.setProperty("--r-x", rot.x + "deg");
    ref.current.style.setProperty("--r-y", rot.y + "deg");
    ref.current.style.setProperty("--bg-x", bg.x + "%");
    ref.current.style.setProperty("--bg-y", bg.y + "%");
  };

  return (
    <div
      style={cs}
      ref={ref}
      className="relative isolate [contain:layout_style] [perspective:600px] transition-transform duration-[var(--duration)] ease-[var(--easing)] will-change-transform w-full h-full"
      onPointerMove={(e) => {
        const rect = e.currentTarget.getBoundingClientRect();
        const px = ((e.clientX - rect.left) / rect.width) * 100;
        const py = ((e.clientY - rect.top) / rect.height) * 100;
        const dx = px - 50, dy = py - 50;
        const s = stateRef.current;
        s.bg.x = 50 + px / 4 - 12.5;
        s.bg.y = 50 + py / 3 - 16.67;
        s.rot.x = -(dx / 3.5) * 0.4;
        s.rot.y = (dy / 2) * 0.4;
        s.glare.x = px; s.glare.y = py;
        apply();
      }}
      onPointerEnter={() => {
        inside.current = true;
        setTimeout(() => { if (inside.current && ref.current) ref.current.style.setProperty("--duration", "0s"); }, 300);
      }}
      onPointerLeave={() => {
        inside.current = false;
        if (ref.current) {
          ref.current.style.removeProperty("--duration");
          ref.current.style.setProperty("--r-x", "0deg");
          ref.current.style.setProperty("--r-y", "0deg");
        }
      }}
    >
      <div className="h-full grid will-change-transform origin-center transition-transform duration-[var(--duration)] ease-[var(--easing)] [transform:rotateY(var(--r-x))_rotateX(var(--r-y))] rounded-[var(--radius)] border border-slate-800 hover:[--opacity:0.6] hover:[--duration:200ms] hover:[--easing:linear] overflow-hidden">
        <div className="w-full h-full grid [grid-area:1/1] mix-blend-soft-light [clip-path:inset(0_0_0_0_round_var(--radius))]">
          <div className={"h-full w-full bg-slate-950 " + className}>{children}</div>
        </div>
        <div className="w-full h-full grid [grid-area:1/1] mix-blend-soft-light [clip-path:inset(0_0_1px_0_round_var(--radius))] opacity-[var(--opacity)] transition-opacity duration-[var(--duration)] [background:radial-gradient(farthest-corner_circle_at_var(--m-x)_var(--m-y),_rgba(255,255,255,0.8)_10%,_rgba(255,255,255,0.65)_20%,_rgba(255,255,255,0)_90%)]" />
        <div
          className="w-full h-full grid [grid-area:1/1] mix-blend-color-dodge opacity-[var(--opacity)] transition-opacity [clip-path:inset(0_0_1px_0_round_var(--radius))] [background:var(--pattern),_var(--rainbow),_var(--diagonal),_var(--shade)]"
          style={bgs}
        />
      </div>
    </div>
  );
}
window.GlareCard = GlareCard;

// ------- FocusCards (sibling-blur on hover) — port of focus-cards.jsx -------
function FocusCards({ items }) {
  const [hovered, setHovered] = useState(null);
  return (
    <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 max-w-6xl mx-auto w-full">
      {items.map((c, i) => (
        <div
          key={i}
          onMouseEnter={() => setHovered(i)}
          onMouseLeave={() => setHovered(null)}
          onClick={() => c.onClick && c.onClick(i)}
          className={
            "rounded-xl relative bg-neutral-900 overflow-hidden h-56 md:h-72 w-full transition-all duration-300 ease-out cursor-pointer border border-amber-400/10 " +
            (hovered !== null && hovered !== i ? "blur-sm scale-[0.98]" : "")
          }
        >
          {c.src ? <img src={c.src} alt={c.title} className="object-cover absolute inset-0 w-full h-full" /> : (
            <div className="absolute inset-0 flex items-center justify-center bg-[linear-gradient(135deg,#0e2148,#06122B)] text-amber-400/30">
              <svg width="56" height="56" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="9" r="1.5"/><path d="M3 17l5-5 4 4 3-3 6 6"/></svg>
            </div>
          )}
          <div className={"absolute inset-0 bg-black/55 flex flex-col justify-end p-5 transition-opacity duration-300 " + (hovered === i ? "opacity-100" : "opacity-0")}>
            <p className="text-sm md:text-base font-medium bg-clip-text text-transparent bg-gradient-to-b from-neutral-50 to-neutral-300">{c.desc}</p>
            <div className="mt-3 text-xl md:text-2xl font-medium bg-clip-text text-transparent bg-gradient-to-b from-yellow-200 via-amber-300 to-yellow-500">{c.title}</div>
          </div>
        </div>
      ))}
    </div>
  );
}
window.FocusCards = FocusCards;


const HSilver = ({ children }) => (
  <span className="bg-gradient-to-t from-slate-200 via-gray-300 to-slate-50 bg-clip-text text-transparent">{children}</span>
);
const HGold = ({ children }) => (
  <span className="bg-gradient-to-r from-yellow-300 via-amber-400 to-yellow-600 bg-clip-text text-transparent">{children}</span>
);

// Highlights mandated by PRD
const Hi = {
  accent: ({ children }) => (
    <span className="italic font-semibold text-amber-200 [background:linear-gradient(180deg,transparent_72%,rgba(212,175,55,.32)_72%,rgba(212,175,55,.32)_92%,transparent_92%)] px-[0.08em]">{children}</span>
  ),
  proof: ({ children }) => (
    <span className="inline-block font-bold text-slate-950 px-2 py-[1px] rounded-md text-[0.92em] -translate-y-[1px] bg-gradient-to-b from-yellow-200 via-amber-400 to-yellow-500 shadow-[0_4px_14px_rgba(212,175,55,0.35),inset_0_1px_0_rgba(255,255,255,0.45)]">{children}</span>
  ),
  risk: ({ children }) => (
    <span className="text-white font-bold px-2 py-[2px] rounded-lg border border-amber-400/55 [background:linear-gradient(180deg,rgba(212,175,55,.18),rgba(212,175,55,.06))] shadow-[0_0_0_4px_rgba(212,175,55,0.08),inset_0_1px_0_rgba(255,255,255,0.08)]">{children}</span>
  ),
  urgency: ({ children }) => (
    <span className="text-amber-200 font-semibold relative">
      <span className="inline-block w-[6px] h-[6px] rounded-full bg-amber-400 mr-2 align-middle shadow-[0_0_10px_rgba(212,175,55,0.8)] animate-pulse" />
      {children}
    </span>
  ),
};

// ------- Wordmark (logo mark + PILLARS SCALING SYSTEMS) -------
function Wordmark({ size = "text-sm sm:text-lg" }) {
  return (
    <span className="flex items-center gap-3">
      <img
        src="assets/logo-pillars.svg"
        alt="Pillars Scaling Systems"
        className="flex-none w-11 h-8 object-contain drop-shadow-[0_2px_8px_rgba(255,255,255,0.35)]"
      />
      <span className={"text-white tracking-[0.32em] font-medium " + size}>PILLARS SCALING SYSTEMS</span>
    </span>
  );
}

// ------- Survey Modal -------
function SurveyModal() {
  const [open, setOpen] = useState(false);

  useEffect(() => {
    const handler = () => setOpen(true);
    window.addEventListener("stellmaris:opensurvey", handler);
    return () => window.removeEventListener("stellmaris:opensurvey", handler);
  }, []);

  useEffect(() => {
    const k = (e) => { if (e.key === "Escape") setOpen(false); };
    document.addEventListener("keydown", k);
    return () => document.removeEventListener("keydown", k);
  }, []);

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

  if (!open) return null;

  return (
    <div
      className="fixed inset-0 z-[900] bg-slate-950/85 backdrop-blur-md flex items-center justify-center p-4"
      onClick={() => setOpen(false)}
    >
      <div
        onClick={(e) => e.stopPropagation()}
        className="relative w-full max-w-xl bg-slate-900 rounded-2xl border border-amber-400/20 overflow-hidden shadow-[0_30px_80px_rgba(0,0,0,0.7)]"
      >
        <button
          onClick={() => setOpen(false)}
          className="absolute top-4 right-4 z-10 w-10 h-10 rounded-full bg-slate-800 border border-amber-400/20 text-white/70 hover:text-white hover:border-amber-400/50 flex items-center justify-center transition-colors text-lg cursor-pointer"
        >✕</button>
        <div className="flex justify-center px-6 py-4">
          <iframe
            src="https://api.leadconnectorhq.com/widget/survey/YfqQP0ZbzvTlkjW8yDtQ"
            style={{ border: "none", width: "100%" }}
            scrolling="no"
            id="YfqQP0ZbzvTlkjW8yDtQ"
            title="survey"
            height="620"
          />
        </div>
      </div>
    </div>
  );
}
window.SurveyModal = SurveyModal;

const openSurvey = () => window.dispatchEvent(new Event("stellmaris:opensurvey"));

// ------- Hero -------
function HeroSection() {
  return (
    <div id="hero" data-screen-label="01 Hero" className="bg relative min-h-[92vh] flex flex-col">
      <div className="absolute inset-0 bg-gradient-to-b from-slate-950/30 via-slate-950/60 to-slate-950 pointer-events-none" />
      <div className="relative px-4 sm:px-12 lg:px-24 xl:px-40 pt-10 pb-16 flex flex-col flex-1">
        {/* Wordmark */}
        <Reveal as="div" delay={0} className="flex items-center justify-between">
          <a href="#hero" className="flex items-center gap-3">
            <Wordmark />
          </a>
        </Reveal>

        {/* Two-column hero */}
        <div className="flex-1 grid lg:grid-cols-2 gap-12 lg:gap-16 items-center mt-10 pb-8">
          {/* Left: copy */}
          <div className="flex flex-col">
            <Reveal as="p" delay={0.05} className="text-2xl sm:text-3xl font-bold mb-6">
              <Hi.urgency>Residential Solar Companies doing $3M+ / year:</Hi.urgency>
            </Reveal>

            <Reveal as="h1" delay={0.1} className="text-white text-4xl sm:text-5xl md:text-6xl xl:text-[68px] font-medium leading-[1.1] tracking-tight">
              <HSilver>Add $100k+ Per Month in Installation Revenue.</HSilver><br />
              <HGold>Within 90 Days. Pay On Results Only.</HGold>
            </Reveal>

            <Reveal as="p" delay={0.3} className="mt-7 text-base sm:text-lg text-white/75 disclaimer leading-relaxed max-w-xl">
              The solar companies that dominate the next 10 years aren't waiting on doors and referrals. They're running a machine that fills their calendar with <Hi.urgency>$30,000–$60,000 installs</Hi.urgency> year-round.
          
            </Reveal>

            <Reveal as="div" delay={0.45} className="mt-9">
              <Button1 size="lg" onClick={openSurvey}>Claim My Metro</Button1>
            </Reveal>
          </div>

          {/* Right: hero video 4:3 */}
          <Reveal as="div" delay={0.25} className="w-full aspect-[4/3] rounded-2xl overflow-hidden border border-amber-400/15">
            <video
              src="assets/residential-checks.mp4"
              autoPlay
              loop
              muted
              playsInline
              className="w-full h-full object-cover"
            />
          </Reveal>
        </div>
      </div>

      {/* Trust marquee */}
      <div className="border-y border-amber-400/15 bg-amber-400/[0.03] py-4 overflow-hidden relative">
        <div className="absolute inset-y-0 left-0 w-32 bg-gradient-to-r from-slate-950 to-transparent z-10 pointer-events-none" />
        <div className="absolute inset-y-0 right-0 w-32 bg-gradient-to-l from-slate-950 to-transparent z-10 pointer-events-none" />
        <div className="flex gap-14 w-max animate-[marquee_38s_linear_infinite]">
          {Array.from({length:2}).flatMap((_, dup) => [
            <TrustItem key={`a-${dup}`}><span className="text-amber-400 font-bold mr-2">✓</span> Plugs Into Your Existing Sales Org &amp; CRM</TrustItem>,
            <TrustItem key={`b-${dup}`}><span className="text-amber-400 font-bold mr-2">✓</span> <strong className="text-white font-semibold">Pre-Qualified Appointments</strong> — Not Leads</TrustItem>,
            <TrustItem key={`c-${dup}`}><span className="text-amber-400 font-bold mr-2">✓</span> You only pay when appointments hit your calendar.</TrustItem>,
            <TrustItem key={`d-${dup}`}><Hi.urgency>One Solar Company Per Metro — Your Market, Locked In</Hi.urgency></TrustItem>,
          ])}
        </div>
      </div>
    </div>
  );
}
const TrustItem = ({ children }) => <span className="whitespace-nowrap text-sm text-white/80 tracking-wide">{children}</span>;

// ------- Case Studies (the proof core) -------
const Stat = ({ value, label }) => (
  <div className="flex flex-col items-center justify-center text-center px-2 py-4 rounded-xl border border-amber-400/20 bg-slate-950/60">
    <div className="text-2xl sm:text-3xl font-bold bg-gradient-to-r from-yellow-300 via-amber-400 to-yellow-600 bg-clip-text text-transparent">{value}</div>
    <div className="mt-1.5 text-[10px] sm:text-[11px] uppercase tracking-[0.14em] text-white/50 font-semibold">{label}</div>
  </div>
);

const Shot = ({ src, alt, w, h, caption }) => (
  <figure className="mb-6">
    <img
      src={src}
      alt={alt}
      width={w}
      height={h}
      loading="lazy"
      decoding="async"
      className="w-full h-auto rounded-xl border border-amber-400/15 bg-slate-950"
    />
    <figcaption className="mt-2 text-xs text-white/45 leading-relaxed">{caption}</figcaption>
  </figure>
);

function CaseStudySection() {
  return (
    <div id="case-studies" data-screen-label="02 Case Studies" className="px-4 sm:px-12 lg:px-24 xl:px-40 py-24 text-white">
      <div className="text-center max-w-4xl mx-auto mb-16">
        <Reveal as="h2" delay={0.1} className="text-4xl sm:text-5xl md:text-6xl xl:text-[68px] font-medium leading-[1.05] tracking-tight">
          <HSilver>Real Solar Companies. Real Transformations.</HSilver>{" "}
          <HGold>The Numbers, Front to Back.</HGold>
        </Reveal>
        <Reveal as="p" delay={0.3} className="mt-5 text-white/75 disclaimer text-xl sm:text-l max-w-3xl mx-auto leading-relaxed">
          In collaboration with our sister company JARA
        </Reveal>
      </div>

      <div className="max-w-6xl mx-auto space-y-10">

        {/* Case Study 01 — REC */}
        <Reveal as="div" delay={0.15} className="rounded-2xl border border-amber-400/15 bg-gradient-to-b from-slate-900/60 to-slate-950/70 p-6 sm:p-10">
          <p className="text-[11px] tracking-[0.22em] text-amber-400 font-semibold uppercase mb-8">Case Study 01 — Renewable Energy Corporation 7 months in</p>
          <div className="grid lg:grid-cols-2 gap-8 items-start">
            {/* Narrative */}
            <div>
              <div className="rounded-xl border border-white/10 bg-slate-950/50 p-5 mb-6">
                <p className="text-xs tracking-[0.2em] text-white/40 font-semibold uppercase mb-2">Before</p>
                <p className="text-white/80 leading-relaxed text-base">100,000+ purchased internet leads over 14 years. Had many defensive, angry prospects — half of whom couldn't clear underwriting. <Hi.accent>3–4x the work, for a fraction of the productivity.</Hi.accent></p>
              </div>
              <p className="text-xs tracking-[0.2em] text-white/40 font-semibold uppercase mb-2">The fix</p>
              <ul className="space-y-2 mb-6 text-white/80 text-base leading-relaxed">
                <li>• Branded Meta campaigns built on his face and story.</li>
                <li>• Custom landing pages that sell before the call.</li>
                <li>• An AI qualification layer, booking straight to the calendar.</li>
              </ul>
              <div className="grid grid-cols-2 sm:grid-cols-4 gap-3 mb-4">
                <Stat value="155" label="Install Appointments" />
                <Stat value="25" label="Projects Closed" />
                <Stat value="$966k" label="Closed Revenue" />
                <Stat value="$38k" label="Avg. Project" />
              </div>
              <p className="text-sm text-white/60 leading-relaxed mb-6">Jan–Jul 2026. Sales floor 3 → 6 reps, at ¼ the time and energy.</p>
              <blockquote className="border-l-4 border-l-amber-400 pl-4 mb-4">
                <p className="text-lg text-white font-medium leading-snug italic">"It's a godsend to keep the momentum going without having to be compromised… They're just coming in and… lining up on the calendar."</p>
                <footer className="mt-2 text-sm text-amber-300 font-semibold not-italic">— Sean McNeill, Renewable Energy Corporation</footer>
              </blockquote>
              <div className="space-y-1.5 text-sm text-white/60">
                <p>✦ One Saturday: <strong className="text-white/85">$100K closed before dinner.</strong></p>
                <p>✦ "Generating not just leads, but actual appointments. There's a difference."</p>
              </div>
            </div>
            {/* Media */}
            <div>
              <Shot
                src="assets/case-studies/rec-results-jan-jul-2026.png"
                alt="REC dashboard: $966,585 closed revenue, 25 projects, January–July 2026"
                w={1314} h={612}
                caption="REC's dashboard, Jan–Jul 2026: $966,585 closed on 25 projects. This is the same screen we'd put in front of you."
              />
              <div className="aspect-video rounded-xl bg-black border border-amber-400/10 overflow-hidden mb-2">
                <iframe src="https://www.youtube.com/embed/Cy6Vv9RPrRg" className="w-full h-full" frameBorder="0" allowFullScreen allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" title="REC Case Study — Sean McNeill" />
              </div>
              <p className="text-xs text-white/45">REC Case Study — Sean McNeill, July 2026.</p>
            </div>
          </div>
        </Reveal>

        {/* Case Study 02 — Solar Ninjas */}
        <Reveal as="div" delay={0.15} className="rounded-2xl border border-amber-400/15 bg-gradient-to-b from-slate-900/60 to-slate-950/70 p-6 sm:p-10">
          <p className="text-[11px] tracking-[0.22em] text-amber-400 font-semibold uppercase mb-8">Case Study 02 — Solar Ninjas Energy Solutions Last 12 month performance</p>
          <div className="grid lg:grid-cols-2 gap-8 items-start">
            {/* Narrative (order-2 on desktop so media sits left) */}
            <div className="lg:order-2">
              <div className="rounded-xl border border-white/10 bg-slate-950/50 p-5 mb-6">
                <p className="text-xs tracking-[0.2em] text-white/40 font-semibold uppercase mb-2">Before</p>
                <p className="text-white/80 leading-relaxed text-base">No marketing. Referrals and door-knocking only. Reps sitting idle, meeting tire-kickers.</p>
              </div>
              <p className="text-xs tracking-[0.2em] text-white/40 font-semibold uppercase mb-2">The fix</p>
              <ul className="space-y-2 mb-6 text-white/80 text-base leading-relaxed">
                <li>• Redefined appointment qualification: owns the home, roof age and material, recent electrical bill, in service area.</li>
                <li>• Reactivated <strong className="text-white">2,000 dormant contacts</strong> first — at <strong className="text-white">$0</strong> ad spend.</li>
                <li>• Repositioned messaging for the post-tax-credit market.</li>
              </ul>
              <div className="grid grid-cols-2 sm:grid-cols-4 gap-3 mb-4">
                <Stat value="413" label="Qualified Appointments" />
                <Stat value="67" label="Projects Installed" />
                <Stat value="$2.19M" label="Installed Revenue" />
                <Stat value="41x" label="Blended ROAS" />
              </div>
              <p className="text-sm text-white/60 leading-relaxed mb-6">Last 12 months, on <Hi.proof>$41K</Hi.proof> in ad spend. Sales team 1 → 3 reps. Through the December dead spot — <Hi.proof>~$182K/month</Hi.proof>.</p>
              <blockquote className="border-l-4 border-l-amber-400 pl-4">
                <p className="text-lg text-white font-medium leading-snug italic">"I appreciate their professionalism, responsiveness and the consistent progress they've helped us achieve."</p>
                <footer className="mt-2 text-sm text-amber-300 font-semibold not-italic">— Derrick LeClerc, Solar Ninjas Energy Solutions</footer>
              </blockquote>
            </div>
            {/* Media (order-1 on desktop) */}
            <div className="lg:order-1">
              <Shot
                src="assets/case-studies/ninjas-crm-2025-06.png"
                alt="Solar Ninjas CRM dashboard: $1.33M total revenue, 23.64% win rate"
                w={1622} h={643}
                caption="Outstanding month, generated $581k in additional revenue from 13 closed jobs generated using our system."
              />
              <Shot
                src="assets/case-studies/ninjas-calendar-jul-2026.png"
                alt="Solar Ninjas July 2026 calendar packed with In Person Visits, Phone Calls, and Online Video Calls"
                w={2988} h={1628}
                caption="Derrick's calendar, July 2026 — In Person Visits, Phone Calls, and Online Video Calls stacked back to back."
              />
              <Shot
                src="assets/case-studies/ninjas-nurture-thread.png"
                alt="Solar Ninjas nurture thread: homeowner question, natural reply, booked appointment, pipeline stage"
                w={1824} h={778}
                caption="The nurture loop in action: a homeowner's question gets a natural reply, a booked appointment, and a pipeline stage — automatically."
              />
            </div>
          </div>
        </Reveal>

      </div>

      <CTAGroup />
    </div>
  );
}

// ------- Section 3 — Testimonials + System -------
function ValueStackSection() {
  const cards = [
    { i: "i.", title: "Targeting", body: "Only qualified homeowners enter: they own the home, roof and financing check out, in your service area. No renters. No tire-kickers. No underwriting surprises at the door." },
    { i: "ii.", title: "Demand Generation", body: "Database reactivation -- free, highest leverage opening move + scaling traffic and sales with paid ads." },
    { i: "iii.", title: "Closed Loop", body: "First click to installed revenue: AI qualification, nurture, booking, and follow-through past signature — financing, permitting, install. The loop closes at installation." },
  ];
  return (
    <div id="testimonials" data-screen-label="03 System" className="px-4 sm:px-12 lg:px-24 xl:px-40 py-24 text-white">
      <div className="text-center max-w-4xl mx-auto mb-14">
        <Reveal as="h2" delay={0.1} className="text-4xl sm:text-5xl md:text-6xl xl:text-[68px] font-medium leading-[1.05] tracking-tight">
          <HSilver>We Could Tell You How Good the System Is.</HSilver>{" "}
          <HGold>Or We Could Just Show You.</HGold>
        </Reveal>
        <Reveal as="p" delay={0.3} className="mt-5 text-white/75 disclaimer text-xl sm:text-l max-w-3xl mx-auto leading-relaxed">
          In collaboration with our sister company JARA
        </Reveal>
      </div>

      {/* Testimonials */}
      <Reveal as="h3" delay={0} className="text-center text-2xl sm:text-3xl md:text-4xl font-medium tracking-tight mb-8">
      </Reveal>
      <div className="mt-6 max-w-6xl mx-auto space-y-6">
        {[
          { name: "Derek LeClerc",   img: "assets/SolarNinjas.webp", quote: "Over time I've seen the results of their efforts build and improve which has made a real impact on my performance.", video: "https://www.youtube.com/embed/ETgu3YpghMw" },
          { name: "Andres Dovale",   img: "assets/Andres.webp",      quote: "An extremely pleasant experience. I would definitely use them again.",                                               video: "https://www.youtube.com/embed/Pt6GsS1q0wY" },
          { name: "Nikolai Hertz",   img: "assets/Nikolai.webp",     quote: "150% increase in new customers... Extraordinary",                                                                    video: "https://www.youtube.com/embed/BBUoqU6vWFE" },
          { name: "Siraat Mustafa",  img: "assets/Siraat.webp",      quote: "We hope to continue our business together and continue building!",                                                    video: "https://www.youtube.com/embed/kKMNhkyFQ1A" },
        ].map((t, i) => (
          <Reveal as="div" key={i} delay={0.05 * (i + 1)} className="grid md:grid-cols-2 gap-7 p-6 sm:p-8 rounded-2xl border border-amber-400/15 bg-gradient-to-b from-slate-900/60 to-slate-950/70 items-center">
            <div>
              <div className="text-amber-400 text-lg tracking-[0.18em] mb-3">★ ★ ★ ★ ★</div>
              <p className="text-xl sm:text-2xl text-white font-medium leading-snug mb-5">"{t.quote}"</p>
              <div className="flex items-center gap-3">
                <img src={t.img} alt={t.name} className="w-12 h-12 rounded-full border border-amber-400/30 object-cover" />
                <div className="text-white text-sm font-semibold">{t.name}</div>
              </div>
            </div>
            <div className="aspect-video rounded-xl bg-black border border-amber-400/10 overflow-hidden">
              <iframe src={t.video} className="w-full h-full" frameBorder="0" allowFullScreen allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" title={t.name} />
            </div>
          </Reveal>
        ))}
      </div>

      {/* Value Stack */}
      <Reveal as="h2" delay={0} className="text-center max-w-4xl mx-auto text-4xl sm:text-5xl md:text-6xl xl:text-[68px] font-medium leading-[1.05] tracking-tight mt-20 mb-6">
        <HSilver>The Full-Stack System That Fills Your Calendar With</HSilver>{" "}
        <HGold>High-Ticket Installs.</HGold>
      </Reveal>
      <div className="grid grid-cols-1 md:grid-cols-3 gap-5 max-w-6xl mx-auto mb-14">
        {cards.map((c, i) => (
          <Reveal as="div" key={i} delay={0.15 + i*0.08} className="h-full">
            <GlareCard className="flex flex-col items-start p-7 min-h-[260px]">
              <div className="text-amber-400/70 italic text-3xl mb-2" style={{fontFamily: "Roboto, serif"}}>{c.i}</div>
              <h3 className="text-white font-bold text-2xl mb-3">{c.title}</h3>
              <p className="text-sm font-medium bg-clip-text text-transparent bg-gradient-to-b from-neutral-50 to-neutral-400 mb-4">{c.body}</p>
            </GlareCard>
          </Reveal>
        ))}
      </div>
      <Reveal as="p" delay={0.2} className="text-center text-base sm:text-lg max-w-2xl mx-auto mb-8 leading-relaxed text-white/80">
        Done-for-you. You do two things: <Hi.accent>Onboard your reps into the CRM — once. Show up and close.</Hi.accent>
      </Reveal>
      <Reveal as="p" delay={0.3} className="text-center text-lg sm:text-xl md:text-2xl max-w-3xl mx-auto leading-relaxed text-white">
 <Hi.proof>$100K+/month in additional installation revenue within 90 days</Hi.proof>.<br />
        <Hi.risk>If your calendar doesn't fill, we don't get paid.</Hi.risk><br />
      </Reveal>

      <CTAGroup />
    </div>
  );
}

function CTAGroup() {
  return (
    <div className="text-center mt-12">
      <Button1 onClick={openSurvey}>Claim My Metro</Button1>
    </div>
  );
}


// ------- FAQ -------
const FAQ_ITEMS = [
  {
    q: "How is this different from what other appointment generation agencies do?",
    a: <>Other agencies charge you for leads whether your phone rings or not. We built a Target–Nurture–Seal system that qualifies every homeowner before they touch your calendar — and <Hi.risk>we only get paid when appointments land on it</Hi.risk>.</>
  },
  {
    q: "What happens to my existing marketing channels?",
    a: <>We don't replace what's working — we layer a booked-appointment machine on top of it. Canvassing, referrals, and your existing lead sources still have a role. While your competitor waits on a door-knock, <Hi.accent>you've got appointments that came in overnight</Hi.accent> — from contacts you already own and ads you didn't have to manage.</>
  },
  {
    q: "How quickly will I see results?",
    a: <>Reactivation puts the first appointments on your calendar within <Hi.proof>1–2 weeks</Hi.proof> — before a dollar of ad spend. The full target: <Hi.proof>$100K+/month in additional installation revenue within 90 days</Hi.proof>. Solar Ninjas booked <Hi.proof>413 qualified appointments</Hi.proof> in 12 months, through the December dead spot. And speed compounds: HBR's study of 1.25M leads found you're <Hi.proof>7x more likely</Hi.proof> to qualify a lead contacted within the hour — we respond in under 5 minutes.</>
  },
  {
    q: "We do $1M+ a year — we don't really need more marketing.",
    a: <>Revenue isn't the problem — <Hi.accent>installed revenue is</Hi.accent>. At a <Hi.proof>$30K average install</Hi.proof> and a <Hi.proof>15% close rate</Hi.proof> on qualified appointments, <Hi.proof>27 booked appointments a month = $100K+ in additional installed revenue</Hi.proof> — from the same closers, same hours. We don't push volume; we replace low-yield sits with high-yield ones.</>
  },
  {
    q: "We've tried paid ads before and got garbage leads. Why would this be different?",
    a: <>Most installers ran ads leading with "30% off" and "no-cost solar" — a discount that stopped existing when the federal tax credit expired at the end of 2025. Those ads pre-selected freebie-hunters, and the platforms optimized for cheap clicks, not appointments. We fix both failures: <Hi.accent>positioning that leads with a real outcome, and targeting that only reaches install-ready homeowners</Hi.accent> — optimized for booked appointments, not clicks.</>
  },
  {
    q: "We already have more leads than we can handle — we can't take on more jobs.",
    a: <>That's not a lead problem — <Hi.accent>that's a job-quality problem</Hi.accent>. A closer grinding through 15 cold sits a week closes in the single digits — and half of those signatures die before install. One qualified, financeable appointment that closes and actually installs <Hi.proof>beats ten flaky signatures</Hi.proof> — and nothing gets clawed back.</>
  },
];

function FAQSection() {
  const [open, setOpen] = useState(null);
  return (
    <div id="faq" data-screen-label="04 FAQ" className="px-4 sm:px-12 lg:px-24 xl:px-40 py-24 text-white">
      <div className="text-center max-w-3xl mx-auto mb-12">
        <Reveal as="h2" delay={0.1} className="text-4xl sm:text-5xl md:text-6xl xl:text-[68px] font-medium leading-[1.05]">
          <HSilver>Frequently Asked Questions</HSilver>
        </Reveal>
      </div>
      <div className="max-w-3xl mx-auto">
        {FAQ_ITEMS.map((it, i) => {
          const isOpen = open === i;
          return (
            <Reveal as="div" key={i} delay={i * 0.05} className="border-t border-amber-400/15 last:border-b">
              <button onClick={()=>setOpen(isOpen?null:i)} className="w-full flex items-center justify-between gap-5 py-6 text-left text-lg sm:text-xl font-semibold hover:text-amber-200 transition-colors">
                <span>{it.q}</span>
                <span className={"flex-none w-8 h-8 rounded-full border border-amber-400 text-amber-400 flex items-center justify-center text-lg font-light transition-transform duration-300 " + (isOpen ? "rotate-45 bg-amber-400/10" : "")}>+</span>
              </button>
              <div style={{maxHeight: isOpen ? 800 : 0}} className="overflow-hidden transition-[max-height] duration-500 ease-out">
                <p className="pb-7 text-white/75 leading-relaxed text-base max-w-2xl">{it.a}</p>
              </div>
            </Reveal>
          );
        })}
      </div>
      <CTAGroup />
    </div>
  );
}

// ------- Proof Gallery + P.S. -------
function ProofSection() {
  const [lightbox, setLightbox] = useState(null);
  const items = Array.from({length: 12}, (_, i) => ({
    src: `assets/proof/${i + 1}.webp`,
    alt: `Result ${i + 1}`,
  }));
  useEffect(()=>{
    const k = (e) => {
      if (lightbox === null) return;
      if (e.key === "Escape") setLightbox(null);
      if (e.key === "ArrowLeft") setLightbox((lightbox - 1 + items.length) % items.length);
      if (e.key === "ArrowRight") setLightbox((lightbox + 1) % items.length);
    };
    document.addEventListener("keydown", k);
    return ()=>document.removeEventListener("keydown", k);
  }, [lightbox]);

  return (
    <div id="proof" data-screen-label="05 Proof" className="px-4 sm:px-12 lg:px-24 xl:px-40 py-24 text-white">
      <div className="text-center max-w-3xl mx-auto mb-12">
        <Reveal as="h2" delay={0.1} className="text-4xl sm:text-5xl md:text-6xl xl:text-[68px] font-medium leading-[1.05]">
          <HSilver>More receipts —</HSilver>{" "}<HGold>raw screenshots from the field.</HGold>
        </Reveal>
      </div>

      {/* Masonry grid — CSS columns preserves each image's natural aspect ratio */}
      <div className="max-w-6xl mx-auto" style={{columns: "1", columnGap: "1rem"}}>
        <style>{`
          @media (min-width: 640px)  { #proof-masonry { columns: 2; } }
          @media (min-width: 1024px) { #proof-masonry { columns: 3; } }
        `}</style>
        <div id="proof-masonry" style={{columnGap: "1rem"}}>
          {items.map((item, i) => (
            <div
              key={i}
              className="break-inside-avoid mb-4 rounded-xl overflow-hidden border border-amber-400/10 cursor-pointer relative group"
              onClick={() => setLightbox(i)}
            >
              <img
                src={item.src}
                alt={item.alt}
                className="w-full h-auto block"
                loading="lazy"
              />
              <div className="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity duration-250 flex items-center justify-center">
                <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="white" strokeWidth="1.5"><path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/></svg>
              </div>
            </div>
          ))}
        </div>
      </div>

      {/* P.S. / P.P.S. blocks */}
      <div className="mt-16 max-w-6xl mx-auto space-y-4">
        <Reveal as="div" delay={0.2} className="rounded-2xl border border-amber-400/15 border-l-[4px] border-l-amber-400 bg-gradient-to-b from-slate-900/60 to-slate-950/70 p-7 sm:p-10">
          <p className="text-lg sm:text-xl text-white/85 leading-relaxed">
            <strong className="text-amber-300 font-bold italic mr-1.5 text-xl" style={{fontFamily:"Manrope"}}>P.S.</strong>
            We only work with owners who are serious about dominating high-ticket installs — not chasing volume with more canvassers. If that's the business you're building, book the call. If not, no hard feelings.
          </p>
        </Reveal>
        <Reveal as="div" delay={0.3} className="rounded-2xl border border-amber-400/15 border-l-[4px] border-l-amber-400 bg-gradient-to-b from-slate-900/60 to-slate-950/70 p-7 sm:p-10">
          <p className="text-lg sm:text-xl text-white/85 leading-relaxed">
            <strong className="text-amber-300 font-bold italic mr-1.5 text-xl" style={{fontFamily:"Manrope"}}>P.P.S.</strong>
            We cap at one solar company per metro. When yours is claimed, it's closed. <Hi.accent>That's not a sales tactic. It's the model.</Hi.accent>
          </p>
        </Reveal>
      </div>

      <CTAGroup />

      {/* Lightbox */}
      {lightbox !== null && (
        <div className="fixed inset-0 z-[1000] bg-slate-950/95 backdrop-blur-md flex items-center justify-center p-6" onClick={()=>setLightbox(null)}>
          <button onClick={(e)=>{e.stopPropagation(); setLightbox(null);}} className="absolute top-6 right-6 w-12 h-12 rounded-full bg-slate-900/70 border border-amber-400/20 text-white hover:bg-amber-400/15 hover:border-amber-400 hover:text-amber-300 cursor-pointer">✕</button>
          <button onClick={(e)=>{e.stopPropagation(); setLightbox((lightbox-1+items.length)%items.length);}} className="absolute left-4 top-1/2 -translate-y-1/2 w-12 h-12 rounded-full bg-slate-900/70 border border-amber-400/20 text-white hover:bg-amber-400/15 hover:border-amber-400 hover:text-amber-300 cursor-pointer text-xl">‹</button>
          <button onClick={(e)=>{e.stopPropagation(); setLightbox((lightbox+1)%items.length);}} className="absolute right-4 top-1/2 -translate-y-1/2 w-12 h-12 rounded-full bg-slate-900/70 border border-amber-400/20 text-white hover:bg-amber-400/15 hover:border-amber-400 hover:text-amber-300 cursor-pointer text-xl">›</button>
          <img
            onClick={(e)=>e.stopPropagation()}
            src={items[lightbox].src}
            alt={items[lightbox].alt}
            className="max-w-[88vw] max-h-[88vh] object-contain rounded-xl shadow-2xl"
          />
          <p className="absolute bottom-5 left-1/2 -translate-x-1/2 text-white/40 text-xs tracking-[0.2em]">{lightbox+1} / {items.length}</p>
        </div>
      )}
    </div>
  );
}

// ------- Sticky CTA bar -------
function StickyBar() {
  const [show, setShow] = useState(false);
  useEffect(()=>{
    const hero = document.getElementById("hero");
    if (!hero) return;
    const obs = new IntersectionObserver(([e]) => setShow(!e.isIntersecting), { rootMargin: "-80px 0px 0px 0px" });
    obs.observe(hero);
    return () => obs.disconnect();
  }, []);
  return (
    <div className={"fixed bottom-0 left-0 right-0 z-[500] backdrop-blur-md bg-slate-950/90 border-t border-amber-400/15 px-5 py-3 transition-transform duration-300 " + (show?"translate-y-0":"translate-y-full")}>
      <div className="max-w-6xl mx-auto flex items-center justify-between gap-4 flex-wrap">
        <span className="text-sm text-white">One solar company per metro. <Hi.urgency>Don't lose yours.</Hi.urgency></span>
        <Button1 onClick={openSurvey}>Claim My Metro</Button1>
      </div>
    </div>
  );
}

// ------- App -------
function App() {
  return (
    <div className="dark bg-slate-950 min-h-screen relative">
      <HeroSection/>
      <CaseStudySection/>
      <ValueStackSection/>
      <FAQSection/>
      <ProofSection/>
      <footer className="text-center text-white/45 text-xs tracking-[0.12em] py-10 border-t border-amber-400/10">
        PILLARS SCALING SYSTEMS · © 2026 · APPOINTMENT GENERATION FOR HIGH-TICKET SOLAR INSTALLERS · POWERED BY JARA
      </footer>
      <StickyBar/>
      <SurveyModal/>
    </div>
  );
}
window.SolarApp = App;
