# Entity card

One record at a glance: what it is, its status and the 4–6 fields that matter, with a link to open it in your app. The agent answers the question; the card shows the record.

{/* Generated by scripts/build-ui-catalog.mjs from src/ui-catalog/. Do not edit. */}

One record at a glance: what it is, its status and the 4–6 fields that matter, with a link to open it in your app. The agent answers the question; the card shows the record.

## When to use it

**Use it when:** The user asks about one record (an account, a contact, an order, a project) and the answer is what it is, its status and 4–6 key fields, with a way to open it in your app.

**Use something else when:** Several records (records list or table). The user wants to change the record (form with approval). More than ~6 fields or long text (link to the record, or a canvas).

## What the agent receives

| The template calls | The agent gets | When |
| --- | --- | --- |
| `displayed()` | `FUNCTION_TOOL_DISPLAYED` | As soon as the card shows. The agent goes on. |

## States

Besides its data, the template draws these as itself, with `mountState()`. Pick one on the preview with **State**.

| State | When it shows |
| --- | --- |
| Loading | While the card loads the record again in place, for example after Try again. While execute runs, the SDK shows its own loader. |
| Empty | execute found no record that matches. The card says so and the agent offers the closest match. |
| Error | execute returned the failure as data, so the agent can explain it. Try again loads the record in place. |

```ts
mountState({ root, head, title: "…", state: { kind: "error", text: "…", retry } });
```

The hosted action and the in-page handler below show each case. The state types are `LoadingState`, `EmptyState` and `ErrorState` in fs-kit.

## Data

### EntityCardData

| Field | Type | Notes |
| --- | --- | --- |
| `id` (optional) | `string` | Your record's id. The card doesn't show it; your actions.run can use it. |
| `kind` (optional) | `string` | What the record is, above the name: "Account", "Contact", "Order". |
| `name` | `string` |  |
| `subtitle` (optional) | `string` |  |
| `avatarUrl` (optional) | `string` | Logo or photo URL. Without it, or if it fails to load, the card shows initials. |
| `avatarShape` (optional) | `"square" \| "circle"` | "square" (default) for companies and things, "circle" for people. |
| `status` (optional) | `EntityStatus` |  |
| `fields` | `EntityField[]` | 4–6 key fields. More are cut. |
| `tags` (optional) | `string[]` |  |
| `owner` (optional) | `EntityOwner` |  |
| `links` (optional) | `EntityLink[]` | At most 2, in the footer. More are cut. |

### EntityField

| Field | Type | Notes |
| --- | --- | --- |
| `label` | `string` |  |
| `value` | `string \| number` | A number is formatted with format; a string is shown as is. |
| `format` (optional) | `NumberFormat` |  |
| `icon` (optional) | `IconName` | Small icon before the label. |
| `hint` (optional) | `string` | Short note after the value, e.g. "in 108 days". |
| `href` (optional) | `string` | Makes the value a link: a page in your app, mailto: or tel:. |
| `meter` (optional) | `number` | 0–100: draws a thin bar under the value (seat usage, a health score). |
| `tone` (optional) | `EntityTone` | Colour of the meter. Default: info (the brand colour). |
| `wide` (optional) | `boolean` | Full row in the two-column grid. |

### EntityStatus

| Field | Type | Notes |
| --- | --- | --- |
| `label` | `string` |  |
| `tone` (optional) | `EntityTone` | neutral (default), info, success, warning, error. |

### EntityOwner

| Field | Type | Notes |
| --- | --- | --- |
| `name` | `string` |  |
| `role` (optional) | `string` | e.g. "Account owner". |
| `avatarUrl` (optional) | `string` | Photo URL. Without it the card shows initials. |

### EntityLink

| Field | Type | Notes |
| --- | --- | --- |
| `label` | `string` |  |
| `href` (optional) | `string` | Where the link goes. Without it, the card calls actions.run(link). |
| `id` (optional) | `string` | Tells your actions.run which link was clicked. |
| `primary` (optional) | `boolean` | One link can be the primary button (brand colour). The others are then outline buttons. |
| `icon` (optional) | `IconName` |  |

### EntityCardActions

| Field | Type | Notes |
| --- | --- | --- |
| `run()` (optional) | `(link: EntityLink) => void` | A footer link without href was clicked. Open or do it in your app. |

## Install

Copy the template and the shared kit into your code: `agent/ui/` in an agent repo, or anywhere in your app. The template imports only `./fs-kit.js`. Then wire it up from the hosted action or the in-page handler.

- Hosted action: [TypeScript](/ui-catalog/files/ts/usage/entity-card.hosted.ts), [JavaScript](/ui-catalog/files/js/usage/entity-card.hosted.js)
- In-page handler: [TypeScript](/ui-catalog/files/ts/usage/entity-card.component.ts), [JavaScript](/ui-catalog/files/js/usage/entity-card.component.js)
- entity-card: [TypeScript](/ui-catalog/files/ts/entity-card.ts), [JavaScript](/ui-catalog/files/js/entity-card.js)
- fs-kit: [TypeScript](/ui-catalog/files/ts/fs-kit.ts), [JavaScript](/ui-catalog/files/js/fs-kit.js)

The hosted action needs an agent repo with one folder per action (`agent/actions/<action_key>/index.ts`). If your repo keeps its actions in `agent/actions/index.ts`, use the in-page handler: it runs the same template in your app.

All templates in machine-readable form: [/ui-catalog/catalog.json](/ui-catalog/catalog.json).

## Code

### Hosted action

