After his party suffered a humiliating loss in Istanbul, President Recep Tayyip Erdogan is down but far from out.