Skip to content
Organisms

Navbar

A site header with a morphing mega menu.

Primitive

Variants

6 more takes on the navbar, each a single file you install on its own by its id.

aui-009Minimal

A compact header with an elastic underline.

$ pnpm dlx asta-ui@latest add navbar-aui-009

Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/navbar-aui-009.json

aui-010Glass pill

A floating pill that follows your pointer.

$ pnpm dlx asta-ui@latest add navbar-aui-010

Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/navbar-aui-010.json

aui-011Wordmark

Dark header with a rippling centred wordmark.

$ pnpm dlx asta-ui@latest add navbar-aui-011

Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/navbar-aui-011.json

aui-012App header

App header with search, workspace, bell and avatar.

$ pnpm dlx asta-ui@latest add navbar-aui-012

Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/navbar-aui-012.json

aui-013Docs header

Docs header with search and a version switch.

$ pnpm dlx asta-ui@latest add navbar-aui-013

Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/navbar-aui-013.json

aui-014Reading

Hides on scroll and shows how far you've read.

$ pnpm dlx asta-ui@latest add navbar-aui-014

Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/navbar-aui-014.json

Installation

Primitive
  1. Run the CLI

    Run pnpm dlx asta-ui@latest init once, then this. The file lands in components/astabyte/, installs radix-ui@base-ui/react and the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.

    $ pnpm dlx asta-ui@latest add navbar --radix

    Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/navbar.json

  2. Or install the package

    Don’t want the file? Import from asta-uiasta-ui/base and update with pnpm update asta-ui. Add the stylesheet once. More.

    $ pnpm add asta-ui radix-ui @base-ui/react
    import { Navbar } from "asta-ui";
    import { Navbar } from "asta-ui/base";
  3. Or copy it by hand

    Install radix-ui@base-ui/react, then copy these files. Keep the paths, or fix the @/ imports. Then add the tokens from globals.css.

    "use client";
    
    import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from "react";
    import { Button } from "@/components/kit/button";
    
    const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
    
    export interface NavTile {
      title: string;
      description?: string;
      href: string;
      icon?: ReactNode;
      /** Big tiles get a small mock preview in the corner. */
      preview?: "chart" | "list" | "code";
    }
    export interface NavMenu {
      /** Panel width in px (clamped to the space available). */
      width?: number;
      /** A plain dropdown: a short list that opens right under its trigger instead of the centred mega panel. */
      list?: NavTile[];
      tiles?: NavTile[];
      columns?: { heading: string; links: NavTile[] }[];
      feature?: { title: string; description: string; href: string; cta: string };
    }
    export interface NavItem {
      label: string;
      href?: string;
      menu?: NavMenu;
    }
    export interface NavbarProps {
      brand: ReactNode;
      brandHref?: string;
      items: NavItem[];
      /** Quiet link that folds away once the page scrolls. */
      docs?: { label: string; href: string };
      cta: { label: string; href: string };
      /** Element whose scroll drives the folded state (defaults to the window). */
      scrollRoot?: RefObject<HTMLElement | null>;
      className?: string;
    }
    
    const RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_12%,transparent)]";
    const EASE = "ease-[cubic-bezier(.16,1,.3,1)]";
    
    const Chevron = ({ className = "" }: { className?: string }) => (
      <svg viewBox="0 0 24 24" className={cx("h-3.5 w-3.5", className)} fill="none" stroke="currentColor" strokeWidth="2.55" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
        <path d="m9.5 6 6 6-6 6" />
      </svg>
    );
    
    /** Abstract UI shapes so big tiles hint at what's behind them. Grey until hovered. */
    function Preview({ kind }: { kind: NonNullable<NavTile["preview"]> }) {
      const bar = "rounded-full bg-[color-mix(in_srgb,var(--color-ink)_12%,transparent)] transition-colors duration-500";
      return (
        <div
          aria-hidden
          className={cx(
            "absolute -bottom-px -right-px h-[46%] w-[72%] rounded-tl-xl bg-paper p-3 transition-transform duration-500 group-hover/tile:-translate-x-1 group-hover/tile:-translate-y-1",
            RING,
            EASE,
          )}
        >
          {kind === "chart" && (
            <div className="flex h-full items-end gap-1.5">
              {[40, 64, 52, 80, 70, 96].map((h, i) => (
                <span key={i} className={cx(bar, "w-full rounded-[3px] group-hover/tile:bg-brand")} style={{ height: `${h}%`, transitionDelay: `${i * 40}ms` }} />
              ))}
            </div>
          )}
          {kind === "list" && (
            <div className="flex flex-col gap-2">
              {[80, 56, 68].map((w, i) => (
                <div key={i} className="flex items-center gap-2">
                  <span className={cx(bar, "h-3 w-3 shrink-0 group-hover/tile:bg-brand")} style={{ transitionDelay: `${i * 60}ms` }} />
                  <span className={cx(bar, "h-1.5")} style={{ width: `${w}%` }} />
                </div>
              ))}
            </div>
          )}
          {kind === "code" && (
            <div className="flex flex-col gap-1.5 font-mono">
              {[
                [20, 50],
                [36, 30],
                [28, 44],
                [20, 24],
              ].map(([a, b], i) => (
                <div key={i} className="flex gap-1.5">
                  <span className={cx(bar, "h-1.5 group-hover/tile:bg-brand")} style={{ width: `${a}%`, transitionDelay: `${i * 50}ms` }} />
                  <span className={cx(bar, "h-1.5")} style={{ width: `${b}%` }} />
                </div>
              ))}
            </div>
          )}
        </div>
      );
    }
    
    function Tile({ tile, big }: { tile: NavTile; big: boolean }) {
      return (
        <a
          href={tile.href}
          data-kit-nav-link
          className={cx(
            "group/tile relative flex flex-col gap-1.5 overflow-hidden rounded-[10px] bg-paper-2 p-4 outline-none transition-[opacity,background-color] duration-300",
            "group-has-[a:hover]/menu:opacity-55 hover:!opacity-100 focus-visible:ring-2 focus-visible:ring-brand/50",
            big ? "min-h-[184px]" : "min-h-[92px]",
          )}
        >
          <span className="flex items-center gap-2 text-[14px] font-medium tracking-[-0.01em] text-ink">
            {tile.icon && (
              <span className={cx("flex h-6 w-6 items-center justify-center rounded-md bg-paper text-ink [&_svg]:h-3.5 [&_svg]:w-3.5", RING)}>{tile.icon}</span>
            )}
            {tile.title}
            <Chevron className={cx("-translate-x-0.5 text-mute transition-[translate,color] duration-300 group-hover/tile:translate-x-0 group-hover/tile:text-ink", EASE)} />
          </span>
          {tile.description && <span className={cx("text-[12.5px] leading-snug text-mute", big && "max-w-[22ch]")}>{tile.description}</span>}
          {big && tile.preview && <Preview kind={tile.preview} />}
        </a>
      );
    }
    
    function List({ links }: { links: NavTile[] }) {
      return (
        <div className="flex flex-col gap-0.5 p-1.5">
          {links.map((l) => (
            <a
              key={l.title}
              href={l.href}
              data-kit-nav-link
              className="group/item flex items-start gap-3 rounded-lg px-2.5 py-2 outline-none transition-colors duration-150 hover:bg-paper-2 focus-visible:bg-paper-2"
            >
              {l.icon && (
                <span className={cx("mt-px flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-paper text-mute transition-colors duration-150 group-hover/item:text-ink [&_svg]:h-3.5 [&_svg]:w-3.5", RING)}>
                  {l.icon}
                </span>
              )}
              <span className="flex min-w-0 flex-col">
                <span className="text-[13.5px] font-medium text-ink">{l.title}</span>
                {l.description && <span className="text-[12px] leading-snug text-mute">{l.description}</span>}
              </span>
            </a>
          ))}
        </div>
      );
    }
    
    function Panel({ menu }: { menu: NavMenu }) {
      if (menu.list) return <List links={menu.list} />;
      const tiles = menu.tiles ?? [];
      const big = tiles.some((t) => t.preview);
      return (
        <div className="group/menu flex flex-col gap-2 p-2">
          {tiles.length > 0 && (
            <div className="grid gap-2" style={{ gridTemplateColumns: `repeat(${tiles.length === 4 ? 2 : tiles.length}, minmax(0, 1fr))` }}>
              {tiles.map((t) => (
                <Tile key={t.title} tile={t} big={big} />
              ))}
            </div>
          )}
          {(menu.columns || menu.feature) && (
            <div className="grid gap-2" style={{ gridTemplateColumns: `repeat(${(menu.columns?.length ?? 0) + (menu.feature ? 1 : 0)}, minmax(0, 1fr))` }}>
              {menu.columns?.map((col) => (
                <div key={col.heading} className="flex flex-col gap-0.5 p-2">
                  <span className="mb-1.5 px-2 text-[11.5px] text-mute">{col.heading}</span>
                  {col.links.map((l) => (
                    <a
                      key={l.title}
                      href={l.href}
                      data-kit-nav-link
                      className="group/link flex flex-col rounded-lg px-2 py-1.5 outline-none transition-[background-color,opacity] duration-200 hover:bg-paper-2 focus-visible:bg-paper-2 group-has-[a:hover]/menu:opacity-60 hover:!opacity-100"
                    >
                      <span className="flex items-center gap-1 text-[13.5px] font-medium text-ink">
                        {l.title}
                        <Chevron className={cx("h-3 w-3 -translate-x-1 text-mute opacity-0 transition-[translate,opacity] duration-300 group-hover/link:translate-x-0 group-hover/link:opacity-100", EASE)} />
                      </span>
                      {l.description && <span className="text-[12px] leading-snug text-mute">{l.description}</span>}
                    </a>
                  ))}
                </div>
              ))}
              {menu.feature && (
                <a
                  href={menu.feature.href}
                  data-kit-nav-link
                  className="group/feat relative flex min-h-[200px] flex-col justify-end overflow-hidden rounded-[10px] bg-brand p-4 text-on-brand outline-none transition-opacity duration-300 group-has-[a:hover]/menu:opacity-70 hover:!opacity-100 focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper"
                >
                  <span aria-hidden className={cx("absolute -right-10 -top-10 h-40 w-40 rounded-full bg-on-brand/15 transition-transform duration-700 group-hover/feat:scale-125", EASE)} />
                  <span aria-hidden className={cx("absolute -right-2 top-12 h-20 w-20 rounded-full bg-on-brand/10 transition-transform duration-700 group-hover/feat:-translate-x-3", EASE)} />
                  <span className="relative text-[15px] font-medium tracking-[-0.01em]">{menu.feature.title}</span>
                  <span className="relative mt-1 text-[12.5px] leading-snug text-on-brand/80">{menu.feature.description}</span>
                  <span className="relative mt-3 flex items-center gap-1 text-[13px] font-medium">
                    {menu.feature.cta}
                    <Chevron className={cx("transition-transform duration-300 group-hover/feat:translate-x-0.5", EASE)} />
                  </span>
                </a>
              )}
            </div>
          )}
        </div>
      );
    }
    
    /** Every link in a menu, flattened, for the mobile sheet. */
    const flat = (m: NavMenu): NavTile[] => [
      ...(m.list ?? []),
      ...(m.tiles ?? []),
      ...(m.columns?.flatMap((c) => c.links) ?? []),
      ...(m.feature ? [{ title: m.feature.title, description: m.feature.description, href: m.feature.href }] : []),
    ];
    
    /**
     * Site header with a mega menu. One shared panel sits under the bar and morphs its size between
     * sections while the new content slides in from the side you moved toward. A menu with `list` is a
     * plain dropdown: the same panel glides over to sit right under its trigger. Hovering a tile dims the
     * rest. Below 560px of container width it collapses to a burger and a sheet of accordion sections.
     * One highlight glides between links on hover, `#anchor` links mark the section on screen, and once the page
     * scrolls the bar becomes a floating island.
     * Wrap it in an element with `@container` (the demo does) or it falls back to the viewport width.
     */
    export function Navbar({ brand, brandHref = "/", items, docs, cta, scrollRoot, className }: NavbarProps) {
      const [open, setOpen] = useState<number | null>(null);
      const [dir, setDir] = useState<1 | -1>(1);
      // The last menu stays rendered while the panel fades out; `slide` is true only when moving between menus.
      const [last, setLast] = useState<number | null>(null);
      const [slide, setSlide] = useState(false);
      const [size, setSize] = useState({ w: 0, h: 0 });
      // Where the open trigger sits in the bar, measured when a menu opens (never per frame).
      const [anchor, setAnchor] = useState({ left: 0, bar: 0 });
      const [scrolled, setScrolled] = useState(false);
      const [sheet, setSheet] = useState(false);
      const [section, setSection] = useState<number | null>(null);
      // One highlight that glides between links. Measured on pointer enter, never per frame.
      const [pill, setPill] = useState({ x: 0, w: 0, on: false, glide: false });
      // The `#anchor` link whose section is on screen.
      const [current, setCurrent] = useState<string | null>(null);
      const root = useRef<HTMLElement>(null);
      const content = useRef<HTMLDivElement>(null);
      const triggers = useRef<(HTMLButtonElement | null)[]>([]);
      const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
      const focusPanel = useRef(false);
      // When hover last opened a menu. A click right after it must not toggle the menu shut again.
      const hoverAt = useRef(0);
      const uid = useId();
      const panelId = `${uid}-panel`;
      const sheetId = `${uid}-sheet`;
      const openRef = useRef<number | null>(null);
      const shown = open ?? last;
      useEffect(() => {
        openRef.current = open;
      }, [open]);
    
      const show = useCallback((i: number | null) => {
        clearTimeout(timer.current);
        const cur = openRef.current;
        const moving = i !== null && cur !== null && i !== cur;
        if (moving) setDir(i > cur ? 1 : -1);
        setSlide(moving);
        if (i !== null) {
          setLast(i);
          const t = triggers.current[i];
          const bar = t?.closest<HTMLElement>("[data-kit-nav-bar]");
          if (t && bar) setAnchor({ left: t.getBoundingClientRect().left - bar.getBoundingClientRect().left, bar: bar.offsetWidth });
        }
        setOpen(i);
      }, []);
    
      // Hover intent: a short delay before the first open, instant while moving between triggers.
      const enter = (i: number) => {
        clearTimeout(timer.current);
        const go = () => {
          hoverAt.current = performance.now();
          show(i);
        };
        if (openRef.current === null) timer.current = setTimeout(go, 80);
        else go();
      };
      const leave = () => {
        clearTimeout(timer.current);
        timer.current = setTimeout(() => show(null), 150);
      };
      const stay = () => clearTimeout(timer.current);
    
      // Measure the active menu so the panel can animate to its size.
      useLayoutEffect(() => {
        const el = content.current;
        if (shown === null || !el) return;
        const measure = () => setSize({ w: el.offsetWidth, h: el.offsetHeight });
        // ResizeObserver reports once right after layout, so there is no layout read while the page mounts.
        const ro = new ResizeObserver(measure);
        ro.observe(el);
        if (focusPanel.current) {
          focusPanel.current = false;
          el.querySelector<HTMLElement>("[data-kit-nav-link]")?.focus();
        }
        return () => ro.disconnect();
      }, [shown, open]);
    
      // Folded state once the page scrolls.
      useEffect(() => {
        const el = scrollRoot?.current ?? null;
        const read = () => setScrolled((el ? el.scrollTop : window.scrollY) > 40);
        read();
        const target: HTMLElement | Window = el ?? window;
        target.addEventListener("scroll", read, { passive: true });
        return () => target.removeEventListener("scroll", read);
      }, [scrollRoot]);
    
      // Section links (`#pricing`) light up while their section crosses the middle of the screen.
      const anchors = items.map((it) => it.href).filter((h): h is string => !!h && h.startsWith("#") && h.length > 1).join(" ");
      useEffect(() => {
        const els = anchors
          .split(" ")
          .filter(Boolean)
          .map((h) => document.getElementById(decodeURIComponent(h.slice(1))))
          .filter((el): el is HTMLElement => !!el);
        if (!els.length) return;
        const io = new IntersectionObserver(
          (entries) => {
            for (const e of entries) if (e.isIntersecting) setCurrent(`#${e.target.id}`);
            if (entries.every((e) => !e.isIntersecting) && entries.length === els.length) setCurrent(null);
          },
          { root: scrollRoot?.current ?? null, rootMargin: "-45% 0px -50% 0px" },
        );
        els.forEach((el) => io.observe(el));
        return () => io.disconnect();
      }, [anchors, scrollRoot]);
    
      const glideTo = (el: HTMLElement, e: React.PointerEvent) => {
        if (e.pointerType !== "mouse") return;
        const x = el.offsetLeft;
        const w = el.offsetWidth;
        setPill((p) => ({ x, w, on: true, glide: p.on }));
      };
    
      // Outside click and Escape close everything.
      useEffect(() => {
        const down = (e: PointerEvent) => {
          if (!root.current?.contains(e.target as Node)) {
            show(null);
            setSheet(false);
          }
        };
        const key = (e: KeyboardEvent) => {
          if (e.key !== "Escape") return;
          const i = openRef.current;
          if (i !== null) {
            show(null);
            triggers.current[i]?.focus();
          }
          setSheet(false);
        };
        document.addEventListener("pointerdown", down);
        document.addEventListener("keydown", key);
        return () => {
          document.removeEventListener("pointerdown", down);
          document.removeEventListener("keydown", key);
        };
      }, [show]);
    
      useEffect(() => () => clearTimeout(timer.current), []);
    
      const menu = shown !== null ? items[shown]?.menu : undefined;
      // Mega menus centre under the bar, plain dropdowns line up with their trigger. Clamped to the bar.
      const panelX = menu?.list ? Math.max(12, Math.min(anchor.left - 6, anchor.bar - size.w - 12)) : (anchor.bar - size.w) / 2;
      const trigger =
        "relative flex h-8 items-center gap-1 rounded-md px-2.5 text-[13.5px] font-medium text-ink-2 outline-none transition-colors duration-200 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50 aria-expanded:text-ink";
    
      return (
        <header
          ref={root}
          className={cx(
            "sticky top-0 z-30 w-full transition-colors duration-300",
            sheet && "bg-paper",
            className,
          )}
        >
          <style href="asta-navbar" precedence="asta">{`
            @keyframes kit-nav-in { from { opacity: 0; transform: translateX(calc(var(--kit-dir) * 14px)); } to { opacity: 1; transform: none; } }
            @keyframes kit-nav-pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
            @media (prefers-reduced-motion: reduce) { .kit-nav-motion, .kit-nav-motion * { animation: none !important; transition-duration: 0s !important; } }
          `}</style>
          <div data-kit-nav-bar className="kit-nav-motion relative isolate flex h-14 items-center gap-3 px-4">
            {/* The bar's surface. Flat at the top of the page, then it fades in as a floating island: inset, rounded,
                a hairline ring and a soft shadow. Only opacity and transform move. */}
            <span
              aria-hidden
              className={cx(
                "pointer-events-none absolute inset-x-1.5 inset-y-1.5 -z-10 rounded-[14px] bg-paper/90 backdrop-blur-md transition-[opacity,transform] duration-500",
                "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_9%,transparent),0_1px_2px_rgb(0_0_0/0.04),0_12px_32px_-16px_rgb(0_0_0/0.28)]",
                EASE,
                scrolled && !sheet ? "opacity-100" : "scale-[.985] opacity-0",
              )}
            />
            <a href={brandHref} className="flex flex-1 items-center gap-2 text-[15px] font-semibold tracking-[-0.02em] text-ink outline-none focus-visible:ring-2 focus-visible:ring-brand/50 rounded-md">
              {brand}
            </a>
    
            {/* Desktop nav */}
            <nav
              aria-label="Main"
              className="hidden @min-[560px]:block"
              onPointerLeave={() => {
                leave();
                setPill((p) => ({ ...p, on: false }));
              }}
              onPointerEnter={stay}
            >
              <ul className="relative flex items-center gap-0.5">
                <li aria-hidden className="pointer-events-none absolute left-0 top-0">
                  <span
                    className={cx(
                      "block h-8 rounded-md bg-paper-2",
                      // perf-ok: width follows the hovered link. An absolute 32px box, so nothing else lays out.
                      pill.glide ? "transition-[transform,width,opacity] duration-300" : "transition-opacity duration-200",
                      EASE,
                      pill.on || open !== null ? "opacity-100" : "opacity-0",
                    )}
                    style={{ width: pill.w, transform: `translateX(${pill.x}px)` }}
                  />
                </li>
                {items.map((it, i) => (
                  <li key={it.label}>
                    {it.menu ? (
                      <button
                        ref={(el) => {
                          triggers.current[i] = el;
                        }}
                        type="button"
                        aria-expanded={open === i}
                        aria-controls={panelId}
                        onPointerEnter={(e) => {
                          glideTo(e.currentTarget, e);
                          if (e.pointerType === "mouse") enter(i);
                        }}
                        onClick={() => {
                          if (open !== i) return show(i);
                          if (performance.now() - hoverAt.current > 400) show(null);
                        }}
                        onKeyDown={(e) => {
                          if (e.key === "ArrowDown" || ((e.key === "Enter" || e.key === " ") && open !== i)) {
                            e.preventDefault();
                            // Already open: nothing re-renders, so focus the first link here instead of in the layout effect.
                            if (open === i) return content.current?.querySelector<HTMLElement>("[data-kit-nav-link]")?.focus();
                            focusPanel.current = true;
                            show(i);
                          } else if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
                            e.preventDefault();
                            const step = e.key === "ArrowRight" ? 1 : -1;
                            const next = (i + step + items.length) % items.length;
                            root.current?.querySelectorAll<HTMLElement>("nav[aria-label=Main] li:not([aria-hidden]) > *")[next]?.focus();
                            if (open !== null && items[next].menu) show(next);
                          }
                        }}
                        className={cx(trigger, "pr-2")}
                      >
                        {it.label}
                        <Chevron className={cx("text-mute transition-transform duration-300", EASE, open === i ? "-rotate-90" : "rotate-90")} />
                      </button>
                    ) : (
                      <a
                        href={it.href}
                        aria-current={current !== null && it.href === current ? "location" : undefined}
                        className={cx(
                          trigger,
                          "aria-[current=location]:text-ink",
                          // A small brand dot under the section on screen, with aria-current and a darker label.
                          "after:absolute after:bottom-0 after:left-1/2 after:h-1 after:w-1 after:-translate-x-1/2 after:rounded-full after:bg-brand after:opacity-0 after:transition-opacity after:duration-300 aria-[current=location]:after:opacity-100",
                        )}
                        onPointerEnter={(e) => {
                          glideTo(e.currentTarget, e);
                          if (openRef.current !== null) show(null);
                        }}
                      >
                        {it.label}
                      </a>
                    )}
                  </li>
                ))}
              </ul>
            </nav>
    
            <div className="flex flex-1 items-center justify-end gap-1.5">
              {docs && (
                <div
                  className={cx(
                    "hidden overflow-hidden transition-[max-width,opacity] duration-500 @min-[680px]:block",
                    EASE,
                    scrolled ? "max-w-0 opacity-0" : "max-w-[120px] opacity-100",
                  )}
                  aria-hidden={scrolled || undefined}
                >
                  <Button href={docs.href} variant="ghost" size="sm" shape="pill" tabIndex={scrolled ? -1 : undefined}>
                    {docs.label}
                  </Button>
                </div>
              )}
              <Button href={cta.href} size="sm" shape="pill" iconRight={<Chevron />} nudge>
                {cta.label}
              </Button>
              <button
                type="button"
                aria-label={sheet ? "Close menu" : "Open menu"}
                aria-expanded={sheet}
                aria-controls={sheetId}
                onClick={() => setSheet((v) => !v)}
                className="relative flex h-8 w-8 items-center justify-center rounded-md outline-none transition-colors hover:bg-paper-2 focus-visible:ring-2 focus-visible:ring-brand/50 @min-[560px]:hidden"
              >
                <span className={cx("absolute h-[1.5px] w-4 rounded-full bg-ink transition-transform duration-500", EASE, sheet ? "rotate-45" : "-translate-y-[3.5px]")} />
                <span className={cx("absolute h-[1.5px] w-4 rounded-full bg-ink transition-transform duration-500", EASE, sheet ? "-rotate-45" : "translate-y-[3.5px]")} />
              </button>
            </div>
    
            {/* Shared panel: one surface that morphs between menus. */}
            <div
              id={panelId}
              inert={open === null}
              onPointerEnter={stay}
              onPointerLeave={leave}
              className={cx(
                "absolute left-0 top-[calc(100%-2px)] hidden @min-[560px]:block",
                size.w > 0 && "transition-transform duration-300",
                EASE,
                open === null && "pointer-events-none",
              )}
              style={{ transform: `translateX(${Math.round(panelX)}px)` }}
            >
              <div
                className={cx(
                  "overflow-hidden rounded-xl bg-paper shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_12%,transparent),0_16px_40px_-12px_rgb(0_0_0/0.22)] transition-[width,height,opacity,transform] duration-300",
                  EASE,
                  open === null ? "-translate-y-1 scale-[.98] opacity-0" : "opacity-100",
                )}
                style={{ width: size.w || undefined, height: size.h || undefined }}
              >
                {menu && (
                  <div
                    key={shown}
                    ref={content}
                    className="w-max"
                    style={
                      {
                        "--kit-dir": dir,
                        width: `min(${menu.width ?? (menu.list ? 300 : 560)}px, calc(100cqw - 24px))`,
                        animation: slide ? "kit-nav-in .28s cubic-bezier(.16,1,.3,1) both" : undefined,
                      } as React.CSSProperties
                    }
                  >
                    <Panel menu={menu} />
                  </div>
                )}
              </div>
            </div>
          </div>
    
          {/* Mobile sheet */}
          <div
            id={sheetId}
            hidden={!sheet}
            className="kit-nav-motion absolute inset-x-0 top-full max-h-[calc(100svh-3.5rem)] overflow-y-auto overscroll-contain bg-paper px-3 pb-6 pt-2 @min-[560px]:hidden"
            style={{ animation: sheet ? "kit-nav-pop .4s cubic-bezier(.16,1,.3,1) both" : undefined }}
          >
            <ul className="flex flex-col">
              {items.map((it, i) => (
                <li key={it.label}>
                  {it.menu ? (
                    <>
                      <button
                        type="button"
                        aria-expanded={section === i}
                        onClick={() => setSection(section === i ? null : i)}
                        className="flex h-12 w-full items-center justify-between rounded-[10px] px-3 text-[15px] font-medium text-ink outline-none focus-visible:bg-paper-2"
                      >
                        {it.label}
                        <Chevron className={cx("text-mute transition-transform duration-300", EASE, section === i ? "-rotate-90" : "rotate-90")} />
                      </button>
                      <div className={cx("grid transition-[grid-template-rows] duration-500", EASE, section === i ? "grid-rows-[1fr]" : "grid-rows-[0fr]")}>
                        <div className="overflow-hidden">
                          <div className="flex flex-col gap-0.5 pb-2 pl-2">
                            {flat(it.menu).map((l) => (
                              <a key={l.title} href={l.href} tabIndex={section === i ? undefined : -1} className="flex items-center gap-3 rounded-lg px-3 py-2 outline-none hover:bg-paper-2 focus-visible:bg-paper-2">
                                {l.icon && <span className={cx("flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-paper-2 text-ink [&_svg]:h-3.5 [&_svg]:w-3.5")}>{l.icon}</span>}
                                <span className="flex flex-col">
                                  <span className="text-[14px] text-ink">{l.title}</span>
                                  {l.description && <span className="text-[12px] leading-snug text-mute">{l.description}</span>}
                                </span>
                              </a>
                            ))}
                          </div>
                        </div>
                      </div>
                    </>
                  ) : (
                    <a href={it.href} className="flex h-12 items-center rounded-[10px] px-3 text-[15px] font-medium text-ink outline-none focus-visible:bg-paper-2">
                      {it.label}
                    </a>
                  )}
                </li>
              ))}
            </ul>
            <div className="mt-4 flex flex-col gap-2 px-1">
              {docs && (
                <Button href={docs.href} variant="outline" shape="pill" className="w-full">
                  {docs.label}
                </Button>
              )}
              <Button href={cta.href} shape="pill" className="w-full">
                {cta.label}
              </Button>
            </div>
          </div>
        </header>
      );
    }
    
    export default Navbar;
    
    "use client";
    
    import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from "react";
    import { Button } from "@/components/kit/base/button";
    
    const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
    
    export interface NavTile {
      title: string;
      description?: string;
      href: string;
      icon?: ReactNode;
      /** Big tiles get a small mock preview in the corner. */
      preview?: "chart" | "list" | "code";
    }
    export interface NavMenu {
      /** Panel width in px (clamped to the space available). */
      width?: number;
      /** A plain dropdown: a short list that opens right under its trigger instead of the centred mega panel. */
      list?: NavTile[];
      tiles?: NavTile[];
      columns?: { heading: string; links: NavTile[] }[];
      feature?: { title: string; description: string; href: string; cta: string };
    }
    export interface NavItem {
      label: string;
      href?: string;
      menu?: NavMenu;
    }
    export interface NavbarProps {
      brand: ReactNode;
      brandHref?: string;
      items: NavItem[];
      /** Quiet link that folds away once the page scrolls. */
      docs?: { label: string; href: string };
      cta: { label: string; href: string };
      /** Element whose scroll drives the folded state (defaults to the window). */
      scrollRoot?: RefObject<HTMLElement | null>;
      className?: string;
    }
    
    const RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_12%,transparent)]";
    const EASE = "ease-[cubic-bezier(.16,1,.3,1)]";
    
    const Chevron = ({ className = "" }: { className?: string }) => (
      <svg viewBox="0 0 24 24" className={cx("h-3.5 w-3.5", className)} fill="none" stroke="currentColor" strokeWidth="2.55" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
        <path d="m9.5 6 6 6-6 6" />
      </svg>
    );
    
    /** Abstract UI shapes so big tiles hint at what's behind them. Grey until hovered. */
    function Preview({ kind }: { kind: NonNullable<NavTile["preview"]> }) {
      const bar = "rounded-full bg-[color-mix(in_srgb,var(--color-ink)_12%,transparent)] transition-colors duration-500";
      return (
        <div
          aria-hidden
          className={cx(
            "absolute -bottom-px -right-px h-[46%] w-[72%] rounded-tl-xl bg-paper p-3 transition-transform duration-500 group-hover/tile:-translate-x-1 group-hover/tile:-translate-y-1",
            RING,
            EASE,
          )}
        >
          {kind === "chart" && (
            <div className="flex h-full items-end gap-1.5">
              {[40, 64, 52, 80, 70, 96].map((h, i) => (
                <span key={i} className={cx(bar, "w-full rounded-[3px] group-hover/tile:bg-brand")} style={{ height: `${h}%`, transitionDelay: `${i * 40}ms` }} />
              ))}
            </div>
          )}
          {kind === "list" && (
            <div className="flex flex-col gap-2">
              {[80, 56, 68].map((w, i) => (
                <div key={i} className="flex items-center gap-2">
                  <span className={cx(bar, "h-3 w-3 shrink-0 group-hover/tile:bg-brand")} style={{ transitionDelay: `${i * 60}ms` }} />
                  <span className={cx(bar, "h-1.5")} style={{ width: `${w}%` }} />
                </div>
              ))}
            </div>
          )}
          {kind === "code" && (
            <div className="flex flex-col gap-1.5 font-mono">
              {[
                [20, 50],
                [36, 30],
                [28, 44],
                [20, 24],
              ].map(([a, b], i) => (
                <div key={i} className="flex gap-1.5">
                  <span className={cx(bar, "h-1.5 group-hover/tile:bg-brand")} style={{ width: `${a}%`, transitionDelay: `${i * 50}ms` }} />
                  <span className={cx(bar, "h-1.5")} style={{ width: `${b}%` }} />
                </div>
              ))}
            </div>
          )}
        </div>
      );
    }
    
    function Tile({ tile, big }: { tile: NavTile; big: boolean }) {
      return (
        <a
          href={tile.href}
          data-kit-nav-link
          className={cx(
            "group/tile relative flex flex-col gap-1.5 overflow-hidden rounded-[10px] bg-paper-2 p-4 outline-none transition-[opacity,background-color] duration-300",
            "group-has-[a:hover]/menu:opacity-55 hover:!opacity-100 focus-visible:ring-2 focus-visible:ring-brand/50",
            big ? "min-h-[184px]" : "min-h-[92px]",
          )}
        >
          <span className="flex items-center gap-2 text-[14px] font-medium tracking-[-0.01em] text-ink">
            {tile.icon && (
              <span className={cx("flex h-6 w-6 items-center justify-center rounded-md bg-paper text-ink [&_svg]:h-3.5 [&_svg]:w-3.5", RING)}>{tile.icon}</span>
            )}
            {tile.title}
            <Chevron className={cx("-translate-x-0.5 text-mute transition-[translate,color] duration-300 group-hover/tile:translate-x-0 group-hover/tile:text-ink", EASE)} />
          </span>
          {tile.description && <span className={cx("text-[12.5px] leading-snug text-mute", big && "max-w-[22ch]")}>{tile.description}</span>}
          {big && tile.preview && <Preview kind={tile.preview} />}
        </a>
      );
    }
    
    function List({ links }: { links: NavTile[] }) {
      return (
        <div className="flex flex-col gap-0.5 p-1.5">
          {links.map((l) => (
            <a
              key={l.title}
              href={l.href}
              data-kit-nav-link
              className="group/item flex items-start gap-3 rounded-lg px-2.5 py-2 outline-none transition-colors duration-150 hover:bg-paper-2 focus-visible:bg-paper-2"
            >
              {l.icon && (
                <span className={cx("mt-px flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-paper text-mute transition-colors duration-150 group-hover/item:text-ink [&_svg]:h-3.5 [&_svg]:w-3.5", RING)}>
                  {l.icon}
                </span>
              )}
              <span className="flex min-w-0 flex-col">
                <span className="text-[13.5px] font-medium text-ink">{l.title}</span>
                {l.description && <span className="text-[12px] leading-snug text-mute">{l.description}</span>}
              </span>
            </a>
          ))}
        </div>
      );
    }
    
    function Panel({ menu }: { menu: NavMenu }) {
      if (menu.list) return <List links={menu.list} />;
      const tiles = menu.tiles ?? [];
      const big = tiles.some((t) => t.preview);
      return (
        <div className="group/menu flex flex-col gap-2 p-2">
          {tiles.length > 0 && (
            <div className="grid gap-2" style={{ gridTemplateColumns: `repeat(${tiles.length === 4 ? 2 : tiles.length}, minmax(0, 1fr))` }}>
              {tiles.map((t) => (
                <Tile key={t.title} tile={t} big={big} />
              ))}
            </div>
          )}
          {(menu.columns || menu.feature) && (
            <div className="grid gap-2" style={{ gridTemplateColumns: `repeat(${(menu.columns?.length ?? 0) + (menu.feature ? 1 : 0)}, minmax(0, 1fr))` }}>
              {menu.columns?.map((col) => (
                <div key={col.heading} className="flex flex-col gap-0.5 p-2">
                  <span className="mb-1.5 px-2 text-[11.5px] text-mute">{col.heading}</span>
                  {col.links.map((l) => (
                    <a
                      key={l.title}
                      href={l.href}
                      data-kit-nav-link
                      className="group/link flex flex-col rounded-lg px-2 py-1.5 outline-none transition-[background-color,opacity] duration-200 hover:bg-paper-2 focus-visible:bg-paper-2 group-has-[a:hover]/menu:opacity-60 hover:!opacity-100"
                    >
                      <span className="flex items-center gap-1 text-[13.5px] font-medium text-ink">
                        {l.title}
                        <Chevron className={cx("h-3 w-3 -translate-x-1 text-mute opacity-0 transition-[translate,opacity] duration-300 group-hover/link:translate-x-0 group-hover/link:opacity-100", EASE)} />
                      </span>
                      {l.description && <span className="text-[12px] leading-snug text-mute">{l.description}</span>}
                    </a>
                  ))}
                </div>
              ))}
              {menu.feature && (
                <a
                  href={menu.feature.href}
                  data-kit-nav-link
                  className="group/feat relative flex min-h-[200px] flex-col justify-end overflow-hidden rounded-[10px] bg-brand p-4 text-on-brand outline-none transition-opacity duration-300 group-has-[a:hover]/menu:opacity-70 hover:!opacity-100 focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper"
                >
                  <span aria-hidden className={cx("absolute -right-10 -top-10 h-40 w-40 rounded-full bg-on-brand/15 transition-transform duration-700 group-hover/feat:scale-125", EASE)} />
                  <span aria-hidden className={cx("absolute -right-2 top-12 h-20 w-20 rounded-full bg-on-brand/10 transition-transform duration-700 group-hover/feat:-translate-x-3", EASE)} />
                  <span className="relative text-[15px] font-medium tracking-[-0.01em]">{menu.feature.title}</span>
                  <span className="relative mt-1 text-[12.5px] leading-snug text-on-brand/80">{menu.feature.description}</span>
                  <span className="relative mt-3 flex items-center gap-1 text-[13px] font-medium">
                    {menu.feature.cta}
                    <Chevron className={cx("transition-transform duration-300 group-hover/feat:translate-x-0.5", EASE)} />
                  </span>
                </a>
              )}
            </div>
          )}
        </div>
      );
    }
    
    /** Every link in a menu, flattened, for the mobile sheet. */
    const flat = (m: NavMenu): NavTile[] => [
      ...(m.list ?? []),
      ...(m.tiles ?? []),
      ...(m.columns?.flatMap((c) => c.links) ?? []),
      ...(m.feature ? [{ title: m.feature.title, description: m.feature.description, href: m.feature.href }] : []),
    ];
    
    /**
     * Site header with a mega menu. One shared panel sits under the bar and morphs its size between
     * sections while the new content slides in from the side you moved toward. A menu with `list` is a
     * plain dropdown: the same panel glides over to sit right under its trigger. Hovering a tile dims the
     * rest. Below 560px of container width it collapses to a burger and a sheet of accordion sections.
     * One highlight glides between links on hover, `#anchor` links mark the section on screen, and once the page
     * scrolls the bar becomes a floating island.
     * Wrap it in an element with `@container` (the demo does) or it falls back to the viewport width.
     */
    export function Navbar({ brand, brandHref = "/", items, docs, cta, scrollRoot, className }: NavbarProps) {
      const [open, setOpen] = useState<number | null>(null);
      const [dir, setDir] = useState<1 | -1>(1);
      // The last menu stays rendered while the panel fades out; `slide` is true only when moving between menus.
      const [last, setLast] = useState<number | null>(null);
      const [slide, setSlide] = useState(false);
      const [size, setSize] = useState({ w: 0, h: 0 });
      // Where the open trigger sits in the bar, measured when a menu opens (never per frame).
      const [anchor, setAnchor] = useState({ left: 0, bar: 0 });
      const [scrolled, setScrolled] = useState(false);
      const [sheet, setSheet] = useState(false);
      const [section, setSection] = useState<number | null>(null);
      // One highlight that glides between links. Measured on pointer enter, never per frame.
      const [pill, setPill] = useState({ x: 0, w: 0, on: false, glide: false });
      // The `#anchor` link whose section is on screen.
      const [current, setCurrent] = useState<string | null>(null);
      const root = useRef<HTMLElement>(null);
      const content = useRef<HTMLDivElement>(null);
      const triggers = useRef<(HTMLButtonElement | null)[]>([]);
      const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
      const focusPanel = useRef(false);
      // When hover last opened a menu. A click right after it must not toggle the menu shut again.
      const hoverAt = useRef(0);
      const uid = useId();
      const panelId = `${uid}-panel`;
      const sheetId = `${uid}-sheet`;
      const openRef = useRef<number | null>(null);
      const shown = open ?? last;
      useEffect(() => {
        openRef.current = open;
      }, [open]);
    
      const show = useCallback((i: number | null) => {
        clearTimeout(timer.current);
        const cur = openRef.current;
        const moving = i !== null && cur !== null && i !== cur;
        if (moving) setDir(i > cur ? 1 : -1);
        setSlide(moving);
        if (i !== null) {
          setLast(i);
          const t = triggers.current[i];
          const bar = t?.closest<HTMLElement>("[data-kit-nav-bar]");
          if (t && bar) setAnchor({ left: t.getBoundingClientRect().left - bar.getBoundingClientRect().left, bar: bar.offsetWidth });
        }
        setOpen(i);
      }, []);
    
      // Hover intent: a short delay before the first open, instant while moving between triggers.
      const enter = (i: number) => {
        clearTimeout(timer.current);
        const go = () => {
          hoverAt.current = performance.now();
          show(i);
        };
        if (openRef.current === null) timer.current = setTimeout(go, 80);
        else go();
      };
      const leave = () => {
        clearTimeout(timer.current);
        timer.current = setTimeout(() => show(null), 150);
      };
      const stay = () => clearTimeout(timer.current);
    
      // Measure the active menu so the panel can animate to its size.
      useLayoutEffect(() => {
        const el = content.current;
        if (shown === null || !el) return;
        const measure = () => setSize({ w: el.offsetWidth, h: el.offsetHeight });
        // ResizeObserver reports once right after layout, so there is no layout read while the page mounts.
        const ro = new ResizeObserver(measure);
        ro.observe(el);
        if (focusPanel.current) {
          focusPanel.current = false;
          el.querySelector<HTMLElement>("[data-kit-nav-link]")?.focus();
        }
        return () => ro.disconnect();
      }, [shown, open]);
    
      // Folded state once the page scrolls.
      useEffect(() => {
        const el = scrollRoot?.current ?? null;
        const read = () => setScrolled((el ? el.scrollTop : window.scrollY) > 40);
        read();
        const target: HTMLElement | Window = el ?? window;
        target.addEventListener("scroll", read, { passive: true });
        return () => target.removeEventListener("scroll", read);
      }, [scrollRoot]);
    
      // Section links (`#pricing`) light up while their section crosses the middle of the screen.
      const anchors = items.map((it) => it.href).filter((h): h is string => !!h && h.startsWith("#") && h.length > 1).join(" ");
      useEffect(() => {
        const els = anchors
          .split(" ")
          .filter(Boolean)
          .map((h) => document.getElementById(decodeURIComponent(h.slice(1))))
          .filter((el): el is HTMLElement => !!el);
        if (!els.length) return;
        const io = new IntersectionObserver(
          (entries) => {
            for (const e of entries) if (e.isIntersecting) setCurrent(`#${e.target.id}`);
            if (entries.every((e) => !e.isIntersecting) && entries.length === els.length) setCurrent(null);
          },
          { root: scrollRoot?.current ?? null, rootMargin: "-45% 0px -50% 0px" },
        );
        els.forEach((el) => io.observe(el));
        return () => io.disconnect();
      }, [anchors, scrollRoot]);
    
      const glideTo = (el: HTMLElement, e: React.PointerEvent) => {
        if (e.pointerType !== "mouse") return;
        const x = el.offsetLeft;
        const w = el.offsetWidth;
        setPill((p) => ({ x, w, on: true, glide: p.on }));
      };
    
      // Outside click and Escape close everything.
      useEffect(() => {
        const down = (e: PointerEvent) => {
          if (!root.current?.contains(e.target as Node)) {
            show(null);
            setSheet(false);
          }
        };
        const key = (e: KeyboardEvent) => {
          if (e.key !== "Escape") return;
          const i = openRef.current;
          if (i !== null) {
            show(null);
            triggers.current[i]?.focus();
          }
          setSheet(false);
        };
        document.addEventListener("pointerdown", down);
        document.addEventListener("keydown", key);
        return () => {
          document.removeEventListener("pointerdown", down);
          document.removeEventListener("keydown", key);
        };
      }, [show]);
    
      useEffect(() => () => clearTimeout(timer.current), []);
    
      const menu = shown !== null ? items[shown]?.menu : undefined;
      // Mega menus centre under the bar, plain dropdowns line up with their trigger. Clamped to the bar.
      const panelX = menu?.list ? Math.max(12, Math.min(anchor.left - 6, anchor.bar - size.w - 12)) : (anchor.bar - size.w) / 2;
      const trigger =
        "relative flex h-8 items-center gap-1 rounded-md px-2.5 text-[13.5px] font-medium text-ink-2 outline-none transition-colors duration-200 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50 aria-expanded:text-ink";
    
      return (
        <header
          ref={root}
          className={cx(
            "sticky top-0 z-30 w-full transition-colors duration-300",
            sheet && "bg-paper",
            className,
          )}
        >
          <style href="asta-navbar" precedence="asta">{`
            @keyframes kit-nav-in { from { opacity: 0; transform: translateX(calc(var(--kit-dir) * 14px)); } to { opacity: 1; transform: none; } }
            @keyframes kit-nav-pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
            @media (prefers-reduced-motion: reduce) { .kit-nav-motion, .kit-nav-motion * { animation: none !important; transition-duration: 0s !important; } }
          `}</style>
          <div data-kit-nav-bar className="kit-nav-motion relative isolate flex h-14 items-center gap-3 px-4">
            {/* The bar's surface. Flat at the top of the page, then it fades in as a floating island: inset, rounded,
                a hairline ring and a soft shadow. Only opacity and transform move. */}
            <span
              aria-hidden
              className={cx(
                "pointer-events-none absolute inset-x-1.5 inset-y-1.5 -z-10 rounded-[14px] bg-paper/90 backdrop-blur-md transition-[opacity,transform] duration-500",
                "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_9%,transparent),0_1px_2px_rgb(0_0_0/0.04),0_12px_32px_-16px_rgb(0_0_0/0.28)]",
                EASE,
                scrolled && !sheet ? "opacity-100" : "scale-[.985] opacity-0",
              )}
            />
            <a href={brandHref} className="flex flex-1 items-center gap-2 text-[15px] font-semibold tracking-[-0.02em] text-ink outline-none focus-visible:ring-2 focus-visible:ring-brand/50 rounded-md">
              {brand}
            </a>
    
            {/* Desktop nav */}
            <nav
              aria-label="Main"
              className="hidden @min-[560px]:block"
              onPointerLeave={() => {
                leave();
                setPill((p) => ({ ...p, on: false }));
              }}
              onPointerEnter={stay}
            >
              <ul className="relative flex items-center gap-0.5">
                <li aria-hidden className="pointer-events-none absolute left-0 top-0">
                  <span
                    className={cx(
                      "block h-8 rounded-md bg-paper-2",
                      // perf-ok: width follows the hovered link. An absolute 32px box, so nothing else lays out.
                      pill.glide ? "transition-[transform,width,opacity] duration-300" : "transition-opacity duration-200",
                      EASE,
                      pill.on || open !== null ? "opacity-100" : "opacity-0",
                    )}
                    style={{ width: pill.w, transform: `translateX(${pill.x}px)` }}
                  />
                </li>
                {items.map((it, i) => (
                  <li key={it.label}>
                    {it.menu ? (
                      <button
                        ref={(el) => {
                          triggers.current[i] = el;
                        }}
                        type="button"
                        aria-expanded={open === i}
                        aria-controls={panelId}
                        onPointerEnter={(e) => {
                          glideTo(e.currentTarget, e);
                          if (e.pointerType === "mouse") enter(i);
                        }}
                        onClick={() => {
                          if (open !== i) return show(i);
                          if (performance.now() - hoverAt.current > 400) show(null);
                        }}
                        onKeyDown={(e) => {
                          if (e.key === "ArrowDown" || ((e.key === "Enter" || e.key === " ") && open !== i)) {
                            e.preventDefault();
                            // Already open: nothing re-renders, so focus the first link here instead of in the layout effect.
                            if (open === i) return content.current?.querySelector<HTMLElement>("[data-kit-nav-link]")?.focus();
                            focusPanel.current = true;
                            show(i);
                          } else if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
                            e.preventDefault();
                            const step = e.key === "ArrowRight" ? 1 : -1;
                            const next = (i + step + items.length) % items.length;
                            root.current?.querySelectorAll<HTMLElement>("nav[aria-label=Main] li:not([aria-hidden]) > *")[next]?.focus();
                            if (open !== null && items[next].menu) show(next);
                          }
                        }}
                        className={cx(trigger, "pr-2")}
                      >
                        {it.label}
                        <Chevron className={cx("text-mute transition-transform duration-300", EASE, open === i ? "-rotate-90" : "rotate-90")} />
                      </button>
                    ) : (
                      <a
                        href={it.href}
                        aria-current={current !== null && it.href === current ? "location" : undefined}
                        className={cx(
                          trigger,
                          "aria-[current=location]:text-ink",
                          // A small brand dot under the section on screen, with aria-current and a darker label.
                          "after:absolute after:bottom-0 after:left-1/2 after:h-1 after:w-1 after:-translate-x-1/2 after:rounded-full after:bg-brand after:opacity-0 after:transition-opacity after:duration-300 aria-[current=location]:after:opacity-100",
                        )}
                        onPointerEnter={(e) => {
                          glideTo(e.currentTarget, e);
                          if (openRef.current !== null) show(null);
                        }}
                      >
                        {it.label}
                      </a>
                    )}
                  </li>
                ))}
              </ul>
            </nav>
    
            <div className="flex flex-1 items-center justify-end gap-1.5">
              {docs && (
                <div
                  className={cx(
                    "hidden overflow-hidden transition-[max-width,opacity] duration-500 @min-[680px]:block",
                    EASE,
                    scrolled ? "max-w-0 opacity-0" : "max-w-[120px] opacity-100",
                  )}
                  aria-hidden={scrolled || undefined}
                >
                  <Button href={docs.href} variant="ghost" size="sm" shape="pill" tabIndex={scrolled ? -1 : undefined}>
                    {docs.label}
                  </Button>
                </div>
              )}
              <Button href={cta.href} size="sm" shape="pill" iconRight={<Chevron />} nudge>
                {cta.label}
              </Button>
              <button
                type="button"
                aria-label={sheet ? "Close menu" : "Open menu"}
                aria-expanded={sheet}
                aria-controls={sheetId}
                onClick={() => setSheet((v) => !v)}
                className="relative flex h-8 w-8 items-center justify-center rounded-md outline-none transition-colors hover:bg-paper-2 focus-visible:ring-2 focus-visible:ring-brand/50 @min-[560px]:hidden"
              >
                <span className={cx("absolute h-[1.5px] w-4 rounded-full bg-ink transition-transform duration-500", EASE, sheet ? "rotate-45" : "-translate-y-[3.5px]")} />
                <span className={cx("absolute h-[1.5px] w-4 rounded-full bg-ink transition-transform duration-500", EASE, sheet ? "-rotate-45" : "translate-y-[3.5px]")} />
              </button>
            </div>
    
            {/* Shared panel: one surface that morphs between menus. */}
            <div
              id={panelId}
              inert={open === null}
              onPointerEnter={stay}
              onPointerLeave={leave}
              className={cx(
                "absolute left-0 top-[calc(100%-2px)] hidden @min-[560px]:block",
                size.w > 0 && "transition-transform duration-300",
                EASE,
                open === null && "pointer-events-none",
              )}
              style={{ transform: `translateX(${Math.round(panelX)}px)` }}
            >
              <div
                className={cx(
                  "overflow-hidden rounded-xl bg-paper shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_12%,transparent),0_16px_40px_-12px_rgb(0_0_0/0.22)] transition-[width,height,opacity,transform] duration-300",
                  EASE,
                  open === null ? "-translate-y-1 scale-[.98] opacity-0" : "opacity-100",
                )}
                style={{ width: size.w || undefined, height: size.h || undefined }}
              >
                {menu && (
                  <div
                    key={shown}
                    ref={content}
                    className="w-max"
                    style={
                      {
                        "--kit-dir": dir,
                        width: `min(${menu.width ?? (menu.list ? 300 : 560)}px, calc(100cqw - 24px))`,
                        animation: slide ? "kit-nav-in .28s cubic-bezier(.16,1,.3,1) both" : undefined,
                      } as React.CSSProperties
                    }
                  >
                    <Panel menu={menu} />
                  </div>
                )}
              </div>
            </div>
          </div>
    
          {/* Mobile sheet */}
          <div
            id={sheetId}
            hidden={!sheet}
            className="kit-nav-motion absolute inset-x-0 top-full max-h-[calc(100svh-3.5rem)] overflow-y-auto overscroll-contain bg-paper px-3 pb-6 pt-2 @min-[560px]:hidden"
            style={{ animation: sheet ? "kit-nav-pop .4s cubic-bezier(.16,1,.3,1) both" : undefined }}
          >
            <ul className="flex flex-col">
              {items.map((it, i) => (
                <li key={it.label}>
                  {it.menu ? (
                    <>
                      <button
                        type="button"
                        aria-expanded={section === i}
                        onClick={() => setSection(section === i ? null : i)}
                        className="flex h-12 w-full items-center justify-between rounded-[10px] px-3 text-[15px] font-medium text-ink outline-none focus-visible:bg-paper-2"
                      >
                        {it.label}
                        <Chevron className={cx("text-mute transition-transform duration-300", EASE, section === i ? "-rotate-90" : "rotate-90")} />
                      </button>
                      <div className={cx("grid transition-[grid-template-rows] duration-500", EASE, section === i ? "grid-rows-[1fr]" : "grid-rows-[0fr]")}>
                        <div className="overflow-hidden">
                          <div className="flex flex-col gap-0.5 pb-2 pl-2">
                            {flat(it.menu).map((l) => (
                              <a key={l.title} href={l.href} tabIndex={section === i ? undefined : -1} className="flex items-center gap-3 rounded-lg px-3 py-2 outline-none hover:bg-paper-2 focus-visible:bg-paper-2">
                                {l.icon && <span className={cx("flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-paper-2 text-ink [&_svg]:h-3.5 [&_svg]:w-3.5")}>{l.icon}</span>}
                                <span className="flex flex-col">
                                  <span className="text-[14px] text-ink">{l.title}</span>
                                  {l.description && <span className="text-[12px] leading-snug text-mute">{l.description}</span>}
                                </span>
                              </a>
                            ))}
                          </div>
                        </div>
                      </div>
                    </>
                  ) : (
                    <a href={it.href} className="flex h-12 items-center rounded-[10px] px-3 text-[15px] font-medium text-ink outline-none focus-visible:bg-paper-2">
                      {it.label}
                    </a>
                  )}
                </li>
              ))}
            </ul>
            <div className="mt-4 flex flex-col gap-2 px-1">
              {docs && (
                <Button href={docs.href} variant="outline" shape="pill" className="w-full">
                  {docs.label}
                </Button>
              )}
              <Button href={cta.href} shape="pill" className="w-full">
                {cta.label}
              </Button>
            </div>
          </div>
        </header>
      );
    }
    
    export default Navbar;
    
  4. Or ask your AI agent

    Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.

    Add the Astabyte UI Navbar component to my project.
    
    A site header with a morphing mega menu.
    It includes: mega menu, dropdown, morphing panel, mobile sheet, scroll state.
    
    Install it (Radix build):
    ```sh
    pnpm dlx asta-ui@latest add navbar --radix
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/navbar.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4).
    
    Import it like this:
    ```tsx
    import { Navbar, type NavItem } from "@/components/astabyte/navbar";
    ```
    
    Usage example and props: https://ui.astabyte.com/navbar
    Full catalogue for context: https://ui.astabyte.com/llms.txt
    
    Rules:
    - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS.
    - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback.
    - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package).
    - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]
    Add the Astabyte UI Navbar component to my project.
    
    A site header with a morphing mega menu.
    It includes: mega menu, dropdown, morphing panel, mobile sheet, scroll state.
    
    Install it (Base UI build):
    ```sh
    pnpm dlx asta-ui@latest add navbar
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/navbar.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4).
    
    Import it like this:
    ```tsx
    import { Navbar, type NavItem } from "@/components/astabyte/navbar";
    ```
    
    Usage example and props: https://ui.astabyte.com/navbar
    Full catalogue for context: https://ui.astabyte.com/llms.txt
    
    Rules:
    - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS.
    - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback.
    - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package).
    - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]
  5. Or use plain HTML + CSS

    Not on React? Use it from Django, Rails, Laravel, Go html/template, htmx or a static page. Load asta.css and asta.js once (the head.html tab), then paste the markup. The ui.astabyte.com/cdn link is temporary: pin a version from jsDelivr for production. More in HTML + CSS.

    <!-- Needs asta.js: mega panel switching and sizing, the scrolled state and the phone sheet are scripted. -->
    <div style="width:100%;overflow:hidden;border-radius:12px;background:var(--paper)">
      <header class="asta-navbar" data-asta-navbar style="position:static">
        <div class="asta-navbar-bar">
          <a href="#navbar" class="asta-navbar-brand"><span style="display:grid;height:24px;width:24px;place-items:center;border-radius:6px;background:var(--brand);font-size:12px;font-weight:600;color:#fff">A</span><span>Astabyte</span></a>
          <nav aria-label="Main" data-asta-nav-zone class="asta-navbar-nav"><ul>
            <li><button type="button" class="asta-navbar-trigger" data-asta-nav-trigger="0" aria-expanded="false" aria-controls="ex-nav-demo-panel">Product<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></button></li>
            <li><button type="button" class="asta-navbar-trigger" data-asta-nav-trigger="1" aria-expanded="false" aria-controls="ex-nav-demo-panel">Resources<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></button></li>
            <li><a href="#navbar" class="asta-navbar-trigger" data-asta-nav-link>Pricing</a></li>
          </ul></nav>
          <div class="asta-navbar-actions">
            <div>
              <a href="#navbar" data-asta-nav-docs class="asta-btn asta-btn-ghost asta-btn-sm asta-btn-pill asta-navbar-docs">Docs</a>
              <a href="#navbar" class="asta-btn asta-btn-sm asta-btn-pill asta-navbar-cta"><span class="asta-btn-label">Get started</span></a>
            </div>
            <button type="button" class="asta-navbar-burger" data-asta-nav-burger aria-label="Open menu" aria-expanded="false" aria-controls="ex-nav-demo-sheet"><span></span><span></span></button>
          </div>
          <div id="ex-nav-demo-panel" data-asta-nav-zone data-asta-nav-surface class="asta-navbar-surface">
            <div class="asta-navbar-pop">
              <div data-asta-nav-bg class="asta-navbar-bg"></div>
              <div>
                <div data-asta-nav-panel="0" hidden class="asta-navbar-panel" style="width:min(560px,calc(100cqw - 24px))">
                  <div class="asta-navbar-menu"><div class="asta-navbar-grid asta-navbar-cols-2">
                    <a href="#navbar" data-asta-nav-link class="asta-navbar-tile asta-navbar-tile-tall"><span class="asta-navbar-tile-head">Analytics<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></span><span class="asta-navbar-tile-desc">See what people do, without cookies.</span>
                      <div aria-hidden="true" class="asta-navbar-preview"><div class="asta-navbar-chart"><span class="asta-navbar-bar-fill" style="height:40%"></span><span class="asta-navbar-bar-fill" style="height:64%;transition-delay:40ms"></span><span class="asta-navbar-bar-fill" style="height:52%;transition-delay:80ms"></span><span class="asta-navbar-bar-fill" style="height:80%;transition-delay:120ms"></span><span class="asta-navbar-bar-fill" style="height:70%;transition-delay:160ms"></span><span class="asta-navbar-bar-fill" style="height:96%;transition-delay:200ms"></span></div></div></a>
                    <a href="#navbar" data-asta-nav-link class="asta-navbar-tile asta-navbar-tile-tall"><span class="asta-navbar-tile-head">Inbox<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></span><span class="asta-navbar-tile-desc">Every inquiry in one list.</span>
                      <div aria-hidden="true" class="asta-navbar-preview"><div class="asta-navbar-list"><div><span class="asta-navbar-bar-fill"></span><span class="asta-navbar-bar-fill" style="width:80%"></span></div><div><span class="asta-navbar-bar-fill" style="transition-delay:60ms"></span><span class="asta-navbar-bar-fill" style="width:56%"></span></div><div><span class="asta-navbar-bar-fill" style="transition-delay:120ms"></span><span class="asta-navbar-bar-fill" style="width:68%"></span></div></div></div></a>
                    <a href="#navbar" data-asta-nav-link class="asta-navbar-tile asta-navbar-tile-tall"><span class="asta-navbar-tile-head">API<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></span><span class="asta-navbar-tile-desc">Typed, versioned, documented.</span>
                      <div aria-hidden="true" class="asta-navbar-preview"><div class="asta-navbar-lines"><div><span class="asta-navbar-bar-fill" style="width:20%"></span><span class="asta-navbar-bar-fill" style="width:50%"></span></div><div><span class="asta-navbar-bar-fill" style="width:36%;transition-delay:50ms"></span><span class="asta-navbar-bar-fill" style="width:30%"></span></div><div><span class="asta-navbar-bar-fill" style="width:28%;transition-delay:100ms"></span><span class="asta-navbar-bar-fill" style="width:44%"></span></div></div></div></a>
                    <a href="#navbar" data-asta-nav-link class="asta-navbar-tile asta-navbar-tile-tall"><span class="asta-navbar-tile-head">CMS<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></span><span class="asta-navbar-tile-desc">Edit the site without a deploy.</span>
                      <div aria-hidden="true" class="asta-navbar-preview"><div class="asta-navbar-list"><div><span class="asta-navbar-bar-fill"></span><span class="asta-navbar-bar-fill" style="width:80%"></span></div><div><span class="asta-navbar-bar-fill"></span><span class="asta-navbar-bar-fill" style="width:56%"></span></div></div></div></a>
                  </div></div>
                </div>
                <div data-asta-nav-panel="1" hidden class="asta-navbar-panel" style="width:min(620px,calc(100cqw - 24px))">
                  <div class="asta-navbar-menu"><div class="asta-navbar-grid asta-navbar-cols-3">
                    <div class="asta-navbar-col"><span class="asta-navbar-col-heading">Learn</span>
                      <a href="#navbar" data-asta-nav-link class="asta-navbar-col-link"><span class="asta-navbar-col-title">Docs<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></span></a>
                      <a href="#navbar" data-asta-nav-link class="asta-navbar-col-link"><span class="asta-navbar-col-title">Guides<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></span><span class="asta-navbar-col-desc">Step by step.</span></a>
                    </div>
                    <div class="asta-navbar-col"><span class="asta-navbar-col-heading">Company</span>
                      <a href="#navbar" data-asta-nav-link class="asta-navbar-col-link"><span class="asta-navbar-col-title">About<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></span></a>
                      <a href="#navbar" data-asta-nav-link class="asta-navbar-col-link"><span class="asta-navbar-col-title">Contact<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></span></a>
                    </div>
                    <a href="#navbar" data-asta-nav-link class="asta-navbar-feature"><span class="asta-navbar-orb" aria-hidden="true"></span><span class="asta-navbar-orb" aria-hidden="true"></span><span class="asta-navbar-feature-title">Astabyte UI 0.8</span><span class="asta-navbar-feature-desc">A CSS-only layer is here.</span><span class="asta-navbar-feature-cta">Read the notes<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></span></a>
                  </div></div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div id="ex-nav-demo-sheet" data-asta-nav-sheet hidden class="asta-navbar-sheet">
          <ul>
            <li><details class="asta-navbar-sec"><summary>Product<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></summary>
              <div class="asta-nav-sec asta-navbar-sec-links">
                <a href="#navbar" class="asta-navbar-sheet-link"><span><span class="asta-navbar-sheet-title">Analytics</span> <span class="asta-navbar-sheet-desc">See what people do, without cookies.</span></span></a>
                <a href="#navbar" class="asta-navbar-sheet-link"><span><span class="asta-navbar-sheet-title">Inbox</span> <span class="asta-navbar-sheet-desc">Every inquiry in one list.</span></span></a>
              </div></details></li>
            <li><a href="#navbar" class="asta-navbar-sheet-item">Pricing</a></li>
          </ul>
          <div class="asta-navbar-sheet-actions">
            <a href="#navbar" class="asta-btn asta-btn-outline asta-btn-pill"><span class="asta-btn-label">Docs</span></a>
            <a href="#navbar" class="asta-btn asta-btn-pill"><span class="asta-btn-label">Get started</span></a>
          </div>
        </div>
      </header>
      <div style="height:460px"></div>
    </div>

