// flows.jsx — Screen Sets 2, 3, 4, 5: Appointment / Class / Event / Membership
// Each flow returns its checkout body; the screen wrapper (Phone/Desktop) provides
// the studio header, scroll container, and sticky bottom CTA.

const { useState: useStateF, useMemo: useMemoF } = React;

// ────────────────────────────────────────────────────────────────
//  Detail row used inside summary cards
// ────────────────────────────────────────────────────────────────
function DetailRow({ icon, label, value, accent, brand }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '8px 0' }}>
      <div style={{
        width: 28, height: 28, borderRadius: 8,
        background: brand.accentSoft,
        color: brand.accentDeep,
        display: 'grid', placeItems: 'center',
        flex: '0 0 auto',
      }}>{icon}</div>
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{ fontSize: 11, color: brand.inkSoft, fontWeight: 600, letterSpacing: '0.04em', textTransform: 'uppercase' }}>{label}</div>
        <div style={{ fontSize: 14, color: brand.ink, fontWeight: 500, marginTop: 1 }}>{value}</div>
      </div>
      {accent}
    </div>
  );
}

// Tiny lucide-ish icons
const ICONS = {
  calendar: <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>,
  clock:    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>,
  user:     <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>,
  pin:      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"/><circle cx="12" cy="10" r="3"/></svg>,
  edit:     <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4z"/></svg>,
  spark:    <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2 13.6 8.4 20 10l-6.4 1.6L12 18l-1.6-6.4L4 10l6.4-1.6z"/></svg>,
};

// ────────────────────────────────────────────────────────────────
//  ClassHero — concise "what you're booking" panel.
//    Sits visually apart from the action sections below: tinted
//    surface, large class photo, instructor avatar inline.
// ────────────────────────────────────────────────────────────────
function ClassHero({ brand, c, tweaks, desktop }) {
  const photo = c.image || brand.classImage;
  const avatar = c.instructorImage || brand.instructorImage;

  if (desktop) {
    // Split-card: smaller photo on left, details panel on right
    return (
      <div style={{
        background: brand.accentSoft,
        border: `1px solid ${brand.border}`,
        borderRadius: 18,
        overflow: 'hidden',
        marginBottom: 20,
        display: 'flex',
        minHeight: 220,
      }}>
        <div style={{
          position: 'relative',
          flex: '0 0 260px',
          background: photo
            ? `url(${photo}) center/cover`
            : `linear-gradient(135deg, ${brand.accent}, ${brand.accentDeep})`,
        }}>
          <div style={{
            position: 'absolute', top: 12, left: 12,
            background: 'rgba(255,255,255,0.94)',
            color: brand.ink,
            fontSize: 10.5, fontWeight: 700, letterSpacing: '0.1em', textTransform: 'uppercase',
            padding: '5px 9px', borderRadius: 6,
          }}>Class</div>
        </div>
        <div style={{
          flex: 1, minWidth: 0,
          padding: '20px 22px',
          background: brand.surface,
          display: 'flex', flexDirection: 'column', gap: 14,
        }}>
          <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 16 }}>
            <div style={{ minWidth: 0, flex: 1 }}>
              <div style={{ marginBottom: 8 }}>
                <CapacityCounter brand={brand} state={tweaks.capacity} />
              </div>
              <div style={{ fontFamily: brand.displayFont, fontWeight: brand.displayWeight, fontSize: 22, color: brand.ink, lineHeight: 1.2, letterSpacing: '-0.01em' }}>{c.title}</div>
            </div>
            <div style={{ textAlign: 'right', flex: '0 0 auto' }}>
              <div style={{ fontSize: 11, color: brand.inkSoft, fontWeight: 600, letterSpacing: '0.04em', textTransform: 'uppercase' }}>From</div>
              <div style={{ fontFamily: brand.displayFont, fontSize: 22, fontWeight: 700, color: brand.ink, marginTop: 1 }}>${c.pricing[0].price}</div>
            </div>
          </div>
          <div style={{
            display: 'flex', alignItems: 'center', gap: 10,
            paddingTop: 12,
            borderTop: `1px solid ${brand.border}`,
          }}>
            <div style={{
              width: 34, height: 34, borderRadius: 999,
              flex: '0 0 auto',
              background: avatar
                ? `url(${avatar}) center/cover`
                : `linear-gradient(135deg, ${brand.accent}, ${brand.accentDeep})`,
              color: '#fff',
              display: 'grid', placeItems: 'center',
              fontFamily: brand.displayFont, fontWeight: 700, fontSize: 13,
            }}>{!avatar && c.instructor.split(' ').map(s => s[0]).slice(0,2).join('')}</div>
            <div style={{ minWidth: 0 }}>
              <div style={{ fontSize: 11, color: brand.inkSoft, fontWeight: 600, letterSpacing: '0.04em', textTransform: 'uppercase' }}>With</div>
              <div style={{ fontSize: 14, color: brand.ink, fontWeight: 600, marginTop: 1 }}>{c.instructor}</div>
            </div>
          </div>
          <div style={{
            display: 'flex', flexWrap: 'wrap', gap: 16,
            fontSize: 13, color: brand.ink,
          }}>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}>
              <span style={{ color: brand.accentDeep, display: 'inline-flex' }}>{ICONS.calendar}</span>
              <span style={{ fontWeight: 500 }}>{c.date} · {c.time}</span>
            </span>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}>
              <span style={{ color: brand.accentDeep, display: 'inline-flex' }}>{ICONS.clock}</span>
              <span style={{ fontWeight: 500 }}>{c.duration}</span>
            </span>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}>
              <span style={{ color: brand.accentDeep, display: 'inline-flex' }}>{ICONS.pin}</span>
              <span style={{ fontWeight: 500 }}>{c.location}</span>
            </span>
          </div>
        </div>
      </div>
    );
  }

  // Mobile: stacked layout — full-bleed 16:9 photo with title overlay
  return (
    <div style={{
      background: brand.accentSoft,
      border: `1px solid ${brand.border}`,
      borderRadius: 18,
      overflow: 'hidden',
      marginBottom: 18,
    }}>
      <div style={{
        position: 'relative',
        aspectRatio: '16 / 9',
        background: photo
          ? `linear-gradient(180deg, transparent 55%, rgba(0,0,0,0.42) 100%), url(${photo}) center/cover`
          : `linear-gradient(135deg, ${brand.accent}, ${brand.accentDeep})`,
      }}>
        <div style={{
          position: 'absolute', top: 12, left: 12,
          background: 'rgba(255,255,255,0.92)',
          color: brand.ink,
          fontSize: 10.5, fontWeight: 700, letterSpacing: '0.1em', textTransform: 'uppercase',
          padding: '5px 9px', borderRadius: 6,
        }}>Class</div>
        <div style={{ position: 'absolute', top: 12, right: 12 }}>
          <CapacityCounter brand={brand} state={tweaks.capacity} />
        </div>
        <div style={{
          position: 'absolute', left: 14, right: 14, bottom: 12,
          color: '#fff',
          fontFamily: brand.displayFont,
          fontWeight: brand.displayWeight,
          fontSize: 22,
          lineHeight: 1.15,
          letterSpacing: '-0.01em',
          textShadow: '0 1px 12px rgba(0,0,0,0.35)',
        }}>{c.title}</div>
      </div>
      <div style={{
        padding: '12px 14px',
        background: brand.surface,
        display: 'flex', alignItems: 'center', gap: 12,
      }}>
        <div style={{
          width: 38, height: 38, borderRadius: 999,
          flex: '0 0 auto',
          background: avatar
            ? `url(${avatar}) center/cover`
            : `linear-gradient(135deg, ${brand.accent}, ${brand.accentDeep})`,
          color: '#fff',
          display: 'grid', placeItems: 'center',
          fontFamily: brand.displayFont, fontWeight: 700, fontSize: 14,
          border: `2px solid ${brand.surface}`,
          boxShadow: `0 0 0 1px ${brand.border}`,
        }}>{!avatar && c.instructor.split(' ').map(s => s[0]).slice(0,2).join('')}</div>
        <div style={{ flex: 1, minWidth: 0 }}>
          <div style={{ fontSize: 11, color: brand.inkSoft, fontWeight: 600, letterSpacing: '0.04em', textTransform: 'uppercase' }}>With</div>
          <div style={{ fontSize: 14, color: brand.ink, fontWeight: 600, marginTop: 1 }}>{c.instructor}</div>
        </div>
        <div style={{ textAlign: 'right' }}>
          <div style={{ fontSize: 11, color: brand.inkSoft, fontWeight: 600, letterSpacing: '0.04em', textTransform: 'uppercase' }}>From</div>
          <div style={{ fontFamily: brand.displayFont, fontSize: 16, fontWeight: 700, color: brand.ink, marginTop: 1 }}>${c.pricing[0].price}</div>
        </div>
      </div>
      <div style={{
        padding: '10px 14px',
        borderTop: `1px solid ${brand.border}`,
        background: brand.surface,
        display: 'flex', flexWrap: 'wrap', gap: 14,
        fontSize: 12.5, color: brand.ink,
      }}>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, color: brand.inkSoft }}>
          <span style={{ color: brand.accentDeep, display: 'inline-flex' }}>{ICONS.calendar}</span>
          <span style={{ color: brand.ink, fontWeight: 500 }}>{c.date} · {c.time}</span>
        </span>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, color: brand.inkSoft }}>
          <span style={{ color: brand.accentDeep, display: 'inline-flex' }}>{ICONS.clock}</span>
          <span style={{ color: brand.ink, fontWeight: 500 }}>{c.duration}</span>
        </span>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, color: brand.inkSoft }}>
          <span style={{ color: brand.accentDeep, display: 'inline-flex' }}>{ICONS.pin}</span>
          <span style={{ color: brand.ink, fontWeight: 500 }}>{c.location}</span>
        </span>
      </div>
    </div>
  );
}

