# Intelligent UI coverage

A code-backed map of the conversational UI expected by a modern AI chat across Classic and AI Mode.

## Key rules

- AI Mode: use OpenAI Apps UI guidelines as a checklist; code assigns the grade.
- AI Mode: distinguish waiting, streaming, error, retry and done.
- Classic: reuse existing components and pattern pages; do not duplicate chat UI.
- Classic: use Target for an unowned capability, not for documentation.

## Where tokens live

| Surface | File | Scope root | Theme switch |
| --- | --- | --- | --- |
| Classic | Lazy panel manager | Storefront widget owner | No coverage-specific theme switch |
| AI Mode | Conversation view | `streaming` and retry state | No coverage-specific theme switch |

## How to apply

| Surface | API / class | Example |
| --- | --- | --- |
| Classic | Existing guide pages | Product and answer states are linked from the coverage map |
| AI Mode | Conversation state | `streaming`, retry and suggested-question branches |

### Capability coverage

Ma trận đối chiếu capability giữa Classic và AI Mode, không phải tỷ lệ hoàn thiện của tài liệu guide. Mỗi ô dẫn tới đúng dòng Element map cùng capability và surface.

Example — Trạng thái và số đếm lấy từ bảng Element map của trang này.

```jsx
import React, {useEffect, useState} from 'react';

function coverageModel(rows) {
  const surfaces = ['Classic', 'AI Mode'];
  const grades = ['Has', 'Partial', 'Target'];
  const capabilities = new Map();
  const anchors = new Set();
  const counts = Object.fromEntries(
    surfaces.map(surface => [surface, {Has: 0, Partial: 0, Target: 0}])
  );
  const slug = text =>
    text
      .toLowerCase()
      .replace(/[^a-z0-9]+/g, '-')
      .replace(/^-|-$/g, '');
  for (const {capability, surface, detail} of rows) {
    if (!surfaces.includes(surface)) throw Error('Unknown coverage surface: ' + surface);
    const grade = detail.match(/^(Has|Partial|Target)\b/)?.[1];
    if (!grade || !capability) throw Error('Invalid coverage row: ' + capability);
    if (!capabilities.has(capability)) capabilities.set(capability, {});
    const item = capabilities.get(capability);
    if (item[surface]) throw Error('Duplicate coverage row: ' + capability + ' / ' + surface);
    const anchor = 'capability-' + slug(capability) + '-' + slug(surface);
    if (anchors.has(anchor)) throw Error('Duplicate coverage anchor: ' + anchor);
    anchors.add(anchor);
    item[surface] = {
      capability,
      surface,
      grade,
      detail,
      id: anchor
    };
    counts[surface][grade]++;
  }
  const items = [...capabilities].map(([capability, cells]) => {
    if (surfaces.some(surface => !cells[surface]))
      throw Error('Missing coverage surface: ' + capability);
    return {capability, cells: surfaces.map(surface => cells[surface])};
  });
  if (!items.length) throw Error('Coverage table is empty');
  return {surfaces, grades, items, counts};
}

export function Matrix() {
  const [model, setModel] = useState(null);
  const [error, setError] = useState('');
  const [base, setBase] = useState('/foundations/intelligent-ui-coverage/');
  useEffect(() => {
    const doc = window.parent.document;
    const heading = doc.getElementById('element-map');
    const table = heading?.nextElementSibling?.querySelector('table');
    if (!table) {
      setError('Open the capability table to view this chart.');
      return;
    }
    try {
      const rows = [...table.querySelectorAll('tbody tr')];
      const data = rows.map(row => ({
        capability: row.cells[0]?.textContent.trim(),
        surface: row.cells[1]?.textContent.trim(),
        detail: row.cells[2]?.textContent.trim()
      }));
      const result = coverageModel(data);
      for (const item of result.items)
        for (const cell of item.cells) {
          const row =
            rows[
              data.findIndex(
                value => value.capability === cell.capability && value.surface === cell.surface
              )
            ];
          row.id = cell.id;
          row.tabIndex = -1;
          row.style.scrollMarginTop = '120px';
          row.dataset.coverageCapability = cell.capability;
          row.dataset.coverageSurface = cell.surface;
        }
      setBase(doc.location.pathname + doc.location.search);
      setModel(result);
      const target = doc.location.hash.slice(1);
      if (target.startsWith('capability-'))
        doc.getElementById(target)?.scrollIntoView({block: 'center'});
    } catch (failure) {
      setError(failure.message);
    }
  }, []);
  if (error)
    return (
      <p role="alert">
        {error}{' '}
        <a href="/foundations/intelligent-ui-coverage/#element-map" target="_parent">
          Open capability table
        </a>
      </p>
    );
  if (!model) return <p role="status">Loading coverage…</p>;
  return (
    <figure className="capability-matrix" aria-label="AI chat capability coverage">
      <style>{`
      .capability-matrix{margin:0;color:var(--vib-1,#202223);font-size:14px;line-height:1.5}
      .capability-matrix *{box-sizing:border-box;min-width:0}
      .capability-matrix .counts{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:24px}
      .capability-matrix .counts strong{display:block;font-size:16px;margin-bottom:8px}
      .capability-matrix .bar{display:flex;gap:2px;height:14px;margin-top:10px;border-radius:3px;overflow:hidden}
      .capability-matrix .Has{background:#d9f0e1;color:#14532d}.capability-matrix .Partial{background:#f8e7b7;color:#634400}.capability-matrix .Target{background:#e8e9ed;color:#383b45}
      .capability-matrix table{border-collapse:collapse;width:100%;table-layout:fixed;background:var(--bg-deep,#fff)}
      .capability-matrix th,.capability-matrix td{border-bottom:1px solid #95959d;padding:10px 6px;text-align:left;vertical-align:middle;font-weight:400;overflow-wrap:break-word}
      .capability-matrix thead th{font-weight:600}.capability-matrix th:first-child{width:46%}
      .capability-matrix a{display:flex;min-height:44px;align-items:center;justify-content:center;border-radius:6px;text-decoration:underline;text-underline-offset:3px;padding:8px 2px}
      .capability-matrix a:focus-visible{outline:3px solid #786bdb;outline-offset:2px}
      .capability-matrix figcaption{font-size:12px;line-height:1.6;margin-top:14px}
      @media(max-width:520px){.capability-matrix{font-size:13px}.capability-matrix .counts{gap:12px}.capability-matrix th,.capability-matrix td{padding:8px 4px}.capability-matrix th:first-child{width:44%}}
    `}</style>
      <div className="counts">
        {model.surfaces.map(surface => (
          <section key={surface} aria-label={surface + ' counts'}>
            <strong>{surface}</strong>
            <span>
              {model.grades.map(grade => grade + ' ' + model.counts[surface][grade]).join(' · ')} /{' '}
              {model.items.length}
            </span>
            <div className="bar" aria-hidden="true">
              {model.grades.map(grade =>
                model.counts[surface][grade] ? (
                  <span
                    key={grade}
                    className={grade}
                    style={{flex: model.counts[surface][grade]}}
                  />
                ) : null
              )}
            </div>
          </section>
        ))}
      </div>
      <table>
        <caption>Capability × surface</caption>
        <thead>
          <tr>
            <th scope="col">Capability</th>
            {model.surfaces.map(surface => (
              <th scope="col" key={surface}>
                {surface}
              </th>
            ))}
          </tr>
        </thead>
        <tbody>
          {model.items.map(item => (
            <tr key={item.capability}>
              <th scope="row">{item.capability}</th>
              {item.cells.map(cell => (
                <td key={cell.surface}>
                  <a
                    className={cell.grade}
                    data-coverage-cell=""
                    data-capability={cell.capability}
                    data-surface={cell.surface}
                    href={base + '#' + cell.id}
                    target="_parent"
                    title={cell.detail}
                    aria-label={cell.capability + ', ' + cell.surface + ': ' + cell.grade}
                  >
                    {cell.grade}
                  </a>
                </td>
              ))}
            </tr>
          ))}
        </tbody>
      </table>
      <figcaption>
        Has: có owner trong code. Partial: mới có một phần. Target: chưa có owner. Số và trạng thái
        đọc trực tiếp từ Element map; mỗi ô mở đúng dòng bằng chứng bên dưới.
      </figcaption>
    </figure>
  );
}
```

Example — Cùng dữ liệu capability, đối chiếu hai surface và mở từng dòng bằng chứng.

```jsx
import React, {useEffect, useState} from 'react';

function coverageModel(rows) {
  const surfaces = ['Classic', 'AI Mode'];
  const grades = ['Has', 'Partial', 'Target'];
  const capabilities = new Map();
  const anchors = new Set();
  const counts = Object.fromEntries(
    surfaces.map(surface => [surface, {Has: 0, Partial: 0, Target: 0}])
  );
  const slug = text =>
    text
      .toLowerCase()
      .replace(/[^a-z0-9]+/g, '-')
      .replace(/^-|-$/g, '');
  for (const {capability, surface, detail} of rows) {
    if (!surfaces.includes(surface)) throw Error('Unknown coverage surface: ' + surface);
    const grade = detail.match(/^(Has|Partial|Target)\b/)?.[1];
    if (!grade || !capability) throw Error('Invalid coverage row: ' + capability);
    if (!capabilities.has(capability)) capabilities.set(capability, {});
    const item = capabilities.get(capability);
    if (item[surface]) throw Error('Duplicate coverage row: ' + capability + ' / ' + surface);
    const anchor = 'capability-' + slug(capability) + '-' + slug(surface);
    if (anchors.has(anchor)) throw Error('Duplicate coverage anchor: ' + anchor);
    anchors.add(anchor);
    item[surface] = {
      capability,
      surface,
      grade,
      detail,
      id: anchor
    };
    counts[surface][grade]++;
  }
  const items = [...capabilities].map(([capability, cells]) => {
    if (surfaces.some(surface => !cells[surface]))
      throw Error('Missing coverage surface: ' + capability);
    return {capability, cells: surfaces.map(surface => cells[surface])};
  });
  if (!items.length) throw Error('Coverage table is empty');
  return {surfaces, grades, items, counts};
}

export function Matrix() {
  const [model, setModel] = useState(null);
  const [error, setError] = useState('');
  const [base, setBase] = useState('/foundations/intelligent-ui-coverage/');
  useEffect(() => {
    const doc = window.parent.document;
    const heading = doc.getElementById('element-map');
    const table = heading?.nextElementSibling?.querySelector('table');
    if (!table) {
      setError('Open the capability table to view this chart.');
      return;
    }
    try {
      const rows = [...table.querySelectorAll('tbody tr')];
      const data = rows.map(row => ({
        capability: row.cells[0]?.textContent.trim(),
        surface: row.cells[1]?.textContent.trim(),
        detail: row.cells[2]?.textContent.trim()
      }));
      const result = coverageModel(data);
      for (const item of result.items)
        for (const cell of item.cells) {
          const row =
            rows[
              data.findIndex(
                value => value.capability === cell.capability && value.surface === cell.surface
              )
            ];
          row.id = cell.id;
          row.tabIndex = -1;
          row.style.scrollMarginTop = '120px';
          row.dataset.coverageCapability = cell.capability;
          row.dataset.coverageSurface = cell.surface;
        }
      setBase(doc.location.pathname + doc.location.search);
      setModel(result);
      const target = doc.location.hash.slice(1);
      if (target.startsWith('capability-'))
        doc.getElementById(target)?.scrollIntoView({block: 'center'});
    } catch (failure) {
      setError(failure.message);
    }
  }, []);
  if (error)
    return (
      <p role="alert">
        {error}{' '}
        <a href="/foundations/intelligent-ui-coverage/#element-map" target="_parent">
          Open capability table
        </a>
      </p>
    );
  if (!model) return <p role="status">Loading coverage…</p>;
  return (
    <figure className="capability-matrix" aria-label="AI chat capability coverage">
      <style>{`
      .capability-matrix{margin:0;color:var(--vib-1,#202223);font-size:14px;line-height:1.5}
      .capability-matrix *{box-sizing:border-box;min-width:0}
      .capability-matrix .counts{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:24px}
      .capability-matrix .counts strong{display:block;font-size:16px;margin-bottom:8px}
      .capability-matrix .bar{display:flex;gap:2px;height:14px;margin-top:10px;border-radius:3px;overflow:hidden}
      .capability-matrix .Has{background:#d9f0e1;color:#14532d}.capability-matrix .Partial{background:#f8e7b7;color:#634400}.capability-matrix .Target{background:#e8e9ed;color:#383b45}
      .capability-matrix table{border-collapse:collapse;width:100%;table-layout:fixed;background:var(--bg-deep,#fff)}
      .capability-matrix th,.capability-matrix td{border-bottom:1px solid #95959d;padding:10px 6px;text-align:left;vertical-align:middle;font-weight:400;overflow-wrap:break-word}
      .capability-matrix thead th{font-weight:600}.capability-matrix th:first-child{width:46%}
      .capability-matrix a{display:flex;min-height:44px;align-items:center;justify-content:center;border-radius:6px;text-decoration:underline;text-underline-offset:3px;padding:8px 2px}
      .capability-matrix a:focus-visible{outline:3px solid #786bdb;outline-offset:2px}
      .capability-matrix figcaption{font-size:12px;line-height:1.6;margin-top:14px}
      @media(max-width:520px){.capability-matrix{font-size:13px}.capability-matrix .counts{gap:12px}.capability-matrix th,.capability-matrix td{padding:8px 4px}.capability-matrix th:first-child{width:44%}}
    `}</style>
      <div className="counts">
        {model.surfaces.map(surface => (
          <section key={surface} aria-label={surface + ' counts'}>
            <strong>{surface}</strong>
            <span>
              {model.grades.map(grade => grade + ' ' + model.counts[surface][grade]).join(' · ')} /{' '}
              {model.items.length}
            </span>
            <div className="bar" aria-hidden="true">
              {model.grades.map(grade =>
                model.counts[surface][grade] ? (
                  <span
                    key={grade}
                    className={grade}
                    style={{flex: model.counts[surface][grade]}}
                  />
                ) : null
              )}
            </div>
          </section>
        ))}
      </div>
      <table>
        <caption>Capability × surface</caption>
        <thead>
          <tr>
            <th scope="col">Capability</th>
            {model.surfaces.map(surface => (
              <th scope="col" key={surface}>
                {surface}
              </th>
            ))}
          </tr>
        </thead>
        <tbody>
          {model.items.map(item => (
            <tr key={item.capability}>
              <th scope="row">{item.capability}</th>
              {item.cells.map(cell => (
                <td key={cell.surface}>
                  <a
                    className={cell.grade}
                    data-coverage-cell=""
                    data-capability={cell.capability}
                    data-surface={cell.surface}
                    href={base + '#' + cell.id}
                    target="_parent"
                    title={cell.detail}
                    aria-label={cell.capability + ', ' + cell.surface + ': ' + cell.grade}
                  >
                    {cell.grade}
                  </a>
                </td>
              ))}
            </tr>
          ))}
        </tbody>
      </table>
      <figcaption>
        Has: có owner trong code. Partial: mới có một phần. Target: chưa có owner. Số và trạng thái
        đọc trực tiếp từ Element map; mỗi ô mở đúng dòng bằng chứng bên dưới.
      </figcaption>
    </figure>
  );
}
```

## Element map

| Element | Surface | Role/Token | Light | Dark |
| --- | --- | --- | --- | --- |
| Product card and carousel | Classic | Has — [Product recommendation](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/product-recommendation) | — | — |
| Product card and carousel | AI Mode | Has — [Product card](https://chatty-ui-research.avada-tesla-chatty.workers.dev/components/product-card) | — | — |
| Thinking or reasoning state | Classic | Has — message status rendering | — | — |
| Thinking or reasoning state | AI Mode | Has — [Waiting + streaming](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/waiting-streaming) | — | — |
| Streaming text | Classic | Has — message status rendering | — | — |
| Streaming text | AI Mode | Has — [Waiting + streaming](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/waiting-streaming) | — | — |
| Markdown lists, tables and code | Classic | Has — chat Markdown rendering | — | — |
| Markdown lists, tables and code | AI Mode | Has — [Waiting + streaming](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/waiting-streaming) | — | — |
| Chart | Classic | Target — no shipped chart owner found | — | — |
| Chart | AI Mode | Target — no shipped chart branch | — | — |
| Citations and sources | Classic | Target — no shipped citation owner found | — | — |
| Citations and sources | AI Mode | Has — citations rendered from response metadata | — | — |
| Suggested replies | Classic | Has — [Suggested questions](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/suggested-questions) | — | — |
| Suggested replies | AI Mode | Has — [Suggested questions](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/suggested-questions) | — | — |
| Tool or action states | Classic | Target — no shipped tool-runner state found | — | — |
| Tool or action states | AI Mode | Partial — [Error + retry](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/error-retry) covers recovery, not a general tool runner | — | — |
| Transitions | Classic | Has — [Motion](https://chatty-ui-research.avada-tesla-chatty.workers.dev/foundations/motion) | — | — |
| Transitions | AI Mode | Has — [Motion](https://chatty-ui-research.avada-tesla-chatty.workers.dev/foundations/motion) | — | — |
| Empty, error and retry | Classic | Has — [Error + retry](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/error-retry); loading skeleton while messages load | — | — |
| Empty, error and retry | AI Mode | Has — [Error + retry](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/error-retry) | — | — |
| Human handoff | Classic | Has — [Handoff to a human](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/handoff-to-a-human) | — | — |
| Human handoff | AI Mode | Has — [Handoff to a human](https://chatty-ui-research.avada-tesla-chatty.workers.dev/patterns/handoff-to-a-human) | — | — |
| Voice | Classic | Has — [Voice player](https://chatty-ui-research.avada-tesla-chatty.workers.dev/components/voice-player) | — | — |
| Voice | AI Mode | Has — [Voice player](https://chatty-ui-research.avada-tesla-chatty.workers.dev/components/voice-player) | — | — |
| File or image attachments | Classic | Has — attachment rendering | — | — |
| File or image attachments | AI Mode | Has — attachment store with retryable upload state | — | — |

## Tokens

### Classic

#### Variables

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Panel modules | `ParentWidget` | Lazy module | Same module |

### AI Mode

#### Variables

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Streaming state | `streaming` | Thread state | — |

## Composed values

| Element | Surface | Light | Dark | Fallback |
| --- | --- | --- | --- | --- |
| Conversation response | Classic | Message status, Markdown, retries and attachments | — | Loading skeleton while messages load; Target when no owner is shipped |
| Conversation response | AI Mode | Thread combines streaming, errors and suggestions | — | Explicit Target for unsupported categories |

## Copy-paste export

### Classic

```css
.Avada-Faqs_Popup {
  position: fixed !important;
}
```

### AI Mode

```css
.chatty-ai-mode {
  --dur-2: var(--chatty-motion-duration-200);
}
```

## Contrast matrix

| Surface | Pair | Light ratio | Dark ratio |
| --- | --- | --- | --- |
| Classic | Coverage map | Not a colour pair | Not a colour pair |
| AI Mode | Thread state map | Not a colour pair | Not a colour pair |

## Target

```target
| Surface | Now | Target |
| --- | --- | --- |
| Classic | Charts, citations and tool states have no shipped Classic owners in this map. | Not in code yet — build with the body values. Add each capability only with a public owner, accessible state contract and guide page. |
| AI Mode | Charts have no shipped thread branch. | Not in code yet — build with the body values. Add a chart owner before listing it as Has. |
```


- [OpenAI — UI guidelines](https://developers.openai.com/plugins/concepts/ui-guidelines)
-  tokens($surface)
