// sections2.jsx — ForWhom, Calculator, Reviews, FAQ, AppBlock, ContactForm, Footer

const fmt = (n) => Math.round(n).toLocaleString("ru-RU").replace(/,/g, " ");

// ---- For whom ----
function ForWhom({ t }) {
  const ref = useReveal();
  return (
    <section id="forwhom" className="section" ref={ref}>
      <div className="wrap">
        <div className="reveal" style={{ maxWidth: 660, marginBottom: 50 }}>
          <div className="eyebrow" style={{ marginBottom: 16 }}>{t.forwhom.eyebrow}</div>
          <h2 className="h-section" style={{ marginBottom: 16 }}>{t.forwhom.title}</h2>
          <p className="lead">{t.forwhom.sub}</p>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(4,1fr)", gap: 16 }} className="fw-grid">
          {t.forwhom.items.map((it, i) => (
            <div key={i} className="reveal" style={{
              transitionDelay: `${i * 70}ms`, padding: "30px 24px", borderRadius: "var(--radius)",
              background: "var(--dark)", color: "var(--on-dark)", position: "relative", overflow: "hidden",
            }}>
              <div className="mono" style={{ fontSize: 12, color: "#ff7a5f", letterSpacing: "0.12em", marginBottom: 60 }}>0{i + 1}</div>
              <h3 style={{ fontSize: 22, color: "var(--on-dark)", marginBottom: 9 }}>{it.t}</h3>
              <p style={{ color: "var(--on-dark-muted)", fontSize: 14.5, lineHeight: 1.55 }}>{it.d}</p>
              <div style={{ position: "absolute", right: -20, bottom: -20, width: 90, height: 90, borderRadius: "50%", background: "radial-gradient(circle, rgba(226,58,30,.22), transparent 70%)" }} />
            </div>
          ))}
        </div>
      </div>
      <style>{`
        @media(max-width:900px){ .fw-grid{ grid-template-columns:repeat(2,1fr) !important; } }
        @media(max-width:520px){ .fw-grid{ grid-template-columns:1fr !important; } }
      `}</style>
    </section>
  );
}

