# Free Trial Lifecycle

## Objective

Give temporary access and make the end of the trial predictable.

The full trial state machine: starting, entitlement, expiry, conversion, cancellation, and what happens to the data afterwards.

## 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. Model the trial as explicit states — active, expiring, expired, converted, cancelled, payment failed — and record every transition with a timestamp. Trials inferred from a date field alone become unanswerable support tickets.
2. Decide and document whether a card is required to start. Card-up-front converts higher and reduces abuse; card-free trials fill the funnel. Both are valid; ambiguity is not.
3. Grant entitlements through the app's existing plan and permission model, so the trial account behaves exactly like a paid one.
4. On expiry, downgrade entitlements without destroying anything the user created during the trial. Make the data read-only or locked behind an upgrade, and say so.
5. Do NOT implement admin-granted date changes here — that is owned by Trial Extension. Do NOT implement retry schedules or recovery emails for failed payments; that is owned by Failed Payment Recovery.

## 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

- Expiry and failed payment are different states with different copy. Telling a paying customer their trial ended because their card was declined loses the customer.
- Repeat trials via a fresh email are trivially easy. Limit by payment fingerprint or account domain, and make sure a legitimate second team at the same company can still start one.
- A trial that expires while the user is mid-session must degrade at the next action, not blank the current screen without explanation.
- Over-limit usage after downgrade needs a rule: block new work but keep existing work visible. Deleting the eleventh project because the free plan allows ten is unacceptable.
- Converting mid-trial must not charge for the remaining trial days twice, and must not silently forfeit them either. State which.
- Trial end must be computed in a stated time zone. A trial ending 'on the 30th' ends at different moments for different users otherwise.
- If the billing provider and the app disagree about trial state, the provider wins for money and the app wins for access. Reconcile on webhook, do not guess.

## 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

- [ ] Trial state is explicit and every transition is recorded with a timestamp.
- [ ] Whether a card is required is a documented, enforced decision.
- [ ] Expiry, conversion, cancellation, and failed payment are distinct states with distinct messaging.
- [ ] Downgrade removes entitlements without deleting trial-created data.
- [ ] Repeat-trial abuse is limited without blocking legitimate second accounts.
- [ ] Trial end times are computed in a stated time zone.
- [ ] App and billing-provider state are reconciled from webhooks, not inferred.
- [ ] 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.
