## Fix release: auth images + QR camera

**Why the camera did nothing:** the site's Content-Security-Policy (`script-src 'self'`) blocks inline `<script>` blocks, and the scanner was an inline script. (It also had an unescaped apostrophe in `customer's`, a second JavaScript error.) The same CSP (`img-src`) blocked the Unsplash backgrounds, and the image panel was hidden on phones.

- **QR scanner rewritten** (`public/assets/js/qr-scan.js`, external file): works under the CSP; native `BarcodeDetector` when available, otherwise the bundled **jsQR 1.4.0** (`assets/vendor/jsqr/`, Apache-2.0) so it also works on Firefox, iOS Safari and desktop Chrome on Windows/Linux. Adds clear permission/HTTPS/busy-camera messages, switch-camera, torch (light) toggle, a scan-line animation, "Scan a photo of the QR" fallback (works even without HTTPS) and automatic camera shut-off when the tab is hidden.
- **Login / register backgrounds:** a bundled SVG illustration is always visible (never a broken image, works offline) and online photos from `config/auth_images.php` fade in only if they load, rotating every 7 s with a gentle zoom. Only the lower, text area is darkened, so the picture stays crisp. Respects reduced-motion and data-saver. Shown as a banner on phones too.
- **CSP:** `img-src` now also allows `images.unsplash.com` and `images.pexels.com`. Nothing else was loosened (scripts and styles remain `'self'` only).
- **Chat:** the "scroll to latest message" inline script (also blocked by the CSP) moved into `app.js`.
- **Service worker v2:** old cache dropped; static files now stale-while-revalidate so future fixes reach installed PWAs.

## UI/UX enhancement — service discovery and provider QR scanning

- Added a provider QR scan screen with camera scanning via browser BarcodeDetector and manual token/link fallback. Provider scan routes into the existing server-side token ownership/status verification.
- Added a customer-facing `/services` discovery page with text/location search, service image cards sourced from service_images, pricing, provider name and booking/profile link.
- Added customer/guest navigation links and a provider navigation link to QR scan.
- Applied BizMtaani emerald/forest/cream CSS design tokens, service marketplace card styling, responsive layout, subtle interactions and reduced-motion support.
- No external JS scanning library or font download was added; camera scanning requires HTTPS or localhost and a browser with BarcodeDetector support.

# Changelog

## 0.3.0 (Phase 3: search and location)
- Migration `003_search.sql`: `geocode_cache`, `businesses.hide_exact_location`, search indexes.
- `/search`: keyword search with Kenyan synonyms (whole-phrase and per-word), category (with subcategories), county, typed place, distance (1-50 km), price range, open-now (from listed hours, Africa/Nairobi), sorting (best match / nearest / lowest price / newest), pagination. Only approved + published + active-owner businesses are searchable.
- Optional "Use my location": coordinates are rounded to ~110 m in the browser and server, never stored, never shown to providers. Denial or no support never blocks anything; typed-place search works with no map service.
- `GeocodeService`: Nominatim-compatible, cached (30 days found / 1 day not found), per-IP limited, >=1 s spacing, results outside Kenya rejected, failures never fatal.
- Leaflet 1.9.4 vendored locally (no CDN): results map, business-page map, provider location picker (click, drag, place search, current location). Providers can show only an approximate (~1 km) area.
- Landing page: working search, categories with real counts, recently added businesses (hidden when none).
- CSP updated to allow OpenStreetMap tiles only. Popups built with textContent (no HTML injection).

## 0.2.0 (Phase 2: business profiles and verification)
- Migration `002_providers.sql`: businesses, hours, photos, provider documents, verification events, category synonyms, services, service images; 48 Kenyan synonyms seeded (kinyozi, chomelea, fundi wa maji, mama mboga ...).
- Provider area: business profile (47 counties), opening hours, up to 4 premises photos, services (KES price or price on request, duration, delivery and booking mode, up to 3 photos each, limit from Settings), ID/permit upload, completeness checklist, submit for verification, show/hide listing.
- Verification state machine (`VerificationService`): draft/submitted/pending_review/more_info_required/approved/rejected/suspended/deactivated; every change stored with actor, time and reason, audited, with email + in-app notification.
- Admin: provider review queue and detail page, decisions, document viewing (permission-checked and audited), category and synonym management; new permission `categories.manage`.
- Public business page `/business/{slug}` (approved + published + active owner only). Contact details hidden unless the provider opts in.
- `CategoryService::resolve()` for Phase 3 search (case, spacing, punctuation, repeated letters, parent->children).
- Uploads: real MIME check, GD re-encode to random JPEG names (strips EXIF/GPS and hidden payloads), size/pixel limits; documents in `storage/private_uploads` served only through an authorised controller; uploads folder allows only `<24 hex>.jpg`.
- Retention: documents of applications rejected longer than N days (setting, default 90) are purged by `cron/run.php`.
- Oversized uploads return a clear 413 message instead of a misleading CSRF error.

## 0.1.0 (Phase 1: foundation)
## 0.1.0 (Phase 1: foundation)
- Front controller, router, middleware (guest/auth/role/staff/admin/perm), CSRF, sessions, PDO layer.
- Accounts: customer and provider registration, login (rate-limited), logout, email verification, password reset, account page.
- Employees with granular permissions; admin overview, users, employees, audit log, settings, system pages.
- Email: PHPMailer wrapper (`log` and `smtp` drivers), database outbox with dedupe, retry/backoff, honest statuses; HTML + plain-text templates with escaping.
- In-app notifications. `QrService` wrapping the existing phpqrcode library.
- Migration `001_foundation.sql`, `bin/migrate.php`, `bin/create-admin.php`, `bin/seed-demo.php`, `cron/run.php`.
- phpqrcode patched for PHP 8.1+ (intdiv); rendering via temp file to avoid library `header()` side effects.
- Fixed during testing: CSRF failures now 403 (419 becomes HTTP 500 on Apache); `password_changed_at` is microsecond precision so same-second password changes still invalidate other sessions.


## Phase 4 revised package
- Added product listings with photos, fixed or seller-confirmed prices, units and optional stock tracking.
- Added customer cart and product order lifecycle separate from service bookings.
- Added seller price confirmation for unpriced products, order status history and stock restoration on rejection/cancellation.
- Added branded order receipt emails with item lines, totals, payment disclaimer and embedded QR PNG; booking confirmation email also embeds QR.
- Added provider-side QR redemption for collection or delivery at the appropriate order status.

## Customer dashboard and persistent QR receipts
- Customer dashboard now provides marketplace entry points, recent products and services, plus direct links to orders, bookings and cart.
- Product-order QR tokens and booking QR tokens are persisted with their hashes so customers can reopen the in-platform receipt after logging out or using another session.
- Login and customer registration can return the customer to the business/item page they were viewing.
- Added migration `006_dashboard_qr_persistence.sql`; run `php bin/migrate.php` after updating.


## Phase 5 — Marketplace-wide product discovery
- Added `/products` with keyword search across product and seller details.
- Added category, county, town, estate, minimum/maximum price filters.
- Added best-match, newest, price ascending/descending and name sorting.
- Added server-side pagination and empty-state guidance.
- Linked product discovery from the public homepage and customer dashboard.
- No database migration is required.

## Phase 6 — Booking Chat Inbox
- Added customer My Chats and provider Booking Chats inboxes, one thread per booking.
- Automatically opens chat on provider acceptance and synchronizes older eligible bookings.
- Added private text messaging, unread counts, in-app alerts, reporting and contact-detail filtering.


## Launch-readiness update — 2026-11-03
- Added admin date-range analytics for service bookings and product orders, with separate totals and filters for activity type, status, provider and customer.
- Added inclusive Africa/Nairobi date filtering and clear/reset controls.
- Tightened service lifecycle: QR verification is the normal provider check-in path; direct provider status submission cannot impersonate QR check-in.
- Added service-start timestamp and QR verification event metadata.
- Updated launch documentation and acceptance checks.
- Payment collection, escrow, commissions and payouts remain disabled. Manual verification exceptions, customer completion confirmation and full no-show/dispute workflows remain documented follow-up work and must not be assumed implemented.
