---
title: "Shell Nav · UI SDK — StyleX Blocks"
description: "Application shell pairing a top navigation bar (workspace switcher, command search dialog, notifications popover, account menu) with a collapsible left sidebar, mobile slide-over drawer, and interactive cloud deployment views."
url: "https://stylexblocks.com/block/ui-sdk/shell-nav/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Shell Nav block

Application shell pairing a top navigation bar (workspace switcher, command search dialog, notifications popover, account menu) with a collapsible left sidebar, mobile slide-over drawer, and interactive cloud deployment views.

- Behavior engine: UI SDK
- Category: [App shells](https://stylexblocks.com/blocks/app-shells.md)
- Built with: [App Shell](https://stylexblocks.com/components/ui-sdk/app-shell.md), [Avatar](https://stylexblocks.com/components/ui-sdk/avatar.md), [Badge](https://stylexblocks.com/components/ui-sdk/badge.md), [Button](https://stylexblocks.com/components/ui-sdk/button.md), [Card](https://stylexblocks.com/components/ui-sdk/card.md), [Center](https://stylexblocks.com/components/ui-sdk/center.md), [Code](https://stylexblocks.com/components/ui-sdk/code.md), [Dialog](https://stylexblocks.com/components/ui-sdk/dialog.md), [Drawer](https://stylexblocks.com/components/ui-sdk/drawer.md), [Grid](https://stylexblocks.com/components/ui-sdk/grid.md), [Heading](https://stylexblocks.com/components/ui-sdk/heading.md), [Icon](https://stylexblocks.com/components/ui-sdk/icon.md), [Icon Button](https://stylexblocks.com/components/ui-sdk/icon-button.md), [Input](https://stylexblocks.com/components/ui-sdk/input.md), [Kbd](https://stylexblocks.com/components/ui-sdk/kbd.md), [Menu](https://stylexblocks.com/components/ui-sdk/menu.md), [Navbar](https://stylexblocks.com/components/ui-sdk/navbar.md), [Popover](https://stylexblocks.com/components/ui-sdk/popover.md), [Progress](https://stylexblocks.com/components/ui-sdk/progress.md), [Separator](https://stylexblocks.com/components/ui-sdk/separator.md), [Sidebar](https://stylexblocks.com/components/ui-sdk/sidebar.md), [Sidebar Nav Item](https://stylexblocks.com/components/ui-sdk/sidebar-nav-item.md), [Stack](https://stylexblocks.com/components/ui-sdk/stack.md), [Stat](https://stylexblocks.com/components/ui-sdk/stat.md), [Status](https://stylexblocks.com/components/ui-sdk/status.md), [Switch](https://stylexblocks.com/components/ui-sdk/switch.md), [Table](https://stylexblocks.com/components/ui-sdk/table.md), [Text](https://stylexblocks.com/components/ui-sdk/text.md), [Toast](https://stylexblocks.com/components/ui-sdk/toast.md)
- HTML page: https://stylexblocks.com/block/ui-sdk/shell-nav/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add shell-nav
```

Equivalent: `npx shadcn add @stylexblocks/shell-nav`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/shell-nav.json

## Usage

```tsx
import { ShellNav } from "#components/blocks/ui-sdk/shell-nav.tsx";

export function Example() {
  return (
    <div style={{ height: "100dvh" }}>
      <ShellNav />
    </div>
  );
}
```

## Source

`components/blocks/ui-sdk/shell-nav.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { useCallback, useEffect, useMemo, useState } from "react";
import { AppShell } from "#components/ui/ui-sdk/app-shell.tsx";
import { Avatar } from "#components/ui/ui-sdk/avatar.tsx";
import { Badge } from "#components/ui/ui-sdk/badge.tsx";
import { Button } from "#components/ui/ui-sdk/button.tsx";
import { Card } from "#components/ui/ui-sdk/card.tsx";
import { Center } from "#components/ui/ui-sdk/center.tsx";
import { Code } from "#components/ui/ui-sdk/code.tsx";
import { Dialog } from "#components/ui/ui-sdk/dialog.tsx";
import { Drawer } from "#components/ui/ui-sdk/drawer.tsx";
import { Grid } from "#components/ui/ui-sdk/grid.tsx";
import { Heading } from "#components/ui/ui-sdk/heading.tsx";
import { Icon } from "#components/ui/ui-sdk/icon.tsx";
import { IconButton } from "#components/ui/ui-sdk/icon-button.tsx";
import { Input } from "#components/ui/ui-sdk/input.tsx";
import { Kbd } from "#components/ui/ui-sdk/kbd.tsx";
import { Menu } from "#components/ui/ui-sdk/menu.tsx";
import { Navbar } from "#components/ui/ui-sdk/navbar.tsx";
import { Popover } from "#components/ui/ui-sdk/popover.tsx";
import { Progress } from "#components/ui/ui-sdk/progress.tsx";
import { Separator } from "#components/ui/ui-sdk/separator.tsx";
import { Sidebar } from "#components/ui/ui-sdk/sidebar.tsx";
import {
  SidebarNavItem,
  sidebarNavItemActive,
} from "#components/ui/ui-sdk/sidebar-nav-item.tsx";
import { HStack, VStack } from "#components/ui/ui-sdk/stack.tsx";
import { Stat } from "#components/ui/ui-sdk/stat.tsx";
import { Status } from "#components/ui/ui-sdk/status.tsx";
import { Switch } from "#components/ui/ui-sdk/switch.tsx";
import { Table } from "#components/ui/ui-sdk/table.tsx";
import { Text } from "#components/ui/ui-sdk/text.tsx";
import { Toast, Toaster } from "#components/ui/ui-sdk/toast.tsx";
import { semanticColors } from "@stylexblocks/ui/semantic-tokens/colors.stylex.ts";
import { semanticRadii } from "@stylexblocks/ui/semantic-tokens/radii.stylex.ts";
import {
  accentPalette,
  amberPalette,
  bluePalette,
  greenPalette,
  redPalette,
} from "@stylexblocks/ui/themes/palettes.ts";
import { fontSizes } from "@stylexblocks/ui/tokens/font-sizes.stylex.ts";
import { fonts } from "@stylexblocks/ui/tokens/fonts.stylex.ts";
import { lineHeights } from "@stylexblocks/ui/tokens/line-heights.stylex.ts";
import { radii } from "@stylexblocks/ui/tokens/radii.stylex.ts";
import { sizes } from "@stylexblocks/ui/tokens/sizes.stylex.ts";
import { spacing } from "@stylexblocks/ui/tokens/spacing.stylex.ts";
import type { StyleOverrideProps } from "#lib/recipe-props.ts";

export type ShellNavRoute =
  | "overview"
  | "deployments"
  | "logs"
  | "domains"
  | "environment"
  | "billing";

interface WorkspaceConfig {
  id: string;
  name: string;
  env: "Production" | "Staging" | "Preview";
  region: string;
  release: string;
  uptime: string;
  p95Latency: string;
  bandwidth: string;
  activeDeployments: string;
  palette: "green" | "amber" | "blue";
}

interface DeploymentItem {
  id: string;
  workspaceId: string;
  commit: string;
  message: string;
  branch: string;
  author: string;
  status: "live" | "building" | "failed";
  region: string;
  duration: string;
  createdAt: string;
}

interface LogEntry {
  id: string;
  timestamp: string;
  level: "info" | "warn" | "error";
  region: string;
  service: string;
  message: string;
}

interface DomainItem {
  id: string;
  host: string;
  target: string;
  tls: "Valid · Auto-renew" | "Provisioning";
  status: "verified" | "pending";
  primary?: boolean;
}

interface EnvVarItem {
  id: string;
  key: string;
  value: string;
  scope: "Production" | "Preview" | "Development";
  secret: boolean;
  updatedAt: string;
}

interface NotificationItem {
  id: string;
  title: string;
  detail: string;
  time: string;
  route: ShellNavRoute;
  unread: boolean;
}

const NARROW = "@container shell-nav (max-width: 768px)";
const COMPACT = "@container shell-nav (max-width: 560px)";
const MEDIUM = "@container shell-nav (max-width: 1024px)";

const WORKSPACES: WorkspaceConfig[] = [
  {
    id: "harbor-prod",
    name: "Harbor Cloud",
    env: "Production",
    region: "eu-west-1",
    release: "rel-482",
    uptime: "99.98%",
    p95Latency: "42 ms",
    bandwidth: "1.84 TB",
    activeDeployments: "14",
    palette: "green",
  },
  {
    id: "harbor-staging",
    name: "Harbor Staging",
    env: "Staging",
    region: "us-east-1",
    release: "rel-485-rc",
    uptime: "99.91%",
    p95Latency: "56 ms",
    bandwidth: "420 GB",
    activeDeployments: "6",
    palette: "amber",
  },
  {
    id: "harbor-edge",
    name: "Harbor Edge Lab",
    env: "Preview",
    region: "ap-northeast-1",
    release: "rel-486-exp",
    uptime: "99.74%",
    p95Latency: "31 ms",
    bandwidth: "118 GB",
    activeDeployments: "4",
    palette: "blue",
  },
];

const INITIAL_DEPLOYMENTS: DeploymentItem[] = [
  {
    id: "rel-482",
    workspaceId: "harbor-prod",
    commit: "9f4c2a1",
    message: "Enable Brotli level-6 streaming on edge gateway",
    branch: "main",
    author: "Nora Lindholm",
    status: "live",
    region: "eu-west-1",
    duration: "38s",
    createdAt: "12m ago",
  },
  {
    id: "rel-481",
    workspaceId: "harbor-prod",
    commit: "4b8e110",
    message: "Rotate webhook HMAC verifier keys with dual-window grace",
    branch: "main",
    author: "Marek Nowak",
    status: "live",
    region: "us-east-1",
    duration: "44s",
    createdAt: "2h ago",
  },
  {
    id: "rel-480",
    workspaceId: "harbor-staging",
    commit: "c17d9a4",
    message: "Add regional read-replica failover probe for Postgres pool",
    branch: "feat/replica-probe",
    author: "Tessa Vermeer",
    status: "building",
    region: "us-east-1",
    duration: "29s",
    createdAt: "3h ago",
  },
  {
    id: "rel-479",
    workspaceId: "harbor-edge",
    commit: "77a3f5e",
    message: "Test HTTP/3 early hints for static asset preloading",
    branch: "exp/early-hints",
    author: "Kenji Sato",
    status: "live",
    region: "ap-northeast-1",
    duration: "33s",
    createdAt: "5h ago",
  },
  {
    id: "rel-478",
    workspaceId: "harbor-prod",
    commit: "2e09ab8",
    message: "Upgrade worker runtime to v22.14 LTS",
    branch: "chore/runtime-22",
    author: "Nora Lindholm",
    status: "failed",
    region: "eu-west-1",
    duration: "1m 14s",
    createdAt: "Yesterday",
  },
];

const INITIAL_LOGS: LogEntry[] = [
  {
    id: "log-1",
    timestamp: "14:22:08.412",
    level: "info",
    region: "eu-west-1",
    service: "edge-router",
    message: "Promoted release rel-482 across 18 edge PoPs with 0 dropped connections",
  },
  {
    id: "log-2",
    timestamp: "14:22:06.104",
    level: "info",
    region: "us-east-1",
    service: "tls-manager",
    message: "OCSP staple refreshed for api.harbor.app (valid 89 days)",
  },
  {
    id: "log-3",
    timestamp: "14:21:54.889",
    level: "warn",
    region: "eu-west-1",
    service: "worker-pool",
    message: "Cold-start duration peaked at 142ms during autoscaling burst (8 → 14 instances)",
  },
  {
    id: "log-4",
    timestamp: "14:21:41.203",
    level: "info",
    region: "ap-northeast-1",
    service: "cache-layer",
    message: "Edge cache hit ratio stabilized at 96.4% after stale-while-revalidate tune",
  },
  {
    id: "log-5",
    timestamp: "14:20:59.017",
    level: "error",
    region: "eu-west-1",
    service: "build-runner",
    message: "Release rel-478 failed healthcheck on /readyz: upstream timeout after 5000ms",
  },
  {
    id: "log-6",
    timestamp: "14:20:12.641",
    level: "info",
    region: "us-east-1",
    service: "billing-meter",
    message: "Hourly bandwidth rollup committed (14.2 GB egress, 0 quota alerts)",
  },
];

const INITIAL_DOMAINS: DomainItem[] = [
  {
    id: "dom-1",
    host: "harbor.app",
    target: "main · eu-west-1",
    tls: "Valid · Auto-renew",
    status: "verified",
    primary: true,
  },
  {
    id: "dom-2",
    host: "api.harbor.app",
    target: "main · global anycast",
    tls: "Valid · Auto-renew",
    status: "verified",
  },
  {
    id: "dom-3",
    host: "docs.harbor.app",
    target: "main · static edge",
    tls: "Valid · Auto-renew",
    status: "verified",
  },
  {
    id: "dom-4",
    host: "preview.harbor.app",
    target: "staging · us-east-1",
    tls: "Provisioning",
    status: "pending",
  },
];

const INITIAL_ENV_VARS: EnvVarItem[] = [
  {
    id: "env-1",
    key: "DATABASE_POOL_URL",
    value: "postgres://harbor_prod@pg-eu.internal:6432/core?sslmode=require",
    scope: "Production",
    secret: true,
    updatedAt: "3d ago",
  },
  {
    id: "env-2",
    key: "EDGE_CACHE_TTL_SECONDS",
    value: "300",
    scope: "Production",
    secret: false,
    updatedAt: "5d ago",
  },
  {
    id: "env-3",
    key: "WEBHOOK_SIGNING_SECRET",
    value: "whsec_harbor_9f82c41e09b74a22c81d7e30",
    scope: "Production",
    secret: true,
    updatedAt: "2h ago",
  },
  {
    id: "env-4",
    key: "TELEMETRY_SAMPLE_RATE",
    value: "0.25",
    scope: "Preview",
    secret: false,
    updatedAt: "1w ago",
  },
  {
    id: "env-5",
    key: "OAUTH_CALLBACK_ORIGIN",
    value: "https://preview.harbor.app",
    scope: "Development",
    secret: false,
    updatedAt: "2w ago",
  },
];

const INITIAL_NOTIFICATIONS: NotificationItem[] = [
  {
    id: "notif-1",
    title: "Release rel-482 is live",
    detail: "Brotli level-6 streaming promoted to eu-west-1 in 38s.",
    time: "12m ago",
    route: "deployments",
    unread: true,
  },
  {
    id: "notif-2",
    title: "Worker burst warning",
    detail: "Cold-start latency briefly reached 142ms during scale-out.",
    time: "15m ago",
    route: "logs",
    unread: true,
  },
  {
    id: "notif-3",
    title: "Pending DNS verification",
    detail: "Add the CNAME record for preview.harbor.app to issue TLS.",
    time: "1h ago",
    route: "domains",
    unread: false,
  },
];

const EDGE_REGIONS = [
  { id: "eu-west-1", city: "Frankfurt", latency: "24 ms", load: 62 },
  { id: "us-east-1", city: "Virginia", latency: "38 ms", load: 48 },
  { id: "ap-northeast-1", city: "Tokyo", latency: "31 ms", load: 34 },
] as const;

const BILLING_QUOTAS = [
  { label: "Compute Hours", used: "1,420 hrs", limit: "2,000 hrs", percent: 71 },
  { label: "Edge Bandwidth", used: "1.84 TB", limit: "3.00 TB", percent: 61 },
  { label: "Build Minutes", used: "890 min", limit: "2,500 min", percent: 36 },
  { label: "Team Seats", used: "9 seats", limit: "12 seats", percent: 75 },
] as const;

const INVOICES = [
  { id: "INV-2026-11", period: "Nov 2026", amount: "$149.00", status: "Paid" },
  { id: "INV-2026-10", period: "Oct 2026", amount: "$149.00", status: "Paid" },
  { id: "INV-2026-09", period: "Sep 2026", amount: "$129.00", status: "Paid" },
] as const;

const ROUTE_META: Record<
  ShellNavRoute,
  { label: string; group: "Platform" | "Configuration"; description: string }
> = {
  overview: {
    label: "Overview",
    group: "Platform",
    description: "Cluster health, recent releases, and edge throughput across regions.",
  },
  deployments: {
    label: "Deployments",
    group: "Platform",
    description: "Inspect build pipelines, promote releases, or roll back instant snapshots.",
  },
  logs: {
    label: "Logs",
    group: "Platform",
    description: "Real-time structured runtime and build stream across edge regions.",
  },
  domains: {
    label: "Domains",
    group: "Configuration",
    description: "Custom hostnames, DNS verification, and managed TLS certificates.",
  },
  environment: {
    label: "Environment",
    group: "Configuration",
    description: "Scoped runtime variables, encrypted secrets, and rollout guardrails.",
  },
  billing: {
    label: "Billing",
    group: "Configuration",
    description: "Plan allocation, monthly consumption quotas, and invoice history.",
  },
};

const PLATFORM_ROUTES: ShellNavRoute[] = ["overview", "deployments", "logs"];
const CONFIG_ROUTES: ShellNavRoute[] = ["domains", "environment", "billing"];

function RouteGlyph({ route }: { route: ShellNavRoute }) {
  switch (route) {
    case "overview":
      return (
        <>
          <rect x="3" y="3" width="6" height="6" rx="1.25" />
          <rect x="11" y="3" width="6" height="6" rx="1.25" />
          <rect x="3" y="11" width="6" height="6" rx="1.25" />
          <rect x="11" y="11" width="6" height="6" rx="1.25" />
        </>
      );
    case "deployments":
      return (
        <>
          <path d="M10 3.25v9.5" />
          <path d="M6.25 7 10 3.25 13.75 7" />
          <path d="M4 15.75h12" />
        </>
      );
    case "logs":
      return (
        <>
          <rect x="2.75" y="3.75" width="14.5" height="12.5" rx="2" />
          <path d="m6.25 8 2.25 2-2.25 2" />
          <path d="M10.75 12h3" />
        </>
      );
    case "domains":
      return (
        <>
          <circle cx="10" cy="10" r="7" />
          <ellipse cx="10" cy="10" rx="3.25" ry="7" />
          <path d="M3.25 10h13.5" />
        </>
      );
    case "environment":
      return (
        <>
          <path d="M4 6h12" />
          <path d="M4 14h12" />
          <circle cx="7.5" cy="6" r="1.75" fill="currentColor" />
          <circle cx="12.5" cy="14" r="1.75" fill="currentColor" />
        </>
      );
    case "billing":
      return (
        <>
          <rect x="2.75" y="4.5" width="14.5" height="11" rx="2" />
          <path d="M2.75 8.5h14.5" />
          <path d="M6 12.25h3.5" />
        </>
      );
  }
}

function HarborMark() {
  return (
    <svg
      width="20"
      height="20"
      viewBox="0 0 20 20"
      fill="none"
      aria-hidden="true"
    >
      <rect width="20" height="20" rx="5" fill="currentColor" />
      <path
        d="M5.75 13.5V6.5h2.1v2.65h4.3V6.5h2.1v7h-2.1v-2.6h-4.3v2.6h-2.1Z"
        fill="var(--sui-colors-bg, #ffffff)"
      />
    </svg>
  );
}

const styles = stylex.create({
  root: {
    backgroundColor: semanticColors.bg,
    color: semanticColors.fg,
    containerName: "shell-nav",
    containerType: "inline-size",
    fontFamily: fonts.body,
    height: "100%",
    minHeight: 0,
    overflow: "hidden",
    width: "100%",
  },
  shrink0: {
    flexShrink: 0,
  },
  fullWidth: {
    width: "100%",
  },
  navbar: {
    "--navbar-height": "3.5rem",
    borderBottomColor: semanticColors.border,
    borderBottomStyle: "solid",
    borderBottomWidth: "1px",
    flexShrink: 0,
    paddingInline: spacing._4,
  },
  mobileMenuTrigger: {
    display: {
      default: "none",
      [NARROW]: "inline-flex",
    },
  },
  desktopCollapseTrigger: {
    display: {
      default: "inline-flex",
      [NARROW]: "none",
    },
  },
  brandMark: {
    alignItems: "center",
    color: semanticColors.accentSolid,
    display: "inline-flex",
    flexShrink: 0,
  },
  brandTitle: {
    letterSpacing: "-0.01em",
    display: {
      default: "inline",
      [COMPACT]: "none",
    },
  },
  brandDivider: {
    display: {
      default: "inline",
      [COMPACT]: "none",
    },
  },
  workspaceTrigger: {
    gap: spacing._2,
    maxWidth: "15rem",
  },
  workspaceEnvBadge: {
    display: {
      default: "inline-flex",
      [COMPACT]: "none",
    },
  },
  searchTrigger: {
    alignItems: "center",
    backgroundColor: {
      default: semanticColors.bgMuted,
      ":hover": semanticColors.bgSubtle,
    },
    borderColor: semanticColors.border,
    borderRadius: semanticRadii.control,
    borderStyle: "solid",
    borderWidth: "1px",
    color: semanticColors.fgMuted,
    cursor: "pointer",
    display: "inline-flex",
    fontSize: fontSizes.sm,
    gap: spacing._2,
    height: sizes.controlSm,
    justifyContent: "space-between",
    paddingInline: spacing._2_5,
    width: {
      default: "15.5rem",
      [MEDIUM]: "11rem",
      [NARROW]: "auto",
    },
  },
  searchTriggerLabel: {
    alignItems: "center",
    display: "inline-flex",
    gap: spacing._2,
    minWidth: 0,
    overflow: "hidden",
    textOverflow: "ellipsis",
    whiteSpace: "nowrap",
  },
  searchPlaceholderText: {
    display: {
      default: "inline",
      [NARROW]: "none",
    },
  },
  searchKbd: {
    display: {
      default: "inline-flex",
      [NARROW]: "none",
    },
  },
  deployButton: {
    display: {
      default: "inline-flex",
      [COMPACT]: "none",
    },
  },
  iconButtonWrap: {
    position: "relative",
    display: "inline-flex",
  },
  unreadDot: {
    backgroundColor: semanticColors.accentSolid,
    borderColor: semanticColors.bgPanel,
    borderRadius: radii.full,
    borderStyle: "solid",
    borderWidth: "1.5px",
    height: "0.5rem",
    pointerEvents: "none",
    position: "absolute",
    right: "0.35rem",
    top: "0.35rem",
    width: "0.5rem",
  },
  avatarTrigger: {
    paddingInline: spacing._1,
  },
  sidebar: {
    "--sidebar-width": "15rem",
    "--sidebar-min-width": "15rem",
    borderRightStyle: "solid",
    display: {
      default: "flex",
      [NARROW]: "none",
    },
    flexShrink: 0,
    transitionDuration: "180ms",
    transitionProperty: "width, min-width",
  },
  sidebarCollapsed: {
    "--sidebar-width": "3.75rem",
    "--sidebar-min-width": "3.75rem",
  },
  sidebarBodyCollapsed: {
    paddingInline: spacing._2,
  },
  navList: {
    listStyle: "none",
    marginBlock: 0,
    marginInline: 0,
    paddingBlock: 0,
    paddingInline: 0,
  },
  navButtonCollapsed: {
    justifyContent: "center",
    paddingInline: 0,
  },
  sidebarFooter: {
    borderTopColor: semanticColors.sidebarBorder,
    borderTopStyle: "solid",
    borderTopWidth: "1px",
    gap: spacing._2,
    paddingBlock: spacing._3,
  },
  clusterCard: {
    backgroundColor: semanticColors.bgPanel,
    borderColor: semanticColors.border,
    borderRadius: semanticRadii.control,
    borderStyle: "solid",
    borderWidth: "1px",
    paddingBlock: spacing._2_5,
    paddingInline: spacing._3,
  },
  clusterCardCollapsed: {
    paddingBlock: spacing._1,
  },
  drawerBody: {
    display: "flex",
    flexDirection: "column",
    gap: spacing._4,
    paddingInline: spacing._3,
  },
  main: {
    backgroundColor: semanticColors.bgContent,
    overflowY: "auto",
  },
  mainInner: {
    marginInline: "auto",
    maxWidth: "70rem",
    paddingBlock: spacing._6,
    paddingInline: {
      default: spacing._6,
      [NARROW]: spacing._4,
    },
    width: "100%",
  },
  pageHeader: {
    alignItems: {
      default: "flex-end",
      [NARROW]: "flex-start",
    },
    flexDirection: {
      default: "row",
      [NARROW]: "column",
    },
  },
  breadcrumbRow: {
    color: semanticColors.fgMuted,
    fontSize: fontSizes.xs,
  },
  pageTitle: {
    marginBlock: 0,
  },
  statGrid: {
    gridTemplateColumns: {
      default: "repeat(4, minmax(0, 1fr))",
      [MEDIUM]: "repeat(2, minmax(0, 1fr))",
      [COMPACT]: "minmax(0, 1fr)",
    },
  },
  twoColGrid: {
    gridTemplateColumns: {
      default: "minmax(0, 1.5fr) minmax(0, 1fr)",
      [MEDIUM]: "minmax(0, 1fr)",
    },
  },
  cardHeaderRow: {
    alignItems: "center",
    display: "flex",
    flexDirection: "row",
    gap: spacing._3,
    justifyContent: "space-between",
  },
  cardTitleReset: {
    marginBlock: 0,
  },
  cardDescReset: {
    marginBlock: 0,
  },
  tableWrap: {
    overflowX: "auto",
    width: "100%",
  },
  quickActionGrid: {
    paddingTop: spacing._2,
  },
  inlineSearch: {
    maxWidth: "18rem",
    minWidth: "12rem",
    flexGrow: 1,
  },
  inlineInput: {
    flexGrow: 1,
    minWidth: "11rem",
  },
  logStream: {
    backgroundColor: semanticColors.bgInset,
    borderColor: semanticColors.border,
    borderRadius: semanticRadii.control,
    borderStyle: "solid",
    borderWidth: "1px",
    fontFamily: fonts.mono,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.md,
    overflow: "hidden",
  },
  logRow: {
    alignItems: "baseline",
    borderBottomColor: semanticColors.borderMuted,
    borderBottomStyle: "solid",
    borderBottomWidth: "1px",
    gridTemplateColumns: {
      default: "6.5rem 3.5rem 7rem minmax(0, 1fr)",
      [NARROW]: "minmax(0, 1fr)",
    },
    paddingBlock: spacing._2,
    paddingInline: spacing._3,
  },
  logMessage: {
    wordBreak: "break-word",
  },
  quotaGrid: {
    gridTemplateColumns: {
      default: "repeat(2, minmax(0, 1fr))",
      [COMPACT]: "minmax(0, 1fr)",
    },
  },
  planPrice: {
    letterSpacing: "-0.02em",
  },
  popoverContent: {
    "--popover-size": "21rem",
  },
  popoverHeaderRow: {
    paddingBottom: spacing._2,
  },
  notifButton: {
    alignItems: "flex-start",
    backgroundColor: {
      default: "transparent",
      ":hover": semanticColors.bgSubtle,
    },
    borderRadius: semanticRadii.control,
    borderStyle: "none",
    color: semanticColors.fg,
    cursor: "pointer",
    display: "flex",
    flexDirection: "column",
    gap: spacing._0_5,
    paddingBlock: spacing._2,
    paddingInline: spacing._2_5,
    textAlign: "start",
    width: "100%",
  },
  menuWidth: {
    minWidth: "14rem",
  },
  userMenuHeader: {
    paddingBlock: spacing._1_5,
    paddingInline: spacing._2,
  },
  paletteDialogBody: {
    display: "flex",
    flexDirection: "column",
    gap: spacing._3,
    paddingBlock: spacing._4,
  },
  paletteResults: {
    maxHeight: "18rem",
    overflowY: "auto",
  },
  paletteItem: {
    alignItems: "center",
    backgroundColor: {
      default: "transparent",
      ":hover": semanticColors.bgSubtle,
    },
    borderRadius: semanticRadii.control,
    borderStyle: "none",
    color: semanticColors.fg,
    cursor: "pointer",
    display: "flex",
    gap: spacing._2_5,
    justifyContent: "space-between",
    paddingBlock: spacing._2,
    paddingInline: spacing._2_5,
    textAlign: "start",
    width: "100%",
  },
  emptyStateText: {
    paddingBlock: spacing._6,
  },
});

export interface ShellNavProps extends StyleOverrideProps {
  /** Initial active navigation route. */
  defaultRoute?: ShellNavRoute;
  /** Initial active workspace id (`harbor-prod` | `harbor-staging` | `harbor-edge`). */
  defaultWorkspaceId?: string;
  /** Start with the desktop sidebar collapsed to an icon rail. */
  defaultSidebarCollapsed?: boolean;
  /** Called whenever the user switches the active route. */
  onRouteChange?: (route: ShellNavRoute) => void;
  /** Called whenever the user switches the active workspace. */
  onWorkspaceChange?: (workspaceId: string) => void;
}

/**
 * ShellNav — full application shell combining a top navigation bar (workspace
 * switcher, quick search dialog, notifications popover, user menu), a
 * collapsible left sidebar with grouped route navigation, a mobile slide-over
 * drawer fallback, and interactive multi-route views for Harbor Deploy.
 */
export function ShellNav({
  defaultRoute = "overview",
  defaultWorkspaceId = "harbor-prod",
  defaultSidebarCollapsed = false,
  onRouteChange,
  onWorkspaceChange,
  palette,
  style,
}: ShellNavProps) {
  const queue = useMemo(() => Toast.createToaster(), []);

  const [activeRoute, setActiveRoute] = useState<ShellNavRoute>(defaultRoute);
  const [workspaceId, setWorkspaceId] = useState<string>(defaultWorkspaceId);
  const [sidebarCollapsed, setSidebarCollapsed] = useState<boolean>(
    defaultSidebarCollapsed,
  );
  const [mobileNavOpen, setMobileNavOpen] = useState(false);
  const [searchOpen, setSearchOpen] = useState(false);
  const [searchQuery, setSearchQuery] = useState("");

  const [deployments, setDeployments] =
    useState<DeploymentItem[]>(INITIAL_DEPLOYMENTS);
  const [deployFilter, setDeployFilter] = useState<
    "all" | "live" | "building" | "failed"
  >("all");
  const [deploySearch, setDeploySearch] = useState("");

  const [logs, setLogs] = useState<LogEntry[]>(INITIAL_LOGS);
  const [logLevelFilter, setLogLevelFilter] = useState<
    "all" | "info" | "warn" | "error"
  >("all");
  const [logSearch, setLogSearch] = useState("");
  const [liveTail, setLiveTail] = useState(true);

  const [domains, setDomains] = useState<DomainItem[]>(INITIAL_DOMAINS);
  const [newDomainHost, setNewDomainHost] = useState("");

  const [envVars, setEnvVars] = useState<EnvVarItem[]>(INITIAL_ENV_VARS);
  const [envScopeFilter, setEnvScopeFilter] = useState<
    "All" | "Production" | "Preview" | "Development"
  >("All");
  const [revealedIds, setRevealedIds] = useState<Record<string, boolean>>({});
  const [newEnvKey, setNewEnvKey] = useState("");
  const [newEnvValue, setNewEnvValue] = useState("");
  const [edgeCacheEnabled, setEdgeCacheEnabled] = useState(true);
  const [autoRollbackEnabled, setAutoRollbackEnabled] = useState(true);
  const [zeroDowntimeEnabled, setZeroDowntimeEnabled] = useState(true);

  const [notifications, setNotifications] = useState<NotificationItem[]>(
    INITIAL_NOTIFICATIONS,
  );

  const activeWorkspace = useMemo(
    () => WORKSPACES.find((w) => w.id === workspaceId) ?? WORKSPACES[0],
    [workspaceId],
  );

  const unreadCount = useMemo(
    () => notifications.filter((n) => n.unread).length,
    [notifications],
  );

  const navigateTo = useCallback(
    (route: ShellNavRoute) => {
      setActiveRoute(route);
      setMobileNavOpen(false);
      onRouteChange?.(route);
    },
    [onRouteChange],
  );

  const selectWorkspace = useCallback(
    (nextId: string) => {
      const target = WORKSPACES.find((w) => w.id === nextId);
      if (!target) return;
      setWorkspaceId(nextId);
      onWorkspaceChange?.(nextId);
      queue.info(`Switched to ${target.name}`, {
        description: `${target.env} · ${target.region} (${target.release})`,
      });
    },
    [onWorkspaceChange, queue],
  );

  const triggerDeploy = useCallback(() => {
    const nextNum = 483 + (deployments.length - INITIAL_DEPLOYMENTS.length);
    const nextId = `rel-${nextNum}`;
    const newDeployment: DeploymentItem = {
      id: nextId,
      workspaceId: activeWorkspace.id,
      commit: Math.random().toString(16).slice(2, 9),
      message: `Manual promotion to ${activeWorkspace.name} (${activeWorkspace.region})`,
      branch: activeWorkspace.env === "Production" ? "main" : "staging",
      author: "Nora Lindholm",
      status: "live",
      region: activeWorkspace.region,
      duration: "31s",
      createdAt: "Just now",
    };
    setDeployments((prev) => [newDeployment, ...prev]);
    setLogs((prev) => [
      {
        id: `log-${Date.now()}`,
        timestamp: new Date().toTimeString().slice(0, 8) + ".120",
        level: "info",
        region: activeWorkspace.region,
        service: "edge-router",
        message: `Promoted ${nextId} to ${activeWorkspace.name} with zero downtime`,
      },
      ...prev,
    ]);
    queue.success(`Deployed ${nextId} to ${activeWorkspace.name}`, {
      description: `Live in ${activeWorkspace.region} · completed in 31s.`,
    });
  }, [activeWorkspace, deployments.length, queue]);

  useEffect(() => {
    const handleKeyDown = (event: KeyboardEvent) => {
      if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
        event.preventDefault();
        setSearchOpen((prev) => !prev);
      }
    };
    window.addEventListener("keydown", handleKeyDown);
    return () => window.removeEventListener("keydown", handleKeyDown);
  }, []);

  const paletteCommands = useMemo(() => {
    const items: Array<{
      id: string;
      label: string;
      category: string;
      hint?: string;
      run: () => void;
    }> = [
      ...(Object.keys(ROUTE_META) as ShellNavRoute[]).map((route) => ({
        id: `route-${route}`,
        label: ROUTE_META[route].label,
        category: "Navigate",
        hint: ROUTE_META[route].group,
        run: () => navigateTo(route),
      })),
      ...WORKSPACES.map((ws) => ({
        id: `ws-${ws.id}`,
        label: `Switch workspace: ${ws.name}`,
        category: "Workspace",
        hint: ws.region,
        run: () => selectWorkspace(ws.id),
      })),
      {
        id: "action-deploy",
        label: `Deploy latest build to ${activeWorkspace.name}`,
        category: "Action",
        hint: activeWorkspace.region,
        run: () => triggerDeploy(),
      },
      {
        id: "action-sidebar",
        label: sidebarCollapsed ? "Expand navigation sidebar" : "Collapse navigation sidebar",
        category: "View",
        hint: "Layout",
        run: () => setSidebarCollapsed((prev) => !prev),
      },
    ];
    const query = searchQuery.trim().toLowerCase();
    if (!query) return items;
    return items.filter(
      (item) =>
        item.label.toLowerCase().includes(query) ||
        item.category.toLowerCase().includes(query) ||
        (item.hint?.toLowerCase().includes(query) ?? false),
    );
  }, [
    activeWorkspace.name,
    activeWorkspace.region,
    navigateTo,
    searchQuery,
    selectWorkspace,
    sidebarCollapsed,
    triggerDeploy,
  ]);

  const filteredDeployments = useMemo(() => {
    const q = deploySearch.trim().toLowerCase();
    return deployments.filter((item) => {
      if (deployFilter !== "all" && item.status !== deployFilter) return false;
      if (!q) return true;
      return (
        item.id.toLowerCase().includes(q) ||
        item.message.toLowerCase().includes(q) ||
        item.branch.toLowerCase().includes(q) ||
        item.commit.toLowerCase().includes(q)
      );
    });
  }, [deployFilter, deploySearch, deployments]);

  const filteredLogs = useMemo(() => {
    const q = logSearch.trim().toLowerCase();
    return logs.filter((entry) => {
      if (logLevelFilter !== "all" && entry.level !== logLevelFilter) {
        return false;
      }
      if (!q) return true;
      return (
        entry.message.toLowerCase().includes(q) ||
        entry.service.toLowerCase().includes(q) ||
        entry.region.toLowerCase().includes(q)
      );
    });
  }, [logLevelFilter, logSearch, logs]);

  const filteredEnvVars = useMemo(() => {
    if (envScopeFilter === "All") return envVars;
    return envVars.filter((item) => item.scope === envScopeFilter);
  }, [envScopeFilter, envVars]);

  const handleAddDomain = (event: React.FormEvent) => {
    event.preventDefault();
    const cleaned = newDomainHost.trim().toLowerCase();
    if (!cleaned) return;
    if (domains.some((d) => d.host === cleaned)) {
      queue.warning(`${cleaned} is already configured`);
      return;
    }
    setDomains((prev) => [
      {
        id: `dom-${Date.now()}`,
        host: cleaned,
        target: `${activeWorkspace.env.toLowerCase()} · ${activeWorkspace.region}`,
        tls: "Provisioning",
        status: "pending",
      },
      ...prev,
    ]);
    setNewDomainHost("");
    queue.success(`Added ${cleaned}`, {
      description: "Point a CNAME record to edge.harbordeploy.net to finish verification.",
    });
  };

  const handleVerifyDomain = (domain: DomainItem) => {
    setDomains((prev) =>
      prev.map((item) =>
        item.id === domain.id
          ? { ...item, status: "verified", tls: "Valid · Auto-renew" }
          : item,
      ),
    );
    queue.success(`Verified ${domain.host}`, {
      description: "TLS certificate issued and edge routing active.",
    });
  };

  const handleAddEnvVar = (event: React.FormEvent) => {
    event.preventDefault();
    const key = newEnvKey.trim().toUpperCase().replace(/[^A-Z0-9_]/g, "_");
    const value = newEnvValue.trim();
    if (!key || !value) {
      queue.warning("Enter both a variable name and value");
      return;
    }
    setEnvVars((prev) => [
      {
        id: `env-${Date.now()}`,
        key,
        value,
        scope: envScopeFilter === "All" ? "Production" : envScopeFilter,
        secret: key.includes("SECRET") || key.includes("TOKEN") || key.includes("KEY"),
        updatedAt: "Just now",
      },
      ...prev,
    ]);
    setNewEnvKey("");
    setNewEnvValue("");
    queue.success(`Saved ${key}`, {
      description: "Encrypted at rest and queued for the next release.",
    });
  };

  const workspaceBadgePalette =
    activeWorkspace.palette === "green"
      ? greenPalette
      : activeWorkspace.palette === "amber"
        ? amberPalette
        : bluePalette;

  const renderNavGroups = (collapsed: boolean) => (
    <>
      <Sidebar.Group>
        {!collapsed ? (
          <Sidebar.GroupHeader>
            <Sidebar.GroupTitle>Platform</Sidebar.GroupTitle>
          </Sidebar.GroupHeader>
        ) : null}
        <Sidebar.GroupContent>
          <VStack render={<ul />} gap="0.5" style={styles.navList}>
            {PLATFORM_ROUTES.map((route) => {
              const active = activeRoute === route;
              const meta = ROUTE_META[route];
              return (
                <SidebarNavItem.Item key={route} variant="muted" size="md">
                  <SidebarNavItem.Button
                    type="button"
                    aria-current={active ? "page" : undefined}
                    aria-label={collapsed ? meta.label : undefined}
                    title={collapsed ? meta.label : undefined}
                    style={[
                      active && sidebarNavItemActive,
                      collapsed && styles.navButtonCollapsed,
                    ]}
                    onClick={() => navigateTo(route)}
                  >
                    <SidebarNavItem.Icon
                      viewBox="0 0 20 20"
                      fill="none"
                      stroke="currentColor"
                      strokeWidth="1.5"
                      strokeLinecap="round"
                      strokeLinejoin="round"
                      aria-hidden="true"
                    >
                      <RouteGlyph route={route} />
                    </SidebarNavItem.Icon>
                    {!collapsed ? (
                      <>
                        <Text render={<span />} size="sm" truncate="true">
                          {meta.label}
                        </Text>
                        {route === "deployments" ? (
                          <SidebarNavItem.EndElement>
                            <Badge variant="subtle" size="xs">
                              {deployments.length}
                            </Badge>
                          </SidebarNavItem.EndElement>
                        ) : null}
                        {route === "logs" && liveTail ? (
                          <SidebarNavItem.EndElement>
                            <Status.Root size="sm" palette={greenPalette}>
                              <Status.Indicator />
                            </Status.Root>
                          </SidebarNavItem.EndElement>
                        ) : null}
                      </>
                    ) : null}
                  </SidebarNavItem.Button>
                </SidebarNavItem.Item>
              );
            })}
          </VStack>
        </Sidebar.GroupContent>
      </Sidebar.Group>

      <Sidebar.Group>
        {!collapsed ? (
          <Sidebar.GroupHeader>
            <Sidebar.GroupTitle>Configuration</Sidebar.GroupTitle>
          </Sidebar.GroupHeader>
        ) : null}
        <Sidebar.GroupContent>
          <VStack render={<ul />} gap="0.5" style={styles.navList}>
            {CONFIG_ROUTES.map((route) => {
              const active = activeRoute === route;
              const meta = ROUTE_META[route];
              return (
                <SidebarNavItem.Item key={route} variant="muted" size="md">
                  <SidebarNavItem.Button
                    type="button"
                    aria-current={active ? "page" : undefined}
                    aria-label={collapsed ? meta.label : undefined}
                    title={collapsed ? meta.label : undefined}
                    style={[
                      active && sidebarNavItemActive,
                      collapsed && styles.navButtonCollapsed,
                    ]}
                    onClick={() => navigateTo(route)}
                  >
                    <SidebarNavItem.Icon
                      viewBox="0 0 20 20"
                      fill="none"
                      stroke="currentColor"
                      strokeWidth="1.5"
                      strokeLinecap="round"
                      strokeLinejoin="round"
                      aria-hidden="true"
                    >
                      <RouteGlyph route={route} />
                    </SidebarNavItem.Icon>
                    {!collapsed ? (
                      <Text render={<span />} size="sm" truncate="true">
                        {meta.label}
                      </Text>
                    ) : null}
                  </SidebarNavItem.Button>
                </SidebarNavItem.Item>
              );
            })}
          </VStack>
        </Sidebar.GroupContent>
      </Sidebar.Group>
    </>
  );

  return (
    <AppShell.Root palette={palette} style={[styles.root, style]}>
      <Navbar.Root variant="neutral" size="md" style={styles.navbar}>
        <Navbar.Content>
          <HStack gap="2">
            <IconButton
              variant="ghost"
              size="sm"
              aria-label="Open navigation menu"
              style={styles.mobileMenuTrigger}
              onClick={() => setMobileNavOpen(true)}
            >
              <Icon
                size="sm"
                viewBox="0 0 20 20"
                fill="none"
                stroke="currentColor"
                strokeWidth="1.6"
                strokeLinecap="round"
                aria-hidden="true"
              >
                <path d="M3.5 5.5h13" />
                <path d="M3.5 10h13" />
                <path d="M3.5 14.5h13" />
              </Icon>
            </IconButton>

            <IconButton
              variant="ghost"
              size="sm"
              aria-label={
                sidebarCollapsed ? "Expand sidebar" : "Collapse sidebar"
              }
              aria-expanded={!sidebarCollapsed}
              style={styles.desktopCollapseTrigger}
              onClick={() => setSidebarCollapsed((prev) => !prev)}
            >
              <Icon
                size="sm"
                viewBox="0 0 20 20"
                fill="none"
                stroke="currentColor"
                strokeWidth="1.5"
                strokeLinecap="round"
                strokeLinejoin="round"
                aria-hidden="true"
              >
                <rect x="3" y="3.5" width="14" height="13" rx="2" />
                <path d="M7.5 3.5v13" />
              </Icon>
            </IconButton>

            <span {...stylex.props(styles.brandMark)}>
              <HarborMark />
            </span>
            <Text
              render={<span />}
              size="sm"
              weight="semibold"
              style={styles.brandTitle}
            >
              Harbor Deploy
            </Text>
            <Text
              render={<span />}
              size="sm"
              tone="subtle"
              aria-hidden="true"
              style={styles.brandDivider}
            >
              /
            </Text>

            <Menu.Root size="md">
              <Menu.Trigger
                render={
                  <Button
                    variant="ghost"
                    size="sm"
                    style={styles.workspaceTrigger}
                  />
                }
              >
                <Text render={<span />} size="sm" truncate="true">
                  {activeWorkspace.name}
                </Text>
                <Badge
                  variant="subtle"
                  size="xs"
                  palette={workspaceBadgePalette}
                  style={styles.workspaceEnvBadge}
                >
                  {activeWorkspace.env}
                </Badge>
                <Icon
                  size="xs"
                  viewBox="0 0 16 16"
                  fill="none"
                  stroke="currentColor"
                  strokeWidth="1.6"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                  aria-hidden="true"
                >
                  <path d="m4.5 6.25 3.5 3.5 3.5-3.5" />
                </Icon>
              </Menu.Trigger>
              <Menu.Content align="start" style={styles.menuWidth}>
                <Menu.Group>
                  <Menu.GroupLabel>Workspaces</Menu.GroupLabel>
                  <Menu.RadioGroup
                    value={workspaceId}
                    onValueChange={(next) => selectWorkspace(next)}
                  >
                    {WORKSPACES.map((ws) => (
                      <Menu.RadioItem key={ws.id} value={ws.id}>
                        <Menu.ItemIndicator />
                        <Menu.ItemText>{ws.name}</Menu.ItemText>
                        <Menu.ItemCommand>{ws.region}</Menu.ItemCommand>
                      </Menu.RadioItem>
                    ))}
                  </Menu.RadioGroup>
                </Menu.Group>
                <Menu.Separator />
                <Menu.Item
                  onSelect={() =>
                    queue.info("New workspace wizard", {
                      description: "Provision isolated regions, domains, and IAM policies.",
                    })
                  }
                >
                  <Menu.ItemText>Create workspace…</Menu.ItemText>
                </Menu.Item>
              </Menu.Content>
            </Menu.Root>
          </HStack>

          <HStack gap="2" style={styles.shrink0}>
            <button
              type="button"
              aria-label="Search routes, workspaces, and commands"
              onClick={() => setSearchOpen(true)}
              {...stylex.props(styles.searchTrigger)}
            >
              <span {...stylex.props(styles.searchTriggerLabel)}>
                <Icon
                  size="xs"
                  viewBox="0 0 16 16"
                  fill="none"
                  stroke="currentColor"
                  strokeWidth="1.5"
                  strokeLinecap="round"
                  aria-hidden="true"
                >
                  <circle cx="7.25" cy="7.25" r="4.5" />
                  <path d="m10.75 10.75 2.75 2.75" />
                </Icon>
                <span {...stylex.props(styles.searchPlaceholderText)}>
                  Search workspace…
                </span>
              </span>
              <Kbd size="xs" variant="outline" style={styles.searchKbd}>
                ⌘K
              </Kbd>
            </button>

            <Popover.Root size="sm">
              <div {...stylex.props(styles.iconButtonWrap)}>
                <Popover.Trigger
                  render={
                    <IconButton
                      variant="ghost"
                      size="sm"
                      aria-label={`Notifications (${unreadCount} unread)`}
                    />
                  }
                >
                  <Icon
                    size="sm"
                    viewBox="0 0 20 20"
                    fill="none"
                    stroke="currentColor"
                    strokeWidth="1.5"
                    strokeLinecap="round"
                    strokeLinejoin="round"
                    aria-hidden="true"
                  >
                    <path d="M5.5 8.5a4.5 4.5 0 1 1 9 0c0 3 1.25 4.5 1.75 5.25H3.75C4.25 13 5.5 11.5 5.5 8.5Z" />
                    <path d="M8.5 16a1.75 1.75 0 0 0 3 0" />
                  </Icon>
                </Popover.Trigger>
                {unreadCount > 0 ? (
                  <span {...stylex.props(styles.unreadDot)} aria-hidden="true" />
                ) : null}
              </div>
              <Popover.Content align="end" style={styles.popoverContent}>
                <Popover.Header>
                  <HStack justify="between" style={styles.popoverHeaderRow}>
                    <Popover.Title>Notifications</Popover.Title>
                    {unreadCount > 0 ? (
                      <Button
                        variant="plain"
                        size="xs"
                        onClick={() => {
                          setNotifications((prev) =>
                            prev.map((n) => ({ ...n, unread: false })),
                          );
                          queue.info("All notifications marked as read");
                        }}
                      >
                        Mark all read
                      </Button>
                    ) : null}
                  </HStack>
                </Popover.Header>
                <Separator />
                <Popover.Body>
                  <VStack gap="1.5">
                    {notifications.map((notif) => (
                      <button
                        key={notif.id}
                        type="button"
                        onClick={() => {
                          setNotifications((prev) =>
                            prev.map((n) =>
                              n.id === notif.id ? { ...n, unread: false } : n,
                            ),
                          );
                          navigateTo(notif.route);
                        }}
                        {...stylex.props(styles.notifButton)}
                      >
                        <HStack
                          gap="2"
                          justify="between"
                          style={styles.fullWidth}
                        >
                          <Text render={<span />} size="sm" weight="medium">
                            {notif.title}
                          </Text>
                          {notif.unread ? (
                            <Badge
                              variant="subtle"
                              size="xs"
                              palette={accentPalette}
                            >
                              New
                            </Badge>
                          ) : (
                            <Text render={<span />} size="xs" tone="muted">
                              {notif.time}
                            </Text>
                          )}
                        </HStack>
                        <Text render={<span />} size="xs" tone="muted">
                          {notif.detail}
                        </Text>
                      </button>
                    ))}
                  </VStack>
                </Popover.Body>
              </Popover.Content>
            </Popover.Root>

            <Button
              variant="solid"
              size="sm"
              palette={accentPalette}
              style={styles.deployButton}
              onClick={triggerDeploy}
            >
              Deploy
            </Button>

            <Menu.Root size="md">
              <Menu.Trigger
                render={
                  <Button
                    variant="ghost"
                    size="sm"
                    aria-label="Account menu"
                    style={styles.avatarTrigger}
                  />
                }
              >
                <Avatar.Root
                  size="sm"
                  variant="subtle"
                  palette={accentPalette}
                >
                  <Avatar.Fallback>NL</Avatar.Fallback>
                </Avatar.Root>
              </Menu.Trigger>
              <Menu.Content align="end" style={styles.menuWidth}>
                <VStack gap="0.5" style={styles.userMenuHeader}>
                  <Text render={<span />} size="sm" weight="medium">
                    Nora Lindholm
                  </Text>
                  <Text render={<span />} size="xs" tone="muted">
                    nora@harbordeploy.dev
                  </Text>
                </VStack>
                <Menu.Separator />
                <Menu.Item onSelect={() => navigateTo("environment")}>
                  <Menu.ItemText>Environment &amp; secrets</Menu.ItemText>
                </Menu.Item>
                <Menu.Item onSelect={() => navigateTo("billing")}>
                  <Menu.ItemText>Billing &amp; quotas</Menu.ItemText>
                </Menu.Item>
                <Menu.Item onSelect={() => setSearchOpen(true)}>
                  <Menu.ItemText>Command palette</Menu.ItemText>
                  <Menu.ItemCommand>⌘K</Menu.ItemCommand>
                </Menu.Item>
                <Menu.Separator />
                <Menu.Item
                  destructive
                  onSelect={() =>
                    queue.info("Signed out of Harbor Deploy", {
                      description: "Session tokens cleared for this browser.",
                    })
                  }
                >
                  <Menu.ItemText>Sign out</Menu.ItemText>
                </Menu.Item>
              </Menu.Content>
            </Menu.Root>
          </HStack>
        </Navbar.Content>
      </Navbar.Root>

      <AppShell.Content>
        <Sidebar.Root
          variant="sidebar"
          mode="collapsible"
          size="md"
          aria-label="Workspace navigation"
          style={[styles.sidebar, sidebarCollapsed && styles.sidebarCollapsed]}
        >
          <Sidebar.Body
            style={sidebarCollapsed ? styles.sidebarBodyCollapsed : undefined}
          >
            {renderNavGroups(sidebarCollapsed)}
          </Sidebar.Body>
          <Sidebar.Footer style={styles.sidebarFooter}>
            {sidebarCollapsed ? (
              <Center
                style={styles.clusterCardCollapsed}
                title={`${activeWorkspace.region} · All systems operational`}
              >
                <Status.Root size="sm" palette={greenPalette}>
                  <Status.Indicator />
                </Status.Root>
              </Center>
            ) : (
              <VStack gap="1" style={styles.clusterCard}>
                <Status.Root size="sm" palette={greenPalette}>
                  <Status.Indicator />
                  All regions healthy
                </Status.Root>
                <Text render={<span />} size="xs" tone="muted">
                  {activeWorkspace.region} · {activeWorkspace.release} ·{" "}
                  {activeWorkspace.uptime}
                </Text>
              </VStack>
            )}
          </Sidebar.Footer>
        </Sidebar.Root>

        <AppShell.Main style={styles.main}>
          <VStack gap="6" style={styles.mainInner}>
            <HStack
              render={<header />}
              gap="4"
              justify="between"
              style={styles.pageHeader}
            >
              <VStack gap="1">
                <HStack gap="1.5" style={styles.breadcrumbRow}>
                  <span>{activeWorkspace.name}</span>
                  <span aria-hidden="true">/</span>
                  <span>{ROUTE_META[activeRoute].group}</span>
                  <span aria-hidden="true">/</span>
                  <span>{ROUTE_META[activeRoute].label}</span>
                </HStack>
                <Heading render={<h1 />} size="2xl" style={styles.pageTitle}>
                  {ROUTE_META[activeRoute].label}
                </Heading>
                <Text size="sm" tone="muted">
                  {ROUTE_META[activeRoute].description}
                </Text>
              </VStack>

              <HStack gap="2" wrap="wrap">
                {activeRoute === "overview" ? (
                  <>
                    <Button
                      variant="surface"
                      size="sm"
                      onClick={() => navigateTo("logs")}
                    >
                      Tail live logs
                    </Button>
                    <Button
                      variant="solid"
                      size="sm"
                      palette={accentPalette}
                      onClick={triggerDeploy}
                    >
                      New deployment
                    </Button>
                  </>
                ) : null}
                {activeRoute === "deployments" ? (
                  <Button
                    variant="solid"
                    size="sm"
                    palette={accentPalette}
                    onClick={triggerDeploy}
                  >
                    Trigger deployment
                  </Button>
                ) : null}
                {activeRoute === "logs" ? (
                  <Button
                    variant="surface"
                    size="sm"
                    onClick={() => {
                      const entry: LogEntry = {
                        id: `log-${Date.now()}`,
                        timestamp: new Date().toTimeString().slice(0, 8) + ".408",
                        level: "info",
                        region: activeWorkspace.region,
                        service: "edge-probe",
                        message: `Synthetic health check succeeded on ${activeWorkspace.name} (200 OK · 19ms)`,
                      };
                      setLogs((prev) => [entry, ...prev]);
                      queue.info("Synthetic health check logged");
                    }}
                  >
                    Emit test event
                  </Button>
                ) : null}
                {activeRoute === "billing" ? (
                  <Button
                    variant="surface"
                    size="sm"
                    onClick={() =>
                      queue.info("Invoice archive exported", {
                        description: "CSV summary ready for November 2026.",
                      })
                    }
                  >
                    Export statements
                  </Button>
                ) : null}
              </HStack>
            </HStack>

            {activeRoute === "overview" ? (
              <>
                <Grid gap="4" style={styles.statGrid}>
                  <Card.Root variant="outline" size="md">
                    <Card.Body>
                      <Stat.Root size="md">
                        <Stat.Label>Active Deployments</Stat.Label>
                        <Stat.ValueText>
                          {activeWorkspace.activeDeployments}
                        </Stat.ValueText>
                        <Stat.HelpText>
                          Latest: {activeWorkspace.release}
                        </Stat.HelpText>
                      </Stat.Root>
                    </Card.Body>
                  </Card.Root>

                  <Card.Root variant="outline" size="md">
                    <Card.Body>
                      <Stat.Root size="md">
                        <Stat.Label>P95 Edge Latency</Stat.Label>
                        <Stat.ValueText>
                          {activeWorkspace.p95Latency}
                        </Stat.ValueText>
                        <Stat.HelpText>-14% vs last 7 days</Stat.HelpText>
                      </Stat.Root>
                    </Card.Body>
                  </Card.Root>

                  <Card.Root variant="outline" size="md">
                    <Card.Body>
                      <Stat.Root size="md">
                        <Stat.Label>30d Availability</Stat.Label>
                        <Stat.ValueText>{activeWorkspace.uptime}</Stat.ValueText>
                        <Stat.HelpText>Zero severity-1 incidents</Stat.HelpText>
                      </Stat.Root>
                    </Card.Body>
                  </Card.Root>

                  <Card.Root variant="outline" size="md">
                    <Card.Body>
                      <Stat.Root size="md">
                        <Stat.Label>Monthly Bandwidth</Stat.Label>
                        <Stat.ValueText>
                          {activeWorkspace.bandwidth}
                        </Stat.ValueText>
                        <Stat.HelpText>61% of 3.00 TB allowance</Stat.HelpText>
                      </Stat.Root>
                    </Card.Body>
                  </Card.Root>
                </Grid>

                <Grid gap="4" style={styles.twoColGrid}>
                  <Card.Root variant="outline" size="md">
                    <Card.Header style={styles.cardHeaderRow}>
                      <VStack gap="1">
                        <Card.Title style={styles.cardTitleReset}>
                          Recent Deployments
                        </Card.Title>
                        <Card.Description style={styles.cardDescReset}>
                          Latest builds promoted across {activeWorkspace.name}
                        </Card.Description>
                      </VStack>
                      <Button
                        variant="ghost"
                        size="xs"
                        onClick={() => navigateTo("deployments")}
                      >
                        View all
                      </Button>
                    </Card.Header>
                    <Card.Body>
                      <div {...stylex.props(styles.tableWrap)}>
                        <Table.Root variant="line" size="sm">
                          <Table.Header>
                            <Table.Row>
                              <Table.ColumnHeader>Release</Table.ColumnHeader>
                              <Table.ColumnHeader>Branch</Table.ColumnHeader>
                              <Table.ColumnHeader>Status</Table.ColumnHeader>
                              <Table.ColumnHeader>Time</Table.ColumnHeader>
                            </Table.Row>
                          </Table.Header>
                          <Table.Body>
                            {deployments.slice(0, 4).map((item) => (
                              <Table.Row key={item.id}>
                                <Table.Cell>
                                  <VStack gap="0.5">
                                    <Text
                                      render={<span />}
                                      size="sm"
                                      weight="medium"
                                    >
                                      {item.id}
                                    </Text>
                                    <Text
                                      render={<span />}
                                      size="xs"
                                      tone="muted"
                                    >
                                      {item.message}
                                    </Text>
                                  </VStack>
                                </Table.Cell>
                                <Table.Cell>
                                  <Code size="xs">{item.branch}</Code>
                                </Table.Cell>
                                <Table.Cell>
                                  <Status.Root
                                    size="sm"
                                    palette={
                                      item.status === "live"
                                        ? greenPalette
                                        : item.status === "building"
                                          ? amberPalette
                                          : redPalette
                                    }
                                  >
                                    <Status.Indicator />
                                    {item.status === "live"
                                      ? "Live"
                                      : item.status === "building"
                                        ? "Building"
                                        : "Failed"}
                                  </Status.Root>
                                </Table.Cell>
                                <Table.Cell>
                                  <Text render={<span />} size="xs" tone="muted">
                                    {item.createdAt}
                                  </Text>
                                </Table.Cell>
                              </Table.Row>
                            ))}
                          </Table.Body>
                        </Table.Root>
                      </div>
                    </Card.Body>
                  </Card.Root>

                  <Card.Root variant="outline" size="md">
                    <Card.Header>
                      <Card.Title style={styles.cardTitleReset}>
                        Edge Regions
                      </Card.Title>
                      <Card.Description style={styles.cardDescReset}>
                        Live capacity and routing latency per PoP cluster
                      </Card.Description>
                    </Card.Header>
                    <Card.Body>
                      <VStack gap="4">
                        {EDGE_REGIONS.map((region) => (
                          <VStack key={region.id} gap="1.5">
                            <HStack gap="2" justify="between">
                              <HStack render={<span />} gap="2">
                                <Status.Root size="sm" palette={greenPalette}>
                                  <Status.Indicator />
                                </Status.Root>
                                <Text
                                  render={<span />}
                                  size="sm"
                                  weight="medium"
                                >
                                  {region.city}
                                </Text>
                                <Code size="xs">{region.id}</Code>
                              </HStack>
                              <Text render={<span />} size="xs" tone="muted">
                                {region.latency} · {region.load}% load
                              </Text>
                            </HStack>
                            <Progress.Root
                              value={region.load}
                              variant="subtle"
                              size="xs"
                              shape="full"
                              palette={accentPalette}
                            >
                              <Progress.Track>
                                <Progress.Range />
                              </Progress.Track>
                            </Progress.Root>
                          </VStack>
                        ))}

                        <Separator />

                        <HStack
                          gap="2"
                          wrap="wrap"
                          style={styles.quickActionGrid}
                        >
                          <Button
                            variant="surface"
                            size="xs"
                            onClick={() => navigateTo("domains")}
                          >
                            Manage domains
                          </Button>
                          <Button
                            variant="surface"
                            size="xs"
                            onClick={() => navigateTo("environment")}
                          >
                            Edit secrets
                          </Button>
                          <Button
                            variant="surface"
                            size="xs"
                            onClick={() => navigateTo("billing")}
                          >
                            Inspect quotas
                          </Button>
                        </HStack>
                      </VStack>
                    </Card.Body>
                  </Card.Root>
                </Grid>
              </>
            ) : null}

            {activeRoute === "deployments" ? (
              <Card.Root variant="outline" size="md">
                <Card.Header>
                  <HStack gap="3" wrap="wrap" justify="between">
                    <HStack gap="1.5" wrap="wrap">
                      {(["all", "live", "building", "failed"] as const).map(
                        (status) => (
                          <Button
                            key={status}
                            variant={deployFilter === status ? "solid" : "surface"}
                            size="xs"
                            palette={
                              deployFilter === status ? accentPalette : undefined
                            }
                            onClick={() => setDeployFilter(status)}
                          >
                            {status === "all"
                              ? "All"
                              : status[0].toUpperCase() + status.slice(1)}
                          </Button>
                        ),
                      )}
                    </HStack>
                    <div {...stylex.props(styles.inlineSearch)}>
                      <Input
                        size="sm"
                        placeholder="Filter by release, branch, or commit…"
                        value={deploySearch}
                        onChange={(event) => setDeploySearch(event.target.value)}
                      />
                    </div>
                  </HStack>
                </Card.Header>
                <Card.Body>
                  <div {...stylex.props(styles.tableWrap)}>
                    <Table.Root variant="line" size="md">
                      <Table.Header>
                        <Table.Row>
                          <Table.ColumnHeader>Release</Table.ColumnHeader>
                          <Table.ColumnHeader>Commit</Table.ColumnHeader>
                          <Table.ColumnHeader>Status</Table.ColumnHeader>
                          <Table.ColumnHeader>Region</Table.ColumnHeader>
                          <Table.ColumnHeader>Duration</Table.ColumnHeader>
                          <Table.ColumnHeader>Action</Table.ColumnHeader>
                        </Table.Row>
                      </Table.Header>
                      <Table.Body>
                        {filteredDeployments.map((item) => (
                          <Table.Row key={item.id}>
                            <Table.Cell>
                              <VStack gap="0.5">
                                <Text
                                  render={<span />}
                                  size="sm"
                                  weight="medium"
                                >
                                  {item.id}
                                </Text>
                                <Text render={<span />} size="xs" tone="muted">
                                  {item.message}
                                </Text>
                              </VStack>
                            </Table.Cell>
                            <Table.Cell>
                              <VStack gap="0.5">
                                <Code size="xs">{item.branch}</Code>
                                <Text render={<span />} variant="mono" size="xs">
                                  {item.commit} · {item.author}
                                </Text>
                              </VStack>
                            </Table.Cell>
                            <Table.Cell>
                              <Badge
                                variant="subtle"
                                size="sm"
                                palette={
                                  item.status === "live"
                                    ? greenPalette
                                    : item.status === "building"
                                      ? amberPalette
                                      : redPalette
                                }
                              >
                                {item.status === "live"
                                  ? "Live"
                                  : item.status === "building"
                                    ? "Building"
                                    : "Failed"}
                              </Badge>
                            </Table.Cell>
                            <Table.Cell>
                              <Code size="xs">{item.region}</Code>
                            </Table.Cell>
                            <Table.Cell>
                              <VStack gap="0.5">
                                <span>{item.duration}</span>
                                <Text render={<span />} size="xs" tone="muted">
                                  {item.createdAt}
                                </Text>
                              </VStack>
                            </Table.Cell>
                            <Table.Cell>
                              <Button
                                variant="ghost"
                                size="xs"
                                onClick={() => {
                                  setDeployments((prev) =>
                                    prev.map((d) =>
                                      d.id === item.id
                                        ? { ...d, status: "live", createdAt: "Just now" }
                                        : d,
                                    ),
                                  );
                                  queue.success(`Promoted ${item.id}`, {
                                    description: `Traffic routed to ${item.commit} in ${item.region}.`,
                                  });
                                }}
                              >
                                {item.status === "live" ? "Redeploy" : "Promote"}
                              </Button>
                            </Table.Cell>
                          </Table.Row>
                        ))}
                      </Table.Body>
                    </Table.Root>
                    {filteredDeployments.length === 0 ? (
                      <Text
                        size="sm"
                        tone="muted"
                        align="center"
                        style={styles.emptyStateText}
                      >
                        No deployments match the current filter.
                      </Text>
                    ) : null}
                  </div>
                </Card.Body>
              </Card.Root>
            ) : null}

            {activeRoute === "logs" ? (
              <Card.Root variant="outline" size="md">
                <Card.Header>
                  <HStack gap="3" wrap="wrap" justify="between">
                    <HStack gap="1.5" wrap="wrap">
                      {(["all", "info", "warn", "error"] as const).map((lvl) => (
                        <Button
                          key={lvl}
                          variant={logLevelFilter === lvl ? "solid" : "surface"}
                          size="xs"
                          palette={
                            logLevelFilter === lvl ? accentPalette : undefined
                          }
                          onClick={() => setLogLevelFilter(lvl)}
                        >
                          {lvl.toUpperCase()}
                        </Button>
                      ))}
                      <Switch.Root
                        size="sm"
                        palette={greenPalette}
                      >
                        <Switch.Control
                          checked={liveTail}
                          onCheckedChange={(checked) => {
                            setLiveTail(checked);
                            queue.info(
                              checked ? "Live log stream resumed" : "Log stream paused",
                            );
                          }}
                        />
                        <Switch.Label>Live tail</Switch.Label>
                      </Switch.Root>
                    </HStack>
                    <div {...stylex.props(styles.inlineSearch)}>
                      <Input
                        size="sm"
                        placeholder="Search service, region, or message…"
                        value={logSearch}
                        onChange={(event) => setLogSearch(event.target.value)}
                      />
                    </div>
                  </HStack>
                </Card.Header>
                <Card.Body>
                  <VStack gap="0" role="log" style={styles.logStream}>
                    {filteredLogs.map((entry) => (
                      <Grid key={entry.id} gap="3" style={styles.logRow}>
                        <Text
                          render={<span />}
                          variant="mono"
                          size="xs"
                          tone="subtle"
                          tabular="true"
                        >
                          {entry.timestamp}
                        </Text>
                        <span>
                          <Badge
                            variant="subtle"
                            size="xs"
                            palette={
                              entry.level === "error"
                                ? redPalette
                                : entry.level === "warn"
                                  ? amberPalette
                                  : bluePalette
                            }
                          >
                            {entry.level.toUpperCase()}
                          </Badge>
                        </span>
                        <Text
                          render={<span />}
                          variant="mono"
                          size="xs"
                          tone="muted"
                        >
                          {entry.service}
                        </Text>
                        <Text
                          render={<span />}
                          variant="mono"
                          size="xs"
                          style={styles.logMessage}
                        >
                          [{entry.region}] {entry.message}
                        </Text>
                      </Grid>
                    ))}
                    {filteredLogs.length === 0 ? (
                      <Text
                        size="sm"
                        tone="muted"
                        align="center"
                        style={styles.emptyStateText}
                      >
                        No log lines match your query.
                      </Text>
                    ) : null}
                  </VStack>
                </Card.Body>
              </Card.Root>
            ) : null}

            {activeRoute === "domains" ? (
              <>
                <Card.Root variant="outline" size="md">
                  <Card.Header>
                    <Card.Title style={styles.cardTitleReset}>
                      Add Custom Domain
                    </Card.Title>
                    <Card.Description style={styles.cardDescReset}>
                      Attach an apex domain or subdomain with automatic edge TLS
                    </Card.Description>
                  </Card.Header>
                  <Card.Body>
                    <HStack
                      render={<form onSubmit={handleAddDomain} />}
                      gap="2"
                      wrap="wrap"
                    >
                      <div {...stylex.props(styles.inlineInput)}>
                        <Input
                          size="sm"
                          placeholder="e.g. status.harbor.app"
                          value={newDomainHost}
                          onChange={(event) => setNewDomainHost(event.target.value)}
                        />
                      </div>
                      <Button
                        type="submit"
                        variant="solid"
                        size="sm"
                        palette={accentPalette}
                      >
                        Add domain
                      </Button>
                    </HStack>
                  </Card.Body>
                </Card.Root>

                <Card.Root variant="outline" size="md">
                  <Card.Header>
                    <Card.Title style={styles.cardTitleReset}>
                      Configured Domains
                    </Card.Title>
                    <Card.Description style={styles.cardDescReset}>
                      CNAME target: <Code size="xs">edge.harbordeploy.net</Code>
                    </Card.Description>
                  </Card.Header>
                  <Card.Body>
                    <div {...stylex.props(styles.tableWrap)}>
                      <Table.Root variant="line" size="md">
                        <Table.Header>
                          <Table.Row>
                            <Table.ColumnHeader>Hostname</Table.ColumnHeader>
                            <Table.ColumnHeader>Target</Table.ColumnHeader>
                            <Table.ColumnHeader>TLS Certificate</Table.ColumnHeader>
                            <Table.ColumnHeader>DNS</Table.ColumnHeader>
                            <Table.ColumnHeader>Action</Table.ColumnHeader>
                          </Table.Row>
                        </Table.Header>
                        <Table.Body>
                          {domains.map((domain) => (
                            <Table.Row key={domain.id}>
                              <Table.Cell>
                                <HStack gap="1.5" wrap="wrap">
                                  <Text
                                    render={<span />}
                                    size="sm"
                                    weight="medium"
                                  >
                                    {domain.host}
                                  </Text>
                                  {domain.primary ? (
                                    <Badge
                                      variant="subtle"
                                      size="xs"
                                      palette={accentPalette}
                                    >
                                      Primary
                                    </Badge>
                                  ) : null}
                                </HStack>
                              </Table.Cell>
                              <Table.Cell>
                                <Code size="xs">{domain.target}</Code>
                              </Table.Cell>
                              <Table.Cell>
                                <Badge
                                  variant="subtle"
                                  size="xs"
                                  palette={
                                    domain.status === "verified"
                                      ? greenPalette
                                      : amberPalette
                                  }
                                >
                                  {domain.tls}
                                </Badge>
                              </Table.Cell>
                              <Table.Cell>
                                <Status.Root
                                  size="sm"
                                  palette={
                                    domain.status === "verified"
                                      ? greenPalette
                                      : amberPalette
                                  }
                                >
                                  <Status.Indicator />
                                  {domain.status === "verified"
                                    ? "Verified"
                                    : "Pending"}
                                </Status.Root>
                              </Table.Cell>
                              <Table.Cell>
                                {domain.status === "pending" ? (
                                  <Button
                                    variant="surface"
                                    size="xs"
                                    onClick={() => handleVerifyDomain(domain)}
                                  >
                                    Verify DNS
                                  </Button>
                                ) : (
                                  <Button
                                    variant="ghost"
                                    size="xs"
                                    onClick={() =>
                                      queue.info(`Copied CNAME for ${domain.host}`, {
                                        description: "edge.harbordeploy.net",
                                      })
                                    }
                                  >
                                    Copy CNAME
                                  </Button>
                                )}
                              </Table.Cell>
                            </Table.Row>
                          ))}
                        </Table.Body>
                      </Table.Root>
                    </div>
                  </Card.Body>
                </Card.Root>
              </>
            ) : null}

            {activeRoute === "environment" ? (
              <>
                <Card.Root variant="outline" size="md">
                  <Card.Header>
                    <HStack gap="3" wrap="wrap" justify="between">
                      <VStack gap="1">
                        <Card.Title style={styles.cardTitleReset}>
                          Variables &amp; Secrets
                        </Card.Title>
                        <Card.Description style={styles.cardDescReset}>
                          Injected at build and runtime for {activeWorkspace.name}
                        </Card.Description>
                      </VStack>
                      <HStack gap="1.5" wrap="wrap">
                        {(
                          ["All", "Production", "Preview", "Development"] as const
                        ).map((scope) => (
                          <Button
                            key={scope}
                            variant={envScopeFilter === scope ? "solid" : "surface"}
                            size="xs"
                            palette={
                              envScopeFilter === scope ? accentPalette : undefined
                            }
                            onClick={() => setEnvScopeFilter(scope)}
                          >
                            {scope}
                          </Button>
                        ))}
                      </HStack>
                    </HStack>
                  </Card.Header>
                  <Card.Body>
                    <VStack gap="4">
                      <HStack
                        render={<form onSubmit={handleAddEnvVar} />}
                        gap="2"
                        wrap="wrap"
                      >
                        <div {...stylex.props(styles.inlineInput)}>
                          <Input
                            size="sm"
                            placeholder="VARIABLE_NAME"
                            value={newEnvKey}
                            onChange={(event) => setNewEnvKey(event.target.value)}
                          />
                        </div>
                        <div {...stylex.props(styles.inlineInput)}>
                          <Input
                            size="sm"
                            placeholder="Value or secret"
                            value={newEnvValue}
                            onChange={(event) => setNewEnvValue(event.target.value)}
                          />
                        </div>
                        <Button
                          type="submit"
                          variant="solid"
                          size="sm"
                          palette={accentPalette}
                        >
                          Add variable
                        </Button>
                      </HStack>

                      <div {...stylex.props(styles.tableWrap)}>
                        <Table.Root variant="line" size="md">
                          <Table.Header>
                            <Table.Row>
                              <Table.ColumnHeader>Key</Table.ColumnHeader>
                              <Table.ColumnHeader>Value</Table.ColumnHeader>
                              <Table.ColumnHeader>Scope</Table.ColumnHeader>
                              <Table.ColumnHeader>Actions</Table.ColumnHeader>
                            </Table.Row>
                          </Table.Header>
                          <Table.Body>
                            {filteredEnvVars.map((envVar) => {
                              const isRevealed = Boolean(revealedIds[envVar.id]);
                              return (
                                <Table.Row key={envVar.id}>
                                  <Table.Cell>
                                    <Code size="xs">{envVar.key}</Code>
                                  </Table.Cell>
                                  <Table.Cell>
                                    <Text
                                      render={<span />}
                                      variant="mono"
                                      size="xs"
                                    >
                                      {envVar.secret && !isRevealed
                                        ? "••••••••••••••••••••"
                                        : envVar.value}
                                    </Text>
                                  </Table.Cell>
                                  <Table.Cell>
                                    <Badge variant="subtle" size="xs">
                                      {envVar.scope}
                                    </Badge>
                                  </Table.Cell>
                                  <Table.Cell>
                                    <HStack gap="1.5" wrap="wrap">
                                      {envVar.secret ? (
                                        <Button
                                          variant="ghost"
                                          size="xs"
                                          onClick={() =>
                                            setRevealedIds((prev) => ({
                                              ...prev,
                                              [envVar.id]: !prev[envVar.id],
                                            }))
                                          }
                                        >
                                          {isRevealed ? "Hide" : "Reveal"}
                                        </Button>
                                      ) : null}
                                      <Button
                                        variant="ghost"
                                        size="xs"
                                        onClick={() =>
                                          queue.info(`Copied ${envVar.key}`)
                                        }
                                      >
                                        Copy
                                      </Button>
                                    </HStack>
                                  </Table.Cell>
                                </Table.Row>
                              );
                            })}
                          </Table.Body>
                        </Table.Root>
                      </div>
                    </VStack>
                  </Card.Body>
                </Card.Root>

                <Card.Root variant="outline" size="md">
                  <Card.Header>
                    <Card.Title style={styles.cardTitleReset}>
                      Runtime Guardrails
                    </Card.Title>
                    <Card.Description style={styles.cardDescReset}>
                      Configure automated edge protection and rollout behavior
                    </Card.Description>
                  </Card.Header>
                  <Card.Body>
                    <VStack gap="4">
                      <HStack gap="4" justify="between">
                        <VStack gap="0.5">
                          <Text render={<span />} size="sm" weight="medium">
                            Edge response caching
                          </Text>
                          <Text render={<span />} size="xs" tone="muted">
                            Serve stale-while-revalidate responses from nearest PoP.
                          </Text>
                        </VStack>
                        <Switch.Root size="md" palette={accentPalette}>
                          <Switch.Control
                            checked={edgeCacheEnabled}
                            onCheckedChange={(checked) => {
                              setEdgeCacheEnabled(checked);
                              queue.info(
                                `Edge response caching ${checked ? "enabled" : "disabled"}`,
                              );
                            }}
                          />
                        </Switch.Root>
                      </HStack>

                      <Separator />

                      <HStack gap="4" justify="between">
                        <VStack gap="0.5">
                          <Text render={<span />} size="sm" weight="medium">
                            Automatic canary rollback
                          </Text>
                          <Text render={<span />} size="xs" tone="muted">
                            Revert release immediately if 5xx error rate exceeds 1.5%.
                          </Text>
                        </VStack>
                        <Switch.Root size="md" palette={accentPalette}>
                          <Switch.Control
                            checked={autoRollbackEnabled}
                            onCheckedChange={(checked) => {
                              setAutoRollbackEnabled(checked);
                              queue.info(
                                `Automatic canary rollback ${checked ? "enabled" : "disabled"}`,
                              );
                            }}
                          />
                        </Switch.Root>
                      </HStack>

                      <Separator />

                      <HStack gap="4" justify="between">
                        <VStack gap="0.5">
                          <Text render={<span />} size="sm" weight="medium">
                            Zero-downtime connection draining
                          </Text>
                          <Text render={<span />} size="xs" tone="muted">
                            Wait up to 30 seconds for active WebSocket and HTTP streams.
                          </Text>
                        </VStack>
                        <Switch.Root size="md" palette={accentPalette}>
                          <Switch.Control
                            checked={zeroDowntimeEnabled}
                            onCheckedChange={(checked) => {
                              setZeroDowntimeEnabled(checked);
                              queue.info(
                                `Connection draining ${checked ? "enabled" : "disabled"}`,
                              );
                            }}
                          />
                        </Switch.Root>
                      </HStack>
                    </VStack>
                  </Card.Body>
                </Card.Root>
              </>
            ) : null}

            {activeRoute === "billing" ? (
              <>
                <Card.Root variant="outline" size="md">
                  <Card.Header style={styles.cardHeaderRow}>
                    <VStack gap="1">
                      <HStack gap="1.5" wrap="wrap">
                        <Card.Title style={styles.cardTitleReset}>
                          Scale Team Plan
                        </Card.Title>
                        <Badge
                          variant="subtle"
                          size="xs"
                          palette={greenPalette}
                        >
                          Active
                        </Badge>
                      </HStack>
                      <Card.Description style={styles.cardDescReset}>
                        Renews on Dec 31, 2026 · Visa ending in 4821
                      </Card.Description>
                    </VStack>
                    <HStack align="baseline" gap="2">
                      <Text
                        render={<span />}
                        size="2xl"
                        weight="semibold"
                        style={styles.planPrice}
                      >
                        $149
                      </Text>
                      <Text render={<span />} size="xs" tone="muted">
                        / month
                      </Text>
                    </HStack>
                  </Card.Header>
                  <Card.Footer>
                    <Button
                      variant="solid"
                      size="sm"
                      palette={accentPalette}
                      onClick={() =>
                        queue.info("Upgrade comparison opened", {
                          description: "Enterprise plan includes dedicated PoPs and 99.99% SLA.",
                        })
                      }
                    >
                      Upgrade plan
                    </Button>
                    <Button
                      variant="surface"
                      size="sm"
                      onClick={() =>
                        queue.info("Payment portal opened", {
                          description: "Manage cards, billing contacts, and VAT details.",
                        })
                      }
                    >
                      Update payment method
                    </Button>
                  </Card.Footer>
                </Card.Root>

                <Card.Root variant="outline" size="md">
                  <Card.Header>
                    <Card.Title style={styles.cardTitleReset}>
                      Monthly Usage &amp; Quotas
                    </Card.Title>
                    <Card.Description style={styles.cardDescReset}>
                      Billing cycle Nov 1 – Nov 30, 2026
                    </Card.Description>
                  </Card.Header>
                  <Card.Body>
                    <Grid gap="4" style={styles.quotaGrid}>
                      {BILLING_QUOTAS.map((quota) => (
                        <VStack key={quota.label} gap="2">
                          <HStack justify="between">
                            <Text render={<span />} size="sm" weight="medium">
                              {quota.label}
                            </Text>
                            <Text render={<span />} size="xs" tone="muted">
                              {quota.used} / {quota.limit}
                            </Text>
                          </HStack>
                          <Progress.Root
                            value={quota.percent}
                            variant="subtle"
                            size="sm"
                            shape="full"
                            palette={
                              quota.percent >= 75 ? amberPalette : accentPalette
                            }
                          >
                            <Progress.Track>
                              <Progress.Range />
                            </Progress.Track>
                          </Progress.Root>
                        </VStack>
                      ))}
                    </Grid>
                  </Card.Body>
                </Card.Root>

                <Card.Root variant="outline" size="md">
                  <Card.Header>
                    <Card.Title style={styles.cardTitleReset}>
                      Recent Invoices
                    </Card.Title>
                  </Card.Header>
                  <Card.Body>
                    <div {...stylex.props(styles.tableWrap)}>
                      <Table.Root variant="line" size="md">
                        <Table.Header>
                          <Table.Row>
                            <Table.ColumnHeader>Invoice</Table.ColumnHeader>
                            <Table.ColumnHeader>Period</Table.ColumnHeader>
                            <Table.ColumnHeader>Amount</Table.ColumnHeader>
                            <Table.ColumnHeader>Status</Table.ColumnHeader>
                            <Table.ColumnHeader>Receipt</Table.ColumnHeader>
                          </Table.Row>
                        </Table.Header>
                        <Table.Body>
                          {INVOICES.map((inv) => (
                            <Table.Row key={inv.id}>
                              <Table.Cell>
                                <Code size="xs">{inv.id}</Code>
                              </Table.Cell>
                              <Table.Cell>{inv.period}</Table.Cell>
                              <Table.Cell>{inv.amount}</Table.Cell>
                              <Table.Cell>
                                <Badge
                                  variant="subtle"
                                  size="xs"
                                  palette={greenPalette}
                                >
                                  {inv.status}
                                </Badge>
                              </Table.Cell>
                              <Table.Cell>
                                <Button
                                  variant="ghost"
                                  size="xs"
                                  onClick={() =>
                                    queue.success(`Downloaded ${inv.id}.pdf`)
                                  }
                                >
                                  Download PDF
                                </Button>
                              </Table.Cell>
                            </Table.Row>
                          ))}
                        </Table.Body>
                      </Table.Root>
                    </div>
                  </Card.Body>
                </Card.Root>
              </>
            ) : null}
          </VStack>
        </AppShell.Main>
      </AppShell.Content>

      <Drawer.Root
        open={mobileNavOpen}
        onOpenChange={setMobileNavOpen}
        placement="start"
        size="xs"
      >
        <Drawer.Backdrop />
        <Drawer.Content>
          <Drawer.Header>
            <HStack gap="2">
              <span {...stylex.props(styles.brandMark)}>
                <HarborMark />
              </span>
              <Drawer.Title>Harbor Deploy</Drawer.Title>
            </HStack>
            <Drawer.Close
              render={
                <IconButton
                  variant="ghost"
                  size="xs"
                  aria-label="Close navigation drawer"
                />
              }
            >
              <Icon
                size="sm"
                viewBox="0 0 16 16"
                fill="none"
                stroke="currentColor"
                strokeWidth="1.6"
                strokeLinecap="round"
                aria-hidden="true"
              >
                <path d="m4 4 8 8" />
                <path d="m12 4-8 8" />
              </Icon>
            </Drawer.Close>
          </Drawer.Header>
          <Separator />
          <Drawer.Body style={styles.drawerBody}>
            {renderNavGroups(false)}
          </Drawer.Body>
          <Drawer.Footer>
            <Button
              variant="solid"
              size="sm"
              palette={accentPalette}
              onClick={() => {
                setMobileNavOpen(false);
                triggerDeploy();
              }}
            >
              Deploy {activeWorkspace.name}
            </Button>
          </Drawer.Footer>
        </Drawer.Content>
      </Drawer.Root>

      <Dialog.Root
        open={searchOpen}
        onOpenChange={(next) => {
          setSearchOpen(next);
          if (!next) setSearchQuery("");
        }}
        size="md"
        placement="top"
      >
        <Dialog.Backdrop />
        <Dialog.Content>
          <Dialog.Header>
            <Dialog.Title>Quick Jump &amp; Commands</Dialog.Title>
          </Dialog.Header>
          <Dialog.Body style={styles.paletteDialogBody}>
            <Input
              size="md"
              placeholder="Jump to route, switch workspace, or run a command…"
              value={searchQuery}
              onChange={(event) => setSearchQuery(event.target.value)}
              autoFocus
            />
            <VStack gap="1" style={styles.paletteResults}>
              {paletteCommands.map((cmd) => (
                <button
                  key={cmd.id}
                  type="button"
                  onClick={() => {
                    cmd.run();
                    setSearchOpen(false);
                    setSearchQuery("");
                  }}
                  {...stylex.props(styles.paletteItem)}
                >
                  <HStack render={<span />} gap="2.5">
                    <Badge variant="subtle" size="xs">
                      {cmd.category}
                    </Badge>
                    <span>{cmd.label}</span>
                  </HStack>
                  {cmd.hint ? (
                    <Text render={<span />} size="xs" tone="muted">
                      {cmd.hint}
                    </Text>
                  ) : null}
                </button>
              ))}
              {paletteCommands.length === 0 ? (
                <Text
                  size="sm"
                  tone="muted"
                  align="center"
                  style={styles.emptyStateText}
                >
                  No matching commands for &ldquo;{searchQuery}&rdquo;.
                </Text>
              ) : null}
            </VStack>
          </Dialog.Body>
          <Dialog.Footer>
            <Button
              variant="ghost"
              size="sm"
              onClick={() => {
                setSearchOpen(false);
                setSearchQuery("");
              }}
            >
              Close
            </Button>
          </Dialog.Footer>
        </Dialog.Content>
      </Dialog.Root>

      <Toaster toaster={queue} />
    </AppShell.Root>
  );
}
```

Credit: Inspired by [Shell Nav](https://astryx.atmeta.com/playground?template=shell-nav) from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.)