// ────────────────────────────────────────────────────────────────
//  SignInCallout — prominent reminder for returning clients with
//    an existing membership / class pack to sign in instead of
//    paying again.
// ────────────────────────────────────────────────────────────────
function SignInCallout({ brand }) {
  return (
    <div style={{
      display: 'flex', alignItems: 'center', gap: 12,
      padding: '12px 14px',
      marginBottom: 10,
      background: '#FFFFFF',
      border: `1.5px solid ${brand.accent}`,
      borderRadius: 12,
      boxShadow: `0 0 0 4px ${brand.accentSoft}`,
    }}>
      <div style={{
        width: 32, height: 32, borderRadius: 999,
        background: brand.accent, color: '#fff',
        display: 'grid', placeItems: 'center',
        flex: '0 0 auto',
      }}>
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" y1="12" x2="3" y2="12"/></svg>
      </div>
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{ fontSize: 13.5, fontWeight: 700, color: brand.ink, lineHeight: 1.3 }}>Already have a membership or class pack?</div>
        <div style={{ fontSize: 12, color: brand.inkSoft, marginTop: 2, lineHeight: 1.4 }}>Sign in to use credits — don't pay twice.</div>
      </div>
      <button style={{
        flex: '0 0 auto',
        background: brand.accent, color: '#fff',
        border: 0, borderRadius: 10,
        padding: '8px 14px',
        fontSize: 13, fontWeight: 700,
        cursor: 'pointer',
        whiteSpace: 'nowrap',
      }}>Sign in</button>
    </div>
  );
}

