---
title: "Inline Wizard · UI SDK — StyleX Blocks"
description: "Single-column accordion-style inline wizard for custom domain and TLS provisioning, featuring compact summary rows with inline Edit/Re-run actions, downstream stale invalidation, a self-running nested DNS preflight check stepper with mismatch simulation and retry recovery, and live cutover activation."
url: "https://stylexblocks.com/block/ui-sdk/form-wizard-inline/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Inline Wizard block

Single-column accordion-style inline wizard for custom domain and TLS provisioning, featuring compact summary rows with inline Edit/Re-run actions, downstream stale invalidation, a self-running nested DNS preflight check stepper with mismatch simulation and retry recovery, and live cutover activation.

- Behavior engine: UI SDK
- Category: [Onboarding](https://stylexblocks.com/blocks/onboarding.md)
- Built with: [Alert](https://stylexblocks.com/components/ui-sdk/alert.md), [Badge](https://stylexblocks.com/components/ui-sdk/badge.md), [Button](https://stylexblocks.com/components/ui-sdk/button.md), [Card](https://stylexblocks.com/components/ui-sdk/card.md), [Center](https://stylexblocks.com/components/ui-sdk/center.md), [Code](https://stylexblocks.com/components/ui-sdk/code.md), [Data List](https://stylexblocks.com/components/ui-sdk/data-list.md), [Field](https://stylexblocks.com/components/ui-sdk/field.md), [Grid](https://stylexblocks.com/components/ui-sdk/grid.md), [Heading](https://stylexblocks.com/components/ui-sdk/heading.md), [Icon](https://stylexblocks.com/components/ui-sdk/icon.md), [Input](https://stylexblocks.com/components/ui-sdk/input.md), [Progress](https://stylexblocks.com/components/ui-sdk/progress.md), [Radio Card](https://stylexblocks.com/components/ui-sdk/radio-card.md), [Segment Group](https://stylexblocks.com/components/ui-sdk/segment-group.md), [Select](https://stylexblocks.com/components/ui-sdk/select.md), [Separator](https://stylexblocks.com/components/ui-sdk/separator.md), [Spinner](https://stylexblocks.com/components/ui-sdk/spinner.md), [Stack](https://stylexblocks.com/components/ui-sdk/stack.md), [Status](https://stylexblocks.com/components/ui-sdk/status.md), [Switch](https://stylexblocks.com/components/ui-sdk/switch.md), [Text](https://stylexblocks.com/components/ui-sdk/text.md), [Toast](https://stylexblocks.com/components/ui-sdk/toast.md), [Visually Hidden](https://stylexblocks.com/components/ui-sdk/visually-hidden.md)
- HTML page: https://stylexblocks.com/block/ui-sdk/form-wizard-inline/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add form-wizard-inline
```

Equivalent: `npx shadcn add @stylexblocks/form-wizard-inline`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/form-wizard-inline.json

## Usage

```tsx
import { FormWizardInline } from "#components/blocks/ui-sdk/form-wizard-inline.tsx";

export function Example() {
  return (
    <div style={{ minHeight: "100dvh" }}>
      <FormWizardInline />
    </div>
  );
}
```

## Source

`components/blocks/ui-sdk/form-wizard-inline.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
import { Alert } from "#components/ui/ui-sdk/alert.tsx";
import { Badge } from "#components/ui/ui-sdk/badge.tsx";
import { Button } from "#components/ui/ui-sdk/button.tsx";
import { Card } from "#components/ui/ui-sdk/card.tsx";
import { Circle } from "#components/ui/ui-sdk/center.tsx";
import { Code } from "#components/ui/ui-sdk/code.tsx";
import { DataList } from "#components/ui/ui-sdk/data-list.tsx";
import { Field } from "#components/ui/ui-sdk/field.tsx";
import { Grid } from "#components/ui/ui-sdk/grid.tsx";
import { Heading } from "#components/ui/ui-sdk/heading.tsx";
import { Icon } from "#components/ui/ui-sdk/icon.tsx";
import { Input } from "#components/ui/ui-sdk/input.tsx";
import { Progress } from "#components/ui/ui-sdk/progress.tsx";
import { RadioCard } from "#components/ui/ui-sdk/radio-card.tsx";
import { SegmentGroup } from "#components/ui/ui-sdk/segment-group.tsx";
import { Select } from "#components/ui/ui-sdk/select.tsx";
import { Separator } from "#components/ui/ui-sdk/separator.tsx";
import { Spinner } from "#components/ui/ui-sdk/spinner.tsx";
import { HStack, VStack } from "#components/ui/ui-sdk/stack.tsx";
import { Status } from "#components/ui/ui-sdk/status.tsx";
import { Switch } from "#components/ui/ui-sdk/switch.tsx";
import { Text } from "#components/ui/ui-sdk/text.tsx";
import { Toast, Toaster } from "#components/ui/ui-sdk/toast.tsx";
import { VisuallyHidden } from "#components/ui/ui-sdk/visually-hidden.tsx";
import { semanticColors } from "@stylexblocks/ui/semantic-tokens/colors.stylex.ts";
import { semanticRadii } from "@stylexblocks/ui/semantic-tokens/radii.stylex.ts";
import {
  accentPalette,
  amberPalette,
  grayPalette,
  greenPalette,
  redPalette,
} from "@stylexblocks/ui/themes/palettes.ts";
import { durations } from "@stylexblocks/ui/tokens/durations.stylex.ts";
import { fontSizes } from "@stylexblocks/ui/tokens/font-sizes.stylex.ts";
import { fontWeights } from "@stylexblocks/ui/tokens/font-weights.stylex.ts";
import { fonts } from "@stylexblocks/ui/tokens/fonts.stylex.ts";
import { radii } from "@stylexblocks/ui/tokens/radii.stylex.ts";
import { spacing } from "@stylexblocks/ui/tokens/spacing.stylex.ts";
import type { StyleOverrideProps } from "#lib/recipe-props.ts";

// ── Inline SVG icons (zero external icon packages) ───────────────────────────

function CheckIcon() {
  return (
    <Icon
      size="xs"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="2.1"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d="m3.5 8.5 3 3 6-6.5" />
    </Icon>
  );
}

function AlertCircleIcon() {
  return (
    <Icon
      size="sm"
      viewBox="0 0 20 20"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.65"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <circle cx="10" cy="10" r="7.25" />
      <path d="M10 6.75v3.75" />
      <path d="M10 13.5v.1" />
    </Icon>
  );
}

function AlertCircleXsIcon() {
  return (
    <Icon
      size="xs"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.8"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <circle cx="8" cy="8" r="6" />
      <path d="M8 5.25v3" />
      <path d="M8 10.75v.1" />
    </Icon>
  );
}

function AlertTriangleXsIcon() {
  return (
    <Icon
      size="xs"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.7"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d="M7.13 2.95 1.85 12.1a1 1 0 0 0 .87 1.5h10.56a1 1 0 0 0 .87-1.5L8.87 2.95a1 1 0 0 0-1.74 0Z" />
      <path d="M8 6.25v2.75" />
      <path d="M8 11.25v.1" />
    </Icon>
  );
}

function CheckCircleIcon() {
  return (
    <Icon
      size="sm"
      viewBox="0 0 20 20"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.65"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <circle cx="10" cy="10" r="7.25" />
      <path d="m7 10.2 2 2 4-4.4" />
    </Icon>
  );
}

function RefreshIcon() {
  return (
    <Icon
      size="xs"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.7"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d="M13 8a5 5 0 1 1-1.35-3.42" />
      <path d="M13 2.75v2.5h-2.5" />
    </Icon>
  );
}

function GlobeIcon() {
  return (
    <Icon
      size="xs"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.6"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <circle cx="8" cy="8" r="6" />
      <path d="M2.25 8h11.5" />
      <path d="M8 2a9.2 9.2 0 0 1 2.35 6A9.2 9.2 0 0 1 8 14a9.2 9.2 0 0 1-2.35-6A9.2 9.2 0 0 1 8 2Z" />
    </Icon>
  );
}

function LockIcon() {
  return (
    <Icon
      size="xs"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.6"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <rect x="3.25" y="7.25" width="9.5" height="6.25" rx="1.5" />
      <path d="M5.5 7.25V5.5a2.5 2.5 0 0 1 5 0v1.75" />
    </Icon>
  );
}

function ArrowRightIcon() {
  return (
    <Icon
      size="xs"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.75"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d="M3.5 8h9" />
      <path d="M8.75 4.25 12.5 8l-3.75 3.75" />
    </Icon>
  );
}

function ArrowLeftIcon() {
  return (
    <Icon
      size="xs"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.75"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d="M12.5 8h-9" />
      <path d="M7.25 4.25 3.5 8l3.75 3.75" />
    </Icon>
  );
}

// ── Types & domain data ──────────────────────────────────────────────────────

export type ZoneRecordType = "subdomain" | "apex";
export type RoutingProfileId =
  | "global-anycast"
  | "regional-eu"
  | "regional-us"
  | "origin-shield";
export type TlsMinVersion = "tls-1.2" | "tls-1.3";
export type WafPresetId = "standard" | "strict" | "monitor";

export interface FormWizardInlineValues {
  domain: string;
  zoneType: ZoneRecordType;
  routingProfile: RoutingProfileId;
  tlsMinVersion: TlsMinVersion;
  hstsPreload: boolean;
  wafPreset: WafPresetId;
}

export interface FormWizardInlineActivationPayload {
  certificateId: string;
  edgeTarget: string;
  activatedAt: string;
  values: FormWizardInlineValues;
}

export interface FormWizardInlineProps extends StyleOverrideProps {
  /** Primary heading displayed at the top of the wizard column. */
  title?: string;
  /** Supporting subtitle beneath the main heading. */
  subtitle?: string;
  /** Optional initial values overriding the default Meridian Edge domain preset. */
  initialValues?: Partial<FormWizardInlineValues>;
  /** Start with the simulated DNS mismatch switch enabled to test failure recovery. */
  defaultSimulateDnsMismatch?: boolean;
  /** Called when the user confirms activation on the final cutover step. */
  onActivate?: (payload: FormWizardInlineActivationPayload) => void;
}

interface StepDefinition {
  id: "domain" | "preflight" | "policy" | "cutover";
  label: string;
  kind: "human" | "auto";
}

interface PreflightSnapshot {
  domain: string;
  zoneType: ZoneRecordType;
  routingProfile: RoutingProfileId;
}

type PreflightStatus = "idle" | "running" | "passed" | "failed";

interface PreflightState {
  status: PreflightStatus;
  completedChecks: number;
  runId: number;
  certificateId: string | null;
  elapsedMs: number;
}

interface PreflightCheckSpec {
  id: string;
  label: string;
  runningDetail: string;
  passedDetail: string;
  failedDetail: string;
  durationMs: number;
}

const STEPS: readonly StepDefinition[] = [
  { id: "domain", label: "Domain & zone", kind: "human" },
  { id: "preflight", label: "DNS & ownership preflight", kind: "auto" },
  { id: "policy", label: "Traffic & security policy", kind: "human" },
  { id: "cutover", label: "Activate & cutover", kind: "human" },
];

const ROUTING_PROFILES: ReadonlyArray<{
  value: RoutingProfileId;
  label: string;
  shortLabel: string;
  popSummary: string;
  cnameTarget: string;
  anycastIp: string;
}> = [
  {
    value: "global-anycast",
    label: "Global Anycast (310+ edge PoPs)",
    shortLabel: "Global Anycast",
    popSummary: "310+ edge PoPs",
    cnameTarget: "edge.meridian-dns.net",
    anycastIp: "198.51.100.42",
  },
  {
    value: "regional-eu",
    label: "EU Sovereign Edge (Frankfurt & Dublin)",
    shortLabel: "EU Sovereign Edge",
    popSummary: "42 EU-only PoPs",
    cnameTarget: "eu.meridian-dns.net",
    anycastIp: "198.51.100.78",
  },
  {
    value: "regional-us",
    label: "US Low-Latency Tier (NA + LatAm)",
    shortLabel: "US Low-Latency",
    popSummary: "96 Americas PoPs",
    cnameTarget: "us.meridian-dns.net",
    anycastIp: "198.51.100.64",
  },
  {
    value: "origin-shield",
    label: "Origin Shield + Tiered Cache",
    shortLabel: "Origin Shield",
    popSummary: "Tiered shield + 310 PoPs",
    cnameTarget: "shield.meridian-dns.net",
    anycastIp: "198.51.100.91",
  },
];

const WAF_PRESETS: ReadonlyArray<{
  id: WafPresetId;
  label: string;
  tag: string;
  description: string;
  recommended?: boolean;
}> = [
  {
    id: "standard",
    label: "Standard Managed",
    tag: "OWASP Core + Bot mitigation",
    description:
      "Blocks common SQLi, XSS, and credential stuffing with minimal false positives.",
    recommended: true,
  },
  {
    id: "strict",
    label: "Strict API Shield",
    tag: "Zero-trust + Rate limiting",
    description:
      "Enforces schema checks, strict TLS fingerprints, and aggressive bot challenges.",
  },
  {
    id: "monitor",
    label: "Observe Only",
    tag: "Telemetry without blocking",
    description:
      "Logs matched signatures to Meridian Edge streams while migrating legacy clients.",
  },
];

const DEFAULT_VALUES: FormWizardInlineValues = {
  domain: "app.northstar.dev",
  zoneType: "subdomain",
  routingProfile: "global-anycast",
  tlsMinVersion: "tls-1.3",
  hstsPreload: true,
  wafPreset: "standard",
};

const DOMAIN_PATTERN =
  /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;

// One sub-check per tick (~700ms clears a full Spinner rotation cleanly), then a
// short beat on the final check before handing off to the next step.
const CHECK_TICK_MS = 680;
const SETTLE_HANDOFF_MS = 620;

const INITIAL_PREFLIGHT: PreflightState = {
  status: "idle",
  completedChecks: 0,
  runId: 0,
  certificateId: null,
  elapsedMs: 0,
};

// ── Helpers ───────────────────────────────────────────────────────────────────

function normalizeDomain(raw: string): string {
  return raw
    .trim()
    .toLowerCase()
    .replace(/^https?:\/\//, "")
    .replace(/\/.*$/, "")
    .replace(/\.$/, "");
}

function getApexDomain(domain: string): string {
  const parts = domain.split(".").filter(Boolean);
  if (parts.length <= 2) return domain || "northstar.dev";
  return parts.slice(-2).join(".");
}

function buildCertificateId(domain: string, routingProfile: RoutingProfileId): string {
  const seed = `${domain}:${routingProfile}`;
  let hash = 0;
  for (let i = 0; i < seed.length; i += 1) {
    hash = (hash * 33 + seed.charCodeAt(i)) % 1679616;
  }
  const suffix = hash.toString(36).padStart(4, "0").slice(-4);
  return `cert_mrd_${suffix}`;
}

function snapshotsEqual(
  a: PreflightSnapshot | null,
  b: PreflightSnapshot,
): boolean {
  if (!a) return false;
  return (
    a.domain === b.domain &&
    a.zoneType === b.zoneType &&
    a.routingProfile === b.routingProfile
  );
}

// ── Container Queries ────────────────────────────────────────────────────────

const COMPACT = "@container form-wizard-inline (max-width: 600px)";
const NARROW = "@container form-wizard-inline (max-width: 460px)";

// ── Styles (StyleX longhand properties + named @container queries) ───────────

const styles = stylex.create({
  root: {
    backgroundColor: semanticColors.bg,
    color: semanticColors.fg,
    containerName: "form-wizard-inline",
    containerType: "inline-size",
    fontFamily: fonts.body,
    minHeight: "100%",
    width: "100%",
  },
  column: {
    marginInline: "auto",
    maxWidth: "46rem",
    paddingBlock: {
      default: spacing._8,
      [COMPACT]: spacing._5,
    },
    paddingInline: {
      default: spacing._6,
      [COMPACT]: spacing._4,
    },
    width: "100%",
  },
  pageTitle: {
    marginBlock: 0,
  },
  fullWidth: {
    width: "100%",
  },
  flexGrow: {
    flexGrow: 1,
  },
  flexShrinkZero: {
    flexShrink: 0,
  },
  breakWord: {
    wordBreak: "break-word",
  },
  listReset: {
    listStyleType: "none",
    marginBlock: 0,
    marginInline: 0,
    paddingBlock: 0,
    paddingInline: 0,
    width: "100%",
  },
  // Vertical accordion stepper rail
  stepItem: {
    columnGap: {
      default: spacing._3_5,
      [NARROW]: spacing._2_5,
    },
    display: "grid",
    gridTemplateColumns: "1.75rem minmax(0, 1fr)",
    position: "relative",
  },
  railColumn: {
    paddingTop: spacing._0_5,
  },
  indicator: {
    borderStyle: "solid",
    borderWidth: "1.5px",
    fontSize: fontSizes.xs,
    fontVariantNumeric: "tabular-nums",
    fontWeight: fontWeights.semibold,
    height: "1.75rem",
    lineHeight: 1,
    transitionProperty: "background-color, border-color, color",
    transitionDuration: durations.fast,
    width: "1.75rem",
  },
  indicatorUpcoming: {
    backgroundColor: semanticColors.bg,
    borderColor: semanticColors.border,
    color: semanticColors.fgSubtle,
  },
  indicatorActive: {
    backgroundColor: semanticColors.accentSubtle,
    borderColor: semanticColors.accentSolid,
    color: semanticColors.accentFg,
  },
  indicatorPassed: {
    backgroundColor: semanticColors.greenSolid,
    borderColor: semanticColors.greenSolid,
    color: semanticColors.greenContrast,
  },
  indicatorFailed: {
    backgroundColor: semanticColors.redSubtle,
    borderColor: semanticColors.redSolid,
    color: semanticColors.redFg,
  },
  indicatorStale: {
    backgroundColor: semanticColors.amberSubtle,
    borderColor: semanticColors.amberBorder,
    color: semanticColors.amberFg,
  },
  railConnector: {
    backgroundColor: semanticColors.border,
    borderRadius: radii.full,
    flexGrow: 1,
    marginBlock: spacing._1_5,
    minHeight: spacing._4,
    transitionProperty: "background-color",
    transitionDuration: durations.moderate,
    width: "2px",
  },
  railConnectorPassed: {
    backgroundColor: semanticColors.greenSolid,
  },
  railConnectorFailed: {
    backgroundColor: semanticColors.redBorder,
  },
  railConnectorStale: {
    backgroundColor: semanticColors.amberBorder,
  },
  stepMain: {
    paddingBottom: spacing._5,
  },
  stepMainLast: {
    paddingBottom: 0,
  },
  stepRow: {
    alignItems: {
      default: "center",
      [COMPACT]: "flex-start",
    },
    columnGap: spacing._3,
    display: "flex",
    flexDirection: {
      default: "row",
      [COMPACT]: "column",
    },
    justifyContent: "space-between",
    minHeight: "2rem",
    rowGap: spacing._1_5,
    width: "100%",
  },
  stepMetaRight: {
    alignItems: "center",
    display: "flex",
    flexGrow: 1,
    gap: spacing._2_5,
    justifyContent: {
      default: "flex-end",
      [COMPACT]: "space-between",
    },
    minWidth: 0,
    width: {
      default: "auto",
      [COMPACT]: "100%",
    },
  },
  stepSummary: {
    color: semanticColors.fgMuted,
    minWidth: 0,
    textAlign: {
      default: "end",
      [COMPACT]: "start",
    },
  },
  stepSummaryStale: {
    color: semanticColors.amberFg,
  },
  lockedHint: {
    color: semanticColors.fgSubtle,
    whiteSpace: "nowrap",
  },
  // Expanded inline step body
  stepBody: {
    paddingTop: spacing._3_5,
    width: "100%",
  },
  fieldRowGrid: {
    gridTemplateColumns: {
      default: "repeat(2, minmax(0, 1fr))",
      [COMPACT]: "minmax(0, 1fr)",
    },
    width: "100%",
  },
  dnsPreviewCard: {
    backgroundColor: semanticColors.bgSubtle,
    borderColor: semanticColors.border,
    borderRadius: semanticRadii.panel,
    borderStyle: "solid",
    borderWidth: "1px",
    paddingBlock: spacing._3_5,
    paddingInline: spacing._4,
  },
  switchRow: {
    alignItems: "center",
    display: "flex",
    gap: spacing._3,
    justifyContent: "space-between",
    width: "100%",
  },
  actionRow: {
    paddingTop: spacing._1,
  },
  // Nested preflight check stepper inside Step 2
  preflightCardBody: {
    display: "flex",
    flexDirection: "column",
    gap: spacing._4,
    paddingBlock: spacing._4,
    paddingInline: spacing._4,
  },
  mismatchToggleRoot: {
    alignItems: "center",
    display: "inline-flex",
    gap: spacing._2,
  },
  checkItem: {
    columnGap: spacing._2_5,
    display: "grid",
    gridTemplateColumns: "1.25rem minmax(0, 1fr)",
  },
  checkNode: {
    height: "1.25rem",
    width: "1.25rem",
  },
  checkNodeQueued: {
    backgroundColor: semanticColors.bgMuted,
    color: semanticColors.fgSubtle,
  },
  checkNodeRunning: {
    color: semanticColors.accentFg,
  },
  checkNodePassed: {
    backgroundColor: semanticColors.greenSubtle,
    color: semanticColors.greenFg,
  },
  checkNodeFailed: {
    backgroundColor: semanticColors.redSubtle,
    color: semanticColors.redFg,
  },
  checkDot: {
    backgroundColor: semanticColors.borderEmphasized,
    borderRadius: radii.full,
    height: "0.375rem",
    width: "0.375rem",
  },
  checkConnector: {
    backgroundColor: semanticColors.borderSubtle,
    flexGrow: 1,
    marginBlock: spacing._1,
    minHeight: spacing._3,
    width: "1.5px",
  },
  checkConnectorPassed: {
    backgroundColor: semanticColors.greenBorder,
  },
  checkContentCol: {
    paddingBottom: spacing._3,
  },
  checkContentColLast: {
    paddingBottom: 0,
  },
  alertActions: {
    marginTop: spacing._2_5,
  },
  // Step 3 — WAF RadioCard grid
  wafGrid: {
    display: "grid",
    gap: spacing._3,
    gridTemplateColumns: {
      default: "repeat(3, minmax(0, 1fr))",
      [COMPACT]: "minmax(0, 1fr)",
    },
    width: "100%",
  },
  wafCardItem: {
    height: "100%",
  },
  wafCardControl: {
    alignItems: "flex-start",
    height: "100%",
    width: "100%",
  },
  wafCardContent: {
    gap: spacing._1_5,
    height: "100%",
    width: "100%",
  },
  // Step 4 — Review DataList & completion card
  summaryCard: {
    backgroundColor: semanticColors.bgSubtle,
  },
  summaryCardBody: {
    paddingBlock: spacing._4,
    paddingInline: spacing._4,
  },
  dataListItem: {
    alignItems: {
      default: "baseline",
      [COMPACT]: "flex-start",
    },
    display: "flex",
    flexDirection: {
      default: "row",
      [COMPACT]: "column",
    },
    gap: {
      default: spacing._4,
      [COMPACT]: spacing._0_5,
    },
  },
  dataListLabel: {
    flexShrink: 0,
    minWidth: {
      default: "10.5rem",
      [COMPACT]: 0,
    },
  },
});

// ── Component ─────────────────────────────────────────────────────────────────

/**
 * FormWizardInline — single-column accordion-style inline wizard for Meridian
 * Edge custom domain & TLS provisioning. Every step stays stacked in one rail:
 * completed steps collapse to a compact summary row with an inline Edit/Re-run
 * action, editing an upstream domain marks downstream verification stale, an
 * automated preflight step expands into a nested check-by-check stepper with
 * failure simulation and retry recovery, and upcoming locked steps remain
 * cleanly collapsed until unlocked.
 */
export function FormWizardInline({
  title = "Connect custom domain",
  subtitle = "Configure routing, verify DNS ownership automatically, and cut over TLS traffic in one column.",
  initialValues,
  defaultSimulateDnsMismatch = false,
  onActivate,
  palette,
  style,
}: FormWizardInlineProps) {
  const mergedInitial = useMemo<FormWizardInlineValues>(
    () => ({
      ...DEFAULT_VALUES,
      ...initialValues,
    }),
    [initialValues],
  );

  const queue = useMemo(() => Toast.createToaster(), []);
  const zoneLabelId = useId();
  const tlsLabelId = useId();
  const wafLabelId = useId();
  const domainInputRef = useRef<HTMLInputElement>(null);

  // Wizard flow state (`activeStep === STEPS.length` means domain is activated)
  const [activeStep, setActiveStep] = useState(0);
  const [policyConfigured, setPolicyConfigured] = useState(false);
  const [domainAttempted, setDomainAttempted] = useState(false);

  // Step 1 — Domain & zone
  const [domain, setDomain] = useState(mergedInitial.domain);
  const [zoneType, setZoneType] = useState<ZoneRecordType>(
    mergedInitial.zoneType,
  );
  const [routingProfile, setRoutingProfile] = useState<RoutingProfileId>(
    mergedInitial.routingProfile,
  );

  // Step 2 — Automated DNS & ownership preflight
  const [simulateDnsMismatch, setSimulateDnsMismatch] = useState(
    defaultSimulateDnsMismatch,
  );
  const [preflight, setPreflight] = useState<PreflightState>(INITIAL_PREFLIGHT);
  const [verifiedSnapshot, setVerifiedSnapshot] =
    useState<PreflightSnapshot | null>(null);

  // Step 3 — Traffic & security policy
  const [tlsMinVersion, setTlsMinVersion] = useState<TlsMinVersion>(
    mergedInitial.tlsMinVersion,
  );
  const [hstsPreload, setHstsPreload] = useState(mergedInitial.hstsPreload);
  const [wafPreset, setWafPreset] = useState<WafPresetId>(
    mergedInitial.wafPreset,
  );

  // Step 4 — Activation record
  const [activatedAt, setActivatedAt] = useState<string | null>(null);

  const normalizedDomain = useMemo(() => normalizeDomain(domain), [domain]);
  const apexDomain = useMemo(
    () => getApexDomain(normalizedDomain),
    [normalizedDomain],
  );
  const selectedRouting = useMemo(
    () =>
      ROUTING_PROFILES.find((item) => item.value === routingProfile) ??
      ROUTING_PROFILES[0],
    [routingProfile],
  );
  const selectedWaf = useMemo(
    () => WAF_PRESETS.find((item) => item.id === wafPreset) ?? WAF_PRESETS[0],
    [wafPreset],
  );

  const currentSnapshot = useMemo<PreflightSnapshot>(
    () => ({
      domain: normalizedDomain,
      zoneType,
      routingProfile,
    }),
    [normalizedDomain, zoneType, routingProfile],
  );

  const isActivated = activeStep >= STEPS.length;
  const isPreflightStale =
    verifiedSnapshot !== null &&
    !snapshotsEqual(verifiedSnapshot, currentSnapshot);

  const edgeTarget =
    zoneType === "subdomain"
      ? selectedRouting.cnameTarget
      : selectedRouting.anycastIp;
  const recordTypeLabel = zoneType === "subdomain" ? "CNAME" : "ALIAS / A";
  const computedCertId = useMemo(
    () => buildCertificateId(normalizedDomain || "app.northstar.dev", routingProfile),
    [normalizedDomain, routingProfile],
  );

  // Step 1 validation
  const domainError = useMemo<string | null>(() => {
    if (!normalizedDomain) {
      return "Enter a custom hostname to attach to Meridian Edge.";
    }
    if (!DOMAIN_PATTERN.test(normalizedDomain)) {
      return "Enter a valid domain name using letters, numbers, hyphens, and dots (e.g. app.northstar.dev).";
    }
    const labelCount = normalizedDomain.split(".").length;
    if (zoneType === "subdomain" && labelCount < 3) {
      return "Subdomain mode expects a host prefix like app.northstar.dev, or switch to Apex / Root.";
    }
    if (zoneType === "apex" && labelCount > 2) {
      return "Apex mode targets a root zone like northstar.dev, or switch to Subdomain (CNAME).";
    }
    return null;
  }, [normalizedDomain, zoneType]);

  // Nested preflight check definitions (memoized so timer effects remain stable)
  const preflightChecks = useMemo<readonly PreflightCheckSpec[]>(() => {
    const targetDomain = normalizedDomain || "app.northstar.dev";
    return [
      {
        id: "dns-record",
        label:
          zoneType === "subdomain"
            ? "CNAME target lookup"
            : "ALIAS / A record lookup",
        runningDetail: `Querying authoritative nameservers for ${targetDomain}…`,
        passedDetail: `${targetDomain} → ${edgeTarget} (${recordTypeLabel} · TTL 300s)`,
        failedDetail:
          zoneType === "subdomain"
            ? `Observed CNAME legacy-lb.${apexDomain} — expected ${edgeTarget}`
            : `Observed A 203.0.113.19 — expected ${edgeTarget}`,
        durationMs: 185,
      },
      {
        id: "caa-auth",
        label: "CAA record authorization",
        runningDetail: `Checking CAA issuance records on ${apexDomain}…`,
        passedDetail: `0 issue "meridian-ca.net" authorized for ${apexDomain}`,
        failedDetail: `CAA record on ${apexDomain} blocks Meridian CA issuance`,
        durationMs: 140,
      },
      {
        id: "tls-alpn",
        label: "TLS-ALPN-01 challenge",
        runningDetail: `Validating ACME edge challenge across ${selectedRouting.popSummary}…`,
        passedDetail: `ACME token verified across ${selectedRouting.popSummary} in 142ms`,
        failedDetail: "Challenge handshake timed out at edge PoP",
        durationMs: 210,
      },
      {
        id: "edge-cert",
        label: "Edge certificate issuance",
        runningDetail: `Signing ECDSA P-256 certificate and pinning to ${selectedRouting.shortLabel}…`,
        passedDetail: `Issued ${computedCertId} (ECDSA P-256 · 90-day auto-renew)`,
        failedDetail: "Certificate signing halted before edge distribution",
        durationMs: 195,
      },
    ];
  }, [
    normalizedDomain,
    zoneType,
    edgeTarget,
    recordTypeLabel,
    apexDomain,
    selectedRouting.popSummary,
    selectedRouting.shortLabel,
    computedCertId,
  ]);

  const startPreflightRun = useCallback(() => {
    setVerifiedSnapshot(null);
    setPreflight((prev) => ({
      status: "running",
      completedChecks: 0,
      runId: prev.runId + 1,
      certificateId: null,
      elapsedMs: 0,
    }));
  }, []);

  // Self-running nested check stepper effect
  useEffect(() => {
    if (activeStep !== 1 || preflight.status !== "running") {
      return undefined;
    }

    if (preflight.completedChecks >= preflightChecks.length) {
      const settleTimer = setTimeout(() => {
        setPreflight((prev) => ({
          ...prev,
          status: "passed",
          certificateId: computedCertId,
        }));
        setVerifiedSnapshot(currentSnapshot);
        setActiveStep(2);
      }, SETTLE_HANDOFF_MS);
      return () => clearTimeout(settleTimer);
    }

    const currentCheck = preflightChecks[preflight.completedChecks];
    const shouldFailHere =
      preflight.completedChecks === 0 && simulateDnsMismatch;

    const tickTimer = setTimeout(() => {
      if (shouldFailHere) {
        setPreflight((prev) => ({
          ...prev,
          status: "failed",
        }));
      } else {
        setPreflight((prev) => ({
          ...prev,
          completedChecks: prev.completedChecks + 1,
          elapsedMs: prev.elapsedMs + (currentCheck?.durationMs ?? 160),
        }));
      }
    }, CHECK_TICK_MS);

    return () => clearTimeout(tickTimer);
  }, [
    activeStep,
    preflight.status,
    preflight.completedChecks,
    preflight.runId,
    preflightChecks,
    simulateDnsMismatch,
    computedCertId,
    currentSnapshot,
  ]);

  // Smartly adjust subdomain/apex prefix when toggling zone type so demo users
  // can switch cleanly without fighting a stale prefix.
  const handleZoneTypeChange = (nextZone: string) => {
    if (nextZone !== "subdomain" && nextZone !== "apex") return;
    setZoneType(nextZone);
    const cleaned = normalizeDomain(domain);
    const parts = cleaned.split(".").filter(Boolean);
    if (nextZone === "apex" && parts.length >= 3) {
      setDomain(parts.slice(-2).join("."));
    } else if (nextZone === "subdomain" && parts.length === 2) {
      setDomain(`app.${cleaned}`);
    }
  };

  const handleContinueFromDomain = () => {
    setDomainAttempted(true);
    if (domainError) {
      domainInputRef.current?.focus();
      return;
    }

    const needsFreshPreflight =
      preflight.status !== "passed" || isPreflightStale;

    if (needsFreshPreflight) {
      setActiveStep(1);
      startPreflightRun();
    } else {
      setActiveStep(policyConfigured ? 3 : 2);
    }
  };

  const handleToggleMismatchInPreflight = (checked: boolean) => {
    setSimulateDnsMismatch(checked);
    if (activeStep === 1 && checked) {
      startPreflightRun();
    }
  };

  const handleRerunChecks = () => {
    setActiveStep(1);
    startPreflightRun();
  };

  const handleResolveAndRerun = () => {
    setSimulateDnsMismatch(false);
    setActiveStep(1);
    startPreflightRun();
  };

  const handleContinueFromPolicy = () => {
    setPolicyConfigured(true);
    setActiveStep(3);
  };

  const handleEditStep = (index: number) => {
    if (isActivated) return;
    if (activeStep === 1 && preflight.status === "running" && index !== 1) {
      setPreflight(INITIAL_PREFLIGHT);
    }
    if (index === 1) {
      setActiveStep(1);
      startPreflightRun();
      return;
    }
    setActiveStep(index);
  };

  const handleActivateDomain = () => {
    const certId = preflight.certificateId ?? computedCertId;
    const timestamp = new Date().toLocaleTimeString([], {
      hour: "2-digit",
      minute: "2-digit",
    });

    setActivatedAt(timestamp);
    setActiveStep(STEPS.length);

    onActivate?.({
      certificateId: certId,
      edgeTarget,
      activatedAt: timestamp,
      values: {
        domain: normalizedDomain,
        zoneType,
        routingProfile,
        tlsMinVersion,
        hstsPreload,
        wafPreset,
      },
    });

    queue.success("Custom domain activated", {
      description: `${normalizedDomain} is now serving ${
        tlsMinVersion === "tls-1.3" ? "TLS 1.3" : "TLS 1.2+"
      } across ${selectedRouting.popSummary}.`,
    });
  };

  const handleResetWizard = () => {
    setActiveStep(0);
    setPolicyConfigured(false);
    setDomainAttempted(false);
    setDomain(mergedInitial.domain);
    setZoneType(mergedInitial.zoneType);
    setRoutingProfile(mergedInitial.routingProfile);
    setSimulateDnsMismatch(defaultSimulateDnsMismatch);
    setPreflight(INITIAL_PREFLIGHT);
    setVerifiedSnapshot(null);
    setTlsMinVersion(mergedInitial.tlsMinVersion);
    setHstsPreload(mergedInitial.hstsPreload);
    setWafPreset(mergedInitial.wafPreset);
    setActivatedAt(null);
  };

  // Determine the visual state of each step row
  const getStepPhase = (
    index: number,
  ): "active" | "running" | "passed" | "failed" | "stale" | "upcoming" => {
    if (isActivated) return "passed";

    if (index === activeStep) {
      if (index === 1) {
        if (preflight.status === "failed") return "failed";
        if (preflight.status === "running") return "running";
      }
      return "active";
    }

    if (index === 0) {
      return activeStep > 0 ? "passed" : "upcoming";
    }

    if (index === 1) {
      if (isPreflightStale) return "stale";
      if (preflight.status === "passed") return "passed";
      if (preflight.status === "failed") return "failed";
      return "upcoming";
    }

    if (index === 2) {
      if (policyConfigured && isPreflightStale) return "stale";
      if (policyConfigured && preflight.status === "passed") return "passed";
      return "upcoming";
    }

    return "upcoming";
  };

  // Compact single-line summary for collapsed steps (always reports real values)
  const getStepSummary = (index: number): string | null => {
    const phase = getStepPhase(index);
    if (phase === "active" || phase === "running" || phase === "upcoming") {
      return null;
    }

    switch (index) {
      case 0:
        return `${normalizedDomain || "—"} · ${
          zoneType === "subdomain" ? "Subdomain" : "Apex"
        } · ${selectedRouting.shortLabel}`;
      case 1:
        if (phase === "stale") {
          return "Domain changed · needs DNS re-verification";
        }
        if (phase === "failed") {
          return `Halted at ${preflightChecks[0].label}`;
        }
        return `${preflightChecks.length} checks passed · ${
          preflight.certificateId ?? computedCertId
        }`;
      case 2:
        if (phase === "stale") {
          return `${
            tlsMinVersion === "tls-1.3" ? "TLS 1.3" : "TLS 1.2+"
          } · ${selectedWaf.label} · awaiting preflight`;
        }
        return `${tlsMinVersion === "tls-1.3" ? "TLS 1.3 only" : "TLS 1.2+"} · ${
          hstsPreload ? "HSTS preload" : "Standard HSTS"
        } · ${selectedWaf.label}`;
      case 3:
        return `Active · Serving ${
          tlsMinVersion === "tls-1.3" ? "TLS 1.3" : "TLS 1.2+"
        } on ${selectedRouting.shortLabel}`;
      default:
        return null;
    }
  };

  const canJumpToStep = (index: number): boolean => {
    if (isActivated || index === activeStep) return false;
    const phase = getStepPhase(index);
    if (index === 0) return phase === "passed";
    if (index === 1) return phase === "passed" || phase === "failed";
    if (index === 2) return phase === "passed";
    return false;
  };

  const progressPercent = Math.round(
    (preflight.completedChecks / preflightChecks.length) * 100,
  );

  // Live announcement for screen readers on discrete auto-step transitions
  const liveAnnouncement = useMemo(() => {
    if (isActivated) {
      return `${normalizedDomain} is now active on Meridian Edge.`;
    }
    if (activeStep === 1) {
      if (preflight.status === "failed") {
        return `DNS and ownership preflight halted at ${preflightChecks[0].label}.`;
      }
      if (preflight.status === "running") {
        const current = preflightChecks[preflight.completedChecks];
        return current
          ? `Running preflight check ${preflight.completedChecks + 1} of ${preflightChecks.length}: ${current.label}.`
          : "All preflight checks passed. Advancing to Traffic and security policy.";
      }
    }
    return "";
  }, [
    isActivated,
    normalizedDomain,
    activeStep,
    preflight.status,
    preflight.completedChecks,
    preflightChecks,
  ]);

  const headerStatusBadge = isActivated
    ? { label: "Active on edge", palette: greenPalette }
    : preflight.status === "failed" && activeStep === 1
      ? { label: "Preflight halted", palette: redPalette }
      : isPreflightStale
        ? { label: "Re-verification required", palette: amberPalette }
        : {
            label: `Step ${Math.min(activeStep + 1, STEPS.length)} of ${STEPS.length}`,
            palette: accentPalette,
          };

  return (
    <VStack gap="0" palette={palette} style={[styles.root, style]}>
      <VStack gap="6" style={styles.column}>
        {/* Header */}
        <VStack render={<header />} gap="2">
          <HStack justify="between" wrap="wrap" gap="2.5">
            <HStack wrap="wrap" gap="2.5">
              <Heading render={<h1 />} size="2xl" style={styles.pageTitle}>
                {isActivated ? "Custom domain live" : title}
              </Heading>
              <Badge variant="outline" size="sm" palette={grayPalette}>
                Meridian Edge
              </Badge>
            </HStack>
            <Badge
              variant="subtle"
              size="sm"
              palette={headerStatusBadge.palette}
            >
              {headerStatusBadge.label}
            </Badge>
          </HStack>
          <Text variant="muted" size="sm">
            {subtitle}
          </Text>
        </VStack>

        {/* Polite live region for automated preflight hand-offs */}
        <VisuallyHidden render={<div aria-live="polite" />}>
          {liveAnnouncement}
        </VisuallyHidden>

        {/* Single-column vertical accordion stepper */}
        <main>
          <VStack
            render={
              <ol aria-label="Custom domain and TLS provisioning steps" />
            }
            gap="0"
            style={styles.listReset}
          >
            {STEPS.map((stepDef, index) => {
              const phase = getStepPhase(index);
              const summary = getStepSummary(index);
              const isExpanded = !isActivated && activeStep === index;
              const isLast = index === STEPS.length - 1;
              const isClickable = canJumpToStep(index);

              return (
                <li
                  key={stepDef.id}
                  aria-current={isExpanded ? "step" : undefined}
                  {...stylex.props(styles.stepItem)}
                >
                  {/* Left vertical rail: circular indicator + vertical connector */}
                  <VStack align="center" gap="0" style={styles.railColumn}>
                    <Circle
                      render={<span aria-hidden="true" />}
                      style={[
                        styles.indicator,
                        phase === "upcoming" && styles.indicatorUpcoming,
                        (phase === "active" || phase === "running") &&
                          styles.indicatorActive,
                        phase === "passed" && styles.indicatorPassed,
                        phase === "failed" && styles.indicatorFailed,
                        phase === "stale" && styles.indicatorStale,
                      ]}
                    >
                      {phase === "running" ? (
                        <Spinner size="xs" />
                      ) : phase === "passed" ? (
                        <CheckIcon />
                      ) : phase === "failed" ? (
                        <AlertCircleXsIcon />
                      ) : phase === "stale" ? (
                        <AlertTriangleXsIcon />
                      ) : (
                        index + 1
                      )}
                    </Circle>
                    {!isLast ? (
                      <span
                        aria-hidden="true"
                        {...stylex.props(
                          styles.railConnector,
                          phase === "passed" && styles.railConnectorPassed,
                          phase === "failed" && styles.railConnectorFailed,
                          phase === "stale" && styles.railConnectorStale,
                        )}
                      />
                    ) : null}
                  </VStack>

                  {/* Right column: single-line header row + optional expanded body */}
                  <VStack
                    gap="0"
                    style={[styles.stepMain, isLast && styles.stepMainLast]}
                  >
                    <div {...stylex.props(styles.stepRow)}>
                      <HStack
                        wrap="wrap"
                        gap="2"
                        style={styles.flexShrinkZero}
                      >
                        <Text
                          render={<span />}
                          size="sm"
                          weight={phase === "upcoming" ? "medium" : "semibold"}
                          tone={phase === "upcoming" ? "muted" : "default"}
                        >
                          {stepDef.label}
                        </Text>
                        {phase === "running" ? (
                          <Badge
                            variant="subtle"
                            size="xs"
                            palette={accentPalette}
                          >
                            Verifying…
                          </Badge>
                        ) : null}
                        {phase === "failed" ? (
                          <Badge variant="subtle" size="xs" palette={redPalette}>
                            Halted
                          </Badge>
                        ) : null}
                        {phase === "stale" ? (
                          <Badge
                            variant="subtle"
                            size="xs"
                            palette={amberPalette}
                          >
                            Stale
                          </Badge>
                        ) : null}
                      </HStack>

                      {/* Collapsed step summary + Edit/Re-run OR locked hint */}
                      {!isExpanded ? (
                        <div {...stylex.props(styles.stepMetaRight)}>
                          {summary ? (
                            <Text
                              render={<span title={summary} />}
                              size="xs"
                              truncate="true"
                              style={[
                                styles.stepSummary,
                                phase === "stale" && styles.stepSummaryStale,
                              ]}
                            >
                              {summary}
                            </Text>
                          ) : (
                            <HStack
                              render={<span />}
                              gap="1"
                              style={styles.lockedHint}
                            >
                              <LockIcon />
                              <Text render={<span />} size="xs" tone="subtle">
                                {index === 1
                                  ? "Runs after domain setup"
                                  : index === 2
                                    ? "Unlocks after preflight"
                                    : "Final review"}
                              </Text>
                            </HStack>
                          )}

                          {isClickable ? (
                            <Button
                              variant="ghost"
                              size="xs"
                              palette={accentPalette}
                              aria-label={`${
                                stepDef.kind === "auto" ? "Re-run" : "Edit"
                              } ${stepDef.label}`}
                              onClick={() => handleEditStep(index)}
                            >
                              {stepDef.kind === "auto" ? "Re-run" : "Edit"}
                            </Button>
                          ) : null}
                        </div>
                      ) : null}
                    </div>

                    {/* ── Step 1: Domain & zone ── */}
                    {isExpanded && index === 0 ? (
                      <VStack gap="4" style={styles.stepBody}>
                        <Text variant="muted" size="sm">
                          Choose the hostname and edge routing tier. Meridian
                          Edge will verify DNS ownership and issue a managed
                          certificate in the next step.
                        </Text>

                        <Grid columns="2" gap="4" style={styles.fieldRowGrid}>
                          <Field.Root
                            required
                            invalid={Boolean(domainAttempted && domainError)}
                          >
                            <Field.Label>
                              Domain name
                              <Field.RequiredIndicator />
                            </Field.Label>
                            <Input
                              ref={domainInputRef}
                              value={domain}
                              onValueChange={(nextValue) => {
                                setDomain(nextValue);
                                if (domainAttempted) {
                                  setDomainAttempted(true);
                                }
                              }}
                              placeholder={
                                zoneType === "subdomain"
                                  ? "app.northstar.dev"
                                  : "northstar.dev"
                              }
                              autoCapitalize="none"
                              autoCorrect="off"
                              spellCheck={false}
                              aria-invalid={
                                domainAttempted && domainError
                                  ? true
                                  : undefined
                              }
                            />
                            {domainAttempted && domainError ? (
                              <Field.Error match={true}>
                                {domainError}
                              </Field.Error>
                            ) : (
                              <Field.Description>
                                Fully qualified hostname without protocol or
                                path.
                              </Field.Description>
                            )}
                          </Field.Root>

                          <Select.Root
                            items={ROUTING_PROFILES}
                            value={routingProfile}
                            onValueChange={(next) => {
                              if (
                                next === "global-anycast" ||
                                next === "regional-eu" ||
                                next === "regional-us" ||
                                next === "origin-shield"
                              ) {
                                setRoutingProfile(next);
                              }
                            }}
                            placeholder="Select routing profile"
                            palette={accentPalette}
                          >
                            <Select.Label>Routing profile</Select.Label>
                            <Select.Control>
                              <Select.Trigger>
                                <Select.Value />
                              </Select.Trigger>
                              <Select.IndicatorGroup>
                                <Select.Icon />
                              </Select.IndicatorGroup>
                            </Select.Control>
                            <Select.Content>
                              {ROUTING_PROFILES.map((option) => (
                                <Select.Item
                                  key={option.value}
                                  value={option.value}
                                >
                                  <Select.ItemText>
                                    {option.label}
                                  </Select.ItemText>
                                  <Select.ItemIndicator />
                                </Select.Item>
                              ))}
                            </Select.Content>
                          </Select.Root>
                        </Grid>

                        <Field.Root>
                          <Field.Label id={zoneLabelId}>
                            Zone record type
                          </Field.Label>
                          <HStack
                            align="start"
                            wrap="wrap"
                            gap="0"
                            style={styles.fullWidth}
                          >
                            <SegmentGroup.Root
                              value={zoneType}
                              onValueChange={handleZoneTypeChange}
                              size="sm"
                              aria-labelledby={zoneLabelId}
                            >
                              <SegmentGroup.Item value="subdomain">
                                Subdomain (CNAME)
                              </SegmentGroup.Item>
                              <SegmentGroup.Item value="apex">
                                Apex / Root (ALIAS)
                              </SegmentGroup.Item>
                            </SegmentGroup.Root>
                          </HStack>
                        </Field.Root>

                        {/* Target DNS record preview + preflight simulation toggle */}
                        <VStack gap="3" style={styles.dnsPreviewCard}>
                          <HStack justify="between" wrap="wrap" gap="2">
                            <Text
                              render={<span />}
                              size="xs"
                              tone="muted"
                              weight="medium"
                            >
                              Required DNS target
                            </Text>
                            <Badge
                              variant="subtle"
                              size="xs"
                              palette={grayPalette}
                            >
                              {selectedRouting.popSummary}
                            </Badge>
                          </HStack>
                          <HStack wrap="wrap" gap="2">
                            <Badge
                              variant="outline"
                              size="xs"
                              palette={accentPalette}
                            >
                              {recordTypeLabel}
                            </Badge>
                            <Code variant="subtle" size="xs">
                              {normalizedDomain || "app.northstar.dev"}
                            </Code>
                            <Text
                              render={<span aria-hidden="true" />}
                              size="xs"
                              tone="subtle"
                            >
                              →
                            </Text>
                            <Code variant="outline" size="xs">
                              {edgeTarget}
                            </Code>
                          </HStack>

                          <Separator decorative />

                          <Switch.Root
                            variant="solid"
                            size="sm"
                            palette={amberPalette}
                            style={styles.switchRow}
                          >
                            <VStack
                              render={<span />}
                              gap="0.5"
                              style={styles.flexGrow}
                            >
                              <Text
                                render={<span />}
                                size="xs"
                                tone="muted"
                                weight="medium"
                              >
                                Simulate DNS mismatch in preflight
                              </Text>
                              <Text render={<span />} size="xs" tone="muted">
                                Preview how a misconfigured record halts the
                                automated check chain and lets you retry.
                              </Text>
                            </VStack>
                            <Switch.Control
                              checked={simulateDnsMismatch}
                              onCheckedChange={setSimulateDnsMismatch}
                            />
                          </Switch.Root>
                        </VStack>

                        <HStack wrap="wrap" gap="2.5" style={styles.actionRow}>
                          <Button
                            variant="solid"
                            size="sm"
                            palette={accentPalette}
                            onClick={handleContinueFromDomain}
                          >
                            {isPreflightStale
                              ? "Save & re-run preflight"
                              : preflight.status === "passed"
                                ? "Continue"
                                : "Run DNS preflight"}
                            <ArrowRightIcon />
                          </Button>
                        </HStack>
                      </VStack>
                    ) : null}

                    {/* ── Step 2: Automated DNS & ownership preflight ── */}
                    {isExpanded && index === 1 ? (
                      <VStack gap="4" style={styles.stepBody}>
                        <Card.Root variant="outline" size="md">
                          <Card.Body style={styles.preflightCardBody}>
                            <HStack justify="between" wrap="wrap" gap="3">
                              <VStack gap="0.5">
                                <HStack wrap="wrap" gap="2">
                                  <Text
                                    render={<span />}
                                    variant="mono"
                                    size="xs"
                                    weight="semibold"
                                  >
                                    {normalizedDomain}
                                  </Text>
                                  <Text
                                    render={<span />}
                                    size="xs"
                                    tone="muted"
                                    tabular="true"
                                  >
                                    {preflight.status === "failed"
                                      ? `Halted at check ${preflight.completedChecks + 1} of ${preflightChecks.length}`
                                      : `${preflight.completedChecks} of ${preflightChecks.length} checks complete`}
                                  </Text>
                                </HStack>
                              </VStack>

                              <HStack wrap="wrap" gap="3">
                                <Switch.Root
                                  variant="solid"
                                  size="sm"
                                  palette={amberPalette}
                                  style={styles.mismatchToggleRoot}
                                >
                                  <Switch.Control
                                    checked={simulateDnsMismatch}
                                    onCheckedChange={
                                      handleToggleMismatchInPreflight
                                    }
                                  />
                                  <Switch.Label>
                                    Simulate DNS mismatch
                                  </Switch.Label>
                                </Switch.Root>

                                <Button
                                  variant="surface"
                                  size="xs"
                                  disabled={preflight.status === "running"}
                                  onClick={handleRerunChecks}
                                >
                                  <RefreshIcon />
                                  Re-run checks
                                </Button>
                              </HStack>
                            </HStack>

                            <Progress.Root
                              value={progressPercent}
                              min={0}
                              max={100}
                              size="xs"
                              shape="full"
                              variant="subtle"
                              palette={
                                preflight.status === "failed"
                                  ? redPalette
                                  : preflight.completedChecks >=
                                      preflightChecks.length
                                    ? greenPalette
                                    : accentPalette
                              }
                            >
                              <Progress.Track>
                                <Progress.Range
                                  striped={preflight.status === "running"}
                                  animated={preflight.status === "running"}
                                />
                              </Progress.Track>
                            </Progress.Root>

                            {/* Nested check-by-check vertical stepper */}
                            <VStack
                              render={
                                <ol aria-label="DNS preflight verification checks" />
                              }
                              gap="0"
                              style={styles.listReset}
                            >
                              {preflightChecks.map((check, checkIndex) => {
                                const isPast =
                                  checkIndex < preflight.completedChecks;
                                const isCurrent =
                                  checkIndex === preflight.completedChecks;
                                const isFailedCheck =
                                  isCurrent && preflight.status === "failed";
                                const isRunningCheck =
                                  isCurrent && preflight.status === "running";
                                const isLastCheck =
                                  checkIndex === preflightChecks.length - 1;

                                const checkStatus = isPast
                                  ? { label: "Passed", palette: greenPalette }
                                  : isFailedCheck
                                    ? { label: "Failed", palette: redPalette }
                                    : isRunningCheck
                                      ? {
                                          label: "Checking",
                                          palette: accentPalette,
                                        }
                                      : {
                                          label:
                                            preflight.status === "failed"
                                              ? "Blocked"
                                              : "Queued",
                                          palette: grayPalette,
                                        };

                                const detailText = isPast
                                  ? check.passedDetail
                                  : isFailedCheck
                                    ? check.failedDetail
                                    : isRunningCheck
                                      ? check.runningDetail
                                      : "Waiting for upstream check to pass";

                                return (
                                  <li
                                    key={check.id}
                                    {...stylex.props(styles.checkItem)}
                                  >
                                    <VStack
                                      align="center"
                                      gap="0"
                                      style={styles.railColumn}
                                    >
                                      <Circle
                                        render={<span aria-hidden="true" />}
                                        style={[
                                          styles.checkNode,
                                          isPast && styles.checkNodePassed,
                                          isFailedCheck &&
                                            styles.checkNodeFailed,
                                          isRunningCheck &&
                                            styles.checkNodeRunning,
                                          !isPast &&
                                            !isFailedCheck &&
                                            !isRunningCheck &&
                                            styles.checkNodeQueued,
                                        ]}
                                      >
                                        {isPast ? (
                                          <CheckIcon />
                                        ) : isFailedCheck ? (
                                          <AlertCircleXsIcon />
                                        ) : isRunningCheck ? (
                                          <Spinner size="xs" />
                                        ) : (
                                          <span
                                            {...stylex.props(styles.checkDot)}
                                          />
                                        )}
                                      </Circle>
                                      {!isLastCheck ? (
                                        <span
                                          aria-hidden="true"
                                          {...stylex.props(
                                            styles.checkConnector,
                                            isPast &&
                                              styles.checkConnectorPassed,
                                          )}
                                        />
                                      ) : null}
                                    </VStack>

                                    <VStack
                                      gap="0.5"
                                      style={[
                                        styles.checkContentCol,
                                        isLastCheck &&
                                          styles.checkContentColLast,
                                      ]}
                                    >
                                      <HStack
                                        justify="between"
                                        wrap="wrap"
                                        gap="2"
                                      >
                                        <Text
                                          render={<span />}
                                          size="sm"
                                          weight={
                                            !isPast &&
                                            !isRunningCheck &&
                                            !isFailedCheck
                                              ? "normal"
                                              : "medium"
                                          }
                                          tone={
                                            !isPast &&
                                            !isRunningCheck &&
                                            !isFailedCheck
                                              ? "muted"
                                              : "default"
                                          }
                                        >
                                          {check.label}
                                        </Text>
                                        <Status.Root
                                          size="sm"
                                          palette={checkStatus.palette}
                                        >
                                          <Status.Indicator />
                                          {checkStatus.label}
                                        </Status.Root>
                                      </HStack>
                                      <Text
                                        render={<span />}
                                        variant="mono"
                                        size="xs"
                                        tone={isFailedCheck ? "error" : "muted"}
                                        style={styles.breakWord}
                                      >
                                        {detailText}
                                      </Text>
                                    </VStack>
                                  </li>
                                );
                              })}
                            </VStack>

                            {/* Failure diagnosis & recovery actions */}
                            {preflight.status === "failed" ? (
                              <Alert.Root
                                status="error"
                                variant="subtle"
                                size="sm"
                                palette={redPalette}
                              >
                                <Alert.Indicator>
                                  <AlertCircleIcon />
                                </Alert.Indicator>
                                <Alert.Content>
                                  <Alert.Title>
                                    DNS target mismatch for {normalizedDomain}
                                  </Alert.Title>
                                  <Alert.Description>
                                    Authoritative DNS returned a legacy target
                                    instead of {edgeTarget}. Update the{" "}
                                    {recordTypeLabel} record (or turn off the
                                    simulated mismatch) and re-run preflight to
                                    continue certificate issuance.
                                  </Alert.Description>
                                  <HStack
                                    wrap="wrap"
                                    gap="2"
                                    style={styles.alertActions}
                                  >
                                    {simulateDnsMismatch ? (
                                      <Button
                                        variant="solid"
                                        size="xs"
                                        palette={accentPalette}
                                        onClick={handleResolveAndRerun}
                                      >
                                        <RefreshIcon />
                                        Fix DNS &amp; re-run checks
                                      </Button>
                                    ) : (
                                      <Button
                                        variant="solid"
                                        size="xs"
                                        palette={accentPalette}
                                        onClick={handleRerunChecks}
                                      >
                                        <RefreshIcon />
                                        Re-run checks
                                      </Button>
                                    )}
                                    <Button
                                      variant="ghost"
                                      size="xs"
                                      onClick={() => setActiveStep(0)}
                                    >
                                      <ArrowLeftIcon />
                                      Edit domain &amp; zone
                                    </Button>
                                  </HStack>
                                </Alert.Content>
                              </Alert.Root>
                            ) : null}
                          </Card.Body>
                        </Card.Root>
                      </VStack>
                    ) : null}

                    {/* ── Step 3: Traffic & security policy ── */}
                    {isExpanded && index === 2 ? (
                      <VStack gap="4" style={styles.stepBody}>
                        <Text variant="muted" size="sm">
                          Set edge transport encryption and managed WAF rules
                          applied before traffic reaches your origin.
                        </Text>

                        <Field.Root>
                          <Field.Label id={tlsLabelId}>
                            Minimum TLS version
                          </Field.Label>
                          <HStack
                            align="start"
                            wrap="wrap"
                            gap="0"
                            style={styles.fullWidth}
                          >
                            <SegmentGroup.Root
                              value={tlsMinVersion}
                              onValueChange={(next) => {
                                if (next === "tls-1.2" || next === "tls-1.3") {
                                  setTlsMinVersion(next);
                                }
                              }}
                              size="sm"
                              aria-labelledby={tlsLabelId}
                            >
                              <SegmentGroup.Item value="tls-1.2">
                                TLS 1.2+
                              </SegmentGroup.Item>
                              <SegmentGroup.Item value="tls-1.3">
                                TLS 1.3 only
                              </SegmentGroup.Item>
                            </SegmentGroup.Root>
                          </HStack>
                          <Field.Description>
                            TLS 1.3 eliminates legacy cipher negotiation and
                            cuts handshake latency by one round-trip.
                          </Field.Description>
                        </Field.Root>

                        <Switch.Root
                          variant="solid"
                          size="md"
                          palette={accentPalette}
                          style={styles.switchRow}
                        >
                          <VStack
                            render={<span />}
                            gap="0.5"
                            style={styles.flexGrow}
                          >
                            <Text render={<span />} size="sm" weight="medium">
                              Enable HSTS with preload
                            </Text>
                            <Text render={<span />} size="xs" tone="muted">
                              Sends Strict-Transport-Security (max-age=31536000;
                              includeSubDomains; preload) on all HTTPS
                              responses.
                            </Text>
                          </VStack>
                          <Switch.Control
                            checked={hstsPreload}
                            onCheckedChange={setHstsPreload}
                          />
                        </Switch.Root>

                        <Separator decorative />

                        <Field.Root>
                          <Field.Label id={wafLabelId}>
                            WAF rule preset
                          </Field.Label>
                          <RadioCard.Root
                            value={wafPreset}
                            onValueChange={(next) => {
                              if (
                                next === "standard" ||
                                next === "strict" ||
                                next === "monitor"
                              ) {
                                setWafPreset(next);
                              }
                            }}
                            variant="outline"
                            size="sm"
                            palette={accentPalette}
                            aria-labelledby={wafLabelId}
                            style={styles.wafGrid}
                          >
                            {WAF_PRESETS.map((preset) => (
                              <RadioCard.Item
                                key={preset.id}
                                value={preset.id}
                                style={styles.wafCardItem}
                              >
                                <RadioCard.ItemControl
                                  style={styles.wafCardControl}
                                >
                                  <RadioCard.ItemContent
                                    style={styles.wafCardContent}
                                  >
                                    <HStack
                                      justify="between"
                                      gap="2"
                                      style={styles.fullWidth}
                                    >
                                      <HStack wrap="wrap" gap="1.5">
                                        <RadioCard.ItemText>
                                          {preset.label}
                                        </RadioCard.ItemText>
                                        {preset.recommended ? (
                                          <Badge
                                            variant="subtle"
                                            size="xs"
                                            palette={greenPalette}
                                          >
                                            Recommended
                                          </Badge>
                                        ) : null}
                                      </HStack>
                                      <RadioCard.ItemIndicator />
                                    </HStack>
                                    <Text
                                      render={<span />}
                                      size="xs"
                                      tone="subtle"
                                      weight="medium"
                                    >
                                      {preset.tag}
                                    </Text>
                                    <RadioCard.ItemDescription>
                                      {preset.description}
                                    </RadioCard.ItemDescription>
                                  </RadioCard.ItemContent>
                                </RadioCard.ItemControl>
                              </RadioCard.Item>
                            ))}
                          </RadioCard.Root>
                        </Field.Root>

                        <HStack wrap="wrap" gap="2.5" style={styles.actionRow}>
                          <Button
                            variant="solid"
                            size="sm"
                            palette={accentPalette}
                            onClick={handleContinueFromPolicy}
                          >
                            Review cutover
                            <ArrowRightIcon />
                          </Button>
                          <Button
                            variant="ghost"
                            size="sm"
                            onClick={() => setActiveStep(0)}
                          >
                            <ArrowLeftIcon />
                            Back to domain
                          </Button>
                        </HStack>
                      </VStack>
                    ) : null}

                    {/* ── Step 4: Activate & cutover ── */}
                    {isExpanded && index === 3 ? (
                      <VStack gap="4" style={styles.stepBody}>
                        <Text variant="muted" size="sm">
                          Verify the complete edge configuration below. Cutting
                          over binds the issued TLS certificate and begins
                          routing live requests immediately.
                        </Text>

                        <Card.Root
                          variant="outline"
                          size="md"
                          style={styles.summaryCard}
                        >
                          <Card.Body style={styles.summaryCardBody}>
                            <DataList.Root
                              orientation="horizontal"
                              variant="subtle"
                              size="sm"
                            >
                              <DataList.Item style={styles.dataListItem}>
                                <DataList.ItemLabel style={styles.dataListLabel}>
                                  Hostname &amp; zone
                                </DataList.ItemLabel>
                                <DataList.ItemValue>
                                  <Text
                                    render={<span />}
                                    variant="mono"
                                    size="xs"
                                    style={styles.breakWord}
                                  >
                                    {normalizedDomain} ({recordTypeLabel} →{" "}
                                    {edgeTarget})
                                  </Text>
                                </DataList.ItemValue>
                              </DataList.Item>
                              <DataList.Item style={styles.dataListItem}>
                                <DataList.ItemLabel style={styles.dataListLabel}>
                                  Routing profile
                                </DataList.ItemLabel>
                                <DataList.ItemValue>
                                  {selectedRouting.label}
                                </DataList.ItemValue>
                              </DataList.Item>
                              <DataList.Item style={styles.dataListItem}>
                                <DataList.ItemLabel style={styles.dataListLabel}>
                                  Edge certificate
                                </DataList.ItemLabel>
                                <DataList.ItemValue>
                                  <Text
                                    render={<span />}
                                    variant="mono"
                                    size="xs"
                                    style={styles.breakWord}
                                  >
                                    {preflight.certificateId ?? computedCertId}{" "}
                                    · ECDSA P-256 (90-day auto-renew)
                                  </Text>
                                </DataList.ItemValue>
                              </DataList.Item>
                              <DataList.Item style={styles.dataListItem}>
                                <DataList.ItemLabel style={styles.dataListLabel}>
                                  TLS &amp; HSTS
                                </DataList.ItemLabel>
                                <DataList.ItemValue>
                                  {tlsMinVersion === "tls-1.3"
                                    ? "TLS 1.3 only"
                                    : "TLS 1.2+"}{" "}
                                  ·{" "}
                                  {hstsPreload
                                    ? "HSTS preload enabled"
                                    : "HSTS preload off"}
                                </DataList.ItemValue>
                              </DataList.Item>
                              <DataList.Item style={styles.dataListItem}>
                                <DataList.ItemLabel style={styles.dataListLabel}>
                                  WAF preset
                                </DataList.ItemLabel>
                                <DataList.ItemValue>
                                  {selectedWaf.label} ({selectedWaf.tag})
                                </DataList.ItemValue>
                              </DataList.Item>
                            </DataList.Root>
                          </Card.Body>
                        </Card.Root>

                        <HStack wrap="wrap" gap="2.5" style={styles.actionRow}>
                          <Button
                            variant="solid"
                            size="sm"
                            palette={accentPalette}
                            onClick={handleActivateDomain}
                          >
                            <GlobeIcon />
                            Activate domain
                          </Button>
                          <Button
                            variant="ghost"
                            size="sm"
                            onClick={() => setActiveStep(2)}
                          >
                            <ArrowLeftIcon />
                            Back to policy
                          </Button>
                        </HStack>
                      </VStack>
                    ) : null}
                  </VStack>
                </li>
              );
            })}
          </VStack>

          {/* Bottom contextual note when preflight halts the chain */}
          {!isActivated && preflight.status === "failed" && activeStep === 1 ? (
            <Text variant="muted" size="xs">
              Provisioning is paused at DNS &amp; ownership preflight. Resolve
              the mismatch above and re-run checks to unlock traffic policy and
              cutover.
            </Text>
          ) : null}

          {/* Post-activation confirmation & reset */}
          {isActivated ? (
            <VStack
              render={<section aria-label="Domain activation summary" />}
              gap="4"
              style={styles.actionRow}
            >
              <Alert.Root
                status="success"
                variant="subtle"
                size="md"
                palette={greenPalette}
              >
                <Alert.Indicator>
                  <CheckCircleIcon />
                </Alert.Indicator>
                <Alert.Content>
                  <Alert.Title>
                    {normalizedDomain} is live on Meridian Edge
                  </Alert.Title>
                  <Alert.Description>
                    Certificate {preflight.certificateId ?? computedCertId} is
                    pinned across {selectedRouting.popSummary} with{" "}
                    {selectedWaf.label} WAF active
                    {activatedAt ? ` (cutover at ${activatedAt})` : ""}.
                  </Alert.Description>
                </Alert.Content>
              </Alert.Root>

              <HStack wrap="wrap" gap="2.5" style={styles.actionRow}>
                <Button
                  variant="surface"
                  size="sm"
                  onClick={handleResetWizard}
                >
                  <RefreshIcon />
                  Provision another domain
                </Button>
              </HStack>
            </VStack>
          ) : null}
        </main>
      </VStack>

      <Toaster toaster={queue} />
    </VStack>
  );
}
```

Credit: Inspired by [Inline Wizard](https://astryx.atmeta.com/playground?template=form-wizard-inline) from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.)