Usage

The demo above, as code.

"use client";

import { useRef } from "react";
import { Navbar, type NavItem } from "@/components/astabyte/navbar";

const icon = (d: string) => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
    <path d={d} />
  </svg>
);

const NAV: NavItem[] = [
  {
    label: "Product",
    menu: {
      width: 600,
      tiles: [
        { title: "Analytics", description: "See what moves revenue, live.", href: "#", icon: icon("M4 20h16M7 16.5v-4M12 16.5V7M17 16.5v-7"), preview: "chart" },
        { title: "Automations", description: "Rules that run while you sleep.", href: "#", icon: icon("M13.5 3 5.5 13.5h6L10.5 21l8-10.5h-6Z"), preview: "list" },
        { title: "API", description: "Everything, programmable.", href: "#", icon: icon("M8.5 7l-5 5 5 5M15.5 7l5 5-5 5"), preview: "code" },
      ],
    },
  },
  {
    label: "Solutions",
    menu: {
      width: 620,
      columns: [
        {
          heading: "By team",
          links: [
            { title: "Marketing", description: "Campaigns that report themselves.", href: "#" },
            { title: "Sales", description: "A pipeline you can trust.", href: "#" },
            { title: "Support", description: "Answers in one place.", href: "#" },
          ],
        },
        {
          heading: "By size",
          links: [
            { title: "Startups", description: "Free for your first year.", href: "#" },
            { title: "Enterprise", description: "SSO, audit logs, SLAs.", href: "#" },
          ],
        },
      ],
      feature: { title: "Customer stories", description: "How 2,000 teams ship faster with Astabyte.", href: "#", cta: "Read stories" },
    },
  },
  {
    label: "Resources",
    menu: {
      list: [
        { title: "Docs", description: "Guides and reference.", href: "#", icon: icon("M6 3.5h8l4.5 4.5v12.5H6ZM14 3.5V8h4.5") },
        { title: "Changelog", description: "What shipped this week.", href: "#", icon: icon("M3.5 12a8.5 8.5 0 1 0 17 0a8.5 8.5 0 1 0-17 0M12 7.5V12l3 2") },
        { title: "Community", description: "Ask, share, meet.", href: "#", icon: icon("M6 8.5a3.5 3.5 0 1 0 7 0a3.5 3.5 0 1 0-7 0M3.5 19.5a6 6 0 0 1 12 0M15.5 5.2a3.5 3.5 0 0 1 0 6.6M17.5 14a6 6 0 0 1 3 5.5") },
        { title: "Templates", description: "Start from a working setup.", href: "#", icon: icon("M5.5 4h3.5a1.5 1.5 0 0 1 1.5 1.5v3.5a1.5 1.5 0 0 1-1.5 1.5h-3.5a1.5 1.5 0 0 1-1.5-1.5v-3.5a1.5 1.5 0 0 1 1.5-1.5ZM15 4h3.5a1.5 1.5 0 0 1 1.5 1.5v3.5a1.5 1.5 0 0 1-1.5 1.5h-3.5a1.5 1.5 0 0 1-1.5-1.5v-3.5a1.5 1.5 0 0 1 1.5-1.5ZM5.5 13.5h3.5a1.5 1.5 0 0 1 1.5 1.5v3.5a1.5 1.5 0 0 1-1.5 1.5h-3.5a1.5 1.5 0 0 1-1.5-1.5v-3.5a1.5 1.5 0 0 1 1.5-1.5ZM15 13.5h3.5a1.5 1.5 0 0 1 1.5 1.5v3.5a1.5 1.5 0 0 1-1.5 1.5h-3.5a1.5 1.5 0 0 1-1.5-1.5v-3.5a1.5 1.5 0 0 1 1.5-1.5Z") },
      ],
    },
  },
  {
    label: "Company",
    menu: {
      list: [
        { title: "About", description: "Who builds Astabyte.", href: "#", icon: icon("M8.25 8.5a3.75 3.75 0 1 0 7.5 0a3.75 3.75 0 1 0-7.5 0M5 20a7 7 0 0 1 14 0") },
        { title: "Careers", description: "Four open roles.", href: "#", icon: icon("M5.5 7h13a2 2 0 0 1 2 2v8.5a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-8.5a2 2 0 0 1 2-2ZM9 7V5.5A1.5 1.5 0 0 1 10.5 4h3A1.5 1.5 0 0 1 15 5.5V7M3.5 12.5h17") },
        { title: "Contact", description: "Talk to the team.", href: "#", icon: icon("M5.5 5.5h13a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-9a2 2 0 0 1 2-2ZM4 7l8 6 8-6") },
      ],
    },
  },
  { label: "Pricing", href: "#" },
];

