Shareholders are the last to be paid in the event of a liquidation (equity is by definition assets minus liabilities) and dividends are not a cost (unlike interest payments).
They are far ahead of the employees though. Employees have no claims on assets (except for unpaid, contractual provisions such as earned wages) in event of a liquidation.
Dividends are a cost to the organization. They are resources that will never be recovered. However, from the point of view of the shareholder it is personal income. If dividends are not a cost to the organization, what are they?
Shareholders are not "far ahead" of employees, because there is no one behind shareholders. Employees get what they are owed before shareholders see a cent. Why should they get more than that? Maybe you think customers should get a piece of the pie, too? Or competitors?
Dividends are the distribution of a part of the profit (or maybe retained earnings, if the current earnings are not enough) to shareholders. Profit is what is left from revenue after costs. Unless you want to redefine the basic accounting terms, dividends cannot be a cost.