{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"searchable-faq-accordion","type":"registry:component","title":"Searchable FAQ Accordion","description":"An FAQ with live search that highlights matches, topic chips with a sliding indicator and counts, height-animated answers, a plus-to-minus icon morph, deep-link anchors with a copy-link button, a designed empty state and a full keyboard model.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/searchable-faq-accordion.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type {\n  CSSProperties,\n  KeyboardEvent as ReactKeyboardEvent,\n  PointerEvent as ReactPointerEvent,\n} from \"react\";\n\nexport type Faq = { q: string; a: string; category?: string };\n\nexport type SearchableFaqAccordionProps = {\n  /** Question and answer pairs. Add a `category` to any entry to get topic chips. */\n  faqs?: Faq[];\n  searchPlaceholder?: string;\n  /** Panel surface: \"dark\" (default) or \"light\". */\n  tone?: \"dark\" | \"light\";\n  /** Hex colour for highlights, chips and the focus ring. */\n  accent?: string;\n  /** Indexes (into faqs) that start open. */\n  defaultOpen?: number[];\n  /** false = opening one answer closes the others. */\n  allowMultiple?: boolean;\n  /** Read #anchors on load, show a copy-link button in each answer. */\n  deepLink?: boolean;\n  /** Write the open answer's anchor to the URL hash when it opens (default off). */\n  syncHash?: boolean;\n  /** Prefix for answer anchors, e.g. #faq-how-do-i-install-it. */\n  idPrefix?: string;\n  /** Show the topic chips when the entries carry categories. */\n  showCategories?: boolean;\n  /** Replaces the default width class (max-w-md). */\n  className?: string;\n};\n\nconst DEFAULT_FAQS: Faq[] = [\n  {\n    q: \"How do I install it?\",\n    a: \"Copy the file into your project and import it. There is no package to add and no build step beyond what React and Tailwind already give you.\",\n    category: \"Setup\",\n  },\n  {\n    q: \"Does it work with Next.js?\",\n    a: \"Yes. It is a client component with no browser-only code at module scope, so it renders on the server and hydrates cleanly.\",\n    category: \"Setup\",\n  },\n  {\n    q: \"Can I change the colors?\",\n    a: \"Pass an accent color and choose a dark or light tone. The surface paints itself, so it does not depend on your theme tokens.\",\n    category: \"Style\",\n  },\n  {\n    q: \"How do I add my own questions?\",\n    a: \"Give it an array of question and answer pairs. Add a category to any entry and the topic chips appear on their own.\",\n    category: \"Style\",\n  },\n  {\n    q: \"Is it keyboard friendly?\",\n    a: \"Every question is a real button. Arrow keys move between questions, slash jumps to the search field and Escape clears it. Motion switches off when the system asks for less of it.\",\n    category: \"Usage\",\n  },\n  {\n    q: \"Can I link to one answer?\",\n    a: \"Yes. Each answer has its own anchor, so a link opens the page with that answer already expanded. Use the copy link button inside any open answer.\",\n    category: \"Usage\",\n  },\n];\n\nconst NO_OPEN: number[] = [];\nconst ACCENT_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;\nconst ACCENT_DEFAULT = { dark: \"#8aa0ff\", light: \"#3347d4\" };\n\nconst slugify = (s: string) =>\n  s\n    .toLowerCase()\n    .replace(/[^a-z0-9]+/g, \"-\")\n    .replace(/^-+|-+$/g, \"\")\n    .slice(0, 48);\nconst escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\nconst CSS = `\n.sfa{container-type:inline-size;--sfa-ring:var(--sfa-accent);font-family:inherit;text-align:left;-webkit-font-smoothing:antialiased}\n.sfa[data-tone=\"dark\"]{--sfa-bg:#0b0c10;--sfa-text:#f2f3f6;--sfa-muted:rgba(232,236,246,.62);--sfa-faint:rgba(232,236,246,.38);--sfa-line:rgba(255,255,255,.08);--sfa-hover:rgba(255,255,255,.035);--sfa-open:rgba(255,255,255,.03);--sfa-field:rgba(255,255,255,.05);--sfa-shadow:0 1px 0 rgba(255,255,255,.07) inset,0 0 0 1px rgba(255,255,255,.07),0 28px 70px -28px rgba(0,0,0,.85)}\n.sfa[data-tone=\"light\"]{--sfa-bg:#ffffff;--sfa-text:#0f1222;--sfa-muted:rgba(15,18,34,.64);--sfa-faint:rgba(15,18,34,.42);--sfa-line:rgba(15,18,34,.09);--sfa-hover:rgba(15,18,34,.03);--sfa-open:rgba(15,18,34,.02);--sfa-field:rgba(15,18,34,.04);--sfa-shadow:0 0 0 1px rgba(15,18,34,.08),0 1px 2px rgba(15,18,34,.05),0 24px 56px -30px rgba(15,18,34,.28)}\n.sfa *{box-sizing:border-box}\n.sfa-surface{position:relative;isolation:isolate;overflow:hidden;border-radius:20px;background:var(--sfa-bg);color:var(--sfa-text);box-shadow:var(--sfa-shadow)}\n.sfa-glow{position:absolute;inset:0;z-index:-1;pointer-events:none;opacity:0;transition:opacity .5s ease;background:radial-gradient(380px circle at var(--sfa-x,50%) var(--sfa-y,0%),color-mix(in srgb,var(--sfa-accent) 15%,transparent),transparent 72%)}\n@media (hover:hover){.sfa-surface:hover .sfa-glow{opacity:1}}\n.sfa-head{padding:14px 14px 10px}\n.sfa-field{display:flex;align-items:center;gap:10px;height:48px;padding:0 10px 0 14px;border-radius:14px;background:var(--sfa-field);box-shadow:inset 0 0 0 1px var(--sfa-line);transition:box-shadow .25s ease}\n.sfa-field:focus-within{box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--sfa-accent) 65%,transparent),0 0 0 4px color-mix(in srgb,var(--sfa-accent) 16%,transparent)}\n.sfa-si{flex:none;width:16px;height:16px;color:var(--sfa-faint);transition:color .25s ease}\n.sfa-field:focus-within .sfa-si{color:var(--sfa-accent)}\n.sfa .sfa-input{flex:1;min-width:0;height:100%;padding:0;margin:0;border:0;background:transparent;color:var(--sfa-text);font:inherit;font-size:15px;letter-spacing:-.005em;outline:none!important;box-shadow:none;-webkit-appearance:none;appearance:none;border-radius:0!important}\n.sfa .sfa-input::placeholder{color:var(--sfa-faint);opacity:1}\n.sfa .sfa-input::-webkit-search-cancel-button,.sfa .sfa-input::-webkit-search-decoration{-webkit-appearance:none;display:none}\n.sfa-kbd{flex:none;font:500 11px/1 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:var(--sfa-faint);padding:5px 7px;border-radius:7px;box-shadow:inset 0 0 0 1px var(--sfa-line);transition:opacity .2s ease}\n.sfa-field:focus-within .sfa-kbd{opacity:0}\n.sfa-x{flex:none;display:grid;place-items:center;width:28px;height:28px;padding:0;border:0;border-radius:999px;background:transparent;color:var(--sfa-muted);cursor:pointer;transition:background .2s ease,color .2s ease}\n.sfa-x:hover{background:var(--sfa-line);color:var(--sfa-text)}\n.sfa-x svg{width:14px;height:14px}\n.sfa-chipwrap{padding:0 14px 8px}\n.sfa-chips{position:relative;display:flex;gap:6px;padding:2px;margin:-2px;overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch}\n.sfa-chips::-webkit-scrollbar{display:none}\n.sfa-ind{position:absolute;top:2px;left:0;height:32px;width:0;border-radius:999px;pointer-events:none;opacity:0;background:color-mix(in srgb,var(--sfa-accent) 16%,transparent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--sfa-accent) 45%,transparent)}\n.sfa-ind[data-ready]{transition:transform .42s cubic-bezier(.32,.72,0,1),width .42s cubic-bezier(.32,.72,0,1),opacity .2s ease}\n.sfa-chip{position:relative;z-index:1;flex:none;display:inline-flex;align-items:center;height:32px;padding:0 13px;border:0;border-radius:999px;background:transparent;color:var(--sfa-muted);font:inherit;font-size:12.5px;font-weight:500;letter-spacing:.005em;cursor:pointer;box-shadow:inset 0 0 0 1px var(--sfa-line);transition:color .2s ease,background .2s ease,transform .2s ease;-webkit-tap-highlight-color:transparent}\n.sfa-chip:hover{color:var(--sfa-text);background:var(--sfa-hover)}\n.sfa-chip:active{transform:scale(.96)}\n.sfa-chip[data-active=\"true\"]{color:var(--sfa-text);box-shadow:none;background:transparent}\n.sfa-chip[data-dim=\"true\"]{opacity:.45}\n.sfa-n{margin-left:7px;font-size:11px;font-variant-numeric:tabular-nums;opacity:.6}\n.sfa .sfa-chip:focus-visible,.sfa .sfa-link:focus-visible,.sfa .sfa-x:focus-visible,.sfa .sfa-copy:focus-visible,.sfa .sfa-empty-btn:focus-visible{outline:2px solid var(--sfa-ring)!important;outline-offset:2px!important;border-radius:999px}\n.sfa-meta{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:6px 18px 10px;min-height:34px}\n.sfa-count{margin:0;font-size:12px;color:var(--sfa-faint);font-variant-numeric:tabular-nums}\n.sfa-link{padding:4px 2px;border:0;background:transparent;color:var(--sfa-muted);font:inherit;font-size:12px;cursor:pointer;transition:color .2s ease}\n.sfa-link:hover{color:var(--sfa-accent)}\n.sfa-list{border-top:1px solid var(--sfa-line)}\n.sfa-item{position:relative;animation:sfa-in .44s cubic-bezier(.22,1,.36,1) both;animation-delay:calc(var(--i,0)*34ms)}\n.sfa-item+.sfa-item{border-top:1px solid var(--sfa-line)}\n.sfa-item::before{content:\"\";position:absolute;left:0;top:12px;bottom:12px;width:2px;border-radius:2px;background:var(--sfa-accent);box-shadow:0 0 14px var(--sfa-accent);transform:scaleY(0);transform-origin:50% 50%;transition:transform .42s cubic-bezier(.32,.72,0,1)}\n.sfa-item[data-open=\"true\"]::before{transform:scaleY(1)}\n.sfa-item[data-open=\"true\"]{background:var(--sfa-open)}\n@keyframes sfa-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}\n.sfa-h{margin:0;font:inherit}\n.sfa-trigger{display:flex;align-items:center;gap:14px;width:100%;min-height:58px;padding:14px 16px 14px 18px;border:0;background:transparent;color:inherit;font:inherit;text-align:left;cursor:pointer;transition:background .2s ease;-webkit-tap-highlight-color:transparent}\n.sfa-trigger:hover{background:var(--sfa-hover)}\n.sfa .sfa-trigger:focus-visible{outline:2px solid var(--sfa-ring)!important;outline-offset:-2px!important;border-radius:0!important;background:var(--sfa-hover)}\n.sfa-q{flex:1;min-width:0;font-size:15px;font-weight:550;line-height:1.35;letter-spacing:-.01em;color:var(--sfa-text)}\n.sfa-tag{flex:none;display:none;font-size:10.5px;font-weight:500;letter-spacing:.09em;text-transform:uppercase;color:var(--sfa-faint)}\n.sfa-tag[data-hit=\"true\"]{display:inline-flex;align-items:center;gap:6px;color:var(--sfa-accent);letter-spacing:.06em}\n.sfa-tag[data-hit=\"true\"]::before{content:\"\";width:5px;height:5px;border-radius:99px;background:var(--sfa-accent)}\n@container (min-width:520px){.sfa-tag{display:inline-flex}}\n.sfa-icon{position:relative;flex:none;width:28px;height:28px;border-radius:999px;box-shadow:inset 0 0 0 1px var(--sfa-line);color:var(--sfa-muted);transition:transform .5s cubic-bezier(.34,1.4,.64,1),background .3s ease,color .3s ease,box-shadow .3s ease}\n.sfa-icon i{position:absolute;left:50%;top:50%;width:11px;height:1.5px;margin:0;border-radius:2px;background:currentColor;transform:translate(-50%,-50%);transition:transform .5s cubic-bezier(.34,1.4,.64,1)}\n.sfa-icon i+i{transform:translate(-50%,-50%) rotate(90deg)}\n.sfa-trigger:hover .sfa-icon{color:var(--sfa-text)}\n.sfa-item[data-open=\"true\"] .sfa-icon{transform:rotate(180deg);color:var(--sfa-accent);background:color-mix(in srgb,var(--sfa-accent) 14%,transparent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--sfa-accent) 50%,transparent)}\n.sfa-item[data-open=\"true\"] .sfa-icon i+i{transform:translate(-50%,-50%) rotate(0deg)}\n.sfa-panel{display:grid;grid-template-rows:0fr;visibility:hidden;transition:grid-template-rows .4s cubic-bezier(.32,.72,0,1),visibility 0s linear .4s}\n.sfa-item[data-open=\"true\"] .sfa-panel{grid-template-rows:1fr;visibility:visible;transition:grid-template-rows .4s cubic-bezier(.32,.72,0,1),visibility 0s}\n.sfa-clip{min-height:0;overflow:hidden}\n.sfa-inner{padding:0 62px 18px 18px;opacity:0;transform:translateY(-6px);transition:opacity .2s ease,transform .3s cubic-bezier(.32,.72,0,1)}\n.sfa-item[data-open=\"true\"] .sfa-inner{opacity:1;transform:none;transition:opacity .35s ease .08s,transform .45s cubic-bezier(.22,1,.36,1) .06s}\n.sfa-a{margin:0;max-width:62ch;font-size:14.5px;line-height:1.65;color:var(--sfa-muted)}\n.sfa-mark{padding:0 2px;margin:0 -1px;border-radius:4px;background:color-mix(in srgb,var(--sfa-accent) 28%,transparent);color:inherit;box-shadow:0 0 0 1px color-mix(in srgb,var(--sfa-accent) 22%,transparent);animation:sfa-mark .36s cubic-bezier(.22,1,.36,1) both}\n.sfa-q .sfa-mark{color:var(--sfa-text)}\n@keyframes sfa-mark{from{background-color:color-mix(in srgb,var(--sfa-accent) 60%,transparent)}}\n.sfa-copy{display:inline-flex;align-items:center;gap:7px;height:32px;margin-top:12px;padding:0 12px;border:0;border-radius:999px;background:var(--sfa-field);box-shadow:inset 0 0 0 1px var(--sfa-line);color:var(--sfa-muted);font:inherit;font-size:12px;font-weight:500;cursor:pointer;transition:color .2s ease,background .2s ease,box-shadow .2s ease,transform .2s ease;-webkit-tap-highlight-color:transparent}\n.sfa-copy:hover{color:var(--sfa-text)}\n.sfa-copy:active{transform:scale(.96)}\n.sfa-copy[data-done=\"true\"]{color:var(--sfa-accent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--sfa-accent) 50%,transparent)}\n.sfa-copy svg{width:13px;height:13px}\n.sfa-empty{display:flex;flex-direction:column;align-items:center;padding:34px 24px 38px;text-align:center;animation:sfa-in .5s cubic-bezier(.22,1,.36,1) both}\n.sfa-art{width:84px;height:84px;margin-bottom:16px;color:var(--sfa-faint)}\n.sfa-art .sfa-orbit{transform-origin:42px 42px;animation:sfa-spin 28s linear infinite}\n.sfa-art .sfa-lens{animation:sfa-bob 4.2s ease-in-out infinite}\n@keyframes sfa-spin{to{transform:rotate(360deg)}}\n@keyframes sfa-bob{50%{transform:translate(2px,-3px)}}\n.sfa-empty-t{margin:0;font-size:15px;font-weight:550;letter-spacing:-.01em;color:var(--sfa-text);overflow-wrap:anywhere}\n.sfa-empty-s{margin:6px 0 0;max-width:34ch;font-size:13.5px;line-height:1.55;color:var(--sfa-muted)}\n.sfa-empty-row{display:flex;flex-wrap:wrap;justify-content:center;gap:8px;margin-top:18px}\n.sfa-empty-btn{height:34px;padding:0 14px;border:0;border-radius:999px;background:var(--sfa-field);box-shadow:inset 0 0 0 1px var(--sfa-line);color:var(--sfa-text);font:inherit;font-size:12.5px;font-weight:500;cursor:pointer;transition:background .2s ease,box-shadow .2s ease,transform .2s ease}\n.sfa-empty-btn:hover{box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--sfa-accent) 55%,transparent)}\n.sfa-empty-btn:active{transform:scale(.96)}\n.sfa-empty-btn[data-primary=\"true\"]{background:color-mix(in srgb,var(--sfa-accent) 18%,transparent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--sfa-accent) 50%,transparent)}\n@media (hover:none),(pointer:coarse){\n.sfa-kbd{display:none}\n.sfa .sfa-input{font-size:16px}\n.sfa-field{height:52px}\n.sfa-chip{height:40px}\n.sfa-ind{height:40px}\n.sfa-x{width:40px;height:40px}\n.sfa-link{min-height:40px;padding:0 4px}\n.sfa-copy{height:40px}\n.sfa-empty-btn{height:40px}\n.sfa-trigger{min-height:62px}\n}\n@container (max-width:380px){\n.sfa-q{font-size:14.5px}\n.sfa-trigger{gap:10px;padding-left:14px;padding-right:12px}\n.sfa-inner{padding:0 14px 16px 14px}\n.sfa-head{padding:10px 10px 8px}\n.sfa-chipwrap{padding:0 10px 6px}\n.sfa-meta{padding:4px 14px 8px}\n}\n@media (prefers-reduced-motion:reduce){\n.sfa *,.sfa *::before,.sfa *::after{transition-duration:.01ms!important;transition-delay:0s!important;animation-duration:.01ms!important;animation-delay:0s!important;animation-iteration-count:1!important}\n.sfa-item[data-open=\"true\"] .sfa-icon{transform:none}\n.sfa-item[data-open=\"true\"] .sfa-icon i+i{transform:translate(-50%,-50%) rotate(90deg) scaleX(0)}\n.sfa-inner{transform:none!important}\n}\n`;\n\nfunction Hl({ text, re }: { text: string; re: RegExp | null }) {\n  if (!re) return <>{text}</>;\n  const parts = text.split(re);\n  return (\n    <>\n      {parts.map((p, i) =>\n        i % 2 === 1 ? (\n          <mark key={i} className=\"sfa-mark\">\n            {p}\n          </mark>\n        ) : (\n          p\n        ),\n      )}\n    </>\n  );\n}\n\nexport function SearchableFaqAccordion({\n  faqs = DEFAULT_FAQS,\n  searchPlaceholder = \"Search questions\",\n  tone = \"dark\",\n  accent,\n  defaultOpen = NO_OPEN,\n  allowMultiple = true,\n  deepLink = true,\n  syncHash = false,\n  idPrefix = \"faq\",\n  showCategories = true,\n  className,\n}: SearchableFaqAccordionProps) {\n  const uid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const rootRef = useRef<HTMLDivElement>(null);\n  const inputRef = useRef<HTMLInputElement>(null);\n  const chipsRef = useRef<HTMLDivElement>(null);\n  const indRef = useRef<HTMLSpanElement>(null);\n  const copyTimer = useRef(0);\n  const itemsRef = useRef<{ id: number; anchor: string }[]>([]);\n\n  const [query, setQuery] = useState(\"\");\n  const [cat, setCat] = useState<string | null>(null);\n  const [open, setOpen] = useState<ReadonlySet<number>>(\n    () => new Set(defaultOpen.filter((i) => i >= 0 && i < faqs.length)),\n  );\n  const [copied, setCopied] = useState<number | null>(null);\n  const [announce, setAnnounce] = useState(\"\");\n\n  const items = useMemo(() => {\n    const seen = new Map<string, number>();\n    return faqs.map((f, i) => {\n      let s = slugify(f.q) || \"question\";\n      const n = seen.get(s) ?? 0;\n      seen.set(s, n + 1);\n      if (n > 0) s = s + \"-\" + (n + 1);\n      return {\n        ...f,\n        id: i,\n        anchor: idPrefix + \"-\" + s,\n        hay: (f.q + \" \" + f.a + \" \" + (f.category ?? \"\")).toLowerCase(),\n        qLow: f.q.toLowerCase(),\n      };\n    });\n  }, [faqs, idPrefix]);\n\n  const categories = useMemo(() => {\n    const out: string[] = [];\n    for (const it of items) if (it.category && !out.includes(it.category)) out.push(it.category);\n    return out;\n  }, [items]);\n  const hasChips = showCategories && categories.length > 1;\n  const activeCat = cat !== null && categories.includes(cat) ? cat : null;\n\n  const terms = useMemo(\n    () => Array.from(new Set(query.trim().toLowerCase().split(/\\s+/).filter(Boolean))),\n    [query],\n  );\n  const re = useMemo(\n    () =>\n      terms.length\n        ? new RegExp(\"(\" + [...terms].sort((a, b) => b.length - a.length).map(escapeRe).join(\"|\") + \")\", \"gi\")\n        : null,\n    [terms],\n  );\n  const textMatches = useMemo(() => items.filter((it) => terms.every((t) => it.hay.includes(t))), [items, terms]);\n  const visible = activeCat === null ? textMatches : textMatches.filter((it) => it.category === activeCat);\n  const catCount = (c: string) => textMatches.filter((it) => it.category === c).length;\n\n  const chipSig =\n    String(activeCat) + \"|\" + categories.map((c) => c + \":\" + textMatches.filter((it) => it.category === c).length).join(\"|\") + \"|\" + textMatches.length + \"|\" + hasChips;\n\n  const accentColor = accent && ACCENT_RE.test(accent) ? accent : ACCENT_DEFAULT[tone === \"light\" ? \"light\" : \"dark\"];\n  const vars = { \"--sfa-accent\": accentColor } as CSSProperties;\n\n  useEffect(() => {\n    itemsRef.current = items;\n  }, [items]);\n\n  useEffect(\n    () => () => {\n      window.clearTimeout(copyTimer.current);\n    },\n    [],\n  );\n\n  // Deep links: open the answer named by the URL hash, now and on hashchange.\n  useEffect(() => {\n    if (!deepLink) return;\n    const apply = () => {\n      let h = \"\";\n      try {\n        h = decodeURIComponent(window.location.hash.slice(1));\n      } catch {\n        return;\n      }\n      const it = itemsRef.current.find((x) => x.anchor === h);\n      if (!it) return;\n      setQuery(\"\");\n      setCat(null);\n      setOpen((prev) => (allowMultiple ? new Set(prev).add(it.id) : new Set([it.id])));\n      requestAnimationFrame(() => {\n        const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n        document.getElementById(it.anchor)?.scrollIntoView({ block: \"nearest\", behavior: reduce ? \"auto\" : \"smooth\" });\n      });\n    };\n    const raf = requestAnimationFrame(apply);\n    window.addEventListener(\"hashchange\", apply);\n    return () => {\n      cancelAnimationFrame(raf);\n      window.removeEventListener(\"hashchange\", apply);\n    };\n  }, [deepLink, allowMultiple]);\n\n  // Sliding chip indicator, placed in layout pixels.\n  useEffect(() => {\n    const wrap = chipsRef.current;\n    const ind = indRef.current;\n    if (!wrap || !ind || !hasChips) return;\n    const place = () => {\n      const btn = wrap.querySelector<HTMLElement>('[data-active=\"true\"]');\n      if (!btn) {\n        ind.style.opacity = \"0\";\n        return;\n      }\n      ind.style.opacity = \"1\";\n      ind.style.width = btn.offsetWidth + \"px\";\n      ind.style.transform = \"translateX(\" + btn.offsetLeft + \"px)\";\n    };\n    place();\n    const raf = requestAnimationFrame(() => {\n      ind.setAttribute(\"data-ready\", \"\");\n      const btn = wrap.querySelector<HTMLElement>('[data-active=\"true\"]');\n      if (btn && wrap.scrollWidth > wrap.clientWidth + 1) {\n        const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n        wrap.scrollTo({ left: btn.offsetLeft - (wrap.clientWidth - btn.offsetWidth) / 2, behavior: reduce ? \"auto\" : \"smooth\" });\n      }\n    });\n    const ro = new ResizeObserver(place);\n    ro.observe(wrap);\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n    };\n  }, [chipSig, hasChips]);\n\n  const toggle = (id: number, anchor: string) => {\n    const willOpen = !open.has(id);\n    setOpen((prev) => {\n      if (!allowMultiple) return prev.has(id) ? new Set<number>() : new Set([id]);\n      const next = new Set(prev);\n      if (next.has(id)) next.delete(id);\n      else next.add(id);\n      return next;\n    });\n    if (deepLink && syncHash) {\n      try {\n        const base = window.location.pathname + window.location.search;\n        window.history.replaceState(null, \"\", willOpen ? base + \"#\" + anchor : base);\n      } catch {\n        /* history can be unavailable in sandboxed frames */\n      }\n    }\n  };\n\n  const allOpen = visible.length > 0 && visible.every((it) => open.has(it.id));\n  const toggleAll = () => {\n    setOpen((prev) => {\n      const next = new Set(prev);\n      for (const it of visible) {\n        if (allOpen) next.delete(it.id);\n        else next.add(it.id);\n      }\n      return next;\n    });\n  };\n\n  const copyLink = async (id: number, anchor: string) => {\n    const url = window.location.origin + window.location.pathname + window.location.search + \"#\" + anchor;\n    try {\n      await navigator.clipboard.writeText(url);\n      setCopied(id);\n      setAnnounce(\"Link copied\");\n    } catch {\n      setCopied(id);\n      setAnnounce(\"Link: \" + url);\n    }\n    window.clearTimeout(copyTimer.current);\n    copyTimer.current = window.setTimeout(() => {\n      setCopied(null);\n      setAnnounce(\"\");\n    }, 1800);\n  };\n\n  const onSurfaceMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n    if (e.pointerType === \"touch\") return;\n    const el = e.currentTarget;\n    const r = el.getBoundingClientRect();\n    const k = r.width ? el.offsetWidth / r.width : 1;\n    el.style.setProperty(\"--sfa-x\", ((e.clientX - r.left) * k).toFixed(1) + \"px\");\n    el.style.setProperty(\"--sfa-y\", ((e.clientY - r.top) * k).toFixed(1) + \"px\");\n  };\n\n  const onRootKey = (e: ReactKeyboardEvent<HTMLDivElement>) => {\n    if (e.key !== \"/\" || e.metaKey || e.ctrlKey || e.altKey) return;\n    const t = e.target as HTMLElement;\n    if (t.tagName === \"INPUT\" || t.tagName === \"TEXTAREA\" || t.isContentEditable) return;\n    e.preventDefault();\n    inputRef.current?.focus();\n    inputRef.current?.select();\n  };\n\n  const onListKey = (e: ReactKeyboardEvent<HTMLDivElement>) => {\n    const t = e.target as HTMLElement;\n    if (!t.hasAttribute(\"data-sfa-trigger\")) return;\n    if (![\"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"].includes(e.key)) return;\n    const list = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-sfa-trigger]\") ?? []);\n    const i = list.indexOf(t);\n    e.preventDefault();\n    if (e.key === \"ArrowUp\" && i <= 0) {\n      inputRef.current?.focus();\n      return;\n    }\n    const n = e.key === \"ArrowDown\" ? i + 1 : e.key === \"ArrowUp\" ? i - 1 : e.key === \"Home\" ? 0 : list.length - 1;\n    list[Math.max(0, Math.min(n, list.length - 1))]?.focus();\n  };\n\n  const onInputKey = (e: ReactKeyboardEvent<HTMLInputElement>) => {\n    if (e.key === \"Escape\") {\n      if (query) {\n        e.preventDefault();\n        setQuery(\"\");\n      } else {\n        e.currentTarget.blur();\n      }\n    } else if (e.key === \"ArrowDown\") {\n      const first = rootRef.current?.querySelector<HTMLElement>(\"[data-sfa-trigger]\");\n      if (first) {\n        e.preventDefault();\n        first.focus();\n      }\n    }\n  };\n\n  const clearAll = () => {\n    setQuery(\"\");\n    setCat(null);\n    inputRef.current?.focus();\n  };\n\n  const total = items.length;\n  const status =\n    visible.length === total\n      ? total + (total === 1 ? \" question\" : \" questions\")\n      : visible.length + \" of \" + total + (total === 1 ? \" question\" : \" questions\");\n  const shown = query.trim().length > 30 ? query.trim().slice(0, 30) + \"…\" : query.trim();\n\n  return (\n    <div\n      ref={rootRef}\n      className={\"sfa relative w-full \" + (className ?? \"max-w-md\")}\n      data-tone={tone === \"light\" ? \"light\" : \"dark\"}\n      style={vars}\n      onKeyDown={onRootKey}\n    >\n      <style>{CSS}</style>\n      <div className=\"sfa-surface\" onPointerMove={onSurfaceMove}>\n        <div className=\"sfa-glow\" aria-hidden=\"true\" />\n\n        <div className=\"sfa-head\" role=\"search\">\n          <div className=\"sfa-field\">\n            <svg className=\"sfa-si\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n              <circle cx=\"7\" cy=\"7\" r=\"4.6\" />\n              <path d=\"M10.6 10.6 14 14\" />\n            </svg>\n            <input\n              ref={inputRef}\n              className=\"sfa-input\"\n              type=\"search\"\n              value={query}\n              onChange={(e) => setQuery(e.target.value)}\n              onKeyDown={onInputKey}\n              placeholder={searchPlaceholder}\n              aria-label=\"Search questions\"\n              aria-controls={uid + \"-list\"}\n              autoComplete=\"off\"\n              autoCorrect=\"off\"\n              spellCheck={false}\n              enterKeyHint=\"search\"\n            />\n            {query ? (\n              <button type=\"button\" className=\"sfa-x\" aria-label=\"Clear search\" onClick={() => { setQuery(\"\"); inputRef.current?.focus(); }}>\n                <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                  <path d=\"m3.5 3.5 7 7m0-7-7 7\" />\n                </svg>\n              </button>\n            ) : (\n              <span className=\"sfa-kbd\" aria-hidden=\"true\">/</span>\n            )}\n          </div>\n        </div>\n\n        {hasChips && (\n          <div className=\"sfa-chipwrap\" role=\"group\" aria-label=\"Filter by topic\">\n            <div className=\"sfa-chips\" ref={chipsRef}>\n              <span className=\"sfa-ind\" ref={indRef} aria-hidden=\"true\" />\n              {[\"All\", ...categories].map((c, i) => {\n                const isAll = i === 0;\n                const active = isAll ? activeCat === null : activeCat === c;\n                const n = isAll ? textMatches.length : catCount(c);\n                return (\n                  <button\n                    key={c}\n                    type=\"button\"\n                    className=\"sfa-chip\"\n                    aria-pressed={active}\n                    data-active={active}\n                    data-dim={n === 0 && !active}\n                    onClick={() => setCat(isAll ? null : c)}\n                  >\n                    {c}\n                    <span className=\"sfa-n\">{n}</span>\n                  </button>\n                );\n              })}\n            </div>\n          </div>\n        )}\n\n        <div className=\"sfa-meta\">\n          <p className=\"sfa-count\" aria-live=\"polite\">{total === 0 ? \"No questions\" : status}</p>\n          {allowMultiple && visible.length > 1 && (\n            <button type=\"button\" className=\"sfa-link\" onClick={toggleAll}>\n              {allOpen ? \"Collapse all\" : \"Expand all\"}\n            </button>\n          )}\n        </div>\n\n        <div className=\"sfa-list\" id={uid + \"-list\"} onKeyDown={onListKey}>\n          {visible.length === 0 ? (\n            <div className=\"sfa-empty\" role=\"status\">\n              <svg className=\"sfa-art\" viewBox=\"0 0 84 84\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <circle className=\"sfa-orbit\" cx=\"42\" cy=\"42\" r=\"37\" strokeDasharray=\"2 7\" opacity=\".7\" />\n                <path d=\"M16 30h14M16 42h9M16 54h12\" opacity=\".35\" />\n                <g className=\"sfa-lens\">\n                  <circle cx=\"44\" cy=\"40\" r=\"14\" style={{ stroke: \"var(--sfa-accent)\" }} strokeWidth=\"2\" />\n                  <path d=\"m54.5 50.5 9 9\" style={{ stroke: \"var(--sfa-accent)\" }} strokeWidth=\"2.4\" />\n                  <path d=\"M38.5 40h11\" />\n                </g>\n              </svg>\n              {total === 0 ? (\n                <>\n                  <p className=\"sfa-empty-t\">No questions yet</p>\n                  <p className=\"sfa-empty-s\">Pass an array of question and answer pairs to fill this list.</p>\n                </>\n              ) : (\n                <>\n                  <p className=\"sfa-empty-t\">{shown ? \"Nothing matches “\" + shown + \"”\" : \"Nothing in this topic\"}</p>\n                  <p className=\"sfa-empty-s\">Check the spelling, try fewer words, or browse a topic instead.</p>\n                  <div className=\"sfa-empty-row\">\n                    <button type=\"button\" className=\"sfa-empty-btn\" data-primary=\"true\" onClick={clearAll}>\n                      Clear search\n                    </button>\n                    {categories.slice(0, 3).map((c) => (\n                      <button key={c} type=\"button\" className=\"sfa-empty-btn\" onClick={() => { setQuery(\"\"); setCat(c); }}>\n                        {c}\n                      </button>\n                    ))}\n                  </div>\n                </>\n              )}\n            </div>\n          ) : (\n            visible.map((it, idx) => {\n              const isOpen = open.has(it.id);\n              const panelId = uid + \"-panel-\" + it.id;\n              const triggerId = uid + \"-trigger-\" + it.id;\n              const answerOnly = terms.length > 0 && !terms.every((t) => it.qLow.includes(t));\n              return (\n                <div\n                  key={it.id}\n                  id={deepLink ? it.anchor : undefined}\n                  className=\"sfa-item\"\n                  data-open={isOpen}\n                  style={{ \"--i\": Math.min(idx, 7) } as CSSProperties}\n                >\n                  <div role=\"heading\" aria-level={3} className=\"sfa-h\">\n                    <button\n                      type=\"button\"\n                      id={triggerId}\n                      className=\"sfa-trigger\"\n                      data-sfa-trigger=\"\"\n                      aria-expanded={isOpen}\n                      aria-controls={panelId}\n                      onClick={() => toggle(it.id, it.anchor)}\n                    >\n                      <span className=\"sfa-q\">\n                        <Hl text={it.q} re={re} />\n                      </span>\n                      {answerOnly ? (\n                        <span className=\"sfa-tag\" data-hit=\"true\">in answer</span>\n                      ) : showCategories && it.category ? (\n                        <span className=\"sfa-tag\">{it.category}</span>\n                      ) : null}\n                      <span className=\"sfa-icon\" aria-hidden=\"true\">\n                        <i />\n                        <i />\n                      </span>\n                    </button>\n                  </div>\n                  <div id={panelId} role=\"region\" aria-labelledby={triggerId} className=\"sfa-panel\">\n                    <div className=\"sfa-clip\">\n                      <div className=\"sfa-inner\">\n                        <p className=\"sfa-a\">\n                          <Hl text={it.a} re={re} />\n                        </p>\n                        {deepLink && (\n                          <button\n                            type=\"button\"\n                            className=\"sfa-copy\"\n                            data-done={copied === it.id}\n                            tabIndex={isOpen ? 0 : -1}\n                            onClick={() => copyLink(it.id, it.anchor)}\n                          >\n                            {copied === it.id ? (\n                              <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                                <path d=\"m2.8 7.4 2.7 2.7 5.7-6\" />\n                              </svg>\n                            ) : (\n                              <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                                <path d=\"M5.8 8.2a2.6 2.6 0 0 0 3.7 0l2-2a2.6 2.6 0 0 0-3.7-3.7l-.6.6\" />\n                                <path d=\"M8.2 5.8a2.6 2.6 0 0 0-3.7 0l-2 2a2.6 2.6 0 0 0 3.7 3.7l.6-.6\" />\n                              </svg>\n                            )}\n                            {copied === it.id ? \"Link copied\" : \"Copy link\"}\n                          </button>\n                        )}\n                      </div>\n                    </div>\n                  </div>\n                </div>\n              );\n            })\n          )}\n        </div>\n      </div>\n      <span className=\"sr-only\" role=\"status\" aria-live=\"polite\">{announce}</span>\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/searchable-faq-accordion.tsx"}],"meta":{"tier":"free","tags":["faq","search","accordion","filter","highlight","chips","deep-link","keyboard"],"href":"https://viberdy.dev/library/searchable-faq-accordion","aiPrompt":"Create a dependency-free React + Tailwind \"searchable FAQ accordion\" named SearchableFaqAccordion, a \"use client\" single file. React only: no framer-motion, no icon library (inline SVG).\n\nProps (all optional, keep these defaults): faqs (array of { q, a, category? }; default six generic product questions in three categories Setup / Style / Usage), searchPlaceholder = \"Search questions\", tone = \"dark\" | \"light\" (default \"dark\"), accent (hex only, validated with a regex; default #8aa0ff dark, #3347d4 light), defaultOpen = [] (indexes into faqs), allowMultiple = true (false: opening one closes the rest), deepLink = true, syncHash = false (opt in), idPrefix = \"faq\", showCategories = true, className (replaces the default width class \"max-w-md\"; root is w-full).\n\nSurface: one panel, radius 20px, paints its own colours. Dark: #0b0c10 with a 1px white inset highlight, 1px white/7% ring and a deep drop shadow. Light: white with a 1px slate/8% ring and a soft shadow. Set every colour through CSS variables on the root; inject the CSS with a plain <style> element (class names prefixed sfa-, so they beat the host page's unlayered resets). The root is a size container. A 380px soft radial light in the accent at 15% follows the pointer across the surface (set --sfa-x/--sfa-y in layout pixels, ignore touch) and fades in on hover only on hover devices.\n\nSearch: a 48px field with a search icon, a 15px input (16px on coarse pointers), a \"/\" keycap that fades on focus, and a clear button once there is text. Focus ring is an accent 1px inset line plus a 4px 16% halo on the field (the input itself has no outline). Query is trimmed, lowercased and split on whitespace; an entry survives when every term appears in question + answer + category. Matches are wrapped in <mark> with a 28% accent fill and a 1px 22% ring, flashing from 60% to 28% over 360ms. If a term is missing from the question (matched only in the answer) show a tiny accent \"in answer\" tag on the closed row.\n\nTopic chips (only when there are 2+ categories and showCategories): \"All\" plus each category, 32px pills (40px on coarse) with a tabular-nums count that follows the current search; zero-count chips dim to 45%. One absolutely positioned indicator (accent 16% fill, 45% inset ring) slides under the active chip: translateX/width in layout pixels from offsetLeft/offsetWidth, 420ms cubic-bezier(.32,.72,0,1), no transition on first placement, re-placed by a ResizeObserver. The row scrolls horizontally on phones (hidden scrollbar) and recentres the active chip. Chips are aria-pressed toggles.\n\nMeta row: a polite live count (\"6 questions\" or \"2 of 6 questions\") and an \"Expand all\" / \"Collapse all\" text button when allowMultiple and more than one is visible.\n\nRows: separated by 1px lines, entering with a 440ms cubic-bezier(.22,1,.36,1) rise (8px, opacity) staggered 34ms up to eight rows. Trigger is a real <button> inside role=heading aria-level=3: min-height 58px (62 on coarse), 15px/550 question text, an uppercase 10.5px category tag at container width >= 520px, and a 28px ring icon. Icon morph: two 11x1.5px bars; the second sits at 90deg (a plus). Open: the whole icon rotates 180deg and the second bar rotates to 0deg, becoming a minus, over 500ms cubic-bezier(.34,1.4,.64,1), with an accent-tinted fill and ring. Open rows get a 3% tint and a 2px accent bar with a 14px glow on the left that scales in over 420ms. Hover tints the row 3.5%. Focus-visible is a 2px inset accent outline (use !important; the host may have global focus rules).\n\nPanel: role=region aria-labelledby the trigger, id referenced by aria-controls. Animate by grid-template-rows 0fr -> 1fr over 400ms cubic-bezier(.32,.72,0,1) (child min-height 0, overflow hidden), with visibility hidden after the close delay so closed content leaves the tab order. The inner content fades and rises from -6px (350ms, 80ms delay on open). Answer text 14.5px/1.65 in muted, max 62ch, padding-right 62px.\n\nDeep links: each entry gets an anchor idPrefix + \"-\" + slug(question) (duplicates get -2, -3). The item carries that id. On mount (inside requestAnimationFrame) and on hashchange, a matching hash clears the search and chip, opens that answer and scrolls it into view (smooth unless reduced motion). With syncHash (off by default), opening an answer replaceState's the hash and closing removes it. Each open answer has a 32px \"Copy link\" pill that writes the full URL to the clipboard, swaps to a check and \"Link copied\" for 1.8s, announced through a polite sr-only status.\n\nEmpty state (no results): an 84px SVG of a dashed orbiting ring, three faint list lines and a magnifier with a dash inside it (accent stroke, gently bobbing), the title “Nothing matches “query”” (query truncated to 30 chars), a hint line, a primary \"Clear search\" button and up to three topic buttons. Zero faqs shows \"No questions yet\".\n\nState: open state is a Set of each entry's original index (never the filtered position). Keyboard: Arrow Up/Down, Home, End move between triggers; Arrow Up from the first returns to the search field; Arrow Down in search enters the list; \"/\" (outside inputs) focuses and selects the search field; Escape clears the query, then blurs.\n\nReduced motion: transitions and animations collapse to 0.01ms, the icon does not rotate (the second bar scales away instead), panels still open. Low-width: below 380px container width reduce paddings. Output one self-contained component.","license":"https://viberdy.dev/license"}}