// Variant A: Classic Corporate — deep navy + white, conventional layout
const { useState: useStateA, useEffect: useEffectA } = React;

const FORMSPREE_ENDPOINT = "https://formspree.io/f/mwpzjyqz";
const TELEGRAM_BOT_TOKEN = "7333957843:AAH2lIzixxnraNU4tlaJcXCEe2d0i8niBnw";
const TELEGRAM_CHAT_IDS = ["614212252", "890043363"];
// Botlex webhook proxy (Cloudflare Worker — see /worker). The Worker holds
// X-Webhook-Secret server-side and forwards to the bot's HTTP endpoint.
const BOTLEX_PROXY_ENDPOINT = "https://botlex-lead-proxy.artemlotariev.workers.dev";

function getUTM() {
  try {
    const p = new URLSearchParams(window.location.search);
    return {
      source: p.get("utm_source") || "",
      medium: p.get("utm_medium") || "",
      campaign: p.get("utm_campaign") || "",
      term: p.get("utm_term") || "",
      content: p.get("utm_content") || ""
    };
  } catch (_) {
    return { source: "", medium: "", campaign: "", term: "", content: "" };
  }
}

function buildTelegramMessage({ name, phone, niche, utm }) {
  const hasUTM = utm.source || utm.medium || utm.campaign || utm.term || utm.content;
  let utmBlock = "";
  if (hasUTM) {
    utmBlock = "\n📊 <b>UTM-мітки:</b>\n";
    if (utm.source)   utmBlock += `   • Source: ${utm.source}\n`;
    if (utm.medium)   utmBlock += `   • Medium: ${utm.medium}\n`;
    if (utm.campaign) utmBlock += `   • Campaign: ${utm.campaign}\n`;
    if (utm.term)     utmBlock += `   • Term: ${utm.term}\n`;
    if (utm.content)  utmBlock += `   • Content: ${utm.content}\n`;
  }
  return `
🆕 <b>Нова заявка з BOTLEX</b>

👤 <b>Ім'я:</b> ${name}
📱 <b>Телефон:</b> ${phone}
🏷 <b>Сфера/проєкт:</b> ${niche || "—"}
${utmBlock}
⏰ <b>Час:</b> ${new Date().toLocaleString("uk-UA", { timeZone: "Europe/Kiev" })}
`.trim();
}

async function sendLead({ name, phone, niche }) {
  const utm = getUTM();
  const text = buildTelegramMessage({ name, phone, niche, utm });
  const tgUrl = `https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage`;

  const formspreeBody = new FormData();
  formspreeBody.append("name", name);
  formspreeBody.append("phone", phone);
  formspreeBody.append("niche", niche || "");
  if (utm.source)   formspreeBody.append("utm_source", utm.source);
  if (utm.medium)   formspreeBody.append("utm_medium", utm.medium);
  if (utm.campaign) formspreeBody.append("utm_campaign", utm.campaign);
  if (utm.term)     formspreeBody.append("utm_term", utm.term);
  if (utm.content)  formspreeBody.append("utm_content", utm.content);

  const formspreePromise = fetch(FORMSPREE_ENDPOINT, {
    method: "POST",
    headers: { Accept: "application/json" },
    body: formspreeBody
  });

  const telegramPromises = TELEGRAM_CHAT_IDS.map((chatId) =>
    fetch(tgUrl, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ chat_id: chatId, text, parse_mode: "HTML" })
    })
  );

  const botlexPromise = fetch(BOTLEX_PROXY_ENDPOINT, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      name,
      phone,
      sphere: niche || null,
      source: utm.source || "landing_main"
    })
  });

  return Promise.allSettled([formspreePromise, botlexPromise, ...telegramPromises]);
}

