/**
 * Anjaneyulu.in — Global Footer v2.0
 * Injected on all pages via <script src="assets/js/footer.js"></script>
 */
document.addEventListener('DOMContentLoaded', () => {
  injectFooter();
  initFloatingWhatsApp();
  initBackToTop();
});

function injectFooter() {
  const footerHTML = `
  <footer class="site-footer">
    <div class="sf-inner container">

      <div class="sf-top">
        <!-- Brand Column -->
        <div class="sf-brand">
          <a href="index.html" class="sf-logo">
            <img src="assets/img/logo.png" alt="Anjaneyulu.in Logo" class="sf-logo-img">
            <div class="sf-logo-wordmark">
              <span class="sf-word-part1">Anjaneyulu</span><span class="sf-word-part2">.in</span>
            </div>
          </a>
          <div class="sf-tagline">Loans &bull; Finance &bull; Technology &bull; Legal &bull; Government &bull; Real Estate</div>
          <p class="sf-about">
            <strong>Anjaneyulu.in (formerly Anjaneyulu Enterprises)</strong><br>
            Providing expert consultancy and end-to-end solutions for Bank Loans, Insurance policies, Government registrations, custom software development, legal document processing, and real estate matchmaking in Hyderabad since 2019.
          </p>
          <div class="sf-socials">
            <a href="https://wa.me/918686095951" target="_blank" class="sf-social-btn sf-wa" aria-label="WhatsApp">
              <i class="fab fa-whatsapp"></i>
            </a>
            <a href="#" class="sf-social-btn sf-fb" aria-label="Facebook"><i class="fab fa-facebook-f"></i></a>
            <a href="#" class="sf-social-btn sf-ig" aria-label="Instagram"><i class="fab fa-instagram"></i></a>
            <a href="#" class="sf-social-btn sf-yt" aria-label="YouTube"><i class="fab fa-youtube"></i></a>
          </div>
        </div>

        <!-- Services Links -->
        <div class="sf-col">
          <h4 class="sf-col-title">Our Services</h4>
          <ul class="sf-links">
            <li><a href="bank-loans.html"><i class="fas fa-hand-holding-dollar"></i> Loans & Finance</a></li>
            <li><a href="finance.html"><i class="fas fa-chart-pie"></i> Insurance & Investment</a></li>
            <li><a href="tech.html"><i class="fas fa-microchip"></i> Tech & Digital</a></li>
            <li><a href="legal.html"><i class="fas fa-scale-balanced"></i> Legal Services</a></li>
            <li><a href="properties.html"><i class="fas fa-building"></i> Properties</a></li>
            <li><a href="govt.html"><i class="fas fa-building-columns"></i> Govt. Registrations</a></li>
          </ul>
        </div>

        <!-- Quick Links -->
        <div class="sf-col">
          <h4 class="sf-col-title">Quick Links</h4>
          <ul class="sf-links">
            <li><a href="about.html"><i class="fas fa-circle-info"></i> About Us</a></li>
            <li><a href="contact.html"><i class="fas fa-phone"></i> Contact Us</a></li>
            <li><a href="join.html"><i class="fas fa-handshake"></i> Join / Partner</a></li>
            <li><a href="emi-calculator.html"><i class="fas fa-calculator"></i> EMI Calculator</a></li>
            <li><a href="request-property.html"><i class="fas fa-search"></i> Property Search</a></li>
            <li><a href="privacy-policy.html"><i class="fas fa-shield-halved"></i> Privacy Policy</a></li>
          </ul>
        </div>

        <!-- Contact Info -->
        <div class="sf-col">
          <h4 class="sf-col-title">Get In Touch</h4>
          <ul class="sf-contact-list">
            <li>
              <div class="sf-contact-icon"><i class="fas fa-phone"></i></div>
              <div>
                <div class="sf-contact-label">Call / WhatsApp</div>
                <a href="tel:+918686095951" class="sf-contact-val">+91 86860 95951</a>
              </div>
            </li>
            <li>
              <div class="sf-contact-icon"><i class="fas fa-envelope"></i></div>
              <div>
                <div class="sf-contact-label">Email Us</div>
                <a href="mailto:support@anjaneyulu.in" class="sf-contact-val">support@anjaneyulu.in</a>
              </div>
            </li>
            <li>
              <div class="sf-contact-icon"><i class="fas fa-location-dot"></i></div>
              <div>
                <div class="sf-contact-label">Office</div>
                <span class="sf-contact-val">Moula Ali, Hyderabad, TS</span>
              </div>
            </li>
            <li>
              <div class="sf-contact-icon"><i class="fas fa-clock"></i></div>
              <div>
                <div class="sf-contact-label">Hours</div>
                <span class="sf-contact-val">Mon–Sat: 9 AM – 8 PM</span>
              </div>
            </li>
          </ul>
          <a href="https://wa.me/918686095951" target="_blank" class="sf-wa-cta">
            <i class="fab fa-whatsapp"></i> Chat on WhatsApp
          </a>
        </div>
      </div>

      <!-- Bottom Bar -->
      <div class="sf-bottom">
        <div class="sf-copyright">
          &copy; ${new Date().getFullYear()} Anjaneyulu.in. All Rights Reserved.
        </div>
        <div class="sf-bottom-links">
          <a href="privacy-policy.html">Privacy Policy</a>
          <span class="sf-dot">·</span>
          <a href="terms.html">Terms of Service</a>
          <span class="sf-dot">·</span>
          <a href="sitemap.html">Sitemap</a>
        </div>
      </div>

    </div>
  </footer>`;

  const footerStyles = `
  <style id="sf-injected-styles">
    .site-footer {
      background: linear-gradient(to bottom, #0F172A 0%, #020617 100%);
      color: #94A3B8;
      margin-top: 5rem;
      position: relative;
      font-family: 'Inter', 'Plus Jakarta Sans', sans-serif;
    }
    .site-footer::before {
      content: '';
      display: block; height: 4px;
      background: linear-gradient(90deg, #001f4d, #d4a017, #001f4d, #d4a017);
    }
    .sf-inner { padding-top: 5rem; }
    .sf-top {
      display: grid;
      grid-template-columns: 1fr;
      gap: 2.5rem;
      padding-bottom: 4rem;
      border-bottom: 1px solid rgba(255,255,255,0.06);
    }
    @media (min-width: 640px) {
      .sf-top { grid-template-columns: repeat(2, 1fr); }
    }
    @media (min-width: 1024px) { 
      .sf-top { grid-template-columns: 2.2fr 1fr 1fr 1.6fr; gap: 3.5rem; } 
    }

    /* Brand */
    .sf-logo {
      display: flex; align-items: center; gap: 12px; margin-bottom: 1.25rem; text-decoration: none;
    }
    .sf-logo-img { height: 48px; width: auto; object-fit: contain; background: #FFFFFF; padding: 6px; border-radius: 8px; display: block; box-shadow: 0 4px 12px rgba(0,0,0,0.25); }
    .sf-logo-wordmark { font-family: 'Plus Jakarta Sans','Inter',sans-serif; font-size: 1.6rem; font-weight: 900; line-height: 1; letter-spacing: -0.02em; }
    .sf-word-part1 { color: #FFFFFF; }
    .sf-word-part2 { color: #D4AF37; }
    .sf-tagline {
      font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
      color: rgba(255,255,255,0.4); margin-bottom: 1.25rem; margin-top: 0.5rem; line-height: 1.4;
    }
    .sf-about { font-size: 0.875rem; line-height: 1.7; max-width: 320px; margin-bottom: 1.5rem; color: #64748B; }
    .sf-socials { display: flex; gap: 0.75rem; }
    .sf-social-btn {
      width: 40px; height: 40px; border-radius: 50%;
      display: flex; align-items: center; justify-content: center;
      font-size: 1rem; text-decoration: none; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
      background: rgba(255,255,255,0.04); color: #94A3B8;
      border: 1px solid rgba(255,255,255,0.05);
    }
    .sf-social-btn:hover { transform: translateY(-3px); border-color: rgba(255,255,255,0.15); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
    .sf-wa:hover { background: #25D366; color: white; border-color: #25D366; }
    .sf-fb:hover { background: #1877F2; color: white; border-color: #1877F2; }
    .sf-ig:hover { background: #E1306C; color: white; border-color: #E1306C; }
    .sf-yt:hover { background: #FF0000; color: white; border-color: #FF0000; }

    /* Columns */
    .sf-col-title {
      font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.15em;
      color: #FFFFFF; margin-bottom: 1.5rem; opacity: 0.9;
    }
    .sf-links { display: flex; flex-direction: column; gap: 0.85rem; list-style: none; }
    .sf-links a {
      display: flex; align-items: center; gap: 0.65rem;
      font-size: 0.875rem; font-weight: 500;
      color: #94A3B8; text-decoration: none;
      transition: all 0.2s ease;
    }
    .sf-links a i { font-size: 0.75rem; opacity: 0.5; width: 14px; transition: transform 0.2s ease; }
    .sf-links a:hover { color: #FFFFFF; }
    .sf-links a:hover i { transform: translateX(2px); opacity: 1; color: #D4AF37; }

    /* Contact */
    .sf-contact-list { display: flex; flex-direction: column; gap: 1.2rem; list-style: none; margin-bottom: 1.5rem; }
    .sf-contact-list li { display: flex; gap: 0.85rem; align-items: flex-start; }
    .sf-contact-icon {
      width: 36px; height: 36px; background: rgba(255,255,255,0.04);
      border-radius: 0.5rem; display: flex; align-items: center; justify-content: center;
      font-size: 0.85rem; color: #94A3B8; flex-shrink: 0; margin-top: 2px;
      border: 1px solid rgba(255,255,255,0.03);
    }
    .sf-contact-label { font-size: 0.65rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: #64748B; margin-bottom: 3px; }
    .sf-contact-val { font-size: 0.875rem; font-weight: 600; color: #E2E8F0; text-decoration: none; display: block; transition: color 0.2s; }
    .sf-contact-val:hover { color: #FFFFFF; }
    .sf-wa-cta {
      display: flex; align-items: center; justify-content: center; gap: 0.6rem;
      padding: 0.85rem 1.5rem; background: #25D366; color: white;
      border-radius: 0.75rem; font-size: 0.875rem; font-weight: 800;
      text-decoration: none; transition: all 0.3s ease; width: 100%;
      box-shadow: 0 4px 14px rgba(37,211,102,0.25);
    }
    .sf-wa-cta:hover { background: #128C7E; transform: translateY(-2px); box-shadow: 0 6px 20px rgba(37,211,102,0.35); }

    /* Bottom Bar */
    .sf-bottom {
      display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
      gap: 1rem; padding: 2rem 0 calc(2rem + env(safe-area-inset-bottom));
      border-top: 1px solid rgba(255,255,255,0.03);
    }
    @media (max-width: 767px) { .sf-bottom { flex-direction: column; text-align: center; } }
    .sf-copyright { font-size: 0.75rem; font-weight: 500; color: #475569; }
    .sf-bottom-links { display: flex; align-items: center; gap: 0.8rem; }
    .sf-bottom-links a { font-size: 0.75rem; font-weight: 500; color: #475569; text-decoration: none; transition: color 0.2s; }
    .sf-bottom-links a:hover { color: #94A3B8; }
    .sf-dot { color: rgba(255,255,255,0.1); }
    
    @media (max-width: 1023px) {
      #floatingWhatsAppBtn { display: none !important; }
    }
  </style>`;

  if (!document.getElementById('sf-injected-styles')) {
    document.head.insertAdjacentHTML('beforeend', footerStyles);
  }
  document.body.insertAdjacentHTML('beforeend', footerHTML);
}

