File size: 23,963 Bytes
97ee7cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
import { useState, useEffect, useCallback } from 'react';
import { motion } from 'motion/react';
import { Check, ShieldCheck, ArrowRight, Zap, Loader2 } from 'lucide-react';
import { startCheckout, subscribeCheckoutPhase, type CheckoutPhase } from '../services/checkout';
import { t, tArray } from '../i18n';

// Static fallback from build-time generation (used while fetching live prices)
import fallbackTiers from '../generated/tiers.json';
import { resolveCheckoutProduct } from './pricing-billing-mode';

interface Tier {
  name: string;
  localeKey?: string;
  description: string;
  features: string[];
  /** License/commercial-use callouts, rendered green + distinct from features. */
  highlightFeatures?: string[];
  highlighted?: boolean;
  price?: number | null;
  period?: string;
  monthlyPrice?: number;
  annualPrice?: number | null;
  cta?: string;
  href?: string;
  monthlyProductId?: string;
  annualProductId?: string;
}

const CATALOG_API = 'https://api.worldmonitor.app/api/product-catalog';

function usePricingData(): Tier[] {
  const [tiers, setTiers] = useState<Tier[]>(fallbackTiers as Tier[]);

  useEffect(() => {
    let cancelled = false;
    fetch(CATALOG_API, { signal: AbortSignal.timeout(5000) })
      .then(res => res.ok ? res.json() : null)
      .then(data => {
        if (!cancelled && data?.tiers?.length) {
          setTiers(data.tiers as Tier[]);
        }
      })
      .catch(() => { /* keep fallback */ });
    return () => { cancelled = true; };
  }, []);

  return tiers;
}

/**
 * Stable per-tier key: the generated `localeKey` when present, else the
 * lowercased display name. Used both for locale lookup and for identifying
 * the tier that renders outside the card grid.
 */
function tierKey(tier: Tier): string {
  return tier.localeKey ?? tier.name.toLowerCase();
}

/** The tier that renders as a full-width band below the self-serve columns. */
const BAND_TIER_KEY = 'enterprise';

/**
 * Look up localized copy for a catalog tier, falling back to the catalog
 * value when the locale hasn't translated this tier yet. Generated tiers
 * carry a stable localeKey so display-name changes do not affect lookup.
 */
function localizeTier(tier: Tier): {
  description: string;
  features: string[];
  highlightFeatures?: string[];
  cta?: string;
} {
  const key = tierKey(tier);
  const description = t(`pricing.tiers.${key}.description`, { defaultValue: tier.description });
  const features = tArray(`pricing.tiers.${key}.features`) ?? tier.features;
  // License callouts (e.g. "No commercial use") live on the catalog as
  // highlightFeatures; fall back to the English catalog when the locale has
  // not translated them yet β€” same pattern as features.
  const highlightFeatures =
    tArray(`pricing.tiers.${key}.highlightFeatures`) ?? tier.highlightFeatures;
  // Resolve CTA priority: locale-specific tier override β†’ catalog tier.cta β†’
  // undefined (so getCtaProps applies the generic localized fallback). The
  // SENTINEL trick lets us detect "key missing" vs "key resolves to empty".
  const SENTINEL = '__no_locale_cta__';
  const localeCta = t(`pricing.tiers.${key}.cta`, { defaultValue: SENTINEL });
  const cta = localeCta !== SENTINEL ? localeCta : tier.cta;
  return { description, features, highlightFeatures, cta };
}

function formatPrice(tier: Tier, billing: 'monthly' | 'annual'): { amount: string; suffix: string } {
  // Free tier
  if (tier.price === 0) {
    return { amount: "$0", suffix: t('pricing.suffixForever') };
  }
  // Enterprise / custom
  if (tier.price === null && tier.monthlyPrice === undefined) {
    return { amount: t('pricing.amountCustom'), suffix: t('pricing.suffixTailored') };
  }
  // API tier (monthly only)
  if (tier.annualPrice === null && tier.monthlyPrice !== undefined) {
    return { amount: `$${tier.monthlyPrice}`, suffix: t('pricing.suffixPerMonth') };
  }
  // Pro tier with toggle
  if (billing === 'annual' && tier.annualPrice != null) {
    return { amount: `$${tier.annualPrice}`, suffix: t('pricing.suffixPerYear') };
  }
  return { amount: `$${tier.monthlyPrice}`, suffix: t('pricing.suffixPerMonth') };
}

type CtaProps =
  | { type: 'link'; label: string; href: string; external: boolean }
  | { type: 'checkout'; label: string; productId: string; billedMonthlyOnly: boolean };

