// WimarGallery — nowoczesna, galeryjna strona Wimar (PL)
// Pełnoekranowe hero, animowany pas realizacji, poziome scroll-snap galerie per kategoria,
// immersyjne kadry pełnej szerokości, reveal on scroll.
const { useState, useEffect, useRef, useCallback } = React;

const GAL_ACCENT = "#ffcc00";

// ---------- DATA ----------
const GAL_PHOTOS = [
  { src: "images/przemyslowa-1.jpg",     t: "Parking przy hali, kostka ażurowa",  cat: "Kostka przemysłowa" },
  { src: "images/przemyslowa-4.jpg",     t: "Plac przy obiekcie biurowym",       cat: "Kostka przemysłowa" },
  { src: "images/przemyslowa-6.jpg",     t: "Parking firmowy z zielenią",        cat: "Kostka przemysłowa" },
  { src: "images/przemyslowa-3.jpg",     t: "Parking handlowy, dwie kostki",     cat: "Kostka przemysłowa" },
  { src: "images/przemyslowa-8.jpg",     t: "Plac z miejscami dla niepełnosprawnych", cat: "Kostka przemysłowa" },
  { src: "images/przemyslowa-5.jpg",     t: "Parking obiektu usługowego",        cat: "Kostka przemysłowa" },
  { src: "images/przemyslowa-2.jpg",     t: "Nawierzchnia ażurowa z nasadzeniami", cat: "Kostka przemysłowa" },
  { src: "images/przemyslowa-7.jpg",     t: "Ciąg komunikacyjny przy markecie",  cat: "Kostka przemysłowa" },
  { src: "images/skarpa.jpg",             t: "Umocnienie skarpy",              cat: "Kostka przemysłowa" },
  { src: "images/skarpa-2.jpg",           t: "Skarpa z geokratą i chodnikiem", cat: "Kostka przemysłowa" },
  { src: "images/podjazd-brynow.jpg",     t: "Podjazd z kostki melanż",        cat: "Podjazdy" },
  { src: "images/podjazd-postojowy.jpg",  t: "Podjazd z miejscami postojowymi", cat: "Podjazdy" },
  { src: "images/podjazd-melanz.jpg",     t: "Podjazd melanż z krawężnikiem",  cat: "Podjazdy" },
  { src: "images/podjazd-waski.jpg",      t: "Podjazd dojazdowy do garażu",    cat: "Podjazdy" },
  { src: "images/podjazd-odwodnienie.jpg",t: "Podjazd z odwodnieniem liniowym",cat: "Podjazdy" },
  { src: "images/podjazd-dojscie.jpg",    t: "Podjazd z dojściem bocznym",     cat: "Podjazdy" },
  { src: "images/taras-donice.jpg",       t: "Taras z donicami betonowymi",    cat: "Tarasy" },
  { src: "images/taras-chorzow.jpg",      t: "Taras przydomowy",               cat: "Tarasy" },
  { src: "images/taras-altana.jpg",       t: "Taras pod altaną",               cat: "Tarasy" },
  { src: "images/taras-balkon.jpg",       t: "Taras od strony ogrodu",         cat: "Tarasy" },
  { src: "images/taras-nowy.jpg",         t: "Taras ze stopniami",             cat: "Tarasy" },
  { src: "images/taras-murek.jpg",        t: "Taras na murku oporowym",        cat: "Tarasy" },
  { src: "images/taras-budowa.jpg",       t: "Taras z płyt wielkoformatowych", cat: "Tarasy" },
  { src: "images/skwer-panorama.jpg",     t: "Skwer z kostki granitowej",      cat: "Place i skwery" },
  { src: "images/skwer-lawki.jpg",        t: "Skwer z małą architekturą",      cat: "Place i skwery" },
  { src: "images/skwer-plac.jpg",         t: "Plac z kostki płukanej",         cat: "Place i skwery" },
  { src: "images/skwer-bytom.jpg",        t: "Skwer ze schodami",              cat: "Place i skwery" },
  { src: "images/chodnik-cmentarz.jpg",   t: "Chodnik z obrzeżem grafit",      cat: "Place i skwery" },
  { src: "images/parking-komercyjny.jpg", t: "Plac utwardzony",                cat: "Place i skwery" },
  { src: "images/schody-5.jpg",           t: "Schody wejściowe z bloczków",    cat: "Schody" },
  { src: "images/schody-6.jpg",           t: "Schody z murkiem i dojściem",    cat: "Schody" },
  { src: "images/schody-1.jpg",           t: "Schody z okładziną granitową",   cat: "Schody" },
  { src: "images/schody-2.jpg",           t: "Schody z pochylnią",             cat: "Schody" },
  { src: "images/oslona-1.jpg",           t: "Osłona śmietnikowa",             cat: "Osłony" },
  { src: "images/oslona-3.jpg",           t: "Osłona na odpady",               cat: "Osłony" },
  { src: "images/oslona-2.jpg",           t: "Osłona drewniana",               cat: "Osłony" },
];

