{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "security-settings",
  "type": "registry:block",
  "title": "Security Settings",
  "description": "Password, two-factor, passkeys and sessions in grouped rows: a tiny ring counts recommended steps, passkeys are added inline while your device confirms, and signed-out sessions slide off the table one after another.",
  "categories": [
    "screen",
    "Settings"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/badge.json",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/input.json",
    "https://coss.com/ui/r/label.json",
    "https://coss.com/ui/r/menu.json"
  ],
  "files": [
    {
      "path": "registry/devl/security-settings.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport {\n  ArrowLeftIcon,\n  BellIcon,\n  CheckIcon,\n  CopyIcon,\n  CreditCardIcon,\n  DownloadIcon,\n  FingerprintIcon,\n  KeyRoundIcon,\n  LaptopIcon,\n  LogOutIcon,\n  MonitorIcon,\n  MoreHorizontalIcon,\n  PaletteIcon,\n  PencilIcon,\n  PlusIcon,\n  SettingsIcon,\n  ShieldIcon,\n  SmartphoneIcon,\n  TabletIcon,\n  Trash2Icon,\n  UsbIcon,\n  UserIcon,\n  UsersIcon,\n} from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { type ReactNode, useEffect, useId, useRef, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { Input, type InputProps } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { Menu, MenuItem, MenuPopup, MenuSeparator, MenuTrigger } from \"@/components/ui/menu\";\n\nexport type SettingsSectionId =\n  | \"profile\"\n  | \"appearance\"\n  | \"notifications\"\n  | \"security\"\n  | \"general\"\n  | \"members\"\n  | \"billing\"\n  | \"developer\";\n\nexport type SecurityDeviceKind = \"laptop\" | \"desktop\" | \"phone\" | \"tablet\" | \"key\";\n\nexport interface SecurityPasskey {\n  id: string;\n  name: string;\n  kind: SecurityDeviceKind;\n  added: string;\n  lastUsed: string;\n}\n\nexport interface SecuritySession {\n  id: string;\n  browser: string;\n  os: string;\n  kind: SecurityDeviceKind;\n  location: string;\n  lastActive: string;\n  current?: boolean;\n}\n\nexport interface SecuritySettingsProps {\n  className?: string;\n  passwordChanged?: string;\n  passkeys?: SecurityPasskey[];\n  sessions?: SecuritySession[];\n  authenticatorSince?: string;\n  recoveryCodesLeft?: number;\n  recoveryCodesSaved?: boolean;\n  newPasskey?: { name: string; kind: SecurityDeviceKind; authenticator: string };\n  onNavigate?: (section: SettingsSectionId) => void;\n}\n\nconst easeOut = [0.23, 1, 0.32, 1] as const;\n\nconst navGroups: { label: string; items: { id: SettingsSectionId; label: string; icon: ReactNode }[] }[] = [\n  {\n    label: \"Account\",\n    items: [\n      { id: \"profile\", label: \"Profile\", icon: <UserIcon /> },\n      { id: \"appearance\", label: \"Appearance\", icon: <PaletteIcon /> },\n      { id: \"notifications\", label: \"Notifications\", icon: <BellIcon /> },\n      { id: \"security\", label: \"Security\", icon: <ShieldIcon /> },\n    ],\n  },\n  {\n    label: \"Workspace\",\n    items: [\n      { id: \"general\", label: \"General\", icon: <SettingsIcon /> },\n      { id: \"members\", label: \"Members & roles\", icon: <UsersIcon /> },\n      { id: \"billing\", label: \"Billing\", icon: <CreditCardIcon /> },\n    ],\n  },\n  {\n    label: \"Developer\",\n    items: [{ id: \"developer\", label: \"API keys & webhooks\", icon: <KeyRoundIcon /> }],\n  },\n];\n\nconst deviceIcons: Record<SecurityDeviceKind, ReactNode> = {\n  laptop: <LaptopIcon />,\n  desktop: <MonitorIcon />,\n  phone: <SmartphoneIcon />,\n  tablet: <TabletIcon />,\n  key: <UsbIcon />,\n};\n\nconst defaultPasskeys: SecurityPasskey[] = [\n  { id: \"pk1\", name: \"MacBook Air\", kind: \"laptop\", added: \"Mar 4, 2026\", lastUsed: \"2 hours ago\" },\n  { id: \"pk2\", name: \"Pixel 9\", kind: \"phone\", added: \"Jun 18, 2026\", lastUsed: \"Yesterday\" },\n  { id: \"pk3\", name: \"YubiKey 5C\", kind: \"key\", added: \"Aug 30, 2026\", lastUsed: \"3 weeks ago\" },\n];\n\nconst defaultSessions: SecuritySession[] = [\n  { id: \"s1\", browser: \"Chrome\", os: \"macOS\", kind: \"laptop\", location: \"Lisbon, PT\", lastActive: \"Now\", current: true },\n  { id: \"s2\", browser: \"Ridgeline\", os: \"Android\", kind: \"phone\", location: \"Lisbon, PT\", lastActive: \"18 min ago\" },\n  { id: \"s3\", browser: \"Safari\", os: \"iPadOS\", kind: \"tablet\", location: \"Porto, PT\", lastActive: \"2 days ago\" },\n  { id: \"s4\", browser: \"Firefox\", os: \"Windows\", kind: \"desktop\", location: \"Rotterdam, NL\", lastActive: \"9 days ago\" },\n];\n\nconst defaultNewPasskey = { name: \"MacBook Pro\", kind: \"laptop\" as const, authenticator: \"Touch ID\" };\n\nconst codeAlphabet = \"abcdefghjkmnpqrstuvwxyz23456789\";\n\nfunction makeCodes(seed: number, count = 10) {\n  let state = seed >>> 0;\n  const next = () => {\n    state = (state + 0x6d2b79f5) >>> 0;\n    let t = state;\n    t = Math.imul(t ^ (t >>> 15), t | 1);\n    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n  };\n  return Array.from({ length: count }, () => {\n    let code = \"\";\n    for (let i = 0; i < 8; i++) {\n      code += codeAlphabet[Math.floor(next() * codeAlphabet.length)];\n      if (i === 3) code += \"-\";\n    }\n    return code;\n  });\n}\n\nfunction useFocusOnMount<T extends HTMLElement>() {\n  const ref = useRef<T>(null);\n  useEffect(() => {\n    ref.current?.focus({ preventScroll: true });\n  }, []);\n  return ref;\n}\n\nfunction AutoFocusInput(props: InputProps) {\n  const ref = useFocusOnMount<HTMLInputElement>();\n  return <Input ref={ref} {...props} />;\n}\n\nfunction useCalmMotion() {\n  const prefers = useReducedMotion();\n  const [mounted, setMounted] = useState(false);\n  useEffect(() => setMounted(true), []);\n  return mounted && Boolean(prefers);\n}\n\nfunction RidgelineShell({\n  active,\n  onNavigate,\n  children,\n  className,\n}: {\n  active: SettingsSectionId;\n  onNavigate?: (section: SettingsSectionId) => void;\n  children: ReactNode;\n  className?: string;\n}) {\n  const pillsRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const scroller = pillsRef.current;\n    const el = scroller?.querySelector<HTMLElement>(`[data-section=\"${active}\"]`);\n    if (!scroller || !el || scroller.scrollWidth <= scroller.clientWidth) return;\n    scroller.scrollLeft = el.offsetLeft - 16;\n  }, [active]);\n\n  return (\n    <div className={cn(\"flex h-[760px] w-full bg-background text-foreground\", className)}>\n      <aside className=\"hidden w-60 shrink-0 flex-col border-r bg-muted/30 px-3 py-4 md:flex\">\n        <button\n          className=\"flex h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-muted-foreground text-sm outline-none transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n          type=\"button\"\n        >\n          <ArrowLeftIcon className=\"size-4\" />\n          Back to Ridgeline\n        </button>\n        <nav aria-label=\"Settings\" className=\"flex flex-col\">\n          {navGroups.map((group) => (\n            <div className=\"flex flex-col\" key={group.label}>\n              <span className=\"px-2 pt-5 pb-1.5 font-medium text-muted-foreground text-xs\">{group.label}</span>\n              <div className=\"flex flex-col gap-0.5\">\n                {group.items.map((item) => {\n                  const current = item.id === active;\n                  return (\n                    <button\n                      aria-current={current ? \"page\" : undefined}\n                      className={cn(\n                        \"flex h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-left text-sm outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground\",\n                        current ? \"bg-accent font-medium text-foreground\" : \"text-foreground/80 hover:bg-accent/60\",\n                      )}\n                      key={item.id}\n                      onClick={() => onNavigate?.(item.id)}\n                      type=\"button\"\n                    >\n                      {item.icon}\n                      <span className=\"truncate\">{item.label}</span>\n                    </button>\n                  );\n                })}\n              </div>\n            </div>\n          ))}\n        </nav>\n        <div className=\"mt-auto flex items-center gap-2.5 px-2 pt-4\">\n          <span className=\"flex size-7 shrink-0 items-center justify-center rounded-full bg-foreground font-medium text-[11px] text-background\">\n            AL\n          </span>\n          <span className=\"flex min-w-0 flex-col\">\n            <span className=\"truncate font-medium text-sm\">Ada Lindqvist</span>\n            <span className=\"truncate text-muted-foreground text-xs\">ada@ridgeline.app</span>\n          </span>\n        </div>\n      </aside>\n      <div className=\"flex min-w-0 flex-1 flex-col\">\n        <div className=\"md:hidden\">\n          <div className=\"flex h-12 items-center gap-2 border-b px-4\">\n            <button\n              aria-label=\"Back to Ridgeline\"\n              className=\"-ms-1.5 flex size-8 cursor-pointer items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-accent/60 focus-visible:ring-2 focus-visible:ring-ring\"\n              type=\"button\"\n            >\n              <ArrowLeftIcon className=\"size-4\" />\n            </button>\n            <span className=\"font-medium text-sm\">Settings</span>\n          </div>\n          <nav\n            aria-label=\"Settings\"\n            className=\"overflow-x-auto border-b px-4 py-2.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\"\n            ref={pillsRef}\n          >\n            <div className=\"flex w-max gap-1.5\">\n              {navGroups.flatMap((g) => g.items).map((item) => {\n                const current = item.id === active;\n                return (\n                  <button\n                    aria-current={current ? \"page\" : undefined}\n                    className={cn(\n                      \"flex h-7 cursor-pointer items-center rounded-full px-3 text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n                      current\n                        ? \"bg-foreground font-medium text-background\"\n                        : \"bg-muted text-muted-foreground hover:text-foreground\",\n                    )}\n                    data-section={item.id}\n                    key={item.id}\n                    onClick={() => onNavigate?.(item.id)}\n                    type=\"button\"\n                  >\n                    {item.label}\n                  </button>\n                );\n              })}\n            </div>\n          </nav>\n        </div>\n        <div className=\"min-h-0 flex-1 overflow-y-auto\">{children}</div>\n      </div>\n    </div>\n  );\n}\n\nfunction SectionHeader({ title, description, action }: { title: string; description: ReactNode; action?: ReactNode }) {\n  return (\n    <div className=\"flex items-center gap-4\">\n      <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n        <h2 className=\"font-medium text-sm\">{title}</h2>\n        <p className=\"text-pretty text-muted-foreground text-sm\">{description}</p>\n      </div>\n      {action && <div className=\"shrink-0\">{action}</div>}\n    </div>\n  );\n}\n\nfunction Collapse({ open, children, reduce }: { open: boolean; children: ReactNode; reduce: boolean }) {\n  return (\n    <AnimatePresence initial={false}>\n      {open && (\n        <motion.div\n          animate={{ height: \"auto\", opacity: 1 }}\n          className=\"overflow-hidden\"\n          exit={{ height: 0, opacity: 0 }}\n          initial={{ height: 0, opacity: 0 }}\n          transition={reduce ? { duration: 0 } : { duration: 0.22, ease: easeOut }}\n        >\n          {children}\n        </motion.div>\n      )}\n    </AnimatePresence>\n  );\n}\n\nfunction ConfirmStrip({\n  tone = \"destructive\",\n  title,\n  detail,\n  confirmLabel,\n  onCancel,\n  onConfirm,\n}: {\n  tone?: \"destructive\" | \"default\";\n  title: string;\n  detail: string;\n  confirmLabel: string;\n  onCancel: () => void;\n  onConfirm: () => void;\n}) {\n  const cancelRef = useFocusOnMount<HTMLButtonElement>();\n  return (\n    <div\n      className={cn(\n        \"flex flex-wrap items-center gap-x-4 gap-y-2.5 border-t px-4 py-3\",\n        tone === \"destructive\" ? \"bg-destructive/4\" : \"bg-muted/40\",\n      )}\n      role=\"alert\"\n    >\n      <p className=\"min-w-0 flex-1 basis-56 text-pretty text-sm\">\n        <span className=\"font-medium\">{title}</span> <span className=\"text-muted-foreground\">{detail}</span>\n      </p>\n      <div className=\"flex gap-2\">\n        <Button onClick={onCancel} ref={cancelRef} size=\"sm\" variant=\"ghost\">\n          Cancel\n        </Button>\n        <Button onClick={onConfirm} size=\"sm\" variant={tone === \"destructive\" ? \"destructive\" : \"default\"}>\n          {confirmLabel}\n        </Button>\n      </div>\n    </div>\n  );\n}\n\nfunction DeviceIcon({ kind, className }: { kind: SecurityDeviceKind; className?: string }) {\n  return (\n    <span\n      className={cn(\n        \"flex size-8 shrink-0 items-center justify-center rounded-lg border bg-background text-muted-foreground [&_svg]:size-4\",\n        className,\n      )}\n    >\n      {deviceIcons[kind]}\n    </span>\n  );\n}\n\nfunction ProgressRing({ steps, done, reduce }: { steps: number; done: number; reduce: boolean }) {\n  const r = 8;\n  const c = 2 * Math.PI * r;\n  const gap = 3;\n  const seg = c / steps - gap;\n  const complete = done === steps;\n  return (\n    <svg aria-hidden className=\"size-5 shrink-0 -rotate-90\" fill=\"none\" viewBox=\"0 0 20 20\">\n      {Array.from({ length: steps }, (_, i) => (\n        <motion.circle\n          animate={{ opacity: i < done ? 1 : 0.18 }}\n          className={cn(\n            \"transition-[stroke] duration-300\",\n            i < done ? (complete ? \"stroke-success\" : \"stroke-foreground\") : \"stroke-foreground\",\n          )}\n          cx=\"10\"\n          cy=\"10\"\n          initial={false}\n          key={i}\n          r={r}\n          strokeDasharray={`${seg.toFixed(2)} ${(c - seg).toFixed(2)}`}\n          strokeDashoffset={(-(i * (c / steps)) - gap / 2).toFixed(2)}\n          strokeLinecap=\"round\"\n          strokeWidth=\"2.5\"\n          transition={reduce ? { duration: 0 } : { duration: 0.3, ease: easeOut }}\n        />\n      ))}\n    </svg>\n  );\n}\n\nfunction DrawnCheck({ className }: { className?: string }) {\n  return (\n    <svg aria-hidden className={cn(\"size-3.5\", className)} fill=\"none\" viewBox=\"0 0 16 16\">\n      <motion.path\n        animate={{ pathLength: 1 }}\n        d=\"M3.5 8.5 6.5 11.5 12.5 4.5\"\n        initial={{ pathLength: 0 }}\n        stroke=\"currentColor\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        strokeWidth=\"2\"\n        transition={{ duration: 0.3, ease: easeOut, delay: 0.05 }}\n      />\n    </svg>\n  );\n}\n\nfunction PasswordRow({ changed, reduce }: { changed: string; reduce: boolean }) {\n  const [open, setOpen] = useState(false);\n  const [value, setValue] = useState(\"\");\n  const [error, setError] = useState<string | null>(null);\n  const [updated, setUpdated] = useState(false);\n  const inputId = useId();\n  const errorId = useId();\n\n  const submit = () => {\n    if (value.length < 12) return setError(\"Use at least 12 characters.\");\n    setOpen(false);\n    setValue(\"\");\n    setError(null);\n    setUpdated(true);\n  };\n\n  return (\n    <div className=\"mt-3 overflow-hidden rounded-xl border bg-card\">\n      <div className=\"flex items-center gap-4 px-4 py-3.5\">\n        <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n          <span className=\"font-medium text-sm\">Password</span>\n          <span className=\"flex items-center gap-1 text-muted-foreground text-xs\">\n            {updated && <DrawnCheck className=\"text-success-foreground\" />}\n            {updated ? \"Changed just now\" : `Last changed ${changed}`}\n          </span>\n        </div>\n        <Button onClick={() => setOpen((v) => !v)} size=\"sm\" variant=\"outline\">\n          {open ? \"Cancel\" : \"Change\"}\n        </Button>\n      </div>\n      <Collapse open={open} reduce={reduce}>\n        <form\n          className=\"flex flex-col gap-2 border-t bg-muted/30 px-4 py-3.5\"\n          noValidate\n          onSubmit={(e) => {\n            e.preventDefault();\n            submit();\n          }}\n        >\n          <Label htmlFor={inputId}>New password</Label>\n          <div className=\"flex gap-2\">\n            <AutoFocusInput\n              aria-describedby={error ? errorId : undefined}\n              aria-invalid={!!error || undefined}\n              autoComplete=\"new-password\"\n              id={inputId}\n              onChange={(e) => {\n                setValue(e.target.value);\n                if (error) setError(null);\n              }}\n              type=\"password\"\n              value={value}\n            />\n            <Button type=\"submit\">Update</Button>\n          </div>\n          <p className={cn(\"text-xs\", error ? \"text-destructive-foreground\" : \"text-muted-foreground\")} id={errorId}>\n            {error ?? \"Other sessions stay signed in. Sign them out below if you need to.\"}\n          </p>\n        </form>\n      </Collapse>\n    </div>\n  );\n}\n\nfunction PasskeyRow({\n  passkey,\n  isLast,\n  isNew,\n  editing,\n  confirming,\n  onRename,\n  onStartRename,\n  onCancelRename,\n  onAskRemove,\n  onCancelRemove,\n  onRemove,\n  reduce,\n}: {\n  passkey: SecurityPasskey;\n  isLast: boolean;\n  isNew: boolean;\n  editing: boolean;\n  confirming: boolean;\n  onRename: (name: string) => void;\n  onStartRename: () => void;\n  onCancelRename: () => void;\n  onAskRemove: () => void;\n  onCancelRemove: () => void;\n  onRemove: () => void;\n  reduce: boolean;\n}) {\n  const [draft, setDraft] = useState(passkey.name);\n  const inputId = useId();\n\n  useEffect(() => {\n    if (editing) setDraft(passkey.name);\n  }, [editing, passkey.name]);\n\n  const commit = () => {\n    const name = draft.trim();\n    if (name && name !== passkey.name) onRename(name);\n    else onCancelRename();\n  };\n\n  return (\n    <motion.li\n      animate={{ opacity: 1, height: \"auto\" }}\n      className=\"relative overflow-hidden border-t first:border-t-0\"\n      exit={{ opacity: 0, height: 0 }}\n      initial={reduce ? false : { opacity: 0, height: 0 }}\n      transition={reduce ? { duration: 0 } : { duration: 0.24, ease: easeOut }}\n    >\n      {isNew && !reduce && (\n        <motion.span\n          animate={{ opacity: 0 }}\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0 bg-success/8\"\n          initial={{ opacity: 1 }}\n          transition={{ duration: 1.4, ease: \"easeOut\", delay: 0.3 }}\n        />\n      )}\n      <div className=\"relative flex items-center gap-3 px-4 py-3 sm:grid sm:grid-cols-[minmax(0,1fr)_7.5rem_7.5rem_2rem] sm:gap-4\">\n        <div className=\"flex min-w-0 flex-1 items-center gap-3\">\n          <DeviceIcon kind={passkey.kind} />\n          <div className=\"flex min-w-0 flex-1 flex-col\">\n            {editing ? (\n              <form\n                onSubmit={(e) => {\n                  e.preventDefault();\n                  commit();\n                }}\n              >\n                <Label className=\"sr-only\" htmlFor={inputId}>\n                  Passkey name\n                </Label>\n                <AutoFocusInput\n\n                  id={inputId}\n                  maxLength={40}\n                  onBlur={commit}\n                  onChange={(e) => setDraft(e.target.value)}\n                  onFocus={(e) => e.currentTarget.select()}\n                  onKeyDown={(e) => {\n                    if (e.key === \"Escape\") {\n                      e.preventDefault();\n                      onCancelRename();\n                    }\n                  }}\n                  size=\"sm\"\n                  value={draft}\n                />\n              </form>\n            ) : (\n              <span className=\"truncate font-medium text-sm\">{passkey.name}</span>\n            )}\n            <span className=\"truncate text-muted-foreground text-xs sm:hidden\">\n              Added {passkey.added} · {passkey.lastUsed === \"Never\" ? \"Not used yet\" : `Used ${passkey.lastUsed}`}\n            </span>\n          </div>\n        </div>\n        <span className=\"hidden text-muted-foreground text-sm sm:block\">{passkey.added}</span>\n        <span className=\"hidden text-muted-foreground text-sm sm:block\">\n          {passkey.lastUsed === \"Never\" ? \"Not yet\" : passkey.lastUsed}\n        </span>\n        <Menu>\n          <MenuTrigger\n            render={<Button aria-label={`Options for ${passkey.name}`} className=\"shrink-0\" size=\"icon-sm\" variant=\"ghost\" />}\n          >\n            <MoreHorizontalIcon />\n          </MenuTrigger>\n          <MenuPopup align=\"end\">\n            <MenuItem onClick={onStartRename}>\n              <PencilIcon /> Rename\n            </MenuItem>\n            <MenuSeparator />\n            <MenuItem onClick={onAskRemove} variant=\"destructive\">\n              <Trash2Icon /> Remove\n            </MenuItem>\n          </MenuPopup>\n        </Menu>\n      </div>\n      <Collapse open={confirming} reduce={reduce}>\n        <ConfirmStrip\n          confirmLabel=\"Remove\"\n          detail={\n            isLast\n              ? \"It's your only passkey, so you'll sign in with your password and a code.\"\n              : \"You can still sign in with your other passkeys.\"\n          }\n          onCancel={onCancelRemove}\n          onConfirm={onRemove}\n          title={`Remove ${passkey.name}?`}\n        />\n      </Collapse>\n    </motion.li>\n  );\n}\n\nfunction PendingPasskeyRow({\n  authenticator,\n  onCancel,\n  reduce,\n}: {\n  authenticator: string;\n  onCancel: () => void;\n  reduce: boolean;\n}) {\n  return (\n    <motion.li\n      animate={{ opacity: 1, height: \"auto\" }}\n      className=\"overflow-hidden border-t first:border-t-0\"\n      exit={{ opacity: 0, height: 0 }}\n      initial={reduce ? false : { opacity: 0, height: 0 }}\n      transition={reduce ? { duration: 0 } : { duration: 0.24, ease: easeOut }}\n    >\n      <div className=\"flex items-center gap-3 px-4 py-3\" role=\"status\">\n        <span className=\"relative flex size-8 shrink-0 items-center justify-center rounded-lg border bg-background text-foreground\">\n          {!reduce && (\n            <motion.span\n              animate={{ opacity: [0.6, 0], scale: [1, 1.45] }}\n              aria-hidden\n              className=\"pointer-events-none absolute inset-0 rounded-lg border border-foreground/30\"\n              transition={{ duration: 1.4, ease: \"easeOut\", repeat: Number.POSITIVE_INFINITY }}\n            />\n          )}\n          <FingerprintIcon className=\"size-4\" />\n        </span>\n        <div className=\"flex min-w-0 flex-1 flex-col\">\n          <span className=\"font-medium text-sm\">Waiting for your device…</span>\n          <span className=\"truncate text-muted-foreground text-xs\">Confirm with {authenticator} to create the passkey</span>\n        </div>\n        <Button onClick={onCancel} size=\"sm\" variant=\"ghost\">\n          Cancel\n        </Button>\n      </div>\n    </motion.li>\n  );\n}\n\nfunction RecoveryCodesPanel({\n  codes,\n  used,\n  copied,\n  onCopy,\n  onDownload,\n}: {\n  codes: string[];\n  used: number;\n  copied: boolean;\n  onCopy: () => void;\n  onDownload: () => void;\n}) {\n  return (\n    <div className=\"border-t bg-muted/30 px-4 py-4\">\n      <ol className=\"grid max-w-md grid-cols-2 gap-x-6 gap-y-2 font-mono text-sm tabular-nums\">\n        {codes.map((code, i) => (\n          <li className=\"flex items-baseline gap-3\" key={code + i}>\n            <span className=\"w-4 text-right text-muted-foreground/70 text-xs\">{i + 1}</span>\n            <span className={cn(i < used && \"text-muted-foreground/60 line-through\")}>{code}</span>\n            {i < used && <span className=\"sr-only\">(used)</span>}\n          </li>\n        ))}\n      </ol>\n      <div className=\"mt-4 flex flex-wrap items-center gap-x-4 gap-y-2.5\">\n        <p className=\"min-w-0 flex-1 basis-48 text-pretty text-muted-foreground text-xs\">\n          Each code works once. Keep them somewhere other than this device.\n        </p>\n        <div className=\"flex gap-2\">\n          <Button onClick={onDownload} size=\"sm\" variant=\"ghost\">\n            <DownloadIcon /> Download\n          </Button>\n          <Button className=\"min-w-22\" onClick={onCopy} size=\"sm\" variant=\"outline\">\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              <motion.span\n                animate={{ opacity: 1, scale: 1 }}\n                className=\"flex items-center gap-1.5\"\n                exit={{ opacity: 0, scale: 0.96 }}\n                initial={{ opacity: 0, scale: 0.96 }}\n                key={copied ? \"copied\" : \"copy\"}\n                transition={{ duration: 0.15, ease: easeOut }}\n              >\n                {copied ? <DrawnCheck className=\"size-4 text-success-foreground\" /> : <CopyIcon />}\n                {copied ? \"Copied\" : \"Copy\"}\n              </motion.span>\n            </AnimatePresence>\n          </Button>\n        </div>\n      </div>\n    </div>\n  );\n}\n\nfunction SessionRow({\n  session,\n  index,\n  onSignOut,\n  reduce,\n}: {\n  session: SecuritySession;\n  index: number;\n  onSignOut: () => void;\n  reduce: boolean;\n}) {\n  return (\n    <motion.li\n      animate={{ opacity: 1, x: 0, height: \"auto\" }}\n      className=\"overflow-hidden border-t first:border-t-0\"\n      exit=\"leave\"\n      initial={false}\n      transition={reduce ? { duration: 0 } : { duration: 0.24, ease: easeOut }}\n      variants={{\n        leave: (stagger: boolean) => {\n          const delay = stagger ? index * 0.05 : 0;\n          return {\n            opacity: 0,\n            x: reduce ? 0 : 24,\n            height: 0,\n            transition: reduce\n              ? { duration: 0.12 }\n              : {\n                  opacity: { duration: 0.16, delay },\n                  x: { duration: 0.22, ease: easeOut, delay },\n                  height: { duration: 0.22, ease: easeOut, delay: 0.1 + delay },\n                },\n          };\n        },\n      }}\n    >\n      <div className=\"flex items-center gap-3 px-4 py-3 sm:grid sm:grid-cols-[minmax(0,1fr)_6.5rem_5.5rem_4.5rem] sm:gap-3\">\n        <div className=\"flex min-w-0 flex-1 items-center gap-3\">\n          <DeviceIcon kind={session.kind} />\n          <div className=\"flex min-w-0 flex-1 flex-col\">\n            <span className=\"flex min-w-0 items-center gap-2\">\n              <span className=\"truncate font-medium text-sm\">\n                {session.browser} on {session.os}\n              </span>\n              {session.current && (\n                <Badge className=\"shrink-0\" variant=\"success\">\n                  This device\n                </Badge>\n              )}\n            </span>\n            <span className=\"truncate text-muted-foreground text-xs sm:hidden\">\n              {session.location} · {session.current ? \"Active now\" : session.lastActive}\n            </span>\n          </div>\n        </div>\n        <span className=\"hidden truncate text-muted-foreground text-sm sm:block\">{session.location}</span>\n        <span className={cn(\"hidden text-sm sm:block\", session.current ? \"text-success-foreground\" : \"text-muted-foreground\")}>\n          {session.current ? \"Active now\" : session.lastActive}\n        </span>\n        <div className=\"flex shrink-0 justify-end\">\n          {!session.current && (\n            <Button\n              aria-label={`Sign out ${session.browser} on ${session.os}`}\n              onClick={onSignOut}\n              size=\"sm\"\n              variant=\"ghost\"\n            >\n              <LogOutIcon className=\"sm:hidden\" />\n              <span className=\"hidden sm:inline\">Sign out</span>\n            </Button>\n          )}\n        </div>\n      </div>\n    </motion.li>\n  );\n}\n\nexport function SecuritySettings({\n  className,\n  passwordChanged = \"4 months ago\",\n  passkeys: initialPasskeys = defaultPasskeys,\n  sessions: initialSessions = defaultSessions,\n  authenticatorSince = \"Jan 12, 2026\",\n  recoveryCodesLeft = 8,\n  recoveryCodesSaved = false,\n  newPasskey = defaultNewPasskey,\n  onNavigate,\n}: SecuritySettingsProps) {\n  const reduce = useCalmMotion();\n\n  const [passkeys, setPasskeys] = useState(initialPasskeys);\n  const [editingId, setEditingId] = useState<string | null>(null);\n  const [confirmingId, setConfirmingId] = useState<string | null>(null);\n  const [newId, setNewId] = useState<string | null>(null);\n  const [pending, setPending] = useState(false);\n  const [created, setCreated] = useState(0);\n\n  const [authOn, setAuthOn] = useState(true);\n  const [confirmDisable, setConfirmDisable] = useState(false);\n  const [codesOpen, setCodesOpen] = useState(false);\n  const [confirmRegen, setConfirmRegen] = useState(false);\n  const [codeSeed, setCodeSeed] = useState(4471);\n  const [used, setUsed] = useState(Math.max(0, 10 - recoveryCodesLeft));\n  const [saved, setSaved] = useState(recoveryCodesSaved);\n  const [copied, setCopied] = useState(false);\n\n  const [sessions, setSessions] = useState(initialSessions);\n  const [confirmAll, setConfirmAll] = useState(false);\n  const [bulk, setBulk] = useState(false);\n\n  const codes = makeCodes(codeSeed);\n  const others = sessions.filter((s) => !s.current);\n  const steps = [\n    { done: passkeys.length > 0, hint: \"Add a passkey\" },\n    { done: authOn, hint: \"Turn on two-factor\" },\n    { done: authOn && saved, hint: \"Save your recovery codes\" },\n  ];\n  const doneCount = steps.filter((s) => s.done).length;\n  const nextStep = steps.find((s) => !s.done);\n\n  useEffect(() => {\n    if (!copied) return;\n    const t = setTimeout(() => setCopied(false), 1800);\n    return () => clearTimeout(t);\n  }, [copied]);\n\n  useEffect(() => {\n    if (!pending) return;\n    const t = setTimeout(\n      () => {\n        const id = `pk-new-${created + 1}`;\n        setCreated((c) => c + 1);\n        setPasskeys((all) => [\n          ...all,\n          { id, name: newPasskey.name, kind: newPasskey.kind, added: \"Today\", lastUsed: \"Never\" },\n        ]);\n        setNewId(id);\n        setEditingId(id);\n        setPending(false);\n      },\n      reduce ? 400 : 1600,\n    );\n    return () => clearTimeout(t);\n  }, [pending, created, newPasskey.name, newPasskey.kind, reduce]);\n\n  const copyCodes = () => {\n    const text = codes.filter((_, i) => i >= used).join(\"\\n\");\n    navigator.clipboard?.writeText(text).catch(() => {});\n    setCopied(true);\n    setSaved(true);\n  };\n\n  const downloadCodes = () => {\n    const text = `Ridgeline recovery codes for ada@ridgeline.app\\n\\n${codes.filter((_, i) => i >= used).join(\"\\n\")}\\n`;\n    const url = URL.createObjectURL(new Blob([text], { type: \"text/plain\" }));\n    const a = Object.assign(document.createElement(\"a\"), { href: url, download: \"ridgeline-recovery-codes.txt\" });\n    a.click();\n    URL.revokeObjectURL(url);\n    setSaved(true);\n  };\n\n  const fixNext = () => {\n    if (!passkeys.length) setPending(true);\n    else if (!authOn) setAuthOn(true);\n    else setCodesOpen(true);\n  };\n\n  return (\n    <RidgelineShell active=\"security\" className={className} onNavigate={onNavigate}>\n      <div className=\"mx-auto w-full max-w-2xl px-6 py-10 md:px-10\">\n        <h1 className=\"font-semibold text-2xl tracking-tight\">Security</h1>\n        <p className=\"mt-1 text-muted-foreground text-sm\">How you sign in, and where you're signed in right now.</p>\n        <div aria-live=\"polite\" className=\"mt-4 flex min-h-6 flex-wrap items-center gap-x-2 gap-y-1 text-sm\">\n          <ProgressRing done={doneCount} reduce={reduce} steps={steps.length} />\n          <span className=\"font-medium tabular-nums\">\n            {doneCount === steps.length\n              ? \"All recommended steps done\"\n              : `${doneCount} of ${steps.length} recommended steps done`}\n          </span>\n          {nextStep && (\n            <>\n              <span aria-hidden className=\"text-muted-foreground max-sm:hidden\">\n                ·\n              </span>\n              <button\n                className=\"cursor-pointer rounded-sm max-sm:basis-full max-sm:ps-7 max-sm:text-left text-muted-foreground underline-offset-4 outline-none transition-colors hover:text-foreground hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                onClick={fixNext}\n                type=\"button\"\n              >\n                {nextStep.hint}\n              </button>\n            </>\n          )}\n        </div>\n\n        <section className=\"mt-10\">\n          <SectionHeader description=\"How you prove it's you when a passkey isn't handy.\" title=\"Sign-in\" />\n          <PasswordRow changed={passwordChanged} reduce={reduce} />\n        </section>\n\n        <section className=\"mt-10\">\n          <SectionHeader\n            description=\"A second check after your password, so a leaked password isn't enough.\"\n            title=\"Two-factor authentication\"\n          />\n          <div className=\"mt-3 overflow-hidden rounded-xl border bg-card\">\n            <div className=\"flex items-center gap-4 px-4 py-3.5\">\n              <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n                <span className=\"flex items-center gap-2\">\n                  <span className=\"font-medium text-sm\">Authenticator app</span>\n                  <Badge variant={authOn ? \"success\" : \"outline\"}>{authOn ? \"Enabled\" : \"Off\"}</Badge>\n                </span>\n                <span className=\"text-pretty text-muted-foreground text-xs\">\n                  {authOn ? `6-digit codes from an app on your phone. Added ${authenticatorSince}.` : \"Use an app on your phone for 6-digit codes.\"}\n                </span>\n              </div>\n              {authOn ? (\n                <Button onClick={() => setConfirmDisable((v) => !v)} size=\"sm\" variant=\"outline\">\n                  Disable\n                </Button>\n              ) : (\n                <Button onClick={() => setAuthOn(true)} size=\"sm\" variant=\"outline\">\n                  Set up\n                </Button>\n              )}\n            </div>\n            <Collapse open={confirmDisable && authOn} reduce={reduce}>\n              <ConfirmStrip\n                confirmLabel=\"Disable\"\n                detail=\"Anyone with your password could sign in as you.\"\n                onCancel={() => setConfirmDisable(false)}\n                onConfirm={() => {\n                  setConfirmDisable(false);\n                  setCodesOpen(false);\n                  setConfirmRegen(false);\n                  setAuthOn(false);\n                }}\n                title=\"Turn off two-factor?\"\n              />\n            </Collapse>\n            <div className={cn(\"flex items-center gap-4 border-t px-4 py-3.5 transition-opacity\", !authOn && \"opacity-60\")}>\n              <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n                <span className=\"flex items-center gap-2\">\n                  <span className=\"font-medium text-sm\">Recovery codes</span>\n                  {authOn && !saved && <Badge variant=\"warning\">Not saved</Badge>}\n                </span>\n                <span className=\"text-muted-foreground text-xs tabular-nums\">\n                  {authOn ? `${10 - used} of 10 left. Use one if you lose your phone.` : \"Available once two-factor is on.\"}\n                </span>\n              </div>\n              <div className=\"flex shrink-0 gap-2\">\n                <Button\n                  className=\"max-sm:hidden\"\n                  disabled={!authOn}\n                  onClick={() => setConfirmRegen((v) => !v)}\n                  size=\"sm\"\n                  variant=\"ghost\"\n                >\n                  Regenerate\n                </Button>\n                <Button\n                  aria-expanded={codesOpen}\n                  disabled={!authOn}\n                  onClick={() => setCodesOpen((v) => !v)}\n                  size=\"sm\"\n                  variant=\"outline\"\n                >\n                  {codesOpen ? \"Hide\" : \"View\"}\n                </Button>\n              </div>\n            </div>\n            <Collapse open={confirmRegen && authOn} reduce={reduce}>\n              <ConfirmStrip\n                confirmLabel=\"Regenerate\"\n                detail=\"Your current codes stop working straight away.\"\n                onCancel={() => setConfirmRegen(false)}\n                onConfirm={() => {\n                  setConfirmRegen(false);\n                  setCodeSeed((s) => s * 7 + 13);\n                  setUsed(0);\n                  setSaved(false);\n                  setCopied(false);\n                  setCodesOpen(true);\n                }}\n                title=\"Make a new set?\"\n                tone=\"default\"\n              />\n            </Collapse>\n            <Collapse open={codesOpen && authOn} reduce={reduce}>\n              <RecoveryCodesPanel codes={codes} copied={copied} onCopy={copyCodes} onDownload={downloadCodes} used={used} />\n              <div className=\"flex justify-end border-t px-4 py-2.5 sm:hidden\">\n                <Button onClick={() => setConfirmRegen(true)} size=\"sm\" variant=\"ghost\">\n                  Regenerate codes\n                </Button>\n              </div>\n            </Collapse>\n          </div>\n        </section>\n\n        <section className=\"mt-10\">\n          <SectionHeader\n            action={\n              <Button disabled={pending} onClick={() => setPending(true)} size=\"sm\" variant=\"outline\">\n                <PlusIcon /> Add passkey\n              </Button>\n            }\n            description=\"Sign in with your fingerprint, face or a security key.\"\n            title=\"Passkeys\"\n          />\n          <div className=\"mt-3 overflow-hidden rounded-xl border bg-card\">\n            <div className=\"hidden grid-cols-[minmax(0,1fr)_7.5rem_7.5rem_2rem] gap-4 border-b px-4 py-2.5 font-medium text-muted-foreground text-xs sm:grid\">\n              <span>Name</span>\n              <span>Added</span>\n              <span>Last used</span>\n              <span className=\"sr-only\">Actions</span>\n            </div>\n            <ul aria-label=\"Passkeys\">\n              <AnimatePresence initial={false}>\n                {passkeys.map((p) => (\n                  <PasskeyRow\n                    confirming={confirmingId === p.id}\n                    editing={editingId === p.id}\n                    isLast={passkeys.length === 1}\n                    isNew={newId === p.id}\n                    key={p.id}\n                    onAskRemove={() => {\n                      setEditingId(null);\n                      setConfirmingId(p.id);\n                    }}\n                    onCancelRemove={() => setConfirmingId(null)}\n                    onCancelRename={() => setEditingId(null)}\n                    onRemove={() => {\n                      setConfirmingId(null);\n                      setPasskeys((all) => all.filter((x) => x.id !== p.id));\n                    }}\n                    onRename={(name) => {\n                      setPasskeys((all) => all.map((x) => (x.id === p.id ? { ...x, name } : x)));\n                      setEditingId(null);\n                    }}\n                    onStartRename={() => {\n                      setConfirmingId(null);\n                      setEditingId(p.id);\n                    }}\n                    passkey={p}\n                    reduce={reduce}\n                  />\n                ))}\n                {pending && (\n                  <PendingPasskeyRow\n                    authenticator={newPasskey.authenticator}\n                    key=\"pending\"\n                    onCancel={() => setPending(false)}\n                    reduce={reduce}\n                  />\n                )}\n              </AnimatePresence>\n            </ul>\n            <Collapse open={passkeys.length === 0 && !pending} reduce={reduce}>\n              <p className=\"px-4 py-6 text-center text-muted-foreground text-sm\">\n                No passkeys yet. Add one and skip the password next time.\n              </p>\n            </Collapse>\n          </div>\n        </section>\n\n        <section className=\"mt-10\">\n          <SectionHeader\n            action={\n              <Button\n                className=\"max-sm:hidden\"\n                disabled={others.length === 0}\n                onClick={() => setConfirmAll((v) => !v)}\n                size=\"sm\"\n                variant=\"outline\"\n              >\n                Sign out of all other sessions\n              </Button>\n            }\n            description=\"Where you're signed in. Locations are approximate.\"\n            title=\"Sessions\"\n          />\n          <div className=\"mt-3 overflow-hidden rounded-xl border bg-card\">\n            <div className=\"hidden grid-cols-[minmax(0,1fr)_6.5rem_5.5rem_4.5rem] gap-3 border-b px-4 py-2.5 font-medium text-muted-foreground text-xs sm:grid\">\n              <span>Device</span>\n              <span>Location</span>\n              <span>Last active</span>\n              <span className=\"sr-only\">Actions</span>\n            </div>\n            <ul aria-label=\"Sessions\">\n              <AnimatePresence custom={bulk} initial={false}>\n                {sessions.map((s) => (\n                  <SessionRow\n                    index={Math.max(0, others.findIndex((o) => o.id === s.id))}\n                    key={s.id}\n                    onSignOut={() => {\n                      setBulk(false);\n                      setSessions((all) => all.filter((x) => x.id !== s.id));\n                    }}\n                    reduce={reduce}\n                    session={s}\n                  />\n                ))}\n              </AnimatePresence>\n            </ul>\n            <Collapse open={confirmAll && others.length > 0} reduce={reduce}>\n              <ConfirmStrip\n                confirmLabel={`Sign out ${others.length}`}\n                detail=\"They'll need a passkey or password to get back in.\"\n                onCancel={() => setConfirmAll(false)}\n                onConfirm={() => {\n                  setConfirmAll(false);\n                  setBulk(true);\n                  setSessions((all) => all.filter((s) => s.current));\n                }}\n                title={`Sign out of ${others.length} other ${others.length === 1 ? \"session\" : \"sessions\"}?`}\n              />\n            </Collapse>\n            {others.length > 0 && !confirmAll && (\n              <div className=\"border-t px-4 py-2.5 sm:hidden\">\n                <Button className=\"w-full\" onClick={() => setConfirmAll(true)} size=\"sm\" variant=\"ghost\">\n                  Sign out of all other sessions\n                </Button>\n              </div>\n            )}\n            <Collapse open={others.length === 0} reduce={reduce}>\n              <p className=\"flex items-center gap-2 border-t px-4 py-3 text-muted-foreground text-xs\">\n                <CheckIcon className=\"size-3.5 text-success-foreground\" />\n                You're only signed in on this device.\n              </p>\n            </Collapse>\n          </div>\n        </section>\n      </div>\n    </RidgelineShell>\n  );\n}\n"
    }
  ]
}