// Header, search form, landing page, results page.

function Header({ lang, setLang, go, theme }) {
  return (
    <header style={{
      display: "flex", alignItems: "center", justifyContent: "space-between",
      padding: "18px 56px",
      borderBottom: "1px solid " + theme.border,
      background: theme.bg,
      position: "sticky", top: 0, zIndex: 10,
    }}>
      <button onClick={() => go("home")} style={{
        display: "flex", alignItems: "center", gap: 10,
        background: "none", border: "none", cursor: "pointer",
        fontFamily: theme.fontDisplay, fontSize: 20, fontWeight: 700, color: theme.ink,
        letterSpacing: -0.5, whiteSpace: "nowrap",
      }}>
        <Icon name="logo" size={30} color={theme.primary} />
        <span style={{ whiteSpace: "nowrap" }}>Parking Officiel<span style={{ color: theme.primary }}>.</span></span>
      </button>

      <nav style={{ display: "flex", gap: 28, alignItems: "center", fontSize: 14, color: theme.inkMuted }}>
        <a href="#" onClick={(e) => { e.preventDefault(); go("parkings"); }} style={{ color: theme.inkMuted, textDecoration: "none", cursor: "pointer", whiteSpace: "nowrap" }}>{lang === "fr" ? "Nos parkings" : "Our parkings"}</a>
        <a href="#" onClick={(e) => { e.preventDefault(); go("services"); }} style={{ color: theme.inkMuted, textDecoration: "none", cursor: "pointer", whiteSpace: "nowrap" }}>{lang === "fr" ? "Services" : "Services"}</a>
        <a href="#" onClick={(e) => { e.preventDefault(); go("contact"); }} style={{ color: theme.inkMuted, textDecoration: "none", cursor: "pointer", whiteSpace: "nowrap" }}>{lang === "fr" ? "Contact" : "Contact"}</a>

        {/* Clickable phone */}
        <a href="tel:+33123456789" style={{
          display: "inline-flex", alignItems: "center", gap: 7,
          color: theme.ink, textDecoration: "none",
          padding: "7px 14px", borderRadius: 999,
          border: "1px solid " + theme.border,
          fontSize: 13, fontWeight: 600, whiteSpace: "nowrap",
          transition: "all .15s ease",
        }}
        onMouseOver={e => { e.currentTarget.style.background = theme.primaryBg; e.currentTarget.style.borderColor = theme.primary; e.currentTarget.style.color = theme.primary; }}
        onMouseOut={e => { e.currentTarget.style.background = "transparent"; e.currentTarget.style.borderColor = theme.border; e.currentTarget.style.color = theme.ink; }}
        >
          <Icon name="phone" size={13}/> 01 23 45 67 89
        </a>

        <div style={{
          display: "inline-flex", borderRadius: 999, background: theme.chip, padding: 2,
          fontSize: 12, fontWeight: 600,
        }}>
          {["fr", "en"].map(l => (
            <button key={l} onClick={() => setLang(l)} style={{
              border: "none", cursor: "pointer",
              padding: "4px 10px", borderRadius: 999,
              background: lang === l ? theme.bg : "transparent",
              color: lang === l ? theme.ink : theme.inkMuted,
              boxShadow: lang === l ? "0 1px 2px rgba(0,0,0,0.05)" : "none",
            }}>{l.toUpperCase()}</button>
          ))}
        </div>

        <button style={{
          background: theme.ink, color: theme.bg, border: "none", borderRadius: 999,
          padding: "9px 16px", fontSize: 13, fontWeight: 600, cursor: "pointer",
        }}>{lang === "fr" ? "Mon compte" : "My account"}</button>
      </nav>
    </header>
  );
}

