/* global React, Icon, Button, Eyebrow, Chip, Logo */
const { useState, useEffect } = React;

const scrollTo = (id) => {
  const el = document.getElementById(id);
  if (el) el.scrollIntoView({ behavior: "smooth" });
};

// ================= NAV =================
function Nav() {
  const [scrolled, setScrolled] = useState(false);
  useEffect(() => {
    const h = () => setScrolled(window.scrollY > 20);
    window.addEventListener("scroll", h);
    return () => window.removeEventListener("scroll", h);
  }, []);
  useEffect(() => {
    const close = (e) => {
      document.querySelectorAll("details[data-nav]").forEach(d => {
        if (!d.contains(e.target)) d.removeAttribute("open");
      });
    };
    document.addEventListener("click", close);
    return () => document.removeEventListener("click", close);
  }, []);
  const LINKS = [
    {t:"scroll", id:"hero", label:"Home"},
    {t:"dropdown", label:"Services", items:[
      ["/services/tv-mounting/","TV Mounting"],
      ["/services/furniture-assembly/","Furniture Assembly"],
      ["/services/wall-drywall/","Wall & Drywall"],
      ["/services/fixtures-hardware/","Fixtures & Hardware"],
      ["/services/smart-home-lighting/","Smart Home & Lighting"],
      ["/services/faucet-toilet-repair/","Faucet & Toilet Repair"],
    ]},
    {t:"scroll", id:"about", label:"About"},
    {t:"scroll", id:"reviews", label:"Reviews"},
    {t:"dropdown", label:"Areas", items:[
      ["/areas/palo-alto/","Palo Alto"],
      ["/areas/menlo-park/","Menlo Park"],
      ["/areas/mountain-view/","Mountain View"],
      ["/areas/sunnyvale/","Sunnyvale"],
      ["/areas/cupertino/","Cupertino"],
      ["/areas/san-mateo/","San Mateo & Foster City"],
      ["/areas/burlingame/","Burlingame & Millbrae"],
      ["/areas/redwood-city/","Redwood City & San Carlos"],
      ["/areas/san-jose-south/","South San Jose"],
    ]},
    {t:"scroll", id:"contact", label:"Contact"},
  ];
  return (
    <header style={{
      position: "sticky", top: 0, zIndex: 50,
      background: scrolled ? "rgba(250,251,252,0.85)" : "rgba(250,251,252,0.97)",
      backdropFilter: "blur(16px) saturate(1.4)",
      WebkitBackdropFilter: "blur(16px) saturate(1.4)",
      borderBottom: scrolled ? "1px solid var(--gs-hairline)" : "1px solid transparent",
      transition: "border-color .2s ease",
    }}>
      <div style={{ maxWidth: "var(--container)", margin: "0 auto", padding: "14px var(--gutter)", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16 }}>
        <div style={{ flexShrink: 0 }}><Logo /></div>
        <nav style={{ display: "flex", gap: 2, flexWrap: "nowrap", alignItems: "center" }}>
          {LINKS.map((lnk, i) => lnk.t === "scroll" ? (
            <button key={i} onClick={() => scrollTo(lnk.id)} style={{
              background: "transparent", border: 0, padding: "8px 10px",
              fontFamily: "var(--font-sans)", fontSize: 13, fontWeight: 500,
              color: "var(--fg-3)", cursor: "pointer", borderRadius: 6, whiteSpace: "nowrap",
            }}>{lnk.label}</button>
          ) : (
            <details key={i} data-nav style={{ position: "relative" }}>
              <summary style={{
                listStyle: "none", cursor: "pointer", padding: "8px 10px",
                fontFamily: "var(--font-sans)", fontSize: 13, fontWeight: 500,
                color: "var(--fg-3)", borderRadius: 6, whiteSpace: "nowrap",
                display: "inline-block",
              }}>{lnk.label} ▾</summary>
              <div style={{
                position: "absolute", top: "calc(100% + 4px)", left: 0,
                background: "#FAFBFC", border: "1px solid var(--gs-hairline)",
                borderRadius: 8, padding: 6, minWidth: 220,
                boxShadow: "0 8px 24px rgba(0,0,0,0.08)", zIndex: 100,
              }}>
                {lnk.items.map(([href, label]) => (
                  <a key={href} href={href} style={{
                    display: "block", padding: "8px 12px", fontSize: 13,
                    fontFamily: "var(--font-sans)", color: "var(--fg-2)",
                    textDecoration: "none", borderRadius: 4, whiteSpace: "nowrap",
                  }}>{label}</a>
                ))}
              </div>
            </details>
          ))}
        </nav>
        <div style={{ display: "flex", gap: 8, alignItems: "center", flexShrink: 0 }}>
          <a href="tel:+16692805858" style={{ fontFamily: "var(--font-mono)", fontSize: 13, color: "var(--fg-2)", textDecoration: "none", padding: "8px 10px", display: "inline-flex", alignItems: "center", gap: 6, whiteSpace: "nowrap" }}>
            <Icon name="phone" size={14} />(669) 280-5858
          </a>
          <Button onClick={() => scrollTo("contact")} style={{ padding: "10px 16px", fontSize: 13 }}>Book</Button>
        </div>
      </div>
    </header>
  );
}

