// Shared ContactForm — used on every form across the site.
//
// Renders a different field set per form type. Falls back to a mailto:
// link so submissions actually do something in this static design build.
// When the user wires a real backend (Formspree / own API / etc.), swap
// the handleSubmit() body — the rest of the UI doesn't change.

// The only email address the site shows/sends to, per direct
// instruction. Fallback used only if window.SOLO_BACKEND fails to
// load; the real routing is SOLO_BACKEND.inbox in solo-backend.js
// (kept in sync above).
const FORM_INBOX = "contactus@solosecure.group";

// Per-form field config. Order matters — fields render in this order.
// `type`: 'text' | 'email' | 'select' | 'textarea' | 'date' | 'file' | 'yesno'
// `req`: true if required.
const FORM_CONFIGS = {
  sales: {
    title:       "Get in touch with sales",
    subtitle:    "Demo requests, quotes, and general enquiries.",
    defaultSubject: "General enquiry",
    fields: [
      { key: "subject",     label: "Subject",                   type: "text",  req: true,  placeholder: "What's this about?" },
      { key: "name",        label: "Full name",                 type: "text",  req: true,  placeholder: "Jane Operator" },
      { key: "email",       label: "Work email",                type: "email", req: true,  placeholder: "jane@example.com" },
      { key: "company",     label: "Company",                   type: "text",  req: true,  placeholder: "Acme Security Ltd" },
      { key: "position",    label: "Position / job title",      type: "text",  req: false, placeholder: "Operations Director" },
      { key: "companySize", label: "Company size",              type: "select", req: false,
        options: ["1–10", "11–50", "51–200", "201–500", "500+"] },
      { key: "country",     label: "Country",                   type: "text",  req: false, placeholder: "United Kingdom" },
      { key: "usesTowers",  label: "Do you currently use CCTV towers?", type: "yesno", req: false },
      { key: "callbackDate", label: "Preferred call-back date (optional)", type: "date", req: false },
      { key: "message",     label: "Brief — tell us about your requirement", type: "textarea", req: true, placeholder: "Site type, scale, timing, any specific requirements." },
      { key: "attachment",  label: "Attach a file (RFP, drawings, site plan)", type: "file", req: false },
    ],
  },
  reseller: {
    title:    "Reseller intake",
    subtitle: "Apply to the Solo partner programme, or request portal access.",
    defaultSubject: "Partner programme enquiry",
    fields: [
      { key: "subject",     label: "Subject",                  type: "text",  req: true },
      { key: "name",        label: "Full name",                type: "text",  req: true },
      { key: "email",       label: "Work email",               type: "email", req: true },
      { key: "company",     label: "Organisation",             type: "text",  req: true },
      { key: "position",    label: "Position / job title",     type: "text",  req: false },
      { key: "territory",   label: "Territory",                type: "select", req: true,
        options: ["United Kingdom", "European Union", "North America", "Other"] },
      { key: "companySize", label: "Company size",             type: "select", req: false,
        options: ["1–10", "11–50", "51–200", "201–500", "500+"] },
      { key: "existingPartner", label: "Existing Solo partner?", type: "yesno", req: false },
      { key: "estUnits",    label: "Est. units per year",      type: "text",  req: false, placeholder: "50 — 500" },
      { key: "message",     label: "Brief — about your business + portfolio", type: "textarea", req: true },
    ],
  },
  careers: {
    title:    "Apply to Solo",
    subtitle: "Open roles, speculative applications, internships.",
    defaultSubject: "General careers enquiry",
    fields: [
      { key: "subject",   label: "Role / subject",         type: "text",  req: true,  placeholder: "e.g. Senior firmware engineer" },
      { key: "name",      label: "Full name",              type: "text",  req: true },
      { key: "email",     label: "Email",                  type: "email", req: true },
      { key: "position",  label: "Current position",       type: "text",  req: false },
      { key: "linkedin",  label: "LinkedIn URL (optional)", type: "text", req: false, placeholder: "linkedin.com/in/..." },
      { key: "country",   label: "Where you're based",     type: "text",  req: false },
      { key: "message",   label: "Tell us about yourself", type: "textarea", req: true },
      { key: "attachment", label: "Attach your CV (PDF preferred)", type: "file", req: false },
    ],
  },
  press: {
    title:    "Press & media enquiries",
    subtitle: "Interviews, comment, story angles, brand assets.",
    defaultSubject: "Press enquiry",
    fields: [
      { key: "subject",     label: "Subject",                type: "text",  req: true },
      { key: "name",        label: "Full name",              type: "text",  req: true },
      { key: "email",       label: "Email",                  type: "email", req: true },
      { key: "outlet",      label: "Publication / outlet",   type: "text",  req: true,  placeholder: "Construction News / The Register / etc." },
      { key: "topic",       label: "Topic",                  type: "select", req: false,
        options: ["Interview", "Comment / quote", "Story / feature", "Brand assets request", "Other"] },
      { key: "deadline",    label: "Deadline (if any)",      type: "date",  req: false },
      { key: "message",     label: "Brief",                  type: "textarea", req: true },
    ],
  },
  investors: {
    title:    "Investor relations",
    subtitle: "Confidential enquiries from current and prospective Solo investors.",
    defaultSubject: "Investor enquiry",
    fields: [
      { key: "subject",      label: "Subject",                type: "text",  req: true },
      { key: "name",         label: "Full name",              type: "text",  req: true },
      { key: "email",        label: "Email",                  type: "email", req: true },
      { key: "investorType", label: "Investor type",          type: "select", req: false,
        options: ["Individual", "VC / institutional", "Family office", "Strategic / corporate", "Other"] },
      { key: "capitalRange", label: "Capital range of interest", type: "select", req: false,
        options: ["Under £100k", "£100k – £500k", "£500k – £2m", "£2m – £10m", "£10m+"] },
      { key: "message",      label: "Brief",                  type: "textarea", req: true },
    ],
  },
};

