// Shared nav HTML generator
function getNav(activePage) {
  const pages = [
    {href:'index.html', label:'Home'},
    {href:'about.html', label:'About'},
    {href:'services.html', label:'Services'},
    {href:'our-approach.html', label:'Our Approach'},
    {href:'contact.html', label:'Contact'},
  ];
  const links = pages.map(p => 
    `<a href="${p.href}" class="nav-link${activePage===p.href?' active':''}">${p.label}</a>`
  ).join('');
  const mobileLinks = pages.map(p => 
    `<a href="${p.href}" class="nav-link d-block py-2">${p.label}</a>`
  ).join('');
  
  document.querySelector('#main-nav').innerHTML = `
    <div class="container">
      <div class="d-flex align-items-center justify-content-between">
        <a href="index.html" class="navbar-brand-tzr">
          <div class="logo-icon">T</div>
          <div class="logo-text">
            <div class="company-name">TZR Investment Holdings</div>
            <div class="company-sub">Pte. Ltd. · Est. 2012</div>
          </div>
        </a>
        <button id="navToggle" class="d-lg-none" style="background:transparent;border:1px solid rgba(197,151,58,0.4);padding:6px 10px;border-radius:6px;cursor:pointer;">
          <span style="display:block;width:20px;height:2px;background:var(--gold-mid);margin:4px 0;"></span>
          <span style="display:block;width:20px;height:2px;background:var(--gold-mid);margin:4px 0;"></span>
          <span style="display:block;width:20px;height:2px;background:var(--gold-mid);margin:4px 0;"></span>
        </button>
        <div class="d-none d-lg-flex align-items-center gap-1">${links}<a href="contact.html" class="btn-gold ms-3">Apply for Funding</a></div>
      </div>
      <div class="d-lg-none" id="mobileNav" style="display:none;padding:16px 0 8px;">${mobileLinks}<a href="contact.html" class="btn-gold d-inline-block mt-2">Apply for Funding</a></div>
    </div>
  `;
  document.getElementById('navToggle')?.addEventListener('click', () => {
    const mn = document.getElementById('mobileNav');
    mn.style.display = mn.style.display === 'none' ? 'block' : 'none';
  });
}

function initPage(activePage) {
  window.addEventListener('scroll', () => {
    document.querySelector('.navbar-tzr')?.classList.toggle('scrolled', window.scrollY > 50);
  });
  const fadeEls = document.querySelectorAll('.fade-up');
  const obs = new IntersectionObserver((entries) => {
    entries.forEach(e => { if (e.isIntersecting) e.target.classList.add('visible'); });
  }, { threshold: 0.1 });
  fadeEls.forEach(el => obs.observe(el));
}
