"use client";

import { useEffect, useMemo, useRef, useState } from "react";
import Link from "next/link";
import { useLang } from "@/context/LanguageContext";
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
import { IncrelogLogo } from "@/components/IncrelogLogo";
import {
  Alert,
  Button,
  Input,
  Select,
  Spinner,
  EmptyState,
  Skeleton,
  Textarea,
} from "@/components/ui";
import { INSTITUTION_TYPES } from "@/lib/constants";
import { PricingCategory, yearlyEffectiveMonthly } from "@/lib/pricing";
import { formatBDT, formatNumber } from "@/lib/utils";
import { api, useApi } from "@/lib/client";
import {
  IconAcademic,
  IconArrowRight,
  IconAward,
  IconBell,
  IconBook,
  IconBriefcase,
  IconBuilding,
  IconCard,
  IconCheck,
  IconClipboard,
  IconDashboard,
  IconHome,
  IconLayers,
  IconMessageCircle,
  IconPackage,
  IconSparkle,
  IconTrend,
  IconUserCheck,
  IconUsers,
  IconWallet,
} from "@/components/icons";

/** One student-count slab inside a pricing card (DB-backed, admin-managed). */
interface PricingTierView {
  id: number;
  minStudents: number;
  maxStudents: number | null;
  monthlyPrice: number;
  yearlyDiscount: number;
}

type PricingCategoryView = PricingCategory & { tiers: PricingTierView[] };
/* Premium hero illustration — a layered EMS dashboard collage: main window,
   floating result & attendance cards, soft blobs and a dotted grid. */
function HeroArt() {
  const white = "#ffffff";
  const bar = "#d7dfe6";
  const barSoft = "#e8eef2";
  const green = "#2f9e6b";
  const greenTint = "#e2f4ea";
  const gold = "#c9a227";
  return (
    <svg viewBox="0 0 560 440" className="ems-hero-svg" aria-hidden="true">
      <defs>
        <filter id="f-hero" x="-30%" y="-30%" width="160%" height="160%">
          <feDropShadow dx="0" dy="14" stdDeviation="16" floodColor="#1a2e29" floodOpacity="0.18" />
        </filter>
        <linearGradient id="g-hero" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0" stopColor="#2c7d6d" />
          <stop offset="1" stopColor="#24695c" />
        </linearGradient>
        <linearGradient id="g-hero-chart" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor="#24695c" stopOpacity="0.28" />
          <stop offset="1" stopColor="#24695c" stopOpacity="0" />
        </linearGradient>
        <linearGradient id="g-hero-gold" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0" stopColor="#d4af37" />
          <stop offset="1" stopColor="#b8901d" />
        </linearGradient>
      </defs>

      {/* soft blobs + dot grid */}
      <circle cx="330" cy="216" r="196" fill="#24695c" opacity="0.07" />
      <circle cx="448" cy="112" r="84" fill={gold} opacity="0.12" />
      <circle cx="92" cy="380" r="70" fill="#24695c" opacity="0.06" />
      {[0, 1, 2, 3].map((c) =>
        [0, 1, 2, 3].map((r) => (
          <circle key={`${c}${r}`} cx={30 + c * 26} cy={34 + r * 26} r="2.2" fill="#24695c" opacity="0.18" />
        ))
      )}

      {/* main dashboard window */}
      <rect x="70" y="56" width="330" height="308" rx="18" fill={white} filter="url(#f-hero)" />
      <path d="M88 56h294a18 18 0 0 1 18 18v30H70V74a18 18 0 0 1 18-18z" fill="url(#g-hero)" />
      <circle cx="92" cy="80" r="4.5" fill={white} opacity="0.5" />
      <circle cx="107" cy="80" r="4.5" fill={white} opacity="0.5" />
      <circle cx="122" cy="80" r="4.5" fill={white} opacity="0.5" />
      <rect x="142" y="73" width="130" height="14" rx="7" fill={white} opacity="0.35" />
      <rect x="344" y="70" width="42" height="20" rx="10" fill={white} opacity="0.22" />

      {/* sidebar */}
      <rect x="70" y="104" width="66" height="260" rx="0" fill="#f4f8f7" />
      <rect x="70" y="338" width="66" height="26" fill="#f4f8f7" />
      {[0, 1, 2, 3, 4].map((r) => (
        <g key={r}>
          <rect x="84" y={120 + r * 34} width="16" height="16" rx="6" fill={r === 0 ? "#24695c" : "#dbe7e3"} />
          <rect x="108" y={124 + r * 34} width={r === 0 ? 22 : 18} height="8" rx="4" fill={r === 0 ? "#24695c" : barSoft} />
        </g>
      ))}

      {/* KPI tiles */}
      {[0, 1].map((i) => (
        <g key={i}>
          <rect x={152 + i * 122} y={120} width="112" height="58" rx="12" fill="#fbfdfc" stroke="#e6edef" strokeWidth="1.4" />
          <rect x={164 + i * 122} y={132} width="20" height="20" rx="7" fill={i === 0 ? "url(#g-hero)" : "url(#g-hero-gold)"} />
          <rect x={192 + i * 122} y={132} width="52" height="8" rx="4" fill={bar} />
          <rect x={164 + i * 122} y={158} width={i === 0 ? 58 : 44} height="12" rx="6" fill={i === 0 ? "#24695c" : "#b8901d"} opacity="0.85" />
        </g>
      ))}

      {/* area chart */}
      <rect x="152" y="192" width="234" height="106" rx="12" fill="#fbfdfc" stroke="#e6edef" strokeWidth="1.4" />
      <path d="M166 272c26-20 44-34 66-40 30-8 48 10 74-4 24-13 48-24 66-30v72h-206z" fill="url(#g-hero-chart)" />
      <path d="M166 272c26-20 44-34 66-40 30-8 48 10 74-4 24-13 48-24 66-30" fill="none" stroke="#24695c" strokeWidth="2.6" strokeLinecap="round" />
      <circle cx="306" cy="228" r="5" fill="#24695c" stroke={white} strokeWidth="2.5" className="a-pulse d1" />
      <line x1="166" y1="284" x2="372" y2="284" stroke="#e6edef" strokeWidth="1.4" />
      {[0, 1, 2, 3, 4].map((i) => (
        <rect key={i} x={172 + i * 44} y={290} width="26" height="7" rx="3.5" fill={barSoft} />
      ))}

      {/* table rows hint */}
      {[0, 1].map((r) => (
        <g key={r}>
          <rect x="152" y={312 + r * 26} width="20" height="14" rx="5" fill={greenTint} />
          <path d={`M157 ${319 + r * 26}l3 3 6-6.5`} fill="none" stroke={green} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
          <rect x="180" y={315 + r * 26} width="120" height="8" rx="4" fill={barSoft} />
          <rect x="330" y={315 + r * 26} width="56" height="8" rx="4" fill={bar} />
        </g>
      ))}

      {/* floating notification card */}
      <g className="a-float d1">
        <rect x="408" y="84" width="132" height="78" rx="14" fill={white} filter="url(#f-hero)" />
        <circle cx="434" cy="114" r="14" fill="url(#g-hero-gold)" />
        <path d="M427 116a7 7 0 0 1 14 0c0 6 3 7.5 3 7.5h-20s3-1.5 3-7.5" fill="none" stroke={white} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
        <rect x="456" y="100" width="70" height="9" rx="4.5" fill={bar} />
        <rect x="456" y="116" width="48" height="8" rx="4" fill={barSoft} />
        <g className="a-pulse d2">
          <circle cx="524" cy="152" r="6" fill={green} />
        </g>
      </g>

      {/* floating attendance card */}
      <g className="a-float d2">
        <rect x="16" y="316" width="168" height="88" rx="14" fill={white} filter="url(#f-hero)" />
        <rect x="32" y="332" width="58" height="10" rx="5" fill={bar} />
        <circle cx="58" cy="374" r="20" fill="none" stroke="#e2f4ea" strokeWidth="8" />
        <circle cx="58" cy="374" r="20" fill="none" stroke={green} strokeWidth="8" strokeLinecap="round"
          strokeDasharray="100 126" transform="rotate(-90 58 374)" />
        {txtSafe()}
        {[0, 1, 2].map((i) => (
          <g key={i}>
            <rect x="92" y={344 + i * 18} width="10" height="10" rx="3.5" fill={greenTint} />
            {(() => (
              <path d={`M94 ${349 + i * 18}l2.5 2.5 5-5.5`} fill="none" stroke={green} strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" />
            ))()}
            <rect x="110" y={345 + i * 18} width={i === 2 ? 42 : 58} height="8" rx="4" fill={barSoft} />
          </g>
        ))}
      </g>

      {/* sparkle accents */}
      <path d="M498 300l4 10 10 4-10 4-4 10-4-10-10-4 10-4z" fill={gold} opacity="0.65" className="a-pulse d3" />
      <path d="M60 120l3 8 8 3-8 3-3 8-3-8-8-3 8-3z" fill="#24695c" opacity="0.35" className="a-pulse d1" />
    </svg>
  );

  function txtSafe() {
    return (
      <text x="58" y="379" textAnchor="middle" fontSize="10" fontWeight="800" fill="#173f37" stroke="none">
        96%
      </text>
    );
  }
}