// Build a mailto: link from the form state. URL-encodes properly,
// preserves line breaks in the body.
function buildMailto(formType, state) {
  const subject = state.subject || FORM_CONFIGS[formType].defaultSubject;
  const lines = [];
  const config = FORM_CONFIGS[formType];
  for (const field of config.fields) {
    if (field.key === "subject" || field.key === "attachment") continue;
    const v = state[field.key];
    if (v == null || v === "") continue;
    lines.push(`${field.label}: ${v}`);
  }
  if (state.marketingOptIn) lines.push("[Marketing opt-in: yes]");
  lines.push("");
  lines.push("---");
  lines.push(`Submitted from solosecure.tech · form: ${formType}`);
  if (state.attachment) {
    lines.push("");
    lines.push(`(Attachment selected: ${state.attachment} — attach it to this email before sending.)`);
  }
  const body = lines.join("\n");
  return `mailto:${FORM_INBOX}?subject=${encodeURIComponent("[" + formType.toUpperCase() + "] " + subject)}&body=${encodeURIComponent(body)}`;
}

/* ──────────── ContactForm ────────────
 * Props:
 *   formType  — 'sales' | 'reseller' | 'careers' | 'press' | 'investors'
 *   subject   — optional pre-fill for the subject field
 *   compact   — render without the title/subtitle header
 */
