/**
 * Language switcher.
 *
 * Meant to disappear into the theme's menu. Nothing here sets a font, a
 * size or a text colour on the control itself: every one of those is
 * inherited from the menu item it sits in, so it wears whatever the other
 * items wear. The one surface it draws is the open panel, which needs a
 * background to be read over the page; that background, its text, its
 * border and its corner are custom properties the theme can override on
 * .wptm-lang without touching this file.
 *
 * Logical properties throughout, so the panel opens on the inner side of
 * the header in Arabic as in English.
 */

.wptm-lang {
	--wptm-lang-panel-bg: var(--wptm-lang-bg, #fff);
	--wptm-lang-panel-fg: var(--wptm-lang-fg, #1f2430);
	--wptm-lang-panel-line: var(--wptm-lang-line, rgba(0, 0, 0, 0.08));
	--wptm-lang-panel-hover: var(--wptm-lang-hover, rgba(0, 0, 0, 0.05));
	--wptm-lang-panel-radius: var(--wptm-lang-radius, var(--wptm-radius-sm, 8px));
	--wptm-lang-panel-shadow: var(--wptm-lang-shadow, 0 8px 24px -12px rgba(15, 20, 28, 0.35));
	--wptm-lang-focus: var(--wptm-lang-ring, currentColor);

	position: relative;
	display: inline-flex;
	align-items: center;
	font: inherit;
	color: inherit;
	line-height: inherit;
	max-width: 100%;
}

.wptm-lang,
.wptm-lang * {
	box-sizing: border-box;
}

.wptm-lang__menu,
.wptm-lang__item {
	list-style: none;
	margin: 0;
	padding: 0;
}

.wptm-lang__item::marker {
	content: "";
}

/* The button: text, a globe, a caret. Reset so the theme's button style
 * does not turn it into a call to action. */
.wptm-lang__toggle {
	display: inline-flex;
	align-items: center;
	gap: 0.4em;
	margin: 0;
	padding-block: 0.25em;
	padding-inline: 0.5em;
	border: 0;
	border-radius: var(--wptm-lang-panel-radius);
	background: transparent;
	box-shadow: none;
	font: inherit;
	line-height: inherit;
	letter-spacing: inherit;
	text-transform: inherit;
	color: inherit;
	cursor: pointer;
	white-space: nowrap;
	-webkit-appearance: none;
	appearance: none;
}

.wptm-lang__toggle:hover {
	opacity: 0.8;
}

.wptm-lang__icon {
	display: inline-flex;
	line-height: 0;
	opacity: 0.75;
}

.wptm-lang__icon .wptm-icon {
	width: 1em;
	height: 1em;
}

.wptm-lang__caret {
	display: inline-block;
	width: 0.5em;
	height: 0.5em;
	margin-inline-start: 0.1em;
	border-inline-end: 1.5px solid currentColor;
	border-block-end: 1.5px solid currentColor;
	transform: translateY(-0.15em) rotate(45deg);
	transition: transform 0.18s ease;
	opacity: 0.7;
}

.wptm-lang__toggle[aria-expanded="true"] .wptm-lang__caret {
	transform: translateY(0.1em) rotate(-135deg);
}

/* The panel. Opens on the inner edge of the control and never wider than
 * the longest name in it. */
.wptm-lang--dropdown .wptm-lang__menu {
	position: absolute;
	inset-block-start: calc(100% + 0.35em);
	inset-inline-end: 0;
	z-index: 1001;
	display: flex;
	flex-direction: column;
	min-width: max-content;
	max-width: min(80vw, 18rem);
	padding: 0.35em;
	background: var(--wptm-lang-panel-bg);
	color: var(--wptm-lang-panel-fg);
	border: 1px solid var(--wptm-lang-panel-line);
	border-radius: var(--wptm-lang-panel-radius);
	box-shadow: var(--wptm-lang-panel-shadow);
	text-align: start;
	opacity: 0;
	visibility: hidden;
	transform: translateY(-4px);
	transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

.wptm-lang--dropdown.is-open .wptm-lang__menu,
.wptm-lang--dropdown:not(.has-js):focus-within .wptm-lang__menu {
	opacity: 1;
	visibility: visible;
	transform: none;
}

.wptm-lang--dropdown .wptm-lang__link {
	display: block;
	padding-block: 0.45em;
	padding-inline: 0.85em;
	border-radius: calc(var(--wptm-lang-panel-radius) - 2px);
	font: inherit;
	font-weight: inherit;
	line-height: 1.3;
	color: inherit;
	text-decoration: none;
	white-space: nowrap;
}

.wptm-lang--dropdown a.wptm-lang__link:hover,
.wptm-lang--dropdown a.wptm-lang__link:focus-visible {
	background: var(--wptm-lang-panel-hover);
	color: inherit;
}

/* The flat list, for the mobile menu and the footer. */
.wptm-lang--inline {
	flex-wrap: wrap;
	gap: 0.25em 0.75em;
	max-width: 100%;
}

.wptm-lang--inline .wptm-lang__label {
	display: inline-flex;
	align-items: center;
	line-height: 0;
	opacity: 0.75;
}

.wptm-lang--inline .wptm-lang__menu {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25em 0.25em;
	min-width: 0;
}

.wptm-lang--inline .wptm-lang__link {
	display: inline-flex;
	align-items: center;
	min-height: 2.5em;
	padding-block: 0.25em;
	padding-inline: 0.6em;
	border-radius: var(--wptm-lang-panel-radius);
	font: inherit;
	color: inherit;
	text-decoration: none;
	white-space: nowrap;
}

.wptm-lang--inline a.wptm-lang__link:hover {
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

/* Current and missing, in either shape. */
.wptm-lang__link[aria-current="page"] {
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 0.25em;
	text-decoration-thickness: 1.5px;
}

.wptm-lang__item.is-missing .wptm-lang__link {
	opacity: 0.45;
	cursor: not-allowed;
}

/* Focus. Visible, drawn in the text colour so it reads on any header. */
.wptm-lang__toggle:focus,
.wptm-lang__link:focus {
	outline: none;
}

.wptm-lang__toggle:focus-visible,
.wptm-lang__link:focus-visible {
	outline: 2px solid var(--wptm-lang-focus);
	outline-offset: 2px;
}

/* Inside a theme menu: no inherited item padding on the inner list, and
 * no room for the theme's sub-menu arrow, because there is none. */
.menu-item.wptm-lang-item {
	display: inline-flex;
	align-items: center;
}

.menu-item.wptm-lang-item > .wptm-lang {
	vertical-align: middle;
}

.menu-item.wptm-lang-item .wptm-lang__menu li {
	margin: 0;
	padding: 0;
}

/* The mobile menu variant, when the theme has a menu of its own for it. */
.wptm-lang--mobile.wptm-lang--inline {
	padding-block: 0.5em;
	padding-inline: 0;
}

/* The row after the page footer, when the theme has no footer menu. */
.wptm-lang-bar {
	display: flex;
	justify-content: center;
	padding-block: 0.75em;
	padding-inline: 1rem;
	font-size: 0.9em;
	opacity: 0.85;
}

@media (prefers-reduced-motion: reduce) {
	.wptm-lang--dropdown .wptm-lang__menu,
	.wptm-lang__caret {
		transition: none;
	}
}
