Thank you so much for all the suggestions. We are staying at the Hotel Caireles which is close to the Mezquita. I kind of want to start with the Mezquita to make sure we have enough time to spend there. Casa De Sefard seems to be open until 6pm and Palacio de Viana until 7PM. Alkazar opens early in the morning. So maybe we can do something like this (no horse show in this plan):
Mezquita and the area around it - 11:30 am to 2:00 pm, Lunch - 2:00 to 3:00 pm
Palacio de Viana - 3:30 to 4:30
Casa De Sefard, Synagogue and Juderia 5 to 7:30
Dinner - 8 - 9
Night walk or night tour (the tour you mention starts is from 9 PM to 11 PM, we can probably make it if we eat near the meeting place)
There is actually a Hammam session at midnight so that might be an option or just sleep at this point.
Morning - quick breakfast, then go to the Alkazar (or we might decide to skip it and take another walk) - 9-11:30 or 12 PM
Train to Madrid and from there to Toledo - 1 PM or 1:30 PM - this is actually a key question, we'd like to have some time in Toledo before it gets dark. 12:30 train seems like it would be too early but either 1 PM or 1:30 PM seem OK. What do you all think?
I also found this option for seeing patios (this could be an alternative to going to Palacio de Viana):
https://www.tripadvisor.com/Attraction_Review-g187430-d4164568-Reviews-Los_Patios_del_Alcazar_Viejo-Cordoba_Province_of_Cordoba_Andalucia.html
Does anyone know and can recommend this tour?