// BookingModal — multi-step booking flow. Composes Input, Select, Button, Badge.
const { Input, Select, Button, Badge } = window.BluePhoenixDesignSystem_f91d3d;

const BP_DIAL_CODES = [
  { c: "US", n: "United States", d: "+1" },
  { c: "MX", n: "Mexico", d: "+52" },
  { c: "CA", n: "Canada", d: "+1" },
  { c: "GB", n: "United Kingdom", d: "+44" },
  { c: "AU", n: "Australia", d: "+61" },
  { c: "AR", n: "Argentina", d: "+54" },
  { c: "BS", n: "Bahamas", d: "+1-242" },
  { c: "BZ", n: "Belize", d: "+501" },
  { c: "BR", n: "Brazil", d: "+55" },
  { c: "CL", n: "Chile", d: "+56" },
  { c: "CN", n: "China", d: "+86" },
  { c: "CO", n: "Colombia", d: "+57" },
  { c: "CR", n: "Costa Rica", d: "+506" },
  { c: "DO", n: "Dominican Republic", d: "+1-809" },
  { c: "EC", n: "Ecuador", d: "+593" },
  { c: "SV", n: "El Salvador", d: "+503" },
  { c: "FR", n: "France", d: "+33" },
  { c: "DE", n: "Germany", d: "+49" },
  { c: "GT", n: "Guatemala", d: "+502" },
  { c: "HN", n: "Honduras", d: "+504" },
  { c: "IN", n: "India", d: "+91" },
  { c: "IE", n: "Ireland", d: "+353" },
  { c: "IT", n: "Italy", d: "+39" },
  { c: "JM", n: "Jamaica", d: "+1-876" },
  { c: "JP", n: "Japan", d: "+81" },
  { c: "NL", n: "Netherlands", d: "+31" },
  { c: "NZ", n: "New Zealand", d: "+64" },
  { c: "NI", n: "Nicaragua", d: "+505" },
  { c: "PA", n: "Panama", d: "+507" },
  { c: "PE", n: "Peru", d: "+51" },
  { c: "PH", n: "Philippines", d: "+63" },
  { c: "PT", n: "Portugal", d: "+351" },
  { c: "PR", n: "Puerto Rico", d: "+1-787" },
  { c: "ES", n: "Spain", d: "+34" },
  { c: "CH", n: "Switzerland", d: "+41" },
  { c: "VE", n: "Venezuela", d: "+58" },
];

