The old sense is the literal one. やばい is recorded in Edo-period criminal slang for a situation about to go wrong — a lookout's word. Through the twentieth century it stayed close to that: dangerous, dodgy, about to cost you. やばい人 and やばい店 still mean exactly that today, and nobody reads them as praise.
The flip is about intensity, not about good and bad. What the word really reports is that something has exceeded your capacity to deal with it calmly. A tax bill does that. So does a dessert. Once younger speakers started using it for the second kind in the 1990s, the word stopped carrying a direction at all — it carries a magnitude, and the listener supplies the sign.
Tone and grammar do the disambiguating. Falling and sharp is trouble; drawn out and rising is praise. やばくない? as a question is nearly always admiring. やばいくらい〜 forces the good reading by attaching to something already positive. And in front of a noun, the old sense wins by default.
It is unsayable at work, and this matters more than it sounds. やばい is register-marked as young and casual, so using it with a manager or a client reads roughly like saying “that's sick” in a job interview. The safe substitutes are まずい for the bad sense, 危険 for actual danger, and すごい or 素晴らしい for the good one. Learners hear やばい constantly and conclude it is neutral. It is not.