Colors mismatch between plots and legends on Time Series panel

Colors mismatch between plots and legends on Time Series panel

I am using Grafana version 8.5.10 on Windows 10, Sql Server ad data source.
I have a mismatch between legend (and tootltip) colors and plot colors on Time Series Panel. The colors are different and the right ones are the colors of the plot.

If I re-render the plot (reload page, reload dashboard, close and reopen the corresponding row) all the colors adjust in the right way.
Then if I change the plot in some way (changing time span, changing some dashboard variable values that are included in the queries ect.) the plot changes again its colors in a wrong way.

I have a set of different queries and no Transforms and some overrides on the “standard options”->“Units” field.
The colors scheme selected is “Classic palette” and I think the problem is in the assignment of the colors on classic palette with multiple queries based on the following experiment:
The queries can return or not values depending on a multi value dashboard variable, so it can can have that only the third and the fourth queries have values. If I now manually disable the first and second query (both empty) then the time series always behaves correctly.
It seems that the colors on legend and tooltip are assigned assuming (wrongly) that the empty queries have some values, and the colors of the plot are correctly assigned based only on the query that actually have values.

Thanks