const Logo = () => (
  <>
    <svg viewBox="0 0 20 20" className="h-5 w-5" aria-hidden>
      <circle cx="7.5" cy="10" r="5.5" fill="currentColor" />
      <circle cx="12.5" cy="10" r="5.5" fill="var(--color-brand)" fillOpacity="0.85" />
    </svg>
    Astabyte
  </>
);

export default function NavbarDemo() {
  const page = useRef<HTMLDivElement>(null);
  return (
    <div className="flex min-h-[420px] w-full items-center justify-center p-3 sm:p-4">
      {/* A small browser frame: the navbar sticks inside it and folds as the page scrolls. */}
      <div className="@container relative w-full max-w-[960px] overflow-hidden rounded-xl bg-paper shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent),0_24px_60px_-30px_rgb(0_0_0/0.35)]">
        <div ref={page} className="h-[520px] overflow-y-auto overscroll-contain [scrollbar-width:thin]">
          <Navbar brand={<Logo />} items={NAV} docs={{ label: "Docs", href: "#" }} cta={{ label: "Get started", href: "#" }} scrollRoot={page} />
          <main className="px-6 pb-16 pt-14 text-center">
            <p className="mx-auto w-fit rounded-full bg-paper-2 px-3 py-1 text-[12px] text-mute">Hover the menu, then scroll</p>
            <h2 className="mx-auto mt-5 max-w-[16ch] text-[clamp(1.8rem,6cqw,3rem)] font-medium leading-[1.02] tracking-[-0.04em] text-ink">Revenue analytics for teams that ship.</h2>
            <p className="mx-auto mt-4 max-w-md text-[14px] leading-relaxed text-mute">A mock page so the header has something to scroll over. The Docs link folds away after 40px.</p>
            <div className="mx-auto mt-10 grid max-w-2xl gap-3 @min-[560px]:grid-cols-3">
              {Array.from({ length: 6 }, (_, i) => (
                <div key={i} className="h-36 rounded-[10px] bg-paper-2" />
              ))}
            </div>
          </main>
        </div>
      </div>
    </div>
  );
}