/* AI Language Translator — Frontend Flag Widget */

/* ---- Widget wrapper ---- */
.ailt-flag-widget {
	position: relative;
	display: inline-block;
	font-family: inherit;
	font-size: 14px;
	user-select: none;
	-webkit-user-select: none;
}

/* ---- Trigger button ---- */
.ailt-flag-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	background: transparent;
	border: 1px solid rgba(255,255,255,0.25);
	border-radius: 6px;
	padding: 5px 9px;
	cursor: pointer;
	color: inherit;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.04em;
	transition: background 0.15s, border-color 0.15s;
	line-height: 1;
	white-space: nowrap;
}

.ailt-flag-btn:hover,
.ailt-flag-btn[aria-expanded="true"] {
	background: rgba(255,255,255,0.12);
	border-color: rgba(255,255,255,0.5);
}

/* Light-background contexts */
.widget .ailt-flag-btn,
.sidebar .ailt-flag-btn {
	border-color: #ccc;
	color: #333;
}
.widget .ailt-flag-btn:hover,
.sidebar .ailt-flag-btn[aria-expanded="true"] {
	background: #f0f0f0;
	border-color: #999;
}

.ailt-flag-img {
	display: block;
	border-radius: 2px;
	box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
	object-fit: cover;
	width: 22px;
	height: 15px;
}

.ailt-flag-code {
	text-transform: uppercase;
}

.ailt-flag-caret {
	opacity: 0.65;
	transition: transform 0.2s;
	margin-left: 1px;
}

.ailt-flag-btn[aria-expanded="true"] .ailt-flag-caret {
	transform: rotate(180deg);
}

/* ---- Dropdown panel ---- */
.ailt-flag-dropdown {
	display: none !important;
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	z-index: 99999;
	background: #fff;
	border: 1px solid #ddd;
	border-radius: 8px;
	box-shadow: 0 8px 28px rgba(0,0,0,0.15);
	min-width: 210px;
	max-height: 320px;
	overflow-y: auto;
	padding: 4px 0;
	scroll-behavior: smooth;
}

.ailt-flag-dropdown.ailt-open {
	display: block !important;
	animation: ailt-drop-in 0.15s ease;
}

.ailt-flag-dropdown:not([hidden]) {
	animation: ailt-drop-in 0.15s ease;
}

@keyframes ailt-drop-in {
	from { opacity: 0; transform: translateY(-5px); }
	to   { opacity: 1; transform: translateY(0); }
}

.ailt-flag-dropdown::-webkit-scrollbar { width: 5px; }
.ailt-flag-dropdown::-webkit-scrollbar-track { background: transparent; }
.ailt-flag-dropdown::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }

/* ---- Dropdown items ---- */
.ailt-flag-item {
	display: flex;
	align-items: center;
	gap: 9px;
	padding: 7px 13px;
	cursor: pointer;
	color: #222;
	font-size: 13px;
	transition: background 0.1s;
	outline: none;
}

.ailt-flag-item:hover,
.ailt-flag-item:focus {
	background: #eef4ff;
}

.ailt-flag-item--active {
	background: #eef4ff;
	font-weight: 600;
	color: #1a5aab;
}

.ailt-flag-item--active::after {
	content: '\2713';
	margin-left: auto;
	color: #1a5aab;
	font-size: 12px;
}

.ailt-flag-item--loading {
	opacity: 0.5;
	pointer-events: none;
}

.ailt-flag-divider {
	border-top: 1px solid #eee;
	margin: 3px 0;
}

/* ---- Status bar ---- */
.ailt-flag-status {
	display: none !important;
	margin-top: 7px;
	padding: 6px 10px;
	border-radius: 6px;
	font-size: 12px;
	line-height: 1.5;
}

.ailt-flag-status.ailt-open {
	display: block !important;
}

.ailt-flag-status[data-type="loading"] {
	background: #edf4ff;
	color: #1a5aab;
	display: flex !important;
	align-items: center;
	gap: 7px;
}

.ailt-flag-status[data-type="success"] {
	background: #edfaef;
	color: #1e5c2a;
}

.ailt-flag-status[data-type="error"] {
	background: #fff0f0;
	color: #a32020;
}

/* ---- Spinner ---- */
.ailt-spinner {
	display: inline-block;
	width: 13px;
	height: 13px;
	border: 2px solid rgba(26,90,171,0.25);
	border-top-color: #1a5aab;
	border-radius: 50%;
	animation: ailt-spin 0.65s linear infinite;
	flex-shrink: 0;
}

@keyframes ailt-spin { to { transform: rotate(360deg); } }

/* ---- Content fade while loading ---- */
.ailt-content-translating {
	opacity: 0.4;
	pointer-events: none;
	transition: opacity 0.2s;
}

