I am getting more confused the more I read.LOL
Seems my best option is one week in Spain and one in Portugal
Fly to Madrid 4 nights
Train to Barcelona 3 nights
Fly to Porto 3 nights
Train to Lisbon 4 nights.
Fly home from Lisbon.
This makes more sense. It is much faster to fly between Spain and Portugal, as the driving times are deceptively long, due to the terrain in between. It also makes sense not to backtrack to Barcelona.
We spent roughly the same number of nights/days as this in each place, minus Porto, and I thought that worked really well. 4 nights in Lisbon would give you days trips to both Sintra and Cascais (beautiful beach town). We found that the Lisboa card was really worth it (unlike some city cards), because it not only gave us transport to/from the airport, within Lisbon (on metro, trolleys, etc.), on the trains to and from both Sintra and Cascais, and admission to major sights in Lisbon, but the card was good for a specified number of hours (rather than days), meaning that a partial day didn't use up a whole day. So, we were able to time it so that we could use it to get back to the airport on our last morning.
Your Madrid days will give you enough time for a day trip to Toledo---so worth it. The palacio in Madrid is definitely something to see, as well as Plaza Mayor. The Prado museum is incredible, and seeing Guernica at the Reina Sofia is a great experience. Retiro Park is huge and fun to explore. There is also a great Botanical Gardens in this area (outside of the Prado, if I recall correctly). However, because of the popularity of Barcelona, I agree that you might steal a day from here and add it to Barcelona, as the sights at the latter are more spread out and busier, and, therefore, take more time to see.
Although Barcelona was not my favourite (mostly because it was very, very crowded and people tended not to be as courteous as in the other places we visited and had a very different tolerance for personal space), there is a LOT to see there, and you may want to add a day there if you want to go to Montserrat (which I strongly recommend, particularly as you like hiking). There is the Sagrada Familia, other Gaudi sights, including Parc Guell (note: the Gaudi sites should be booked in advance, as they are very, very, very popular). There is the Gothic quarter, the harbourfront, Las Ramblas (yuck--very, very crowded--but there is a big Mercado along there), a mall in an old bullfighting arena, a hill that we didn't get to (forget the name, but there are sights there), a fortress, etc.