Collective firm bankruptcies and phase transition in rating dynamics