I've heard the term "Mary Sue" thrown around a lot, and it seems to mean different things to different people, but is always something negative about the way the character is written, not necessarily about the character itself, usually involving the phrase "overly idealized". Is there any common definition that most people follow that can be properly qualified?
A Mary Sue is a character who passively warps the fabric of the story to their own benefit by virtue of mere existence, and acts only within that context. That's really what most of the extant and often inconsistent definitions boil down to.
The key defining characteristic of this is a sort of reversed narrative causality: The character is unique; therefore they were born with an unusual eye color. The character succeeds; therefore they learned the necessary skills somewhere. The character is popular; therefore other characters like them, regardless of behavior or motivation. The character is dark and angsty; therefore they had a tragic past. There's often no rhyme or reason to the implied backstory except in the context of setting the character up to act in the current situation. Most descriptions of a Mary Sue are essentially lists of character traits commonly used to prop up a Mary Sue in this manner.
A consequence of the reversed causality is that justification of the character's traits or development of their personality is treated as inessential. Other characters will interact with the Mary Sue in whatever way they're Supposed To, their motivations for doing so contrived as needed or just having their personal agency overridden outright by force of narrative.
Self-inserts are frequently written as Sues for obvious reasons, but any character favored by the author can get the same treatment, up to and including distorted interpretations of canon characters in fanfic.
The term originates from fanfiction, where the artificiality of the character and the effects of their presence are most clearly visible against an established backdrop. A setting with multiple authors can be similar--writers using a shared setting, role-playing groups, &c.--if one author tries to make their character(s) more important by fiat or contrived situations.
For a single author with a new story in an independent setting with original characters the term is harder to use in a meaningful way, which is not to say that accusations aren't made. A main character who is too perfect, too competent, too successful, and all around too much isn't a Mary Sue if showcasing their larger-than-life exploits is the intended purpose of the story. A secondary character being oh-so-special and interesting and important isn't a Mary Sue if the entire cast is similarly over the top and the narrative doesn't consistently favor any one character. A female character doing something unexpectedly interesting is not automatically a Mary Sue, for crying out loud.
In short, there is no "archetype" here, though some archetypes are more susceptible than others. A character being a Mary Sue is first and foremost a property of their role in the story.
A "Mary Sue" is a character who represents a highly-idealized version of the author (usually). This is the sort of character who, as needed, can perform brain surgery with one hand on a turbulent jet that she's piloting absent-mindedly while working on a cure for cancer -- that sort of thing. Wikipedia gives the origin as:
While this originated with teen females with romantic interests, the article goes on to say, and my friends who write fan fiction confirm, that it's since evolved into exaggerated "super-everything" wish-fulfillment along the lines of my first paragraph. Sometimes super-everything characters who aren't proxies for the author are also called Mary Sues.
According to Lauren Ipsum (see comments), the masculine form is "Marty Stu".
I'd like to make an amendment to the above. It's entirely possible to have a unique, overly-described character who isn't a Mary Sue, and a character with little to no description who is. There's no real formula that can exactly pin this down. Those listed above have good points and went over the common tell-tale signs, but here's what I consider to be the real problem:
Mary-Sues get the attention of the author for not having done enough. They get the attention of the characters around them for reasons that just don't exist in the story, for good or ill. A character that everyone hates for no good reason is as much of a Mary Sue as one who's universally loved. Anti-Mary-Sues fall for the same sins as what they were trying to protest. Their ego, the author's love of their darling pearl, and private fantasies and wish fulfillment has out-shown the story they were going to write.
I'm going to suggest that everyone forget what they know about Mary-Sues, though. Don't think about them. Don't concern yourself. Keep your own ego in check, and try to develop all your characters without focusing on too much on a favorite. Listen when your writing buddies say 'how is she getting away with this?' and find a good answer. The symptoms of Mary Sue-ism will fade, even if you keep the violet eyes and fiery hair.
People too afraid of falling into this category can drab their characters down until they're no longer interesting. I've known quite a few writers too scared to let anything interesting happen in their books, crying 'realism!' as if a baseball bat of critical disbelief was going to beat them at any moment. I used to be one of them. And I wrote Mary Sues in my early teens, before my writing matured and I found more interesting things to pursue instead.
Keep your work balanced, work hard on your writing, and don't worry about what people have done before. Writing's too much work to spend all your energy scared of what other people might think of you.