function ContactForm({ formType = "sales", subject, compact }) {
  const config = FORM_CONFIGS[formType] || FORM_CONFIGS.sales;
  const [submitted, setSubmitted] = useState(false);
  // Real outcome of the last submitForm() call — used instead of blindly
  // showing "success" every time. null = mailto/fallback path (can't
  // fail client-side); otherwise the { ok, emailed, message } result.
  const [submitResult, setSubmitResult] = useState(null);
  const [submitting, setSubmitting] = useState(false);
  const [state, setState] = useState(() => ({
    subject: subject || config.defaultSubject,
  }));

  // If the parent updates the subject prop (e.g. user navigated with new context), sync it.
  useEffect(() => {
    if (subject) setState((s) => ({ ...s, subject }));
  }, [subject]);

  const setField = (key, value) => setState((s) => ({ ...s, [key]: value }));

  const handleSubmit = async (e) => {
    e.preventDefault();
    // Delegate to the central SOLO_BACKEND_HELPERS.submitForm — this lets
    // us swap mailto for Formspree / webhook / JotForm by flipping a
    // single config flag in solo-backend.js, without touching this file.
    const helpers = window.SOLO_BACKEND_HELPERS;
    if (helpers && helpers.submitForm) {
      const { subject, attachment, marketingOptIn, ...fields } = state;
      // attachment in mailto mode is just a filename string (real upload
      // disabled in current config). Surface it in the field list so the
      // user knows to attach manually.
      const payload = {
        formType,
        subject: subject || FORM_CONFIGS[formType].defaultSubject,
        fields: { ...fields, marketingOptIn: marketingOptIn ? "Yes" : undefined, attachmentNote: attachment || undefined },
      };
      setSubmitting(true);
      const result = await helpers.submitForm(payload);
      setSubmitting(false);
      // Reflect the REAL outcome instead of always claiming success —
      // this is the fix for the bug where every submission used to show
      // "Message received" even when nothing was actually delivered.
      setSubmitResult(result);
      if (result && result.ok) setSubmitted(true);
      // If result.ok is false, we deliberately do NOT setSubmitted(true)
      // — the form stays visible with an error notice below (see render)
      // so the user can retry or fall back to a direct email.
    } else {
      // Defensive fallback if solo-backend.js failed to load.
      const url = buildMailto(formType, state);
      window.location.href = url;
      setSubmitResult(null);
      setSubmitted(true);
    }
  };

  // Pick the right thank-you message for this form type, sourced from
  // the central backend config so it's a single place to retune copy.
  const thankYouMessage = (() => {
    const cfg = window.SOLO_BACKEND;
    const msg = cfg?.autoReply?.messages?.[formType];
    return msg || "Thanks. We'll be in touch within one working day.";
  })();

  if (submitted) {
    // Tailor copy to the current backend mode AND the real outcome of
    // the submission. In mailto mode the user genuinely needs to send
    // the email draft we just composed. In "worker" mode the submission
    // was captured server-side (see routes/contact.ts) — `submitResult`
    // tells us whether the email itself actually went out too, so the
    // copy doesn't unconditionally claim success like it used to.
    const mode = window.SOLO_BACKEND?.forms?.mode || "mailto";
    const isMailto = mode === "mailto";
    const inbox = window.SOLO_BACKEND?.inbox?.[formType] || FORM_INBOX;
    // In worker mode, "captured but not emailed yet" (e.g. RESEND_API_KEY
    // not configured) is still a genuine success from the visitor's POV
    // — their message is safely on file — so we don't show an error, but
    // we also don't falsely imply an email confirmation went out.
    const emailPending = !isMailto && submitResult && submitResult.ok && submitResult.emailed === false;
    const heading = isMailto
      ? "Your email client should now open."
      : "Message received.";
    return (
      <div style={{
        background: "var(--surface)",
        border: "1px solid var(--line)",
        padding: 40,
      }}>
        <Eyebrow style={{ marginBottom: 16 }}>
          {isMailto ? "Message ready" : "Thanks"}
        </Eyebrow>
        <h3 style={{
          fontFamily: "var(--font-display)", fontWeight: 700,
          fontSize: 28, letterSpacing: "0.005em",
          textTransform: "uppercase", margin: "0 0 20px",
          color: "var(--fg)",
        }}>{heading}</h3>
        <p style={{
          fontFamily: "var(--font-body)", fontSize: 15,
          lineHeight: 1.6, color: "var(--fg-soft)", margin: "0 0 16px",
        }}>
          {isMailto
            ? <>Hit send on the draft addressed to <strong style={{ color: "var(--fg)" }}>{inbox}</strong> and {thankYouMessage.toLowerCase()}</>
            : thankYouMessage}
        </p>
        {isMailto && (
          <p style={{
            fontFamily: "var(--font-body)", fontSize: 14,
            lineHeight: 1.6, color: "var(--fg-soft)", margin: "0 0 24px",
          }}>
            Didn't see anything happen? Email us directly at <a href={`mailto:${inbox}`} style={{ color: "var(--fg)", textDecoration: "underline" }}>{inbox}</a>.
          </p>
        )}
        {emailPending && (
          <p style={{
            fontFamily: "var(--font-body)", fontSize: 13,
            lineHeight: 1.6, color: "var(--fg-dim)", margin: "0 0 24px",
          }}>
            {submitResult.message || `Your details are saved. If you need an immediate reply, email us directly at ${inbox}.`}
          </p>
        )}
        <Button small onClick={() => { setSubmitted(false); setSubmitResult(null); }}>Submit another →</Button>
      </div>
    );
  }

  return (
    <form
      onSubmit={handleSubmit}
      style={{
        background: "var(--surface)",
        border: "1px solid var(--line)",
        padding: 40,
      }}
    >
      {!compact && (
        <>
          <Eyebrow style={{ marginBottom: 14 }}>{config.subtitle}</Eyebrow>
          <h3 style={{
            fontFamily: "var(--font-display)", fontWeight: 700,
            fontSize: 24, letterSpacing: "0.005em",
            textTransform: "uppercase", margin: "0 0 28px",
            color: "var(--fg)",
          }}>{config.title}</h3>
        </>
      )}

      {/* Real error notice — only shown when submitForm() actually
          reported failure (e.g. the Worker route returned an error).
          Previously this state was unreachable because the form always
          jumped straight to the success screen regardless of outcome. */}
      {submitResult && submitResult.ok === false && (
        <div style={{
          background: "var(--surface)",
          border: "1px solid var(--fg)",
          padding: "16px 18px",
          marginBottom: 24,
          fontFamily: "var(--font-body)", fontSize: 13.5,
          lineHeight: 1.55, color: "var(--fg)",
        }}>
          Something went wrong sending your message ({submitResult.message || "unknown error"}). Please try again, or email us directly at{" "}
          <a href={`mailto:${window.SOLO_BACKEND?.inbox?.[formType] || FORM_INBOX}`} style={{ color: "var(--fg)", textDecoration: "underline" }}>
            {window.SOLO_BACKEND?.inbox?.[formType] || FORM_INBOX}
          </a>.
        </div>
      )}

      {config.fields.map((f) => (
        <Field
          key={f.key}
          field={f}
          value={state[f.key]}
          onChange={(v) => setField(f.key, v)}
        />
      ))}

      <Checkbox
        label="I'd like to receive Solo updates, product news and partner programme info."
        checked={!!state.marketingOptIn}
        onChange={(v) => setField("marketingOptIn", v)}
      />

      {/* GDPR notice */}
      <p style={{
        fontFamily: "var(--font-body)", fontSize: 11.5,
        lineHeight: 1.6, color: "var(--fg-dim)",
        marginTop: 18, marginBottom: 16,
      }}>
        Solo Secure Technologies will process your information in line with our privacy policy. We respond within one working day and we will not share your details with third parties.
      </p>

      {/* reCAPTCHA v3 — invisible / score-based.
          v3 doesn't render a checkbox. Google requires either the small
          badge (loaded automatically by the enterprise script) OR an
          inline attribution line. We hide the floating badge site-wide
          via CSS in index.html and use this inline attribution so the
          Google terms are still satisfied. */}
      {window.SOLO_BACKEND?.recaptcha?.enabled ? (
        <p style={{
          fontFamily: "var(--font-body)", fontSize: 11,
          lineHeight: 1.5, color: "var(--fg-dim)",
          marginTop: 0, marginBottom: 20,
          letterSpacing: "0.02em",
        }}>
          This form is protected by reCAPTCHA and the Google{" "}
          <a href="https://policies.google.com/privacy" target="_blank" rel="noopener noreferrer" style={{ color: "var(--fg-dim)", textDecoration: "underline" }}>Privacy Policy</a>{" "}and{" "}
          <a href="https://policies.google.com/terms" target="_blank" rel="noopener noreferrer" style={{ color: "var(--fg-dim)", textDecoration: "underline" }}>Terms of Service</a> apply.
        </p>
      ) : null}

      <button type="submit" disabled={submitting} style={{
        width: "100%",
        background: "var(--fg)", color: "var(--bg)",
        border: "1px solid var(--fg)",
        padding: "18px 22px", cursor: submitting ? "default" : "pointer",
        opacity: submitting ? 0.6 : 1,
        fontFamily: "var(--font-body)",
        fontSize: 13, fontWeight: 500,
        letterSpacing: "0.18em", textTransform: "uppercase",
      }}>{submitting ? "Sending…" : "Send message →"}</button>

      <FormFooterNote formType={formType} />
    </form>
  );
}

