LONDON (Reuters) - Don't mess with Merkel - that might be the conclusion of some after the German chancellor, not for the first time, saw off a challenge to her leadership.

German Chancellor Angela Merkel and Interior Minister Horst Seehofer arrive for a CDU/CSU meeting in Berlin, July 3, 2018

Bavarian CSU leader Horst Seehofer has withdrawn his threat to resign from her government after a compromise on migrant policy late last night, and Merkel’s coalition is intact for now at least.

Whereas Merkel got backing from her CDU throughout the saga, polls show that Seehofer’s challenge actually lost votes for his party - the opposite of what the whole gambit was designed to do.

Merkel's other coalition partner, the centre-left SPD, said it would look at the deal very closely before deciding whether to give its backing. Given its declining voter base, the last thing it is likely to want is a confrontation with Merkel that could end in bruising early elections.

But all this is not without cost, both to Merkel and the EU. She can argue that the creation of “transit centres” on the German border to detain EU-registered migrants does not contravene the rules of the EU’s borderless Schengen zone.

But the centres, which like "airside zones" in international airports will not be regarded as being in Germany, are nonetheless a concession to the increasingly influential voices across Europe who want to limit people's freedom to move around. For someone like Merkel who grew up behind the Iron Curtain and has staunchly defended that freedom ever since, that is not an optimal result and is further evidence of her waning power.

It will be their last day at work today for about a third of Poland’s Supreme Court judges, who are being forced into retirement by a shake-up of the legal system that comes into effect from midnight.

Brussels says the whole thing is an attempt to undermine the judiciary's independence and has opened an investigation into the rule of law in Poland. That could in theory, lead to sanctions. But as we have said many times here before, that is unlikely to happen as any such actions would be vetoed by Poland's eurosceptic ally, Hungary.

MARKETS AT 0655 GMT

Some calm has returned to world markets as Wall St trading wound down ahead of the U.S. Independence Day holiday on Wednesday, June business surveys there held up smartly and China’s central bank was reported to be directing some stabilisation of the ailing yuan exchange rate via state-owned banks.

The overnight resolution of a row over immigration between the conservative parties in Germany’s coalition government also helped improve the market mood.

The S&P500 closed 0.3 percent higher late Monday, with bellwether tech and internet stocks leading the way. The steadier tone swept through Asia, where Shanghai and other major bourses ended marginally higher after a boneshaking start to the week. The exception was Hong Kong’s Hang Seng, which fell almost 2 percent in catch-up as it reopened after a holiday closure on Monday.

The yuan’s slide through 6.7 per dollar on Tuesday for the first time in almost a year has alarmed many as it’s been widely seen as a sanctioned response to looming U.S. tariffs on some $38 billion of Chinese goods due to come into force on Friday. The yuan regained some of its poise after state-owned banks, which are often directed by the People’s Bank of China, were seen selling dollars in the spot market.

The dilemma for Chinese officials is between allowing a weaker yuan to regain competitiveness hit by the tariffs as monetary policy diverges with the Federal Reserve and keeping the decline orderly without spooking stock and bond markets locally.

On the other hand, heavy intervention to support the yuan may require some rundown of its massive dollar reserves – potentially leading to sales of U.S. Treasury securities. U.S. Treasury yields and dollar/yen were higher first thing. Brent crude oil prices were also firmer just below $78 per barrel.

European stock markets were expected to open higher too, helped by Merkel’s CDU and junior coalition partner CSU reaching a compromise over immigration policy. Euro/dollar was up slightly and euro zone sovereign spreads tightened.

Turkey’s lira weakened against the dollar in early trading, with June Turkish inflation coming in almost twice expectations at 2.6 percent month-on-month. Australia’s central bank left interest rates unchanged as expected.

-- A look at the day ahead from European Economics and Politics Editor Mark John and EMEA markets editor Mike Dolan. The views expressed are their own --