And then some of those stupid ideas stuck. Just like in TOS, where they had this Communications Officer character of no particular function, or the Engineer who left Engineering to occasionally command the ship.
We know the uniform colors are generally associated with "divisions", "specialties" or "lines of work", but this is not completely consistent; in TOS, it actually seemed closer to being completely random in that respect. Moreover, nobody in the Trek universe actually outright comes and says that the colors denote divisions. It just so happens that a character in a certain line of work wears a certain color, and may mention wearing that color because of being what he is. But "is engineer -> wears mustard" is not the logical equivalent of "wearing mustard -> being engineer", or even of "being engineer -> wearing mustard"...
It might be that the colors are fundamentally unrelated to lines of work. Rather, to put it in today's military terms, one color (gold in TOS, red in TNG, blue in the 2230s of the latest movie) is associated with line officers who have an unlimited mandate to command people of lower rank, and also to boss over staff officers of basically any rank. And another color (blue in TOS and TNG) is for staff officers who are specialists with "civilian" training (doctors, astronomers, geologists, entomologists) and only carry high rank to denote their academic education and associated pay rate. This tells the casual TNG Starfleeter that a Commander wearing red is to be obeyed, but a Commander wearing blue is to be argued with - and OTOH that somebody in red is likely to be in a "soldier" line of work and can tell about the tactical aims of the mission, while somebody in blue is likely to have an answer to his "civilian" question about dibronium ore or Catullan wedding habits or the nagging pain on the left side, just below the ribs.
The in-between color might then apply to so-called restricted line officers, with skills that make them more useful in their specific tasks and unlikely to be mere markers and keystones in the hierarchy structure (unit commanders and decisionmakers of various sorts).
Naturally, certain types of "profession" would get to predominantly wear staff colors, then - doctors, scientists, support personnel. Other "professions" would get line colors - the leaders of the various hierarchy levels, the people studying up for leadership positions in relevant lines of work such as helm or gunnery. And there'd be a great pool of personnel in restricted line colors, with potential to "ascend" to line colors but with current duties in "middle management" of various specialties - calling for more authority in group interaction than staff has. A lone astronomer doesn't really need the authority of his LtCmdr rank in his line of work, and can wear staff colors to indicate this, but an engineer would need to hold higher rank than her team of engineers in order to efficiently manage them, and would wear restricted line colors to highlight her hierarchical status.
Three colors is a perfect fit for the system of line vs. restricted line vs. staff. On the other hand, it's a piss-poor fit for a system of divisions, because Starfleet clearly has far more than three divisions, and uniform color never tells apart a useless cosmologist from a vitally important surgeon.
Granted, Star Trek is a TV show where simplification is important to prevent the audience from getting hopelessly confused by all the alien and futuristic things... But it never seemed the makers of the show thought in terms of division colors as such. In TOS and its pilots, uniform colors existed from the very start - but separate "line of work" identifiers did, too, in the form of symbols worn in the middle of the arrowhead insignia on the uniform chest. At various times in the history of Star Trek the phenomenon, this duality may have been forgotten, and indeed in the first movie there was a conscious effort to use color for divisions; this was done by introducing lots and lots of new colors, now only worn on the epaulets or chest badges, while uniform color itself became pseudo-random (that is, with some method to the madness, but none the audience could figure out). The following TOS movies continued the use of division colors on epaulets and shirt collars. But then TNG went back to simple three uniform colors, this time without separate division markers anywhere. And there we have it: a confusing and almost information-free "system" of colors that the modern writers probably do not understand themselves. But the concept of the colors denoting line vs. staff still fits the evidence, and allows us to think that our characters at least have some sort of order and sense in their lives, even if this isn't exactly due to the efforts of the writers or the costumers.
Timo Saloniemi