/* ============================================= NAVBAR — scroll behavior + mobile toggle ============================================= */ (function () { const navbar = document.getElementById('navbar'); const navToggle = document.getElementById('navToggle'); const navLinks = document.getElementById('navLinks'); window.addEventListener('scroll', function () { if (window.scrollY > 40) { navbar.classList.add('scrolled'); } else { navbar.classList.remove('scrolled'); } }, { passive: true }); navToggle.addEventListener('click', function () { navLinks.classList.toggle('open'); }); navLinks.querySelectorAll('a').forEach(function (a) { a.addEventListener('click', function () { navLinks.classList.remove('open'); }); }); // Mobile dropdown toggle var dropdowns = document.querySelectorAll('.nav-dropdown'); dropdowns.forEach(function (dropdown) { var toggle = dropdown.querySelector('.nav-dropdown-toggle'); if (toggle) { toggle.addEventListener('click', function (e) { if (window.innerWidth <= 768) { e.preventDefault(); dropdown.classList.toggle('open'); } }); } }); })(); /* ============================================= HERO SLIDER ============================================= */ (function () { var slides = document.querySelectorAll('.hero-slide'); var dots = document.querySelectorAll('.hero-dot'); var current = 0; var timer; function goTo(index) { slides[current].classList.remove('active'); dots[current].classList.remove('active'); current = (index + slides.length) % slides.length; slides[current].classList.add('active'); dots[current].classList.add('active'); } function next() { goTo(current + 1); } function prev() { goTo(current - 1); } function startTimer() { clearInterval(timer); timer = setInterval(next, 5500); } document.getElementById('heroNext').addEventListener('click', function () { next(); startTimer(); }); document.getElementById('heroPrev').addEventListener('click', function () { prev(); startTimer(); }); dots.forEach(function (dot) { dot.addEventListener('click', function () { goTo(parseInt(this.dataset.index, 10)); startTimer(); }); }); startTimer(); })(); /* ============================================= STATS COUNTER ============================================= */ (function () { var counters = document.querySelectorAll('.stat-number'); var observed = false; function animateCounter(el) { var target = parseInt(el.dataset.target, 10); var duration = 1600; var start = null; function step(timestamp) { if (!start) start = timestamp; var progress = Math.min((timestamp - start) / duration, 1); var eased = 1 - Math.pow(1 - progress, 3); el.textContent = Math.floor(eased * target); if (progress < 1) requestAnimationFrame(step); else el.textContent = target; } requestAnimationFrame(step); } var observer = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting && !observed) { observed = true; counters.forEach(animateCounter); } }); }, { threshold: 0.4 }); var bar = document.querySelector('.stats-bar'); if (bar) observer.observe(bar); })(); /* ============================================= INADIMPLÊNCIA SIMULATOR ============================================= */ (function () { var fatInput = document.getElementById('faturamento'); var inadRange = document.getElementById('inadimplencia'); var inadLabel = document.getElementById('inadimplenciaLabel'); var valMensal = document.getElementById('valMensal'); var valAnual = document.getElementById('valAnual'); var valRecuperaMes = document.getElementById('valRecuperaMes'); var valRecuperaAno = document.getElementById('valRecuperaAno'); var simBarBad = document.getElementById('simBarBad'); var simBarGood = document.getElementById('simBarGood'); if (!fatInput) return; function formatBRL(n) { return 'R$ ' + n.toLocaleString('pt-BR', { minimumFractionDigits: 0, maximumFractionDigits: 0 }); } function parseBRL(str) { return parseInt(str.replace(/\D/g, ''), 10) || 0; } function calculate() { var fat = parseBRL(fatInput.value); var inadPct = parseInt(inadRange.value, 10); var inadValue = fat * inadPct / 100; var recover = inadValue * 0.7; inadLabel.textContent = inadPct + '%'; valMensal.textContent = formatBRL(inadValue); valAnual.textContent = formatBRL(inadValue * 12); valRecuperaMes.textContent = formatBRL(recover); valRecuperaAno.textContent = formatBRL(recover * 12); var badWidth = Math.max(inadPct * 2.5, 6); var goodWidth = Math.max((inadPct * 0.3) * 2.5, 3); simBarBad.style.width = Math.min(badWidth, 100) + '%'; simBarGood.style.width = Math.min(goodWidth, 100) + '%'; } fatInput.addEventListener('input', function () { var digits = this.value.replace(/\D/g, ''); var num = parseInt(digits, 10) || 0; this.value = num.toLocaleString('pt-BR'); calculate(); }); inadRange.addEventListener('input', calculate); calculate(); })(); /* ============================================= DOCUMENT LIVE PREVIEW ============================================= */ (function () { var fields = [ { input: 'docNome', preview: 'previewNome', blank: '_____________________' }, { input: 'docCPF', preview: 'previewCPF', blank: '_____________________' }, { input: 'docServico', preview: 'previewServico', blank: '_____________________' }, { input: 'docValor', preview: 'previewValor', blank: 'R$ _________', prefix: 'R$ ' }, { input: 'docObs', preview: 'previewObs', blank: '—' } ]; var docDataInput = document.getElementById('docData'); var previewData = document.getElementById('previewData'); if (!docDataInput) return; docDataInput.addEventListener('input', function () { if (!this.value) { previewData.textContent = '___/___/______'; return; } var parts = this.value.split('-'); previewData.textContent = parts[2] + '/' + parts[1] + '/' + parts[0]; }); fields.forEach(function (f) { var input = document.getElementById(f.input); var preview = document.getElementById(f.preview); if (!input || !preview) return; input.addEventListener('input', function () { var val = this.value.trim(); if (!val) { preview.textContent = f.blank; return; } preview.textContent = (f.prefix && !val.startsWith(f.prefix)) ? f.prefix + val : val; preview.classList.add('typing-blink'); clearTimeout(preview._t); preview._t = setTimeout(function () { preview.classList.remove('typing-blink'); }, 600); }); }); })(); /* ============================================= SEGMENTS TABS ============================================= */ (function () { var buttons = document.querySelectorAll('.seg-btn'); var panels = document.querySelectorAll('.seg-panel'); buttons.forEach(function (btn) { btn.addEventListener('click', function () { var seg = this.dataset.seg; buttons.forEach(function (b) { b.classList.remove('active'); }); panels.forEach(function (p) { p.classList.remove('active'); }); this.classList.add('active'); var panel = document.querySelector('.seg-panel[data-seg="' + seg + '"]'); if (panel) panel.classList.add('active'); }); }); })(); /* ============================================= SCROLL ANIMATIONS ============================================= */ (function () { var animatables = [ '.service-card', '.case-card', '.sim-card', '.seg-content', '.section-header', '.stat-item', '.contact-left', '.contact-card' ]; var selector = animatables.join(', '); var elements = document.querySelectorAll(selector); elements.forEach(function (el) { el.classList.add('animate-up'); }); var observer = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting) { entry.target.classList.add('visible'); observer.unobserve(entry.target); } }); }, { threshold: 0.1, rootMargin: '0px 0px -40px 0px' }); elements.forEach(function (el) { observer.observe(el); }); })(); /* ============================================= AI AGENT — approve button interaction ============================================= */ (function () { var btn = document.getElementById('aiBtnApprove'); var approvedState = document.getElementById('aiApprovedState'); if (!btn || !approvedState) return; btn.addEventListener('click', function () { var processingBox = btn.closest('.ai-processing-box'); var status = processingBox ? processingBox.querySelector('.ai-proc-status') : null; btn.textContent = '✓ Lançando…'; btn.disabled = true; btn.style.opacity = '0.7'; setTimeout(function () { if (status) status.textContent = 'Lançado no ERP ✓'; if (status) { status.style.color = '#1a8a4a'; status.style.background = 'rgba(26,138,74,.1)'; status.style.animation = 'none'; } approvedState.classList.add('visible'); btn.innerHTML = '✓ Aprovado!'; btn.style.background = '#145e35'; }, 900); setTimeout(function () { btn.disabled = false; btn.style.opacity = '1'; btn.innerHTML = '✓ Aprovar e Lançar'; btn.style.background = ''; approvedState.classList.remove('visible'); if (status) { status.textContent = 'Aguardando aprovação'; status.style.color = ''; status.style.background = ''; status.style.animation = ''; } }, 4500); }); })(); /* ============================================= CONTRACT NUMBER — auto-increment with form interaction ============================================= */ (function () { var contractNum = document.getElementById('previewContractNum'); if (!contractNum) return; var year = new Date().getFullYear(); var seq = 1; contractNum.textContent = year + '/00' + seq; document.querySelectorAll('.doc-form-side input, .doc-form-side textarea').forEach(function (el) { el.addEventListener('focus', function () { seq = Math.floor(Math.random() * 89) + 10; contractNum.textContent = year + '/0' + seq; }); }); })(); /* ============================================= QR CODE VISUAL — dynamic pixel pattern ============================================= */ (function () { var grid = document.getElementById('qrGrid'); if (!grid) return; var size = 7; var cells = ''; for (var i = 0; i < size * size; i++) { var on = Math.random() > 0.45; cells += '
'; } grid.innerHTML = cells; grid.style.display = 'grid'; grid.style.gridTemplateColumns = 'repeat(' + size + ', 1fr)'; grid.style.gap = '1px'; grid.style.backgroundImage = 'none'; })(); /* ============================================= SMOOTH SCROLL for anchor links ============================================= */ (function () { document.querySelectorAll('a[href^="#"]').forEach(function (a) { a.addEventListener('click', function (e) { var target = document.querySelector(this.getAttribute('href')); if (!target) return; e.preventDefault(); var navH = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--nav-h'), 10) || 72; var top = target.getBoundingClientRect().top + window.scrollY - navH; window.scrollTo({ top: top, behavior: 'smooth' }); }); }); })();