// Pricing — the full QubikOS pricing experience.
// Premium, not cheap: full OS included at every size, AI capabilities as
// optional upgrades, transparent payments with real choice. English copy.

const { useState: _pUseS, useEffect: _pUseE, useRef: _pUseR } = React;

// ---------------------------------------------------------------- data

const PLANS = [
  {
    key: 'start', name: 'Start', price: 99, members: 'Up to 100 active members',
    blurb: 'For smaller activity businesses building a serious operation.',
    popular: false,
  },
  {
    key: 'grow', name: 'Grow', price: 179, members: 'Up to 400 active members',
    blurb: 'For established activity businesses ready to grow.',
    popular: true,
  },
  {
    key: 'scale', name: 'Scale', price: 299, members: 'Up to 800 active members',
    blurb: 'For larger activity businesses running serious volume.',
    popular: false,
  },
];

const ENTERPRISE = {
  key: 'enterprise', name: 'Enterprise', members: '800+ active members',
  blurb: 'Multi-location, large organizations, and franchises.',
};

// Same list on every plan — the OS doesn't shrink with the tier.
const CAPABILITY_PREVIEW = [
  'Scheduling', 'Billing', 'Website', 'Online Booking', 'Parent Portal',
  'Attendance', 'Leads', 'Staff', 'Progress', 'Automations',
];

const TRUST_SIGNALS = [
  '30-day free trial', 'No setup fee', 'No migration fee',
  'Unlimited staff', 'Full QubikOS', 'No long-term contract',
];

const ADDONS = [
  {
    key: 'frontdesk', name: 'AI Front Desk', price: 149, hero: true, icon: 'phone',
    headline: 'Never miss another lead.',
    blurb: 'Answers. Follows up. Books. Even when your team is coaching.',
    bullets: ['24/7 responses', 'Website chat & SMS', 'Missed-inquiry follow-up', 'Trial booking', 'Program & pricing questions', 'Human handoff'],
  },
  {
    key: 'connectai', name: 'Connect Your AI', price: 49, icon: 'plug',
    headline: 'Let ChatGPT, Claude and AI agents securely work with your QubikOS.',
    bullets: ['Secure AI connections', 'Permission-controlled access', 'Business data context', 'Agent actions', 'Activity logs'],
    small: 'Powered by QubikOS MCP',
  },
  {
    key: 'brandedapp', name: 'Branded App', price: 99, icon: 'app',
    headline: 'Your business. Your app.',
    bullets: ['Your logo & colors', 'iOS & Android', 'Push notifications', 'App Store presence'],
  },
  {
    key: 'intelligence', name: 'Advanced Intelligence', price: 79, icon: 'brain',
    headline: 'See what’s coming.',
    bullets: ['Churn prediction', 'At-risk members', 'Revenue forecasting', 'Class profitability', 'Natural-language business questions'],
  },
];

const FEATURE_GROUPS = [
  { key: 'run', name: 'Run', icon: 'calendar',
    preview: ['Scheduling', 'Recurring Classes', 'Camps', 'Waitlists', 'Attendance'],
    full: ['Scheduling', 'Classes', 'Recurring Classes', 'Private Lessons', 'Camps', 'Clinics', 'Events', 'Waitlists', 'Capacity Management', 'Attendance', 'Make-ups'] },
  { key: 'families', name: 'Families', icon: 'users',
    preview: ['Family Accounts', 'Parent Portal', 'Online Registration', 'Self-Service Enrollment', 'Waivers'],
    full: ['Family Accounts', 'Parent Portal', 'Online Registration', 'Self-Service Enrollment', 'Self-Service Make-ups', 'Waivers', 'Transfers', 'Profile Management', 'Communication History'] },
  { key: 'money', name: 'Money', icon: 'card',
    preview: ['Recurring Billing', 'Autopay', 'Sibling Discounts', 'Failed-Payment Recovery', 'Revenue Reporting'],
    full: ['Recurring Billing', 'Autopay', 'Invoices', 'Prorating', 'Sibling Discounts', 'Multi-Class Discounts', 'Coupon Codes', 'Credits', 'Refunds', 'Payment Plans', 'Deposits', 'Late Fees', 'Failed-Payment Recovery', '5th-Week Billing', 'Revenue Reporting'] },
  { key: 'grow', name: 'Grow', icon: 'trend',
    preview: ['Lead Capture', 'Lead Pipeline', 'Trial Booking', 'Automated Follow-ups', 'Conversion Tracking'],
    full: ['Lead Capture', 'Lead Pipeline', 'Trials', 'Trial Booking', 'Lead Sources', 'Conversion Tracking', 'Automated Follow-ups', 'Campaigns', 'Website Forms', 'Lead History'] },
  { key: 'team', name: 'Team', icon: 'shield',
    preview: ['Staff Profiles', 'Staff Scheduling', 'Availability', 'Time Clock', 'Permissions'],
    full: ['Staff Profiles', 'Staff Scheduling', 'Availability', 'Substitutions', 'Time Clock', 'Permissions', 'Internal Communication', 'Staff Reporting'] },
  { key: 'progress', name: 'Progress', icon: 'sparkle',
    preview: ['Skill Tracking', 'Evaluations', 'Levels', 'Parent-Visible Progress', 'Certificates'],
    full: ['Skill Tracking', 'Evaluations', 'Levels', 'Progress Tracking', 'Testing', 'Parent-Visible Progress', 'Certificates / Achievements'] },
  { key: 'connect', name: 'Connect', icon: 'bell',
    preview: ['Email', 'SMS', 'Two-Way Messaging', 'Push Notifications', 'Automations'],
    full: ['Email', 'SMS', 'Two-Way Messaging', 'Message History', 'Push Notifications', 'Automations', 'Integrations', 'API', 'Webhooks'] },
  { key: 'reports', name: 'Reports', icon: 'chart',
    preview: ['Revenue', 'Enrollment', 'Attendance', 'Retention', 'Dashboards'],
    full: ['Revenue', 'Enrollment', 'Attendance', 'Retention', 'Lead Conversion', 'Staff', 'Capacity', 'Dashboards'] },
];