/**
 * Is this href pointing back at our own product surface (so a
 * same-tab navigation is the natural UX), or to something genuinely
 * off-platform (mailto, external docs) where a new tab is preferred?
 *
 * Anchors (`#pricing`) and relative paths are treated as in-product.
 * `mailto:` / `tel:` and any other-origin http(s) URLs are external.
 */
function isInProductHref(href: string): boolean {
  if (!href || href === '#' || href.startsWith('#')) return true;
  // Exclude protocol-relative URLs (//cdn.evilhost.com/x) β€” they LOOK
  // like leading-slash paths but browsers resolve them to a different
  // origin. Only true absolute paths (`/foo`, `/foo/bar`) are in-product.
  if (href.startsWith('/') && !href.startsWith('//')) return true;
  // Catch relative paths without a leading slash: `pricing`, `./dashboard`,
  // `../foo`. `new URL('pricing')` throws without a base β€” those were
  // hitting the catch branch below and being misclassified as external.
  // Resolve against the current origin to determine whether the result
  // lands on our product surface.
  const looksRelative = !/^[a-z][a-z0-9+.-]*:/i.test(href) && !href.startsWith('//');
  try {
    const base = typeof window !== 'undefined' ? window.location.href : 'https://worldmonitor.app/';
    const url = new URL(href, looksRelative ? base : undefined);
    if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
    return url.hostname === 'worldmonitor.app' ||
           url.hostname.endsWith('.worldmonitor.app') ||
           // localhost dev-server case so relative CTAs work in pro-test
           url.hostname === 'localhost' ||
           url.hostname === '127.0.0.1';
  } catch {
    return false;
  }
}

function getCtaProps(tier: Tier, billing: 'monthly' | 'annual'): CtaProps {
  if (tier.cta && tier.href && tier.price === 0) {
    // Free tier on an in-product href (e.g. worldmonitor.app dashboard)
    // should open in-place. Only send to a new tab when the href is
    // genuinely off-platform (unusual for free tier but possible).
    return {
      type: 'link',
      label: tier.cta,
      href: tier.href,
      external: !isInProductHref(tier.href),
    };
  }
  if (tier.cta && tier.href && tier.price === null) {
    // Enterprise is typically `mailto:` β†’ external remains true so the
    // OS mail client opens in its own window. Any hypothetical in-
    // product enterprise href would navigate same-tab instead.
    return {
      type: 'link',
      label: tier.cta,
      href: tier.href,
      external: !isInProductHref(tier.href),
    };
  }
  const resolved = resolveCheckoutProduct(tier, billing);
  if (resolved) {
    // Honor per-tier CTA text from the catalog (e.g. "Start Pro",
    // "Subscribe") when present; fall back to a localized generic label
    // so paid checkout buttons aren't English-only on non-English locales.
    // billedMonthlyOnly (#4946 round 4): with the page toggle on Annual, a
    // monthly-only tier (API Business) still checks out its monthly product
    // β€” the card renders an explicit "billed monthly" note so entering
    // checkout from an annual-selected state is never a silent surprise.
    return {
      type: 'checkout',
      label: tier.cta ?? t('pricing.cta.checkoutDefault'),
      productId: resolved.productId,
      billedMonthlyOnly: resolved.billedMonthlyOnly,
    };
  }
  return { type: 'link', label: t('pricing.cta.learnMore'), href: '#', external: false };
}

/**
 * The tier CTA β€” rendered identically by the card columns and the Enterprise
 * band, so the checkout spinner/disabled semantics and the external-link rel
 * policy can never drift between the two surfaces.
 */
