This might simplify the question: how is it possible to use the search function to filter multiple tables on one page? That makes the CSS accordion simple to implement and I expect that the output would hide any unpopulated parent accordions.
Please can you tell me where that code needs to go and where I need to modify my theme so it doesn’t break the layout?