Its biggest medicine was heading for a sales cliff. AbbVie spent years building the businesses that would have to catch it - and learned how expensive a wrong bet can be.