function TierCta({ cta, highlighted, loadingProductId, rateLimited, onCheckout }: {
  cta: CtaProps;
  highlighted: boolean;
  loadingProductId: string | null;
  rateLimited: boolean;
  onCheckout: (productId: string) => void;
}) {
  if (cta.type === 'link') {
    return (
      <a
        href={cta.href}
        target={cta.external ? "_blank" : undefined}
        rel={cta.external ? "noreferrer" : undefined}
        className={`block text-center py-3 rounded-sm font-mono text-xs uppercase tracking-wider font-bold transition-colors ${
          highlighted
            ? 'bg-wm-green text-wm-bg hover:bg-green-400'
            : 'border border-wm-border text-wm-muted hover:text-wm-text hover:border-wm-text'
        }`}
      >
        {cta.label} <ArrowRight className="w-3.5 h-3.5 inline-block ml-1" aria-hidden="true" />
      </a>
    );
  }

  const isLoading = loadingProductId === cta.productId;
  const isDisabled = isLoading || rateLimited;
  // Only the clicked tier disables during creating_checkout.
  // Sibling tiers stay clickable; if the user changes their
  // mind mid-flow, their next click simply updates the
  // pending intent. The pricing page is never hard-locked.
  return (
    <button
      onClick={() => onCheckout(cta.productId)}
      disabled={isDisabled}
      aria-busy={isLoading || undefined}
      className={`block w-full text-center py-3 rounded-sm font-mono text-xs uppercase tracking-wider font-bold transition-colors ${
        isLoading ? 'cursor-wait opacity-70' : rateLimited ? 'cursor-not-allowed opacity-60' : 'cursor-pointer'
      } ${
        highlighted
          ? 'bg-wm-green text-wm-bg hover:bg-green-400'
          : 'border border-wm-border text-wm-muted hover:text-wm-text hover:border-wm-text'
      }`}
    >
      {isLoading ? (
        <>
          <Loader2 className="w-3.5 h-3.5 inline-block mr-2 animate-spin" aria-hidden="true" />
          <span>{t('pricing.opening')}</span>
        </>
      ) : (
        <>
          {cta.label} <ArrowRight className="w-3.5 h-3.5 inline-block ml-1" aria-hidden="true" />
        </>
      )}
    </button>
  );
}