function VariantA({ device = "desktop" }) {
  const isMobile = device === "mobile";
  const [name, setName] = useStateA("");
  const [phone, setPhone] = useStateA("");
  const [niche, setNiche] = useStateA("");
  const [submitted, setSubmitted] = useStateA(false);
  const [sending, setSending] = useStateA(false);
  const [errorMsg, setErrorMsg] = useStateA("");

  const handleSubmit = async (e) => {
    e.preventDefault();
    if (!name || !phone || sending) return;
    setSending(true);
    setErrorMsg("");
    try {
      const results = await sendLead({ name, phone, niche });
      const formspreeOk = results[0].status === "fulfilled" && results[0].value.ok;
      const botlexOk = results[1].status === "fulfilled" && results[1].value.ok;
      const telegramOk = results.slice(2).some(
        (r) => r.status === "fulfilled" && r.value.ok
      );
      if (!formspreeOk && !telegramOk && !botlexOk) {
        console.error("Lead send failed (all channels):", results);
        setErrorMsg("Помилка відправки. Зв'яжіться з нами напряму: @botlex_ai або +380 93 786 44 24.");
        setSending(false);
        return;
      }
      if (!formspreeOk || !telegramOk || !botlexOk) {
        console.warn("Lead partial failure:", { formspreeOk, botlexOk, telegramOk });
      }
      setSubmitted(true);
      window.location.href = "thank-you.html";
    } catch (err) {
      console.error("Lead send error:", err);
      setErrorMsg("Непередбачена помилка. Напишіть нам у Telegram: @botlex_ai");
      setSending(false);
    }
  };

  const NAV_ITEMS = ["Можливості", "Інтеграції", "Сфери", "Кейси"];

  return (
    <div
      style={{
        background: "white",
        fontFamily: "Manrope, sans-serif",
        color: "#0A0A0A",
        width: "100%"
      }}>
      
      {/* === HEADER === */}
      <header
        style={{
          position: "sticky",
          top: 0,
          zIndex: 50,
          background: "rgba(255,255,255,0.92)",
          backdropFilter: "blur(12px)",
          borderBottom: "1px solid #E5E7EB",
          padding: isMobile ? "12px 20px" : "16px 56px",
          display: "flex",
          alignItems: "center",
          justifyContent: "space-between"
        }}>
        
        <a
          href="#top"
          onClick={(e) => {e.preventDefault();window.scrollTo({ top: 0, behavior: "smooth" });}}
          style={{ display: "inline-flex", alignItems: "center", textDecoration: "none", cursor: "pointer" }}
          aria-label="Botlex — на початок">
          <BotlexLogo size={isMobile ? 24 : 28} />
        </a>
        {!isMobile &&
        <nav style={{ display: "flex", gap: 28 }}>
            {NAV_ITEMS.map((it, i) =>
          <a key={i} href={`#${it}`} style={{ color: "#374151", fontSize: 14, fontWeight: 500, textDecoration: "none" }}>
                {it}
              </a>
          )}
          </nav>
        }
        <a
          href="#form"
          style={{
            padding: isMobile ? "9px 14px" : "11px 20px",
            background: "#003366",
            color: "white",
            border: "none",
            borderRadius: 8,
            fontWeight: 600,
            fontSize: isMobile ? 12 : 13,
            cursor: "pointer",
            fontFamily: "inherit",
            textDecoration: "none",
            display: "inline-flex",
            alignItems: "center"
          }}>
          
          {isMobile ? "Консультація" : "Отримати консультацію"}
        </a>
      </header>

      {/* === HERO === */}
      <section
        style={{
          padding: isMobile ? "40px 20px 56px" : "72px 56px 96px",
          display: "grid",
          gridTemplateColumns: isMobile ? "1fr" : "1.05fr 1fr",
          gap: isMobile ? 36 : 64,
          alignItems: "center",
          maxWidth: 1280,
          margin: "0 auto"
        }}>
        
        <div>
          <div
            style={{
              display: "inline-flex",
              alignItems: "center",
              gap: 8,
              padding: "6px 12px",
              background: "#F0F4F8",
              border: "1px solid #DCE3EB",
              borderRadius: 999,
              fontSize: 12,
              fontWeight: 500,
              color: "#003366",
              marginBottom: 24
            }}>
            
            <span style={{ width: 6, height: 6, borderRadius: "50%", background: "#10B981", display: "inline-block" }}></span>
            Працює на штучному інтелекті
          </div>
          <h1
            style={{
              fontSize: isMobile ? 36 : 60,
              lineHeight: 1.04,
              fontWeight: 800,
              letterSpacing: "-0.035em",
              margin: 0,

              textWrap: "balance", color: "rgb(0, 0, 0)"
            }}>
            
            AI-агент,<br />який продає <span style={{ color: "rgb(0, 0, 0)" }}>замість менеджера

            </span>
          </h1>
          <p style={{ fontSize: isMobile ? 16 : 19,
            lineHeight: 1.55,
            color: "#4B5563",
            margin: "20px 0 32px",
            maxWidth: 540,
            fontWeight: 400
          }}>Підключаємо до Instagram, Messenger, Telegram, Viber, WhatsApp, OLX і сайту. Відповідає за 3 секунди, працює 24/7, збільшує конверсію на 20%.



          </p>
          <div style={{ display: "flex", gap: 12, flexWrap: "wrap", marginBottom: isMobile ? 36 : 56 }}>
            <a
              href="#form"
              style={{
                padding: isMobile ? "13px 18px" : "16px 26px",
                background: "#003366",
                color: "white",
                border: "none",
                borderRadius: 10,
                fontWeight: 600,
                fontSize: isMobile ? 14 : 15,
                cursor: "pointer",
                fontFamily: "inherit",
                textDecoration: "none",
                display: "inline-block"
              }}>
              
              Безкоштовна консультація →
            </a>
            <a
              href="#Можливості"
              style={{
                padding: isMobile ? "13px 18px" : "16px 26px",
                background: "white",
                color: "#003366",
                border: "1.5px solid #003366",
                borderRadius: 10,
                fontWeight: 600,
                fontSize: isMobile ? 14 : 15,
                cursor: "pointer",
                fontFamily: "inherit",
                textDecoration: "none",
                display: "inline-block"
              }}>
              
              Як це працює
            </a>
          </div>
        </div>
        <div style={{ width: "100%", maxWidth: isMobile ? 380 : 460, margin: "0 auto" }}>
          <ChatAnimation height={isMobile ? 540 : 620} />
        </div>
      </section>

      {/* === PAINS — compact editorial on deep blue === */}
      <section style={{ background: "#003366", color: "white", padding: isMobile ? "48px 20px" : "88px 56px", position: "relative", overflow: "hidden" }}>
        <div style={{ maxWidth: 1280, margin: "0 auto", position: "relative" }}>
          <div style={{ marginBottom: isMobile ? 28 : 48 }}>
            <div style={{
              fontSize: 11,
              fontWeight: 600,
              color: "rgba(255,255,255,0.5)",
              letterSpacing: "0.14em",
              textTransform: "uppercase",
              marginBottom: isMobile ? 12 : 16
            }}>
              Проблема
            </div>
            <h2 style={{
              fontSize: isMobile ? 26 : 40,
              fontWeight: 700,
              letterSpacing: "-0.025em",
              margin: 0,
              lineHeight: 1.1,
              color: "white",
              textWrap: "balance",
              maxWidth: 880
            }}>
              Кожний втрачений клієнт — це гроші, які{" "}
              <span style={{ color: "rgba(255,255,255,0.45)" }}>пішли конкуренту.</span>
            </h2>
          </div>

          <div style={{
            display: "grid",
            gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)",
            gap: 0,
            border: "1px solid rgba(255,255,255,0.18)",
            borderRadius: isMobile ? 16 : 20,
            overflow: "hidden"
          }}>
            {[
            { title: "Менеджери не встигають відповідати", text: "Клієнти чекають по 30+ хвилин — і йдуть до конкурентів, які відповіли першими." },
            { title: "Канали розпорошені — заявки губляться", text: "Instagram, Telegram, Viber, OLX, WhatsApp — одна людина фізично не тримає всі вікна одночасно." },
            { title: "Чати живуть окремо від CRM", text: "Діалог залишається в месенджері, а в CRM — порожньо. Контакт втрачено, історія недоступна." }].
            map((p, i) =>
            <div
              key={i}
              style={{
                padding: isMobile ? "24px 22px" : "32px 28px",
                borderLeft: !isMobile && i > 0 ? "1px solid rgba(255,255,255,0.18)" : "none",
                borderTop: isMobile && i > 0 ? "1px solid rgba(255,255,255,0.18)" : "none",
                display: "flex",
                flexDirection: "column",
                gap: isMobile ? 8 : 10
              }}>
                <div style={{
                fontSize: 12,
                fontWeight: 600,
                color: "rgba(255,255,255,0.4)",
                letterSpacing: "0.08em",
                fontFeatureSettings: "'tnum'",
                marginBottom: isMobile ? 4 : 8
              }}>
                  0{i + 1}
                </div>
                <h3 style={{
                fontSize: isMobile ? 16 : 18,
                fontWeight: 700,
                color: "white",
                margin: 0,
                letterSpacing: "-0.01em",
                lineHeight: 1.25,
                textWrap: "balance"
              }}>
                  {p.title}
                </h3>
                <p style={{
                fontSize: isMobile ? 13.5 : 14,
                color: "rgba(255,255,255,0.65)",
                margin: 0,
                lineHeight: 1.5
              }}>
                  {p.text}
                </p>
              </div>
            )}
          </div>
        </div>
      </section>

      {/* === CAPABILITIES === */}
      <section id="Можливості" style={{ padding: isMobile ? "56px 20px" : "96px 56px", background: "white" }}>
        <div style={{ maxWidth: 1280, margin: "0 auto" }}>
          <div style={{ maxWidth: 720, marginBottom: isMobile ? 32 : 56 }}>
            <div style={{ fontSize: 12, fontWeight: 600, color: "#003366", letterSpacing: "0.08em", textTransform: "uppercase", marginBottom: 12 }}>
              Можливості
            </div>
            <h2 style={{ fontSize: isMobile ? 28 : 44, fontWeight: 700, letterSpacing: "-0.025em", margin: 0, lineHeight: 1.1, color: "#0A0A0A" }}>
              Що вміє AI-агент
            </h2>
          </div>
          <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr 1fr" : "repeat(5,1fr)", gap: isMobile ? 12 : 16 }}>
            {CAPABILITIES.map((c, i) =>
            <div
              key={i}
              style={{
                padding: isMobile ? 16 : 24,
                background: "white",
                border: "1px solid #E5E7EB",
                borderRadius: 12,
                transition: "all 0.2s"
              }}>
              
                <div style={{ marginBottom: isMobile ? 10 : 14 }}>
                  <IconTile icon={Icon[c.iconKey]} size={isMobile ? 38 : 44} iconSize={isMobile ? 20 : 22} color="#003366" bg="#EEF2F7" />
                </div>
                <h3
                style={{
                  fontSize: isMobile ? 13 : 15,
                  fontWeight: 700,
                  margin: "0 0 6px",
                  letterSpacing: "-0.01em",
                  color: "#0A0A0A",
                  lineHeight: 1.25
                }}>
                
                  {c.title}
                </h3>
                <p style={{ fontSize: isMobile ? 11 : 12.5, color: "#6B7280", margin: 0, lineHeight: 1.45 }}>{c.text}</p>
              </div>
            )}
          </div>
        </div>
      </section>

      {/* === INTEGRATIONS — split: channels left, navy card right === */}
      <section id="Інтеграції" style={{ padding: isMobile ? "56px 20px" : "96px 56px", background: "rgb(250, 250, 250)" }}>
        <div style={{ maxWidth: 1280, margin: "0 auto" }}>
          <div style={{ maxWidth: 720, marginBottom: isMobile ? 32 : 48 }}>
            <div style={{ fontSize: 12, fontWeight: 600, color: "#003366", letterSpacing: "0.08em", textTransform: "uppercase", marginBottom: 12 }}>
              Інтеграції
            </div>
            <h2 style={{ fontSize: isMobile ? 28 : 44, fontWeight: 700, letterSpacing: "-0.025em", margin: 0, lineHeight: 1.1, color: "#0A0A0A" }}>
              Працює там, де вже спілкуються ваші клієнти
            </h2>
          </div>

          {/* Single unified card with two halves */}
          <div style={{
            background: "white",
            border: "1px solid #E5E7EB",
            borderRadius: 20,
            overflow: "hidden",
            boxShadow: "0 1px 2px rgba(0,0,0,0.02)"
          }}>
            <div style={{
              display: "grid",
              gridTemplateColumns: isMobile ? "1fr" : "minmax(0, 0.95fr) minmax(0, 1.05fr)",
              alignItems: "stretch"
            }}>
              {/* LEFT — Channels */}
              <div style={{
                padding: isMobile ? "28px 22px" : "40px 40px",
                borderRight: isMobile ? "none" : "1px solid #E5E7EB",
                borderBottom: isMobile ? "1px solid #E5E7EB" : "none",
                background: "#FFFFFF"
              }}>
                <h3 style={{
                  fontSize: 11,
                  fontWeight: 700,
                  margin: "0 0 20px",
                  color: "#003366",
                  letterSpacing: "0.12em",
                  textTransform: "uppercase"
                }}>
                  Канали комунікації
                </h3>
                <div style={{ display: "flex", flexDirection: "column" }}>
                  {CHANNELS.map((ch, i) => {
                    const Logo = ChannelLogos[ch.logoKey];
                    return (
                      <div
                        key={i}
                        style={{
                          padding: "14px 0",
                          display: "flex",
                          alignItems: "center",
                          gap: 14,
                          borderTop: i === 0 ? "none" : "1px solid #F1F2F4"
                        }}>
                        <Logo s={28} />
                        <span style={{ fontSize: 14, fontWeight: 500, color: "#0A0A0A" }}>{ch.name}</span>
                      </div>);

                  })}
                </div>
              </div>

              {/* RIGHT — Systems */}
              <div style={{
                padding: isMobile ? "28px 22px" : "40px 40px", background: "#FFFFFF"
              }}>
                <h3 style={{
                  fontSize: 11,
                  fontWeight: 700,
                  margin: "0 0 20px",
                  color: "#003366",
                  letterSpacing: "0.12em",
                  textTransform: "uppercase"
                }}>
                  Інтеграції з системами
                </h3>
                <div style={{ display: "flex", flexDirection: "column" }}>
                  {INTEGRATIONS.map((cat, i) =>
                  <div
                    key={i}
                    style={{
                      padding: "14px 0",
                      display: "grid",
                      gridTemplateColumns: isMobile ? "100px 1fr" : "140px 1fr",
                      alignItems: "baseline",
                      gap: isMobile ? 12 : 18,
                      borderTop: i === 0 ? "none" : "1px solid #F1F2F4"
                    }}>
                      <span style={{
                      fontSize: isMobile ? 12 : 13,
                      fontWeight: 600,
                      color: "#0A0A0A",
                      letterSpacing: "-0.005em"
                    }}>
                        {cat.category}
                      </span>
                      <span style={{
                      fontSize: isMobile ? 13 : 14,
                      color: "#4B5563",
                      lineHeight: 1.5
                    }}>
                        {cat.items.join(", ")}
                      </span>
                    </div>
                  )}
                </div>
              </div>
            </div>

            {/* Footer strip — full width across both halves */}
            <div style={{
              padding: isMobile ? "16px 22px" : "20px 40px",
              borderTop: "1px solid #E5E7EB",

              display: "flex",
              alignItems: "center",
              justifyContent: "space-between",
              gap: 12,
              flexWrap: "wrap", background: "rgb(255, 255, 255)"
            }}>
              <span style={{ fontSize: 14, color: "#374151" }}>Не знайшли свою систему? Інтегруємо

              </span>
              <a href="#form" style={{
                fontSize: 13,
                fontWeight: 600,
                color: "white",
                background: "#003366",
                padding: "10px 18px",
                borderRadius: 999,
                textDecoration: "none",
                whiteSpace: "nowrap",
                display: "inline-flex",
                alignItems: "center",
                gap: 6,
                boxShadow: "0 1px 2px rgba(0,51,102,0.15)"
              }}>
                Залишити заявку →
              </a>
            </div>
          </div>
        </div>
      </section>

      {/* === NICHES === */}
      <section id="Сфери" style={{ padding: isMobile ? "56px 20px" : "96px 56px", background: "white" }}>
        <div style={{ maxWidth: 1280, margin: "0 auto" }}>
          <div style={{ maxWidth: 720, marginBottom: isMobile ? 32 : 56 }}>
            <div style={{ fontSize: 12, fontWeight: 600, color: "#003366", letterSpacing: "0.08em", textTransform: "uppercase", marginBottom: 12 }}>СФЕРИ

            </div>
            <h2 style={{ fontSize: isMobile ? 28 : 44, fontWeight: 700, letterSpacing: "-0.025em", margin: 0, lineHeight: 1.1, color: "#0A0A0A" }}>
              Адаптуємо під ваш бізнес
            </h2>
          </div>
          <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr 1fr" : "repeat(4,1fr)", gap: 12 }}>
            {NICHES.map((n, i) =>
            <div
              key={i}
              style={{
                padding: isMobile ? 16 : 22,
                background: "white",
                border: "1px solid #E5E7EB",
                borderRadius: 12
              }}>
              
                <div style={{ marginBottom: 12 }}>
                  <IconTile icon={Icon[n.iconKey]} size={isMobile ? 38 : 44} iconSize={isMobile ? 20 : 22} color="#003366" bg="#EEF2F7" />
                </div>
                <h3 style={{ fontSize: isMobile ? 14 : 15, fontWeight: 700, margin: "0 0 6px", letterSpacing: "-0.01em", color: "#0A0A0A" }}>
                  {n.name}
                </h3>
                <p style={{ fontSize: isMobile ? 12 : 12.5, color: "#6B7280", margin: 0, lineHeight: 1.45 }}>{n.text}</p>
              </div>
            )}
            <div
              style={{
                padding: isMobile ? 16 : 22,
                background: "white",
                border: "1px solid #E5E7EB",
                borderRadius: 12
              }}>
              <div style={{ marginBottom: 12 }}>
                <IconTile icon={Icon.Plus} size={isMobile ? 38 : 44} iconSize={isMobile ? 20 : 22} color="#003366" bg="#EEF2F7" />
              </div>
              <h3 style={{ fontSize: isMobile ? 14 : 15, fontWeight: 700, margin: "0 0 6px", letterSpacing: "-0.01em", color: "#0A0A0A" }}>
                Інші напрямки
              </h3>
              <p style={{ fontSize: isMobile ? 12 : 12.5, color: "#6B7280", margin: 0, lineHeight: 1.45 }}>
                Працюємо з будь-яким бізнесом, де є переписка з клієнтами
              </p>
            </div>
          </div>
        </div>
      </section>

      {/* === CASES === */}
      <section id="Кейси" style={{ padding: isMobile ? "56px 0" : "96px 0", background: "#FAFAFA" }}>
        <div style={{ maxWidth: 1280, margin: "0 auto", padding: isMobile ? "0 20px" : "0 56px" }}>
          <div style={{
            display: "flex",
            alignItems: isMobile ? "flex-start" : "flex-end",
            justifyContent: "space-between",
            gap: 16,
            flexDirection: isMobile ? "column" : "row",
            marginBottom: isMobile ? 24 : 40
          }}>
            <div>
              <div style={{ fontSize: 12, fontWeight: 600, color: "#003366", letterSpacing: "0.08em", textTransform: "uppercase", marginBottom: 12 }}>
                Кейси
              </div>
              <h2 style={{ fontSize: isMobile ? 28 : 44, fontWeight: 700, letterSpacing: "-0.025em", margin: 0, lineHeight: 1.1, color: "#0A0A0A" }}>
                Реальні проєкти
              </h2>
            </div>
            {!isMobile && <CasesNavButtons />}
          </div>
        </div>

        <CasesCarousel cases={CASES} isMobile={isMobile} />
      </section>

      {/* === FORM === */}
      <section id="form" style={{ padding: isMobile ? "56px 20px" : "96px 56px", background: "#003366", color: "white" }}>
        <div style={{ maxWidth: 720, margin: "0 auto", textAlign: "center" }}>
          <h2
            style={{
              fontSize: isMobile ? 28 : 44,
              fontWeight: 700,
              letterSpacing: "-0.025em",
              margin: 0,
              lineHeight: 1.1,
              textWrap: "balance"
            }}>
            
            Отримайте безкоштовну консультацію
          </h2>
          <p style={{ fontSize: isMobile ? 15 : 17, color: "rgba(255,255,255,0.75)", margin: "16px 0 36px", lineHeight: 1.5 }}>
            Покажемо, як AI-агент впишеться у ваш бізнес. Без зобов'язань — 30 хвилин.
          </p>
          <form
            onSubmit={handleSubmit}
            style={{
              display: "grid",
              gap: 12,
              textAlign: "left",
              background: "white",
              padding: isMobile ? 20 : 28,
              borderRadius: 14,
              color: "#0A0A0A"
            }}>
            
            <Field label="Ім'я" value={name} onChange={setName} placeholder="Олександр" />
            <Field label="Номер телефону" value={phone} onChange={setPhone} placeholder="+380 ..." type="tel" />
            <Field label="Сфера та назва проєкту" value={niche} onChange={setNiche} placeholder="Готель «Lisova Hata»" optional />
            <button
              type="submit"
              disabled={sending || submitted}
              style={{
                marginTop: 8,
                padding: isMobile ? "14px 18px" : "16px 22px",
                background: "#003366",
                color: "white",
                border: "none",
                borderRadius: 10,
                fontWeight: 600,
                fontSize: 15,
                cursor: sending || submitted ? "default" : "pointer",
                opacity: sending || submitted ? 0.85 : 1,
                fontFamily: "inherit"
              }}>

              {submitted ? "✓ Дякуємо! Зв'яжемось найближчим часом" : sending ? "Відправляємо…" : "Отримати консультацію"}
            </button>
            {errorMsg && (
              <p style={{ fontSize: 13, color: "#B91C1C", margin: "4px 0 0", textAlign: "center", lineHeight: 1.45 }}>
                {errorMsg}
              </p>
            )}
            <p style={{ fontSize: 11.5, color: "#9CA3AF", margin: "4px 0 0", textAlign: "center" }}>
              Натискаючи кнопку, ви погоджуєтесь з обробкою персональних даних
            </p>
          </form>
        </div>
      </section>

      {/* === FOOTER === */}
      <footer style={{ padding: isMobile ? "48px 20px 28px" : "72px 56px 32px", background: "white", color: "#0A0A0A", borderTop: "1px solid #E5E7EB" }}>
        <div style={{ maxWidth: 1280, margin: "0 auto" }}>
          <div
            style={{
              display: "grid",
              gridTemplateColumns: isMobile ? "1fr" : "1.6fr 1fr 1fr",
              gap: isMobile ? 36 : 64,
              paddingBottom: isMobile ? 28 : 48
            }}>
            
            {/* Brand column */}
            <div>
              <BotlexLogo size={28} />
              <p style={{ fontSize: 14, lineHeight: 1.55, color: "#6B7280", margin: "16px 0 0", maxWidth: 360 }}>
                Розробляємо AI-агентів, які продають у месенджерах та інтегруються з вашою CRM і таблицями.
              </p>
            </div>

            {/* Contacts column */}
            <div>
              <h3 style={{ fontSize: 14, fontWeight: 700, margin: "0 0 18px", color: "#0A0A0A" }}>
                Контакти
              </h3>
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "grid", gap: 12 }}>
                <li>
                  <a href="tel:+380937864424" style={{ display: "flex", alignItems: "center", gap: 10, color: "#374151", textDecoration: "none", fontSize: 14 }}>
                    <Icon.Phone s={16} c="#003366" />
                    +38 (093) 786 44 24
                  </a>
                </li>
                <li>
                  <a href="https://t.me/botlex_ai" target="_blank" rel="noopener" style={{ display: "flex", alignItems: "center", gap: 10, color: "#374151", textDecoration: "none", fontSize: 14 }}>
                    <Icon.TelegramOutline s={16} c="#003366" />
                    @botlex_ai
                  </a>
                </li>
                <li>
                  <a href="https://www.instagram.com/botlex.ai" target="_blank" rel="noopener" style={{ display: "flex", alignItems: "center", gap: 10, color: "#374151", textDecoration: "none", fontSize: 14 }}>
                    <Icon.InstagramOutline s={16} c="#003366" />
                    @botlex.ai
                  </a>
                </li>
              </ul>
            </div>

            {/* Sections column */}
            <div>
              <h3 style={{ fontSize: 14, fontWeight: 700, margin: "0 0 18px", color: "#0A0A0A" }}>
                Розділи
              </h3>
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "grid", gap: 12 }}>
                {[
                { label: "Можливості", href: "#Можливості" },
                { label: "Інтеграції", href: "#Інтеграції" },
                { label: "Сфери", href: "#Сфери" },
                { label: "Кейси", href: "#Кейси" },
                { label: "Консультація", href: "#form" }].
                map((item, i) =>
                <li key={i}>
                    <a href={item.href} style={{ color: "#374151", textDecoration: "none", fontSize: 14 }}>
                      {item.label}
                    </a>
                  </li>
                )}
              </ul>
            </div>
          </div>

          {/* Bottom bar */}
          <div
            style={{
              borderTop: "1px solid #E5E7EB",
              paddingTop: isMobile ? 20 : 24,
              display: "flex",
              flexDirection: isMobile ? "column" : "row",
              justifyContent: "space-between",
              alignItems: isMobile ? "flex-start" : "center",
              gap: 12,
              fontSize: 13,
              color: "#6B7280"
            }}>
            
            <span>© 2026 Botlex. Всі права захищені.</span>
            <span style={{ display: "flex", alignItems: "center", gap: 6 }}>
              Made in Ukraine
              <svg width="18" height="13" viewBox="0 0 18 13" aria-hidden style={{ borderRadius: 2, display: "block" }}>
                <rect width="18" height="6.5" fill="#0057B7" />
                <rect y="6.5" width="18" height="6.5" fill="#FFD700" />
              </svg>
            </span>
          </div>
        </div>
      </footer>
    </div>);

}

