How do you approach state management in a complex, multi-page application?
Implement reduce_app_state(initial_state, actions) as a pure reducer. Store shared records in normalized entities and order collections, while keeping each page's filter and selectedIds independent. Support navigate, set_filter, upsert_items, toggle_selected, and remove_item actions.
Input is a state dictionary and an action list. Return a new final state without mutating either input. Each record contains a unique string id.
def reduce_app_state(initial_state, actions):