{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kanban-board",
  "type": "registry:block",
  "title": "Kanban Board",
  "description": "A team board you can really work in: drag cards between columns, add one with a keystroke, filter by label, and open any card for its checklist and notes.",
  "categories": [
    "block",
    "Apps"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/checkbox.json",
    "https://coss.com/ui/r/input-group.json",
    "https://coss.com/ui/r/switch.json",
    "https://coss.com/ui/r/textarea.json"
  ],
  "files": [
    {
      "path": "registry/devl/kanban-board.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport {\n  CalendarIcon,\n  CheckSquareIcon,\n  GripVerticalIcon,\n  MessageSquareIcon,\n  PlusIcon,\n  SearchIcon,\n  XIcon,\n} from \"lucide-react\";\nimport { AnimatePresence, LayoutGroup, animate, motion, useMotionValue, useReducedMotion } from \"motion/react\";\nimport {\n  type FormEvent,\n  type KeyboardEvent,\n  type PointerEvent,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from \"react\";\nimport { Checkbox } from \"@/components/ui/checkbox\";\nimport { InputGroup, InputGroupAddon, InputGroupInput } from \"@/components/ui/input-group\";\nimport { Switch } from \"@/components/ui/switch\";\nimport { Textarea } from \"@/components/ui/textarea\";\nimport { cn } from \"@/lib/utils\";\n\nexport type LabelTone = \"gray\" | \"blue\" | \"green\" | \"amber\" | \"red\";\nexport type TaskPriority = \"low\" | \"medium\" | \"high\" | \"urgent\";\n\nexport interface BoardLabel {\n  id: string;\n  name: string;\n  tone: LabelTone;\n}\n\nexport interface BoardColumn {\n  id: string;\n  title: string;\n  tone?: LabelTone;\n}\n\nexport interface BoardTask {\n  id: string;\n  title: string;\n  column: string;\n  labels: string[];\n  priority?: TaskPriority;\n  assignee?: string;\n  due?: string;\n  description?: string;\n  checklist?: { id: string; text: string; done: boolean }[];\n  comments?: number;\n}\n\nexport interface KanbanBoardProps {\n  columns: BoardColumn[];\n  labels: BoardLabel[];\n  tasks: BoardTask[];\n  onTasksChange?: (tasks: BoardTask[]) => void;\n  className?: string;\n}\n\nconst toneBg: Record<LabelTone, string> = {\n  gray: \"bg-muted-foreground/60\",\n  blue: \"bg-info\",\n  green: \"bg-success\",\n  amber: \"bg-warning\",\n  red: \"bg-destructive\",\n};\nconst toneSoft: Record<LabelTone, string> = {\n  gray: \"bg-muted-foreground/12\",\n  blue: \"bg-info/12\",\n  green: \"bg-success/12\",\n  amber: \"bg-warning/16\",\n  red: \"bg-destructive/12\",\n};\nconst avatarTones = [\n  \"bg-info/16 text-info-foreground\",\n  \"bg-success/16 text-success-foreground\",\n  \"bg-warning/14 text-warning-foreground\",\n  \"bg-destructive/14 text-destructive-foreground\",\n];\nconst priorities: TaskPriority[] = [\"low\", \"medium\", \"high\", \"urgent\"];\nconst spring = { type: \"spring\", stiffness: 520, damping: 40 } as const;\nconst glide = { type: \"spring\", stiffness: 380, damping: 39 } as const;\nconst hit = \"relative after:absolute after:-inset-y-1 after:inset-x-0 after:content-['']\";\n\nfunction initials(name: string) {\n  return name\n    .split(/\\s+/)\n    .map((p) => p[0])\n    .slice(0, 2)\n    .join(\"\")\n    .toUpperCase();\n}\n\nfunction avatarTone(name: string) {\n  let hash = 0;\n  for (const char of name) hash = (hash * 31 + char.charCodeAt(0)) >>> 0;\n  return avatarTones[hash % avatarTones.length];\n}\n\nfunction Avatar({ name, className }: { name: string; className?: string }) {\n  return (\n    <span\n      className={cn(\n        \"flex size-6 shrink-0 items-center justify-center rounded-full font-semibold text-[0.625rem]\",\n        avatarTone(name),\n        className,\n      )}\n      title={name}\n    >\n      {initials(name)}\n    </span>\n  );\n}\n\nfunction PriorityBars({ priority }: { priority: TaskPriority }) {\n  if (priority === \"urgent\") {\n    return (\n      <span\n        aria-label=\"Urgent\"\n        className=\"flex size-4 items-center justify-center rounded-[calc(var(--radius)*0.4)] bg-destructive font-bold text-[0.625rem] text-white\"\n      >\n        !\n      </span>\n    );\n  }\n  const level = priorities.indexOf(priority) + 1;\n  return (\n    <span aria-label={`${priority} priority`} className=\"flex h-3.5 items-end gap-0.5\" role=\"img\">\n      {[1, 2, 3].map((bar) => (\n        <span\n          className={cn(\"w-[3px] rounded-full\", bar <= level ? \"bg-foreground/70\" : \"bg-foreground/16\")}\n          key={bar}\n          style={{ height: `${bar * 4 + 2}px` }}\n        />\n      ))}\n    </span>\n  );\n}\n\nfunction CardBody({\n  task,\n  labels,\n  compact,\n}: {\n  task: BoardTask;\n  labels: BoardLabel[];\n  compact: boolean;\n}) {\n  const taskLabels = task.labels\n    .map((id) => labels.find((l) => l.id === id))\n    .filter((l): l is BoardLabel => Boolean(l));\n  const done = task.checklist?.filter((c) => c.done).length ?? 0;\n  const total = task.checklist?.length ?? 0;\n\n  if (compact) {\n    return (\n      <span className=\"flex items-center gap-2\">\n        <span className=\"flex shrink-0 gap-0.5\">\n          {taskLabels.map((l) => (\n            <span className={cn(\"size-2 rounded-full\", toneBg[l.tone])} key={l.id} title={l.name} />\n          ))}\n        </span>\n        <span className=\"min-w-0 flex-1 truncate font-medium text-sm\">{task.title}</span>\n        {task.priority && <PriorityBars priority={task.priority} />}\n        {task.assignee && <Avatar className=\"size-5 text-[0.5625rem]\" name={task.assignee} />}\n      </span>\n    );\n  }\n\n  return (\n    <span className=\"block\">\n      {taskLabels.length > 0 && (\n        <span className=\"mb-2 flex flex-wrap gap-1\">\n          {taskLabels.map((l) => (\n            <span\n              className={cn(\"inline-flex items-center gap-1 rounded-full px-1.5 py-px font-medium text-[0.6875rem]\", toneSoft[l.tone])}\n              key={l.id}\n            >\n              <span className={cn(\"size-1.5 rounded-full\", toneBg[l.tone])} />\n              {l.name}\n            </span>\n          ))}\n        </span>\n      )}\n      <span className=\"block text-pretty font-medium text-sm leading-snug\">{task.title}</span>\n      <span className=\"mt-3 flex items-center gap-3 text-muted-foreground text-xs\">\n        {task.priority && <PriorityBars priority={task.priority} />}\n        {task.due && (\n          <span className=\"inline-flex items-center gap-1\">\n            <CalendarIcon className=\"size-3.5\" />\n            {task.due}\n          </span>\n        )}\n        {total > 0 && (\n          <span className={cn(\"inline-flex items-center gap-1 tabular-nums\", done === total && \"text-success-foreground\")}>\n            <CheckSquareIcon className=\"size-3.5\" />\n            {done}/{total}\n          </span>\n        )}\n        {!!task.comments && (\n          <span className=\"inline-flex items-center gap-1 tabular-nums\">\n            <MessageSquareIcon className=\"size-3.5\" />\n            {task.comments}\n          </span>\n        )}\n        {task.assignee && <Avatar className=\"ms-auto\" name={task.assignee} />}\n      </span>\n    </span>\n  );\n}\n\nfunction TaskDetail({\n  task,\n  columns,\n  labels,\n  onUpdate,\n  onMove,\n  onClose,\n}: {\n  task: BoardTask;\n  columns: BoardColumn[];\n  labels: BoardLabel[];\n  onUpdate: (patch: Partial<BoardTask>) => void;\n  onMove: (column: string) => void;\n  onClose: () => void;\n}) {\n  const reduce = useReducedMotion();\n  const closeRef = useRef<HTMLButtonElement>(null);\n  const [newItem, setNewItem] = useState(\"\");\n  const checklist = task.checklist ?? [];\n  const done = checklist.filter((c) => c.done).length;\n\n  useEffect(() => {\n    closeRef.current?.focus();\n  }, []);\n\n  const addItem = (event: FormEvent) => {\n    event.preventDefault();\n    const text = newItem.trim();\n    if (!text) return;\n    onUpdate({ checklist: [...checklist, { id: `${task.id}-${Date.now()}`, text, done: false }] });\n    setNewItem(\"\");\n  };\n\n  return (\n    <motion.aside\n      animate={{ x: 0 }}\n      aria-label={`Task details: ${task.title}`}\n      aria-modal=\"true\"\n      className=\"absolute inset-y-0 right-0 z-30 flex w-full flex-col border-s bg-popover text-popover-foreground sm:w-[380px]\"\n      exit={{ x: \"100%\" }}\n      initial={{ x: \"100%\" }}\n      onKeyDown={(e) => {\n        if (e.key === \"Escape\") {\n          e.stopPropagation();\n          onClose();\n        }\n      }}\n      role=\"dialog\"\n      transition={reduce ? { duration: 0 } : glide}\n    >\n      <div className=\"flex items-center gap-2 border-b px-4 py-3\">\n        <span className=\"font-mono text-muted-foreground text-xs\">{task.id.toUpperCase()}</span>\n        <button\n          aria-label=\"Close details\"\n          className=\"ms-auto inline-flex size-8 cursor-pointer items-center justify-center rounded-lg text-muted-foreground outline-none transition-[color,background-color,transform] duration-150 ease-out hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.97]\"\n          onClick={onClose}\n          ref={closeRef}\n          type=\"button\"\n        >\n          <XIcon className=\"size-4\" />\n        </button>\n      </div>\n      <div className=\"flex-1 space-y-5 overflow-y-auto p-4\">\n        <textarea\n          aria-label=\"Task title\"\n          className=\"-mx-1 block w-[calc(100%+0.5rem)] resize-none text-balance rounded-lg bg-transparent px-1 font-semibold text-lg leading-snug outline-none [field-sizing:content] focus-visible:ring-2 focus-visible:ring-ring/40\"\n          onChange={(e) => onUpdate({ title: e.target.value.replace(/\\n/g, \" \") })}\n          onKeyDown={(e) => {\n            if (e.key === \"Enter\") e.preventDefault();\n          }}\n          rows={1}\n          value={task.title}\n        />\n\n        <fieldset>\n          <legend className=\"mb-2 font-medium text-muted-foreground text-xs\">Status</legend>\n          <div className=\"flex flex-wrap gap-1 rounded-xl bg-muted p-1\">\n            {columns.map((col) => {\n              const active = col.id === task.column;\n              return (\n                <button\n                  aria-pressed={active}\n                  className={cn(\n                    \"relative flex-1 cursor-pointer whitespace-nowrap rounded-lg px-2 py-1.5 font-medium text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n                    active ? \"text-foreground\" : \"text-muted-foreground hover:text-foreground\",\n                  )}\n                  key={col.id}\n                  onClick={() => onMove(col.id)}\n                  type=\"button\"\n                >\n                  {active && (\n                    <motion.span\n                      className=\"absolute inset-0 rounded-lg bg-background shadow-xs/5\"\n                      layoutId=\"status-pill\"\n                      transition={reduce ? { duration: 0 } : spring}\n                    />\n                  )}\n                  <span className=\"relative\">{col.title}</span>\n                </button>\n              );\n            })}\n          </div>\n        </fieldset>\n\n        <fieldset>\n          <legend className=\"mb-2 font-medium text-muted-foreground text-xs\">Priority</legend>\n          <div className=\"flex gap-1.5\">\n            {priorities.map((p) => (\n              <button\n                aria-pressed={task.priority === p}\n                className={cn(\n                  \"inline-flex cursor-pointer items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs capitalize outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n                  task.priority === p ? \"border-foreground/24 bg-accent font-medium\" : \"text-muted-foreground hover:bg-accent/60\",\n                )}\n                key={p}\n                onClick={() => onUpdate({ priority: p })}\n                type=\"button\"\n              >\n                <PriorityBars priority={p} />\n                {p}\n              </button>\n            ))}\n          </div>\n        </fieldset>\n\n        <fieldset>\n          <legend className=\"mb-2 font-medium text-muted-foreground text-xs\">Labels</legend>\n          <div className=\"flex flex-wrap gap-1.5\">\n            {labels.map((l) => {\n              const on = task.labels.includes(l.id);\n              return (\n                <button\n                  aria-pressed={on}\n                  className={cn(\n                    \"inline-flex cursor-pointer items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n                    on ? cn(\"border-transparent font-medium\", toneSoft[l.tone]) : \"text-muted-foreground hover:bg-accent/60\",\n                  )}\n                  key={l.id}\n                  onClick={() =>\n                    onUpdate({ labels: on ? task.labels.filter((id) => id !== l.id) : [...task.labels, l.id] })\n                  }\n                  type=\"button\"\n                >\n                  <span className={cn(\"size-2 rounded-full\", toneBg[l.tone])} />\n                  {l.name}\n                </button>\n              );\n            })}\n          </div>\n        </fieldset>\n\n        <dl className=\"grid grid-cols-2 gap-3 text-sm\">\n          <div className=\"rounded-xl border p-3\">\n            <dt className=\"text-muted-foreground text-xs\">Assignee</dt>\n            <dd className=\"mt-1.5 flex items-center gap-2 font-medium\">\n              {task.assignee ? (\n                <>\n                  <Avatar name={task.assignee} />\n                  <span className=\"truncate\">{task.assignee}</span>\n                </>\n              ) : (\n                <span className=\"text-muted-foreground\">Unassigned</span>\n              )}\n            </dd>\n          </div>\n          <div className=\"rounded-xl border p-3\">\n            <dt className=\"text-muted-foreground text-xs\">Due</dt>\n            <dd className=\"mt-1.5 flex items-center gap-2 font-medium\">\n              <CalendarIcon className=\"size-4 text-muted-foreground\" />\n              {task.due ?? \"No date\"}\n            </dd>\n          </div>\n        </dl>\n\n        <div>\n          <label className=\"mb-2 block font-medium text-muted-foreground text-xs\" htmlFor={`${task.id}-desc`}>\n            Description\n          </label>\n          <Textarea\n            id={`${task.id}-desc`}\n            onChange={(e) => onUpdate({ description: e.target.value })}\n            placeholder=\"Add more detail…\"\n            value={task.description ?? \"\"}\n          />\n        </div>\n\n        <div>\n          <div className=\"mb-2 flex items-center justify-between text-xs\">\n            <span className=\"font-medium text-muted-foreground\">Checklist</span>\n            {checklist.length > 0 && (\n              <span className=\"text-muted-foreground tabular-nums\">\n                {done}/{checklist.length}\n              </span>\n            )}\n          </div>\n          {checklist.length > 0 && (\n            <div className=\"mb-3 h-1.5 overflow-hidden rounded-full bg-muted\">\n              <motion.div\n                animate={{ scaleX: done / checklist.length }}\n                className=\"h-full origin-left rounded-full bg-success\"\n                initial={false}\n                transition={reduce ? { duration: 0 } : spring}\n              />\n            </div>\n          )}\n          <ul className=\"space-y-1\">\n            {checklist.map((item) => (\n              <li key={item.id}>\n                <label className=\"flex cursor-pointer items-center gap-2.5 rounded-lg px-1.5 py-1 text-sm hover:bg-accent/50\">\n                  <Checkbox\n                    checked={item.done}\n                    onCheckedChange={(checked) =>\n                      onUpdate({\n                        checklist: checklist.map((c) => (c.id === item.id ? { ...c, done: Boolean(checked) } : c)),\n                      })\n                    }\n                  />\n                  <span className={cn(\"transition-colors\", item.done && \"text-muted-foreground line-through\")}>\n                    {item.text}\n                  </span>\n                </label>\n              </li>\n            ))}\n          </ul>\n          <form className=\"mt-2\" onSubmit={addItem}>\n            <InputGroup>\n              <InputGroupAddon>\n                <PlusIcon />\n              </InputGroupAddon>\n              <InputGroupInput\n                aria-label=\"Add checklist item\"\n                onChange={(e) => setNewItem(e.target.value)}\n                placeholder=\"Add an item\"\n                size=\"sm\"\n                value={newItem}\n              />\n            </InputGroup>\n          </form>\n        </div>\n      </div>\n    </motion.aside>\n  );\n}\n\ninterface DragState {\n  id: string;\n  width: number;\n  height: number;\n  over: string;\n  dropping: boolean;\n}\n\nfunction placeTask(\n  prev: BoardTask[],\n  id: string,\n  column: string,\n  index: number,\n  visible: (t: BoardTask) => boolean,\n): BoardTask[] {\n  const task = prev.find((t) => t.id === id);\n  if (!task) return prev;\n  const current = prev.filter((t) => t.column === column && visible(t));\n  if (task.column === column && current.indexOf(task) === index) return prev;\n  const without = prev.filter((t) => t.id !== id);\n  const peers = without.filter((t) => t.column === column && visible(t));\n  let at: number;\n  if (index < peers.length) at = without.indexOf(peers[Math.max(0, index)]);\n  else if (peers.length) at = without.indexOf(peers[peers.length - 1]) + 1;\n  else {\n    const same = without.filter((t) => t.column === column);\n    at = same.length ? without.indexOf(same[same.length - 1]) + 1 : without.length;\n  }\n  const next = [...without];\n  next.splice(at, 0, { ...task, column });\n  return next;\n}\n\nexport function KanbanBoard({ columns, labels, tasks: initialTasks, onTasksChange, className }: KanbanBoardProps) {\n  const groupId = useId();\n  const reduce = useReducedMotion();\n  const [tasks, setTasks] = useState(initialTasks);\n  const [query, setQuery] = useState(\"\");\n  const [activeLabels, setActiveLabels] = useState<string[]>([]);\n  const [compact, setCompact] = useState(false);\n  const [selectedId, setSelectedId] = useState<string | null>(null);\n  const [addingTo, setAddingTo] = useState<string | null>(null);\n  const [draft, setDraft] = useState(\"\");\n  const [announcement, setAnnouncement] = useState(\"\");\n  const [drag, setDrag] = useState<DragState | null>(null);\n\n  const rootRef = useRef<HTMLDivElement>(null);\n  const scrollerRef = useRef<HTMLDivElement>(null);\n  const columnRefs = useRef<Record<string, HTMLElement | null>>({});\n  const listRefs = useRef<Record<string, HTMLDivElement | null>>({});\n  const pending = useRef<{ id: string; x: number; y: number; el: HTMLElement; pointerId: number } | null>(null);\n  const dragRef = useRef<DragState | null>(null);\n  const grab = useRef({ dx: 0, dy: 0 });\n  const justDragged = useRef(false);\n  const ox = useMotionValue(0);\n  const oy = useMotionValue(0);\n  const firstRender = useRef(true);\n  const onTasksChangeRef = useRef(onTasksChange);\n  onTasksChangeRef.current = onTasksChange;\n\n  useEffect(() => {\n    if (firstRender.current) {\n      firstRender.current = false;\n      return;\n    }\n    onTasksChangeRef.current?.(tasks);\n  }, [tasks]);\n\n  const q = query.trim().toLowerCase();\n  const matches = (t: BoardTask) =>\n    (!q || t.title.toLowerCase().includes(q) || (t.description ?? \"\").toLowerCase().includes(q)) &&\n    (activeLabels.length === 0 || t.labels.some((l) => activeLabels.includes(l)));\n  const visible = (t: BoardTask) => matches(t) || t.id === drag?.id;\n\n  const updateTask = (id: string, patch: Partial<BoardTask>) =>\n    setTasks((prev) => prev.map((t) => (t.id === id ? { ...t, ...patch } : t)));\n\n  const columnTitle = (id: string) => columns.find((c) => c.id === id)?.title ?? id;\n\n  const moveToColumn = (id: string, column: string) => {\n    setTasks((prev) => {\n      const peers = prev.filter((t) => t.column === column && t.id !== id && matches(t));\n      return placeTask(prev, id, column, peers.length, matches);\n    });\n    const task = tasks.find((t) => t.id === id);\n    if (task) setAnnouncement(`Moved “${task.title}” to ${columnTitle(column)}`);\n  };\n\n  const refocus = (id: string) =>\n    requestAnimationFrame(() =>\n      rootRef.current?.querySelector<HTMLElement>(`[data-task-id=\"${id}\"] [data-card]`)?.focus(),\n    );\n\n  const onCardKeyDown = (event: KeyboardEvent<HTMLButtonElement>, task: BoardTask) => {\n    if (!event.shiftKey) return;\n    const colIndex = columns.findIndex((c) => c.id === task.column);\n    const peers = tasks.filter((t) => t.column === task.column && matches(t));\n    const index = peers.indexOf(task);\n    if (event.key === \"ArrowRight\" || event.key === \"ArrowLeft\") {\n      const next = columns[colIndex + (event.key === \"ArrowRight\" ? 1 : -1)];\n      if (!next) return;\n      event.preventDefault();\n      moveToColumn(task.id, next.id);\n      refocus(task.id);\n    } else if (event.key === \"ArrowUp\" || event.key === \"ArrowDown\") {\n      const target = index + (event.key === \"ArrowDown\" ? 1 : -1);\n      if (target < 0 || target >= peers.length) return;\n      event.preventDefault();\n      setTasks((prev) => placeTask(prev, task.id, task.column, target, matches));\n      setAnnouncement(`Moved “${task.title}” to position ${target + 1} in ${columnTitle(task.column)}`);\n      refocus(task.id);\n    }\n  };\n\n  const onCardPointerDown = (event: PointerEvent<HTMLElement>, id: string) => {\n    if (event.button !== 0 || dragRef.current) return;\n    const fromHandle = (event.target as HTMLElement).closest(\"[data-drag-handle]\");\n    if (event.pointerType !== \"mouse\" && !fromHandle) return;\n    const el = (event.currentTarget as HTMLElement).closest<HTMLElement>(\"[data-task-id]\");\n    if (!el) return;\n    pending.current = { id, x: event.clientX, y: event.clientY, el, pointerId: event.pointerId };\n    if (fromHandle) beginDrag(event.clientX, event.clientY);\n  };\n\n  const beginDrag = (clientX: number, clientY: number) => {\n    const p = pending.current;\n    const root = rootRef.current;\n    if (!p || !root) return;\n    const rootRect = root.getBoundingClientRect();\n    const rect = p.el.getBoundingClientRect();\n    grab.current = { dx: clientX - rect.left, dy: clientY - rect.top };\n    ox.set(rect.left - rootRect.left);\n    oy.set(rect.top - rootRect.top);\n    const task = tasks.find((t) => t.id === p.id);\n    const state: DragState = { id: p.id, width: rect.width, height: rect.height, over: task?.column ?? \"\", dropping: false };\n    dragRef.current = state;\n    setDrag(state);\n    try {\n      root.setPointerCapture(p.pointerId);\n    } catch {}\n  };\n\n  const hitTest = (clientX: number, clientY: number, id: string) => {\n    let best: string | null = null;\n    let bestDistance = Number.POSITIVE_INFINITY;\n    for (const col of columns) {\n      const el = columnRefs.current[col.id];\n      if (!el) continue;\n      const r = el.getBoundingClientRect();\n      const distance = clientX < r.left ? r.left - clientX : clientX > r.right ? clientX - r.right : 0;\n      if (distance < bestDistance) {\n        bestDistance = distance;\n        best = col.id;\n      }\n    }\n    const list = best ? listRefs.current[best] : null;\n    if (!best || !list) return;\n    const listRect = list.getBoundingClientRect();\n    const y = clientY - listRect.top + list.scrollTop;\n    let index = 0;\n    for (const card of list.querySelectorAll<HTMLElement>(\"[data-task-id]:not([data-placeholder])\")) {\n      if (card.offsetTop + card.offsetHeight / 2 < y) index++;\n    }\n    if (clientY > listRect.bottom - 36) list.scrollTop += 10;\n    else if (clientY < listRect.top + 24) list.scrollTop -= 10;\n    const column = best;\n    if (dragRef.current && dragRef.current.over !== column) {\n      dragRef.current = { ...dragRef.current, over: column };\n      setDrag(dragRef.current);\n    }\n    setTasks((prev) => placeTask(prev, id, column, index, (t) => matches(t) || t.id === id));\n  };\n\n  const onRootPointerMove = (event: PointerEvent<HTMLDivElement>) => {\n    const p = pending.current;\n    if (!p || p.pointerId !== event.pointerId) return;\n    if (!dragRef.current) {\n      if (Math.hypot(event.clientX - p.x, event.clientY - p.y) < 5) return;\n      beginDrag(event.clientX, event.clientY);\n    }\n    const d = dragRef.current;\n    const root = rootRef.current;\n    if (!d || d.dropping || !root) return;\n    const rootRect = root.getBoundingClientRect();\n    ox.set(event.clientX - rootRect.left - grab.current.dx);\n    oy.set(event.clientY - rootRect.top - grab.current.dy);\n    const scroller = scrollerRef.current;\n    if (scroller) {\n      const r = scroller.getBoundingClientRect();\n      if (event.clientX > r.right - 48) scroller.scrollLeft += 14;\n      else if (event.clientX < r.left + 48) scroller.scrollLeft -= 14;\n    }\n    hitTest(event.clientX, event.clientY, d.id);\n  };\n\n  const endDrag = () => {\n    const d = dragRef.current;\n    pending.current = null;\n    if (!d || d.dropping) return;\n    justDragged.current = true;\n    setTimeout(() => {\n      justDragged.current = false;\n    }, 0);\n    const root = rootRef.current;\n    const placeholder = root?.querySelector<HTMLElement>(\"[data-placeholder]\");\n    const finish = () => {\n      dragRef.current = null;\n      setDrag(null);\n      const task = tasks.find((t) => t.id === d.id);\n      if (task) setAnnouncement(`Dropped “${task.title}” in ${columnTitle(d.over)}`);\n    };\n    if (!root || !placeholder || reduce) return finish();\n    const rootRect = root.getBoundingClientRect();\n    const rect = placeholder.getBoundingClientRect();\n    dragRef.current = { ...d, dropping: true };\n    setDrag(dragRef.current);\n    Promise.all([\n      animate(ox, rect.left - rootRect.left, glide),\n      animate(oy, rect.top - rootRect.top, glide),\n    ]).then(finish);\n  };\n\n  const submitDraft = (event: FormEvent, column: string) => {\n    event.preventDefault();\n    const title = draft.trim();\n    if (!title) return;\n    const id = `t-${Date.now().toString(36)}`;\n    setTasks((prev) => {\n      const first = prev.findIndex((t) => t.column === column);\n      const next = [...prev];\n      next.splice(first < 0 ? next.length : first, 0, { id, title, column, labels: [...activeLabels], priority: \"medium\" });\n      return next;\n    });\n    setDraft(\"\");\n    setAnnouncement(`Added “${title}” to ${columnTitle(column)}`);\n  };\n\n  const selected = tasks.find((t) => t.id === selectedId) ?? null;\n  const dragged = drag ? tasks.find((t) => t.id === drag.id) : null;\n\n  return (\n    <LayoutGroup id={groupId}>\n      <div\n        className={cn(\n          \"relative isolate mx-auto flex h-[680px] w-full max-w-[1100px] flex-col overflow-hidden rounded-2xl border bg-card\",\n          drag && \"cursor-grabbing select-none\",\n          className,\n        )}\n        onPointerCancel={endDrag}\n        onPointerMove={onRootPointerMove}\n        onPointerUp={endDrag}\n        ref={rootRef}\n      >\n        <div className=\"flex flex-wrap items-center gap-2 border-b p-3\">\n          <InputGroup className=\"min-w-0 flex-1 sm:w-56 sm:flex-none\">\n            <InputGroupAddon>\n              <SearchIcon />\n            </InputGroupAddon>\n            <InputGroupInput\n              aria-label=\"Search tasks\"\n              onChange={(e) => setQuery(e.target.value)}\n              placeholder=\"Search tasks\"\n              type=\"search\"\n              value={query}\n            />\n          </InputGroup>\n          <div aria-label=\"Filter by label\" className=\"order-last flex w-full gap-1.5 overflow-x-auto py-0.5 sm:order-none sm:w-auto sm:flex-1\" role=\"group\">\n            {labels.map((l) => {\n              const on = activeLabels.includes(l.id);\n              return (\n                <button\n                  aria-pressed={on}\n                  className={cn(\n                    \"inline-flex shrink-0 cursor-pointer items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n                    hit,\n                    on ? cn(\"border-transparent font-medium text-foreground\", toneSoft[l.tone]) : \"text-muted-foreground hover:bg-accent/60\",\n                  )}\n                  key={l.id}\n                  onClick={() => setActiveLabels((prev) => (on ? prev.filter((id) => id !== l.id) : [...prev, l.id]))}\n                  type=\"button\"\n                >\n                  <span className={cn(\"size-2 rounded-full\", toneBg[l.tone])} />\n                  {l.name}\n                </button>\n              );\n            })}\n            <AnimatePresence>\n              {(activeLabels.length > 0 || q) && (\n                <motion.button\n                  animate={{ opacity: 1, scale: 1 }}\n                  className=\"inline-flex shrink-0 cursor-pointer items-center gap-1 rounded-full px-2 py-1 text-muted-foreground text-xs outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n                  exit={{ opacity: 0, scale: 0.95 }}\n                  initial={{ opacity: 0, scale: 0.95 }}\n                  transition={{ duration: 0.15, ease: \"easeOut\" }}\n                  onClick={() => {\n                    setActiveLabels([]);\n                    setQuery(\"\");\n                  }}\n                  type=\"button\"\n                >\n                  <XIcon className=\"size-3\" />\n                  Clear\n                </motion.button>\n              )}\n            </AnimatePresence>\n          </div>\n          <label className=\"ms-auto flex shrink-0 cursor-pointer items-center gap-2 text-muted-foreground text-xs\">\n            Compact\n            <Switch checked={compact} onCheckedChange={setCompact} />\n          </label>\n        </div>\n\n        <motion.div\n          className=\"flex min-h-0 flex-1 snap-x snap-mandatory scroll-px-2 gap-2 overflow-x-auto p-2 lg:snap-none\"\n          layoutScroll\n          ref={scrollerRef}\n        >\n          {columns.map((col) => {\n            const colTasks = tasks.filter((t) => t.column === col.id && visible(t));\n            const total = tasks.filter((t) => t.column === col.id).length;\n            const isOver = drag?.over === col.id;\n            return (\n              <section\n                aria-label={col.title}\n                className={cn(\n                  \"flex h-full w-[min(280px,82vw)] shrink-0 snap-start flex-col rounded-xl border bg-muted/60 transition-colors duration-150 lg:w-auto lg:min-w-0 lg:flex-1\",\n                  isOver && \"border-foreground/16 bg-accent\",\n                )}\n                key={col.id}\n                ref={(el) => {\n                  columnRefs.current[col.id] = el;\n                }}\n              >\n                <header className=\"flex items-center gap-2 ps-3 pe-2 pt-2.5 pb-2\">\n                  <span className={cn(\"size-2 rounded-full\", toneBg[col.tone ?? \"gray\"])} />\n                  <h3 className=\"font-medium text-sm\">{col.title}</h3>\n                  <span className=\"rounded-full bg-background px-1.5 font-medium text-muted-foreground text-xs tabular-nums\">\n                    {colTasks.length === total ? total : `${colTasks.length}/${total}`}\n                  </span>\n                  <button\n                    aria-label={`Add task to ${col.title}`}\n                    className=\"relative ms-auto -me-1 inline-flex size-7 cursor-pointer items-center justify-center rounded-lg text-muted-foreground outline-none transition-[color,background-color,transform] duration-150 ease-out after:absolute after:-inset-0.5 after:content-[''] hover:bg-background hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.97]\"\n                    onClick={() => {\n                      setAddingTo(addingTo === col.id ? null : col.id);\n                      setDraft(\"\");\n                    }}\n                    type=\"button\"\n                  >\n                    <PlusIcon className=\"size-4\" />\n                  </button>\n                </header>\n                <motion.div\n                  className=\"relative min-h-0 flex-1 overflow-y-auto px-1.5 pb-1.5\"\n                  layoutScroll\n                  ref={(el) => {\n                    listRefs.current[col.id] = el;\n                  }}\n                >\n                  <AnimatePresence initial={false}>\n                    {addingTo === col.id && (\n                      <motion.form\n                        animate={{ opacity: 1, height: \"auto\" }}\n                        className=\"overflow-hidden\"\n                        exit={{ opacity: 0, height: 0 }}\n                        initial={{ opacity: 0, height: 0 }}\n                        onSubmit={(e) => submitDraft(e, col.id)}\n                        transition={glide}\n                      >\n                        <div className=\"mb-1.5 rounded-md border bg-card p-2\">\n                          <input\n                            aria-label={`New task in ${col.title}`}\n                            autoFocus\n                            className=\"w-full bg-transparent px-1 py-1 text-sm outline-none placeholder:text-muted-foreground/72\"\n                            onChange={(e) => setDraft(e.target.value)}\n                            onKeyDown={(e) => {\n                              if (e.key === \"Escape\") setAddingTo(null);\n                            }}\n                            placeholder=\"Task title, then Enter\"\n                            value={draft}\n                          />\n                          <div className=\"mt-1 flex justify-end gap-1\">\n                            <button\n                              className=\"h-7 cursor-pointer rounded-md px-2.5 text-muted-foreground text-xs outline-none transition-[color,background-color,transform] duration-150 ease-out hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.97]\"\n                              onClick={() => setAddingTo(null)}\n                              type=\"button\"\n                            >\n                              Cancel\n                            </button>\n                            <button\n                              className=\"h-7 cursor-pointer rounded-md bg-primary px-2.5 font-medium text-primary-foreground text-xs outline-none transition-[opacity,transform] duration-150 ease-out focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.97] disabled:cursor-default disabled:opacity-50 disabled:active:scale-100\"\n                              disabled={!draft.trim()}\n                              type=\"submit\"\n                            >\n                              Add\n                            </button>\n                          </div>\n                        </div>\n                      </motion.form>\n                    )}\n                  </AnimatePresence>\n                  <div className={cn(\"flex flex-col\", compact ? \"gap-1.5\" : \"gap-2\")}>\n                    {colTasks.map((task) =>\n                      task.id === drag?.id ? (\n                        <motion.div\n                          className=\"rounded-md border-2 border-foreground/16 border-dashed bg-background/50\"\n                          data-placeholder=\"\"\n                          data-task-id={task.id}\n                          key={task.id}\n                          layout=\"position\"\n                          layoutId={task.id}\n                          style={{ height: drag.height }}\n                          transition={reduce ? { duration: 0 } : spring}\n                        />\n                      ) : (\n                        <motion.div\n                          animate={{ opacity: 1, scale: 1 }}\n                          className=\"group relative\"\n                          data-task-id={task.id}\n                          initial={{ opacity: 0, scale: 0.96 }}\n                          key={task.id}\n                          layout=\"position\"\n                          layoutId={task.id}\n                          transition={reduce ? { duration: 0 } : spring}\n                        >\n                          <button\n                            aria-describedby={`${groupId}-dnd-help`}\n                            className={cn(\n                              \"block w-full cursor-pointer rounded-md border bg-card text-start shadow-xs/5 outline-none transition-[border-color,box-shadow,transform] duration-150 ease-out hover:border-foreground/16 focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.97] motion-reduce:active:scale-100\",\n                              compact ? \"px-2.5 py-2 ps-3\" : \"p-3 ps-3.5\",\n                              selectedId === task.id && \"border-foreground/24 ring-2 ring-ring/24\",\n                            )}\n                            data-card=\"\"\n                            onClick={() => {\n                              if (!justDragged.current) setSelectedId(task.id);\n                            }}\n                            onKeyDown={(e) => onCardKeyDown(e, task)}\n                            onPointerDown={(e) => onCardPointerDown(e, task.id)}\n                            type=\"button\"\n                          >\n                            <CardBody compact={compact} labels={labels} task={task} />\n                          </button>\n                          <span\n                            aria-hidden\n                            className=\"absolute top-1/2 -left-1 flex h-7 w-4 -translate-y-1/2 cursor-grab touch-none items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 pointer-coarse:opacity-70\"\n                            data-drag-handle=\"\"\n                            onPointerDown={(e) => onCardPointerDown(e, task.id)}\n                          >\n                            <GripVerticalIcon className=\"size-3.5\" />\n                          </span>\n                        </motion.div>\n                      ),\n                    )}\n                  </div>\n                  {colTasks.length === 0 && (\n                    <div className=\"flex h-24 items-center justify-center rounded-md border border-dashed text-muted-foreground text-xs\">\n                      {total > 0 ? \"No matching tasks\" : drag ? \"Drop here\" : \"Nothing here yet\"}\n                    </div>\n                  )}\n                </motion.div>\n              </section>\n            );\n          })}\n        </motion.div>\n\n        {drag && dragged && (\n          <motion.div\n            animate={drag.dropping ? { rotate: 0, scale: 1 } : { rotate: 2.5, scale: 1.03 }}\n            className=\"pointer-events-none absolute top-0 left-0 z-40\"\n            initial={{ rotate: 0, scale: 1 }}\n            style={{ x: ox, y: oy, width: drag.width }}\n            transition={reduce ? { duration: 0 } : spring}\n          >\n            <div\n              className={cn(\n                \"rounded-md border border-foreground/16 bg-card shadow-lg/8 ring-4 ring-foreground/4\",\n                compact ? \"px-2.5 py-2 ps-3\" : \"p-3 ps-3.5\",\n              )}\n            >\n              <CardBody compact={compact} labels={labels} task={dragged} />\n            </div>\n          </motion.div>\n        )}\n\n        <AnimatePresence>\n          {selected && (\n            <motion.div\n              animate={{ opacity: 1 }}\n              className=\"absolute inset-0 z-20 bg-background/40\"\n              exit={{ opacity: 0 }}\n              initial={{ opacity: 0 }}\n              key=\"scrim\"\n              onClick={() => setSelectedId(null)}\n            />\n          )}\n          {selected && (\n            <TaskDetail\n              columns={columns}\n              key=\"detail\"\n              labels={labels}\n              onClose={() => {\n                const id = selected.id;\n                setSelectedId(null);\n                refocus(id);\n              }}\n              onMove={(column) => moveToColumn(selected.id, column)}\n              onUpdate={(patch) => updateTask(selected.id, patch)}\n              task={selected}\n            />\n          )}\n        </AnimatePresence>\n\n        <p className=\"sr-only\" id={`${groupId}-dnd-help`}>\n          Press Enter to open. Shift plus arrow keys moves the task between columns or up and down.\n        </p>\n        <p aria-live=\"polite\" className=\"sr-only\">\n          {announcement}\n        </p>\n      </div>\n    </LayoutGroup>\n  );\n}\n"
    }
  ]
}