Kerry Ellison and Sterling Gray worked 20 feet from each other at the Internal Revenue Service office in San Mateo, Calif. One day in June 1986, they went to lunch. A few months later, Gray asked Ellison out for a drink and lunch -- invitations she declined. Then he started to write her love letters.

"I cried over you last night, and I'm totally drained today," he scribbled on a message slip in October 1986, according to court documents. Ellison asked a co-worker to tell Gray to leave her alone, to no avail. "I know that you are worth knowing with or without sex . . . ," he wrote in a single-spaced, three-page letter a few days later. "Don't you think it odd that two people who have never even talked together, alone, are striking off such intense sparks."

Eventually, Ellison, who said she was "frightened" by Gray's attention and "frantic" about "what he would do next," filed a complaint alleging sexual harassment.

A federal judge dismissed her case, calling Gray's conduct "isolated and genuinely trivial." Last month, the 9th U.S. Circuit Court of Appeals in San Francisco reversed that ruling, saying that sexual harassment had to be viewed from the perspective of what a "reasonable woman" -- not the prototypical "reasonable man" -- would find offensive.

While a man might look at Gray's conduct and see him as a "modern-day Cyrano de Bergerac wishing only to woo Ellison with his words . . . " Judge Robert R. Beezer said in an opinion joined by Judge Alex Kozinski, "conduct that many men consider unobjectionable may offend many women" and "a reasonable woman could have had a similar reaction" to Ellison's.

The ruling is one of a spate of recent decisions in which courts have struggled to define the line between acceptable workplace behavior and harmless flirtation;

between an amusing, if ribald, joke

among friends and illegal sexual harassment.

Some conduct indisputably goes too far, the courts have determined. It is clearly illegal to require sexual favors as a "quid pro quo" of continued employment or promotion.

But another category of sexual harassment cases is far murkier: conduct that does not directly affect an employee's economic well-being, but creates a "hostile or offensive" working environment.

Five years ago, the Supreme Court ruled unanimously that the federal employment law prohibiting discrimination on the basis of sex covers sexual harassment that is

"sufficiently severe or pervasive to al- ter the conditions of the victim's employment and create an abusive working environment."

In that case, Meritor Savings Bank v. Vinson, bank teller Mechelle Vinson claimed that her supervisor fondled her in front of other employees, followed her into the bathroom, demanded sex from her and even forcibly raped her on several occasions.

Since Meritor, the lower federal courts have sought to apply its test to a host of different and -- in some instances -- less egregious facts and have come up with varying results.

Last month, for example, a federal judge in Jacksonville, Fla. -- upholding the sexual harassment claim of a female shipyard welder -- ruled that the pervasive posting of nude and pornographic pictures throughout the overwhelmingly male workplace, combined with sexually demeaning remarks and jokes by male workers, created a hostile environment. One of the pictures showed a nude woman's body with the words "U.S.D.A. Choice" printed on it. Also posted was a dart board made of a drawing of a woman's breast, with her nipple as the bull's eye.

"A reasonable woman would find that the working environment at {the shipyard} was abusive," Judge Howell W. Melton found, noting that "pornography in the workplace may be far more threatening to women workers than it is to the world at large . . . . Pornography on an employer's wall or desk communicates a message about the way he views women, a view strikingly at odds with the way women wish to be viewed in the workplace."

In a decision Feb. 6 going the other way, a federal judge in Alexandria dismissed a harassment lawsuit brought by a secretary who said she was subjected to illegal sexual harassment by a boss who insisted on

escorting her to the bathroom and her

car, rubbed her back and hands despite

her requests that he refrain from touch- ing her, and showered her with notes and gifts.

"Put simply, {the supervisor's} conduct would not have interfered with a reasonable person's work performance or created an intimidating, hostile or offensive working environment that would have seriously

affected a reasonable person's psycho- logical well-being," Judge James C. Cacheris wrote.

He found that the woman's requests that her boss back off "were not delivered with any sense of urgency, sincerity, or force. In essence, she was sending out mixed signals."

Likewise, in a 1986 case brought by an administrative assistant at a refining company, the federal appeals court in Cincinnati said there was not a hostile environment in a workplace with posters of naked women -- including one of a woman lying down with a golf ball on her breasts, straddled by a man holding a golf club and yelling, "Fore."

According to testimony in the case, a co-worker called the plaintiff and other women employees "whores" and other sexually explicit names, and once remarked, in vulgar language, that all the plaintiff needed was "a good lay."

It "cannot seriously be disputed that in some work environments, humor and language are rough hewn and vulgar," the court said, quoting the trial judge's ruling in the case. "Sexual jokes, sexual conversations and girlie magazines may abound. Title VII {the federal job discrimination law} was not meant to," nor can it, "change this." It was not "designed to bring about a magical transformation in the social mores of American workers."

The confused state of the law appears in part to be a reflection of the difficult nature of the problem, and the fact that -- as the Equal Employment Opportunity Commission stated in guidelines issued after the Meritor ruling -- "Title VII does not proscribe all conduct of a sexual nature in the workplace."

Because "sexual attraction may often play a role in the day-to-day social exchange between employees," the commission noted, "the distinction between invited, uninvited-but-welcome, offensive-but-tolerated, and flatly rejected sexual advances may well be difficult to discern."

As judges are increasingly called on to make such distinctions, said Alison Wetherfield of the National Organization for Women Legal Defense and Education Fund, "the state of the law is kind of in flux." Some courts, she said, have been using the phrase "reasonable person" but clearly looking at the harassment from the woman's perspective.

In others, like the Alexandria case, "it does seem the judge hasn't tried at all to think about how women are really vulnerable when their bosses start making moves on them. . . . This stuff is so far beyond the experience of many male judges they just cannot imagine what it would be like to be in that situation."

Victor Schachter, a San Francisco lawyer who represents employers, said he believes the 9th Circuit and Jacksonville rulings reflect a recent trend in which "courts are going to be far more sensitive to how a reasonable woman is going to perceive this conduct, as distinct from they way a man would perceive the welcomeness or unwelcomeness of the conduct. . . . When we deal with sexual harassment, that means we're broadening the arena dramatically. If a man feels he's making a social, flirtatious overture, his standard of what is reasonable social behavior is not going to control liability."

The number of sexual harassment claims is growing, primarily because women are increasingly willing to complain about what they perceive as sexual harassment.

According to EEOC figures, complaints of sexual harassment filed with the agency rose from 4,046 in fiscal year 1986 to 5,572 last year; sexual harassment allegations were part of 38 lawsuits filed by the commission in fiscal year 1986, and 50 last year.

Lawyers who specialize in such cases say that reflects only a small percentage of the action. Under federal law, women who have been the victims of harassment but have not lost their jobs or failed to win promotions as a result, cannot obtain monetary damages -- a limitation Congress is now considering changing in the Civil Rights Act of 1991.

As a result of the restrictions, however, a growing number of plaintiffs are filing state court claims of assault and battery, or infliction of emotional distress, which may allow them to recover damages for pain and suffering or even punitive damages.

In the meantime, management lawyers are advising their clients to shield themselves from liability by instructing employees that sexual harassment will not be tolerated -- and that workers should err on the side of caution if they are not certain where the line is.

"Unless you know for sure that a woman won't mind hearing a dirty joke, you'd better not tell it," said Stephen Bokat, general counsel of the U.S. Chamber of Commerce, who teaches a course on sexual harassment to the organization's employees.

". . . Our major message is that sexual things ought to be left at home, out of the office."