Run when all application windows have closed

There is no trigger for window changed/window opened/window closed because the system does not provide events for that, and so it would require polling to notice which is slow and inefficient.

You could trigger on application deactivation which is probably when you would want to perform the action anyway.

Then it is just a question of counting the number of open windows in the application. Keyboard Maestro has no ability to count the windows in the non-front application (and it would already be non-front by the time it had deactivated) so you would have to use some other means. Probably you can do it using AppleScript. The name of the application you just deactivated is available via the %TriggerValue% text token.