Impact of AGN feedback on galaxies and their multiphase ISM across cosmic time