// ────────────────────────────────────────────────────────────────
//  SectionCard — wraps a numbered (or unnumbered) form section in
//    a white card with a header. Used to group all the controls of
//    one logical step into a single visual container.
// ────────────────────────────────────────────────────────────────
function SectionCard({ brand, step, title, children }) {
  return (
    <div style={{
      background: brand.surface,
      border: `1px solid ${brand.border}`,
      borderRadius: 18,
      padding: '18px 18px 16px',
      marginBottom: 14,
    }}>
      <div style={{
        display: 'flex', alignItems: 'center', gap: 10,
        marginBottom: 14,
      }}>
        {step != null && (
          <div style={{
            width: 24, height: 24,
            borderRadius: 999,
            background: brand.accent,
            color: '#fff',
            fontSize: 12,
            fontWeight: 700,
            display: 'grid', placeItems: 'center',
            fontFamily: brand.bodyFont,
            flex: '0 0 auto',
          }}>{step}</div>
        )}
        <div style={{
          fontFamily: brand.displayFont,
          fontWeight: brand.displayWeight,
          fontSize: 16,
          color: brand.ink,
          letterSpacing: '-0.005em',
        }}>{title}</div>
      </div>
      {children}
    </div>
  );
}

// ────────────────────────────────────────────────────────────────
//  WaiverExpandable — collapsible liability waiver inside the
//    Payment card. Click the header to expand the full text;
//    a checkbox below requires explicit acceptance.
// ────────────────────────────────────────────────────────────────
function WaiverExpandable({ brand, checked, onChange }) {
  const [open, setOpen] = useStateF(false);
  return (
    <div style={{
      border: `1px solid ${brand.border}`,
      borderRadius: 12,
      overflow: 'hidden',
      marginTop: 14,
      background: brand.bg || '#fafafa',
    }}>
      <button
        type="button"
        onClick={() => setOpen(o => !o)}
        style={{
          width: '100%',
          display: 'flex', alignItems: 'center', gap: 10,
          padding: '12px 14px',
          background: 'transparent',
          border: 0,
          cursor: 'pointer',
          textAlign: 'left',
        }}>
        <div style={{
          width: 28, height: 28, borderRadius: 8,
          background: brand.accentSoft,
          color: brand.accentDeep,
          display: 'grid', placeItems: 'center',
          flex: '0 0 auto',
        }}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="9" y1="15" x2="15" y2="15"/></svg>
        </div>
        <div style={{ flex: 1, minWidth: 0 }}>
          <div style={{ fontSize: 13.5, fontWeight: 700, color: brand.ink }}>Liability waiver</div>
          <div style={{ fontSize: 11.5, color: brand.inkSoft, marginTop: 1 }}>{open ? 'Tap to collapse' : 'Tap to read full waiver'}</div>
        </div>
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke={brand.inkSoft} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" style={{ transform: open ? 'rotate(180deg)' : 'rotate(0deg)', transition: 'transform .2s ease' }}><polyline points="6 9 12 15 18 9"/></svg>
      </button>
      {open && (
        <div style={{
          maxHeight: 200, overflow: 'auto',
          padding: '0 14px 14px',
          fontSize: 12, lineHeight: 1.55,
          color: brand.inkSoft,
          borderTop: `1px solid ${brand.border}`,
        }}>
          <p style={{ marginTop: 12 }}>I, the undersigned, acknowledge that participation in the activities offered by {brand.name} carries inherent risks of physical injury. I confirm that I am physically able to participate and have disclosed any conditions, injuries, or pregnancy that may affect my safe practice.</p>
          <p>I voluntarily assume all risk of injury, loss, or damage to person or property arising from participation, including (but not limited to) strains, sprains, falls, and contact with equipment. I agree to follow all instructor and studio guidance.</p>
          <p>I release {brand.name}, its instructors, employees, and contractors from any and all claims, demands, and causes of action arising out of my participation, except where caused by gross negligence.</p>
          <p>This waiver is binding upon me, my heirs, and my legal representatives. I have read this waiver in full and understand its terms.</p>
        </div>
      )}
      <div style={{ padding: '12px 14px', borderTop: `1px solid ${brand.border}`, background: brand.surface }}>
        <Checkbox brand={brand} checked={checked} onChange={onChange}>
          I've read and agree to the liability waiver. I'm participating at my own risk and have no conditions that prevent safe practice.
        </Checkbox>
      </div>
    </div>
  );
}

// ────────────────────────────────────────────────────────────────
//  TierPicker — selectable price-option cards (drop-in/pack/membership)
// ────────────────────────────────────────────────────────────────
function TierPicker({ brand, options, value, onChange }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
      {options.map(opt => {
        const active = value === opt.id;
        return (
          <button key={opt.id} onClick={() => onChange(opt.id)} style={{
            background: active ? brand.accentSoft : brand.surface,
            border: `1.5px solid ${active ? brand.accent : brand.border}`,
            borderRadius: 12,
            padding: '12px 14px',
            display: 'flex', alignItems: 'center', gap: 12,
            textAlign: 'left',
            transition: 'all .15s ease',
            position: 'relative',
          }}>
            <div style={{
              width: 18, height: 18, borderRadius: 999,
              border: `2px solid ${active ? brand.accent : brand.border}`,
              background: active ? brand.accent : '#fff',
              display: 'grid', placeItems: 'center', flex: '0 0 auto',
            }}>
              {active && <span style={{ width: 7, height: 7, borderRadius: 999, background: '#fff' }}></span>}
            </div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
                <div style={{ fontSize: 14, fontWeight: 600, color: brand.ink }}>{opt.label}</div>
                {opt.badge && <Pill brand={brand} accent>{opt.badge}</Pill>}
              </div>
              <div style={{ fontSize: 11.5, color: brand.inkSoft, marginTop: 2 }}>{opt.sub}</div>
            </div>
            <div style={{ textAlign: 'right', flex: '0 0 auto' }}>
              <div style={{ fontFamily: brand.displayFont, fontSize: 16, fontWeight: 700, color: brand.ink, lineHeight: 1 }}>${opt.price}{opt.recurring ? <span style={{ fontSize: 11, fontWeight: 500, color: brand.inkSoft }}>/mo</span> : null}</div>
                {opt.perSession && opt.sessions > 1 && <div style={{ fontSize: 10.5, color: brand.inkSoft, marginTop: 3 }}>${opt.perSession}/session</div>}
            </div>
          </button>
        );
      })}
    </div>
  );
}

