Optimal gradient estimates for multi-phase integrals