@SantiagoFromColombia Welcome to the forum.
I think if you are concerned enough to ask the question, you can be confident that you are respectful enough not to have to worry!!
I am a Catholic priest.
The rules about women and men and headgear while in church were formalised in the Code of Canon Law in 1917, which required women to have their heads covered, and men not to, during the liturgy. This was stated in canon 1262. There was no formal rule prior to 1917, though there was long tradition,
The Code of Canon Law was revised in1983 and the new Code replaces the old Code. This canon of the old code is
not in the new code and is technically 'abrogated'. So there is now no rule in effect for those who attend the liturgy, male or female.
This change rather
followed practice. Many women had stopped wearing headgear (in UK and Ireland, USA, perhaps less so in more Latin southern Europe) once the mass in the vernacular was introduced after the Second Vatican Council in the 1960s, even though the Council did not speak on the specific question of attire.
In 69 years of attending Mass I can never remember anyone being sanctioned for not wearing headgear or for wearing headgear. I think it would be quite extraordinary, though traditional practice may vary in different cultures.
I think men wearing hats in church doesn't happen often (in my own culture) because men don't wear hats much any more - in my culture. In the days when they did (when I was young) I think men used to take their hats off when going indoors anyway.
The present Pope, Francis, would be wholly against any kind of behaviour which made anyone feel unwelcome in a church, eitther the church building or the church community. He has frequently said that churches should be open at all times to all.
I did once get in trouble in a church on the Camino Portugues on a Sunday morning when I sat in the seat which apparently belonged to one of the 'regular' local ladies. And I had put my sopping wet hat on the seat which belonged to another of the regulars. But I was happy to move, although they remained a bti suspicious.
But one of them bought me coffee afterwards.
I think for anyone a basic approach of common sense and respect for others is sufficient. I know that in Italy is still to be found occasionally signage aboout very short and revealing dress. Some places will lend you a skirt or top to cover, but I think this happens less now.
Anyone is welcome to stay throughout a service if they so wish. To have a basic orientation that you would not wish to offend will take you a long way. No one is going to get exercised by whether you stand or sit or kneel at the right time. If in doubt, follow the majority. If you are weary and want to sit throughout, no one will be alarmed.
I note that the OP asks
specifically about Spain. That is important - apart from the
univeral rules, the
local culture and practice does need to be respected. But that is not difficult.