{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-inbox",
  "title": "Inbox",
  "description": "Inbox 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-inbox.tsx",
      "content": "\"use client\";\n\nimport {\n  useEffect,\n  useId,\n  useMemo,\n  useRef,\n  useState,\n  type ComponentType,\n  type KeyboardEvent as ReactKeyboardEvent,\n  type ReactNode,\n  type RefObject,\n  type SVGProps,\n} from \"react\";\nimport { AnimatePresence, motion } from \"framer-motion\";\nimport {\n  Archive,\n  ArchiveRestore,\n  ArrowLeft,\n  ChevronDown,\n  ChevronUp,\n  File,\n  FileText,\n  Inbox,\n  Keyboard,\n  MailOpen,\n  Mail,\n  Menu,\n  Paperclip,\n  PenSquare,\n  Reply,\n  Search,\n  Send,\n  Star,\n  Trash2,\n  X,\n} from \"lucide-react\";\nimport {\n  BlockButton,\n  BlockDialog,\n  BlockDrawer,\n  BlockField,\n  IconButton,\n  InitialsAvatar,\n  Kbd,\n  blockRoot,\n  focusRing,\n  inputClass,\n  useAnnouncer,\n  useAppBlockTheme,\n  useBlockReducedMotion,\n  useElementWidth,\n  useHydrated,\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 InboxFolder = \"inbox\" | \"sent\" | \"drafts\" | \"archive\" | \"trash\";\n\nexport interface InboxPerson {\n  name: string;\n  email: string;\n}\n\nexport interface InboxMessage {\n  id: string;\n  from: InboxPerson;\n  /** ISO timestamp. */\n  date: string;\n  /** Plain text; blank lines separate paragraphs. */\n  body: string;\n}\n\nexport interface InboxThread {\n  id: string;\n  subject: string;\n  folder: InboxFolder;\n  labels?: string[];\n  unread?: boolean;\n  starred?: boolean;\n  attachments?: { name: string; size: string }[];\n  /** Oldest first. */\n  messages: InboxMessage[];\n}\n\nexport interface InboxLabel {\n  id: string;\n  name: string;\n  color: string;\n}\n\nexport interface AppInboxProps {\n  threads?: InboxThread[];\n  labels?: InboxLabel[];\n  /** The signed-in user; replies are sent as them. */\n  me?: InboxPerson;\n  defaultFolder?: InboxFolder | \"starred\";\n  /** Thread open on first render. Defaults to the newest in the folder; pass null for none. */\n  defaultOpenId?: string | null;\n  onReply?: (threadId: string, body: string) => void;\n  onCompose?: (draft: { to: string; subject: string; body: string }) => void;\n  /** Fired after any change to a thread (read, star, move). */\n  onThreadChange?: (thread: InboxThread) => void;\n  /** \"Now\" for relative dates. Defaults to the newest message, so sample data reads naturally. */\n  now?: string;\n  theme?: AppBlockTheme;\n  /** Skips list animations; for static captures. */\n  disableAnimation?: boolean;\n  className?: string;\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Sample data\n * -------------------------------------------------------------------------------------------------------- */\n\nconst ME: InboxPerson = { name: \"Rhea Castillo\", email: \"rhea@halcyon.app\" };\n\nconst SAMPLE_LABELS: InboxLabel[] = [\n  { id: \"design\", name: \"Design\", color: \"#ec7d43\" },\n  { id: \"customers\", name: \"Customers\", color: \"#3e9e74\" },\n  { id: \"hiring\", name: \"Hiring\", color: \"#7b6cf0\" },\n  { id: \"billing\", name: \"Billing\", color: \"#c9a227\" },\n];\n\nconst p = (name: string, email: string): InboxPerson => ({ name, email });\nconst MAREN = p(\"Maren Okafor\", \"maren@fieldnote.studio\");\nconst THEO = p(\"Theo Lindqvist\", \"theo@halcyon.app\");\nconst AMARA = p(\"Amara Nwosu\", \"amara@halcyon.app\");\nconst JONAS = p(\"Jonas Weber\", \"jonas@kettle.dev\");\nconst PRIYA = p(\"Priya Raman\", \"priya@halcyon.app\");\nconst STRIPE = p(\"Billing\", \"receipts@payments.example\");\nconst LENA = p(\"Lena Duarte\", \"lena@northwind.coop\");\nconst SAMI = p(\"Sami Haddad\", \"sami@halcyon.app\");\nconst ODA = p(\"Oda Kristiansen\", \"oda@greyhaven.io\");\n\nconst SAMPLE_THREADS: InboxThread[] = [\n  {\n    id: \"t1\",\n    subject: \"Revenue chart: the comparison line is confusing people\",\n    folder: \"inbox\",\n    labels: [\"design\", \"customers\"],\n    unread: true,\n    starred: true,\n    attachments: [\n      { name: \"session-notes.pdf\", size: \"212 KB\" },\n      { name: \"chart-v3.fig\", size: \"4.1 MB\" },\n    ],\n    messages: [\n      {\n        id: \"t1m1\",\n        from: MAREN,\n        date: \"2026-10-08T09:12:00Z\",\n        body:\n          \"Hi Rhea,\\n\\nWe ran five sessions with finance leads this week. Four of them read the dashed comparison line as a forecast, not last period. One asked why we were predicting a dip in March.\\n\\nNotes attached. The quick fix might just be a legend that says “Previous period” and a lighter dash.\",\n      },\n      {\n        id: \"t1m2\",\n        from: THEO,\n        date: \"2026-10-08T11:40:00Z\",\n        body:\n          \"Agree on the legend. I'd also drop the comparison line entirely on the 7-day view, where it's mostly noise.\\n\\nRhea, can you take a pass before Thursday's review?\",\n      },\n      {\n        id: \"t1m3\",\n        from: MAREN,\n        date: \"2026-10-08T15:58:00Z\",\n        body:\n          \"One more: two people hovered the chart and expected the KPI cards above it to update to the hovered day. Might be worth a prototype.\\n\\nThe Figma file has three variants. My vote is v3.\",\n      },\n    ],\n  },\n  {\n    id: \"t2\",\n    subject: \"Offer letter for the senior design engineer role\",\n    folder: \"inbox\",\n    labels: [\"hiring\"],\n    unread: true,\n    messages: [\n      {\n        id: \"t2m1\",\n        from: AMARA,\n        date: \"2026-10-08T14:20:00Z\",\n        body:\n          \"Hi Rhea, the panel signed off on Kai. Can you write two sentences on what impressed you in the systems interview? I'll fold it into the offer note.\\n\\nWe'd like to send it by Friday.\",\n      },\n    ],\n  },\n  {\n    id: \"t3\",\n    subject: \"Re: Webhook retries after the outage\",\n    folder: \"inbox\",\n    labels: [\"customers\"],\n    messages: [\n      {\n        id: \"t3m1\",\n        from: JONAS,\n        date: \"2026-10-07T18:05:00Z\",\n        body:\n          \"Hey team, after Tuesday's incident we received each order.paid event three times. Our handler is idempotent so nothing broke, but our on-call got paged twice.\\n\\nIs there a header we can use to spot a retry?\",\n      },\n      {\n        id: \"t3m2\",\n        from: SAMI,\n        date: \"2026-10-08T08:30:00Z\",\n        body:\n          \"Hi Jonas, sorry for the noise. Every delivery carries Halcyon-Delivery-Attempt, starting at 1. We're also adding the original timestamp next sprint so you can drop stale retries outright.\",\n      },\n    ],\n  },\n  {\n    id: \"t4\",\n    subject: \"Your October invoice is ready\",\n    folder: \"inbox\",\n    labels: [\"billing\"],\n    attachments: [{ name: \"INV-2026-010.pdf\", size: \"48 KB\" }],\n    messages: [\n      {\n        id: \"t4m1\",\n        from: STRIPE,\n        date: \"2026-10-08T07:00:00Z\",\n        body: \"Invoice INV-2026-010 for $588.00 is ready. It will be charged to the Visa ending in 4242 on October 15.\\n\\nNo action is needed.\",\n      },\n    ],\n  },\n  {\n    id: \"t5\",\n    subject: \"Design review moved to Thursday 2pm\",\n    folder: \"inbox\",\n    labels: [\"design\"],\n    starred: true,\n    messages: [\n      {\n        id: \"t5m1\",\n        from: PRIYA,\n        date: \"2026-10-07T16:45:00Z\",\n        body:\n          \"Moving the dashboard review to Thursday at 2pm so Theo can join from Lisbon. Same room, same doc.\\n\\nAgenda: chart legend, empty states, the orders table on phones.\",\n      },\n    ],\n  },\n  {\n    id: \"t6\",\n    subject: \"Co-op pilot: 40 seats from November\",\n    folder: \"inbox\",\n    labels: [\"customers\"],\n    unread: true,\n    messages: [\n      {\n        id: \"t6m1\",\n        from: LENA,\n        date: \"2026-10-06T13:10:00Z\",\n        body:\n          \"Hello! Northwind would like to start the pilot on November 3 with 40 seats across two warehouses.\\n\\nTwo questions: can we export the orders table to CSV on a schedule, and can store managers see only their own store?\",\n      },\n    ],\n  },\n  {\n    id: \"t7\",\n    subject: \"Empty states, round two\",\n    folder: \"inbox\",\n    labels: [\"design\"],\n    messages: [\n      {\n        id: \"t7m1\",\n        from: THEO,\n        date: \"2026-10-05T10:00:00Z\",\n        body: \"Pushed the second round of empty states. I cut the illustrations down to a single line of copy and one action. Much calmer.\",\n      },\n      {\n        id: \"t7m2\",\n        from: ME,\n        date: \"2026-10-05T12:22:00Z\",\n        body: \"Much better. The search empty state should offer “Clear filters” as the action, since that's usually the cause.\",\n      },\n    ],\n  },\n  {\n    id: \"t8\",\n    subject: \"Interview loop for Saturday candidates\",\n    folder: \"inbox\",\n    labels: [\"hiring\"],\n    messages: [\n      {\n        id: \"t8m1\",\n        from: AMARA,\n        date: \"2026-10-03T09:40:00Z\",\n        body: \"Three candidates on Saturday. I've put you on the 11:00 systems interview. The rubric is linked in the calendar invite.\",\n      },\n    ],\n  },\n  {\n    id: \"t9\",\n    subject: \"Accessibility audit results\",\n    folder: \"inbox\",\n    attachments: [{ name: \"audit-q3.pdf\", size: \"1.2 MB\" }],\n    messages: [\n      {\n        id: \"t9m1\",\n        from: ODA,\n        date: \"2026-09-29T15:15:00Z\",\n        body:\n          \"Attached is the Q3 audit. The headline: 2 blockers, 9 serious, 14 minor. Both blockers are focus traps in the old filter popover.\\n\\nHappy to walk through it on a call.\",\n      },\n    ],\n  },\n  {\n    id: \"t10\",\n    subject: \"Re: Chart colours in dark mode\",\n    folder: \"sent\",\n    labels: [\"design\"],\n    messages: [\n      {\n        id: \"t10m1\",\n        from: ME,\n        date: \"2026-10-07T20:10:00Z\",\n        body: \"Sending the updated palette. The comparison series now uses a neutral ink at 30% so it never competes with the accent.\",\n      },\n    ],\n  },\n  {\n    id: \"t11\",\n    subject: \"Draft: Q4 roadmap notes\",\n    folder: \"drafts\",\n    messages: [\n      {\n        id: \"t11m1\",\n        from: ME,\n        date: \"2026-10-06T22:00:00Z\",\n        body: \"Q4 themes: saved views, scheduled exports, per-store permissions…\",\n      },\n    ],\n  },\n  {\n    id: \"t12\",\n    subject: \"Quarterly offsite logistics\",\n    folder: \"archive\",\n    messages: [\n      {\n        id: \"t12m1\",\n        from: PRIYA,\n        date: \"2026-09-20T11:00:00Z\",\n        body: \"Hotel blocks are booked. Please submit travel by October 1.\",\n      },\n    ],\n  },\n];\n\n/* ----------------------------------------------------------------------------------------------------------\n * Helpers\n * -------------------------------------------------------------------------------------------------------- */\n\nconst FOLDERS: { id: InboxFolder | \"starred\"; label: string; icon: ComponentType<SVGProps<SVGSVGElement>> }[] = [\n  { id: \"inbox\", label: \"Inbox\", icon: Inbox },\n  { id: \"starred\", label: \"Starred\", icon: Star },\n  { id: \"sent\", label: \"Sent\", icon: Send },\n  { id: \"drafts\", label: \"Drafts\", icon: FileText },\n  { id: \"archive\", label: \"Archive\", icon: Archive },\n  { id: \"trash\", label: \"Trash\", icon: Trash2 },\n];\n\nconst lastDate = (t: InboxThread) => t.messages[t.messages.length - 1]?.date ?? \"\";\n\nfunction snippet(body: string) {\n  return body.replace(/\\s+/g, \" \").trim();\n}\n\nfunction inFolder(t: InboxThread, folder: InboxFolder | \"starred\") {\n  return folder === \"starred\" ? Boolean(t.starred) && t.folder !== \"trash\" : t.folder === folder;\n}\n\nfunction newestIn(threads: InboxThread[], folder: InboxFolder | \"starred\", label: string | null = null) {\n  return threads\n    .filter((t) => inFolder(t, folder) && (!label || t.labels?.includes(label)))\n    .sort((a, b) => lastDate(b).localeCompare(lastDate(a)))[0];\n}\n\n/** Formats in UTC until hydrated so server and client agree, then in the viewer's zone. */\nfunction useDateFormat(now: number) {\n  const hydrated = useHydrated();\n  return useMemo(() => {\n    const timeZone = hydrated ? undefined : \"UTC\";\n    const time = new Intl.DateTimeFormat(\"en-US\", { hour: \"numeric\", minute: \"2-digit\", timeZone });\n    const day = new Intl.DateTimeFormat(\"en-US\", { month: \"short\", day: \"numeric\", timeZone });\n    const full = new Intl.DateTimeFormat(\"en-US\", {\n      weekday: \"short\",\n      month: \"short\",\n      day: \"numeric\",\n      hour: \"numeric\",\n      minute: \"2-digit\",\n      timeZone,\n    });\n    const dayKey = new Intl.DateTimeFormat(\"en-CA\", { timeZone });\n    const today = dayKey.format(now);\n    return {\n      short: (iso: string) => {\n        const d = new Date(iso);\n        return dayKey.format(d) === today ? time.format(d) : day.format(d);\n      },\n      full: (iso: string) => full.format(new Date(iso)),\n    };\n  }, [hydrated, now]);\n}\n\nconst isTyping = (el: EventTarget | null) =>\n  el instanceof HTMLElement && Boolean(el.closest(\"input, textarea, select, [contenteditable=true]\"));\n\n/* ----------------------------------------------------------------------------------------------------------\n * Block\n * -------------------------------------------------------------------------------------------------------- */\n\nconst WIDE = 1040;\nconst MEDIUM = 700;\n\nexport function AppInbox({\n  threads: initialThreads = SAMPLE_THREADS,\n  labels = SAMPLE_LABELS,\n  me = ME,\n  defaultFolder = \"inbox\",\n  defaultOpenId,\n  onReply,\n  onCompose,\n  onThreadChange,\n  now,\n  theme = \"auto\",\n  disableAnimation = false,\n  className,\n}: AppInboxProps) {\n  const { style } = useAppBlockTheme(theme);\n  const reduce = useBlockReducedMotion();\n  const animate = !disableAnimation && !reduce;\n  const rootRef = useRef<HTMLDivElement>(null);\n  const width = useElementWidth(rootRef);\n  const wide = width === 0 || width >= WIDE;\n  const medium = width === 0 || width >= MEDIUM;\n  const { announce, region } = useAnnouncer();\n\n  const nowMs = useMemo(() => {\n    if (now) return new Date(now).getTime();\n    return Math.max(...initialThreads.map((t) => new Date(lastDate(t)).getTime()).filter(Number.isFinite), 0);\n  }, [now, initialThreads]);\n  const fmt = useDateFormat(nowMs);\n\n  const [threads, setThreads] = useState<InboxThread[]>(() => {\n    const firstId = defaultOpenId === undefined ? newestIn(initialThreads, defaultFolder)?.id : defaultOpenId;\n    return initialThreads.map((t) => (t.id === firstId ? { ...t, unread: false } : t));\n  });\n  const [folder, setFolder] = useState<InboxFolder | \"starred\">(defaultFolder);\n  const [label, setLabel] = useState<string | null>(null);\n  const [unreadOnly, setUnreadOnly] = useState(false);\n  const [query, setQuery] = useState(\"\");\n  const [openId, setOpenId] = useState<string | null>(() =>\n    defaultOpenId === undefined ? (newestIn(initialThreads, defaultFolder)?.id ?? null) : defaultOpenId,\n  );\n  // On narrow containers the reader replaces the list; this tracks whether it is showing.\n  const [readerShown, setReaderShown] = useState(false);\n  const [selected, setSelected] = useState<Set<string>>(() => new Set());\n  const [drawerOpen, setDrawerOpen] = useState(false);\n  const [composeOpen, setComposeOpen] = useState(false);\n  const [helpOpen, setHelpOpen] = useState(false);\n  const [undo, setUndo] = useState<{ message: string; previous: InboxThread[] } | null>(null);\n  const undoTimer = useRef<number | undefined>(undefined);\n\n  const searchRef = useRef<HTMLInputElement>(null);\n  const rowRefs = useRef(new Map<string, HTMLButtonElement>());\n  const replyRef = useRef<HTMLTextAreaElement>(null);\n  const modalOpen = composeOpen || helpOpen || (drawerOpen && !wide);\n\n  const visible = useMemo(() => {\n    const q = query.trim().toLowerCase();\n    return threads\n      .filter((t) => inFolder(t, folder))\n      .filter((t) => !label || t.labels?.includes(label))\n      .filter((t) => !unreadOnly || t.unread)\n      .filter(\n        (t) =>\n          !q ||\n          t.subject.toLowerCase().includes(q) ||\n          t.messages.some((m) => m.from.name.toLowerCase().includes(q) || m.body.toLowerCase().includes(q)),\n      )\n      .sort((a, b) => lastDate(b).localeCompare(lastDate(a)));\n  }, [threads, folder, label, unreadOnly, query]);\n\n  const counts = useMemo(() => {\n    const unread: Record<string, number> = {};\n    for (const f of FOLDERS) unread[f.id] = threads.filter((t) => inFolder(t, f.id) && t.unread).length;\n    const drafts = threads.filter((t) => t.folder === \"drafts\").length;\n    return { unread, drafts };\n  }, [threads]);\n\n  const open = threads.find((t) => t.id === openId) ?? null;\n  const openIndex = visible.findIndex((t) => t.id === openId);\n  const showList = medium || !readerShown;\n  const showReader = medium || readerShown;\n\n  useEffect(() => () => window.clearTimeout(undoTimer.current), []);\n\n  /* --- mutations ------------------------------------------------------------------------------------- */\n\n  const patch = (ids: string[], change: (t: InboxThread) => InboxThread) => {\n    if (onThreadChange) threads.filter((t) => ids.includes(t.id)).forEach((t) => onThreadChange(change(t)));\n    setThreads((list) => list.map((t) => (ids.includes(t.id) ? change(t) : t)));\n  };\n\n  const offerUndo = (message: string, ids: string[]) => {\n    window.clearTimeout(undoTimer.current);\n    setUndo({ message, previous: threads.filter((t) => ids.includes(t.id)) });\n    announce(`${message}. Press Z to undo.`);\n    undoTimer.current = window.setTimeout(() => setUndo(null), 6000);\n  };\n\n  const runUndo = () => {\n    if (!undo) return;\n    const byId = new Map(undo.previous.map((t) => [t.id, t]));\n    setThreads((list) => list.map((t) => byId.get(t.id) ?? t));\n    window.clearTimeout(undoTimer.current);\n    setUndo(null);\n    announce(\"Undone\");\n  };\n\n  const openThread = (id: string | null, opts: { focusRow?: boolean } = {}) => {\n    setOpenId(id);\n    if (id) {\n      patch([id], (t) => (t.unread ? { ...t, unread: false } : t));\n      if (!medium) setReaderShown(true);\n      if (opts.focusRow) rowRefs.current.get(id)?.focus();\n    }\n  };\n\n  /** After threads leave the view, keep the reader on the next one down (or up, at the end). */\n  const advancePast = (ids: string[]) => {\n    if (!openId || !ids.includes(openId)) return;\n    const remaining = visible.filter((t) => !ids.includes(t.id));\n    const after = visible.slice(openIndex + 1).find((t) => !ids.includes(t.id));\n    const nextId = after?.id ?? remaining[remaining.length - 1]?.id ?? null;\n    setOpenId(nextId);\n    if (!medium) setReaderShown(false);\n    if (nextId) window.requestAnimationFrame(() => rowRefs.current.get(nextId)?.focus());\n  };\n\n  const move = (ids: string[], to: InboxFolder) => {\n    if (ids.length === 0) return;\n    const noun = ids.length === 1 ? \"Conversation\" : `${ids.length} conversations`;\n    const verb = to === \"archive\" ? \"archived\" : to === \"trash\" ? \"moved to Trash\" : \"moved to Inbox\";\n    offerUndo(`${noun} ${verb}`, ids);\n    advancePast(ids);\n    patch(ids, (t) => ({ ...t, folder: to }));\n    setSelected(new Set());\n  };\n\n  const toggleStar = (id: string) => {\n    const t = threads.find((x) => x.id === id);\n    if (!t) return;\n    patch([id], (x) => ({ ...x, starred: !x.starred }));\n    announce(t.starred ? \"Unstarred\" : \"Starred\");\n  };\n\n  const setRead = (ids: string[], read: boolean) => {\n    if (ids.length === 0) return;\n    patch(ids, (t) => ({ ...t, unread: !read }));\n    announce(`Marked ${ids.length === 1 ? \"\" : `${ids.length} `}as ${read ? \"read\" : \"unread\"}`);\n    setSelected(new Set());\n  };\n\n  const toggleSelect = (id: string) =>\n    setSelected((s) => {\n      const next = new Set(s);\n      if (next.has(id)) next.delete(id);\n      else next.add(id);\n      return next;\n    });\n\n  const changeFolder = (next: InboxFolder | \"starred\", nextLabel: string | null = null) => {\n    setFolder(next);\n    setLabel(nextLabel);\n    setSelected(new Set());\n    setReaderShown(false);\n    setDrawerOpen(false);\n    const first = newestIn(threads, next, nextLabel);\n    setOpenId(medium ? (first?.id ?? null) : null);\n    if (medium && first) patch([first.id], (t) => ({ ...t, unread: false }));\n  };\n\n  const sendReply = (body: string) => {\n    if (!open) return;\n    const message: InboxMessage = { id: `${open.id}-r${Date.now()}`, from: me, date: new Date(Math.max(Date.now(), nowMs)).toISOString(), body };\n    patch([open.id], (t) => ({ ...t, messages: [...t.messages, message] }));\n    onReply?.(open.id, body);\n    announce(\"Reply sent\");\n  };\n\n  /* --- keyboard -------------------------------------------------------------------------------------- */\n\n  const step = (delta: number) => {\n    if (visible.length === 0) return;\n    const from = openIndex < 0 ? (delta > 0 ? -1 : visible.length) : openIndex;\n    const next = visible[Math.min(visible.length - 1, Math.max(0, from + delta))];\n    if (!next) return;\n    if (!medium && !readerShown) {\n      setOpenId(next.id);\n      rowRefs.current.get(next.id)?.focus();\n      return;\n    }\n    openThread(next.id, { focusRow: medium });\n  };\n\n  const onRootKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {\n    if (modalOpen || event.metaKey || event.ctrlKey || event.altKey || isTyping(event.target)) return;\n    const target = openId ? [openId] : [];\n    const ids = selected.size > 0 ? [...selected] : target;\n    const handlers: Record<string, () => void> = {\n      j: () => step(1),\n      k: () => step(-1),\n      e: () => move(ids, folder === \"archive\" ? \"inbox\" : \"archive\"),\n      \"#\": () => move(ids, \"trash\"),\n      s: () => openId && toggleStar(openId),\n      u: () => {\n        if (ids.length === 0) return;\n        const t = threads.find((x) => x.id === ids[0]);\n        setRead(ids, Boolean(t?.unread));\n      },\n      x: () => openId && toggleSelect(openId),\n      r: () => replyRef.current?.focus(),\n      c: () => setComposeOpen(true),\n      z: () => runUndo(),\n      \"/\": () => searchRef.current?.focus(),\n      \"?\": () => setHelpOpen(true),\n      Escape: () => {\n        if (selected.size > 0) setSelected(new Set());\n        else if (!medium && readerShown) {\n          setReaderShown(false);\n          if (openId) window.requestAnimationFrame(() => rowRefs.current.get(openId)?.focus());\n        }\n      },\n    };\n    const handler = handlers[event.key];\n    if (!handler) return;\n    event.preventDefault();\n    handler();\n  };\n\n  /* --- render ---------------------------------------------------------------------------------------- */\n\n  const folderNav = (\n    <FolderNav\n      folder={folder}\n      label={label}\n      labels={labels}\n      counts={counts}\n      onFolder={(f) => changeFolder(f)}\n      onLabel={(l) => changeFolder(\"inbox\", l)}\n      onCompose={() => {\n        setDrawerOpen(false);\n        setComposeOpen(true);\n      }}\n      onClose={wide ? undefined : () => setDrawerOpen(false)}\n    />\n  );\n\n  const folderTitle = label ? (labels.find((l) => l.id === label)?.name ?? \"Label\") : FOLDERS.find((f) => f.id === folder)?.label;\n\n  return (\n    <div ref={rootRef} tabIndex={-1} className={cn(blockRoot, \"h-full outline-none\", className)} style={style} onKeyDown={onRootKeyDown}>\n      {wide && (\n        <aside aria-label=\"Mailboxes\" inert={modalOpen} className=\"flex h-full w-[220px] shrink-0 flex-col border-r border-[color:var(--bjork-border)] bg-[var(--bjork-panel)]\">\n          {folderNav}\n        </aside>\n      )}\n\n      <div className=\"flex min-w-0 flex-1\" inert={modalOpen}>\n        {showList && (\n          <section\n            aria-label={`${folderTitle} conversations`}\n            className={cn(\n              \"flex h-full min-w-0 flex-col\",\n              medium ? \"w-[min(380px,42%)] shrink-0 border-r border-[color:var(--bjork-border)]\" : \"flex-1\",\n            )}\n          >\n            <ListHeader\n              title={folderTitle ?? \"Inbox\"}\n              unread={counts.unread[folder] ?? 0}\n              showMenu={!wide}\n              onMenu={() => setDrawerOpen(true)}\n              query={query}\n              onQuery={setQuery}\n              searchRef={searchRef}\n              unreadOnly={unreadOnly}\n              onUnreadOnly={setUnreadOnly}\n              onCompose={() => setComposeOpen(true)}\n              onHelp={() => setHelpOpen(true)}\n            />\n            <BulkBar\n              count={selected.size}\n              total={visible.length}\n              folder={folder}\n              onSelectAll={() =>\n                setSelected(selected.size === visible.length ? new Set() : new Set(visible.map((t) => t.id)))\n              }\n              onArchive={() => move([...selected], folder === \"archive\" ? \"inbox\" : \"archive\")}\n              onTrash={() => move([...selected], \"trash\")}\n              onRead={() => setRead([...selected], true)}\n              onUnread={() => setRead([...selected], false)}\n              onClear={() => setSelected(new Set())}\n            />\n            <ThreadList\n              threads={visible}\n              labels={labels}\n              openId={openId}\n              selected={selected}\n              animate={animate}\n              highlightOpen={medium}\n              fmt={fmt.short}\n              rowRefs={rowRefs}\n              onOpen={(id) => openThread(id)}\n              onToggleSelect={toggleSelect}\n              onToggleStar={toggleStar}\n              onStep={(id, delta) => {\n                const i = visible.findIndex((t) => t.id === id);\n                const next = visible[Math.min(visible.length - 1, Math.max(0, i + delta))];\n                if (next) rowRefs.current.get(next.id)?.focus();\n              }}\n              emptyAction={\n                query || unreadOnly || label ? (\n                  <BlockButton\n                    size=\"sm\"\n                    variant=\"secondary\"\n                    onClick={() => {\n                      setQuery(\"\");\n                      setUnreadOnly(false);\n                      setLabel(null);\n                    }}\n                  >\n                    Clear filters\n                  </BlockButton>\n                ) : null\n              }\n              emptyTitle={query ? `Nothing matches “${query}”` : folder === \"inbox\" && !label ? \"Inbox zero\" : `No conversations in ${folderTitle}`}\n            />\n          </section>\n        )}\n\n        {showReader && (\n          <Reader\n            thread={open}\n            labels={labels}\n            me={me}\n            fmt={fmt}\n            position={openIndex >= 0 ? { index: openIndex, total: visible.length } : null}\n            showBack={!medium}\n            folder={folder}\n            replyRef={replyRef}\n            onBack={() => {\n              setReaderShown(false);\n              if (openId) window.requestAnimationFrame(() => rowRefs.current.get(openId)?.focus());\n            }}\n            onStep={step}\n            onArchive={() => openId && move([openId], folder === \"archive\" ? \"inbox\" : \"archive\")}\n            onTrash={() => openId && move([openId], \"trash\")}\n            onUnread={() => {\n              if (!openId) return;\n              setRead([openId], false);\n              if (!medium) setReaderShown(false);\n            }}\n            onStar={() => openId && toggleStar(openId)}\n            onSend={sendReply}\n          />\n        )}\n      </div>\n\n      {!wide && (\n        <BlockDrawer open={drawerOpen} onClose={() => setDrawerOpen(false)} label=\"Mailboxes\">\n          {folderNav}\n        </BlockDrawer>\n      )}\n\n      <UndoBar undo={undo} onUndo={runUndo} onDismiss={() => setUndo(null)} />\n\n      <ComposeDialog\n        open={composeOpen}\n        onClose={() => setComposeOpen(false)}\n        onSend={(draft) => {\n          const id = `c${Date.now()}`;\n          setThreads((list) => [\n            ...list,\n            {\n              id,\n              subject: draft.subject || \"(no subject)\",\n              folder: \"sent\",\n              messages: [{ id: `${id}m1`, from: me, date: new Date(Math.max(Date.now(), nowMs)).toISOString(), body: draft.body }],\n            },\n          ]);\n          onCompose?.(draft);\n          setComposeOpen(false);\n          announce(`Message to ${draft.to} sent`);\n        }}\n      />\n      <ShortcutsDialog open={helpOpen} onClose={() => setHelpOpen(false)} />\n      {region}\n    </div>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Folder navigation\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction FolderNav({\n  folder,\n  label,\n  labels,\n  counts,\n  onFolder,\n  onLabel,\n  onCompose,\n  onClose,\n}: {\n  folder: InboxFolder | \"starred\";\n  label: string | null;\n  labels: InboxLabel[];\n  counts: { unread: Record<string, number>; drafts: number };\n  onFolder: (folder: InboxFolder | \"starred\") => void;\n  onLabel: (label: string) => void;\n  onCompose: () => void;\n  onClose?: () => void;\n}) {\n  return (\n    <>\n      <div className=\"flex h-14 shrink-0 items-center gap-2 border-b border-[color:var(--bjork-border)] px-3\">\n        <BlockButton variant=\"primary\" size=\"md\" className=\"flex-1\" onClick={onCompose}>\n          <PenSquare aria-hidden=\"true\" />\n          Compose\n          <Kbd className=\"ml-auto border-white/25 bg-white/10 text-[color:var(--blk-accent-fill-ink)] shadow-none\">C</Kbd>\n        </BlockButton>\n        {onClose && (\n          <IconButton label=\"Close mailboxes\" size=\"sm\" onClick={onClose}>\n            <X />\n          </IconButton>\n        )}\n      </div>\n      <nav aria-label=\"Folders\" className=\"hide-scrollbar flex-1 overflow-y-auto px-2.5 py-3\">\n        <ul className=\"flex flex-col gap-0.5\">\n          {FOLDERS.map((f) => {\n            const active = f.id === folder && !label;\n            const Icon = f.icon;\n            const count = f.id === \"drafts\" ? counts.drafts : (counts.unread[f.id] ?? 0);\n            return (\n              <li key={f.id}>\n                <a\n                  href={`#${f.id}`}\n                  aria-current={active ? \"page\" : undefined}\n                  onClick={(e) => {\n                    e.preventDefault();\n                    onFolder(f.id);\n                  }}\n                  className={cn(\n                    \"relative flex h-9 items-center gap-2.5 rounded-[9px] px-2.5 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 aria-hidden=\"true\" className={cn(\"size-4 shrink-0\", active ? \"text-[color:var(--blk-accent-ink)]\" : \"text-[color:var(--bjork-text-muted)]\")} />\n                  <span className=\"flex-1 truncate\">{f.label}</span>\n                  {count > 0 && (\n                    <span className={cn(\"font-mono text-[11px] tabular-nums\", f.id === \"drafts\" ? \"text-[color:var(--bjork-text-soft)]\" : \"font-medium text-[color:var(--blk-accent-ink)]\")}>\n                      {count}\n                      <span className=\"sr-only\">{f.id === \"drafts\" ? \" drafts\" : \" unread\"}</span>\n                    </span>\n                  )}\n                </a>\n              </li>\n            );\n          })}\n        </ul>\n\n        {labels.length > 0 && (\n          <>\n            <h2 className=\"mb-1.5 mt-6 px-2.5 font-mono text-[10.5px] uppercase tracking-[0.1em] text-[color:var(--bjork-text-soft)]\">Labels</h2>\n            <ul className=\"flex flex-col gap-0.5\">\n              {labels.map((l) => {\n                const active = l.id === label;\n                return (\n                  <li key={l.id}>\n                    <a\n                      href={`#label-${l.id}`}\n                      aria-current={active ? \"page\" : undefined}\n                      onClick={(e) => {\n                        e.preventDefault();\n                        onLabel(l.id);\n                      }}\n                      className={cn(\n                        \"flex h-8 items-center gap-2.5 rounded-[9px] px-2.5 text-[13px] 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                      <span aria-hidden=\"true\" className=\"ml-1 mr-0.5 size-2 rounded-[3px]\" style={{ background: l.color }} />\n                      {l.name}\n                    </a>\n                  </li>\n                );\n              })}\n            </ul>\n          </>\n        )}\n      </nav>\n      <div className=\"shrink-0 border-t border-[color:var(--bjork-border)] p-3 text-[11.5px] leading-[1.5] text-[color:var(--bjork-text-soft)]\">\n        <p className=\"flex items-center gap-1.5\">\n          <Keyboard aria-hidden=\"true\" className=\"size-3.5\" />\n          Press <Kbd>?</Kbd> for shortcuts\n        </p>\n      </div>\n    </>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * List header, bulk bar and list\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction ListHeader({\n  title,\n  unread,\n  showMenu,\n  onMenu,\n  query,\n  onQuery,\n  searchRef,\n  unreadOnly,\n  onUnreadOnly,\n  onCompose,\n  onHelp,\n}: {\n  title: string;\n  unread: number;\n  showMenu: boolean;\n  onMenu: () => void;\n  query: string;\n  onQuery: (q: string) => void;\n  searchRef: RefObject<HTMLInputElement | null>;\n  unreadOnly: boolean;\n  onUnreadOnly: (v: boolean) => void;\n  onCompose: () => void;\n  onHelp: () => void;\n}) {\n  return (\n    <div className=\"shrink-0 border-b border-[color:var(--bjork-border)]\">\n      <div className=\"flex h-14 items-center gap-2 px-3\">\n        {showMenu && (\n          <IconButton label=\"Open mailboxes\" onClick={onMenu}>\n            <Menu />\n          </IconButton>\n        )}\n        <h1 className=\"min-w-0 truncate text-[16px] font-semibold tracking-[-0.015em]\">{title}</h1>\n        {unread > 0 && (\n          <span className=\"rounded-full bg-[var(--bjork-accent-soft)] px-2 py-px font-mono text-[11px] font-medium tabular-nums text-[color:var(--blk-accent-ink)]\">\n            {unread} new\n          </span>\n        )}\n        <div className=\"ml-auto flex items-center gap-1\">\n          <div role=\"group\" aria-label=\"Show\" className=\"flex rounded-[9px] border border-[color:var(--bjork-border)] bg-[var(--bjork-field-inset)] p-[2px]\">\n            {[\n              { v: false, l: \"All\" },\n              { v: true, l: \"Unread\" },\n            ].map((o) => (\n              <button\n                key={o.l}\n                type=\"button\"\n                aria-pressed={unreadOnly === o.v}\n                onClick={() => onUnreadOnly(o.v)}\n                className={cn(\n                  \"h-6 rounded-[7px] px-2 text-[12px] font-medium transition-colors duration-150\",\n                  unreadOnly === o.v\n                    ? \"bg-[var(--bjork-surface)] text-[color:var(--bjork-text)] shadow-[0_0_0_1px_var(--bjork-border)]\"\n                    : \"text-[color:var(--bjork-text-muted)] hover:text-[color:var(--bjork-text)]\",\n                  focusRing,\n                )}\n              >\n                {o.l}\n              </button>\n            ))}\n          </div>\n          {showMenu && (\n            <IconButton label=\"Compose\" onClick={onCompose}>\n              <PenSquare />\n            </IconButton>\n          )}\n          <IconButton label=\"Keyboard shortcuts\" size=\"sm\" onClick={onHelp} className=\"hidden @lg:inline-grid\">\n            <Keyboard />\n          </IconButton>\n        </div>\n      </div>\n      <div className=\"px-3 pb-3\">\n        <label className=\"group relative flex items-center\">\n          <span className=\"sr-only\">Search mail</span>\n          <Search aria-hidden=\"true\" className=\"pointer-events-none absolute left-2.5 size-[15px] text-[color:var(--bjork-text-soft)]\" />\n          <input\n            ref={searchRef}\n            type=\"search\"\n            value={query}\n            onChange={(e) => onQuery(e.target.value)}\n            onKeyDown={(e) => {\n              if (e.key === \"Escape\") {\n                e.stopPropagation();\n                if (query) onQuery(\"\");\n                else e.currentTarget.blur();\n              }\n            }}\n            placeholder=\"Search mail\"\n            className={cn(inputClass, \"h-8 pl-8 pr-8 text-[13px] [&::-webkit-search-cancel-button]:hidden\")}\n          />\n          {query ? (\n            <button\n              type=\"button\"\n              onClick={() => {\n                onQuery(\"\");\n                searchRef.current?.focus();\n              }}\n              aria-label=\"Clear search\"\n              className={cn(\"absolute right-1.5 grid size-5 place-items-center rounded-[5px] text-[color:var(--bjork-text-soft)] hover:text-[color:var(--bjork-text)]\", focusRing)}\n            >\n              <X aria-hidden=\"true\" className=\"size-3.5\" />\n            </button>\n          ) : (\n            <Kbd className=\"pointer-events-none absolute right-2 group-focus-within:opacity-0\">/</Kbd>\n          )}\n        </label>\n      </div>\n    </div>\n  );\n}\n\nfunction BulkBar({\n  count,\n  total,\n  folder,\n  onSelectAll,\n  onArchive,\n  onTrash,\n  onRead,\n  onUnread,\n  onClear,\n}: {\n  count: number;\n  total: number;\n  folder: InboxFolder | \"starred\";\n  onSelectAll: () => void;\n  onArchive: () => void;\n  onTrash: () => void;\n  onRead: () => void;\n  onUnread: () => void;\n  onClear: () => void;\n}) {\n  if (count === 0) return null;\n  const all = count === total;\n  return (\n    <div role=\"toolbar\" aria-label={`${count} selected`} className=\"flex h-11 shrink-0 items-center gap-1 border-b border-[color:var(--bjork-border)] bg-[var(--bjork-accent-soft)] px-2\">\n      <button\n        type=\"button\"\n        role=\"checkbox\"\n        aria-checked={all ? true : \"mixed\"}\n        aria-label={all ? \"Deselect all\" : \"Select all\"}\n        onClick={onSelectAll}\n        className={cn(\"grid size-8 place-items-center rounded-[8px] hover:bg-[var(--bjork-surface-hover)]\", focusRing)}\n      >\n        <CheckBox state={all ? \"on\" : \"mixed\"} />\n      </button>\n      <span className=\"mr-auto text-[12.5px] font-medium tabular-nums\" aria-live=\"polite\">\n        {count} selected\n      </span>\n      <IconButton label={folder === \"archive\" ? \"Move to inbox\" : \"Archive\"} size=\"sm\" onClick={onArchive}>\n        {folder === \"archive\" ? <ArchiveRestore /> : <Archive />}\n      </IconButton>\n      <IconButton label=\"Mark as read\" size=\"sm\" onClick={onRead}>\n        <MailOpen />\n      </IconButton>\n      <IconButton label=\"Mark as unread\" size=\"sm\" onClick={onUnread}>\n        <Mail />\n      </IconButton>\n      <IconButton label=\"Move to trash\" size=\"sm\" onClick={onTrash}>\n        <Trash2 />\n      </IconButton>\n      <IconButton label=\"Clear selection\" size=\"sm\" onClick={onClear}>\n        <X />\n      </IconButton>\n    </div>\n  );\n}\n\nfunction CheckBox({ state }: { state: \"on\" | \"off\" | \"mixed\" }) {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className={cn(\n        \"grid size-4 place-items-center rounded-[5px] border transition-colors duration-100\",\n        state === \"off\"\n          ? \"border-[color:var(--bjork-border-strong)] bg-[var(--bjork-field)]\"\n          : \"border-transparent bg-[var(--blk-accent-fill)] text-[color:var(--blk-accent-fill-ink)]\",\n      )}\n    >\n      {state === \"on\" && (\n        <svg viewBox=\"0 0 12 12\" className=\"size-3\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n          <path d=\"m2.5 6.2 2.3 2.3L9.5 3.5\" />\n        </svg>\n      )}\n      {state === \"mixed\" && <span className=\"h-[1.6px] w-2 rounded-full bg-current\" />}\n    </span>\n  );\n}\n\nfunction ThreadList({\n  threads,\n  labels,\n  openId,\n  selected,\n  animate,\n  highlightOpen,\n  fmt,\n  rowRefs,\n  onOpen,\n  onToggleSelect,\n  onToggleStar,\n  onStep,\n  emptyTitle,\n  emptyAction,\n}: {\n  threads: InboxThread[];\n  labels: InboxLabel[];\n  openId: string | null;\n  selected: Set<string>;\n  animate: boolean;\n  highlightOpen: boolean;\n  fmt: (iso: string) => string;\n  rowRefs: RefObject<Map<string, HTMLButtonElement>>;\n  onOpen: (id: string) => void;\n  onToggleSelect: (id: string) => void;\n  onToggleStar: (id: string) => void;\n  onStep: (id: string, delta: number) => void;\n  emptyTitle: string;\n  emptyAction: ReactNode;\n}) {\n  // Roving tab stop: the open row (or the first) is the list's one entry point.\n  const tabId = threads.some((t) => t.id === openId) ? openId : threads[0]?.id;\n  const selecting = selected.size > 0;\n\n  if (threads.length === 0) {\n    return (\n      <div className=\"flex flex-1 flex-col items-center justify-center gap-2 px-6 text-center\">\n        <span aria-hidden=\"true\" className=\"mb-1 grid size-11 place-items-center rounded-[13px] border border-[color:var(--bjork-border)] bg-[var(--bjork-surface)] shadow-[var(--bjork-shadow-surface)]\">\n          <Inbox className=\"size-5 text-[color:var(--bjork-text-muted)]\" />\n        </span>\n        <p className=\"text-[13.5px] font-medium\">{emptyTitle}</p>\n        <p className=\"max-w-[240px] text-[12.5px] leading-[1.5] text-[color:var(--bjork-text-muted)]\">\n          {emptyAction ? \"Try a different search or clear the filters.\" : \"New mail shows up here.\"}\n        </p>\n        {emptyAction && <div className=\"mt-2\">{emptyAction}</div>}\n      </div>\n    );\n  }\n\n  return (\n    <ul className=\"min-h-0 flex-1 overflow-y-auto overscroll-contain\" aria-label=\"Conversations\">\n      <AnimatePresence initial={false}>\n        {threads.map((t) => {\n          const last = t.messages[t.messages.length - 1];\n          const isOpen = t.id === openId && highlightOpen;\n          const isSelected = selected.has(t.id);\n          const tab = t.id === tabId ? 0 : -1;\n          const senders = [...new Set(t.messages.map((m) => m.from.name.split(\" \")[0]))];\n          const senderText = senders.length > 2 ? `${senders[0]} … ${senders[senders.length - 1]}` : senders.join(\", \");\n          return (\n            <motion.li\n              key={t.id}\n              layout={animate ? \"position\" : false}\n              initial={animate ? { opacity: 0, height: 0 } : false}\n              animate={{ opacity: 1, height: \"auto\" }}\n              exit={animate ? { opacity: 0, height: 0, transition: { duration: 0.18, ease: [0.4, 0, 1, 1] } } : { opacity: 0, transition: { duration: 0 } }}\n              transition={{ duration: 0.22, ease: [0.23, 1, 0.32, 1] }}\n              className=\"overflow-hidden\"\n            >\n              <div\n                className={cn(\n                  \"group relative flex items-start gap-2.5 border-b border-[color:var(--bjork-border-muted)] py-3 pl-2 pr-2.5 transition-colors duration-100\",\n                  isSelected\n                    ? \"bg-[var(--bjork-accent-soft)]\"\n                    : isOpen\n                      ? \"bg-[var(--bjork-surface-active)]\"\n                      : \"hover:bg-[var(--bjork-surface-hover)]\",\n                )}\n              >\n                {isOpen && <span aria-hidden=\"true\" className=\"absolute inset-y-2 left-0 w-[3px] rounded-r-full bg-[var(--bjork-accent)]\" />}\n                <button\n                  type=\"button\"\n                  role=\"checkbox\"\n                  aria-checked={isSelected}\n                  aria-label={`Select “${t.subject}”`}\n                  tabIndex={tab}\n                  onClick={() => onToggleSelect(t.id)}\n                  className={cn(\"relative grid size-8 shrink-0 place-items-center rounded-full\", focusRing)}\n                >\n                  <span className={cn(\"transition-opacity duration-100\", isSelected || selecting ? \"opacity-0\" : \"group-hover:opacity-0 group-focus-within:opacity-0\")}>\n                    <InitialsAvatar name={last.from.name} size={30} />\n                  </span>\n                  <span\n                    className={cn(\n                      \"absolute inset-0 grid place-items-center transition-opacity duration-100\",\n                      isSelected || selecting ? \"opacity-100\" : \"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100\",\n                    )}\n                  >\n                    <CheckBox state={isSelected ? \"on\" : \"off\"} />\n                  </span>\n                </button>\n\n                <button\n                  ref={(el) => {\n                    if (el) rowRefs.current.set(t.id, el);\n                    else rowRefs.current.delete(t.id);\n                  }}\n                  type=\"button\"\n                  tabIndex={tab}\n                  aria-current={isOpen ? \"true\" : undefined}\n                  onClick={() => onOpen(t.id)}\n                  onKeyDown={(e) => {\n                    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n                      e.preventDefault();\n                      onStep(t.id, e.key === \"ArrowDown\" ? 1 : -1);\n                    }\n                  }}\n                  className={cn(\"min-w-0 flex-1 rounded-[6px] text-left\", focusRing)}\n                >\n                  <span className=\"flex items-baseline gap-2\">\n                    {t.unread && (\n                      <>\n                        <span aria-hidden=\"true\" className=\"size-[7px] shrink-0 -translate-y-px self-center rounded-full bg-[var(--bjork-accent)]\" />\n                        <span className=\"sr-only\">Unread. </span>\n                      </>\n                    )}\n                    <span className={cn(\"min-w-0 flex-1 truncate text-[13.5px]\", t.unread ? \"font-semibold\" : \"font-medium text-[color:var(--bjork-text-medium)]\")}>\n                      {senderText}\n                      {t.messages.length > 1 && <span className=\"ml-1 font-mono text-[11px] font-normal text-[color:var(--bjork-text-soft)]\">{t.messages.length}</span>}\n                    </span>\n                    <span className={cn(\"shrink-0 font-mono text-[11px] tabular-nums\", t.unread ? \"text-[color:var(--bjork-text)]\" : \"text-[color:var(--bjork-text-soft)]\")}>\n                      {fmt(last.date)}\n                    </span>\n                  </span>\n                  <span className={cn(\"mt-0.5 block truncate pr-6 text-[13px]\", t.unread ? \"font-medium text-[color:var(--bjork-text)]\" : \"text-[color:var(--bjork-text-medium)]\")}>\n                    {t.subject}\n                  </span>\n                  <span className=\"mt-0.5 line-clamp-2 pr-6 text-[12.5px] leading-[1.45] text-[color:var(--bjork-text-muted)]\">{snippet(last.body)}</span>\n                  {Boolean(t.labels?.length || t.attachments?.length) && (\n                    <span className=\"mt-2 flex flex-wrap items-center gap-1.5\">\n                      {t.attachments && t.attachments.length > 0 && (\n                        <span className=\"inline-flex items-center gap-1 rounded-[6px] border border-[color:var(--bjork-border)] px-1.5 py-px text-[11px] text-[color:var(--bjork-text-muted)]\">\n                          <Paperclip aria-hidden=\"true\" className=\"size-3\" />\n                          {t.attachments.length}\n                          <span className=\"sr-only\"> attachments</span>\n                        </span>\n                      )}\n                      {t.labels?.map((id) => {\n                        const l = labels.find((x) => x.id === id);\n                        if (!l) return null;\n                        return (\n                          <span key={id} className=\"inline-flex items-center gap-1 rounded-[6px] bg-[var(--bjork-surface-active)] px-1.5 py-px text-[11px] text-[color:var(--bjork-text-medium)]\">\n                            <span aria-hidden=\"true\" className=\"size-1.5 rounded-[2px]\" style={{ background: l.color }} />\n                            {l.name}\n                          </span>\n                        );\n                      })}\n                    </span>\n                  )}\n                </button>\n\n                <button\n                  type=\"button\"\n                  aria-pressed={Boolean(t.starred)}\n                  aria-label={`Star “${t.subject}”`}\n                  tabIndex={tab}\n                  onClick={() => onToggleStar(t.id)}\n                  className={cn(\n                    \"absolute bottom-3 right-2 grid size-7 place-items-center rounded-[7px] transition-[color,opacity,transform] duration-150 active:scale-90 motion-reduce:active:scale-100\",\n                    t.starred\n                      ? \"text-[color:var(--blk-warning)]\"\n                      : \"text-[color:var(--bjork-text-faint)] opacity-0 hover:text-[color:var(--bjork-text-medium)] group-hover:opacity-100 focus-visible:opacity-100\",\n                    focusRing,\n                  )}\n                >\n                  <Star aria-hidden=\"true\" className=\"size-[15px]\" fill={t.starred ? \"currentColor\" : \"none\"} />\n                </button>\n              </div>\n            </motion.li>\n          );\n        })}\n      </AnimatePresence>\n    </ul>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Reader\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction Reader({\n  thread,\n  labels,\n  me,\n  fmt,\n  position,\n  showBack,\n  folder,\n  replyRef,\n  onBack,\n  onStep,\n  onArchive,\n  onTrash,\n  onUnread,\n  onStar,\n  onSend,\n}: {\n  thread: InboxThread | null;\n  labels: InboxLabel[];\n  me: InboxPerson;\n  fmt: { short: (iso: string) => string; full: (iso: string) => string };\n  position: { index: number; total: number } | null;\n  showBack: boolean;\n  folder: InboxFolder | \"starred\";\n  replyRef: RefObject<HTMLTextAreaElement | null>;\n  onBack: () => void;\n  onStep: (delta: number) => void;\n  onArchive: () => void;\n  onTrash: () => void;\n  onUnread: () => void;\n  onStar: () => void;\n  onSend: (body: string) => void;\n}) {\n  const scrollRef = useRef<HTMLDivElement>(null);\n  const headingId = useId();\n\n  if (!thread) {\n    return (\n      <section aria-label=\"Reading pane\" className=\"flex min-w-0 flex-1 flex-col items-center justify-center gap-3 bg-[var(--bjork-panel)] px-8 text-center\">\n        <span aria-hidden=\"true\" className=\"grid size-14 place-items-center rounded-[16px] border border-[color:var(--bjork-border)] bg-[var(--bjork-surface)] shadow-[var(--bjork-shadow-surface)]\">\n          <Mail className=\"size-6 text-[color:var(--bjork-text-muted)]\" />\n        </span>\n        <p className=\"text-[14px] font-medium\">No conversation open</p>\n        <p className=\"flex flex-wrap items-center justify-center gap-1.5 text-[12.5px] text-[color:var(--bjork-text-muted)]\">\n          Pick one from the list, or press <Kbd>J</Kbd> to start at the top.\n        </p>\n      </section>\n    );\n  }\n\n  return (\n    <section aria-labelledby={headingId} className=\"flex min-w-0 flex-1 flex-col bg-[var(--bjork-panel)]\">\n      <div role=\"toolbar\" aria-label=\"Conversation actions\" className=\"flex h-14 shrink-0 items-center gap-1 border-b border-[color:var(--bjork-border)] bg-[var(--bjork-bg)] px-2 @3xl:px-3\">\n        {showBack && (\n          <IconButton label=\"Back to list\" onClick={onBack}>\n            <ArrowLeft />\n          </IconButton>\n        )}\n        <IconButton label={folder === \"archive\" ? \"Move to inbox (E)\" : \"Archive (E)\"} onClick={onArchive}>\n          {folder === \"archive\" ? <ArchiveRestore /> : <Archive />}\n        </IconButton>\n        <IconButton label=\"Move to trash (#)\" onClick={onTrash}>\n          <Trash2 />\n        </IconButton>\n        <IconButton label=\"Mark as unread (U)\" onClick={onUnread}>\n          <Mail />\n        </IconButton>\n        <IconButton label={thread.starred ? \"Unstar (S)\" : \"Star (S)\"} pressed={Boolean(thread.starred)} onClick={onStar}>\n          <Star fill={thread.starred ? \"currentColor\" : \"none\"} className={thread.starred ? \"text-[color:var(--blk-warning)]\" : undefined} />\n        </IconButton>\n        {position && (\n          <div className=\"ml-auto flex items-center gap-1\">\n            <span className=\"hidden font-mono text-[11.5px] tabular-nums text-[color:var(--bjork-text-soft)] @lg:inline\">\n              {position.index + 1} of {position.total}\n            </span>\n            <IconButton label=\"Newer conversation (K)\" size=\"sm\" disabled={position.index === 0} onClick={() => onStep(-1)}>\n              <ChevronUp />\n            </IconButton>\n            <IconButton label=\"Older conversation (J)\" size=\"sm\" disabled={position.index >= position.total - 1} onClick={() => onStep(1)}>\n              <ChevronDown />\n            </IconButton>\n          </div>\n        )}\n      </div>\n\n      <div ref={scrollRef} className=\"@container/reader min-h-0 flex-1 overflow-y-auto overscroll-contain\">\n        <div className=\"mx-auto w-full max-w-[760px] px-4 pb-6 pt-6 @2xl/reader:px-8\">\n          <h2 id={headingId} className=\"text-[20px] font-semibold leading-[1.25] tracking-[-0.02em] @2xl/reader:text-[22px]\">\n            {thread.subject}\n          </h2>\n          {thread.labels && thread.labels.length > 0 && (\n            <ul className=\"mt-2.5 flex flex-wrap gap-1.5\" aria-label=\"Labels\">\n              {thread.labels.map((id) => {\n                const l = labels.find((x) => x.id === id);\n                if (!l) return null;\n                return (\n                  <li key={id} className=\"inline-flex items-center gap-1.5 rounded-[7px] border border-[color:var(--bjork-border)] bg-[var(--bjork-surface)] px-2 py-0.5 text-[11.5px] text-[color:var(--bjork-text-medium)]\">\n                    <span aria-hidden=\"true\" className=\"size-1.5 rounded-[2px]\" style={{ background: l.color }} />\n                    {l.name}\n                  </li>\n                );\n              })}\n            </ul>\n          )}\n\n          <MessageStack key={thread.id} thread={thread} fmt={fmt} />\n\n          {thread.attachments && thread.attachments.length > 0 && (\n            <ul aria-label=\"Attachments\" className=\"mt-4 grid grid-cols-1 gap-2 @lg/reader:grid-cols-2\">\n              {thread.attachments.map((a) => (\n                <li key={a.name}>\n                  <a\n                    href={`#${a.name}`}\n                    onClick={(e) => e.preventDefault()}\n                    className={cn(\n                      \"flex items-center gap-3 rounded-[12px] border border-[color:var(--bjork-border)] bg-[var(--bjork-surface)] p-2.5 shadow-[var(--bjork-shadow-soft)] transition-colors hover:border-[color:var(--bjork-border-strong)]\",\n                      focusRing,\n                    )}\n                  >\n                    <span aria-hidden=\"true\" className=\"grid size-9 shrink-0 place-items-center rounded-[9px] bg-[var(--bjork-accent-soft)] text-[color:var(--blk-accent-ink)]\">\n                      <File className=\"size-4\" />\n                    </span>\n                    <span className=\"min-w-0\">\n                      <span className=\"block truncate text-[13px] font-medium\">{a.name}</span>\n                      <span className=\"block font-mono text-[11px] text-[color:var(--bjork-text-soft)]\">{a.size}</span>\n                    </span>\n                  </a>\n                </li>\n              ))}\n            </ul>\n          )}\n        </div>\n      </div>\n\n      <ReplyBox\n        key={thread.id}\n        to={thread.messages.filter((m) => m.from.email !== me.email).at(-1)?.from ?? thread.messages[0].from}\n        replyRef={replyRef}\n        onSend={(body) => {\n          onSend(body);\n          window.requestAnimationFrame(() => scrollRef.current?.scrollTo({ top: scrollRef.current.scrollHeight, behavior: \"smooth\" }));\n        }}\n      />\n    </section>\n  );\n}\n\nfunction MessageStack({ thread, fmt }: { thread: InboxThread; fmt: { short: (iso: string) => string; full: (iso: string) => string } }) {\n  // The newest message is open; older ones fold to one line and open on click.\n  const [expanded, setExpanded] = useState<Set<string>>(() => new Set([thread.messages[thread.messages.length - 1]?.id]));\n  const lastId = thread.messages[thread.messages.length - 1]?.id;\n  return (\n    <ol className=\"mt-5 flex flex-col gap-2.5\">\n      {thread.messages.map((m) => {\n        const isOpen = expanded.has(m.id) || m.id === lastId;\n        return (\n          <li\n            key={m.id}\n            className={cn(\n              \"overflow-hidden rounded-[14px] border border-[color:var(--bjork-border)] bg-[var(--bjork-surface)]\",\n              isOpen && \"shadow-[var(--bjork-shadow-surface)]\",\n            )}\n          >\n            <button\n              type=\"button\"\n              aria-expanded={isOpen}\n              disabled={m.id === lastId}\n              onClick={() =>\n                setExpanded((s) => {\n                  const next = new Set(s);\n                  if (next.has(m.id)) next.delete(m.id);\n                  else next.add(m.id);\n                  return next;\n                })\n              }\n              className={cn(\"flex w-full items-center gap-3 px-4 py-3 text-left disabled:cursor-default\", focusRing, \"focus-visible:ring-inset focus-visible:ring-offset-0\")}\n            >\n              <InitialsAvatar name={m.from.name} size={30} />\n              <span className=\"min-w-0 flex-1\">\n                <span className=\"flex items-baseline gap-2\">\n                  <span className=\"truncate text-[13.5px] font-semibold\">{m.from.name}</span>\n                  {isOpen && <span className=\"hidden truncate text-[12px] text-[color:var(--bjork-text-soft)] @md/reader:inline\">{m.from.email}</span>}\n                </span>\n                {!isOpen && <span className=\"block truncate text-[12.5px] text-[color:var(--bjork-text-muted)]\">{snippet(m.body)}</span>}\n              </span>\n              <time dateTime={m.date} className=\"shrink-0 text-[11.5px] tabular-nums text-[color:var(--bjork-text-soft)]\">\n                {isOpen ? fmt.full(m.date) : fmt.short(m.date)}\n              </time>\n            </button>\n            {isOpen && (\n              <div className=\"px-4 pb-4 pl-[58px] text-[13.5px] leading-[1.65] text-[color:var(--bjork-text-strong)]\">\n                {m.body.split(/\\n{2,}/).map((para, i) => (\n                  <p key={i} className={cn(i > 0 && \"mt-3\", \"whitespace-pre-line\")}>\n                    {para}\n                  </p>\n                ))}\n              </div>\n            )}\n          </li>\n        );\n      })}\n    </ol>\n  );\n}\n\nfunction ReplyBox({\n  to,\n  replyRef,\n  onSend,\n}: {\n  to: InboxPerson;\n  replyRef: RefObject<HTMLTextAreaElement | null>;\n  onSend: (body: string) => void;\n}) {\n  const [body, setBody] = useState(\"\");\n  const [focused, setFocused] = useState(false);\n  const id = useId();\n  const send = () => {\n    const text = body.trim();\n    if (!text) return;\n    onSend(text);\n    setBody(\"\");\n  };\n  const expanded = focused || body.length > 0;\n  return (\n    <div className=\"shrink-0 border-t border-[color:var(--bjork-border)] bg-[var(--bjork-bg)] p-3 @2xl:px-5\">\n      <div\n        className={cn(\n          \"mx-auto max-w-[760px] rounded-[14px] border bg-[var(--bjork-field)] shadow-[var(--bjork-shadow-soft)] transition-[border-color,box-shadow] duration-150\",\n          focused ? \"border-[color:var(--bjork-accent)] ring-[3px] ring-[color:var(--bjork-accent-soft)]\" : \"border-[color:var(--bjork-border)]\",\n        )}\n      >\n        <label htmlFor={id} className=\"flex items-center gap-1.5 px-3.5 pt-2.5 text-[12px] text-[color:var(--bjork-text-muted)]\">\n          <Reply aria-hidden=\"true\" className=\"size-3.5\" />\n          Reply to <span className=\"font-medium text-[color:var(--bjork-text-medium)]\">{to.name}</span>\n        </label>\n        <textarea\n          ref={replyRef}\n          id={id}\n          value={body}\n          rows={expanded ? 4 : 1}\n          onChange={(e) => setBody(e.target.value)}\n          onFocus={() => setFocused(true)}\n          onBlur={() => setFocused(false)}\n          onKeyDown={(e) => {\n            if (e.key === \"Enter\" && (e.metaKey || e.ctrlKey)) {\n              e.preventDefault();\n              send();\n            } else if (e.key === \"Escape\") {\n              e.stopPropagation();\n              e.currentTarget.blur();\n            }\n          }}\n          placeholder=\"Write a reply…\"\n          className=\"block w-full resize-none bg-transparent px-3.5 py-2 text-[13.5px] leading-[1.55] text-[color:var(--bjork-text)] outline-none placeholder:text-[color:var(--bjork-text-soft)]\"\n        />\n        <div className={cn(\"flex items-center justify-between gap-2 px-2.5 pb-2.5\", !expanded && \"hidden\")}>\n          <span className=\"flex items-center gap-1 pl-1 text-[11.5px] text-[color:var(--bjork-text-soft)]\">\n            <Kbd>⌘</Kbd>\n            <Kbd>↵</Kbd>\n            <span className=\"ml-0.5\">to send</span>\n          </span>\n          <BlockButton\n            variant=\"primary\"\n            size=\"sm\"\n            disabled={!body.trim()}\n            onMouseDown={(e) => e.preventDefault()}\n            onClick={send}\n          >\n            <Send aria-hidden=\"true\" />\n            Send\n          </BlockButton>\n        </div>\n      </div>\n    </div>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Undo bar and dialogs\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction UndoBar({\n  undo,\n  onUndo,\n  onDismiss,\n}: {\n  undo: { message: string } | null;\n  onUndo: () => void;\n  onDismiss: () => void;\n}) {\n  return (\n    <div className=\"pointer-events-none absolute inset-x-0 bottom-4 z-40 flex justify-center px-4\">\n      <div\n        inert={!undo}\n        aria-hidden={!undo}\n        className={cn(\n          \"flex max-w-full items-center gap-2 rounded-[12px] border border-[color:var(--bjork-border-strong)] bg-[var(--bjork-menu)] py-1.5 pl-3.5 pr-1.5 text-[12.5px] font-medium shadow-[var(--bjork-shadow-menu)] backdrop-blur-xl transition-[opacity,transform] duration-200 ease-out motion-reduce:transition-opacity\",\n          undo ? \"pointer-events-auto translate-y-0 opacity-100\" : \"translate-y-2 opacity-0\",\n        )}\n      >\n        <span className=\"truncate\">{undo?.message}</span>\n        <BlockButton size=\"sm\" variant=\"ghost\" onClick={onUndo} className=\"text-[color:var(--blk-accent-ink)]\">\n          Undo\n          <Kbd>Z</Kbd>\n        </BlockButton>\n        <IconButton label=\"Dismiss\" size=\"sm\" onClick={onDismiss}>\n          <X />\n        </IconButton>\n      </div>\n    </div>\n  );\n}\n\nfunction ComposeDialog({\n  open,\n  onClose,\n  onSend,\n}: {\n  open: boolean;\n  onClose: () => void;\n  onSend: (draft: { to: string; subject: string; body: string }) => void;\n}) {\n  const [to, setTo] = useState(\"\");\n  const [subject, setSubject] = useState(\"\");\n  const [body, setBody] = useState(\"\");\n  const [error, setError] = useState<string | null>(null);\n  const bodyId = useId();\n  const reset = () => {\n    setTo(\"\");\n    setSubject(\"\");\n    setBody(\"\");\n    setError(null);\n  };\n  const submit = () => {\n    if (!/^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/.test(to.trim())) {\n      setError(\"Add a valid email address.\");\n      return;\n    }\n    onSend({ to: to.trim(), subject: subject.trim(), body: body.trim() });\n    reset();\n  };\n  return (\n    <BlockDialog\n      open={open}\n      onClose={() => {\n        onClose();\n      }}\n      title=\"New message\"\n      className=\"max-w-[520px]\"\n      footer={\n        <>\n          <span className=\"mr-auto hidden items-center gap-1 text-[11.5px] text-[color:var(--bjork-text-soft)] @md:flex\">\n            <Kbd>⌘</Kbd>\n            <Kbd>↵</Kbd>\n          </span>\n          <BlockButton\n            size=\"sm\"\n            variant=\"ghost\"\n            onClick={() => {\n              reset();\n              onClose();\n            }}\n          >\n            Discard\n          </BlockButton>\n          <BlockButton size=\"sm\" variant=\"primary\" onClick={submit}>\n            <Send aria-hidden=\"true\" />\n            Send\n          </BlockButton>\n        </>\n      }\n    >\n      <form\n        className=\"flex flex-col gap-3\"\n        onSubmit={(e) => {\n          e.preventDefault();\n          submit();\n        }}\n        onKeyDown={(e) => {\n          if (e.key === \"Enter\" && (e.metaKey || e.ctrlKey)) {\n            e.preventDefault();\n            submit();\n          }\n        }}\n      >\n        <BlockField\n          data-autofocus\n          label=\"To\"\n          type=\"email\"\n          value={to}\n          onChange={(e) => {\n            setTo(e.target.value);\n            setError(null);\n          }}\n          error={error}\n          placeholder=\"name@company.com\"\n        />\n        <BlockField label=\"Subject\" value={subject} onChange={(e) => setSubject(e.target.value)} />\n        <div className=\"flex flex-col gap-1.5\">\n          <label htmlFor={bodyId} className=\"text-[12.5px] font-medium text-[color:var(--bjork-text-medium)]\">\n            Message\n          </label>\n          <textarea id={bodyId} rows={6} value={body} onChange={(e) => setBody(e.target.value)} className={cn(inputClass, \"h-auto resize-none py-2.5 leading-[1.55]\")} />\n        </div>\n        <button type=\"submit\" className=\"hidden\" tabIndex={-1} aria-hidden=\"true\" />\n      </form>\n    </BlockDialog>\n  );\n}\n\nconst SHORTCUTS: [string[], string][] = [\n  [[\"J\"], \"Older conversation\"],\n  [[\"K\"], \"Newer conversation\"],\n  [[\"↑\", \"↓\"], \"Move through the list\"],\n  [[\"E\"], \"Archive\"],\n  [[\"#\"], \"Move to trash\"],\n  [[\"S\"], \"Star\"],\n  [[\"U\"], \"Mark as unread\"],\n  [[\"X\"], \"Select\"],\n  [[\"R\"], \"Reply\"],\n  [[\"C\"], \"Compose\"],\n  [[\"Z\"], \"Undo\"],\n  [[\"/\"], \"Search\"],\n  [[\"Esc\"], \"Clear selection or go back\"],\n];\n\nfunction ShortcutsDialog({ open, onClose }: { open: boolean; onClose: () => void }) {\n  return (\n    <BlockDialog\n      open={open}\n      onClose={onClose}\n      title=\"Keyboard shortcuts\"\n      description=\"They work anywhere in the inbox except while you're typing.\"\n      footer={\n        <BlockButton size=\"sm\" variant=\"secondary\" onClick={onClose} data-autofocus>\n          Done\n        </BlockButton>\n      }\n    >\n      <dl className=\"grid grid-cols-[auto_1fr] items-center gap-x-4 gap-y-2 text-[13px]\">\n        {SHORTCUTS.map(([keys, what]) => (\n          <div key={what} className=\"contents\">\n            <dt className=\"flex gap-1\">\n              {keys.map((k) => (\n                <Kbd key={k}>{k}</Kbd>\n              ))}\n            </dt>\n            <dd className=\"text-[color:var(--bjork-text-medium)]\">{what}</dd>\n          </div>\n        ))}\n      </dl>\n    </BlockDialog>\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/bjork-ui/blocks/app-inbox.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-inbox.json",
    "installCommand": "npx shadcn@latest add https://ui.isaiahbjork.com/app-inbox.json"
  },
  "type": "registry:block"
}