I hope it's not discourteous to emphasize one of George's points as a tl;dr:
> "don't leave yourself in situations where you can be second-guessed"
THAT'S THE KEY TAKEAWAY -- HERE ARE TWO RULES OF THUMB:
(1) Never make comments of an even-remotely sexual nature, joking or otherwise, to anyone, at any time.
In particular, don't so much as hint that a co-worker should go out with you.
You also want to be extremely careful about complimenting anyone's appearance.
Here's why:
* If there ever is a lawsuit, you will be asked, under oath, whether you ever made such comments.
* Moreover, people who work with you are likely to be asked, also under oath, whether they ever heard you make such comments.
* If the answer is yes, you did make such comments, then the jurors will be that much more likely to believe your accuser. Plaintiffs' lawyers know this and will take advantage of it every time.
* If you deny ever having made such comments, but other people said you did, then your credibility will take a serious and possibly-fatal hit --- not a happy event in a he-said / she-said situation.
(2) To the greatest extent possible, avoid being alone with anyone, of either sex and of any age, who might conceivably bring a sexual-harassment charge against you --- you want always to have a neutral witness who could testify in your favor.