Capitalism only optimizes for profit. Which, incidentally, has resulted in a higher standard of living in countries where it is practiced. You can point to wealth inequality in the developed world but even our poor live better than medieval kings.
I agree though that social democracy looks like the most workable solution to these ills, and hopefully the arc of history will lead us to a stable condition where most or all countries on Earth have embraced it.