// ================= HERO =================
function Hero() {
  return (
    <section id="hero" style={{ background: "linear-gradient(150deg,#202C3A 0%,#2A3B4E 55%,#334455 100%)", padding: "96px var(--gutter) 112px", textAlign: "center" }}>
      <div style={{ maxWidth: 700, margin: "0 auto" }}>
        <div style={{ fontFamily: "var(--font-mono)", fontSize: 11, letterSpacing: "0.2em", textTransform: "uppercase", color: "rgba(74,158,255,0.75)", marginBottom: 20 }}>
          SF Peninsula · South Bay · Same-day available
        </div>
        <h1 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(34px,5vw,58px)", fontWeight: 400, color: "#fff", letterSpacing: "-0.02em", lineHeight: 1.12, margin: "0 0 18px" }}>
          White Glove Handyman<br/>for the Silicon Valley Home
        </h1>
        <p style={{ fontSize: 17, color: "rgba(255,255,255,0.65)", lineHeight: 1.7, maxWidth: 420, margin: "0 auto 40px" }}>
          Insured · Same-day<br/>
          Mon–Wed, Fri–Sat · 8 AM–8 PM · Closed Thu & Sun
        </p>
        <div style={{ display: "flex", gap: 12, justifyContent: "center", flexWrap: "wrap" }}>
          <Button onClick={() => scrollTo("contact")} style={{ padding: "14px 28px", fontSize: 15, background: "var(--gs-blue)", boxShadow: "0 0 24px rgba(74,158,255,0.35)" }}>Book a Visit</Button>
          <a href="tel:+16692805858" style={{ display: "inline-flex", alignItems: "center", gap: 8, padding: "14px 28px", fontFamily: "var(--font-sans)", fontSize: 15, fontWeight: 500, color: "rgba(255,255,255,0.9)", textDecoration: "none", border: "1px solid rgba(255,255,255,0.2)", borderRadius: 8 }}>
            <Icon name="phone" size={15} style={{ color: "var(--gs-blue)" }} />(669) 280-5858
          </a>
        </div>
      </div>
    </section>
  );
}

// ================= TRUST BAR =================
function TrustBar() {
  const items = [
    { icon: "star",         text: "4.97 ★ Rating" },
    { icon: "briefcase",    text: "1,000+ Projects" },
    { icon: "shield-check", text: "Insured · $1M GL" },
  ];
  return (
    <div style={{ background: "#242F3C", borderBottom: "1px solid rgba(255,255,255,0.06)" }}>
      <div style={{ maxWidth: "var(--container)", margin: "0 auto", display: "flex", flexWrap: "wrap" }}>
        {items.map((item, i) => (
          <div key={i} style={{ flex: "1 1 180px", padding: "16px 24px", display: "flex", alignItems: "center", gap: 10, borderRight: i < items.length - 1 ? "1px solid rgba(255,255,255,0.08)" : "none" }}>
            <Icon name={item.icon} size={15} style={{ color: "var(--gs-blue)", flexShrink: 0 }} />
            <span style={{ fontFamily: "var(--font-sans)", fontSize: 13, fontWeight: 500, color: "rgba(255,255,255,0.85)", whiteSpace: "nowrap" }}>{item.text}</span>
          </div>
        ))}
      </div>
    </div>
  );
}

