What were the causes of the collapsed disintegration of Spain in 1640?

What happened to Spain in the early seventeenth century? Was there a decline? What was the nature of the decline? Knowing what you do about the reforms of the catholic Monarchs, why did Spain almost disintegrate in 1640? What were the causeso of the collapse of Spain?