function SearchForm({ search, setSearch, onSubmit, lang, theme, compact = false }) {
  const t = COPY[lang];
  const airports = [
    { code: "CDG", name: "Paris Charles de Gaulle", sub: "Roissy" },
    { code: "ORY", name: "Paris Orly", sub: "Orly" },
  ];

  return (
    <form onSubmit={(e) => { e.preventDefault(); onSubmit(); }} style={{
      display: "grid",
      gridTemplateColumns: compact ? "1.3fr 1fr 1fr auto" : "1.3fr 1fr 1fr auto",
      gap: 0,
      background: theme.bg,
      border: "1px solid " + theme.border,
      borderRadius: compact ? 14 : 18,
      padding: compact ? 6 : 8,
      boxShadow: compact ? "0 1px 3px rgba(10,20,40,0.04)" : "0 20px 60px -20px rgba(10,30,60,0.25), 0 2px 6px rgba(10,30,60,0.05)",
      alignItems: "stretch",
    }}>
      {/* Airport */}
      <div style={{ padding: "12px 18px", borderRight: "1px solid " + theme.border }}>
        <div style={{ fontSize: 10, fontWeight: 700, textTransform: "uppercase", letterSpacing: 0.8, color: theme.inkMuted, marginBottom: 6 }}>
          {t.airport}
        </div>
        <div style={{ display: "flex", gap: 8 }}>
          {airports.map(a => (
            <button type="button" key={a.code} onClick={() => setSearch({ ...search, airport: a.code })} style={{
              flex: 1, textAlign: "left",
              background: search.airport === a.code ? theme.primaryBg : "transparent",
              border: "1px solid " + (search.airport === a.code ? theme.primary : theme.border),
              color: search.airport === a.code ? theme.primary : theme.ink,
              borderRadius: 10, padding: "8px 10px", cursor: "pointer",
              display: "flex", alignItems: "center", gap: 8, fontSize: 13, fontWeight: 600,
            }}>
              <Icon name="plane" size={16} />
              <div style={{ lineHeight: 1.1 }}>
                <div style={{ fontWeight: 700 }}>{a.code}</div>
                <div style={{ fontSize: 10, fontWeight: 500, opacity: 0.7 }}>{a.sub}</div>
              </div>
            </button>
          ))}
        </div>
      </div>

      {/* From */}
      <DateField label={t.from} iconName="calendar" value={search.from} onChange={(v) => setSearch({ ...search, from: v })} time={search.fromTime} onTimeChange={(v) => setSearch({ ...search, fromTime: v })} theme={theme} />
      <DateField label={t.to} iconName="calendar" value={search.to} onChange={(v) => setSearch({ ...search, to: v })} time={search.toTime} onTimeChange={(v) => setSearch({ ...search, toTime: v })} theme={theme} />

      <div style={{ display: "flex", alignItems: "stretch", padding: 4 }}>
        <button type="submit" style={{
          background: theme.primary, color: "#fff", border: "none", borderRadius: 12,
          padding: "0 28px", fontSize: 15, fontWeight: 700, cursor: "pointer",
          display: "flex", alignItems: "center", gap: 10,
        }}>
          <Icon name="search" size={18} />
          {t.search}
        </button>
      </div>
    </form>
  );
}

function DateField({ label, iconName, value, onChange, time, onTimeChange, theme }) {
  return (
    <div style={{ padding: "12px 18px", borderRight: "1px solid " + theme.border }}>
      <div style={{ fontSize: 10, fontWeight: 700, textTransform: "uppercase", letterSpacing: 0.8, color: theme.inkMuted, marginBottom: 6 }}>
        {label}
      </div>
      <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
        <Icon name={iconName} size={16} color={theme.inkMuted} />
        <input type="date" value={value} onChange={(e) => onChange(e.target.value)} style={{
          border: "none", outline: "none", background: "transparent",
          fontFamily: "inherit", fontSize: 14, fontWeight: 600, color: theme.ink,
          width: 132, padding: 0,
        }}/>
        <input type="time" value={time} onChange={(e) => onTimeChange(e.target.value)} style={{
          border: "none", outline: "none", background: "transparent",
          fontFamily: "inherit", fontSize: 14, fontWeight: 600, color: theme.ink,
          width: 86, padding: 0,
        }}/>
      </div>
    </div>
  );
}