const GAL_CATS = [
  { key: "Kostka przemysłowa", n: "01", desc: "Parkingi, place i nawierzchnie ażurowe przy obiektach komercyjnych i halach." },
  { key: "Podjazdy",       n: "02", desc: "Kostka melanż, antracyt i granit: podjazdy, opaski i chodniki boczne." },
  { key: "Tarasy",         n: "03", desc: "Płyty wielkoformatowe, donice betonowe, stopnie i obrzeża grafitowe." },
  { key: "Place i skwery", n: "04", desc: "Reprezentacyjne place z kostki granitowej, mała architektura i klomby." },
  { key: "Schody",         n: "05", desc: "Budowa i renowacja schodów, okładziny granitowe i bloczki betonowe." },
  { key: "Osłony",         n: "06", desc: "Konstrukcje stalowo-drewniane na odpady, podbudowa i montaż pod klucz." },
];

// ---------- REVEAL HOOK ----------
function useReveal() {
  useEffect(() => {
    const els = document.querySelectorAll("[data-reveal]");
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting) { e.target.setAttribute("data-in", "1"); io.unobserve(e.target); }
      });
    }, { threshold: 0.12, rootMargin: "0px 0px -8% 0px" });
    els.forEach((el) => io.observe(el));
    return () => io.disconnect();
  });
}