function initBackToTop() {
  const btn = document.createElement('button');
  btn.id = 'backToTopBtn';
  btn.setAttribute('aria-label', 'Back to top');
  btn.innerHTML = '<i class="fas fa-arrow-up"></i>';
  btn.style.cssText = `
    position:fixed; bottom:calc(76px + 64px + env(safe-area-inset-bottom)); right:1rem;
    width:44px; height:44px; background:#001f4d; color:white;
    border:none; border-radius:50%; cursor:pointer;
    display:flex; align-items:center; justify-content:center;
    box-shadow:0 4px 16px rgba(0, 31, 77, 0.35);
    opacity:0; transform:translateY(20px) scale(0.8);
    transition:all 0.3s cubic-bezier(0.175,0.885,0.32,1.275);
    z-index:800; font-size:14px;`;
  document.body.appendChild(btn);

  window.addEventListener('scroll', () => {
    const show = window.scrollY > 400;
    btn.style.opacity = show ? '1' : '0';
    btn.style.transform = show ? 'translateY(0) scale(1)' : 'translateY(20px) scale(0.8)';
    btn.style.pointerEvents = show ? 'auto' : 'none';
  }, { passive: true });

  btn.addEventListener('click', () => window.scrollTo({ top: 0, behavior: 'smooth' }));
}