// ────────────────────────────────────────────────────────────────
//  Customer info form chunk — reused across all flows
// ────────────────────────────────────────────────────────────────
function CustomerInfo({ brand, returning, data, set }) {
  return (
    <>
      <Field brand={brand} label="Full name" value={data.name} onChange={v => set({ ...data, name: v })} autoComplete="name" />
      <Field brand={brand} label="Email"     value={data.email} onChange={v => set({ ...data, email: v })} type="email" autoComplete="email" />
      <Field brand={brand} label="Phone"     value={data.phone} onChange={v => set({ ...data, phone: v })} type="tel"   autoComplete="tel" />
    </>
  );
}

// ────────────────────────────────────────────────────────────────
//  Screen Set 2 — Appointment guest checkout
// ────────────────────────────────────────────────────────────────
function AppointmentFlow({ brand, tweaks, customer, setCustomer, onSubmit }) {
  const a = brand.appointment;
  const [tierId, setTierId] = useStateF(tweaks.loggedIn ? 'membership-credit' : 'single');
  const tier = a.pricing.find(t => t.id === tierId) || a.pricing[0];
  const [notes, setNotes] = useStateF('');
  const [waiverChecked, setWaiverChecked] = useStateF(false);
  const [policyChecked, setPolicyChecked] = useStateF(false);
  const [whoFor, setWhoFor] = useStateF({ self: true, family: [], guests: [] });
  const [savePay, setSavePay] = useStateF(!tweaks.loggedIn);
  const [discount, setDiscount] = useStateF(0);
  const baseTotal = tier.price;
  const total = Math.max(0, baseTotal - discount);

  return (
    <>
      <SummaryCard brand={brand}>
        <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 12, marginBottom: 10 }}>
          <div>
            <div style={{ fontSize: 11, color: brand.inkSoft, fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase' }}>Appointment</div>
            <div style={{ fontFamily: brand.displayFont, fontWeight: brand.displayWeight, fontSize: 20, color: brand.ink, lineHeight: 1.2, marginTop: 4, letterSpacing: '-0.01em' }}>{a.title}</div>
          </div>
          <div style={{ fontFamily: brand.displayFont, fontWeight: 700, fontSize: 20, color: brand.ink }}>from ${a.pricing[0].price}</div>
        </div>
        <div style={{ borderTop: `1px solid ${brand.border}`, paddingTop: 4 }}>
          <DetailRow brand={brand} icon={ICONS.user}     label="With"     value={a.provider} />
          <DetailRow brand={brand} icon={ICONS.calendar} label="When"     value={`${a.date} · ${a.time}`} accent={
            <button style={{ background: 'transparent', border: 0, color: brand.accent, fontSize: 12, fontWeight: 600, display: 'inline-flex', alignItems: 'center', gap: 4 }}>{ICONS.edit} Edit</button>
          } />
          <DetailRow brand={brand} icon={ICONS.clock}    label="Duration" value={a.duration} />
          <DetailRow brand={brand} icon={ICONS.pin}      label="Location" value={a.address} />
        </div>
      </SummaryCard>

      <SectionTitle brand={brand} step={1}>Who's this for?</SectionTitle>
      <WhoFor brand={brand} value={whoFor} onChange={setWhoFor} loggedIn={tweaks.loggedIn} />

      <SectionTitle brand={brand} step={2}>Choose how to pay</SectionTitle>
      {tweaks.loggedIn ? (
        <PaymentSourceChoice brand={brand} value={tierId} onChange={setTierId} options={[
          { id: 'membership-credit', label: 'Use membership credit',  sub: '6 credits remaining · membership active', cost: 'Free' },
          { id: 'single',            label: 'Single session',         sub: 'Save your credits for later',           cost: `$${a.pricing[0].price}` },
          { id: a.pricing[1] ? a.pricing[1].id : 'pack', label: a.pricing[1] ? a.pricing[1].label : 'Buy pack', sub: a.pricing[1] ? a.pricing[1].sub : '',          cost: `$${a.pricing[1] ? a.pricing[1].price : ''}` },
        ].filter(o => o.id)} />
      ) : (
        <TierPicker brand={brand} options={a.pricing} value={tierId} onChange={setTierId} />
      )}
      {tier.sessions > 1 && !tweaks.loggedIn && (
        <div style={{ fontSize: 12, color: brand.inkSoft, marginTop: 8, paddingLeft: 4, lineHeight: 1.5 }}>
          One credit applied to today's session. {tier.sessions - 1} remaining for future bookings.
        </div>
      )}

      <SectionTitle brand={brand} step={3}>Your details</SectionTitle>
      <CustomerInfo brand={brand} returning={returning(customer)} data={customer} set={setCustomer} />
      <Field brand={brand} label="Anything we should know?" optional rows={3} value={notes} onChange={setNotes} hint="Injuries, prior experience, what you want to work on…" />

      {tweaks.waiver && (
        <>
          <SectionTitle brand={brand} step={4}>Studio waiver</SectionTitle>
          <Checkbox brand={brand} checked={waiverChecked} onChange={setWaiverChecked}>
            I've read and agree to the <u style={{ color: brand.accent }}>liability waiver</u>. I'm participating at my own risk and have no conditions that prevent safe practice.
          </Checkbox>
        </>
      )}

      {tweaks.cancelFee && (
        <div style={{ marginTop: 10 }}>
          <CancelPolicyAck brand={brand} checked={policyChecked} onChange={setPolicyChecked} />
        </div>
      )}

      <SectionTitle brand={brand} step={5}>Payment</SectionTitle>
      <PaymentSection brand={brand} methods={tweaks.methods} />
      <SavePayment brand={brand} returning={tweaks.loggedIn || tweaks.returning} value={savePay} onChange={setSavePay} />
      <PromoAndGiftCard brand={brand} giftBalance={tweaks.loggedIn ? 0 : 0}
        onApplyPromo={p => setDiscount(p.amt)} onApplyGift={g => setDiscount(g.amt)} />

      <Disclaimer brand={brand} />

      <StickyCta
        brand={brand}
        label={tier.sessions > 1 ? `Buy ${tier.label.toLowerCase()} & book` : 'Book and pay'}
        sub={`$${total} · ${a.time} on ${a.date}`}
        onClick={() => onSubmit({ kind: 'appointment', total, item: a, tier, whoFor, savePay })}
        disabled={(tweaks.waiver && !waiverChecked) || (tweaks.cancelFee && !policyChecked)}
      />
    </>
  );
}

