The 16th Century was the Golden Age of Spain, however the mountains of Gold that poured in from the New World were quickly spent as Spain was never at peace, both with the Ottoman Empire which was trying to dominate the Mediterranean and expand further into Europe through Austria, and the Eighty Years War with the Netherlands who had succeeded and become a Protestant nation. The Spanish and France had been at war on and off throughout the Renaissance trying to gain control of Italy. Spain had always bested them, that is until the Thirty Years War. France entered the conflict late, but had done untold damage but bankrolling armies of protestant mercenaries that sacked and destroyed whole sections of the Habsburg Holy Roman Empire, over three million German civilians died from famine and disease caused by the chaos of war. The Peace of Westphalia in 1648 marked the defeat of Habsburg's, the rest of the 17th Century saw France emerge as the European Superpower, with Protestant England and Netherlands' becoming France's chief rivals. The decline of Hapsburg power was the decline of Spanish power, the throne in Madrid was occupied by more and more feeble minded monarchs (Habsburg inbreeding). The Spanish Economy had never been strong and remained very feudal, the Spanish Aristocrats saw most commerce and economic pursuits as unmanly and preferred ranching, horse breeding and the noble arts of war, they horded gold rather than investing it, even though the sheer amount that was coming in from New World halved its value by the end of 16th century. What little economic growth there was died from staggering inflation and high taxation caused by the never ending wars. Because the English and the Dutch Aristocracy were more effeminate, modern banking and joint stock companies developed which enabled them to develop the first modern economies, which were better able to handle protracted warfare and invest the fruits of their empires. 1648 is usually the year France is considered to have overtaken Spain as the leading European power, but Spain remained a power until the end of the end of the Habsburg line there. When King Charles II who was born both mentally disabled and sterile died in 1700 Louis XIV tried putting his 16 year old grand-nephew on the Spanish Throne, this lead to the fourteen year long War of the Spanish Succession. In which coalitions of European powers lead by England and the Netherlands' tried to stop Bourbon Dynasty from annexing Spain and its global Empire. By this point Spain was a shadow of its former self, and during the War of the Succession acted as more like a French puppet than an independent power. Spanish global power continued to dwindle from this time on until its end in 1898.
tldr: Spain was displaced as the Great European power by France in 1648, had become a French puppet and was no longer a major European power by War of Spanish Succession at the begining of the 18th Century.
There is a whole section of this book that covers the decline of Spain:
Kennedy, Paul Rise and Fall of the Great Powers
On the later end, the Spanish-American war really demonstrated that Spain had become fully irrelevant militarily. While long displaced from their former position of political importance, they were still regarded as probably being the third strongest navy at that time. When the US crushed the Spanish navy essentially without taking losses, it led to a reappraisal of the relative potency of both Spain as well as the US.