/* Presentation — the full-screen, customer-facing Customer Presentation Mode.
   Three screens: Why Us (social proof) · Our Solution (door-style showcase) ·
   Investment (3-tier reveal → signature → Agreed Investment → contract).
   All data is app-owned (window.REVIEWS, window.DOOR_STYLES, the pricing
   engine) — no live E31 calls happen during a pitch. */

const P = window.Ds1Threshold_e046d3;

// One-time keyframe injection for the pricing-tier reveal.
function ensurePresStyles() {
  if (document.getElementById("od-pres-anim")) return;
  const s = document.createElement("style");
  s.id = "od-pres-anim";
  s.textContent = "@keyframes odTierIn{from{opacity:0;transform:translateY(18px) scale(.97)}to{opacity:1;transform:none}}@keyframes odHeroIn{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}";
  document.head.appendChild(s);
}
const prefersReduced = () => window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;

// ── Stars ─────────────────────────────────────────────────────────────────
function StarRow({ rating = 5, size = 16 }) {
  const GOLD = "#E0A12C";
  return (
    <span style={{ display: "inline-flex", gap: 2 }}>
      {[0,1,2,3,4].map((i) => (
        <Icon key={i} name="Star" size={size} color={i < rating ? GOLD : "var(--border-default)"} fill={i < rating ? GOLD : "transparent"} />
      ))}
    </span>
  );
}

function ReviewCard({ r }) {
  return (
    <div style={{ flex: "1 1 0", minWidth: 240, background: "var(--surface-card)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-xl)", boxShadow: "var(--shadow-sm)", padding: "20px 20px 18px", display: "flex", flexDirection: "column" }}>
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 12 }}>
        <StarRow rating={r.rating} size={15} />
        <span style={{ fontSize: "var(--text-2xs)", fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.08em", color: "var(--text-faint)" }}>{r.source}</span>
      </div>
      <p style={{ margin: 0, fontSize: "var(--text-sm)", lineHeight: "var(--leading-relaxed)", color: "var(--text-secondary)", flex: 1 }}>“{r.content}”</p>
      <div style={{ marginTop: 14, paddingTop: 12, borderTop: "1px solid var(--border-subtle)" }}>
        <div style={{ fontSize: "var(--text-sm)", fontWeight: 700, color: "var(--text-primary)" }}>{r.name}</div>
        <div style={{ fontSize: "var(--text-xs)", color: "var(--text-muted)", marginTop: 1 }}>{r.location}</div>
      </div>
    </div>
  );
}

