Stability trends of MAX phases from first principles