```ts title="agent/actions/show_account/index.ts"
// agent/actions/show_account/index.ts: a hosted action.
// Copy the template (entity-card.ts) and fs-kit.ts into agent/ui/.

type Result = EntityCardData | { error: string } | { notFound: string };

export async function execute(args: { accountId: string }, ctx: ActionContext): Promise<Result> {
  const res = await ctx.fetch(`/api/accounts/${encodeURIComponent(args.accountId)}`);
  // No match and failures go back as data: the agent explains them, and the card shows them.
  if (res.status === 404) return { notFound: "No account has that id. It may have been merged or deleted." };
  if (!res.ok) return { error: `The account didn't load (${res.status}). Nothing changed.` };
  const a = await res.json();
  const renews = new Date(a.renewsAt);
  const days = Math.round((renews.getTime() - Date.now()) / 86400000);
  // Return every value the card shows: the agent reads this, not the card.
  return {
    id: a.id,
    kind: "Account",
    name: a.name,
    subtitle: [a.industry, a.city].filter(Boolean).join(" · "),
    avatarUrl: a.logoUrl,
    status: a.churned ? { label: "Churned", tone: "neutral" } : { label: "Active customer", tone: "success" },
    fields: [
      { label: "ARR", value: a.arr, format: { style: "currency" }, icon: "dollar" },
      { label: "Plan", value: a.plan, icon: "star" },
      { label: "Seats", value: `${a.seatsUsed} of ${a.seats}`, icon: "users", meter: Math.round((a.seatsUsed / a.seats) * 100), tone: a.seatsUsed / a.seats > 0.9 ? "warning" : "info" },
      { label: "Renews", value: renews.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" }), icon: "calendar", hint: `in ${days} days` },
    ],
    tags: a.segments,
    owner: a.owner ? { name: a.owner.name, role: "Account owner", avatarUrl: a.owner.photoUrl } : undefined,
    links: [{ label: "Open account", href: `/accounts/${a.id}` }],
  };
}

// Read-only in every case: the card reports displayed(result), so the agent reads the data and goes on.
export function render(result: Result, ctx: RenderContext) {
  const { root, head } = ctx.card;
  if ("error" in result) {
    mountState({ root, head, title: "Account", state: { kind: "error", title: "Couldn't load this account", text: result.error } });
  } else if ("notFound" in result) {
    mountState({ root, head, title: "Account", icon: "search", state: { kind: "empty", title: "No account found", text: result.notFound } });
  } else {
    mount({ root, head, data: result, api: { displayed: () => ctx.card.displayed(result) } });
    return;
  }
  ctx.card.displayed(result); // the agent reads what it shows, or the error to explain
}
```

```js title="agent/actions/show_account/index.js"
// agent/actions/show_account/index.js: a hosted action.
// Copy the template (entity-card.ts) and fs-kit.ts into agent/ui/.