/* ──────────── FormFooterNote ────────────
 * Honest copy that matches the current backend mode. mailto mode says
 * "opens your email client"; real-backend modes say "sent securely". */
function FormFooterNote({ formType }) {
  const cfg = window.SOLO_BACKEND;
  const mode = cfg?.forms?.mode || "mailto";
  const inbox = cfg?.inbox?.[formType] || FORM_INBOX;
  const note = (() => {
    if (mode === "mailto") return `// Opens your email client addressed to ${inbox}`;
    if (mode === "formspree") return "// Sent securely via Formspree";
    if (mode === "webhook")   return "// Sent securely to Solo";
    if (mode === "jotform")   return "// Powered by JotForm";
    return "";
  })();
  return (
    <p style={{
      fontFamily: "var(--font-body)", fontSize: 11,
      color: "var(--fg-faint)", letterSpacing: "0.14em",
      marginTop: 14, marginBottom: 0, textTransform: "uppercase",
    }}>{note}</p>
  );
}

/* ──────────── Field renderer ──────────── */
function Field({ field, value, onChange }) {
  const baseStyle = {
    width: "100%", boxSizing: "border-box",
    background: "var(--bg)",
    border: "1px solid var(--line)",
    color: "var(--fg)",
    fontFamily: "var(--font-body)",
    fontSize: 15, padding: "12px 14px",
    outline: "none",
  };

  return (
    <label style={{ display: "block", marginBottom: 20 }}>
      <div style={{
        fontFamily: "var(--font-body)", fontSize: 11,
        letterSpacing: "0.16em", color: "var(--fg-dim)",
        textTransform: "uppercase", marginBottom: 8, fontWeight: 500,
      }}>
        {field.label}{field.req && <span style={{ color: "var(--fg)" }}> *</span>}
      </div>
      {field.type === "textarea" ? (
        <textarea
          rows={4}
          required={field.req}
          placeholder={field.placeholder || ""}
          value={value || ""}
          onChange={(e) => onChange(e.target.value)}
          style={{ ...baseStyle, resize: "vertical" }}
          onFocus={(e) => e.target.style.borderColor = "var(--fg)"}
          onBlur={(e) => e.target.style.borderColor = "var(--line)"}
        />
      ) : field.type === "select" ? (
        <select
          required={field.req}
          value={value || ""}
          onChange={(e) => onChange(e.target.value)}
          style={baseStyle}
          onFocus={(e) => e.target.style.borderColor = "var(--fg)"}
          onBlur={(e) => e.target.style.borderColor = "var(--line)"}
        >
          <option value="">— Select —</option>
          {field.options.map((opt) => (
            <option key={opt} value={opt}>{opt}</option>
          ))}
        </select>
      ) : field.type === "yesno" ? (
        <div style={{ display: "flex", gap: 8 }}>
          {["Yes", "No"].map((opt) => (
            <button
              key={opt}
              type="button"
              onClick={() => onChange(opt)}
              style={{
                ...baseStyle,
                width: "auto", flex: 1,
                cursor: "pointer",
                background: value === opt ? "var(--fg)" : "var(--bg)",
                color: value === opt ? "var(--bg)" : "var(--fg)",
                borderColor: value === opt ? "var(--fg)" : "var(--line)",
                fontWeight: 500,
                textTransform: "uppercase", letterSpacing: "0.14em",
                fontSize: 12, padding: "13px 14px",
              }}>{opt}</button>
          ))}
        </div>
      ) : field.type === "file" ? (
        <div>
          <input
            type="file"
            id={`file-${field.key}`}
            onChange={(e) => {
              const file = e.target.files && e.target.files[0];
              onChange(file ? file.name : "");
            }}
            style={{ display: "none" }}
          />
          <label htmlFor={`file-${field.key}`} style={{
            ...baseStyle,
            cursor: "pointer", display: "flex",
            alignItems: "center", justifyContent: "space-between",
            color: value ? "var(--fg)" : "var(--fg-dim)",
          }}>
            <span>{value || "Choose file…"}</span>
            <span style={{
              fontFamily: "var(--font-body)", fontSize: 11,
              letterSpacing: "0.16em", textTransform: "uppercase",
              color: "var(--fg)", fontWeight: 500,
            }}>Browse</span>
          </label>
        </div>
      ) : (
        <input
          type={field.type}
          required={field.req}
          placeholder={field.placeholder || ""}
          value={value || ""}
          onChange={(e) => onChange(e.target.value)}
          style={baseStyle}
          onFocus={(e) => e.target.style.borderColor = "var(--fg)"}
          onBlur={(e) => e.target.style.borderColor = "var(--line)"}
        />
      )}
    </label>
  );
}