// ────────────────────────────────────────────────────────────────
//  Screen Set 3 — Class guest checkout
// ────────────────────────────────────────────────────────────────
function ClassFlow({ brand, tweaks, customer, setCustomer, onSubmit, desktop }) {
  const c = brand.class;
  const isWaitlist = tweaks.capacity === 'waitlist';
  const [tierId, setTierId] = useStateF(tweaks.loggedIn ? 'membership-credit' : 'dropin');
  const tier = c.pricing.find(t => t.id === tierId) || c.pricing[0];
  const [addons, setAddons] = useStateF({ socks: false, water: false });
  const [whoFor, setWhoFor] = useStateF({ self: true, family: [], guests: [] });
  const [policyChecked, setPolicyChecked] = useStateF(false);
  const [savePay, setSavePay] = useStateF(!tweaks.loggedIn);
  const [discount, setDiscount] = useStateF(0);
  const addonItems = [
    { id: 'socks', label: 'Grip socks', sub: 'Required for first class', price: 14 },
    { id: 'water', label: 'Spring water', sub: 'Glass bottle, refundable',       price: 4 },
  ];
  const addonTotal = addonItems.reduce((s, x) => s + (addons[x.id] ? x.price : 0), 0);
  const total = Math.max(0, tier.price + addonTotal - discount);

  const loggedInOptions = [
    { id: 'membership-credit', label: 'Use membership credit', sub: '6 credits left · unlimited monthly active', cost: 'Free' },
    { id: 'dropin',            label: 'Pay drop-in',           sub: 'Save your credits for later',              cost: `$${c.pricing[0].price}` },
  ];
  const [waiverChecked, setWaiverChecked] = useStateF(false);

  return (
    <>
      <ClassHero brand={brand} c={c} tweaks={tweaks} desktop={desktop} />

      {tweaks.loggedIn && (
        <LoggedInWalletStrip brand={brand} credits={6} membership={{ name: 'Unlimited', renews: 'Sep 1' }} />
      )}

      {!isWaitlist && (
        <>
          <SectionCard brand={brand} step={1} title="Who's this for?">
            <WhoFor brand={brand} value={whoFor} onChange={setWhoFor} loggedIn={tweaks.loggedIn} />
          </SectionCard>

          <SectionCard brand={brand} step={2} title="Choose how to pay">
            {!tweaks.loggedIn && <SignInCallout brand={brand} />}
            {tweaks.loggedIn ? (
              <PaymentSourceChoice brand={brand} value={tierId} onChange={setTierId} options={loggedInOptions} />
            ) : (
              <TierPicker brand={brand} options={c.pricing} value={tierId} onChange={setTierId} />
            )}
            {tier.sessions > 1 && !tweaks.loggedIn && (
              <div style={{ fontSize: 12, color: brand.inkSoft, marginTop: 10, paddingLeft: 4, lineHeight: 1.5 }}>
                One credit applied to this class. {tier.sessions - 1} remaining for future bookings.
              </div>
            )}
            {tier.recurring && !tweaks.loggedIn && (
              <div style={{ fontSize: 12, color: brand.inkSoft, marginTop: 10, paddingLeft: 4, lineHeight: 1.5 }}>
                Membership starts today and includes this class. Pause or cancel any time, no fees.
              </div>
            )}
            {tweaks.addons && (
              <div style={{ marginTop: 14, paddingTop: 14, borderTop: `1px dashed ${brand.border}` }}>
                <div style={{ fontSize: 12, fontWeight: 700, color: brand.inkSoft, letterSpacing: '0.06em', textTransform: 'uppercase', marginBottom: 8, display: 'flex', alignItems: 'center', gap: 8 }}>
                  Add to your booking
                  <Pill brand={brand}>Optional</Pill>
                </div>
                <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
                  {addonItems.map(item => (
                    <button key={item.id} onClick={() => setAddons(a => ({ ...a, [item.id]: !a[item.id] }))} style={{
                      display: 'flex', alignItems: 'center', gap: 12,
                      background: addons[item.id] ? brand.accentSoft : 'transparent',
                      border: `1px solid ${addons[item.id] ? brand.accent : brand.border}`,
                      borderRadius: 10,
                      padding: '10px 12px',
                      textAlign: 'left',
                      transition: 'all .15s ease',
                      cursor: 'pointer',
                    }}>
                      <div style={{
                        width: 22, height: 22, borderRadius: 6,
                        border: `1.5px solid ${addons[item.id] ? brand.accent : brand.border}`,
                        background: addons[item.id] ? brand.accent : '#fff',
                        display: 'grid', placeItems: 'center', flex: '0 0 auto',
                      }}>
                        {addons[item.id] && <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="3.5" strokeLinecap="round" strokeLinejoin="round"><polyline points="20 6 9 17 4 12"/></svg>}
                      </div>
                      <div style={{ flex: 1, minWidth: 0 }}>
                        <div style={{ fontSize: 13.5, fontWeight: 600, color: brand.ink }}>{item.label}</div>
                        <div style={{ fontSize: 11.5, color: brand.inkSoft, marginTop: 1 }}>{item.sub}</div>
                      </div>
                      <div style={{ fontSize: 13.5, fontWeight: 700, color: brand.ink }}>+${item.price}</div>
                    </button>
                  ))}
                </div>
              </div>
            )}
          </SectionCard>

          <SectionCard brand={brand} step={3} title="Payment">
            <CustomerInfo brand={brand} returning={returning(customer)} data={customer} set={setCustomer} />
            <div style={{ height: 14 }}></div>
            <div style={{ height: 1, background: brand.border, margin: '0 -18px 14px' }}></div>
            <PaymentSection brand={brand} methods={tweaks.methods} />
            <SavePayment brand={brand} returning={tweaks.loggedIn || tweaks.returning} value={savePay} onChange={setSavePay} />
            <PromoAndGiftCard brand={brand} onApplyPromo={p => setDiscount(p.amt)} onApplyGift={g => setDiscount(g.amt)} />
            {tweaks.waiver && (
              <WaiverExpandable brand={brand} checked={waiverChecked} onChange={setWaiverChecked} />
            )}
            {tweaks.cancelFee && (
              <div style={{ marginTop: 12 }}>
                <CancelPolicyAck brand={brand} checked={policyChecked} onChange={setPolicyChecked} />
              </div>
            )}
          </SectionCard>
        </>
      )}

      {isWaitlist && (
        <SectionCard brand={brand} title="Join the waitlist">
          <WaitlistBanner brand={brand} position={3} />
          <div style={{ height: 14 }}></div>
          <CustomerInfo brand={brand} returning={returning(customer)} data={customer} set={setCustomer} />
        </SectionCard>
      )}

      <StickyCta
        brand={brand}
        label={isWaitlist ? 'Join waitlist' : (tier.recurring ? 'Start membership & book' : (tier.sessions > 1 ? `Buy ${tier.label.toLowerCase()} & book` : 'Book class'))}
        sub={isWaitlist ? `${c.title} · ${c.time}` : `$${total}${tier.recurring ? '/mo' : ''} · ${c.title}`}
        onClick={() => onSubmit({ kind: 'class', total, item: c, isWaitlist, tier })}
        disabled={!isWaitlist && ((tweaks.waiver && !waiverChecked) || (tweaks.cancelFee && !policyChecked))}
      />
    </>
  );
}