export async function execute(args, ctx) {
  const res = await ctx.fetch(`/api/accounts/${encodeURIComponent(args.accountId)}`);
  // No match and failures go back as data: the agent explains them, and the card shows them.
  if (res.status === 404) return { notFound: "No account has that id. It may have been merged or deleted." };
  if (!res.ok) return { error: `The account didn't load (${res.status}). Nothing changed.` };
  const a = await res.json();
  const renews = new Date(a.renewsAt);
  const days = Math.round((renews.getTime() - Date.now()) / 86400000);
  // Return every value the card shows: the agent reads this, not the card.
  return {
    id: a.id,
    kind: "Account",
    name: a.name,
    subtitle: [a.industry, a.city].filter(Boolean).join(" · "),
    avatarUrl: a.logoUrl,
    status: a.churned ? { label: "Churned", tone: "neutral" } : { label: "Active customer", tone: "success" },
    fields: [
      { label: "ARR", value: a.arr, format: { style: "currency" }, icon: "dollar" },
      { label: "Plan", value: a.plan, icon: "star" },
      { label: "Seats", value: `${a.seatsUsed} of ${a.seats}`, icon: "users", meter: Math.round((a.seatsUsed / a.seats) * 100), tone: a.seatsUsed / a.seats > 0.9 ? "warning" : "info" },
      { label: "Renews", value: renews.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" }), icon: "calendar", hint: `in ${days} days` },
    ],
    tags: a.segments,
    owner: a.owner ? { name: a.owner.name, role: "Account owner", avatarUrl: a.owner.photoUrl } : undefined,
    links: [{ label: "Open account", href: `/accounts/${a.id}` }],
  };
}

// Read-only in every case: the card reports displayed(result), so the agent reads the data and goes on.
export function render(result, ctx) {
  const { root, head } = ctx.card;
  if ("error" in result) {
    mountState({ root, head, title: "Account", state: { kind: "error", title: "Couldn't load this account", text: result.error } });
  } else if ("notFound" in result) {
    mountState({ root, head, title: "Account", icon: "search", state: { kind: "empty", title: "No account found", text: result.notFound } });
  } else {
    mount({ root, head, data: result, api: { displayed: () => ctx.card.displayed(result) } });
    return;
  }
  ctx.card.displayed(result); // the agent reads what it shows, or the error to explain
}
```

### In-page handler

```ts title="in-page handler.ts"
// An in-page action handler: the template runs in your page.

type Result = EntityCardData | { error: string; accountId: string } | null;

foldspace("when", "ready", () => {
  foldspace.agent({ /* …common setup… */ }).addActionHandlers({
    show_account: {
      // Return every value the card shows: the agent reads this, not the card.
      // No match and failures go back as data too, so the agent can explain them.
      execute: async ({ accountId }: { accountId: string }): Promise<Result> =>
        loadAccountCard(accountId).catch(() => ({ error: "The account didn't load. Nothing changed.", accountId })),

      // Read-only: declares readyState only. The agent goes on as soon as the card reports it's shown.
      renderComponent: ({ data, host, header, readyState }: ComponentContext<Result>) => {
        // Once: on desktop a second readyState (after Retry) would start a new agent turn.
        const shown = once(readyState);
        const show = (result: Result): void => {
          if (!result) { // loadAccountCard resolves to null when no account has that id
            mountState({ root: host, head: header, title: "Account", icon: "search", state: { kind: "empty", title: "No account found", text: "No account has that id. It may have been merged or deleted." } });
          } else if ("error" in result) {
            mountState({
              root: host, head: header, title: "Account",
              state: {
                kind: "error", title: "Couldn't load this account", text: result.error,
                // Retry in the card: bones while it loads, then the record (or the error again).
                retry: async () => {
                  mountState({ root: host, head: header, state: { kind: "loading", label: "Loading account…" } });
                  show(await loadAccountCard(result.accountId).catch(() => ({ error: "Still not loading. Try again in a minute.", accountId: result.accountId })));
                },
              },
            });
          } else {
            return void mount({
              root: host, head: header, data: result, api: { displayed: () => shown(result) },
              // Links without href come here: open them with your router, no page reload.
              actions: { run: (link) => link.id === "open" && router.push(`/accounts/${result.id}`) },
            });
          }
          shown(result);
        };
        show(data);
      },
    },
  });
});
```

```js title="in-page handler.js"
// An in-page action handler: the template runs in your page.

foldspace("when", "ready", () => {
  foldspace.agent({ /* …common setup… */ }).addActionHandlers({
    show_account: {
      // Return every value the card shows: the agent reads this, not the card.
      // No match and failures go back as data too, so the agent can explain them.
      execute: async ({ accountId }) =>
        loadAccountCard(accountId).catch(() => ({ error: "The account didn't load. Nothing changed.", accountId })),

      // Read-only: declares readyState only. The agent goes on as soon as the card reports it's shown.
      renderComponent: ({ data, host, header, readyState }) => {
        // Once: on desktop a second readyState (after Retry) would start a new agent turn.
        const shown = once(readyState);
        const show = (result) => {
          if (!result) { // loadAccountCard resolves to null when no account has that id
            mountState({ root: host, head: header, title: "Account", icon: "search", state: { kind: "empty", title: "No account found", text: "No account has that id. It may have been merged or deleted." } });
          } else if ("error" in result) {
            mountState({
              root: host, head: header, title: "Account",
              state: {
                kind: "error", title: "Couldn't load this account", text: result.error,
                // Retry in the card: bones while it loads, then the record (or the error again).
                retry: async () => {
                  mountState({ root: host, head: header, state: { kind: "loading", label: "Loading account…" } });
                  show(await loadAccountCard(result.accountId).catch(() => ({ error: "Still not loading. Try again in a minute.", accountId: result.accountId })));
                },
              },
            });
          } else {
            return void mount({
              root: host, head: header, data: result, api: { displayed: () => shown(result) },
              // Links without href come here: open them with your router, no page reload.
              actions: { run: (link) => link.id === "open" && router.push(`/accounts/${result.id}`) },
            });
          }
          shown(result);
        };
        show(data);
      },
    },
  });
});
```

### entity-card

```ts title="agent/ui/entity-card.ts"
// Template: entity-card. A read-only chat card that shows one record at a glance: what it is, its status and the fields that matter.

export const meta = {
  id: "entity-card",
  title: "Entity card",
  surface: "card",
  kind: "read-only",
  mobile: "same",
  whenToUse: "The user asks about one record (an account, a contact, an order, a project) and the answer is what it is, its status and 4–6 key fields, with a way to open it in your app.",
  whenNotToUse: "Several records (records list or table). The user wants to change the record (form with approval). More than ~6 fields or long text (link to the record, or a canvas).",
};

const CSS = `
.fsk-ent {
  container-type: inline-size;
  background:
    radial-gradient(130% 90px at 0% 0%, color-mix(in srgb, var(--k-primary) 9%, transparent), transparent),
    var(--k-paper);
}
.fsk-ent .fsk-ent-head { display: flex; align-items: flex-start; gap: 8px 12px; margin-bottom: 14px; }
.fsk-ent .fsk-ent-id { flex: 1 1 0; min-width: 0; padding-top: 1px; }
.fsk-ent .fsk-ent-kind { display: block; margin-bottom: 1px; font-size: .72em; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--k-text-2); }
.fsk-ent .fsk-ent-name { margin: 0; font-size: 1.2em; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; overflow-wrap: anywhere; }
.fsk-ent .fsk-ent-av {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; overflow: hidden;
  border-radius: var(--k-r-md); font-weight: 650; letter-spacing: .02em; line-height: 1;
  color: color-mix(in srgb, var(--k-primary) 78%, var(--k-text));
  background: linear-gradient(145deg, color-mix(in srgb, var(--k-primary) 20%, var(--k-paper)), color-mix(in srgb, var(--k-primary) 7%, var(--k-paper)));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--k-primary) 16%, transparent);
}
.fsk-ent .fsk-ent-av--circle { border-radius: 50%; }
.fsk-ent .fsk-ent-av--sm { width: 28px; height: 28px; font-size: .72em; }
.fsk-ent .fsk-ent-av img { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--k-paper); }

.fsk-ent .fsk-ent-pill {
  --t: var(--k-text-2);
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; margin-top: 2px;
  border-radius: calc(var(--k-r) * 100); font-size: .79em; font-weight: 550; line-height: 1.5; white-space: nowrap;
  color: color-mix(in srgb, var(--t) 65%, var(--k-text));
  background: color-mix(in srgb, var(--t) 12%, var(--k-paper));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--t) 22%, transparent);
}
.fsk-ent .fsk-ent-pill::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--t); }
.fsk-ent .fsk-tone--info { --t: var(--k-primary); }
.fsk-ent .fsk-tone--success { --t: var(--k-success); }
.fsk-ent .fsk-tone--warning { --t: var(--k-warning); }
.fsk-ent .fsk-tone--error { --t: var(--k-error); }

/* Key fields: a hairline grid, two columns. */
.fsk-ent .fsk-ent-dl {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 0; overflow: hidden;
  background: var(--k-divider); border: 1px solid var(--k-divider); border-radius: var(--k-r-md);
}
.fsk-ent .fsk-ent-f { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 10px 12px; background: var(--k-paper); }
.fsk-ent .fsk-ent-f--wide { grid-column: 1 / -1; }
.fsk-ent dt { display: flex; align-items: center; gap: 5px; font-size: .79em; color: var(--k-text-2); }
.fsk-ent dd { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.fsk-ent .fsk-ent-hint { font-size: .79em; font-weight: 400; color: var(--k-text-2); }
.fsk-ent dd a {
  color: inherit; border-radius: 2px; text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, var(--k-text-2) 50%, transparent); transition: text-decoration-color .15s;
}
.fsk-ent dd a:hover { text-decoration-color: currentColor; }
.fsk-ent .fsk-ent-meter { --t: var(--k-primary); flex-basis: 100%; height: 4px; margin-top: 5px; overflow: hidden; border-radius: calc(var(--k-r) * 100); background: var(--k-hover); }
.fsk-ent .fsk-ent-meter > span { display: block; height: 100%; border-radius: inherit; background: var(--t); transform-origin: left; animation: fsk-ent-grow .8s var(--k-ease) .15s both; }
@keyframes fsk-ent-grow { from { transform: scaleX(0); } }

.fsk-ent .fsk-ent-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }
.fsk-ent .fsk-ent-tags li {
  padding: 1px 8px; border-radius: var(--k-r); font-size: .79em; line-height: 1.6;
  color: color-mix(in srgb, var(--k-text-2) 80%, var(--k-text)); background: var(--k-sunken); border: 1px solid var(--k-muted-border);
}

.fsk-ent .fsk-ent-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 16px -16px -16px; padding: 10px 16px;
  border-top: 1px solid var(--k-divider); background: var(--k-sunken);
  border-radius: 0 0 max(0px, calc(var(--k-r-lg) - 1px)) max(0px, calc(var(--k-r-lg) - 1px));
}
.fsk-ent .fsk-ent-owner { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; font-size: .86em; line-height: 1.3; }
.fsk-ent .fsk-ent-owner > div { min-width: 0; }
.fsk-ent .fsk-ent-owner-name { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsk-ent .fsk-ent-owner-role { display: block; font-size: .93em; color: var(--k-text-2); }
.fsk-ent .fsk-ent-acts { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.fsk-ent .fsk-ent-acts .fsk-btn { min-height: 32px; padding: 0 12px; }
.fsk-ent .fsk-ent-acts .fsk-btn--link { padding: 0 4px; }
.fsk-ent a:focus-visible, .fsk-ent button:focus-visible { outline: 2px solid var(--k-primary); outline-offset: 2px; }

/* Narrow card: the status drops under the name, fields go to one column. */
@container (max-width: 320px) {
  .fsk-ent .fsk-ent-head { flex-wrap: wrap; }
  .fsk-ent .fsk-ent-id { flex-basis: calc(100% - 56px); }
  .fsk-ent .fsk-ent-pill { margin: -2px 0 0 56px; }
}
@container (max-width: 250px) { .fsk-ent .fsk-ent-dl { grid-template-columns: 1fr; } }
.fsk-ent[data-surface="mobile"] .fsk-ent-acts .fsk-btn { min-height: 44px; }

/* Loading: the skeleton draws the card's own header (avatar, name, status), so the kit's header steps aside. */
.fsk-ent.fsk-state--loading > .fsk-head { display: none; }
.fsk-ent .fsk-ent-sk-id { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.fsk-ent .fsk-ent-sk-pill { margin-top: 4px; border-radius: calc(var(--k-r) * 100); }
.fsk-ent .fsk-ent-sk-f { gap: 8px; padding: 12px; }
.fsk-ent .fsk-ent-sk-owner { display: flex; flex-direction: column; gap: 6px; }
@container (max-width: 320px) { .fsk-ent .fsk-ent-sk-pill { display: none; } }
`;

export type EntityTone = "neutral" | "info" | "success" | "warning" | "error";

export interface EntityStatus {
  label: string;
  /** neutral (default), info, success, warning, error. */
  tone?: EntityTone;
}

export interface EntityField {
  label: string;
  /** A number is formatted with format; a string is shown as is. */
  value: string | number;
  format?: NumberFormat;
  /** Small icon before the label. */
  icon?: IconName;
  /** Short note after the value, e.g. "in 108 days". */
  hint?: string;
  /** Makes the value a link: a page in your app, mailto: or tel:. */
  href?: string;
  /** 0–100: draws a thin bar under the value (seat usage, a health score). */
  meter?: number;
  /** Colour of the meter. Default: info (the brand colour). */
  tone?: EntityTone;
  /** Full row in the two-column grid. */
  wide?: boolean;
}

export interface EntityOwner {
  name: string;
  /** e.g. "Account owner". */
  role?: string;
  /** Photo URL. Without it the card shows initials. */
  avatarUrl?: string;
}

export interface EntityLink {
  label: string;
  /** Where the link goes. Without it, the card calls actions.run(link). */
  href?: string;
  /** Tells your actions.run which link was clicked. */
  id?: string;
  /** One link can be the primary button (brand colour). The others are then outline buttons. */
  primary?: boolean;
  icon?: IconName;
}

export interface EntityCardData {
  /** Your record's id. The card doesn't show it; your actions.run can use it. */
  id?: string;
  /** What the record is, above the name: "Account", "Contact", "Order". */
  kind?: string;
  name: string;
  subtitle?: string;
  /** Logo or photo URL. Without it, or if it fails to load, the card shows initials. */
  avatarUrl?: string;
  /** "square" (default) for companies and things, "circle" for people. */
  avatarShape?: "square" | "circle";
  status?: EntityStatus;
  /** 4–6 key fields. More are cut. */
  fields: EntityField[];
  tags?: string[];
  owner?: EntityOwner;
  /** At most 2, in the footer. More are cut. */
  links?: EntityLink[];
}

export interface EntityCardActions {
  /** A footer link without href was clicked. Open or do it in your app. */
  run?(link: EntityLink): void;
}

export interface EntityCardProps {
  root: HTMLElement;
  head: StyleHost;
  data: EntityCardData;
  api?: CardApi;
  actions?: EntityCardActions;
  /** "mobile": 44px footer buttons. Otherwise the same card. */
  surface?: "desktop" | "mobile";
}

const initials = (name: string): string =>
  name.split(/[\s&·:,-]+/).filter(Boolean).slice(0, 2).map((w) => [...w][0].toUpperCase()).join("") || "?";

function avatar(name: string, url: string | undefined, cls: string): HTMLElement {
  const box = h("span", { class: cls, "aria-hidden": "true" }, initials(name));
  if (url) {
    const img = h<HTMLImageElement>("img", { src: url, alt: "", decoding: "async", onerror: () => { img.remove(); box.textContent = initials(name); } });
    box.replaceChildren(img);
  }
  return box;
}

/** Links to other sites open in a new tab; your app's pages replace the page (the card may sit in a frame). */
function linkTarget(href: string): Record<string, string> {
  if (/^(mailto|tel):/i.test(href)) return {};
  return /^https?:\/\//i.test(href) ? { target: "_blank", rel: "noopener noreferrer" } : { target: "_top" };
}

/** Read-only: draws the record and reports "displayed", so the agent doesn't wait. */
export function mount({ root, head, data, api, actions, surface = "desktop" }: EntityCardProps): Cleanup {
  ensureStyles(head, "fsk-base", BASE_CSS);
  ensureStyles(head, "fsk-ent", CSS);

  const fields = data.fields.slice(0, 6);
  // No empty half-cells in the grid: a field left alone on its row takes the full row.
  const wide = fields.map((f) => !!f.wide);
  let col = 0;
  fields.forEach((f, i) => {
    if (wide[i]) { if (col === 1) wide[i - 1] = true; col = 0; } else col = (col + 1) % 2;
  });
  if (col === 1) wide[fields.length - 1] = true;

  const cells = fields.map((f, i) => {
    const text = typeof f.value === "number" ? formatValue(f.value, f.format) : f.value;
    const pct = f.meter == null ? null : Math.max(0, Math.min(100, f.meter));
    return h("div", { class: `fsk-ent-f${wide[i] ? " fsk-ent-f--wide" : ""}` },
      h("dt", {}, f.icon && icon(f.icon, 13), f.label),
      h("dd", {},
        h("span", { class: "fsk-num" }, f.href ? h("a", { href: f.href, ...linkTarget(f.href) }, text) : text),
        f.hint && h("span", { class: "fsk-ent-hint" }, f.hint),
        pct != null && h("span", {
          class: `fsk-ent-meter${f.tone ? ` fsk-tone--${f.tone}` : ""}`, role: "meter",
          "aria-label": f.label, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": pct,
        }, h("span", { style: { width: `${pct}%` } }))));
  });

  const links = (data.links ?? []).filter((l) => l.href || actions?.run).slice(0, 2);
  const primaryAt = links.findIndex((l) => l.primary);
  const linkEl = (l: EntityLink, i: number): HTMLElement => {
    const primary = i === primaryAt;
    const style = primary ? "fsk-btn--primary" : primaryAt >= 0 ? "fsk-btn--ghost" : "fsk-btn--link";
    const external = !!l.href && /^https?:\/\//i.test(l.href);
    const kids = [l.icon && icon(l.icon, 14), l.label, !l.icon && style === "fsk-btn--link" && icon(external ? "external" : "chevron", 14)];
    return l.href
      ? h("a", { class: `fsk-btn ${style}`, href: l.href, ...linkTarget(l.href) }, kids)
      : h("button", { class: `fsk-btn ${style}`, type: "button", onclick: () => actions?.run?.(l) }, kids);
  };

  const owner = data.owner;
  const card = h("section", { class: "fsk fsk-card fsk-ent", "data-surface": surface, "aria-label": data.kind ? `${data.kind}: ${data.name}` : data.name },
    h("header", { class: "fsk-ent-head" },
      avatar(data.name, data.avatarUrl, `fsk-ent-av${data.avatarShape === "circle" ? " fsk-ent-av--circle" : ""}`),
      h("div", { class: "fsk-ent-id" },
        data.kind && h("span", { class: "fsk-ent-kind" }, data.kind),
        h("h3", { class: "fsk-ent-name" }, data.name),
        data.subtitle && h("p", { class: "fsk-sub" }, data.subtitle)),
      data.status && h("span", { class: `fsk-ent-pill fsk-tone--${data.status.tone ?? "neutral"}` }, data.status.label)),
    cells.length > 0 && h("dl", { class: "fsk-ent-dl" }, cells),
    (data.tags?.length ?? 0) > 0 && h("ul", { class: "fsk-ent-tags", "aria-label": "Tags" }, data.tags!.map((t) => h("li", {}, t))),
    (owner || links.length > 0) && h("footer", { class: "fsk-ent-foot" },
      owner && h("div", { class: "fsk-ent-owner" },
        avatar(owner.name, owner.avatarUrl, "fsk-ent-av fsk-ent-av--sm fsk-ent-av--circle"),
        h("div", {},
          h("span", { class: "fsk-ent-owner-name" }, owner.name),
          owner.role && h("span", { class: "fsk-ent-owner-role" }, owner.role))),
      links.length > 0 && h("div", { class: "fsk-ent-acts" }, links.map(linkEl))));

  root.replaceChildren(card);
  api?.displayed?.(); // read-only: shown, the agent doesn't wait
  return () => root.replaceChildren();
}

/** The states this card draws besides its data. */
export const states: StateKind[] = ["loading", "empty", "error"];

export interface EntityCardStateProps extends StateProps {
  /** The header icon for empty and error. Default: building. */
  icon?: IconName;
  /** The avatar's shape while loading, as in the data. Default: square. */
  avatarShape?: "square" | "circle";
}

const SK_LABEL = [38, 30, 44, 34, 48, 40];
const SK_VALUE = [62, 54, 70, 58, 46, 66];

/** Bones in the card's own shape: avatar and name (or the name, when you know it), the two-column field grid, the owner footer. */
function skeleton(title: string | undefined, subtitle: string | undefined, shape: "square" | "circle"): HTMLElement[] {
  return [
    h("div", { class: "fsk-ent-head" },
      bone("44px", "44px", { cls: shape === "circle" ? "fsk-bone--round" : "fsk-bone--box" }),
      title
        ? h("div", { class: "fsk-ent-id" }, subtitle && h("span", { class: "fsk-ent-kind" }, subtitle), h("p", { class: "fsk-ent-name" }, title))
        : h("div", { class: "fsk-ent-id fsk-ent-sk-id" }, bone("22%", "8px"), bone("58%", "16px")),
      bone("88px", "20px", { cls: "fsk-ent-sk-pill" })),
    h("div", { class: "fsk-ent-dl" }, SK_LABEL.map((w, i) =>
      h("div", { class: "fsk-ent-f fsk-ent-sk-f" }, bone(`${w}%`, "8px", { i }), bone(`${SK_VALUE[i]}%`, "12px", { i })))),
    h("div", { class: "fsk-ent-foot" },
      h("div", { class: "fsk-ent-owner" },
        bone("28px", "28px", { cls: "fsk-bone--round", i: 6 }),
        h("div", { class: "fsk-ent-sk-owner" }, bone("96px", "9px", { i: 6 }), bone("64px", "8px", { i: 6 }))),
      bone("104px", "28px", { cls: "fsk-bone--box", i: 7 })),
  ];
}

/** Loading (the record's shape in bones), empty (no record found) or error, drawn as this card. Read-only: report displayed() yourself if the agent shouldn't wait. */
export function mountState({ root, head, state, title, subtitle, surface = "desktop", icon: ic = "building", avatarShape = "square" }: EntityCardStateProps): Cleanup {
  ensureStyles(head, "fsk-base", BASE_CSS);
  ensureStyles(head, "fsk-ent", CSS);
  const card = stateCard({ state, cls: "fsk-ent", icon: ic, title, subtitle, surface, skeleton: () => skeleton(title, subtitle, avatarShape) });
  root.replaceChildren(card.el);
  return () => { card.dispose(); root.replaceChildren(); };
}

export const fixtures: Record<string, EntityCardData> = {
  default: {
    id: "acc_10482",
    kind: "Account",
    name: "Acme Logistics",
    subtitle: "Freight and logistics · Chicago, IL",
    status: { label: "Active customer", tone: "success" },
    fields: [
      { label: "ARR", value: 184000, format: { style: "currency" }, icon: "dollar", hint: "+18% this year" },
      { label: "Plan", value: "Enterprise", icon: "star", hint: "annual" },
      { label: "Seats", value: "240 of 250", icon: "users", hint: "96% used", meter: 96, tone: "warning" },
      { label: "Renews", value: "Mar 14, 2027", icon: "calendar", hint: "in 108 days" },
      { label: "Health score", value: 82, icon: "shield", hint: "of 100", meter: 82, tone: "success" },
      { label: "Website", value: "acme.example", icon: "globe", href: "https://acme.example" },
    ],
    tags: ["Logistics", "Multi-region", "Priority support"],
    owner: { name: "Dana Ortiz", role: "Account owner" },
    links: [{ id: "open", label: "Open account" }],
  },
  contact: {
    id: "con_2291",
    kind: "Contact",
    name: "Priya Raman",
    subtitle: "VP Operations · Acme Logistics",
    avatarShape: "circle",
    status: { label: "Champion", tone: "info" },
    fields: [
      { label: "Email", value: "priya@acme.example", icon: "mail", href: "mailto:priya@acme.example", wide: true },
      { label: "Phone", value: "+1 312 555 0148", icon: "phone", href: "tel:+13125550148" },
      { label: "Last contact", value: "3 days ago", icon: "clock", hint: "call" },
      { label: "Open deals", value: 2, icon: "briefcase", hint: "$174,000" },
      { label: "Time zone", value: "Central", icon: "globe", hint: "UTC-6" },
    ],
    links: [{ id: "email", label: "Email", icon: "mail" }, { id: "open", label: "Open contact", primary: true }],
  },
};
```

```js title="agent/ui/entity-card.js"
// Template: entity-card. A read-only chat card that shows one record at a glance: what it is, its status and the fields that matter.

export const meta = {
  id: "entity-card",
  title: "Entity card",
  surface: "card",
  kind: "read-only",
  mobile: "same",
  whenToUse: "The user asks about one record (an account, a contact, an order, a project) and the answer is what it is, its status and 4–6 key fields, with a way to open it in your app.",
  whenNotToUse: "Several records (records list or table). The user wants to change the record (form with approval). More than ~6 fields or long text (link to the record, or a canvas).",
};

const CSS = `
.fsk-ent {
  container-type: inline-size;
  background:
    radial-gradient(130% 90px at 0% 0%, color-mix(in srgb, var(--k-primary) 9%, transparent), transparent),
    var(--k-paper);
}
.fsk-ent .fsk-ent-head { display: flex; align-items: flex-start; gap: 8px 12px; margin-bottom: 14px; }
.fsk-ent .fsk-ent-id { flex: 1 1 0; min-width: 0; padding-top: 1px; }
.fsk-ent .fsk-ent-kind { display: block; margin-bottom: 1px; font-size: .72em; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--k-text-2); }
.fsk-ent .fsk-ent-name { margin: 0; font-size: 1.2em; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; overflow-wrap: anywhere; }
.fsk-ent .fsk-ent-av {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; overflow: hidden;
  border-radius: var(--k-r-md); font-weight: 650; letter-spacing: .02em; line-height: 1;
  color: color-mix(in srgb, var(--k-primary) 78%, var(--k-text));
  background: linear-gradient(145deg, color-mix(in srgb, var(--k-primary) 20%, var(--k-paper)), color-mix(in srgb, var(--k-primary) 7%, var(--k-paper)));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--k-primary) 16%, transparent);
}
.fsk-ent .fsk-ent-av--circle { border-radius: 50%; }
.fsk-ent .fsk-ent-av--sm { width: 28px; height: 28px; font-size: .72em; }
.fsk-ent .fsk-ent-av img { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--k-paper); }

.fsk-ent .fsk-ent-pill {
  --t: var(--k-text-2);
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; margin-top: 2px;
  border-radius: calc(var(--k-r) * 100); font-size: .79em; font-weight: 550; line-height: 1.5; white-space: nowrap;
  color: color-mix(in srgb, var(--t) 65%, var(--k-text));
  background: color-mix(in srgb, var(--t) 12%, var(--k-paper));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--t) 22%, transparent);
}
.fsk-ent .fsk-ent-pill::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--t); }
.fsk-ent .fsk-tone--info { --t: var(--k-primary); }
.fsk-ent .fsk-tone--success { --t: var(--k-success); }
.fsk-ent .fsk-tone--warning { --t: var(--k-warning); }
.fsk-ent .fsk-tone--error { --t: var(--k-error); }

/* Key fields: a hairline grid, two columns. */
.fsk-ent .fsk-ent-dl {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 0; overflow: hidden;
  background: var(--k-divider); border: 1px solid var(--k-divider); border-radius: var(--k-r-md);
}
.fsk-ent .fsk-ent-f { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 10px 12px; background: var(--k-paper); }
.fsk-ent .fsk-ent-f--wide { grid-column: 1 / -1; }
.fsk-ent dt { display: flex; align-items: center; gap: 5px; font-size: .79em; color: var(--k-text-2); }
.fsk-ent dd { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.fsk-ent .fsk-ent-hint { font-size: .79em; font-weight: 400; color: var(--k-text-2); }
.fsk-ent dd a {
  color: inherit; border-radius: 2px; text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, var(--k-text-2) 50%, transparent); transition: text-decoration-color .15s;
}
.fsk-ent dd a:hover { text-decoration-color: currentColor; }
.fsk-ent .fsk-ent-meter { --t: var(--k-primary); flex-basis: 100%; height: 4px; margin-top: 5px; overflow: hidden; border-radius: calc(var(--k-r) * 100); background: var(--k-hover); }
.fsk-ent .fsk-ent-meter > span { display: block; height: 100%; border-radius: inherit; background: var(--t); transform-origin: left; animation: fsk-ent-grow .8s var(--k-ease) .15s both; }
@keyframes fsk-ent-grow { from { transform: scaleX(0); } }

.fsk-ent .fsk-ent-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }
.fsk-ent .fsk-ent-tags li {
  padding: 1px 8px; border-radius: var(--k-r); font-size: .79em; line-height: 1.6;
  color: color-mix(in srgb, var(--k-text-2) 80%, var(--k-text)); background: var(--k-sunken); border: 1px solid var(--k-muted-border);
}

.fsk-ent .fsk-ent-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 16px -16px -16px; padding: 10px 16px;
  border-top: 1px solid var(--k-divider); background: var(--k-sunken);
  border-radius: 0 0 max(0px, calc(var(--k-r-lg) - 1px)) max(0px, calc(var(--k-r-lg) - 1px));
}
.fsk-ent .fsk-ent-owner { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; font-size: .86em; line-height: 1.3; }
.fsk-ent .fsk-ent-owner > div { min-width: 0; }
.fsk-ent .fsk-ent-owner-name { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsk-ent .fsk-ent-owner-role { display: block; font-size: .93em; color: var(--k-text-2); }
.fsk-ent .fsk-ent-acts { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.fsk-ent .fsk-ent-acts .fsk-btn { min-height: 32px; padding: 0 12px; }
.fsk-ent .fsk-ent-acts .fsk-btn--link { padding: 0 4px; }
.fsk-ent a:focus-visible, .fsk-ent button:focus-visible { outline: 2px solid var(--k-primary); outline-offset: 2px; }

/* Narrow card: the status drops under the name, fields go to one column. */
@container (max-width: 320px) {
  .fsk-ent .fsk-ent-head { flex-wrap: wrap; }
  .fsk-ent .fsk-ent-id { flex-basis: calc(100% - 56px); }
  .fsk-ent .fsk-ent-pill { margin: -2px 0 0 56px; }
}
@container (max-width: 250px) { .fsk-ent .fsk-ent-dl { grid-template-columns: 1fr; } }
.fsk-ent[data-surface="mobile"] .fsk-ent-acts .fsk-btn { min-height: 44px; }

/* Loading: the skeleton draws the card's own header (avatar, name, status), so the kit's header steps aside. */
.fsk-ent.fsk-state--loading > .fsk-head { display: none; }
.fsk-ent .fsk-ent-sk-id { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.fsk-ent .fsk-ent-sk-pill { margin-top: 4px; border-radius: calc(var(--k-r) * 100); }
.fsk-ent .fsk-ent-sk-f { gap: 8px; padding: 12px; }
.fsk-ent .fsk-ent-sk-owner { display: flex; flex-direction: column; gap: 6px; }
@container (max-width: 320px) { .fsk-ent .fsk-ent-sk-pill { display: none; } }
`;

const initials = (name) =>
  name.split(/[\s&·:,-]+/).filter(Boolean).slice(0, 2).map((w) => [...w][0].toUpperCase()).join("") || "?";

function avatar(name, url, cls) {
  const box = h("span", { class: cls, "aria-hidden": "true" }, initials(name));
  if (url) {
    const img = h("img", { src: url, alt: "", decoding: "async", onerror: () => { img.remove(); box.textContent = initials(name); } });
    box.replaceChildren(img);
  }
  return box;
}

/** Links to other sites open in a new tab; your app's pages replace the page (the card may sit in a frame). */
function linkTarget(href) {
  if (/^(mailto|tel):/i.test(href)) return {};
  return /^https?:\/\//i.test(href) ? { target: "_blank", rel: "noopener noreferrer" } : { target: "_top" };
}

/** Read-only: draws the record and reports "displayed", so the agent doesn't wait. */
export function mount({ root, head, data, api, actions, surface = "desktop" }) {
  ensureStyles(head, "fsk-base", BASE_CSS);
  ensureStyles(head, "fsk-ent", CSS);

  const fields = data.fields.slice(0, 6);
  // No empty half-cells in the grid: a field left alone on its row takes the full row.
  const wide = fields.map((f) => !!f.wide);
  let col = 0;
  fields.forEach((f, i) => {
    if (wide[i]) { if (col === 1) wide[i - 1] = true; col = 0; } else col = (col + 1) % 2;
  });
  if (col === 1) wide[fields.length - 1] = true;

  const cells = fields.map((f, i) => {
    const text = typeof f.value === "number" ? formatValue(f.value, f.format) : f.value;
    const pct = f.meter == null ? null : Math.max(0, Math.min(100, f.meter));
    return h("div", { class: `fsk-ent-f${wide[i] ? " fsk-ent-f--wide" : ""}` },
      h("dt", {}, f.icon && icon(f.icon, 13), f.label),
      h("dd", {},
        h("span", { class: "fsk-num" }, f.href ? h("a", { href: f.href, ...linkTarget(f.href) }, text) : text),
        f.hint && h("span", { class: "fsk-ent-hint" }, f.hint),
        pct != null && h("span", {
          class: `fsk-ent-meter${f.tone ? ` fsk-tone--${f.tone}` : ""}`, role: "meter",
          "aria-label": f.label, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": pct,
        }, h("span", { style: { width: `${pct}%` } }))));
  });

  const links = (data.links ?? []).filter((l) => l.href || actions?.run).slice(0, 2);
  const primaryAt = links.findIndex((l) => l.primary);
  const linkEl = (l, i) => {
    const primary = i === primaryAt;
    const style = primary ? "fsk-btn--primary" : primaryAt >= 0 ? "fsk-btn--ghost" : "fsk-btn--link";
    const external = !!l.href && /^https?:\/\//i.test(l.href);
    const kids = [l.icon && icon(l.icon, 14), l.label, !l.icon && style === "fsk-btn--link" && icon(external ? "external" : "chevron", 14)];
    return l.href
      ? h("a", { class: `fsk-btn ${style}`, href: l.href, ...linkTarget(l.href) }, kids)
      : h("button", { class: `fsk-btn ${style}`, type: "button", onclick: () => actions?.run?.(l) }, kids);
  };

  const owner = data.owner;
  const card = h("section", { class: "fsk fsk-card fsk-ent", "data-surface": surface, "aria-label": data.kind ? `${data.kind}: ${data.name}` : data.name },
    h("header", { class: "fsk-ent-head" },
      avatar(data.name, data.avatarUrl, `fsk-ent-av${data.avatarShape === "circle" ? " fsk-ent-av--circle" : ""}`),
      h("div", { class: "fsk-ent-id" },
        data.kind && h("span", { class: "fsk-ent-kind" }, data.kind),
        h("h3", { class: "fsk-ent-name" }, data.name),
        data.subtitle && h("p", { class: "fsk-sub" }, data.subtitle)),
      data.status && h("span", { class: `fsk-ent-pill fsk-tone--${data.status.tone ?? "neutral"}` }, data.status.label)),
    cells.length > 0 && h("dl", { class: "fsk-ent-dl" }, cells),
    (data.tags?.length ?? 0) > 0 && h("ul", { class: "fsk-ent-tags", "aria-label": "Tags" }, data.tags.map((t) => h("li", {}, t))),
    (owner || links.length > 0) && h("footer", { class: "fsk-ent-foot" },
      owner && h("div", { class: "fsk-ent-owner" },
        avatar(owner.name, owner.avatarUrl, "fsk-ent-av fsk-ent-av--sm fsk-ent-av--circle"),
        h("div", {},
          h("span", { class: "fsk-ent-owner-name" }, owner.name),
          owner.role && h("span", { class: "fsk-ent-owner-role" }, owner.role))),
      links.length > 0 && h("div", { class: "fsk-ent-acts" }, links.map(linkEl))));

  root.replaceChildren(card);
  api?.displayed?.(); // read-only: shown, the agent doesn't wait
  return () => root.replaceChildren();
}

/** The states this card draws besides its data. */
export const states = ["loading", "empty", "error"];

const SK_LABEL = [38, 30, 44, 34, 48, 40];
const SK_VALUE = [62, 54, 70, 58, 46, 66];

/** Bones in the card's own shape: avatar and name (or the name, when you know it), the two-column field grid, the owner footer. */
function skeleton(title, subtitle, shape) {
  return [
    h("div", { class: "fsk-ent-head" },
      bone("44px", "44px", { cls: shape === "circle" ? "fsk-bone--round" : "fsk-bone--box" }),
      title
        ? h("div", { class: "fsk-ent-id" }, subtitle && h("span", { class: "fsk-ent-kind" }, subtitle), h("p", { class: "fsk-ent-name" }, title))
        : h("div", { class: "fsk-ent-id fsk-ent-sk-id" }, bone("22%", "8px"), bone("58%", "16px")),
      bone("88px", "20px", { cls: "fsk-ent-sk-pill" })),
    h("div", { class: "fsk-ent-dl" }, SK_LABEL.map((w, i) =>
      h("div", { class: "fsk-ent-f fsk-ent-sk-f" }, bone(`${w}%`, "8px", { i }), bone(`${SK_VALUE[i]}%`, "12px", { i })))),
    h("div", { class: "fsk-ent-foot" },
      h("div", { class: "fsk-ent-owner" },
        bone("28px", "28px", { cls: "fsk-bone--round", i: 6 }),
        h("div", { class: "fsk-ent-sk-owner" }, bone("96px", "9px", { i: 6 }), bone("64px", "8px", { i: 6 }))),
      bone("104px", "28px", { cls: "fsk-bone--box", i: 7 })),
  ];
}

/** Loading (the record's shape in bones), empty (no record found) or error, drawn as this card. Read-only: report displayed() yourself if the agent shouldn't wait. */
export function mountState({ root, head, state, title, subtitle, surface = "desktop", icon: ic = "building", avatarShape = "square" }) {
  ensureStyles(head, "fsk-base", BASE_CSS);
  ensureStyles(head, "fsk-ent", CSS);
  const card = stateCard({ state, cls: "fsk-ent", icon: ic, title, subtitle, surface, skeleton: () => skeleton(title, subtitle, avatarShape) });
  root.replaceChildren(card.el);
  return () => { card.dispose(); root.replaceChildren(); };
}

export const fixtures = {
  default: {
    id: "acc_10482",
    kind: "Account",
    name: "Acme Logistics",
    subtitle: "Freight and logistics · Chicago, IL",
    status: { label: "Active customer", tone: "success" },
    fields: [
      { label: "ARR", value: 184000, format: { style: "currency" }, icon: "dollar", hint: "+18% this year" },
      { label: "Plan", value: "Enterprise", icon: "star", hint: "annual" },
      { label: "Seats", value: "240 of 250", icon: "users", hint: "96% used", meter: 96, tone: "warning" },
      { label: "Renews", value: "Mar 14, 2027", icon: "calendar", hint: "in 108 days" },
      { label: "Health score", value: 82, icon: "shield", hint: "of 100", meter: 82, tone: "success" },
      { label: "Website", value: "acme.example", icon: "globe", href: "https://acme.example" },
    ],
    tags: ["Logistics", "Multi-region", "Priority support"],
    owner: { name: "Dana Ortiz", role: "Account owner" },
    links: [{ id: "open", label: "Open account" }],
  },
  contact: {
    id: "con_2291",
    kind: "Contact",
    name: "Priya Raman",
    subtitle: "VP Operations · Acme Logistics",
    avatarShape: "circle",
    status: { label: "Champion", tone: "info" },
    fields: [
      { label: "Email", value: "priya@acme.example", icon: "mail", href: "mailto:priya@acme.example", wide: true },
      { label: "Phone", value: "+1 312 555 0148", icon: "phone", href: "tel:+13125550148" },
      { label: "Last contact", value: "3 days ago", icon: "clock", hint: "call" },
      { label: "Open deals", value: 2, icon: "briefcase", hint: "$174,000" },
      { label: "Time zone", value: "Central", icon: "globe", hint: "UTC-6" },
    ],
    links: [{ id: "email", label: "Email", icon: "mail" }, { id: "open", label: "Open contact", primary: true }],
  },
};
```

### fs-kit (shared by every template)

TypeScript: /ui-catalog/files/ts/fs-kit.ts, JavaScript: /ui-catalog/files/js/fs-kit.js