// ================= SERVICES =================
function ServiceCard({ s }) {
  const [open, setOpen] = React.useState(false);
  const tiers = {
    A: { color: "#1A7A52", bg: "#E8F5EF" },
    B: { color: "#1E5DB8", bg: "#E8F2FF" },
    C: { color: "#7A5716", bg: "#FAF3E4" },
  };
  const t = tiers[s.tier] || tiers.A;
  return (
    <div style={{ background: "#FAFBFC", border: "1px solid var(--gs-hairline)", borderRadius: 14, padding: "28px 28px 24px", display: "flex", flexDirection: "column", gap: 14 }}>
      <div style={{ display: "flex", alignItems: "flex-start", justifyContent: "space-between" }}>
        <div style={{ width: 44, height: 44, borderRadius: 10, background: "var(--gs-charcoal-deep)", display: "flex", alignItems: "center", justifyContent: "center" }}>
          <Icon name={s.icon} size={20} style={{ color: "var(--gs-blue)" }} />
        </div>

      </div>
      <div>
        <div style={{ fontFamily: "var(--font-sans)", fontSize: 17, fontWeight: 600, color: "var(--fg-1)", marginBottom: 6 }}>{s.title}</div>
        <div style={{ fontSize: 14, color: "var(--fg-3)", lineHeight: 1.6 }}>{s.blurb}</div>
      </div>
      {s.subs && s.subs.length > 0 && (
        <div>
          <button onClick={() => setOpen(!open)} style={{ background: "none", border: "none", cursor: "pointer", display: "flex", alignItems: "center", gap: 6, padding: "6px 0", fontFamily: "var(--font-sans)", fontSize: 13, color: "var(--gs-blue)", fontWeight: 500 }}>
            <Icon name={open ? "chevron-up" : "chevron-down"} size={14} style={{ color: "var(--gs-blue)" }} />
            {open ? "Hide services" : `See all ${s.subs.length} services`}
          </button>
          {open && (
            <ul style={{ margin: "8px 0 0", padding: 0, listStyle: "none", display: "flex", flexDirection: "column", gap: 5 }}>
              {s.subs.map((sub, i) => (
                <li key={i} style={{ display: "flex", alignItems: "flex-start", gap: 8, fontSize: 13, color: "var(--fg-2)", lineHeight: 1.4 }}>
                  <span style={{ marginTop: 4, width: 5, height: 5, borderRadius: "50%", background: t.color, flexShrink: 0 }} />
                  {sub}
                </li>
              ))}
            </ul>
          )}
        </div>
      )}
      <div style={{ marginTop: "auto", display: "flex", alignItems: "center", justifyContent: "space-between", paddingTop: 14, borderTop: "1px solid var(--gs-hairline)" }}>
        <span style={{ fontFamily: "var(--font-mono)", fontSize: 24, fontWeight: 700, color: "var(--fg-1)" }}>from ${s.price}</span>
        <span style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--fg-3)" }}>{s.unit}</span>
      </div>
    </div>
  );
}

