{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-settings",
  "title": "Settings page",
  "description": "Settings page is a production-ready blocks component from BJORK UI, packaged for shadcn registries.",
  "dependencies": [
    "clsx",
    "framer-motion",
    "lucide-react",
    "next-themes",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/bjork-ui/blocks/app-settings.tsx",
      "content": "\"use client\";\n\nimport {\n  useEffect,\n  useId,\n  useMemo,\n  useRef,\n  useState,\n  type ComponentType,\n  type FormEvent,\n  type KeyboardEvent as ReactKeyboardEvent,\n  type ReactNode,\n  type SVGProps,\n} from \"react\";\nimport {\n  Bell,\n  Check,\n  CreditCard,\n  Download,\n  KeyRound,\n  Laptop,\n  Monitor,\n  Moon,\n  Palette,\n  ShieldCheck,\n  Smartphone,\n  Sun,\n  Trash2,\n  Upload,\n  UserRound,\n} from \"lucide-react\";\nimport {\n  BlockButton,\n  BlockDialog,\n  BlockField,\n  BlockSpinner,\n  BlockSwitch,\n  InitialsAvatar,\n  Kbd,\n  blockRoot,\n  focusRing,\n  inputClass,\n  useAppBlockTheme,\n  useBlockToast,\n  type AppBlockTheme,\n} from \"@/components/bjork-ui/blocks/app-block-kit\";\nimport { cn } from \"@/lib/utils\";\n\n/* ----------------------------------------------------------------------------------------------------------\n * Types\n * -------------------------------------------------------------------------------------------------------- */\n\nexport type SettingsSection = \"profile\" | \"notifications\" | \"appearance\" | \"security\" | \"billing\";\n\nexport interface SettingsProfile {\n  name: string;\n  username: string;\n  email: string;\n  bio: string;\n  timezone: string;\n}\n\nexport type NotificationChannel = \"email\" | \"push\";\n\nexport interface NotificationPrefs {\n  /** Event id -> channels that are on. */\n  events: Record<string, Record<NotificationChannel, boolean>>;\n  digest: \"instant\" | \"hourly\" | \"daily\";\n  quietHours: { enabled: boolean; from: string; to: string };\n}\n\nexport interface SettingsSession {\n  id: string;\n  device: string;\n  kind: \"desktop\" | \"mobile\";\n  location: string;\n  lastActive: string;\n  current?: boolean;\n}\n\nexport interface SettingsInvoice {\n  id: string;\n  date: string;\n  amount: string;\n  status: \"paid\" | \"due\";\n}\n\nexport interface AppSettingsProps {\n  profile?: SettingsProfile;\n  notifications?: NotificationPrefs;\n  sessions?: SettingsSession[];\n  invoices?: SettingsInvoice[];\n  defaultSection?: SettingsSection;\n  /** Called with only the parts that changed. Throw to show an error. */\n  onSave?: (changes: { profile?: SettingsProfile; notifications?: NotificationPrefs }) => Promise<void> | void;\n  /** Throw with a message to reject (e.g. a wrong current password). */\n  onChangePassword?: (current: string, next: string) => Promise<void> | void;\n  onRevokeSession?: (id: string) => void;\n  onToggleTwoFactor?: (enabled: boolean) => void;\n  onDeleteAccount?: () => void;\n  /** Theme picked under Appearance. The block re-themes itself either way. */\n  onThemeChange?: (theme: AppBlockTheme) => void;\n  /** Rejects these usernames as taken. */\n  takenUsernames?: string[];\n  theme?: AppBlockTheme;\n  className?: string;\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Sample data\n * -------------------------------------------------------------------------------------------------------- */\n\nconst SAMPLE_PROFILE: SettingsProfile = {\n  name: \"Rhea Castillo\",\n  username: \"rhea\",\n  email: \"rhea@halcyon.app\",\n  bio: \"Design engineer. I look after the dashboard and the parts of it nobody notices until they break.\",\n  timezone: \"America/Los_Angeles\",\n};\n\nconst NOTIFICATION_EVENTS: { id: string; label: string; hint: string; locked?: NotificationChannel[] }[] = [\n  { id: \"mentions\", label: \"Mentions\", hint: \"Someone @mentions you in a comment or doc.\" },\n  { id: \"assigned\", label: \"Assigned to you\", hint: \"An issue or review is handed to you.\" },\n  { id: \"comments\", label: \"Comments on your work\", hint: \"Replies on docs and issues you created.\" },\n  { id: \"digest\", label: \"Weekly summary\", hint: \"A Monday recap of what moved in your workspace.\" },\n  { id: \"product\", label: \"Product updates\", hint: \"New features, at most twice a month.\" },\n  { id: \"security\", label: \"Security alerts\", hint: \"New sign-ins and changes to your password.\", locked: [\"email\"] },\n];\n\nconst SAMPLE_NOTIFICATIONS: NotificationPrefs = {\n  events: {\n    mentions: { email: true, push: true },\n    assigned: { email: true, push: true },\n    comments: { email: false, push: true },\n    digest: { email: true, push: false },\n    product: { email: false, push: false },\n    security: { email: true, push: true },\n  },\n  digest: \"hourly\",\n  quietHours: { enabled: true, from: \"22:00\", to: \"07:00\" },\n};\n\nconst SAMPLE_SESSIONS: SettingsSession[] = [\n  { id: \"s1\", device: \"Chrome on macOS\", kind: \"desktop\", location: \"San Francisco, US\", lastActive: \"Active now\", current: true },\n  { id: \"s2\", device: \"Halcyon for iOS\", kind: \"mobile\", location: \"San Francisco, US\", lastActive: \"2 hours ago\" },\n  { id: \"s3\", device: \"Firefox on Windows\", kind: \"desktop\", location: \"Lisbon, PT\", lastActive: \"Sep 29\" },\n  { id: \"s4\", device: \"Safari on iPadOS\", kind: \"mobile\", location: \"Oakland, US\", lastActive: \"Sep 12\" },\n];\n\nconst SAMPLE_INVOICES: SettingsInvoice[] = [\n  { id: \"INV-2026-010\", date: \"Oct 1, 2026\", amount: \"$588.00\", status: \"due\" },\n  { id: \"INV-2026-009\", date: \"Sep 1, 2026\", amount: \"$588.00\", status: \"paid\" },\n  { id: \"INV-2026-008\", date: \"Aug 1, 2026\", amount: \"$539.00\", status: \"paid\" },\n  { id: \"INV-2026-007\", date: \"Jul 1, 2026\", amount: \"$539.00\", status: \"paid\" },\n];\n\nconst TIMEZONES = [\n  { id: \"Pacific/Honolulu\", label: \"Honolulu (GMT−10)\" },\n  { id: \"America/Los_Angeles\", label: \"Los Angeles (GMT−7)\" },\n  { id: \"America/Denver\", label: \"Denver (GMT−6)\" },\n  { id: \"America/Chicago\", label: \"Chicago (GMT−5)\" },\n  { id: \"America/New_York\", label: \"New York (GMT−4)\" },\n  { id: \"Europe/London\", label: \"London (GMT+1)\" },\n  { id: \"Europe/Lisbon\", label: \"Lisbon (GMT+1)\" },\n  { id: \"Europe/Berlin\", label: \"Berlin (GMT+2)\" },\n  { id: \"Asia/Kolkata\", label: \"Kolkata (GMT+5:30)\" },\n  { id: \"Asia/Tokyo\", label: \"Tokyo (GMT+9)\" },\n  { id: \"Australia/Sydney\", label: \"Sydney (GMT+11)\" },\n];\n\nconst SECTIONS: { id: SettingsSection; label: string; hint: string; icon: ComponentType<SVGProps<SVGSVGElement>> }[] = [\n  { id: \"profile\", label: \"Profile\", hint: \"How you appear to your team.\", icon: UserRound },\n  { id: \"notifications\", label: \"Notifications\", hint: \"What reaches you, and where.\", icon: Bell },\n  { id: \"appearance\", label: \"Appearance\", hint: \"Theme and density. Applies right away.\", icon: Palette },\n  { id: \"security\", label: \"Security\", hint: \"Password, two-factor and where you're signed in.\", icon: ShieldCheck },\n  { id: \"billing\", label: \"Billing\", hint: \"Plan, seats and invoices.\", icon: CreditCard },\n];\n\nconst BIO_MAX = 160;\nconst USERNAME_RE = /^[a-z0-9](?:[a-z0-9-]{1,22}[a-z0-9])$/;\n\nfunction sameJson(a: unknown, b: unknown) {\n  return JSON.stringify(a) === JSON.stringify(b);\n}\n\nfunction profileErrors(p: SettingsProfile, taken: string[]) {\n  const errors: Partial<Record<keyof SettingsProfile, string>> = {};\n  if (!p.name.trim()) errors.name = \"Add the name your team knows you by.\";\n  if (!USERNAME_RE.test(p.username)) errors.username = \"3 to 24 lowercase letters, numbers or dashes, not starting or ending with a dash.\";\n  else if (taken.includes(p.username)) errors.username = `“${p.username}” is taken. Try another.`;\n  if (!/^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/.test(p.email.trim())) errors.email = \"That doesn't look like an email address.\";\n  if (p.bio.length > BIO_MAX) errors.bio = `Keep it under ${BIO_MAX} characters.`;\n  return errors;\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Block\n * -------------------------------------------------------------------------------------------------------- */\n\nexport function AppSettings({\n  profile = SAMPLE_PROFILE,\n  notifications = SAMPLE_NOTIFICATIONS,\n  sessions = SAMPLE_SESSIONS,\n  invoices = SAMPLE_INVOICES,\n  defaultSection = \"profile\",\n  onSave,\n  onChangePassword,\n  onRevokeSession,\n  onToggleTwoFactor,\n  onDeleteAccount,\n  onThemeChange,\n  takenUsernames = [\"admin\", \"support\", \"halcyon\"],\n  theme = \"auto\",\n  className,\n}: AppSettingsProps) {\n  const [appearance, setAppearance] = useState<AppBlockTheme>(theme);\n  const [density, setDensity] = useState<\"comfortable\" | \"compact\">(\"comfortable\");\n  const { style } = useAppBlockTheme(appearance);\n  const toast = useBlockToast();\n\n  const [section, setSection] = useState<SettingsSection>(defaultSection);\n  // Saved values and the working drafts. Drafts survive switching sections, and one bar saves them all.\n  const [savedProfile, setSavedProfile] = useState(profile);\n  const [savedPrefs, setSavedPrefs] = useState(notifications);\n  const [draftProfile, setDraftProfile] = useState(profile);\n  const [draftPrefs, setDraftPrefs] = useState(notifications);\n  const [saving, setSaving] = useState(false);\n  const [showErrors, setShowErrors] = useState(false);\n  const [deleteOpen, setDeleteOpen] = useState(false);\n  const [twoFactorOpen, setTwoFactorOpen] = useState(false);\n  const [twoFactor, setTwoFactor] = useState(false);\n  const [sessionList, setSessionList] = useState(sessions);\n  const headingRef = useRef<HTMLHeadingElement>(null);\n  const focusHeading = useRef(false);\n\n  const profileDirty = !sameJson(savedProfile, draftProfile);\n  const prefsDirty = !sameJson(savedPrefs, draftPrefs);\n  const dirtyCount = (profileDirty ? 1 : 0) + (prefsDirty ? 1 : 0);\n  const errors = useMemo(() => profileErrors(draftProfile, takenUsernames), [draftProfile, takenUsernames]);\n  const modalOpen = deleteOpen || twoFactorOpen;\n\n  useEffect(() => {\n    if (!focusHeading.current) return;\n    focusHeading.current = false;\n    headingRef.current?.focus({ preventScroll: true });\n  }, [section]);\n\n  const goTo = (next: SettingsSection) => {\n    if (next === section) return;\n    focusHeading.current = true;\n    setSection(next);\n  };\n\n  const save = async () => {\n    if (saving || dirtyCount === 0) return;\n    if (profileDirty && Object.keys(errors).length > 0) {\n      setShowErrors(true);\n      if (section !== \"profile\") goTo(\"profile\");\n      toast.show(\"Fix the highlighted profile fields first.\", \"error\");\n      return;\n    }\n    setSaving(true);\n    try {\n      await onSave?.({\n        profile: profileDirty ? draftProfile : undefined,\n        notifications: prefsDirty ? draftPrefs : undefined,\n      });\n      if (!onSave) await new Promise((r) => setTimeout(r, 700));\n      setSavedProfile(draftProfile);\n      setSavedPrefs(draftPrefs);\n      setShowErrors(false);\n      toast.show(\"Settings saved\", \"success\");\n    } catch (error) {\n      toast.show(error instanceof Error ? error.message : \"Couldn't save. Try again.\", \"error\");\n    } finally {\n      setSaving(false);\n    }\n  };\n\n  const discard = () => {\n    setDraftProfile(savedProfile);\n    setDraftPrefs(savedPrefs);\n    setShowErrors(false);\n    toast.show(\"Changes discarded\");\n  };\n\n  const onRootKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {\n    if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === \"s\" && !modalOpen) {\n      event.preventDefault();\n      void save();\n    }\n  };\n\n  const meta = SECTIONS.find((s) => s.id === section) ?? SECTIONS[0];\n\n  return (\n    <div\n      className={cn(blockRoot, \"h-full flex-col\", density === \"compact\" && \"[--set-gap:14px]\", className)}\n      style={style}\n      onKeyDown={onRootKeyDown}\n    >\n      <div className=\"flex min-h-0 flex-1 flex-col\" inert={modalOpen}>\n        <header className=\"flex h-14 shrink-0 items-center gap-3 border-b border-[color:var(--bjork-border)] px-4 @3xl:px-6\">\n          <h1 className=\"font-bjork-display text-[20px] font-bold italic leading-none tracking-[-0.02em]\">Settings</h1>\n          <span aria-hidden=\"true\" className=\"text-[color:var(--bjork-text-faint)]\">/</span>\n          <span className=\"truncate text-[13px] text-[color:var(--bjork-text-muted)]\">{meta.label}</span>\n          <span className=\"ml-auto hidden items-center gap-1.5 text-[11.5px] text-[color:var(--bjork-text-soft)] @2xl:flex\">\n            <Kbd>⌘</Kbd>\n            <Kbd>S</Kbd>\n            <span>to save</span>\n          </span>\n        </header>\n\n        <div className=\"flex min-h-0 flex-1 flex-col @3xl:flex-row\">\n          <SectionNav value={section} onChange={goTo} dirty={{ profile: profileDirty, notifications: prefsDirty }} />\n\n          <main className=\"@container/main relative min-h-0 flex-1 overflow-y-auto overscroll-contain\">\n            <div\n              className={cn(\n                \"mx-auto flex w-full max-w-[760px] flex-col px-4 pt-6 @3xl:px-8 @3xl:pt-8\",\n                density === \"compact\" ? \"gap-4\" : \"gap-6\",\n                dirtyCount > 0 ? \"pb-28\" : \"pb-12\",\n              )}\n            >\n              <div>\n                <h2\n                  ref={headingRef}\n                  tabIndex={-1}\n                  className=\"text-[20px] font-semibold tracking-[-0.02em] outline-none @3xl/main:text-[22px]\"\n                >\n                  {meta.label}\n                </h2>\n                <p className=\"mt-1 text-[13px] text-[color:var(--bjork-text-muted)]\">{meta.hint}</p>\n              </div>\n\n              {section === \"profile\" && (\n                <ProfileSection\n                  draft={draftProfile}\n                  saved={savedProfile}\n                  errors={showErrors ? errors : {}}\n                  liveErrors={errors}\n                  onChange={setDraftProfile}\n                  onDelete={() => setDeleteOpen(true)}\n                />\n              )}\n              {section === \"notifications\" && <NotificationsSection draft={draftPrefs} onChange={setDraftPrefs} />}\n              {section === \"appearance\" && (\n                <AppearanceSection\n                  theme={appearance}\n                  density={density}\n                  onTheme={(next) => {\n                    setAppearance(next);\n                    onThemeChange?.(next);\n                    toast.show(`Theme set to ${next === \"auto\" ? \"system\" : next}`);\n                  }}\n                  onDensity={setDensity}\n                />\n              )}\n              {section === \"security\" && (\n                <SecuritySection\n                  twoFactor={twoFactor}\n                  sessions={sessionList}\n                  onChangePassword={async (current, next) => {\n                    if (onChangePassword) await onChangePassword(current, next);\n                    else {\n                      await new Promise((r) => setTimeout(r, 800));\n                      if (current === \"wrong\") throw new Error(\"That isn't your current password.\");\n                    }\n                    toast.show(\"Password updated. Other sessions stay signed in.\", \"success\");\n                  }}\n                  onTwoFactor={(next) => {\n                    if (next) setTwoFactorOpen(true);\n                    else {\n                      setTwoFactor(false);\n                      onToggleTwoFactor?.(false);\n                      toast.show(\"Two-factor authentication turned off\");\n                    }\n                  }}\n                  onRevoke={(id) => {\n                    const target = sessionList.find((s) => s.id === id);\n                    setSessionList((list) => list.filter((s) => s.id !== id));\n                    onRevokeSession?.(id);\n                    toast.show(`Signed out ${target?.device ?? \"session\"}`);\n                  }}\n                  onRevokeOthers={() => {\n                    const others = sessionList.filter((s) => !s.current);\n                    others.forEach((s) => onRevokeSession?.(s.id));\n                    setSessionList((list) => list.filter((s) => s.current));\n                    toast.show(`Signed out ${others.length} other ${others.length === 1 ? \"session\" : \"sessions\"}`);\n                  }}\n                />\n              )}\n              {section === \"billing\" && <BillingSection invoices={invoices} onNotify={(m) => toast.show(m)} />}\n            </div>\n          </main>\n        </div>\n\n        <SaveBar count={dirtyCount} saving={saving} onSave={save} onDiscard={discard} />\n      </div>\n\n      <DeleteAccountDialog\n        open={deleteOpen}\n        username={savedProfile.username}\n        onClose={() => setDeleteOpen(false)}\n        onConfirm={() => {\n          setDeleteOpen(false);\n          onDeleteAccount?.();\n          toast.show(\"Account scheduled for deletion in 14 days\", \"error\");\n        }}\n      />\n      <TwoFactorDialog\n        open={twoFactorOpen}\n        email={savedProfile.email}\n        onClose={() => setTwoFactorOpen(false)}\n        onVerified={() => {\n          setTwoFactorOpen(false);\n          setTwoFactor(true);\n          onToggleTwoFactor?.(true);\n          toast.show(\"Two-factor authentication is on\", \"success\");\n        }}\n      />\n      {toast.node}\n    </div>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Section nav: a vertical list beside the content, a horizontal scroller above it on narrow containers.\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction SectionNav({\n  value,\n  onChange,\n  dirty,\n}: {\n  value: SettingsSection;\n  onChange: (section: SettingsSection) => void;\n  dirty: Partial<Record<SettingsSection, boolean>>;\n}) {\n  const refs = useRef<(HTMLAnchorElement | null)[]>([]);\n  const onKeyDown = (event: ReactKeyboardEvent, index: number) => {\n    let next = -1;\n    if (event.key === \"ArrowDown\" || event.key === \"ArrowRight\") next = (index + 1) % SECTIONS.length;\n    else if (event.key === \"ArrowUp\" || event.key === \"ArrowLeft\") next = (index - 1 + SECTIONS.length) % SECTIONS.length;\n    else if (event.key === \"Home\") next = 0;\n    else if (event.key === \"End\") next = SECTIONS.length - 1;\n    if (next < 0) return;\n    event.preventDefault();\n    refs.current[next]?.focus();\n  };\n  return (\n    <nav\n      aria-label=\"Settings sections\"\n      className=\"hide-scrollbar shrink-0 overflow-x-auto border-b border-[color:var(--bjork-border)] @3xl:w-[220px] @3xl:overflow-visible @3xl:border-b-0 @3xl:border-r @3xl:bg-[var(--bjork-panel)]\"\n    >\n      <ul className=\"flex gap-1 px-3 py-2 @3xl:flex-col @3xl:gap-0.5 @3xl:px-3 @3xl:py-4\">\n        {SECTIONS.map((s, i) => {\n          const active = s.id === value;\n          const Icon = s.icon;\n          return (\n            <li key={s.id} className=\"shrink-0\">\n              <a\n                ref={(el) => {\n                  refs.current[i] = el;\n                }}\n                href={`#${s.id}`}\n                aria-current={active ? \"page\" : undefined}\n                onClick={(e) => {\n                  e.preventDefault();\n                  onChange(s.id);\n                }}\n                onKeyDown={(e) => onKeyDown(e, i)}\n                className={cn(\n                  \"relative flex h-9 items-center gap-2.5 whitespace-nowrap rounded-[9px] px-3 text-[13.5px] transition-colors duration-150\",\n                  active\n                    ? \"bg-[var(--bjork-surface)] font-medium text-[color:var(--bjork-text)] shadow-[var(--bjork-shadow-soft),0_0_0_1px_var(--bjork-border)]\"\n                    : \"text-[color:var(--bjork-text-medium)] hover:bg-[var(--bjork-surface-hover)] hover:text-[color:var(--bjork-text)]\",\n                  focusRing,\n                )}\n              >\n                <Icon\n                  aria-hidden=\"true\"\n                  className={cn(\"size-4 shrink-0\", active ? \"text-[color:var(--blk-accent-ink)]\" : \"text-[color:var(--bjork-text-muted)]\")}\n                />\n                {s.label}\n                {dirty[s.id] && (\n                  <>\n                    <span aria-hidden=\"true\" className=\"ml-auto size-1.5 rounded-full bg-[var(--bjork-accent)] @max-3xl:ml-0\" />\n                    <span className=\"sr-only\">(unsaved changes)</span>\n                  </>\n                )}\n              </a>\n            </li>\n          );\n        })}\n      </ul>\n    </nav>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Shared section pieces\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction Card({\n  title,\n  description,\n  children,\n  footer,\n  tone = \"neutral\",\n  id,\n}: {\n  title: string;\n  description?: ReactNode;\n  children: ReactNode;\n  footer?: ReactNode;\n  tone?: \"neutral\" | \"danger\";\n  id?: string;\n}) {\n  const headingId = useId();\n  return (\n    <section\n      id={id}\n      aria-labelledby={headingId}\n      className={cn(\n        \"overflow-hidden rounded-[16px] border bg-[var(--bjork-surface)] shadow-[var(--bjork-shadow-surface)]\",\n        tone === \"danger\" ? \"border-[color:color-mix(in_oklab,var(--blk-error)_35%,var(--bjork-border))]\" : \"border-[color:var(--bjork-border)]\",\n      )}\n    >\n      <div className=\"px-4 pb-4 pt-4 @2xl/main:px-5 @2xl/main:pt-5\">\n        <h3 id={headingId} className={cn(\"text-[14.5px] font-semibold tracking-[-0.01em]\", tone === \"danger\" && \"text-[color:var(--blk-error)]\")}>\n          {title}\n        </h3>\n        {description && <p className=\"mt-1 text-[12.5px] leading-[1.5] text-[color:var(--bjork-text-muted)]\">{description}</p>}\n        <div className=\"mt-4\">{children}</div>\n      </div>\n      {footer && (\n        <div className=\"flex flex-wrap items-center justify-between gap-3 border-t border-[color:var(--bjork-border)] bg-[var(--bjork-panel)] px-4 py-3 text-[12.5px] text-[color:var(--bjork-text-muted)] @2xl/main:px-5\">\n          {footer}\n        </div>\n      )}\n    </section>\n  );\n}\n\nfunction SaveBar({\n  count,\n  saving,\n  onSave,\n  onDiscard,\n}: {\n  count: number;\n  saving: boolean;\n  onSave: () => void;\n  onDiscard: () => void;\n}) {\n  const visible = count > 0 || saving;\n  return (\n    <div\n      role=\"region\"\n      aria-label=\"Unsaved changes\"\n      aria-hidden={!visible}\n      inert={!visible}\n      className={cn(\n        \"pointer-events-none absolute inset-x-0 bottom-0 z-30 flex justify-center px-3 pb-3 transition-[opacity,transform] duration-[260ms] ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-opacity @3xl:pl-[232px]\",\n        visible ? \"translate-y-0 opacity-100\" : \"translate-y-3 opacity-0\",\n      )}\n    >\n      <div className=\"pointer-events-auto flex w-full max-w-[600px] items-center gap-3 rounded-[14px] border border-[color:var(--bjork-border-strong)] bg-[var(--bjork-menu)] py-2 pl-4 pr-2 shadow-[var(--bjork-shadow-menu)] backdrop-blur-xl\">\n        <span aria-hidden=\"true\" className=\"size-1.5 shrink-0 rounded-full bg-[var(--bjork-accent)]\" />\n        <p className=\"min-w-0 flex-1 truncate text-[13px] font-medium\" aria-live=\"polite\">\n          {saving ? \"Saving…\" : count > 1 ? \"Unsaved changes in 2 sections\" : \"You have unsaved changes\"}\n        </p>\n        <BlockButton variant=\"ghost\" size=\"sm\" onClick={onDiscard} disabled={saving}>\n          Discard\n        </BlockButton>\n        <BlockButton variant=\"primary\" size=\"sm\" onClick={onSave} disabled={saving} className=\"min-w-[72px]\">\n          {saving ? <BlockSpinner /> : \"Save\"}\n        </BlockButton>\n      </div>\n    </div>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Profile\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction ProfileSection({\n  draft,\n  saved,\n  errors,\n  liveErrors,\n  onChange,\n  onDelete,\n}: {\n  draft: SettingsProfile;\n  saved: SettingsProfile;\n  errors: Partial<Record<keyof SettingsProfile, string>>;\n  liveErrors: Partial<Record<keyof SettingsProfile, string>>;\n  onChange: (next: SettingsProfile) => void;\n  onDelete: () => void;\n}) {\n  // A field shows its error once it has been left, or after a failed save.\n  const [touched, setTouched] = useState<Partial<Record<keyof SettingsProfile, boolean>>>({});\n  const [avatar, setAvatar] = useState<string | null>(null);\n  const fileRef = useRef<HTMLInputElement>(null);\n  const bioId = useId();\n  const tzId = useId();\n  const set = <K extends keyof SettingsProfile>(key: K, value: SettingsProfile[K]) => onChange({ ...draft, [key]: value });\n  const errorFor = (key: keyof SettingsProfile) => errors[key] ?? (touched[key] ? liveErrors[key] : undefined) ?? null;\n  const blur = (key: keyof SettingsProfile) => () => setTouched((t) => ({ ...t, [key]: true }));\n\n  useEffect(() => {\n    return () => {\n      if (avatar) URL.revokeObjectURL(avatar);\n    };\n  }, [avatar]);\n\n  const emailChanged = draft.email.trim() !== saved.email;\n  const bioLeft = BIO_MAX - draft.bio.length;\n\n  return (\n    <>\n      <Card title=\"Public profile\" description=\"Shown on your comments, docs and in the member directory.\">\n        <div className=\"flex flex-col gap-5\">\n          <div className=\"flex items-center gap-4\">\n            {avatar ? (\n              // eslint-disable-next-line @next/next/no-img-element -- a local object URL preview\n              <img src={avatar} alt=\"\" className=\"size-16 shrink-0 rounded-full object-cover ring-1 ring-[color:var(--bjork-border)]\" />\n            ) : (\n              <InitialsAvatar name={draft.name || \"?\"} size={64} />\n            )}\n            <div className=\"flex min-w-0 flex-col gap-2\">\n              <div className=\"flex flex-wrap gap-2\">\n                <BlockButton size=\"sm\" variant=\"secondary\" onClick={() => fileRef.current?.click()}>\n                  <Upload aria-hidden=\"true\" />\n                  Upload photo\n                </BlockButton>\n                {avatar && (\n                  <BlockButton size=\"sm\" variant=\"ghost\" onClick={() => setAvatar(null)}>\n                    Remove\n                  </BlockButton>\n                )}\n              </div>\n              <p className=\"text-[12px] text-[color:var(--bjork-text-soft)]\">PNG or JPG, square works best.</p>\n              <input\n                ref={fileRef}\n                type=\"file\"\n                accept=\"image/png,image/jpeg,image/webp\"\n                className=\"sr-only\"\n                tabIndex={-1}\n                aria-hidden=\"true\"\n                onChange={(e) => {\n                  const file = e.target.files?.[0];\n                  if (file) setAvatar(URL.createObjectURL(file));\n                  e.target.value = \"\";\n                }}\n              />\n            </div>\n          </div>\n\n          <div className=\"grid grid-cols-1 gap-4 @xl/main:grid-cols-2\">\n            <BlockField\n              label=\"Full name\"\n              value={draft.name}\n              autoComplete=\"name\"\n              onChange={(e) => set(\"name\", e.target.value)}\n              onBlur={blur(\"name\")}\n              error={errorFor(\"name\")}\n            />\n            <div className=\"flex min-w-0 flex-col gap-1.5\">\n              <UsernameField\n                value={draft.username}\n                onChange={(v) => set(\"username\", v.toLowerCase())}\n                onBlur={blur(\"username\")}\n                error={errorFor(\"username\")}\n              />\n            </div>\n          </div>\n\n          <BlockField\n            label=\"Email\"\n            type=\"email\"\n            autoComplete=\"email\"\n            value={draft.email}\n            onChange={(e) => set(\"email\", e.target.value)}\n            onBlur={blur(\"email\")}\n            error={errorFor(\"email\")}\n            labelAside={\n              !emailChanged ? (\n                <span className=\"inline-flex items-center gap-1 text-[11.5px] font-medium text-[color:var(--blk-success)]\">\n                  <Check aria-hidden=\"true\" className=\"size-3\" />\n                  Verified\n                </span>\n              ) : undefined\n            }\n            hint={emailChanged ? `We'll send a confirmation link to the new address. ${saved.email} stays active until you click it.` : undefined}\n          />\n\n          <div className=\"flex flex-col gap-1.5\">\n            <div className=\"flex items-baseline justify-between\">\n              <label htmlFor={bioId} className=\"text-[12.5px] font-medium text-[color:var(--bjork-text-medium)]\">\n                Bio\n              </label>\n              <span\n                className={cn(\n                  \"font-mono text-[11px] tabular-nums\",\n                  bioLeft < 0 ? \"text-[color:var(--blk-error)]\" : bioLeft < 20 ? \"text-[color:var(--blk-warning)]\" : \"text-[color:var(--bjork-text-soft)]\",\n                )}\n                aria-hidden=\"true\"\n              >\n                {bioLeft}\n              </span>\n            </div>\n            <textarea\n              id={bioId}\n              rows={3}\n              value={draft.bio}\n              onChange={(e) => set(\"bio\", e.target.value)}\n              onBlur={blur(\"bio\")}\n              aria-invalid={errorFor(\"bio\") ? true : undefined}\n              aria-describedby={`${bioId}-note`}\n              className={cn(inputClass, \"h-auto resize-none py-2.5 leading-[1.5]\")}\n            />\n            <p id={`${bioId}-note`} className={cn(\"text-[12px]\", errorFor(\"bio\") ? \"text-[color:var(--blk-error)]\" : \"text-[color:var(--bjork-text-soft)]\")}>\n              {errorFor(\"bio\") ?? `${Math.max(0, bioLeft)} characters left. Links aren't clickable here.`}\n            </p>\n          </div>\n\n          <div className=\"flex flex-col gap-1.5\">\n            <label htmlFor={tzId} className=\"text-[12.5px] font-medium text-[color:var(--bjork-text-medium)]\">\n              Time zone\n            </label>\n            <select\n              id={tzId}\n              value={draft.timezone}\n              onChange={(e) => set(\"timezone\", e.target.value)}\n              className={cn(inputClass, \"cursor-pointer appearance-none bg-[length:12px] bg-[right_12px_center] bg-no-repeat pr-9\")}\n              style={{\n                backgroundImage:\n                  \"url(\\\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E\\\")\",\n              }}\n            >\n              {TIMEZONES.map((tz) => (\n                <option key={tz.id} value={tz.id}>\n                  {tz.label}\n                </option>\n              ))}\n            </select>\n            <p className=\"text-[12px] text-[color:var(--bjork-text-soft)]\">Used for due dates, digests and quiet hours.</p>\n          </div>\n        </div>\n      </Card>\n\n      <Card\n        tone=\"danger\"\n        title=\"Delete account\"\n        description=\"Removes your profile, your private docs and your access to every workspace. Shared docs stay with their workspace.\"\n      >\n        <BlockButton variant=\"danger\" size=\"sm\" onClick={onDelete}>\n          <Trash2 aria-hidden=\"true\" />\n          Delete account…\n        </BlockButton>\n      </Card>\n    </>\n  );\n}\n\nfunction UsernameField({\n  value,\n  onChange,\n  onBlur,\n  error,\n}: {\n  value: string;\n  onChange: (value: string) => void;\n  onBlur: () => void;\n  error: string | null;\n}) {\n  const id = useId();\n  return (\n    <>\n      <label htmlFor={id} className=\"text-[12.5px] font-medium text-[color:var(--bjork-text-medium)]\">\n        Username\n      </label>\n      <div\n        className={cn(\n          \"flex h-10 min-w-0 items-center overflow-hidden rounded-[10px] border bg-[var(--bjork-field)] shadow-[var(--bjork-shadow-soft)] transition-[border-color,box-shadow] duration-150 focus-within:ring-[3px]\",\n          error\n            ? \"border-[color:var(--blk-error)] focus-within:ring-[color:var(--blk-error-soft)]\"\n            : \"border-[color:var(--bjork-border)] hover:border-[color:var(--bjork-border-strong)] focus-within:border-[color:var(--bjork-accent)] focus-within:ring-[color:var(--bjork-accent-soft)]\",\n        )}\n      >\n        <span aria-hidden=\"true\" className=\"flex h-full shrink-0 items-center border-r border-[color:var(--bjork-border)] bg-[var(--bjork-field-inset)] px-2.5 font-mono text-[12px] text-[color:var(--bjork-text-soft)]\">\n          halcyon.app/\n        </span>\n        <input\n          id={id}\n          value={value}\n          onChange={(e) => onChange(e.target.value)}\n          onBlur={onBlur}\n          autoComplete=\"username\"\n          spellCheck={false}\n          aria-invalid={error ? true : undefined}\n          aria-describedby={`${id}-note`}\n          className=\"h-full min-w-0 flex-1 bg-transparent px-2.5 font-mono text-[13px] text-[color:var(--bjork-text)] outline-none\"\n        />\n      </div>\n      <p\n        id={`${id}-note`}\n        role={error ? \"alert\" : undefined}\n        className={cn(\"text-[12px] leading-[1.45]\", error ? \"text-[color:var(--blk-error)]\" : \"text-[color:var(--bjork-text-soft)]\")}\n      >\n        {error ?? \"Your profile link. Changing it redirects the old one for 30 days.\"}\n      </p>\n    </>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Notifications\n * -------------------------------------------------------------------------------------------------------- */\n\nconst HOURS = Array.from({ length: 24 }, (_, h) => `${String(h).padStart(2, \"0\")}:00`);\n\nfunction NotificationsSection({ draft, onChange }: { draft: NotificationPrefs; onChange: (next: NotificationPrefs) => void }) {\n  const fromId = useId();\n  const toId = useId();\n  const quietLabelId = useId();\n  const setChannel = (event: string, channel: NotificationChannel, on: boolean) =>\n    onChange({ ...draft, events: { ...draft.events, [event]: { ...draft.events[event], [channel]: on } } });\n  const allOn = (channel: NotificationChannel) =>\n    NOTIFICATION_EVENTS.every((e) => e.locked?.includes(channel) || draft.events[e.id]?.[channel]);\n  const setAll = (channel: NotificationChannel, on: boolean) => {\n    const events = { ...draft.events };\n    for (const e of NOTIFICATION_EVENTS) {\n      if (e.locked?.includes(channel)) continue;\n      events[e.id] = { ...events[e.id], [channel]: on };\n    }\n    onChange({ ...draft, events });\n  };\n\n  return (\n    <>\n      <Card title=\"Events\" description=\"Pick a channel per event. Security alerts always go to email.\">\n        <table className=\"w-full border-collapse text-left\">\n          <caption className=\"sr-only\">Notification channels per event</caption>\n          <thead>\n            <tr className=\"text-[11px] font-medium uppercase tracking-[0.08em] text-[color:var(--bjork-text-soft)]\">\n              <th scope=\"col\" className=\"pb-2 font-mono font-normal\">Event</th>\n              {([\"email\", \"push\"] as const).map((ch) => (\n                <th key={ch} scope=\"col\" className=\"w-[64px] pb-2 text-center font-mono font-normal @xl/main:w-[88px]\">\n                  <button\n                    type=\"button\"\n                    onClick={() => setAll(ch, !allOn(ch))}\n                    className={cn(\"rounded-[6px] px-1.5 py-0.5 uppercase hover:text-[color:var(--bjork-text)]\", focusRing)}\n                    aria-label={`${allOn(ch) ? \"Turn off\" : \"Turn on\"} all ${ch === \"email\" ? \"email\" : \"push\"} notifications`}\n                  >\n                    {ch === \"email\" ? \"Email\" : \"Push\"}\n                  </button>\n                </th>\n              ))}\n            </tr>\n          </thead>\n          <tbody>\n            {NOTIFICATION_EVENTS.map((e) => (\n              <tr key={e.id} className=\"border-t border-[color:var(--bjork-border-muted)]\">\n                <th scope=\"row\" className=\"py-3 pr-3 text-left font-normal\">\n                  <span className=\"block text-[13.5px] font-medium\">{e.label}</span>\n                  <span className=\"mt-0.5 block text-[12px] leading-[1.45] text-[color:var(--bjork-text-muted)]\">{e.hint}</span>\n                </th>\n                {([\"email\", \"push\"] as const).map((ch) => {\n                  const locked = e.locked?.includes(ch);\n                  return (\n                    <td key={ch} className=\"py-3 text-center\">\n                      <BlockSwitch\n                        checked={locked ? true : Boolean(draft.events[e.id]?.[ch])}\n                        disabled={locked}\n                        onCheckedChange={(on) => setChannel(e.id, ch, on)}\n                        label={`${e.label} by ${ch === \"email\" ? \"email\" : \"push\"}${locked ? \", always on\" : \"\"}`}\n                      />\n                    </td>\n                  );\n                })}\n              </tr>\n            ))}\n          </tbody>\n        </table>\n      </Card>\n\n      <Card title=\"Delivery\" description=\"How often batched email arrives.\">\n        <ChoiceGroup\n          label=\"Email delivery\"\n          value={draft.digest}\n          onChange={(digest) => onChange({ ...draft, digest })}\n          options={[\n            { id: \"instant\", label: \"As it happens\", hint: \"One email per event.\" },\n            { id: \"hourly\", label: \"Hourly bundle\", hint: \"At most one email an hour.\" },\n            { id: \"daily\", label: \"Daily digest\", hint: \"Every morning at 8:00.\" },\n          ]}\n        />\n      </Card>\n\n      <Card title=\"Quiet hours\" description=\"Push notifications wait until quiet hours end. Security alerts still come through.\">\n        <div className=\"flex flex-col gap-4\">\n          <div className=\"flex items-center justify-between gap-4\">\n            <span id={quietLabelId} className=\"text-[13.5px] font-medium\">\n              Pause push notifications overnight\n            </span>\n            <BlockSwitch\n              aria-labelledby={quietLabelId}\n              checked={draft.quietHours.enabled}\n              onCheckedChange={(enabled) => onChange({ ...draft, quietHours: { ...draft.quietHours, enabled } })}\n            />\n          </div>\n          <div className={cn(\"flex flex-wrap items-end gap-3 transition-opacity duration-150\", !draft.quietHours.enabled && \"opacity-45\")}>\n            {[\n              { id: fromId, key: \"from\" as const, label: \"From\" },\n              { id: toId, key: \"to\" as const, label: \"Until\" },\n            ].map((f) => (\n              <div key={f.key} className=\"flex flex-col gap-1.5\">\n                <label htmlFor={f.id} className=\"text-[12.5px] font-medium text-[color:var(--bjork-text-medium)]\">\n                  {f.label}\n                </label>\n                <select\n                  id={f.id}\n                  disabled={!draft.quietHours.enabled}\n                  value={draft.quietHours[f.key]}\n                  onChange={(e) => onChange({ ...draft, quietHours: { ...draft.quietHours, [f.key]: e.target.value } })}\n                  className={cn(inputClass, \"w-[120px] cursor-pointer font-mono tabular-nums\")}\n                >\n                  {HOURS.map((h) => (\n                    <option key={h} value={h}>\n                      {h}\n                    </option>\n                  ))}\n                </select>\n              </div>\n            ))}\n            <p className=\"pb-2.5 text-[12px] text-[color:var(--bjork-text-soft)]\">In your time zone.</p>\n          </div>\n        </div>\n      </Card>\n    </>\n  );\n}\n\n/** Radio cards with roving focus. */\nfunction ChoiceGroup<T extends string>({\n  label,\n  value,\n  onChange,\n  options,\n  columns = 3,\n}: {\n  label: string;\n  value: T;\n  onChange: (value: T) => void;\n  options: { id: T; label: string; hint?: string; visual?: ReactNode }[];\n  columns?: 2 | 3;\n}) {\n  const refs = useRef<(HTMLButtonElement | null)[]>([]);\n  const index = Math.max(0, options.findIndex((o) => o.id === value));\n  const onKeyDown = (event: ReactKeyboardEvent) => {\n    let next = index;\n    if (event.key === \"ArrowRight\" || event.key === \"ArrowDown\") next = (index + 1) % options.length;\n    else if (event.key === \"ArrowLeft\" || event.key === \"ArrowUp\") next = (index - 1 + options.length) % options.length;\n    else return;\n    event.preventDefault();\n    onChange(options[next].id);\n    refs.current[next]?.focus();\n  };\n  return (\n    <div\n      role=\"radiogroup\"\n      aria-label={label}\n      onKeyDown={onKeyDown}\n      className={cn(\"grid grid-cols-1 gap-2.5\", columns === 3 ? \"@xl/main:grid-cols-3\" : \"@md/main:grid-cols-2\")}\n    >\n      {options.map((o, i) => {\n        const checked = o.id === value;\n        return (\n          <button\n            key={o.id}\n            ref={(el) => {\n              refs.current[i] = el;\n            }}\n            type=\"button\"\n            role=\"radio\"\n            aria-checked={checked}\n            tabIndex={checked ? 0 : -1}\n            onClick={() => onChange(o.id)}\n            className={cn(\n              \"group relative flex cursor-pointer flex-col items-start gap-1 rounded-[12px] border p-3 text-left transition-[border-color,background-color,box-shadow] duration-150\",\n              checked\n                ? \"border-[color:var(--bjork-accent)] bg-[var(--bjork-accent-soft)] shadow-[0_0_0_1px_var(--bjork-accent)]\"\n                : \"border-[color:var(--bjork-border)] bg-[var(--bjork-field)] hover:border-[color:var(--bjork-border-strong)]\",\n              focusRing,\n            )}\n          >\n            {o.visual}\n            <span className=\"flex w-full items-center justify-between gap-2\">\n              <span className=\"text-[13px] font-medium\">{o.label}</span>\n              <span\n                aria-hidden=\"true\"\n                className={cn(\n                  \"grid size-4 place-items-center rounded-full border transition-colors duration-150\",\n                  checked ? \"border-[color:var(--blk-accent-fill)] bg-[var(--blk-accent-fill)]\" : \"border-[color:var(--bjork-border-strong)]\",\n                )}\n              >\n                {checked && <span className=\"size-1.5 rounded-full bg-[var(--blk-accent-fill-ink)]\" />}\n              </span>\n            </span>\n            {o.hint && <span className=\"text-[12px] leading-[1.4] text-[color:var(--bjork-text-muted)]\">{o.hint}</span>}\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Appearance\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction ThemeSwatch({ tone }: { tone: \"light\" | \"dark\" | \"split\" }) {\n  const light = { bg: \"#f7f3ea\", panel: \"#fffcf6\", line: \"#e1d7c8\", ink: \"#171717\" };\n  const dark = { bg: \"#111111\", panel: \"#1a1a1a\", line: \"#343434\", ink: \"#ededed\" };\n  const pane = (c: typeof light, x: number, w: number) => (\n    <g>\n      <rect x={x} y=\"0\" width={w} height=\"60\" fill={c.bg} />\n      <rect x={x + 8} y=\"8\" width={Math.min(26, w - 12)} height=\"44\" rx=\"4\" fill={c.panel} stroke={c.line} />\n      <rect x={x + 40} y=\"10\" width={Math.max(0, w - 50)} height=\"5\" rx=\"2.5\" fill={c.ink} opacity=\"0.75\" />\n      <rect x={x + 40} y=\"20\" width={Math.max(0, w - 62)} height=\"4\" rx=\"2\" fill={c.ink} opacity=\"0.25\" />\n      <rect x={x + 40} y=\"30\" width={Math.max(0, w - 56)} height=\"16\" rx=\"3\" fill={c.panel} stroke={c.line} />\n      <rect x={x + 44} y=\"36\" width=\"12\" height=\"4\" rx=\"2\" fill=\"#ec5c13\" />\n    </g>\n  );\n  return (\n    <svg viewBox=\"0 0 120 60\" aria-hidden=\"true\" className=\"mb-1.5 w-full overflow-hidden rounded-[8px] ring-1 ring-[color:var(--bjork-border)]\">\n      {tone === \"light\" && pane(light, 0, 120)}\n      {tone === \"dark\" && pane(dark, 0, 120)}\n      {tone === \"split\" && (\n        <>\n          <clipPath id=\"settings-split-l\">\n            <rect x=\"0\" y=\"0\" width=\"60\" height=\"60\" />\n          </clipPath>\n          <clipPath id=\"settings-split-r\">\n            <rect x=\"60\" y=\"0\" width=\"60\" height=\"60\" />\n          </clipPath>\n          <g clipPath=\"url(#settings-split-l)\">{pane(light, 0, 120)}</g>\n          <g clipPath=\"url(#settings-split-r)\">{pane(dark, 0, 120)}</g>\n        </>\n      )}\n    </svg>\n  );\n}\n\nfunction AppearanceSection({\n  theme,\n  density,\n  onTheme,\n  onDensity,\n}: {\n  theme: AppBlockTheme;\n  density: \"comfortable\" | \"compact\";\n  onTheme: (theme: AppBlockTheme) => void;\n  onDensity: (density: \"comfortable\" | \"compact\") => void;\n}) {\n  return (\n    <>\n      <Card title=\"Theme\" description=\"System follows your device and switches at sunset if it does.\">\n        <ChoiceGroup<AppBlockTheme>\n          label=\"Theme\"\n          value={theme}\n          onChange={onTheme}\n          options={[\n            { id: \"auto\", label: \"System\", visual: <ThemeSwatch tone=\"split\" />, hint: \"Match the device\" },\n            { id: \"light\", label: \"Light\", visual: <ThemeSwatch tone=\"light\" />, hint: \"Warm paper\" },\n            { id: \"dark\", label: \"Dark\", visual: <ThemeSwatch tone=\"dark\" />, hint: \"Low light\" },\n          ]}\n        />\n        <div className=\"mt-3 flex items-center gap-2 text-[12px] text-[color:var(--bjork-text-soft)]\">\n          <Monitor aria-hidden=\"true\" className=\"size-3.5\" />\n          <Sun aria-hidden=\"true\" className=\"size-3.5\" />\n          <Moon aria-hidden=\"true\" className=\"size-3.5\" />\n          <span>This preview re-themes as you choose.</span>\n        </div>\n      </Card>\n      <Card title=\"Density\" description=\"Compact tightens spacing in lists and settings.\">\n        <ChoiceGroup\n          label=\"Density\"\n          value={density}\n          onChange={onDensity}\n          columns={2}\n          options={[\n            { id: \"comfortable\", label: \"Comfortable\", hint: \"More room to breathe.\" },\n            { id: \"compact\", label: \"Compact\", hint: \"More rows on screen.\" },\n          ]}\n        />\n      </Card>\n    </>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Security\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction passwordScore(pw: string) {\n  const checks = [pw.length >= 12, /[a-z]/.test(pw) && /[A-Z]/.test(pw), /\\d/.test(pw), /[^A-Za-z0-9]/.test(pw)];\n  return checks.filter(Boolean).length;\n}\n\nfunction SecuritySection({\n  twoFactor,\n  sessions,\n  onChangePassword,\n  onTwoFactor,\n  onRevoke,\n  onRevokeOthers,\n}: {\n  twoFactor: boolean;\n  sessions: SettingsSession[];\n  onChangePassword: (current: string, next: string) => Promise<void>;\n  onTwoFactor: (next: boolean) => void;\n  onRevoke: (id: string) => void;\n  onRevokeOthers: () => void;\n}) {\n  const [current, setCurrent] = useState(\"\");\n  const [next, setNext] = useState(\"\");\n  const [confirm, setConfirm] = useState(\"\");\n  const [submitted, setSubmitted] = useState(false);\n  const [busy, setBusy] = useState(false);\n  const [serverError, setServerError] = useState<string | null>(null);\n  const currentRef = useRef<HTMLInputElement>(null);\n  const nextRef = useRef<HTMLInputElement>(null);\n  const confirmRef = useRef<HTMLInputElement>(null);\n  const twoFaLabel = useId();\n\n  const score = passwordScore(next);\n  const errs = {\n    current: !current ? \"Enter your current password.\" : serverError,\n    next: next.length < 12 ? \"Use at least 12 characters.\" : next === current ? \"Pick something different from your current password.\" : null,\n    confirm: confirm !== next ? \"The passwords don't match.\" : null,\n  };\n\n  const submit = async (event: FormEvent) => {\n    event.preventDefault();\n    setSubmitted(true);\n    setServerError(null);\n    const first = ([\"current\", \"next\", \"confirm\"] as const).find((k) => (k === \"current\" ? !current : errs[k]));\n    if (first) {\n      ({ current: currentRef, next: nextRef, confirm: confirmRef })[first].current?.focus();\n      return;\n    }\n    setBusy(true);\n    try {\n      await onChangePassword(current, next);\n      setCurrent(\"\");\n      setNext(\"\");\n      setConfirm(\"\");\n      setSubmitted(false);\n    } catch (error) {\n      setServerError(error instanceof Error ? error.message : \"Couldn't update the password.\");\n      currentRef.current?.focus();\n    } finally {\n      setBusy(false);\n    }\n  };\n\n  const meterLabel = [\"Too weak\", \"Weak\", \"Fair\", \"Good\", \"Strong\"][score];\n  const others = sessions.filter((s) => !s.current).length;\n\n  return (\n    <>\n      <Card title=\"Password\" description=\"Changing it keeps you signed in here. Try “wrong” as the current password to see the error.\">\n        <form noValidate onSubmit={submit} className=\"flex flex-col gap-4\">\n          <input type=\"text\" name=\"username\" autoComplete=\"username\" className=\"hidden\" defaultValue=\"\" aria-hidden=\"true\" tabIndex={-1} />\n          <BlockField\n            ref={currentRef}\n            label=\"Current password\"\n            type=\"password\"\n            autoComplete=\"current-password\"\n            value={current}\n            onChange={(e) => {\n              setCurrent(e.target.value);\n              setServerError(null);\n            }}\n            error={submitted || serverError ? errs.current : null}\n          />\n          <div className=\"grid grid-cols-1 gap-4 @xl/main:grid-cols-2\">\n            <div className=\"flex flex-col gap-2\">\n              <BlockField\n                ref={nextRef}\n                label=\"New password\"\n                type=\"password\"\n                autoComplete=\"new-password\"\n                value={next}\n                onChange={(e) => setNext(e.target.value)}\n                error={submitted ? errs.next : null}\n              />\n              <div className=\"flex items-center gap-2\" aria-hidden={next ? undefined : true}>\n                <div className=\"grid flex-1 grid-cols-4 gap-1\">\n                  {[1, 2, 3, 4].map((n) => (\n                    <span\n                      key={n}\n                      className=\"h-1 rounded-full transition-colors duration-200\"\n                      style={{\n                        background:\n                          next && score >= n\n                            ? score <= 1\n                              ? \"var(--blk-error)\"\n                              : score === 2\n                                ? \"var(--blk-warning)\"\n                                : \"var(--blk-success)\"\n                            : \"var(--bjork-surface-active)\",\n                      }}\n                    />\n                  ))}\n                </div>\n                <span className=\"w-[64px] text-right text-[11.5px] text-[color:var(--bjork-text-muted)]\" aria-live=\"polite\">\n                  {next ? meterLabel : \"\"}\n                </span>\n              </div>\n            </div>\n            <BlockField\n              ref={confirmRef}\n              label=\"Confirm new password\"\n              type=\"password\"\n              autoComplete=\"new-password\"\n              value={confirm}\n              onChange={(e) => setConfirm(e.target.value)}\n              error={submitted ? errs.confirm : null}\n            />\n          </div>\n          <div className=\"flex items-center justify-end gap-3\">\n            <BlockButton type=\"submit\" variant=\"primary\" size=\"sm\" disabled={busy} className=\"min-w-[132px]\">\n              {busy ? <BlockSpinner /> : (\n                <>\n                  <KeyRound aria-hidden=\"true\" />\n                  Update password\n                </>\n              )}\n            </BlockButton>\n          </div>\n        </form>\n      </Card>\n\n      <Card\n        title=\"Two-factor authentication\"\n        description=\"Ask for a code from an authenticator app when you sign in on a new device.\"\n        footer={\n          <>\n            <span className=\"inline-flex items-center gap-1.5\">\n              <span\n                aria-hidden=\"true\"\n                className=\"size-1.5 rounded-full\"\n                style={{ background: twoFactor ? \"var(--blk-success)\" : \"var(--blk-warning)\" }}\n              />\n              {twoFactor ? \"On, using an authenticator app\" : \"Off. Your account is protected by password only.\"}\n            </span>\n          </>\n        }\n      >\n        <div className=\"flex items-center justify-between gap-4\">\n          <span id={twoFaLabel} className=\"text-[13.5px] font-medium\">\n            Require a code at sign-in\n          </span>\n          <BlockSwitch aria-labelledby={twoFaLabel} checked={twoFactor} onCheckedChange={onTwoFactor} />\n        </div>\n      </Card>\n\n      <Card\n        title=\"Where you're signed in\"\n        description=\"Sign out anything you don't recognise, then change your password.\"\n        footer={\n          <>\n            <span>\n              {sessions.length} {sessions.length === 1 ? \"session\" : \"sessions\"}\n            </span>\n            <BlockButton size=\"sm\" variant=\"outline\" onClick={onRevokeOthers} disabled={others === 0}>\n              Sign out other sessions\n            </BlockButton>\n          </>\n        }\n      >\n        <ul className=\"-my-1 flex flex-col\">\n          {sessions.map((s) => {\n            const Icon = s.kind === \"mobile\" ? Smartphone : Laptop;\n            return (\n              <li key={s.id} className=\"flex items-center gap-3 border-t border-[color:var(--bjork-border-muted)] py-3 first:border-t-0\">\n                <span className=\"grid size-9 shrink-0 place-items-center rounded-[10px] border border-[color:var(--bjork-border)] bg-[var(--bjork-field-inset)]\">\n                  <Icon aria-hidden=\"true\" className=\"size-[17px] text-[color:var(--bjork-text-muted)]\" />\n                </span>\n                <div className=\"min-w-0 flex-1\">\n                  <p className=\"flex items-center gap-2 text-[13.5px] font-medium\">\n                    <span className=\"truncate\">{s.device}</span>\n                    {s.current && (\n                      <span className=\"shrink-0 rounded-[6px] bg-[var(--blk-success-soft)] px-1.5 py-px text-[11px] font-medium text-[color:var(--blk-success)]\">\n                        This device\n                      </span>\n                    )}\n                  </p>\n                  <p className=\"truncate text-[12px] text-[color:var(--bjork-text-muted)]\">\n                    {s.location} · {s.lastActive}\n                  </p>\n                </div>\n                {!s.current && (\n                  <BlockButton size=\"sm\" variant=\"ghost\" onClick={() => onRevoke(s.id)} aria-label={`Sign out ${s.device} in ${s.location}`}>\n                    Sign out\n                  </BlockButton>\n                )}\n              </li>\n            );\n          })}\n        </ul>\n      </Card>\n    </>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Billing\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction BillingSection({ invoices, onNotify }: { invoices: SettingsInvoice[]; onNotify: (message: string) => void }) {\n  const seats = { used: 12, total: 15 };\n  return (\n    <>\n      <Card\n        title=\"Plan\"\n        footer={\n          <>\n            <span>Renews on Nov 1, 2026</span>\n            <div className=\"flex gap-2\">\n              <BlockButton size=\"sm\" variant=\"ghost\" onClick={() => onNotify(\"Opening plan comparison\")}>\n                Compare plans\n              </BlockButton>\n              <BlockButton size=\"sm\" variant=\"secondary\" onClick={() => onNotify(\"Seat request sent to billing admin\")}>\n                Add seats\n              </BlockButton>\n            </div>\n          </>\n        }\n      >\n        <div className=\"flex flex-wrap items-end justify-between gap-4\">\n          <div>\n            <p className=\"font-mono text-[11px] uppercase tracking-[0.1em] text-[color:var(--blk-accent-ink)]\">Scale</p>\n            <p className=\"mt-1 flex items-baseline gap-1\">\n              <span className=\"font-bjork-display text-[32px] font-bold italic leading-none tracking-[-0.03em] tabular-nums\">$49</span>\n              <span className=\"text-[13px] text-[color:var(--bjork-text-muted)]\">per seat / month, billed monthly</span>\n            </p>\n          </div>\n          <div className=\"w-full max-w-[240px]\">\n            <div className=\"flex items-baseline justify-between text-[12px]\">\n              <span className=\"font-medium\">Seats</span>\n              <span className=\"font-mono tabular-nums text-[color:var(--bjork-text-muted)]\">\n                {seats.used} / {seats.total}\n              </span>\n            </div>\n            <div\n              role=\"meter\"\n              aria-label=\"Seats used\"\n              aria-valuemin={0}\n              aria-valuemax={seats.total}\n              aria-valuenow={seats.used}\n              aria-valuetext={`${seats.used} of ${seats.total} seats used`}\n              className=\"mt-2 grid h-2 gap-[3px]\"\n              style={{ gridTemplateColumns: `repeat(${seats.total}, minmax(0, 1fr))` }}\n            >\n              {Array.from({ length: seats.total }, (_, i) => (\n                <span\n                  key={i}\n                  className=\"rounded-[2px]\"\n                  style={{ background: i < seats.used ? \"var(--bjork-accent)\" : \"var(--bjork-surface-active)\" }}\n                />\n              ))}\n            </div>\n          </div>\n        </div>\n      </Card>\n\n      <Card\n        title=\"Payment method\"\n        footer={\n          <>\n            <span>Receipts go to billing@halcyon.app</span>\n            <BlockButton size=\"sm\" variant=\"secondary\" onClick={() => onNotify(\"Opening secure card form\")}>\n              Update card\n            </BlockButton>\n          </>\n        }\n      >\n        <div className=\"flex items-center gap-3\">\n          <span aria-hidden=\"true\" className=\"grid h-9 w-[54px] place-items-center rounded-[7px] bg-[#1a1f71] text-[11px] font-bold italic tracking-[0.02em] text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)]\">\n            VISA\n          </span>\n          <div>\n            <p className=\"font-mono text-[13.5px] tabular-nums\">\n              <span className=\"sr-only\">Visa ending in </span>\n              <span aria-hidden=\"true\">•••• </span>4242\n            </p>\n            <p className=\"text-[12px] text-[color:var(--bjork-text-muted)]\">Expires 08/28</p>\n          </div>\n        </div>\n      </Card>\n\n      <Card title=\"Invoices\">\n        <div className=\"-mx-1 overflow-x-auto\">\n          <table className=\"w-full min-w-[420px] border-collapse text-left text-[13px]\">\n            <caption className=\"sr-only\">Invoices</caption>\n            <thead>\n              <tr className=\"font-mono text-[11px] uppercase tracking-[0.08em] text-[color:var(--bjork-text-soft)]\">\n                <th scope=\"col\" className=\"px-1 pb-2 font-normal\">Invoice</th>\n                <th scope=\"col\" className=\"px-1 pb-2 font-normal\">Date</th>\n                <th scope=\"col\" className=\"px-1 pb-2 font-normal\">Status</th>\n                <th scope=\"col\" className=\"px-1 pb-2 text-right font-normal\">Amount</th>\n                <th scope=\"col\" className=\"w-10 px-1 pb-2 font-normal\">\n                  <span className=\"sr-only\">Download</span>\n                </th>\n              </tr>\n            </thead>\n            <tbody>\n              {invoices.map((inv) => (\n                <tr key={inv.id} className=\"border-t border-[color:var(--bjork-border-muted)]\">\n                  <td className=\"px-1 py-2.5 font-mono text-[12.5px] text-[color:var(--bjork-text-medium)]\">{inv.id}</td>\n                  <td className=\"whitespace-nowrap px-1 py-2.5\">{inv.date}</td>\n                  <td className=\"px-1 py-2.5\">\n                    <span\n                      className={cn(\n                        \"inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[11.5px] font-medium\",\n                        inv.status === \"paid\"\n                          ? \"bg-[var(--blk-success-soft)] text-[color:var(--blk-success)]\"\n                          : \"bg-[var(--blk-warning-soft)] text-[color:var(--blk-warning)]\",\n                      )}\n                    >\n                      {inv.status === \"paid\" ? \"Paid\" : \"Due Oct 15\"}\n                    </span>\n                  </td>\n                  <td className=\"px-1 py-2.5 text-right font-mono tabular-nums\">{inv.amount}</td>\n                  <td className=\"px-1 py-2.5 text-right\">\n                    <button\n                      type=\"button\"\n                      onClick={() => onNotify(`Downloading ${inv.id}.pdf`)}\n                      aria-label={`Download ${inv.id} as PDF`}\n                      title=\"Download PDF\"\n                      className={cn(\n                        \"inline-grid size-7 place-items-center rounded-[8px] text-[color:var(--bjork-text-muted)] transition-colors hover:bg-[var(--bjork-surface-hover)] hover:text-[color:var(--bjork-text)]\",\n                        focusRing,\n                      )}\n                    >\n                      <Download aria-hidden=\"true\" className=\"size-[15px]\" />\n                    </button>\n                  </td>\n                </tr>\n              ))}\n            </tbody>\n          </table>\n        </div>\n      </Card>\n    </>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Dialogs\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction DeleteAccountDialog({\n  open,\n  username,\n  onClose,\n  onConfirm,\n}: {\n  open: boolean;\n  username: string;\n  onClose: () => void;\n  onConfirm: () => void;\n}) {\n  const [typed, setTyped] = useState(\"\");\n  const matches = typed.trim() === username;\n  const close = () => {\n    setTyped(\"\");\n    onClose();\n  };\n  return (\n    <BlockDialog\n      open={open}\n      onClose={close}\n      tone=\"danger\"\n      title=\"Delete your account?\"\n      description={\n        <>\n          Your account is deactivated now and erased after 14 days. Sign in before then to cancel. To confirm, type{\" \"}\n          <strong className=\"font-mono font-medium text-[color:var(--bjork-text)]\">{username}</strong> below.\n        </>\n      }\n      footer={\n        <>\n          <BlockButton size=\"sm\" variant=\"ghost\" onClick={close}>\n            Cancel\n          </BlockButton>\n          <BlockButton\n            size=\"sm\"\n            variant=\"danger\"\n            disabled={!matches}\n            onClick={() => {\n              setTyped(\"\");\n              onConfirm();\n            }}\n          >\n            Delete account\n          </BlockButton>\n        </>\n      }\n    >\n      <form\n        onSubmit={(e) => {\n          e.preventDefault();\n          if (!matches) return;\n          setTyped(\"\");\n          onConfirm();\n        }}\n      >\n        <BlockField\n          data-autofocus\n          label=\"Username\"\n          value={typed}\n          onChange={(e) => setTyped(e.target.value)}\n          autoComplete=\"off\"\n          spellCheck={false}\n          inputClassName=\"font-mono\"\n          placeholder={username}\n        />\n      </form>\n    </BlockDialog>\n  );\n}\n\n/** A deterministic, QR-like pattern; the real block swaps in the provider's otpauth QR. */\nfunction FauxQr({ seed }: { seed: string }) {\n  const cells = useMemo(() => {\n    let h = 2166136261;\n    for (let i = 0; i < seed.length; i += 1) h = Math.imul(h ^ seed.charCodeAt(i), 16777619);\n    const out: boolean[] = [];\n    for (let i = 0; i < 21 * 21; i += 1) {\n      h = Math.imul(h ^ (h >>> 13), 0x5bd1e995);\n      out.push(((h >>> 7) & 1) === 1);\n    }\n    return out;\n  }, [seed]);\n  const finder = (x: number, y: number) =>\n    (x < 7 && y < 7) || (x > 13 && y < 7) || (x < 7 && y > 13);\n  return (\n    <svg viewBox=\"-2 -2 25 25\" aria-hidden=\"true\" className=\"size-[132px] rounded-[10px] bg-white p-1 shadow-[0_0_0_1px_var(--bjork-border)]\">\n      {cells.map((on, i) => {\n        const x = i % 21;\n        const y = Math.floor(i / 21);\n        if (finder(x, y) || !on) return null;\n        return <rect key={i} x={x} y={y} width=\"1\" height=\"1\" fill=\"#111\" />;\n      })}\n      {[\n        [0, 0],\n        [14, 0],\n        [0, 14],\n      ].map(([x, y]) => (\n        <g key={`${x}-${y}`}>\n          <rect x={x + 0.5} y={y + 0.5} width=\"6\" height=\"6\" fill=\"none\" stroke=\"#111\" />\n          <rect x={x + 2} y={y + 2} width=\"3\" height=\"3\" fill=\"#111\" />\n        </g>\n      ))}\n    </svg>\n  );\n}\n\nfunction TwoFactorDialog({\n  open,\n  email,\n  onClose,\n  onVerified,\n}: {\n  open: boolean;\n  email: string;\n  onClose: () => void;\n  onVerified: () => void;\n}) {\n  const [code, setCode] = useState(\"\");\n  const [error, setError] = useState<string | null>(null);\n  const [busy, setBusy] = useState(false);\n  const close = () => {\n    setCode(\"\");\n    setError(null);\n    onClose();\n  };\n  const verify = async () => {\n    if (code.length !== 6) {\n      setError(\"Enter the 6-digit code from your app.\");\n      return;\n    }\n    setBusy(true);\n    await new Promise((r) => setTimeout(r, 600));\n    setBusy(false);\n    if (code === \"000000\") {\n      setError(\"That code has expired. Codes change every 30 seconds.\");\n      return;\n    }\n    setCode(\"\");\n    setError(null);\n    onVerified();\n  };\n  return (\n    <BlockDialog\n      open={open}\n      onClose={close}\n      title=\"Set up two-factor authentication\"\n      description=\"Scan this with 1Password, Authy or Google Authenticator, then enter the code it shows.\"\n      footer={\n        <>\n          <BlockButton size=\"sm\" variant=\"ghost\" onClick={close}>\n            Cancel\n          </BlockButton>\n          <BlockButton size=\"sm\" variant=\"primary\" onClick={verify} disabled={busy} className=\"min-w-[96px]\">\n            {busy ? <BlockSpinner /> : \"Verify & turn on\"}\n          </BlockButton>\n        </>\n      }\n    >\n      <div className=\"flex flex-col items-center gap-4 @container\">\n        <FauxQr seed={email} />\n        <p className=\"text-center text-[12px] text-[color:var(--bjork-text-muted)]\">\n          Can&apos;t scan? Enter <span className=\"select-all font-mono text-[color:var(--bjork-text)]\">JBSW Y3DP EHPK 3PXP</span>\n        </p>\n        <form\n          className=\"w-full max-w-[220px]\"\n          onSubmit={(e) => {\n            e.preventDefault();\n            void verify();\n          }}\n        >\n          <BlockField\n            data-autofocus\n            label=\"6-digit code\"\n            inputMode=\"numeric\"\n            autoComplete=\"one-time-code\"\n            maxLength={6}\n            value={code}\n            onChange={(e) => {\n              setCode(e.target.value.replace(/\\D/g, \"\").slice(0, 6));\n              setError(null);\n            }}\n            error={error}\n            inputClassName=\"text-center font-mono text-[18px] tracking-[0.4em]\"\n            placeholder=\"••••••\"\n          />\n        </form>\n      </div>\n    </BlockDialog>\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/bjork-ui/blocks/app-settings.tsx"
    },
    {
      "path": "components/bjork-ui/blocks/app-block-kit.tsx",
      "content": "\"use client\";\n\nimport {\n  forwardRef,\n  useCallback,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n  useSyncExternalStore,\n  type ButtonHTMLAttributes,\n  type CSSProperties,\n  type InputHTMLAttributes,\n  type ReactNode,\n  type RefObject,\n} from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\nimport { useBjorkTone } from \"@/components/bjork-ui/_core/tone\";\nimport type { BjorkTone } from \"@/components/bjork-ui/_core/palette\";\nimport { cn } from \"@/lib/utils\";\n\n// Shared plumbing for the application blocks (app-*). Every block is a full layout that sizes itself to its\n// container, not the viewport, so it behaves the same pasted into a page, a dialog or a docs preview.\n\nexport type AppBlockTheme = \"light\" | \"dark\" | \"auto\";\n\n// The library tokens, so a forced theme works even when the page itself is in the other mode.\nconst TOKENS: Record<BjorkTone, Record<string, string>> = {\n  light: {\n    \"--bjork-bg\": \"#f7f3ea\",\n    \"--bjork-surface\": \"#fffcf6\",\n    \"--bjork-surface-muted\": \"rgba(250, 246, 237, 0.94)\",\n    \"--bjork-surface-hover\": \"#f5efe3\",\n    \"--bjork-surface-active\": \"#efe7d8\",\n    \"--bjork-panel\": \"#f8f2e7\",\n    \"--bjork-menu\": \"rgba(255, 252, 246, 0.98)\",\n    \"--bjork-field\": \"rgba(255, 252, 246, 0.96)\",\n    \"--bjork-field-muted\": \"rgba(248, 242, 231, 0.82)\",\n    \"--bjork-field-inset\": \"rgba(239, 231, 216, 0.72)\",\n    \"--bjork-error-bg\": \"#fff0e8\",\n    \"--bjork-text\": \"#171717\",\n    \"--bjork-text-strong\": \"rgba(23, 23, 23, 0.9)\",\n    \"--bjork-text-medium\": \"rgba(23, 23, 23, 0.72)\",\n    \"--bjork-text-muted\": \"rgba(23, 23, 23, 0.56)\",\n    \"--bjork-text-soft\": \"rgba(23, 23, 23, 0.46)\",\n    \"--bjork-text-faint\": \"rgba(23, 23, 23, 0.22)\",\n    \"--bjork-inverted-text\": \"#fff8f0\",\n    \"--bjork-border\": \"#eee6db\",\n    \"--bjork-border-muted\": \"#f5ede2\",\n    \"--bjork-border-strong\": \"#e1d7c8\",\n    \"--bjork-thumb\": \"#a49b8e\",\n    \"--bjork-track\": \"#ded6ca\",\n    \"--bjork-accent\": \"#ec7d43\",\n    \"--bjork-accent-hover\": \"#f0935f\",\n    \"--bjork-accent-soft\": \"rgba(236, 125, 67, 0.1)\",\n    \"--bjork-accent-muted\": \"rgba(236, 125, 67, 0.2)\",\n    \"--bjork-accent-foreground\": \"#3f2112\",\n    \"--bjork-shadow-surface\":\n      \"inset 0 7px 14px rgba(88, 72, 49, 0.045), inset 0 0.5px 0.5px rgba(255, 255, 255, 0.92), inset 1px 0 0 rgba(88, 72, 49, 0.026), inset -1px 0 0 rgba(255, 255, 255, 0.68), 0 14px 22px -9px rgba(66, 52, 33, 0.11)\",\n    \"--bjork-shadow-soft\": \"inset 0 1px 0 rgba(88, 72, 49, 0.045), inset 0 0.5px 0.5px rgba(255, 255, 255, 0.86)\",\n    \"--bjork-shadow-panel\":\n      \"inset 0 1px 0 rgba(88, 72, 49, 0.04), inset 1px 0 0 rgba(88, 72, 49, 0.024), inset -1px 0 0 rgba(255, 255, 255, 0.64), 0 18px 38px -30px rgba(66, 52, 33, 0.2)\",\n    \"--bjork-shadow-menu\":\n      \"inset 0 1px 0 rgba(88, 72, 49, 0.04), inset 0 12px 24px rgba(88, 72, 49, 0.022), inset 1px 0 0 rgba(88, 72, 49, 0.024), inset -1px 0 0 rgba(255, 255, 255, 0.62), 0 22px 44px -26px rgba(66, 52, 33, 0.22)\",\n    \"--bjork-shadow-inset\": \"inset 0 1px 10px rgba(88, 72, 49, 0.12), inset 0 0.5px 0.5px rgba(255, 255, 255, 0.72)\",\n    \"--bjork-ring-offset\": \"#f7f3ea\",\n  },\n  dark: {\n    \"--bjork-bg\": \"#111111\",\n    \"--bjork-surface\": \"#121212\",\n    \"--bjork-surface-muted\": \"rgba(22, 22, 22, 0.92)\",\n    \"--bjork-surface-hover\": \"#181818\",\n    \"--bjork-surface-active\": \"#202020\",\n    \"--bjork-panel\": \"#0d0d0d\",\n    \"--bjork-menu\": \"rgba(18, 18, 18, 0.98)\",\n    \"--bjork-field\": \"rgba(18, 18, 18, 0.95)\",\n    \"--bjork-field-muted\": \"rgba(18, 18, 18, 0.55)\",\n    \"--bjork-field-inset\": \"rgba(9, 9, 9, 0.75)\",\n    \"--bjork-error-bg\": \"#130d0a\",\n    \"--bjork-text\": \"#ededed\",\n    \"--bjork-text-strong\": \"rgba(237, 237, 237, 0.9)\",\n    \"--bjork-text-medium\": \"rgba(237, 237, 237, 0.72)\",\n    \"--bjork-text-muted\": \"rgba(237, 237, 237, 0.6)\",\n    \"--bjork-text-soft\": \"rgba(237, 237, 237, 0.4)\",\n    \"--bjork-text-faint\": \"rgba(237, 237, 237, 0.22)\",\n    \"--bjork-inverted-text\": \"#080808\",\n    \"--bjork-border\": \"#232323\",\n    \"--bjork-border-muted\": \"#1c1c1c\",\n    \"--bjork-border-strong\": \"#343434\",\n    \"--bjork-thumb\": \"#626262\",\n    \"--bjork-track\": \"#090909\",\n    \"--bjork-accent\": \"#ec5c13\",\n    \"--bjork-accent-hover\": \"#f07832\",\n    \"--bjork-accent-soft\": \"rgba(236, 92, 19, 0.12)\",\n    \"--bjork-accent-muted\": \"rgba(236, 92, 19, 0.24)\",\n    \"--bjork-accent-foreground\": \"#fff2ea\",\n    \"--bjork-shadow-surface\":\n      \"inset 0 7px 14px rgba(255, 255, 255, 0.03), inset 0 0.5px 0.5px rgba(255, 255, 255, 0.06), 0 14px 20px -6px rgba(0, 0, 0, 0.45)\",\n    \"--bjork-shadow-soft\": \"inset 0 1px 0 rgba(255, 255, 255, 0.045)\",\n    \"--bjork-shadow-panel\": \"inset 0 1px 0 rgba(255, 255, 255, 0.035), 0 18px 36px -28px rgba(0, 0, 0, 0.9)\",\n    \"--bjork-shadow-menu\":\n      \"inset 0 1px 0 rgba(255, 255, 255, 0.055), inset 0 12px 24px rgba(255, 255, 255, 0.018), inset 0 -18px 26px rgba(0, 0, 0, 0.24), 0 22px 42px -22px rgba(0, 0, 0, 0.9)\",\n    \"--bjork-shadow-inset\": \"inset 0 1px 10px rgba(0, 0, 0, 0.45)\",\n    \"--bjork-ring-offset\": \"#080808\",\n  },\n};\n\n// Block-only tokens the global sheet does not carry: status inks, a readable accent ink and the scrim.\nconst EXTRAS: Record<BjorkTone, Record<string, string>> = {\n  light: {\n    \"--blk-accent-ink\": \"#b4531f\",\n    \"--blk-accent-fill\": \"#e0692c\",\n    \"--blk-accent-fill-ink\": \"#fffaf5\",\n    \"--blk-success\": \"#1f8a55\",\n    \"--blk-success-soft\": \"rgba(31, 138, 85, 0.1)\",\n    \"--blk-warning\": \"#9a6200\",\n    \"--blk-warning-soft\": \"rgba(168, 107, 0, 0.1)\",\n    \"--blk-error\": \"#c8361f\",\n    \"--blk-error-soft\": \"rgba(200, 54, 31, 0.08)\",\n    \"--blk-scrim\": \"rgba(40, 32, 22, 0.28)\",\n    \"--blk-chart-ghost\": \"rgba(23, 23, 23, 0.28)\",\n  },\n  dark: {\n    \"--blk-accent-ink\": \"#f07832\",\n    \"--blk-accent-fill\": \"#c94f12\",\n    \"--blk-accent-fill-ink\": \"#fff2ea\",\n    \"--blk-success\": \"#4cc38a\",\n    \"--blk-success-soft\": \"rgba(76, 195, 138, 0.12)\",\n    \"--blk-warning\": \"#f2b544\",\n    \"--blk-warning-soft\": \"rgba(242, 181, 68, 0.12)\",\n    \"--blk-error\": \"#ff6a5c\",\n    \"--blk-error-soft\": \"rgba(255, 92, 77, 0.1)\",\n    \"--blk-scrim\": \"rgba(0, 0, 0, 0.55)\",\n    \"--blk-chart-ghost\": \"rgba(237, 237, 237, 0.3)\",\n  },\n};\n\nconst subscribeNoop = () => () => {};\n\n/** True after hydration. Server and first client render agree on false. */\nexport function useHydrated() {\n  return useSyncExternalStore(\n    subscribeNoop,\n    () => true,\n    () => false,\n  );\n}\n\n/** Reduced motion, read only after hydration so the first render matches the server. */\nexport function useBlockReducedMotion() {\n  const hydrated = useHydrated();\n  const reduced = useReducedMotion();\n  return hydrated && reduced === true;\n}\n\n/**\n * Resolves a block's theme to inline custom properties. \"auto\" leaves the library tokens to the page\n * (no flash on load) and only adds the block extras for the resolved tone; \"light\" and \"dark\" pin every token.\n */\nexport function useAppBlockTheme(theme: AppBlockTheme = \"auto\") {\n  const forced = theme === \"auto\" ? undefined : theme;\n  const tone = useBjorkTone(forced);\n  const style = {\n    ...(forced ? TOKENS[forced] : {}),\n    ...EXTRAS[tone],\n    colorScheme: tone,\n  } as CSSProperties;\n  return { tone, style };\n}\n\n/** Width of an element, tracked with ResizeObserver. 0 until measured. */\nexport function useElementWidth(ref: RefObject<HTMLElement | null>) {\n  const [width, setWidth] = useState(0);\n  useLayoutEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    setWidth(el.getBoundingClientRect().width);\n    if (typeof ResizeObserver === \"undefined\") return;\n    const ro = new ResizeObserver(([entry]) => setWidth(entry.contentRect.width));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [ref]);\n  return width;\n}\n\nexport const focusRing =\n  \"outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--bjork-accent)] focus-visible:ring-offset-2 focus-visible:ring-offset-[color:var(--bjork-ring-offset)]\";\n\nexport const blockRoot =\n  \"@container relative isolate flex min-h-0 w-full overflow-hidden bg-[var(--bjork-bg)] font-bjork-alpha text-[color:var(--bjork-text)] antialiased selection:bg-[color:var(--bjork-accent-muted)]\";\n\ntype ButtonVariant = \"primary\" | \"secondary\" | \"ghost\" | \"danger\" | \"outline\";\ntype ButtonSize = \"sm\" | \"md\" | \"lg\";\n\nconst BUTTON_VARIANTS: Record<ButtonVariant, string> = {\n  primary:\n    \"bg-[var(--blk-accent-fill)] text-[color:var(--blk-accent-fill-ink)] shadow-[inset_0_1px_0_rgba(255,255,255,0.22),0_1px_2px_rgba(0,0,0,0.18)] hover:brightness-[1.08]\",\n  secondary:\n    \"border border-[color:var(--bjork-border)] bg-[var(--bjork-surface)] text-[color:var(--bjork-text)] shadow-[var(--bjork-shadow-soft)] hover:bg-[var(--bjork-surface-hover)]\",\n  outline:\n    \"border border-[color:var(--bjork-border-strong)] bg-transparent text-[color:var(--bjork-text)] hover:bg-[var(--bjork-surface-hover)]\",\n  ghost:\n    \"bg-transparent text-[color:var(--bjork-text-medium)] hover:bg-[var(--bjork-surface-hover)] hover:text-[color:var(--bjork-text)]\",\n  danger:\n    \"bg-[var(--blk-error)] text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] hover:brightness-[1.08]\",\n};\n\nconst BUTTON_SIZES: Record<ButtonSize, string> = {\n  sm: \"h-8 gap-1.5 rounded-[9px] px-2.5 text-[12.5px]\",\n  md: \"h-9 gap-2 rounded-[10px] px-3.5 text-[13px]\",\n  lg: \"h-11 gap-2 rounded-[12px] px-4 text-[14px]\",\n};\n\nexport interface BlockButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {\n  variant?: ButtonVariant;\n  size?: ButtonSize;\n}\n\nexport const BlockButton = forwardRef<HTMLButtonElement, BlockButtonProps>(function BlockButton(\n  { variant = \"secondary\", size = \"md\", className, type = \"button\", ...props },\n  ref,\n) {\n  return (\n    <button\n      ref={ref}\n      type={type}\n      className={cn(\n        \"inline-flex shrink-0 cursor-pointer select-none items-center justify-center whitespace-nowrap font-medium tracking-[-0.01em] transition-[background-color,color,filter,transform,border-color] duration-150 ease-out active:scale-[0.97] disabled:pointer-events-none disabled:opacity-40 motion-reduce:transition-none motion-reduce:active:scale-100 [&_svg]:size-4 [&_svg]:shrink-0\",\n        focusRing,\n        BUTTON_VARIANTS[variant],\n        BUTTON_SIZES[size],\n        className,\n      )}\n      {...props}\n    />\n  );\n});\n\nexport interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {\n  /** Accessible name. Also used as the native tooltip. */\n  label: string;\n  size?: \"sm\" | \"md\";\n  pressed?: boolean;\n}\n\nexport const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(\n  { label, size = \"md\", pressed, className, type = \"button\", children, ...props },\n  ref,\n) {\n  return (\n    <button\n      ref={ref}\n      type={type}\n      aria-label={label}\n      title={label}\n      aria-pressed={pressed}\n      className={cn(\n        \"inline-grid shrink-0 cursor-pointer place-items-center rounded-[9px] text-[color:var(--bjork-text-muted)] transition-[background-color,color,transform] duration-150 ease-out hover:bg-[var(--bjork-surface-hover)] hover:text-[color:var(--bjork-text)] active:scale-[0.94] disabled:pointer-events-none disabled:opacity-40 motion-reduce:transition-none motion-reduce:active:scale-100 aria-pressed:text-[color:var(--blk-accent-ink)] [&_svg]:shrink-0\",\n        size === \"sm\" ? \"size-7 [&_svg]:size-[15px]\" : \"size-9 [&_svg]:size-[17px]\",\n        focusRing,\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </button>\n  );\n});\n\nexport function Kbd({ children, className }: { children: ReactNode; className?: string }) {\n  return (\n    <kbd\n      className={cn(\n        \"inline-flex h-5 min-w-5 items-center justify-center rounded-[5px] border border-[color:var(--bjork-border-strong)] bg-[var(--bjork-surface)] px-1 font-mono text-[11px] font-medium leading-none text-[color:var(--bjork-text-muted)] shadow-[0_1px_0_var(--bjork-border-strong)]\",\n        className,\n      )}\n    >\n      {children}\n    </kbd>\n  );\n}\n\nexport const inputClass =\n  \"h-10 w-full min-w-0 rounded-[10px] border border-[color:var(--bjork-border)] bg-[var(--bjork-field)] px-3 text-[13.5px] text-[color:var(--bjork-text)] shadow-[var(--bjork-shadow-soft)] outline-none transition-[border-color,box-shadow,background-color] duration-150 placeholder:text-[color:var(--bjork-text-soft)] hover:border-[color:var(--bjork-border-strong)] focus-visible:border-[color:var(--bjork-accent)] focus-visible:ring-[3px] focus-visible:ring-[color:var(--bjork-accent-soft)] aria-[invalid=true]:border-[color:var(--blk-error)] aria-[invalid=true]:focus-visible:ring-[color:var(--blk-error-soft)] disabled:cursor-not-allowed disabled:opacity-50\";\n\nexport interface BlockFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, \"children\"> {\n  label: string;\n  hint?: ReactNode;\n  error?: string | null;\n  /** Rendered at the right of the label row, e.g. a \"Forgot?\" link. */\n  labelAside?: ReactNode;\n  /** Rendered inside the field on the right, e.g. a show/hide toggle. */\n  trailing?: ReactNode;\n  className?: string;\n  inputClassName?: string;\n}\n\n/** Label, input, hint and error wired together with ids. The error replaces the hint and is announced. */\nexport const BlockField = forwardRef<HTMLInputElement, BlockFieldProps>(function BlockField(\n  { label, hint, error, labelAside, trailing, className, inputClassName, id, ...props },\n  ref,\n) {\n  const autoId = useId();\n  const inputId = id ?? autoId;\n  const noteId = `${inputId}-note`;\n  const hasNote = Boolean(error) || hint !== undefined;\n  return (\n    <div className={cn(\"flex min-w-0 flex-col gap-1.5\", className)}>\n      <div className=\"flex items-baseline justify-between gap-3\">\n        <label htmlFor={inputId} className=\"text-[12.5px] font-medium text-[color:var(--bjork-text-medium)]\">\n          {label}\n        </label>\n        {labelAside}\n      </div>\n      <div className=\"relative\">\n        <input\n          ref={ref}\n          id={inputId}\n          aria-invalid={error ? true : undefined}\n          aria-describedby={hasNote ? noteId : undefined}\n          className={cn(inputClass, trailing ? \"pr-10\" : undefined, inputClassName)}\n          {...props}\n        />\n        {trailing && <div className=\"absolute inset-y-0 right-1 flex items-center\">{trailing}</div>}\n      </div>\n      {hasNote && (\n        <p\n          id={noteId}\n          role={error ? \"alert\" : undefined}\n          className={cn(\n            \"flex items-start gap-1.5 text-[12px] leading-[1.45]\",\n            error ? \"text-[color:var(--blk-error)]\" : \"text-[color:var(--bjork-text-soft)]\",\n          )}\n        >\n          {error ? (\n            <>\n              <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" className=\"mt-[2px] size-3 shrink-0\">\n                <circle cx=\"8\" cy=\"8\" r=\"6.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n                <path d=\"M8 4.75v3.75M8 10.9v.1\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n              </svg>\n              {error}\n            </>\n          ) : (\n            hint\n          )}\n        </p>\n      )}\n    </div>\n  );\n});\n\n/** Initials avatar on a quiet tinted disc. Hue comes from the name so a person keeps their colour. */\nexport function InitialsAvatar({\n  name,\n  size = 28,\n  className,\n}: {\n  name: string;\n  size?: number;\n  className?: string;\n}) {\n  const initials = name\n    .split(/\\s+/)\n    .filter(Boolean)\n    .slice(0, 2)\n    .map((part) => part[0]?.toUpperCase())\n    .join(\"\");\n  let hash = 0;\n  for (let i = 0; i < name.length; i += 1) hash = (hash * 31 + name.charCodeAt(i)) >>> 0;\n  const hue = [22, 38, 150, 200, 260, 330][hash % 6];\n  return (\n    <span\n      aria-hidden=\"true\"\n      className={cn(\n        \"inline-grid shrink-0 place-items-center rounded-full font-semibold tracking-[-0.02em] text-[color:var(--bjork-text)]\",\n        className,\n      )}\n      style={{\n        width: size,\n        height: size,\n        fontSize: Math.max(11, Math.round(size * 0.38)),\n        background: `color-mix(in oklab, hsl(${hue} 70% 55%) 22%, var(--bjork-surface-active))`,\n        boxShadow: `inset 0 0 0 1px color-mix(in oklab, hsl(${hue} 70% 55%) 24%, transparent)`,\n      }}\n    >\n      {initials}\n    </span>\n  );\n}\n\nconst FOCUSABLE =\n  'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Keeps focus inside `ref` while `active`, closes on Escape, and hands focus back to whatever had it\n * before. Used by the in-block drawers and dialogs, which are positioned inside the block rather than portalled,\n * so a forced theme reaches them.\n */\nexport function useFocusTrap(ref: RefObject<HTMLElement | null>, active: boolean, onEscape: () => void) {\n  const escapeRef = useRef(onEscape);\n  useLayoutEffect(() => {\n    escapeRef.current = onEscape;\n  });\n  useEffect(() => {\n    if (!active) return;\n    const node = ref.current;\n    if (!node) return;\n    const previous = document.activeElement as HTMLElement | null;\n    const first = node.querySelector<HTMLElement>(\"[data-autofocus]\") ?? node.querySelector<HTMLElement>(FOCUSABLE);\n    (first ?? node).focus({ preventScroll: true });\n    const onKey = (event: KeyboardEvent) => {\n      if (event.key === \"Escape\") {\n        event.stopPropagation();\n        escapeRef.current();\n        return;\n      }\n      if (event.key !== \"Tab\") return;\n      const items = Array.from(node.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(\n        (el) => el.offsetParent !== null || el === document.activeElement,\n      );\n      if (items.length === 0) return;\n      const head = items[0];\n      const tail = items[items.length - 1];\n      if (event.shiftKey && document.activeElement === head) {\n        event.preventDefault();\n        tail.focus();\n      } else if (!event.shiftKey && document.activeElement === tail) {\n        event.preventDefault();\n        head.focus();\n      }\n    };\n    node.addEventListener(\"keydown\", onKey);\n    return () => {\n      node.removeEventListener(\"keydown\", onKey);\n      if (previous && document.contains(previous)) previous.focus({ preventScroll: true });\n    };\n  }, [active, ref]);\n}\n\nexport interface BlockDrawerProps {\n  open: boolean;\n  onClose: () => void;\n  side?: \"left\" | \"right\";\n  /** Accessible name of the dialog. */\n  label: string;\n  children: ReactNode;\n  className?: string;\n}\n\n/**\n * A modal drawer anchored to the block, not the viewport. Under reduced motion it fades instead of sliding.\n * The block's own content should be marked `inert` while it is open.\n */\nexport function BlockDrawer({ open, onClose, side = \"left\", label, children, className }: BlockDrawerProps) {\n  const panelRef = useRef<HTMLDivElement>(null);\n  const reduce = useBlockReducedMotion();\n  useFocusTrap(panelRef, open, onClose);\n  const hidden = side === \"left\" ? \"-translate-x-full\" : \"translate-x-full\";\n  return (\n    <div className={cn(\"absolute inset-0 z-40\", open ? \"pointer-events-auto\" : \"pointer-events-none\")} aria-hidden={!open}>\n      <div\n        className={cn(\n          \"absolute inset-0 bg-[var(--blk-scrim)] transition-opacity duration-200 ease-out\",\n          open ? \"opacity-100\" : \"opacity-0\",\n        )}\n        onClick={onClose}\n      />\n      <div\n        ref={panelRef}\n        role=\"dialog\"\n        aria-modal=\"true\"\n        aria-label={label}\n        tabIndex={-1}\n        inert={!open}\n        className={cn(\n          \"absolute inset-y-0 flex w-[min(300px,86%)] flex-col bg-[var(--bjork-surface)] shadow-[var(--bjork-shadow-menu)] outline-none\",\n          side === \"left\" ? \"left-0 border-r\" : \"right-0 border-l\",\n          \"border-[color:var(--bjork-border)]\",\n          reduce\n            ? cn(\"transition-opacity duration-150\", open ? \"opacity-100\" : \"opacity-0\")\n            : cn(\n                \"transition-transform duration-[280ms] ease-[cubic-bezier(0.32,0.72,0,1)]\",\n                open ? \"translate-x-0\" : hidden,\n              ),\n          className,\n        )}\n      >\n        {children}\n      </div>\n    </div>\n  );\n}\n\n/** Polite status text for screen readers; changes are announced once. */\nexport function useAnnouncer() {\n  const [message, setMessage] = useState(\"\");\n  const announce = useCallback((next: string) => {\n    // Clearing first makes a repeated message announce again.\n    setMessage(\"\");\n    window.requestAnimationFrame(() => setMessage(next));\n  }, []);\n  const region = (\n    <span role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" className=\"sr-only\">\n      {message}\n    </span>\n  );\n  return { announce, region };\n}\n\n/** A small toast pinned to the bottom of the block. Purely visual; pair it with `useAnnouncer`. */\nexport function BlockToast({ message, tone = \"neutral\" }: { message: string | null; tone?: \"neutral\" | \"success\" | \"error\" }) {\n  const reduce = useBlockReducedMotion();\n  const dot =\n    tone === \"success\" ? \"var(--blk-success)\" : tone === \"error\" ? \"var(--blk-error)\" : \"var(--bjork-accent)\";\n  return (\n    <div className=\"pointer-events-none absolute inset-x-0 bottom-4 z-50 flex justify-center px-4\" aria-hidden=\"true\">\n      <div\n        className={cn(\n          \"flex max-w-full items-center gap-2.5 rounded-full border border-[color:var(--bjork-border)] bg-[var(--bjork-menu)] py-2 pl-3 pr-4 text-[12.5px] font-medium text-[color:var(--bjork-text)] shadow-[var(--bjork-shadow-menu)] backdrop-blur-xl\",\n          reduce ? \"transition-opacity duration-150\" : \"transition-[opacity,transform] duration-200 ease-out\",\n          message ? \"translate-y-0 opacity-100\" : \"translate-y-2 opacity-0\",\n        )}\n      >\n        <span className=\"size-1.5 shrink-0 rounded-full\" style={{ background: dot }} />\n        <span className=\"truncate\">{message}</span>\n      </div>\n    </div>\n  );\n}\n\n/** Shows a toast for `ms` and announces it. */\nexport function useBlockToast(ms = 2600) {\n  const { announce, region } = useAnnouncer();\n  const [toast, setToast] = useState<{ message: string; tone: \"neutral\" | \"success\" | \"error\" } | null>(null);\n  const timer = useRef<number | undefined>(undefined);\n  const show = useCallback(\n    (message: string, tone: \"neutral\" | \"success\" | \"error\" = \"neutral\") => {\n      window.clearTimeout(timer.current);\n      setToast({ message, tone });\n      announce(message);\n      timer.current = window.setTimeout(() => setToast(null), ms);\n    },\n    [announce, ms],\n  );\n  useEffect(() => () => window.clearTimeout(timer.current), []);\n  const node = (\n    <>\n      <BlockToast message={toast?.message ?? null} tone={toast?.tone} />\n      {region}\n    </>\n  );\n  return { show, node };\n}\n\nexport interface BlockDialogProps {\n  open: boolean;\n  onClose: () => void;\n  /** Visible title; also the dialog's accessible name. */\n  title: string;\n  description?: ReactNode;\n  children?: ReactNode;\n  /** Buttons for the footer, right-aligned. */\n  footer?: ReactNode;\n  tone?: \"neutral\" | \"danger\";\n  className?: string;\n}\n\n/**\n * A modal dialog positioned inside the block (not portalled), so a forced theme reaches it. Traps focus, closes\n * on Escape or a scrim click, and returns focus to the trigger. Mark the block's own content `inert` while open.\n */\nexport function BlockDialog({ open, onClose, title, description, children, footer, tone = \"neutral\", className }: BlockDialogProps) {\n  const panelRef = useRef<HTMLDivElement>(null);\n  const reduce = useBlockReducedMotion();\n  const titleId = useId();\n  const descId = useId();\n  useFocusTrap(panelRef, open, onClose);\n  return (\n    <div\n      className={cn(\"absolute inset-0 z-50 grid place-items-center p-4\", open ? \"pointer-events-auto\" : \"pointer-events-none\")}\n      aria-hidden={!open}\n    >\n      <div\n        className={cn(\n          \"absolute inset-0 bg-[var(--blk-scrim)] transition-opacity duration-200 ease-out\",\n          open ? \"opacity-100\" : \"opacity-0\",\n        )}\n        onClick={onClose}\n      />\n      <div\n        ref={panelRef}\n        role={tone === \"danger\" ? \"alertdialog\" : \"dialog\"}\n        aria-modal=\"true\"\n        aria-labelledby={titleId}\n        aria-describedby={description ? descId : undefined}\n        tabIndex={-1}\n        inert={!open}\n        className={cn(\n          \"relative flex max-h-full w-full max-w-[440px] flex-col overflow-hidden rounded-[18px] border border-[color:var(--bjork-border)] bg-[var(--bjork-surface)] shadow-[var(--bjork-shadow-menu)] outline-none\",\n          reduce\n            ? cn(\"transition-opacity duration-150\", open ? \"opacity-100\" : \"opacity-0\")\n            : cn(\n                \"transition-[opacity,transform] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)]\",\n                open ? \"scale-100 opacity-100\" : \"scale-[0.97] opacity-0\",\n              ),\n          className,\n        )}\n      >\n        <div className=\"overflow-y-auto px-5 pb-4 pt-5\">\n          <h2 id={titleId} className=\"text-[16px] font-semibold tracking-[-0.015em]\">\n            {title}\n          </h2>\n          {description && (\n            <div id={descId} className=\"mt-1.5 text-[13px] leading-[1.55] text-[color:var(--bjork-text-muted)]\">\n              {description}\n            </div>\n          )}\n          {children && <div className=\"mt-4\">{children}</div>}\n        </div>\n        {footer && (\n          <div className=\"flex flex-wrap items-center justify-end gap-2 border-t border-[color:var(--bjork-border)] bg-[var(--bjork-panel)] px-5 py-3\">\n            {footer}\n          </div>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport interface BlockSwitchProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, \"onChange\"> {\n  checked: boolean;\n  onCheckedChange: (checked: boolean) => void;\n  /** Accessible name when there is no visible label wired with aria-labelledby. */\n  label?: string;\n}\n\n/** A role=\"switch\" toggle. Space and Enter flip it; it reads as on/off to assistive tech. */\nexport const BlockSwitch = forwardRef<HTMLButtonElement, BlockSwitchProps>(function BlockSwitch(\n  { checked, onCheckedChange, label, className, disabled, ...props },\n  ref,\n) {\n  return (\n    <button\n      ref={ref}\n      type=\"button\"\n      role=\"switch\"\n      aria-checked={checked}\n      aria-label={label}\n      disabled={disabled}\n      onClick={() => onCheckedChange(!checked)}\n      className={cn(\n        \"relative inline-flex h-[22px] w-[38px] shrink-0 cursor-pointer items-center rounded-full border transition-[background-color,border-color] duration-200 ease-out disabled:cursor-not-allowed disabled:opacity-45 motion-reduce:transition-none\",\n        checked\n          ? \"border-transparent bg-[var(--blk-accent-fill)]\"\n          : \"border-[color:var(--bjork-border-strong)] bg-[var(--bjork-field-inset)] shadow-[var(--bjork-shadow-inset)]\",\n        focusRing,\n        className,\n      )}\n      {...props}\n    >\n      <span\n        aria-hidden=\"true\"\n        className={cn(\n          \"absolute left-[2px] size-4 rounded-full bg-white shadow-[0_1px_2px_rgba(0,0,0,0.3)] transition-transform duration-200 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none\",\n          checked ? \"translate-x-4\" : \"translate-x-0\",\n        )}\n      />\n    </button>\n  );\n});\n\nexport function BlockSpinner({ className }: { className?: string }) {\n  return (\n    <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" className={cn(\"animate-spin motion-reduce:animate-[spin_1.6s_linear_infinite]\", className)}>\n      <circle cx=\"8\" cy=\"8\" r=\"6\" fill=\"none\" stroke=\"currentColor\" strokeOpacity=\"0.25\" strokeWidth=\"1.8\" />\n      <path d=\"M14 8a6 6 0 0 0-6-6\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/bjork-ui/blocks/app-block-kit.tsx"
    },
    {
      "path": "components/bjork-ui/_core/tone.ts",
      "content": "\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\nimport { useTheme } from \"next-themes\";\nimport type { BjorkTone } from \"./palette\";\n\nconst subscribeNoop = () => () => {};\nconst getMounted = () => true;\nconst getServerMounted = () => false;\n\n/**\n * Resolves the tone for a component. An explicit `tone` always wins.\n * Otherwise it follows next-themes' resolved theme, but only after mount,\n * so the server render and first client render agree on dark.\n */\nexport function useBjorkTone(tone?: BjorkTone): BjorkTone {\n  const { resolvedTheme } = useTheme();\n  const mounted = useSyncExternalStore(subscribeNoop, getMounted, getServerMounted);\n  if (tone) return tone;\n  if (!mounted) return \"dark\";\n  return resolvedTheme === \"light\" ? \"light\" : \"dark\";\n}\n",
      "type": "registry:component",
      "target": "@components/bjork-ui/_core/tone.ts"
    },
    {
      "path": "components/bjork-ui/_core/palette.ts",
      "content": "export type BjorkTone = \"dark\" | \"light\";\n\n// Canvas, WebGL and SVG attribute colours. DOM code uses the CSS tokens with these as fallbacks.\nexport const BJORK_PALETTE = {\n  dark: {\n    bg: \"#050505\", stage: \"#111111\", surface: \"#121212\", raised: \"#161616\", active: \"#202020\",\n    border: \"#232323\", borderStrong: \"#343434\",\n    text: \"#ededed\", textMedium: \"rgba(237,237,237,0.72)\", textMuted: \"rgba(237,237,237,0.6)\",\n    textSoft: \"rgba(237,237,237,0.5)\", textFaint: \"rgba(237,237,237,0.22)\", hair: \"rgba(237,237,237,0.12)\",\n    accent: \"#ec5c13\", accentInk: \"#ec5c13\", accentFill: \"#b84a12\", accentSoft: \"rgba(236,92,19,0.12)\", accentMuted: \"rgba(236,92,19,0.24)\",\n    accentFg: \"#fff2ea\", success: \"#4cc38a\", warning: \"#f2b544\", error: \"#ff5c4d\",\n  },\n  light: {\n    bg: \"#f7f5ef\", stage: \"#f7f5ef\", surface: \"#fffcf6\", raised: \"#f5efe3\", active: \"#efe7d8\",\n    border: \"#eee6db\", borderStrong: \"#e1d7c8\",\n    text: \"#171717\", textMedium: \"rgba(23,23,23,0.78)\", textMuted: \"rgba(23,23,23,0.68)\",\n    textSoft: \"rgba(23,23,23,0.62)\", textFaint: \"rgba(23,23,23,0.22)\", hair: \"rgba(23,23,23,0.10)\",\n    accent: \"#ec7d43\", accentInk: \"#b4531f\", accentFill: \"#ec7d43\", accentSoft: \"rgba(236,125,67,0.10)\", accentMuted: \"rgba(236,125,67,0.20)\",\n    accentFg: \"#3f2112\", success: \"#1f8a55\", warning: \"#a86b00\", error: \"#c8361f\",\n  },\n} as const;\n",
      "type": "registry:component",
      "target": "@components/bjork-ui/_core/palette.ts"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs))\n}\n",
      "type": "registry:lib",
      "target": "@lib/utils.ts"
    }
  ],
  "cssVars": {
    "light": {
      "bjork-bg": "#f7f3ea",
      "bjork-surface": "#fffcf6",
      "bjork-surface-muted": "rgba(250, 246, 237, 0.94)",
      "bjork-surface-hover": "#f5efe3",
      "bjork-surface-active": "#efe7d8",
      "bjork-panel": "#f8f2e7",
      "bjork-menu": "rgba(255, 252, 246, 0.98)",
      "bjork-field": "rgba(255, 252, 246, 0.96)",
      "bjork-field-muted": "rgba(248, 242, 231, 0.82)",
      "bjork-field-inset": "rgba(239, 231, 216, 0.72)",
      "bjork-error-bg": "#fff0e8",
      "bjork-text": "#171717",
      "bjork-text-strong": "rgba(23, 23, 23, 0.9)",
      "bjork-text-medium": "rgba(23, 23, 23, 0.78)",
      "bjork-text-muted": "rgba(23, 23, 23, 0.68)",
      "bjork-text-soft": "rgba(23, 23, 23, 0.62)",
      "bjork-text-faint": "rgba(23, 23, 23, 0.22)",
      "bjork-inverted-text": "#fff8f0",
      "bjork-border": "#eee6db",
      "bjork-border-muted": "#f5ede2",
      "bjork-border-strong": "#e1d7c8",
      "bjork-thumb": "#a49b8e",
      "bjork-track": "#ded6ca",
      "bjork-accent": "#ec7d43",
      "bjork-accent-hover": "#f0935f",
      "bjork-accent-soft": "rgba(236, 125, 67, 0.1)",
      "bjork-accent-muted": "rgba(236, 125, 67, 0.2)",
      "bjork-accent-badge": "rgba(236, 125, 67, 0.16)",
      "bjork-accent-badge-foreground": "#8d421d",
      "bjork-accent-foreground": "#3f2112",
      "bjork-accent-fill": "#ec7d43",
      "bjork-accent-fill-hover": "#f0935f",
      "bjork-shadow-surface": "inset 0 7px 14px rgba(88, 72, 49, 0.045), inset 0 0.5px 0.5px rgba(255, 255, 255, 0.92), inset 1px 0 0 rgba(88, 72, 49, 0.026), inset -1px 0 0 rgba(255, 255, 255, 0.68), 0 14px 22px -9px rgba(66, 52, 33, 0.11)",
      "bjork-shadow-soft": "inset 0 1px 0 rgba(88, 72, 49, 0.045), inset 0 0.5px 0.5px rgba(255, 255, 255, 0.86)",
      "bjork-shadow-panel": "inset 0 1px 0 rgba(88, 72, 49, 0.04), inset 1px 0 0 rgba(88, 72, 49, 0.024), inset -1px 0 0 rgba(255, 255, 255, 0.64), 0 18px 38px -30px rgba(66, 52, 33, 0.2)",
      "bjork-shadow-menu": "inset 0 1px 0 rgba(88, 72, 49, 0.04), inset 0 12px 24px rgba(88, 72, 49, 0.022), inset 1px 0 0 rgba(88, 72, 49, 0.024), inset -1px 0 0 rgba(255, 255, 255, 0.62), 0 22px 44px -26px rgba(66, 52, 33, 0.22)",
      "bjork-shadow-inset": "inset 0 1px 10px rgba(88, 72, 49, 0.12), inset 0 0.5px 0.5px rgba(255, 255, 255, 0.72)",
      "bjork-ring-offset": "#f7f3ea"
    },
    "dark": {
      "bjork-bg": "#111111",
      "bjork-surface": "#121212",
      "bjork-surface-muted": "rgba(22, 22, 22, 0.92)",
      "bjork-surface-hover": "#161616",
      "bjork-surface-active": "#202020",
      "bjork-panel": "#0d0d0d",
      "bjork-menu": "rgba(18, 18, 18, 0.98)",
      "bjork-field": "rgba(18, 18, 18, 0.95)",
      "bjork-field-muted": "rgba(18, 18, 18, 0.55)",
      "bjork-field-inset": "rgba(9, 9, 9, 0.75)",
      "bjork-error-bg": "#130d0a",
      "bjork-text": "#ededed",
      "bjork-text-strong": "rgba(237, 237, 237, 0.9)",
      "bjork-text-medium": "rgba(237, 237, 237, 0.72)",
      "bjork-text-muted": "rgba(237, 237, 237, 0.6)",
      "bjork-text-soft": "rgba(237, 237, 237, 0.5)",
      "bjork-text-faint": "rgba(237, 237, 237, 0.22)",
      "bjork-inverted-text": "#080808",
      "bjork-border": "#232323",
      "bjork-border-muted": "#1c1c1c",
      "bjork-border-strong": "#343434",
      "bjork-thumb": "#626262",
      "bjork-track": "#090909",
      "bjork-accent": "#ec5c13",
      "bjork-accent-hover": "#f07832",
      "bjork-accent-soft": "rgba(236, 92, 19, 0.12)",
      "bjork-accent-muted": "rgba(236, 92, 19, 0.24)",
      "bjork-accent-badge": "#b84a12",
      "bjork-accent-badge-foreground": "#fff2ea",
      "bjork-accent-foreground": "#fff2ea",
      "bjork-accent-fill": "#b84a12",
      "bjork-accent-fill-hover": "#a84a14",
      "bjork-shadow-surface": "inset 0 7px 14px rgba(255, 255, 255, 0.03), inset 0 0.5px 0.5px rgba(255, 255, 255, 0.06), 0 14px 20px -6px rgba(0, 0, 0, 0.45)",
      "bjork-shadow-soft": "inset 0 1px 0 rgba(255, 255, 255, 0.045)",
      "bjork-shadow-panel": "inset 0 1px 0 rgba(255, 255, 255, 0.035), 0 18px 36px -28px rgba(0, 0, 0, 0.9)",
      "bjork-shadow-menu": "inset 0 1px 0 rgba(255, 255, 255, 0.055), inset 0 12px 24px rgba(255, 255, 255, 0.018), inset 0 -18px 26px rgba(0, 0, 0, 0.24), 0 22px 42px -22px rgba(0, 0, 0, 0.9)",
      "bjork-shadow-inset": "inset 0 1px 10px rgba(0, 0, 0, 0.45)",
      "bjork-ring-offset": "#080808"
    }
  },
  "css": {
    ".bjork-range": {
      "box-shadow": "inset 0 1px 1px rgba(255, 255, 255, 0.04), 0 0 14px rgba(189, 69, 20, 0.06)"
    },
    ".bjork-range::-webkit-slider-thumb": {
      "appearance": "none",
      "width": "16px",
      "height": "8px",
      "border": "0",
      "border-radius": "999px",
      "background": "var(--bjork-thumb)",
      "box-shadow": "inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.42)"
    },
    ".bjork-range::-moz-range-thumb": {
      "width": "16px",
      "height": "8px",
      "border": "0",
      "border-radius": "999px",
      "background": "var(--bjork-thumb)",
      "box-shadow": "inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.42)"
    },
    ".bjork-layered-button-accent, .bjork-layered-button-raised": {
      "position": "relative",
      "isolation": "isolate",
      "appearance": "none",
      "overflow": "hidden",
      "border": "0",
      "border-radius": "13px",
      "box-shadow": "inset 0 1px 0 #ffffff38, 0 4px 6px -1px #0000001a, 0 2px 4px -2px #0000001a",
      "transition": "filter 150ms ease-out, box-shadow 150ms ease-out"
    },
    ".bjork-layered-button-accent::after, .bjork-layered-button-raised::after": {
      "position": "absolute",
      "inset": "0",
      "pointer-events": "none",
      "content": "\"\"",
      "border": "1.5px solid transparent",
      "border-radius": "inherit",
      "background": "linear-gradient(#ffffffb8, #0000003d 41% 75%, #ffffff47) border-box",
      "mix-blend-mode": "overlay",
      "-webkit-mask-image": "linear-gradient(#000, #000), linear-gradient(#000, #000)",
      "mask-image": "linear-gradient(#000, #000), linear-gradient(#000, #000)",
      "-webkit-mask-clip": "padding-box, border-box",
      "mask-clip": "padding-box, border-box",
      "-webkit-mask-origin": "padding-box, border-box",
      "mask-origin": "padding-box, border-box",
      "-webkit-mask-composite": "xor",
      "mask-composite": "exclude"
    },
    ".bjork-layered-button-accent": {
      "color": "oklch(100% 0 0)",
      "text-shadow": "0 -1px #00000040",
      "background": "radial-gradient(ellipse at -20px top, rgba(255, 255, 255, 0.14), transparent), linear-gradient(180deg, #ec5c13 0%, #ec5c13 62%, color-mix(in oklab, #ec5c13 84%, black 16%) 100%)"
    },
    ".bjork-layered-button-raised": {
      "color": "oklch(100% 0 0)",
      "text-shadow": "0 -1px #00000026",
      "background": "radial-gradient(ellipse at -20px top, #ffffff38, #fff0), linear-gradient(180deg, oklch(0.1881 0.006 265), oklch(0.5493 0.0081 265))"
    },
    ".dark .bjork-layered-button-raised": {
      "color": "oklch(0.2574 0.0056 265)",
      "text-shadow": "0 -1px #00000026",
      "background": "radial-gradient(ellipse at -20px top, #ffffff38, #fff0), linear-gradient(180deg, color-mix(in oklab, oklch(0.9674 0.0013 265) 80%, oklch(0.2574 0.0056 265) 20%), color-mix(in oklab, oklch(0.669 0.0107 265) 80%, oklch(0.2574 0.0056 265) 20%))"
    },
    "@media (hover: hover)": {
      ".bjork-layered-button-accent:hover": {
        "filter": "brightness(1.08) saturate(1.04)"
      },
      ".bjork-layered-button-raised:hover": {
        "filter": "brightness(1.08) contrast(0.9)"
      }
    }
  },
  "meta": {
    "collection": "Blocks",
    "registryUrl": "https://ui.isaiahbjork.com/app-settings.json",
    "installCommand": "npx shadcn@latest add https://ui.isaiahbjork.com/app-settings.json"
  },
  "type": "registry:block"
}