function Field({ label, value, onChange, placeholder, type = "text", optional = false }) {
  return (
    <label style={{ display: "grid", gap: 6 }}>
      <span style={{ fontSize: 12.5, fontWeight: 600, color: "#374151" }}>{label}</span>
      <input
        type={type}
        value={value}
        onChange={(e) => onChange(e.target.value)}
        placeholder={placeholder}
        required={!optional}
        style={{
          padding: "12px 14px",
          background: "white",
          border: "1.5px solid #E5E7EB",
          borderRadius: 8,
          fontSize: 14,
          fontFamily: "inherit",
          outline: "none",
          color: "#0A0A0A"
        }}
        onFocus={(e) => e.target.style.borderColor = "#003366"}
        onBlur={(e) => e.target.style.borderColor = "#E5E7EB"} />
      
    </label>);

}

window.VariantA = VariantA;
window.FormField = Field;

// ============ CASES CAROUSEL ============
function CasesCarousel({ cases, isMobile }) {
  const scrollRef = React.useRef(null);

  React.useEffect(() => {
    const handler = (e) => {
      const el = scrollRef.current;
      if (!el) return;
      const card = el.querySelector("[data-case-card]");
      const step = card ? card.getBoundingClientRect().width + 16 : 320;
      el.scrollBy({ left: e.detail.dir * step, behavior: "smooth" });
    };
    window.addEventListener("__cases_nav", handler);
    return () => window.removeEventListener("__cases_nav", handler);
  }, []);

  return (
    <div
      ref={scrollRef}
      style={{
        display: "flex",
        gap: 16,
        overflowX: "auto",
        scrollSnapType: "x mandatory",
        padding: isMobile ? "4px 20px 28px" : "4px 56px 32px",
        scrollPaddingLeft: isMobile ? 20 : 56,
        WebkitOverflowScrolling: "touch"
      }}>
      {cases.map((c, i) =>
      <CaseCard key={i} c={c} isMobile={isMobile} />
      )}
      {/* trailing spacer so last card can snap with breathing room */}
      <div aria-hidden style={{ minWidth: 1, flexShrink: 0 }}></div>
    </div>);

}