// ---- Calculator ----
function Calculator({ t, lang, onApply }) {
  const ref = useReveal();
  const [cur, setCur] = useState("USD");
  const [amount, setAmount] = useState(15000);
  const c = CURRENCIES.find((x) => x.code === cur);
  const unit = (r) => (c.per100 ? r / 100 : r);
  const base = amount * unit(c.mostpay);
  const fee = base * 0.015;
  const total = base + fee;
  const bankTotal = amount * unit(c.bank);
  const save = Math.max(0, bankTotal - total);

  const rows = [
    { label: t.calc.payLabel, val: `${fmt(amount)} ${cur}`, big: true },
    { label: `${t.calc.rateLabel} (${t.calc.perUnit} ${c.per100 ? "100 " + cur : cur})`, val: `${(c.per100 ? c.mostpay : c.mostpay).toLocaleString("ru-RU")} c` },
    { label: t.calc.feeLabel + " · 1,5%", val: `${fmt(fee)} c` },
  ];

  return (
    <section id="calc" className="section" ref={ref} style={{ background: "var(--surface)", borderTop: "1px solid var(--line)", borderBottom: "1px solid var(--line)" }}>
      <div className="wrap">
        <div className="reveal" style={{ maxWidth: 660, marginBottom: 44 }}>
          <div className="eyebrow" style={{ marginBottom: 16 }}>{t.calc.eyebrow}</div>
          <h2 className="h-section" style={{ marginBottom: 16 }}>{t.calc.title}</h2>
          <p className="lead">{t.calc.sub}</p>
        </div>

        <div className="reveal calc-card" style={{ display: "grid", gridTemplateColumns: "1.05fr 0.95fr", borderRadius: "var(--radius-lg)", overflow: "hidden", border: "1px solid var(--line)", boxShadow: "var(--shadow)" }}>
          {/* inputs */}
          <div style={{ padding: "38px 36px", background: "var(--bg)" }}>
            <label style={{ display: "block", marginBottom: 12 }}>{t.calc.currencyLabel}</label>
            <div style={{ display: "flex", flexWrap: "wrap", gap: 8, marginBottom: 26 }}>
              {CURRENCIES.map((x) => (
                <button key={x.code} onClick={() => setCur(x.code)} style={{
                  display: "flex", alignItems: "center", gap: 7, padding: "10px 14px", borderRadius: 999,
                  border: `1.5px solid ${cur === x.code ? "var(--accent)" : "var(--line-strong)"}`,
                  background: cur === x.code ? "var(--accent-tint)" : "var(--surface)",
                  color: cur === x.code ? "var(--accent)" : "var(--ink-soft)",
                  fontWeight: 700, fontSize: 14, fontFamily: "var(--font-mono)", transition: "all .15s",
                }}>
                  <span style={{ fontSize: 16 }}>{x.flag}</span>{x.code}
                </button>
              ))}
            </div>

            <label htmlFor="calc-amt" style={{ display: "block", marginBottom: 10 }}>{t.calc.amountLabel}</label>
            <div style={{ position: "relative", marginBottom: 14 }}>
              <input id="calc-amt" type="number" min="0" value={amount}
                onChange={(e) => setAmount(Math.max(0, Number(e.target.value) || 0))}
                style={{ fontSize: 26, fontWeight: 700, fontFamily: "var(--font-mono)", paddingRight: 64, height: 64 }} />
              <span className="mono" style={{ position: "absolute", right: 16, top: "50%", transform: "translateY(-50%)", fontWeight: 700, color: "var(--muted)", fontSize: 18 }}>{cur}</span>
            </div>
            <input type="range" min="1000" max="120000" step="500" value={Math.min(120000, amount)}
              onChange={(e) => setAmount(Number(e.target.value))}
              style={{ width: "100%", accentColor: "var(--accent)", padding: 0, border: "none", background: "none", height: "auto", cursor: "pointer" }} />
            <div className="mono" style={{ display: "flex", justifyContent: "space-between", fontSize: 11.5, color: "var(--muted)", marginTop: 4 }}>
              <span>1 000</span><span>120 000+</span>
            </div>
          </div>

          {/* result */}
          <div style={{ padding: "38px 36px", background: "var(--dark)", color: "var(--on-dark)", display: "flex", flexDirection: "column" }}>
            <div style={{ display: "flex", flexDirection: "column", gap: 14, marginBottom: 22 }}>
              {rows.map((r, i) => (
                <div key={i} style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", gap: 12 }}>
                  <span style={{ color: "var(--on-dark-muted)", fontSize: 14 }}>{r.label}</span>
                  <span className="mono" style={{ fontWeight: 700, fontSize: r.big ? 18 : 15.5 }}>{r.val}</span>
                </div>
              ))}
              <div style={{ height: 1, background: "rgba(255,255,255,.12)", margin: "4px 0" }} />
              <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
                <span style={{ fontSize: 15, fontWeight: 600 }}>{t.calc.totalLabel}</span>
                <span className="mono" style={{ fontWeight: 700, fontSize: 30, color: "#fff", letterSpacing: "-0.02em" }}>{fmt(total)} c</span>
              </div>
            </div>

            <div style={{ display: "flex", alignItems: "center", gap: 10, background: "rgba(31,138,91,.16)", border: "1px solid rgba(31,138,91,.4)", borderRadius: 12, padding: "13px 15px", marginBottom: "auto" }}>
              <span style={{ width: 30, height: 30, borderRadius: 8, background: "var(--good)", display: "grid", placeItems: "center", color: "#fff", flex: "0 0 auto" }}><Icon name="rate" size={17} /></span>
              <div style={{ lineHeight: 1.25 }}>
                <div style={{ fontSize: 12.5, color: "#8fe0b6" }}>{t.calc.saveLabel}</div>
                <div className="mono" style={{ fontWeight: 700, fontSize: 17, color: "#bff2d4" }}>≈ {fmt(save)} c</div>
              </div>
            </div>

            <button className="btn btn-primary" onClick={onApply} style={{ marginTop: 22, width: "100%" }}>{t.calc.ctaText}<Icon name="arrow" size={18} /></button>
            <p className="mono" style={{ fontSize: 10.5, color: "var(--on-dark-muted)", marginTop: 14, lineHeight: 1.4, textAlign: "center" }}>{t.calc.disclaimer}</p>
          </div>
        </div>
      </div>
      <style>{`@media(max-width:780px){ .calc-card{ grid-template-columns:1fr !important; } }`}</style>
    </section>
  );
}

