#fhalina-popup-overlay {
position: fixed !important; top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.92) !important; z-index: 999999 !important; display: none;
align-items: center; justify-content: center; padding: 20px; font-family: 'Inter', sans-serif !important;
}
/* Wrapper dla złotego koła zamykania */
.fhl-m-wrapper { position: relative !important; width: 100%; max-width: 440px; margin: 20px; }
.fhl-m-body {
background: #1a1a1a !important; border-radius: 20px !important; overflow: hidden !important;
display: flex !important; flex-direction: column !important; max-height: 90vh !important;
border: 1px solid #333 !important; box-sizing: border-box !important;
}
/* Złoty X na zewnątrz */
.fhl-m-close {
position: absolute !important; top: -15px !important; right: -15px !important;
width: 40px !important; height: 40px !important; background: #e4b85f !important;
border-radius: 50% !important; border: none !important; color: #000 !important;
font-size: 24px !important; font-weight: 700 !important; cursor: pointer !important;
z-index: 1002 !important; display: flex !important; align-items: center; justify-content: center;
box-shadow: 0 4px 15px rgba(0,0,0,0.5) !important; line-height: 1 !important;
}
.fhl-m-tabs { display: flex !important; background: #111 !important; width: 100% !important; }
.fhl-m-tab {
flex: 1; padding: 18px 10px; text-align: center; color: #555;
font-family: 'Gotu', serif !important;
font-size: 14px; text-transform: uppercase; cursor: pointer; border-bottom: 2px solid #222;
}
.fhl-m-tab.active { color: #e4b85f !important; background: #1a1a1a !important; border-bottom-color: #e4b85f !important; }
.fhl-m-content {
padding: 25px !important; overflow-y: auto !important;
box-sizing: border-box !important;
}
.fhl-form { display: none; flex-direction: column !important; gap: 12px !important; width: 100% !important; box-sizing: border-box !important; }
.fhl-form.active { display: flex !important; }
/* Gwarancja, że pola nie zostaną obcięte */
.fhl-in {
width: 100% !important;
padding: 12px 15px !important;
background: #000 !important;
border: 1px solid #333 !important;
border-radius: 10px !important;
color: #fff !important;
font-size: 14px !important;
box-sizing: border-box !important;
margin: 0 !important;
}
.fhl-btn-main {
width: 100% !important;
padding: 15px !important;
background: #e4b85f !important;
color: #000 !important;
border: none !important;
border-radius: 50px !important;
font-weight: 700 !important;
text-transform: uppercase !important;
cursor: pointer !important;
margin-top: 5px !important;
box-sizing: border-box !important;
}
/* Wiersze z dwoma polami (NIP+GUS, KOD+MIASTO) */
.fhl-row-half { display: flex !important; gap: 10px !important; width: 100% !important; box-sizing: border-box !important; }
.fhl-row-half .fhl-in { flex: 1 !important; min-width: 0 !important; }
/* Specyficzne ID przycisku POBIERZ, aby nie psuło layoutu */
#r-gus-btn {
background: #e4b85f !important; border: none !important; border-radius: 10px !important;
padding: 0 15px !important; font-weight: 700 !important; cursor: pointer !important;
font-size: 11px !important; color: #000 !important; white-space: nowrap !important;
}
// Logika UI
function closeFhlPopup() { document.getElementById('fhalina-popup-overlay').style.display='none'; document.body.style.overflow=''; }
window.fhalinaOpenLoginPopup = function() { document.getElementById('fhalina-popup-overlay').style.display='flex'; document.body.style.overflow='hidden'; };
function swFhl(m) {
document.getElementById('t-l').classList.toggle('active', m==='l');
document.getElementById('t-r').classList.toggle('active', m==='r');
document.getElementById('fhl-form-l').classList.toggle('active', m==='l');
document.getElementById('fhl-form-r').classList.toggle('active', m==='r');
}
// Obsługa GUS bez ruszania Snippetu 4
document.addEventListener('click', function(e) {
if (e.target && e.target.id === 'r-gus-btn') {
const nip = document.getElementById('r-nip').value.replace(/D/g,'');
if(nip.length !== 10) { alert('Wprowadź 10 cyfr NIP'); return; }
const btn = e.target; btn.innerText = '...';
const fd = new FormData();
fd.append('action', 'fhalina_get_gus_data'); // Akcja ze Snippetu 4
fd.append('nip', nip);
fd.append('nonce', window._fhlGusNonce || '');
fetch('', {method:'POST', body:fd})
.then(r=>r.json()).then(res=>{
btn.innerText = 'POBIERZ';
if(res.success && res.data) {
// Mapowanie danych wg Twojego Snippetu 4
if(document.getElementById('r-comp')) document.getElementById('r-comp').value = res.data.company || res.data.nazwa || '';
if(document.getElementById('r-str')) document.getElementById('r-str').value = res.data.street || res.data.ulica || '';
if(document.getElementById('r-zip')) document.getElementById('r-zip').value = res.data.postcode || res.data.kod || '';
if(document.getElementById('r-cit')) document.getElementById('r-cit').value = res.data.city || res.data.miasto || '';
} else { alert('Nie znaleziono firmy.'); }
}).catch(() => { btn.innerText = 'POBIERZ'; });
}
});
window._fhlAuthNonce = '';
window._fhlGusNonce = '';
// Logika logowania/rejestracji (Snippet 3)
document.getElementById('fhl-form-l').onsubmit = function(e) {
e.preventDefault();
const fd = new FormData(this);
fd.append('action', 'fhl_ajax_login_v7');
fd.append('nonce', window._fhlAuthNonce || '');
fetch('', {method:'POST', body:fd})
.then(r=>r.json()).then(res=>{
if(res.success) location.reload();
else alert(res.data.msg);
});
};
document.getElementById('fhl-form-r').onsubmit = function(e) {
e.preventDefault();
const fd = new FormData(this);
fd.append('action', 'fhl_ajax_register_v7');
fd.append('nonce', window._fhlAuthNonce || '');
fetch('', {method:'POST', body:fd})
.then(r=>r.json()).then(res=>{
if(res.success) location.reload();
else alert(res.data.msg);
});
};