If a student's work has been substantially (>80%) revised, is s/he still qualified as the first author?
There is no hard and fast rule about what exactly qualifies a person for first authorship, which is why it is so often a thorny issue (except in those disciplines where the convention is to always list people alphabetically).  It is also often highly dependent on the particulars of a given situation.  For example, I have had situations like this a number of times and in some cases have ended up keeping the student as first author and in other cases ended up replacing them.  

Accordingly, the principles that I would go by in making such a decision are, from most important to least important:


Did you previously make an agreement about authorship order?  If so, you should almost always respect that agreement.  Renegotiating, even if things have changed significantly, is likely to be coercive to the student given the difference of power between you.
How much work was the non-writing effort?  Advisors are often much, much better at writing than students, and 80% of the writing may be far less than 80% of the work that went into a paper, particularly if the advisor's writing focuses on the "supporting" material like references, introduction, discussion, etc.  If the student has put in a lot of hard work, especially if there has been significant intellectual work, in gathering the data, then I give the student first authorship even if I basically wrote the whole text.
Is the student interested in continuing in academia?  If authorship could be argued either way, and the student has any possible interest in continuing, it's generally better to put them first.  It's a gracious act promoting your proteges and you still gain recognition as the advisor on the paper.


In the end, it is likely that it will not be clear-cut exactly who should be first author.  Personally, I prefer to err in the direction of giving a student too much credit rather than too little, but others may choose otherwise.