Note that statusBarColor has no effect in Android 15 and later, as described in: Behavior changes: Apps targeting Android 15 or higher.
In Android 15 it is possible to opt-out edge2edge feature, but in Android 16 and later there is no way to opt-out.
In the beginning I tried to use the same approach as in your post, but there were several issues, so I removed from xml the parameter android:fitsSystemWindows and I implemented the handling of insets using ViewCompat.setOnApplyWindowInsetsListener as described in Display content edge-to-edge in views