The decline of Spain I think it was in the end of XVIII. century.
1º The Absolutist regime was becoming obsolete and needed to modernize to the parlamentary regime and the economic liberalism.
2º The continue war against UK damage spanish economy a lot. The merchant fleet was nearly destroyed, the textile industry, in spite of the success, was sinking. The agriculture and mining production was weak.
The politicians with landslide support started the reform, however, the french revolution, slowdown the reforms.
The example was the Count of Floridablanca, liberal politician and lawyer. He was the prime minister in the last absolutist monarchy government favour to liberal reform. However, before the reforms started, the king decided to substitute the prime minister for the Count of Aranda, a military stadist. However, due to Count of Aranda was alarmed in order to intervene in French revolution (he take into account that spain was not ready fot that adventure), was subtitute to Manuel Godoy, a politician that rejected any kind of reform and was decided to invade france. The decisions made from the king was Due to he thaught that spain needed a military leader in order to face French revolution and Napoleon. A great mistake that the king committed because spain was not ready for any war.
The plan of invasion of Godoy to invade was really bad planned. Spain invade french south with 55000 men poorly equipped joining in the war. The war started with victories but temporary because the french army DOUBLED the size of spanish expedition army. General Antonio Ricardos sent a urgent letter to madrid asking for reinforcements, however, the letter arrived to late. That was the spanish situation of the communications between head government and the army, really BAD. Manuel Godoy passed from being the prime minister that attacked france to ask for peace rapidly, he lost all his reputation and he became the future loyal servant of Napoleon´s brother.
At the end, spain was invaded by french army. The war against Napoleon put the spanish administration even worse than before. Later the transition was more caotic and with civil war. A lot of time lost, that provocked a late industrial revolution.