// --- LANDING PAGE ---
function Landing({ lang, search, setSearch, go, theme }) {
  const t = COPY[lang];

  return (
    <div>
      {/* HERO */}
      <section style={{
        position: "relative", overflow: "hidden",
        padding: "60px 56px 100px",
        background: `linear-gradient(180deg, ${theme.primaryBg} 0%, ${theme.bg} 100%)`,
      }}>
        {/* decorative flight path */}
        <svg width="600" height="300" viewBox="0 0 600 300" style={{ position: "absolute", right: -40, top: 20, opacity: 0.25 }}>
          <path d="M20 250 C 140 140, 300 80, 580 30" stroke={theme.primary} strokeWidth="1.5" fill="none" strokeDasharray="4 6"/>
          <circle cx="580" cy="30" r="4" fill={theme.primary}/>
          <circle cx="20" cy="250" r="3" fill={theme.primary}/>
        </svg>

        <div style={{ maxWidth: 900, position: "relative" }}>
          <div style={{
            display: "inline-flex", alignItems: "center", gap: 8,
            background: theme.bg, border: "1px solid " + theme.border,
            padding: "6px 12px", borderRadius: 999,
            fontSize: 12, color: theme.inkMuted, marginBottom: 20, fontWeight: 500,
          }}>
            <span style={{ width: 6, height: 6, borderRadius: 3, background: "oklch(0.65 0.15 145)" }}/>
            {lang === "fr" ? "+12 000 voyageurs nous font confiance chaque mois" : "+12,000 travelers trust us every month"}
          </div>
          <h1 style={{
            fontFamily: theme.fontDisplay, fontSize: 56, lineHeight: 1.05,
            fontWeight: 700, color: theme.ink, margin: "0 0 16px",
            letterSpacing: -1.5, textWrap: "balance",
          }}>{t.heroTitle}</h1>
          <p style={{ fontSize: 17, color: theme.inkMuted, margin: "0 0 36px", maxWidth: 560, lineHeight: 1.5 }}>
            {t.heroSub}
          </p>
        </div>

        <div style={{ position: "relative", maxWidth: 1040 }}>
          <SearchForm search={search} setSearch={setSearch} onSubmit={() => go("results")} lang={lang} theme={theme}/>
        </div>
      </section>

      {/* POPULAR OFFERS — horizontal carousel */}
      <section style={{ padding: "60px 0 60px 56px", overflow: "hidden" }}>
        <div style={{ paddingRight: 56 }}>
          <ParkingCarousel lang={lang} theme={theme} go={go} setSearch={setSearch} title={t.popularOffers}/>
        </div>
      </section>

      {/* BENEFITS */}
      <section style={{ padding: "40px 56px 60px", background: theme.subtle }}>
        <SectionHead title={t.whyUs} theme={theme} lang={lang}/>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 32, marginTop: 28 }}>
          {t.benefits.map((b, i) => (
            <div key={i} style={{ display: "flex", flexDirection: "column", gap: 10 }}>
              <div style={{
                width: 44, height: 44, borderRadius: 12,
                background: theme.primaryBg, color: theme.primary,
                display: "flex", alignItems: "center", justifyContent: "center",
              }}>
                <Icon name={["check", "shield", "shuttle"][i]} size={22}/>
              </div>
              <div style={{ fontFamily: theme.fontDisplay, fontSize: 18, fontWeight: 600, color: theme.ink }}>{b.t}</div>
              <div style={{ fontSize: 14, color: theme.inkMuted, lineHeight: 1.5 }}>{b.d}</div>
            </div>
          ))}
        </div>
      </section>

      {/* HOW IT WORKS */}
      <section style={{ padding: "60px 56px" }}>
        <SectionHead title={t.howItWorks} theme={theme} lang={lang}/>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 24, marginTop: 28 }}>
          {t.steps.map((s, i) => (
            <div key={i} style={{
              border: "1px solid " + theme.border, borderRadius: 16, padding: 24,
              background: theme.bg,
            }}>
              <div style={{
                fontFamily: theme.fontDisplay, fontWeight: 700, fontSize: 32, color: theme.primary,
                marginBottom: 12, letterSpacing: -1,
              }}>0{i + 1}</div>
              <div style={{ fontFamily: theme.fontDisplay, fontSize: 18, fontWeight: 600, color: theme.ink, marginBottom: 6 }}>{s.t}</div>
              <div style={{ fontSize: 14, color: theme.inkMuted, lineHeight: 1.5 }}>{s.d}</div>
            </div>
          ))}
        </div>
      </section>

      <Footer lang={lang} theme={theme} />
    </div>
  );
}

