Add z-index calculation function