// ---- Reviews ----
function Reviews({ t }) {
  const ref = useReveal();
  return (
    <section id="reviews" className="section" ref={ref}>
      <div className="wrap">
        <div className="reveal" style={{ maxWidth: 620, marginBottom: 48 }}>
          <div className="eyebrow" style={{ marginBottom: 16 }}>{t.reviews.eyebrow}</div>
          <h2 className="h-section">{t.reviews.title}</h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3,1fr)", gap: 18 }} className="rv-grid">
          {t.reviews.items.map((r, i) => (
            <figure key={i} className="reveal card" style={{ margin: 0, padding: "30px 28px", display: "flex", flexDirection: "column", transitionDelay: `${i * 80}ms` }}>
              <div style={{ display: "flex", gap: 3, color: "var(--accent)", marginBottom: 16 }}>
                {[0, 1, 2, 3, 4].map((s) => <Icon key={s} name="star" size={16} />)}
              </div>
              <blockquote style={{ margin: 0, fontSize: 16.5, lineHeight: 1.5, color: "var(--ink)", fontWeight: 500, flex: 1 }}>«{r.quote}»</blockquote>
              <figcaption style={{ marginTop: 22, display: "flex", alignItems: "center", gap: 12 }}>
                <div style={{ width: 42, height: 42, borderRadius: "50%", background: "var(--accent-tint)", color: "var(--accent)", display: "grid", placeItems: "center", fontWeight: 800, fontSize: 18, fontFamily: "var(--font-head)" }}>{r.name[0]}</div>
                <div>
                  <div style={{ fontWeight: 700, fontSize: 15 }}>{r.name}</div>
                  <div style={{ fontSize: 13, color: "var(--muted)" }}>{r.role}</div>
                </div>
              </figcaption>
            </figure>
          ))}
        </div>
      </div>
      <style>{`
        @media(max-width:900px){ .rv-grid{ grid-template-columns:1fr !important; max-width:540px; } }
      `}</style>
    </section>
  );
}

// ---- FAQ ----
function FAQ({ t }) {
  const ref = useReveal();
  const [open, setOpen] = useState(0);
  return (
    <section id="faq" className="section" ref={ref} style={{ background: "var(--surface)", borderTop: "1px solid var(--line)" }}>
      <div className="wrap" style={{ display: "grid", gridTemplateColumns: "0.8fr 1.2fr", gap: 48 }}>
        <div className="reveal faq-head">
          <div className="eyebrow" style={{ marginBottom: 16 }}>{t.faq.eyebrow}</div>
          <h2 className="h-section">{t.faq.title}</h2>
        </div>
        <div className="reveal" style={{ display: "flex", flexDirection: "column", gap: 12 }}>
          {t.faq.items.map((it, i) => {
            const isOpen = open === i;
            return (
              <div key={i} style={{ border: "1px solid var(--line)", borderRadius: "var(--radius-sm)", overflow: "hidden", background: "var(--bg)" }}>
                <button onClick={() => setOpen(isOpen ? -1 : i)} style={{ width: "100%", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16, padding: "20px 22px", background: "none", border: "none", textAlign: "left" }}>
                  <span style={{ fontWeight: 700, fontSize: 16.5, color: "var(--ink)" }}>{it.q}</span>
                  <span style={{ flex: "0 0 auto", color: "var(--accent)", transform: isOpen ? "rotate(180deg)" : "none", transition: "transform .25s" }}><Icon name="chevron" size={20} /></span>
                </button>
                <div style={{ maxHeight: isOpen ? 240 : 0, transition: "max-height .3s ease", overflow: "hidden" }}>
                  <p style={{ padding: "0 22px 22px", color: "var(--muted)", fontSize: 15.5, lineHeight: 1.6 }}>{it.a}</p>
                </div>
              </div>
            );
          })}
        </div>
      </div>
      <style>{`@media(max-width:840px){ #faq .wrap{ grid-template-columns:1fr !important; gap:28px !important; } }`}</style>
    </section>
  );
}