function initFloatingWhatsApp() {
  const waBtn = document.createElement('a');
  waBtn.id = 'floatingWhatsAppBtn';
  waBtn.setAttribute('aria-label', 'Chat on WhatsApp');
  waBtn.href = 'https://wa.me/918686095951';
  waBtn.target = '_blank';
  waBtn.innerHTML = '<i class="fab fa-whatsapp"></i>';
  waBtn.style.cssText = `
    position:fixed; bottom:calc(76px + env(safe-area-inset-bottom)); right:1rem;
    width:54px; height:54px; background:#25D366; color:white;
    border-radius:50%; display:flex; align-items:center; justify-content:center;
    box-shadow:0 6px 20px rgba(37,211,102,0.4);
    z-index:800; font-size:30px; text-decoration:none;
    transition:transform 0.3s cubic-bezier(0.175,0.885,0.32,1.275), box-shadow 0.3s ease;
  `;
  
  waBtn.addEventListener('mouseenter', () => {
    waBtn.style.transform = 'scale(1.1) translateY(-4px)';
    waBtn.style.boxShadow = '0 10px 24px rgba(37,211,102,0.5)';
  });
  waBtn.addEventListener('mouseleave', () => {
    waBtn.style.transform = 'none';
    waBtn.style.boxShadow = '0 6px 20px rgba(37,211,102,0.4)';
  });

  document.body.appendChild(waBtn);
}