function DialCodePicker({ value, onChange }) {
  const [open, setOpen] = React.useState(false);
  const [q, setQ] = React.useState("");
  const ref = React.useRef(null);
  React.useEffect(() => {
    if (!open) return;
    const h = e => { if (ref.current && !ref.current.contains(e.target)) setOpen(false); };
    document.addEventListener("mousedown", h);
    return () => document.removeEventListener("mousedown", h);
  }, [open]);
  const pinned = BP_DIAL_CODES.slice(0, 2);
  const rest = BP_DIAL_CODES.slice(2).filter(o => !q || o.n.toLowerCase().includes(q.toLowerCase()) || o.d.includes(q));
  const shown = q ? pinned.filter(o => o.n.toLowerCase().includes(q.toLowerCase()) || o.d.includes(q)).concat(rest) : null;
  const flag = (o, size) => <img src={`https://flagcdn.com/w40/${o.c.toLowerCase()}.png`} alt="" width={size} style={{ borderRadius: 2, boxShadow: "0 0 0 1px var(--border-subtle)", flexShrink: 0 }} />;
  const itemStyle = { display: "flex", alignItems: "center", gap: 10, padding: "8px 12px", cursor: "pointer", fontSize: 13, color: "var(--text-body)" };
  const renderItem = o => (
    <div key={o.c} onClick={() => { onChange(o); setOpen(false); setQ(""); }} style={itemStyle}
      onMouseEnter={e => e.currentTarget.style.background = "var(--surface-inset)"}
      onMouseLeave={e => e.currentTarget.style.background = "transparent"}>
      {flag(o, 22)}<span style={{ flex: 1 }}>{o.n}</span><span style={{ fontFamily: "var(--font-mono)", color: "var(--text-muted)" }}>{o.d}</span>
    </div>
  );
  return (
    <div ref={ref} style={{ position: "relative", flexShrink: 0 }}>
      <div style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 11, letterSpacing: ".08em", textTransform: "uppercase", color: "var(--text-muted)", marginBottom: 6 }}>Code</div>
      <button type="button" onClick={() => setOpen(!open)} style={{ display: "flex", alignItems: "center", gap: 6, height: 42, padding: "0 12px", background: "var(--surface-inset)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-sm)", color: "var(--text-body)", fontFamily: "var(--font-mono)", fontSize: 13, cursor: "pointer" }}>
        {flag(value, 20)}{value.d}<span style={{ fontSize: 9, color: "var(--text-muted)" }}>▾</span>
      </button>
      {open && (
        <div style={{ position: "absolute", bottom: "100%", left: 0, marginBottom: 6, width: 260, maxHeight: 280, overflowY: "auto", background: "var(--surface-card)", border: "1px solid var(--border-strong)", borderRadius: "var(--radius-md)", boxShadow: "var(--shadow-lg)", zIndex: 20 }}>
          <div style={{ position: "sticky", top: 0, background: "var(--surface-card)", padding: 8, borderBottom: "1px solid var(--border-subtle)" }}>
            <input autoFocus value={q} onChange={e => setQ(e.target.value)} placeholder="Search country…" style={{ width: "100%", boxSizing: "border-box", height: 32, padding: "0 10px", background: "var(--surface-inset)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-sm)", color: "var(--text-body)", fontSize: 13, outline: "none" }} />
          </div>
          {shown ? (shown.length ? shown.map(renderItem) : <div style={{ padding: "12px", fontSize: 13, color: "var(--text-muted)" }}>No matches</div>) : <>
            {pinned.map(renderItem)}
            <div style={{ padding: "8px 12px", fontSize: 12, color: "var(--text-muted)" }}>Search for other countries…</div>
          </>}
        </div>
      )}
    </div>
  );
}

