MARTINEZ -- In a potentially landmark legal challenge to Gov. Jerry Brown's 2012 pension reform legislation that has financial implications for thousands of public employees and taxpayers, state attorneys Thursday said county retirement systems had illegally included vacation and other types of terminal pay in their members' pension calculations for nearly 15 years.

The state is asking Judge David Flinn to rule that the retirement associations of Contra Costa, Alameda and Merced counties overstepped their legal authority when they granted the perks as part of pension dispute settlements signed in the late 1990s.

Unions at the time had won a major pension lawsuit out of Ventura County, where a judge expanded what was factored into pension formulas.

If Flinn ultimately sides with the state, thousands of not-yet-retired or "legacy" public employees could lose up to a quarter of their future monthly pension payments, depending on their labor contracts. The court's decision will have no direct impact on the paychecks of people who have already retired.

The state's position is part of its response to the November 2012 lawsuit filed by public employee unions challenging the pension reform legislation.

Despite the Ventura County court decision and settlements between public agencies, retirement associations and unions, the practice of adding into retirement formulas unused vacation and other extras -- referred to as terminal pay -- in excess of what a worker would typically earn in a single year "was never allowed in state law," deputy attorney general Anthony O'Brien told the court. The law that governs county-based pensions has been in effect since 1937.

Intended as an anti-spiking measure, Brown's pension reform law specifically prohibited for all public workers who retire on or after Jan. 1, 2013, the inclusion of certain types of pay that exceeded what was earned and payable during the agreed upon calculation period -- typically the highest income year or the highest three-year average. The law also gave county retirement associations authority to reject income as pensionable if it was paid for the sole purpose of increasing the employee's monthly pension check.

Flinn stayed the new pension law pending the outcome of the lawsuit.

Association lawyer Harvey Leiderman rejected the state's position during oral arguments. He said that decades of shifting California pension law has forced association boards to litigate and reach settlements in numerous disputed areas for which the state never previously registered any objections.

"It's been a moving target," Leiderman said.

The unions, in particular, oppose the state's position that retirement associations lacked the legal authority to grant the benefits spelled out in the post-Ventura County settlements.

The agreed upon pension formula is a vested right that courts have long upheld as inviolable once given, labor attorney Peter Saltzman wrote in court briefs. But state lawyers say an illegal benefit cannot be vested.

Flinn gave few clues during his questioning as to how he will rule but put the dozens of attorneys on notice that he wants to finish the high-profile case by mid-December. The separate Alameda, Contra Costa and Merced lawsuits were consolidated into his courtroom. The Marin County case is proceeding on its own, but it could wind up joining the other three cases on appeal.

"I'm going to work seven days a week on this case," Flinn said. "I wanted to be finished (last) April, and it's October. I don't want people to have to keep standing on one foot and then on the other like they have to go potty."

Until recently, Contra Costa, Alameda, Merced and Marin counties permitted workers to accumulate in excess of what they would earn in either a single year or a three-year average of unused vacation, holiday and sick leave, convert the value to cash at the time of retirement and boost their monthly pension check. Contra Costa banned the practice for all new hires starting on Jan. 1, 2011.

Analysts put the value of terminal pay in Contra Costa County at a range of $4 to $24 in additional income out of every $100 in final average wage, one of three factors used to calculate workers' retirement benefit amount. The most generous amount goes to those who retire from the Central Contra Costa Sanitary District, according to the association's 2011 actuarial valuation.

Not every current public employee is eligible for terminal pay.

For vested employees, the perk varies depending on labor contracts negotiated between the agency and each union. Contra Costa County, which is more than 80 percent of the retirement system's rolls, has 15 employee unions.

Other member agencies include the San Ramon, Moraga-Orinda and East Contra Costa fire districts and Contra Costa Superior Court.

Contact Lisa Vorderbrueggen at 925-945-4773. Follow her at Twitter.com/lvorderbrueggen.