{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-ai-chat",
  "title": "AI chat app",
  "description": "AI chat app 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-ai-chat.tsx",
      "content": "\"use client\";\n\nimport {\n  Fragment,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n  type KeyboardEvent as ReactKeyboardEvent,\n  type RefObject,\n} from \"react\";\nimport {\n  ArrowDown,\n  ArrowUp,\n  Check,\n  ChevronDown,\n  Copy,\n  FileText,\n  Menu,\n  MessageSquarePlus,\n  PanelLeftClose,\n  PanelLeftOpen,\n  Paperclip,\n  Pencil,\n  RotateCcw,\n  Search,\n  Square,\n  ThumbsDown,\n  ThumbsUp,\n  Trash2,\n  X,\n} from \"lucide-react\";\nimport {\n  BlockButton,\n  BlockDrawer,\n  IconButton,\n  InitialsAvatar,\n  Kbd,\n  blockRoot,\n  focusRing,\n  useAnnouncer,\n  useAppBlockTheme,\n  useBlockReducedMotion,\n  useElementWidth,\n  type AppBlockTheme,\n} from \"@/components/bjork-ui/blocks/app-block-kit\";\nimport { cn } from \"@/lib/utils\";\n\n/* ----------------------------------------------------------------------------------------------------------\n * Types\n * -------------------------------------------------------------------------------------------------------- */\n\nexport interface ChatAttachment {\n  name: string;\n  size: string;\n}\n\nexport interface ChatMessage {\n  id: string;\n  role: \"user\" | \"assistant\";\n  /** Markdown-lite: paragraphs, `- ` lists, `1. ` lists, **bold**, `code` and ``` fenced blocks. */\n  content: string;\n  attachments?: ChatAttachment[];\n  /** Set when a reply was stopped part-way. */\n  stopped?: boolean;\n  feedback?: \"up\" | \"down\";\n}\n\nexport interface ChatConversation {\n  id: string;\n  title: string;\n  /** ISO date, for grouping in the sidebar. */\n  updated: string;\n  messages: ChatMessage[];\n}\n\nexport interface ChatModel {\n  id: string;\n  name: string;\n  hint: string;\n}\n\nexport interface ChatRequest {\n  conversationId: string;\n  model: string;\n  messages: ChatMessage[];\n  signal: AbortSignal;\n}\n\nexport interface AppAiChatProps {\n  conversations?: ChatConversation[];\n  models?: ChatModel[];\n  defaultModel?: string;\n  /** Conversation open on first render. Defaults to the most recent; pass null for a new chat. */\n  defaultConversationId?: string | null;\n  /**\n   * Streams the assistant reply. Yield text chunks; stop when `signal` aborts. Defaults to a local\n   * simulator so the block works without a backend.\n   */\n  respond?: (request: ChatRequest) => AsyncIterable<string>;\n  onConversationsChange?: (conversations: ChatConversation[]) => void;\n  onFeedback?: (messageId: string, feedback: \"up\" | \"down\" | undefined) => void;\n  user?: { name: string };\n  assistantName?: string;\n  suggestions?: { title: string; prompt: string }[];\n  /** \"Now\" for the Today / Previous 7 days grouping. Defaults to the newest conversation. */\n  now?: string;\n  theme?: AppBlockTheme;\n  className?: string;\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Sample data and the offline responder\n * -------------------------------------------------------------------------------------------------------- */\n\nconst SAMPLE_MODELS: ChatModel[] = [\n  { id: \"swift\", name: \"Swift\", hint: \"Fast answers for everyday questions\" },\n  { id: \"deep\", name: \"Deep\", hint: \"Slower, thinks through multi-step problems\" },\n  { id: \"code\", name: \"Code\", hint: \"Tuned for reading and writing code\" },\n];\n\nconst SAMPLE_SUGGESTIONS = [\n  { title: \"Explain a concept\", prompt: \"Explain how a debounce differs from a throttle, with a small example.\" },\n  { title: \"Draft a message\", prompt: \"Draft a short note to my team moving Thursday's review to 2pm.\" },\n  { title: \"Review some code\", prompt: \"What could go wrong with this?\\n\\nuseEffect(() => { setCount(count + 1) }, [count])\" },\n  { title: \"Plan something\", prompt: \"Plan a three-step rollout for a new dashboard to 40 users.\" },\n];\n\nconst SAMPLE_CONVERSATIONS: ChatConversation[] = [\n  {\n    id: \"c1\",\n    title: \"Debounce vs throttle for search\",\n    updated: \"2026-10-08T15:20:00Z\",\n    messages: [\n      { id: \"c1m1\", role: \"user\", content: \"Should the dashboard search input be debounced or throttled?\" },\n      {\n        id: \"c1m2\",\n        role: \"assistant\",\n        content:\n          \"**Debounce it.** You want one query after the person stops typing, not a query every N milliseconds while they type.\\n\\n- **Debounce** waits for a pause, then fires once. Right for search, autosave and resize-driven layout.\\n- **Throttle** fires at most once per interval while events keep coming. Right for scroll position and pointer tracking.\\n\\nA small version:\\n\\n```ts\\nfunction debounce<T extends unknown[]>(fn: (...args: T) => void, ms = 200) {\\n  let timer: ReturnType<typeof setTimeout> | undefined;\\n  return (...args: T) => {\\n    clearTimeout(timer);\\n    timer = setTimeout(() => fn(...args), ms);\\n  };\\n}\\n```\\n\\nFor a filter over data already in memory, skip both and filter on every keystroke; it's fast enough and feels more direct.\",\n        feedback: \"up\",\n      },\n    ],\n  },\n  {\n    id: \"c2\",\n    title: \"Rollout plan for the Northwind pilot\",\n    updated: \"2026-10-07T18:02:00Z\",\n    messages: [\n      { id: \"c2m1\", role: \"user\", content: \"Help me plan the Northwind pilot. 40 seats, two warehouses, starts Nov 3.\" },\n      {\n        id: \"c2m2\",\n        role: \"assistant\",\n        content:\n          \"Here's a three-phase plan that keeps risk low:\\n\\n1. **Week 1, one warehouse, 8 people.** Shadow two shifts, fix the top three papercuts.\\n2. **Week 2, the rest of that warehouse.** Turn on scheduled CSV exports and per-store permissions.\\n3. **Week 3, second warehouse.** Run a 20-minute training and keep a feedback channel open.\\n\\nDecide upfront what “success” means, for example 80% weekly active seats by the end of week 4.\",\n      },\n    ],\n  },\n  { id: \"c3\", title: \"Offer note for Kai\", updated: \"2026-10-06T10:00:00Z\", messages: [{ id: \"c3m1\", role: \"user\", content: \"Help me write two sentences for an offer note.\" }, { id: \"c3m2\", role: \"assistant\", content: \"Kai's systems interview stood out for how calmly they reasoned about failure: every design came with a plan for the slow, partial and wrong cases. We think that instinct will make our dashboard sturdier from week one.\" }] },\n  { id: \"c4\", title: \"Colour contrast for chart lines\", updated: \"2026-10-02T09:00:00Z\", messages: [{ id: \"c4m1\", role: \"user\", content: \"Is 30% ink enough contrast for a comparison line?\" }, { id: \"c4m2\", role: \"assistant\", content: \"For a secondary series, yes, as long as it's not the only way to tell the series apart. Pair it with a dash pattern and a legend, and keep the primary line at full strength.\" }] },\n  { id: \"c5\", title: \"SQL for weekly active seats\", updated: \"2026-09-24T14:00:00Z\", messages: [{ id: \"c5m1\", role: \"user\", content: \"SQL for weekly active seats?\" }, { id: \"c5m2\", role: \"assistant\", content: \"```sql\\nselect date_trunc('week', seen_at) as week,\\n       count(distinct user_id) as active_seats\\nfrom events\\ngroup by 1\\norder by 1;\\n```\" }] },\n];\n\nconst delay = (ms: number, signal: AbortSignal) =>\n  new Promise<void>((resolve) => {\n    const t = setTimeout(resolve, ms);\n    signal.addEventListener(\"abort\", () => {\n      clearTimeout(t);\n      resolve();\n    });\n  });\n\n/** Picks a canned answer for the prompt and streams it word by word. */\nasync function* simulateResponse({ messages, model, signal }: ChatRequest): AsyncIterable<string> {\n  const prompt = messages[messages.length - 1]?.content.toLowerCase() ?? \"\";\n  let answer: string;\n  if (prompt.includes(\"debounce\") || prompt.includes(\"throttle\")) {\n    answer =\n      \"A **debounce** waits until events stop for a set time, then runs once. A **throttle** runs at most once per interval while events keep arriving.\\n\\n- Typing in a search box: debounce, so you query once after the pause.\\n- Tracking scroll position: throttle, so you update steadily without flooding.\\n\\n```ts\\nconst onSearch = debounce((q: string) => fetchResults(q), 250);\\n```\\n\\nRule of thumb: if only the final value matters, debounce. If the in-between values matter, throttle.\";\n  } else if (prompt.includes(\"draft\") || prompt.includes(\"note\") || prompt.includes(\"message\")) {\n    answer =\n      \"Here's a short version you can paste:\\n\\n> Hi all, I'm moving Thursday's design review to **2pm** so Theo can join from Lisbon. Same room, same doc. Agenda stays the same: chart legend, empty states, and the orders table on phones.\\n\\nWant it warmer, or shorter for Slack?\";\n  } else if (prompt.includes(\"useeffect\") || prompt.includes(\"code\") || prompt.includes(\"wrong\")) {\n    answer =\n      \"That effect runs **forever**. It sets `count`, which changes `count`, which is in the dependency list, so the effect runs again.\\n\\nIf you meant to bump it once on mount:\\n\\n```tsx\\nuseEffect(() => {\\n  setCount((c) => c + 1);\\n}, []);\\n```\\n\\nIf you meant to derive something from `count`, compute it during render instead of storing it in state.\";\n  } else if (prompt.includes(\"plan\") || prompt.includes(\"rollout\")) {\n    answer =\n      \"A three-step rollout:\\n\\n1. **Pilot with 5 people** for a week. Watch them use it; fix the top three papercuts.\\n2. **Expand to half** (about 20). Turn on feedback in the app and review it twice a week.\\n3. **Everyone.** Send a two-minute walkthrough video and keep office hours open for the first week.\\n\\nSet the success metric before step one, for example *weekly active seats above 80%*.\";\n  } else {\n    answer = `Good question. Here's how I'd think about it:\\n\\n- Start from what you need to decide, then work back to the information that would change the decision.\\n- Prefer the smallest experiment that gives you a real answer.\\n- Write the result down where the team will see it.\\n\\nTell me more about the context and I can get specific. (Answered by the **${model}** model, simulated locally.)`;\n  }\n  await delay(model === \"deep\" ? 900 : 380, signal);\n  const tokens = answer.match(/\\s*\\S+/g) ?? [answer];\n  for (const token of tokens) {\n    if (signal.aborted) return;\n    yield token;\n    await delay(model === \"swift\" ? 14 : 26, signal);\n  }\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Markdown-lite rendering\n * -------------------------------------------------------------------------------------------------------- */\n\ntype MdBlock =\n  | { kind: \"p\"; text: string }\n  | { kind: \"quote\"; text: string }\n  | { kind: \"ul\" | \"ol\"; items: string[] }\n  | { kind: \"code\"; lang: string; code: string; open: boolean };\n\nfunction parseBlocks(src: string): MdBlock[] {\n  const blocks: MdBlock[] = [];\n  const lines = src.split(\"\\n\");\n  let i = 0;\n  while (i < lines.length) {\n    const line = lines[i];\n    const fence = line.match(/^```(\\w*)\\s*$/);\n    if (fence) {\n      const body: string[] = [];\n      i += 1;\n      while (i < lines.length && !/^```\\s*$/.test(lines[i])) body.push(lines[i++]);\n      const open = i >= lines.length;\n      blocks.push({ kind: \"code\", lang: fence[1] || \"text\", code: body.join(\"\\n\"), open });\n      i += 1;\n      continue;\n    }\n    if (!line.trim()) {\n      i += 1;\n      continue;\n    }\n    const listKind = /^\\s*[-*] /.test(line) ? \"ul\" : /^\\s*\\d+\\. /.test(line) ? \"ol\" : null;\n    if (listKind) {\n      const items: string[] = [];\n      const re = listKind === \"ul\" ? /^\\s*[-*] (.*)$/ : /^\\s*\\d+\\. (.*)$/;\n      while (i < lines.length && re.test(lines[i])) items.push(lines[i++].replace(re, \"$1\"));\n      blocks.push({ kind: listKind, items });\n      continue;\n    }\n    if (line.startsWith(\"> \")) {\n      const body: string[] = [];\n      while (i < lines.length && lines[i].startsWith(\"> \")) body.push(lines[i++].slice(2));\n      blocks.push({ kind: \"quote\", text: body.join(\" \") });\n      continue;\n    }\n    const para: string[] = [];\n    while (i < lines.length && lines[i].trim() && !/^```/.test(lines[i]) && !/^\\s*([-*]|\\d+\\.) /.test(lines[i]) && !lines[i].startsWith(\"> \")) {\n      para.push(lines[i++]);\n    }\n    blocks.push({ kind: \"p\", text: para.join(\" \") });\n  }\n  return blocks;\n}\n\nfunction Inline({ text: raw }: { text: string }) {\n  // Close a bold run that is still streaming, so a half-sent \"**word\" never shows raw asterisks.\n  const text = (raw.split(\"**\").length - 1) % 2 === 1 ? `${raw}**` : raw;\n  const parts = text.split(/(\\*\\*[^*]+\\*\\*|`[^`]+`|\\*[^*\\s][^*]*\\*)/g);\n  return (\n    <>\n      {parts.map((part, i) => {\n        if (part.startsWith(\"**\") && part.endsWith(\"**\") && part.length > 4) {\n          return (\n            <strong key={i} className=\"font-semibold text-[color:var(--bjork-text)]\">\n              {part.slice(2, -2)}\n            </strong>\n          );\n        }\n        if (part.startsWith(\"`\") && part.endsWith(\"`\") && part.length > 2) {\n          return (\n            <code key={i} className=\"rounded-[5px] border border-[color:var(--bjork-border)] bg-[var(--bjork-field-inset)] px-1 py-px font-mono text-[0.88em]\">\n              {part.slice(1, -1)}\n            </code>\n          );\n        }\n        if (part.startsWith(\"*\") && part.endsWith(\"*\") && part.length > 2) return <em key={i}>{part.slice(1, -1)}</em>;\n        return <Fragment key={i}>{part}</Fragment>;\n      })}\n    </>\n  );\n}\n\nfunction CodeBlock({ lang, code }: { lang: string; code: string }) {\n  const [copied, setCopied] = useState(false);\n  const timer = useRef<number | undefined>(undefined);\n  useEffect(() => () => window.clearTimeout(timer.current), []);\n  return (\n    <div className=\"my-3 overflow-hidden rounded-[12px] border border-[color:var(--bjork-border)] bg-[var(--bjork-field-inset)]\">\n      <div className=\"flex h-8 items-center justify-between border-b border-[color:var(--bjork-border)] pl-3 pr-1\">\n        <span className=\"font-mono text-[11px] text-[color:var(--bjork-text-soft)]\">{lang}</span>\n        <button\n          type=\"button\"\n          onClick={() => {\n            void navigator.clipboard?.writeText(code);\n            setCopied(true);\n            window.clearTimeout(timer.current);\n            timer.current = window.setTimeout(() => setCopied(false), 1600);\n          }}\n          className={cn(\n            \"inline-flex h-6 items-center gap-1 rounded-[6px] px-1.5 text-[11.5px] text-[color:var(--bjork-text-muted)] transition-colors hover:bg-[var(--bjork-surface-hover)] hover:text-[color:var(--bjork-text)]\",\n            focusRing,\n          )}\n        >\n          {copied ? <Check aria-hidden=\"true\" className=\"size-3.5\" /> : <Copy aria-hidden=\"true\" className=\"size-3.5\" />}\n          <span aria-live=\"polite\">{copied ? \"Copied\" : \"Copy\"}</span>\n          <span className=\"sr-only\"> code</span>\n        </button>\n      </div>\n      <pre className=\"overflow-x-auto px-3.5 py-3 font-mono text-[12.5px] leading-[1.6] text-[color:var(--bjork-text-strong)]\">\n        <code>{code}</code>\n      </pre>\n    </div>\n  );\n}\n\nfunction Markdown({ content }: { content: string }) {\n  const blocks = useMemo(() => parseBlocks(content), [content]);\n  return (\n    <div className=\"text-[14px] leading-[1.7] text-[color:var(--bjork-text-strong)]\">\n      {blocks.map((b, i) => {\n        const gap = i > 0 ? \"mt-3\" : \"\";\n        if (b.kind === \"code\") return <CodeBlock key={i} lang={b.lang} code={b.code} />;\n        if (b.kind === \"quote\") {\n          return (\n            <blockquote key={i} className={cn(gap, \"border-l-2 border-[color:var(--bjork-accent)] pl-3.5 text-[color:var(--bjork-text-medium)]\")}>\n              <Inline text={b.text} />\n            </blockquote>\n          );\n        }\n        if (b.kind !== \"p\") {\n          const List = b.kind;\n          return (\n            <List key={i} className={cn(gap, \"flex flex-col gap-1.5 pl-5\", b.kind === \"ul\" ? \"list-disc marker:text-[color:var(--bjork-text-soft)]\" : \"list-decimal marker:font-mono marker:text-[12px] marker:text-[color:var(--bjork-text-soft)]\")}>\n              {b.items.map((item, j) => (\n                <li key={j} className=\"pl-1\">\n                  <Inline text={item} />\n                </li>\n              ))}\n            </List>\n          );\n        }\n        return (\n          <p key={i} className={gap}>\n            <Inline text={b.text} />\n          </p>\n        );\n      })}\n    </div>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Helpers\n * -------------------------------------------------------------------------------------------------------- */\n\nconst DAY = 86_400_000;\n\nfunction groupConversations(list: ChatConversation[], now: number) {\n  const groups: { label: string; items: ChatConversation[] }[] = [\n    { label: \"Today\", items: [] },\n    { label: \"Previous 7 days\", items: [] },\n    { label: \"Older\", items: [] },\n  ];\n  const startOfToday = Math.floor(now / DAY) * DAY;\n  for (const c of [...list].sort((a, b) => b.updated.localeCompare(a.updated))) {\n    const t = new Date(c.updated).getTime();\n    groups[t >= startOfToday ? 0 : t >= startOfToday - 7 * DAY ? 1 : 2].items.push(c);\n  }\n  return groups.filter((g) => g.items.length > 0);\n}\n\nlet idCounter = 0;\nconst newId = (prefix: string) => `${prefix}${Date.now().toString(36)}${(idCounter += 1)}`;\n\nfunction titleFrom(text: string) {\n  const clean = text.replace(/\\s+/g, \" \").trim();\n  return clean.length > 42 ? `${clean.slice(0, 40).trimEnd()}…` : clean || \"New chat\";\n}\n\nconst DRAWER_BELOW = 760;\n\n/* ----------------------------------------------------------------------------------------------------------\n * Block\n * -------------------------------------------------------------------------------------------------------- */\n\nexport function AppAiChat({\n  conversations: initial = SAMPLE_CONVERSATIONS,\n  models = SAMPLE_MODELS,\n  defaultModel,\n  defaultConversationId,\n  respond = simulateResponse,\n  onConversationsChange,\n  onFeedback,\n  user = { name: \"Rhea Castillo\" },\n  assistantName = \"Assistant\",\n  suggestions = SAMPLE_SUGGESTIONS,\n  now,\n  theme = \"auto\",\n  className,\n}: AppAiChatProps) {\n  const { style } = useAppBlockTheme(theme);\n  const reduce = useBlockReducedMotion();\n  const rootRef = useRef<HTMLDivElement>(null);\n  const width = useElementWidth(rootRef);\n  const narrow = width > 0 && width < DRAWER_BELOW;\n  const { announce, region } = useAnnouncer();\n\n  const [conversations, setConversations] = useState(initial);\n  const [activeId, setActiveId] = useState<string | null>(() =>\n    defaultConversationId === undefined\n      ? ([...initial].sort((a, b) => b.updated.localeCompare(a.updated))[0]?.id ?? null)\n      : defaultConversationId,\n  );\n  const [model, setModel] = useState(defaultModel ?? models[0]?.id ?? \"default\");\n  const [collapsed, setCollapsed] = useState(false);\n  const [drawerOpen, setDrawerOpen] = useState(false);\n  const [streamingId, setStreamingId] = useState<string | null>(null);\n  const [draft, setDraft] = useState(\"\");\n  const [attachments, setAttachments] = useState<ChatAttachment[]>([]);\n  const [error, setError] = useState<string | null>(null);\n  const abortRef = useRef<AbortController | null>(null);\n  // Latest list, for code that runs after an await and must not read a stale closure.\n  const latest = useRef(initial);\n  useEffect(() => {\n    latest.current = conversations;\n  }, [conversations]);\n  const composerRef = useRef<HTMLTextAreaElement>(null);\n\n  const nowMs = useMemo(\n    () => (now ? new Date(now).getTime() : Math.max(0, ...initial.map((c) => new Date(c.updated).getTime()))),\n    [now, initial],\n  );\n  const active = conversations.find((c) => c.id === activeId) ?? null;\n  const streaming = streamingId !== null;\n\n  const commit = (next: ChatConversation[]) => {\n    setConversations(next);\n    onConversationsChange?.(next);\n  };\n\n  useEffect(() => () => abortRef.current?.abort(), []);\n\n  /** Streams a reply into `conversationId`, given the history it should answer. */\n  const stream = async (conversationId: string, history: ChatMessage[], base: ChatConversation[]) => {\n    const controller = new AbortController();\n    abortRef.current = controller;\n    const replyId = newId(\"a\");\n    const reply: ChatMessage = { id: replyId, role: \"assistant\", content: \"\" };\n    const working = base.map((c) =>\n      c.id === conversationId ? { ...c, messages: [...history, reply], updated: new Date(Math.max(Date.now(), nowMs)).toISOString() } : c,\n    );\n    latest.current = working;\n    setConversations(working);\n    setStreamingId(replyId);\n    setError(null);\n    let text = \"\";\n    let frame = 0;\n    const flush = () => {\n      frame = 0;\n      setConversations((list) =>\n        list.map((c) =>\n          c.id === conversationId ? { ...c, messages: c.messages.map((m) => (m.id === replyId ? { ...m, content: text } : m)) } : c,\n        ),\n      );\n    };\n    try {\n      for await (const chunk of respond({ conversationId, model, messages: history, signal: controller.signal })) {\n        if (controller.signal.aborted) break;\n        text += chunk;\n        // Batch chunks into one render per frame.\n        if (!frame) frame = window.requestAnimationFrame(flush);\n      }\n    } catch (err) {\n      if (!controller.signal.aborted) setError(err instanceof Error ? err.message : \"The reply failed. Try again.\");\n    } finally {\n      if (frame) window.cancelAnimationFrame(frame);\n      const stopped = controller.signal.aborted;\n      const next = latest.current.map((c) =>\n        c.id === conversationId\n          ? { ...c, messages: c.messages.map((m) => (m.id === replyId ? { ...m, content: text, stopped: stopped || undefined } : m)) }\n          : c,\n      );\n      latest.current = next;\n      commit(next);\n      setStreamingId(null);\n      if (abortRef.current === controller) abortRef.current = null;\n      announce(stopped ? \"Response stopped\" : `${assistantName} replied`);\n    }\n  };\n\n  const send = (text: string) => {\n    const content = text.trim();\n    if (!content || streaming) return;\n    const message: ChatMessage = { id: newId(\"u\"), role: \"user\", content, attachments: attachments.length ? attachments : undefined };\n    let id = active?.id;\n    let base = conversations;\n    if (!id) {\n      id = newId(\"c\");\n      base = [{ id, title: titleFrom(content), updated: new Date(Math.max(Date.now(), nowMs)).toISOString(), messages: [] }, ...conversations];\n      setActiveId(id);\n    }\n    const history = [...(base.find((c) => c.id === id)?.messages ?? []), message];\n    setDraft(\"\");\n    setAttachments([]);\n    void stream(id, history, base);\n  };\n\n  const stop = () => abortRef.current?.abort();\n\n  const regenerate = () => {\n    if (!active || streaming) return;\n    const lastUser = active.messages.map((m) => m.role).lastIndexOf(\"user\");\n    if (lastUser < 0) return;\n    void stream(active.id, active.messages.slice(0, lastUser + 1), conversations);\n  };\n\n  const editLast = () => {\n    if (!active || streaming) return;\n    const lastUser = active.messages.map((m) => m.role).lastIndexOf(\"user\");\n    if (lastUser < 0) return;\n    setDraft(active.messages[lastUser].content);\n    commit(conversations.map((c) => (c.id === active.id ? { ...c, messages: c.messages.slice(0, lastUser) } : c)));\n    window.requestAnimationFrame(() => {\n      const el = composerRef.current;\n      el?.focus();\n      el?.setSelectionRange(el.value.length, el.value.length);\n    });\n  };\n\n  const newChat = () => {\n    if (streaming) stop();\n    setActiveId(null);\n    setDrawerOpen(false);\n    setDraft(\"\");\n    setError(null);\n    window.requestAnimationFrame(() => composerRef.current?.focus());\n  };\n\n  const selectConversation = (id: string) => {\n    if (streaming) stop();\n    setActiveId(id);\n    setDrawerOpen(false);\n    setError(null);\n  };\n\n  const deleteConversation = (id: string) => {\n    const target = conversations.find((c) => c.id === id);\n    if (id === activeId) {\n      if (streaming) stop();\n      setActiveId(null);\n    }\n    commit(conversations.filter((c) => c.id !== id));\n    announce(`Deleted “${target?.title ?? \"conversation\"}”`);\n  };\n\n  const setFeedback = (messageId: string, value: \"up\" | \"down\") => {\n    if (!active) return;\n    const current = active.messages.find((m) => m.id === messageId)?.feedback;\n    const next = current === value ? undefined : value;\n    commit(\n      conversations.map((c) =>\n        c.id === active.id ? { ...c, messages: c.messages.map((m) => (m.id === messageId ? { ...m, feedback: next } : m)) } : c,\n      ),\n    );\n    onFeedback?.(messageId, next);\n    announce(next ? \"Thanks for the feedback\" : \"Feedback removed\");\n  };\n\n  const onRootKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {\n    const mod = event.metaKey || event.ctrlKey;\n    if (mod && event.shiftKey && event.key.toLowerCase() === \"o\") {\n      event.preventDefault();\n      newChat();\n    } else if (event.key === \"Escape\" && streaming) {\n      event.preventDefault();\n      stop();\n    }\n  };\n\n  const sidebar = (mode: \"rail\" | \"drawer\") => (\n    <ChatSidebar\n      mode={mode}\n      collapsed={mode === \"rail\" && collapsed}\n      conversations={conversations}\n      activeId={activeId}\n      now={nowMs}\n      onSelect={selectConversation}\n      onNew={newChat}\n      onDelete={deleteConversation}\n      onToggleCollapsed={() => setCollapsed((v) => !v)}\n      onClose={() => setDrawerOpen(false)}\n      user={user}\n    />\n  );\n\n  return (\n    <div ref={rootRef} className={cn(blockRoot, \"h-full\", className)} style={style} onKeyDown={onRootKeyDown}>\n      {!narrow && (\n        <aside\n          aria-label=\"Chat history\"\n          className={cn(\n            \"relative z-20 flex h-full shrink-0 flex-col border-r border-[color:var(--bjork-border)] bg-[var(--bjork-panel)] transition-[width] duration-[260ms] ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none\",\n            collapsed ? \"w-[60px]\" : \"w-[264px]\",\n          )}\n        >\n          {sidebar(\"rail\")}\n        </aside>\n      )}\n\n      <div className=\"flex min-w-0 flex-1 flex-col\" inert={narrow && drawerOpen}>\n        <header className=\"flex h-14 shrink-0 items-center gap-2 border-b border-[color:var(--bjork-border)] px-3 @3xl:px-4\">\n          {narrow && (\n            <IconButton label=\"Open chat history\" onClick={() => setDrawerOpen(true)} aria-expanded={drawerOpen}>\n              <Menu />\n            </IconButton>\n          )}\n          <ModelPicker models={models} value={model} onChange={setModel} disabled={streaming} />\n          <h1 className=\"sr-only\">{active ? active.title : \"New chat\"}</h1>\n          <p aria-hidden=\"true\" className=\"hidden min-w-0 flex-1 truncate text-center text-[13px] text-[color:var(--bjork-text-muted)] @2xl:block\">\n            {active?.title}\n          </p>\n          <div className=\"ml-auto flex items-center gap-1 @2xl:ml-0\">\n            {narrow && (\n              <IconButton label=\"New chat\" onClick={newChat}>\n                <MessageSquarePlus />\n              </IconButton>\n            )}\n          </div>\n        </header>\n\n        <Thread\n          key={active?.id ?? \"new\"}\n          conversation={active}\n          streamingId={streamingId}\n          reduce={reduce}\n          user={user}\n          assistantName={assistantName}\n          suggestions={suggestions}\n          error={error}\n          onSuggestion={(prompt) => send(prompt)}\n          onRetry={regenerate}\n          onRegenerate={regenerate}\n          onEditLast={editLast}\n          onFeedback={setFeedback}\n          onCopied={() => announce(\"Copied to clipboard\")}\n        />\n\n        <Composer\n          inputRef={composerRef}\n          value={draft}\n          onChange={setDraft}\n          attachments={attachments}\n          onAttach={(files) => setAttachments((a) => [...a, ...files])}\n          onRemoveAttachment={(name) => setAttachments((a) => a.filter((x) => x.name !== name))}\n          streaming={streaming}\n          onSend={() => send(draft)}\n          onStop={stop}\n          canEditLast={Boolean(active?.messages.some((m) => m.role === \"user\"))}\n          onEditLast={editLast}\n          assistantName={assistantName}\n        />\n      </div>\n\n      {narrow && (\n        <BlockDrawer open={drawerOpen} onClose={() => setDrawerOpen(false)} label=\"Chat history\">\n          {sidebar(\"drawer\")}\n        </BlockDrawer>\n      )}\n      {region}\n    </div>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Sidebar\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction ChatSidebar({\n  mode,\n  collapsed,\n  conversations,\n  activeId,\n  now,\n  onSelect,\n  onNew,\n  onDelete,\n  onToggleCollapsed,\n  onClose,\n  user,\n}: {\n  mode: \"rail\" | \"drawer\";\n  collapsed: boolean;\n  conversations: ChatConversation[];\n  activeId: string | null;\n  now: number;\n  onSelect: (id: string) => void;\n  onNew: () => void;\n  onDelete: (id: string) => void;\n  onToggleCollapsed: () => void;\n  onClose: () => void;\n  user: { name: string };\n}) {\n  const [query, setQuery] = useState(\"\");\n  const filtered = useMemo(() => {\n    const q = query.trim().toLowerCase();\n    if (!q) return conversations;\n    return conversations.filter(\n      (c) => c.title.toLowerCase().includes(q) || c.messages.some((m) => m.content.toLowerCase().includes(q)),\n    );\n  }, [conversations, query]);\n  const groups = groupConversations(filtered, now);\n\n  return (\n    <>\n      <div className={cn(\"flex h-14 shrink-0 items-center gap-1.5 border-b border-[color:var(--bjork-border)]\", collapsed ? \"justify-center px-2\" : \"px-3\")}>\n        {collapsed ? (\n          <IconButton label=\"New chat\" onClick={onNew}>\n            <MessageSquarePlus />\n          </IconButton>\n        ) : (\n          <>\n            <BlockButton variant=\"secondary\" size=\"md\" className=\"flex-1 justify-start\" onClick={onNew}>\n              <MessageSquarePlus aria-hidden=\"true\" />\n              New chat\n              <span className=\"ml-auto flex gap-0.5\">\n                <Kbd>⌘</Kbd>\n                <Kbd>⇧</Kbd>\n                <Kbd>O</Kbd>\n              </span>\n            </BlockButton>\n            {mode === \"drawer\" && (\n              <IconButton label=\"Close chat history\" size=\"sm\" onClick={onClose}>\n                <X />\n              </IconButton>\n            )}\n          </>\n        )}\n      </div>\n\n      {!collapsed && (\n        <div className=\"px-3 pt-3\">\n          <label className=\"relative flex items-center\">\n            <span className=\"sr-only\">Search chats</span>\n            <Search aria-hidden=\"true\" className=\"pointer-events-none absolute left-2.5 size-[14px] text-[color:var(--bjork-text-soft)]\" />\n            <input\n              type=\"search\"\n              value={query}\n              onChange={(e) => setQuery(e.target.value)}\n              onKeyDown={(e) => {\n                if (e.key === \"Escape\" && query) {\n                  e.stopPropagation();\n                  setQuery(\"\");\n                }\n              }}\n              placeholder=\"Search chats\"\n              className=\"h-8 w-full rounded-[9px] border border-[color:var(--bjork-border)] bg-[var(--bjork-field)] pl-8 pr-2 text-[12.5px] text-[color:var(--bjork-text)] outline-none transition-[border-color,box-shadow] placeholder:text-[color:var(--bjork-text-soft)] focus-visible:border-[color:var(--bjork-accent)] focus-visible:ring-[3px] focus-visible:ring-[color:var(--bjork-accent-soft)] [&::-webkit-search-cancel-button]:hidden\"\n            />\n          </label>\n        </div>\n      )}\n\n      <nav aria-label=\"Conversations\" className={cn(\"hide-scrollbar flex-1 overflow-y-auto py-3\", collapsed ? \"hidden\" : \"px-2\")}>\n        {groups.length === 0 && (\n          <p className=\"px-3 py-6 text-center text-[12.5px] text-[color:var(--bjork-text-muted)]\">\n            {query ? `No chats match “${query}”.` : \"No chats yet.\"}\n          </p>\n        )}\n        {groups.map((g, gi) => (\n          <div key={g.label} className={cn(gi > 0 && \"mt-4\")}>\n            <h2 className=\"mb-1 px-2.5 font-mono text-[10.5px] uppercase tracking-[0.1em] text-[color:var(--bjork-text-soft)]\">{g.label}</h2>\n            <ul className=\"flex flex-col gap-px\">\n              {g.items.map((c) => {\n                const isActive = c.id === activeId;\n                return (\n                  <li key={c.id} className=\"group relative\">\n                    <a\n                      href={`#${c.id}`}\n                      aria-current={isActive ? \"page\" : undefined}\n                      onClick={(e) => {\n                        e.preventDefault();\n                        onSelect(c.id);\n                      }}\n                      className={cn(\n                        \"flex h-8 items-center rounded-[8px] pl-2.5 pr-8 text-[13px] transition-colors duration-150\",\n                        isActive\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 className=\"truncate\">{c.title}</span>\n                    </a>\n                    <button\n                      type=\"button\"\n                      onClick={() => onDelete(c.id)}\n                      aria-label={`Delete “${c.title}”`}\n                      title=\"Delete chat\"\n                      className={cn(\n                        \"absolute right-1 top-1 grid size-6 place-items-center rounded-[6px] text-[color:var(--bjork-text-soft)] opacity-0 transition-[opacity,color] hover:text-[color:var(--blk-error)] focus-visible:opacity-100 group-hover:opacity-100\",\n                        isActive && \"opacity-100\",\n                        focusRing,\n                      )}\n                    >\n                      <Trash2 aria-hidden=\"true\" className=\"size-3.5\" />\n                    </button>\n                  </li>\n                );\n              })}\n            </ul>\n          </div>\n        ))}\n      </nav>\n      {collapsed && <div className=\"flex-1\" />}\n\n      <div className={cn(\"flex shrink-0 items-center gap-1 border-t border-[color:var(--bjork-border)] p-2.5\", collapsed && \"flex-col px-2\")}>\n        <span className={cn(\"flex min-w-0 items-center gap-2.5 p-1\", !collapsed && \"flex-1\")} title={collapsed ? user.name : undefined}>\n          <InitialsAvatar name={user.name} size={28} />\n          {!collapsed && <span className=\"truncate text-[12.5px] font-medium\">{user.name}</span>}\n          {collapsed && <span className=\"sr-only\">{user.name}</span>}\n        </span>\n        {mode === \"rail\" && (\n          <IconButton label={collapsed ? \"Expand sidebar\" : \"Collapse sidebar\"} size=\"sm\" onClick={onToggleCollapsed} aria-expanded={!collapsed}>\n            {collapsed ? <PanelLeftOpen /> : <PanelLeftClose />}\n          </IconButton>\n        )}\n      </div>\n    </>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Model picker: a menu button with a radio list.\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction ModelPicker({\n  models,\n  value,\n  onChange,\n  disabled,\n}: {\n  models: ChatModel[];\n  value: string;\n  onChange: (id: string) => void;\n  disabled?: boolean;\n}) {\n  const [open, setOpen] = useState(false);\n  const buttonRef = useRef<HTMLButtonElement>(null);\n  const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const menuId = useId();\n  const current = models.find((m) => m.id === value) ?? models[0];\n\n  useEffect(() => {\n    if (!open) return;\n    const onDown = (e: PointerEvent) => {\n      if (!wrapRef.current?.contains(e.target as Node)) setOpen(false);\n    };\n    document.addEventListener(\"pointerdown\", onDown);\n    const index = Math.max(0, models.findIndex((m) => m.id === value));\n    itemRefs.current[index]?.focus();\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [open, models, value]);\n\n  const close = (refocus = true) => {\n    setOpen(false);\n    if (refocus) buttonRef.current?.focus();\n  };\n\n  const onMenuKey = (event: ReactKeyboardEvent, i: number) => {\n    let next = -1;\n    if (event.key === \"ArrowDown\") next = (i + 1) % models.length;\n    else if (event.key === \"ArrowUp\") next = (i - 1 + models.length) % models.length;\n    else if (event.key === \"Home\") next = 0;\n    else if (event.key === \"End\") next = models.length - 1;\n    else if (event.key === \"Escape\") {\n      event.preventDefault();\n      event.stopPropagation();\n      close();\n      return;\n    } else if (event.key === \"Tab\") {\n      setOpen(false);\n      return;\n    }\n    if (next < 0) return;\n    event.preventDefault();\n    itemRefs.current[next]?.focus();\n  };\n\n  return (\n    <div ref={wrapRef} className=\"relative\">\n      <button\n        ref={buttonRef}\n        type=\"button\"\n        aria-haspopup=\"menu\"\n        aria-expanded={open}\n        aria-controls={open ? menuId : undefined}\n        disabled={disabled}\n        onClick={() => setOpen((v) => !v)}\n        onKeyDown={(e) => {\n          if (e.key === \"ArrowDown\" && !open) {\n            e.preventDefault();\n            setOpen(true);\n          }\n        }}\n        className={cn(\n          \"inline-flex h-8 items-center gap-1.5 rounded-[9px] px-2.5 text-[14px] font-semibold tracking-[-0.01em] transition-colors hover:bg-[var(--bjork-surface-hover)] disabled:opacity-60\",\n          focusRing,\n        )}\n      >\n        <span className=\"sr-only\">Model: </span>\n        {current?.name}\n        <ChevronDown aria-hidden=\"true\" className={cn(\"size-3.5 text-[color:var(--bjork-text-muted)] transition-transform duration-150\", open && \"rotate-180\")} />\n      </button>\n      {open && (\n        <div\n          id={menuId}\n          role=\"menu\"\n          aria-label=\"Model\"\n          className=\"absolute left-0 top-[calc(100%+6px)] z-40 w-[260px] rounded-[14px] border border-[color:var(--bjork-border)] bg-[var(--bjork-menu)] p-1.5 shadow-[var(--bjork-shadow-menu)] backdrop-blur-xl\"\n        >\n          {models.map((m, i) => {\n            const checked = m.id === value;\n            return (\n              <button\n                key={m.id}\n                ref={(el) => {\n                  itemRefs.current[i] = el;\n                }}\n                type=\"button\"\n                role=\"menuitemradio\"\n                aria-checked={checked}\n                tabIndex={-1}\n                onKeyDown={(e) => onMenuKey(e, i)}\n                onClick={() => {\n                  onChange(m.id);\n                  close();\n                }}\n                className=\"flex w-full items-start gap-2.5 rounded-[9px] px-2.5 py-2 text-left outline-none transition-colors hover:bg-[var(--bjork-surface-hover)] focus-visible:bg-[var(--bjork-surface-active)]\"\n              >\n                <span className=\"min-w-0 flex-1\">\n                  <span className=\"block text-[13px] font-medium\">{m.name}</span>\n                  <span className=\"block text-[12px] leading-[1.4] text-[color:var(--bjork-text-muted)]\">{m.hint}</span>\n                </span>\n                <Check aria-hidden=\"true\" className={cn(\"mt-0.5 size-4 shrink-0 text-[color:var(--blk-accent-ink)]\", !checked && \"invisible\")} />\n              </button>\n            );\n          })}\n        </div>\n      )}\n    </div>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Thread\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction Thread({\n  conversation,\n  streamingId,\n  reduce,\n  user,\n  assistantName,\n  suggestions,\n  error,\n  onSuggestion,\n  onRetry,\n  onRegenerate,\n  onEditLast,\n  onFeedback,\n  onCopied,\n}: {\n  conversation: ChatConversation | null;\n  streamingId: string | null;\n  reduce: boolean;\n  user: { name: string };\n  assistantName: string;\n  suggestions: { title: string; prompt: string }[];\n  error: string | null;\n  onSuggestion: (prompt: string) => void;\n  onRetry: () => void;\n  onRegenerate: () => void;\n  onEditLast: () => void;\n  onFeedback: (id: string, value: \"up\" | \"down\") => void;\n  onCopied: () => void;\n}) {\n  const scrollRef = useRef<HTMLElement>(null);\n  const pinned = useRef(true);\n  const [atBottom, setAtBottom] = useState(true);\n  const messages = conversation?.messages ?? [];\n  const lastContent = messages[messages.length - 1]?.content;\n\n  // Follow the stream while the reader is at the bottom; stop following once they scroll up.\n  useLayoutEffect(() => {\n    const el = scrollRef.current;\n    if (!el || !pinned.current) return;\n    el.scrollTop = el.scrollHeight;\n  }, [messages.length, lastContent, streamingId]);\n\n  const onScroll = () => {\n    const el = scrollRef.current;\n    if (!el) return;\n    const near = el.scrollHeight - el.scrollTop - el.clientHeight < 48;\n    pinned.current = near;\n    setAtBottom(near);\n  };\n\n  const jump = () => {\n    const el = scrollRef.current;\n    if (!el) return;\n    pinned.current = true;\n    el.scrollTo({ top: el.scrollHeight, behavior: reduce ? \"auto\" : \"smooth\" });\n  };\n\n  if (!conversation || messages.length === 0) {\n    return (\n      <div className=\"@container/thread flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8\">\n        <div className=\"w-full max-w-[640px]\">\n          <AssistantMark className=\"mx-auto size-11\" />\n          <h2 className=\"mt-4 text-center font-bjork-display text-[26px] font-bold italic leading-tight tracking-[-0.02em] @xl/thread:text-[30px]\">\n            What are we working on?\n          </h2>\n          <p className=\"mt-2 text-center text-[13.5px] text-[color:var(--bjork-text-muted)]\">\n            Ask anything, or start from one of these.\n          </p>\n          <ul className=\"mt-7 grid grid-cols-1 gap-2 @xl/thread:grid-cols-2\">\n            {suggestions.map((s) => (\n              <li key={s.title}>\n                <button\n                  type=\"button\"\n                  onClick={() => onSuggestion(s.prompt)}\n                  className={cn(\n                    \"group flex h-full w-full flex-col items-start gap-1 rounded-[14px] border border-[color:var(--bjork-border)] bg-[var(--bjork-surface)] p-3.5 text-left shadow-[var(--bjork-shadow-soft)] transition-[border-color,background-color,transform] duration-150 hover:border-[color:var(--bjork-border-strong)] hover:bg-[var(--bjork-surface-hover)] active:scale-[0.99] motion-reduce:active:scale-100\",\n                    focusRing,\n                  )}\n                >\n                  <span className=\"text-[13px] font-medium\">{s.title}</span>\n                  <span className=\"line-clamp-2 text-[12.5px] leading-[1.45] text-[color:var(--bjork-text-muted)]\">{s.prompt.split(\"\\n\")[0]}</span>\n                </button>\n              </li>\n            ))}\n          </ul>\n        </div>\n      </div>\n    );\n  }\n\n  const lastAssistant = [...messages].reverse().find((m) => m.role === \"assistant\");\n  const lastUserIndex = messages.map((m) => m.role).lastIndexOf(\"user\");\n\n  return (\n    <div className=\"relative min-h-0 flex-1\">\n      <section\n        ref={scrollRef}\n        onScroll={onScroll}\n        className=\"@container/thread h-full overflow-y-auto overscroll-contain\"\n        aria-label=\"Conversation\"\n        aria-busy={streamingId !== null}\n      >\n        <ol className=\"mx-auto flex w-full max-w-[760px] flex-col gap-7 px-4 pb-8 pt-6 @2xl/thread:px-6\">\n          {messages.map((m, i) =>\n            m.role === \"user\" ? (\n              <li key={m.id} className=\"group flex flex-col items-end gap-1.5\">\n                <h3 className=\"sr-only\">{user.name} said</h3>\n                {m.attachments && m.attachments.length > 0 && (\n                  <ul className=\"flex flex-wrap justify-end gap-1.5\" aria-label=\"Attachments\">\n                    {m.attachments.map((a) => (\n                      <li key={a.name}>\n                        <AttachmentChip file={a} />\n                      </li>\n                    ))}\n                  </ul>\n                )}\n                <div className=\"max-w-[85%] whitespace-pre-wrap rounded-[18px] rounded-br-[6px] border border-[color:var(--bjork-border)] bg-[var(--bjork-surface-active)] px-4 py-2.5 text-[14px] leading-[1.6]\">\n                  {m.content}\n                </div>\n                {i === lastUserIndex && streamingId === null && (\n                  <button\n                    type=\"button\"\n                    onClick={onEditLast}\n                    className={cn(\n                      \"inline-flex h-7 items-center gap-1 rounded-[7px] px-2 text-[12px] text-[color:var(--bjork-text-muted)] opacity-0 transition-opacity hover:bg-[var(--bjork-surface-hover)] hover:text-[color:var(--bjork-text)] focus-visible:opacity-100 group-hover:opacity-100\",\n                      focusRing,\n                    )}\n                  >\n                    <Pencil aria-hidden=\"true\" className=\"size-3.5\" />\n                    Edit\n                  </button>\n                )}\n              </li>\n            ) : (\n              <li key={m.id} className=\"flex gap-3\">\n                <AssistantMark className=\"mt-0.5 size-7 shrink-0\" pulsing={m.id === streamingId && !reduce} />\n                <div className=\"min-w-0 flex-1\">\n                  <h3 className=\"sr-only\">{assistantName} said</h3>\n                  {m.id === streamingId && !m.content ? (\n                    <TypingDots reduce={reduce} />\n                  ) : (\n                    <>\n                      <Markdown content={m.content} />\n                      {m.id === streamingId && (\n                        <span aria-hidden=\"true\" className=\"ml-0.5 inline-block h-[1.05em] w-[7px] translate-y-[3px] animate-pulse rounded-[2px] bg-[var(--bjork-accent)] motion-reduce:animate-none\" />\n                      )}\n                    </>\n                  )}\n                  {m.stopped && (\n                    <p className=\"mt-2 inline-flex items-center gap-1.5 rounded-[7px] bg-[var(--bjork-surface-active)] px-2 py-0.5 text-[11.5px] text-[color:var(--bjork-text-muted)]\">\n                      <Square aria-hidden=\"true\" className=\"size-2.5 fill-current\" />\n                      Stopped\n                    </p>\n                  )}\n                  {m.id !== streamingId && m.content && (\n                    <MessageActions\n                      message={m}\n                      canRegenerate={m.id === lastAssistant?.id && streamingId === null}\n                      onRegenerate={onRegenerate}\n                      onFeedback={onFeedback}\n                      onCopied={onCopied}\n                    />\n                  )}\n                </div>\n              </li>\n            ),\n          )}\n          {error && (\n            <li role=\"alert\" className=\"flex items-center justify-between gap-3 rounded-[12px] border border-[color:color-mix(in_oklab,var(--blk-error)_35%,var(--bjork-border))] bg-[var(--blk-error-soft)] px-3.5 py-2.5 text-[13px] text-[color:var(--blk-error)]\">\n              {error}\n              <BlockButton size=\"sm\" variant=\"secondary\" onClick={onRetry}>\n                <RotateCcw aria-hidden=\"true\" />\n                Retry\n              </BlockButton>\n            </li>\n          )}\n        </ol>\n      </section>\n      <div\n        className={cn(\n          \"pointer-events-none absolute inset-x-0 bottom-3 flex justify-center transition-[opacity,transform] duration-200 motion-reduce:transition-opacity\",\n          atBottom ? \"translate-y-2 opacity-0\" : \"translate-y-0 opacity-100\",\n        )}\n      >\n        <button\n          type=\"button\"\n          onClick={jump}\n          tabIndex={atBottom ? -1 : 0}\n          aria-hidden={atBottom}\n          aria-label=\"Scroll to latest\"\n          className={cn(\n            \"grid size-8 place-items-center rounded-full border border-[color:var(--bjork-border-strong)] bg-[var(--bjork-menu)] text-[color:var(--bjork-text-medium)] shadow-[var(--bjork-shadow-menu)] backdrop-blur-xl hover:text-[color:var(--bjork-text)]\",\n            !atBottom && \"pointer-events-auto\",\n            focusRing,\n          )}\n        >\n          <ArrowDown aria-hidden=\"true\" className=\"size-4\" />\n        </button>\n      </div>\n    </div>\n  );\n}\n\nfunction MessageActions({\n  message,\n  canRegenerate,\n  onRegenerate,\n  onFeedback,\n  onCopied,\n}: {\n  message: ChatMessage;\n  canRegenerate: boolean;\n  onRegenerate: () => void;\n  onFeedback: (id: string, value: \"up\" | \"down\") => void;\n  onCopied: () => void;\n}) {\n  const [copied, setCopied] = useState(false);\n  const timer = useRef<number | undefined>(undefined);\n  useEffect(() => () => window.clearTimeout(timer.current), []);\n  return (\n    <div role=\"group\" aria-label=\"Message actions\" className=\"-ml-1.5 mt-2 flex items-center gap-0.5\">\n      <IconButton\n        label={copied ? \"Copied\" : \"Copy response\"}\n        size=\"sm\"\n        onClick={() => {\n          void navigator.clipboard?.writeText(message.content);\n          setCopied(true);\n          onCopied();\n          window.clearTimeout(timer.current);\n          timer.current = window.setTimeout(() => setCopied(false), 1600);\n        }}\n      >\n        {copied ? <Check /> : <Copy />}\n      </IconButton>\n      <IconButton label=\"Good response\" size=\"sm\" pressed={message.feedback === \"up\"} onClick={() => onFeedback(message.id, \"up\")}>\n        <ThumbsUp fill={message.feedback === \"up\" ? \"currentColor\" : \"none\"} fillOpacity={0.18} />\n      </IconButton>\n      <IconButton label=\"Bad response\" size=\"sm\" pressed={message.feedback === \"down\"} onClick={() => onFeedback(message.id, \"down\")}>\n        <ThumbsDown fill={message.feedback === \"down\" ? \"currentColor\" : \"none\"} fillOpacity={0.18} />\n      </IconButton>\n      {canRegenerate && (\n        <IconButton label=\"Regenerate response\" size=\"sm\" onClick={onRegenerate}>\n          <RotateCcw />\n        </IconButton>\n      )}\n    </div>\n  );\n}\n\nfunction AssistantMark({ className, pulsing }: { className?: string; pulsing?: boolean }) {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className={cn(\n        \"relative grid place-items-center rounded-[9px] bg-[var(--blk-accent-fill)] shadow-[inset_0_1px_0_rgba(255,255,255,0.28),0_1px_2px_rgba(0,0,0,0.2)]\",\n        className,\n      )}\n    >\n      <svg viewBox=\"0 0 20 20\" className=\"size-[62%]\" fill=\"none\">\n        <path\n          d=\"M10 2.5c.5 3.6 1.9 5 5.5 5.5-3.6.5-5 1.9-5.5 5.5-.5-3.6-1.9-5-5.5-5.5 3.6-.5 5-1.9 5.5-5.5Z\"\n          fill=\"var(--blk-accent-fill-ink)\"\n          className={cn(pulsing && \"origin-center animate-[spin_2.4s_linear_infinite]\")}\n          style={{ transformBox: \"fill-box\" }}\n        />\n        <circle cx=\"15.5\" cy=\"15\" r=\"1.5\" fill=\"var(--blk-accent-fill-ink)\" opacity=\"0.7\" />\n      </svg>\n    </span>\n  );\n}\n\nfunction TypingDots({ reduce }: { reduce: boolean }) {\n  return (\n    <span className=\"inline-flex h-6 items-center gap-1\" aria-label=\"Thinking\" role=\"img\">\n      {[0, 1, 2].map((i) => (\n        <span\n          key={i}\n          className={cn(\"size-1.5 rounded-full bg-[var(--bjork-text-muted)]\", !reduce && \"animate-bounce\")}\n          style={{ animationDelay: `${i * 140}ms`, animationDuration: \"900ms\" }}\n        />\n      ))}\n    </span>\n  );\n}\n\nfunction AttachmentChip({ file, onRemove }: { file: ChatAttachment; onRemove?: () => void }) {\n  return (\n    <span className=\"inline-flex max-w-[220px] items-center gap-2 rounded-[10px] border border-[color:var(--bjork-border)] bg-[var(--bjork-surface)] py-1.5 pl-2 pr-2.5 text-[12px] shadow-[var(--bjork-shadow-soft)]\">\n      <span aria-hidden=\"true\" className=\"grid size-6 shrink-0 place-items-center rounded-[6px] bg-[var(--bjork-accent-soft)] text-[color:var(--blk-accent-ink)]\">\n        <FileText className=\"size-3.5\" />\n      </span>\n      <span className=\"min-w-0\">\n        <span className=\"block truncate font-medium\">{file.name}</span>\n        <span className=\"block font-mono text-[11px] text-[color:var(--bjork-text-soft)]\">{file.size}</span>\n      </span>\n      {onRemove && (\n        <button\n          type=\"button\"\n          onClick={onRemove}\n          aria-label={`Remove ${file.name}`}\n          className={cn(\"-mr-1 grid size-5 shrink-0 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\" />\n        </button>\n      )}\n    </span>\n  );\n}\n\n/* ----------------------------------------------------------------------------------------------------------\n * Composer\n * -------------------------------------------------------------------------------------------------------- */\n\nfunction formatSize(bytes: number) {\n  if (bytes < 1024) return `${bytes} B`;\n  if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;\n  return `${(bytes / 1024 / 1024).toFixed(1)} MB`;\n}\n\nfunction Composer({\n  inputRef,\n  value,\n  onChange,\n  attachments,\n  onAttach,\n  onRemoveAttachment,\n  streaming,\n  onSend,\n  onStop,\n  canEditLast,\n  onEditLast,\n  assistantName,\n}: {\n  inputRef: RefObject<HTMLTextAreaElement | null>;\n  value: string;\n  onChange: (value: string) => void;\n  attachments: ChatAttachment[];\n  onAttach: (files: ChatAttachment[]) => void;\n  onRemoveAttachment: (name: string) => void;\n  streaming: boolean;\n  onSend: () => void;\n  onStop: () => void;\n  canEditLast: boolean;\n  onEditLast: () => void;\n  assistantName: string;\n}) {\n  const fileRef = useRef<HTMLInputElement>(null);\n  const hintId = useId();\n  const [dragging, setDragging] = useState(false);\n\n  // Grow with the text up to a cap, then scroll.\n  useLayoutEffect(() => {\n    const el = inputRef.current;\n    if (!el) return;\n    el.style.height = \"auto\";\n    el.style.height = `${Math.min(el.scrollHeight, 220)}px`;\n  }, [value, inputRef]);\n\n  const addFiles = (list: FileList | null) => {\n    if (!list || list.length === 0) return;\n    onAttach(Array.from(list).map((f) => ({ name: f.name, size: formatSize(f.size) })));\n  };\n\n  return (\n    <div className=\"shrink-0 px-3 pb-3 @2xl:px-6 @2xl:pb-5\">\n      <form\n        onSubmit={(e) => {\n          e.preventDefault();\n          onSend();\n        }}\n        onDragOver={(e) => {\n          if (e.dataTransfer.types.includes(\"Files\")) {\n            e.preventDefault();\n            setDragging(true);\n          }\n        }}\n        onDragLeave={() => setDragging(false)}\n        onDrop={(e) => {\n          e.preventDefault();\n          setDragging(false);\n          addFiles(e.dataTransfer.files);\n        }}\n        className={cn(\n          \"mx-auto w-full max-w-[760px] rounded-[20px] border bg-[var(--bjork-surface)] p-2 shadow-[var(--bjork-shadow-surface)] transition-[border-color,box-shadow] duration-150 focus-within:border-[color:var(--bjork-border-strong)]\",\n          dragging ? \"border-dashed border-[color:var(--bjork-accent)] ring-[3px] ring-[color:var(--bjork-accent-soft)]\" : \"border-[color:var(--bjork-border)]\",\n        )}\n      >\n        {attachments.length > 0 && (\n          <ul className=\"flex flex-wrap gap-1.5 px-1 pb-2 pt-1\" aria-label=\"Attached files\">\n            {attachments.map((a) => (\n              <li key={a.name}>\n                <AttachmentChip file={a} onRemove={() => onRemoveAttachment(a.name)} />\n              </li>\n            ))}\n          </ul>\n        )}\n        <label className=\"sr-only\" htmlFor={`${hintId}-input`}>\n          Message {assistantName}\n        </label>\n        <textarea\n          ref={inputRef}\n          id={`${hintId}-input`}\n          rows={1}\n          value={value}\n          onChange={(e) => onChange(e.target.value)}\n          onKeyDown={(e) => {\n            if (e.key === \"Enter\" && !e.shiftKey && !e.nativeEvent.isComposing) {\n              e.preventDefault();\n              onSend();\n            } else if (e.key === \"ArrowUp\" && !value && canEditLast && !streaming) {\n              e.preventDefault();\n              onEditLast();\n            }\n          }}\n          onPaste={(e) => {\n            if (e.clipboardData.files.length > 0) {\n              e.preventDefault();\n              addFiles(e.clipboardData.files);\n            }\n          }}\n          aria-describedby={hintId}\n          placeholder={`Message ${assistantName}`}\n          className=\"block max-h-[220px] min-h-[44px] w-full resize-none bg-transparent px-2.5 py-2.5 text-[14.5px] leading-[1.55] text-[color:var(--bjork-text)] outline-none placeholder:text-[color:var(--bjork-text-soft)]\"\n        />\n        <div className=\"flex items-center gap-1.5\">\n          <IconButton label=\"Attach files\" size=\"sm\" onClick={() => fileRef.current?.click()}>\n            <Paperclip />\n          </IconButton>\n          <input\n            ref={fileRef}\n            type=\"file\"\n            multiple\n            className=\"sr-only\"\n            tabIndex={-1}\n            aria-hidden=\"true\"\n            onChange={(e) => {\n              addFiles(e.target.files);\n              e.target.value = \"\";\n            }}\n          />\n          <p id={hintId} className=\"hidden min-w-0 flex-1 truncate text-[11.5px] text-[color:var(--bjork-text-soft)] @xl:block\">\n            <Kbd>↵</Kbd> send · <Kbd>⇧</Kbd> <Kbd>↵</Kbd> new line · <Kbd>↑</Kbd> edit last\n          </p>\n          <span className=\"flex-1 @xl:hidden\" />\n          {streaming ? (\n            <button\n              type=\"button\"\n              onClick={onStop}\n              aria-label=\"Stop generating (Esc)\"\n              title=\"Stop generating (Esc)\"\n              className={cn(\n                \"grid size-9 place-items-center rounded-full bg-[var(--bjork-text)] text-[color:var(--bjork-bg)] transition-transform active:scale-95 motion-reduce:active:scale-100\",\n                focusRing,\n              )}\n            >\n              <Square aria-hidden=\"true\" className=\"size-3 fill-current\" />\n            </button>\n          ) : (\n            <button\n              type=\"submit\"\n              disabled={!value.trim()}\n              aria-label=\"Send message\"\n              title=\"Send (Enter)\"\n              className={cn(\n                \"grid size-9 place-items-center rounded-full bg-[var(--blk-accent-fill)] text-[color:var(--blk-accent-fill-ink)] shadow-[inset_0_1px_0_rgba(255,255,255,0.22)] transition-[transform,opacity,filter] hover:brightness-110 active:scale-95 disabled:cursor-not-allowed disabled:opacity-35 motion-reduce:active:scale-100\",\n                focusRing,\n              )}\n            >\n              <ArrowUp aria-hidden=\"true\" className=\"size-[18px]\" strokeWidth={2.2} />\n            </button>\n          )}\n        </div>\n      </form>\n      <p className=\"mx-auto mt-2 max-w-[760px] text-center text-[11px] text-[color:var(--bjork-text-soft)]\">\n        Answers can be wrong. Check anything important.\n      </p>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/bjork-ui/blocks/app-ai-chat.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-ai-chat.json",
    "installCommand": "npx shadcn@latest add https://ui.isaiahbjork.com/app-ai-chat.json"
  },
  "type": "registry:block"
}