# Weather Widget

## Objective

Show current conditions and a short forecast for a place your users care about.

A compact widget showing current conditions and a few days of forecast for a chosen location.

## 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. Add this as a tile in the app's existing Customizable Dashboard Widgets rather than as a fixed element bolted into a layout, so users who do not want it can remove it.
2. Fetch the forecast on the server on a schedule and serve the widget from the app's own cache. Calling the weather source from every visitor's browser leaks the credential and multiplies the request count by your traffic.
3. Show the observation time alongside the reading, and reuse the app's Stale Data Indicator conventions so ageing weather looks the same as any other ageing data in the product.
4. Reserve the widget's dimensions and render the layout with placeholder values before the data lands, so the dashboard does not reflow when a slow forecast arrives.
5. Do not present the forecast as more precise than it is. Round to whole units, keep the forecast short, and do not build hourly detail, radar, or alerts unless someone has actually asked for them.

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

- When the weather source is unreachable, keep showing the last successful reading with its timestamp and a quiet note that it could not be refreshed. Blanking the widget or showing an error is worse than slightly old weather.
- Temperature units are a strong regional habit and getting them wrong reads as broken. Follow the viewer's stored unit preference, fall back to their locale, and let them change it from the widget itself.
- One popular page can turn into thousands of requests a minute against the upstream source. Cache by location with a sensible minimum interval and coalesce concurrent lookups for the same place into a single upstream call.
- Some locations have no forecast coverage, and some resolve ambiguously to several places with the same name. Say that no forecast is available for the place rather than rendering empty fields, and disambiguate at the point the location is chosen.
- Weather without a timestamp looks current forever. Show when the observation was taken in the viewer's own time zone, and make an unusually old reading visually distinct rather than merely labelled.
- Weather icons and condition codes are meaningless to a screen reader. Give every condition a text label, and never convey severity by colour alone.
- A location chosen from a user's profile may be missing or set to something unresolvable. Fall back to a configured default location rather than showing a broken widget or an empty state with no explanation.

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

- [ ] The widget shows current conditions and a short forecast for the chosen location.
- [ ] Forecast data is fetched server-side and served from cache; no upstream credential reaches the browser.
- [ ] An unavailable source keeps the last reading visible with its timestamp instead of blanking.
- [ ] Units follow the viewer's preference and can be changed from the widget.
- [ ] Observation time renders in the viewer's time zone and old data is visibly marked.
- [ ] Locations without coverage produce a clear message rather than empty fields.
- [ ] The widget occupies its final dimensions before data arrives.
- [ ] 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.
