/**
 * Instant Language Switcher – frontend styles.
 * Theme-friendly: inherits typography, uses CSS custom properties,
 * supports light/dark, RTL and prefers-reduced-motion.
 */

/* ------------------------------------------------------------------ */
/* Design tokens (overridable via .ils-mode-custom inline variables)   */
/* ------------------------------------------------------------------ */
.ils-switcher {
	--ils-bg: rgba(255, 255, 255, 0.96);
	--ils-bg-hover: rgba(0, 0, 0, 0.05);
	--ils-text: inherit;
	--ils-text-hover: inherit;
	--ils-active: #2271b1;
	--ils-focus: #2271b1;
	--ils-border-color: rgba(0, 0, 0, 0.12);
	--ils-border-w: 1px;
	--ils-radius: 10px;
	--ils-gap: 6px;
	--ils-pad: 8px;
	--ils-font-size: 14px;
	--ils-font-weight: 500;
	--ils-flag-size: 24px;
	--ils-anim-ms: 180ms;
	--ils-dropdown-w: 220px;
	--ils-max-h: 320px;
	--ils-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
	--ils-grid-cols: 3;

	display: inline-flex;
	position: relative;
	font-size: var(--ils-font-size);
	font-weight: var(--ils-font-weight);
	line-height: 1.4;
	color: var(--ils-text);
	font-family: inherit;
	box-sizing: border-box;
}
.ils-switcher *,
.ils-switcher *::before,
.ils-switcher *::after { box-sizing: border-box; }

/* Dark scheme (auto + forced) */
@media (prefers-color-scheme: dark) {
	.ils-switcher:not(.ils-light) {
		--ils-bg: rgba(30, 32, 38, 0.96);
		--ils-bg-hover: rgba(255, 255, 255, 0.08);
		--ils-border-color: rgba(255, 255, 255, 0.14);
		--ils-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
	}
}
.ils-switcher.ils-dark {
	--ils-bg: rgba(30, 32, 38, 0.96);
	--ils-bg-hover: rgba(255, 255, 255, 0.08);
	--ils-border-color: rgba(255, 255, 255, 0.14);
	--ils-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
	color: #eee;
}

