My flight arrives in San Jose in the middle of the night. I plan to get a hotel and leave later that day for Quepos by bus.
When and where do I buy my bus ticket? Can I be sure that there will be tickets available for that day? (I have a non-refundable reservation in Manuel Antonio that night.) Are bus tickets sold 24 hours a day, and, if so, should I go buy my ticket in the middle of the night (1:00 a.m.) before heading to my hotel in San Jose? Thanks!

It depends when you go to Costa Rica, at high season peak you should buy your ticket early as possible. But normally it is not neccessary to make reservation in advance. There are 9 buses a day to Quepos. Try to get one of four direct buses. See bus stop and schedule on San Jose bus map.

Don't try to get your ticket in the night. The Coca Cola area is not secure and I think there is no counter for tickets open at this time.

Dont spend any time in the Coco Cola bus terminal at night!
If you're arriving that late get a shuttle bus to Quepos the next day!