SACRAMENTO, Calif. (AP) — California lawmakers voted Thursday to set rules for the state's nascent marijuana industry and to quash the growth of federal immigration detention as part of a $125 billion state budget lawmakers approved for the next fiscal year.

Lawmakers sent Gov. Jerry Brown a measure merging the state's longstanding medical marijuana law with the much more permissive rules voters approved last year to legalize pot sales to people 21 and older. The state will develop standards for organic marijuana, allow pot samples at county fairs and permit home deliveries.

The Legislature also backed a measure to limit new beds for immigration detention, dealing a blow to the Trump administration's efforts to boost deportation. The measure prevents local governments from signing or expanding contracts with federal authorities for immigration detention facilities. It also calls for the state's attorney general to review conditions at the centers.

The marijuana and immigration provisions are pieces of a one-year budget plan that increases money for education and social services while imposing new financial restrictions on the University of California following a scathing audit. It cleared the Assembly and Senate mostly along party lines with only a handful of Republicans in support.

Brown, a Democrat, has called the budget "balanced and progressive." Legislative Democrats said it would help alleviate poverty while building up savings for a future economic downturn.

"This is a budget that does things for people, not to people," said Assembly Speaker Anthony Rendon. "With this budget we keep our promises to students, patients and voters... In this budget we will protect what we have gained and we will persist in moving forward."

Republicans blasted unrelated measures tucked into the budget, including a plan to change the rules for removing lawmakers from office, which could benefit a Democratic Orange County senator facing a recall. They said the budget fails to adequately prepare for a recession and reneges on promises to voters, who last year approved a tobacco tax increase intended to improve access to health care.

"It's corrosive to continue to break promises," said Senate Minority Leader Pat Bates, R-Laguna Niguel. "Californians were promised better schools, better health care, better roads. Yet this budget falls short on all three counts."

The one-year budget takes effect July 1. The $125 billion figure reflects spending from the general fund — the money over which lawmakers have the most control. Including bonds and special funds, the budget is $183 billion.

Thursday's vote caps weeks of negotiations after Brown, warning of a looming recession and likely federal budget cuts, proposed a budget that reversed spending approved last year and eliminated a middle-class scholarship program. Brown also wanted to use $1.2 billion from a voter-approved tobacco tax increase to cover normal growth in the Medi-Cal program.

He relented on those demands, agreeing to use about half of the tobacco tax money to boost payments for doctors and dentists who care for people on Medi-Cal, the state health plan for the needy.

Brown and lawmakers also agreed to increase funding for after-school care, subsidized child care and legal assistance for immigrants facing deportation. And they restored full dental and eyeglass coverage for people on Medi-Cal.

By law, about half the budget goes to education. Spending on K-12 schools and community colleges is up $3.1 billion from this year, and universities are getting a funding boost tied to increasing enrollment.

The budget seeks to impose reforms on the University of California's budgeting and record-keeping following the release of an April audit found administrators hid tens of millions of dollars from the public as tuition rose. UC President Janet Napolitano disputes the findings, but $50 million will be withheld from the university system until she shows she's complying with the audit.

___

This story has been corrected to show the budget is $125 billion, not $125 million.

___

Associated Press writer Sophia Bollag contributed.