// ---- App block ----
function AppBlock({ t }) {
  const ref = useReveal();
  const Badge = ({ store, href, sub }) => (
    <a href={href} target="_blank" rel="noopener" style={{ display: "flex", alignItems: "center", gap: 11, background: "rgba(255,255,255,.06)", border: "1px solid rgba(255,255,255,.14)", borderRadius: 12, padding: "11px 18px", transition: "background .15s" }}
      onMouseEnter={(e) => e.currentTarget.style.background = "rgba(255,255,255,.12)"} onMouseLeave={(e) => e.currentTarget.style.background = "rgba(255,255,255,.06)"}>
      <span style={{ color: "var(--on-dark)" }}><Icon name="check" size={18} /></span>
      <span style={{ lineHeight: 1.1 }}>
        <span style={{ display: "block", fontSize: 11, color: "var(--on-dark-muted)" }}>{sub}</span>
        <span style={{ display: "block", fontSize: 15.5, fontWeight: 700, color: "var(--on-dark)" }}>{store}</span>
      </span>
    </a>
  );
  return (
    <section className="section" ref={ref} style={{ background: "var(--dark)" }}>
      <div className="wrap" style={{ display: "grid", gridTemplateColumns: "1.1fr 0.9fr", gap: 50, alignItems: "center" }}>
        <div className="reveal app-copy">
          <div className="eyebrow on-dark" style={{ marginBottom: 16 }}>{t.app.eyebrow}</div>
          <h2 className="h-section" style={{ color: "var(--on-dark)", marginBottom: 18 }}>{t.app.title}</h2>
          <p className="lead" style={{ color: "rgba(243,239,231,.78)", marginBottom: 26 }}>{t.app.sub}</p>
          <div style={{ display: "flex", flexDirection: "column", gap: 12, marginBottom: 30 }}>
            {t.app.bullets.map((b, i) => (
              <div key={i} style={{ display: "flex", alignItems: "center", gap: 11, color: "rgba(243,239,231,.92)", fontSize: 15.5 }}>
                <span style={{ width: 24, height: 24, borderRadius: 999, background: "rgba(255,122,95,.18)", color: "#ff7a5f", display: "grid", placeItems: "center", flex: "0 0 auto" }}><Icon name="check" size={14} /></span>{b}
              </div>
            ))}
          </div>
          <div style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
            <Badge store="App Store" sub="Скачать в" href={LINKS.appstore} />
            <Badge store="RuStore" sub="Скачать в" href={LINKS.rustore} />
            <Badge store="AppGallery" sub="Скачать в" href={LINKS.appgallery} />
          </div>
        </div>
        {/* phone mock */}
        <div className="reveal" style={{ display: "flex", justifyContent: "center" }}>
          <div style={{ width: 248, height: 506, borderRadius: 40, background: "linear-gradient(160deg,#2a2118,#16130f)", border: "8px solid #07060500", boxShadow: "0 0 0 9px #232019, var(--shadow-lg)", padding: 12, position: "relative" }}>
            <div style={{ position: "absolute", top: 16, left: "50%", transform: "translateX(-50%)", width: 90, height: 22, background: "#0c0a08", borderRadius: 999, zIndex: 2 }} />
            <div style={{ width: "100%", height: "100%", borderRadius: 30, background: "repeating-linear-gradient(135deg,#211d18 0 2px,transparent 2px 12px), #1b1813", display: "grid", placeItems: "center", overflow: "hidden", position: "relative" }}>
              <div style={{ position: "absolute", inset: 0, display: "flex", flexDirection: "column", padding: "44px 18px 20px" }}>
                <Logo onDark size={22} />
                <div className="mono" style={{ marginTop: "auto", color: "rgba(255,255,255,.3)", fontSize: 10.5, letterSpacing: "0.08em", textAlign: "center" }}>{t.app.mockNote}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <style>{`@media(max-width:820px){ section .wrap[style*="1.1fr"]{ grid-template-columns:1fr !important; } .app-copy{ order:2; } }`}</style>
    </section>
  );
}

