{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "money",
  "type": "registry:block",
  "title": "Money",
  "description": "A personal finance home: the balance rolls digit by digit as you switch accounts or pay a bill, the payment lands in your transactions, spending donut and budgets at once, and each budget shows if you’re spending ahead of pace.",
  "categories": [
    "screen",
    "Personal"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/avatar.json",
    "https://coss.com/ui/r/badge.json",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/input-group.json"
  ],
  "files": [
    {
      "path": "registry/devl/money.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport {\n  ArrowDownLeftIcon,\n  CheckIcon,\n  CreditCardIcon,\n  GoalIcon,\n  HomeIcon,\n  LayoutGridIcon,\n  type LucideIcon,\n  MenuIcon,\n  PiggyBankIcon,\n  ReceiptTextIcon,\n  RepeatIcon,\n  SearchIcon,\n  ShoppingBagIcon,\n  ShoppingBasketIcon,\n  TicketIcon,\n  TramFrontIcon,\n  UtensilsIcon,\n  WalletIcon,\n  XIcon,\n} from \"lucide-react\";\nimport {\n  AnimatePresence,\n  animate,\n  motion,\n  useMotionValue,\n  useReducedMotion,\n  useTransform,\n} from \"motion/react\";\nimport { type PointerEvent, type ReactNode, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { Avatar, AvatarFallback } from \"@/components/ui/avatar\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { InputGroup, InputGroupAddon, InputGroupInput } from \"@/components/ui/input-group\";\n\nexport type MoneyCategory = \"groceries\" | \"dining\" | \"transport\" | \"shopping\" | \"home\" | \"fun\" | \"income\";\n\nexport interface MoneyAccount {\n  id: string;\n  name: string;\n  kind: \"checking\" | \"savings\" | \"credit\";\n  mask: string;\n  balance: number;\n}\n\nexport interface MoneyTransaction {\n  id: string;\n  merchant: string;\n  category: MoneyCategory;\n  amount: number;\n  accountId: string;\n  date: string;\n  time: string;\n}\n\nexport interface MoneyBill {\n  id: string;\n  name: string;\n  amount: number;\n  due: string;\n  category: MoneyCategory;\n  autopay?: boolean;\n}\n\nexport interface MoneyBudget {\n  category: MoneyCategory;\n  limit: number;\n}\n\ntype MoneyView = \"overview\" | \"transactions\" | \"bills\" | \"budgets\";\n\nexport interface MoneyProps {\n  className?: string;\n  accounts?: MoneyAccount[];\n  transactions?: MoneyTransaction[];\n  bills?: MoneyBill[];\n  budgets?: MoneyBudget[];\n  today?: string;\n  userName?: string;\n  productName?: string;\n}\n\nconst spring = { type: \"spring\", stiffness: 520, damping: 46, mass: 1 } as const;\nconst roll = { type: \"spring\", stiffness: 210, damping: 30, mass: 1 } as const;\nconst easeOut = [0.23, 1, 0.32, 1] as const;\nconst press = \"transition-[color,background-color,box-shadow,scale,opacity] duration-150 ease-out active:scale-[0.97]\";\nconst card = \"rounded-2xl border bg-card shadow-xs/5\";\n\nconst categories: Record<\n  MoneyCategory,\n  { label: string; icon: LucideIcon; tile: string; dot: string; stroke: string }\n> = {\n  groceries: {\n    label: \"Groceries\",\n    icon: ShoppingBasketIcon,\n    tile: \"bg-teal-500/12 text-teal-700 dark:bg-teal-400/14 dark:text-teal-300\",\n    dot: \"bg-teal-500 dark:bg-teal-400\",\n    stroke: \"stroke-teal-500 dark:stroke-teal-400\",\n  },\n  dining: {\n    label: \"Eating out\",\n    icon: UtensilsIcon,\n    tile: \"bg-orange-500/12 text-orange-700 dark:bg-orange-400/14 dark:text-orange-300\",\n    dot: \"bg-orange-500 dark:bg-orange-400\",\n    stroke: \"stroke-orange-500 dark:stroke-orange-400\",\n  },\n  transport: {\n    label: \"Transport\",\n    icon: TramFrontIcon,\n    tile: \"bg-sky-500/12 text-sky-700 dark:bg-sky-400/14 dark:text-sky-300\",\n    dot: \"bg-sky-500 dark:bg-sky-400\",\n    stroke: \"stroke-sky-500 dark:stroke-sky-400\",\n  },\n  shopping: {\n    label: \"Shopping\",\n    icon: ShoppingBagIcon,\n    tile: \"bg-violet-500/12 text-violet-700 dark:bg-violet-400/14 dark:text-violet-300\",\n    dot: \"bg-violet-500 dark:bg-violet-400\",\n    stroke: \"stroke-violet-500 dark:stroke-violet-400\",\n  },\n  home: {\n    label: \"Home & bills\",\n    icon: HomeIcon,\n    tile: \"bg-amber-500/14 text-amber-700 dark:bg-amber-400/14 dark:text-amber-300\",\n    dot: \"bg-amber-500 dark:bg-amber-400\",\n    stroke: \"stroke-amber-500 dark:stroke-amber-400\",\n  },\n  fun: {\n    label: \"Going out\",\n    icon: TicketIcon,\n    tile: \"bg-rose-500/12 text-rose-700 dark:bg-rose-400/14 dark:text-rose-300\",\n    dot: \"bg-rose-500 dark:bg-rose-400\",\n    stroke: \"stroke-rose-500 dark:stroke-rose-400\",\n  },\n  income: {\n    label: \"Income\",\n    icon: ArrowDownLeftIcon,\n    tile: \"bg-success/12 text-success-foreground dark:bg-success/16\",\n    dot: \"bg-success\",\n    stroke: \"stroke-success\",\n  },\n};\n\nconst accountIcons: Record<MoneyAccount[\"kind\"], LucideIcon> = {\n  checking: WalletIcon,\n  savings: PiggyBankIcon,\n  credit: CreditCardIcon,\n};\n\nconst defaultAccounts: MoneyAccount[] = [\n  { id: \"everyday\", name: \"Everyday\", kind: \"checking\", mask: \"4021\", balance: 4218.4 },\n  { id: \"savings\", name: \"Rainy day\", kind: \"savings\", mask: \"7730\", balance: 18650 },\n  { id: \"credit\", name: \"Credit card\", kind: \"credit\", mask: \"0915\", balance: -1342.18 },\n];\n\nconst t = (\n  id: string,\n  merchant: string,\n  category: MoneyCategory,\n  amount: number,\n  date: string,\n  time: string,\n  accountId = \"everyday\",\n): MoneyTransaction => ({ id, merchant, category, amount, date, time, accountId });\n\nconst defaultTransactions: MoneyTransaction[] = [\n  t(\"t1\", \"Ridely\", \"transport\", -14.2, \"2026-10-24\", \"6:05 pm\", \"credit\"),\n  t(\"t2\", \"Greenleaf Market\", \"groceries\", -64.18, \"2026-10-24\", \"12:40 pm\"),\n  t(\"t3\", \"Nimbus Coffee\", \"dining\", -6.4, \"2026-10-24\", \"8:12 am\"),\n  t(\"t4\", \"Pho Saigon Kitchen\", \"dining\", -38.5, \"2026-10-23\", \"7:48 pm\", \"credit\"),\n  t(\"t5\", \"Atlas Books\", \"shopping\", -27.99, \"2026-10-23\", \"1:15 pm\"),\n  t(\"t6\", \"Metro Transit\", \"transport\", -2.9, \"2026-10-23\", \"8:31 am\"),\n  t(\"t7\", \"Brightline Studio\", \"income\", 3240, \"2026-10-22\", \"9:00 am\"),\n  t(\"t8\", \"Fieldstone Grocers\", \"groceries\", -41.72, \"2026-10-22\", \"5:52 pm\"),\n  t(\"t9\", \"Cinema Lumière\", \"fun\", -26, \"2026-10-22\", \"8:20 pm\", \"credit\"),\n  t(\"t10\", \"Marlowe's Diner\", \"dining\", -41.3, \"2026-10-21\", \"12:30 pm\"),\n  t(\"t11\", \"Harbor Hardware\", \"home\", -48.35, \"2026-10-20\", \"11:04 am\"),\n  t(\"t12\", \"Sunday Supper Club\", \"dining\", -92, \"2026-10-19\", \"8:45 pm\", \"credit\"),\n  t(\"t13\", \"Nimbus Coffee\", \"dining\", -5.8, \"2026-10-19\", \"9:10 am\"),\n  t(\"t14\", \"Greenleaf Market\", \"groceries\", -88.04, \"2026-10-18\", \"10:22 am\"),\n  t(\"t15\", \"Spinwell Cycles\", \"transport\", -34, \"2026-10-18\", \"3:40 pm\"),\n  t(\"t16\", \"Pinball Parlour\", \"fun\", -18, \"2026-10-18\", \"9:15 pm\"),\n  t(\"t17\", \"Greenleaf Market\", \"groceries\", -72.3, \"2026-10-15\", \"6:02 pm\"),\n  t(\"t18\", \"Tidewater Ramen\", \"dining\", -44.1, \"2026-10-15\", \"7:30 pm\", \"credit\"),\n  t(\"t19\", \"Fieldstone Grocers\", \"groceries\", -59.66, \"2026-10-12\", \"11:48 am\"),\n  t(\"t20\", \"Corner Bakehouse\", \"dining\", -12.75, \"2026-10-12\", \"8:55 am\"),\n  t(\"t21\", \"Kiln & Co.\", \"shopping\", -64, \"2026-10-12\", \"2:10 pm\", \"credit\"),\n  t(\"t22\", \"Brightline Studio\", \"income\", 3240, \"2026-10-08\", \"9:00 am\"),\n  t(\"t23\", \"Greenleaf Market\", \"groceries\", -66.4, \"2026-10-08\", \"5:35 pm\"),\n  t(\"t24\", \"Velvet Room\", \"dining\", -58.2, \"2026-10-08\", \"10:40 pm\", \"credit\"),\n  t(\"t25\", \"Ticketpost\", \"fun\", -68, \"2026-10-07\", \"1:02 pm\", \"credit\"),\n  t(\"t26\", \"Northgate Pharmacy\", \"shopping\", -18.45, \"2026-10-05\", \"4:18 pm\"),\n  t(\"t27\", \"Metro Transit\", \"transport\", -12.9, \"2026-10-05\", \"7:58 am\"),\n  t(\"t28\", \"Corner Bakehouse\", \"dining\", -9.6, \"2026-10-05\", \"9:20 am\"),\n  t(\"t29\", \"Fieldstone Grocers\", \"groceries\", -39.85, \"2026-10-02\", \"6:44 pm\"),\n  t(\"t30\", \"Habitat Living\", \"home\", -1450, \"2026-10-01\", \"7:00 am\"),\n];\n\nconst defaultBills: MoneyBill[] = [\n  { id: \"b1\", name: \"Northwind Energy\", amount: 86.4, due: \"2026-10-26\", category: \"home\", autopay: true },\n  { id: \"b2\", name: \"Fernway Fiber\", amount: 55, due: \"2026-10-28\", category: \"home\" },\n  { id: \"b3\", name: \"Reelhouse\", amount: 12.99, due: \"2026-10-30\", category: \"fun\", autopay: true },\n  { id: \"b4\", name: \"Habitat Living\", amount: 1450, due: \"2026-11-01\", category: \"home\" },\n  { id: \"b5\", name: \"Ironbridge Insurance\", amount: 38.2, due: \"2026-11-04\", category: \"home\" },\n];\n\nconst defaultBudgets: MoneyBudget[] = [\n  { category: \"groceries\", limit: 600 },\n  { category: \"dining\", limit: 300 },\n  { category: \"transport\", limit: 150 },\n  { category: \"fun\", limit: 200 },\n];\n\nconst usd = new Intl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\nconst usd0 = new Intl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\", maximumFractionDigits: 0 });\nconst money = (n: number) => usd.format(n);\nconst money0 = (n: number) => usd0.format(Math.round(n));\n\nfunction parseDate(iso: string) {\n  return new Date(`${iso}T12:00:00`);\n}\nfunction daysBetween(a: string, b: string) {\n  return Math.round((parseDate(b).getTime() - parseDate(a).getTime()) / 86_400_000);\n}\nfunction initials(name: string) {\n  const words = name.replace(/[^A-Za-zÀ-ÿ\\s]/g, \"\").split(/\\s+/).filter(Boolean);\n  return (words.length > 1 ? words[0][0] + words[1][0] : (words[0] ?? \"?\").slice(0, 2)).toUpperCase();\n}\n\nfunction seededNoise(seed: number) {\n  const x = Math.sin(seed * 12.9898) * 43758.5453;\n  return x - Math.floor(x);\n}\n\nfunction history(account: MoneyAccount, end: number, days = 30) {\n  const seed = account.id.split(\"\").reduce((s, c) => s + c.charCodeAt(0), 0);\n  const out = new Array<number>(days);\n  let v = end;\n  out[days - 1] = v;\n  for (let i = days - 2; i >= 0; i--) {\n    const daysAgo = days - 1 - i;\n    let step: number;\n    if (account.kind === \"savings\") step = (daysAgo === 15 ? 1000 : daysAgo === 1 ? 600 : 0) + 1 + seededNoise(seed + i) * 2;\n    else if (account.kind === \"credit\") step = -(seededNoise(seed + i) * 70) + (daysAgo === 18 ? -900 : 0);\n    else {\n      step = -(seededNoise(seed + i) * 90 + 15);\n      if (daysAgo === 2 || daysAgo === 16) step += 3240;\n      if (daysAgo === 23) step -= 1450;\n      if (daysAgo === 15) step -= 1000;\n      if (daysAgo === 1) step -= 600;\n    }\n    v -= step;\n    out[i] = v;\n  }\n  return out;\n}\n\nfunction Odometer({ value, format }: { value: number; format: (n: number) => string }) {\n  const text = format(value);\n  const chars = text.split(\"\");\n  return (\n    <span className=\"inline-flex items-center tabular-nums leading-none\">\n      <span className=\"sr-only\">{text}</span>\n      {chars.map((ch, i) => {\n        const key = chars.length - i;\n        return /\\d/.test(ch) ? (\n          <Digit digit={Number(ch)} key={`d${key}`} />\n        ) : (\n          <span aria-hidden className=\"flex h-[1.15em] items-center\" key={`c${key}${ch}`}>\n            {ch}\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nfunction Digit({ digit }: { digit: number }) {\n  const reduce = useReducedMotion();\n  return (\n    <span\n      aria-hidden\n      className=\"relative inline-flex h-[1.15em] items-center overflow-hidden [mask-image:linear-gradient(transparent,black_18%,black_82%,transparent)]\"\n    >\n      <span className=\"invisible\">0</span>\n      <motion.span\n        animate={{ y: `${-digit * 1.15}em` }}\n        className=\"absolute inset-x-0 top-0 flex flex-col items-center\"\n        initial={false}\n        transition={reduce ? { duration: 0 } : roll}\n      >\n        {Array.from({ length: 10 }, (_, n) => (\n          <span className=\"flex h-[1.15em] items-center\" key={n}>\n            {n}\n          </span>\n        ))}\n      </motion.span>\n    </span>\n  );\n}\n\nfunction Tween({ value, format = money }: { value: number; format?: (n: number) => string }) {\n  const reduce = useReducedMotion();\n  const mv = useMotionValue(value);\n  const text = useTransform(mv, format);\n  useEffect(() => {\n    if (reduce) {\n      mv.set(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 <motion.span className=\"tabular-nums\">{text}</motion.span>;\n}\n\nfunction MerchantTile({ merchant, category }: { merchant: string; category: MoneyCategory }) {\n  const c = categories[category];\n  const Icon = c.icon;\n  return (\n    <span className=\"relative shrink-0\">\n      <span\n        aria-hidden\n        className={cn(\"flex size-9 items-center justify-center rounded-xl font-semibold text-[11px] tracking-wide\", c.tile)}\n      >\n        {initials(merchant)}\n      </span>\n      <span\n        aria-hidden\n        className=\"absolute -right-1 -bottom-1 flex size-4 items-center justify-center rounded-full bg-card text-muted-foreground ring-2 ring-card\"\n      >\n        <Icon className=\"size-2.5\" />\n      </span>\n    </span>\n  );\n}\n\nexport function Money({\n  className,\n  accounts: initialAccounts = defaultAccounts,\n  transactions: initialTransactions = defaultTransactions,\n  bills = defaultBills,\n  budgets = defaultBudgets,\n  today = \"2026-10-24\",\n  userName = \"Ines Moreau\",\n  productName = \"Tally\",\n}: MoneyProps) {\n  const [accounts, setAccounts] = useState(initialAccounts);\n  const [transactions, setTransactions] = useState(initialTransactions);\n  const [accountId, setAccountId] = useState<string>(\"all\");\n  const [focusCat, setFocusCat] = useState<MoneyCategory | null>(null);\n  const [filterCat, setFilterCat] = useState<MoneyCategory | null>(null);\n  const [query, setQuery] = useState(\"\");\n  const [billState, setBillState] = useState<Record<string, \"paying\" | \"paid\">>({});\n  const [drawer, setDrawer] = useState(false);\n  const [view, setView] = useState<MoneyView>(\"overview\");\n  const hasSwitchedView = useRef(false);\n  const reduce = useReducedMotion();\n  const uid = useId().replace(/:/g, \"\");\n  const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n  const drawerRef = useRef<HTMLDivElement>(null);\n  const listRef = useRef<HTMLElement>(null);\n  const scrollRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => () => timers.current.forEach(clearTimeout), []);\n  useEffect(() => {\n    if (drawer) drawerRef.current?.focus();\n  }, [drawer]);\n\n  const month = today.slice(0, 7);\n  const monthName = parseDate(today).toLocaleDateString(\"en-US\", { month: \"long\" });\n  const monthEnd = new Date(parseDate(today).getFullYear(), parseDate(today).getMonth() + 1, 0).getDate();\n  const daysLeft = monthEnd - parseDate(today).getDate();\n  const firstName = userName.split(\" \")[0];\n\n  const total = accounts.reduce((s, a) => s + a.balance, 0);\n  const selected = accounts.find((a) => a.id === accountId);\n  const shown = selected ? selected.balance : total;\n\n  const series = useMemo(() => {\n    const per = accounts.map((a) => {\n      const start = initialAccounts.find((b) => b.id === a.id) ?? a;\n      const h = history(start, start.balance);\n      h[h.length - 1] = a.balance;\n      return h;\n    });\n    if (selected) return per[accounts.indexOf(selected)];\n    return per[0].map((_, i) => per.reduce((s, p) => s + p[i], 0));\n  }, [accounts, selected, initialAccounts]);\n  const since = shown - series[0];\n\n  const monthTx = transactions.filter((x) => x.date.startsWith(month));\n  const spendBy = (cat: MoneyCategory) =>\n    monthTx.filter((x) => x.category === cat && x.amount < 0).reduce((s, x) => s - x.amount, 0);\n  const spendCats = (Object.keys(categories) as MoneyCategory[])\n    .filter((c) => c !== \"income\")\n    .map((c) => ({ cat: c, value: spendBy(c) }))\n    .filter((s) => s.value > 0)\n    .sort((a, b) => b.value - a.value);\n  const spent = spendCats.reduce((s, c) => s + c.value, 0);\n  const income = monthTx.filter((x) => x.amount > 0).reduce((s, x) => s + x.amount, 0);\n\n  const openBills = bills.filter((b) => billState[b.id] !== \"paid\");\n  const dueTotal = openBills.reduce((s, b) => s + b.amount, 0);\n\n  const payBill = (bill: MoneyBill) => {\n    if (billState[bill.id]) return;\n    setBillState((s) => ({ ...s, [bill.id]: \"paying\" }));\n    timers.current.push(\n      setTimeout(() => {\n        setBillState((s) => ({ ...s, [bill.id]: \"paid\" }));\n        setAccounts((all) => all.map((a) => (a.kind === \"checking\" ? { ...a, balance: a.balance - bill.amount } : a)));\n        const from = accounts.find((a) => a.kind === \"checking\")?.id ?? accounts[0]?.id ?? \"\";\n        setTransactions((all) => [\n          {\n            id: `pay-${bill.id}`,\n            merchant: bill.name,\n            category: bill.category,\n            amount: -bill.amount,\n            accountId: from,\n            date: today,\n            time: \"Just now\",\n          },\n          ...all,\n        ]);\n      }, 700),\n    );\n  };\n\n  const q = query.trim().toLowerCase();\n  const visibleTx = transactions.filter(\n    (x) =>\n      (!filterCat || x.category === filterCat) &&\n      (!selected || x.accountId === selected.id) &&\n      (!q || x.merchant.toLowerCase().includes(q) || categories[x.category].label.toLowerCase().includes(q)),\n  );\n  const groups: { date: string; items: MoneyTransaction[] }[] = [];\n  for (const x of visibleTx) {\n    const g = groups.at(-1);\n    if (g && g.date === x.date) g.items.push(x);\n    else groups.push({ date: x.date, items: [x] });\n  }\n  const dayLabel = (iso: string) => {\n    const d = daysBetween(iso, today);\n    if (d === 0) return \"Today\";\n    if (d === 1) return \"Yesterday\";\n    return parseDate(iso).toLocaleDateString(\"en-US\", { weekday: \"short\", month: \"short\", day: \"numeric\" });\n  };\n\n  const scrollTo = (el: HTMLElement | null) => {\n    const root = scrollRef.current;\n    if (!root || !el) return;\n    const top = el.getBoundingClientRect().top - root.getBoundingClientRect().top + root.scrollTop - 16;\n    root.scrollTo({ top, behavior: reduce ? \"auto\" : \"smooth\" });\n  };\n\n  const go = (next: MoneyView) => {\n    setDrawer(false);\n    if (next === view) {\n      scrollRef.current?.scrollTo({ top: 0, behavior: reduce ? \"auto\" : \"smooth\" });\n      return;\n    }\n    hasSwitchedView.current = true;\n    setView(next);\n    if (scrollRef.current) scrollRef.current.scrollTop = 0;\n  };\n\n  const pickCategory = (cat: MoneyCategory) => {\n    setFilterCat((c) => (c === cat && view !== \"budgets\" ? null : cat));\n    if (view === \"budgets\") {\n      hasSwitchedView.current = true;\n      setView(\"transactions\");\n      if (scrollRef.current) scrollRef.current.scrollTop = 0;\n    } else if (view === \"overview\") scrollTo(listRef.current);\n  };\n\n  const nav: { id: MoneyView; label: string; icon: ReactNode; badge?: number }[] = [\n    { id: \"overview\", label: \"Overview\", icon: <LayoutGridIcon /> },\n    { id: \"transactions\", label: \"Transactions\", icon: <ReceiptTextIcon /> },\n    { id: \"bills\", label: \"Bills\", icon: <RepeatIcon />, badge: openBills.length || undefined },\n    { id: \"budgets\", label: \"Budgets\", icon: <GoalIcon /> },\n  ];\n  const viewLabel = nav.find((n) => n.id === view)?.label ?? \"Overview\";\n\n  const sidebar = (where: \"rail\" | \"drawer\") => (\n    <div className=\"flex h-full flex-col gap-6 p-3\">\n      <div className=\"flex items-center gap-2.5 px-1.5 pt-1\">\n        <span className=\"flex size-8 items-center justify-center rounded-lg bg-primary text-primary-foreground\">\n          <PiggyBankIcon className=\"size-4\" />\n        </span>\n        <span className=\"font-heading font-semibold\">{productName}</span>\n      </div>\n      <nav aria-label=\"Main\" className=\"isolate flex flex-col gap-0.5\">\n        {nav.map((n) => {\n          const active = n.id === view;\n          return (\n            <button\n              aria-current={active ? \"page\" : undefined}\n              className={cn(\n                \"relative flex h-8 cursor-pointer items-center gap-2.5 rounded-lg px-2.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4 [&_svg]:opacity-80\",\n                press,\n                active ? \"font-medium text-foreground\" : \"text-muted-foreground hover:bg-accent/60 hover:text-foreground\",\n              )}\n              key={n.id}\n              onClick={() => go(n.id)}\n              type=\"button\"\n            >\n              {active && (\n                <motion.span\n                  className=\"absolute inset-0 -z-10 rounded-lg bg-accent\"\n                  layoutId={`${uid}-${where}-nav`}\n                  transition={reduce ? { duration: 0 } : spring}\n                />\n              )}\n              {n.icon}\n              <span className=\"flex-1\">{n.label}</span>\n              {n.badge ? (\n                <Badge className=\"tabular-nums\" size=\"sm\" variant=\"secondary\">\n                  {n.badge}\n                </Badge>\n              ) : null}\n            </button>\n          );\n        })}\n      </nav>\n      <div className=\"isolate flex flex-col gap-1\">\n        <span className=\"px-2.5 font-medium text-muted-foreground text-xs\">Accounts</span>\n        {accounts.map((a) => {\n          const Icon = accountIcons[a.kind];\n          const active = a.id === accountId;\n          return (\n            <button\n              aria-pressed={active}\n              className={cn(\n                \"relative flex h-11 cursor-pointer items-center gap-2.5 rounded-lg px-2.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n                press,\n                !active && \"hover:bg-accent/60\",\n              )}\n              key={a.id}\n              onClick={() => {\n                setAccountId(active ? \"all\" : a.id);\n                setDrawer(false);\n              }}\n              type=\"button\"\n            >\n              {active && (\n                <motion.span\n                  className=\"absolute inset-0 -z-10 rounded-lg bg-accent\"\n                  layoutId={`${uid}-${where}-account`}\n                  transition={reduce ? { duration: 0 } : spring}\n                />\n              )}\n              <Icon className=\"size-4 shrink-0 text-muted-foreground\" />\n              <span className=\"flex min-w-0 flex-1 flex-col\">\n                <span className={cn(\"truncate\", active && \"font-medium\")}>{a.name}</span>\n                <span className=\"font-mono text-[11px] text-muted-foreground\">•• {a.mask}</span>\n              </span>\n              <span className={cn(\"text-xs\", a.balance < 0 ? \"text-muted-foreground\" : \"text-foreground\")}>\n                <Tween value={a.balance} />\n              </span>\n            </button>\n          );\n        })}\n      </div>\n      <div className=\"mt-auto flex items-center gap-2.5 rounded-xl border bg-card p-2.5\">\n        <Avatar className=\"[--avatar-size:--spacing(7)]\">\n          <AvatarFallback className=\"bg-teal-500/20 dark:bg-teal-400/20\">{initials(userName)}</AvatarFallback>\n        </Avatar>\n        <div className=\"flex min-w-0 flex-col\">\n          <span className=\"truncate font-medium text-xs\">{userName}</span>\n          <span className=\"text-muted-foreground text-xs\">Personal plan</span>\n        </div>\n      </div>\n    </div>\n  );\n\n  const pills = [{ id: \"all\", name: \"All accounts\" }, ...accounts.map((a) => ({ id: a.id, name: a.name }))];\n\n  const balanceSection = (\n    <section aria-label=\"Balance\" className={cn(card, \"order-1 overflow-hidden\")}>\n      <div className=\"flex flex-col gap-4 p-4 pb-0 @lg:p-5 @lg:pb-0\">\n        <div\n          aria-label=\"Account\"\n          className=\"-mx-4 isolate flex gap-1 overflow-x-auto px-4 [scrollbar-width:none] @lg:-mx-5 @lg:px-5\"\n          role=\"group\"\n        >\n          {pills.map((p) => {\n            const active = p.id === accountId;\n            return (\n              <button\n                aria-pressed={active}\n                className={cn(\n                  \"relative h-7 shrink-0 cursor-pointer rounded-full px-3 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n                  press,\n                  active ? \"font-medium text-primary-foreground\" : \"text-muted-foreground hover:text-foreground\",\n                )}\n                key={p.id}\n                onClick={() => setAccountId(p.id)}\n                type=\"button\"\n              >\n                {active && (\n                  <motion.span\n                    className=\"absolute inset-0 -z-10 rounded-full bg-primary\"\n                    layoutId={`${uid}-pill`}\n                    transition={reduce ? { duration: 0 } : spring}\n                  />\n                )}\n                {p.name}\n              </button>\n            );\n          })}\n        </div>\n        <div className=\"flex flex-wrap items-end justify-between gap-x-4 gap-y-2\">\n          <div className=\"flex flex-col gap-1.5\">\n            <span className=\"text-muted-foreground text-xs\">\n              {selected ? (selected.kind === \"credit\" ? \"Card balance\" : `${selected.name} balance`) : \"Total balance\"}\n            </span>\n            <span className=\"font-heading font-semibold text-[2.5rem] tracking-tight @lg:text-5xl\">\n              <Odometer format={money} value={shown} />\n            </span>\n          </div>\n          <Badge className=\"mb-1.5\" size=\"lg\" variant={since >= 0 ? \"success\" : \"error\"}>\n            <Tween format={(n) => `${n >= 0 ? \"+\" : \"−\"}${money(Math.abs(n))}`} value={since} />\n            <span className=\"font-normal opacity-80\">in 30 days</span>\n          </Badge>\n        </div>\n      </div>\n      <BalanceChart series={series} today={today} />\n    </section>\n  );\n\n  const spendingSection = (\n    <section aria-labelledby={`${uid}-spend`} className={cn(card, \"order-4 p-4 @lg:p-5\")}>\n      <div className=\"flex items-baseline justify-between gap-3\">\n        <h3 className=\"font-medium\" id={`${uid}-spend`}>\n          Spending in {monthName}\n        </h3>\n        <span className=\"text-muted-foreground text-xs\">Tap a category to filter</span>\n      </div>\n      <div className=\"mt-4 flex flex-col items-center gap-5 @lg:flex-row @lg:items-center @lg:gap-6\">\n        <Donut focus={focusCat ?? filterCat} onFocus={setFocusCat} onPick={pickCategory} parts={spendCats} total={spent} />\n        <ul className=\"flex w-full min-w-0 flex-1 flex-col gap-0.5\">\n          {spendCats.map((s) => {\n            const c = categories[s.cat];\n            const active = filterCat === s.cat;\n            return (\n              <li key={s.cat}>\n                <button\n                  aria-pressed={active}\n                  className={cn(\n                    \"flex h-9 w-full cursor-pointer items-center gap-2.5 rounded-lg px-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n                    press,\n                    active ? \"bg-accent\" : \"hover:bg-accent/60\",\n                  )}\n                  onBlur={() => setFocusCat(null)}\n                  onClick={() => pickCategory(s.cat)}\n                  onFocus={() => setFocusCat(s.cat)}\n                  onPointerEnter={() => setFocusCat(s.cat)}\n                  onPointerLeave={() => setFocusCat(null)}\n                  type=\"button\"\n                >\n                  <span className={cn(\"size-2 shrink-0 rounded-full\", c.dot)} />\n                  <span className=\"flex-1 truncate\">{c.label}</span>\n                  <span className=\"text-muted-foreground text-xs tabular-nums\">{Math.round((s.value / spent) * 100)}%</span>\n                  <span className=\"w-[4.75rem] text-right font-medium tabular-nums\">\n                    <Tween value={s.value} />\n                  </span>\n                </button>\n              </li>\n            );\n          })}\n        </ul>\n      </div>\n    </section>\n  );\n\n  const txSection = (\n    <section aria-labelledby={`${uid}-tx`} className={cn(card, \"order-5 overflow-hidden\")} ref={listRef}>\n      <div className=\"flex flex-col gap-3 border-b p-4 @lg:flex-row @lg:items-center @lg:px-5\">\n        <div className=\"flex flex-1 items-center gap-2\">\n          <h3 className=\"font-medium\" id={`${uid}-tx`}>\n            Transactions\n          </h3>\n          <AnimatePresence initial={false}>\n            {filterCat && (\n              <motion.button\n                animate={{ opacity: 1, scale: 1 }}\n                aria-label={`Remove ${categories[filterCat].label} filter`}\n                className={cn(\n                  \"relative flex h-6 cursor-pointer items-center gap-1.5 rounded-full border bg-background ps-2 pe-1.5 text-xs outline-none after:absolute after:-inset-y-1.5 after:inset-x-0 after:content-[''] focus-visible:ring-2 focus-visible:ring-ring\",\n                  press,\n                )}\n                exit={{ opacity: 0, scale: 0.95 }}\n                initial={{ opacity: 0, scale: 0.95 }}\n                onClick={() => setFilterCat(null)}\n                transition={{ duration: 0.15, ease: easeOut }}\n                type=\"button\"\n              >\n                <span className={cn(\"size-1.5 rounded-full\", categories[filterCat].dot)} />\n                {categories[filterCat].label}\n                <XIcon className=\"size-3 text-muted-foreground\" />\n              </motion.button>\n            )}\n          </AnimatePresence>\n        </div>\n        <InputGroup className=\"@lg:w-56\">\n          <InputGroupAddon>\n            <SearchIcon />\n          </InputGroupAddon>\n          <InputGroupInput\n            aria-label=\"Search transactions\"\n            onChange={(e) => setQuery(e.target.value)}\n            placeholder=\"Search merchants\"\n            type=\"search\"\n            value={query}\n          />\n        </InputGroup>\n      </div>\n      {groups.length === 0 ? (\n        <div className=\"flex flex-col items-center gap-2 px-6 py-12 text-center\">\n          <span className=\"flex size-10 items-center justify-center rounded-full bg-muted text-muted-foreground\">\n            <SearchIcon className=\"size-4\" />\n          </span>\n          <p className=\"font-medium\">Nothing matches</p>\n          <p className=\"text-muted-foreground\">Try another merchant, or clear the filter.</p>\n          <Button\n            className={cn(\"mt-1\", press)}\n            onClick={() => {\n              setQuery(\"\");\n              setFilterCat(null);\n            }}\n            size=\"sm\"\n            variant=\"outline\"\n          >\n            Clear search\n          </Button>\n        </div>\n      ) : (\n        <div className=\"flex flex-col pb-2\">\n          {groups.map((g) => {\n            const net = g.items.reduce((s, x) => s + x.amount, 0);\n            return (\n              <div key={g.date}>\n                <div className=\"flex items-center justify-between px-4 pt-4 pb-1.5 text-muted-foreground text-xs @lg:px-5\">\n                  <span className=\"font-medium\">{dayLabel(g.date)}</span>\n                  <span className=\"tabular-nums\">\n                    {net > 0 ? \"+\" : \"−\"}\n                    {money(Math.abs(net))}\n                  </span>\n                </div>\n                <ul>\n                  <AnimatePresence initial={false}>\n                    {g.items.map((x) => {\n                      const acct = accounts.find((a) => a.id === x.accountId);\n                      return (\n                        <motion.li\n                          animate={{ opacity: 1, y: 0 }}\n                          className=\"flex items-center gap-3 px-4 py-2 @lg:px-5\"\n                          initial={reduce ? { opacity: 0 } : { opacity: 0, y: -8 }}\n                          key={x.id}\n                          layout={reduce ? false : \"position\"}\n                          transition={spring}\n                        >\n                          <MerchantTile category={x.category} merchant={x.merchant} />\n                          <div className=\"flex min-w-0 flex-1 flex-col\">\n                            <span className=\"truncate font-medium\">{x.merchant}</span>\n                            <span className=\"truncate text-muted-foreground text-xs\">\n                              {categories[x.category].label} · {acct?.name ?? \"Account\"} · {x.time}\n                            </span>\n                          </div>\n                          <span className={cn(\"shrink-0 font-medium tabular-nums\", x.amount > 0 && \"text-success-foreground\")}>\n                            {x.amount > 0 ? \"+\" : \"−\"}\n                            {money(Math.abs(x.amount))}\n                          </span>\n                        </motion.li>\n                      );\n                    })}\n                  </AnimatePresence>\n                </ul>\n              </div>\n            );\n          })}\n        </div>\n      )}\n    </section>\n  );\n\n  const budgetsSection = (\n    <section aria-labelledby={`${uid}-budgets`} className={cn(card, \"order-2 p-4 @lg:p-5\")}>\n      <div className=\"flex items-baseline justify-between gap-3\">\n        <h3 className=\"font-medium\" id={`${uid}-budgets`}>\n          Budgets\n        </h3>\n        <span className=\"text-muted-foreground text-xs\">{daysLeft} days to go</span>\n      </div>\n      <ul className=\"-mx-2 mt-2 flex flex-col\">\n        {budgets.map((b) => (\n          <li key={b.category}>\n            <BudgetRow\n              category={b.category}\n              limit={b.limit}\n              onPick={() => pickCategory(b.category)}\n              pace={(monthEnd - daysLeft) / monthEnd}\n              spent={spendBy(b.category)}\n            />\n          </li>\n        ))}\n      </ul>\n      <p className=\"mt-2 flex items-center gap-1.5 text-muted-foreground text-xs\">\n        <span aria-hidden className=\"h-2.5 w-px bg-foreground/40\" />\n        Where you’d be at an even pace\n      </p>\n    </section>\n  );\n\n  const billsSection = (\n    <section aria-labelledby={`${uid}-bills`} className={cn(card, \"order-3 overflow-hidden\")}>\n      <div className=\"flex items-baseline justify-between gap-3 p-4 pb-2 @lg:px-5 @lg:pt-5\">\n        <h3 className=\"font-medium\" id={`${uid}-bills`}>\n          Upcoming bills\n        </h3>\n        <span className=\"text-muted-foreground text-xs\">\n          {openBills.length ? (\n            <>\n              <span className=\"text-foreground\">\n                <Tween value={dueTotal} />\n              </span>{\" \"}\n              due\n            </>\n          ) : (\n            \"All paid\"\n          )}\n        </span>\n      </div>\n      <ul className=\"flex flex-col pb-2\">\n        {bills.map((b) => {\n          const state = billState[b.id];\n          const d = daysBetween(today, b.due);\n          const due = parseDate(b.due);\n          return (\n            <li\n              className={cn(\n                \"flex items-center gap-3 px-4 py-2.5 transition-opacity duration-200 @lg:px-5\",\n                state === \"paid\" && \"opacity-60\",\n              )}\n              key={b.id}\n            >\n              <span className=\"flex w-10 shrink-0 flex-col items-center rounded-lg border bg-background py-1 leading-none\">\n                <span className=\"font-medium text-[10px] text-muted-foreground uppercase tracking-wide\">\n                  {due.toLocaleDateString(\"en-US\", { month: \"short\" })}\n                </span>\n                <span className=\"mt-1 font-semibold tabular-nums\">{due.getDate()}</span>\n              </span>\n              <div className=\"flex min-w-0 flex-1 flex-col\">\n                <span className=\"truncate font-medium\">{b.name}</span>\n                <span className=\"flex items-center gap-1 truncate text-muted-foreground text-xs\">\n                  <span className={cn(d <= 2 && state !== \"paid\" && \"text-warning-foreground\")}>\n                    {state === \"paid\" ? \"Paid today\" : d === 0 ? \"Due today\" : d === 1 ? \"Tomorrow\" : `In ${d} days`}\n                  </span>\n                  {b.autopay && state !== \"paid\" && (\n                    <>\n                      <span aria-hidden>·</span>\n                      <RepeatIcon aria-hidden className=\"size-3\" /> Autopay\n                    </>\n                  )}\n                </span>\n              </div>\n              <div className=\"flex shrink-0 flex-col items-end gap-1\">\n                <span className=\"font-medium tabular-nums\">{money(b.amount)}</span>\n                <PayButton name={b.name} onPay={() => payBill(b)} state={state} />\n              </div>\n            </li>\n          );\n        })}\n      </ul>\n    </section>\n  );\n\n  return (\n    <div\n      className={cn(\n        \"@container relative isolate flex h-[760px] w-full overflow-hidden bg-background text-foreground text-sm\",\n        className,\n      )}\n      onKeyDown={(e) => {\n        if (e.key === \"Escape\" && drawer) setDrawer(false);\n      }}\n    >\n      <aside className=\"hidden w-60 shrink-0 border-r bg-muted/40 @4xl:block\">{sidebar(\"rail\")}</aside>\n\n      <AnimatePresence>\n        {drawer && (\n          <>\n            <motion.div\n              animate={{ opacity: 1 }}\n              aria-hidden\n              className=\"absolute inset-0 z-40 bg-black/32 @4xl:hidden\"\n              exit={{ opacity: 0 }}\n              initial={{ opacity: 0 }}\n              key=\"backdrop\"\n              onClick={() => setDrawer(false)}\n              transition={{ duration: 0.2, ease: easeOut }}\n            />\n            <motion.div\n              animate={{ x: 0 }}\n              aria-label=\"Navigation\"\n              aria-modal\n              className=\"absolute inset-y-0 left-0 z-50 w-72 max-w-[85%] border-r bg-background outline-none @4xl:hidden\"\n              exit={{ x: \"-100%\" }}\n              initial={{ x: \"-100%\" }}\n              key=\"drawer\"\n              ref={drawerRef}\n              role=\"dialog\"\n              tabIndex={-1}\n              transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 42 }}\n            >\n              <Button\n                aria-label=\"Close navigation\"\n                className=\"absolute top-3 right-3\"\n                onClick={() => setDrawer(false)}\n                size=\"icon-sm\"\n                variant=\"ghost\"\n              >\n                <XIcon />\n              </Button>\n              {sidebar(\"drawer\")}\n            </motion.div>\n          </>\n        )}\n      </AnimatePresence>\n\n      <div className=\"relative flex min-w-0 flex-1 flex-col\">\n        <header className=\"flex h-12 shrink-0 items-center gap-2 border-b px-3 @4xl:hidden\">\n          <Button aria-label=\"Open navigation\" onClick={() => setDrawer(true)} size=\"icon-sm\" variant=\"ghost\">\n            <MenuIcon />\n          </Button>\n          <span className=\"font-heading font-semibold\">{productName}</span>\n          <span className=\"truncate text-muted-foreground\">/ {viewLabel}</span>\n          <Avatar className=\"ms-auto [--avatar-size:--spacing(7)]\">\n            <AvatarFallback className=\"bg-teal-500/20 text-xs dark:bg-teal-400/20\">{initials(userName)}</AvatarFallback>\n          </Avatar>\n        </header>\n\n        <div className=\"min-h-0 flex-1 overflow-y-auto\" ref={scrollRef}>\n          <motion.div\n            animate={{ opacity: 1 }}\n            className=\"flex flex-col gap-5 px-4 pt-5 pb-10 @4xl:px-6 @4xl:pt-6\"\n            initial={hasSwitchedView.current && !reduce ? { opacity: 0 } : false}\n            key={view}\n            transition={{ duration: 0.15, ease: easeOut }}\n          >\n            <div className=\"flex flex-col gap-1\">\n              <h2 className=\"text-balance font-heading font-semibold text-xl tracking-tight\">\n                {view === \"overview\" ? `Evening, ${firstName}` : viewLabel}\n              </h2>\n              <p className=\"text-pretty text-muted-foreground\">\n                {view === \"bills\" ? (\n                  <>\n                    {openBills.length\n                      ? `${openBills.length} ${openBills.length === 1 ? \"bill\" : \"bills\"} due in the next two weeks.`\n                      : \"Nothing left to pay this cycle.\"}\n                  </>\n                ) : view === \"transactions\" ? (\n                  <>\n                    {visibleTx.length} {visibleTx.length === 1 ? \"transaction\" : \"transactions\"}\n                    {selected ? ` on ${selected.name}` : \" across all accounts\"}.\n                  </>\n                ) : (\n                  <>\n                    {daysLeft} days left in {monthName}. You’ve spent{\" \"}\n                    <span className=\"text-foreground\">\n                      <Tween format={money0} value={spent} />\n                    </span>{\" \"}\n                    and brought in{\" \"}\n                    <span className=\"text-foreground\">\n                      <Tween format={money0} value={income} />\n                    </span>\n                    .\n                  </>\n                )}\n              </p>\n            </div>\n\n            {view === \"overview\" ? (\n              <div className=\"flex flex-col gap-4 @5xl:grid @5xl:grid-cols-[minmax(0,1fr)_minmax(0,320px)] @5xl:items-start @5xl:gap-5\">\n                <div className=\"contents @5xl:flex @5xl:flex-col @5xl:gap-5\">\n                  {balanceSection}\n                  {spendingSection}\n                  {txSection}\n                </div>\n                <div className=\"contents @5xl:flex @5xl:flex-col @5xl:gap-5\">\n                  {budgetsSection}\n                  {billsSection}\n                </div>\n              </div>\n            ) : view === \"transactions\" ? (\n              <div className=\"flex max-w-3xl flex-col gap-4\">{txSection}</div>\n            ) : view === \"bills\" ? (\n              <div className=\"flex max-w-xl flex-col gap-4\">{billsSection}</div>\n            ) : (\n              <div className=\"flex max-w-3xl flex-col gap-4\">\n                {budgetsSection}\n                {spendingSection}\n              </div>\n            )}\n          </motion.div>\n        </div>\n      </div>\n    </div>\n  );\n}\nfunction PayButton({ state, onPay, name }: { state?: \"paying\" | \"paid\"; onPay: () => void; name: string }) {\n  const reduce = useReducedMotion();\n  return (\n    <button\n      aria-label={state === \"paid\" ? `${name} paid` : `Pay ${name}`}\n      className={cn(\n        \"relative -my-1 flex h-6 min-w-12 cursor-pointer items-center justify-center overflow-hidden rounded-full px-2 font-medium text-xs outline-none after:absolute after:-inset-x-1 after:-inset-y-2 after:content-[''] focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default\",\n        press,\n        state === \"paid\"\n          ? \"text-success-foreground\"\n          : \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n      )}\n      disabled={Boolean(state)}\n      onClick={onPay}\n      type=\"button\"\n    >\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        <motion.span\n          animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n          className=\"flex items-center gap-1\"\n          exit={reduce ? { opacity: 0 } : { opacity: 0, y: -6, filter: \"blur(2px)\" }}\n          initial={reduce ? { opacity: 0 } : { opacity: 0, y: 6, filter: \"blur(2px)\" }}\n          key={state ?? \"idle\"}\n          transition={{ duration: 0.18, ease: easeOut }}\n        >\n          {state === \"paid\" ? (\n            <>\n              <CheckIcon className=\"size-3\" /> Paid\n            </>\n          ) : state === \"paying\" ? (\n            <span aria-hidden className=\"flex gap-0.5\">\n              {[0, 1, 2].map((i) => (\n                <motion.span\n                  animate={reduce ? undefined : { opacity: [0.3, 1, 0.3] }}\n                  className=\"size-1 rounded-full bg-current\"\n                  key={i}\n                  transition={{ duration: 0.8, repeat: Number.POSITIVE_INFINITY, delay: i * 0.12, ease: \"linear\" }}\n                />\n              ))}\n            </span>\n          ) : (\n            \"Pay\"\n          )}\n        </motion.span>\n      </AnimatePresence>\n    </button>\n  );\n}\n\nfunction BalanceChart({ series, today }: { series: number[]; today: string }) {\n  const reduce = useReducedMotion();\n  const gid = `bal-${useId().replace(/:/g, \"\")}`;\n  const [hover, setHover] = useState<number | null>(null);\n  const W = 600;\n  const H = 120;\n  const pad = 10;\n  const min = Math.min(...series);\n  const max = Math.max(...series);\n  const span = max - min || 1;\n  const x = (i: number) => (i / (series.length - 1)) * W;\n  const y = (v: number) => pad + (1 - (v - min) / span) * (H - pad - 30);\n  const line = series\n    .map((v, i) => {\n      const px = x(i).toFixed(1);\n      const py = y(v).toFixed(1);\n      if (!i) return `M${px} ${py}`;\n      const cx = ((x(i - 1) + x(i)) / 2).toFixed(1);\n      return `C${cx} ${y(series[i - 1]).toFixed(1)} ${cx} ${py} ${px} ${py}`;\n    })\n    .join(\" \");\n  const area = `${line} L${W} ${H} L0 ${H} Z`;\n\n  const onMove = (e: PointerEvent<SVGSVGElement>) => {\n    const r = e.currentTarget.getBoundingClientRect();\n    const i = Math.round(((e.clientX - r.left) / r.width) * (series.length - 1));\n    setHover(Math.max(0, Math.min(series.length - 1, i)));\n  };\n  const dateFor = (i: number) => {\n    const d = new Date(`${today}T12:00:00`);\n    d.setDate(d.getDate() - (series.length - 1 - i));\n    return d.toLocaleDateString(\"en-US\", { month: \"short\", day: \"numeric\" });\n  };\n  const morph = reduce ? { duration: 0 } : { duration: 0.45, ease: easeOut };\n  const hi = hover ?? null;\n\n  return (\n    <div className=\"relative mt-4 h-36 text-foreground\">\n      <svg\n        aria-label=\"Balance over the last 30 days\"\n        className=\"absolute inset-0 size-full touch-pan-y overflow-visible\"\n        onPointerLeave={() => setHover(null)}\n        onPointerMove={onMove}\n        preserveAspectRatio=\"none\"\n        role=\"img\"\n        viewBox={`0 0 ${W} ${H}`}\n      >\n        <defs>\n          <linearGradient id={gid} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\">\n            <stop offset=\"0%\" stopColor=\"currentColor\" stopOpacity=\"0.1\" />\n            <stop offset=\"100%\" stopColor=\"currentColor\" stopOpacity=\"0\" />\n          </linearGradient>\n        </defs>\n        <motion.path animate={{ d: area }} fill={`url(#${gid})`} initial={false} transition={morph} />\n        <motion.path\n          animate={{ d: line }}\n          fill=\"none\"\n          initial={false}\n          stroke=\"currentColor\"\n          strokeLinejoin=\"round\"\n          strokeOpacity={0.8}\n          strokeWidth={1.75}\n          transition={morph}\n          vectorEffect=\"non-scaling-stroke\"\n        />\n        {hi !== null && (\n          <line\n            stroke=\"currentColor\"\n            strokeDasharray=\"3 3\"\n            strokeOpacity={0.3}\n            vectorEffect=\"non-scaling-stroke\"\n            x1={x(hi)}\n            x2={x(hi)}\n            y1={0}\n            y2={H}\n          />\n        )}\n      </svg>\n      <div aria-hidden className=\"pointer-events-none absolute inset-x-4 bottom-2 flex justify-between text-[11px] text-muted-foreground tabular-nums @lg:inset-x-5\">\n        <span>{dateFor(0)}</span>\n        <span>{dateFor(Math.floor((series.length - 1) / 2))}</span>\n        <span>Today</span>\n      </div>\n      {hi !== null && (\n        <>\n          <span\n            aria-hidden\n            className=\"pointer-events-none absolute size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-foreground ring-2 ring-card\"\n            style={{ left: `${(hi / (series.length - 1)) * 100}%`, top: `${(y(series[hi]) / H) * 100}%` }}\n          />\n          <span\n            className=\"pointer-events-none absolute top-1 rounded-md border bg-popover px-2 py-1 text-xs shadow-xs/5\"\n            style={{\n              left: `clamp(0.5rem, calc(${(hi / (series.length - 1)) * 100}% - 3.5rem), calc(100% - 7.5rem))`,\n            }}\n          >\n            <span className=\"text-muted-foreground\">{dateFor(hi)}</span>{\" \"}\n            <span className=\"font-medium tabular-nums\">{money(series[hi])}</span>\n          </span>\n        </>\n      )}\n    </div>\n  );\n}\n\nfunction Donut({\n  parts,\n  total,\n  focus,\n  onFocus,\n  onPick,\n}: {\n  parts: { cat: MoneyCategory; value: number }[];\n  total: number;\n  focus: MoneyCategory | null;\n  onFocus: (c: MoneyCategory | null) => void;\n  onPick: (c: MoneyCategory) => void;\n}) {\n  const reduce = useReducedMotion();\n  const gap = 1.4;\n  let start = 0;\n  const focused = parts.find((p) => p.cat === focus);\n  return (\n    <div className=\"relative size-40 shrink-0\">\n      <svg aria-hidden className=\"size-full -rotate-90\" viewBox=\"0 0 120 120\">\n        <circle className=\"stroke-muted\" cx=\"60\" cy=\"60\" fill=\"none\" r=\"48\" strokeWidth=\"14\" />\n        {parts.map((p) => {\n          const pct = (p.value / (total || 1)) * 100;\n          const dash = Math.max(pct - gap, 0.5);\n          const offset = -start;\n          start += pct;\n          return (\n            <motion.circle\n              animate={{ strokeDasharray: `${dash} ${100 - dash}`, strokeDashoffset: offset, opacity: !focus || focus === p.cat ? 1 : 0.3 }}\n              className={cn(\"cursor-pointer\", categories[p.cat].stroke)}\n              cx=\"60\"\n              cy=\"60\"\n              fill=\"none\"\n              initial={false}\n              key={p.cat}\n              onClick={() => onPick(p.cat)}\n              onPointerEnter={() => onFocus(p.cat)}\n              onPointerLeave={() => onFocus(null)}\n              pathLength={100}\n              r=\"48\"\n              strokeWidth=\"14\"\n              style={{ pointerEvents: \"stroke\" }}\n              transition={reduce ? { duration: 0 } : { duration: 0.35, ease: easeOut }}\n            />\n          );\n        })}\n      </svg>\n      <div className=\"pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center\">\n        <span className=\"text-muted-foreground text-xs\">{focused ? categories[focused.cat].label : \"Spent\"}</span>\n        <span className=\"font-heading font-semibold text-lg tracking-tight\">\n          <Tween format={money0} value={focused ? focused.value : total} />\n        </span>\n      </div>\n    </div>\n  );\n}\n\nfunction BudgetRow({\n  category,\n  spent,\n  limit,\n  pace,\n  onPick,\n}: {\n  category: MoneyCategory;\n  spent: number;\n  limit: number;\n  pace: number;\n  onPick: () => void;\n}) {\n  const reduce = useReducedMotion();\n  const c = categories[category];\n  const ratio = spent / limit;\n  const over = ratio > 1;\n  const ahead = !over && ratio > pace + 0.08;\n  const left = limit - spent;\n  return (\n    <button\n      aria-label={`${c.label}: ${money0(spent)} of ${money0(limit)}${over ? `, ${money0(-left)} over` : `, ${money0(left)} left`}`}\n      className={cn(\n        \"flex w-full cursor-pointer items-center gap-3 rounded-xl px-2 py-2.5 text-left outline-none hover:bg-accent/60 focus-visible:ring-2 focus-visible:ring-ring\",\n        press,\n      )}\n      onClick={onPick}\n      type=\"button\"\n    >\n      <span className={cn(\"flex size-8 shrink-0 items-center justify-center rounded-lg\", c.tile)}>\n        <c.icon aria-hidden className=\"size-4\" />\n      </span>\n      <span className=\"flex min-w-0 flex-1 flex-col gap-2\">\n        <span className=\"flex items-baseline justify-between gap-2\">\n          <span className=\"truncate font-medium\">{c.label}</span>\n          <span className=\"shrink-0 text-xs tabular-nums\">\n            <span className=\"font-medium text-foreground\">\n              <Tween format={money0} value={spent} />\n            </span>\n            <span className=\"text-muted-foreground\"> of {money0(limit)}</span>\n          </span>\n        </span>\n        <span className=\"relative h-1.5 rounded-full bg-muted\">\n          <motion.span\n            animate={{ scaleX: Math.min(ratio, 1) }}\n            className={cn(\n              \"absolute inset-0 origin-left rounded-full\",\n              over ? \"bg-destructive\" : ahead ? \"bg-warning\" : c.dot,\n            )}\n            initial={false}\n            transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 160, damping: 26 }}\n          />\n          <span aria-hidden className=\"absolute -top-1 -bottom-1 w-px bg-foreground/40\" style={{ left: `${pace * 100}%` }} />\n        </span>\n        <span className={cn(\"text-xs tabular-nums\", over ? \"text-destructive-foreground\" : ahead ? \"text-warning-foreground\" : \"text-muted-foreground\")}>\n          {over ? `${money0(-left)} over budget` : ahead ? `${money0(left)} left · spending fast` : `${money0(left)} left`}\n        </span>\n      </span>\n    </button>\n  );\n}\n"
    }
  ]
}