
const { useState, useEffect, useRef } = React;

// ── Icons (inline SVG, simple paths only) ───────────────────────────────────
const Icons = {
  Globe: () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>,
  Graduation: () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M22 10v6M2 10l10-5 10 5-10 5z"/><path d="M6 12v5c3 3 9 3 12 0v-5"/></svg>,
  FileCheck: () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><polyline points="9 15 11 17 15 13"/></svg>,
  DollarSign: () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/></svg>,
  ArrowRight: () => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>,
  Check: () => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><polyline points="20 6 9 17 4 12"/></svg>,
  Menu: () => <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>,
  Close: () => <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>,
  User: () => <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>,
  Star: () => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" strokeWidth="1"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>,
  ChevronRight: () => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><polyline points="9 18 15 12 9 6"/></svg>,
  Whatsapp: () => <svg width="26" height="26" viewBox="0 0 24 24" fill="currentColor"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 0 0 5.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 0 0-3.48-8.413z"/></svg>,
};

// ── Button ───────────────────────────────────────────────────────────────────
function Btn({ children, variant = 'primary', size = 'md', onClick, type = 'button', style = {} }) {
  const base = {
    display: 'inline-flex', alignItems: 'center', gap: 8, fontFamily: 'var(--font-body)',
    fontWeight: 600, border: 'none', cursor: 'pointer', transition: 'all 0.2s ease',
    textDecoration: 'none', whiteSpace: 'nowrap',
  };
  const sizes = {
    sm: { padding: '8px 18px', fontSize: 13, borderRadius: 10 },
    md: { padding: '12px 24px', fontSize: 15, borderRadius: 12 },
    lg: { padding: '16px 32px', fontSize: 16, borderRadius: 14 },
  };
  const variants = {
    primary: { background: 'var(--accent)', color: '#fff' },
    secondary: { background: 'transparent', color: 'var(--primary)', border: '1.5px solid var(--primary)' },
    ghost: { background: 'transparent', color: 'var(--primary)' },
    dark: { background: 'var(--primary)', color: '#fff' },
    white: { background: '#fff', color: 'var(--primary)' },
  };
  const [hov, setHov] = useState(false);
  const hovStyle = hov ? { opacity: 0.88, transform: 'translateY(-1px)' } : {};
  return (
    <button type={type} onClick={onClick} onMouseEnter={() => setHov(true)} onMouseLeave={() => setHov(false)}
      style={{ ...base, ...sizes[size], ...variants[variant], ...hovStyle, ...style }}>
      {children}
    </button>
  );
}