function CasesNavButtons() {
  const dispatch = (dir) => {
    window.dispatchEvent(new CustomEvent("__cases_nav", { detail: { dir } }));
  };
  const btnStyle = {
    width: 44,
    height: 44,
    borderRadius: "50%",
    background: "white",
    border: "1px solid #E5E7EB",
    cursor: "pointer",
    display: "grid",
    placeItems: "center",
    color: "#003366",
    fontFamily: "inherit",
    transition: "background 0.15s, border-color 0.15s, transform 0.1s"
  };
  return (
    <div style={{ display: "flex", gap: 10 }}>
      <button
        aria-label="Попередній кейс"
        onClick={() => dispatch(-1)}
        style={btnStyle}
        onMouseEnter={(e) => {e.currentTarget.style.background = "#003366";e.currentTarget.style.color = "white";e.currentTarget.style.borderColor = "#003366";}}
        onMouseLeave={(e) => {e.currentTarget.style.background = "white";e.currentTarget.style.color = "#003366";e.currentTarget.style.borderColor = "#E5E7EB";}}>
        <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
          <path d="M15 18l-6-6 6-6" />
        </svg>
      </button>
      <button
        aria-label="Наступний кейс"
        onClick={() => dispatch(1)}
        style={btnStyle}
        onMouseEnter={(e) => {e.currentTarget.style.background = "#003366";e.currentTarget.style.color = "white";e.currentTarget.style.borderColor = "#003366";}}
        onMouseLeave={(e) => {e.currentTarget.style.background = "white";e.currentTarget.style.color = "#003366";e.currentTarget.style.borderColor = "#E5E7EB";}}>
        <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
          <path d="M9 18l6-6-6-6" />
        </svg>
      </button>
    </div>);

}