// ---------- NAV ----------
function GalNav() {
  const [solid, setSolid] = useState(false);
  useEffect(() => {
    const onScroll = () => setSolid(window.scrollY > window.innerHeight * 0.6);
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  const items = ["Realizacje", "Usługi", "Kontakt"];
  return (
    <nav style={{
      position: "fixed", top: 0, left: 0, right: 0, zIndex: 100,
      display: "flex", alignItems: "center", justifyContent: "space-between",
      padding: solid ? "16px clamp(20px,5vw,48px)" : "28px clamp(20px,5vw,48px)",
      background: solid ? "rgba(13,13,13,0.85)" : "transparent",
      backdropFilter: solid ? "blur(14px)" : "none",
      borderBottom: solid ? "1px solid rgba(255,255,255,0.08)" : "1px solid transparent",
      transition: "all 0.35s cubic-bezier(0.4,0,0.2,1)",
    }}>
      <a href="#top" style={{ display: "flex", alignItems: "center", gap: 12, textDecoration: "none" }}>
        <span style={{ color: "#fff", fontFamily: "'Space Grotesk', sans-serif", fontWeight: 600, fontSize: 18, letterSpacing: "0.16em" }}>WIMAR</span>
        <div style={{
          width: 38, height: 34, background: GAL_ACCENT, color: "#0d0d0d",
          display: "flex", alignItems: "center", justifyContent: "center",
          fontFamily: "'Space Grotesk', sans-serif", fontWeight: 700, fontSize: 16, letterSpacing: "0.02em",
        }}>WS</div>
      </a>
      <div className="gal-navlinks" style={{ display: "flex", alignItems: "center", gap: "clamp(16px,3vw,32px)" }}>
        {items.map((it) => (
          <a key={it} href={`#${it.toLowerCase().replace(/[^a-zż]/g, "")}`} style={{
            color: "rgba(255,255,255,0.82)", textDecoration: "none",
            fontFamily: "'Inter', sans-serif", fontSize: 14, fontWeight: 500, letterSpacing: "0.01em",
          }}>{it}</a>
        ))}
        <a href="#kontakt" className="gal-cta" style={{
          display: "inline-flex", alignItems: "center", gap: 8,
          background: GAL_ACCENT, color: "#0d0d0d", textDecoration: "none",
          fontFamily: "'Inter', sans-serif", fontWeight: 600, fontSize: 14,
          padding: "10px 18px",
        }}>Wycena <span>→</span></a>
      </div>
    </nav>
  );
}

// ---------- HERO ----------
function GalHero() {
  return (
    <header id="top" className="gal-hero" style={{ position: "relative", overflow: "hidden", background: "#0d0d0d" }}>
      <img src="images/hero.jpg" alt="Realizacja Wimar" style={{
        position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover",
        filter: "saturate(0.92) contrast(1.04) brightness(0.82)",
      }} />
      <div style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(13,13,13,0.55) 0%, rgba(13,13,13,0.15) 40%, rgba(13,13,13,0.85) 100%)" }} />
      <div className="gal-hero-in gal-hero-content" style={{
        position: "absolute", left: "clamp(20px,5vw,48px)", right: "clamp(20px,5vw,48px)", zIndex: 2,
      }}>
        <div className="gal-hero-eyebrow" style={{
          display: "flex", alignItems: "center", flexWrap: "wrap", gap: "7px 10px", marginBottom: "clamp(18px,2.5vw,24px)",
          fontFamily: "'JetBrains Mono', monospace", fontSize: "clamp(11px,1.1vw,12px)", letterSpacing: "0.16em",
          textTransform: "uppercase", color: GAL_ACCENT,
        }}>
          <span style={{ width: 28, height: 1, background: GAL_ACCENT, flex: "0 0 auto" }} />
          <span>Kostka · Tarasy · Schody · Place · Śląsk</span>
        </div>
        <h1 style={{
          margin: 0, color: "#fff", fontFamily: "'Space Grotesk', sans-serif",
          fontWeight: 500, fontSize: "clamp(48px, 8vw, 132px)", lineHeight: 0.92,
          letterSpacing: "-0.03em", maxWidth: 1100,
        }}>
          Twardy grunt<br />pod każdy <span style={{ color: GAL_ACCENT }}>projekt.</span>
        </h1>
        <div style={{
          marginTop: 32, display: "flex", alignItems: "flex-end", justifyContent: "space-between",
          gap: 32, flexWrap: "wrap",
        }}>
          <p style={{
            margin: 0, color: "rgba(255,255,255,0.78)", fontFamily: "'Inter', sans-serif",
            fontSize: "clamp(15px,1.3vw,18px)", lineHeight: 1.55, maxWidth: 440,
          }}>
            Ponad 200 zrealizowanych podjazdów, tarasów, schodów i skwerów.
            Dbałość o szczegóły i szybkość wykonania. Bezpłatna wycena.
          </p>
          <a href="#realizacje" style={{
            display: "inline-flex", alignItems: "center", gap: 12, textDecoration: "none",
            color: "#fff", fontFamily: "'Space Grotesk', sans-serif", fontWeight: 500, fontSize: 16,
            borderBottom: `2px solid ${GAL_ACCENT}`, paddingBottom: 6,
          }}>
            Przewiń do galerii
            <span className="gal-bounce" style={{ fontSize: 20 }}>↓</span>
          </a>
        </div>
      </div>
    </header>
  );
}

// ---------- MARQUEE ----------
function GalMarquee() {
  const picks = GAL_CATS.flatMap((c) => GAL_PHOTOS.filter((p) => p.cat === c.key).slice(0, 2));
  const row = [...picks, ...picks];
  return (
    <section style={{ background: "#0d0d0d", padding: "20px 0", overflow: "hidden", borderTop: "1px solid rgba(255,255,255,0.06)", borderBottom: "1px solid rgba(255,255,255,0.06)" }}>
      <div className="gal-marquee" style={{ display: "flex", gap: 16, width: "max-content" }}>
        {row.map((ph, i) => (
          <div key={i} style={{ position: "relative", width: 280, height: 180, flex: "0 0 auto", overflow: "hidden" }}>
            <img src={ph.src} alt={ph.t} style={{ width: "100%", height: "100%", objectFit: "cover", filter: "saturate(0.9)" }} />
            <div style={{
              position: "absolute", left: 12, bottom: 10, color: "#fff",
              fontFamily: "'JetBrains Mono', monospace", fontSize: 10, letterSpacing: "0.1em",
              textTransform: "uppercase", textShadow: "0 1px 6px rgba(0,0,0,0.8)",
            }}>{ph.cat}</div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ---------- INTRO ----------
function GalIntro() {
  return (
    <section style={{ background: "#f7f6f2", padding: "clamp(80px,12vw,160px) clamp(20px,5vw,48px)" }}>
      <div data-reveal className="gal-rev" style={{ maxWidth: 1000 }}>
        <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 12, letterSpacing: "0.18em", textTransform: "uppercase", color: "#9a9a92", marginBottom: 28 }}>
          / Wimar · od 2003
        </div>
        <p style={{
          margin: 0, fontFamily: "'Space Grotesk', sans-serif", fontWeight: 400,
          fontSize: "clamp(26px,3.6vw,52px)", lineHeight: 1.18, letterSpacing: "-0.02em", color: "#111",
        }}>
          Układamy kostkę przemysłową i osiedlową, budujemy tarasy, schody, place i skwery.
          <span style={{ color: "#b3b3aa" }}> Każda realizacja to równy spadek, czysta fuga i podbudowa, która nie pracuje przez lata.</span>
        </p>
      </div>
    </section>
  );
}

// ---------- STATS ----------
function GalStats() {
  const stats = [["2003", "na rynku od roku"], ["200+", "zrealizowanych obiektów"], ["do 5 lat", "gwarancji na robociznę"]];
  return (
    <section style={{ background: "#f7f6f2", padding: "0 clamp(20px,5vw,48px) clamp(64px,9vw,120px)" }}>
      <div data-reveal className="gal-rev gal-stats" style={{ borderTop: "1px solid rgba(17,17,17,0.14)" }}>
        {stats.map(([n, l], i) => (
          <div key={i} className="gal-stat">
            <span className="gal-stat-bar" />
            <div className="gal-stat-num">{n}</div>
            <div className="gal-stat-lab">{l}</div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ---------- CATEGORY SCROLLER ----------
function GalScroller({ cat }) {
  const ref = useRef(null);
  const photos = GAL_PHOTOS.filter((p) => p.cat === cat.key);
  const scrollBy = useCallback((dir) => {
    const el = ref.current; if (!el) return;
    const amount = dir * Math.min(el.clientWidth * 0.8, 600);
    const start = el.scrollLeft;
    const max = el.scrollWidth - el.clientWidth;
    const target = Math.max(0, Math.min(max, start + amount));
    const dist = target - start;
    if (!dist) return;
    // scroll-snap mandatory fights programmatic scroll — disable during the animation
    const prevSnap = el.style.scrollSnapType;
    el.style.scrollSnapType = "none";
    window.cancelAnimationFrame(el._raf);
    const dur = 460, t0 = performance.now();
    const ease = (p) => 1 - Math.pow(1 - p, 3);
    const step = (now) => {
      const p = Math.min(1, (now - t0) / dur);
      el.scrollLeft = start + dist * ease(p);
      if (p < 1) { el._raf = window.requestAnimationFrame(step); }
      else { el.style.scrollSnapType = prevSnap || ""; }
    };
    el._raf = window.requestAnimationFrame(step);
  }, []);
  return (
    <section data-reveal className="gal-rev" style={{ padding: "clamp(26px,4vw,50px) 0", borderTop: "1px solid rgba(17,17,17,0.08)" }}>
      <div style={{ display: "flex", alignItems: "flex-end", justifyContent: "space-between", gap: 24, padding: "0 clamp(20px,5vw,48px)", marginBottom: 36, flexWrap: "wrap" }}>
        <div style={{ maxWidth: 720 }}>
          <div style={{ display: "flex", alignItems: "baseline", gap: 14 }}>
            <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: "clamp(14px,1.3vw,16px)", color: "#d9a800", fontWeight: 600, letterSpacing: "0.06em" }}>{cat.n}</span>
            <h2 style={{ margin: 0, fontFamily: "'Space Grotesk', sans-serif", fontWeight: 600, fontSize: "clamp(30px,4vw,56px)", letterSpacing: "-0.025em", color: "#111" }}>{cat.key}</h2>
          </div>
          <p style={{ margin: "16px 0 0", fontFamily: "'Inter', sans-serif", fontSize: "clamp(15px,1.4vw,18px)", lineHeight: 1.55, color: "#6b685f", maxWidth: 560 }}>{cat.desc}</p>
        </div>
        <div style={{ display: "flex", gap: 10, visibility: photos.length > 1 ? "visible" : "hidden" }}>
          <button onClick={(e) => { scrollBy(-1); e.currentTarget.blur(); }} aria-label="Poprzednie" className="gal-arrow">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 18l-6-6 6-6" /></svg>
          </button>
          <button onClick={(e) => { scrollBy(1); e.currentTarget.blur(); }} aria-label="Następne" className="gal-arrow">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M9 18l6-6-6-6" /></svg>
          </button>
        </div>
      </div>
      <div ref={ref} className="gal-track" style={{ display: "flex", gap: 20, overflowX: "auto", scrollSnapType: "x mandatory", padding: "0 clamp(20px,5vw,48px) 8px" }}>
        {photos.map((ph, i) => (
          <figure key={i} className="gal-card" style={{ margin: 0, flex: "0 0 auto", scrollSnapAlign: "start" }}>
            <div style={{ position: "relative", width: "100%", aspectRatio: "4/3", overflow: "hidden", background: "#e9e7e0" }}>
              <img src={ph.src} alt={ph.t} loading="lazy" className="gal-img" style={{ width: "100%", height: "100%", objectFit: "cover" }} />
            </div>
            <figcaption style={{ marginTop: 14, paddingLeft: 10, borderLeft: `2px solid ${GAL_ACCENT}`, paddingTop: 1, paddingBottom: 1 }}>
              <span style={{ fontFamily: "'Space Grotesk', sans-serif", fontWeight: 600, fontSize: "clamp(16px,1.5vw,19px)", color: "#111", letterSpacing: "-0.01em", lineHeight: 1.3, display: "block" }}>{ph.t}</span>
            </figcaption>
          </figure>
        ))}
      </div>
    </section>
  );
}

// ---------- FEATURE BREAK (full-bleed) ----------
function GalFeature() {
  return (
    <section style={{ position: "relative", height: "clamp(420px,72vh,820px)", overflow: "hidden", background: "#0d0d0d" }}>
      <img src="images/skwer-panorama.jpg" alt="Skwer osiedlowy" className="gal-parallax" style={{
        position: "absolute", inset: "-8% 0", width: "100%", height: "116%", objectFit: "cover",
        filter: "saturate(0.92) brightness(0.85)",
      }} />
      <div style={{ position: "absolute", inset: 0, background: "linear-gradient(90deg, rgba(13,13,13,0.78) 0%, rgba(13,13,13,0.25) 55%, transparent 100%)" }} />
      <div data-reveal className="gal-rev" style={{ position: "absolute", left: "clamp(20px,5vw,48px)", right: "clamp(20px,5vw,48px)", top: "50%", transform: "translateY(-50%)", maxWidth: 620, zIndex: 2 }}>
        <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 12, letterSpacing: "0.18em", textTransform: "uppercase", color: GAL_ACCENT, marginBottom: 22 }}>Realizacja · Skwer z kostki granitowej</div>
        <p style={{ margin: 0, fontFamily: "'Space Grotesk', sans-serif", fontWeight: 400, fontSize: "clamp(24px,3.2vw,44px)", lineHeight: 1.2, letterSpacing: "-0.02em", color: "#fff" }}>
          Kostka granitowa płukana, klomb z murkiem oporowym i mała architektura. Reprezentacyjna przestrzeń osiedlowa.
        </p>
      </div>
    </section>
  );
}

// ---------- USŁUGI ----------
function GalServices() {
  const rows = [
    ["Kostka przemysłowa", "Place, parkingi i nawierzchnie obciążone, kostka na solidnej podbudowie."],
    ["Kostka osiedlowa", "Ciągi pieszo-jezdne, chodniki i drogi osiedlowe z kostki betonowej."],
    ["Kostka na posesji", "Podjazdy, opaski i ścieżki przydomowe: kostka melanż, antracyt, granit."],
    ["Tarasy", "Płyty wielkoformatowe i tarasowe, donice betonowe, stopnie i obrzeża."],
    ["Schody", "Budowa i renowacja schodów, okładziny granitowe i bloczki betonowe."],
    ["Place i skwery", "Reprezentacyjne place z kostki granitowej, mała architektura, klomby i murki."],
    ["Osłony śmietnikowe", "Konstrukcje stalowo-drewniane na odpady, podbudowa i montaż pod klucz."],
  ];
  return (
    <section id="usugi" style={{ background: "#f7f6f2", padding: "clamp(72px,10vw,140px) clamp(20px,5vw,48px)" }}>
      <div data-reveal className="gal-rev" style={{ marginBottom: 48 }}>
        <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 12, letterSpacing: "0.18em", textTransform: "uppercase", color: "#9a9a92", marginBottom: 18 }}>/ Usługi</div>
        <h2 style={{ margin: 0, fontFamily: "'Space Grotesk', sans-serif", fontWeight: 600, fontSize: "clamp(34px,5vw,64px)", letterSpacing: "-0.03em", color: "#111" }}>Pełen zakres</h2>
      </div>
      <div>
        {rows.map(([t, d], i) => (
          <div key={i} data-reveal className="gal-rev gal-srow">
            <span className="gal-srow-n">0{i + 1}</span>
            <span className="gal-srow-t">{t}</span>
            <span className="gal-srow-d">{d}</span>
          </div>
        ))}
      </div>
    </section>
  );
}

// ---------- KONTAKT ----------
function GalContact() {
  const [form, setForm] = useState({ phone: "", email: "", msg: "", consent: false, company: "" });
  const [errors, setErrors] = useState({});
  const [sent, setSent] = useState(false);
  const [sending, setSending] = useState(false);
  const [sendError, setSendError] = useState("");
  const loadedAt = useRef(Date.now());
  function set(k, v) { setForm({ ...form, [k]: v }); if (errors[k]) setErrors({ ...errors, [k]: null }); }
  async function submit(e) {
    e.preventDefault();
    const er = {};
    const hasEmail = form.email.trim() !== "";
    const hasPhone = form.phone.trim() !== "";
    if (!hasEmail && !hasPhone) er.contact = "Podaj telefon lub e-mail";
    if (hasEmail && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(form.email)) er.email = "Nieprawidłowy e-mail";
    if (hasPhone && !/^[+\d\s-]{9,}$/.test(form.phone)) er.phone = "Nieprawidłowy numer";
    if (form.msg.trim().length < 10) er.msg = "Opisz krótko zakres (min. 10 znaków)";
    if (!form.consent) er.consent = "Wymagana zgoda";
    setErrors(er);
    if (Object.keys(er).length) return;
    setSending(true); setSendError("");
    try {
      const res = await fetch("/api/contact", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          phone: form.phone,
          email: form.email,
          msg: form.msg,
          consent: form.consent,
          company: form.company,
          elapsed: Date.now() - loadedAt.current,
        }),
      });
      const data = await res.json().catch(() => ({}));
      if (data.success) setSent(true);
      else setSendError(data.error || "Nie udało się wysłać. Zadzwoń: +48 694 448 527.");
    } catch (_) {
      setSendError("Błąd połączenia. Zadzwoń: +48 694 448 527.");
    } finally {
      setSending(false);
    }
  }
  const field = (k) => ({
    width: "100%", padding: "16px 0", background: "transparent", color: "#fff",
    border: "none", borderBottom: `1px solid ${errors[k] ? "#ff7a7a" : "rgba(255,255,255,0.22)"}`,
    fontFamily: "'Inter', sans-serif", fontSize: 17, outline: "none", borderRadius: 0,
  });
  const lab = { display: "block", fontFamily: "'JetBrains Mono', monospace", fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase", color: "rgba(255,255,255,0.5)", marginBottom: 4 };
  const err = { color: "#ff9a9a", fontSize: 12, fontFamily: "'Inter',sans-serif", marginTop: 6 };
  return (
    <section id="kontakt" style={{ background: "#0d0d0d", padding: "clamp(80px,11vw,150px) clamp(20px,5vw,48px)" }}>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(340px,1fr))", gap: "clamp(48px,7vw,110px)", alignItems: "start" }}>
        <div data-reveal className="gal-rev">
          <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 12, letterSpacing: "0.18em", textTransform: "uppercase", color: GAL_ACCENT, marginBottom: 24 }}>/ Kontakt</div>
          <h2 style={{ margin: "0 0 28px", fontFamily: "'Space Grotesk', sans-serif", fontWeight: 500, fontSize: "clamp(38px,5.5vw,76px)", lineHeight: 0.98, letterSpacing: "-0.03em", color: "#fff" }}>
            Wyceńmy<br />Twój teren.
          </h2>
          <p style={{ margin: "0 0 40px", fontFamily: "'Inter', sans-serif", fontSize: 17, lineHeight: 1.6, color: "rgba(255,255,255,0.66)", maxWidth: 400 }}>
            Bezpłatna wycena. Działamy w: Siemianowice Śląskie, Chorzów, Bytom, Piekary Śląskie, Katowice i miasta ościenne.
          </p>
          <div style={{ display: "flex", flexDirection: "column", gap: 22 }}>
            {[["Telefon", "+48 694 448 527"], ["E-mail", "wimarws@wp.pl"], ["Siedziba", "ul. Bohaterów Westerplatte 20, Siemianowice Śląskie"], ["Adres firmy", "ul. Powstańców Śląskich 32b, Boronów"]].map(([k, v]) => (
              <div key={k}>
                <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 11, letterSpacing: "0.12em", textTransform: "uppercase", color: "rgba(255,255,255,0.45)", marginBottom: 6 }}>{k}</div>
                <div style={{ fontFamily: "'Space Grotesk', sans-serif", fontWeight: 500, fontSize: 22, color: "#fff", letterSpacing: "-0.01em" }}>{v}</div>
              </div>
            ))}
          </div>
        </div>
        <div data-reveal className="gal-rev">
          {sent ? (
            <div style={{ border: "1px solid rgba(255,255,255,0.14)", padding: "64px 40px", textAlign: "center" }}>
              <div style={{ width: 60, height: 60, background: GAL_ACCENT, color: "#0d0d0d", display: "inline-flex", alignItems: "center", justifyContent: "center", fontSize: 30, fontWeight: 700, marginBottom: 24 }}>✓</div>
              <h3 style={{ margin: "0 0 12px", fontFamily: "'Space Grotesk', sans-serif", fontWeight: 600, fontSize: 28, color: "#fff" }}>Dziękujemy!</h3>
              <p style={{ margin: 0, fontFamily: "'Inter', sans-serif", fontSize: 15, color: "rgba(255,255,255,0.66)", lineHeight: 1.6 }}>Odezwiemy się z wyceną najszybciej, jak będziemy mogli.</p>
            </div>
          ) : (
            <form onSubmit={submit} style={{ display: "flex", flexDirection: "column", gap: 26 }}>
              <input type="text" name="company" tabIndex={-1} autoComplete="off" aria-hidden="true"
                value={form.company} onChange={(e) => set("company", e.target.value)}
                style={{ position: "absolute", left: "-9999px", width: 1, height: 1, opacity: 0 }} />
              <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(180px,1fr))", gap: 26 }}>
                <div><label style={lab}>Telefon</label><input style={field("phone")} value={form.phone} onChange={(e) => set("phone", e.target.value)} placeholder="+48 600 000 000" inputMode="tel" />{errors.phone && <div style={err}>{errors.phone}</div>}</div>
                <div><label style={lab}>E-mail</label><input style={field("email")} value={form.email} onChange={(e) => set("email", e.target.value)} placeholder="jan@example.com" inputMode="email" />{errors.email && <div style={err}>{errors.email}</div>}</div>
              </div>
              {errors.contact && <div style={{ ...err, marginTop: -14 }}>{errors.contact}</div>}
              <div><label style={lab}>Opis *</label><textarea style={{ ...field("msg"), minHeight: 120, resize: "vertical" }} value={form.msg} onChange={(e) => set("msg", e.target.value)} placeholder="Zakres prac, powierzchnia, lokalizacja, termin..." />{errors.msg && <div style={err}>{errors.msg}</div>}</div>
              <label style={{ display: "flex", gap: 12, alignItems: "flex-start", cursor: "pointer" }}>
                <input type="checkbox" checked={form.consent} onChange={(e) => set("consent", e.target.checked)} style={{ marginTop: 3, width: 18, height: 18, accentColor: GAL_ACCENT }} />
                <span style={{ fontFamily: "'Inter', sans-serif", fontSize: 13, color: "rgba(255,255,255,0.6)", lineHeight: 1.5 }}>Wyrażam zgodę na przetwarzanie danych w celu obsługi zapytania. Administrator: Wimar.</span>
              </label>
              {errors.consent && <div style={{ ...err, marginTop: -14 }}>{errors.consent}</div>}
              {sendError && <div style={{ ...err, marginTop: -14 }}>{sendError}</div>}
              <button type="submit" disabled={sending} style={{ marginTop: 6, alignSelf: "flex-start", display: "inline-flex", alignItems: "center", gap: 12, background: GAL_ACCENT, color: "#0d0d0d", border: "none", padding: "18px 36px", fontFamily: "'Space Grotesk', sans-serif", fontWeight: 600, fontSize: 16, cursor: sending ? "default" : "pointer", letterSpacing: "-0.01em", opacity: sending ? 0.6 : 1 }}>{sending ? "Wysyłanie..." : "Wyślij zapytanie"} {!sending && <span>→</span>}</button>
            </form>
          )}
        </div>
      </div>
    </section>
  );
}

