Clicking on an app icon in dock opens the oldest instance (window) rather than the latest
If you minimise a window but have another window from the app still open, clicking on the Dock icon brings the older window to the front because that's the one that's open. If you want the minimised window, click the minimised window in the Dock, not the app icon.