// Calculator — Opendoor-structured: Net Proceeds card (silver/metallic) on left,
// stacked cost line items on right. Plus a "Lock in your offer" capture form below the card
// with address + bed/bath/sqft + condition + days-to-sell (fast-sell premium emphasized).

const { useState, useMemo } = React;

const fmt = (n) => "$" + Math.round(n).toLocaleString();

const CostLine = ({ title, description, mode, setMode, dollars, percent, salePrice, onPctChange, onDollarChange, allowToggle = true }) => {
  const computedDollars = mode === "%" ? Math.round(salePrice * (percent / 100)) : dollars;
  const computedPercent = mode === "$" && salePrice > 0 ? ((dollars / salePrice) * 100) : percent;

  return (
    <div className="ehc-line">
      <h4 className="ehc-line-title">{title}</h4>
      <p className="ehc-line-desc">{description}</p>
      <div className={"ehc-input-row" + (allowToggle ? " has-toggle" : "")}>
        <div className="ehc-input-pill">
          {mode === "%" ? (
            <>
              <input type="number" value={percent} step="0.1" onChange={(e) => onPctChange(Number(e.target.value) || 0)} className="ehc-input" />
              <span className="ehc-unit">%</span>
              {allowToggle && <span className="ehc-input-aside">{fmt(computedDollars)}</span>}
            </>
          ) : (
            <>
              <span className="ehc-unit">$</span>
              <input type="number" value={dollars} step="100" onChange={(e) => onDollarChange(Number(e.target.value) || 0)} className="ehc-input" />
              {allowToggle && salePrice > 0 && <span className="ehc-input-aside">{computedPercent.toFixed(1)}%</span>}
            </>
          )}
        </div>
        {allowToggle && (
          <div className="ehc-toggle">
            <button className={"ehc-toggle-btn" + (mode === "$" ? " active" : "")} onClick={() => setMode("$")}>$</button>
            <button className={"ehc-toggle-btn" + (mode === "%" ? " active" : "")} onClick={() => setMode("%")}>%</button>
          </div>
        )}
      </div>
      <a className="ehc-learn" href="#" onClick={(e) => e.preventDefault()}>Learn more</a>
    </div>
  );
};