/* ──────────── Checkbox ──────────── */
function Checkbox({ label, checked, onChange }) {
  return (
    <label style={{
      display: "flex", gap: 12, alignItems: "flex-start",
      cursor: "pointer", marginBottom: 4,
      fontFamily: "var(--font-body)", fontSize: 13,
      lineHeight: 1.5, color: "var(--fg)",
    }}>
      <input
        type="checkbox"
        checked={checked}
        onChange={(e) => onChange(e.target.checked)}
        style={{
          width: 18, height: 18, accentColor: "var(--fg)",
          margin: 0, marginTop: 2, flexShrink: 0,
        }}
      />
      <span>{label}</span>
    </label>
  );
}

/* ──────────── Chat bubble ────────────
 * Floating bottom-right. Click to open a placeholder panel.
 * Replace the panel contents with a real widget (Intercom / Crisp / Tawk)
 * when ready — this just claims the UI real estate. */
function ChatBubble({ onNavigate }) {
  const [open, setOpen] = useState(false);

  // If a real chat provider is configured (Crisp / Tawk / Intercom / HubSpot),
  // the provider's own widget renders — we don't want to show the
  // placeholder alongside it or the page ends up with two floating
  // bubbles. Suppress the placeholder in that case.
  if (window.SOLO_BACKEND?.chat?.provider) return null;
  return (
    <>
      <button
        onClick={() => setOpen((o) => !o)}
        aria-label="Open chat"
        style={{
          position: "fixed", bottom: 24, right: 24,
          width: 56, height: 56,
          borderRadius: "50%",
          background: "var(--fg)", color: "var(--bg)",
          border: "1px solid var(--fg)",
          cursor: "pointer",
          display: "flex", alignItems: "center", justifyContent: "center",
          boxShadow: "0 12px 32px rgba(0,0,0,0.18)",
          zIndex: 80,
          transition: "transform 160ms",
          transform: open ? "scale(0.95)" : "scale(1)",
        }}>
        <svg width="22" height="22" viewBox="0 0 22 22" fill="none" stroke="currentColor" strokeWidth="1.8">
          {open ? (
            <g><line x1="5" y1="5" x2="17" y2="17" /><line x1="17" y1="5" x2="5" y2="17" /></g>
          ) : (
            <path d="M3 5 h16 v10 h-6 l-3 3 v-3 h-7 z" />
          )}
        </svg>
      </button>

      {open && (
        <div style={{
          position: "fixed", bottom: 96, right: 24,
          width: "min(360px, calc(100vw - 48px))",
          maxHeight: "calc(100vh - 140px)",
          background: "var(--bg)",
          border: "1px solid var(--line-strong)",
          boxShadow: "0 24px 60px rgba(0,0,0,0.18)",
          zIndex: 80,
          display: "flex", flexDirection: "column",
        }}>
          <div style={{
            padding: "20px 22px",
            borderBottom: "1px solid var(--line)",
            background: "var(--fg)", color: "var(--bg)",
          }}>
            <div style={{
              fontFamily: "var(--font-body)", fontSize: 10,
              letterSpacing: "0.22em", textTransform: "uppercase",
              color: "rgba(255,255,255,0.6)", marginBottom: 6, fontWeight: 500,
            }}>Solo chat</div>
            <div style={{
              fontFamily: "var(--font-display)", fontWeight: 700,
              fontSize: 18, letterSpacing: "0.005em",
              textTransform: "uppercase", color: "var(--bg)",
            }}>Hi — how can we help?</div>
          </div>
          <div style={{ padding: "24px 22px", flex: 1, overflow: "auto" }}>
            <p style={{
              fontFamily: "var(--font-body)", fontSize: 14,
              lineHeight: 1.55, color: "var(--fg-soft)", marginTop: 0, marginBottom: 18,
            }}>
              Live chat is being set up. While we connect it, here's the fastest way to reach us:
            </p>

            {/* Featured action — just a shortcut to reseller login for
                existing partners. Deliberately does NOT name "support
                ticket" here — ticket raising is a reseller-portal-only
                feature reached after signing in, never advertised or
                reachable from the public site itself (see pages.jsx's
                Contact page, which no longer has any ticket-shaped
                section at all). */}
            <button
              type="button"
              onClick={() => { onNavigate && onNavigate("reseller-login"); setOpen(false); }}
              style={{
                width: "100%", textAlign: "left",
                background: "var(--fg)", color: "var(--bg)",
                border: "1px solid var(--fg)",
                padding: "16px 18px", cursor: "pointer",
                marginBottom: 14,
                display: "flex", alignItems: "center",
                justifyContent: "space-between", gap: 12,
                fontFamily: "var(--font-body)",
              }}>
              <span>
                <span style={{
                  display: "block",
                  fontFamily: "var(--font-body)", fontSize: 10,
                  letterSpacing: "0.22em", textTransform: "uppercase",
                  color: "rgba(255,255,255,0.6)", marginBottom: 4, fontWeight: 500,
                }}>Existing partner</span>
                <span style={{
                  fontFamily: "var(--font-display)", fontWeight: 700,
                  fontSize: 14, letterSpacing: "0.005em",
                  textTransform: "uppercase", color: "var(--bg)",
                }}>Sign in to the reseller portal</span>
              </span>
              <span style={{ fontSize: 16 }}>→</span>
            </button>

            <ul style={{
              listStyle: "none", padding: 0, margin: 0,
              fontFamily: "var(--font-body)", fontSize: 14,
            }}>
              <li style={{
                borderTop: "1px solid var(--line)",
                padding: "12px 0", color: "var(--fg)",
              }}>
                Email <a href={`mailto:${FORM_INBOX}`} style={{ color: "var(--fg)", textDecoration: "underline" }}>{FORM_INBOX}</a>
              </li>
              <li style={{
                borderTop: "1px solid var(--line)",
                borderBottom: "1px solid var(--line)",
                padding: "12px 0", color: "var(--fg)",
              }}>
                Send a message via our{" "}
                <button
                  type="button"
                  onClick={() => { onNavigate && onNavigate("contact"); setOpen(false); }}
                  style={{
                    background: "none", border: "none", padding: 0,
                    color: "var(--fg)", textDecoration: "underline",
                    fontFamily: "inherit", fontSize: "inherit", cursor: "pointer",
                  }}
                >contact form</button>.
              </li>
            </ul>
          </div>
          <div style={{
            padding: "14px 22px",
            borderTop: "1px solid var(--line)",
            background: "var(--surface)",
            fontFamily: "var(--font-body)", fontSize: 11,
            letterSpacing: "0.16em", textTransform: "uppercase",
            color: "var(--fg-dim)",
          }}>
            // Live chat — coming soon
          </div>
        </div>
      )}
    </>
  );
}

Object.assign(window, { ContactForm, ChatBubble, FORM_INBOX });
