Write a Python function to perform data transformation on a dataset.
Implement transform_dataset(records). Each record is a dictionary with id, category, and numeric value. Keep only the last record for each ID, discard records with missing or invalid fields, normalize categories by trimming whitespace and converting them to lowercase, then return category aggregates sorted alphabetically.
Return dictionaries with category, count, and total, where total is the sum of valid values.
Example: [{"id": 1, "category": " A ", "value": 2}, {"id": 2, "category": "a", "value": 3}] returns [{"category": "a", "count": 2, "total": 5}].
def transform_dataset(records):