## ADDED Requirements

### Requirement: Training panel
The system SHALL display a collapsible "Training" panel in the sidebar. The panel SHALL contain model type selection, a "Start Training" button, and training run history. The panel SHALL be usable independently of the prediction panel.

#### Scenario: Display training panel
- **WHEN** the user expands the Training panel
- **THEN** the panel shows model type selector, training action button, and recent training history

### Requirement: Model type selection
The system SHALL provide a dropdown to select the ML model type for training. Available options SHALL be "Random Forest" and "XGBoost". The selection SHALL default to "Random Forest".

#### Scenario: Select model type
- **WHEN** the user opens the model type dropdown
- **THEN** "Random Forest" and "XGBoost" are listed as options

#### Scenario: Default selection
- **WHEN** the training panel loads
- **THEN** "Random Forest" is pre-selected

### Requirement: Training execution
The system SHALL trigger a training run via `POST /api/training/start` when the user clicks "Start Training". The request SHALL include the selected model type. The system SHALL show a progress indicator and poll for status updates every 5 seconds while training is active. The "Start Training" button SHALL be disabled while a training run is in progress.

#### Scenario: Start training
- **WHEN** the user selects "XGBoost" and clicks "Start Training"
- **THEN** the system sends `POST /api/training/start` with `{model_type: "xgboost"}`, disables the button, and shows a "Training in progress..." indicator

#### Scenario: Training completes
- **WHEN** a training run status changes from "running" to "completed"
- **THEN** the system shows a success message with key metrics (accuracy, F1 score), re-enables the button, and adds the run to training history

#### Scenario: Training fails
- **WHEN** a training run status changes to "failed"
- **THEN** the system shows an error message with the failure reason and re-enables the button

#### Scenario: Prevent concurrent training
- **WHEN** a training run is already in progress and the user tries to start another
- **THEN** the "Start Training" button remains disabled

### Requirement: Training run history
The system SHALL display a list of recent training runs fetched from `GET /api/training/runs`. Each entry SHALL show: model type, status, date, and key metrics (accuracy, F1 macro). The list SHALL be sorted by date descending (most recent first). The list SHALL show the 5 most recent runs.

#### Scenario: Display training history
- **WHEN** the training panel loads
- **THEN** the system fetches training runs and displays them with model type, status badge, date, and metrics

#### Scenario: No training runs
- **WHEN** no training runs exist
- **THEN** the panel shows "No training runs yet"

### Requirement: Dataset info display
The system SHALL display information about the training dataset before training starts. This SHALL include the dataset file path and whether it exists. The user SHALL be informed that training uses the exported annotation dataset.

#### Scenario: Dataset available
- **WHEN** the training panel loads and the labeled dataset exists
- **THEN** the panel shows the dataset path and a ready indicator

#### Scenario: Dataset missing
- **WHEN** the training panel loads and no labeled dataset exists
- **THEN** the panel shows a warning "No training dataset found. Export annotations first." and the "Start Training" button is disabled
