Cardiff City move out of the bottom three thanks to a dramatic last-minute winner against 10-man Brighton.