function DatePicker({ value, onChange }) {
  const today = new Date(); today.setHours(0,0,0,0);
  const maxDate = new Date(today.getFullYear() + 2, today.getMonth(), today.getDate());
  const fmt = (d) => `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,"0")}-${String(d.getDate()).padStart(2,"0")}`;
  const [isMobile, setIsMobile] = React.useState(() => typeof window !== "undefined" && window.matchMedia("(max-width: 680px)").matches);
  React.useEffect(() => {
    const mq = window.matchMedia("(max-width: 680px)");
    const on = e => setIsMobile(e.matches);
    mq.addEventListener ? mq.addEventListener("change", on) : mq.addListener(on);
    return () => { mq.removeEventListener ? mq.removeEventListener("change", on) : mq.removeListener(on); };
  }, []);
  const [view, setView] = React.useState(() => new Date(today.getFullYear(), today.getMonth(), 1));
  const [expanded, setExpanded] = React.useState(true);
  const label = (
    <div style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 11, letterSpacing: ".08em", textTransform: "uppercase", color: "var(--text-muted)", marginBottom: 6 }}>Date</div>
  );
  if (isMobile) return (
    <div style={{ flex: 1, minWidth: 0 }}>
      {label}
      <input type="date" value={value ? fmt(value) : ""} min={fmt(today)} max={fmt(maxDate)}
        onChange={e => { const v = e.target.value; if (!v) return onChange(null); const [y,m,d] = v.split("-").map(Number); onChange(new Date(y, m-1, d)); }}
        style={{ width: "100%", boxSizing: "border-box", height: 46, padding: "0 12px", background: "var(--surface-inset)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-sm)", fontFamily: "var(--font-body, inherit)", fontSize: 16, fontWeight: 600, color: "#171718", WebkitAppearance: "none", appearance: "none" }} />
    </div>
  );
  const canPrev = view > new Date(today.getFullYear(), today.getMonth(), 1);
  const canNext = new Date(view.getFullYear(), view.getMonth() + 1, 1) <= maxDate;
  const monthName = view.toLocaleDateString("en-US", { month: "long" });
  const years = Array.from({ length: maxDate.getFullYear() - today.getFullYear() + 1 }, (_, i) => today.getFullYear() + i);
  const setYear = (y) => {
    let v = new Date(y, view.getMonth(), 1);
    const minV = new Date(today.getFullYear(), today.getMonth(), 1);
    const maxV = new Date(maxDate.getFullYear(), maxDate.getMonth(), 1);
    if (v < minV) v = minV;
    if (v > maxV) v = maxV;
    setView(v);
  };
  const firstDow = view.getDay();
  const daysInMonth = new Date(view.getFullYear(), view.getMonth() + 1, 0).getDate();
  const cells = Array(firstDow).fill(null).concat(Array.from({ length: daysInMonth }, (_, i) => i + 1));
  const navBtn = (dir, enabled) => ({ width: 28, height: 28, borderRadius: "var(--radius-sm)", border: "1px solid var(--border-subtle)", background: "var(--surface-inset)", color: enabled ? "var(--text-strong)" : "var(--border-subtle)", cursor: enabled ? "pointer" : "default", fontSize: 14, lineHeight: 1 });
  return (
    <div style={{ flex: 1 }}>
      {label}
      {value && !expanded ? (
        <button type="button" onClick={() => setExpanded(true)} style={{ width: "100%", boxSizing: "border-box", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, height: 42, padding: "0 12px", background: "var(--surface-inset)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-sm)", cursor: "pointer", fontSize: 14, fontWeight: 600, color: "#171718" }}>
          {value.toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric", year: "numeric" })}
          <span style={{ fontSize: 11, color: "var(--bp-cyan-700)", fontFamily: "var(--font-display)", fontWeight: 700, textTransform: "uppercase", letterSpacing: ".08em" }}>Change</span>
        </button>
      ) : (
      <div style={{ border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-md)", background: "var(--surface-card)", padding: 12, boxShadow: "var(--shadow-sm, 0 1px 3px rgba(4,10,18,.08))" }}>
        <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 10 }}>
          <button type="button" disabled={!canPrev} onClick={() => canPrev && setView(new Date(view.getFullYear(), view.getMonth() - 1, 1))} style={navBtn(-1, canPrev)}>‹</button>
          <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
            <span style={{ fontFamily: "var(--font-display)", fontWeight: 700, fontSize: 14, textTransform: "uppercase", letterSpacing: ".05em", color: "var(--text-strong)" }}>{monthName}</span>
            <select value={view.getFullYear()} onChange={e => setYear(+e.target.value)} style={{ fontFamily: "var(--font-mono)", fontSize: 13, fontWeight: 700, color: "var(--text-strong)", background: "transparent", border: "none", padding: 0, cursor: "pointer", appearance: "auto" }}>
              {years.map(y => <option key={y} value={y}>{y}</option>)}
            </select>
          </div>
          <button type="button" disabled={!canNext} onClick={() => canNext && setView(new Date(view.getFullYear(), view.getMonth() + 1, 1))} style={navBtn(1, canNext)}>›</button>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(7,1fr)", gap: 3, textAlign: "center" }}>
          {["S","M","T","W","T","F","S"].map((d, i) => <div key={i} style={{ fontSize: 10.5, fontWeight: 700, color: "var(--bp-cyan-600, var(--bp-cyan-500))", fontFamily: "var(--font-display)", letterSpacing: ".08em", padding: "3px 0" }}>{d}</div>)}
          {cells.map((d, i) => {
            if (!d) return <div key={i} />;
            const dt = new Date(view.getFullYear(), view.getMonth(), d);
            const disabled = dt < today || dt > maxDate;
            const sel = value && dt.getTime() === value.getTime();
            return <button key={i} type="button" disabled={disabled} onClick={() => { onChange(dt); setExpanded(false); }} style={{ padding: "6px 0", fontSize: 13, border: "none", borderRadius: 7, cursor: disabled ? "default" : "pointer", fontFamily: "var(--font-body, inherit)", fontWeight: sel ? 700 : 500, background: sel ? "var(--bp-cyan-500)" : "transparent", color: disabled ? "var(--border-subtle)" : sel ? "#fff" : "#171718", transition: "background .12s" }}
              onMouseEnter={e => { if (!disabled && !sel) e.currentTarget.style.background = "var(--surface-inset)"; }}
              onMouseLeave={e => { if (!sel) e.currentTarget.style.background = "transparent"; }}>{d}</button>;
          })}
        </div>
      </div>
      )}
    </div>
  );
}