function ValueScreen() {
  const reviews = window.REVIEWS || { totalReviewsCount: 0, reviewsData: [] };
  const pillars = (window.VALUE_FEATURES || []).filter((f) => f.title !== "Worry-Free Guarantee");
  const guarantee = (window.VALUE_FEATURES || []).find((f) => f.title === "Worry-Free Guarantee");
  return (
    <div style={{ maxWidth: "var(--panel-max)", margin: "0 auto", padding: "40px 32px" }}>
      {/* Social proof hero */}
      <div style={{ textAlign: "center", marginBottom: 30 }}>
        <P.Eyebrow tone="primary" style={{ marginBottom: 14 }}>Trusted Across San Antonio</P.Eyebrow>
        <div style={{ display: "inline-flex", alignItems: "baseline", gap: 14, flexWrap: "wrap", justifyContent: "center" }}>
          <span style={{ fontFamily: "var(--font-num)", fontVariantNumeric: "tabular-nums", fontWeight: 800, fontSize: "var(--text-6xl, 60px)", letterSpacing: "var(--tracking-tight)", color: "var(--color-primary-deep)", lineHeight: 1 }}>{reviews.totalReviewsCount.toLocaleString()}</span>
          <span style={{ fontSize: "var(--text-2xl)", fontWeight: 700, color: "var(--text-primary)" }}>five-star reviews</span>
        </div>
        <div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 10, marginTop: 12 }}>
          <StarRow rating={5} size={20} />
          <span style={{ fontSize: "var(--text-base)", color: "var(--text-muted)" }}>{reviews.averageRating} average · verified homeowners</span>
        </div>
      </div>

      {/* Featured reviews */}
      <div style={{ display: "flex", gap: 14, marginBottom: 40, flexWrap: "wrap" }}>
        {reviews.reviewsData.slice(0, 3).map((r, i) => <ReviewCard key={i} r={r} />)}
      </div>

      {/* Value pillars */}
      <P.Eyebrow style={{ textAlign: "center", display: "block", marginBottom: 18 }}>Why One Day</P.Eyebrow>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 12, marginBottom: 36 }}>
        {pillars.map((f) => (
          <div key={f.title} style={{ background: "var(--surface-card)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-xl)", padding: "20px 16px", textAlign: "center" }}>
            <div style={{ width: 44, height: 44, margin: "0 auto 14px", borderRadius: "var(--radius-lg)", background: "var(--color-primary-soft)", display: "flex", alignItems: "center", justifyContent: "center", color: "var(--color-primary-deep)" }}>
              <Icon name={f.icon} size={22} />
            </div>
            <h3 style={{ margin: "0 0 6px", fontSize: "var(--text-sm)", fontWeight: 700, color: "var(--text-primary)" }}>{f.title}</h3>
            <p style={{ margin: 0, fontSize: "var(--text-xs)", lineHeight: "var(--leading-normal)", color: "var(--text-muted)" }}>{f.desc}</p>
          </div>
        ))}
      </div>

      {/* Worry-Free Guarantee band */}
      {guarantee && (
        <div style={{ background: "var(--surface-hero)", borderRadius: "var(--radius-2xl)", padding: "28px 32px", display: "flex", alignItems: "center", gap: 22, marginBottom: 36 }}>
          <div style={{ width: 56, height: 56, flexShrink: 0, borderRadius: "var(--radius-xl)", background: "rgba(255,255,255,0.1)", display: "flex", alignItems: "center", justifyContent: "center", color: "#fff" }}>
            <Icon name="ShieldCheck" size={28} />
          </div>
          <div>
            <h3 style={{ margin: "0 0 5px", fontSize: "var(--text-xl)", fontWeight: 700, color: "#fff" }}>The Absolutely, Positively, Worry-Free Guarantee</h3>
            <p style={{ margin: 0, fontSize: "var(--text-sm)", lineHeight: "var(--leading-normal)", color: "rgba(255,255,255,0.78)" }}>{guarantee.desc}</p>
          </div>
        </div>
      )}

      {/* Press */}
      <P.Eyebrow size="2xs" style={{ textAlign: "center", display: "block", marginBottom: 14 }}>As Seen In</P.Eyebrow>
      <div style={{ display: "flex", justifyContent: "center", alignItems: "center", gap: 30, flexWrap: "wrap" }}>
        {(window.PRESS || []).map((b) => <PressLogo key={b.key} item={b} height={28} />)}
      </div>
    </div>
  );
}

