# Order Tracking Page

## Objective

Let customers check where their order is without emailing support.

A per-order status page showing the order's current state and shipment progress, reachable by signed-in customers and by guests with an order number and email.

## 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. Show the order's own state and its shipment progress as two separate things. An order can be paid and confirmed while nothing has shipped, and a delivered parcel does not close an order that has a second parcel outstanding.
2. Give guests a lookup that requires both the order number and the email on the order, and give signed-in customers direct links from their order history. The same page serves both, with the same information.
3. Present carrier progress as a small number of plain states with a timestamp on each, and label the most recent one as current. Do not render the carrier's raw event codes.
4. Reuse the app's existing Status Indicator System for the state treatments and, if orders arrive through Shopify Order Import or WooCommerce Order Sync, read status from those records rather than maintaining a second copy.
5. Do not put the order behind a bare guessable URL. Order numbers are sequential in most systems, so the page must require the second factor and must not confirm that a number exists when the email does not match.

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

- A guest lookup must prove the requester knows both the order number and the email on the order, and must return the same response for a wrong email and a nonexistent order so the form cannot be used to discover which orders exist.
- An order can ship in parts. Show each parcel as its own tracked leg with its own items and its own progress, rather than collapsing them into one misleading status.
- Carrier feeds go stale, skip states, and occasionally move backwards. Show the last successful update time, never move a shipment backwards in the displayed timeline, and say the tracking has not updated recently rather than implying the parcel is stuck.
- Lookups must be rate limited per address and per order number so the form cannot be used to enumerate orders. Reuse the app's existing Rate Limiting rather than adding a counter here.
- Cancelled, refunded, and returned orders need their own copy and their own end state. A refunded order showing a delivery estimate reads as a system that has lost track of itself.
- The page must be safe to forward. Assume the link and its contents end up in a shared inbox, and keep full payment details and any unrelated customer data off it.
- An order placed minutes ago has no tracking at all. Say that fulfilment has not started yet rather than showing an empty timeline.
- Timestamps must render in the customer's time zone and locale, and delivery estimates should be a date range rather than a false-precision time.

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

- [ ] A guest can find their order with the order number and matching email, and cannot with a mismatched one.
- [ ] Wrong-email and nonexistent-order lookups are indistinguishable in response and timing.
- [ ] Lookups are rate limited through the app's existing limiter.
- [ ] Split shipments appear as separate legs with their own items and progress.
- [ ] Stale carrier data is labelled with a last-updated time and never rewinds the timeline.
- [ ] Cancelled, refunded, and returned orders show state-appropriate copy and no delivery estimate.
- [ ] Order status is read from the app's existing order records rather than a duplicate store.
- [ ] 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.
