# Admin Control Center & Hardening Design

## Goal
Improve the existing BD News admin panel without breaking existing APIs, Feed Hub, YouTube Live Monitor, cron jobs, or database schema.

## Scope
1. Reorganize the 24-link sidebar into collapsible groups while preserving every existing admin page URL.
2. Upgrade the dashboard into a command center with Live, Feed Hub, source-problem and cron-health summaries plus quick actions.
3. Add lightweight operational health helpers that fail safely when optional MySQL-backed modules are unavailable.
4. Harden admin authentication: secure session cookie defaults, session ID regeneration after login, CSRF protection for admin POST actions, and basic login throttling.
5. Allow production secrets to come from environment variables while preserving current constants as compatibility fallbacks.

## Compatibility
- PHP 8.1+.
- No framework or new Composer dependency.
- Existing Android API endpoints and response formats remain unchanged.
- Existing admin URLs remain unchanged.
- Existing MySQL tables are not modified in this batch.
- Existing JSON-backed content flows remain functional.

## Admin Navigation
Groups: Overview; Content; Video & Live; Distribution; Monetization; Monitoring; System. The group containing the current page starts expanded. A mobile menu button exposes the sidebar on narrow screens.

## Dashboard
Add status cards for Live Now, Upcoming Live, Feed Hub sources, and source issues. Show cron freshness badges based on log-file modification time. Add high-value quick actions to Breaking News, Live Monitor, Feed Sources, Notifications, and Settings.

## Security
- Set secure/httponly/SameSite=Lax session cookies and strict session mode before session start.
- Regenerate the session ID on successful login.
- Generate a session CSRF token and validate every authenticated admin POST request.
- Admin header automatically injects the CSRF token into POST forms; login form includes it explicitly.
- Throttle repeated login failures by IP+username using small files under `data/login_attempts/`.
- Read DB/API/admin settings from environment variables when available. Use a stable bcrypt fallback hash instead of calling `password_hash()` on every request.

## Error Handling
Optional dashboard modules are wrapped in `try/catch`; a Feed/Live database problem must not take down the dashboard. Security failures return HTTP 419 for CSRF and a friendly login error for throttling.

## Verification
Static PHP helper tests will cover CSRF, session/login helper behavior, stable admin hash configuration, and navigation grouping. Run `php -l` across all PHP files and `unzip -t` on the final package.