function ServicesSection() {
  return (
    <section id="services" style={{ padding: "96px var(--gutter)", background: "#fff" }}>
      <div style={{ maxWidth: "var(--container)", margin: "0 auto" }}>
        <div style={{ textAlign: "center", marginBottom: 56 }}>
          <Eyebrow style={{ marginBottom: 10 }}>Services</Eyebrow>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(28px,3.5vw,42px)", fontWeight: 400, color: "var(--fg-1)", letterSpacing: "-0.02em", margin: 0 }}>
            What we fix, build & install
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(300px,1fr))", gap: 24 }}>
          {(window.GS_SERVICES || []).map(s => <ServiceCard key={s.id} s={s} />)}
        </div>
        <div style={{ textAlign: "center", marginTop: 28, fontSize: 13, color: "var(--fg-3)", fontFamily: "var(--font-sans)" }}>
          All visits capped at $1,000 · After 90 min: +$40–$67/30 min (rate varies by service) · Materials not included
        </div>
      </div>
    </section>
  );
}
// ================= ABOUT =================
function AboutSection() {
  const stats = [["1,000+","Projects"],["4.97★","Avg Rating"],["2023","Founded"],["$1M","GL Insurance"]];
  return (
    <section id="about" style={{ padding: "96px var(--gutter)", background: "var(--gs-paper-warm)" }}>
      <div style={{ maxWidth: "var(--container)", margin: "0 auto", display: "grid", gridTemplateColumns: "1fr 1fr", gap: 72, alignItems: "center" }}>
        <div>
          <Eyebrow style={{ marginBottom: 14 }}>About</Eyebrow>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(26px,3vw,38px)", fontWeight: 400, color: "var(--fg-1)", letterSpacing: "-0.02em", lineHeight: 1.2, margin: "0 0 20px" }}>
            One person. Full accountability.
          </h2>
          <p style={{ fontSize: 15, color: "var(--fg-2)", lineHeight: 1.75, margin: "0 0 16px" }}>
            Grace Services was founded in 2023 to fill a gap in the Peninsula market: a single skilled professional who shows up on time, communicates clearly, and takes full responsibility for the result.
          </p>
          <div style={{ display: "flex", gap: 16, flexWrap: "wrap", marginTop: 8 }}>
            <span style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--fg-3)" }}>GL $1M · per occ.</span>
            <span style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--fg-3)" }}>CA handyman exempt (§7048.5, under $1,000 cap)</span>
          </div>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20 }}>
          {stats.map(([val, lbl]) => (
            <div key={lbl} style={{ background: "#fff", border: "1px solid var(--gs-hairline)", borderRadius: 12, padding: "24px 20px", textAlign: "center" }}>
              <div style={{ fontFamily: "var(--font-display)", fontSize: 36, fontWeight: 400, color: "var(--fg-1)", letterSpacing: "-0.02em", lineHeight: 1 }}>{val}</div>
              <div style={{ fontFamily: "var(--font-sans)", fontSize: 11, color: "var(--fg-3)", marginTop: 6, textTransform: "uppercase", letterSpacing: "0.1em" }}>{lbl}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ================= REVIEWS =================
function ReviewsSection() {
  return (
    <section id="reviews" style={{ padding: "96px var(--gutter)", background: "#fff" }}>
      <div style={{ maxWidth: "var(--container)", margin: "0 auto" }}>
        <div style={{ textAlign: "center", marginBottom: 52 }}>
          <Eyebrow style={{ marginBottom: 10 }}>Reviews</Eyebrow>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(26px,3vw,38px)", fontWeight: 400, color: "var(--fg-1)", letterSpacing: "-0.02em", margin: 0 }}>
            What clients say
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(280px,1fr))", gap: 24 }}>
          {(window.GS_REVIEWS || []).map((r, i) => (
            <div key={i} style={{ background: "#FAFBFC", border: "1px solid var(--gs-hairline)", borderRadius: 14, padding: "28px" }}>
              <div style={{ display: "flex", gap: 2, marginBottom: 14 }}>
                {Array.from({length: r.stars}).map((_, j) => (
                  <span key={j} style={{ color: "#F4A200", fontSize: 15 }}>★</span>
                ))}
              </div>
              <p style={{ fontSize: 15, color: "var(--fg-2)", lineHeight: 1.65, margin: "0 0 20px" }}>
                &ldquo;{r.text}&rdquo;
              </p>
              <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end" }}>
                <div>
                  <div style={{ fontFamily: "var(--font-sans)", fontSize: 14, fontWeight: 600, color: "var(--fg-1)" }}>{r.name}</div>
                  <div style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--fg-3)" }}>{r.city} · {r.zip}</div>
                </div>
                <div style={{ fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--fg-3)" }}>{r.date}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ================= ZONE MAP =================
function ZoneMap() {
  useEffect(() => {
    if (!window.L) return;
    const container = document.getElementById("gs-zone-map");
    if (!container || container._leaflet_id) return;

    const map = L.map("gs-zone-map", { zoomControl: true, scrollWheelZoom: false })
      .setView([37.43, -122.14], 10);

    L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
      attribution: "\u00a9 OpenStreetMap contributors", maxZoom: 14
    }).addTo(map);

    const SAME_DAY = new Set((window.GS_ZIPS || []).filter(z => z.same).map(z => z.zip));

    function addLegend() {
      const leg = L.control({ position: "bottomright" });
      leg.onAdd = () => {
        const d = L.DomUtil.create("div");
        d.style.cssText = "background:#fff;padding:8px 12px;border-radius:8px;border:1px solid #e5e8ec;font:13px/1.9 -apple-system,sans-serif;box-shadow:0 2px 8px rgba(0,0,0,.08)";
        d.innerHTML = '<span style="color:#2D9A6A">\u25cf</span> Same-day &nbsp; <span style="color:#94A0AD">\u25cf</span> Scheduled';
        return d;
      };
      leg.addTo(map);
    }

    function addCityFallback() {
      const COORDS = {"Palo Alto":[37.441,-122.143],"Menlo Park":[37.454,-122.182],"Atherton":[37.462,-122.197],"Los Altos":[37.385,-122.114],"Mountain View":[37.386,-122.083],"Sunnyvale":[37.369,-122.038],"Cupertino":[37.323,-122.032],"San Mateo":[37.563,-122.323],"Foster City":[37.555,-122.268],"Burlingame":[37.584,-122.366],"Millbrae":[37.600,-122.387],"Redwood City":[37.485,-122.236],"San Carlos":[37.507,-122.261],"Belmont":[37.521,-122.276],"Portola Valley":[37.375,-122.218],"Saratoga":[37.264,-122.023],"Los Gatos":[37.226,-121.982],"Campbell":[37.287,-121.950],"San Jose SW":[37.234,-121.912]};
      const seen = new Set();
      (window.GS_ZIPS || []).forEach(z => {
        if (seen.has(z.city) || !COORDS[z.city]) return;
        seen.add(z.city);
        const col = z.same ? "#2D9A6A" : "#94A0AD";
        L.circleMarker(COORDS[z.city], { radius: 9, color: "#fff", weight: 2, fillColor: col, fillOpacity: 0.9 })
          .addTo(map)
          .bindPopup('<strong>' + z.city + '</strong><br><span style="color:' + col + '">\u25cf ' + (z.same ? 'Same-day' : 'Scheduled') + '</span>');
      });
    }

    const zips = (window.GS_ZIPS || []).map(z => z.zip);
    const where = "ZCTA5 IN (" + zips.map(z => "'" + z + "'").join(",") + ")";
    const url = "https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/PUMA_TAD_TAZ_UGA_ZCTA/MapServer/1/query?"
      + "where=" + encodeURIComponent(where)
      + "&outFields=ZCTA5&f=geojson&returnGeometry=true&maxAllowableOffset=0.0001";

    fetch(url)
      .then(r => { if (!r.ok) throw new Error("http " + r.status); return r.json(); })
      .then(data => {
        if (!data.features || !data.features.length) throw new Error("no features");
        L.geoJSON(data, {
          style: f => {
            const z = f.properties.ZCTA5;
            const sd = SAME_DAY.has(z);
            return { color: sd ? "#1A7A52" : "#7A8A96", fillColor: sd ? "#2D9A6A" : "#94A0AD", fillOpacity: 0.4, weight: 1.5 };
          },
          onEachFeature: (f, layer) => {
            const z = f.properties.ZCTA5;
            const sd = SAME_DAY.has(z);
            const entry = (window.GS_ZIPS || []).find(x => x.zip === z) || {};
            layer.bindPopup('<strong>ZIP ' + z + '</strong>' + (entry.city ? '<br>' + entry.city : '') + '<br><span style="color:' + (sd ? '#2D9A6A' : '#94A0AD') + '">\u25cf ' + (sd ? 'Same-day available' : 'Scheduled visits') + '</span>');
          }
        }).addTo(map);
        addLegend();
      })
      .catch(() => {
        addCityFallback();
        addLegend();
      });
  }, []);

  return (
    <div id="gs-zone-map" style={{ height: 460, borderRadius: 12, border: "1px solid var(--gs-hairline)" }} />
  );
}

function ZonesSection() {
  return (
    <section id="zones" style={{ padding: "96px var(--gutter)", background: "var(--gs-paper-warm)" }}>
      <div style={{ maxWidth: "var(--container)", margin: "0 auto" }}>
        <div style={{ textAlign: "center", marginBottom: 48 }}>
          <Eyebrow style={{ marginBottom: 10 }}>Service Area</Eyebrow>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(26px,3vw,38px)", fontWeight: 400, color: "var(--fg-1)", letterSpacing: "-0.02em", margin: "0 0 10px" }}>
            SF Peninsula & South Bay
          </h2>
          <p style={{ fontSize: 14, color: "var(--fg-3)", margin: 0 }}>
            36 ZIP codes · Green = same-day available · Grey = scheduled visits
          </p>
        </div>
        <ZoneMap />
        <div style={{ marginTop: 40, display: "grid", gridTemplateColumns: "repeat(auto-fill,minmax(130px,1fr))", gap: 10 }}>
          {(window.GS_ZIPS || []).map(z => (
            <div key={z.zip} style={{ background: "#fff", border: "1px solid var(--gs-hairline)", borderRadius: 8, padding: "10px 14px", display: "flex", alignItems: "center", gap: 8 }}>
              <span style={{ width: 8, height: 8, borderRadius: "50%", background: z.same ? "#2D9A6A" : "#94A0AD", flexShrink: 0 }} />
              <div>
                <div style={{ fontFamily: "var(--font-mono)", fontSize: 13, fontWeight: 600, color: "var(--fg-1)" }}>{z.zip}</div>
                <div style={{ fontSize: 11, color: "var(--fg-3)" }}>{z.city}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ================= CTA BANNER =================
function CTABanner() {
  return (
    <section style={{ background: "var(--gs-charcoal-deep)", padding: "72px var(--gutter)", textAlign: "center" }}>
      <div style={{ maxWidth: 580, margin: "0 auto" }}>
        <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(26px,3.5vw,40px)", fontWeight: 400, color: "#fff", letterSpacing: "-0.02em", margin: "0 0 14px" }}>
          Ready to schedule your visit?
        </h2>
        <p style={{ fontSize: 15, color: "rgba(255,255,255,0.6)", margin: "0 0 32px" }}>
          Same-day slots Mon, Tue, Wed, Fri, Sat. Call or book online.
        </p>
        <div style={{ display: "flex", gap: 12, justifyContent: "center", flexWrap: "wrap" }}>
          <Button onClick={() => scrollTo("contact")} style={{ padding: "13px 28px", fontSize: 15, background: "var(--gs-blue)" }}>Book Online</Button>
          <a href="tel:+16692805858" style={{ display: "inline-flex", alignItems: "center", gap: 8, padding: "13px 28px", fontFamily: "var(--font-sans)", fontSize: 15, fontWeight: 500, color: "rgba(255,255,255,0.9)", textDecoration: "none", border: "1px solid rgba(255,255,255,0.2)", borderRadius: 8 }}>
            <Icon name="phone" size={15} style={{ color: "var(--gs-blue)" }} />Call Now
          </a>
        </div>
      </div>
    </section>
  );
}

// ================= CONTACT =================
function ContactSection() {
  const [form, setForm] = useState({ name: "", phone: "", zip: "", service: "", message: "" });
  const [sent, setSent] = useState(false);
  const [sending, setSending] = useState(false);
  const [err, setErr] = useState("");

  const handle = e => setForm(prev => ({ ...prev, [e.target.name]: e.target.value }));

  const submit = async (ev) => {
    ev.preventDefault();
    if (!form.phone) { setErr("Phone is required."); return; }
    setSending(true); setErr("");
    try {
      const resp = await fetch("/api/contact", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ ...form, source: "website" }),
      });
      if (resp.ok) { setSent(true); }
      else { setErr("Could not send. Please call us directly."); }
    } catch { setErr("Network error. Please call (669)\u00a0280-5858."); }
    finally { setSending(false); }
  };

  const inp = { width: "100%", padding: "11px 14px", fontFamily: "var(--font-sans)", fontSize: 14, color: "var(--fg-1)", background: "#fff", border: "1px solid var(--gs-hairline-strong)", borderRadius: 8, outline: "none", boxSizing: "border-box" };

  return (
    <section id="contact" style={{ padding: "96px var(--gutter)", background: "#fff" }}>
      <div style={{ maxWidth: "var(--container)", margin: "0 auto", display: "grid", gridTemplateColumns: "1fr 1fr", gap: 72, alignItems: "start" }}>
        <div>
          <Eyebrow style={{ marginBottom: 14 }}>Contact</Eyebrow>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(26px,3vw,38px)", fontWeight: 400, color: "var(--fg-1)", letterSpacing: "-0.02em", margin: "0 0 32px" }}>
            Book a visit
          </h2>
          {sent ? (
            <div style={{ background: "#E8F5EF", border: "1px solid #9ECFB4", borderRadius: 12, padding: "24px", color: "#1A7A52", fontSize: 15, lineHeight: 1.6 }}>
              ✅ Request received! We’ll confirm your slot within 2 hours.
            </div>
          ) : (
            <form onSubmit={submit} style={{ display: "flex", flexDirection: "column", gap: 16 }}>
              <input name="name" placeholder="Your name" value={form.name} onChange={handle} style={inp} />
              <input name="phone" placeholder="Phone (required)" value={form.phone} onChange={handle} required style={inp} />
              <input name="zip" placeholder="ZIP code" value={form.zip} onChange={handle} style={inp} />
              <select name="service" value={form.service} onChange={handle} style={inp}>
                <option value="">Select a service...</option>
                {(window.GS_SERVICES || []).map(s => [
                  <optgroup key={s.id} label={s.title + " — from $" + s.price + "/90 min"}>
                    {(s.subs || []).map((sub, i) => (
                      <option key={i} value={sub}>{sub}</option>
                    ))}
                  </optgroup>
                ])}
              </select>
              <textarea name="message" placeholder="Describe the job (optional)" value={form.message} onChange={handle} rows={4} style={{ ...inp, resize: "vertical" }} />
              {err && <div style={{ color: "#8F2E26", fontSize: 13 }}>{err}</div>}
              <Button type="submit" style={{ padding: "13px 24px", alignSelf: "flex-start" }} disabled={sending}>
                {sending ? "Sending…" : "Send Request"}
              </Button>
              <p style={{ fontSize: 11, color: "var(--fg-3)", margin: "4px 0 0", lineHeight: 1.5 }}>
                By submitting you agree to be contacted by phone or AI voice assistant about your request.
                Consent is not a condition of purchase. Msg &amp; data rates may apply.
              </p>
            </form>
          )}
        </div>
        <div style={{ paddingTop: 60 }}>
          {[
            { icon: "phone", label: "Phone",     val: "(669) 280-5858",             href: "tel:+16692805858" },
            { icon: "mail",  label: "Email",     val: "leads@nextunitpro.com",      href: "mailto:leads@nextunitpro.com" },
            { icon: "clock", label: "Hours",     val: "Mon–Wed, Fri–Sat · 8 AM–8 PM · Closed Thu & Sun" },
          ].map((item, i) => (
            <div key={i} style={{ display: "flex", gap: 16, marginBottom: 28, alignItems: "flex-start" }}>
              <div style={{ width: 38, height: 38, borderRadius: 9, background: "var(--gs-paper-warm)", border: "1px solid var(--gs-hairline)", display: "flex", alignItems: "center", justifyContent: "center", flexShrink: 0 }}>
                <Icon name={item.icon} size={16} style={{ color: "var(--gs-blue)" }} />
              </div>
              <div>
                <div style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.12em", color: "var(--fg-3)", marginBottom: 4 }}>{item.label}</div>
                {item.href
                  ? <a href={item.href} style={{ fontFamily: "var(--font-mono)", fontSize: 14, color: "var(--fg-1)", textDecoration: "none" }}>{item.val}</a>
                  : <div style={{ fontFamily: "var(--font-mono)", fontSize: 14, color: "var(--fg-1)" }}>{item.val}</div>
                }
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ================= MOBILE STICKY =================
function MobileSticky() {
  return (
    <div className="gs-mobile-sticky" style={{ position: "fixed", bottom: 0, left: 0, right: 0, zIndex: 100, padding: "12px 16px 16px", background: "#fff", borderTop: "1px solid var(--gs-hairline)", boxShadow: "0 -4px 20px rgba(0,0,0,.08)", gap: 10, display: "none" }}>
      <Button onClick={() => scrollTo("contact")} style={{ flex: 1, justifyContent: "center", padding: "13px" }}>Book a Visit</Button>
      <a href="tel:+16692805858" style={{ flex: 1, display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 6, padding: "13px", fontFamily: "var(--font-sans)", fontSize: 14, fontWeight: 500, color: "var(--fg-1)", textDecoration: "none", border: "1px solid var(--gs-hairline-strong)", borderRadius: 8 }}>
        <Icon name="phone" size={14} />(669) 280-5858
      </a>
    </div>
  );
}