/* Animated SVG emblem for each pricing tier — light stroke scenes that
   replace the static icon chip. Shares the feature-card motion classes. */
function PriceArt({ kind }: { kind: string }) {
  const st = {
    fill: "none",
    stroke: "currentColor",
    strokeWidth: 2.2,
    strokeLinecap: "round" as const,
    strokeLinejoin: "round" as const,
  };
  const scenes: Record<string, React.ReactNode> = {
    GOVT_SCHOOL: (
      <>
        <path d="M10 26L36 12l26 14" {...st} className="a-draw" />
        <line x1="16" y1="32" x2="16" y2="50" {...st} className="a-draw d1" />
        <line x1="26" y1="32" x2="26" y2="50" {...st} className="a-draw d2" />
        <line x1="46" y1="32" x2="46" y2="50" {...st} className="a-draw d3" />
        <line x1="56" y1="32" x2="56" y2="50" {...st} className="a-draw d4" />
        <line x1="10" y1="54" x2="62" y2="54" {...st} className="a-draw d2" />
        <line x1="36" y1="12" x2="36" y2="6" {...st} strokeWidth={1.8} />
        <path d="M36 6h7l-2.5 2.5L43 11h-7z" {...st} strokeWidth={1.8} className="a-float" />
      </>
    ),
    PRIMARY: (
      <>
        <path d="M12 20c8-4 15-4 21 0 6-4 13-4 21 0v28c-8-4-15-4-21 0-6-4-13-4-21 0z" {...st} className="a-draw" />
        <line x1="33" y1="20" x2="33" y2="48" {...st} strokeWidth={1.8} className="a-draw d1" />
        <g className="a-float">
          <path d="M46 8l7 7-12 12-8 2 2-8z" {...st} className="a-draw d2" />
          <line x1="51" y1="13" x2="44" y2="20" {...st} strokeWidth={1.6} className="a-pulse d3" />
        </g>
      </>
    ),
    HIGH_SCHOOL: (
      <>
        <path d="M10 28l26-11 26 11-26 11z" {...st} className="a-draw" />
        <path d="M22 34v9c0 4 28 4 28 0v-9" {...st} className="a-draw d1" />
        <path d="M57 30v11" {...st} className="a-swing" style={{ transformOrigin: "57px 30px" }} />
        <circle cx="57" cy="43" r="2.4" fill="currentColor" stroke="none" className="a-pulse d2" />
      </>
    ),
    PRIMARY_HIGH: (
      <>
        <rect x="9" y="28" width="17" height="28" rx="1.5" {...st} className="a-draw" />
        <rect x="38" y="14" width="21" height="42" rx="1.5" {...st} className="a-draw d1" />
        <line x1="26" y1="42" x2="38" y2="42" {...st} className="a-draw d2" />
        <circle cx="16" cy="36" r="2.2" fill="currentColor" stroke="none" className="a-pulse d1" />
        <circle cx="16" cy="45" r="2.2" fill="currentColor" stroke="none" className="a-pulse d2" />
        <circle cx="45" cy="24" r="2.2" fill="currentColor" stroke="none" className="a-pulse d3" />
        <circle cx="53" cy="24" r="2.2" fill="currentColor" stroke="none" className="a-pulse d4" />
        <circle cx="45" cy="34" r="2.2" fill="currentColor" stroke="none" className="a-pulse d2" />
        <circle cx="53" cy="34" r="2.2" fill="currentColor" stroke="none" className="a-pulse d3" />
      </>
    ),
    GOVT_COLLEGE: (
      <>
        <path d="M14 32a22 22 0 0144 0" {...st} className="a-draw" />
        <line x1="9" y1="32" x2="63" y2="32" {...st} className="a-draw d1" />
        <line x1="19" y1="38" x2="19" y2="52" {...st} className="a-draw d1" />
        <line x1="30" y1="38" x2="30" y2="52" {...st} className="a-draw d2" />
        <line x1="42" y1="38" x2="42" y2="52" {...st} className="a-draw d3" />
        <line x1="53" y1="38" x2="53" y2="52" {...st} className="a-draw d4" />
        <line x1="12" y1="56" x2="60" y2="56" {...st} className="a-draw d2" />
        <line x1="36" y1="10" x2="36" y2="5" {...st} strokeWidth={1.8} />
        <circle cx="36" cy="4" r="2" fill="currentColor" stroke="none" className="a-pulse" />
      </>
    ),
    COLLEGE_UNIV: (
      <>
        <rect x="13" y="22" width="7" height="13" rx="3.5" {...st} className="a-draw" />
        <rect x="49" y="22" width="7" height="13" rx="3.5" {...st} className="a-draw d1" />
        <line x1="20" y1="24" x2="49" y2="24" {...st} className="a-draw d1" />
        <line x1="20" y1="30" x2="49" y2="30" {...st} className="a-draw d2" />
        <line x1="20" y1="36" x2="44" y2="36" {...st} className="a-draw d3" />
        <path d="M31 38l-4 9 4-2.5 4 2.5z" {...st} strokeWidth={1.8} className="a-pulse d4" />
        <path d="M52 8l1.5 3.5L57 13l-3.5 1.5L52 18l-1.5-3.5L47 13l3.5-1.5z" {...st} strokeWidth={1.6} className="a-pulse d2" />
      </>
    ),
    COACHING: (
      <>
        <path d="M36 10a15 15 0 00-8.5 27.3V42h17v-4.7A15 15 0 0036 10z" {...st} className="a-draw" />
        <line x1="30" y1="47" x2="42" y2="47" {...st} className="a-draw d1" />
        <line x1="32" y1="52" x2="40" y2="52" {...st} className="a-draw d2" />
        <path d="M33 24l6 5m0-5l-6 5" {...st} strokeWidth={1.6} className="a-pulse d3" />
        <line x1="15" y1="20" x2="20" y2="22" {...st} strokeWidth={1.8} className="a-pulse d1" />
        <line x1="57" y1="20" x2="52" y2="22" {...st} strokeWidth={1.8} className="a-pulse d3" />
        <line x1="36" y1="4" x2="36" y2="0" {...st} strokeWidth={1.8} className="a-pulse d2" />
      </>
    ),
    MADRASHA: (
      <>
        <path d="M20 36c0-12 7-20 16-20s16 8 16 20" {...st} className="a-draw" />
        <line x1="16" y1="36" x2="56" y2="36" {...st} className="a-draw d1" />
        <line x1="36" y1="16" x2="36" y2="11" {...st} strokeWidth={1.8} />
        <circle cx="36" cy="9" r="1.8" fill="currentColor" stroke="none" className="a-pulse d2" />
        <line x1="10" y1="56" x2="10" y2="22" {...st} className="a-draw d2" />
        <circle cx="10" cy="19" r="2.4" {...st} strokeWidth={1.8} className="a-pulse d1" />
        <line x1="62" y1="56" x2="62" y2="22" {...st} className="a-draw d3" />
        <circle cx="62" cy="19" r="2.4" {...st} strokeWidth={1.8} className="a-pulse d3" />
        <line x1="16" y1="56" x2="56" y2="56" {...st} className="a-draw d2" />
        <path d="M30 56v-8a6 6 0 0112 0v8" {...st} className="a-draw d4" />
      </>
    ),
  };
  return (
    <svg viewBox="0 0 72 72" className="ems-feat-svg ems-price-svg" aria-hidden="true">
      {scenes[kind] ?? scenes.PRIMARY}
    </svg>
  );
}