// ── Nav ──────────────────────────────────────────────────────────────────────
function Nav({ page, navigate }) {
  const [scrolled, setScrolled] = useState(false);
  const [mobileOpen, setMobileOpen] = useState(false);
  useEffect(() => {
    const handler = () => setScrolled(window.scrollY > 40);
    window.addEventListener('scroll', handler);
    return () => window.removeEventListener('scroll', handler);
  }, []);
  const links = [
    { label: 'Home', page: 'landing' }, { label: 'About', page: 'about' },
    { label: 'Plans', page: 'plans' }, { label: 'Contact', page: 'landing' },
  ];
  const isLight = page === 'landing' && !scrolled;
  const navStyle = {
    position: 'fixed', top: 0, left: 0, right: 0, zIndex: 100,
    background: scrolled || page !== 'landing' ? 'rgba(255,255,255,0.96)' : 'transparent',
    backdropFilter: scrolled ? 'blur(12px)' : 'none',
    borderBottom: scrolled || page !== 'landing' ? '1px solid rgba(0,0,0,0.07)' : 'none',
    transition: 'all 0.3s ease',
    padding: '0 24px',
  };
  const linkColor = isLight ? 'rgba(255,255,255,0.9)' : 'var(--text-muted)';
  return (
    <nav style={navStyle}>
      <div style={{ maxWidth: 1200, margin: '0 auto', height: 68, display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        {/* Logo */}
        <div onClick={() => navigate('landing')} style={{ cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 10 }}>
          <div style={{ width: 36, height: 36, borderRadius: 10, background: 'var(--accent)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#fff', fontFamily: 'var(--font-display)', fontSize: 16, fontWeight: 400 }}>T</div>
          <span style={{ fontFamily: 'var(--font-display)', fontSize: 18, color: isLight ? '#fff' : 'var(--primary)', letterSpacing: '-0.3px' }}>Tureen Ventures</span>
        </div>
        {/* Desktop links */}
        <div style={{ display: 'flex', gap: 36, alignItems: 'center' }} className="nav-desktop">
          {links.map(l => (
            <span key={l.label} onClick={() => navigate(l.page)} style={{ cursor: 'pointer', fontSize: 14, fontWeight: 500, color: page === l.page ? 'var(--accent)' : linkColor, transition: 'color 0.2s' }}>{l.label}</span>
          ))}
        </div>
        {/* Auth buttons */}
        <div style={{ display: 'flex', gap: 10, alignItems: 'center' }} className="nav-desktop">
          <Btn variant="ghost" size="sm" onClick={() => navigate('login')} style={{ color: isLight ? 'rgba(255,255,255,0.9)' : 'var(--text-muted)' }}>Sign In</Btn>
          <Btn variant="primary" size="sm" onClick={() => navigate('signup')}>Get Started</Btn>
        </div>
        {/* Mobile hamburger */}
        <button onClick={() => setMobileOpen(!mobileOpen)} style={{ display: 'none', background: 'none', border: 'none', cursor: 'pointer', color: isLight ? '#fff' : 'var(--primary)', padding: 4 }} className="nav-mobile">
          {mobileOpen ? <Icons.Close /> : <Icons.Menu />}
        </button>
      </div>
      {/* Mobile menu */}
      {mobileOpen && (
        <div style={{ background: '#fff', borderTop: '1px solid rgba(0,0,0,0.07)', padding: '16px 24px 24px' }}>
          {links.map(l => <div key={l.label} onClick={() => { navigate(l.page); setMobileOpen(false); }} style={{ padding: '12px 0', fontSize: 16, fontWeight: 500, color: 'var(--text)', cursor: 'pointer', borderBottom: '1px solid var(--border)' }}>{l.label}</div>)}
          <div style={{ display: 'flex', gap: 12, marginTop: 16 }}>
            <Btn variant="secondary" size="sm" onClick={() => { navigate('login'); setMobileOpen(false); }}>Sign In</Btn>
            <Btn variant="primary" size="sm" onClick={() => { navigate('signup'); setMobileOpen(false); }}>Get Started</Btn>
          </div>
        </div>
      )}
    </nav>
  );
}

// ── Footer ───────────────────────────────────────────────────────────────────
function Footer({ navigate }) {
  return (
    <footer style={{ background: 'var(--primary)', color: 'rgba(255,255,255,0.7)', padding: '64px 24px 32px' }}>
      <div style={{ maxWidth: 1200, margin: '0 auto' }}>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: 40, marginBottom: 48 }}>
          <div>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 16 }}>
              <div style={{ width: 34, height: 34, borderRadius: 9, background: 'var(--accent)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#fff', fontFamily: 'var(--font-display)', fontSize: 15 }}>T</div>
              <span style={{ fontFamily: 'var(--font-display)', fontSize: 17, color: '#fff' }}>Tureen Ventures</span>
            </div>
            <p style={{ fontSize: 13, lineHeight: 1.7, maxWidth: 220 }}>Your trusted partner for overseas education, visa, and immigration services since 2015.</p>
            <p style={{ fontSize: 13, marginTop: 16 }}>📍 New Delhi, India</p>
            <p style={{ fontSize: 13, marginTop: 4 }}>📞 +91-9818797819</p>
            <p style={{ fontSize: 13, marginTop: 4 }}>✉️ tureenventures@gmail.com</p>
          </div>
          {[
            { title: 'Services', links: ['Education Consultancy', 'Visa Services', 'Immigration', 'Forex Services'] },
            { title: 'Destinations', links: ['Study in UK', 'Study in USA', 'Study in Canada', 'Study in Australia', 'Study in Germany'] },
            { title: 'Company', links: ['About Us', 'Our Team', 'Testimonials', 'Plans & Pricing', 'Contact Us'] },
          ].map(col => (
            <div key={col.title}>
              <h4 style={{ color: '#fff', fontWeight: 600, fontSize: 14, marginBottom: 16, textTransform: 'uppercase', letterSpacing: '0.08em' }}>{col.title}</h4>
              {col.links.map(link => <div key={link} style={{ fontSize: 13, marginBottom: 10, cursor: 'pointer', transition: 'color 0.2s' }}>{link}</div>)}
            </div>
          ))}
        </div>
        <div style={{ borderTop: '1px solid rgba(255,255,255,0.12)', paddingTop: 24, display: 'flex', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12, fontSize: 12 }}>
          <span>© 2026 Tureen Ventures. All rights reserved.</span>
          <span>Privacy Policy · Terms of Service</span>
        </div>
      </div>
    </footer>
  );
}

