Quite frankly, if we're talking realism about the uniforms... even if Captains don't have wildly different rank devices than lower-ranked officers, separating divisions by the primary color of their uniforms does nothing but invite a sniper to shoot at anyone wearing red. Not to mention, flag officers still have uniforms that make it really easy to tell them apart from mere line officers.
The only reason to color-code uniforms is to compensate for low visibility, like gunpowder smoke in 18th-century musket regiments, or to make their functions easily distinguishable in an extremely high-stress and swift-paced, dangerous environment, like the bright-colored jerseys of flight deck crews on aircraft carriers. There is literally no practical reason for Starfleet not to simply make everyone wear camouflage or utility uniforms while working, and have service dress reserved for reporting duty and desk jobs, with only pins or maybe a bit of colored piping/lapel details denoting their branch.
The one problem with this, as best exemplified by the monster maroons from the '80s, especially the turtleneck-less versions made for TNG flashbacks, is that they're nigh-impossible to distinguish on TV. You can either make it realistic or easy to follow for the average viewer, but not both at the same time.