Write a function that parses complex, nested payroll data and calculates total earnings based on varying overtime rules. Implement calculate_total_earnings(payroll), where each payroll node contains employees and optional child nodes; child or employee rules override inherited rules. Rules are ordered cumulative hour brackets, and up_to: null means unlimited hours. Return total earnings rounded to two decimals. Example: 45 hours at $20 with rules 40 hours at 1x and remaining hours at 1.5x returns 950.0. Input is a JSON-compatible dictionary, and output is a number. Constraints: nested depth is at most 100, each node has at most 10,000 employees or children, and rules are ordered with nondecreasing limits.
def calculate_total_earnings(payroll):