{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-calendar-month",
  "type": "registry:component",
  "title": "App Calendar Month",
  "description": "A month calendar with colored event chips, a highlighted today, an event popover, sliding month changes and an agenda panel for the selected day.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "app-ui",
    "calendar",
    "month",
    "events",
    "agenda",
    "schedule",
    "popover"
  ],
  "docs": "https://hyperblur.dev/effects/app-calendar-month",
  "files": [
    {
      "path": "registry/hyperblur/app-calendar-month.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/app-calendar-month.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface AppCalendarEvent {\n  id: string;\n  date: string;\n  title: string;\n  time?: string;\n  end?: string;\n  color?: string;\n  calendar?: string;\n  location?: string;\n  people?: string[];\n}\n\nexport interface AppCalendarMonthProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  events?: AppCalendarEvent[];\n  today?: string;\n  defaultMonth?: string;\n  weekStartsOn?: 0 | 1;\n  accent?: string;\n  onMonthChange?: (month: string) => void;\n  onDateSelect?: (date: string) => void;\n  onEventOpen?: (event: AppCalendarEvent) => void;\n  onCreateEvent?: (date: string) => void;\n}\n\nconst colors: Record<string, string> = {\n  blue: \"#2f7bff\",\n  violet: \"#9b6bff\",\n  emerald: \"#22c08a\",\n  amber: \"#f2a93b\",\n  coral: \"#ff6f5e\",\n  cyan: \"#22b8d6\",\n  pink: \"#ec5f9c\",\n};\n\nconst defaultEvents: AppCalendarEvent[] = [\n  { id: \"e1\", date: \"2026-11-02\", time: \"09:30\", end: \"10:00\", title: \"Weekly planning\", color: \"blue\", calendar: \"Team\", location: \"Room Atlas\", people: [\"Maya Okafor\", \"Lena Park\", \"Diego Ramos\"] },\n  { id: \"e2\", date: \"2026-11-03\", time: \"14:00\", end: \"15:00\", title: \"Design critique\", color: \"violet\", calendar: \"Design\", location: \"Video call\", people: [\"Amara Chen\", \"Maya Okafor\"] },\n  { id: \"e3\", date: \"2026-11-04\", time: \"10:00\", end: \"10:45\", title: \"Pricing review\", color: \"amber\", calendar: \"Growth\", location: \"Room Lisbon\", people: [\"Tom Whitaker\", \"Lena Park\", \"Maya Okafor\"] },\n  { id: \"e4\", date: \"2026-11-04\", time: \"13:00\", end: \"14:00\", title: \"Lunch with Sofia\", color: \"emerald\", calendar: \"Personal\", location: \"Taberna Sal\", people: [\"Sofia Lind\"] },\n  { id: \"e5\", date: \"2026-11-04\", time: \"16:30\", end: \"17:00\", title: \"1:1 with Diego\", color: \"blue\", calendar: \"Team\", location: \"Video call\", people: [\"Diego Ramos\"] },\n  { id: \"e6\", date: \"2026-11-04\", time: \"18:00\", end: \"19:00\", title: \"Climbing\", color: \"coral\", calendar: \"Personal\", location: \"Bloc Lab\" },\n  { id: \"e7\", date: \"2026-11-06\", time: \"11:00\", end: \"12:00\", title: \"Customer call: Arcadia\", color: \"cyan\", calendar: \"Sales\", location: \"Video call\", people: [\"Kenji Mori\", \"Maya Okafor\"] },\n  { id: \"e8\", date: \"2026-11-09\", time: \"09:30\", end: \"10:00\", title: \"Weekly planning\", color: \"blue\", calendar: \"Team\", location: \"Room Atlas\" },\n  { id: \"e9\", date: \"2026-11-11\", time: \"15:00\", end: \"16:30\", title: \"Brand workshop\", color: \"violet\", calendar: \"Design\", location: \"Studio 2\", people: [\"Sofia Lind\", \"Amara Chen\"] },\n  { id: \"e10\", date: \"2026-11-12\", title: \"v2.15 release\", color: \"emerald\", calendar: \"Product\" },\n  { id: \"e11\", date: \"2026-11-13\", time: \"19:30\", end: \"22:00\", title: \"Team dinner\", color: \"coral\", calendar: \"Team\", location: \"Cervejaria Ramiro\" },\n  { id: \"e12\", date: \"2026-11-16\", time: \"09:30\", end: \"10:00\", title: \"Weekly planning\", color: \"blue\", calendar: \"Team\", location: \"Room Atlas\" },\n  { id: \"e13\", date: \"2026-11-18\", time: \"10:00\", end: \"17:00\", title: \"Offsite day one\", color: \"amber\", calendar: \"Team\", location: \"Sintra\" },\n  { id: \"e14\", date: \"2026-11-19\", time: \"10:00\", end: \"15:00\", title: \"Offsite day two\", color: \"amber\", calendar: \"Team\", location: \"Sintra\" },\n  { id: \"e15\", date: \"2026-11-20\", time: \"12:00\", end: \"13:00\", title: \"Board update\", color: \"cyan\", calendar: \"Company\", location: \"Video call\" },\n  { id: \"e16\", date: \"2026-11-23\", time: \"09:30\", end: \"10:00\", title: \"Weekly planning\", color: \"blue\", calendar: \"Team\" },\n  { id: \"e17\", date: \"2026-11-25\", time: \"14:00\", end: \"15:00\", title: \"Hiring panel\", color: \"pink\", calendar: \"Hiring\", location: \"Room Porto\" },\n  { id: \"e18\", date: \"2026-11-27\", title: \"Mom's birthday\", color: \"emerald\", calendar: \"Personal\" },\n  { id: \"e19\", date: \"2026-11-30\", time: \"09:30\", end: \"10:00\", title: \"Weekly planning\", color: \"blue\", calendar: \"Team\" },\n  { id: \"e20\", date: \"2026-10-27\", time: \"11:00\", end: \"12:00\", title: \"Roadmap review\", color: \"violet\", calendar: \"Product\" },\n  { id: \"e21\", date: \"2026-10-30\", time: \"17:00\", end: \"18:00\", title: \"Halloween demo day\", color: \"coral\", calendar: \"Team\" },\n  { id: \"e22\", date: \"2026-12-02\", time: \"10:00\", end: \"11:00\", title: \"Q1 kickoff prep\", color: \"amber\", calendar: \"Growth\" },\n  { id: \"e23\", date: \"2026-12-08\", time: \"14:00\", end: \"15:00\", title: \"Design critique\", color: \"violet\", calendar: \"Design\" },\n  { id: \"e24\", date: \"2026-12-18\", time: \"18:00\", end: \"23:00\", title: \"Holiday party\", color: \"pink\", calendar: \"Company\", location: \"LX Factory\" },\n];\n\nconst monthNames = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"];\nconst dayNames = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"];\nconst palette = [\"#2f7bff\", \"#9b6bff\", \"#ff7a59\", \"#22b07d\", \"#e0a526\", \"#e5508a\"];\n\nfunction pad(n: number) {\n  return n < 10 ? `0${n}` : `${n}`;\n}\nfunction key(y: number, m: number, d: number) {\n  return `${y}-${pad(m + 1)}-${pad(d)}`;\n}\nfunction parse(s: string) {\n  const [y, m, d] = s.split(\"-\").map(Number);\n  return { y, m: (m || 1) - 1, d: d || 1 };\n}\nfunction daysIn(y: number, m: number) {\n  return [31, (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0 ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][m];\n}\nfunction weekday(y: number, m: number, d: number) {\n  const t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];\n  const yy = m < 2 ? y - 1 : y;\n  return (yy + Math.floor(yy / 4) - Math.floor(yy / 100) + Math.floor(yy / 400) + t[m] + d) % 7;\n}\nfunction shift(s: string, days: number) {\n  let { y, m, d } = parse(s);\n  d += days;\n  while (d < 1) {\n    m -= 1;\n    if (m < 0) { m = 11; y -= 1; }\n    d += daysIn(y, m);\n  }\n  while (d > daysIn(y, m)) {\n    d -= daysIn(y, m);\n    m += 1;\n    if (m > 11) { m = 0; y += 1; }\n  }\n  return key(y, m, d);\n}\nfunction hash(s: string) {\n  let h = 0;\n  for (let i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) | 0;\n  return h >>> 0;\n}\nfunction fmtTime(t?: string) {\n  if (!t) return \"All day\";\n  const [h, mm] = t.split(\":\").map(Number);\n  const suffix = h >= 12 ? \"pm\" : \"am\";\n  const hh = h % 12 === 0 ? 12 : h % 12;\n  return mm ? `${hh}:${pad(mm)}${suffix}` : `${hh}${suffix}`;\n}\nfunction colorOf(c?: string) {\n  if (!c) return colors.blue;\n  return colors[c] ?? c;\n}\nfunction longDate(s: string) {\n  const { y, m, d } = parse(s);\n  return `${dayNames[weekday(y, m, d)]}, ${monthNames[m].slice(0, 3)} ${d}`;\n}\n\nconst css = `\n.hb-ye3 {\n  --hb-ye3-accent: #2f7bff;\n  container-type: inline-size;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  min-height: 600px;\n  overflow: hidden;\n  border: 1px solid rgba(255,255,255,.08);\n  border-radius: 16px;\n  background: #0a0a0a;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 14px;\n  line-height: 1.4;\n}\n.hb-ye3 *, .hb-ye3 *::before, .hb-ye3 *::after { box-sizing: border-box; }\n.hb-ye3-shell { display: grid; grid-template-columns: 1fr; min-height: 600px; }\n.hb-ye3-main { display: flex; flex-direction: column; min-width: 0; padding: 18px; }\n.hb-ye3-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }\n.hb-ye3-title { margin: 0 auto 0 0; font-size: 20px; font-weight: 600; letter-spacing: -.015em; }\n.hb-ye3-title span { color: #737373; font-weight: 400; }\n.hb-ye3-nav { display: flex; align-items: center; gap: 2px; padding: 3px; border: 1px solid rgba(255,255,255,.08); border-radius: 10px; background: #101010; }\n.hb-ye3-ib { display: inline-grid; place-items: center; min-width: 30px; height: 28px; margin: 0; padding: 0 9px; border: 0; border-radius: 7px; background: transparent; color: #d4d4d4; font: inherit; font-size: 13px; cursor: pointer; }\n.hb-ye3-ib:hover { background: #1c1c1c; color: #fff; }\n.hb-ye3-ib svg { width: 16px; height: 16px; }\n.hb-ye3-ib:focus-visible, .hb-ye3-day:focus-visible, .hb-ye3-chip:focus-visible, .hb-ye3-btn:focus-visible, .hb-ye3-ag:focus-visible { outline: 2px solid var(--hb-ye3-accent); outline-offset: 1px; }\n.hb-ye3-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; margin: 0; padding: 0 12px; border: 1px solid transparent; border-radius: 9px; background: var(--hb-ye3-accent); color: #fff; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }\n.hb-ye3-btn:hover { filter: brightness(1.1); }\n.hb-ye3-btn svg { width: 15px; height: 15px; }\n.hb-ye3-btn[data-tone=\"ghost\"] { border-color: #262626; background: #141414; color: #ededed; font-weight: 500; }\n.hb-ye3-wk { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid rgba(255,255,255,.08); border-bottom: 0; border-radius: 12px 12px 0 0; background: #0f0f0f; }\n.hb-ye3-wk span { padding: 8px 10px; color: #737373; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }\n.hb-ye3-gridwrap { position: relative; flex: 1; display: flex; min-height: 0; border: 1px solid rgba(255,255,255,.08); border-radius: 0 0 12px 12px; overflow: hidden; }\n.hb-ye3-grid { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: minmax(76px, 1fr); }\n.hb-ye3-grid[data-dir=\"1\"] { animation: hb-ye3-from-r .38s cubic-bezier(.2,.8,.2,1) both; }\n.hb-ye3-grid[data-dir=\"-1\"] { animation: hb-ye3-from-l .38s cubic-bezier(.2,.8,.2,1) both; }\n.hb-ye3-cell { position: relative; display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 6px; border-right: 1px solid rgba(255,255,255,.06); border-bottom: 1px solid rgba(255,255,255,.06); background: #0a0a0a; transition: background-color .15s ease; }\n.hb-ye3-cell:nth-child(7n) { border-right: 0; }\n.hb-ye3-cell[data-out=\"true\"] { background: #0c0c0c; }\n.hb-ye3-cell[data-out=\"true\"] .hb-ye3-day { color: #4a4a4a; }\n.hb-ye3-cell[data-weekend=\"true\"] { background: #0c0c0c; }\n.hb-ye3-cell[data-selected=\"true\"] { background: color-mix(in srgb, var(--hb-ye3-accent) 7%, #0a0a0a); }\n.hb-ye3-cell:hover { background: #101010; }\n.hb-ye3-day { align-self: flex-start; display: grid; place-items: center; min-width: 26px; height: 26px; margin: 0; padding: 0 6px; border: 0; border-radius: 999px; background: transparent; color: #a1a1a1; font: inherit; font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; cursor: pointer; }\n.hb-ye3-day:hover { background: #1c1c1c; color: #fff; }\n.hb-ye3-cell[data-selected=\"true\"] .hb-ye3-day { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-ye3-accent) 60%, transparent); color: #fff; }\n.hb-ye3-cell[data-today=\"true\"] .hb-ye3-day { background: var(--hb-ye3-accent); color: #fff; font-weight: 700; box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-ye3-accent) 25%, transparent); }\n.hb-ye3-chip { display: flex; align-items: center; gap: 5px; width: 100%; min-width: 0; margin: 0; padding: 2px 6px 2px 5px; border: 0; border-radius: 5px; background: color-mix(in srgb, var(--c) 16%, transparent); color: color-mix(in srgb, var(--c) 55%, #fff); font: inherit; font-size: 11.5px; text-align: left; cursor: pointer; box-shadow: inset 2px 0 0 var(--c); transition: background-color .15s ease, transform .15s ease; }\n.hb-ye3-chip:hover { background: color-mix(in srgb, var(--c) 26%, transparent); }\n.hb-ye3-chip[aria-expanded=\"true\"] { background: var(--c); color: #fff; }\n.hb-ye3-chip b { flex: none; font-weight: 500; opacity: .75; font-variant-numeric: tabular-nums; }\n.hb-ye3-chip span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }\n.hb-ye3-more { padding: 0 6px; color: #8f8f8f; font-size: 11px; }\n.hb-ye3-pop { position: absolute; z-index: 5; width: 260px; padding: 14px; border: 1px solid rgba(255,255,255,.1); border-radius: 12px; background: #171717; box-shadow: 0 22px 50px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.05); animation: hb-ye3-pop .18s cubic-bezier(.2,.9,.2,1) both; }\n.hb-ye3-pop:focus { outline: none; }\n.hb-ye3-pop-head { display: flex; gap: 10px; align-items: flex-start; }\n.hb-ye3-pop-bar { width: 4px; align-self: stretch; flex: none; border-radius: 4px; background: var(--c); }\n.hb-ye3-pop-title { flex: 1; font-size: 15px; font-weight: 600; line-height: 1.3; }\n.hb-ye3-pop-row { display: flex; align-items: center; gap: 8px; margin-top: 9px; color: #a1a1a1; font-size: 12.5px; }\n.hb-ye3-pop-row svg { width: 14px; height: 14px; flex: none; color: #737373; }\n.hb-ye3-people { display: flex; margin-top: 12px; }\n.hb-ye3-av { display: grid; place-items: center; width: 24px; height: 24px; margin-left: -6px; border: 2px solid #171717; border-radius: 999px; color: #fff; font-size: 9.5px; font-weight: 700; }\n.hb-ye3-av:first-child { margin-left: 0; }\n.hb-ye3-pop-actions { display: flex; gap: 6px; margin-top: 14px; }\n.hb-ye3-pop-actions .hb-ye3-btn { height: 30px; flex: 1; justify-content: center; }\n.hb-ye3-side { display: none; flex-direction: column; gap: 18px; min-width: 0; padding: 18px; border-left: 1px solid rgba(255,255,255,.08); background: #0d0d0d; }\n.hb-ye3-side-h { display: flex; align-items: baseline; justify-content: space-between; }\n.hb-ye3-side-day { font-size: 15px; font-weight: 600; }\n.hb-ye3-side-n { color: #737373; font-size: 12px; }\n.hb-ye3-agenda { display: flex; flex-direction: column; gap: 6px; }\n.hb-ye3-ag { display: grid; grid-template-columns: 4px 1fr; gap: 10px; width: 100%; margin: 0; padding: 9px 10px; border: 1px solid rgba(255,255,255,.06); border-radius: 10px; background: #121212; color: inherit; font: inherit; text-align: left; cursor: pointer; animation: hb-ye3-rise .35s cubic-bezier(.2,.8,.2,1) both; }\n.hb-ye3-ag:hover { border-color: rgba(255,255,255,.12); background: #151515; }\n.hb-ye3-ag i { border-radius: 4px; background: var(--c); }\n.hb-ye3-ag-t { font-size: 13px; font-weight: 500; }\n.hb-ye3-ag-m { color: #8f8f8f; font-size: 12px; }\n.hb-ye3-none { padding: 14px; border: 1px dashed #262626; border-radius: 10px; color: #737373; font-size: 12.5px; text-align: center; }\n.hb-ye3-label { color: #737373; font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }\n.hb-ye3-cals { display: flex; flex-direction: column; gap: 7px; }\n.hb-ye3-cal { display: flex; align-items: center; gap: 9px; color: #d4d4d4; font-size: 13px; }\n.hb-ye3-cal i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }\n.hb-ye3-cal span { margin-left: auto; color: #737373; font-size: 12px; font-variant-numeric: tabular-nums; }\n@keyframes hb-ye3-from-r { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }\n@keyframes hb-ye3-from-l { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }\n@keyframes hb-ye3-pop { from { opacity: 0; transform: var(--t) translateY(4px) scale(.97); } to { opacity: 1; transform: var(--t); } }\n@keyframes hb-ye3-rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }\n.hb-ye3-pop { transform: var(--t); }\n@container (max-width: 560px) {\n  .hb-ye3-chip b, .hb-ye3-wk span { font-size: 10px; }\n  .hb-ye3-chip span { display: none; }\n  .hb-ye3-chip { height: 6px; padding: 0; }\n  .hb-ye3-grid { grid-auto-rows: minmax(58px, 1fr); }\n  .hb-ye3-pop { width: 220px; }\n}\n@container (min-width: 820px) {\n  .hb-ye3-shell { grid-template-columns: 1fr 268px; }\n  .hb-ye3-side { display: flex; }\n  .hb-ye3-main { padding: 20px 22px; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ye3 *, .hb-ye3 *::before, .hb-ye3 *::after { animation: none !important; transition: none !important; }\n}\n`;\n\nfunction Icon({ d }: { d: string }) {\n  return (\n    <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={d} />\n    </svg>\n  );\n}\n\nexport function AppCalendarMonth({\n  events = defaultEvents,\n  today = \"2026-11-04\",\n  defaultMonth,\n  weekStartsOn = 1,\n  accent = \"#2f7bff\",\n  onMonthChange,\n  onDateSelect,\n  onEventOpen,\n  onCreateEvent,\n  className,\n  style,\n  ...rest\n}: AppCalendarMonthProps) {\n  const start = parse(defaultMonth ? `${defaultMonth}-01` : today);\n  const [month, setMonth] = React.useState({ y: start.y, m: start.m });\n  const [dir, setDir] = React.useState(0);\n  const [selected, setSelected] = React.useState(today);\n  const [openEvent, setOpenEvent] = React.useState<string | null>(null);\n  const dayRefs = React.useRef<Map<string, HTMLButtonElement>>(new Map());\n  const chipRefs = React.useRef<Map<string, HTMLButtonElement>>(new Map());\n  const popRef = React.useRef<HTMLDivElement>(null);\n  const pendingFocus = React.useRef<string | null>(null);\n\n  const byDate = React.useMemo(() => {\n    const map = new Map<string, AppCalendarEvent[]>();\n    for (const e of events) {\n      const list = map.get(e.date) ?? [];\n      list.push(e);\n      map.set(e.date, list);\n    }\n    for (const list of map.values()) list.sort((a, b) => (a.time ?? \"00:00\").localeCompare(b.time ?? \"00:00\"));\n    return map;\n  }, [events]);\n\n  const cells = React.useMemo(() => {\n    const lead = (weekday(month.y, month.m, 1) - weekStartsOn + 7) % 7;\n    const total = Math.ceil((lead + daysIn(month.y, month.m)) / 7) * 7;\n    const first = shift(key(month.y, month.m, 1), -lead);\n    return Array.from({ length: total }, (_, i) => shift(first, i));\n  }, [month, weekStartsOn]);\n\n  React.useEffect(() => {\n    if (pendingFocus.current) {\n      dayRefs.current.get(pendingFocus.current)?.focus();\n      pendingFocus.current = null;\n    }\n  });\n\n  React.useEffect(() => {\n    if (!openEvent) return;\n    popRef.current?.focus();\n    const close = (e: PointerEvent) => {\n      const t = e.target as HTMLElement;\n      if (popRef.current?.contains(t) || t.closest?.(\"[data-hb-ye3-chip]\")) return;\n      setOpenEvent(null);\n    };\n    document.addEventListener(\"pointerdown\", close);\n    return () => document.removeEventListener(\"pointerdown\", close);\n  }, [openEvent]);\n\n  const goMonth = (delta: number, focusDate?: string) => {\n    let m = month.m + delta;\n    let y = month.y;\n    if (m < 0) { m = 11; y -= 1; }\n    if (m > 11) { m = 0; y += 1; }\n    setDir(delta > 0 ? 1 : -1);\n    setMonth({ y, m });\n    setOpenEvent(null);\n    onMonthChange?.(`${y}-${pad(m + 1)}`);\n    if (focusDate) pendingFocus.current = focusDate;\n  };\n\n  const goToday = () => {\n    const t = parse(today);\n    const delta = (t.y - month.y) * 12 + (t.m - month.m);\n    if (delta !== 0) {\n      setDir(delta > 0 ? 1 : -1);\n      setMonth({ y: t.y, m: t.m });\n      onMonthChange?.(`${t.y}-${pad(t.m + 1)}`);\n    }\n    setSelected(today);\n    setOpenEvent(null);\n  };\n\n  const select = (date: string) => {\n    setSelected(date);\n    onDateSelect?.(date);\n    const p = parse(date);\n    if (p.m !== month.m || p.y !== month.y) goMonth((p.y - month.y) * 12 + (p.m - month.m) > 0 ? 1 : -1, date);\n  };\n\n  const onDayKey = (e: React.KeyboardEvent, date: string) => {\n    const step: Record<string, number> = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -7, ArrowDown: 7 };\n    if (e.key in step) {\n      e.preventDefault();\n      const next = shift(date, step[e.key]);\n      setSelected(next);\n      onDateSelect?.(next);\n      const p = parse(next);\n      if (p.m !== month.m || p.y !== month.y) goMonth(step[e.key] > 0 ? 1 : -1, next);\n      else pendingFocus.current = next;\n    } else if (e.key === \"PageDown\" || e.key === \"PageUp\") {\n      e.preventDefault();\n      goMonth(e.key === \"PageDown\" ? 1 : -1);\n    }\n  };\n\n  const openChip = (ev: AppCalendarEvent) => {\n    setOpenEvent(openEvent === ev.id ? null : ev.id);\n    if (openEvent !== ev.id) onEventOpen?.(ev);\n  };\n\n  const closePop = () => {\n    const id = openEvent;\n    setOpenEvent(null);\n    if (id) chipRefs.current.get(id)?.focus();\n  };\n\n  const rows = cells.length / 7;\n  const popIndex = openEvent ? cells.findIndex((c) => byDate.get(c)?.some((e) => e.id === openEvent)) : -1;\n  const popEvent = openEvent ? events.find((e) => e.id === openEvent) : undefined;\n  let popStyle: React.CSSProperties | undefined;\n  if (popIndex >= 0) {\n    const col = popIndex % 7;\n    const row = Math.floor(popIndex / 7);\n    const right = col >= 4;\n    const low = row >= rows - 2;\n    popStyle = {\n      left: right ? `calc(${((col / 7) * 100).toFixed(3)}% - 6px)` : `calc(${(((col + 1) / 7) * 100).toFixed(3)}% + 6px)`,\n      top: low ? `calc(${(((row + 1) / rows) * 100).toFixed(3)}% - 6px)` : `calc(${((row / rows) * 100).toFixed(3)}% + 6px)`,\n      \"--t\": `translate(${right ? \"-100%\" : \"0\"}, ${low ? \"-100%\" : \"0\"})`,\n      \"--c\": colorOf(popEvent?.color),\n    } as React.CSSProperties;\n  }\n\n  const order = weekStartsOn === 1 ? [1, 2, 3, 4, 5, 6, 0] : [0, 1, 2, 3, 4, 5, 6];\n  const dayEvents = byDate.get(selected) ?? [];\n  const upcoming = events.filter((e) => e.date > selected).sort((a, b) => (a.date + (a.time ?? \"\")).localeCompare(b.date + (b.time ?? \"\"))).slice(0, 4);\n  const monthPrefix = `${month.y}-${pad(month.m + 1)}`;\n  const calCounts = new Map<string, { color: string; n: number }>();\n  for (const e of events) {\n    if (!e.date.startsWith(monthPrefix)) continue;\n    const name = e.calendar ?? \"Calendar\";\n    const c = calCounts.get(name) ?? { color: colorOf(e.color), n: 0 };\n    c.n += 1;\n    calCounts.set(name, c);\n  }\n\n  return (\n    <div className={[\"hb-ye3\", className].filter(Boolean).join(\" \")} style={{ \"--hb-ye3-accent\": accent, ...style } as React.CSSProperties} {...rest}>\n      <style href=\"hb-app-calendar-month\" precedence=\"default\">{css}</style>\n      <div className=\"hb-ye3-shell\">\n        <section className=\"hb-ye3-main\" aria-label=\"Month calendar\">\n          <div className=\"hb-ye3-bar\">\n            <h2 className=\"hb-ye3-title\" aria-live=\"polite\">{monthNames[month.m]} <span>{month.y}</span></h2>\n            <button type=\"button\" className=\"hb-ye3-btn\" data-tone=\"ghost\" onClick={goToday}>Today</button>\n            <div className=\"hb-ye3-nav\">\n              <button type=\"button\" className=\"hb-ye3-ib\" aria-label=\"Previous month\" onClick={() => goMonth(-1)}><Icon d=\"M15 18l-6-6 6-6\" /></button>\n              <button type=\"button\" className=\"hb-ye3-ib\" aria-label=\"Next month\" onClick={() => goMonth(1)}><Icon d=\"M9 6l6 6-6 6\" /></button>\n            </div>\n            <button type=\"button\" className=\"hb-ye3-btn\" onClick={() => onCreateEvent?.(selected)}><Icon d=\"M12 5v14M5 12h14\" />New event</button>\n          </div>\n          <div className=\"hb-ye3-wk\" aria-hidden=\"true\">\n            {order.map((d) => <span key={d}>{dayNames[d].slice(0, 3)}</span>)}\n          </div>\n          <div className=\"hb-ye3-gridwrap\">\n            <div className=\"hb-ye3-grid\" key={monthPrefix} data-dir={dir} role=\"grid\" aria-label={`${monthNames[month.m]} ${month.y}`}>\n              {Array.from({ length: rows }, (_, r) => (\n                <div role=\"row\" key={r} style={{ display: \"contents\" }}>\n                  {cells.slice(r * 7, r * 7 + 7).map((date) => {\n                    const p = parse(date);\n                    const list = byDate.get(date) ?? [];\n                    const wd = weekday(p.y, p.m, p.d);\n                    const shown = list.slice(0, rows > 5 ? 2 : 3);\n                    return (\n                      <div\n                        key={date}\n                        role=\"gridcell\"\n                        className=\"hb-ye3-cell\"\n                        data-out={p.m !== month.m}\n                        data-today={date === today}\n                        data-selected={date === selected}\n                        data-weekend={wd === 0 || wd === 6}\n                        aria-selected={date === selected}\n                      >\n                        <button\n                          type=\"button\"\n                          className=\"hb-ye3-day\"\n                          ref={(el) => { if (el) dayRefs.current.set(date, el); else dayRefs.current.delete(date); }}\n                          tabIndex={date === selected ? 0 : -1}\n                          aria-label={`${longDate(date)}${list.length ? `, ${list.length} event${list.length > 1 ? \"s\" : \"\"}` : \"\"}`}\n                          aria-current={date === today ? \"date\" : undefined}\n                          onClick={() => select(date)}\n                          onKeyDown={(e) => onDayKey(e, date)}\n                        >\n                          {p.d}\n                        </button>\n                        {shown.map((ev) => (\n                          <button\n                            key={ev.id}\n                            type=\"button\"\n                            data-hb-ye3-chip=\"\"\n                            ref={(el) => { if (el) chipRefs.current.set(ev.id, el); else chipRefs.current.delete(ev.id); }}\n                            className=\"hb-ye3-chip\"\n                            style={{ \"--c\": colorOf(ev.color) } as React.CSSProperties}\n                            aria-haspopup=\"dialog\"\n                            aria-expanded={openEvent === ev.id}\n                            aria-label={`${ev.title}, ${fmtTime(ev.time)}`}\n                            onClick={() => openChip(ev)}\n                          >\n                            {ev.time && <b>{fmtTime(ev.time)}</b>}\n                            <span>{ev.title}</span>\n                          </button>\n                        ))}\n                        {list.length > shown.length && <span className=\"hb-ye3-more\">+{list.length - shown.length} more</span>}\n                      </div>\n                    );\n                  })}\n                </div>\n              ))}\n            </div>\n            {popEvent && popStyle && (\n              <div\n                ref={popRef}\n                className=\"hb-ye3-pop\"\n                role=\"dialog\"\n                aria-label={popEvent.title}\n                tabIndex={-1}\n                style={popStyle}\n                onKeyDown={(e) => { if (e.key === \"Escape\") { e.stopPropagation(); closePop(); } }}\n              >\n                <div className=\"hb-ye3-pop-head\">\n                  <span className=\"hb-ye3-pop-bar\" />\n                  <div className=\"hb-ye3-pop-title\">{popEvent.title}</div>\n                  <button type=\"button\" className=\"hb-ye3-ib\" aria-label=\"Close\" onClick={closePop}><Icon d=\"M6 6l12 12M18 6 6 18\" /></button>\n                </div>\n                <div className=\"hb-ye3-pop-row\"><Icon d=\"M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-13v4l3 2\" />{longDate(popEvent.date)} · {popEvent.time ? `${fmtTime(popEvent.time)} to ${fmtTime(popEvent.end)}` : \"All day\"}</div>\n                {popEvent.location && <div className=\"hb-ye3-pop-row\"><Icon d=\"M12 21s7-6.2 7-11.5a7 7 0 1 0-14 0C5 14.8 12 21 12 21Zm0-9a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5Z\" />{popEvent.location}</div>}\n                {popEvent.calendar && <div className=\"hb-ye3-pop-row\"><Icon d=\"M4 6h16v14H4V6Zm0 4h16M9 3v4m6-4v4\" />{popEvent.calendar} calendar</div>}\n                {popEvent.people && popEvent.people.length > 0 && (\n                  <div className=\"hb-ye3-people\" aria-label={popEvent.people.join(\", \")}>\n                    {popEvent.people.map((p) => (\n                      <span key={p} className=\"hb-ye3-av\" title={p} style={{ background: palette[hash(p) % palette.length] }}>\n                        {p.split(\" \").map((w) => w[0]).join(\"\").slice(0, 2)}\n                      </span>\n                    ))}\n                  </div>\n                )}\n                <div className=\"hb-ye3-pop-actions\">\n                  {popEvent.location === \"Video call\" && <button type=\"button\" className=\"hb-ye3-btn\">Join call</button>}\n                  <button type=\"button\" className=\"hb-ye3-btn\" data-tone=\"ghost\">Edit</button>\n                </div>\n              </div>\n            )}\n          </div>\n        </section>\n        <aside className=\"hb-ye3-side\" aria-label=\"Agenda\">\n          <div>\n            <div className=\"hb-ye3-side-h\">\n              <span className=\"hb-ye3-side-day\">{selected === today ? \"Today\" : longDate(selected)}</span>\n              <span className=\"hb-ye3-side-n\">{dayEvents.length ? `${dayEvents.length} event${dayEvents.length > 1 ? \"s\" : \"\"}` : \"Free\"}</span>\n            </div>\n            {selected === today && <div className=\"hb-ye3-side-n\" style={{ marginTop: 2 }}>{longDate(today)}</div>}\n          </div>\n          <div className=\"hb-ye3-agenda\" key={selected}>\n            {dayEvents.length === 0 && <div className=\"hb-ye3-none\">Nothing scheduled. Enjoy the focus time.</div>}\n            {dayEvents.map((ev, i) => (\n              <button key={ev.id} type=\"button\" className=\"hb-ye3-ag\" style={{ \"--c\": colorOf(ev.color), animationDelay: `${(i * 0.05).toFixed(2)}s` } as React.CSSProperties} onClick={() => { const p = parse(ev.date); if (p.m === month.m && p.y === month.y) setOpenEvent(ev.id); onEventOpen?.(ev); }}>\n                <i />\n                <span>\n                  <span className=\"hb-ye3-ag-t\" style={{ display: \"block\" }}>{ev.title}</span>\n                  <span className=\"hb-ye3-ag-m\">{ev.time ? `${fmtTime(ev.time)} to ${fmtTime(ev.end)}` : \"All day\"}{ev.location ? ` · ${ev.location}` : \"\"}</span>\n                </span>\n              </button>\n            ))}\n          </div>\n          {upcoming.length > 0 && (\n            <div className=\"hb-ye3-agenda\">\n              <div className=\"hb-ye3-label\">Coming up</div>\n              {upcoming.map((ev) => (\n                <button key={ev.id} type=\"button\" className=\"hb-ye3-ag\" style={{ \"--c\": colorOf(ev.color) } as React.CSSProperties} onClick={() => select(ev.date)}>\n                  <i />\n                  <span>\n                    <span className=\"hb-ye3-ag-t\" style={{ display: \"block\" }}>{ev.title}</span>\n                    <span className=\"hb-ye3-ag-m\">{longDate(ev.date)} · {fmtTime(ev.time)}</span>\n                  </span>\n                </button>\n              ))}\n            </div>\n          )}\n          {calCounts.size > 0 && (\n            <div className=\"hb-ye3-cals\">\n              <div className=\"hb-ye3-label\">This month</div>\n              {[...calCounts].slice(0, 5).map(([name, c]) => (\n                <div key={name} className=\"hb-ye3-cal\" style={{ \"--c\": c.color } as React.CSSProperties}><i />{name}<span>{c.n}</span></div>\n              ))}\n            </div>\n          )}\n        </aside>\n      </div>\n    </div>\n  );\n}\n\nexport default AppCalendarMonth;\n"
    }
  ]
}