// ── Door-slab illustration (on-brand stand-in until real photography) ───────
function StyleDoor({ variant = "shaker2", hex = "#EAE7DD", w = "100%", h = 184 }) {
  const lum = (() => { const c = (hex || "#eee").replace("#",""); const r=parseInt(c.slice(0,2),16),g=parseInt(c.slice(2,4),16),b=parseInt(c.slice(4,6),16); return (0.299*r+0.587*g+0.114*b); })();
  const dark = lum < 140;
  const line = dark ? "rgba(255,255,255,0.20)" : "rgba(0,0,0,0.12)";
  const inset = { borderRadius: 3, boxShadow: `inset 0 0 0 1.5px ${line}`, background: dark ? "rgba(255,255,255,0.05)" : "rgba(0,0,0,0.028)" };
  const pad = 14, gap = 9;
  const body = (() => {
    switch (variant) {
      case "flat": return <div style={{ flex: 1, ...inset }} />;
      case "shaker1": return <div style={{ flex: 1, ...inset }} />;
      case "shaker2": return <React.Fragment><div style={{ flex: "0 0 36%", ...inset }} /><div style={{ flex: 1, ...inset }} /></React.Fragment>;
      case "panel3": return <React.Fragment><div style={{ flex: 1, ...inset }} /><div style={{ flex: 1, ...inset }} /><div style={{ flex: 1, ...inset }} /></React.Fragment>;
      case "panel2": return <React.Fragment><div style={{ flex: "0 0 30%", ...inset, borderRadius: "12px 12px 3px 3px" }} /><div style={{ flex: 1, ...inset }} /></React.Fragment>;
      case "panel6": return (
        <div style={{ flex: 1, display: "grid", gridTemplateColumns: "1fr 1fr", gridTemplateRows: "1fr 1fr 1fr", gap }}>
          {[0,1,2,3,4,5].map((i) => <div key={i} style={inset} />)}
        </div>);
      case "louver": return <div style={{ flex: 1, display: "flex", flexDirection: "column", gap: 5 }}>{Array.from({length:7}).map((_,i)=><div key={i} style={{ flex: 1, borderRadius: 2, background: dark ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.05)", boxShadow: `inset 0 1px 0 ${line}` }} />)}</div>;
      case "lite": return <React.Fragment><div style={{ flex: "0 0 52%", borderRadius: 3, background: dark ? "rgba(255,255,255,0.14)" : "rgba(190,205,214,0.4)", boxShadow: `inset 0 0 0 1.5px ${line}` }} /><div style={{ flex: 1, ...inset }} /></React.Fragment>;
      case "barn": return <React.Fragment><div style={{ flex: 1, ...inset }} /><div style={{ flex: 1, ...inset }} /><div style={{ position: "absolute", inset: pad, borderRadius: 2, background: `linear-gradient(135deg,transparent 49%, ${line} 49%, ${line} 51%, transparent 51%), linear-gradient(45deg,transparent 49%, ${line} 49%, ${line} 51%, transparent 51%)` }} /></React.Fragment>;
      default: return <div style={{ flex: 1, ...inset }} />;
    }
  })();
  return (
    <div style={{ width: w, height: h, borderRadius: 7, background: hex, border: `1px solid ${line}`, boxShadow: "var(--shadow-sm)", padding: pad, boxSizing: "border-box", display: "flex", flexDirection: "column", gap, position: "relative" }}>
      {body}
      <span style={{ position: "absolute", right: 9, top: "50%", width: 5, height: 22, borderRadius: 3, background: dark ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.32)" }} />
    </div>
  );
}

function CoreChips({ cores, small }) {
  const avail = Object.keys(cores || {}).filter((k) => cores[k]);
  return (
    <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
      {avail.map((c) => (
        <span key={c} style={{ fontSize: small ? "var(--text-2xs)" : "var(--text-xs)", fontWeight: 600, color: "var(--color-primary-deep)", background: "var(--color-primary-soft)", border: "1px solid var(--color-primary-ring)", borderRadius: "var(--radius-full)", padding: small ? "2px 8px" : "3px 10px" }}>{c}</span>
      ))}
    </div>
  );
}

function SolutionScreen() {
  const state = window.__OD_ACTIVE || window.DEFAULT_QUOTE_STATE;
  const cust = Object.assign({}, window.CUSTOMER, (state && state.customer) || {});
  const doors = (state.interior || []).reduce((s, l) => s + (Number(l.qty) || 0), 0);
  const today = new Date().toLocaleString("en-US", { month: "long", day: "numeric", year: "numeric" });
  const groups = window.DOOR_STYLES || [];
  const allStyles = groups.flatMap((g) => g.styles);
  const quoteStyle = (state.interior || [])[0] && (state.interior || [])[0].style;
  const defaultName = (allStyles.find((s) => quoteStyle && quoteStyle.toLowerCase().includes(s.display_name.toLowerCase())) || allStyles[0] || {}).display_name;
  const [selName, setSelName] = React.useState(defaultName);
  const sel = allStyles.find((s) => s.display_name === selName) || allStyles[0];

  // paint (whites only, kept compact — full custom picker lives in the Calculator)
  const co = state.contractOpts || (state.contractOpts = {});
  const [, force] = React.useReducer((x) => x + 1, 0);
  const WHITES = (window.SW_COLORS || []).filter((c) => c.std);
  const paintName = co.paintName || "Pure White";
  const curPaint = WHITES.find((c) => c.name === paintName) || WHITES[1] || WHITES[0];
  const paintHex = (curPaint && curPaint.hex) || "#EEEBE1";

  return (
    <div style={{ maxWidth: "var(--panel-max)", margin: "0 auto", padding: "36px 32px" }}>
      {/* Personalized header */}
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", marginBottom: 24, gap: 16, flexWrap: "wrap" }}>
        <div>
          <P.Eyebrow tone="primary" style={{ marginBottom: 6 }}>Prepared For You</P.Eyebrow>
          <h2 style={{ margin: 0, fontSize: "var(--text-3xl)", fontWeight: 700, letterSpacing: "-0.02em", color: "var(--text-primary)" }}>{cust.name}</h2>
          <p style={{ margin: "5px 0 0", fontSize: "var(--text-sm)", color: "var(--text-muted)" }}>{cust.address}</p>
        </div>
        <div style={{ textAlign: "right" }}>
          <P.Eyebrow size="2xs" style={{ marginBottom: 5 }}>Your Project · {today}</P.Eyebrow>
          <div style={{ fontSize: "var(--text-sm)", fontWeight: 600, color: "var(--text-secondary)" }}>{doors} interior doors · installed in one day</div>
        </div>
      </div>

      {/* Selected style — "here's what's going in your home" */}
      {sel && (
        <div style={{ background: "var(--surface-hero)", borderRadius: "var(--radius-2xl)", padding: 24, marginBottom: 30, display: "grid", gridTemplateColumns: "150px 1fr", gap: 26, alignItems: "center" }}>
          <StyleDoor variant={sel.variant} hex={paintHex} h={210} />
          <div>
            <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 8 }}>
              <span style={{ fontSize: "var(--text-2xs)", fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.12em", color: "var(--color-accent)" }}>Your Selection</span>
              <span style={{ height: 1, width: 28, background: "rgba(255,255,255,0.25)" }} />
            </div>
            <h3 style={{ margin: "0 0 8px", fontSize: "var(--text-2xl)", fontWeight: 700, color: "#fff" }}>{sel.display_name}</h3>
            <p style={{ margin: "0 0 14px", fontSize: "var(--text-sm)", lineHeight: "var(--leading-normal)", color: "rgba(255,255,255,0.78)", maxWidth: 520 }}>{sel.description}</p>
            <div style={{ display: "flex", gap: 22, marginBottom: 14, flexWrap: "wrap" }}>
              <div><div style={{ fontSize: "var(--text-2xs)", textTransform: "uppercase", letterSpacing: "0.1em", color: "rgba(255,255,255,0.5)", fontWeight: 600 }}>Material</div><div style={{ fontSize: "var(--text-sm)", color: "#fff", fontWeight: 600, marginTop: 2 }}>{sel.material_type}</div></div>
              <div><div style={{ fontSize: "var(--text-2xs)", textTransform: "uppercase", letterSpacing: "0.1em", color: "rgba(255,255,255,0.5)", fontWeight: 600 }}>Texture</div><div style={{ fontSize: "var(--text-sm)", color: "#fff", fontWeight: 600, marginTop: 2 }}>{sel.texture}</div></div>
              <div><div style={{ fontSize: "var(--text-2xs)", textTransform: "uppercase", letterSpacing: "0.1em", color: "rgba(255,255,255,0.5)", fontWeight: 600 }}>Finish</div><div style={{ fontSize: "var(--text-sm)", color: "#fff", fontWeight: 600, marginTop: 2 }}>{paintName}</div></div>
            </div>
            <CoreChips cores={sel.core_types} />
          </div>
        </div>
      )}

      {/* Paint (compact whites) */}
      <P.Eyebrow size="2xs" style={{ marginBottom: 10 }}>Factory Finish · Sherwin-Williams</P.Eyebrow>
      <div style={{ display: "flex", flexWrap: "wrap", gap: 8, marginBottom: 30 }}>
        {WHITES.map((c) => (
          <Swatch key={c.code} n={c.name} c={c.code} hex={c.hex} on={paintName === c.name} onClick={() => { co.paintName = c.name; co.paintCode = c.code; force(); }} />
        ))}
      </div>

      {/* Gallery by category */}
      {groups.map((g) => (
        <div key={g.category} style={{ marginBottom: 26 }}>
          <P.Eyebrow style={{ marginBottom: 14 }}>{g.category}</P.Eyebrow>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(200px, 1fr))", gap: 14 }}>
            {g.styles.map((s) => {
              const on = s.display_name === selName;
              return (
                <button key={s.display_name} onClick={() => setSelName(s.display_name)} style={{ textAlign: "left", cursor: "pointer", padding: 0, background: "var(--surface-card)", border: `2px solid ${on ? "var(--color-primary-deep)" : "var(--border-subtle)"}`, borderRadius: "var(--radius-xl)", overflow: "hidden", boxShadow: on ? "var(--shadow-md)" : "var(--shadow-xs)", transition: "all var(--duration-fast) var(--ease-standard)" }}>
                  <div style={{ position: "relative", padding: "18px 18px 6px", background: on ? "var(--color-primary-soft)" : "var(--surface-sunken)" }}>
                    <StyleDoor variant={s.variant} hex={on ? paintHex : "#EAE7DD"} h={150} w={104} />
                    {on && <span style={{ position: "absolute", top: 12, right: 12, width: 24, height: 24, borderRadius: "50%", background: "var(--color-primary-deep)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center" }}><Icon name="Check" size={14} /></span>}
                  </div>
                  <div style={{ padding: "12px 14px 14px" }}>
                    <div style={{ fontSize: "var(--text-sm)", fontWeight: 700, color: "var(--text-primary)" }}>{s.display_name}</div>
                    <div style={{ fontSize: "var(--text-2xs)", color: "var(--text-muted)", margin: "3px 0 9px" }}>{s.material_type} · {s.texture}</div>
                    <CoreChips cores={s.core_types} small />
                  </div>
                </button>
              );
            })}
          </div>
        </div>
      ))}
    </div>
  );
}

// Reused small painted-door + swatch (line items / paint chips)
function Swatch({ n, c, hex, on, onClick }) {
  return (
    <button onClick={onClick} title={n + " · " + c}
      style={{ display: "inline-flex", alignItems: "center", gap: 8, padding: "6px 12px 6px 8px", cursor: "pointer", borderRadius: "var(--radius-full)", fontFamily: "var(--font-sans)", fontSize: "var(--text-xs)", fontWeight: 600, border: `1.5px solid ${on ? "var(--color-primary-deep)" : "var(--border-default)"}`, background: on ? "var(--color-primary-soft)" : "var(--surface-card)", color: on ? "var(--color-primary-deep)" : "var(--text-secondary)" }}>
      <span style={{ width: 18, height: 18, borderRadius: "50%", background: hex, border: "1px solid rgba(0,0,0,0.18)", flexShrink: 0 }} />
      {n}<span style={{ fontWeight: 400, opacity: 0.7 }}>{c}</span>
      {on && <Icon name="Check" size={13} />}
    </button>
  );
}

function PricingScreen({ phase, payment, setPayment, signed, sigName, setSigName, onSign }) {
  const quote = window.OneDayPricing.computeQuote(window.__OD_ACTIVE || window.DEFAULT_QUOTE_STATE, window.PRICING_CFG);
  const animate = !prefersReduced();
  const tiers = [
    { key: "retail", label: "National Fair Trade Retail", price: quote.ladder.retail, sub: "Good until 1 year from today" },
    { key: "advertised", label: "Currently Advertised", price: quote.ladder.advertised, sub: "Good for 30 days from today" },
    { key: "today", label: "Today's Investment", price: quote.ladder.today, sub: "Valid today only — expires at midnight" },
  ];
  const deposit = quote.deposit;
  const savings = Math.round(quote.ladder.retail - quote.ladder.today);

  return (
    <div style={{ maxWidth: "var(--panel-max)", margin: "0 auto", padding: "36px 32px" }}>
      <div style={{ textAlign: "center", marginBottom: 28 }}>
        <P.Eyebrow>{phase === 2 ? "Today's Investment — Valid Today Only" : phase === 1 ? "Currently Advertised Investment" : "National Fair Trade Retail Investment"}</P.Eyebrow>
      </div>

      {/* Tiers — future ones never rendered; each reveal animates in */}
      <div style={{ display: "grid", gridTemplateColumns: phase === 0 ? "minmax(0,360px)" : phase === 1 ? "1fr 1fr" : "1fr 1fr 1fr", gap: 18, justifyContent: "center", maxWidth: phase === 0 ? 360 : phase === 1 ? 640 : "none", margin: "0 auto 30px" }}>
        {tiers.map((t, idx) => {
          if (idx > phase) return null;
          const isCurrent = idx === phase;
          return (
            <div key={`${phase}-${t.key}`} style={isCurrent && animate ? { animation: "odTierIn var(--duration-reveal) var(--ease-standard) both" } : undefined}>
              <P.PriceTier label={t.label} price={t.price} sub={t.sub}
                state={isCurrent ? "active" : "struck"}
                highlight={isCurrent && idx === 2}
                savings={isCurrent && idx === 2 ? savings : undefined} />
            </div>
          );
        })}
      </div>

      {/* Payment options */}
      <P.Eyebrow style={{ marginBottom: 14 }}>Current Payment Options</P.Eyebrow>
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16, marginBottom: 24 }}>
        <P.Card padding="md">
          <p style={{ margin: "0 0 12px", fontSize: "var(--text-xs)", color: "var(--text-muted)" }}>(50% Down, Balance Upon Completion)</p>
          <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
            <P.RadioOption selected={payment === "check"} onSelect={() => setPayment("check")} label="Check" />
            <P.RadioOption selected={payment === "cc"} onSelect={() => setPayment("cc")} label="Credit Card" />
          </div>
          <div style={{ marginTop: 12, paddingTop: 12, borderTop: "1px solid var(--border-subtle)", display: "flex", flexDirection: "column", gap: 6 }}>
            <div style={{ display: "flex", justifyContent: "space-between", fontSize: "var(--text-sm)" }}><span style={{ color: "var(--text-muted)" }}>50% Deposit</span><strong style={{ color: "var(--text-primary)", fontVariantNumeric: "tabular-nums" }}>{fmtD(deposit)}</strong></div>
            <div style={{ display: "flex", justifyContent: "space-between", fontSize: "var(--text-sm)" }}><span style={{ color: "var(--text-muted)" }}>Balance on Completion</span><strong style={{ color: "var(--text-primary)", fontVariantNumeric: "tabular-nums" }}>{fmtD(deposit)}</strong></div>
          </div>
        </P.Card>
        <P.Card padding="md">
          <P.Eyebrow size="2xs" style={{ marginBottom: 12 }}>Easy Monthly Payments</P.Eyebrow>
          <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
            {quote.financing.map((plan) => (
              <P.RadioOption key={plan.id} selected={payment === plan.id} onSelect={() => setPayment(plan.id)}
                label={plan.label}
                trailing={<span style={{ fontSize: "var(--text-xl)", fontWeight: 700, color: "var(--color-primary-deep)", fontVariantNumeric: "tabular-nums" }}>{fmt(plan.monthly)}<span style={{ fontSize: "var(--text-2xs)", fontWeight: 400, color: "var(--text-faint)" }}>/mo</span></span>} />
            ))}
          </div>
        </P.Card>
      </div>

      {/* Close — signature + dark-forest Agreed Investment hero */}
      {phase === 2 && (
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 18 }}>
          <P.Card padding="md">
            <P.Eyebrow size="2xs" style={{ marginBottom: 12 }}>Customer Authorization</P.Eyebrow>
            <p style={{ margin: "0 0 14px", fontSize: "var(--text-xs)", lineHeight: "var(--leading-normal)", color: "var(--text-muted)" }}>By signing, I authorize this proposal at the investment shown and agree to the terms presented.</p>
            <label style={{ display: "block", fontSize: "var(--text-2xs)", fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.1em", color: "var(--text-faint)", marginBottom: 6 }}>Type your full name to sign</label>
            <input value={sigName} onChange={(e) => setSigName(e.target.value)} placeholder="Your name"
              style={{ width: "100%", boxSizing: "border-box", height: 64, padding: "0 16px", borderRadius: "var(--radius-lg)", border: `2px solid ${signed ? "var(--color-primary-deep)" : "var(--border-default)"}`, background: "var(--surface-sunken)", outline: "none", fontFamily: "var(--font-signature)", fontStyle: "italic", fontSize: 28, color: "var(--text-primary)" }} />
            <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginTop: 12 }}>
              <span style={{ fontSize: "var(--text-2xs)", color: "var(--text-faint)" }}>{new Date().toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" })}</span>
              {!signed
                ? <P.Button variant="deep" size="md" onClick={onSign} disabled={!sigName.trim()}><Icon name="PenLine" size={15} />Sign &amp; Authorize</P.Button>
                : <span style={{ display: "inline-flex", alignItems: "center", gap: 6, fontSize: "var(--text-sm)", fontWeight: 700, color: "var(--status-sold-fg)" }}><Icon name="CircleCheck" size={16} />Authorized</span>}
            </div>
          </P.Card>

          <P.Card tone="forest" padding="lg" style={animate ? { animation: "odHeroIn var(--duration-base) var(--ease-standard) both" } : undefined}>
            <P.Eyebrow tone="inverse" size="2xs" style={{ marginBottom: 8 }}>Agreed Investment</P.Eyebrow>
            <div style={{ fontFamily: "var(--font-num)", fontVariantNumeric: "tabular-nums", fontWeight: 800, fontSize: "var(--text-5xl)", color: "#fff", lineHeight: 1, letterSpacing: "var(--tracking-tight)" }}>{fmtD(quote.ladder.today)}</div>
            <div style={{ display: "inline-flex", alignItems: "center", gap: 7, marginTop: 14, background: "rgba(255,255,255,0.12)", borderRadius: "var(--radius-full)", padding: "6px 14px" }}>
              <Icon name="TrendingDown" size={15} color="#fff" />
              <span style={{ fontSize: "var(--text-sm)", fontWeight: 700, color: "#fff" }}>You save {fmt(savings)} today!</span>
            </div>
            <div style={{ marginTop: 18, paddingTop: 16, borderTop: "1px solid rgba(255,255,255,0.14)", display: "flex", flexDirection: "column", gap: 8 }}>
              <div style={{ display: "flex", justifyContent: "space-between", fontSize: "var(--text-sm)" }}><span style={{ color: "rgba(255,255,255,0.6)" }}>50% Deposit Today</span><strong style={{ color: "#fff", fontVariantNumeric: "tabular-nums" }}>{fmtD(deposit)}</strong></div>
              <div style={{ display: "flex", justifyContent: "space-between", fontSize: "var(--text-sm)" }}><span style={{ color: "rgba(255,255,255,0.6)" }}>Balance on Completion</span><strong style={{ color: "#fff", fontVariantNumeric: "tabular-nums" }}>{fmtD(deposit)}</strong></div>
            </div>
            <div style={{ marginTop: 14, fontSize: "var(--text-2xs)", color: "rgba(255,255,255,0.5)" }}>Prepared by One Day Doors &amp; Closets of San Antonio · valid today only</div>
          </P.Card>
        </div>
      )}
    </div>
  );
}

