Called when the fragment is being destroyed. Releases document resources and cleans up internal state.