const Calculator = () => {
  const [salePrice, setSalePrice] = useState(200000);
  const [agent, setAgent] = useState({ pct: 6, dol: 12000, mode: "%" });
  const [staging, setStaging] = useState({ pct: 4, dol: 8000, mode: "%" });
  const [concessions, setConcessions] = useState({ pct: 2, dol: 4000, mode: "%" });
  const [overlap, setOverlap] = useState({ pct: 2, dol: 3500, mode: "$" });
  const [titleEscrow, setTitleEscrow] = useState({ pct: 3, dol: 6000, mode: "%" });
  const [repairs, setRepairs] = useState({ pct: 0, dol: 10000, mode: "$" });
  const [mortgage, setMortgage] = useState(0);

  // Capture form
  const [address, setAddress] = useState("");
  const [beds, setBeds] = useState(3);
  const [baths, setBaths] = useState(2);
  const [sqft, setSqft] = useState(1800);
  const [condition, setCondition] = useState("good"); // rehab | fair | good | great
  const [daysToSell, setDaysToSell] = useState(14);
  const [submitted, setSubmitted] = useState(false);
  const [submitting, setSubmitting] = useState(false);

  // GoHighLevel webhook URL — swap with the live endpoint when ready.
  // Set to null to skip the network call (form will still show success).
  const GHL_WEBHOOK_URL = window.__EHB_GHL_WEBHOOK || null;
  const CALLBACK_PHONE = "888-379-6263";
  const CALLBACK_PHONE_DISPLAY = "(888) 379-6263";

  const handleSubmit = async () => {
    if (!address.trim() || submitting) return;
    setSubmitting(true);
    const payload = {
      source: "elite-home-bids:calculator",
      submittedAt: new Date().toISOString(),
      address, beds, baths, sqft, condition, daysToSell,
      salePrice,
      costs: {
        agentFees: { mode: agent.mode, percent: agent.pct, dollars: agentD },
        stagingPrep: { mode: staging.mode, percent: staging.pct, dollars: stagingD },
        sellerConcessions: { mode: concessions.mode, percent: concessions.pct, dollars: concessD },
        ownershipOverlap: { mode: overlap.mode, percent: overlap.pct, dollars: overlapD },
        titleEscrow: { mode: titleEscrow.mode, percent: titleEscrow.pct, dollars: titleD },
        repairs: { dollars: repairsD },
        mortgagePayoff: mortgage,
        totalCosts,
      },
      netProceeds,
      fastSellPremiumPct: fastSellPremium * 100,
    };
    if (GHL_WEBHOOK_URL) {
      try {
        await fetch(GHL_WEBHOOK_URL, {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify(payload),
          mode: "no-cors",
        });
      } catch (e) {
        console.warn("[EHB] GHL submit failed", e);
      }
    } else {
      console.log("[EHB] Lock-in submission (GHL webhook not set):", payload);
    }
    setSubmitting(false);
    setSubmitted(true);
  };

  const resolve = (line) => line.mode === "%" ? Math.round(salePrice * (line.pct / 100)) : line.dol;
  const agentD = resolve(agent), stagingD = resolve(staging), concessD = resolve(concessions),
        overlapD = resolve(overlap), titleD = resolve(titleEscrow), repairsD = resolve(repairs);
  const totalCosts = agentD + stagingD + concessD + overlapD + titleD + repairsD;
  const netProceeds = Math.max(0, salePrice - totalCosts - mortgage);

  // Fast-sell premium estimate
  const fastSellPremium = useMemo(() => {
    if (daysToSell <= 7) return 0.06;
    if (daysToSell <= 14) return 0.04;
    if (daysToSell <= 30) return 0.02;
    if (daysToSell <= 45) return 0.005;
    return 0;
  }, [daysToSell]);

  const setLineFactory = (line, set) => ({
    setMode: (m) => set({ ...line, mode: m }),
    onPctChange: (v) => set({ ...line, pct: v, mode: "%" }),
    onDollarChange: (v) => set({ ...line, dol: v, mode: "$" }),
  });

  return (
    <div className="ehc-root">
      <style>{`
        .ehc-root {
          display: grid;
          grid-template-columns: 0.85fr 1.15fr;
          gap: 32px;
          align-items: start;
        }
        @media (max-width: 980px) { .ehc-root { grid-template-columns: 1fr; } }

        .ehc-left { position: sticky; top: 92px; display: flex; flex-direction: column; gap: 16px; }
        @media (max-width: 980px) { .ehc-left { position: static; } }

        /* === Net Proceeds — chrome black with gold accent + light reflection === */
        .ehc-net {
          --gold-1: #f6d68a;
          --gold-2: #e9b840;
          --gold-3: #b88018;
          background:
            /* top hard chrome highlight */
            linear-gradient(180deg, rgba(255,255,255,0.10) 0%, transparent 12%),
            /* directional silver sweep */
            linear-gradient(155deg,
              #2a2f3d 0%,
              #181b25 18%,
              #0e1118 38%,
              #0a0c12 50%,
              #0e1118 62%,
              #1c2030 82%,
              #2a2f3d 100%);
          color: #fff;
          border-radius: 18px;
          padding: 36px 32px;
          text-align: center;
          position: relative;
          overflow: hidden;
          border: 1px solid rgba(255,255,255,0.10);
          box-shadow:
            0 30px 60px -25px rgba(0,0,0,0.65),
            0 1px 0 rgba(255,255,255,0.10) inset,
            0 -1px 0 rgba(0,0,0,0.4) inset,
            0 0 0 1px rgba(233,184,64,0.10) inset;
        }
        /* primary directional gloss */
        .ehc-net::before {
          content: ""; position: absolute; inset: 0;
          background:
            /* curved top reflection arc */
            radial-gradient(120% 60% at 50% -10%, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.04) 30%, transparent 55%),
            /* gold spill bottom-right */
            radial-gradient(70% 60% at 100% 110%, rgba(233,184,64,0.16) 0%, transparent 55%),
            /* cool blue spill top-left */
            radial-gradient(50% 50% at -10% 0%, rgba(120,160,255,0.10) 0%, transparent 60%);
          pointer-events: none;
        }
        /* moving sheen sweep */
        .ehc-net::after {
          content: ""; position: absolute; inset: 0;
          background-image: linear-gradient(115deg,
            transparent 35%,
            rgba(255,255,255,0.04) 45%,
            rgba(246,214,138,0.22) 50%,
            rgba(255,255,255,0.04) 55%,
            transparent 65%);
          background-size: 250% 100%;
          background-position: -120% 0;
          mix-blend-mode: screen;
          pointer-events: none;
          animation: ehc-sheen 7s ease-in-out infinite;
        }
        @keyframes ehc-sheen {
          0%, 88%, 100% { background-position: -120% 0; opacity: 0; }
          50% { background-position: 220% 0; opacity: 1; }
        }
        .ehc-net > * { position: relative; z-index: 1; }
        .ehc-net-label {
          font-family: 'JetBrains Mono', monospace;
          font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
          color: rgba(246,214,138,0.85);
          text-shadow: 0 1px 2px rgba(0,0,0,0.5);
        }
        .ehc-net-amt {
          font-family: 'Manrope', sans-serif;
          font-weight: 800;
          font-size: clamp(52px, 6.5vw, 74px); line-height: 1.0;
          letter-spacing: -0.045em; margin: 14px 0 28px;
          font-variant-numeric: tabular-nums;
          background: linear-gradient(180deg, #fff5d6 0%, var(--gold-1) 35%, var(--gold-2) 70%, var(--gold-3) 100%);
          -webkit-background-clip: text;
          background-clip: text;
          -webkit-text-fill-color: transparent;
          filter: drop-shadow(0 2px 0 rgba(0,0,0,0.55)) drop-shadow(0 6px 24px rgba(233,184,64,0.30));
        }
        .ehc-net-meta {
          display: grid; grid-template-columns: 1fr 1fr;
          padding-top: 22px;
          border-top: 1px solid rgba(255,255,255,0.10);
          gap: 12px;
        }
        .ehc-net-meta .k {
          font-family: 'JetBrains Mono', monospace;
          font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
          color: rgba(255,255,255,0.55); margin-bottom: 6px;
          text-shadow: 0 1px 2px rgba(0,0,0,0.5);
        }
        .ehc-net-meta .v {
          font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums;
          color: #fff;
          text-shadow: 0 1px 3px rgba(0,0,0,0.6), 0 0 1px rgba(255,255,255,0.4);
          font-family: 'Manrope', sans-serif;
          letter-spacing: -0.02em;
        }

        /* === Lock-in offer form === */
        .ehc-compare {
          background: #fff;
          border: 1px solid var(--line);
          border-radius: 18px;
          padding: 28px;
        }
        .ehc-compare h3 {
          font-family: 'Manrope', sans-serif; font-weight: 700;
          font-size: 22px; letter-spacing: -0.025em; margin: 0 0 8px; line-height: 1.2;
          text-align: center;
        }
        .ehc-compare p.intro {
          font-size: 13px; color: var(--ink-2); line-height: 1.55; margin: 0 0 20px; text-align: center;
        }

        .ehc-form-step {
          font-family: 'JetBrains Mono', monospace; font-size: 10px;
          letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent);
          margin-bottom: 6px;
        }

        .ehc-form-field { margin-bottom: 14px; }
        .ehc-form-label {
          font-size: 12px; color: var(--ink-2); font-weight: 500;
          margin-bottom: 6px; display: block;
        }

        .ehc-form-input {
          width: 100%; padding: 11px 14px;
          border: 1px solid var(--line); border-radius: 10px;
          font-size: 14px; font-family: inherit; color: var(--ink);
          background: #fff;
          transition: border-color .15s ease, box-shadow .15s ease;
        }
        .ehc-form-input:focus {
          outline: none; border-color: var(--accent);
          box-shadow: 0 0 0 3px rgba(23,89,255,0.12);
        }

        .ehc-form-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

        .ehc-cond { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
        .ehc-cond-pill {
          padding: 8px 4px; text-align: center; border: 1px solid var(--line);
          border-radius: 8px; background: #fff; font-size: 11.5px;
          color: var(--ink-2); cursor: pointer; transition: all .12s ease;
        }
        .ehc-cond-pill.active {
          background: var(--ink); color: #fff; border-color: var(--ink);
        }
        .ehc-cond-pill:not(.active):hover { border-color: var(--ink-2); color: var(--ink); }

        .ehc-days-wrap { display: flex; align-items: center; gap: 10px; }
        .ehc-days-input {
          flex: 1;
          -webkit-appearance: none; appearance: none;
          height: 4px; border-radius: 4px; outline: none;
        }
        .ehc-days-input::-webkit-slider-thumb {
          -webkit-appearance: none; appearance: none;
          width: 18px; height: 18px; border-radius: 50%;
          background: #fff; border: 2px solid var(--accent);
          box-shadow: 0 2px 6px rgba(23,89,255,0.3);
          cursor: pointer;
        }
        .ehc-days-val {
          font-family: 'JetBrains Mono', monospace; font-size: 12px;
          font-weight: 600; color: var(--accent); min-width: 56px; text-align: right;
        }

        .ehc-premium {
          background: linear-gradient(135deg, rgba(31,138,76,0.08), rgba(31,138,76,0.02));
          border: 1px solid rgba(31,138,76,0.2);
          border-radius: 10px;
          padding: 10px 12px;
          font-size: 12px; color: #15703c;
          margin-top: 10px;
          display: flex; align-items: center; gap: 8px;
          line-height: 1.4;
        }
        .ehc-premium-zero {
          background: var(--bg-soft); border-color: var(--line); color: var(--muted);
        }
        .ehc-premium strong { color: #0d5a2e; }

        .ehc-form-cta {
          width: 100%;
          padding: 13px 18px;
          background: var(--ink); color: #fff;
          border-radius: 12px; border: none;
          font-size: 14px; font-weight: 600; font-family: inherit;
          cursor: pointer;
          margin-top: 8px;
          transition: all .15s ease;
        }
        .ehc-form-cta:hover { background: var(--accent); transform: translateY(-1px); }

        .ehc-success {
          padding: 18px; text-align: center;
          background: linear-gradient(135deg, rgba(23,89,255,0.06), rgba(23,89,255,0.02));
          border: 1px solid rgba(23,89,255,0.2);
          border-radius: 12px;
        }
        .ehc-success strong { display: block; margin-bottom: 4px; font-size: 15px; }

        .ehc-callback {
          padding: 14px 16px; border-radius: 12px;
          background: linear-gradient(135deg, #0c0e14 0%, #1a1f2e 100%);
          color: #fff;
          text-align: left;
          margin-top: 8px;
        }
        .ehc-callback-label {
          font-size: 12px; color: rgba(255,255,255,0.7); margin-bottom: 6px;
        }
        .ehc-callback-num {
          display: inline-flex; align-items: center; gap: 8px;
          font-family: 'Manrope', sans-serif;
          font-size: 22px; font-weight: 700; letter-spacing: -0.025em;
          color: #fff; text-decoration: none;
        }
        .ehc-callback-num svg { color: var(--gold-2, #e9b840); }
        .ehc-callback-num:hover { color: #ffe4a3; }

        /* Speed banner above the cost lines */
        .ehc-speed-banner {
          padding: 16px 18px; border-radius: 14px;
          background: linear-gradient(135deg, rgba(31,138,76,0.10) 0%, rgba(31,138,76,0.02) 100%);
          border: 1px solid rgba(31,138,76,0.22);
          display: flex; align-items: flex-start; gap: 12px;
        }
        .ehc-speed-icon {
          flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%;
          background: rgba(31,138,76,0.15); color: #15703c;
          display: grid; place-items: center;
        }
        .ehc-speed-text { font-size: 13.5px; line-height: 1.5; color: #15703c; }
        .ehc-speed-text strong { color: #0d5a2e; font-weight: 700; }

        /* RIGHT side */
        .ehc-right { display: flex; flex-direction: column; gap: 24px; }

        .ehc-line h4.ehc-line-title {
          font-size: 17px; font-weight: 700; margin: 0 0 6px; color: var(--ink);
          font-family: 'Manrope', sans-serif; letter-spacing: -0.02em;
        }
        .ehc-line-desc { font-size: 13px; color: var(--ink-2); margin: 0 0 12px; line-height: 1.55; }

        .ehc-input-row { display: flex; gap: 8px; align-items: stretch; }
        .ehc-input-pill {
          flex: 1; display: flex; align-items: center; gap: 6px;
          border: 1px solid var(--line); border-radius: 12px;
          padding: 0 14px; height: 52px; background: #fff;
          transition: border-color .15s ease, box-shadow .15s ease;
        }
        .ehc-input-pill:focus-within {
          border-color: var(--accent);
          box-shadow: 0 0 0 3px rgba(23,89,255,0.12);
        }
        .ehc-unit { color: var(--ink-2); font-size: 15px; }
        .ehc-input {
          flex: 1; min-width: 0; border: none; outline: none; background: transparent;
          font-size: 15px; font-family: inherit; color: var(--ink);
          font-variant-numeric: tabular-nums;
          -moz-appearance: textfield;
        }
        .ehc-input::-webkit-outer-spin-button, .ehc-input::-webkit-inner-spin-button {
          -webkit-appearance: none; margin: 0;
        }
        .ehc-input-aside {
          font-family: 'JetBrains Mono', monospace;
          font-size: 12.5px; color: var(--muted); letter-spacing: 0.04em;
          padding-left: 8px; border-left: 1px solid var(--line);
        }

        .ehc-toggle {
          display: flex; gap: 0;
          background: var(--bg-soft); border-radius: 999px; padding: 4px;
          border: 1px solid var(--line);
        }
        .ehc-toggle-btn {
          width: 38px; height: 44px; border-radius: 999px;
          border: none; background: transparent;
          font-size: 15px; font-weight: 500; color: var(--ink-2);
          cursor: pointer; transition: all .15s ease;
          font-family: inherit;
        }
        .ehc-toggle-btn.active { background: var(--ink); color: #fff; }

        .ehc-learn {
          display: inline-block; margin-top: 10px;
          font-size: 12.5px; color: var(--ink); text-decoration: underline;
          text-decoration-color: var(--line); text-underline-offset: 4px;
        }
        .ehc-learn:hover { text-decoration-color: var(--accent); color: var(--accent); }

        .ehc-saleprice .ehc-input-pill { height: 60px; }
        .ehc-saleprice .ehc-input { font-size: 18px; font-weight: 500; }
        .ehc-saleprice-link {
          margin-top: 10px; display: inline-block;
          color: var(--accent); font-size: 13px; font-weight: 500;
        }
      `}</style>

      <div className="ehc-left">
        <div className="ehc-net">
          <div className="ehc-net-label">Net proceeds</div>
          <div className="ehc-net-amt">{fmt(netProceeds)}</div>
          <div className="ehc-net-meta">
            <div>
              <div className="k">Home sale price</div>
              <div className="v">{fmt(salePrice)}</div>
            </div>
            <div>
              <div className="k">Total costs to sell</div>
              <div className="v">{fmt(totalCosts)}</div>
            </div>
          </div>
        </div>

        <div className="ehc-compare">
          {!submitted ? (
            <>
              <h3>Enter your home address<br/>to lock in your offer</h3>
              <p className="intro">Two minutes to enter, twenty-four hours to bid. Tell us about your home — we'll match the right buyers.</p>

              <div className="ehc-form-field">
                <label className="ehc-form-label">Property address</label>
                <input className="ehc-form-input" placeholder="123 Main St, City, State" value={address} onChange={(e) => setAddress(e.target.value)} />
              </div>

              <div className="ehc-form-row">
                <div className="ehc-form-field">
                  <label className="ehc-form-label">Beds</label>
                  <input className="ehc-form-input" type="number" min="1" max="10" value={beds} onChange={(e) => setBeds(Number(e.target.value) || 1)} />
                </div>
                <div className="ehc-form-field">
                  <label className="ehc-form-label">Baths</label>
                  <input className="ehc-form-input" type="number" min="1" max="10" step="0.5" value={baths} onChange={(e) => setBaths(Number(e.target.value) || 1)} />
                </div>
                <div className="ehc-form-field">
                  <label className="ehc-form-label">Sq ft</label>
                  <input className="ehc-form-input" type="number" min="200" step="50" value={sqft} onChange={(e) => setSqft(Number(e.target.value) || 200)} />
                </div>
              </div>

              <div className="ehc-form-field">
                <label className="ehc-form-label">Property condition</label>
                <div className="ehc-cond">
                  {[
                    { v: "rehab", l: "Rehab" },
                    { v: "fair", l: "Fair" },
                    { v: "good", l: "Good" },
                    { v: "great", l: "Great" },
                  ].map((c) => (
                    <div key={c.v} className={"ehc-cond-pill" + (condition === c.v ? " active" : "")} onClick={() => setCondition(c.v)}>
                      {c.l}
                    </div>
                  ))}
                </div>
              </div>

              <div className="ehc-form-field">
                <label className="ehc-form-label">How fast do you need to sell?</label>
                <div className="ehc-days-wrap">
                  <input
                    type="range" min="7" max="60" step="1"
                    value={daysToSell}
                    onChange={(e) => setDaysToSell(Number(e.target.value))}
                    className="ehc-days-input"
                    style={{ background: `linear-gradient(to right, var(--accent) 0%, var(--accent) ${((daysToSell - 7) / 53) * 100}%, #e7e8ec ${((daysToSell - 7) / 53) * 100}%, #e7e8ec 100%)` }}
                  />
                  <span className="ehc-days-val">{daysToSell} days</span>
                </div>
                <div className={"ehc-premium" + (fastSellPremium === 0 ? " ehc-premium-zero" : "")}>
                  {fastSellPremium > 0 ? (
                    <>
                      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4"><path d="M5 12l4 4 10-10"/></svg>
                      <span>Sellers closing this fast typically net <strong>+{(fastSellPremium * 100).toFixed(1)}%</strong> over slower sales.</span>
                    </>
                  ) : (
                    <span>Faster timelines unlock a competitive premium — try moving to under 45 days.</span>
                  )}
                </div>
              </div>

              <button className="ehc-form-cta" onClick={handleSubmit} disabled={!address.trim() || submitting}>
                {submitting ? "Sending…" : "Lock in my offer →"}
              </button>
            </>
          ) : (
            <div className="ehc-success">
              <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" strokeWidth="1.8" style={{margin: "0 auto 8px", display: "block"}}>
                <circle cx="12" cy="12" r="10"/><path d="M8 12l3 3 5-7"/>
              </svg>
              <strong>You're in the queue.</strong>
              <span style={{fontSize: 13, color: "var(--ink-2)", display: "block", marginBottom: 14}}>The 24-hour buyer window opens at midnight. We'll text you when bids start landing.</span>
              <div className="ehc-callback">
                <div className="ehc-callback-label">Want a call now? Our AI agent is standing by.</div>
                <a className="ehc-callback-num" href={"tel:+1" + CALLBACK_PHONE.replace(/-/g, "")}>
                  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/></svg>
                  {CALLBACK_PHONE_DISPLAY}
                </a>
              </div>
            </div>
          )}
        </div>
      </div>

      <div className="ehc-right">
        <div className="ehc-speed-banner">
          <div className="ehc-speed-icon">
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4"><path d="M13 2L3 14h7l-1 8 10-12h-7l1-8z"/></svg>
          </div>
          <div className="ehc-speed-text">
            <strong>The faster you sell, the more you keep.</strong> Sellers who close in 7–14 days typically net 4–7% more than those who wait 60+. Adjust the inputs to see your number.
          </div>
        </div>
        <div className="ehc-line ehc-saleprice">
          <h4 className="ehc-line-title">Home sale price</h4>
          <p className="ehc-line-desc">Enter the selling price of your home.</p>
          <div className="ehc-input-row">
            <div className="ehc-input-pill">
              <span className="ehc-unit">$</span>
              <input type="number" className="ehc-input" value={salePrice} step="1000" onChange={(e) => setSalePrice(Math.max(0, Number(e.target.value) || 0))} />
            </div>
          </div>
          <a className="ehc-saleprice-link" href="#">See what Elite Home Bids can offer for your home →</a>
        </div>

        <CostLine title="Real estate agent fees" description="In a traditional home sale, the seller pays fees to both their agent and the buyer's agent. It's common for the total commission to be around 5–6% of the sale price."
          mode={agent.mode} dollars={agent.dol} percent={agent.pct} salePrice={salePrice} {...setLineFactory(agent, setAgent)} />
        <CostLine title="Staging and prep work" description="This is the total cost of getting your home ready to show to potential buyers. This varies depending on whether you pay for staging, cosmetic improvements, and storage."
          mode={staging.mode} dollars={staging.dol} percent={staging.pct} salePrice={salePrice} {...setLineFactory(staging, setStaging)} />
        <CostLine title="Seller concessions" description="Buyers may ask sellers to pay certain costs on their behalf. The amount a buyer can request is limited by their loan type and size of their downpayment. When buyers ask for concessions, they typically ask for 0 – 2% of the home sale price."
          mode={concessions.mode} dollars={concessions.dol} percent={concessions.pct} salePrice={salePrice} {...setLineFactory(concessions, setConcessions)} />
        <CostLine title="Home ownership and overlap costs" description="These are costs you incur transitioning from one home to the next. Examples include paying for a short-term rental, paying two mortgage payments, or leasing your home back from the buyer before you move."
          mode={overlap.mode} dollars={overlap.dol} percent={overlap.pct} salePrice={salePrice} {...setLineFactory(overlap, setOverlap)} />
        <CostLine title="Title, escrow, notary, and transfer tax" description="Also referred to as closing costs, these fees can range from 1% to 3% of the sale price depending on where you live."
          mode={titleEscrow.mode} dollars={titleEscrow.dol} percent={titleEscrow.pct} salePrice={salePrice} {...setLineFactory(titleEscrow, setTitleEscrow)} />
        <CostLine title="Repairs needed to sell home" description="Once you've agreed to a buyer's offer, they'll inspect your home for defects. The buyer will usually ask you to make repairs or request a credit equal to the expected repair cost."
          mode={repairs.mode} dollars={repairs.dol} percent={repairs.pct} salePrice={salePrice} allowToggle={false} {...setLineFactory(repairs, setRepairs)} />

        <div className="ehc-line">
          <h4 className="ehc-line-title">Mortgage payoff amount</h4>
          <p className="ehc-line-desc">This is how much it would cost to pay off your mortgage today. Note that this may not be the same as your current balance.</p>
          <div className="ehc-input-row">
            <div className="ehc-input-pill">
              <span className="ehc-unit">$</span>
              <input type="number" className="ehc-input" value={mortgage} step="1000" onChange={(e) => setMortgage(Math.max(0, Number(e.target.value) || 0))} />
            </div>
          </div>
          <a className="ehc-learn" href="#" onClick={(e) => e.preventDefault()}>Learn more</a>
        </div>
      </div>
    </div>
  );
};

const calcRoot = ReactDOM.createRoot(document.getElementById("calculator-mount"));
calcRoot.render(<Calculator />);