function SectionHead({ title, lang, theme }) {
  return (
    <div style={{ display: "flex", alignItems: "baseline", justifyContent: "space-between", gap: 20 }}>
      <h2 style={{
        fontFamily: theme.fontDisplay, fontSize: 28, fontWeight: 700, color: theme.ink, margin: 0,
        letterSpacing: -0.8,
      }}>{title}</h2>
    </div>
  );
}

function MiniCard({ parking, seed, lang, theme, onClick }) {
  return (
    <button onClick={onClick} style={{
      textAlign: "left", cursor: "pointer", background: theme.bg,
      border: "1px solid " + theme.border, borderRadius: 16, overflow: "hidden",
      padding: 0, display: "block", width: "100%",
    }}>
      <div style={{ position: "relative" }}>
        <PlaceholderImage seed={seed + 10} label="parking photo" height={160} rounded={0}/>
        {parking.premium && (
          <div style={{ position: "absolute", top: 12, left: 12 }}>
            <BadgeFor kind="premium" lang={lang}/>
          </div>
        )}
      </div>
      <div style={{ padding: 18 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 12, color: theme.inkMuted, marginBottom: 6 }}>
          <Icon name="pin" size={12}/> {parking.airport === "CDG" ? "Roissy-CDG" : "Paris-Orly"} · {parking.distanceKm} km
        </div>
        <div style={{ fontFamily: theme.fontDisplay, fontSize: 18, fontWeight: 600, color: theme.ink, marginBottom: 8 }}>{parking.name}</div>
        <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 12 }}>
          <Stars value={parking.rating}/>
          <span style={{ fontSize: 12, color: theme.inkMuted }}>{parking.rating} · {parking.reviews.toLocaleString(lang)}</span>
        </div>
        <div style={{ display: "flex", alignItems: "baseline", justifyContent: "space-between" }}>
          <div>
            <span style={{ fontFamily: theme.fontDisplay, fontSize: 22, fontWeight: 700, color: theme.ink }}>€{parking.pricePerDay.toFixed(2)}</span>
            <span style={{ fontSize: 12, color: theme.inkMuted }}> {COPY[lang].perDay}</span>
          </div>
          <span style={{ fontSize: 13, color: theme.primary, fontWeight: 600, display: "flex", alignItems: "center", gap: 4 }}>
            {COPY[lang].viewDetails} <Icon name="arrow" size={14}/>
          </span>
        </div>
      </div>
    </button>
  );
}