const SIZE_STEPS = [
  { label: '100', plan: 'start' },
  { label: '400', plan: 'grow' },
  { label: '800', plan: 'scale' },
  { label: '800+', plan: 'enterprise' },
];

function planByKey(key) {
  return PLANS.find(p => p.key === key) || ENTERPRISE;
}

// ---------------------------------------------------------------- hero + cards

function PricingHeroAndPlans() {
  return (
    <section id="pricing" style={{
      padding: '120px 24px 96px', position: 'relative', overflow: 'hidden',
      background: 'var(--ink-950)', color: '#fff',
    }}>
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        background: 'radial-gradient(55% 45% at 18% 20%, rgba(57,104,255,0.30), transparent 60%), radial-gradient(45% 40% at 85% 75%, rgba(124,92,255,0.24), transparent 60%)',
      }} />
      <div style={{ maxWidth: 1180, margin: '0 auto', position: 'relative' }}>
        <div style={{ textAlign: 'center', maxWidth: 720, margin: '0 auto 20px' }}>
          <p className="eyebrow" style={{ color: '#8cb0ff', margin: 0 }}>Pricing</p>
          <h2 className="display-lg" style={{ margin: '14px 0 0', color: '#fff', fontSize: 'clamp(32px, 4.6vw, 52px)' }}>
            Simple pricing.<br />
            <span style={{
              background: 'linear-gradient(90deg, #8cb0ff 0%, #d070ff 55%, #4dd4ff 100%)',
              WebkitBackgroundClip: 'text', backgroundClip: 'text', color: 'transparent',
            }}>The full operating system.</span>
          </h2>
          <p style={{ margin: '16px 0 0', color: 'rgba(247,248,250,0.66)', fontSize: 17, lineHeight: 1.55 }}>
            Same QubikOS. More business. Plans scale with the size of your studio &mdash; not with which features you&rsquo;re allowed to use.
          </p>
        </div>

        <div className="pricing-plan-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 20, marginTop: 56, alignItems: 'stretch' }}>
          {PLANS.map(pl => <PlanCard key={pl.key} plan={pl} />)}
        </div>

        <EnterpriseStrip />

        <div className="pricing-trust-row" style={{
          display: 'flex', flexWrap: 'wrap', justifyContent: 'center', gap: 10,
          marginTop: 40,
        }}>
          {TRUST_SIGNALS.map(t => (
            <span key={t} style={{
              display: 'inline-flex', alignItems: 'center', gap: 8,
              padding: '8px 14px', borderRadius: 999, fontSize: 12.5, fontWeight: 500,
              background: 'rgba(255,255,255,0.05)', border: '1px solid rgba(255,255,255,0.10)',
              color: 'rgba(247,248,250,0.78)',
            }}>
              <window.QBIcon name="check" size={12} stroke={2.4} />
              {t}
            </span>
          ))}
        </div>
      </div>
      <style>{`
        @media (max-width: 900px) {
          .pricing-plan-grid { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </section>
  );
}

function PlanCard({ plan }) {
  const scrollToExplorer = (e) => {
    e.preventDefault();
    document.getElementById('everything-inside')?.scrollIntoView({ behavior: 'smooth', block: 'start' });
  };
  return (
    <div style={{
      position: 'relative', display: 'flex', flexDirection: 'column', gap: 18,
      padding: 30, borderRadius: 24,
      background: plan.popular ? 'linear-gradient(165deg, rgba(57,104,255,0.16) 0%, rgba(124,92,255,0.10) 100%)' : 'rgba(255,255,255,0.03)',
      border: plan.popular ? '1px solid rgba(124,92,255,0.45)' : '1px solid rgba(255,255,255,0.08)',
      boxShadow: plan.popular ? '0 24px 64px rgba(57,104,255,0.22)' : 'none',
      backdropFilter: 'blur(20px)',
    }}>
      {plan.popular && (
        <div style={{
          position: 'absolute', top: 20, right: 20,
          padding: '5px 10px', borderRadius: 99, fontSize: 11, fontWeight: 600,
          background: 'rgba(255,255,255,0.14)', color: '#fff', border: '1px solid rgba(255,255,255,0.20)',
        }}>MOST POPULAR</div>
      )}
      <div>
        <h3 className="h3" style={{ margin: 0, fontSize: 20, color: '#fff' }}>{plan.name}</h3>
        <p style={{ margin: '6px 0 0', fontSize: 13.5, color: 'rgba(247,248,250,0.66)', lineHeight: 1.5 }}>{plan.blurb}</p>
      </div>

      <div>
        <span className="display" style={{ fontSize: 44, letterSpacing: '-0.035em', color: '#fff' }}>${plan.price}</span>
        <span style={{ fontSize: 14, color: 'rgba(247,248,250,0.55)', marginLeft: 6 }}>/month</span>
      </div>

      <div style={{
        display: 'inline-flex', alignSelf: 'flex-start', alignItems: 'center', gap: 7,
        padding: '5px 11px', borderRadius: 999, fontSize: 11.5, fontWeight: 600,
        background: 'rgba(77,212,255,0.14)', color: '#4dd4ff', border: '1px solid rgba(77,212,255,0.25)',
      }}>
        <window.QBIcon name="shield" size={12} stroke={2.4} />
        FULL QUBIKOS INCLUDED
      </div>

      <p style={{ margin: 0, fontSize: 13, fontWeight: 600, color: 'rgba(247,248,250,0.85)' }}>{plan.members}</p>

      <div className="pricing-capability-preview" style={{
        display: 'grid', gridTemplateColumns: '1fr 1fr', columnGap: 12, rowGap: 8,
        padding: '16px 0', borderTop: '1px solid rgba(255,255,255,0.08)',
      }}>
        {CAPABILITY_PREVIEW.map(c => (
          <span key={c} style={{ fontSize: 12.5, color: 'rgba(247,248,250,0.72)', display: 'flex', alignItems: 'center', gap: 6 }}>
            <span style={{ width: 4, height: 4, borderRadius: 999, background: 'rgba(140,176,255,0.85)', flexShrink: 0 }} />
            {c}
          </span>
        ))}
      </div>

      <a href="#everything-inside" onClick={scrollToExplorer} style={{
        fontSize: 13, fontWeight: 600, color: '#8cb0ff', display: 'inline-flex', alignItems: 'center', gap: 6,
      }}>
        Explore everything included
        <window.QBIcon name="arrow" size={13} stroke={2.4} />
      </a>

      <window.QBButton size="lg" variant={plan.popular ? 'primary' : 'ghost'} style={{ width: '100%', marginTop: 4 }}>
        Start 30-Day Free Trial
      </window.QBButton>
    </div>
  );
}

function EnterpriseStrip() {
  return (
    <div style={{
      marginTop: 20, padding: '26px 32px', borderRadius: 20,
      background: 'rgba(255,255,255,0.02)', border: '1px solid rgba(255,255,255,0.08)',
      display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 24, flexWrap: 'wrap',
    }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 18, flexWrap: 'wrap' }}>
        <div style={{
          width: 44, height: 44, borderRadius: 12, flexShrink: 0,
          background: 'rgba(140,176,255,0.12)', display: 'grid', placeItems: 'center', color: '#8cb0ff',
        }}>
          <window.QBIcon name="users" size={20} stroke={1.8} />
        </div>
        <div>
          <h3 style={{ margin: 0, fontSize: 16, fontWeight: 700, color: '#fff' }}>Enterprise &mdash; {ENTERPRISE.members}</h3>
          <p style={{ margin: '4px 0 0', fontSize: 13, color: 'rgba(247,248,250,0.62)' }}>{ENTERPRISE.blurb}</p>
        </div>
      </div>
      <window.QBButton size="md" variant="ghost">Let&rsquo;s Talk</window.QBButton>
    </div>
  );
}

// ---------------------------------------------------------------- feature explorer

function FeatureExplorer() {
  const [openKey, setOpenKey] = _pUseS(null);
  return (
    <section id="everything-inside" style={{ padding: '96px 24px', background: 'var(--bg)' }}>
      <div style={{ maxWidth: 1180, margin: '0 auto' }}>
        <div style={{ textAlign: 'center', maxWidth: 640, margin: '0 auto 48px' }}>
          <p className="eyebrow" style={{ margin: 0 }}>Everything inside QubikOS</p>
          <h2 className="display-lg" style={{ margin: '14px 0 0', fontSize: 'clamp(30px, 4vw, 44px)' }}>
            One operating system for everything behind your activity business.
          </h2>
        </div>

        <div className="feature-group-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16 }}>
          {FEATURE_GROUPS.map(g => {
            const open = openKey === g.key;
            return (
              <div key={g.key} style={{
                borderRadius: 20, border: '1px solid var(--border)', background: 'var(--surface)',
                padding: 22, display: 'flex', flexDirection: 'column', gap: 14,
              }}>
                <div style={{
                  width: 38, height: 38, borderRadius: 11, display: 'grid', placeItems: 'center',
                  background: 'rgba(57,104,255,0.10)', color: 'var(--blue-600)',
                }}>
                  <window.QBIcon name={g.icon} size={18} stroke={1.8} />
                </div>
                <h3 style={{ margin: 0, fontSize: 16, fontWeight: 700, color: 'var(--fg-1)' }}>{g.name}</h3>
                <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 7, flex: 1 }}>
                  {(open ? g.full : g.preview).map(f => (
                    <li key={f} style={{ fontSize: 12.5, color: 'var(--fg-2)', lineHeight: 1.4 }}>{f}</li>
                  ))}
                </ul>
                <button onClick={() => setOpenKey(open ? null : g.key)} style={{
                  background: 'none', border: 'none', cursor: 'pointer', padding: 0,
                  fontSize: 12.5, fontWeight: 600, color: 'var(--blue-600)',
                  display: 'inline-flex', alignItems: 'center', gap: 5, alignSelf: 'flex-start',
                }}>
                  {open ? 'Show less' : 'Explore all features'}
                  <span style={{ transform: open ? 'rotate(90deg)' : 'none', transition: 'transform .2s var(--ease-out)', display: 'inline-flex' }}>
                    <window.QBIcon name="arrow" size={12} stroke={2.6} />
                  </span>
                </button>
              </div>
            );
          })}
        </div>
      </div>
      <style>{`
        @media (max-width: 1000px) { .feature-group-grid { grid-template-columns: 1fr 1fr !important; } }
        @media (max-width: 560px) { .feature-group-grid { grid-template-columns: 1fr !important; } }
      `}</style>
    </section>
  );
}

// ---------------------------------------------------------------- website & booking

function WebsiteBooking() {
  const items = [
    'Instant website builder', 'Live schedule', 'Online class booking', 'Trial & camp booking',
    'Private-lesson booking', 'Online registration', 'Lead forms', 'Parent portal connection',
  ];
  return (
    <section style={{ padding: '96px 24px', background: 'var(--bg-muted)' }}>
      <div style={{ maxWidth: 1180, margin: '0 auto', display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 56, alignItems: 'center' }} className="website-booking-grid">
        <div>
          <p className="eyebrow" style={{ margin: 0 }}>Website &amp; booking</p>
          <h2 className="display-lg" style={{ margin: '14px 0 16px', fontSize: 'clamp(28px, 3.6vw, 40px)' }}>
            Your digital front door.<br />Built in.
          </h2>
          <p className="lead" style={{ fontSize: 16.5, marginBottom: 24 }}>
            QubikOS can build your customer-facing website &mdash; not just a link or an embedded calendar. It&rsquo;s connected directly to the same operating system running your schedule, billing, and leads.
          </p>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10, marginBottom: 28 }}>
            {items.map(i => (
              <span key={i} style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13.5, color: 'var(--fg-2)' }}>
                <span style={{
                  width: 18, height: 18, borderRadius: 99, display: 'grid', placeItems: 'center', flexShrink: 0,
                  background: 'rgba(16,185,129,0.14)', color: '#10b981',
                }}><window.QBIcon name="check" size={11} stroke={2.6} /></span>
                {i}
              </span>
            ))}
          </div>
          <p style={{ margin: 0, fontSize: 13, fontWeight: 600, color: 'var(--fg-3)' }}>
            Part of every QubikOS plan &mdash; no separate website pricing.
          </p>
        </div>
        <div style={{
          borderRadius: 24, border: '1px solid var(--border)', background: 'var(--surface)',
          boxShadow: 'var(--shadow-lg)', overflow: 'hidden',
        }}>
          <div style={{ padding: '12px 16px', borderBottom: '1px solid var(--border)', display: 'flex', gap: 6 }}>
            <span style={{ width: 10, height: 10, borderRadius: 99, background: '#ff5f57' }} />
            <span style={{ width: 10, height: 10, borderRadius: 99, background: '#febc2e' }} />
            <span style={{ width: 10, height: 10, borderRadius: 99, background: '#28c840' }} />
          </div>
          <div style={{ padding: 28 }}>
            <div style={{
              borderRadius: 14, padding: 20, marginBottom: 14,
              background: 'linear-gradient(135deg, var(--blue-900), var(--blue-700))', color: '#fff',
            }}>
              <p style={{ margin: 0, fontSize: 11, fontWeight: 600, letterSpacing: '0.06em', textTransform: 'uppercase', opacity: 0.75 }}>Your Studio</p>
              <p style={{ margin: '6px 0 0', fontSize: 19, fontWeight: 700 }}>Book a trial class</p>
            </div>
            {['Tuesday, 4:30 PM — Girls 1', 'Thursday, 5:00 PM — Boys 1', 'Saturday, 10:00 AM — Open Gym'].map(row => (
              <div key={row} style={{
                display: 'flex', alignItems: 'center', justifyContent: 'space-between',
                padding: '12px 4px', borderBottom: '1px solid var(--border)', fontSize: 13, color: 'var(--fg-2)',
              }}>
                {row}
                <span style={{ fontSize: 11.5, fontWeight: 600, color: 'var(--blue-600)' }}>Select</span>
              </div>
            ))}
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px) { .website-booking-grid { grid-template-columns: 1fr !important; gap: 32px !important; } }
      `}</style>
    </section>
  );
}

