CLICK HERE if you are having a problem viewing the photos on a mobile device.

Stacey Sonnenshein got some bad news when she spoke to Contra Costa County planners about making a minor addition to her 60-year-old hillside home.

The county had no record that a decades-old basement apartment, rented to a friend, was built legally. Sonnenshein was told to either evict the tenant or do a renovation that she and her partner couldn’t afford.

Sonnenshein wishes she had never said a word to the county.

“I would tell people to never apply for a permit. Never let them on your property,” said Sonnenshein, a veterinarian in Berkeley. “Don’t engage with them in any way.”

Welcome to the world of gray-market living, a municipal game of “don’t ask, don’t tell” about old converted garages, basement apartments and lived-in backyard studios like Sonnenshein’s built decades ago without permits and considered “uninhabitable” by officials.

State lawmakers, developers and planners have tried to simplify the permitting process and lower fees to encourage new backyard units, known as accessory dwelling units or granny flats, as a relatively cheap and quick attack on the state’s housing shortage and sky-high rents.

But that red-tape cutting hasn’t extended to existing flats. Owners trying to bring older units up to code encounter costly permits and renovations and decide it’s not worth the expense, say advocates, planners and real estate agents.

Most Bay Area cities, including San Jose, don’t have clear directions about bringing ADUs up to code, said Vianey Nava, ADU program manager at Housing Trust Silicon Valley.

“People don’t know what to do,” Nava said. “So nobody bothers to do it.”

The size of the market of unpermitted in-law units in the Bay Area and California is unknown, housing experts say. State lawmakers last year heard estimates that Los Angeles alone has about 300,000 gray-market units.

They often sprout up under a city’s radar and produce healthy incomes for owners in the tight and expensive Silicon Valley rental market. A typical legal one-bedroom goes for $1,770 in Oakland, and $2,090 in San Jose, according to Apartment List.

Granny flats vary in quality, from decades-old home additions or haphazard garage conversions to modern apartments lacking only the proper paperwork for legal occupancy. They can provide a lower-cost alternative for workers, seniors and residents on fixed incomes.

Nava said many owners keep unpermitted units in good shape, but fear the cost of upgrading to the current housing code. State regulations imposed in 2013 require high energy efficiency standards, often expensive on smaller units.

San Jose has considered an amnesty program, she said, but nothing has been set in place.

The quasi-legal apartments even confound real estate agents and property managers.

If a unit is illegal, it can make an owner liable for damage from a fire or other negligence. A new addition or other work requiring city permits can bring a drop-in by a city inspector — blowing the cover of an illegal lease.

“Basically, all it takes is the neighbor to file a complaint,” said Sandy Jamison, a San Jose-based agent who has represented sellers with unpermitted units.

Sometimes an illegal unit makes a property hard to sell, because a new owner would have to bring it up to code or demolish it, she said.

Despite the monthly rent, Jamison said, “it’s actually detracting value.”

Myron Von Raesfeld, CEO of real estate company Windermere Silicon Valley, has brought several properties into compliance. Local cities have been helpful, he said, but new state ADU regulations have slowed the process as city planners learn the new rules.

A client recently asked him for advice on selling a home in San Jose, Von Raesfeld said. The agent researched the property — the owner had added seven bedrooms and bathrooms, filling the backyard and somehow never drawing the attention of neighbors or city inspectors.

The owner made about $10,000 a month renting the units on Airbnb, Von Raesfeld said. He advised the man to tear down the addition, if he wanted to sell.

Von Raesfeld didn’t see it as an isolated case in Santa Clara County. “I think it’s pretty rampant,” he said.

Some cities have tried to wrestle with the problem of grandfathering the units, planners say. A bill sponsored by state Sen. Bob Wieckowski, D-Fremont, would have cleared up some confusion but failed to pass last year.

Sonnenshein and her partner, Adam Bailey, bought their three-bedroom East Richmond home on Felix Avenue in July 2015. The couple paid $700,000 for the hillside rancher, advertised as having a legal in-law unit, she said,

They wanted to add a second bathroom, and interviewed several contractors and architects. Although builders offered to do the work without permits, she said, the couple insisted on keeping the work legal.

They submitted plans to the county. A planner checked the property and judged the 60-year-old apartment to be illegal.

“This is really common,” said Debbie Sanderson, an urban planner and co-founder of Berkeley’s ADU task force who is helping Sonnenshein in her battle, “and it’s coming to a head.”

Sonnenshein believes the two-bedroom, in-law apartment was built legally, around 1955, by the original homeowner. But Contra Costa County has no land use permit — which would make the unit legal — from the 1950s.

Circumstantial evidence suggests the county did know about the unit, Sonnenshein said. She discovered a notation of a work permit for the basement addition — but no actual permit — in public records dated three years after the house was built. The county has long considered it a duplex on tax rolls, and Sonnenshein considers that further proof the county approved the addition.

“If that had been illegal, you don’t invite the assessor in,” Sonnenshein said. “This was never hidden.”

Although county planners acknowledge an incomplete record of permits from the 1950s and 1960s, they say the house needs to be brought up to code.

Stan Muraoka, senior planner for Contra Costa County, said the inspectors were willing to allow the unit if the couple withdrew their request for a second bathroom. Sonnenshein pulled the permits, but a neighbor filed a complaint and the county issued a violation.

“She’s not alone,” Muraoka said. “We haven’t seen people running in to legalize units.”

The case is in limbo, Sonnenshein said. She hopes to prove the unit is legal, and even brought the original home owner’s daughter into the house to verify no major changes had been made since her father built the home.

And she has a stack of planning papers — old drawings, permits, tax records, receipts and a new, red violation notice — growing in her home office. “We did everything by the book,” she said. “If there was an easy way to upgrade, we’d do it.”