// SignupPage.jsx — The Club Tennis checkout/signup flow
// Mock checkout — collects parent + player info, waiver, payment details.
// No real charge until Stripe is wired. On submit, shows a confirmation screen.
const SignupPage = ({ onNavigate }) => {
  const TIERS = {
    dropin:     { name: 'Drop In Session',          price: 100,   per: 'one session',  recurring: false, requiresDate: true,  accent: '#AAAAAA' },
    monthly:    { name: 'Monthly Membership',      price: 720,   per: 'per month',     recurring: true,  requiresDate: false, accent: '#FF2D8A' },
    unlimited:  { name: 'Unlimited Membership',    price: 1120,  per: 'per month',     recurring: true,  requiresDate: false, accent: '#39FF14' },
    tournament: { name: 'Tournament Team',         price: 500,   per: 'per season',    recurring: false, requiresDate: false, accent: '#FF2D8A' },
    spain:      { name: 'Spain Camp Deposit',      price: 1500,  per: 'one time (balance $3,000 invoiced later)', recurring: false, requiresDate: false, accent: '#39FF14' },
  };

  const getInitialTier = () => {
    try {
      const saved = sessionStorage.getItem('tct_signup_tier');
      return saved && TIERS[saved] ? saved : 'monthly';
    } catch { return 'monthly'; }
  };

  const [tierKey, setTierKey] = React.useState(getInitialTier);
  const tier = TIERS[tierKey];

  const [form, setForm] = React.useState({
    parentFirst: '', parentLast: '', parentEmail: '', parentPhone: '',
    playerFirst: '', playerLast: '', playerAge: '', ustaRating: '',
    emergencyName: '', emergencyPhone: '',
    allergies: '', medical: '',
    sessionDate: '',
    waiverAccepted: false,
    cardName: '', cardNumber: '', cardExp: '', cardCvc: '', cardZip: '',
  });

  const [submitted, setSubmitted] = React.useState(false);
  const [errors, setErrors] = React.useState({});

  const update = (key, val) => setForm(f => ({ ...f, [key]: val }));

  // Tax (CA — Stripe Tax will determine; clinics typically not taxable, but UI shows estimate at 0%)
  const subtotal = tier.price;
  const tax = 0;
  const total = subtotal + tax;

  // Generate next 30 days of valid clinic dates (Mon–Sat, no Sundays)
  const upcomingClinicDates = React.useMemo(() => {
    const dates = [];
    const today = new Date();
    for (let i = 1; i <= 45 && dates.length < 14; i++) {
      const d = new Date(today);
      d.setDate(today.getDate() + i);
      const day = d.getDay();
      if (day === 0) continue; // skip Sunday
      const dayLabel = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][day];
      const sessionType = (day === 2 || day === 4 || day === 5) ? 'L5 USTA' : 'Regular';
      const iso = d.toISOString().slice(0, 10);
      const display = `${dayLabel}, ${d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' })} — ${sessionType}`;
      dates.push({ iso, display });
    }
    return dates;
  }, []);

  const validate = () => {
    const e = {};
    if (!form.parentFirst.trim()) e.parentFirst = 'Required';
    if (!form.parentLast.trim()) e.parentLast = 'Required';
    // RFC 5321 compliant email check
    if (!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/.test(form.parentEmail)) e.parentEmail = 'Valid email required';
    if (!/^\+?[\d\s\-().]{7,20}$/.test(form.parentPhone)) e.parentPhone = 'Valid phone required';
    if (!form.playerFirst.trim()) e.playerFirst = 'Required';
    if (!form.playerLast.trim()) e.playerLast = 'Required';
    if (!form.playerAge || +form.playerAge < 5 || +form.playerAge > 19) e.playerAge = 'Age 5–19';
    if (!form.emergencyName.trim()) e.emergencyName = 'Required';
    if (!/^\+?[\d\s\-().]{7,20}$/.test(form.emergencyPhone)) e.emergencyPhone = 'Valid phone required';
    if (tier.requiresDate && !form.sessionDate) e.sessionDate = 'Pick a session date';
    if (!form.waiverAccepted) e.waiverAccepted = 'You must accept the waiver';
    if (!form.cardName.trim()) e.cardName = 'Required';
    if (form.cardNumber.replace(/\s/g, '').length < 13) e.cardNumber = 'Invalid card';
    if (!/^\d{2}\/\d{2}$/.test(form.cardExp)) e.cardExp = 'MM/YY';
    if (!/^\d{3,4}$/.test(form.cardCvc)) e.cardCvc = '3–4 digits';
    if (!/^\d{5}(-\d{4})?$/.test(form.cardZip)) e.cardZip = 'Valid ZIP';
    setErrors(e);
    return Object.keys(e).length === 0;
  };

  const handleSubmit = (ev) => {
    ev.preventDefault();
    if (!validate()) {
      // scroll to first error
      const firstErr = document.querySelector('[data-err="true"]');
      if (firstErr) firstErr.scrollIntoView({ behavior: 'smooth', block: 'center' });
      return;
    }
    setSubmitted(true);
    window.scrollTo(0, 0);
  };

  // ----- Confirmation screen -----
  if (submitted) {
    return (
      <div style={{ background: '#0A0A0A', fontFamily: "'Outfit',sans-serif", paddingTop: 72, minHeight: '100vh' }}>
        <section style={{ maxWidth: 720, margin: '0 auto', padding: '80px 48px' }}>
          <div style={{ width: 60, height: 60, borderRadius: '50%', background: 'rgba(57,255,20,0.1)', border: '2px solid #39FF14', display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: 32 }}>
            <span style={{ color: '#39FF14', fontSize: 28, fontWeight: 900, lineHeight: 1 }}>✓</span>
          </div>
          <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 11, letterSpacing: '2.5px', textTransform: 'uppercase', color: '#39FF14', marginBottom: 16 }}>You're In</div>
          <h1 style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 900, fontSize: 56, letterSpacing: '-2.5px', textTransform: 'uppercase', color: '#F5F5F5', lineHeight: 1, margin: '0 0 24px' }}>
            WELCOME TO THE <span style={{ color: '#FF2D8A' }}>CLUB</span>.
          </h1>
          <p style={{ fontSize: 18, color: '#AAAAAA', lineHeight: 1.7, marginBottom: 32 }}>
            We've sent a confirmation to <span style={{ color: '#F5F5F5' }}>{form.parentEmail}</span> with your receipt and a magic link to access your account portal.
          </p>

          <div style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, padding: 32, marginBottom: 32 }}>
            <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '2px', textTransform: 'uppercase', color: '#888', marginBottom: 16 }}>Order Summary</div>
            <div style={{ display: 'flex', justifyContent: 'space-between', padding: '12px 0', borderBottom: '1px solid #1A1A1A' }}>
              <span style={{ color: '#AAAAAA', fontSize: 14 }}>{tier.name}</span>
              <span style={{ color: '#F5F5F5', fontSize: 14, fontWeight: 600 }}>${tier.price.toLocaleString()}.00</span>
            </div>
            <div style={{ display: 'flex', justifyContent: 'space-between', padding: '12px 0', borderBottom: '1px solid #1A1A1A' }}>
              <span style={{ color: '#AAAAAA', fontSize: 14 }}>Player</span>
              <span style={{ color: '#F5F5F5', fontSize: 14 }}>{form.playerFirst} {form.playerLast}</span>
            </div>
            {tier.requiresDate && form.sessionDate && (
              <div style={{ display: 'flex', justifyContent: 'space-between', padding: '12px 0', borderBottom: '1px solid #1A1A1A' }}>
                <span style={{ color: '#AAAAAA', fontSize: 14 }}>Session date</span>
                <span style={{ color: '#F5F5F5', fontSize: 14 }}>{upcomingClinicDates.find(d => d.iso === form.sessionDate)?.display}</span>
              </div>
            )}
            {tier.recurring && (
              <div style={{ display: 'flex', justifyContent: 'space-between', padding: '12px 0' }}>
                <span style={{ color: '#AAAAAA', fontSize: 14 }}>Next charge</span>
                <span style={{ color: '#39FF14', fontSize: 14, fontFamily: "'Space Mono',monospace" }}>
                  {(() => {
                    const d = new Date();
                    d.setMonth(d.getMonth() + 1);
                    return d.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
                  })()}
                </span>
              </div>
            )}
          </div>

          <div style={{ background: 'rgba(255,45,138,0.05)', border: '1px solid rgba(255,45,138,0.2)', borderRadius: 8, padding: 20, marginBottom: 40 }}>
            <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#FF2D8A', marginBottom: 8 }}>Demo Mode</div>
            <p style={{ fontSize: 13, color: '#AAAAAA', lineHeight: 1.7, margin: 0 }}>
              No card was charged. This is a preview of the checkout flow. Real Stripe payments will go live once the account is connected.
            </p>
          </div>

          <button onClick={() => onNavigate('home')} style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 700, fontSize: 14, textTransform: 'uppercase', letterSpacing: '0.5px', background: '#FF2D8A', color: '#F5F5F5', border: 'none', padding: '14px 32px', cursor: 'pointer' }}>
            Back to Home
          </button>
        </section>
      </div>
    );
  }

  // ----- Field component -----
  // maxLength defaults keep individual fields ≤ what the server schema allows
  const FIELD_MAX = {
    parentFirst: 100, parentLast: 100, parentEmail: 254, parentPhone: 20,
    playerFirst: 100, playerLast: 100, playerAge: 2, ustaRating: 10,
    emergencyName: 100, emergencyPhone: 20, allergies: 500,
    cardName: 100, cardNumber: 19, cardExp: 5, cardCvc: 4, cardZip: 10,
  };

  const Field = ({ label, name, type = 'text', placeholder, required, half, ...rest }) => (
    <div data-err={!!errors[name]} style={{ flex: half ? '1 1 calc(50% - 8px)' : '1 1 100%', minWidth: half ? 200 : '100%' }}>
      <label style={{ display: 'block', fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#888', marginBottom: 8 }}>
        {label} {required && <span style={{ color: '#FF2D8A' }}>*</span>}
      </label>
      <input
        type={type}
        value={form[name]}
        onChange={e => update(name, e.target.value)}
        placeholder={placeholder}
        maxLength={FIELD_MAX[name]}
        style={{
          width: '100%',
          background: '#0A0A0A',
          border: `1px solid ${errors[name] ? '#FF2D8A' : '#2A2A2A'}`,
          color: '#F5F5F5',
          fontSize: 15,
          padding: '12px 14px',
          borderRadius: 4,
          outline: 'none',
          fontFamily: "'Outfit',sans-serif",
          transition: 'border-color 120ms',
        }}
        onFocus={e => e.target.style.borderColor = errors[name] ? '#FF2D8A' : '#39FF14'}
        onBlur={e => e.target.style.borderColor = errors[name] ? '#FF2D8A' : '#2A2A2A'}
        {...rest}
      />
      {errors[name] && <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#FF2D8A', marginTop: 6, letterSpacing: '0.5px' }}>{errors[name]}</div>}
    </div>
  );

  const SectionHeader = ({ num, title, sub }) => (
    <div style={{ marginBottom: 24, paddingTop: 8 }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 6 }}>
        <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 11, color: '#FF2D8A', letterSpacing: '1.5px' }}>0{num}</span>
        <div style={{ width: 24, height: 1, background: '#2A2A2A' }}></div>
        <h2 style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 22, letterSpacing: '-0.5px', textTransform: 'uppercase', color: '#F5F5F5', margin: 0 }}>{title}</h2>
      </div>
      {sub && <div style={{ fontSize: 13, color: '#888', marginLeft: 56 }}>{sub}</div>}
    </div>
  );

  return (
    <div style={{ background: '#0A0A0A', fontFamily: "'Outfit',sans-serif", paddingTop: 72, minHeight: '100vh' }}>
      {/* Header */}
      <section style={{ padding: '60px 48px 40px', borderBottom: '1px solid #2A2A2A' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 16 }}>
          <div style={{ width: 24, height: 1, background: '#39FF14' }}></div>
          <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 11, letterSpacing: '2.5px', textTransform: 'uppercase', color: '#39FF14' }}>Sign Up</span>
        </div>
        <h1 style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 900, fontSize: 56, letterSpacing: '-2.5px', textTransform: 'uppercase', color: '#F5F5F5', lineHeight: 1, margin: '0 0 16px' }}>
          JOIN THE <span style={{ color: '#FF2D8A' }}>CLUB</span>
        </h1>
        <p style={{ fontSize: 16, color: '#AAAAAA', lineHeight: 1.6, maxWidth: 640 }}>
          One form. Card info goes through Stripe.
        </p>
      </section>

      <form onSubmit={handleSubmit}>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 380px', gap: 0, alignItems: 'flex-start' }}>
          {/* LEFT: form */}
          <div style={{ padding: '48px', borderRight: '1px solid #2A2A2A' }}>

            {/* Tier selector */}
            <SectionHeader num="1" title="Choose your plan" />
            <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 10, marginBottom: 16 }}>
              {['dropin', 'monthly', 'unlimited'].map(k => (
                <button key={k} type="button" onClick={() => setTierKey(k)} style={{
                  background: tierKey === k ? 'rgba(255,45,138,0.08)' : '#0A0A0A',
                  border: `1px solid ${tierKey === k ? '#FF2D8A' : '#2A2A2A'}`,
                  padding: '16px 12px',
                  cursor: 'pointer',
                  borderRadius: 4,
                  textAlign: 'left',
                  transition: 'all 120ms',
                }}>
                  <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1.5px', textTransform: 'uppercase', color: tierKey === k ? '#FF2D8A' : '#888', marginBottom: 6 }}>{TIERS[k].name.replace(' Membership','').replace(' Session','')}</div>
                  <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 22, color: '#F5F5F5', letterSpacing: '-1px' }}>${TIERS[k].price}</div>
                  <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, color: '#555', letterSpacing: '0.5px' }}>{TIERS[k].per}</div>
                </button>
              ))}
            </div>
            <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 10, marginBottom: 40 }}>
              {['tournament', 'spain'].map(k => (
                <button key={k} type="button" onClick={() => setTierKey(k)} style={{
                  background: tierKey === k ? 'rgba(57,255,20,0.05)' : '#0A0A0A',
                  border: `1px solid ${tierKey === k ? '#39FF14' : '#2A2A2A'}`,
                  padding: '14px 12px',
                  cursor: 'pointer',
                  borderRadius: 4,
                  textAlign: 'left',
                  transition: 'all 120ms',
                }}>
                  <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1.5px', textTransform: 'uppercase', color: tierKey === k ? '#39FF14' : '#888', marginBottom: 4 }}>{TIERS[k].name}</div>
                  <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 18, color: '#F5F5F5', letterSpacing: '-0.5px' }}>${TIERS[k].price.toLocaleString()}</div>
                </button>
              ))}
            </div>

            {/* Date picker (drop-in only) */}
            {tier.requiresDate && (
              <>
                <SectionHeader num="2" title="Pick your session" sub="Drop-in sessions are redeemable for one specific date." />
                <div data-err={!!errors.sessionDate} style={{ marginBottom: 40 }}>
                  <select
                    value={form.sessionDate}
                    onChange={e => update('sessionDate', e.target.value)}
                    style={{
                      width: '100%',
                      background: '#0A0A0A',
                      border: `1px solid ${errors.sessionDate ? '#FF2D8A' : '#2A2A2A'}`,
                      color: form.sessionDate ? '#F5F5F5' : '#888',
                      fontSize: 15,
                      padding: '14px',
                      borderRadius: 4,
                      outline: 'none',
                      fontFamily: "'Outfit',sans-serif",
                      cursor: 'pointer',
                    }}>
                    <option value="">Select a date —</option>
                    {upcomingClinicDates.map(d => <option key={d.iso} value={d.iso}>{d.display}</option>)}
                  </select>
                  {errors.sessionDate && <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#FF2D8A', marginTop: 6 }}>{errors.sessionDate}</div>}
                </div>
              </>
            )}

            {/* Player */}
            <SectionHeader num={tier.requiresDate ? "3" : "2"} title="Player Info" />
            <div style={{ display: 'flex', flexWrap: 'wrap', gap: 16, marginBottom: 32 }}>
              <Field label="First name" name="playerFirst" required half />
              <Field label="Last name" name="playerLast" required half />
              <Field label="Age" name="playerAge" type="number" required half />
              <Field label="USTA rating (optional)" name="ustaRating" placeholder="e.g. 4.0 or N/A" half />
            </div>

            {/* Parent */}
            <SectionHeader num={tier.requiresDate ? "4" : "3"} title="Parent / Guardian" />
            <div style={{ display: 'flex', flexWrap: 'wrap', gap: 16, marginBottom: 32 }}>
              <Field label="First name" name="parentFirst" required half />
              <Field label="Last name" name="parentLast" required half />
              <Field label="Email" name="parentEmail" type="email" required placeholder="parent@email.com" half />
              <Field label="Phone" name="parentPhone" type="tel" required placeholder="(310) 555-0100" half />
            </div>

            {/* Emergency + medical */}
            <SectionHeader num={tier.requiresDate ? "5" : "4"} title="Safety Info" sub="Coaches need this on-court — keep it accurate." />
            <div style={{ display: 'flex', flexWrap: 'wrap', gap: 16, marginBottom: 32 }}>
              <Field label="Emergency contact name" name="emergencyName" required half />
              <Field label="Emergency contact phone" name="emergencyPhone" type="tel" required half />
              <Field label="Allergies (or 'none')" name="allergies" placeholder="None" />
              <div style={{ flex: '1 1 100%' }}>
                <label style={{ display: 'block', fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#888', marginBottom: 8 }}>Medical notes (optional)</label>
                <textarea
                  value={form.medical}
                  onChange={e => update('medical', e.target.value)}
                  placeholder="Asthma, prior injuries, medication, anything coaches should know."
                  rows={3}
                  maxLength={1000}
                  style={{ width: '100%', background: '#0A0A0A', border: '1px solid #2A2A2A', color: '#F5F5F5', fontSize: 15, padding: '12px 14px', borderRadius: 4, outline: 'none', fontFamily: "'Outfit',sans-serif", resize: 'vertical' }}
                />
              </div>
            </div>

            {/* Waiver */}
            <SectionHeader num={tier.requiresDate ? "6" : "5"} title="Liability Waiver" />
            <div data-err={!!errors.waiverAccepted} style={{ marginBottom: 40, background: '#0A0A0A', border: `1px solid ${errors.waiverAccepted ? '#FF2D8A' : '#2A2A2A'}`, borderRadius: 4, padding: 20 }}>
              <div style={{ fontSize: 13, color: '#AAAAAA', lineHeight: 1.7, marginBottom: 16, maxHeight: 120, overflowY: 'auto', paddingRight: 8 }}>
                I, the undersigned parent or legal guardian, acknowledge that participation in tennis training programs operated by The Club Tennis LLC involves inherent risks including but not limited to physical injury. I voluntarily assume all such risks and release The Club Tennis LLC, its coaches, employees, and affiliated facilities from any and all claims arising from my child's participation. I confirm that my child is physically fit to participate and authorize emergency medical treatment if needed. This waiver is valid for one year from the date signed.
              </div>
              <label style={{ display: 'flex', alignItems: 'flex-start', gap: 12, cursor: 'pointer' }}>
                <input
                  type="checkbox"
                  checked={form.waiverAccepted}
                  onChange={e => update('waiverAccepted', e.target.checked)}
                  style={{ width: 18, height: 18, accentColor: '#FF2D8A', marginTop: 2, cursor: 'pointer' }}
                />
                <span style={{ fontSize: 14, color: '#F5F5F5', lineHeight: 1.5 }}>
                  I have read and agree to the liability waiver. I am the parent or legal guardian of the player listed above. <span style={{ color: '#FF2D8A' }}>*</span>
                </span>
              </label>
              {errors.waiverAccepted && <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#FF2D8A', marginTop: 8 }}>{errors.waiverAccepted}</div>}
            </div>

            {/* Payment */}
            <SectionHeader num={tier.requiresDate ? "7" : "6"} title="Payment" sub={tier.recurring ? `Card auto-charged ${tier.per}. Cancel anytime.` : 'One-time charge. No subscription.'} />
            <div style={{ background: '#0A0A0A', border: '1px solid #2A2A2A', borderRadius: 4, padding: 24, marginBottom: 24 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 20, fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#39FF14', letterSpacing: '1.5px' }}>
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#39FF14" strokeWidth="2"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0110 0v4"/></svg>
                SECURE — POWERED BY STRIPE
              </div>
              <div style={{ display: 'flex', flexWrap: 'wrap', gap: 16 }}>
                <Field label="Name on card" name="cardName" required />
                <Field label="Card number" name="cardNumber" placeholder="1234 5678 9012 3456" required inputMode="numeric" />
                <Field label="MM/YY" name="cardExp" placeholder="12/28" required half />
                <Field label="CVC" name="cardCvc" placeholder="123" required half inputMode="numeric" />
                <Field label="Billing ZIP" name="cardZip" placeholder="90064" required half inputMode="numeric" />
              </div>
            </div>
          </div>

          {/* RIGHT: order summary (sticky) */}
          <div style={{ padding: '48px 48px 48px 32px', position: 'sticky', top: 72, alignSelf: 'flex-start' }}>
            <div style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, padding: 28 }}>
              <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '2px', textTransform: 'uppercase', color: '#888', marginBottom: 20 }}>Order Summary</div>

              <div style={{ borderBottom: '1px solid #2A2A2A', paddingBottom: 16, marginBottom: 16 }}>
                <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 18, color: '#F5F5F5', marginBottom: 4 }}>{tier.name}</div>
                <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 11, color: tier.accent, letterSpacing: '1px' }}>{tier.per}</div>
              </div>

              <div style={{ display: 'flex', justifyContent: 'space-between', padding: '8px 0', fontSize: 14, color: '#AAAAAA' }}>
                <span>Subtotal</span>
                <span style={{ fontFamily: "'Space Mono',monospace", color: '#F5F5F5' }}>${subtotal.toLocaleString()}.00</span>
              </div>
              <div style={{ display: 'flex', justifyContent: 'space-between', padding: '8px 0', fontSize: 14, color: '#AAAAAA' }}>
                <span>Sales tax (CA)</span>
                <span style={{ fontFamily: "'Space Mono',monospace", color: '#888' }}>${tax.toFixed(2)}</span>
              </div>
              <div style={{ display: 'flex', justifyContent: 'space-between', padding: '16px 0 8px', borderTop: '1px solid #2A2A2A', marginTop: 8 }}>
                <span style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 700, fontSize: 16, color: '#F5F5F5', textTransform: 'uppercase', letterSpacing: '1px' }}>Total</span>
                <span style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 900, fontSize: 26, color: '#FF2D8A', letterSpacing: '-1px' }}>${total.toLocaleString()}.00</span>
              </div>

              {tier.recurring && (
                <div style={{ marginTop: 16, padding: 14, background: 'rgba(57,255,20,0.05)', border: '1px solid rgba(57,255,20,0.2)', borderRadius: 4 }}>
                  <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#39FF14', marginBottom: 6 }}>Recurring</div>
                  <div style={{ fontSize: 12, color: '#AAAAAA', lineHeight: 1.6 }}>
                    Auto renews monthly on this date. Manage or cancel anytime from your account.
                  </div>
                </div>
              )}

              <button type="submit" style={{
                width: '100%',
                fontFamily: "'Outfit',sans-serif", fontWeight: 700, fontSize: 14, textTransform: 'uppercase', letterSpacing: '1px',
                background: '#FF2D8A',
                color: '#F5F5F5',
                border: 'none',
                padding: '16px',
                cursor: 'pointer',
                marginTop: 24,
                transition: 'transform 120ms, background 120ms',
              }}
                onMouseEnter={e => { e.target.style.background = '#FF5CA8'; e.target.style.transform = 'translateY(-1px)'; }}
                onMouseLeave={e => { e.target.style.background = '#FF2D8A'; e.target.style.transform = 'translateY(0)'; }}>
                Pay ${total.toLocaleString()}.00
              </button>

              <div style={{ marginTop: 16, fontFamily: "'Space Mono',monospace", fontSize: 9, color: '#555', letterSpacing: '0.5px', lineHeight: 1.6, textAlign: 'center' }}>
                BY PAYING YOU AGREE TO OUR TERMS.<br/>NO REFUNDS — CANCELLED SESSIONS CONVERT TO ACCOUNT CREDIT.
              </div>
            </div>

            <div style={{ marginTop: 16, padding: 16, background: 'rgba(255,45,138,0.05)', border: '1px dashed rgba(255,45,138,0.3)', borderRadius: 4, fontSize: 11, color: '#AAAAAA', lineHeight: 1.6 }}>
              <strong style={{ color: '#FF2D8A', fontFamily: "'Space Mono',monospace", letterSpacing: '1px', fontSize: 10 }}>DEMO MODE:</strong> No card is charged. Stripe goes live once the account is connected.
            </div>
          </div>
        </div>
      </form>

      <Footer onNavigate={onNavigate} />
    </div>
  );
};

Object.assign(window, { SignupPage });
