When will you be in Spain? Andalucía often has brutally hot weather in the summer. When trimming the itinerary (see below), I'd give some weight to weather expectations.
How many nights will you be spending on the ground in Spain?
The reason you're having trouble putting together a workable itinerary is that it cannot be done if you want actually to see much of anything in those places.
First, eliminate Tangier. It means a good part of a day getting into position so you can take a ferry to Tangier, spend some time in that not-great city and then take a ferry back on the second day. Then you'll need some time on a third day just to get to the next Spanish destination on your list. Morocco is a wonderful place, but Tangier is a port town that doesn't have as much to offer as many other Moroccan cities. It really isn't worth giving up such a big chunk of your trip.
The cities of Barcelona, Madrid, Cordoba and Seville are well-connected by fast trains, making them the easiest to visit from a time perspective. It is also easy to get to Montserrat from Barcelona and to Toledo/Segovia/El Escorial from Madrid. If need be, Cordoba can be visited as a day-trip from Seville; that allows you to eliminate one hotel change.
Ease of transportation doesn't mean you must go to those places or only those places, but keep in mind that the time you spend on trains and buses is time you are not sightseeing (you're not generally going to be traveling through spectacular scenery).
Granada is without a doubt one of the very top sights in Spain (arguably the #1 sight). I think you can squeeze in the two nights you need in Granada to visit the Alhambra, assuming you can get tickets. Alhambra tickets sell out very early.
Including Logrono and San Sebastian will require cuts elsewhere, so it depends on your priorities and--I would suggest--the weather. I'm not sure about Logrono, but San Sebastian is usually not very hot even in midsummer.
This is like putting a puzzle together, but you need to know how much time you want to spend at each destination, and that's where your sightseeing interests are critical, especially:
- How interested are you in Madrid's art museums?
- How interested are you in Barcelona's modernista sights?
Keep in mind that the day you arrive from the US/Canada you may well be severely sleep-deprived and jetlagged, so that day may not be a very productive one, beyond just wandering around outdoors, trying to stay awake.
Also, every time you pick up your luggage and head to a different hotel, you're losing at least half a day. The trip between Barcelona and San Sebastian will cost considerably more time than that.
You can explore travel times on the Deutsche Bahn website, though you'll need Renfe to see fares.