You are a Senior Full Stack Engineer.

Project:
Training Management System (TMS)

Current status:
Sprint 5 has been completed and approved.

Before starting Sprint 6, perform a stabilization and technical debt review.

Important constraints:

- Do NOT change folder structure.
- Do NOT migrate ORM.
- Do NOT rename tables.
- Do NOT rename columns.
- Do NOT break existing routes.
- Reuse existing Auth.js.
- Reuse existing Drizzle ORM.
- Reuse existing UI components.
- Maintain Thai UI localization.

Current goal:
Prepare the system for Sprint 6 by fixing architecture gaps, validation gaps, and consistency issues discovered during Sprint 4 and Sprint 5.

Part 1: Dashboard Consistency Review

Requirements:

1. Verify dashboard calculations.

2. Ensure dashboard uses only APPROVED training records.

3. Verify:

- Total Hours
- Knowledge Hours
- Skill Hours
- Attitude Hours

4. Ensure policy values are loaded from Training Policy.

5. Remove any remaining hardcoded:

- 30 hours
- 12 hours
- 6 hours

6. Create a report listing all hardcoded training targets still found.

Part 2: Authorization Review

Requirements:

1. Review all routes under /dashboard.

2. Verify HRD-only pages:

- /dashboard/pending-review
- /dashboard/training-policy
- /dashboard/import-employees
- /dashboard/master-review

3. Verify Employee cannot access HRD routes.

4. Verify direct URL access is blocked.

5. Verify API routes have server-side authorization.

6. Create authorization review summary.

Part 3: Localization Consistency Review

Requirements:

1. Scan all TMS pages.

2. Find remaining English UI text.

3. Verify:

- Sidebar
- Form Labels
- Buttons
- Table Headers
- Toast Messages
- Validation Messages
- Empty States
- Loading States
- Error States

4. Replace remaining English user-facing text with Thai.

5. Keep internal enums and database values in English.

Part 4: Employee Import Hardening

Requirements:

1. Verify duplicate employee handling.

2. Verify duplicate email handling.

3. Verify invalid status handling.

4. Verify invalid Excel template handling.

5. Add clear Thai error messages.

6. Add downloadable error summary support if easy to implement.

Part 5: Master Review Hardening

Requirements:

1. Verify approve workflow.

2. Verify reject workflow.

3. Verify duplicate department creation prevention.

4. Verify duplicate position creation prevention.

5. Verify organization scoping.

Part 6: Output Review File

Create:

docs/pre-sprint-6-stabilization-review.md

The file must include:

1. Summary
2. Files Changed
3. Issues Found
4. Issues Fixed
5. Authorization Review
6. Localization Review
7. Dashboard Review
8. Import Review
9. Master Review
10. Remaining Technical Debt
11. Recommended Sprint 6 Scope

Part 7: Deliverables

Return:

- Complete code changes with file paths.
- Content of docs/pre-sprint-6-stabilization-review.md.
- List of unresolved issues requiring Sprint 6.
