# Date Range Picker

## Objective

Let users pick a valid date window without guessing which end comes first.

A range picker with typed entry, clear boundary semantics, and no timezone drift between what was picked and what was stored.

## 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. Support both calendar clicking and typed entry. Keyboard users should never be forced through a grid to enter two dates they already know.
2. Decide and document whether the range is inclusive or exclusive at each end, and make the summary text say it in words.
3. Handle reversed selection gracefully: picking the later date first should swap the endpoints, not reject the input.
4. Treat a calendar date as a calendar date. Store and compare it without a time component, or you will ship the off-by-one-day bug where a user in UTC-8 picks the 1st and the server records the 31st.
5. Do NOT reimplement locale formatting by hand. Use the platform's locale data for month names, date order, and first day of the week.

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

- First day of week and date order differ by locale — read them from the locale, do not hardcode Sunday or MM/DD.
- Disabled dates inside a range must be enforced, not just greyed out.
- Minimum and maximum span limits must be explained when they block a selection.
- Open-ended ranges need explicit support and a clear label, not a blank endpoint.
- On mobile the calendar must fit without horizontal scroll and should not fight the native keyboard during typed entry.
- Presets like 'last 30 days' must state their boundary rule — whether today counts.

## 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 range can be entered fully by keyboard and fully by pointer.
- [ ] Inclusive or exclusive boundaries are documented and reflected in the displayed summary.
- [ ] Selecting the end before the start produces a valid range.
- [ ] The stored range matches the dates the user saw, in every time zone.
- [ ] Locale determines date format and first day of week.
- [ ] Disabled dates and span limits are enforced with an explanation.
- [ ] 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.