function Footer({ lang, theme }) {
  return (
    <footer style={{
      borderTop: "1px solid " + theme.border, background: theme.subtle,
      color: theme.inkMuted, fontSize: 13,
    }}>
      {/* Top: brand + columns */}
      <div style={{
        padding: "44px 56px 32px",
        display: "grid", gridTemplateColumns: "1.4fr 1fr 1fr 1fr", gap: 40, alignItems: "start",
      }}>
        {/* Brand + address + phone */}
        <div>
          <div style={{
            display: "flex", alignItems: "center", gap: 10,
            fontFamily: theme.fontDisplay, fontSize: 20, fontWeight: 700, color: theme.ink,
            letterSpacing: -0.5, marginBottom: 14,
          }}>
            <Icon name="logo" size={26} color={theme.primary} />
            <span>Parking Officiel<span style={{ color: theme.primary }}>.</span></span>
          </div>
          <div style={{ lineHeight: 1.6, color: theme.inkMuted, marginBottom: 14 }}>
            <div style={{ display: "flex", alignItems: "flex-start", gap: 8 }}>
              <span style={{ marginTop: 2, color: theme.primary }}><Icon name="pin" size={14}/></span>
              <span>
                12 rue des Aviateurs<br/>
                95700 Roissy-en-France<br/>
                France
              </span>
            </div>
          </div>
          <a href="tel:+33123456789" style={{
            display: "inline-flex", alignItems: "center", gap: 7,
            color: theme.ink, textDecoration: "none", fontWeight: 600,
            padding: "8px 12px", borderRadius: 10,
            border: "1px solid " + theme.border, background: theme.bg,
          }}>
            <Icon name="phone" size={14} color={theme.primary}/> +33 1 23 45 67 89
          </a>
        </div>

        {/* Nav */}
        <FooterCol title={lang === "fr" ? "Société" : "Company"} theme={theme}>
          <FooterLink onClick={() => window.__goto && window.__goto("services")} theme={theme}>{lang === "fr" ? "Nos services" : "Our services"}</FooterLink>
          <FooterLink onClick={() => window.__goto && window.__goto("parkings")} theme={theme}>{lang === "fr" ? "Nos parkings" : "Our parkings"}</FooterLink>
          <FooterLink onClick={() => window.__goto && window.__goto("contact")} theme={theme}>Contact</FooterLink>
        </FooterCol>

        <FooterCol title={lang === "fr" ? "Légal" : "Legal"} theme={theme}>
          <FooterLink onClick={() => window.__goto && window.__goto("legal")} theme={theme}>{lang === "fr" ? "Mentions légales" : "Legal notices"}</FooterLink>
          <FooterLink onClick={() => window.__goto && window.__goto("terms")} theme={theme}>{lang === "fr" ? "CGV" : "Terms"}</FooterLink>
          <FooterLink theme={theme}>{lang === "fr" ? "Gestion des cookies" : "Cookie settings"}</FooterLink>
          <FooterLink theme={theme}>{lang === "fr" ? "Politique de confidentialité" : "Privacy policy"}</FooterLink>
        </FooterCol>

        {/* Paiement + Assurance */}
        <div>
          <div style={{ fontSize: 11, fontWeight: 700, color: theme.ink, letterSpacing: 0.6, textTransform: "uppercase", marginBottom: 14 }}>
            {lang === "fr" ? "Paiement sécurisé" : "Secure payment"}
          </div>
          <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginBottom: 18 }}>
            <PayBadge kind="visa" theme={theme}/>
            <PayBadge kind="mc" theme={theme}/>
            <PayBadge kind="amex" theme={theme}/>
            <PayBadge kind="apple" theme={theme}/>
            <PayBadge kind="google" theme={theme}/>
            <PayBadge kind="stripe" theme={theme}/>
          </div>

          <div style={{ fontSize: 11, fontWeight: 700, color: theme.ink, letterSpacing: 0.6, textTransform: "uppercase", marginBottom: 10 }}>
            {lang === "fr" ? "Assuré par" : "Insured by"}
          </div>
          <div style={{
            display: "inline-flex", alignItems: "center", gap: 10,
            background: theme.bg, border: "1px solid " + theme.border,
            borderRadius: 10, padding: "8px 12px",
          }}>
            <AxaLogo/>
            <div style={{ lineHeight: 1.2 }}>
              <div style={{ fontSize: 12, fontWeight: 700, color: theme.ink }}>AXA Assurance</div>
              <div style={{ fontSize: 11, color: theme.inkMuted }}>{lang === "fr" ? "Garantie dommages" : "Damage coverage"}</div>
            </div>
          </div>
        </div>
      </div>

      {/* Bottom bar */}
      <div style={{
        padding: "16px 56px", borderTop: "1px solid " + theme.border,
        display: "flex", justifyContent: "space-between", alignItems: "center", gap: 20, flexWrap: "wrap",
        fontSize: 12, color: theme.inkMuted,
      }}>
        <span>© 2026 Parking Officiel SAS — {lang === "fr" ? "Tous droits réservés" : "All rights reserved"} · RCS Paris 912 345 678</span>
        <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>
          <Icon name="shield" size={12} color={theme.primary}/>
          {lang === "fr" ? "Paiement 100% sécurisé · 3D Secure · PCI DSS" : "100% secure payment · 3D Secure · PCI DSS"}
        </span>
      </div>
    </footer>
  );
}

function FooterCol({ title, children, theme }) {
  return (
    <div>
      <div style={{ fontSize: 11, fontWeight: 700, color: theme.ink, letterSpacing: 0.6, textTransform: "uppercase", marginBottom: 14 }}>{title}</div>
      <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>{children}</div>
    </div>
  );
}