function Presentation({ onClose, onContract }) {
  React.useEffect(() => { ensurePresStyles(); }, []);
  const [screen, setScreen] = React.useState("value");
  const [phase, setPhase] = React.useState(0);
  const [payment, setPayment] = React.useState("942");
  const [sigName, setSigName] = React.useState("");
  const [signed, setSigned] = React.useState(false);
  const tabs = [["value", "Why Us"], ["solution", "Our Solution"], ["pricing", "Investment"]];
  const order = ["value", "solution", "pricing"];

  return (
    <div style={{ position: "absolute", inset: 0, zIndex: 50, background: "var(--surface-sunken)", display: "flex", flexDirection: "column" }}>
      {/* Top bar */}
      <div style={{ background: "var(--surface-card)", borderBottom: "1px solid var(--border-subtle)", padding: "10px 20px", display: "flex", alignItems: "flex-end", justifyContent: "space-between", flexShrink: 0 }}>
        <BrandMark height={30} variant="lockup" />
        <div style={{ display: "flex" }}>
          {tabs.map(([key, label]) => (
            <button key={key + (screen === key ? "-on" : "-off")} onClick={() => setScreen(key)}
              style={{ padding: "12px 20px", border: "none", background: "transparent", cursor: "pointer", fontFamily: "var(--font-sans)", fontSize: "var(--text-xs)", fontWeight: 600,
                color: screen === key ? "var(--color-primary-deep)" : "var(--text-faint)",
                borderBottom: `2px solid ${screen === key ? "var(--color-primary-deep)" : "transparent"}`, transition: "all var(--duration-fast) var(--ease-standard)" }}>
              {label}
            </button>
          ))}
        </div>
        <div style={{ display: "flex", alignItems: "center", gap: 14, marginBottom: 6 }}>
          {screen === "pricing" && <P.PhaseStepper key={phase} current={phase} total={3} />}
          <button onClick={onClose} style={{ width: 34, height: 34, borderRadius: "var(--radius-md)", border: "1px solid var(--border-subtle)", background: "var(--surface-card)", cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center", color: "var(--text-muted)" }}>
            <Icon name="X" size={16} />
          </button>
        </div>
      </div>

      {/* Body */}
      <div style={{ flex: 1, overflow: "auto" }}>
        {screen === "value" && <ValueScreen />}
        {screen === "solution" && <SolutionScreen />}
        {screen === "pricing" && <PricingScreen phase={phase} payment={payment} setPayment={setPayment} signed={signed} sigName={sigName} setSigName={setSigName} onSign={() => setSigned(true)} />}
      </div>

      {/* Bottom action bar */}
      <div style={{ background: "var(--surface-card)", borderTop: "1px solid var(--border-subtle)", padding: "12px 20px", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12, flexShrink: 0 }}>
        <P.Button variant="outline" size="md" onClick={() => { const i = order.indexOf(screen); if (i > 0) setScreen(order[i-1]); else onClose && onClose(); }}>← Back</P.Button>
        <div style={{ flex: 1, maxWidth: 340, margin: "0 auto" }}>
          {screen === "pricing" && phase === 0 && <P.Button variant="dark" fullWidth onClick={() => setPhase(1)}>Reveal Currently Advertised →</P.Button>}
          {screen === "pricing" && phase === 1 && <P.Button variant="deep" fullWidth onClick={() => setPhase(2)}>Reveal Today's Investment →</P.Button>}
          {screen === "pricing" && phase === 2 && <P.Button variant="deep" fullWidth onClick={onContract} disabled={!signed}><Icon name="FileSignature" size={16} />Generate Contract →</P.Button>}
        </div>
        {screen !== "pricing"
          ? <P.Button variant="deep" size="md" onClick={() => { const i = order.indexOf(screen); if (i < 2) setScreen(order[i+1]); }}>Next →</P.Button>
          : <div style={{ width: 92 }} />}
      </div>
    </div>
  );
}

window.Presentation = Presentation;