// ---------------------------------------------------------------- premium capabilities

function PremiumCapabilities() {
  const heroAddon = ADDONS.find(a => a.hero);
  const rest = ADDONS.filter(a => !a.hero);
  return (
    <section style={{
      padding: '96px 24px', position: 'relative', overflow: 'hidden',
      background: 'var(--ink-950)', color: '#fff',
    }}>
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        background: 'radial-gradient(50% 45% at 80% 15%, rgba(124,92,255,0.26), transparent 60%), radial-gradient(45% 40% at 15% 85%, rgba(57,104,255,0.22), transparent 60%)',
      }} />
      <div style={{ maxWidth: 1180, margin: '0 auto', position: 'relative' }}>
        <div style={{ textAlign: 'center', maxWidth: 640, margin: '0 auto 48px' }}>
          <p className="eyebrow" style={{ color: '#8cb0ff', margin: 0 }}>Go further</p>
          <h2 className="display-lg" style={{ margin: '14px 0 0', color: '#fff', fontSize: 'clamp(28px, 3.6vw, 40px)' }}>
            Make QubikOS even more powerful.
          </h2>
          <p style={{ margin: '14px 0 0', color: 'rgba(247,248,250,0.62)', fontSize: 15.5 }}>
            The core operating system is already complete. These are optional.
          </p>
        </div>

        <div className="addon-hero-card" style={{
          padding: 36, borderRadius: 24, marginBottom: 20,
          background: 'linear-gradient(150deg, rgba(57,104,255,0.20) 0%, rgba(124,92,255,0.14) 100%)',
          border: '1px solid rgba(124,92,255,0.35)',
          display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 32, alignItems: 'center',
        }}>
          <div>
            <div style={{
              width: 44, height: 44, borderRadius: 12, display: 'grid', placeItems: 'center', marginBottom: 18,
              background: 'rgba(77,212,255,0.16)', color: '#4dd4ff',
            }}>
              <window.QBIcon name={heroAddon.icon} size={20} stroke={1.8} />
            </div>
            <h3 style={{ margin: 0, fontSize: 24, fontWeight: 700, color: '#fff' }}>{heroAddon.name}</h3>
            <p style={{ margin: '10px 0 4px', fontSize: 17, fontWeight: 600, color: '#fff' }}>{heroAddon.headline}</p>
            <p style={{ margin: '0 0 20px', fontSize: 14, color: 'rgba(247,248,250,0.66)', lineHeight: 1.55 }}>{heroAddon.blurb}</p>
            <p style={{ margin: 0 }}>
              <span className="display" style={{ fontSize: 32, color: '#fff' }}>+${heroAddon.price}</span>
              <span style={{ fontSize: 13.5, color: 'rgba(247,248,250,0.55)', marginLeft: 6 }}>/month</span>
            </p>
          </div>
          <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
            {heroAddon.bullets.map(b => (
              <li key={b} style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13.5, color: 'rgba(247,248,250,0.85)' }}>
                <span style={{
                  width: 18, height: 18, borderRadius: 99, display: 'grid', placeItems: 'center', flexShrink: 0,
                  background: 'rgba(77,212,255,0.18)', color: '#4dd4ff',
                }}><window.QBIcon name="check" size={11} stroke={2.6} /></span>
                {b}
              </li>
            ))}
          </ul>
        </div>

        <div className="addon-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16 }}>
          {rest.map(a => (
            <div key={a.key} style={{
              padding: 26, borderRadius: 20, display: 'flex', flexDirection: 'column', gap: 12,
              background: 'rgba(255,255,255,0.03)', border: '1px solid rgba(255,255,255,0.08)',
            }}>
              <div style={{
                width: 36, height: 36, borderRadius: 10, display: 'grid', placeItems: 'center',
                background: 'rgba(140,176,255,0.12)', color: '#8cb0ff',
              }}>
                <window.QBIcon name={a.icon} size={17} stroke={1.8} />
              </div>
              <h3 style={{ margin: 0, fontSize: 16, fontWeight: 700, color: '#fff' }}>{a.name}</h3>
              <p style={{ margin: 0, fontSize: 13, color: 'rgba(247,248,250,0.68)', lineHeight: 1.5 }}>{a.headline}</p>
              <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 6, flex: 1 }}>
                {a.bullets.map(b => (
                  <li key={b} style={{ fontSize: 12, color: 'rgba(247,248,250,0.55)' }}>{b}</li>
                ))}
              </ul>
              <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', marginTop: 4 }}>
                <span>
                  <span className="display" style={{ fontSize: 22, color: '#fff' }}>+${a.price}</span>
                  <span style={{ fontSize: 12, color: 'rgba(247,248,250,0.50)', marginLeft: 4 }}>/mo</span>
                </span>
              </div>
              {a.small && (
                <p style={{ margin: 0, fontSize: 10.5, letterSpacing: '0.04em', textTransform: 'uppercase', color: 'rgba(247,248,250,0.40)', fontFamily: 'var(--font-mono)' }}>
                  {a.small}
                </p>
              )}
            </div>
          ))}
        </div>
      </div>
      <style>{`
        @media (max-width: 900px) {
          .addon-hero-card { grid-template-columns: 1fr !important; }
          .addon-grid { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </section>
  );
}

// ---------------------------------------------------------------- payments your way

function PaymentsYourWay() {
  return (
    <section style={{ padding: '96px 24px', background: 'var(--bg)' }}>
      <div style={{ maxWidth: 1180, margin: '0 auto' }}>
        <div style={{ textAlign: 'center', maxWidth: 640, margin: '0 auto 48px' }}>
          <p className="eyebrow" style={{ margin: 0 }}>Payments</p>
          <h2 className="display-lg" style={{ margin: '14px 0 0', fontSize: 'clamp(28px, 3.6vw, 40px)' }}>
            Payments. Your way.
          </h2>
          <p className="lead" style={{ fontSize: 15.5, marginTop: 14 }}>
            QubikOS supports more than one processing path &mdash; you choose. No lock-in.
          </p>
        </div>

        <div className="payments-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20 }}>
          <div style={{ padding: 30, borderRadius: 24, border: '1px solid var(--border)', background: 'var(--surface)', display: 'flex', flexDirection: 'column', gap: 14 }}>
            <p className="caption" style={{ margin: 0 }}>Fast Start</p>
            <h3 style={{ margin: 0, fontSize: 20, fontWeight: 700, color: 'var(--fg-1)' }}>Get started fast.</h3>
            <p style={{ margin: 0, fontSize: 14, color: 'var(--fg-2)', lineHeight: 1.55 }}>
              Connect a supported easy-onboarding processor and start accepting payments right away &mdash; no traditional merchant-account process.
            </p>
            <p style={{ margin: '4px 0 0', fontSize: 13, color: 'var(--fg-3)' }}>
              Typical economics: <strong style={{ color: 'var(--fg-1)' }}>3.5%+</strong>, depending on processor and configuration.
            </p>
            <p style={{ margin: 0, fontSize: 12.5, color: 'var(--fg-3)' }}>Best for businesses that value speed and simple onboarding.</p>
            <window.QBButton size="md" variant="light" style={{ alignSelf: 'flex-start', marginTop: 8 }}>Connect &amp; Go</window.QBButton>
          </div>

          <div style={{
            padding: 30, borderRadius: 24, display: 'flex', flexDirection: 'column', gap: 14,
            background: 'linear-gradient(160deg, #070e2e 0%, #1f3cb8 100%)', color: '#fff',
            border: '1px solid rgba(124,92,255,0.35)', boxShadow: '0 24px 60px rgba(41,80,230,0.28)',
          }}>
            <p className="caption" style={{ margin: 0, color: 'rgba(247,248,250,0.60)' }}>QubikOS Payments</p>
            <h3 style={{ margin: 0, fontSize: 20, fontWeight: 700, color: '#fff' }}>Keep more of every payment.</h3>
            <p style={{ margin: 0, fontSize: 14, color: 'rgba(247,248,250,0.75)', lineHeight: 1.55 }}>
              Integrated directly into QubikOS &mdash; billing, autopay, refunds, credits, and reporting in one system.
            </p>
            <p style={{ margin: '4px 0 0' }}>
              <span className="display" style={{ fontSize: 30, color: '#fff' }}>2.9% + $0.30*</span>
              <span style={{ fontSize: 12.5, color: 'rgba(247,248,250,0.55)', marginLeft: 8 }}>per card transaction</span>
            </p>
            <p style={{ margin: 0, fontSize: 12.5, color: 'rgba(247,248,250,0.55)' }}>Start fast today. Optimize your processing when you&rsquo;re ready.</p>
            <window.QBButton size="md" variant="primary" style={{ alignSelf: 'flex-start', marginTop: 8 }}>Switch to QubikOS Payments</window.QBButton>
          </div>
        </div>
        <p style={{ margin: '18px 4px 0', fontSize: 11.5, color: 'var(--fg-3)' }}>
          * Current published card rate for QubikOS Payments; final rate may vary by business configuration.
        </p>
      </div>
      <style>{`
        @media (max-width: 900px) { .payments-grid { grid-template-columns: 1fr !important; } }
      `}</style>
    </section>
  );
}

// ---------------------------------------------------------------- configurator

function Configurator() {
  const [sizeIdx, setSizeIdx] = _pUseS(1); // default: Grow / 400
  const [selected, setSelected] = _pUseS({});
  const plan = planByKey(SIZE_STEPS[sizeIdx].plan);
  const isEnterprise = plan.key === 'enterprise';

  const toggle = (key) => setSelected(s => ({ ...s, [key]: !s[key] }));

  const addonTotal = ADDONS.reduce((sum, a) => sum + (selected[a.key] ? a.price : 0), 0);
  const total = isEnterprise ? null : (plan.price || 0) + addonTotal;
  const animatedTotal = window.useCountUp(total || 0, !isEnterprise, 420);

  // Desktop sticky bar: only once the on-page total has scrolled out of
  // view and there's an actual choice to remember. Mobile stays always-on.
  const totalRef = _pUseR(null);
  const [totalInView, setTotalInView] = _pUseS(true);
  const [isMobile, setIsMobile] = _pUseS(false);

  _pUseE(() => {
    if (!totalRef.current) return;
    const io = new IntersectionObserver(([e]) => setTotalInView(e.isIntersecting), { threshold: 0.1 });
    io.observe(totalRef.current);
    return () => io.disconnect();
  }, []);

  _pUseE(() => {
    const mq = window.matchMedia('(max-width: 700px)');
    const update = () => setIsMobile(mq.matches);
    update();
    mq.addEventListener('change', update);
    return () => mq.removeEventListener('change', update);
  }, []);

  const hasSelection = Object.values(selected).some(Boolean);
  const showDesktopStickyBar = !totalInView && hasSelection;
  const stickyBarVisible = isMobile || showDesktopStickyBar;

  _pUseE(() => {
    document.documentElement.style.setProperty('--qb-sticky-bar-offset', stickyBarVisible ? '78px' : '0px');
    return () => document.documentElement.style.setProperty('--qb-sticky-bar-offset', '0px');
  }, [stickyBarVisible]);

  return (
    <section style={{
      padding: '96px 24px 110px', position: 'relative', overflow: 'hidden',
      background: 'var(--ink-950)', color: '#fff',
    }}>
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        background: 'radial-gradient(50% 45% at 50% 0%, rgba(57,104,255,0.24), transparent 60%)',
      }} />
      <div style={{ maxWidth: 900, margin: '0 auto', position: 'relative' }}>
        <div style={{ textAlign: 'center', marginBottom: 48 }}>
          <p className="eyebrow" style={{ color: '#8cb0ff', margin: 0 }}>Build your QubikOS</p>
          <h2 className="display-lg" style={{ margin: '14px 0 0', color: '#fff', fontSize: 'clamp(28px, 3.6vw, 40px)' }}>
            Build your QubikOS.
          </h2>
        </div>

        {/* Step 1 — size */}
        <div style={{ marginBottom: 40 }}>
          <p className="caption" style={{ color: 'rgba(247,248,250,0.55)', textAlign: 'center', marginBottom: 16 }}>
            Step 1 &mdash; Business size (active members)
          </p>
          <div style={{ display: 'flex', justifyContent: 'center', gap: 10, flexWrap: 'wrap' }}>
            {SIZE_STEPS.map((s, i) => (
              <button key={s.label} onClick={() => setSizeIdx(i)} style={{
                padding: '11px 22px', borderRadius: 999, cursor: 'pointer', fontSize: 14, fontWeight: 600,
                background: i === sizeIdx ? 'linear-gradient(180deg, #4d7dff 0%, #2950e6 100%)' : 'rgba(255,255,255,0.05)',
                color: '#fff',
                border: i === sizeIdx ? '1px solid rgba(255,255,255,0.24)' : '1px solid rgba(255,255,255,0.10)',
                boxShadow: i === sizeIdx ? '0 8px 24px rgba(41,80,230,0.35)' : 'none',
                transition: 'all .18s var(--ease-out)',
              }}>
                {s.label}
              </button>
            ))}
          </div>
          <p style={{ textAlign: 'center', margin: '16px 0 0', fontSize: 14, color: 'rgba(247,248,250,0.66)' }}>
            <strong style={{ color: '#fff' }}>{plan.name}</strong> &mdash; {plan.members}
            {!isEnterprise && <> &mdash; ${plan.price}/month</>}
          </p>
        </div>

        {/* Step 2 — addons */}
        <div style={{ marginBottom: 40 }}>
          <p className="caption" style={{ color: 'rgba(247,248,250,0.55)', textAlign: 'center', marginBottom: 16 }}>
            Step 2 &mdash; Make it yours
          </p>
          <div className="configurator-addon-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 12 }}>
            {ADDONS.map(a => {
              const on = !!selected[a.key];
              return (
                <button key={a.key} onClick={() => toggle(a.key)} style={{
                  textAlign: 'left', cursor: 'pointer', padding: 18, borderRadius: 16,
                  background: on ? 'rgba(77,212,255,0.10)' : 'rgba(255,255,255,0.03)',
                  border: on ? '1px solid rgba(77,212,255,0.55)' : '1px solid rgba(255,255,255,0.08)',
                  boxShadow: on ? '0 0 24px rgba(77,212,255,0.18)' : 'none',
                  transition: 'all .16s var(--ease-out)', display: 'flex', flexDirection: 'column', gap: 8,
                }}>
                  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
                    <window.QBIcon name={a.icon} size={16} stroke={1.8} />
                    <span style={{
                      width: 18, height: 18, borderRadius: 5, display: 'grid', placeItems: 'center',
                      background: on ? '#4dd4ff' : 'rgba(255,255,255,0.10)',
                      border: on ? 'none' : '1px solid rgba(255,255,255,0.20)', color: '#06080f',
                    }}>
                      {on && <window.QBIcon name="check" size={11} stroke={3} />}
                    </span>
                  </div>
                  <p style={{ margin: 0, fontSize: 13, fontWeight: 700, color: '#fff' }}>{a.name}</p>
                  <p style={{ margin: 0, fontSize: 12, color: 'rgba(247,248,250,0.55)' }}>+${a.price}/mo</p>
                </button>
              );
            })}
          </div>
        </div>

        {/* Step 3 — total */}
        <div ref={totalRef} style={{
          borderRadius: 24, padding: 32, background: 'rgba(255,255,255,0.04)',
          border: '1px solid rgba(255,255,255,0.10)', textAlign: 'center',
        }}>
          <p className="caption" style={{ color: 'rgba(247,248,250,0.55)', margin: 0 }}>Your QubikOS</p>
          {isEnterprise ? (
            <p className="display" style={{ margin: '10px 0 0', fontSize: 36, color: '#fff' }}>Custom</p>
          ) : (
            <p className="display" style={{ margin: '10px 0 0', fontSize: 48, color: '#fff' }}>
              ${Math.round(animatedTotal).toLocaleString('en-US')}
              <span style={{ fontSize: 16, color: 'rgba(247,248,250,0.55)', fontWeight: 500 }}> /month</span>
            </p>
          )}
          <p style={{ margin: '10px 0 24px', fontSize: 13, color: 'rgba(247,248,250,0.55)' }}>
            {isEnterprise ? 'Let’s find the right fit for your organization.' : '30 days free'}
          </p>
          <window.QBButton size="lg" variant="primary" style={{ minWidth: 260 }}>
            {isEnterprise ? 'Let’s Talk' : 'Start 30-Day Free Trial'}
          </window.QBButton>
        </div>

        <p style={{ textAlign: 'center', margin: '32px 0 0', fontSize: 13, color: 'rgba(247,248,250,0.40)' }}>
          Whatever comes up. We handle it.
        </p>
      </div>

      <div className="configurator-sticky-bar" style={{
        display: 'flex', position: 'fixed', left: 0, right: 0, bottom: 0, zIndex: 50,
        padding: '14px 20px', alignItems: 'center', justifyContent: 'space-between', gap: 14,
        background: 'rgba(6,8,15,0.92)', backdropFilter: 'blur(16px)',
        borderTop: '1px solid rgba(255,255,255,0.10)',
        opacity: stickyBarVisible ? 1 : 0,
        transform: stickyBarVisible ? 'translateY(0)' : 'translateY(100%)',
        pointerEvents: stickyBarVisible ? 'auto' : 'none',
        transition: 'opacity .25s var(--ease-out), transform .25s var(--ease-out)',
      }}>
        <div>
          <p style={{ margin: 0, fontSize: 10.5, letterSpacing: '0.06em', textTransform: 'uppercase', color: 'rgba(247,248,250,0.50)' }}>Your QubikOS</p>
          <p style={{ margin: '2px 0 0', fontSize: 20, fontWeight: 700, color: '#fff' }}>
            {isEnterprise ? 'Custom' : `$${Math.round(animatedTotal).toLocaleString('en-US')}/mo`}
          </p>
        </div>
        <window.QBButton size="md" variant="primary">
          {isEnterprise ? 'Let’s Talk' : 'Start Free'}
        </window.QBButton>
      </div>

      <style>{`
        @media (max-width: 700px) {
          .configurator-addon-grid { grid-template-columns: 1fr 1fr !important; }
        }
      `}</style>
    </section>
  );
}

// ---------------------------------------------------------------- root

function Pricing() {
  return (
    <>
      <PricingHeroAndPlans />
      <FeatureExplorer />
      <WebsiteBooking />
      <PremiumCapabilities />
      <PaymentsYourWay />
      <Configurator />
    </>
  );
}

window.QBPricing = Pricing;