/* ---- Active-language badge ---- */
#ailt-lang-badge {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	margin: 0 0 12px;
	padding: 3px 10px 3px 7px;
	background: #1a5aab;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	border-radius: 20px;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	cursor: pointer;
	border: none;
	line-height: 1.5;
}
#ailt-lang-badge:hover { background: #154d96; }
#ailt-lang-badge img  { border-radius: 1px; }

.ailt-no-keys { font-size: 12px; color: #a06000; }


/* ---- Selector row ---- */
.ailt-widget__selector {
	position: relative;
	display: flex;
	align-items: center;
	gap: 8px;
}

.ailt-widget__select {
	width: 100%;
	padding: 7px 32px 7px 10px;
	border: 1px solid #ccc;
	border-radius: 6px;
	background-color: #fff;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23555' d='M0 0l6 8 6-8z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 10px center;
	-webkit-appearance: none;
	appearance: none;
	cursor: pointer;
	font-size: 13px;
	color: #333;
	transition: border-color 0.2s, box-shadow 0.2s;
}

.ailt-widget__select:focus {
	outline: none;
	border-color: #2271b1;
	box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.25);
}

/* ---- Status bar ---- */
.ailt-widget__status {
	margin-top: 8px;
	padding: 6px 10px;
	border-radius: 5px;
	font-size: 12px;
	line-height: 1.5;
}

.ailt-widget__status--loading {
	background: #f0f6fc;
	border-left: 3px solid #2271b1;
	color: #2271b1;
	display: flex !important;
	align-items: center;
	gap: 7px;
}

.ailt-widget__status--success {
	background: #edfaef;
	border-left: 3px solid #2fa84f;
	color: #1e4620;
}

.ailt-widget__status--error {
	background: #fef0f0;
	border-left: 3px solid #d63638;
	color: #6a1a1a;
}

/* ---- Spinner ---- */
.ailt-spinner-ring {
	display: inline-block;
	width: 14px;
	height: 14px;
	border: 2px solid rgba(34, 113, 177, 0.3);
	border-top-color: #2271b1;
	border-radius: 50%;
	animation: ailt-spin 0.7s linear infinite;
	flex-shrink: 0;
}

@keyframes ailt-spin {
	to { transform: rotate(360deg); }
}

/* ---- Content overlay while loading ---- */
.ailt-translating-overlay {
	position: relative;
}

.ailt-translating-overlay::after {
	content: '';
	position: absolute;
	inset: 0;
	background: rgba(255, 255, 255, 0.55);
	backdrop-filter: blur(1px);
	z-index: 10;
	border-radius: 4px;
	pointer-events: none;
	transition: opacity 0.3s;
}

/* ---- Language badge shown on the page ---- */
.ailt-lang-indicator {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	margin-bottom: 10px;
	padding: 3px 10px 3px 8px;
	background: #2271b1;
	color: #fff;
	font-size: 11px;
	font-weight: 600;
	border-radius: 20px;
	letter-spacing: 0.04em;
	cursor: pointer;
	border: none;
	text-transform: uppercase;
}

.ailt-lang-indicator:hover {
	background: #1a5a96;
}

.ailt-widget-title-icon {
	margin-right: 3px;
}

/* ---- Auto-injected fixed widget (bottom-right corner) ---- */
/*
 * The widget is rendered directly inside <body> so nothing in the DOM
 * tree should break fixed positioning. All critical layout properties
 * carry !important to survive aggressive theme resets.
 */
#ailt-auto-widget {
	position: fixed !important;
	bottom: 24px !important;
	right: 24px !important;
	top: auto !important;
	left: auto !important;
	z-index: 999999 !important;
	transform: none !important;
	/* ensure the widget itself is block-level and doesn't collapse */
	display: block !important;
	width: auto !important;
	max-width: none !important;
	margin: 0 !important;
	padding: 0 !important;
	background: transparent !important;
	border: none !important;
	box-shadow: none !important;
}

#ailt-auto-widget .ailt-flag-widget {
	position: relative !important;
	display: inline-block !important;
}

#ailt-auto-widget .ailt-flag-btn {
	background: #1a1a2e !important;
	border: 1px solid rgba(255,255,255,0.2) !important;
	color: #fff !important;
	box-shadow: 0 4px 16px rgba(0,0,0,0.35) !important;
}

#ailt-auto-widget .ailt-flag-btn:hover,
#ailt-auto-widget .ailt-flag-btn[aria-expanded="true"] {
	background: #16213e !important;
	border-color: rgba(255,255,255,0.45) !important;
}

/* Dropdown opens upward from the fixed button */
#ailt-auto-widget .ailt-flag-dropdown {
	position: absolute !important;
	bottom: calc(100% + 6px) !important;
	top: auto !important;
	left: auto !important;
	right: 0 !important;
}
