Set navigation menu item to active for child pages
Try using:

   {% set pageIsActive = (page.id == entry.id) %}


and then testing for that in your if statements.

This article covers pretty much every eventuality when it comes to classes and navigation and should help you achieve the markup you are after.