export function PricingSection({ refCode }: { refCode?: string }) {
  const [billing, setBilling] = useState<'monthly' | 'annual'>(() => {
    const planKey = new URLSearchParams(window.location.search).get('wm_reactivate_plan');
    return planKey?.endsWith('_annual') ? 'annual' : 'monthly';
  });
  // Loading state is driven by the service's checkout phase. Only the
  // `creating_checkout` phase (post-auth, inside doCheckout) disables
  // the clicked CTA. During the Clerk modal window, phase stays idle β€”
  // the modal backdrop is the user's feedback, so locking the pricing
  // section underneath adds no value and creates recovery problems
  // (watchdogs, DOM polling) that we don't need.
  const [phase, setPhase] = useState<CheckoutPhase>({ kind: 'idle' });
  const loadingProductId = phase.kind === 'creating_checkout' ? phase.productId : null;
  const rateLimited = phase.kind === 'rate_limited';
  const TIERS = usePricingData();
  // Enterprise leaves the card grid and renders as a full-width band below
  // it: it is the only non-self-serve tier, and pulling it out keeps the grid
  // at exactly five columns so the Personal/Commercial axis header can span
  // 1-2 / 3-5 at xl. Partitioning by key (not index) so a catalog reorder or
  // a live payload that omits Enterprise degrades to "no band", never to a
  // mislabelled column.
  const gridTiers = TIERS.filter(tier => tierKey(tier) !== BAND_TIER_KEY);
  const bandTier = TIERS.find(tier => tierKey(tier) === BAND_TIER_KEY);

  useEffect(() => subscribeCheckoutPhase(setPhase), []);

  // checkoutInFlight in the service guards concurrent doCheckout runs.
  // The handler is fire-and-forget β€” no local loading state to manage.
  const handleCheckout = useCallback((productId: string) => {
    void startCheckout(productId, { referralCode: refCode });
  }, [refCode]);

  return (
    <section id="pricing" className="py-24 px-6 border-t border-wm-border bg-[#060606]">
      <div className="max-w-7xl mx-auto">
        {/* Header */}
        <div className="text-center mb-16">
          <motion.h2
            className="text-3xl md:text-5xl font-display font-bold mb-4"
            initial={{ opacity: 0, y: 20 }}
            whileInView={{ opacity: 1, y: 0 }}
            viewport={{ once: true }}
            transition={{ duration: 0.5 }}
          >
            {t('pricing.headerTitle')}
          </motion.h2>
          <motion.p
            className="text-wm-muted max-w-xl mx-auto mb-8"
            initial={{ opacity: 0, y: 10 }}
            whileInView={{ opacity: 1, y: 0 }}
            viewport={{ once: true }}
            transition={{ duration: 0.5, delay: 0.1 }}
          >
            {t('pricing.headerSubtitle')}
          </motion.p>

          {/* Billing toggle β€” disabled while a checkout is active.
              Switching billing mid-flight would change cta.productId
              out from under the active checkout, making the spinner
              vanish from the tier the user clicked. Locking the toggle
              during the flow is the simplest correct behavior: the
              user committed to a plan by clicking Checkout. */}
          <motion.div
            className="inline-flex items-center gap-3 bg-wm-card border border-wm-border rounded-sm p-1"
            initial={{ opacity: 0, y: 10 }}
            whileInView={{ opacity: 1, y: 0 }}
            viewport={{ once: true }}
            transition={{ duration: 0.5, delay: 0.2 }}
          >
            <button
              onClick={() => setBilling('monthly')}
              disabled={loadingProductId !== null}
              className={`px-4 py-2 rounded-sm font-mono text-xs uppercase tracking-wider transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${
                billing === 'monthly'
                  ? 'bg-wm-green text-wm-bg font-bold'
                  : 'text-wm-muted hover:text-wm-text'
              }`}
            >
              {t('pricing.billingMonthly')}
            </button>
            <button
              onClick={() => setBilling('annual')}
              disabled={loadingProductId !== null}
              className={`px-4 py-2 rounded-sm font-mono text-xs uppercase tracking-wider transition-colors flex items-center gap-2 disabled:cursor-not-allowed disabled:opacity-60 ${
                billing === 'annual'
                  ? 'bg-wm-green text-wm-bg font-bold'
                  : 'text-wm-muted hover:text-wm-text'
              }`}
            >
              {/* Lock billing toggle ONLY during creating_checkout (narrow
                  post-auth window). Through the Clerk modal the toggle
                  is covered by the backdrop anyway; locking during the
                  modal was unnecessary. */}
              {t('pricing.billingAnnual')}
              <span className={`text-[10px] px-1.5 py-0.5 rounded-sm ${
                billing === 'annual'
                  ? 'bg-wm-bg/20 text-wm-bg'
                  : 'bg-wm-green/10 text-wm-green'
              }`}>
                {t('pricing.saveAnnual')}
              </span>
            </button>
          </motion.div>
        </div>

        {/* Tier cards grid */}
        {/* 5 self-serve tiers since Pro Business was published (#5604):
            2-up on tablet, 3+2 on laptop, all five across on desktop.
            Enterprise renders below as a band, not as a sixth column. */}
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 gap-6">
          {/* Personal / Commercial axis header β€” xl only. It is a pair of grid
              children so the spans line up with the columns they label
              (Personal = Free + Pro, Commercial = the three licensed tiers).
              Below xl the grid wraps to 3+2 or 2-up, where a spanning header
              would sit above the wrong cards; there the per-card license
              chips carry the same story.
              Deliberately NOT motion elements: they start `display: none`, so
              an entrance animation gated on whileInView would depend on the
              observer re-firing when a resize past xl reveals them β€” a label
              stuck at opacity 0 is a worse failure than no animation. */}
          <div className="hidden xl:block xl:col-span-2 border-t border-wm-border pt-3">
            <p className="font-mono text-xs uppercase tracking-wider text-wm-muted">
              {t('pricing.axisPersonal')}
            </p>
            <p className="text-xs text-wm-muted/70 mt-0.5">{t('pricing.axisPersonalNote')}</p>
          </div>
          <div className="hidden xl:block xl:col-span-3 border-t border-wm-green pt-3">
            <p className="font-mono text-xs uppercase tracking-wider text-wm-green font-bold">
              {t('pricing.axisCommercial')}
            </p>
            <p className="text-xs text-wm-muted/70 mt-0.5">{t('pricing.axisCommercialNote')}</p>
          </div>

          {gridTiers.map((tier, i) => {
            const price = formatPrice(tier, billing);
            const localized = localizeTier(tier);
            // Build a localized tier shape so getCtaProps picks the right
            // CTA label per locale (link CTAs read tier.cta directly).
            const localizedTier: Tier = { ...tier, cta: localized.cta };
            const cta = getCtaProps(localizedTier, billing);

            return (
              <motion.div
                key={tier.name}
                className={`relative bg-zinc-900 rounded-lg p-6 flex flex-col ${
                  tier.highlighted
                    ? 'border-2 border-wm-green shadow-lg shadow-wm-green/10'
                    : 'border border-wm-border'
                }`}
                initial={{ opacity: 0, y: 30 }}
                whileInView={{ opacity: 1, y: 0 }}
                viewport={{ once: true }}
                transition={{ duration: 0.5, delay: i * 0.1 }}
              >
                {/* Most Popular badge */}
                {tier.highlighted && (
                  <div className="absolute -top-3 left-1/2 -translate-x-1/2 inline-flex items-center gap-1 bg-wm-green text-wm-bg px-3 py-1 rounded-full text-xs font-mono font-bold uppercase tracking-wider">
                    <Zap className="w-3 h-3" aria-hidden="true" />
                    {t('pricing.mostPopular')}
                  </div>
                )}

                {/* Tier name */}
                <h3 className={`font-display text-lg font-bold mb-1 ${
                  tier.highlighted ? 'text-wm-green' : 'text-wm-text'
                }`}>
                  {tier.name}
                </h3>

                {/* Description */}
                <p className="text-xs text-wm-muted mb-4">{localized.description}</p>

                {/* Price */}
                <div className="mb-6">
                  <span className="text-4xl font-display font-bold">{price.amount}</span>
                  <span className="text-sm text-wm-muted ml-1">{price.suffix}</span>
                  {cta.type === 'checkout' && cta.billedMonthlyOnly && (
                    <p className="mt-1 text-[11px] font-mono uppercase tracking-wider text-wm-muted">
                      {t('pricing.billedMonthlyNote', { defaultValue: 'Billed monthly β€” no annual plan' })}
                    </p>
                  )}
                </div>

                {/* Features */}
                <ul className="space-y-3 mb-8 flex-1">
                  {localized.features.map((feature, fi) => (
                    <li key={fi} className="flex items-start gap-2 text-sm">
                      <Check className={`w-4 h-4 shrink-0 mt-0.5 ${
                        tier.highlighted ? 'text-wm-green' : 'text-wm-muted'
                      }`} aria-hidden="true" />
                      <span className="text-wm-muted">{feature}</span>
                    </li>
                  ))}
                  {localized.highlightFeatures?.map((hf, hi) => (
                    <li key={`hl-${hi}`} className="flex items-start gap-2 text-sm">
                      <ShieldCheck className="w-4 h-4 shrink-0 mt-0.5 text-wm-green" aria-hidden="true" />
                      <span className="text-wm-green font-medium">{hf}</span>
                    </li>
                  ))}
                </ul>

                {/* CTA button */}
                <TierCta
                  cta={cta}
                  highlighted={!!tier.highlighted}
                  loadingProductId={loadingProductId}
                  rateLimited={rateLimited}
                  onCheckout={handleCheckout}
                />
              </motion.div>
            );
          })}
        </div>

        {/* Enterprise band β€” full width below the self-serve columns:
            identity + custom price on the left, features across the middle,
            Contact Sales on the right. Stacks to a single column below lg.
            Its stagger delay continues from the band's rendered position
            (after the grid), not from Enterprise's index in the catalog. */}
        {bandTier && (() => {
          const price = formatPrice(bandTier, billing);
          const localized = localizeTier(bandTier);
          const localizedTier: Tier = { ...bandTier, cta: localized.cta };
          const cta = getCtaProps(localizedTier, billing);

          return (
            <motion.div
              data-tier-band={BAND_TIER_KEY}
              className="mt-6 bg-zinc-900 border border-wm-border rounded-lg p-6 md:p-8 flex flex-col gap-6 lg:flex-row lg:items-center lg:gap-10"
              initial={{ opacity: 0, y: 30 }}
              whileInView={{ opacity: 1, y: 0 }}
              viewport={{ once: true }}
              transition={{ duration: 0.5, delay: gridTiers.length * 0.1 }}
            >
              {/* Identity + price */}
              <div className="lg:w-64 lg:shrink-0">
                <h3 className="font-display text-lg font-bold mb-1 text-wm-text">{bandTier.name}</h3>
                <p className="text-xs text-wm-muted mb-4">{localized.description}</p>
                <div>
                  <span className="text-4xl font-display font-bold">{price.amount}</span>
                  <span className="text-sm text-wm-muted ml-1">{price.suffix}</span>
                </div>
              </div>

              {/* Features β€” multi-column so the band stays a band */}
              <ul className="flex-1 grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-x-8 gap-y-3">
                {localized.features.map((feature, fi) => (
                  <li key={fi} className="flex items-start gap-2 text-sm">
                    <Check className="w-4 h-4 shrink-0 mt-0.5 text-wm-muted" aria-hidden="true" />
                    <span className="text-wm-muted">{feature}</span>
                  </li>
                ))}
                {localized.highlightFeatures?.map((hf, hi) => (
                  <li key={`hl-${hi}`} className="flex items-start gap-2 text-sm">
                    <ShieldCheck className="w-4 h-4 shrink-0 mt-0.5 text-wm-green" aria-hidden="true" />
                    <span className="text-wm-green font-medium">{hf}</span>
                  </li>
                ))}
              </ul>

              {/* CTA */}
              <div className="lg:w-56 lg:shrink-0">
                <TierCta
                  cta={cta}
                  highlighted={!!bandTier.highlighted}
                  loadingProductId={loadingProductId}
                  rateLimited={rateLimited}
                  onCheckout={handleCheckout}
                />
              </div>
            </motion.div>
          );
        })()}

        {/* Discount code note */}
        <p className="text-center text-xs text-wm-muted font-mono mt-8">
          {t('pricing.promoCodeNote')}
        </p>
      </div>
    </section>
  );
}