// ────────────────────────────────────────────────────────────────
//  Screen Set 4 — Event / ticket purchase
// ────────────────────────────────────────────────────────────────
function EventFlow({ brand, tweaks, customer, setCustomer, onSubmit }) {
  const e = brand.event;
  const [tier, setTier] = useStateF('member');
  const [qty, setQty]   = useStateF(1);
  const tiers = [
    { id: 'member',    label: 'Members',     sub: '$5 off · ID at door', price: e.price - 5, available: 12 },
    { id: 'standard',  label: 'Standard',    sub: 'Open to everyone',    price: e.price,     available: 28 },
  ];
  const selected = tiers.find(t => t.id === tier);
  const total = selected.price * qty;

  return (
    <>
      <div style={{
        position: 'relative',
        height: 180,
        margin: '0 -22px 16px',
        overflow: 'hidden',
        background: `
          linear-gradient(160deg, ${brand.accent}EE, ${brand.accentDeep}EE),
          radial-gradient(circle at 70% 30%, ${brand.accentSoft}, transparent 60%)
        `,
      }}>
        <div style={{ position: 'absolute', inset: 0, opacity: 0.18, background: `repeating-linear-gradient(45deg, transparent, transparent 24px, rgba(255,255,255,0.08) 24px, rgba(255,255,255,0.08) 25px)` }}></div>
        <div style={{ position: 'absolute', left: 22, right: 22, bottom: 16, color: '#fff' }}>
          <div style={{ fontSize: 11, fontWeight: 700, letterSpacing: '0.12em', textTransform: 'uppercase', opacity: .8 }}>Event</div>
          <div style={{ fontFamily: brand.displayFont, fontWeight: 800, fontSize: 22, lineHeight: 1.15, marginTop: 4, letterSpacing: '-0.01em' }}>{e.title}</div>
          <div style={{ fontSize: 12.5, opacity: 0.85, marginTop: 4 }}>{e.subtitle}</div>
        </div>
      </div>

      <SummaryCard brand={brand}>
        <DetailRow brand={brand} icon={ICONS.calendar} label="Date" value={e.date} />
        <DetailRow brand={brand} icon={ICONS.clock}    label="Time" value={e.time} />
        <DetailRow brand={brand} icon={ICONS.pin}      label="Where" value={e.location} />
      </SummaryCard>

      <SectionTitle brand={brand} step={1}>Choose tickets</SectionTitle>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8, marginBottom: 8 }}>
        {tiers.map(t => (
          <button key={t.id} onClick={() => setTier(t.id)} style={{
            background: tier === t.id ? brand.accentSoft : brand.surface,
            border: `1.5px solid ${tier === t.id ? brand.accent : brand.border}`,
            borderRadius: 12,
            padding: '12px 14px',
            display: 'flex', alignItems: 'center', gap: 12,
            textAlign: 'left',
            transition: 'all .15s ease',
          }}>
            <div style={{
              width: 18, height: 18, borderRadius: 999,
              border: `2px solid ${tier === t.id ? brand.accent : brand.border}`,
              background: tier === t.id ? brand.accent : '#fff',
              display: 'grid', placeItems: 'center',
            }}>
              {tier === t.id && <span style={{ width: 7, height: 7, borderRadius: 999, background: '#fff' }}></span>}
            </div>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 14, fontWeight: 600, color: brand.ink }}>{t.label}</div>
              <div style={{ fontSize: 11.5, color: brand.inkSoft, marginTop: 1 }}>{t.sub} · {t.available} left</div>
            </div>
            <div style={{ fontFamily: brand.displayFont, fontSize: 16, fontWeight: 700, color: brand.ink }}>${t.price}</div>
          </button>
        ))}
      </div>

      <div style={{
        display: 'flex', alignItems: 'center', gap: 12,
        padding: '12px 14px',
        background: brand.surface,
        border: `1px solid ${brand.border}`,
        borderRadius: 12,
        marginBottom: 4,
      }}>
        <div style={{ flex: 1 }}>
          <div style={{ fontSize: 13, fontWeight: 600, color: brand.ink }}>Quantity</div>
          <div style={{ fontSize: 11.5, color: brand.inkSoft, marginTop: 1 }}>Up to 6 per order</div>
        </div>
        <Stepper brand={brand} value={qty} setValue={setQty} min={1} max={6} />
      </div>

      <SectionTitle brand={brand} step={2}>Your details</SectionTitle>
      <CustomerInfo brand={brand} returning={returning(customer)} data={customer} set={setCustomer} />
      {qty > 1 && (
        <div style={{ fontSize: 12, color: brand.inkSoft, marginTop: 4, marginBottom: 4, paddingLeft: 4 }}>
          Each guest gets their own QR ticket via email · names optional at the door.
        </div>
      )}

      <SectionTitle brand={brand} step={3}>Payment</SectionTitle>
      <PaymentSection brand={brand} methods={tweaks.methods} />
      <Disclaimer brand={brand} />

      <StickyCta
        brand={brand}
        label={`Get ${qty > 1 ? `${qty} tickets` : 'ticket'}`}
        sub={`$${total} total`}
        onClick={() => onSubmit({ kind: 'event', total, item: e, qty, tier: selected.label })}
      />
    </>
  );
}