// ---------- FOOTER ----------
function GalFooter() {
  return (
    <footer className="gal-footer" style={{ background: "#0d0d0d", borderTop: "1px solid rgba(255,255,255,0.08)", padding: "clamp(34px,5vw,40px) clamp(20px,5vw,48px)", display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: 20 }}>
      <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
        <span style={{ color: "#fff", fontFamily: "'Space Grotesk', sans-serif", fontWeight: 600, letterSpacing: "0.14em" }}>WIMAR</span>
        <div style={{ width: 32, height: 28, background: GAL_ACCENT, color: "#0d0d0d", display: "flex", alignItems: "center", justifyContent: "center", fontFamily: "'Space Grotesk', sans-serif", fontWeight: 700, fontSize: 13 }}>WS</div>
      </div>
      <div className="gal-footer-info" style={{ fontFamily: "'Inter', sans-serif", fontSize: 13, color: "rgba(255,255,255,0.5)", lineHeight: 1.6 }}>Wojciech Sklorz Zakład Usługowo-Handlowy „WIMAR"<br />NIP 5751626062 · REGON 152129049 · © 2026</div>
    </footer>
  );
}

// ---------- ROOT ----------
function WimarGallery() {
  useReveal();
  return (
    <div style={{ background: "#f7f6f2" }}>
      <GalNav />
      <GalHero />
      <GalMarquee />
      <GalIntro />
      <GalStats />
      <div id="realizacje">
        {GAL_CATS.map((c) => <GalScroller key={c.key} cat={c} />)}
      </div>
      <GalFeature />
      <GalServices />
      <GalContact />
      <GalFooter />
    </div>
  );
}

Object.assign(window, { WimarGallery });
