A possibly-useful fact: Ground-transportation links between those two countries are very limited and infrequent. If you decide to spend the extra time in Portugal, you will lose a great deal of time if you have to cross that border twice. It would be far better to fly into Spain and fly home from Portugal--presumably from Lisbon so there's only one border crossing required. Check now on multi-city flights to be sure the cost will be reasonable by comparison to flying into Barcelona and out of Seville/Malaga/Madrid.
There are no trains across the southern part of the border. For making the initial border crossing, you'd be taking the bus from Seville probably to Faro and on from there. Rede Expressos operates at least some of the buses in Portugal. The train north to Merida and Badajoz, then on to Lisbon, takes a lot longer, and I think there's only one train per day between Badajoz and Lisbon, departing at 4:24 PM. Best to check on flights from Seville to Portugal. Your destinations may be limited to Lisbon and Porto.
The convoluted train routing is a shame, but honestly, I consider the Algarve far from Portugal's most interesting area. I'd much rather spend week in other places in Portugal, or in Spain. If heading to Lisbon/Porto, flying would be better.
Seville has a lot of attractions and is, to me, at least a 3-day city. On the tour you'll only about 1.5 days for that city before the tour ends with breakfast on Day 14. I'd want to stay in Seville for at least one extra day.
Then there's the really unfortunate omission of Cordoba, one of Spain's most interesting cities. I'd want to spend a couple of days there.
If you decide to stay in Spain and don't want to include Cordoba on this trip, check flights from Seville to northern Spain to avoid spending all day on a train. From the chart on the Seville airport's Wikipedia page, I see there are flights on various airlines to the Basque Country (Bilbao and Vitoria) and to Galicia (A Coruna and Vigo). Vigo's the least interesting of those options but--like A Coruna--is well-connected to Santiago de Compostela. If I had just 5 or 6 more days (you may need to travel back to Madrid by train before your flight home), I'd probably spend it all in one area, and the Basque Country would be good. There's plenty to see there.