// ── WhatsApp FAB ─────────────────────────────────────────────────────────────
function WhatsAppFAB() {
  const [hov, setHov] = useState(false);
  return (
    <a href="https://wa.me/919818797819" target="_blank" rel="noopener noreferrer"
      onMouseEnter={() => setHov(true)} onMouseLeave={() => setHov(false)}
      style={{
        position: 'fixed', bottom: 28, right: 28, zIndex: 200,
        width: 56, height: 56, borderRadius: '50%',
        background: '#25D366', display: 'flex', alignItems: 'center', justifyContent: 'center',
        color: '#fff', boxShadow: '0 4px 20px rgba(37,211,102,0.45)',
        transform: hov ? 'scale(1.1)' : 'scale(1)',
        transition: 'transform 0.2s ease, box-shadow 0.2s ease',
        textDecoration: 'none',
      }}>
      <Icons.Whatsapp />
      {hov && (
        <div style={{
          position: 'absolute', right: 64, background: 'var(--primary)', color: '#fff',
          fontSize: 12, fontWeight: 500, padding: '6px 12px', borderRadius: 8, whiteSpace: 'nowrap',
          boxShadow: '0 4px 12px rgba(0,0,0,0.15)',
        }}>Chat with us</div>
      )}
    </a>
  );
}

// ── Stat Counter ─────────────────────────────────────────────────────────────
function StatCounter({ end, label, prefix = '', suffix = '+' }) {
  const [count, setCount] = useState(0);
  const ref = useRef(null);
  useEffect(() => {
    const observer = new IntersectionObserver(([entry]) => {
      if (entry.isIntersecting) {
        let start = 0;
        const step = end / 60;
        const timer = setInterval(() => {
          start += step;
          if (start >= end) { setCount(end); clearInterval(timer); }
          else setCount(Math.floor(start));
        }, 20);
        observer.disconnect();
      }
    }, { threshold: 0.3 });
    if (ref.current) observer.observe(ref.current);
    return () => observer.disconnect();
  }, [end]);
  return (
    <div ref={ref} style={{ textAlign: 'center' }}>
      <div style={{ fontFamily: 'var(--font-display)', fontSize: 'clamp(32px, 5vw, 48px)', color: 'var(--primary)', lineHeight: 1 }}>
        {prefix}{count.toLocaleString()}{suffix}
      </div>
      <div style={{ fontSize: 14, color: 'var(--text-muted)', marginTop: 6, fontWeight: 500 }}>{label}</div>
    </div>
  );
}

// ── Section wrapper ───────────────────────────────────────────────────────────
function Section({ children, style = {}, bg }) {
  return (
    <section style={{ padding: 'clamp(48px, 8vw, 96px) 24px', background: bg || 'transparent', ...style }}>
      <div style={{ maxWidth: 1200, margin: '0 auto' }}>{children}</div>
    </section>
  );
}

function SectionLabel({ children }) {
  return (
    <div style={{ display: 'inline-flex', alignItems: 'center', gap: 8, background: 'var(--accent)', color: '#fff', fontSize: 11, fontWeight: 700, padding: '5px 14px', borderRadius: 20, letterSpacing: '0.1em', textTransform: 'uppercase', marginBottom: 16 }}>
      {children}
    </div>
  );
}

// Export everything to window
Object.assign(window, {
  Icons, Btn, Nav, Footer, WhatsAppFAB, StatCounter, Section, SectionLabel,
});