function Stepper({ brand, value, setValue, min=1, max=99 }) {
  const btn = {
    width: 32, height: 32, borderRadius: 8,
    border: `1px solid ${brand.border}`,
    background: brand.surface,
    color: brand.ink,
    fontSize: 16, fontWeight: 600,
    display: 'grid', placeItems: 'center',
  };
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
      <button style={btn} onClick={() => setValue(Math.max(min, value - 1))} disabled={value <= min}>−</button>
      <div style={{ width: 22, textAlign: 'center', fontSize: 15, fontWeight: 700, color: brand.ink, fontFamily: brand.bodyFont }}>{value}</div>
      <button style={btn} onClick={() => setValue(Math.min(max, value + 1))} disabled={value >= max}>+</button>
    </div>
  );
}

// ────────────────────────────────────────────────────────────────
//  Screen Set 5 — Membership (recurring) checkout
// ────────────────────────────────────────────────────────────────
function MembershipFlow({ brand, tweaks, customer, setCustomer, onSubmit }) {
  const m = brand.membership;
  const [autoRenew, setAutoRenew] = useStateF(true);
  const [promoOpen, setPromoOpen] = useStateF(false);
  const [promo, setPromo] = useStateF('');
  const total = m.price;

  return (
    <>
      <SummaryCard brand={brand}>
        <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 12, marginBottom: 12 }}>
          <div>
            <div style={{ display: 'inline-flex', alignItems: 'center', gap: 6, marginBottom: 4 }}>
              <Pill brand={brand} accent>Membership</Pill>
            </div>
            <div style={{ fontFamily: brand.displayFont, fontWeight: brand.displayWeight, fontSize: 22, color: brand.ink, lineHeight: 1.15, letterSpacing: '-0.01em' }}>{m.title}</div>
            <div style={{ fontSize: 13, color: brand.inkSoft, marginTop: 4 }}>{m.subtitle}</div>
          </div>
          <div style={{ textAlign: 'right' }}>
            <div style={{ fontFamily: brand.displayFont, fontWeight: 700, fontSize: 22, color: brand.ink }}>${m.price}</div>
            <div style={{ fontSize: 11, color: brand.inkSoft, marginTop: 2 }}>{m.cadence}</div>
          </div>
        </div>
        <ul style={{ margin: 0, padding: 0, listStyle: 'none', borderTop: `1px solid ${brand.border}`, paddingTop: 10 }}>
          {[
            'Unlimited classes, all instructors',
            '10% off privates and workshops',
            'Pause or cancel any time, no fees',
          ].map(b => (
            <li key={b} style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '4px 0', fontSize: 13, color: brand.ink }}>
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke={brand.accent} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
              {b}
            </li>
          ))}
        </ul>
      </SummaryCard>

      <div style={{
        background: brand.surface,
        border: `1px solid ${brand.border}`,
        borderRadius: 14,
        padding: '14px 16px',
        marginBottom: 14,
        display: 'flex', alignItems: 'center', gap: 12,
      }}>
        <div style={{ flex: 1 }}>
          <div style={{ fontSize: 13.5, fontWeight: 600, color: brand.ink }}>Auto-renew every 4 weeks</div>
          <div style={{ fontSize: 11.5, color: brand.inkSoft, marginTop: 2 }}>Pause or cancel from your profile, any time. Next charge on Tue, June 11.</div>
        </div>
        <Toggle brand={brand} on={autoRenew} setOn={setAutoRenew} />
      </div>

      <SectionTitle brand={brand} step={1}>Your details</SectionTitle>
      <CustomerInfo brand={brand} returning={returning(customer)} data={customer} set={setCustomer} />

      <SectionTitle brand={brand} step={2}>Payment</SectionTitle>
      <PaymentSection brand={brand} methods={tweaks.methods} />

      {!promoOpen && (
        <button onClick={() => setPromoOpen(true)} style={{ background: 'transparent', border: 0, color: brand.accent, fontSize: 13, fontWeight: 600, marginTop: 6, padding: '4px 0' }}>+ Apply promo code</button>
      )}
      {promoOpen && (
        <div style={{ marginTop: 8 }}>
          <Field brand={brand} label="Promo code" value={promo} onChange={setPromo} />
        </div>
      )}

      <Disclaimer brand={brand} membership />

      <StickyCta
        brand={brand}
        label={autoRenew ? 'Start membership' : 'Pay one cycle'}
        sub={`$${total} ${autoRenew ? '· auto-renew on' : '· no auto-renew'}`}
        onClick={() => onSubmit({ kind: 'membership', total, item: m, autoRenew })}
      />
    </>
  );
}