function ReachChip({ label, icon, on, onClick }) {
  return (
    <div onClick={onClick} role="checkbox" aria-checked={on} tabIndex={0} className="bp-reach-chip"
      onKeyDown={e => { if (e.key === " " || e.key === "Enter") { e.preventDefault(); onClick(); } }}
      style={{ display: "inline-flex", alignItems: "center", gap: 6, padding: "5px 12px", borderRadius: 99, cursor: "pointer", userSelect: "none", fontSize: 13, fontWeight: 600, transition: "all .15s",
        background: on ? "var(--bp-cyan-500)" : "var(--surface-inset)",
        color: on ? "#fff" : "var(--text-muted)",
        border: `1px solid ${on ? "var(--bp-cyan-500)" : "var(--border-subtle)"}` }}>
      <span style={{ fontSize: 12 }}>{on ? "\u2713" : icon}</span>{label}
    </div>
  );
}

function BookingModal({ open, onClose, prefill }) {
  const [step, setStep] = React.useState(0);
  const [dial, setDial] = React.useState(BP_DIAL_CODES[0]);
  const [date, setDate] = React.useState(null);
  const [trip, setTrip] = React.useState("");
  const [boat, setBoat] = React.useState("");
  const [guests, setGuests] = React.useState("6");
  const [first, setFirst] = React.useState("");
  const [last, setLast] = React.useState("");
  const [email, setEmail] = React.useState("");
  const [phone, setPhone] = React.useState("");
  const [canCall, setCanCall] = React.useState(true);
  const [canText, setCanText] = React.useState(true);
  const [sending, setSending] = React.useState(false);
  const [sendError, setSendError] = React.useState("");
  const TRIP_LABELS = { "full-basic": "Full-Day · Basic", "full-ai": "Full-Day · All-Inclusive", "half-basic": "Half-Day · Basic", "half-ai": "Half-Day · All-Inclusive", "sightseeing": "Sightseeing" };
  React.useEffect(() => { if (open) { setStep(0); setTrip(prefill?.trip ?? ""); setBoat(prefill?.boat ?? ""); setDate(null); setGuests("6"); setFirst(""); setLast(""); setEmail(""); setPhone(""); setCanCall(true); setCanText(true); } }, [open]);
  if (!open) return null;
  const steps = ["Trip", "Details", "Confirm"];
  const done = step === 3;
  const emailOk = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email.trim());
  const phoneOk = phone.replace(/\D/g, "").length >= 7;
  const reachOk = canCall || canText;
  const phoneReach = [canCall && "Calls", canText && "Texts"].filter(Boolean).join(" & ") || "—";
  const stepValid = step === 0
    ? Boolean(trip && boat && date && guests)
    : step === 1
      ? Boolean(first.trim() && last.trim() && emailOk && phoneOk && reachOk)
      : true;
  const dateLabel = date ? date.toLocaleDateString("en-US", { weekday: "short", month: "long", day: "numeric", year: "numeric" }) : "—";
  const sendRequest = async () => {
    if (window.BOOKING_ENDPOINT) {
      setSending(true); setSendError("");
      try {
        const r = await fetch(window.BOOKING_ENDPOINT, {
          method: "POST", headers: { "Content-Type": "application/json" },
          body: JSON.stringify({ trip: TRIP_LABELS[trip] || "", boat, date: dateLabel, guests, first, last, name: [first, last].filter(Boolean).join(" "), email, phone: phone ? dial.d + " " + phone : "", phoneReach, canCall, canText }),
        });
        if (!r.ok) throw new Error((await r.json().catch(() => ({}))).error || "Request failed");
        setStep(3);
      } catch (err) {
        setSendError("We couldn't send that. Please call or email us and we'll take it from there.");
      } finally { setSending(false); }
      return;
    }
    mailtoFallback();
    setStep(3);
  };
  const mailtoFallback = () => {
    const lines = [
      "NEW BOOKING REQUEST — Blue Phoenix Sportfishing",
      "",
      "TRIP",
      "  Trip type:  " + (TRIP_LABELS[trip] || "—"),
      "  Charter:    " + (boat || "—"),
      "  Date:       " + dateLabel,
      "  Guests:     " + guests,
      "  Departure:  TBD (recommended 6–7 AM)",
      "",
      "GUEST",
      "  First name: " + (first || "—"),
      "  Last name:  " + (last || "—"),
      "  Email:      " + (email || "—"),
      "  Phone:      " + (phone ? dial.d + " " + phone : "—"),
      "  Reachable:  " + phoneReach,
      "",
      "Submitted from bluephoenixsportfishing.com",
    ];
    const subject = "Booking request · " + (TRIP_LABELS[trip] || "Charter") + " · " + dateLabel;
    window.location.href = "mailto:info@bluephoenixsportfishing.com?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(lines.join("\n"));
  };
  return (
    <div onClick={onClose} className="bp-modal-overlay" style={{ position: "fixed", inset: 0, zIndex: 100, background: "var(--surface-overlay)", backdropFilter: "blur(6px)", display: "flex", alignItems: "center", justifyContent: "center", padding: 24 }}>
      <div onClick={e => e.stopPropagation()} style={{ width: 480, maxWidth: "100%", maxHeight: "92vh", overflowY: "auto", background: "var(--surface-card)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-lg)", boxShadow: "var(--shadow-lg), var(--shadow-glow)" }}>
        <div style={{ position: "relative", height: 120, overflow: "hidden" }}>
          <img src={window.BP_ASSETS.boat} alt="" style={{ width: "100%", height: "100%", objectFit: "cover" }} />
          <div style={{ position: "absolute", inset: 0, background: "linear-gradient(rgba(4,10,18,.2),rgba(4,10,18,.9))" }} />
          <div style={{ position: "absolute", left: 24, bottom: 14 }}>
            <div style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 10, letterSpacing: ".2em", textTransform: "uppercase", color: "var(--bp-cyan-400)" }}>Book A Charter</div>
            <div style={{ fontFamily: "var(--font-display)", fontWeight: 700, fontSize: 26, textTransform: "uppercase", color: "var(--bp-foam)", lineHeight: 1 }}>Booking Request</div>
          </div>
          <div onClick={onClose} style={{ position: "absolute", top: 12, right: 14, width: 30, height: 30, borderRadius: 99, background: "rgba(4,10,18,.6)", border: "1px solid var(--border-strong)", color: "var(--bp-fog)", display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer", fontSize: 16 }}>×</div>
        </div>
        <div style={{ display: "flex", gap: 8, padding: "16px 24px 4px" }}>
          {steps.map((s, i) => (
            <div key={s} style={{ flex: 1, display: "flex", alignItems: "center", gap: 8 }}>
              <div style={{ width: 22, height: 22, borderRadius: 99, flexShrink: 0, display: "flex", alignItems: "center", justifyContent: "center", fontFamily: "var(--font-mono)", fontSize: 11, background: i <= step ? "var(--accent)" : "var(--surface-inset)", color: i <= step ? "var(--bp-abyss)" : "var(--text-muted)", border: `1px solid ${i <= step ? "var(--accent)" : "var(--border-subtle)"}` }}>{i + 1}</div>
              <span style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 11, letterSpacing: ".08em", textTransform: "uppercase", color: i <= step ? "var(--text-strong)" : "var(--text-muted)" }}>{s}</span>
            </div>
          ))}
        </div>
        <div className="bp-modal-body" style={{ padding: "16px 24px 24px", display: "flex", flexDirection: "column", gap: 16 }}>
          {step === 0 && <>
            <div className="bp-modal-row" style={{ display: "flex", gap: 12 }}>
            <Select label="Trip type" value={trip} onChange={e => setTrip(e.target.value)} style={{ flex: 1, minWidth: 0 }}>
              <option value="" disabled>Select trip type…</option>
              <option value="full-basic">Full-Day · Basic</option>
              <option value="full-ai">Full-Day · All-Inclusive</option>
              <option value="half-basic">Half-Day · Basic</option>
              <option value="half-ai">Half-Day · All-Inclusive</option>
              <option value="sightseeing">Sightseeing</option>
            </Select>
            <Select label="Charter" value={boat} onChange={e => setBoat(e.target.value)} style={{ flex: 1, minWidth: 0 }}>
              <option value="" disabled>Select charter…</option>
              <option value="Coral Dream">Coral Dream · 33 ft</option>
              <option value="Blue Phoenix">Blue Phoenix · 34 ft</option>
            </Select>
            </div>
            <div className="bp-modal-row" style={{ display: "flex", gap: 12, alignItems: "flex-start" }}>
              <DatePicker value={date} onChange={setDate} />
              <Select label="Guests" value={guests} onChange={e => setGuests(e.target.value)} className="bp-guests" style={{ width: 120 }}>
                {[1,2,3,4,5,6,7,8].map(n => <option key={n} value={n}>{n}</option>)}
              </Select>
            </div>
            <div style={{ display: "flex", alignItems: "center", gap: 8, padding: "10px 12px", background: "var(--surface-inset)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-sm)", fontSize: 13, color: "#171718" }}>
              <span style={{ color: "var(--bp-cyan-500)", fontSize: 15 }}>☀</span>Recommended departure: 6–7 AM
            </div>
          </>}
          {step === 1 && <>
            <div className="bp-modal-row" style={{ display: "flex", gap: 12 }}>
              <Input label="First name" placeholder="Ernest" value={first} onChange={e => setFirst(e.target.value)} style={{ flex: 1 }} />
              <Input label="Last name" placeholder="Hemingway" value={last} onChange={e => setLast(e.target.value)} style={{ flex: 1 }} />
            </div>
            <Input label="Email" type="email" placeholder="you@email.com" value={email} onChange={e => setEmail(e.target.value)} />
            <div>
              <div className="bp-phone-row" style={{ display: "flex", gap: 12, alignItems: "flex-end" }}>
                <DialCodePicker value={dial} onChange={setDial} />
                <Input label="Phone / WhatsApp" type="tel" placeholder="(619) 555-0142" value={phone} onChange={e => setPhone(e.target.value)} style={{ flex: 1 }} />
              </div>
              <div className="bp-reach-row" style={{ display: "flex", alignItems: "center", flexWrap: "wrap", gap: 8, marginTop: 10 }}>
                <span className="bp-reach-label" style={{ fontSize: 13, color: "var(--text-muted)" }}>This number can receive</span>
                <ReachChip label="Calls" icon={"\u260E"} on={canCall} onClick={() => setCanCall(!canCall)} />
                <ReachChip label="Texts" icon={"\u2709"} on={canText} onClick={() => setCanText(!canText)} />
              </div>
            </div>
          </>}
          {step === 2 && <div style={{ background: "var(--surface-inset)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-md)", padding: 18 }}>
            <div style={{ fontFamily: "var(--font-display)", fontWeight: 700, textTransform: "uppercase", letterSpacing: ".08em", fontSize: 14, color: "var(--text-strong)", marginBottom: 12 }}>Request Summary</div>
            <div style={{ display: "flex", flexDirection: "column", gap: 8, fontSize: 14, color: "#171718" }}>
              <div style={{ display: "flex", justifyContent: "space-between" }}><span style={{ color: "var(--text-muted)" }}>Trip</span><span style={{ fontWeight: 600 }}>{TRIP_LABELS[trip] || "—"}</span></div>
              <div style={{ display: "flex", justifyContent: "space-between" }}><span style={{ color: "var(--text-muted)" }}>Charter</span><span style={{ fontWeight: 600 }}>{boat || "—"}</span></div>
              <div style={{ display: "flex", justifyContent: "space-between" }}><span style={{ color: "var(--text-muted)" }}>Date</span><span style={{ fontWeight: 600 }}>{dateLabel}</span></div>
              <div style={{ display: "flex", justifyContent: "space-between" }}><span style={{ color: "var(--text-muted)" }}>Guests</span><span style={{ fontWeight: 600 }}>{guests}</span></div>
              <div style={{ display: "flex", justifyContent: "space-between" }}><span style={{ color: "var(--text-muted)" }}>Departure</span><span style={{ fontWeight: 600, textAlign: "right" }}>TBD (recommended 6–7 AM)</span></div>
              <div style={{ height: 1, background: "var(--border-subtle)", margin: "4px 0" }} />
              <div style={{ display: "flex", justifyContent: "space-between", gap: 12 }}><span style={{ color: "var(--text-muted)" }}>Name</span><span style={{ fontWeight: 600, textAlign: "right" }}>{[first, last].filter(Boolean).join(" ") || "—"}</span></div>
              <div style={{ display: "flex", justifyContent: "space-between", gap: 12 }}><span style={{ color: "var(--text-muted)" }}>Email</span><span style={{ fontWeight: 600, textAlign: "right", wordBreak: "break-all" }}>{email || "—"}</span></div>
              <div style={{ display: "flex", justifyContent: "space-between", gap: 12 }}><span style={{ color: "var(--text-muted)" }}>Phone</span><span style={{ fontWeight: 600, textAlign: "right" }}>{phone ? dial.d + " " + phone : "—"}</span></div>
              <div style={{ display: "flex", justifyContent: "space-between", gap: 12 }}><span style={{ color: "var(--text-muted)" }}>Reachable by</span><span style={{ fontWeight: 600, textAlign: "right" }}>{phoneReach}</span></div>
            </div>
          </div>}
          {step === 3 && <div style={{ textAlign: "center", padding: "18px 6px 6px" }}>
            <div style={{ width: 54, height: 54, borderRadius: 99, margin: "0 auto 14px", display: "flex", alignItems: "center", justifyContent: "center", background: "var(--bp-cyan-500)", color: "#fff", fontSize: 26 }}>✓</div>
            <div style={{ fontFamily: "var(--font-display)", fontWeight: 700, textTransform: "uppercase", fontSize: 20, color: "var(--text-strong)", marginBottom: 8 }}>Thank You!</div>
            <p style={{ fontSize: 14.5, color: "#171718", lineHeight: 1.6, margin: "0 0 16px" }}>Your request is on its way. Once it reaches us, our team will contact you shortly to confirm your date and finalize the details.</p>
            <div style={{ background: "var(--surface-inset)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-md)", padding: 14, fontSize: 13.5, color: "#171718", lineHeight: 1.7 }}>
              <div style={{ fontFamily: "var(--font-display)", fontWeight: 700, textTransform: "uppercase", letterSpacing: ".08em", fontSize: 12, color: "var(--bp-cyan-700)", marginBottom: 4 }}>Contact Us</div>
              +1 206 446 0449<br/>info@bluephoenixsportfishing.com
            </div>
          </div>}
          {!done && !stepValid && <div style={{ fontSize: 13, color: "var(--text-muted)" }}>{step === 0 ? "Choose a trip, charter, date and guest count to continue." : !reachOk && phoneOk ? "Pick at least one way we can reach that number — calls or texts." : "Add your name, a valid email and a phone number to continue."}</div>}
          {sendError && <div style={{ fontSize: 13.5, color: "#a8341f", background: "#fdf1ee", border: "1px solid #f0cfc6", borderRadius: "var(--radius-sm)", padding: "10px 12px" }}>{sendError}</div>}
          <div style={{ display: "flex", gap: 12, marginTop: 4 }}>
            {step > 0 && !done && <Button variant="secondary" style={{ borderColor: "var(--border-subtle)" }} onClick={() => setStep(step - 1)}>Back</Button>}
            <Button variant={step >= 2 ? "gold" : "primary"} fullWidth style={{ borderColor: "transparent" }} disabled={sending || (!done && !stepValid)} onClick={() => { if (done) return onClose(); if (!stepValid) return; if (step === 2) return sendRequest(); setStep(step + 1); }}>
              {done ? "Close" : step === 2 ? (sending ? "Sending…" : "Confirm Request") : "Continue"}
            </Button>
          </div>
        </div>
      </div>
    </div>
  );
}
window.BookingModal = BookingModal;
