// === BILINGUAL MODAL ===
(function() {
const MODAL_ID = 'bilingual-modal-overlay';
if (document.getElementById(MODAL_ID)) return;
const savedLang = localStorage.getItem('appLang');
if (savedLang) {
document.documentElement.lang = savedLang;
return;
}
const overlay = document.createElement('div');
overlay.id = MODAL_ID;
overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(15,23,42,0.95);z-index:99999;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;';
const logo = document.createElement('div');
logo.textContent = '🌐';
logo.style.cssText = 'font-size:64px;';
const title = document.createElement('h2');
title.textContent = 'Select your language / Elige tu idioma';
title.style.cssText = 'color:white;font-size:22px;text-align:center;font-weight:600;max-width:280px;line-height:1.3;margin:0;';
const btnRow = document.createElement('div');
btnRow.style.cssText = 'display:flex;gap:16px;flex-wrap:wrap;justify-content:center;';
function makeBtn(label, lang) {
const btn = document.createElement('button');
btn.textContent = label;
btn.style.cssText = 'background:linear-gradient(135deg,#6366f1,#8b5cf6);color:white;border:none;border-radius:16px;padding:16px 32px;font-size:18px;font-weight:700;cursor:pointer;min-width:140px;box-shadow:0 4px 20px rgba(99,102,241,0.4);transition:transform 0.15s,box-shadow 0.15s;-webkit-tap-highlight-color:transparent;';
btn.addEventListener('click', function() {
localStorage.setItem('appLang', lang);
document.documentElement.lang = lang;
const mo = document.getElementById(MODAL_ID);
if (mo) mo.style.opacity = '0';
setTimeout(function() { if (mo) mo.remove(); }, 400);
if (window.applyLanguage) window.applyLanguage(lang);
});
btn.addEventListener('mouseenter', function() { this.style.transform = 'scale(1.05)'; this.style.boxShadow = '0 6px 30px rgba(99,102,241,0.6)'; });
btn.addEventListener('mouseleave', function() { this.style.transform = 'scale(1)'; this.style.boxShadow = '0 4px 20px rgba(99,102,241,0.4)'; });
return btn;
}
btnRow.appendChild(makeBtn('🇺🇸 English', 'en'));
btnRow.appendChild(makeBtn('🇲🇽 Español', 'es'));
overlay.appendChild(logo);
overlay.appendChild(title);
overlay.appendChild(btnRow);
document.body.appendChild(overlay);
})();