// ============ CASE CARD ============
function CaseCard({ c, isMobile }) {
  return (
    <div
      data-case-card
      style={{
        background: "white",
        border: "1px solid #E5E7EB",
        borderRadius: 16,
        padding: isMobile ? "22px 20px" : "26px 24px",
        display: "flex",
        flexDirection: "column",
        gap: 14,
        flexShrink: 0,
        width: isMobile ? 280 : 340,
        scrollSnapAlign: "start",
        transition: "transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease"
      }}
      onMouseEnter={(e) => {
        e.currentTarget.style.transform = "translateY(-2px)";
        e.currentTarget.style.boxShadow = "0 12px 28px -12px rgba(0,51,102,0.18)";
        e.currentTarget.style.borderColor = "#D7DEE7";
      }}
      onMouseLeave={(e) => {
        e.currentTarget.style.transform = "translateY(0)";
        e.currentTarget.style.boxShadow = "none";
        e.currentTarget.style.borderColor = "#E5E7EB";
      }}>

      {/* Logo + name row */}
      <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
        <div
          style={{
            width: 64,
            height: 64,
            borderRadius: "50%",
            overflow: "hidden",
            flexShrink: 0,
            border: "1px solid #EEF1F5",
            background: "#F5F6F8"
          }}>
          <img
            src={c.logo}
            alt={c.name}
            style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
        </div>
        <div style={{ minWidth: 0, flex: 1 }}>
          <div style={{
            fontSize: isMobile ? 16 : 17,
            fontWeight: 700,
            letterSpacing: "-0.01em",
            color: "#0A0A0A",
            lineHeight: 1.2,
            marginBottom: 4
          }}>
            {c.name}
          </div>
          <div style={{
            fontSize: 12.5,
            fontWeight: 500,
            color: "#6B7280",
            lineHeight: 1.35
          }}>
            {c.niche}
          </div>
        </div>
      </div>

      {/* City */}
      <div style={{
        display: "flex",
        alignItems: "center",
        gap: 6,
        fontSize: 12.5,
        color: "#6B7280",
        fontWeight: 500
      }}>
        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#9CA3AF" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
          <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 1 1 18 0z" />
          <circle cx="12" cy="10" r="3" />
        </svg>
        <span>{c.city}</span>
      </div>

      {/* Channels + Systems */}
      <div style={{
        display: "flex",
        flexWrap: "wrap",
        alignItems: "center",
        gap: 8,
        paddingTop: 12,
        borderTop: "1px solid #F1F2F4"
      }}>
        {c.channels.map((ch, i) => {
          const Logo = ChannelLogos[ch];
          if (!Logo) return null;
          return (
            <div key={`ch-${i}`} title={ch} style={{ display: "inline-flex" }}>
              <Logo s={22} />
            </div>);

        })}
        {c.systems && c.systems.length > 0 &&
        <>
            <span style={{
            width: 1,
            height: 16,
            background: "#E5E7EB",
            margin: "0 2px"
          }}></span>
            {c.systems.map((sys, i) =>
          <span
            key={`sys-${i}`}
            style={{
              padding: "4px 9px",
              background: "#F0F4F8",
              borderRadius: 6,
              fontSize: 11.5,
              fontWeight: 600,
              color: "#003366",
              letterSpacing: "-0.005em"
            }}>
                {sys}
              </span>
          )}
          </>
        }
      </div>

      {/* Feature description */}
      {c.feature &&
      <p style={{
        fontSize: 13,
        lineHeight: 1.55,
        color: "#374151",
        margin: 0,
        paddingTop: 4
      }}>
          {c.feature}
        </p>
      }
    </div>);

}

window.CaseCard = CaseCard;
window.CasesCarousel = CasesCarousel;
window.CasesNavButtons = CasesNavButtons;