/* ------------------------------------------------------------------ */
/* Style presets (active with Custom/Advanced style mode)              */
/* Admin-set colors/values override these: the settings CSS variables  */
/* are printed later in an inline <style> tag.                          */
/* ------------------------------------------------------------------ */
.ils-preset-minimal {
	--ils-border-w: 0px;
	--ils-shadow: none;
	--ils-bg: transparent;
}
.ils-preset-corporate {
	--ils-radius: 6px;
	--ils-active: #1d4ed8;
	--ils-focus: #1d4ed8;
	--ils-border-color: rgba(29, 78, 216, 0.25);
	--ils-font-weight: 600;
}
.ils-preset-luxury {
	--ils-radius: 2px;
	--ils-bg: rgba(20, 18, 16, 0.97);
	--ils-bg-hover: rgba(201, 168, 106, 0.15);
	--ils-text: #e8e0d0;
	--ils-text-hover: #c9a86a;
	--ils-active: #c9a86a;
	--ils-focus: #c9a86a;
	--ils-border-color: rgba(201, 168, 106, 0.4);
	letter-spacing: 0.04em;
}
.ils-preset-glass .ils-trigger,
.ils-preset-glass .ils-panel {
	backdrop-filter: blur(14px);
	-webkit-backdrop-filter: blur(14px);
	background: color-mix(in srgb, var(--ils-bg, #fff) 55%, transparent);
	border-color: rgba(255, 255, 255, 0.35);
}
.ils-preset-dark {
	--ils-bg: rgba(24, 26, 32, 0.97);
	--ils-bg-hover: rgba(255, 255, 255, 0.09);
	--ils-text: #e6e6e6;
	--ils-text-hover: #fff;
	--ils-border-color: rgba(255, 255, 255, 0.15);
	--ils-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.ils-preset-light {
	--ils-bg: #ffffff;
	--ils-bg-hover: #f0f0f1;
	--ils-text: #1e2026;
	--ils-text-hover: #000;
	--ils-border-color: #dcdcde;
	--ils-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}
.ils-preset-compact {
	--ils-pad: 6px;
	--ils-gap: 2px;
	--ils-font-size: 13px;
	--ils-radius: 6px;
}
.ils-preset-compact button { min-height: 32px; }
.ils-preset-rounded {
	--ils-radius: 999px;
}
.ils-preset-rounded .ils-item,
.ils-preset-rounded .ils-trigger { border-radius: 999px; }
.ils-preset-editorial {
	--ils-radius: 0px;
	--ils-border-w: 0px;
	--ils-bg: transparent;
	--ils-shadow: none;
	--ils-font-weight: 500;
	font-family: Georgia, "Times New Roman", serif;
}
.ils-preset-editorial .ils-item.ils-active { text-decoration: underline; text-underline-offset: 4px; }
.ils-preset-ecommerce {
	--ils-radius: 8px;
	--ils-active: #16a34a;
	--ils-focus: #16a34a;
	--ils-font-weight: 600;
}

/*
 * Automatic contrast: JS sets --ils-text inline on the switcher root based
 * on the page background. Panels and triggers paint their OWN background
 * (--ils-bg, driven by color scheme / .ils-dark / .ils-light), so they must
 * NOT inherit the page-level contrast color. Setting the variable directly
 * on these elements overrides the value inherited from the root's inline
 * style. Custom style mode is excluded (admin-chosen colors win).
 */
.ils-switcher:not(.ils-mode-custom) .ils-panel,
.ils-switcher:not(.ils-mode-custom):not(.ils-context-menu) .ils-trigger {
	--ils-text: #1e2026;
	--ils-text-hover: #000;
	color: var(--ils-text);
}
@media (prefers-color-scheme: dark) {
	.ils-switcher:not(.ils-mode-custom):not(.ils-light) .ils-panel,
	.ils-switcher:not(.ils-mode-custom):not(.ils-light):not(.ils-context-menu) .ils-trigger {
		--ils-text: #eaeaea;
		--ils-text-hover: #fff;
	}
}
.ils-switcher.ils-dark:not(.ils-mode-custom) .ils-panel,
.ils-switcher.ils-dark:not(.ils-mode-custom):not(.ils-context-menu) .ils-trigger {
	--ils-text: #eaeaea;
	--ils-text-hover: #fff;
}
.ils-switcher.ils-light:not(.ils-mode-custom) .ils-panel,
.ils-switcher.ils-light:not(.ils-mode-custom):not(.ils-context-menu) .ils-trigger {
	--ils-text: #1e2026;
	--ils-text-hover: #000;
}

/* ------------------------------------------------------------------ */
/* Buttons / items                                                     */
/* ------------------------------------------------------------------ */
.ils-switcher button {
	appearance: none;
	-webkit-appearance: none;
	background: transparent;
	border: 0;
	margin: 0;
	font: inherit;
	color: inherit;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	gap: calc(var(--ils-gap) + 2px);
	padding: calc(var(--ils-pad) * 0.75) var(--ils-pad);
	border-radius: calc(var(--ils-radius) * 0.7);
	min-height: 40px; /* touch target */
	transition: background-color var(--ils-anim-ms) ease, color var(--ils-anim-ms) ease, box-shadow var(--ils-anim-ms) ease;
}
.ils-switcher button:hover { background: var(--ils-bg-hover); color: var(--ils-text-hover); }
.ils-switcher button:focus-visible {
	outline: 2px solid var(--ils-focus);
	outline-offset: 2px;
}
.ils-item.ils-active { color: var(--ils-active); font-weight: 600; }
.ils-item.ils-highlighted { box-shadow: inset 0 0 0 var(--ils-border-w) var(--ils-active); }

/* Flags */
.ils-flag {
	width: var(--ils-flag-size);
	height: var(--ils-flag-size);
	object-fit: cover;
	flex: 0 0 auto;
	display: block;
	box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.ils-flags-circle .ils-flag { border-radius: 50%; }
.ils-flags-square .ils-flag { border-radius: 4px; }
.ils-flags-rectangle .ils-flag { border-radius: 3px; width: calc(var(--ils-flag-size) * 1.4); }

.ils-code { letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.85em; }
.ils-caret { flex: 0 0 auto; opacity: 0.6; transition: transform var(--ils-anim-ms) ease; }
.ils-open .ils-caret { transform: rotate(180deg); }
.ils-globe { flex: 0 0 auto; }

/* ------------------------------------------------------------------ */
/* Flat lists                                                          */
/* ------------------------------------------------------------------ */
.ils-list { display: flex; flex-wrap: wrap; gap: var(--ils-gap); align-items: center; }
.ils-orient-vertical .ils-list,
.ils-style-list-vertical .ils-list { flex-direction: column; align-items: stretch; }
.ils-align-center .ils-list { justify-content: center; }
.ils-align-right .ils-list { justify-content: flex-end; }
.ils-list-item { display: inline-flex; }
.ils-style-list-vertical .ils-item { width: 100%; justify-content: flex-start; }

/* ------------------------------------------------------------------ */
/* Trigger (dropdown / globe / compact)                                */
/* ------------------------------------------------------------------ */
.ils-trigger {
	background: var(--ils-bg);
	border: var(--ils-border-w) solid var(--ils-border-color);
	border-radius: var(--ils-radius);
	box-shadow: var(--ils-shadow);
}
.ils-style-globe .ils-trigger,
.ils-style-compact .ils-trigger { padding: calc(var(--ils-pad) * 0.75); }
.ils-context-menu .ils-trigger { background: transparent; border: 0; box-shadow: none; min-height: 0; }

/* ------------------------------------------------------------------ */
/* Panels (dropdown, grid, popover)                                    */
/* ------------------------------------------------------------------ */
.ils-panel {
	position: absolute;
	top: calc(100% + 8px);
	inset-inline-start: 0;
	min-width: var(--ils-dropdown-w);
	max-height: var(--ils-max-h);
	overflow-y: auto;
	background: var(--ils-bg);
	border: var(--ils-border-w) solid var(--ils-border-color);
	border-radius: var(--ils-radius);
	box-shadow: var(--ils-shadow);
	padding: calc(var(--ils-pad) * 0.75);
	z-index: 100000;
	animation: ils-fade-in var(--ils-anim-ms) ease;
	scrollbar-width: thin;
}
.ils-panel::-webkit-scrollbar { width: 6px; }
.ils-panel::-webkit-scrollbar-thumb { background: var(--ils-border-color); border-radius: 3px; }

/* Floating opening directions */
.ils-open-up .ils-panel { top: auto; bottom: calc(100% + 8px); }
.ils-open-left .ils-panel { inset-inline-start: auto; inset-inline-end: 0; }

.ils-panel-items { display: flex; flex-direction: column; gap: 2px; }
.ils-panel-items .ils-item { width: 100%; justify-content: flex-start; text-align: start; }
.ils-panel-items.ils-grid {
	display: grid;
	grid-template-columns: repeat(var(--ils-grid-cols), minmax(0, 1fr));
	gap: var(--ils-gap);
}
.ils-panel-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: calc(var(--ils-pad) * 0.5) var(--ils-pad);
	font-weight: 600;
}
.ils-panel-footer { border-top: 1px solid var(--ils-border-color); margin-top: 6px; padding-top: 6px; }
.ils-reset { width: 100%; justify-content: center; font-size: 0.9em; opacity: 0.85; }
.ils-close { min-height: 32px; padding: 4px 10px; font-size: 16px; line-height: 1; }

/* Premium dropdown flavour */
.ils-style-dropdown-premium .ils-panel { padding: 8px; border-radius: calc(var(--ils-radius) * 1.2); }
.ils-style-dropdown-premium .ils-item { border-radius: calc(var(--ils-radius) * 0.8); }

/* ------------------------------------------------------------------ */
/* Modal & bottom sheet overlays                                       */
/* ------------------------------------------------------------------ */
.ils-panel-overlay {
	position: fixed;
	z-index: 100001;
	animation: ils-fade-in var(--ils-anim-ms) ease;
}
.ils-style-modal .ils-panel-overlay {
	top: 50%;
	inset-inline-start: 50%;
	transform: translate(-50%, -50%);
	width: min(92vw, 480px);
	max-height: min(80vh, 560px);
}
[dir="rtl"] .ils-style-modal .ils-panel-overlay { transform: translate(50%, -50%); }
.ils-style-bottom-sheet .ils-panel-overlay {
	top: auto;
	bottom: 0;
	left: 0;
	right: 0;
	inset-inline-start: 0;
	width: 100%;
	min-width: 0;
	max-height: 70vh;
	border-radius: var(--ils-radius) var(--ils-radius) 0 0;
	animation: ils-slide-up var(--ils-anim-ms) ease;
	padding-bottom: max(env(safe-area-inset-bottom), 12px);
}
.ils-style-bottom-sheet .ils-panel-items { padding-bottom: 4px; }

/* ------------------------------------------------------------------ */
/* Floating wrapper                                                    */
/* ------------------------------------------------------------------ */
.ils-floating { transition: opacity 200ms ease; }

/* ------------------------------------------------------------------ */
/* Suggestion popup + error toast                                      */
/* ------------------------------------------------------------------ */
.ils-suggest {
	position: fixed;
	bottom: 24px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 100002;
	background: rgba(255, 255, 255, 0.98);
	color: #1e2026;
	border-radius: 12px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
	padding: 16px 20px;
	max-width: min(92vw, 420px);
	font-size: 14px;
	animation: ils-slide-up 240ms ease;
}
.ils-suggest-actions { display: flex; gap: 10px; margin-top: 12px; }
.ils-suggest-actions button {
	flex: 1;
	border: 0;
	border-radius: 8px;
	padding: 9px 14px;
	font: inherit;
	cursor: pointer;
	min-height: 40px;
}
.ils-suggest-yes { background: #2271b1; color: #fff; }
.ils-suggest-no { background: rgba(0, 0, 0, 0.06); color: inherit; }
.ils-error-toast {
	position: fixed;
	bottom: 24px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 100002;
	background: #1e2026;
	color: #fff;
	border-radius: 10px;
	padding: 12px 18px;
	font-size: 14px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
@media (prefers-color-scheme: dark) {
	.ils-suggest { background: rgba(30, 32, 38, 0.98); color: #eee; }
	.ils-suggest-no { background: rgba(255, 255, 255, 0.1); }
}

/* ------------------------------------------------------------------ */
/* Device visibility helpers                                           */
/* .ils-hide-* and .ils-device/.ils-on-* media queries are printed     */
/* dynamically by Assets::print_custom_css using the breakpoints       */
/* configured in the Responsive tab.                                   */
/* ------------------------------------------------------------------ */
.ils-device { display: contents; }

/* ------------------------------------------------------------------ */
/* Google Translate artefacts: kill banner + layout shift              */
/* ------------------------------------------------------------------ */
#ils-gt-host { position: absolute !important; left: -9999px !important; top: -9999px !important; height: 0; overflow: hidden; }
.goog-te-banner-frame,
iframe.skiptranslate,
.goog-te-balloon-frame { display: none !important; }
body { top: 0 !important; }
.goog-text-highlight { background: transparent !important; box-shadow: none !important; }
#goog-gt-tt { display: none !important; }

/* ------------------------------------------------------------------ */
/* Animations & motion preferences                                     */
/* ------------------------------------------------------------------ */
@keyframes ils-fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes ils-slide-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
	.ils-switcher *, .ils-panel, .ils-suggest, .ils-panel-overlay { animation: none !important; transition: none !important; }
}

/* RTL */
[dir="rtl"] .ils-panel { inset-inline-start: auto; inset-inline-end: 0; }

/* Screen-reader helper (in case the theme lacks it) */
.ils-switcher .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	white-space: nowrap;
}