export default function LandingPage() {
  const { t, locale } = useLang();
  const { data, loading } = useApi<{ categories: PricingCategoryView[] }>("/api/public/pricing");
  const [typeFilter, setTypeFilter] = useState<string>("ALL");
  const [faqOpen, setFaqOpen] = useState<number>(0);
  // billing cycle toggle + per-card selected student range (pricing reference layout)
  const [cycle, setCycle] = useState<"MONTHLY" | "YEARLY">("MONTHLY");
  const [selectedTier, setSelectedTier] = useState<Record<string, number>>({});
  const tierFor = (cat: PricingCategoryView): PricingTierView =>
    cat.tiers.find((x) => x.id === selectedTier[cat.code]) ?? cat.tiers[0];
  const selectTier = (code: string, id: number) => setSelectedTier((m) => ({ ...m, [code]: id }));

  // Referral program — the offer is advertised on the pricing cards to every
  // visitor; a visitor arriving via a subscriber's invite link (/ ?ref=CODE)
  // — or typing a code in — sees the discount applied to the prices live,
  // and the code rides along into registration.
  const [refCode, setRefCode] = useState("");
  const [refInput, setRefInput] = useState("");
  const [referral, setReferral] = useState<{ valid: boolean; discountPct: number; referrerName?: string } | null>(null);
  const [refProgramPct, setRefProgramPct] = useState(0);
  useEffect(() => {
    api<{ discountPct: number }>("/api/public/referral")
      .then((d) => setRefProgramPct(d.discountPct))
      .catch(() => undefined);
    const code = (new URLSearchParams(window.location.search).get("ref") ?? "").trim().toUpperCase();
    if (code) {
      setRefInput(code);
      validateReferral(code);
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  async function validateReferral(code: string) {
    const c = code.trim().toUpperCase();
    if (!c) {
      setRefCode("");
      setRefInput("");
      setReferral(null);
      return;
    }
    setRefCode(c);
    setRefInput(c);
    try {
      const d = await api<{ valid: boolean; discountPct: number; referrerName?: string }>(
        `/api/public/referral?code=${encodeURIComponent(c)}`
      );
      setReferral(d);
    } catch {
      setReferral({ valid: false, discountPct: 0 });
    }
  }
  const refPct = referral?.valid ? referral.discountPct : 0;
  const registerHref = refCode && referral?.valid ? `/register?ref=${encodeURIComponent(refCode)}` : "/register";
  /** price of the selected range with the referral discount applied */
  const withRef = (base: number) =>
    refPct > 0 ? Math.round(base * (1 - refPct / 100) * 100) / 100 : base;

  // demo request form
  const demoTypeOptions = [
    { value: "KG_PRIMARY", label: t.landing.demoTypeKgPrimary },
    { value: "HIGH_SCHOOL", label: t.landing.demoTypeHighSchool },
    { value: "PRIMARY_HIGH", label: t.landing.demoTypePrimaryHigh },
    { value: "COLLEGE_UNI", label: t.landing.demoTypeCollegeUni },
    { value: "COACHING", label: t.landing.demoTypeCoaching },
    { value: "MADRASHA", label: t.landing.demoTypeMadrasha },
  ];
  const [demoForm, setDemoForm] = useState({
    name: "",
    email: "",
    phone: "",
    institutionName: "",
    institutionType: "KG_PRIMARY",
    message: "",
  });
  const [demoSending, setDemoSending] = useState(false);
  const [demoDone, setDemoDone] = useState(false);
  const [demoError, setDemoError] = useState<string | null>(null);

  async function submitDemo(e: React.FormEvent) {
    e.preventDefault();
    setDemoSending(true);
    setDemoError(null);
    try {
      await api("/api/demo-request", { method: "POST", body: JSON.stringify(demoForm) });
      setDemoDone(true);
      setDemoForm({
        name: "",
        email: "",
        phone: "",
        institutionName: "",
        institutionType: "KG_PRIMARY",
        message: "",
      });
    } catch (err) {
      setDemoError(err instanceof Error ? err.message : t.landing.demoError);
    } finally {
      setDemoSending(false);
    }
  }
  // Premium header behavior — static at the top of the page; hides while
  // scrolling down, slides back with an animated glass effect on scroll-up.
  const [headerHidden, setHeaderHidden] = useState(false);
  const [headerScrolled, setHeaderScrolled] = useState(false);
  const lastScrollY = useRef(0);

  useEffect(() => {
    const onScroll = () => {
      const y = window.scrollY;
      setHeaderScrolled(y > 10);
      // hide only when genuinely scrolling down past the hero's start
      if (y > lastScrollY.current && y > 140) {
        setHeaderHidden(true);
      } else if (y < lastScrollY.current || y <= 140) {
        setHeaderHidden(false);
      }
      lastScrollY.current = y;
    };
    window.addEventListener("scroll", onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  // Scroll reveal — sections fade/slide in as they enter the viewport.
  // Re-arms on language change: switching locale remounts the reveal
  // elements (new text, new keys), so they must be observed again.
  useEffect(() => {
    const els = Array.from(document.querySelectorAll("[data-reveal]:not(.revealed)"));
    if (!("IntersectionObserver" in window)) {
      els.forEach((el) => el.classList.add("revealed"));
      return;
    }
    const io = new IntersectionObserver(
      (entries) => {
        entries.forEach((entry) => {
          if (entry.isIntersecting) {
            entry.target.classList.add("revealed");
            io.unobserve(entry.target);
          }
        });
      },
      { threshold: 0.12, rootMargin: "0px 0px -40px 0px" }
    );
    els.forEach((el) => io.observe(el));
    return () => io.disconnect();
  }, [locale]);

  const categories = useMemo(() => {
    if (!data) return [];
    if (typeFilter === "ALL") return data.categories;
    return data.categories.filter((c) => c.types.includes(typeFilter as never));
  }, [data, typeFilter]);

  return (
    <div>
      {/* ---------------- Navbar (static at top; animated hide/show on scroll) ---------------- */}
      <header className={`ems-site-header${headerScrolled ? " is-scrolled" : ""}${headerHidden ? " is-hidden" : ""}`}>
        <div className="container-fluid">
          <div className="row align-items-center py-2 m-0">
            <div className="col-auto d-flex align-items-center gap-2">
              <Link href="/" className="d-flex align-items-center gap-2 text-decoration-none">
                <IncrelogLogo size={40} />
                <div>
                  <h6 className="mb-0 f-w-800 text-dark">Increlog<span className="ems-text-teal">EMS</span></h6>
                  <p className="mb-0 ems-fs-11 text-muted d-none d-sm-block">{t.common.tagline}</p>
                </div>
              </Link>
            </div>
            <div className="col-auto d-flex align-items-center gap-2 ms-auto">
              <LanguageSwitcher />
              <Link href="/apply" className="d-none d-md-inline-block">
                <Button variant="secondary" size="sm">{t.applyPage.navLabel}</Button>
              </Link>
              <Link href="/login">
                <Button variant="secondary" size="sm">{t.common.login}</Button>
              </Link>
              <Link href={registerHref} className="d-none d-sm-inline-block ems-nav-cta">
                <Button size="sm">{t.auth.registerNow}</Button>
              </Link>
            </div>
          </div>
        </div>
      </header>
      {/* reserves the fixed header's space so the page starts below it */}
      <div className="ems-header-spacer" aria-hidden="true" />

      {/* ---------------- Hero ---------------- */}
      <section className="ems-hero pt-4 pb-5">
        <div className="container py-4">
          <div className="ems-hero-grid">
            <div className="ems-hero-copy" data-reveal>
              <span className="ems-feat-badge">
                <IconSparkle className="svg-16" />
                {t.landing.heroBadge}
              </span>
              <h1 className="ems-hero-title mt-3">{t.landing.heroTitle}</h1>
              <p className="ems-hero-sub">{t.landing.heroSubtitle}</p>
              <div className="d-flex flex-wrap gap-3 mb-4 ems-hero-cta">
                <Link href={registerHref}>
                  <Button size="lg" className="btn-grad">
                    {t.landing.getStarted}
                    <IconArrowRight className="svg-16 ms-1" />
                  </Button>
                </Link>
                <a href="#packages">
                  <Button size="lg" variant="secondary">{t.landing.viewPackages}</Button>
                </a>
              </div>
              <div className="ems-hero-stats" data-reveal style={{ "--rd": "180ms" } as React.CSSProperties}>
                {[
                  { value: "8", label: t.central.dashboard.packagePlans },
                  { value: "58", label: t.central.dashboard.academicItems },
                  { value: "24/7", label: t.landing.supportLabel },
                ].map((s, i) => (
                  <div className="ems-hero-stat" key={i}>
                    <span className="v">{s.value}</span>
                    <span className="l">{s.label}</span>
                  </div>
                ))}
              </div>
            </div>
            <div className="ems-hero-art" data-reveal style={{ "--rd": "120ms" } as React.CSSProperties}>
              <HeroArt />
            </div>
          </div>
        </div>
      </section>

      {/* ---------------- Institution types ---------------- */}
      <section id="types" className="py-4">
        <div className="container">
          <div className="text-center mb-4" data-reveal>
            <span className="ems-feat-badge">
              <IconBuilding className="svg-16" />
              {t.landing.trustedBy}
            </span>
          </div>
          <div className="row g-3 justify-content-center">
            {[
              { type: "PRIMARY_AND_HIGH_SCHOOL", cls: "tg-highschool", icon: <IconAcademic /> },
              { type: "COLLEGE_AND_UNIVERSITY", cls: "tg-college", icon: <IconLayers /> },
              { type: "COACHING", cls: "tg-coaching", icon: <IconTrend /> },
              { type: "MADRASHA", cls: "tg-madrasha", icon: <IconHome /> },
            ].map((t2, i) => (
              <div
                className="col-6 col-sm-4 col-lg"
                key={t2.type}
                data-reveal
                style={{ "--rd": `${i * 70}ms` } as React.CSSProperties}
              >
                <button
                  className={`ems-type-tile ${t2.cls}`}
                  onClick={() => {
                    setTypeFilter(t2.type);
                    document.getElementById("packages")?.scrollIntoView({ behavior: "smooth" });
                  }}
                >
                  <span className="ems-type-icon">{t2.icon}</span>
                  <span className="f-w-700 ems-fs-13 text-dark">{t.types[t2.type as keyof typeof t.types]}</span>
                </button>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* ---------------- Packages (education-pattern pricing) ---------------- */}
      <section id="packages" className="py-5 ems-bg-soft">
        <div className="container">
          <div className="text-center mb-4" data-reveal>
            <h4 className="f-w-800">{t.landing.packagesTitle}</h4>
            <p className="text-muted mb-2" style={{ maxWidth: 720, margin: "0 auto" }}>
              {t.landing.packagesSubtitle}
            </p>
            <p className="mb-0">
              <span className="ems-landing-setup-chip">
                <IconCard className="svg-16" />
                {t.landing.setupNote}
              </span>
            </p>
            <p className="mb-0 mt-2 ems-fs-12 text-muted">{t.landing.slabHint}</p>
            <p className="ems-plans-tagline mb-0 mt-1">
              <IconSparkle className="svg-14" />
              {t.landing.plansTagline}
            </p>
          </div>

          {/* Filter chips */}
          <div className="d-flex flex-wrap justify-content-center gap-2 mb-4">
            <button
              className={`btn btn-sm f-w-600 ${typeFilter === "ALL" ? "btn-primary" : "btn-outline-secondary"}`}
              onClick={() => setTypeFilter("ALL")}
            >
              {t.common.all}
            </button>
            {INSTITUTION_TYPES.map((type) => (
              <button
                key={type}
                className={`btn btn-sm f-w-600 ${typeFilter === type ? "btn-primary" : "btn-outline-secondary"}`}
                onClick={() => setTypeFilter(type)}
              >
                {t.types[type]}
              </button>
            ))}
          </div>

          {loading ? (
            <div className="row g-4 mt-2">
              {[0, 1, 2].map((i) => (
                <div className="col-md-6 col-lg-4" key={i}>
                  <div className="card h-100 p-3">
                    <Skeleton width={110} height={86} radius={14} />
                    <div className="mt-3">
                      <Skeleton width="62%" height={18} />
                    </div>
                    <div className="mt-3">
                      <Skeleton width="42%" height={28} />
                    </div>
                    <div className="mt-3">
                      <Skeleton width="45%" height={11} />
                    </div>
                    {Array.from({ length: 5 }).map((_, r) => (
                      <div className="mt-2" key={r}>
                        <Skeleton width="86%" height={10} />
                      </div>
                    ))}
                    <div className="mt-3">
                      <Skeleton width="100%" height={38} radius={999} />
                    </div>
                  </div>
                </div>
              ))}
            </div>
          ) : (
            <>
              {/* billing cycle toggle — Monthly | Yearly */}
              <div className="d-flex justify-content-center mb-4">
                <div className="ems-cycle-toggle">
                  <button
                    className={cycle === "MONTHLY" ? "on" : ""}
                    onClick={() => setCycle("MONTHLY")}
                  >
                    {t.landing.perMonth}
                  </button>
                  <button
                    className={cycle === "YEARLY" ? "on" : ""}
                    onClick={() => setCycle("YEARLY")}
                  >
                    {t.landing.perYear}
                  </button>
                </div>
              </div>

              {/* referral code — type one in or arrive via an invite link; the
                  prices on the cards below update as soon as it is validated */}
              {refProgramPct > 0 && (
                <div className="d-flex justify-content-center mb-2">
                  <div
                    className="d-inline-flex flex-wrap align-items-center gap-2 px-3 py-2"
                    style={{
                      borderRadius: 999,
                      background: "rgba(36,105,92,0.06)",
                      border: "1px dashed rgba(36,105,92,0.4)",
                    }}
                  >
                    <span className="ems-fs-12 f-w-700" style={{ color: "#24695c" }}>
                      <IconSparkle className="svg-14" />{" "}
                      {t.landing.referralOfferTitle.replace("{pct}", formatNumber(refProgramPct, locale))}
                    </span>
                    <input
                      className="form-control form-control-sm text-uppercase"
                      style={{ width: 170 }}
                      placeholder="REF-XXXXXXXX"
                      value={refInput}
                      onChange={(e) => setRefInput(e.target.value.toUpperCase())}
                      onKeyDown={(e) => {
                        if (e.key === "Enter") validateReferral(refInput);
                      }}
                    />
                    <Button size="sm" variant="primary" onClick={() => validateReferral(refInput)}>
                      {t.landing.referralApply}
                    </Button>
                  </div>
                </div>
              )}

              {/* referral code status — prices below already include it when valid */}
              {refCode && referral && (
                <div className="d-flex justify-content-center mb-2">
                  <div
                    className="d-inline-flex align-items-center gap-2 px-4 py-2"
                    style={{
                      borderRadius: 999,
                      fontSize: 13,
                      fontWeight: 600,
                      background: referral.valid ? "rgba(36,105,92,0.08)" : "rgba(220,53,69,0.07)",
                      color: referral.valid ? "#24695c" : "#a13034",
                      border: `1px dashed ${referral.valid ? "rgba(36,105,92,0.45)" : "rgba(220,53,69,0.45)"}`,
                    }}
                  >
                    {referral.valid ? (
                      <>
                        <IconSparkle className="svg-16" />
                        <span>
                          {t.landing.referralValidBanner
                            .replace("{code}", refCode)
                            .replace("{pct}", formatNumber(referral.discountPct, locale))}
                        </span>
                      </>
                    ) : (
                      <span>{t.landing.referralInvalidBanner.replace("{code}", refCode)}</span>
                    )}
                  </div>
                </div>
              )}

              <div className="row g-4 mt-2">
                {categories.map((cat) => {
                  const sel = tierFor(cat);
                  const yearlyTotal = Math.round(sel.monthlyPrice * 12 * (1 - sel.yearlyDiscount / 100));
                  const displayPrice = cycle === "MONTHLY" ? sel.monthlyPrice : yearlyTotal;
                  const refPrice = withRef(displayPrice);
                  const groupLabel: Record<string, string> = {
                    GOVERNMENT: t.central.packages.groupGovernment,
                    SCHOOLS: t.central.packages.groupSchools,
                    HIGHER: t.central.packages.groupHigher,
                    SPECIAL: t.central.packages.groupSpecial,
                  };
                  return (
                    <div className="col-md-6 col-lg-4" key={cat.code}>
                      <div className={`ems-price-card tone-${cat.tone} h-100`}>
                        <div className="ems-price-top">
                          <span className="ems-price-artwrap">
                            <PriceArt kind={cat.art} />
                          </span>
                          <span className={`ems-price-sector sector-${cat.sector.toLowerCase()}`}>
                            {cat.sector === "GOVT" ? t.central.packages.govtBadge : groupLabel[cat.group]}
                          </span>
                          <span className="ems-price-dot" />
                        </div>
                        <h5 className="ems-price-name">{locale === "bn" ? cat.nameBn : cat.name}</h5>
                        <div className="ems-price-rate">
                          {refPct > 0 && (
                            <span
                              className="amt text-muted"
                              style={{ textDecoration: "line-through", fontSize: "0.72em", opacity: 0.75 }}
                            >
                              {formatBDT(displayPrice, locale)}
                            </span>
                          )}
                          <span className="amt">{formatBDT(refPrice, locale)}</span>
                          <span className="per">/{cycle === "MONTHLY" ? t.landing.perMonth : t.landing.perYear}</span>
                        </div>
                        {refPct > 0 ? (
                          <div className="ems-price-yearly">
                            <span className="save">
                              {t.landing.referralBadge.replace("{pct}", formatNumber(refPct, locale))}
                            </span>
                          </div>
                        ) : refProgramPct > 0 ? (
                          <div className="ems-price-yearly">
                            <span
                              className="ems-fs-11 f-w-700"
                              style={{ color: "#24695c", opacity: 0.85 }}
                            >
                              ★ {t.landing.referralOfferLine.replace("{pct}", formatNumber(refProgramPct, locale))}
                            </span>
                          </div>
                        ) : null}
                        {sel.yearlyDiscount > 0 && (
                          <div className="ems-price-yearly">
                            <span className="save">
                              {t.landing.yearlySave.replace("{pct}", formatNumber(sel.yearlyDiscount, locale))}
                            </span>
                            {cycle === "YEARLY" && (
                              <span className="yr">
                                {t.landing.yearlyMonthlyEq.replace(
                                  "{amt}",
                                  formatBDT(
                                    refPct > 0
                                      ? Math.round((refPrice / 12) * 100) / 100
                                      : yearlyEffectiveMonthly(sel.monthlyPrice, sel.yearlyDiscount),
                                    locale
                                  )
                                )}
                              </span>
                            )}
                          </div>
                        )}

                        {/* student range selector */}
                        <p className="ems-tier-select-label">{t.landing.selectRange}</p>
                        <div className="ems-tier-options">
                          {cat.tiers.map((tier) => {
                            const range = tier.maxStudents
                              ? `${formatNumber(tier.minStudents, locale)}-${formatNumber(tier.maxStudents, locale)}`
                              : `${formatNumber(tier.minStudents, locale)}+`;
                            const active = tier.id === sel.id;
                            return (
                              <label
                                key={tier.id}
                                className={`ems-tier-option${active ? " selected" : ""}`}
                              >
                                <input
                                  type="radio"
                                  name={`tier-${cat.code}`}
                                  checked={active}
                                  onChange={() => selectTier(cat.code, tier.id)}
                                />
                                <span className="chk">
                                  <IconCheck className="svg-12" />
                                </span>
                                <span className="rng">
                                  {range} {t.common.students}
                                </span>
                                <span className="amt">({formatBDT(tier.monthlyPrice, locale)})</span>
                              </label>
                            );
                          })}

                          {/* beyond the largest slab — a tailored plan instead of a price */}
                          <button
                            type="button"
                            className="ems-custom-offer"
                            onClick={() => {
                              const label = locale === "bn" ? cat.nameBn : cat.name;
                              setDemoForm((f) => ({
                                ...f,
                                message: t.landing.customOfferPrefill.replace("{cat}", label),
                              }));
                              document.getElementById("demo")?.scrollIntoView({ behavior: "smooth" });
                            }}
                          >
                            <span className="rng">{t.landing.customOfferHint}</span>
                            <span className="cta">
                              {t.landing.customOfferBtn}
                              <IconArrowRight className="svg-14" />
                            </span>
                          </button>
                        </div>

                        <div className="ems-price-foot mt-auto">
                          <span className="subs">{t.landing.slabFlatNote}</span>
                          <Link href={registerHref} className="ems-price-cta">
                            {t.landing.requestThisPackage}
                            <IconArrowRight className="svg-16" />
                          </Link>
                        </div>
                      </div>
                    </div>
                  );
                })}
                {!loading && categories.length === 0 && (
                  <div className="col-12">
                    <div className="card">
                      <EmptyState title={t.common.noData} />
                    </div>
                  </div>
                )}
              </div>

              {/* pricing footnotes (pricing reference) */}
              <div className="text-center ems-fs-12 text-muted mt-4">
                <p className="mb-1">{t.landing.vatNote}</p>
                <p className="mb-0">{t.landing.addonNote}</p>
              </div>
            </>
          )}
        </div>
      </section>

      {/* ---------------- Features infographic: module map + deep dives ---------------- */}
      <section id="features" className="py-5">
        <div className="container">
          <div className="text-center mb-4">
            <span className="ems-feat-badge">
              <IconSparkle className="svg-16" />
              {t.landing.featuresNav}
            </span>
            <h4 className="f-w-800 mt-3">{t.landing.featuresTitle}</h4>
            <p className="text-muted mb-0 mx-auto" style={{ maxWidth: 660 }}>
              {t.landing.featuresSubtitle}
            </p>
          </div>

          {/* Module map — every module, grouped into five suites */}
          <div className="ems-map-panel" data-reveal>
            <div className="ems-map-head">
              <span className="ems-map-badge">
                <IconPackage className="svg-16" />
                {t.landing.mapBadge}
              </span>
              <h4 className="ems-map-title">{t.landing.mapTitle}</h4>
              <p className="ems-map-subtitle">{t.landing.mapSubtitle}</p>
            </div>
            <div className="ems-map-grid">
              {[
                {
                  icon: <IconDashboard className="svg-18" />,
                  label: t.landing.mapCore,
                  items: [t.moduleName.dashboard, t.moduleName.admission, t.moduleName.students, t.moduleName.identity, t.moduleName.controlPanel],
                },
                {
                  icon: <IconAcademic className="svg-18" />,
                  label: t.landing.mapAcademics,
                  items: [t.moduleName.academicInfo, t.moduleName.routine, t.moduleName.exams, t.moduleName.results, t.moduleName.promotions, t.moduleName.lessonPlans, t.moduleName.omr],
                },
                {
                  icon: <IconWallet className="svg-18" />,
                  label: t.landing.mapFinance,
                  items: [t.moduleName.fees, t.moduleName.accounts, t.moduleName.payroll],
                },
                {
                  icon: <IconBriefcase className="svg-18" />,
                  label: t.landing.mapCampus,
                  items: [t.moduleName.hr, t.moduleName.library, t.moduleName.hostel, t.moduleName.inventory, t.moduleName.transport],
                },
                {
                  icon: <IconBell className="svg-18" />,
                  label: t.landing.mapCommunication,
                  items: [t.moduleName.notices, t.moduleName.events, t.moduleName.committees, t.moduleName.certificates, t.moduleName.competitions, t.moduleName.messages, t.moduleName.smsPanel, t.moduleName.support],
                },
              ].map((group) => (
                <div className="ems-map-group" key={group.label}>
                  <span className="ems-map-group-head">
                    <span className="ems-map-group-icon">{group.icon}</span>
                    <span>{group.label}</span>
                  </span>
                  <div className="ems-map-chips">
                    {group.items.map((item) => (
                      <span className="ems-map-chip" key={item}>
                        <span className="dot" />
                        {item}
                      </span>
                    ))}
                  </div>
                </div>
              ))}
            </div>
            <p className="ems-map-footer mb-0">{t.landing.mapFooter}</p>
          </div>

          {/* Deep dives — compact infographic flowchart */}
          <div className="text-center mt-5 mb-4" data-reveal>
            <span className="ems-feat-badge">
              <IconMessageCircle className="svg-16" />
              {t.landing.deepBadge}
            </span>
            <h4 className="f-w-800 mt-3">{t.landing.deepTitle}</h4>
            <p className="text-muted mb-0 mx-auto" style={{ maxWidth: 620 }}>
              {t.landing.deepSubtitle}
            </p>
          </div>
          <div className="ems-flow-wrap">
            {[
              {
                icon: <IconAward />, tone: "teal",
                title: t.landing.deepResultTitle, desc: t.landing.deepResultDesc,
                bullets: t.landing.deepResultBullets,
                stat: t.landing.deepResultStat, statLabel: t.landing.deepResultStatLabel,
              },
              {
                icon: <IconUserCheck />, tone: "blue",
                title: t.landing.deepAttendanceTitle, desc: t.landing.deepAttendanceDesc,
                bullets: t.landing.deepAttendanceBullets,
                stat: t.landing.deepAttendanceStat, statLabel: t.landing.deepAttendanceStatLabel,
              },
              {
                icon: <IconWallet />, tone: "amber",
                title: t.landing.deepFeesTitle, desc: t.landing.deepFeesDesc,
                bullets: t.landing.deepFeesBullets,
                stat: t.landing.deepFeesStat, statLabel: t.landing.deepFeesStatLabel,
              },
              {
                icon: <IconClipboard />, tone: "teal",
                title: t.landing.deepAdmissionTitle, desc: t.landing.deepAdmissionDesc,
                bullets: t.landing.deepAdmissionBullets,
                stat: t.landing.deepAdmissionStat, statLabel: t.landing.deepAdmissionStatLabel,
              },
              {
                icon: <IconMessageCircle />, tone: "violet",
                title: t.landing.deepCommunicationTitle, desc: t.landing.deepCommunicationDesc,
                bullets: t.landing.deepCommunicationBullets,
                stat: t.landing.deepCommunicationStat, statLabel: t.landing.deepCommunicationStatLabel,
              },
              {
                icon: <IconBuilding />, tone: "amber",
                title: t.landing.deepCampusTitle, desc: t.landing.deepCampusDesc,
                bullets: t.landing.deepCampusBullets,
                stat: t.landing.deepCampusStat, statLabel: t.landing.deepCampusStatLabel,
              },
            ].map((row, i) => (
              <div
                className={`ems-flow-row tone-${row.tone}`}
                key={row.title}
                data-reveal
                style={{ "--rd": `${Math.min(i, 3) * 80}ms` } as React.CSSProperties}
              >
                <div className="ems-flow-node">
                  <span className="ic">{row.icon}</span>
                </div>
                <div className="ems-flow-card">
                  <div className="head">
                    <div className="txt">
                      <h5 className="t">{row.title}</h5>
                      <p className="d">{row.desc}</p>
                    </div>
                    <span className="stat">
                      <b>{row.stat}</b> {row.statLabel}
                    </span>
                  </div>
                  <ul className="chips">
                    {row.bullets.map((b, j) => (
                      <li key={j}>{b}</li>
                    ))}
                  </ul>
                </div>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* ---------------- Why ---------------- */}
      <section id="why" className="py-5">
        <div className="container">
          <div className="text-center mb-4" data-reveal>
            <span className="ems-feat-badge">
              <IconSparkle className="svg-16" />
              {t.landing.whyTitle}
            </span>
            <h4 className="f-w-800 mt-3">{t.landing.whySubtitle}</h4>
          </div>
          <div className="ems-why-panel" data-reveal>
            <div className="row g-4">
              {[
                { icon: <IconPackage />, title: t.landing.why1Title, desc: t.landing.why1Desc },
                { icon: <IconCard />, title: t.landing.why2Title, desc: t.landing.why2Desc },
                { icon: <IconAcademic />, title: t.landing.why3Title, desc: t.landing.why3Desc },
                { icon: <IconSparkle />, title: t.landing.why4Title, desc: t.landing.why4Desc },
              ].map((f, i) => (
                <div className="col-md-6 col-xl-3" key={i}>
                  <div className="ems-why-tile h-100">
                    <span className="ic">{f.icon}</span>
                    <h5>{f.title}</h5>
                    <p>{f.desc}</p>
                  </div>
                </div>
              ))}
            </div>
            <p className="ems-why-foot mb-0">{t.landing.mapFooter}</p>
          </div>
        </div>
      </section>

      {/* ---------------- FAQ ---------------- */}
      <section id="faq" className="py-5 ems-bg-soft">
        <div className="container">
          <div className="text-center mb-5" data-reveal>
            <span className="ems-feat-badge">
              <IconMessageCircle className="svg-16" />
              {t.landing.faqNav}
            </span>
            <h4 className="f-w-800 mt-3">{t.landing.faqTitle}</h4>
            <p className="text-muted mb-0 mx-auto" style={{ maxWidth: 560 }}>
              {t.landing.faqSubtitle}
            </p>
          </div>
          <div className="row justify-content-center">
            <div className="col-lg-9">
              <div className="ems-faq-list">
                {[
                  { q: t.landing.faq1Q, a: t.landing.faq1A },
                  { q: t.landing.faq2Q, a: t.landing.faq2A },
                  { q: t.landing.faq3Q, a: t.landing.faq3A },
                  { q: t.landing.faq4Q, a: t.landing.faq4A },
                  { q: t.landing.faq5Q, a: t.landing.faq5A },
                  { q: t.landing.faq6Q, a: t.landing.faq6A },
                  { q: t.landing.faq7Q, a: t.landing.faq7A },
                ].map((f, i) => (
                  <div className={`ems-faq-item${faqOpen === i ? " open" : ""}`} key={i}>
                    <button
                      type="button"
                      className="ems-faq-q"
                      onClick={() => setFaqOpen(faqOpen === i ? -1 : i)}
                      aria-expanded={faqOpen === i}
                    >
                      <span className="q">{f.q}</span>
                      <span className="ems-faq-toggle" aria-hidden="true" />
                    </button>
                    <div className="ems-faq-a">
                      <div className="inner">
                        <p className="mb-0">{f.a}</p>
                      </div>
                    </div>
                  </div>
                ))}
              </div>
            </div>
          </div>
        </div>
      </section>

      {/* ---------------- Request a demo ---------------- */}
      <section id="demo" className="py-5">
        <div className="container">
          <div className="ems-demo-panel">
            <div className="ems-demo-copy" data-reveal>
              <span className="ems-map-badge">
                <IconSparkle className="svg-16" />
                {t.landing.demoBadge}
              </span>
              <h3 className="ems-demo-title">{t.landing.demoTitle}</h3>
              <p className="ems-demo-subtitle">{t.landing.demoSubtitle}</p>
              <ul className="ems-demo-points">
                {[t.landing.demoPoint1, t.landing.demoPoint2, t.landing.demoPoint3].map((p, i) => (
                  <li key={i}>
                    <span className="chk">
                      <IconCheck className="svg-12" />
                    </span>
                    <span>{p}</span>
                  </li>
                ))}
              </ul>
            </div>
            <div className="ems-demo-form-wrap" data-reveal style={{ "--rd": "120ms" } as React.CSSProperties}>
              {demoDone && (
                <div className="mb-3">
                  <Alert type="success" onClose={() => setDemoDone(false)}>{t.landing.demoSuccess}</Alert>
                </div>
              )}
              <form className="ems-demo-form theme-form" onSubmit={submitDemo}>
                <Input
                  label={t.landing.demoName}
                  required
                  maxLength={80}
                  value={demoForm.name}
                  onChange={(e) => setDemoForm({ ...demoForm, name: e.target.value })}
                />
                <div className="row g-3">
                  <div className="col-md-6">
                    <Input
                      label={t.landing.demoEmail}
                      type="email"
                      required
                      maxLength={120}
                      value={demoForm.email}
                      onChange={(e) => setDemoForm({ ...demoForm, email: e.target.value })}
                    />
                  </div>
                  <div className="col-md-6">
                    <Input
                      label={t.landing.demoPhone}
                      maxLength={30}
                      value={demoForm.phone}
                      onChange={(e) => setDemoForm({ ...demoForm, phone: e.target.value })}
                    />
                  </div>
                </div>
                <div className="row g-3">
                  <div className="col-md-7">
                    <Input
                      label={t.landing.demoInstitution}
                      required
                      maxLength={120}
                      value={demoForm.institutionName}
                      onChange={(e) => setDemoForm({ ...demoForm, institutionName: e.target.value })}
                    />
                  </div>
                  <div className="col-md-5">
                    <Select
                      label={t.landing.demoType}
                      value={demoForm.institutionType}
                      onChange={(e) => setDemoForm({ ...demoForm, institutionType: e.target.value })}
                    >
                      {demoTypeOptions.map((o) => (
                        <option key={o.value} value={o.value}>{o.label}</option>
                      ))}
                    </Select>
                  </div>
                </div>
                <Textarea
                  label={t.landing.demoMessage}
                  rows={3}
                  maxLength={1000}
                  value={demoForm.message}
                  onChange={(e) => setDemoForm({ ...demoForm, message: e.target.value })}
                />
                <Button type="submit" className="btn-grad w-100" loading={demoSending}>
                  {t.landing.demoSubmit}
                  <IconArrowRight className="svg-16 ms-1" />
                </Button>
              </form>
            </div>
          </div>
        </div>
      </section>

      {/* ---------------- CTA ---------------- */}
      <section className="py-5">
        <div className="container">
          <div className="ems-cta text-center" data-reveal>
            <span className="deco ring r1" aria-hidden="true" />
            <span className="deco ring r2" aria-hidden="true" />
            <span className="deco dots" aria-hidden="true" />
            <h3 className="f-w-800">{t.landing.ctaTitle}</h3>
            <p className="cta-sub">{t.landing.ctaSubtitle}</p>
            <div className="d-flex flex-wrap justify-content-center gap-3 ems-hero-cta">
              <Link href={registerHref}>
                <Button size="lg" variant="light" className="f-w-700">{t.auth.createAccount}</Button>
              </Link>
              <Link href="/login">
                <Button size="lg" variant="secondary">{t.common.login}</Button>
              </Link>
            </div>
          </div>
        </div>
      </section>

      {/* ---------------- Footer ---------------- */}
      <footer className="ems-footer bg-white border-top pt-5 pb-4">
        <div className="container">
          <div className="row g-4 justify-content-center text-center">
            <div className="col-12 col-lg-4">
              {/* logo + name + tagline stay on one line from md up */}
              <div className="ems-footer-brand d-inline-flex align-items-center gap-2 mb-3">
                <IncrelogLogo size={38} />
                <h6 className="f-w-800 mb-0 text-dark">Increlog<span className="ems-text-teal">EMS</span></h6>
                <span className="ems-footer-brand-sep" />
                <p className="mb-0 ems-fs-12 text-muted">{t.common.tagline}</p>
              </div>
              <p className="ems-fs-13 text-muted mb-0 mx-auto" style={{ maxWidth: 340 }}>
                {t.landing.footerAbout}
              </p>
            </div>
            <div className="col-6 col-md-4 col-lg-2">
              <h6 className="f-w-700 ems-footer-head">{t.landing.footerQuickLinks}</h6>
              <ul className="list-unstyled ems-fs-13 ems-footer-links">
                <li><a href="#packages">{t.common.packages}</a></li>
                <li><a href="#features">{t.landing.featuresNav}</a></li>
                <li><a href="#faq">{t.landing.faqNav}</a></li>
                <li><a href="#types">{t.common.institutions}</a></li>
                <li><a href="#why">{t.landing.whyTitle}</a></li>
              </ul>
            </div>
            <div className="col-6 col-md-4 col-lg-2">
              <h6 className="f-w-700 ems-footer-head">{t.landing.footerForInstitutions}</h6>
              <ul className="list-unstyled ems-fs-13 ems-footer-links">
                <li><Link href={registerHref}>{t.auth.registerNow}</Link></li>
                <li><Link href="/login">{t.common.login}</Link></li>
                <li><Link href="/apply">{t.applyPage.navLabel}</Link></li>
              </ul>
            </div>
            <div className="col-12 col-lg-4">
              <h6 className="f-w-700 ems-footer-head">{t.landing.trustedBy}</h6>
              <div className="d-flex flex-wrap justify-content-center gap-2 ems-footer-types">
                {INSTITUTION_TYPES.map((type) => (
                  <a key={type} href="#types" className={`ems-type-pill ems-type-${type}`}>
                    {t.types[type]}
                  </a>
                ))}
              </div>
            </div>
          </div>
          <div className="ems-footer-bar d-flex flex-column flex-sm-row align-items-center justify-content-sm-between justify-content-center gap-2 mt-4 pt-3 text-center">
            <p className="ems-fs-12 text-muted mb-0">
              © {new Date().getFullYear()} IncrelogEMS — {t.landing.rights}
            </p>
            <p className="mb-0 d-inline-flex align-items-center gap-2">
              <IncrelogLogo size={22} />
              <span className="ems-fs-12 f-w-600 text-muted">{t.landing.poweredBy}</span>
            </p>
          </div>
        </div>
      </footer>
    </div>
  );
}
