QuickBooks frontend utilities may receive nested category values that need to be flattened before rendering or validation. Implement a custom utility that behaves like JavaScript's Array.prototype.flat, without calling built-in prototype methods such as flat, map, reduce, concat, or join.
Given a list containing values or nested lists and a nonnegative integer depth, return a new list in left-to-right order. Flatten a nested list only when the current remaining depth is greater than zero. Non-list values must be copied into the result unchanged. A depth of 0 returns a shallow copy, preserving nested lists as elements.
The implementation should use explicit iteration or recursion and must not mutate the input list.
def flatten_values(values, depth):