// ────────────────────────────────────────────────────────────────
//  Screen Set 5 — Class pack (non-recurring) checkout
// ────────────────────────────────────────────────────────────────
function PackFlow({ brand, tweaks, customer, setCustomer, onSubmit }) {
  const packs = brand.packs || [];
  // Single-option: customer arrived via direct link with a specific pack pre-selected.
  // We default to the 10-class pack (most popular / common deep link target).
  const pack = packs.find(p => p.id === 'pack10') || packs[1] || packs[0];
  const [promoOpen, setPromoOpen] = useStateF(false);
  const [promo, setPromo] = useStateF('');

  if (!pack) return null;
  const total = pack.price;

  return (
    <>
      <SummaryCard brand={brand}>
        <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 12, marginBottom: 10 }}>
          <div style={{ minWidth: 0 }}>
            <div style={{ display: 'inline-flex', alignItems: 'center', gap: 6, marginBottom: 6 }}>
              <Pill brand={brand} accent>{pack.badge || 'Class pack'}</Pill>
            </div>
            <div style={{ fontFamily: brand.displayFont, fontWeight: brand.displayWeight, fontSize: 22, color: brand.ink, lineHeight: 1.15, letterSpacing: '-0.01em' }}>{pack.label}</div>
            <div style={{ fontSize: 13, color: brand.inkSoft, marginTop: 4 }}>{pack.sub}</div>
          </div>
          <div style={{ textAlign: 'right', flex: '0 0 auto' }}>
            <div style={{ fontFamily: brand.displayFont, fontWeight: 700, fontSize: 24, color: brand.ink, lineHeight: 1 }}>${pack.price}</div>
            {pack.perCredit && <div style={{ fontSize: 11, color: brand.inkSoft, marginTop: 4 }}>${pack.perCredit}/class</div>}
          </div>
        </div>
        <div style={{ borderTop: `1px solid ${brand.border}`, paddingTop: 4 }}>
          <DetailRow brand={brand} icon={ICONS.spark}    label="Includes" value={pack.credits ? `${pack.credits} class credits` : 'Unlimited access'} />
          <DetailRow brand={brand} icon={ICONS.calendar} label="Valid"    value={`${pack.expires} from purchase`} />
          <DetailRow brand={brand} icon={ICONS.user}     label="Use on"   value="Any group class on the schedule" />
        </div>
        <div style={{ marginTop: 10, padding: '8px 10px', background: brand.accentSoft, borderRadius: 8, fontSize: 12, color: brand.accentDeep, lineHeight: 1.45, display: 'flex', alignItems: 'center', gap: 8 }}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" style={{ flex: '0 0 auto' }}><circle cx="12" cy="12" r="10"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>
          One-time charge · no subscription, no auto-renew.
        </div>
      </SummaryCard>

      <SectionTitle brand={brand} step={1}>Your details</SectionTitle>
      <CustomerInfo brand={brand} returning={returning(customer)} data={customer} set={setCustomer} />

      <SectionTitle brand={brand} step={2}>Payment</SectionTitle>
      <PaymentSection brand={brand} methods={tweaks.methods} />

      {!promoOpen && (
        <button onClick={() => setPromoOpen(true)} style={{ background: 'transparent', border: 0, color: brand.accent, fontSize: 13, fontWeight: 600, marginTop: 6, padding: '4px 0' }}>+ Apply promo code</button>
      )}
      {promoOpen && (
        <div style={{ marginTop: 8 }}>
          <Field brand={brand} label="Promo code" value={promo} onChange={setPromo} />
        </div>
      )}

      <Disclaimer brand={brand} />

      <StickyCta
        brand={brand}
        label={`Buy now — $${total}`}
        sub={`${pack.label} · ${pack.credits ? pack.credits + ' credits' : 'unlimited'} · ${pack.expires}`}
        onClick={() => onSubmit({ kind: 'pack', total, item: { ...pack, brandName: brand.name } })}
      />
    </>
  );
}

// ────────────────────────────────────────────────────────────────
function Toggle({ brand, on, setOn }) {
  return (
    <button onClick={() => setOn(!on)} style={{
      width: 46, height: 28, borderRadius: 999,
      background: on ? brand.accent : brand.border,
      border: 0, padding: 3, position: 'relative',
      transition: 'background .15s ease',
      flex: '0 0 auto',
    }}>
      <span style={{
        display: 'block',
        width: 22, height: 22, borderRadius: 999,
        background: '#fff',
        boxShadow: '0 2px 4px rgba(0,0,0,.18)',
        marginLeft: on ? 18 : 0,
        transition: 'margin .15s ease',
      }}></span>
    </button>
  );
}

// ────────────────────────────────────────────────────────────────
//  Sticky bottom CTA — pinned to mobile screen base
// ────────────────────────────────────────────────────────────────
function StickyCta({ brand, label, sub, onClick, disabled, loading }) {
  return (
    <div style={{
      position: 'sticky',
      bottom: 0,
      marginTop: 24,
      marginLeft: -22, marginRight: -22,
      padding: '14px 22px 22px',
      background: `linear-gradient(180deg, ${brand.bg}00 0%, ${brand.bg} 30%)`,
      paddingTop: 26,
    }}>
      <PrimaryButton brand={brand} onClick={onClick} disabled={disabled} loading={loading} sub={sub}>{label}</PrimaryButton>
    </div>
  );
}

// ────────────────────────────────────────────────────────────────
//  Disclaimer (terms / cancellation)
// ────────────────────────────────────────────────────────────────
function Disclaimer({ brand, membership }) {
  return (
    <div style={{
      fontSize: 11.5,
      lineHeight: 1.5,
      color: brand.inkSoft,
      marginTop: 14,
      padding: '0 4px',
    }}>
      By continuing you agree to <span style={{ color: brand.accent }}>{brand.name}'s policies</span>
      {membership ? '. Memberships renew automatically until canceled.' : ' and our 24-hour cancellation policy.'}
    </div>
  );
}

// helper
function returning(c) {
  return c && c.email && c.name;
}

Object.assign(window, {
  AppointmentFlow, ClassFlow, EventFlow, MembershipFlow, PackFlow,
  StickyCta, Toggle, Stepper, DetailRow, ICONS, TierPicker,
  CustomerInfo, SignInCallout, WaiverExpandable,
});
