Are late fees legal in a residential tenancy in San Francisco or Oakland? If not, what damages or penalties can the landlord lawfully get?

Late fees in a residential tenancy agreement are generally analyzed within the concept of liquidated damages, and late fees must be specified in the rental agreement, and agreed upon by all the parties in advance. Generally, they're unenforceable unless those provisions are met.