# Theme Acceptance Criteria

## Objective

Set the bar every theme has to clear before it ships to anyone.

A release gate for light, dark, branded, and customer-supplied themes, covering contrast, first paint, tokens, and print.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Write the criteria against the theme layer, not against individual screens. The question is whether a set of token values is fit to ship, and the answer should not require walking every page by hand.
2. Require measured contrast for text, icons, borders, focus rings, and disabled content in every interactive state — resting, hover, focus, active, and selected — because a palette that passes at rest often fails on hover.
3. Cover the surfaces that sit outside the component library: chart series and their gridlines, map and image overlays, embedded documents, illustrations, and any asset shipped as a fixed-colour file that will not follow the theme.
4. State what the first paint must look like. The stored theme has to be resolved before anything renders, and a flash of the wrong theme is a failure of the gate, not a cosmetic quibble.
5. Do not duplicate the per-component bar set by Component Acceptance Criteria. That document owns whether a component behaves correctly; this one owns whether a set of theme values is safe to apply across every component at once.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Contrast must be checked in each interactive state and against each surface a component can sit on — a token that passes on the page background can fail on a card, a modal, or a coloured banner.
- Charts, overlays, and shipped image assets are the usual escapees: a chart series palette tuned for a light background turns unreadable on dark, and a logo baked as a dark PNG disappears entirely.
- First paint has to be tested with an empty cache and a slow connection, since a theme flash is invisible on a warm local reload and glaring for a real user.
- A customer-supplied or branded theme can arrive with missing tokens, malformed values, or a brand colour that fails contrast — validate it on entry, refuse or correct what is unusable, and never let a partial token set render as a half-applied theme.
- Print and forced-colours mode both override the theme in ways the app does not control, so each needs its own line: print on white regardless of the active theme, and forced colours without relying on colour alone to convey state.
- A theme change while the app is open must repaint everything, including portals, toasts, and any component holding a colour it resolved once at mount.
- The theme that follows the operating system preference must still honour an explicit user override, and the gate should check that the override wins.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Every theme is checked against the gate before release, including customer-supplied ones.
- [ ] Contrast is measured for text, icons, borders, and focus rings in every interactive state and on every surface.
- [ ] Charts, overlays, and fixed-colour assets are covered by explicit criteria rather than assumed to follow the theme.
- [ ] First paint on a cold cache shows the correct theme with no flash.
- [ ] Custom token sets are validated on entry and a partial set is refused rather than half-applied.
- [ ] Print output and forced-colours mode each have their own stated pass conditions.
- [ ] Per-component behaviour is left to Component Acceptance Criteria and not restated here.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