// ---- Contact form ----
function ContactForm({ t, lang }) {
  const ref = useReveal();
  const blank = { role: "", country: "", amount: "", currency: "USD", name: "", phone: "", channel: t.form.channels[0], comment: "" };
  const [f, setF] = useState(blank);
  const [err, setErr] = useState({});
  const [step, setStep] = useState(1);
  const [state, setState] = useState("idle"); // idle | sending | done
  const upd = (k, v) => { setF((p) => ({ ...p, [k]: v })); setErr((e) => ({ ...e, [k]: undefined })); };

  useEffect(() => { setF((p) => ({ ...p, channel: t.form.channels[0] })); }, [lang]);

  const phoneOk = f.phone.replace(/\D/g, "").length >= 9;
  const nameOk = f.name.trim().length >= 2;

  const next = () => setStep(2);
  const submit = (e) => {
    e && e.preventDefault();
    const er = {};
    if (!nameOk) er.name = t.form.errName;
    if (!phoneOk) er.phone = t.form.errPhone;
    setErr(er);
    if (Object.keys(er).length) return;
    setState("sending");
    setTimeout(() => setState("done"), 1100);
  };
  const reset = () => { setF(blank); setErr({}); setStep(1); setState("idle"); };

  const curObj = CURRENCIES.find((c) => c.code === f.currency);
  const countryObj = COUNTRIES.find((c) => c.code === f.country);
  const hasSummary = f.role || f.country || f.amount || f.name || f.phone;

  // ---- summary rows ----
  const summaryRows = [
    f.role && { k: t.form.fRole.replace("?", ""), v: f.role },
    countryObj && { k: lang === "kg" ? "Өлкө" : "Страна", v: `${countryObj.flag} ${countryObj[lang]}` },
    f.amount && { k: lang === "kg" ? "Сумма" : "Сумма", v: `${Number(f.amount).toLocaleString("ru-RU")} ${f.currency}` },
    f.name && { k: t.form.fName, v: f.name },
    f.phone && { k: t.form.fPhone, v: f.phone },
    f.name && f.phone && { k: t.form.channelQ, v: f.channel },
  ].filter(Boolean);

  return (
    <section id="form" className="section" ref={ref} style={{ background: "var(--bg)" }}>
      <div className="wrap" style={{ display: "grid", gridTemplateColumns: "0.82fr 1.18fr", gap: 46, alignItems: "start" }} id="cf-wrap">
        {/* LEFT — intro + live summary + direct contacts */}
        <div className="reveal cf-side">
          <div className="eyebrow" style={{ marginBottom: 16 }}>{t.form.eyebrow}</div>
          <h2 className="h-section" style={{ marginBottom: 16 }}>{t.form.title}</h2>
          <p className="lead" style={{ marginBottom: 26 }}>{t.form.sub}</p>

          <div className="summary-card" style={{ background: "var(--dark)", color: "var(--on-dark)", borderRadius: "var(--radius)", padding: "20px 22px", marginBottom: 24 }}>
            <div className="mono" style={{ fontSize: 11, letterSpacing: "0.1em", textTransform: "uppercase", color: "#ff7a5f", marginBottom: 14 }}>{t.form.summaryTitle}</div>
            {hasSummary ? (
              <div style={{ display: "flex", flexDirection: "column", gap: 11 }}>
                {summaryRows.map((r, i) => (
                  <div key={i} style={{ display: "flex", justifyContent: "space-between", gap: 14, fontSize: 14, animation: "fadeUp .35s ease" }}>
                    <span style={{ color: "var(--on-dark-muted)" }}>{r.k}</span>
                    <span style={{ fontWeight: 700, textAlign: "right" }}>{r.v}</span>
                  </div>
                ))}
              </div>
            ) : (
              <p style={{ color: "var(--on-dark-muted)", fontSize: 14, lineHeight: 1.5 }}>{t.form.summaryEmpty}</p>
            )}
          </div>

          <div style={{ fontSize: 13.5, fontWeight: 700, color: "var(--ink-soft)", marginBottom: 12 }}>{t.form.orWrite}</div>
          <div style={{ display: "flex", flexWrap: "wrap", gap: 10 }}>
            <a href={`tel:${LINKS.phoneRaw}`} className="soc-btn" style={{ background: "var(--surface)", border: "1px solid var(--line)", color: "var(--ink)" }}><span style={{ color: "var(--accent)" }}><Icon name="phone" size={17} /></span>{LINKS.phone}</a>
            <a href={LINKS.telegram} target="_blank" rel="noopener" className="soc-btn" style={{ background: "var(--accent)", color: "#fff", border: "none" }}><Social name="telegram" size={18} /> Telegram</a>
            <a href={LINKS.whatsapp} target="_blank" rel="noopener" className="soc-btn" style={{ background: "var(--good)", color: "#fff", border: "none" }}><Social name="whatsapp" size={18} /> WhatsApp</a>
          </div>
        </div>

        {/* RIGHT — wizard */}
        <div className="reveal card cf-card" style={{ padding: "30px 32px", borderRadius: "var(--radius-lg)" }}>
          {state === "done" ? (
            <div style={{ textAlign: "center", padding: "26px 8px" }}>
              <div className="success-pop" style={{ width: 72, height: 72, borderRadius: "50%", background: "var(--good-tint)", color: "var(--good)", display: "grid", placeItems: "center", margin: "0 auto 20px" }}><Icon name="check" size={36} /></div>
              <h3 style={{ fontSize: 25, marginBottom: 10 }}>{t.form.success}</h3>
              <p style={{ color: "var(--muted)", fontSize: 16, maxWidth: 380, margin: "0 auto 24px" }}>{t.form.successSub}</p>
              <div style={{ display: "flex", flexDirection: "column", gap: 12, maxWidth: 420, margin: "0 auto 26px", textAlign: "left" }}>
                {t.form.whatNext.map((w, i) => (
                  <div key={i} style={{ display: "flex", alignItems: "center", gap: 12 }}>
                    <span className="mono" style={{ width: 30, height: 30, borderRadius: "50%", background: "var(--accent-tint)", color: "var(--accent)", display: "grid", placeItems: "center", fontWeight: 700, fontSize: 13, flex: "0 0 auto" }}>{i + 1}</span>
                    <span style={{ fontSize: 15, color: "var(--ink-soft)" }}>{w}</span>
                  </div>
                ))}
              </div>
              <button className="btn btn-ghost" onClick={reset}>{t.form.another}</button>
            </div>
          ) : (
            <form onSubmit={(e) => e.preventDefault()} noValidate>
              {/* progress */}
              <div style={{ marginBottom: 26 }}>
                <div style={{ display: "flex", gap: 10, marginBottom: 12 }}>
                  {[1, 2].map((s) => (
                    <button key={s} type="button" onClick={() => s < step && setStep(s)} style={{ flex: 1, height: 4, borderRadius: 4, border: "none", padding: 0, cursor: s < step ? "pointer" : "default", background: s <= step ? "var(--accent)" : "var(--line-strong)", transition: "background .3s" }} aria-label={"step " + s} />
                  ))}
                </div>
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                  <span className="mono" style={{ fontSize: 12, color: "var(--muted)", letterSpacing: "0.04em" }}>{t.form.stepWord} {step} {t.form.ofWord} 2</span>
                  <span style={{ fontSize: 14, fontWeight: 700, color: "var(--ink)" }}>{step === 1 ? t.form.step1Title : t.form.step2Title}</span>
                </div>
              </div>

              {step === 1 ? (
                <div className="wiz-step" key="s1">
                  {/* role cards */}
                  <label style={{ display: "block", marginBottom: 10 }}>{t.form.fRole}</label>
                  <div className="role-grid" style={{ display: "grid", gridTemplateColumns: "repeat(5,1fr)", gap: 9, marginBottom: 22 }}>
                    {t.form.roles.map((r, i) => {
                      const on = f.role === r;
                      return (
                        <button key={r} type="button" onClick={() => upd("role", on ? "" : r)} className="role-card" style={{ borderColor: on ? "var(--accent)" : "var(--line-strong)", background: on ? "var(--accent-tint)" : "var(--surface)", color: on ? "var(--accent)" : "var(--ink-soft)" }}>
                          <Icon name={ROLE_ICONS[i]} size={24} />
                          <span style={{ fontSize: 12, fontWeight: 700 }}>{r}</span>
                        </button>
                      );
                    })}
                  </div>

                  {/* country chips */}
                  <label style={{ display: "block", marginBottom: 10 }}>{t.form.fCountry}</label>
                  <div style={{ display: "flex", flexWrap: "wrap", gap: 8, marginBottom: 22 }}>
                    {COUNTRIES.map((c) => {
                      const on = f.country === c.code;
                      return (
                        <button key={c.code} type="button" onClick={() => upd("country", on ? "" : c.code)} className="chip" style={{ borderColor: on ? "var(--accent)" : "var(--line-strong)", background: on ? "var(--accent-tint)" : "var(--surface)", color: on ? "var(--accent)" : "var(--ink-soft)" }}>
                          <span style={{ fontSize: 16 }}>{c.flag}</span>{c[lang]}
                        </button>
                      );
                    })}
                  </div>

                  {/* amount + currency */}
                  <label htmlFor="f-amount" style={{ display: "block", marginBottom: 10 }}>{t.form.fAmount} <span style={{ color: "var(--muted)", fontWeight: 400 }}>· {t.form.optional}</span></label>
                  <div style={{ display: "flex", gap: 10, flexWrap: "wrap" }}>
                    <input id="f-amount" type="number" min="0" inputMode="numeric" value={f.amount} placeholder="15 000" onChange={(e) => upd("amount", e.target.value)} style={{ flex: "1 1 160px", fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 18 }} />
                    <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
                      {CURRENCIES.map((c) => {
                        const on = f.currency === c.code;
                        return <button key={c.code} type="button" onClick={() => upd("currency", c.code)} className="cur-chip mono" style={{ borderColor: on ? "var(--accent)" : "var(--line-strong)", background: on ? "var(--accent)" : "var(--surface)", color: on ? "#fff" : "var(--ink-soft)" }}>{c.code}</button>;
                      })}
                    </div>
                  </div>

                  <button type="button" className="btn btn-primary btn-lg" onClick={next} style={{ width: "100%", marginTop: 26 }}>{t.form.next}<Icon name="arrow" size={18} /></button>
                </div>
              ) : (
                <div className="wiz-step" key="s2">
                  <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16, marginBottom: 18 }} className="cf-2col">
                    <div>
                      <label htmlFor="f-name" style={{ display: "block", marginBottom: 7 }}>{t.form.fName}</label>
                      <div style={{ position: "relative" }}>
                        <input id="f-name" value={f.name} autoFocus placeholder="—" onChange={(e) => upd("name", e.target.value)} style={{ borderColor: err.name ? "var(--accent)" : (nameOk ? "var(--good)" : "var(--line-strong)"), paddingRight: nameOk ? 40 : 15 }} />
                        {nameOk && <span style={{ position: "absolute", right: 13, top: "50%", transform: "translateY(-50%)", color: "var(--good)" }}><Icon name="check" size={18} /></span>}
                      </div>
                      {err.name && <div className="err-msg">{err.name}</div>}
                    </div>
                    <div>
                      <label htmlFor="f-phone" style={{ display: "block", marginBottom: 7 }}>{t.form.fPhone}</label>
                      <div style={{ position: "relative" }}>
                        <input id="f-phone" type="tel" value={f.phone} placeholder="+996 ___ ___ ___" onChange={(e) => upd("phone", e.target.value)} onKeyDown={(e) => e.key === "Enter" && submit(e)} style={{ borderColor: err.phone ? "var(--accent)" : (phoneOk ? "var(--good)" : "var(--line-strong)"), fontFamily: "var(--font-mono)", paddingRight: phoneOk ? 40 : 15 }} />
                        {phoneOk && <span style={{ position: "absolute", right: 13, top: "50%", transform: "translateY(-50%)", color: "var(--good)" }}><Icon name="check" size={18} /></span>}
                      </div>
                      {err.phone && <div className="err-msg">{err.phone}</div>}
                    </div>
                  </div>

                  {/* channel segmented */}
                  <label style={{ display: "block", marginBottom: 10 }}>{t.form.channelQ}</label>
                  <div style={{ display: "flex", gap: 9, marginBottom: 18, flexWrap: "wrap" }}>
                    {t.form.channels.map((ch, i) => {
                      const on = f.channel === ch;
                      const ic = ["telegram", "whatsapp", null][i];
                      return (
                        <button key={ch} type="button" onClick={() => upd("channel", ch)} className="seg" style={{ borderColor: on ? "var(--accent)" : "var(--line-strong)", background: on ? "var(--accent-tint)" : "var(--surface)", color: on ? "var(--accent)" : "var(--ink-soft)" }}>
                          {ic ? <Social name={ic} size={17} /> : <Icon name="phone" size={16} />}{ch}
                        </button>
                      );
                    })}
                  </div>

                  <label htmlFor="f-comment" style={{ display: "block", marginBottom: 7 }}>{t.form.fComment}</label>
                  <textarea id="f-comment" rows="3" value={f.comment} onChange={(e) => upd("comment", e.target.value)} style={{ resize: "vertical", marginBottom: 22 }} />

                  <div style={{ display: "flex", gap: 12 }}>
                    <button type="button" className="btn btn-ghost btn-lg" onClick={() => setStep(1)} style={{ flex: "0 0 auto", paddingLeft: 22, paddingRight: 22 }}>{t.form.back}</button>
                    <button type="button" className="btn btn-primary btn-lg" onClick={submit} disabled={state === "sending"} style={{ flex: 1, opacity: state === "sending" ? 0.7 : 1 }}>
                      {state === "sending" ? t.form.sending : t.form.submit}{state !== "sending" && <Icon name="arrow" size={18} />}
                    </button>
                  </div>
                  <p style={{ fontSize: 12, color: "var(--muted)", marginTop: 14, textAlign: "center", lineHeight: 1.45 }}>{t.form.consent}</p>
                </div>
              )}
            </form>
          )}
        </div>
      </div>
      <style>{`
        .soc-btn{ display:inline-flex; align-items:center; gap:8px; padding:11px 16px; border-radius:11px; font-weight:700; font-size:14.5px; }
        .role-card{ display:flex; flex-direction:column; align-items:center; justify-content:center; gap:9px; padding:16px 6px; border:1.5px solid; border-radius:14px; transition:all .15s; text-align:center; }
        .role-card:hover{ border-color:var(--accent) !important; }
        .chip{ display:inline-flex; align-items:center; gap:7px; padding:9px 14px; border:1.5px solid; border-radius:999px; font-weight:600; font-size:14px; transition:all .15s; }
        .chip:hover{ border-color:var(--accent) !important; }
        .cur-chip{ padding:13px 12px; border:1.5px solid; border-radius:11px; font-weight:700; font-size:13px; transition:all .15s; }
        .seg{ display:inline-flex; align-items:center; gap:8px; padding:12px 18px; border:1.5px solid; border-radius:12px; font-weight:700; font-size:14.5px; transition:all .15s; }
        .seg:hover{ border-color:var(--accent) !important; }
        .err-msg{ color:var(--accent); font-size:12.5px; margin-top:5px; font-weight:600; }
        .wiz-step{ animation:wizIn .32s cubic-bezier(.2,.7,.2,1); }
        @keyframes wizIn{ from{opacity:0; transform:translateX(14px);} to{opacity:1; transform:none;} }
        .success-pop{ animation:pop .4s cubic-bezier(.2,.9,.3,1.4); }
        @keyframes pop{ from{transform:scale(.4); opacity:0;} to{transform:scale(1); opacity:1;} }
        @media(max-width:880px){ #cf-wrap{ grid-template-columns:1fr !important; gap:30px !important; } }
        @media(max-width:560px){ .role-grid{ grid-template-columns:repeat(3,1fr) !important; } .cf-2col{ grid-template-columns:1fr !important; } }
      `}</style>
    </section>
  );
}

