---
title: "Executive Dashboard · UI SDK — StyleX Blocks"
description: "Executive scorecard with a Q1–Q4 period switcher, KPI sparkline tiles, interactive ARR vs. plan TanStack Charts, segment mix and net-new ARR breakdowns, regional quota attainment table, strategic objectives tracker, and a narrative highlights rail."
url: "https://stylexblocks.com/block/ui-sdk/executive-dashboard/"
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/"
---

# Executive Dashboard block

Executive scorecard with a Q1–Q4 period switcher, KPI sparkline tiles, interactive ARR vs. plan TanStack Charts, segment mix and net-new ARR breakdowns, regional quota attainment table, strategic objectives tracker, and a narrative highlights rail.

- Behavior engine: UI SDK
- Category: [Dashboards](https://stylexblocks.com/blocks/dashboards.md)
- Built with: [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), [Chart](https://stylexblocks.com/components/ui-sdk/chart.md), [Grid](https://stylexblocks.com/components/ui-sdk/grid.md), [Heading](https://stylexblocks.com/components/ui-sdk/heading.md), [Progress](https://stylexblocks.com/components/ui-sdk/progress.md), [Segment Group](https://stylexblocks.com/components/ui-sdk/segment-group.md), [Separator](https://stylexblocks.com/components/ui-sdk/separator.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), [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/executive-dashboard/

## 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 executive-dashboard
```

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

## Usage

```tsx
import { ExecutiveDashboard } from "#components/blocks/ui-sdk/executive-dashboard.tsx";

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

## Source

`components/blocks/ui-sdk/executive-dashboard.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { useMemo, useState } from "react";
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 {
  BarChart,
  CategoryBar,
  LineChart,
  Sparkline,
  type ChartColorName,
} from "#components/ui/ui-sdk/chart.tsx";
import { Grid } from "#components/ui/ui-sdk/grid.tsx";
import { Heading } from "#components/ui/ui-sdk/heading.tsx";
import { Progress } from "#components/ui/ui-sdk/progress.tsx";
import { SegmentGroup } from "#components/ui/ui-sdk/segment-group.tsx";
import { Separator } from "#components/ui/ui-sdk/separator.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 { 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 {
  amberPalette,
  bluePalette,
  grayPalette,
  greenPalette,
  indigoPalette,
  purplePalette,
  redPalette,
  tealPalette,
} from "@stylexblocks/ui/themes/palettes.ts";
import { fonts } from "@stylexblocks/ui/tokens/fonts.stylex.ts";
import { spacing } from "@stylexblocks/ui/tokens/spacing.stylex.ts";
import type { StyleOverrideProps } from "#lib/recipe-props.ts";

// ============= CONTAINER BREAKPOINTS =============

const NARROW = "@container executive-dashboard (max-width: 1060px)";
const COMPACT = "@container executive-dashboard (max-width: 680px)";

// ============= DOMAIN TYPES =============

type Quarter = "Q1" | "Q2" | "Q3" | "Q4";
type RagStatus = "green" | "amber" | "red";
type HighlightStatus = "success" | "warning" | "info";
type AttainmentFilter = "all" | "on-track" | "watch";

interface KpiMetric {
  key: string;
  label: string;
  value: string;
  deltaLabel: string;
  direction: "up" | "down";
  rag: RagStatus;
  targetNote: string;
  sparkline: readonly number[];
}

interface WeeklyRevenuePoint {
  week: number;
  label: string;
  actual: number;
  target: number;
  prior: number;
}

interface SegmentMixItem {
  label: string;
  arrMillions: number;
  color: ChartColorName;
}

interface AttainmentRow {
  id: string;
  region: string;
  segment: string;
  leadName: string;
  leadInitials: string;
  leadPalette: "blue" | "teal" | "indigo" | "purple" | "amber" | "green";
  bookedArr: number;
  quotaArr: number;
  ndr: number;
}

interface StrategicObjective {
  id: string;
  objective: string;
  ownerName: string;
  ownerRole: string;
  ownerInitials: string;
  ownerPalette: "blue" | "teal" | "indigo" | "purple";
  actual: number;
  target: number;
  unit: string;
  prefix?: string;
}

interface ExecutiveHighlight {
  id: string;
  status: HighlightStatus;
  title: string;
  detail: string;
  impact: string;
}

interface QuarterSnapshot {
  quarter: Quarter;
  dateRange: string;
  updatedLabel: string;
  planAttainment: string;
  planRag: RagStatus;
  kpis: readonly KpiMetric[];
  revenueSeries: readonly WeeklyRevenuePoint[];
  segmentMix: readonly SegmentMixItem[];
  attainment: readonly AttainmentRow[];
  objectives: readonly StrategicObjective[];
  highlights: readonly ExecutiveHighlight[];
}

interface NetNewArrQuarter {
  quarter: Quarter;
  newLogo: number;
  expansion: number;
}

// ============= TONE & PALETTE MAPS =============

const RAG_PALETTE = {
  green: greenPalette,
  amber: amberPalette,
  red: redPalette,
} as const;

const RAG_TEXT_TONE = {
  green: "success",
  amber: "warning",
  red: "error",
} as const;

const AVATAR_PALETTE = {
  blue: bluePalette,
  teal: tealPalette,
  indigo: indigoPalette,
  purple: purplePalette,
  amber: amberPalette,
  green: greenPalette,
} as const;

const HIGHLIGHT_BADGE_PALETTE = {
  success: greenPalette,
  warning: amberPalette,
  info: bluePalette,
} as const;

const WEEK_LABELS = [
  "W1",
  "W2",
  "W3",
  "W4",
  "W5",
  "W6",
  "W7",
  "W8",
  "W9",
  "W10",
  "W11",
  "W12",
] as const;

function buildWeeklyRevenue(
  startActual: number,
  endActual: number,
  startTarget: number,
  endTarget: number,
  priorScale: number,
  seed: number,
): WeeklyRevenuePoint[] {
  return WEEK_LABELS.map((label, i) => {
    const progress = i / 11;
    const wave = Math.sin((i + seed) * 1.15) * 0.45;
    const actual = Number(
      (startActual + (endActual - startActual) * progress + (i === 11 ? 0 : wave)).toFixed(1),
    );
    const target = Number((startTarget + (endTarget - startTarget) * progress).toFixed(1));
    const prior = Number((target * priorScale + Math.cos(i * 0.9) * 0.25).toFixed(1));
    return { week: i, label, actual, target, prior };
  });
}

// ============= KESTREL CLOUD FY26 DEMO DATA =============

const NET_NEW_ARR_BY_QUARTER: readonly NetNewArrQuarter[] = [
  { quarter: "Q1", newLogo: 3.1, expansion: 2.3 },
  { quarter: "Q2", newLogo: 2.6, expansion: 1.9 },
  { quarter: "Q3", newLogo: 2.9, expansion: 2.5 },
  { quarter: "Q4", newLogo: 5.2, expansion: 4.1 },
];

const NET_NEW_ARR_CHART_DATA = NET_NEW_ARR_BY_QUARTER.map((q) => ({
  quarter: q.quarter,
  "New Logo ARR": q.newLogo,
  "Expansion ARR": q.expansion,
}));

const QUARTER_SNAPSHOTS: Record<Quarter, QuarterSnapshot> = {
  Q1: {
    quarter: "Q1",
    dateRange: "Jan 1 – Mar 31, 2026 vs. Q4 2025",
    updatedLabel: "Finalized Apr 3, 2026",
    planAttainment: "100.8% of plan",
    planRag: "green",
    kpis: [
      {
        key: "arr",
        label: "Annual Recurring Revenue",
        value: "$66.4M",
        deltaLabel: "+8.9% QoQ",
        direction: "up",
        rag: "green",
        targetNote: "Plan $65.9M · 100.8% attained",
        sparkline: [61.2, 61.6, 62.1, 62.5, 62.9, 63.4, 63.8, 64.4, 64.9, 65.3, 65.9, 66.4],
      },
      {
        key: "ndr",
        label: "Net Dollar Retention",
        value: "118.2%",
        deltaLabel: "+0.6 pts",
        direction: "up",
        rag: "green",
        targetNote: "Target 117.5% · Enterprise 123%",
        sparkline: [117.4, 117.5, 117.6, 117.5, 117.7, 117.8, 117.9, 118.0, 118.0, 118.1, 118.1, 118.2],
      },
      {
        key: "logos",
        label: "Enterprise Logos",
        value: "322",
        deltaLabel: "+21 QoQ",
        direction: "up",
        rag: "green",
        targetNote: "Plan 318 · Avg ACV $148k",
        sparkline: [301, 303, 305, 307, 309, 311, 313, 315, 317, 319, 320, 322],
      },
      {
        key: "margin",
        label: "Gross Margin",
        value: "80.4%",
        deltaLabel: "+0.3 pts",
        direction: "up",
        rag: "green",
        targetNote: "Plan 80.0% · Cloud commit active",
        sparkline: [80.0, 80.1, 80.1, 80.2, 80.2, 80.3, 80.2, 80.3, 80.3, 80.4, 80.4, 80.4],
      },
    ],
    revenueSeries: buildWeeklyRevenue(61.2, 66.4, 61.0, 65.9, 0.78, 0.4),
    segmentMix: [
      { label: "Enterprise", arrMillions: 37.8, color: "blue" },
      { label: "Mid-Market", arrMillions: 19.2, color: "emerald" },
      { label: "Commercial", arrMillions: 7.3, color: "orange" },
      { label: "Public Sector", arrMillions: 2.1, color: "violet" },
    ],
    attainment: [
      {
        id: "na-ent",
        region: "North America",
        segment: "Enterprise",
        leadName: "Hannah Kowalski",
        leadInitials: "HK",
        leadPalette: "blue",
        bookedArr: 24.4,
        quotaArr: 23.6,
        ndr: 123.1,
      },
      {
        id: "emea-ent",
        region: "EMEA",
        segment: "Enterprise",
        leadName: "Devon Sato",
        leadInitials: "DS",
        leadPalette: "teal",
        bookedArr: 9.8,
        quotaArr: 10.2,
        ndr: 118.6,
      },
      {
        id: "na-mm",
        region: "North America",
        segment: "Mid-Market",
        leadName: "Claire Oduya",
        leadInitials: "CO",
        leadPalette: "indigo",
        bookedArr: 13.6,
        quotaArr: 13.2,
        ndr: 116.4,
      },
      {
        id: "apac-ent",
        region: "APAC",
        segment: "Enterprise",
        leadName: "Kenji Takahashi",
        leadInitials: "KT",
        leadPalette: "purple",
        bookedArr: 5.7,
        quotaArr: 5.8,
        ndr: 119.2,
      },
      {
        id: "emea-mm",
        region: "EMEA",
        segment: "Mid-Market",
        leadName: "Sofie Lindholm",
        leadInitials: "SL",
        leadPalette: "amber",
        bookedArr: 6.4,
        quotaArr: 7.4,
        ndr: 111.0,
      },
      {
        id: "pub-fed",
        region: "Public Sector",
        segment: "Federal",
        leadName: "Rafael Morales",
        leadInitials: "RM",
        leadPalette: "green",
        bookedArr: 2.1,
        quotaArr: 2.2,
        ndr: 115.8,
      },
    ],
    objectives: [
      {
        id: "q1-arr",
        objective: "Close Q1 above $65.9M ARR run-rate",
        ownerName: "Hannah Kowalski",
        ownerRole: "CRO",
        ownerInitials: "HK",
        ownerPalette: "blue",
        actual: 66.4,
        target: 65.9,
        unit: "M",
        prefix: "$",
      },
      {
        id: "q1-emea",
        objective: "Sign 85 cumulative EMEA enterprise logos",
        ownerName: "Devon Sato",
        ownerRole: "SVP EMEA",
        ownerInitials: "DS",
        ownerPalette: "teal",
        actual: 81,
        target: 85,
        unit: "",
      },
      {
        id: "q1-fabric",
        objective: "Complete Kestrel Fabric v4 private preview",
        ownerName: "Nadia Benali",
        ownerRole: "VP Engineering",
        ownerInitials: "NB",
        ownerPalette: "indigo",
        actual: 94,
        target: 100,
        unit: "%",
      },
      {
        id: "q1-margin",
        objective: "Hold non-GAAP gross margin at 80.0%",
        ownerName: "Gareth Osei",
        ownerRole: "CFO",
        ownerInitials: "GO",
        ownerPalette: "purple",
        actual: 80.4,
        target: 80.0,
        unit: "%",
      },
    ],
    highlights: [
      {
        id: "q1-h1",
        status: "success",
        title: "Clean start to FY26: $66.4M ARR (+0.8% vs. plan)",
        detail:
          "North America Enterprise closed four multi-year platform consolidations in March, lifting average contract length to 2.7 years.",
        impact: "+$0.5M vs. plan",
      },
      {
        id: "q1-h2",
        status: "warning",
        title: "EMEA Mid-Market trailing quota at 86.5%",
        detail:
          "Longer security reviews in DACH pushed three late-stage deals into Q2. Dedicated solutions architect coverage starts April 7.",
        impact: "-$1.0M slippage",
      },
      {
        id: "q1-h3",
        status: "info",
        title: "Reserved compute renegotiation locked through FY27",
        detail:
          "Multi-cloud unit cost dropped 6.2% per ingested terabyte, creating headroom for Q3–Q4 telemetry cluster expansion.",
        impact: "+40 bps margin",
      },
    ],
  },
  Q2: {
    quarter: "Q2",
    dateRange: "Apr 1 – Jun 30, 2026 vs. Q1 2026",
    updatedLabel: "Finalized Jul 2, 2026",
    planAttainment: "98.6% of plan",
    planRag: "amber",
    kpis: [
      {
        key: "arr",
        label: "Annual Recurring Revenue",
        value: "$70.9M",
        deltaLabel: "+6.8% QoQ",
        direction: "up",
        rag: "amber",
        targetNote: "Plan $71.9M · 98.6% attained",
        sparkline: [66.4, 66.8, 67.3, 67.6, 68.1, 68.4, 68.8, 69.2, 69.6, 70.0, 70.4, 70.9],
      },
      {
        key: "ndr",
        label: "Net Dollar Retention",
        value: "119.0%",
        deltaLabel: "+0.8 pts",
        direction: "up",
        rag: "green",
        targetNote: "Target 118.0% · Zero Tier-0 churn",
        sparkline: [118.2, 118.2, 118.3, 118.4, 118.5, 118.5, 118.6, 118.7, 118.8, 118.9, 118.9, 119.0],
      },
      {
        key: "logos",
        label: "Enterprise Logos",
        value: "351",
        deltaLabel: "+29 QoQ",
        direction: "up",
        rag: "green",
        targetNote: "Plan 346 · 101.4% attained",
        sparkline: [322, 325, 327, 330, 332, 335, 338, 340, 343, 346, 348, 351],
      },
      {
        key: "margin",
        label: "Gross Margin",
        value: "80.1%",
        deltaLabel: "-0.3 pts",
        direction: "down",
        rag: "amber",
        targetNote: "Plan 80.3% · EU region warm-up",
        sparkline: [80.4, 80.4, 80.3, 80.3, 80.3, 80.2, 80.2, 80.2, 80.1, 80.1, 80.1, 80.1],
      },
    ],
    revenueSeries: buildWeeklyRevenue(66.4, 70.9, 66.2, 71.9, 0.79, 1.2),
    segmentMix: [
      { label: "Enterprise", arrMillions: 40.7, color: "blue" },
      { label: "Mid-Market", arrMillions: 20.1, color: "emerald" },
      { label: "Commercial", arrMillions: 7.8, color: "orange" },
      { label: "Public Sector", arrMillions: 2.3, color: "violet" },
    ],
    attainment: [
      {
        id: "na-ent",
        region: "North America",
        segment: "Enterprise",
        leadName: "Hannah Kowalski",
        leadInitials: "HK",
        leadPalette: "blue",
        bookedArr: 26.2,
        quotaArr: 26.0,
        ndr: 124.0,
      },
      {
        id: "emea-ent",
        region: "EMEA",
        segment: "Enterprise",
        leadName: "Devon Sato",
        leadInitials: "DS",
        leadPalette: "teal",
        bookedArr: 10.6,
        quotaArr: 11.4,
        ndr: 117.9,
      },
      {
        id: "na-mm",
        region: "North America",
        segment: "Mid-Market",
        leadName: "Claire Oduya",
        leadInitials: "CO",
        leadPalette: "indigo",
        bookedArr: 14.3,
        quotaArr: 14.5,
        ndr: 116.8,
      },
      {
        id: "apac-ent",
        region: "APAC",
        segment: "Enterprise",
        leadName: "Kenji Takahashi",
        leadInitials: "KT",
        leadPalette: "purple",
        bookedArr: 6.1,
        quotaArr: 6.2,
        ndr: 120.4,
      },
      {
        id: "emea-mm",
        region: "EMEA",
        segment: "Mid-Market",
        leadName: "Sofie Lindholm",
        leadInitials: "SL",
        leadPalette: "amber",
        bookedArr: 6.1,
        quotaArr: 7.2,
        ndr: 110.2,
      },
      {
        id: "pub-fed",
        region: "Public Sector",
        segment: "Federal",
        leadName: "Rafael Morales",
        leadInitials: "RM",
        leadPalette: "green",
        bookedArr: 2.3,
        quotaArr: 2.5,
        ndr: 116.5,
      },
    ],
    objectives: [
      {
        id: "q2-arr",
        objective: "Reach $71.9M ARR by mid-year",
        ownerName: "Hannah Kowalski",
        ownerRole: "CRO",
        ownerInitials: "HK",
        ownerPalette: "blue",
        actual: 70.9,
        target: 71.9,
        unit: "M",
        prefix: "$",
      },
      {
        id: "q2-emea",
        objective: "Scale EMEA enterprise base to 95 logos",
        ownerName: "Devon Sato",
        ownerRole: "SVP EMEA",
        ownerInitials: "DS",
        ownerPalette: "teal",
        actual: 91,
        target: 95,
        unit: "",
      },
      {
        id: "q2-fabric",
        objective: "Onboard 40 design partners to Fabric v4",
        ownerName: "Nadia Benali",
        ownerRole: "VP Engineering",
        ownerInitials: "NB",
        ownerPalette: "indigo",
        actual: 38,
        target: 40,
        unit: "",
      },
      {
        id: "q2-margin",
        objective: "Keep gross margin above 80.3% during EU launch",
        ownerName: "Gareth Osei",
        ownerRole: "CFO",
        ownerInitials: "GO",
        ownerPalette: "purple",
        actual: 80.1,
        target: 80.3,
        unit: "%",
      },
    ],
    highlights: [
      {
        id: "q2-h1",
        status: "warning",
        title: "Q2 ARR finished $1.0M below plan (98.6%)",
        detail:
          "Two $650k European banking procurements slipped past June 30 on legal redlines; both have verbal sign-off for early Q3.",
        impact: "-$1.0M timing",
      },
      {
        id: "q2-h2",
        status: "success",
        title: "Enterprise logo velocity ahead of forecast (+29 net)",
        detail:
          "Partner-assisted co-sell deals doubled to 28% of new enterprise logos, trimming median enterprise sales cycle by 9 days.",
        impact: "101.4% logo plan",
      },
      {
        id: "q2-h3",
        status: "info",
        title: "Frankfurt sovereign cluster live for regulated accounts",
        detail:
          "Initial cluster warm-up trimmed 30 bps from gross margin; utilization is projected to cross 70% by late Q3.",
        impact: "-30 bps temp drag",
      },
    ],
  },
  Q3: {
    quarter: "Q3",
    dateRange: "Jul 1 – Sep 30, 2026 vs. Q2 2026",
    updatedLabel: "Finalized Oct 4, 2026",
    planAttainment: "101.4% of plan",
    planRag: "green",
    kpis: [
      {
        key: "arr",
        label: "Annual Recurring Revenue",
        value: "$75.3M",
        deltaLabel: "+6.2% QoQ",
        direction: "up",
        rag: "green",
        targetNote: "Plan $74.3M · 101.4% attained",
        sparkline: [70.9, 71.3, 71.8, 72.1, 72.6, 73.0, 73.4, 73.8, 74.1, 74.5, 74.9, 75.3],
      },
      {
        key: "ndr",
        label: "Net Dollar Retention",
        value: "119.6%",
        deltaLabel: "+0.6 pts",
        direction: "up",
        rag: "green",
        targetNote: "Target 118.0% · Expansion led",
        sparkline: [119.0, 119.0, 119.1, 119.1, 119.2, 119.3, 119.3, 119.4, 119.4, 119.5, 119.5, 119.6],
      },
      {
        key: "logos",
        label: "Enterprise Logos",
        value: "384",
        deltaLabel: "+33 QoQ",
        direction: "up",
        rag: "green",
        targetNote: "Plan 374 · Avg ACV $156k",
        sparkline: [351, 354, 357, 360, 363, 366, 369, 372, 375, 378, 381, 384],
      },
      {
        key: "margin",
        label: "Gross Margin",
        value: "80.1%",
        deltaLabel: "0.0 pts",
        direction: "up",
        rag: "green",
        targetNote: "Plan 80.0% · On plan",
        sparkline: [80.1, 80.1, 80.0, 80.1, 80.2, 80.1, 80.1, 80.2, 80.1, 80.1, 80.1, 80.1],
      },
    ],
    revenueSeries: buildWeeklyRevenue(70.9, 75.3, 70.6, 74.3, 0.8, 2.1),
    segmentMix: [
      { label: "Enterprise", arrMillions: 43.4, color: "blue" },
      { label: "Mid-Market", arrMillions: 21.3, color: "emerald" },
      { label: "Commercial", arrMillions: 8.1, color: "orange" },
      { label: "Public Sector", arrMillions: 2.5, color: "violet" },
    ],
    attainment: [
      {
        id: "na-ent",
        region: "North America",
        segment: "Enterprise",
        leadName: "Hannah Kowalski",
        leadInitials: "HK",
        leadPalette: "blue",
        bookedArr: 28.4,
        quotaArr: 27.6,
        ndr: 124.8,
      },
      {
        id: "emea-ent",
        region: "EMEA",
        segment: "Enterprise",
        leadName: "Devon Sato",
        leadInitials: "DS",
        leadPalette: "teal",
        bookedArr: 12.1,
        quotaArr: 11.8,
        ndr: 120.2,
      },
      {
        id: "na-mm",
        region: "North America",
        segment: "Mid-Market",
        leadName: "Claire Oduya",
        leadInitials: "CO",
        leadPalette: "indigo",
        bookedArr: 15.1,
        quotaArr: 15.0,
        ndr: 117.1,
      },
      {
        id: "apac-ent",
        region: "APAC",
        segment: "Enterprise",
        leadName: "Kenji Takahashi",
        leadInitials: "KT",
        leadPalette: "purple",
        bookedArr: 6.7,
        quotaArr: 6.5,
        ndr: 121.0,
      },
      {
        id: "emea-mm",
        region: "EMEA",
        segment: "Mid-Market",
        leadName: "Sofie Lindholm",
        leadInitials: "SL",
        leadPalette: "amber",
        bookedArr: 6.4,
        quotaArr: 7.0,
        ndr: 112.4,
      },
      {
        id: "pub-fed",
        region: "Public Sector",
        segment: "Federal",
        leadName: "Rafael Morales",
        leadInitials: "RM",
        leadPalette: "green",
        bookedArr: 2.5,
        quotaArr: 2.6,
        ndr: 117.0,
      },
    ],
    objectives: [
      {
        id: "q3-arr",
        objective: "Recover mid-year variance and exceed $74.3M ARR",
        ownerName: "Hannah Kowalski",
        ownerRole: "CRO",
        ownerInitials: "HK",
        ownerPalette: "blue",
        actual: 75.3,
        target: 74.3,
        unit: "M",
        prefix: "$",
      },
      {
        id: "q3-emea",
        objective: "Reach 102 EMEA enterprise accounts",
        ownerName: "Devon Sato",
        ownerRole: "SVP EMEA",
        ownerInitials: "DS",
        ownerPalette: "teal",
        actual: 103,
        target: 102,
        unit: "",
      },
      {
        id: "q3-fabric",
        objective: "Hit 99.99% multi-region SLA in Fabric v4 RC",
        ownerName: "Nadia Benali",
        ownerRole: "VP Engineering",
        ownerInitials: "NB",
        ownerPalette: "indigo",
        actual: 96,
        target: 100,
        unit: "%",
      },
      {
        id: "q3-margin",
        objective: "Maintain 80.0% non-GAAP gross margin",
        ownerName: "Gareth Osei",
        ownerRole: "CFO",
        ownerInitials: "GO",
        ownerPalette: "purple",
        actual: 80.1,
        target: 80.0,
        unit: "%",
      },
    ],
    highlights: [
      {
        id: "q3-h1",
        status: "success",
        title: "EMEA Enterprise bounced back to 102.5% attainment",
        detail:
          "Both delayed Q2 banking contracts signed in July alongside three net-new fintech accounts anchored on the Frankfurt region.",
        impact: "+$1.0M vs. plan",
      },
      {
        id: "q3-h2",
        status: "success",
        title: "Q4 pipeline coverage stands at 3.6x bookings plan",
        detail:
          "Stage-3+ enterprise pipeline reached $31.4M, giving strong visibility into the FY26 year-end finish.",
        impact: "3.6x Q4 coverage",
      },
      {
        id: "q3-h3",
        status: "info",
        title: "Fabric v4 GA readiness at 96% with zero Sev-1 blockers",
        detail:
          "Automated failover drills completed across us-east, eu-central, and ap-northeast; billing meter cutover scheduled for October.",
        impact: "GA on track",
      },
    ],
  },
  Q4: {
    quarter: "Q4",
    dateRange: "Oct 1 – Dec 31, 2026 vs. Q3 2026",
    updatedLabel: "Board snapshot · Dec 1, 2026",
    planAttainment: "103.2% of plan",
    planRag: "green",
    kpis: [
      {
        key: "arr",
        label: "Annual Recurring Revenue",
        value: "$84.6M",
        deltaLabel: "+12.4% QoQ",
        direction: "up",
        rag: "green",
        targetNote: "Plan $82.0M · 103.2% attained",
        sparkline: [75.3, 76.1, 76.9, 77.6, 78.5, 79.4, 80.2, 81.1, 82.0, 82.9, 83.8, 84.6],
      },
      {
        key: "ndr",
        label: "Net Dollar Retention",
        value: "121.4%",
        deltaLabel: "+1.8 pts",
        direction: "up",
        rag: "green",
        targetNote: "Target 118.0% · Enterprise 126%",
        sparkline: [119.6, 119.7, 119.9, 120.0, 120.2, 120.4, 120.6, 120.8, 121.0, 121.1, 121.3, 121.4],
      },
      {
        key: "logos",
        label: "Enterprise Logos",
        value: "418",
        deltaLabel: "+34 QoQ",
        direction: "up",
        rag: "green",
        targetNote: "Plan 400 · Avg ACV $164k",
        sparkline: [384, 387, 390, 393, 396, 399, 402, 405, 408, 411, 415, 418],
      },
      {
        key: "margin",
        label: "Gross Margin",
        value: "79.2%",
        deltaLabel: "-0.9 pts",
        direction: "down",
        rag: "amber",
        targetNote: "Plan 80.5% · Fabric v4 GPU ramp",
        sparkline: [80.1, 80.0, 79.9, 79.8, 79.7, 79.6, 79.5, 79.4, 79.3, 79.2, 79.2, 79.2],
      },
    ],
    revenueSeries: buildWeeklyRevenue(75.3, 84.6, 75.0, 82.0, 0.77, 0.8),
    segmentMix: [
      { label: "Enterprise", arrMillions: 49.1, color: "blue" },
      { label: "Mid-Market", arrMillions: 23.7, color: "emerald" },
      { label: "Commercial", arrMillions: 8.9, color: "orange" },
      { label: "Public Sector", arrMillions: 2.9, color: "violet" },
    ],
    attainment: [
      {
        id: "na-ent",
        region: "North America",
        segment: "Enterprise",
        leadName: "Hannah Kowalski",
        leadInitials: "HK",
        leadPalette: "blue",
        bookedArr: 31.8,
        quotaArr: 29.8,
        ndr: 126.4,
      },
      {
        id: "emea-ent",
        region: "EMEA",
        segment: "Enterprise",
        leadName: "Devon Sato",
        leadInitials: "DS",
        leadPalette: "teal",
        bookedArr: 14.2,
        quotaArr: 13.6,
        ndr: 122.1,
      },
      {
        id: "na-mm",
        region: "North America",
        segment: "Mid-Market",
        leadName: "Claire Oduya",
        leadInitials: "CO",
        leadPalette: "indigo",
        bookedArr: 16.4,
        quotaArr: 16.0,
        ndr: 118.5,
      },
      {
        id: "apac-ent",
        region: "APAC",
        segment: "Enterprise",
        leadName: "Kenji Takahashi",
        leadInitials: "KT",
        leadPalette: "purple",
        bookedArr: 7.9,
        quotaArr: 7.4,
        ndr: 123.0,
      },
      {
        id: "emea-mm",
        region: "EMEA",
        segment: "Mid-Market",
        leadName: "Sofie Lindholm",
        leadInitials: "SL",
        leadPalette: "amber",
        bookedArr: 6.8,
        quotaArr: 8.0,
        ndr: 111.8,
      },
      {
        id: "pub-fed",
        region: "Public Sector",
        segment: "Federal",
        leadName: "Rafael Morales",
        leadInitials: "RM",
        leadPalette: "green",
        bookedArr: 2.9,
        quotaArr: 3.1,
        ndr: 118.2,
      },
    ],
    objectives: [
      {
        id: "q4-arr",
        objective: "Cross $82.0M FY26 ending ARR target",
        ownerName: "Hannah Kowalski",
        ownerRole: "CRO",
        ownerInitials: "HK",
        ownerPalette: "blue",
        actual: 84.6,
        target: 82.0,
        unit: "M",
        prefix: "$",
      },
      {
        id: "q4-emea",
        objective: "Expand EMEA enterprise footprint to 110 logos",
        ownerName: "Devon Sato",
        ownerRole: "SVP EMEA",
        ownerInitials: "DS",
        ownerPalette: "teal",
        actual: 114,
        target: 110,
        unit: "",
      },
      {
        id: "q4-fabric",
        objective: "Migrate 75% of Tier-0 clusters to Fabric v4 GA",
        ownerName: "Nadia Benali",
        ownerRole: "VP Engineering",
        ownerInitials: "NB",
        ownerPalette: "indigo",
        actual: 64,
        target: 75,
        unit: "%",
      },
      {
        id: "q4-margin",
        objective: "Deliver 80.5% non-GAAP gross margin",
        ownerName: "Gareth Osei",
        ownerRole: "CFO",
        ownerInitials: "GO",
        ownerPalette: "purple",
        actual: 79.2,
        target: 80.5,
        unit: "%",
      },
    ],
    highlights: [
      {
        id: "q4-h1",
        status: "success",
        title: "Record quarter: $84.6M ARR (+$2.6M ahead of plan)",
        detail:
          "Nine $500k+ Fabric v4 platform upgrades closed ahead of year-end budget lock, driving 44% of Q4 net-new ARR from existing accounts.",
        impact: "+$2.6M vs. plan",
      },
      {
        id: "q4-h2",
        status: "success",
        title: "Net dollar retention climbed 1.8 points to 121.4%",
        detail:
          "Enterprise multi-product attach rose from 2.1 to 2.6 modules per account; gross logo churn stayed below 1.2% annualized.",
        impact: "+340 bps vs. target",
      },
      {
        id: "q4-h3",
        status: "warning",
        title: "Gross margin dipped 90 bps to 79.2% on Fabric v4 ramp",
        detail:
          "Over-provisioned inference and cold-tier indexing capacity ahead of GA accounts for 85 bps of the variance. Autoscale tiering lands in Q1 FY27.",
        impact: "-130 bps vs. plan",
      },
      {
        id: "q4-h4",
        status: "info",
        title: "EMEA Mid-Market enablement reset underway for FY27",
        detail:
          "Territory finished at 85.0% quota due to longer partner ramp; new localized pricing packs and self-serve trials launch January 12.",
        impact: "85.0% quota",
      },
    ],
  },
};

function attainmentRag(pct: number): RagStatus {
  if (pct >= 98) return "green";
  if (pct >= 88) return "amber";
  return "red";
}

function objectiveRag(pct: number): RagStatus {
  if (pct >= 95) return "green";
  if (pct >= 80) return "amber";
  return "red";
}

function statusLabelForRag(rag: RagStatus): string {
  if (rag === "green") return "On Track";
  if (rag === "amber") return "Watch";
  return "At Risk";
}

// ============= STYLES =============

const styles = stylex.create({
  root: {
    backgroundColor: semanticColors.bg,
    color: semanticColors.fg,
    containerName: "executive-dashboard",
    containerType: "inline-size",
    display: "flex",
    flexDirection: "column",
    fontFamily: fonts.body,
    height: "100%",
    minHeight: 0,
    overflowY: "auto",
    width: "100%",
  },
  header: {
    backgroundColor: semanticColors.bgSurface,
    borderBottomColor: semanticColors.border,
    borderBottomStyle: "solid",
    borderBottomWidth: "1px",
    paddingBlock: spacing._5,
    paddingInline: spacing._6,
  },
  headingReset: {
    marginBlock: 0,
  },
  workspace: {
    flexGrow: 1,
    gridTemplateColumns: {
      default: "minmax(0, 1fr) 22.5rem",
      [NARROW]: "minmax(0, 1fr)",
    },
    width: "100%",
  },
  mainColumn: {
    paddingBlock: spacing._6,
    paddingInline: spacing._6,
  },
  railColumn: {
    backgroundColor: semanticColors.bgMuted,
    borderInlineStartColor: {
      default: semanticColors.border,
      [NARROW]: "transparent",
    },
    borderInlineStartStyle: {
      default: "solid",
      [NARROW]: "none",
    },
    borderInlineStartWidth: {
      default: "1px",
      [NARROW]: "0px",
    },
    borderTopColor: {
      default: "transparent",
      [NARROW]: semanticColors.border,
    },
    borderTopStyle: {
      default: "none",
      [NARROW]: "solid",
    },
    borderTopWidth: {
      default: "0px",
      [NARROW]: "1px",
    },
    paddingBlock: spacing._6,
    paddingInline: spacing._5,
  },
  kpiGrid: {
    gridTemplateColumns: {
      default: "repeat(4, minmax(0, 1fr))",
      [NARROW]: "repeat(2, minmax(0, 1fr))",
      [COMPACT]: "minmax(0, 1fr)",
    },
  },
  kpiBody: {
    paddingBlock: spacing._4,
    paddingInline: spacing._4,
  },
  deltaIcon: {
    alignItems: "center",
    display: "inline-flex",
  },
  sparklineHost: {
    marginTop: spacing._1,
  },
  cardInner: {
    paddingBlock: spacing._5,
    paddingInline: spacing._5,
  },
  twoColGrid: {
    gridTemplateColumns: {
      default: "repeat(2, minmax(0, 1fr))",
      [COMPACT]: "minmax(0, 1fr)",
    },
  },
  tableScroll: {
    overflowX: "auto",
    width: "100%",
  },
  nowrap: {
    whiteSpace: "nowrap",
  },
  attainmentCell: {
    minWidth: "7.5rem",
  },
  highlightBody: {
    paddingBlock: spacing._4,
    paddingInline: spacing._4,
  },
  highlightIconWrap: {
    borderRadius: semanticRadii.control,
    flexShrink: 0,
    height: "1.75rem",
    width: "1.75rem",
  },
  highlightIconSuccess: {
    backgroundColor: semanticColors.bgSuccess,
    color: semanticColors.fgSuccess,
  },
  highlightIconWarning: {
    backgroundColor: semanticColors.bgWarning,
    color: semanticColors.fgWarning,
  },
  highlightIconInfo: {
    backgroundColor: semanticColors.bgInfo,
    color: semanticColors.fgInfo,
  },
  boardBriefCard: {
    paddingBlock: spacing._4,
    paddingInline: spacing._4,
  },
  boardChecklist: {
    listStyleType: "none",
    marginBlock: 0,
    paddingInlineStart: 0,
  },
  checkIconOk: {
    alignItems: "center",
    color: semanticColors.fgSuccess,
    display: "inline-flex",
    flexShrink: 0,
  },
});

// ============= INLINE SVGS =============

function ShareIcon() {
  return (
    <svg
      width="14"
      height="14"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.9"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <circle cx="18" cy="5" r="3" />
      <circle cx="6" cy="12" r="3" />
      <circle cx="18" cy="19" r="3" />
      <line x1="8.59" y1="13.51" x2="15.42" y2="17.49" />
      <line x1="15.41" y1="6.51" x2="8.59" y2="10.49" />
    </svg>
  );
}

function DownloadIcon() {
  return (
    <svg
      width="14"
      height="14"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.9"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
      <polyline points="7 10 12 15 17 10" />
      <line x1="12" y1="15" x2="12" y2="3" />
    </svg>
  );
}

function CopyIcon() {
  return (
    <svg
      width="14"
      height="14"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.9"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
      <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
    </svg>
  );
}

function ArrowUpIcon() {
  return (
    <svg
      width="12"
      height="12"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="2.4"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <line x1="12" y1="19" x2="12" y2="5" />
      <polyline points="5 12 12 5 19 12" />
    </svg>
  );
}

function ArrowDownIcon() {
  return (
    <svg
      width="12"
      height="12"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="2.4"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <line x1="12" y1="5" x2="12" y2="19" />
      <polyline points="19 12 12 19 5 12" />
    </svg>
  );
}

function CheckCircleIcon() {
  return (
    <svg
      width="15"
      height="15"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="2"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <circle cx="12" cy="12" r="10" />
      <path d="m9 12 2 2 4-4" />
    </svg>
  );
}

function AlertTriangleIcon() {
  return (
    <svg
      width="15"
      height="15"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="2"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z" />
      <line x1="12" y1="9" x2="12" y2="13" />
      <line x1="12" y1="17" x2="12.01" y2="17" />
    </svg>
  );
}

function InfoCircleIcon() {
  return (
    <svg
      width="15"
      height="15"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="2"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <circle cx="12" cy="12" r="10" />
      <line x1="12" y1="16" x2="12" y2="12" />
      <line x1="12" y1="8" x2="12.01" y2="8" />
    </svg>
  );
}

// ============= CHARTS =============

function KpiSparkline({
  label,
  data,
  rag,
}: {
  label: string;
  data: readonly number[];
  rag: RagStatus;
}) {
  const strokeColor =
    rag === "green"
      ? "blue"
      : rag === "amber"
        ? "orange"
        : semanticColors.redSolid;

  const chartData = useMemo(
    () => data.map((value, idx) => ({ week: `W${idx + 1}`, value })),
    [data],
  );

  return (
    <Sparkline
      data={chartData}
      index="week"
      categories={["value"]}
      colors={[strokeColor]}
      height={36}
      curve="linear"
      ariaLabel={`${label} quarterly 12-week trend`}
      style={styles.sparklineHost}
    />
  );
}

function RevenueVsTargetChart({ snapshot }: { snapshot: QuarterSnapshot }) {
  const chartData = useMemo(
    () =>
      snapshot.revenueSeries.map((pt) => ({
        week: pt.label,
        "Actual ARR": pt.actual,
        "Plan Target": pt.target,
        "Prior Year": pt.prior,
      })),
    [snapshot.revenueSeries],
  );

  return (
    <Card.Root variant="outline">
      <VStack gap="4" style={styles.cardInner}>
        <HStack justify="between" align="center" wrap="wrap" gap="3">
          <VStack gap="0.5">
            <Heading render={<h3 />} size="md" style={styles.headingReset}>
              ARR Run-Rate vs. Plan ({snapshot.quarter} FY26)
            </Heading>
            <Text size="xs" tone="muted">
              Weekly trajectory compared against board operating plan and prior-year baseline
            </Text>
          </VStack>
          <Badge variant="subtle" size="sm" palette={RAG_PALETTE[snapshot.planRag]}>
            {snapshot.planAttainment}
          </Badge>
        </HStack>

        <LineChart
          data={chartData}
          index="week"
          categories={["Actual ARR", "Plan Target", "Prior Year"]}
          colors={["blue", "orange", "slate"]}
          height={250}
          curve="linear"
          valueFormatter={(value) => `$${value.toFixed(1)}M`}
          ariaLabel={`Kestrel Cloud ${snapshot.quarter} ARR run-rate vs. plan target and prior year`}
        />
      </VStack>
    </Card.Root>
  );
}

function SegmentMixCard({ snapshot }: { snapshot: QuarterSnapshot }) {
  const totalArr = snapshot.segmentMix.reduce((sum, item) => sum + item.arrMillions, 0);

  return (
    <Card.Root variant="outline">
      <VStack gap="4" style={styles.cardInner}>
        <HStack justify="between" align="center" wrap="wrap" gap="3">
          <VStack gap="0.5">
            <Heading render={<h3 />} size="sm" style={styles.headingReset}>
              ARR Mix by Segment
            </Heading>
            <Text size="xs" tone="muted">
              Total ${totalArr.toFixed(1)}M across 4 commercial tiers
            </Text>
          </VStack>
          <Badge variant="outline" size="xs" palette={grayPalette}>
            {snapshot.quarter} FY26
          </Badge>
        </HStack>

        <CategoryBar
          values={snapshot.segmentMix.map((seg) => seg.arrMillions)}
          labels={snapshot.segmentMix.map((seg) => seg.label)}
          colors={snapshot.segmentMix.map((seg) => seg.color)}
          valueFormatter={(value) =>
            `$${value.toFixed(1)}M (${((value / totalArr) * 100).toFixed(1)}%)`
          }
          ariaLabel={`${snapshot.quarter} ARR mix by commercial segment`}
        />
      </VStack>
    </Card.Root>
  );
}

function NetNewArrDriversCard({ selectedQuarter }: { selectedQuarter: Quarter }) {
  const selectedData =
    NET_NEW_ARR_BY_QUARTER.find((item) => item.quarter === selectedQuarter) ??
    NET_NEW_ARR_BY_QUARTER[3];
  const selectedTotal = (selectedData.newLogo + selectedData.expansion).toFixed(1);

  return (
    <Card.Root variant="outline">
      <VStack gap="4" style={styles.cardInner}>
        <HStack justify="between" align="center" wrap="wrap" gap="3">
          <VStack gap="0.5">
            <Heading render={<h3 />} size="sm" style={styles.headingReset}>
              Net-New ARR Drivers
            </Heading>
            <Text size="xs" tone="muted">
              {selectedQuarter} added ${selectedTotal}M net-new ARR (New Logo vs. Expansion)
            </Text>
          </VStack>
          <Badge variant="subtle" size="xs" palette={bluePalette}>
            FY26 Cadence
          </Badge>
        </HStack>

        <BarChart
          data={NET_NEW_ARR_CHART_DATA}
          index="quarter"
          categories={["New Logo ARR", "Expansion ARR"]}
          colors={["blue", "teal"]}
          type="grouped"
          layout="vertical"
          height={144}
          valueFormatter={(value) => `$${value.toFixed(1)}M`}
          ariaLabel="FY26 quarterly net-new ARR split by New Logo ARR and Expansion ARR"
        />
      </VStack>
    </Card.Root>
  );
}

// ============= MAIN COMPONENT =============

export interface ExecutiveDashboardProps extends StyleOverrideProps {}

/**
 * ExecutiveDashboard — Kestrel Cloud quarterly executive scorecard built with
 * stock UI SDK components and Chart primitives: period switcher (Q1–Q4), KPI
 * sparkline tiles, interactive ARR vs. plan line chart, segment mix category
 * bar and net-new ARR grouped bar chart, regional attainment scorecard table,
 * OKR progress tracker, and an executive highlights rail with share/export
 * toast actions.
 */
export function ExecutiveDashboard({ style, palette }: ExecutiveDashboardProps) {
  const queue = useMemo(() => Toast.createToaster(), []);
  const [quarter, setQuarter] = useState<Quarter>("Q4");
  const [attainmentFilter, setAttainmentFilter] = useState<AttainmentFilter>("all");

  const snapshot = QUARTER_SNAPSHOTS[quarter];

  const filteredAttainment = useMemo(() => {
    return snapshot.attainment.filter((row) => {
      const pct = (row.bookedArr / row.quotaArr) * 100;
      const rag = attainmentRag(pct);
      if (attainmentFilter === "on-track") return rag === "green";
      if (attainmentFilter === "watch") return rag !== "green";
      return true;
    });
  }, [snapshot.attainment, attainmentFilter]);

  const objectivesOnTrack = useMemo(() => {
    const count = snapshot.objectives.filter(
      (o) => objectiveRag((o.actual / o.target) * 100) === "green",
    ).length;
    return `${count} of ${snapshot.objectives.length} on track`;
  }, [snapshot.objectives]);

  const handleShare = () => {
    queue.info(`Share link ready for ${quarter} FY26`, {
      description: "Read-only board briefing URL copied with current quarter filter.",
    });
  };

  const handleExport = () => {
    queue.success(`Exported Kestrel Cloud ${quarter} Scorecard`, {
      description: "Board packet PDF and CSV attainment schedule queued for download.",
    });
  };

  const handleCopyBrief = () => {
    const summaryLines = [
      `Kestrel Cloud — ${quarter} FY26 Executive Summary (${snapshot.planAttainment})`,
      ...snapshot.kpis.map((k) => `- ${k.label}: ${k.value} (${k.deltaLabel})`),
      "",
      "Highlights:",
      ...snapshot.highlights.map((h) => `- ${h.title} [${h.impact}]`),
    ].join("\n");

    try {
      void navigator.clipboard?.writeText(summaryLines);
    } catch {
      // Clipboard may be restricted in sandboxed preview frames.
    }

    queue.success("Executive brief copied", {
      description: `${quarter} FY26 KPIs and ${snapshot.highlights.length} narrative highlights copied to clipboard.`,
    });
  };

  return (
    <div {...stylex.props(styles.root, palette, style)}>
      {/* Header Bar */}
      <HStack
        render={<header />}
        justify="between"
        align="center"
        wrap="wrap"
        gap="4"
        style={styles.header}
      >
        <VStack gap="1">
          <HStack align="center" wrap="wrap" gap="2.5">
            <Heading render={<h1 />} size="xl" style={styles.headingReset}>
              Kestrel Cloud · Executive Scorecard
            </Heading>
            <Badge variant="subtle" size="sm" palette={bluePalette}>
              {quarter} FY26
            </Badge>
          </HStack>
          <HStack align="center" wrap="wrap" gap="2">
            <Text render={<span />} size="sm" tone="muted">
              {snapshot.dateRange}
            </Text>
            <Text render={<span />} size="sm" tone="muted" aria-hidden="true">
              ·
            </Text>
            <Text render={<span />} size="sm" tone="muted">
              {snapshot.updatedLabel}
            </Text>
          </HStack>
        </VStack>

        <HStack align="center" wrap="wrap" gap="2.5">
          <SegmentGroup.Root
            size="sm"
            value={quarter}
            onValueChange={(next) => {
              if (next === "Q1" || next === "Q2" || next === "Q3" || next === "Q4") {
                setQuarter(next);
              }
            }}
            aria-label="Fiscal quarter"
          >
            <SegmentGroup.Item value="Q1">Q1</SegmentGroup.Item>
            <SegmentGroup.Item value="Q2">Q2</SegmentGroup.Item>
            <SegmentGroup.Item value="Q3">Q3</SegmentGroup.Item>
            <SegmentGroup.Item value="Q4">Q4</SegmentGroup.Item>
          </SegmentGroup.Root>

          <Button variant="surface" size="sm" onClick={handleShare}>
            <ShareIcon />
            Share
          </Button>
          <Button variant="surface" size="sm" onClick={handleExport}>
            <DownloadIcon />
            Export
          </Button>
        </HStack>
      </HStack>

      {/* Two-Column Executive Workspace */}
      <Grid gap="0" style={styles.workspace}>
        <VStack render={<main />} gap="6" style={styles.mainColumn}>
          {/* Band 1: Headline KPI Scorecards */}
          <VStack render={<section aria-label="Key performance scorecards" />} gap="3">
            <HStack justify="between" align="center" wrap="wrap" gap="2">
              <Heading render={<h2 />} size="md" style={styles.headingReset}>
                Headline Scorecards
              </Heading>
              <Text render={<span />} size="xs" tone="muted">
                Quarter-over-quarter performance · 12-week cadence
              </Text>
            </HStack>

            <Grid gap="3" style={styles.kpiGrid}>
              {snapshot.kpis.map((kpi) => (
                <Card.Root key={kpi.key} variant="outline">
                  <VStack gap="2" style={styles.kpiBody}>
                    <Stat.Root size="md">
                      <Stat.Label>{kpi.label}</Stat.Label>
                      <HStack align="baseline" wrap="wrap" gap="2">
                        <Stat.ValueText>{kpi.value}</Stat.ValueText>
                        <HStack render={<span />} align="center" gap="0.5">
                          <Text
                            render={<span />}
                            size="xs"
                            weight="medium"
                            tone={RAG_TEXT_TONE[kpi.rag]}
                            style={styles.deltaIcon}
                          >
                            {kpi.direction === "up" ? <ArrowUpIcon /> : <ArrowDownIcon />}
                          </Text>
                          <Text
                            render={<span />}
                            size="xs"
                            weight="medium"
                            tone={RAG_TEXT_TONE[kpi.rag]}
                            tabular="true"
                          >
                            {kpi.deltaLabel}
                          </Text>
                        </HStack>
                      </HStack>
                      <Stat.HelpText>{kpi.targetNote}</Stat.HelpText>
                    </Stat.Root>
                    <KpiSparkline label={kpi.label} data={kpi.sparkline} rag={kpi.rag} />
                  </VStack>
                </Card.Root>
              ))}
            </Grid>
          </VStack>

          {/* Band 2: Revenue vs. Target & Drivers */}
          <VStack render={<section aria-label="Revenue performance charts" />} gap="4">
            <RevenueVsTargetChart snapshot={snapshot} />

            <Grid gap="4" style={styles.twoColGrid}>
              <SegmentMixCard snapshot={snapshot} />
              <NetNewArrDriversCard selectedQuarter={quarter} />
            </Grid>
          </VStack>

          <Separator />

          {/* Band 3: Regional & Segment Attainment Scorecard Table */}
          <VStack render={<section aria-label="Regional and segment attainment" />} gap="3">
            <Card.Root variant="outline">
              <VStack gap="4" style={styles.cardInner}>
                <HStack justify="between" align="center" wrap="wrap" gap="3">
                  <VStack gap="0.5">
                    <Heading render={<h2 />} size="md" style={styles.headingReset}>
                      Regional &amp; Segment Attainment
                    </Heading>
                    <Text size="xs" tone="muted">
                      Quota execution and net dollar retention by territory ({quarter} FY26)
                    </Text>
                  </VStack>

                  <SegmentGroup.Root
                    size="xs"
                    value={attainmentFilter}
                    onValueChange={(next) => {
                      if (next === "all" || next === "on-track" || next === "watch") {
                        setAttainmentFilter(next);
                      }
                    }}
                    aria-label="Filter territories by status"
                  >
                    <SegmentGroup.Item value="all">All</SegmentGroup.Item>
                    <SegmentGroup.Item value="on-track">On Track</SegmentGroup.Item>
                    <SegmentGroup.Item value="watch">Watch</SegmentGroup.Item>
                  </SegmentGroup.Root>
                </HStack>

                <div {...stylex.props(styles.tableScroll)}>
                  <Table.Root size="sm">
                    <Table.Header>
                      <Table.Row>
                        <Table.ColumnHeader>Territory</Table.ColumnHeader>
                        <Table.ColumnHeader>Executive Lead</Table.ColumnHeader>
                        <Table.ColumnHeader>Booked ARR</Table.ColumnHeader>
                        <Table.ColumnHeader>Quota Attainment</Table.ColumnHeader>
                        <Table.ColumnHeader>NDR</Table.ColumnHeader>
                        <Table.ColumnHeader>Status</Table.ColumnHeader>
                      </Table.Row>
                    </Table.Header>
                    <Table.Body>
                      {filteredAttainment.map((row) => {
                        const pct = Math.round((row.bookedArr / row.quotaArr) * 100);
                        const rag = attainmentRag(pct);
                        const rowPalette = RAG_PALETTE[rag];

                        return (
                          <Table.Row key={row.id}>
                            <Table.Cell>
                              <VStack gap="0.5">
                                <Text render={<span />} size="sm" weight="medium">
                                  {row.region}
                                </Text>
                                <Text render={<span />} size="xs" tone="muted">
                                  {row.segment}
                                </Text>
                              </VStack>
                            </Table.Cell>
                            <Table.Cell>
                              <HStack align="center" gap="2" style={styles.nowrap}>
                                <Avatar.Root
                                  size="xs"
                                  variant="subtle"
                                  palette={AVATAR_PALETTE[row.leadPalette]}
                                >
                                  <Avatar.Fallback>{row.leadInitials}</Avatar.Fallback>
                                </Avatar.Root>
                                <span>{row.leadName}</span>
                              </HStack>
                            </Table.Cell>
                            <Table.Cell style={styles.nowrap}>
                              <Text render={<span />} variant="mono" size="xs" tabular="true">
                                ${row.bookedArr.toFixed(1)}M
                              </Text>
                            </Table.Cell>
                            <Table.Cell>
                              <VStack gap="1" style={styles.attainmentCell}>
                                <HStack justify="between" align="center" gap="2">
                                  <Text
                                    render={<span />}
                                    variant="mono"
                                    size="xs"
                                    weight="semibold"
                                    tabular="true"
                                  >
                                    {pct}%
                                  </Text>
                                  <Text
                                    render={<span />}
                                    variant="mono"
                                    size="xs"
                                    tone="muted"
                                    tabular="true"
                                  >
                                    of ${row.quotaArr.toFixed(1)}M
                                  </Text>
                                </HStack>
                                <Progress.Root
                                  value={Math.min(pct, 100)}
                                  max={100}
                                  size="xs"
                                  palette={rowPalette}
                                  aria-label={`${row.region} ${row.segment} quota attainment`}
                                >
                                  <Progress.Track>
                                    <Progress.Range />
                                  </Progress.Track>
                                </Progress.Root>
                              </VStack>
                            </Table.Cell>
                            <Table.Cell style={styles.nowrap}>
                              <Text render={<span />} variant="mono" size="xs" tabular="true">
                                {row.ndr.toFixed(1)}%
                              </Text>
                            </Table.Cell>
                            <Table.Cell>
                              <Status.Root size="sm" palette={rowPalette}>
                                <Status.Indicator />
                                {statusLabelForRag(rag)}
                              </Status.Root>
                            </Table.Cell>
                          </Table.Row>
                        );
                      })}
                    </Table.Body>
                  </Table.Root>
                </div>
              </VStack>
            </Card.Root>
          </VStack>

          {/* Band 4: Strategic Objectives (OKR Attainment) */}
          <VStack render={<section aria-label="Strategic objectives" />} gap="3">
            <HStack justify="between" align="center" wrap="wrap" gap="2">
              <Heading render={<h2 />} size="md" style={styles.headingReset}>
                Strategic Objectives
              </Heading>
              <Text render={<span />} size="xs" tone="muted">
                {objectivesOnTrack}
              </Text>
            </HStack>

            <Card.Root variant="outline">
              <VStack gap="4" style={styles.cardInner}>
                <VStack gap="4">
                  {snapshot.objectives.map((okr, index) => {
                    const pct = Math.round((okr.actual / okr.target) * 100);
                    const rag = objectiveRag(pct);
                    const formattedActual = `${okr.prefix ?? ""}${okr.actual}${okr.unit}`;
                    const formattedTarget = `${okr.prefix ?? ""}${okr.target}${okr.unit}`;

                    return (
                      <VStack key={okr.id} gap="2">
                        {index > 0 && <Separator />}
                        <HStack justify="between" align="baseline" gap="3">
                          <Text render={<h3 />} size="sm" weight="medium">
                            {okr.objective}
                          </Text>
                          <Text
                            render={<span />}
                            variant="mono"
                            size="xs"
                            weight="semibold"
                            tone="muted"
                            tabular="true"
                            style={styles.nowrap}
                          >
                            {pct}%
                          </Text>
                        </HStack>
                        <Progress.Root
                          value={Math.min(okr.actual, okr.target)}
                          max={okr.target}
                          size="sm"
                          palette={RAG_PALETTE[rag]}
                          aria-label={okr.objective}
                        >
                          <Progress.Track>
                            <Progress.Range />
                          </Progress.Track>
                        </Progress.Root>
                        <HStack justify="between" align="center" wrap="wrap" gap="2">
                          <HStack align="center" gap="2">
                            <Avatar.Root
                              size="xs"
                              variant="subtle"
                              palette={AVATAR_PALETTE[okr.ownerPalette]}
                            >
                              <Avatar.Fallback>{okr.ownerInitials}</Avatar.Fallback>
                            </Avatar.Root>
                            <Text render={<span />} size="xs" tone="muted">
                              {okr.ownerName} · {okr.ownerRole}
                            </Text>
                          </HStack>
                          <Text
                            render={<span />}
                            variant="mono"
                            size="xs"
                            tabular="true"
                            style={styles.nowrap}
                          >
                            {formattedActual} / {formattedTarget} target
                          </Text>
                        </HStack>
                      </VStack>
                    );
                  })}
                </VStack>
              </VStack>
            </Card.Root>
          </VStack>
        </VStack>

        {/* Right Rail: Executive Highlights */}
        <VStack
          render={<aside aria-label="Executive highlights" />}
          gap="4"
          style={styles.railColumn}
        >
          <HStack justify="between" align="center" wrap="wrap" gap="2">
            <Heading render={<h2 />} size="md" style={styles.headingReset}>
              Executive Highlights
            </Heading>
            <Text render={<span />} size="xs" tone="muted">
              What changed &amp; why
            </Text>
          </HStack>

          <VStack gap="3">
            {snapshot.highlights.map((item) => (
              <Card.Root key={item.id} variant="outline">
                <VStack gap="2.5" style={styles.highlightBody}>
                  <HStack align="start" gap="2.5">
                    <Center
                      display="inline"
                      render={<span />}
                      style={[
                        styles.highlightIconWrap,
                        item.status === "success" && styles.highlightIconSuccess,
                        item.status === "warning" && styles.highlightIconWarning,
                        item.status === "info" && styles.highlightIconInfo,
                      ]}
                    >
                      {item.status === "success" ? (
                        <CheckCircleIcon />
                      ) : item.status === "warning" ? (
                        <AlertTriangleIcon />
                      ) : (
                        <InfoCircleIcon />
                      )}
                    </Center>
                    <VStack gap="1">
                      <Text render={<h3 />} size="sm" weight="medium">
                        {item.title}
                      </Text>
                      <Text size="xs" tone="muted">
                        {item.detail}
                      </Text>
                    </VStack>
                  </HStack>
                  <HStack justify="end" align="center">
                    <Badge
                      variant="subtle"
                      size="xs"
                      palette={HIGHLIGHT_BADGE_PALETTE[item.status]}
                    >
                      {item.impact}
                    </Badge>
                  </HStack>
                </VStack>
              </Card.Root>
            ))}
          </VStack>

          <Card.Root variant="outline">
            <VStack gap="3" style={styles.boardBriefCard}>
              <HStack justify="between" align="center" gap="2">
                <Heading render={<h3 />} size="sm" style={styles.headingReset}>
                  Board Packet Readiness
                </Heading>
                <Badge variant="subtle" size="xs" palette={greenPalette}>
                  Signed Off
                </Badge>
              </HStack>
              <Text size="xs" tone="muted">
                Finance, RevOps, and Cloud Infrastructure actuals reconciled for {quarter} FY26.
              </Text>
              <VStack render={<ul />} gap="1.5" style={styles.boardChecklist}>
                <HStack render={<li />} align="center" gap="2">
                  <span {...stylex.props(styles.checkIconOk)}>
                    <CheckCircleIcon />
                  </span>
                  <Text render={<span />} size="xs" tone="muted">
                    ARR &amp; bookings ledger verified by FP&amp;A
                  </Text>
                </HStack>
                <HStack render={<li />} align="center" gap="2">
                  <span {...stylex.props(styles.checkIconOk)}>
                    <CheckCircleIcon />
                  </span>
                  <Text render={<span />} size="xs" tone="muted">
                    Cohort NDR &amp; churn bridge reconciled
                  </Text>
                </HStack>
                <HStack render={<li />} align="center" gap="2">
                  <span {...stylex.props(styles.checkIconOk)}>
                    <CheckCircleIcon />
                  </span>
                  <Text render={<span />} size="xs" tone="muted">
                    Cloud COGS &amp; gross margin footnotes attached
                  </Text>
                </HStack>
              </VStack>
              <Button variant="surface" size="sm" onClick={handleCopyBrief}>
                <CopyIcon />
                Copy executive brief
              </Button>
            </VStack>
          </Card.Root>
        </VStack>
      </Grid>

      <Toaster toaster={queue} />
    </div>
  );
}
```

Credit: Inspired by [Executive Summary Dashboard](https://astryx.atmeta.com/playground?template=dashboard-scorecard) from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.)
