What if it selected items relative to how the container is layered on your body. So your bottom layer container contains the first things you’ve picked up, and the topmost layer selects the most recent items in your inventory. So when you drop your pants, it will do your automatic selection of other items to drop if it goes over your volume, but since your pants are the first priority, all the items that were placed first are selected to be dropped. Alternately, the topmost container will attempt to drop
Maybe add an advanced inventory option that shows you how your inventory is sorted into containers? Note: They aren’t actually in the container, it’s just exploiting inventory first-in-last-out order and placing a marker tab to indicate what LBE the items are considered to be.
Something like:
[cargo pants]
first aid kit (3)
bottle of fruit juice (rotten)
box of candy cigarettes 2 (5)
[messenger bag]
batteries (349)
9mm +P (139)
USP 9mm (7)
If you were to switch to default display, first items first, it would look the same, simply without the messenger bag. The expanded mode however, might allow you to swap items around, changing their order in your inventory but not really moving them.