Inventory/stash sort mechanic?

On what basis does the game sort things in your inventory and stash go by? I clicked sort in my stash thinking it would align everything by type and group similar items together such as all my runes together but that’s not how it does it which is upsetting…

Is there any order to the sort feature? It makes most sense to put things together or in alphabetical order.