function FooterLink({ children, onClick, theme }) {
  return (
    <a href="#" onClick={(e) => { e.preventDefault(); onClick && onClick(); }} style={{
      color: theme.inkMuted, textDecoration: "none", cursor: "pointer",
      transition: "color .15s ease",
    }}
    onMouseOver={e => e.currentTarget.style.color = theme.ink}
    onMouseOut={e => e.currentTarget.style.color = theme.inkMuted}
    >{children}</a>
  );
}

function PayBadge({ kind, theme }) {
  const style = {
    width: 46, height: 30, borderRadius: 6,
    background: theme.bg, border: "1px solid " + theme.border,
    display: "inline-flex", alignItems: "center", justifyContent: "center",
    fontSize: 9, fontWeight: 800, color: theme.ink, letterSpacing: -0.2,
  };
  if (kind === "visa") return <span style={{ ...style, color: "#1a1f71", fontFamily: "Georgia, serif", fontStyle: "italic", fontWeight: 900, fontSize: 13 }}>VISA</span>;
  if (kind === "mc") return (
    <span style={style}>
      <svg viewBox="0 0 46 30" width="46" height="30">
        <circle cx="19" cy="15" r="7" fill="#eb001b"/>
        <circle cx="27" cy="15" r="7" fill="#f79e1b" opacity="0.9"/>
        <path d="M23 10a7 7 0 0 0 0 10 7 7 0 0 0 0-10z" fill="#ff5f00"/>
      </svg>
    </span>
  );
  if (kind === "amex") return <span style={{ ...style, background: "#006fcf", color: "#fff", fontSize: 8, fontWeight: 800 }}>AMEX</span>;
  if (kind === "apple") return (
    <span style={style}>
      <svg viewBox="0 0 24 24" width="14" height="14" fill="#000">
        <path d="M17.05 11.97c-.02-2.18 1.78-3.24 1.86-3.29-1.02-1.49-2.6-1.69-3.16-1.71-1.34-.14-2.63.79-3.31.79-.69 0-1.74-.77-2.87-.75-1.47.02-2.84.86-3.6 2.18-1.55 2.68-.39 6.64 1.1 8.82.73 1.07 1.59 2.26 2.72 2.22 1.09-.04 1.5-.7 2.82-.7 1.31 0 1.68.7 2.83.68 1.17-.02 1.91-1.08 2.62-2.16.83-1.23 1.17-2.44 1.19-2.5-.03-.01-2.27-.87-2.3-3.46zm-2.18-6.36c.6-.73 1-1.74.89-2.75-.86.03-1.91.57-2.53 1.29-.55.64-1.04 1.67-.91 2.66.96.07 1.94-.49 2.55-1.2z"/>
      </svg>
      <span style={{ marginLeft: 2, fontSize: 9, fontWeight: 700 }}>Pay</span>
    </span>
  );
  if (kind === "google") return <span style={{ ...style, fontSize: 9, fontWeight: 700, color: "#3c4043" }}>G Pay</span>;
  if (kind === "stripe") return <span style={{ ...style, color: "#635bff", fontSize: 10, fontWeight: 800, letterSpacing: -0.3 }}>stripe</span>;
  return null;
}

function AxaLogo() {
  // AXA is an iconic wordmark — red/black, flat-chiseled A.
  return (
    <span style={{
      background: "#00008f",
      color: "#fff",
      fontFamily: "Arial, Helvetica, sans-serif",
      fontWeight: 900, fontSize: 14, letterSpacing: -0.5,
      padding: "5px 8px", borderRadius: 4,
      display: "inline-flex", alignItems: "center",
      textTransform: "uppercase",
    }}>
      <span style={{ color: "#ff1721" }}>AXA</span>
    </span>
  );
}

