{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "accounts-crm",
  "type": "registry:block",
  "title": "Pipeline Today",
  "description": "A salesperson's morning view: drag deals between stages (or move them with the keyboard) while each column's weighted value and the forecast roll live, and a Focus rail tells you who to act on and why, with one-click email, call and snooze that update the deal.",
  "categories": [
    "screen",
    "Product"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/avatar.json",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/kbd.json",
    "https://coss.com/ui/r/menu.json",
    "https://coss.com/ui/r/segmented-control.json",
    "https://coss.com/ui/r/tooltip.json"
  ],
  "files": [
    {
      "path": "registry/devl/accounts-crm.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport {\n  ArrowRightIcon,\n  Building2Icon,\n  CalendarClockIcon,\n  ChartNoAxesColumnIcon,\n  CheckIcon,\n  ChevronDownIcon,\n  CircleCheckIcon,\n  Clock3Icon,\n  CoffeeIcon,\n  EyeIcon,\n  InboxIcon,\n  KanbanIcon,\n  type LucideIcon,\n  MailIcon,\n  MoonIcon,\n  PhoneIcon,\n  ReplyIcon,\n  SettingsIcon,\n  SunriseIcon,\n  UserMinusIcon,\n  XIcon,\n} from \"lucide-react\";\nimport {\n  AnimatePresence,\n  animate,\n  MotionConfig,\n  motion,\n  useMotionValue,\n  useReducedMotion,\n  useSpring,\n  useTransform,\n} from \"motion/react\";\nimport {\n  type KeyboardEvent,\n  type PointerEvent,\n  type ReactElement,\n  type ReactNode,\n  type RefObject,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from \"react\";\nimport { Avatar, AvatarFallback } from \"@/components/ui/avatar\";\nimport { Button } from \"@/components/ui/button\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport {\n  Menu,\n  MenuGroup,\n  MenuGroupLabel,\n  MenuItem,\n  MenuPopup,\n  MenuRadioGroup,\n  MenuRadioItem,\n  MenuSeparator,\n  MenuTrigger,\n} from \"@/components/ui/menu\";\nimport { SegmentedControl, SegmentedControlItem } from \"@/components/ui/segmented-control\";\nimport { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from \"@/components/ui/tooltip\";\nimport { cn } from \"@/lib/utils\";\n\nexport type DealStage = \"lead\" | \"qualified\" | \"proposal\" | \"negotiation\" | \"won\";\nexport type Engagement = \"hot\" | \"warm\" | \"cooling\" | \"cold\";\nexport type FocusKind = \"quiet\" | \"opened\" | \"champion\" | \"overdue\" | \"replied\";\nexport type FocusAction = \"email\" | \"call\" | \"snooze\";\n\nexport interface PipelineStage {\n  id: DealStage;\n  label: string;\n  probability: number;\n}\n\nexport interface DealOwner {\n  id: string;\n  name: string;\n  role?: string;\n}\n\nexport interface DealContact {\n  name: string;\n  role: string;\n  tag?: { label: string; tone: \"good\" | \"bad\" | \"neutral\" };\n}\n\nexport interface DealActivity {\n  label: string;\n  when: string;\n}\n\nexport interface Deal {\n  id: string;\n  company: string;\n  domain: string;\n  stage: DealStage;\n  value: number;\n  ownerId: string;\n  daysInStage: number;\n  engagement: Engagement;\n  lastTouch: string;\n  closeLabel: string;\n  nextStep: string;\n  contacts: DealContact[];\n  activity: DealActivity[];\n  note?: string;\n}\n\nexport interface FocusSignal {\n  id: string;\n  dealId: string;\n  kind: FocusKind;\n  headline: string;\n  detail: string;\n  contact: string;\n  tag: string;\n}\n\nexport interface PipelineTodayProps {\n  deals?: Deal[];\n  signals?: FocusSignal[];\n  owners?: DealOwner[];\n  stages?: PipelineStage[];\n  currentUserId?: string;\n  workspace?: string;\n  dateLabel?: string;\n  greeting?: string;\n  target?: number;\n  forecastLabel?: string;\n  onDealMove?: (dealId: string, stage: DealStage, index: number) => void;\n  className?: string;\n}\n\nexport const defaultStages: PipelineStage[] = [\n  { id: \"lead\", label: \"Lead\", probability: 0.1 },\n  { id: \"qualified\", label: \"Qualified\", probability: 0.25 },\n  { id: \"proposal\", label: \"Proposal\", probability: 0.5 },\n  { id: \"negotiation\", label: \"Negotiation\", probability: 0.75 },\n  { id: \"won\", label: \"Won\", probability: 1 },\n];\n\nexport const defaultOwners: DealOwner[] = [\n  { id: \"maren\", name: \"Maren Kole\", role: \"Account executive\" },\n  { id: \"jonah\", name: \"Jonah Ifeanyi\", role: \"Account executive\" },\n  { id: \"sofia\", name: \"Sofia Lindqvist\", role: \"Account executive\" },\n  { id: \"ravi\", name: \"Ravi Castellano\", role: \"Sales lead\" },\n];\n\nexport const defaultDeals: Deal[] = [\n  {\n    id: \"pemberton\",\n    company: \"Pemberton & Vale\",\n    domain: \"pembertonvale.law\",\n    stage: \"lead\",\n    value: 12000,\n    ownerId: \"sofia\",\n    daysInStage: 4,\n    engagement: \"warm\",\n    lastTouch: \"4d ago\",\n    closeLabel: \"Jan 15\",\n    nextStep: \"Discovery call with Priya to map their intake process\",\n    contacts: [{ name: \"Priya Nair\", role: \"Operations director\" }],\n    activity: [{ label: \"Inbound form: intake routing for 40 lawyers\", when: \"Oct 23\" }],\n  },\n  {\n    id: \"mosswood\",\n    company: \"Mosswood Bakery\",\n    domain: \"mosswood.co\",\n    stage: \"lead\",\n    value: 6400,\n    ownerId: \"ravi\",\n    daysInStage: 11,\n    engagement: \"cooling\",\n    lastTouch: \"2w ago\",\n    closeLabel: \"Feb 1\",\n    nextStep: \"Send the three-location pricing sheet\",\n    contacts: [{ name: \"Elsie Bram\", role: \"Owner\" }],\n    activity: [{ label: \"Met at the regional food fair\", when: \"Oct 13\" }],\n  },\n  {\n    id: \"wrenfield\",\n    company: \"Wrenfield Clinics\",\n    domain: \"wrenfield.health\",\n    stage: \"lead\",\n    value: 22000,\n    ownerId: \"maren\",\n    daysInStage: 2,\n    engagement: \"hot\",\n    lastTouch: \"Yesterday\",\n    closeLabel: \"Dec 12\",\n    nextStep: \"Confirm Thursday demo and invite their IT lead\",\n    contacts: [\n      { name: \"Hugo Ferrant\", role: \"Head of patient ops\", tag: { label: \"Champion\", tone: \"good\" } },\n      { name: \"Bea Lund\", role: \"IT manager\" },\n    ],\n    activity: [\n      { label: \"Hugo booked a demo for Thursday\", when: \"Yesterday\" },\n      { label: \"Webinar sign-up\", when: \"Oct 21\" },\n    ],\n  },\n  {\n    id: \"oakhollow\",\n    company: \"Oakhollow Studio\",\n    domain: \"oakhollow.studio\",\n    stage: \"qualified\",\n    value: 18000,\n    ownerId: \"maren\",\n    daysInStage: 6,\n    engagement: \"warm\",\n    lastTouch: \"3d ago\",\n    closeLabel: \"Dec 3\",\n    nextStep: \"Scope the agency plan with Rosa\",\n    contacts: [{ name: \"Rosa Quint\", role: \"Studio director\", tag: { label: \"Champion\", tone: \"good\" } }],\n    activity: [{ label: \"Discovery call, 32 min\", when: \"Oct 24\" }],\n  },\n  {\n    id: \"juniper\",\n    company: \"Juniper Ridge Health\",\n    domain: \"juniperridge.care\",\n    stage: \"qualified\",\n    value: 39000,\n    ownerId: \"sofia\",\n    daysInStage: 8,\n    engagement: \"warm\",\n    lastTouch: \"2d ago\",\n    closeLabel: \"Nov 20\",\n    nextStep: \"Security questionnaire due Friday\",\n    contacts: [{ name: \"Owen Achebe\", role: \"Compliance lead\" }],\n    activity: [{ label: \"Security questionnaire received\", when: \"Oct 25\" }],\n  },\n  {\n    id: \"driftline\",\n    company: \"Driftline Media\",\n    domain: \"driftline.fm\",\n    stage: \"qualified\",\n    value: 15500,\n    ownerId: \"maren\",\n    daysInStage: 5,\n    engagement: \"hot\",\n    lastTouch: \"Today\",\n    closeLabel: \"Nov 14\",\n    nextStep: \"Price out 12 seats with the annual discount\",\n    contacts: [\n      { name: \"Mika Sato\", role: \"Head of production\", tag: { label: \"Champion\", tone: \"good\" } },\n      { name: \"Jules Arden\", role: \"Finance\" },\n    ],\n    activity: [\n      { label: \"Mika replied: ready to talk pricing\", when: \"Today, 8:12\" },\n      { label: \"Trial reached 9 active seats\", when: \"Oct 24\" },\n    ],\n  },\n  {\n    id: \"brightwater\",\n    company: \"Brightwater Labs\",\n    domain: \"brightwater.bio\",\n    stage: \"proposal\",\n    value: 46500,\n    ownerId: \"maren\",\n    daysInStage: 6,\n    engagement: \"hot\",\n    lastTouch: \"Today\",\n    closeLabel: \"Nov 12\",\n    nextStep: \"Walk Theo through pricing options on a call\",\n    contacts: [\n      { name: \"Theo Marsh\", role: \"VP research ops\", tag: { label: \"Champion\", tone: \"good\" } },\n      { name: \"Clara Ng\", role: \"Procurement\", tag: { label: \"Economic buyer\", tone: \"neutral\" } },\n    ],\n    activity: [\n      { label: \"Theo opened the proposal (2nd time)\", when: \"Today, 9:41\" },\n      { label: \"Theo opened the proposal\", when: \"Today, 8:05\" },\n      { label: \"Proposal sent by you\", when: \"Oct 21\" },\n    ],\n    note: \"Budget is approved for Q4. Clara needs the DPA before signature.\",\n  },\n  {\n    id: \"ferrovia\",\n    company: \"Ferrovia Transit\",\n    domain: \"ferrovia.city\",\n    stage: \"proposal\",\n    value: 67000,\n    ownerId: \"maren\",\n    daysInStage: 19,\n    engagement: \"cooling\",\n    lastTouch: \"8d ago\",\n    closeLabel: \"Oct 24\",\n    nextStep: \"Ask Lotte where procurement has it\",\n    contacts: [\n      { name: \"Lotte Vos\", role: \"Digital programme lead\", tag: { label: \"Champion\", tone: \"good\" } },\n      { name: \"Bram Okon\", role: \"Procurement\" },\n    ],\n    activity: [\n      { label: \"Lotte: sent to procurement\", when: \"Oct 19\" },\n      { label: \"Proposal sent by you\", when: \"Oct 8\" },\n    ],\n    note: \"City budget cycle ends in December. Procurement wants three references.\",\n  },\n  {\n    id: \"tessellate\",\n    company: \"Tessellate Robotics\",\n    domain: \"tessellate.dev\",\n    stage: \"proposal\",\n    value: 52000,\n    ownerId: \"jonah\",\n    daysInStage: 3,\n    engagement: \"warm\",\n    lastTouch: \"5h ago\",\n    closeLabel: \"Oct 30\",\n    nextStep: \"Legal review of the order form\",\n    contacts: [{ name: \"Ada Whitlock\", role: \"CTO\", tag: { label: \"Champion\", tone: \"good\" } }],\n    activity: [{ label: \"Order form sent to legal\", when: \"Today, 7:30\" }],\n  },\n  {\n    id: \"halcyon\",\n    company: \"Halcyon Freight\",\n    domain: \"halcyonfreight.co\",\n    stage: \"negotiation\",\n    value: 84000,\n    ownerId: \"maren\",\n    daysInStage: 12,\n    engagement: \"cold\",\n    lastTouch: \"9d ago\",\n    closeLabel: \"Oct 29\",\n    nextStep: \"Send the security pack Ines asked for\",\n    contacts: [\n      { name: \"Ines Okafor\", role: \"Head of logistics IT\", tag: { label: \"Champion\", tone: \"good\" } },\n      { name: \"Marcus Hale\", role: \"COO\", tag: { label: \"Economic buyer\", tone: \"neutral\" } },\n    ],\n    activity: [\n      { label: \"Ines asked for the security pack\", when: \"Oct 18\" },\n      { label: \"Redlines returned on the MSA\", when: \"Oct 15\" },\n    ],\n    note: \"Marcus wants go-live before peak season in January.\",\n  },\n  {\n    id: \"quillstone\",\n    company: \"Quillstone Analytics\",\n    domain: \"quillstone.ai\",\n    stage: \"negotiation\",\n    value: 120000,\n    ownerId: \"maren\",\n    daysInStage: 9,\n    engagement: \"cooling\",\n    lastTouch: \"6d ago\",\n    closeLabel: \"Nov 8\",\n    nextStep: \"Find a new sponsor before the renewal date\",\n    contacts: [\n      { name: \"Dana Reyes\", role: \"Former VP data\", tag: { label: \"Left Oct 19\", tone: \"bad\" } },\n      { name: \"Anil Bhatt\", role: \"CFO\", tag: { label: \"Economic buyer\", tone: \"neutral\" } },\n      { name: \"Wren Castillo\", role: \"Data platform lead\" },\n    ],\n    activity: [\n      { label: \"Dana's out-of-office: no longer with Quillstone\", when: \"Oct 21\" },\n      { label: \"Renewal quote sent by you\", when: \"Oct 14\" },\n    ],\n    note: \"Renewal plus 40 seats. Wren runs the platform day to day and likes it.\",\n  },\n  {\n    id: \"cinderpath\",\n    company: \"Cinderpath Games\",\n    domain: \"cinderpath.gg\",\n    stage: \"negotiation\",\n    value: 28000,\n    ownerId: \"ravi\",\n    daysInStage: 4,\n    engagement: \"warm\",\n    lastTouch: \"2d ago\",\n    closeLabel: \"Nov 4\",\n    nextStep: \"Agree on the multi-year discount\",\n    contacts: [{ name: \"Leo Brandt\", role: \"Studio head\" }],\n    activity: [{ label: \"Asked for a two-year price\", when: \"Oct 25\" }],\n  },\n  {\n    id: \"saltmarsh\",\n    company: \"Saltmarsh Outdoor\",\n    domain: \"saltmarsh.shop\",\n    stage: \"won\",\n    value: 31000,\n    ownerId: \"jonah\",\n    daysInStage: 19,\n    engagement: \"hot\",\n    lastTouch: \"Today\",\n    closeLabel: \"Oct 8\",\n    nextStep: \"Kick-off with onboarding team\",\n    contacts: [{ name: \"Nell Harper\", role: \"E-commerce lead\" }],\n    activity: [{ label: \"Contract signed\", when: \"Oct 8\" }],\n  },\n  {\n    id: \"larkspur\",\n    company: \"Larkspur Energy\",\n    domain: \"larkspur.energy\",\n    stage: \"won\",\n    value: 74000,\n    ownerId: \"sofia\",\n    daysInStage: 25,\n    engagement: \"hot\",\n    lastTouch: \"Yesterday\",\n    closeLabel: \"Oct 2\",\n    nextStep: \"Introduce the customer success manager\",\n    contacts: [{ name: \"Ravi Mendes\", role: \"Grid operations\" }],\n    activity: [{ label: \"Contract signed\", when: \"Oct 2\" }],\n  },\n];\n\nexport const defaultSignals: FocusSignal[] = [\n  {\n    id: \"s-brightwater\",\n    dealId: \"brightwater\",\n    kind: \"opened\",\n    headline: \"opened the proposal twice today\",\n    detail: \"Theo spent four minutes on pricing. A good moment to call.\",\n    contact: \"Theo Marsh\",\n    tag: \"Opened twice\",\n  },\n  {\n    id: \"s-halcyon\",\n    dealId: \"halcyon\",\n    kind: \"quiet\",\n    headline: \"went quiet 9 days ago\",\n    detail: \"Ines asked for the security pack on Oct 18. Nothing since.\",\n    contact: \"Ines Okafor\",\n    tag: \"Quiet 9 days\",\n  },\n  {\n    id: \"s-quillstone\",\n    dealId: \"quillstone\",\n    kind: \"champion\",\n    headline: \"renewal in 12 days, champion left\",\n    detail: \"Dana Reyes left on Oct 19. No new sponsor named yet.\",\n    contact: \"Anil Bhatt\",\n    tag: \"Champion left\",\n  },\n  {\n    id: \"s-driftline\",\n    dealId: \"driftline\",\n    kind: \"replied\",\n    headline: \"replied: ready to talk pricing\",\n    detail: \"Mika wants options for 12 seats before Friday.\",\n    contact: \"Mika Sato\",\n    tag: \"Replied today\",\n  },\n  {\n    id: \"s-ferrovia\",\n    dealId: \"ferrovia\",\n    kind: \"overdue\",\n    headline: \"is 3 days past its close date\",\n    detail: \"Still in Proposal. Move the date or nudge procurement.\",\n    contact: \"Lotte Vos\",\n    tag: \"3 days overdue\",\n  },\n];\n\nconst ease = [0.23, 1, 0.32, 1] as const;\nconst glide = { type: \"spring\", stiffness: 520, damping: 42 } as const;\nconst land = { type: \"spring\", stiffness: 380, damping: 30 } as const;\n\nconst stageDot: Record<DealStage, string> = {\n  lead: \"bg-muted-foreground/50\",\n  qualified: \"bg-sky-500 dark:bg-sky-400\",\n  proposal: \"bg-amber-500 dark:bg-amber-400\",\n  negotiation: \"bg-violet-500 dark:bg-violet-400\",\n  won: \"bg-emerald-500 dark:bg-emerald-400\",\n};\n\nconst engagementMeta: Record<Engagement, { label: string; level: number; bar: string; text: string }> = {\n  hot: { label: \"Hot\", level: 4, bar: \"bg-emerald-500 dark:bg-emerald-400\", text: \"text-emerald-700 dark:text-emerald-300\" },\n  warm: { label: \"Warm\", level: 3, bar: \"bg-emerald-500 dark:bg-emerald-400\", text: \"text-muted-foreground\" },\n  cooling: { label: \"Cooling\", level: 2, bar: \"bg-amber-500 dark:bg-amber-400\", text: \"text-amber-700 dark:text-amber-300\" },\n  cold: { label: \"Cold\", level: 1, bar: \"bg-rose-500 dark:bg-rose-400\", text: \"text-rose-700 dark:text-rose-300\" },\n};\n\nconst warmer: Record<Engagement, Engagement> = { cold: \"cooling\", cooling: \"warm\", warm: \"hot\", hot: \"hot\" };\n\nconst signalMeta: Record<FocusKind, { icon: LucideIcon; tile: string; text: string }> = {\n  quiet: {\n    icon: MoonIcon,\n    tile: \"bg-amber-500/12 text-amber-700 dark:bg-amber-400/14 dark:text-amber-300\",\n    text: \"text-amber-700 dark:text-amber-300\",\n  },\n  opened: {\n    icon: EyeIcon,\n    tile: \"bg-sky-500/12 text-sky-700 dark:bg-sky-400/14 dark:text-sky-300\",\n    text: \"text-sky-700 dark:text-sky-300\",\n  },\n  champion: {\n    icon: UserMinusIcon,\n    tile: \"bg-rose-500/12 text-rose-700 dark:bg-rose-400/14 dark:text-rose-300\",\n    text: \"text-rose-700 dark:text-rose-300\",\n  },\n  overdue: {\n    icon: CalendarClockIcon,\n    tile: \"bg-orange-500/12 text-orange-700 dark:bg-orange-400/14 dark:text-orange-300\",\n    text: \"text-orange-700 dark:text-orange-300\",\n  },\n  replied: {\n    icon: ReplyIcon,\n    tile: \"bg-emerald-500/12 text-emerald-700 dark:bg-emerald-400/14 dark:text-emerald-300\",\n    text: \"text-emerald-700 dark:text-emerald-300\",\n  },\n};\n\nconst monogramTones = [\n  \"bg-amber-500/15 text-amber-800 dark:bg-amber-400/15 dark:text-amber-200\",\n  \"bg-sky-500/15 text-sky-800 dark:bg-sky-400/15 dark:text-sky-200\",\n  \"bg-violet-500/15 text-violet-800 dark:bg-violet-400/15 dark:text-violet-200\",\n  \"bg-emerald-500/15 text-emerald-800 dark:bg-emerald-400/15 dark:text-emerald-200\",\n  \"bg-rose-500/15 text-rose-800 dark:bg-rose-400/15 dark:text-rose-200\",\n  \"bg-teal-500/15 text-teal-800 dark:bg-teal-400/15 dark:text-teal-200\",\n  \"bg-orange-500/15 text-orange-800 dark:bg-orange-400/15 dark:text-orange-200\",\n];\n\nconst ownerTones = [\n  \"bg-orange-500/20 text-orange-900 dark:bg-orange-400/25 dark:text-orange-100\",\n  \"bg-teal-500/20 text-teal-900 dark:bg-teal-400/25 dark:text-teal-100\",\n  \"bg-violet-500/20 text-violet-900 dark:bg-violet-400/25 dark:text-violet-100\",\n  \"bg-sky-500/20 text-sky-900 dark:bg-sky-400/25 dark:text-sky-100\",\n];\n\nconst burstTones = [\n  \"bg-emerald-500 dark:bg-emerald-400\",\n  \"bg-amber-500 dark:bg-amber-400\",\n  \"bg-sky-500 dark:bg-sky-400\",\n  \"bg-violet-500 dark:bg-violet-400\",\n  \"bg-rose-500 dark:bg-rose-400\",\n  \"bg-emerald-500 dark:bg-emerald-400\",\n];\n\nconst fullMoney = new Intl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\", maximumFractionDigits: 0 });\n\nfunction money(n: number) {\n  return fullMoney.format(Math.round(n));\n}\n\nfunction shortMoney(n: number) {\n  const v = Math.round(n);\n  if (v >= 1_000_000) return `$${(v / 1_000_000).toFixed(2).replace(/\\.?0+$/, \"\")}M`;\n  if (v >= 1000) return `$${(v / 1000).toFixed(1).replace(/\\.0$/, \"\")}k`;\n  return `$${v}`;\n}\n\nfunction signedMoney(n: number) {\n  return `${n > 0 ? \"+\" : \"−\"}${money(Math.abs(n))}`;\n}\n\nfunction initials(name: string) {\n  return name\n    .replace(/[^A-Za-z\\s]/g, \" \")\n    .split(/\\s+/)\n    .filter(Boolean)\n    .slice(0, 2)\n    .map((p) => p[0])\n    .join(\"\")\n    .toUpperCase();\n}\n\nfunction shortName(company: string) {\n  return company.split(/\\s+/)[0].replace(/[^A-Za-z-]/g, \"\");\n}\n\nfunction hashIndex(s: string, n: number) {\n  let h = 0;\n  for (let i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) >>> 0;\n  return h % n;\n}\n\nfunction scaleOf(el: HTMLElement) {\n  return el.getBoundingClientRect().width / (el.offsetWidth || 1) || 1;\n}\n\nfunction useCalmMotion() {\n  const prefers = useReducedMotion();\n  const [mounted, setMounted] = useState(false);\n  useEffect(() => setMounted(true), []);\n  return mounted && Boolean(prefers);\n}\n\nfunction moveDeal(list: Deal[], id: string, stage: DealStage, index: number, patch?: Partial<Deal>) {\n  const moving = list.find((d) => d.id === id);\n  if (!moving) return list;\n  const rest = list.filter((d) => d.id !== id);\n  const column = rest.filter((d) => d.stage === stage);\n  const next: Deal = { ...moving, stage, ...(moving.stage !== stage ? { daysInStage: 0 } : {}), ...patch };\n  const anchor = column[index];\n  const at = anchor ? rest.indexOf(anchor) : column.length ? rest.indexOf(column[column.length - 1]) + 1 : rest.length;\n  return [...rest.slice(0, at), next, ...rest.slice(at)];\n}\n\ntype Rect = { left: number; top: number; width: number; rotate?: number; scale?: number };\ntype RectStore = RefObject<Map<string, Rect>>;\n\nfunction Rolling({ value, format, reduce }: { value: number; format: (n: number) => string; reduce: boolean }) {\n  const mv = useMotionValue(value);\n  const text = useTransform(mv, format);\n  useEffect(() => {\n    if (reduce) {\n      mv.jump(value);\n      return;\n    }\n    const controls = animate(mv, value, { type: \"spring\", stiffness: 160, damping: 26 });\n    return () => controls.stop();\n  }, [value, reduce, mv]);\n  return (\n    <motion.span aria-hidden className=\"tabular-nums\">\n      {text}\n    </motion.span>\n  );\n}\n\nfunction Monogram({ name, className }: { name: string; className?: string }) {\n  return (\n    <span\n      aria-hidden\n      className={cn(\n        \"flex shrink-0 items-center justify-center font-semibold tracking-tight\",\n        monogramTones[hashIndex(name, monogramTones.length)],\n        className,\n      )}\n    >\n      {initials(name)}\n    </span>\n  );\n}\n\nfunction OwnerAvatar({ owner, index, className }: { owner?: DealOwner; index: number; className?: string }) {\n  return (\n    <Avatar className={cn(\"[--avatar-size:--spacing(5)]\", className)}>\n      <AvatarFallback className={cn(\"font-semibold text-[9px]\", ownerTones[index % ownerTones.length])}>\n        {owner ? initials(owner.name) : \"?\"}\n      </AvatarFallback>\n    </Avatar>\n  );\n}\n\nfunction SignalBars({ engagement }: { engagement: Engagement }) {\n  const meta = engagementMeta[engagement];\n  return (\n    <span aria-hidden className=\"flex h-2.5 shrink-0 items-end gap-[2px]\">\n      {[0, 1, 2, 3].map((i) => (\n        <span\n          className={cn(\n            \"w-[3px] rounded-[1px] transition-colors duration-300\",\n            i < meta.level ? meta.bar : \"bg-foreground/12\",\n          )}\n          key={i}\n          style={{ height: 4 + i * 2 }}\n        />\n      ))}\n    </span>\n  );\n}\n\nfunction Burst({ reduce }: { reduce: boolean }) {\n  if (reduce) return null;\n  return (\n    <span aria-hidden className=\"pointer-events-none absolute top-1/2 left-1/2\">\n      {burstTones.map((tone, i) => {\n        const angle = (i / burstTones.length) * Math.PI * 2 - Math.PI / 2;\n        return (\n          <motion.span\n            animate={{ x: Math.cos(angle) * 15, y: Math.sin(angle) * 15, opacity: [0, 1, 0], scale: [0.6, 1, 0.6] }}\n            className={cn(\"absolute -top-[2px] -left-[2px] size-1 rounded-full\", tone)}\n            initial={{ x: 0, y: 0, opacity: 0 }}\n            key={i}\n            transition={{ duration: 0.6, ease, opacity: { duration: 0.6, times: [0, 0.2, 1] } }}\n          />\n        );\n      })}\n    </span>\n  );\n}\n\ninterface FaceProps {\n  deal: Deal;\n  owner?: DealOwner;\n  ownerIndex: number;\n  flag?: FocusSignal;\n  celebrate?: number;\n  touched?: number;\n  reduce: boolean;\n  className?: string;\n}\n\nfunction DealFace({ deal, owner, ownerIndex, flag, celebrate, touched, reduce, className }: FaceProps) {\n  const engagement = engagementMeta[deal.engagement];\n  const won = deal.stage === \"won\";\n  return (\n    <div\n      className={cn(\n        \"relative rounded-xl border bg-card p-2.5 shadow-xs/5 transition-[border-color,background-color,box-shadow] duration-200\",\n        className,\n      )}\n    >\n      {celebrate ? (\n        <motion.span\n          animate={{ opacity: 0 }}\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0 rounded-[inherit] bg-emerald-500/12 dark:bg-emerald-400/12\"\n          initial={{ opacity: 1 }}\n          key={`c${celebrate}`}\n          transition={{ duration: 1.1, ease: \"easeOut\", delay: 0.2 }}\n        />\n      ) : null}\n      {touched ? (\n        <motion.span\n          animate={{ opacity: 0 }}\n          aria-hidden\n          className=\"pointer-events-none absolute -inset-px rounded-[inherit] ring-2 ring-sky-500/50 dark:ring-sky-400/50\"\n          initial={{ opacity: 1 }}\n          key={`t${touched}`}\n          transition={{ duration: 1.2, ease: \"easeOut\", delay: 0.3 }}\n        />\n      ) : null}\n      <div className=\"relative truncate font-medium\">{deal.company}</div>\n      <div className=\"relative mt-2 flex items-baseline justify-between gap-2\">\n        <span className=\"font-medium tabular-nums\">{money(deal.value)}</span>\n        <span\n          className={cn(\n            \"shrink-0 text-xs tabular-nums\",\n            !won && deal.daysInStage >= 14 ? \"text-amber-700 dark:text-amber-300\" : \"text-muted-foreground\",\n          )}\n        >\n          {won ? deal.closeLabel : deal.daysInStage === 0 ? \"Just moved\" : `${deal.daysInStage}d in stage`}\n        </span>\n      </div>\n      <div className=\"relative mt-1.5 flex h-[18px] items-center gap-1.5 text-xs\">\n        {won ? (\n          <>\n            <span className=\"relative flex size-3.5 shrink-0 items-center justify-center\">\n              <motion.span\n                animate={{ scale: 1, opacity: 1 }}\n                className=\"flex\"\n                initial={celebrate && !reduce ? { scale: 0.6, opacity: 0 } : false}\n                key={`check-${celebrate ?? 0}`}\n                transition={{ type: \"spring\", stiffness: 500, damping: 18 }}\n              >\n                <CircleCheckIcon className=\"size-3.5 text-emerald-600 dark:text-emerald-400\" />\n              </motion.span>\n              {celebrate ? <Burst key={`burst-${celebrate}`} reduce={reduce} /> : null}\n            </span>\n            <span className=\"truncate text-emerald-700 dark:text-emerald-300\">Closed won</span>\n            <OwnerAvatar className=\"ms-auto [--avatar-size:18px]\" index={ownerIndex} owner={owner} />\n          </>\n        ) : (\n          <>\n            <SignalBars engagement={deal.engagement} />\n            {flag ? (\n              <span className={cn(\"truncate\", signalMeta[flag.kind].text)}>{flag.tag}</span>\n            ) : (\n              <span className={cn(\"truncate\", deal.engagement === \"warm\" ? \"text-muted-foreground\" : engagement.text)}>\n                {deal.lastTouch}\n              </span>\n            )}\n            <OwnerAvatar className=\"ms-auto [--avatar-size:18px]\" index={ownerIndex} owner={owner} />\n          </>\n        )}\n      </div>\n    </div>\n  );\n}\n\nfunction FlipSlot({\n  flipKey,\n  rects,\n  getScale,\n  reduce,\n  className,\n  children,\n}: {\n  flipKey: string;\n  rects: RectStore;\n  getScale: () => number;\n  reduce: boolean;\n  className?: string;\n  children: ReactNode;\n}) {\n  const ref = useRef<HTMLLIElement>(null);\n  const x = useMotionValue(0);\n  const y = useMotionValue(0);\n  const rotate = useMotionValue(0);\n  const scale = useMotionValue(1);\n\n  useLayoutEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const box = el.getBoundingClientRect();\n    const prev = rects.current.get(flipKey);\n    rects.current.set(flipKey, { left: box.left, top: box.top, width: box.width });\n    if (!prev || reduce || box.width === 0 || prev.width === 0) return;\n    const s = getScale();\n    const dx = (prev.left - box.left) / s;\n    const dy = (prev.top - box.top) / s;\n    const dropped = prev.rotate !== undefined;\n    if (!dropped && Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5) return;\n    x.jump(dx + (dropped ? 0 : x.get()));\n    y.jump(dy + (dropped ? 0 : y.get()));\n    const transition = dropped ? land : glide;\n    animate(x, 0, transition);\n    animate(y, 0, transition);\n    if (dropped) {\n      rotate.jump(prev.rotate ?? 0);\n      scale.jump(prev.scale ?? 1);\n      animate(rotate, 0, land);\n      animate(scale, 1, land);\n    }\n  });\n\n  return (\n    <li className={cn(\"relative\", className)} ref={ref}>\n      <motion.div style={{ x, y, rotate, scale }}>\n        {children}\n      </motion.div>\n    </li>\n  );\n}\n\nfunction SignalItem({\n  signal,\n  deal,\n  stageLabel,\n  resolving,\n  reduce,\n  onAct,\n  onOpen,\n  onHint,\n}: {\n  signal: FocusSignal;\n  deal?: Deal;\n  stageLabel: string;\n  resolving?: FocusAction;\n  reduce: boolean;\n  onAct: (signal: FocusSignal, action: FocusAction) => void;\n  onOpen: (dealId: string) => void;\n  onHint: (dealId: string | null) => void;\n}) {\n  const meta = signalMeta[signal.kind];\n  const Icon = meta.icon;\n  const company = deal?.company ?? \"\";\n  const outcome =\n    resolving === \"email\"\n      ? `Follow-up sent to ${signal.contact}`\n      : resolving === \"call\"\n        ? `Call with ${signal.contact} logged`\n        : \"Snoozed until tomorrow\";\n\n  return (\n    <motion.li\n      className=\"overflow-hidden\"\n      exit={reduce ? { opacity: 0, transition: { duration: 0.15 } } : { height: 0, opacity: 0 }}\n      initial={false}\n      onBlur={() => onHint(null)}\n      onFocus={() => onHint(signal.dealId)}\n      onMouseEnter={() => onHint(signal.dealId)}\n      onMouseLeave={() => onHint(null)}\n      transition={{ height: { duration: 0.32, ease }, opacity: { duration: 0.18 } }}\n    >\n      <div className=\"pb-2\">\n        <div className=\"relative rounded-xl border bg-card p-3 shadow-xs/5\">\n          <div aria-hidden={resolving ? true : undefined} className=\"flex gap-3\">\n            <span className={cn(\"flex size-7 shrink-0 items-center justify-center rounded-lg\", meta.tile)}>\n              <Icon className=\"size-3.5\" />\n            </span>\n            <div className=\"min-w-0 flex-1\">\n              <p className=\"text-pretty leading-5\">\n                <button\n                  aria-label={`Open ${company}`}\n                  className=\"relative cursor-pointer rounded-sm font-medium outline-none after:absolute after:-inset-1 after:content-[''] hover:underline hover:underline-offset-2 focus-visible:ring-2 focus-visible:ring-ring\"\n                  onClick={() => onOpen(signal.dealId)}\n                  tabIndex={resolving ? -1 : undefined}\n                  type=\"button\"\n                >\n                  {shortName(company)}\n                </button>{\" \"}\n                {signal.headline}\n              </p>\n              <p className=\"mt-0.5 text-pretty text-muted-foreground text-xs leading-4\">{signal.detail}</p>\n              {deal ? (\n                <p className=\"mt-1.5 flex items-center gap-1.5 text-muted-foreground text-xs tabular-nums\">\n                  <span className={cn(\"size-1.5 rounded-full\", stageDot[deal.stage])} />\n                  {stageLabel} · {money(deal.value)}\n                </p>\n              ) : null}\n            </div>\n          </div>\n          <div aria-hidden={resolving ? true : undefined} className=\"mt-2.5 flex flex-wrap gap-1.5\">\n            <Button\n              aria-label={`Email ${signal.contact}`}\n              disabled={Boolean(resolving)}\n              onClick={() => onAct(signal, \"email\")}\n              size=\"xs\"\n              variant=\"outline\"\n            >\n              <MailIcon />\n              Email\n            </Button>\n            <Button\n              aria-label={`Log call with ${signal.contact}`}\n              disabled={Boolean(resolving)}\n              onClick={() => onAct(signal, \"call\")}\n              size=\"xs\"\n              variant=\"outline\"\n            >\n              <PhoneIcon />\n              Log call\n            </Button>\n            <Button\n              aria-label={`Snooze ${company} until tomorrow`}\n              disabled={Boolean(resolving)}\n              onClick={() => onAct(signal, \"snooze\")}\n              size=\"xs\"\n              variant=\"ghost\"\n            >\n              <Clock3Icon />\n              Snooze\n            </Button>\n          </div>\n          <AnimatePresence>\n            {resolving ? (\n              <motion.div\n                animate={{ opacity: 1 }}\n                className=\"absolute inset-0 flex items-center gap-3 rounded-[inherit] bg-card px-3\"\n                initial={{ opacity: 0 }}\n                transition={{ duration: 0.16, ease }}\n              >\n                <motion.span\n                  animate={{ scale: 1 }}\n                  className={cn(\n                    \"flex size-7 shrink-0 items-center justify-center rounded-full\",\n                    resolving === \"snooze\"\n                      ? \"bg-muted text-muted-foreground\"\n                      : \"bg-emerald-500/14 text-emerald-700 dark:bg-emerald-400/16 dark:text-emerald-300\",\n                  )}\n                  initial={{ scale: 0.7 }}\n                  transition={{ type: \"spring\", stiffness: 520, damping: 20 }}\n                >\n                  {resolving === \"snooze\" ? <Clock3Icon className=\"size-3.5\" /> : <CheckIcon className=\"size-3.5\" />}\n                </motion.span>\n                <span className=\"flex min-w-0 flex-col gap-0.5\">\n                  <span className=\"text-pretty font-medium leading-5\">{outcome}</span>\n                  <span className=\"text-pretty text-muted-foreground text-xs\">\n                    {resolving === \"snooze\" ? `${company} is back in Focus at 9:00` : `${company} · touched just now`}\n                  </span>\n                </span>\n              </motion.div>\n            ) : null}\n          </AnimatePresence>\n        </div>\n      </div>\n    </motion.li>\n  );\n}\n\nfunction DetailPanel({\n  deal,\n  owner,\n  ownerIndex,\n  stages,\n  onClose,\n  onMove,\n  panelRef,\n  headingId,\n}: {\n  deal: Deal;\n  owner?: DealOwner;\n  ownerIndex: number;\n  stages: PipelineStage[];\n  onClose: () => void;\n  onMove: (stage: DealStage) => void;\n  panelRef: RefObject<HTMLDivElement | null>;\n  headingId: string;\n}) {\n  const at = stages.findIndex((s) => s.id === deal.stage);\n  const stage = stages[at];\n  const next = stages[at + 1];\n  const champion = deal.contacts.find((c) => c.tag?.tone === \"good\") ?? deal.contacts[0];\n\n  return (\n    <div\n      aria-labelledby={headingId}\n      className=\"flex h-full min-h-0 flex-col outline-none\"\n      onKeyDown={(e) => {\n        if (e.key === \"Escape\") {\n          e.stopPropagation();\n          onClose();\n        }\n      }}\n      ref={panelRef}\n      role=\"region\"\n      tabIndex={-1}\n    >\n      <div className=\"flex items-start gap-3 px-4 pt-4 pb-3\">\n        <Monogram className=\"size-9 rounded-lg text-xs\" name={deal.company} />\n        <div className=\"flex min-w-0 flex-1 flex-col\">\n          <h2 className=\"truncate font-heading font-semibold text-base\" id={headingId}>\n            {deal.company}\n          </h2>\n          <span className=\"truncate text-muted-foreground text-xs\">{deal.domain}</span>\n        </div>\n        <Button aria-label=\"Close details\" className=\"-me-1.5 -mt-1\" onClick={onClose} size=\"icon-sm\" variant=\"ghost\">\n          <XIcon />\n        </Button>\n      </div>\n      <div className=\"min-h-0 flex-1 overflow-y-auto px-4 pb-4\">\n        <dl className=\"grid grid-cols-2 gap-x-3 gap-y-3 rounded-xl border p-3 text-xs\">\n          <div className=\"flex flex-col gap-1\">\n            <dt className=\"text-muted-foreground\">Value</dt>\n            <dd className=\"font-medium text-sm tabular-nums\">{money(deal.value)}</dd>\n          </div>\n          <div className=\"flex flex-col items-start gap-1\">\n            <dt className=\"text-muted-foreground\">Stage</dt>\n            <dd>\n              <Menu>\n                <MenuTrigger\n                  aria-label={`Stage: ${stage?.label}. Change stage`}\n                  className=\"-mx-1.5 -my-0.5 flex h-6 cursor-pointer items-center gap-1.5 rounded-md px-1.5 font-medium text-sm outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring data-popup-open:bg-accent\"\n                >\n                  <span className={cn(\"size-1.5 rounded-full\", stageDot[deal.stage])} />\n                  {stage?.label}\n                  <ChevronDownIcon className=\"size-3.5 text-muted-foreground\" />\n                </MenuTrigger>\n                <MenuPopup\n                  align=\"start\"\n                  className=\"w-44 transition-[opacity,scale] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] data-ending-style:scale-95 data-starting-style:scale-95 data-ending-style:opacity-0 data-starting-style:opacity-0\"\n                >\n                  <MenuRadioGroup onValueChange={(v) => onMove(v as DealStage)} value={deal.stage}>\n                    {stages.map((s) => (\n                      <MenuRadioItem key={s.id} value={s.id}>\n                        <span className=\"flex w-full items-center gap-2\">\n                          <span className={cn(\"size-1.5 rounded-full\", stageDot[s.id])} />\n                          <span className=\"flex-1\">{s.label}</span>\n                          <span className=\"font-mono text-muted-foreground text-xs\">{Math.round(s.probability * 100)}%</span>\n                        </span>\n                      </MenuRadioItem>\n                    ))}\n                  </MenuRadioGroup>\n                </MenuPopup>\n              </Menu>\n            </dd>\n          </div>\n          <div className=\"flex flex-col gap-1\">\n            <dt className=\"text-muted-foreground\">Owner</dt>\n            <dd className=\"flex min-w-0 items-center gap-1.5\">\n              <OwnerAvatar index={ownerIndex} owner={owner} />\n              <span className=\"truncate font-medium text-sm\">{owner?.name.split(\" \")[0]}</span>\n            </dd>\n          </div>\n          <div className=\"flex flex-col gap-1\">\n            <dt className=\"text-muted-foreground\">{deal.stage === \"won\" ? \"Closed\" : \"Close date\"}</dt>\n            <dd className=\"font-medium text-sm tabular-nums\">{deal.closeLabel}</dd>\n          </div>\n        </dl>\n\n        <section className=\"mt-5\">\n          <h3 className=\"font-medium text-muted-foreground text-xs\">Next step</h3>\n          <p className=\"mt-1.5 flex gap-2 text-pretty\">\n            <ArrowRightIcon className=\"mt-0.5 size-4 shrink-0 text-muted-foreground\" />\n            {deal.nextStep}\n          </p>\n        </section>\n\n        <section className=\"mt-5\">\n          <h3 className=\"font-medium text-muted-foreground text-xs\">Contacts</h3>\n          <ul className=\"mt-2 flex flex-col gap-2.5\">\n            {deal.contacts.map((c, i) => (\n              <li className=\"flex items-center gap-2.5\" key={c.name}>\n                <Avatar className=\"[--avatar-size:--spacing(7)]\">\n                  <AvatarFallback className={cn(\"font-semibold text-[10px]\", ownerTones[(i + 2) % ownerTones.length])}>\n                    {initials(c.name)}\n                  </AvatarFallback>\n                </Avatar>\n                <span className=\"flex min-w-0 flex-1 flex-col\">\n                  <span className={cn(\"truncate font-medium\", c.tag?.tone === \"bad\" && \"text-muted-foreground line-through decoration-foreground/30\")}>\n                    {c.name}\n                  </span>\n                  <span className=\"truncate text-muted-foreground text-xs\">{c.role}</span>\n                </span>\n                {c.tag ? (\n                  <span\n                    className={cn(\n                      \"shrink-0 rounded-full px-2 py-0.5 font-medium text-[11px]\",\n                      c.tag.tone === \"good\" && \"bg-emerald-500/12 text-emerald-700 dark:bg-emerald-400/14 dark:text-emerald-300\",\n                      c.tag.tone === \"bad\" && \"bg-rose-500/12 text-rose-700 dark:bg-rose-400/14 dark:text-rose-300\",\n                      c.tag.tone === \"neutral\" && \"bg-muted text-muted-foreground\",\n                    )}\n                  >\n                    {c.tag.label}\n                  </span>\n                ) : null}\n              </li>\n            ))}\n          </ul>\n        </section>\n\n        <section className=\"mt-5\">\n          <h3 className=\"font-medium text-muted-foreground text-xs\">Last touches</h3>\n          <ol className=\"mt-2 flex flex-col\">\n            {deal.activity.slice(0, 3).map((a, i, list) => (\n              <li className=\"relative flex gap-3 pb-3 last:pb-0\" key={`${a.label}-${a.when}`}>\n                {i < list.length - 1 ? <span aria-hidden className=\"absolute top-3 bottom-0 left-[3px] w-px bg-border\" /> : null}\n                <span\n                  aria-hidden\n                  className={cn(\"mt-1.5 size-[7px] shrink-0 rounded-full\", i === 0 ? \"bg-foreground/70\" : \"bg-foreground/20\")}\n                />\n                <span className=\"flex min-w-0 flex-col\">\n                  <span className=\"text-pretty\">{a.label}</span>\n                  <span className=\"text-muted-foreground text-xs\">{a.when}</span>\n                </span>\n              </li>\n            ))}\n          </ol>\n        </section>\n\n        {deal.note ? (\n          <section className=\"mt-5\">\n            <h3 className=\"font-medium text-muted-foreground text-xs\">Notes</h3>\n            <p className=\"mt-1.5 text-pretty rounded-xl bg-muted/60 p-3 text-sm dark:bg-muted/40\">{deal.note}</p>\n          </section>\n        ) : null}\n      </div>\n      <div className=\"flex gap-2 border-t p-3\">\n        {next ? (\n          <Button className=\"flex-1\" onClick={() => onMove(next.id)} variant={next.id === \"won\" ? \"default\" : \"outline\"}>\n            {next.id === \"won\" ? <CheckIcon /> : <ArrowRightIcon />}\n            {next.id === \"won\" ? \"Mark as won\" : `Move to ${next.label}`}\n          </Button>\n        ) : (\n          <span className=\"flex h-8 flex-1 items-center gap-2 font-medium text-emerald-700 dark:text-emerald-300\">\n            <CircleCheckIcon className=\"size-4\" />\n            Closed won\n          </span>\n        )}\n        {champion ? (\n          <Button aria-label={`Email ${champion.name}`} size=\"icon\" variant=\"outline\">\n            <MailIcon />\n          </Button>\n        ) : null}\n      </div>\n    </div>\n  );\n}\n\ntype DragState = { id: string; width: number; height: number; origin: DealStage; pointerId: number };\ntype Lifted = { id: string; snapshot: Deal[] };\n\nexport function PipelineToday({\n  deals: initialDeals = defaultDeals,\n  signals = defaultSignals,\n  owners = defaultOwners,\n  stages = defaultStages,\n  currentUserId = \"maren\",\n  workspace = \"Kestrel\",\n  dateLabel = \"Tuesday, 27 October\",\n  greeting = \"Good morning\",\n  target = 480000,\n  forecastLabel = \"Q4 weighted forecast\",\n  onDealMove,\n  className,\n}: PipelineTodayProps) {\n  const reduce = useCalmMotion();\n  const uid = useId();\n  const [deals, setDeals] = useState(initialDeals);\n  const [drag, setDrag] = useState<DragState | null>(null);\n  const [over, setOver] = useState<{ stage: DealStage; index: number } | null>(null);\n  const [lifted, setLifted] = useState<Lifted | null>(null);\n  const [selectedId, setSelectedId] = useState<string | null>(null);\n  const [mobileStage, setMobileStage] = useState<DealStage>(\"negotiation\");\n  const [tab, setTab] = useState<\"board\" | \"focus\">(\"board\");\n  const [handled, setHandled] = useState<string[]>([]);\n  const [snoozed, setSnoozed] = useState<string[]>([]);\n  const [resolving, setResolving] = useState<Record<string, FocusAction>>({});\n  const [celebrate, setCelebrate] = useState<{ id: string; key: number } | null>(null);\n  const [touched, setTouched] = useState<{ id: string; key: number } | null>(null);\n  const [delta, setDelta] = useState<{ amount: number; key: number } | null>(null);\n  const [announcement, setAnnouncement] = useState(\"\");\n  const [hinted, setHinted] = useState<string | null>(null);\n\n  const rootRef = useRef<HTMLDivElement>(null);\n  const railRef = useRef<HTMLDivElement>(null);\n  const panelRef = useRef<HTMLDivElement>(null);\n  const chipsRef = useRef<HTMLDivElement>(null);\n  const rects = useRef(new Map<string, Rect>());\n  const pending = useRef<{ id: string; pointerId: number; x: number; y: number; el: HTMLElement } | null>(null);\n  const dragRef = useRef<DragState | null>(null);\n  const overRef = useRef<{ stage: DealStage; index: number } | null>(null);\n  const grabOffset = useRef({ x: 0, y: 0 });\n  const lastPointerX = useRef(0);\n  const pendingFocus = useRef<string | null>(null);\n  const timers = useRef(new Set<ReturnType<typeof setTimeout>>());\n  const counter = useRef(0);\n\n  const dragX = useMotionValue(0);\n  const dragY = useMotionValue(0);\n  const tiltTarget = useMotionValue(0);\n  const tilt = useSpring(tiltTarget, { stiffness: 260, damping: 22 });\n\n  const ids = { instructions: `${uid}-how`, detail: `${uid}-detail`, heading: `${uid}-heading`, rail: `${uid}-rail` };\n  const order = stages.map((s) => s.id);\n  const stageOf = (id: DealStage) => stages.find((s) => s.id === id) ?? stages[0];\n  const prob = (id: DealStage) => stageOf(id).probability;\n  const forecast = (list: Deal[]) => list.reduce((sum, d) => sum + d.value * prob(d.stage), 0);\n  const ownerIndex = (id: string) => Math.max(0, owners.findIndex((o) => o.id === id));\n  const ownerOf = (id: string) => owners.find((o) => o.id === id);\n  const me = ownerOf(currentUserId);\n  const getScale = () => (rootRef.current ? scaleOf(rootRef.current) : 1);\n\n  const view = drag && over ? moveDeal(deals, drag.id, over.stage, over.index) : deals;\n  const columns = Object.fromEntries(order.map((s) => [s, view.filter((d) => d.stage === s)])) as Record<DealStage, Deal[]>;\n  const total = forecast(view);\n  const won = view.filter((d) => d.stage === \"won\").reduce((sum, d) => sum + d.value, 0);\n\n  const visibleSignals = signals.filter((s) => !handled.includes(s.id) && !snoozed.includes(s.id));\n  const openSignals = visibleSignals.filter((s) => !resolving[s.id]);\n  const flagFor = (dealId: string) => openSignals.find((s) => s.dealId === dealId);\n  const selected = deals.find((d) => d.id === selectedId) ?? null;\n\n  const later = (fn: () => void, ms: number) => {\n    const t = setTimeout(() => {\n      timers.current.delete(t);\n      fn();\n    }, ms);\n    timers.current.add(t);\n  };\n\n  useEffect(() => {\n    const all = timers.current;\n    return () => {\n      for (const t of all) clearTimeout(t);\n      all.clear();\n    };\n  }, []);\n\n  useEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n    const observer = new ResizeObserver(() => rects.current.clear());\n    observer.observe(root);\n    return () => observer.disconnect();\n  }, []);\n\n  useLayoutEffect(() => {\n    const id = pendingFocus.current;\n    if (!id) return;\n    const el = [...(rootRef.current?.querySelectorAll<HTMLElement>(`[data-card-id=\"${id}\"]`) ?? [])].find(\n      (node) => node.offsetParent !== null,\n    );\n    if (el) {\n      el.focus({ preventScroll: false });\n      pendingFocus.current = null;\n    }\n  });\n\n  useEffect(() => {\n    if (selectedId) panelRef.current?.focus({ preventScroll: true });\n  }, [selectedId]);\n\n  useEffect(() => {\n    const row = chipsRef.current;\n    const chip = row?.querySelector<HTMLElement>(`[data-drop-stage=\"${mobileStage}\"]`);\n    if (!row || !chip || row.scrollWidth <= row.clientWidth) return;\n    const left = chip.offsetLeft - (row.clientWidth - chip.offsetWidth) / 2;\n    row.scrollTo({ left: Math.max(0, left), behavior: reduce ? \"auto\" : \"smooth\" });\n  }, [mobileStage, reduce]);\n\n  const say = (text: string) => setAnnouncement((prev) => (prev === text ? `${text} ` : text));\n  const nextKey = () => {\n    counter.current += 1;\n    return counter.current;\n  };\n\n  const settle = (before: Deal[], after: Deal[], id: string) => {\n    const was = before.find((d) => d.id === id);\n    const now = after.find((d) => d.id === id);\n    if (!was || !now) return;\n    const index = after.filter((d) => d.stage === now.stage).findIndex((d) => d.id === id);\n    const diff = forecast(after) - forecast(before);\n    setMobileStage(now.stage);\n    if (was.stage === now.stage) {\n      say(`${now.company} stays in ${stageOf(now.stage).label}, position ${index + 1}.`);\n      return;\n    }\n    if (Math.round(diff) !== 0) {\n      const key = nextKey();\n      setDelta({ amount: diff, key });\n      later(() => setDelta((d) => (d?.key === key ? null : d)), 2600);\n    }\n    if (now.stage === \"won\") {\n      const stale = signals.filter((s) => s.dealId === id).map((s) => s.id);\n      if (stale.length) setHandled((h) => [...h, ...stale.filter((s) => !h.includes(s))]);\n      const key = nextKey();\n      setCelebrate({ id, key });\n      later(() => setCelebrate((c) => (c?.key === key ? null : c)), 1500);\n    }\n    say(\n      `${now.company} moved to ${stageOf(now.stage).label}${now.stage === \"won\" ? \", closed won\" : \"\"}. Forecast now ${money(forecast(after))}.`,\n    );\n    onDealMove?.(id, now.stage, index);\n  };\n\n  const commit = (id: string, stage: DealStage, index: number, base: Deal[] = deals) => {\n    const original = base.find((d) => d.id === id);\n    if (!original) return;\n    const patch: Partial<Deal> =\n      original.stage === stage ? {} : stage === \"won\" ? { closeLabel: \"Today\", lastTouch: \"Just now\" } : {};\n    const after = moveDeal(base, id, stage, index, patch);\n    setDeals(after);\n    settle(base, after, id);\n  };\n\n  const moveFromPanel = (id: string, stage: DealStage) => {\n    const len = deals.filter((d) => d.stage === stage && d.id !== id).length;\n    commit(id, stage, len);\n  };\n\n  const endDrag = (dropped: boolean) => {\n    const d = dragRef.current;\n    const root = rootRef.current;\n    if (!d || !root) return;\n    const s = scaleOf(root);\n    const box = root.getBoundingClientRect();\n    rects.current.set(d.id, {\n      left: box.left + dragX.get() * s,\n      top: box.top + dragY.get() * s,\n      width: d.width * s,\n      rotate: tilt.get(),\n      scale: 1.03,\n    });\n    const target = overRef.current;\n    for (const key of [...rects.current.keys()]) if (key.startsWith(\"ph-\")) rects.current.delete(key);\n    dragRef.current = null;\n    overRef.current = null;\n    tiltTarget.jump(0);\n    tilt.jump(0);\n    setDrag(null);\n    setOver(null);\n    pendingFocus.current = d.id;\n    if (root.hasPointerCapture(d.pointerId)) root.releasePointerCapture(d.pointerId);\n    if (dropped && target) {\n      commit(d.id, target.stage, target.index);\n    } else {\n      const deal = deals.find((x) => x.id === d.id);\n      if (deal) say(`Move cancelled. ${deal.company} is back in ${stageOf(deal.stage).label}.`);\n    }\n  };\n\n  const startDrag = (e: PointerEvent<HTMLElement>, p: NonNullable<typeof pending.current>) => {\n    const root = rootRef.current;\n    const deal = deals.find((d) => d.id === p.id);\n    if (!root || !deal) return;\n    const s = scaleOf(root);\n    const rootBox = root.getBoundingClientRect();\n    const box = p.el.getBoundingClientRect();\n    grabOffset.current = { x: (p.x - box.left) / s, y: (p.y - box.top) / s };\n    dragX.jump((e.clientX - rootBox.left) / s - grabOffset.current.x);\n    dragY.jump((e.clientY - rootBox.top) / s - grabOffset.current.y);\n    lastPointerX.current = e.clientX;\n    const column = deals.filter((d) => d.stage === deal.stage);\n    const state: DragState = { id: deal.id, width: box.width / s, height: box.height / s, origin: deal.stage, pointerId: p.pointerId };\n    const start = { stage: deal.stage, index: column.findIndex((d) => d.id === deal.id) };\n    dragRef.current = state;\n    overRef.current = start;\n    pending.current = null;\n    root.setPointerCapture(p.pointerId);\n    root.focus({ preventScroll: true });\n    setDrag(state);\n    setOver(start);\n    say(`Picked up ${deal.company}. Drop it on a stage, or press Escape to cancel.`);\n  };\n\n  const onRootPointerMove = (e: PointerEvent<HTMLDivElement>) => {\n    const d = dragRef.current;\n    const root = rootRef.current;\n    if (!d || !root || e.pointerId !== d.pointerId) return;\n    const s = scaleOf(root);\n    const box = root.getBoundingClientRect();\n    dragX.set((e.clientX - box.left) / s - grabOffset.current.x);\n    dragY.set((e.clientY - box.top) / s - grabOffset.current.y);\n    if (!reduce) tiltTarget.set(Math.max(-5, Math.min(5, (e.clientX - lastPointerX.current) * 0.5)));\n    lastPointerX.current = e.clientX;\n    const zone = document.elementFromPoint(e.clientX, e.clientY)?.closest<HTMLElement>(\"[data-drop-stage]\");\n    if (!zone || !root.contains(zone)) return;\n    const stage = zone.dataset.dropStage as DealStage;\n    let index = deals.filter((x) => x.stage === stage && x.id !== d.id).length;\n    if (zone.dataset.dropKind !== \"chip\") {\n      const cards = [...zone.querySelectorAll<HTMLElement>(\"[data-card-id]\")].filter((el) => el.dataset.cardId !== d.id);\n      index = cards.filter((el) => {\n        const r = el.getBoundingClientRect();\n        return r.top + r.height / 2 < e.clientY;\n      }).length;\n    }\n    const prev = overRef.current;\n    if (prev?.stage === stage && prev.index === index) return;\n    overRef.current = { stage, index };\n    setOver({ stage, index });\n  };\n\n  const onRootPointerUp = (e: PointerEvent<HTMLDivElement>) => {\n    const d = dragRef.current;\n    const root = rootRef.current;\n    if (!d || !root || e.pointerId !== d.pointerId) return;\n    const box = root.getBoundingClientRect();\n    const inside = e.clientX >= box.left && e.clientX <= box.right && e.clientY >= box.top && e.clientY <= box.bottom;\n    endDrag(inside);\n  };\n\n  const dropLifted = () => {\n    if (!lifted) return;\n    const origin = lifted.snapshot.find((d) => d.id === lifted.id);\n    const current = deals.find((d) => d.id === lifted.id);\n    setLifted(null);\n    if (!origin || !current) return;\n    const index = deals.filter((d) => d.stage === current.stage).findIndex((d) => d.id === current.id);\n    const restored = origin.stage === current.stage ? origin : current;\n    const base = lifted.snapshot;\n    const after = moveDeal(base, current.id, current.stage, index, {\n      daysInStage: restored.daysInStage,\n      ...(origin.stage !== current.stage && current.stage === \"won\" ? { closeLabel: \"Today\", lastTouch: \"Just now\" } : {}),\n    });\n    setDeals(after);\n    settle(base, after, current.id);\n  };\n\n  const cancelLifted = () => {\n    if (!lifted) return;\n    const deal = lifted.snapshot.find((d) => d.id === lifted.id);\n    setDeals(lifted.snapshot);\n    setLifted(null);\n    pendingFocus.current = lifted.id;\n    if (deal) {\n      setMobileStage(deal.stage);\n      say(`Move cancelled. ${deal.company} is back in ${stageOf(deal.stage).label}.`);\n    }\n  };\n\n  const liveMove = (deal: Deal, stage: DealStage, index: number) => {\n    const after = moveDeal(deals, deal.id, stage, index);\n    const column = after.filter((d) => d.stage === stage);\n    setDeals(after);\n    setMobileStage(stage);\n    pendingFocus.current = deal.id;\n    say(`${stageOf(stage).label}, position ${column.findIndex((d) => d.id === deal.id) + 1} of ${column.length}.`);\n  };\n\n  const focusCard = (id: string, stage: DealStage) => {\n    setMobileStage(stage);\n    pendingFocus.current = id;\n    const el = [...(rootRef.current?.querySelectorAll<HTMLElement>(`[data-card-id=\"${id}\"]`) ?? [])].find(\n      (node) => node.offsetParent !== null,\n    );\n    if (el) {\n      el.focus();\n      pendingFocus.current = null;\n    }\n  };\n\n  const openDeal = (id: string) => {\n    setSelectedId((cur) => (cur === id ? null : id));\n  };\n\n  const closeDetail = () => {\n    if (selectedId) pendingFocus.current = selectedId;\n    setSelectedId(null);\n  };\n\n  const onCardKeyDown = (e: KeyboardEvent<HTMLDivElement>, deal: Deal) => {\n    if (dragRef.current) return;\n    const column = deals.filter((d) => d.stage === deal.stage);\n    const idx = column.findIndex((d) => d.id === deal.id);\n    const at = order.indexOf(deal.stage);\n\n    if (lifted?.id === deal.id) {\n      if (e.key === \"ArrowLeft\" || e.key === \"ArrowRight\") {\n        e.preventDefault();\n        const to = order[at + (e.key === \"ArrowLeft\" ? -1 : 1)];\n        if (!to) return;\n        liveMove(deal, to, Math.min(idx, deals.filter((d) => d.stage === to).length));\n      } else if (e.key === \"ArrowUp\" || e.key === \"ArrowDown\") {\n        e.preventDefault();\n        const to = idx + (e.key === \"ArrowUp\" ? -1 : 1);\n        if (to < 0 || to >= column.length) return;\n        liveMove(deal, deal.stage, to);\n      } else if (e.key === \" \" || e.key === \"Enter\") {\n        e.preventDefault();\n        pendingFocus.current = deal.id;\n        dropLifted();\n      } else if (e.key === \"Escape\") {\n        e.preventDefault();\n        e.stopPropagation();\n        cancelLifted();\n      } else if (e.key === \"Tab\") {\n        dropLifted();\n      }\n      return;\n    }\n\n    if (e.key === \" \") {\n      e.preventDefault();\n      setLifted({ id: deal.id, snapshot: deals });\n      say(\n        `Picked up ${deal.company} in ${stageOf(deal.stage).label}. Left and right arrows change stage, up and down reorder, Space drops, Escape cancels.`,\n      );\n    } else if (e.key === \"Enter\") {\n      e.preventDefault();\n      openDeal(deal.id);\n    } else if (e.key === \"ArrowUp\" || e.key === \"ArrowDown\") {\n      e.preventDefault();\n      const to = column[idx + (e.key === \"ArrowUp\" ? -1 : 1)];\n      if (to) focusCard(to.id, to.stage);\n    } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowRight\") {\n      e.preventDefault();\n      const step = e.key === \"ArrowLeft\" ? -1 : 1;\n      for (let i = at + step; i >= 0 && i < order.length; i += step) {\n        const list = deals.filter((d) => d.stage === order[i]);\n        if (list.length) {\n          const to = list[Math.min(idx, list.length - 1)];\n          focusCard(to.id, to.stage);\n          break;\n        }\n      }\n    }\n  };\n\n  const act = (signal: FocusSignal, action: FocusAction) => {\n    if (resolving[signal.id]) return;\n    const deal = deals.find((d) => d.id === signal.dealId);\n    setResolving((r) => ({ ...r, [signal.id]: action }));\n    railRef.current?.focus({ preventScroll: true });\n    if (action !== \"snooze\") {\n      setDeals((all) =>\n        all.map((d) =>\n          d.id === signal.dealId\n            ? {\n                ...d,\n                engagement: warmer[d.engagement],\n                lastTouch: \"Just now\",\n                activity: [\n                  {\n                    label: action === \"email\" ? `You emailed ${signal.contact}` : `You logged a call with ${signal.contact}`,\n                    when: \"Just now\",\n                  },\n                  ...d.activity,\n                ],\n              }\n            : d,\n        ),\n      );\n      setTouched({ id: signal.dealId, key: nextKey() });\n    }\n    const left = openSignals.length - 1;\n    say(\n      `${deal?.company ?? \"\"}: ${action === \"email\" ? `follow-up sent to ${signal.contact}` : action === \"call\" ? `call with ${signal.contact} logged` : \"snoozed until tomorrow\"}. ${left === 0 ? \"Focus is clear.\" : `${left} left in Focus.`}`,\n    );\n    later(\n      () => {\n        setResolving((r) => {\n          const { [signal.id]: _, ...rest } = r;\n          return rest;\n        });\n        if (action === \"snooze\") setSnoozed((l) => [...l, signal.id]);\n        else setHandled((l) => [...l, signal.id]);\n      },\n      reduce ? 800 : 1150,\n    );\n  };\n\n  const firstName = me?.name.split(\" \")[0] ?? \"\";\n  const progress = Math.round((total / target) * 100);\n\n  const navItems: { label: string; icon: LucideIcon; current?: boolean; badge?: boolean }[] = [\n    { label: \"Today\", icon: SunriseIcon, current: true },\n    { label: \"Pipeline\", icon: KanbanIcon },\n    { label: \"Accounts\", icon: Building2Icon },\n    { label: \"Inbox\", icon: InboxIcon, badge: true },\n    { label: \"Reports\", icon: ChartNoAxesColumnIcon },\n  ];\n\n  const workspaceMenu = (trigger: ReactElement) => (\n    <Menu>\n      <MenuTrigger render={trigger} />\n      <MenuPopup\n        align=\"start\"\n        className=\"w-56 transition-[opacity,scale] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] data-ending-style:scale-95 data-starting-style:scale-95 data-ending-style:opacity-0 data-starting-style:opacity-0\"\n        side=\"bottom\"\n      >\n        <MenuGroup>\n          <MenuGroupLabel>{workspace}</MenuGroupLabel>\n          <MenuRadioGroup defaultValue=\"sales\">\n            <MenuRadioItem value=\"sales\">Sales pipeline</MenuRadioItem>\n            <MenuRadioItem value=\"renewals\">Renewals</MenuRadioItem>\n            <MenuRadioItem value=\"partners\">Partnerships</MenuRadioItem>\n          </MenuRadioGroup>\n        </MenuGroup>\n        <MenuSeparator />\n        <MenuItem>\n          <SettingsIcon />\n          Workspace settings\n        </MenuItem>\n      </MenuPopup>\n    </Menu>\n  );\n\n  const lane = (stage: PipelineStage) => {\n    const list = columns[stage.id];\n    const weighted = list.reduce((sum, d) => sum + d.value * stage.probability, 0);\n    const isOver = drag !== null && over?.stage === stage.id;\n    const isWon = stage.id === \"won\";\n    return (\n      <section\n        aria-label={`${stage.label}: ${list.length} ${list.length === 1 ? \"deal\" : \"deals\"}, ${shortMoney(weighted)} ${isWon ? \"closed\" : \"weighted\"}`}\n        className={cn(\n          \"flex min-h-0 min-w-0 flex-col rounded-2xl bg-muted/50 p-1 transition-colors duration-150 dark:bg-muted/30\",\n          isOver && (isWon ? \"bg-emerald-500/10 dark:bg-emerald-400/10\" : \"bg-accent dark:bg-accent/70\"),\n          stage.id !== mobileStage && \"hidden @5xl:flex\",\n        )}\n        data-drop-stage={stage.id}\n        key={stage.id}\n      >\n        <header aria-hidden className=\"flex items-start justify-between gap-2 px-2 pt-1.5 pb-2.5\">\n          <div className=\"flex min-w-0 flex-col gap-0.5\">\n            <span className=\"flex items-center gap-1.5 font-medium\">\n              <span className={cn(\"size-1.5 shrink-0 rounded-full\", stageDot[stage.id])} />\n              <span className=\"truncate\">{stage.label}</span>\n              <span className=\"text-muted-foreground text-xs tabular-nums\">{list.length}</span>\n            </span>\n            <span className=\"text-muted-foreground text-xs\">\n              <span className={cn(\"font-medium\", isWon ? \"text-emerald-700 dark:text-emerald-300\" : \"text-foreground/80\")}>\n                <Rolling format={shortMoney} reduce={reduce} value={weighted} />\n              </span>{\" \"}\n              {isWon ? \"closed\" : \"weighted\"}\n            </span>\n          </div>\n          {isWon ? (\n            <CheckIcon className=\"mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400\" />\n          ) : (\n            <span className=\"mt-0.5 shrink-0 font-mono text-[11px] text-muted-foreground tabular-nums\">\n              {Math.round(stage.probability * 100)}%\n            </span>\n          )}\n        </header>\n        <ul className=\"-m-1 flex min-h-0 flex-1 flex-col gap-1.5 overflow-y-auto p-1 [scrollbar-width:thin]\">\n          {list.map((deal) => {\n            if (drag?.id === deal.id) {\n              return (\n                <FlipSlot flipKey={`ph-${stage.id}`} getScale={getScale} key={`ph-${stage.id}`} reduce={reduce} rects={rects}>\n                  <div\n                    aria-hidden\n                    className=\"rounded-xl border border-foreground/15 border-dashed bg-background/60 dark:bg-background/30\"\n                    data-placeholder\n                    style={{ height: drag.height }}\n                  />\n                </FlipSlot>\n              );\n            }\n            const isLifted = lifted?.id === deal.id;\n            const isSelected = selectedId === deal.id;\n            const flag = flagFor(deal.id);\n            const owner = ownerOf(deal.ownerId);\n            const engagement = engagementMeta[deal.engagement].label.toLowerCase();\n            return (\n              <FlipSlot flipKey={deal.id} getScale={getScale} key={deal.id} reduce={reduce} rects={rects}>\n                <div\n                  aria-controls={isSelected ? ids.detail : undefined}\n                  aria-describedby={ids.instructions}\n                  aria-expanded={isSelected}\n                  aria-label={`${deal.company}, ${money(deal.value)}, ${stage.label}, ${\n                    deal.stage === \"won\"\n                      ? `closed ${deal.closeLabel}`\n                      : `${deal.daysInStage === 0 ? \"just moved here\" : `${deal.daysInStage} days in stage`}, ${engagement}`\n                  }, owner ${owner?.name ?? \"unassigned\"}${flag ? `, ${flag.tag}` : \"\"}`}\n                  aria-roledescription=\"draggable deal\"\n                  className={cn(\n                    \"group/card block cursor-grab touch-pan-y select-none rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background active:cursor-grabbing\",\n                  )}\n                  data-card-id={deal.id}\n                  onClick={() => openDeal(deal.id)}\n                  onKeyDown={(e) => onCardKeyDown(e, deal)}\n                  onPointerCancel={() => {\n                    pending.current = null;\n                  }}\n                  onPointerDown={(e) => {\n                    if (e.button !== 0 || e.pointerType === \"touch\") return;\n                    pending.current = { id: deal.id, pointerId: e.pointerId, x: e.clientX, y: e.clientY, el: e.currentTarget };\n                  }}\n                  onPointerMove={(e) => {\n                    const p = pending.current;\n                    if (!p || dragRef.current || p.pointerId !== e.pointerId) return;\n                    if (Math.hypot(e.clientX - p.x, e.clientY - p.y) < 5) return;\n                    startDrag(e, p);\n                  }}\n                  onPointerUp={() => {\n                    pending.current = null;\n                  }}\n                  role=\"button\"\n                  tabIndex={0}\n                >\n                  <motion.div\n                    animate={{ scale: isLifted && !reduce ? 1.03 : 1, rotate: isLifted && !reduce ? -1.2 : 0 }}\n                    transition={{ type: \"spring\", stiffness: 520, damping: 32 }}\n                  >\n                    <DealFace\n                      celebrate={celebrate?.id === deal.id ? celebrate.key : undefined}\n                      className={cn(\n                        \"[@media(hover:hover)]:group-hover/card:border-foreground/20\",\n                        hinted === deal.id && \"border-foreground/25 bg-accent/40\",\n                        isSelected && \"border-foreground/35 ring-1 ring-foreground/10\",\n                        isLifted && \"border-foreground/30 shadow-lg/10\",\n                      )}\n                      deal={deal}\n                      flag={flag}\n                      owner={owner}\n                      ownerIndex={ownerIndex(deal.ownerId)}\n                      reduce={reduce}\n                      touched={touched?.id === deal.id ? touched.key : undefined}\n                    />\n                  </motion.div>\n                </div>\n              </FlipSlot>\n            );\n          })}\n          {list.length === 0 ? (\n            <li\n              aria-hidden\n              className=\"flex h-20 items-center justify-center rounded-xl border border-foreground/10 border-dashed text-muted-foreground text-xs\"\n            >\n              Drop a deal here\n            </li>\n          ) : null}\n        </ul>\n      </section>\n    );\n  };\n\n  const draggedDeal = drag ? deals.find((d) => d.id === drag.id) : undefined;\n\n  const focusRail = (\n    <div\n      aria-labelledby={ids.rail}\n      className=\"flex h-full min-h-0 flex-col outline-none\"\n      ref={railRef}\n      role=\"region\"\n      tabIndex={-1}\n    >\n      <div className=\"flex items-baseline justify-between gap-3 px-4 pt-4 pb-3\">\n        <div className=\"flex flex-col\">\n          <h2 className=\"flex items-center gap-2 font-heading font-semibold text-base\" id={ids.rail}>\n            Focus\n            <span className=\"rounded-full bg-muted px-1.5 py-0.5 font-medium font-sans text-muted-foreground text-xs tabular-nums\">\n              {openSignals.length}\n            </span>\n          </h2>\n          <p className=\"text-muted-foreground text-xs\">Who to act on today, and why</p>\n        </div>\n      </div>\n      <div className=\"min-h-0 flex-1 overflow-y-auto px-4 pb-2 [scrollbar-width:thin]\">\n        {visibleSignals.length ? (\n          <ul>\n            <AnimatePresence initial={false}>\n              {visibleSignals.map((s) => {\n                const deal = deals.find((d) => d.id === s.dealId);\n                return (\n                  <SignalItem\n                    deal={deal}\n                    key={s.id}\n                    onAct={act}\n                    onHint={setHinted}\n                    onOpen={(id) => {\n                      setHinted(null);\n                      openDeal(id);\n                    }}\n                    reduce={reduce}\n                    resolving={resolving[s.id]}\n                    signal={s}\n                    stageLabel={deal ? stageOf(deal.stage).label : \"\"}\n                  />\n                );\n              })}\n            </AnimatePresence>\n          </ul>\n        ) : (\n          <motion.div\n            animate={{ opacity: 1 }}\n            className=\"flex flex-col items-center gap-3 rounded-2xl border border-dashed px-5 py-10 text-center\"\n            initial={{ opacity: 0 }}\n            transition={{ duration: 0.25, ease }}\n          >\n            <span className=\"flex size-10 items-center justify-center rounded-full bg-muted text-muted-foreground\">\n              <CoffeeIcon className=\"size-4.5\" />\n            </span>\n            <div className=\"flex flex-col gap-1\">\n              <span className=\"text-balance font-medium\">You're clear for today</span>\n              <span className=\"text-pretty text-muted-foreground text-xs\">\n                {handled.length} handled{snoozed.length ? `, ${snoozed.length} snoozed until tomorrow` : \"\"}. New signals land\n                here as they happen.\n              </span>\n            </div>\n            {snoozed.length ? (\n              <Button onClick={() => setSnoozed([])} size=\"xs\" variant=\"outline\">\n                <Clock3Icon />\n                Bring back snoozed\n              </Button>\n            ) : null}\n          </motion.div>\n        )}\n      </div>\n    </div>\n  );\n\n  return (\n    <MotionConfig reducedMotion={reduce ? \"always\" : \"never\"}>\n      <div\n        className={cn(\n          \"@container relative isolate flex h-[760px] w-full overflow-hidden bg-background text-foreground text-sm outline-none\",\n          className,\n        )}\n        onKeyDown={(e) => {\n          if (e.key === \"Escape\" && dragRef.current) {\n            e.preventDefault();\n            endDrag(false);\n          }\n        }}\n        onLostPointerCapture={() => {\n          if (dragRef.current) endDrag(false);\n        }}\n        onPointerCancel={() => {\n          if (dragRef.current) endDrag(false);\n        }}\n        onPointerDown={(e) => {\n          if (lifted && !(e.target as HTMLElement).closest(`[data-card-id=\"${lifted.id}\"]`)) dropLifted();\n        }}\n        onPointerMove={onRootPointerMove}\n        onScrollCapture={() => {\n          if (!dragRef.current) rects.current.clear();\n        }}\n        onPointerUp={onRootPointerUp}\n        ref={rootRef}\n        tabIndex={-1}\n      >\n        <p className=\"sr-only\" id={ids.instructions}>\n          Press Space to pick up. Arrow keys move the deal between stages and up or down. Space or Enter drops it, Escape\n          cancels. Press Enter to open details.\n        </p>\n        <p aria-live=\"polite\" className=\"sr-only\" role=\"status\">\n          {announcement}\n        </p>\n\n        <TooltipProvider delay={400}>\n          <nav\n            aria-label=\"Main\"\n            className=\"hidden w-14 shrink-0 flex-col items-center gap-1 border-e py-3 @3xl:flex\"\n          >\n            {workspaceMenu(\n              <button\n                aria-label={`Switch workspace, current ${workspace}`}\n                className=\"mb-3 flex size-9 cursor-pointer items-center justify-center rounded-xl bg-primary font-heading font-semibold text-primary-foreground outline-none transition-transform duration-150 ease-out focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background active:scale-[0.97]\"\n                type=\"button\"\n              >\n                {workspace[0]}\n              </button>,\n            )}\n            {navItems.map((n) => (\n              <Tooltip key={n.label}>\n                <TooltipTrigger\n                  render={\n                    <button\n                      aria-current={n.current ? \"page\" : undefined}\n                      aria-label={n.label}\n                      className={cn(\n                        \"relative flex size-9 cursor-pointer items-center justify-center rounded-lg outline-none transition-[color,background-color,scale] duration-150 ease-out focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.97]\",\n                        n.current\n                          ? \"bg-accent text-foreground\"\n                          : \"text-muted-foreground [@media(hover:hover)]:hover:bg-accent [@media(hover:hover)]:hover:text-foreground\",\n                      )}\n                      type=\"button\"\n                    />\n                  }\n                >\n                  <n.icon className=\"size-4.5\" />\n                  {n.badge ? (\n                    <span className=\"absolute top-2 right-2 size-1.5 rounded-full bg-rose-500 ring-2 ring-background dark:bg-rose-400\" />\n                  ) : null}\n                </TooltipTrigger>\n                <TooltipPopup side=\"right\">{n.label}</TooltipPopup>\n              </Tooltip>\n            ))}\n            <div className=\"mt-auto flex flex-col items-center gap-3\">\n              <Tooltip>\n                <TooltipTrigger\n                  render={\n                    <button\n                      aria-label=\"Settings\"\n                      className=\"flex size-9 cursor-pointer items-center justify-center rounded-lg text-muted-foreground outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring [@media(hover:hover)]:hover:bg-accent [@media(hover:hover)]:hover:text-foreground\"\n                      type=\"button\"\n                    />\n                  }\n                >\n                  <SettingsIcon className=\"size-4.5\" />\n                </TooltipTrigger>\n                <TooltipPopup side=\"right\">Settings</TooltipPopup>\n              </Tooltip>\n              <Avatar aria-label={me?.name} role=\"img\" className=\"[--avatar-size:--spacing(7)]\">\n                <AvatarFallback className={cn(\"font-semibold text-[10px]\", ownerTones[ownerIndex(currentUserId) % ownerTones.length])}>\n                  {me ? initials(me.name) : \"?\"}\n                </AvatarFallback>\n              </Avatar>\n            </div>\n          </nav>\n        </TooltipProvider>\n\n        <div className=\"relative flex min-w-0 flex-1 flex-col\">\n          <div className=\"flex h-12 shrink-0 items-center justify-between border-b px-3 @3xl:hidden\">\n            {workspaceMenu(\n              <button\n                aria-label={`Switch workspace, current ${workspace}`}\n                className=\"flex h-9 cursor-pointer items-center gap-2 rounded-lg px-1.5 font-medium outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n                type=\"button\"\n              >\n                <span className=\"flex size-7 items-center justify-center rounded-lg bg-primary font-heading font-semibold text-primary-foreground text-xs\">\n                  {workspace[0]}\n                </span>\n                {workspace}\n                <ChevronDownIcon className=\"size-3.5 text-muted-foreground\" />\n              </button>,\n            )}\n            <div className=\"flex items-center gap-1\">\n              <Button aria-label=\"Inbox\" className=\"relative\" size=\"icon\" variant=\"ghost\">\n                <InboxIcon />\n                <span className=\"absolute top-2 right-2 size-1.5 rounded-full bg-rose-500 ring-2 ring-background dark:bg-rose-400\" />\n              </Button>\n              <Avatar aria-label={me?.name} role=\"img\" className=\"[--avatar-size:--spacing(7)]\">\n                <AvatarFallback className={cn(\"font-semibold text-[10px]\", ownerTones[ownerIndex(currentUserId) % ownerTones.length])}>\n                  {me ? initials(me.name) : \"?\"}\n                </AvatarFallback>\n              </Avatar>\n            </div>\n          </div>\n\n          <header className=\"flex shrink-0 flex-col gap-3 px-4 pt-4 pb-3 @3xl:flex-row @3xl:items-end @3xl:justify-between @3xl:px-6 @3xl:pt-5 @3xl:pb-4 @5xl:px-5\">\n            <div className=\"flex min-w-0 flex-col gap-0.5\">\n              <span className=\"text-muted-foreground text-xs\">{dateLabel}</span>\n              <h1 className=\"text-balance font-heading font-semibold text-xl tracking-tight\">\n                {greeting}, {firstName}\n              </h1>\n              <p className=\"text-pretty text-muted-foreground\">\n                {openSignals.length === 0\n                  ? \"Nothing needs you right now. Nice work.\"\n                  : `${openSignals.length} ${openSignals.length === 1 ? \"account needs\" : \"accounts need\"} you today.`}\n                <span className=\"hidden @5xl:inline\"> Drag deals as they move.</span>\n              </p>\n            </div>\n            <div className=\"flex flex-col gap-0.5 @3xl:items-end\">\n              <span className=\"text-muted-foreground text-xs\">{forecastLabel}</span>\n              <div className=\"flex items-center gap-2 @3xl:flex-row-reverse\">\n                <span className=\"font-heading font-semibold text-2xl tracking-tight\">\n                  <Rolling format={money} reduce={reduce} value={total} />\n                  <span className=\"sr-only\">{money(total)}</span>\n                </span>\n                <AnimatePresence>\n                  {delta ? (\n                    <motion.span\n                      animate={{ opacity: 1, y: 0 }}\n                      className={cn(\n                        \"rounded-full px-2 py-0.5 font-medium text-xs tabular-nums\",\n                        delta.amount > 0\n                          ? \"bg-emerald-500/12 text-emerald-700 dark:bg-emerald-400/14 dark:text-emerald-300\"\n                          : \"bg-muted text-muted-foreground\",\n                      )}\n                      exit={{ opacity: 0, transition: { duration: 0.2 } }}\n                      initial={{ opacity: 0, y: 4 }}\n                      key={delta.key}\n                      transition={{ duration: 0.2, ease }}\n                    >\n                      {signedMoney(delta.amount)}\n                    </motion.span>\n                  ) : null}\n                </AnimatePresence>\n              </div>\n              <div\n                aria-label={`${progress}% of target`}\n                aria-valuemax={100}\n                aria-valuemin={0}\n                aria-valuenow={Math.min(100, progress)}\n                className=\"relative mt-1.5 mb-1 h-1 w-full overflow-hidden rounded-full bg-muted @3xl:w-56\"\n                role=\"meter\"\n              >\n                <motion.div\n                  animate={{ scaleX: Math.min(1, total / target) }}\n                  className=\"absolute inset-0 origin-left rounded-full bg-primary\"\n                  initial={false}\n                  transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 260, damping: 32 }}\n                />\n                <div\n                  className=\"absolute inset-y-0 left-0 bg-emerald-500 dark:bg-emerald-400\"\n                  style={{ width: `${Math.min(100, (won / target) * 100)}%` }}\n                />\n              </div>\n              <span className=\"text-muted-foreground text-xs tabular-nums\">\n                {progress}% of {shortMoney(target)} target · <span className=\"text-emerald-700 dark:text-emerald-300\">{shortMoney(won)} won</span>\n              </span>\n            </div>\n          </header>\n\n          <div className=\"shrink-0 px-4 pb-3 @5xl:hidden\">\n            <SegmentedControl aria-label=\"Show\" className=\"w-full\">\n              {([\"board\", \"focus\"] as const).map((t) => (\n                <SegmentedControlItem\n                  aria-pressed={tab === t}\n                  className=\"flex-1\"\n                  data-pressed={tab === t ? \"\" : undefined}\n                  key={t}\n                  onClick={() => setTab(t)}\n                >\n                  {t === \"board\" ? \"Pipeline\" : \"Focus\"}\n                  {t === \"focus\" && openSignals.length ? (\n                    <span className=\"text-muted-foreground text-xs tabular-nums\">{openSignals.length}</span>\n                  ) : null}\n                </SegmentedControlItem>\n              ))}\n            </SegmentedControl>\n          </div>\n\n          <div className=\"flex min-h-0 flex-1 @5xl:relative @5xl:border-t\">\n            <div\n              className={cn(\n                \"relative flex min-w-0 flex-1 flex-col @5xl:flex\",\n                tab !== \"board\" && \"hidden\",\n              )}\n            >\n              <div className=\"shrink-0 px-4 pb-3 @5xl:hidden\">\n                <div\n                  aria-label=\"Stage\"\n                  ref={chipsRef}\n                  className=\"relative flex gap-1 overflow-x-auto rounded-xl bg-muted p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\"\n                  role=\"group\"\n                >\n                  {stages.map((s) => {\n                    const active = s.id === mobileStage;\n                    const isOver = drag !== null && over?.stage === s.id;\n                    return (\n                      <button\n                        aria-pressed={active}\n                        className={cn(\n                          \"relative flex h-8 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n                          active ? \"text-foreground\" : \"text-muted-foreground\",\n                          isOver && \"bg-accent\",\n                        )}\n                        data-drop-kind=\"chip\"\n                        data-drop-stage={s.id}\n                        key={s.id}\n                        onClick={() => setMobileStage(s.id)}\n                        type=\"button\"\n                      >\n                        {active ? (\n                          <motion.span\n                            className=\"absolute inset-0 -z-10 rounded-lg bg-background shadow-sm/5 dark:bg-input\"\n                            layoutId={`${uid}-stage`}\n                            transition={glide}\n                          />\n                        ) : null}\n                        <span className={cn(\"size-1.5 rounded-full\", stageDot[s.id])} />\n                        {s.label}\n                        <span className=\"text-muted-foreground text-xs tabular-nums\">{columns[s.id].length}</span>\n                      </button>\n                    );\n                  })}\n                </div>\n              </div>\n              <div className=\"min-h-0 flex-1 overflow-x-auto px-4 pb-4 @3xl:px-6 @5xl:px-5 @5xl:pt-4\">\n                <div className=\"grid h-full grid-cols-1 gap-2 @5xl:min-w-[860px] @5xl:grid-cols-5\">\n                  {stages.map((s) => lane(s))}\n                </div>\n              </div>\n              <AnimatePresence>\n                {lifted ? (\n                  <motion.div\n                    animate={{ opacity: 1, y: 0 }}\n                    aria-hidden\n                    className=\"pointer-events-none absolute inset-x-0 bottom-3 z-20 flex justify-center px-3\"\n                    exit={{ opacity: 0, y: 4, transition: { duration: 0.12 } }}\n                    initial={{ opacity: 0, y: 4 }}\n                    transition={{ duration: 0.18, ease }}\n                  >\n                    <div className=\"flex items-center gap-3 rounded-full border bg-popover px-3 py-1.5 text-muted-foreground text-xs shadow-lg/5\">\n                      <span className=\"flex items-center gap-1\">\n                        <Kbd>←</Kbd>\n                        <Kbd>→</Kbd> stage\n                      </span>\n                      <span className=\"flex items-center gap-1\">\n                        <Kbd>↑</Kbd>\n                        <Kbd>↓</Kbd> order\n                      </span>\n                      <span className=\"flex items-center gap-1\">\n                        <Kbd>Space</Kbd> drop\n                      </span>\n                      <span className=\"hidden items-center gap-1 @md:flex\">\n                        <Kbd>Esc</Kbd> cancel\n                      </span>\n                    </div>\n                  </motion.div>\n                ) : null}\n              </AnimatePresence>\n            </div>\n\n            <aside\n              className={cn(\n                \"min-h-0 flex-col bg-background @5xl:flex @5xl:w-[288px] @5xl:shrink-0 @5xl:border-s @[90rem]:w-[312px]\",\n                selected\n                  ? \"absolute inset-0 z-30 flex @5xl:static\"\n                  : tab === \"focus\"\n                    ? \"flex w-full\"\n                    : \"hidden\",\n              )}\n              id={ids.detail}\n            >\n              <motion.div\n                animate={{ opacity: 1, x: 0 }}\n                className=\"flex min-h-0 flex-1 flex-col\"\n                initial={{ opacity: 0, x: 10 }}\n                key={selected ? \"detail\" : \"focus\"}\n                transition={{ duration: 0.2, ease }}\n              >\n                {selected ? (\n                  <DetailPanel\n                    deal={selected}\n                    headingId={ids.heading}\n                    onClose={closeDetail}\n                    onMove={(stage) => moveFromPanel(selected.id, stage)}\n                    owner={ownerOf(selected.ownerId)}\n                    ownerIndex={ownerIndex(selected.ownerId)}\n                    panelRef={panelRef}\n                    stages={stages}\n                  />\n                ) : (\n                  focusRail\n                )}\n              </motion.div>\n            </aside>\n          </div>\n        </div>\n\n        {drag && draggedDeal ? (\n          <motion.div\n            aria-hidden\n            className=\"pointer-events-none absolute top-0 left-0 z-50\"\n            style={{ x: dragX, y: dragY, rotate: tilt, width: drag.width }}\n          >\n            <motion.div\n              animate={{ scale: 1.03 }}\n              initial={{ scale: 1 }}\n              transition={{ type: \"spring\", stiffness: 500, damping: 30 }}\n            >\n              <DealFace\n                className=\"cursor-grabbing border-foreground/20 shadow-xl/10 dark:shadow-xl/40\"\n                deal={draggedDeal}\n                flag={flagFor(draggedDeal.id)}\n                owner={ownerOf(draggedDeal.ownerId)}\n                ownerIndex={ownerIndex(draggedDeal.ownerId)}\n                reduce={reduce}\n              />\n            </motion.div>\n          </motion.div>\n        ) : null}\n      </div>\n    </MotionConfig>\n  );\n}\n"
    }
  ]
}