As a traveller, your passport is your most valuable possession. It's the only reliable and universally accepted travel identification document that proves you can return to your home country. It's the one thing you don't want stolen. Trust me.
While travelling in Costa Rica, my backpack was stolen off of a bus. We were taking public transit from San Jose to La Fortuna since it was a fairly inexpensive transit option. The experience was heartbreaking since I lost everything important - my passport, my money and my electronics.
1) Don't beat yourself up
How could I be so stupid? Why didn't I keep a better eye on it? Why didn't I keep my passport on my body? I'm guilty of this, but these questions aren't going to do you any good. The experience has already passed. So, there's nothing you can really do about it now. Asking these self-deprecating questions will only make you feel worse about yourself.
Just because some jerk stole your stuff doesn't make you a bad person. These inconveniences happen all the time. You just need to focus on how you're going to deal with it.
2) Call your national embassy
After you manage to calm yourself down, you need to call your national embassy. Let them know that your passport was stolen and that you'll need an emergency one to get back home. They'll ask you for two non-familial references that they can call to confirm your citizenship. Once you make it to the embassy to pick it up, you'll have a pay a decent amount to get it processed.
If you had your credit cards stolen as well, make sure to cancel them as soon as you can. Within a span of two hours, this jerk spent $2000 on my card. Because I told my bank right away, I didn't have to pay it back. Also, if you had anything else stolen, make sure to get a police report so you can claim insurance!
3) Have fun on your trip
Nothing ruins a trip faster than a mopey person. Seriously. Having your passport stolen sucks, but it's not the end of the world. You're alive, have all your limbs and your health intact.
You need to keep your attitude up. So don't let this passport-stealing jerk spoil your trip. We continued with our plans and hiked up a volcano, relaxed in a hot spring and drank coconuts on the beach.
Plus, look on the bright side, you get to come home with an interesting story.