function ParkingCarousel({ lang, theme, go, setSearch, title }) {
  const scrollerRef = React.useRef(null);
  const [tab, setTab] = React.useState("all"); // all | CDG | ORY
  const [paused, setPaused] = React.useState(false);

  const list = React.useMemo(() => {
    if (tab === "all") return PARKINGS;
    return PARKINGS.filter(p => p.airport === tab);
  }, [tab]);

  const scrollBy = (dir) => {
    const el = scrollerRef.current;
    if (!el) return;
    el.scrollBy({ left: dir * 320, behavior: "smooth" });
  };

  // Auto-scroll: nudge right by one card every 3s when not paused.
  // Loop back to start when reaching end.
  React.useEffect(() => {
    if (paused) return;
    const el = scrollerRef.current;
    if (!el) return;
    const id = setInterval(() => {
      if (!el) return;
      const nearEnd = el.scrollLeft + el.clientWidth >= el.scrollWidth - 4;
      if (nearEnd) {
        el.scrollTo({ left: 0, behavior: "smooth" });
      } else {
        el.scrollBy({ left: 318, behavior: "smooth" });
      }
    }, 3200);
    return () => clearInterval(id);
  }, [paused, tab]);

  return (
    <div onMouseEnter={() => setPaused(true)} onMouseLeave={() => setPaused(false)}>
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16, marginBottom: 22, paddingRight: 0 }}>
        <div style={{ display: "flex", alignItems: "baseline", gap: 18 }}>
          <h2 style={{ fontFamily: theme.fontDisplay, fontSize: 28, fontWeight: 700, color: theme.ink, margin: 0, letterSpacing: -0.8 }}>{title}</h2>
          <div style={{ display: "inline-flex", background: theme.subtle, padding: 3, borderRadius: 999, fontSize: 12 }}>
            {[
              { id: "all", label: lang === "fr" ? "Tous" : "All" },
              { id: "CDG", label: "CDG" },
              { id: "ORY", label: "Orly" },
            ].map(o => (
              <button key={o.id} onClick={() => setTab(o.id)} style={{
                border: "none", borderRadius: 999, padding: "5px 12px", cursor: "pointer",
                background: tab === o.id ? theme.bg : "transparent",
                color: tab === o.id ? theme.ink : theme.inkMuted,
                fontWeight: 600,
                boxShadow: tab === o.id ? "0 1px 2px rgba(0,0,0,0.06)" : "none",
              }}>{o.label}</button>
            ))}
          </div>
          <span style={{ fontSize: 11, color: theme.inkMuted, display: "inline-flex", alignItems: "center", gap: 5 }}>
            <span style={{ width: 6, height: 6, borderRadius: 3, background: paused ? theme.inkMuted : "oklch(0.65 0.15 145)" }}/>
            {paused ? (lang === "fr" ? "en pause" : "paused") : (lang === "fr" ? "défilement auto" : "auto-scroll")}
          </span>
        </div>
        <div style={{ display: "flex", gap: 8 }}>
          <CarouselBtn theme={theme} dir="left" onClick={() => scrollBy(-1)}/>
          <CarouselBtn theme={theme} dir="right" onClick={() => scrollBy(1)}/>
        </div>
      </div>

      <div ref={scrollerRef} style={{
        display: "flex", gap: 18, overflowX: "auto", scrollSnapType: "x mandatory",
        paddingBottom: 10, scrollPaddingLeft: 0,
        scrollbarWidth: "none", msOverflowStyle: "none",
      }}>
        <style>{`div::-webkit-scrollbar{display:none}`}</style>
        {list.map((p, i) => (
          <div key={p.id} style={{ flex: "0 0 300px", scrollSnapAlign: "start" }}>
            <MiniCard parking={p} seed={i + 1} lang={lang} theme={theme}
              onClick={() => { setSearch(s => ({ ...s, airport: p.airport })); go("detail", p.id); }}/>
          </div>
        ))}
      </div>
    </div>
  );
}

function CarouselBtn({ theme, dir, onClick }) {
  return (
    <button onClick={onClick} style={{
      width: 40, height: 40, borderRadius: 999, border: "1px solid " + theme.border,
      background: theme.bg, color: theme.ink, cursor: "pointer",
      display: "flex", alignItems: "center", justifyContent: "center",
      transition: "all .15s ease",
    }}
    onMouseOver={e => { e.currentTarget.style.background = theme.subtle; }}
    onMouseOut={e => { e.currentTarget.style.background = theme.bg; }}
    >
      <span style={{ display: "inline-flex", transform: dir === "left" ? "rotate(180deg)" : "none" }}>
        <Icon name="chevron" size={16} color={theme.ink}/>
      </span>
    </button>
  );
}

Object.assign(window, { Header, SearchForm, Landing, SectionHead, MiniCard, Footer, ParkingCarousel });