// ---- Footer ----
function Footer({ t }) {
  const socials = [
    { name: "telegram", href: LINKS.telegram }, { name: "instagram", href: LINKS.instagram },
    { name: "youtube", href: LINKS.youtube }, { name: "rutube", href: LINKS.rutube },
  ];
  return (
    <footer style={{ background: "var(--dark)", color: "var(--on-dark)", paddingTop: 64 }}>
      <div className="wrap">
        <div style={{ display: "grid", gridTemplateColumns: "1.4fr 1fr 1fr 1fr", gap: 36, paddingBottom: 48, borderBottom: "1px solid rgba(255,255,255,.1)" }} className="ft-grid">
          <div>
            <Logo onDark size={28} />
            <p style={{ color: "var(--on-dark-muted)", fontSize: 14.5, lineHeight: 1.55, marginTop: 18, maxWidth: 300 }}>{t.footer.tagline}</p>
            <div style={{ display: "flex", gap: 10, marginTop: 22 }}>
              {socials.map((s) => (
                <a key={s.name} href={s.href} target="_blank" rel="noopener" aria-label={s.name} style={{ width: 40, height: 40, borderRadius: 10, border: "1px solid rgba(255,255,255,.16)", display: "grid", placeItems: "center", color: "var(--on-dark)", transition: "all .15s" }}
                  onMouseEnter={(e) => { e.currentTarget.style.background = "var(--accent)"; e.currentTarget.style.borderColor = "var(--accent)"; }}
                  onMouseLeave={(e) => { e.currentTarget.style.background = "transparent"; e.currentTarget.style.borderColor = "rgba(255,255,255,.16)"; }}>
                  <Social name={s.name} size={19} />
                </a>
              ))}
            </div>
          </div>
          <div>
            <div className="ft-h">{t.footer.contactsTitle}</div>
            <a className="ft-l" href={`tel:${LINKS.phoneRaw}`}>{LINKS.phone}</a>
            <a className="ft-l" href={`mailto:${LINKS.email}`}>{LINKS.email}</a>
          </div>
          <div>
            <div className="ft-h">{t.footer.appTitle}</div>
            <a className="ft-l" href={LINKS.appstore} target="_blank" rel="noopener">App Store</a>
            <a className="ft-l" href={LINKS.rustore} target="_blank" rel="noopener">RuStore</a>
            <a className="ft-l" href={LINKS.appgallery} target="_blank" rel="noopener">AppGallery</a>
          </div>
          <div>
            <div className="ft-h">{t.footer.siteTitle}</div>
            <a className="ft-l" href={LINKS.site} target="_blank" rel="noopener">{t.footer.siteLink}</a>
          </div>
        </div>
        <div style={{ display: "flex", justifyContent: "space-between", gap: 16, flexWrap: "wrap", padding: "26px 0 34px" }}>
          <span style={{ color: "var(--on-dark-muted)", fontSize: 13 }}>{t.footer.rights}</span>
          <span style={{ color: "var(--on-dark-muted)", fontSize: 13, maxWidth: 480, textAlign: "right" }}>{t.footer.legal}</span>
        </div>
      </div>
      <style>{`
        .ft-h{ font-size:13px; font-weight:700; letter-spacing:0.06em; text-transform:uppercase; color:var(--on-dark-muted); margin-bottom:16px; }
        .ft-l{ display:block; color:var(--on-dark); font-size:15px; margin-bottom:11px; transition:color .15s; }
        .ft-l:hover{ color:#ff7a5f; }
        @media(max-width:820px){ .ft-grid{ grid-template-columns:1fr 1fr !important; gap:30px !important; } }
        @media(max-width:480px){ .ft-grid{ grid-template-columns:1fr !important; } }
      `}</style>
    </footer>
  );
}

Object.assign(window, { fmt, ForWhom, Calculator, Reviews, FAQ, AppBlock, ContactForm, Footer });
