What is the legal definition of a habitable space/room?
You'll want to check with your local zoning people (city/county) for specifics on laws in your area, but this is what is required in Colorado.

This answer is specific to bedrooms, so I don't know what is code for other living spaces.

To be a legal bedroom, a closet is required.  Doors are optional.  Also, there needs to be an egress window and window well (if the room is below ground level) large enough for firefighters enter and exit easily, and the window well must be deep enough to be able to turn around with all their gear (specifically oxygen tanks on their backs).  I can get exact measurements for Colorado code, if desired.

Also, it is code in Colorado and good practice regardless - a Carbon Monoxide detector must be within 10 feet of every bedroom door in the house.  DO NOT buy the combo smoke/CO detectors.  These can do one thing or the other, but not both.  Carbon monoxide is a heavy gas and collects at floor level.  Smoke and heat typically rise to the ceiling.  These should be placed no more than 12 inches above the floor.  If you have a combo detector on the ceiling and it goes off, you'd already be incapacitated (probably dead) from the buildup of carbon monoxide.  (These combos are a serious pet peeve of mine, since people are basing their very existence on these working properly in an emergency.)

I hope this helps at least for your query on bedrooms.