/* GALAHOME UI Kit — marketing website components */
/* global React */
const { useState } = React;

const ICONS = {
  search: <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m21 21-4.34-4.34"/><circle cx="11" cy="11" r="8"/></svg>,
  menu: <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M4 5h16"/><path d="M4 12h16"/><path d="M4 19h16"/></svg>,
  mapPin: <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"/><circle cx="12" cy="10" r="3"/></svg>,
  bed: <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M2 4v16"/><path d="M2 8h18a2 2 0 0 1 2 2v10"/><path d="M2 17h20"/><path d="M6 8v9"/></svg>,
  bath: <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M10 4 8 6"/><path d="M17 19v2"/><path d="M2 12h20"/><path d="M7 19v2"/><path d="M9 5 7.621 3.621A2.121 2.121 0 0 0 4 5v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5"/></svg>,
  max: <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3"/><path d="M21 8V5a2 2 0 0 0-2-2h-3"/><path d="M3 16v3a2 2 0 0 0 2 2h3"/><path d="M16 21h3a2 2 0 0 0 2-2v-3"/></svg>,
  house: <svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8"/><path d="M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg>,
  hand: <svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M11 14h2a2 2 0 0 0 0-4h-3c-.6 0-1.1.2-1.4.6L3 16"/><path d="m14.45 13.39 5.05-4.694C20.196 8 21 6.85 21 5.75a2.75 2.75 0 0 0-4.797-1.837.276.276 0 0 1-.406 0A2.75 2.75 0 0 0 11 5.75c0 1.2.802 2.248 1.5 2.946L16 11.95"/><path d="m2 15 6 6"/><path d="m7 20 1.6-1.4c.3-.4.8-.6 1.4-.6h4c1.1 0 2.1-.4 2.8-1.2l4.6-4.4a1 1 0 0 0-2.75-2.91"/></svg>,
  trend: <svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M16 7h6v6"/><path d="m22 7-8.5 8.5-5-5L2 17"/></svg>,
  quote: <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/><path d="M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/></svg>,
  phone: <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"/></svg>,
  mail: <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7"/><rect x="2" y="4" width="20" height="16" rx="2"/></svg>,
  dollar: <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="12" x2="12" y1="2" y2="22"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/></svg>,
  arrow: <span style={{marginLeft:4}}>→</span>,
};

function Header({ current, onNav }) {
  const items = [['propiedades','Propiedades'],['mapa','Mapa'],['calculadoras','Calculadoras'],['nosotros','Nosotros'],['blog','Blog'],['contacto','Contacto']];
  const subItems = [['compradores','Compradores'],['vendedores','Vendedores'],['inversionistas','Inversionistas']];
  const [scrolled, setScrolled] = useState(false);
  const [isMobile, setIsMobile] = useState(false);
  const [menuOpen, setMenuOpen] = useState(false);
  React.useEffect(()=>{
    const onScroll = () => setScrolled(window.scrollY > 8);
    onScroll();
    window.addEventListener('scroll', onScroll, { passive:true });
    const mq = window.matchMedia('(max-width: 768px)');
    const sync = () => setIsMobile(mq.matches);
    sync();
    mq.addEventListener('change', sync);
    return () => { window.removeEventListener('scroll', onScroll); mq.removeEventListener('change', sync); };
  },[]);
  React.useEffect(()=>{
    document.body.style.overflow = menuOpen ? 'hidden' : '';
    return () => { document.body.style.overflow = ''; };
  },[menuOpen]);

  const goTo = (k) => { setMenuOpen(false); onNav(k); };

  if (isMobile) {
    return (
      <React.Fragment>
        <header style={{
          position:'sticky', top:0, zIndex:50,
          background:'rgba(255,255,255,0.95)',
          backdropFilter:'saturate(140%) blur(10px)',
          WebkitBackdropFilter:'saturate(140%) blur(10px)',
          borderBottom: scrolled ? '1px solid rgba(13,43,94,0.08)' : '1px solid transparent',
          transition:'border-color 220ms',
        }}>
          <div style={{display:'grid',gridTemplateColumns:'48px 1fr 48px',alignItems:'center',height:56,padding:'0 8px'}}>
            <button onClick={()=>setMenuOpen(true)} aria-label="Abrir menú"
              style={{border:'none',background:'transparent',cursor:'pointer',padding:12,color:'var(--gh-azul-profundo)',display:'flex',alignItems:'center',justifyContent:'center',borderRadius:8}}>
              {ICONS.menu}
            </button>
            <a onClick={()=>goTo('home')} style={{cursor:'pointer',display:'flex',alignItems:'center',justifyContent:'center'}}>
              <span style={{fontFamily:'var(--gh-font-serif)',fontSize:18,color:'var(--gh-azul-profundo)',letterSpacing:1.2}}>GALAHOME</span>
            </a>
            <a href="tel:+525571224111" aria-label="Llamar"
              style={{display:'flex',alignItems:'center',justifyContent:'center',color:'var(--gh-azul-profundo)',padding:12,borderRadius:8,textDecoration:'none'}}>
              <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"/></svg>
            </a>
          </div>
        </header>

        {menuOpen && (
          <div role="dialog" aria-modal="true"
            style={{
              position:'fixed', inset:0, zIndex:100, background:'#fff',
              display:'flex', flexDirection:'column',
              animation:'gh-menu-in 240ms cubic-bezier(0.2,0.8,0.2,1) both',
            }}>
            <style>{`@keyframes gh-menu-in { from { opacity:0; transform:translateY(-12px) } to { opacity:1; transform:none } }`}</style>
            <div style={{display:'grid',gridTemplateColumns:'48px 1fr 48px',alignItems:'center',height:56,padding:'0 8px',borderBottom:'1px solid rgba(13,43,94,0.06)'}}>
              <button onClick={()=>setMenuOpen(false)} aria-label="Cerrar menú"
                style={{border:'none',background:'transparent',cursor:'pointer',padding:12,color:'var(--gh-azul-profundo)',display:'flex',alignItems:'center',justifyContent:'center',borderRadius:8}}>
                <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
              </button>
              <span style={{fontFamily:'var(--gh-font-serif)',fontSize:18,color:'var(--gh-azul-profundo)',letterSpacing:1.2,textAlign:'center'}}>GALAHOME</span>
              <span/>
            </div>

            <nav style={{flex:1,overflowY:'auto',padding:'12px 24px 24px'}}>
              {items.map(([k,label])=>{
                const active = current===k;
                return (
                  <a key={k} onClick={()=>goTo(k)} style={{
                    cursor:'pointer', display:'flex', alignItems:'center', gap:12,
                    minHeight:56, padding:'12px 4px',
                    fontFamily:'var(--gh-font-serif)', fontSize:30, lineHeight:1.1,
                    color: active ? 'var(--gh-violeta)' : 'var(--gh-azul-profundo)',
                    borderBottom:'1px solid rgba(13,43,94,0.06)',
                  }}>
                    {active && <span style={{width:6,height:6,borderRadius:'50%',background:'var(--gh-violeta)',flexShrink:0}}/>}
                    {label}
                  </a>
                );
              })}

              <div style={{height:1,background:'var(--gh-lavanda)',opacity:0.6,margin:'24px 0 16px'}}/>

              {subItems.map(([k,label])=>(
                <a key={k} onClick={()=>goTo(k)} style={{
                  cursor:'pointer', display:'block',
                  padding:'14px 4px',
                  fontFamily:'var(--gh-font-sans)', fontSize:12, fontWeight:600,
                  letterSpacing:'0.14em', textTransform:'uppercase',
                  color:'var(--gh-gris-carbon)',
                }}>{label}</a>
              ))}
            </nav>

            <div style={{padding:'16px 24px 24px',borderTop:'1px solid rgba(13,43,94,0.06)',background:'#fff'}}>
              <button onClick={()=>goTo('contacto')} style={{
                width:'100%', minHeight:56, border:'none', cursor:'pointer',
                background:'var(--gh-violeta)', color:'#fff',
                fontFamily:'var(--gh-font-sans)', fontSize:16, fontWeight:700,
                borderRadius:12,
              }}>Agenda una visita</button>

              <div style={{display:'flex',flexDirection:'column',gap:8,marginTop:20,fontSize:13,color:'var(--gh-gris-carbon)'}}>
                <a href="tel:+525571224111" style={{display:'flex',alignItems:'center',gap:10,color:'inherit',textDecoration:'none'}}>{ICONS.phone}<span>+52 55 7122 4111</span></a>
                <a href="mailto:contacto@galahome.mx" style={{display:'flex',alignItems:'center',gap:10,color:'inherit',textDecoration:'none'}}>{ICONS.mail}<span>contacto@galahome.mx</span></a>
                <span style={{display:'flex',alignItems:'center',gap:10}}>{ICONS.mapPin}<span>Benito Juárez, CDMX</span></span>
              </div>

              <div style={{display:'flex',gap:16,marginTop:20}}>
                <a href="https://www.instagram.com/galahome/" aria-label="Instagram" style={{color:'var(--gh-azul-profundo)'}}>
                  <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="2" y="2" width="20" height="20" rx="5" ry="5"/><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"/><line x1="17.5" x2="17.51" y1="6.5" y2="6.5"/></svg>
                </a>
                <a href="https://www.facebook.com/profile.php?id=100083097502311" aria-label="Facebook" style={{color:'var(--gh-azul-profundo)'}}>
                  <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M22 12c0-5.52-4.48-10-10-10S2 6.48 2 12c0 4.84 3.44 8.87 8 9.8V15H8v-3h2V9.5C10 7.57 11.57 6 13.5 6H16v3h-2c-.55 0-1 .45-1 1v2h3v3h-3v6.95c5.05-.5 9-4.76 9-9.95z"/></svg>
                </a>
              </div>
            </div>
          </div>
        )}
      </React.Fragment>
    );
  }

  return (
    <header style={{
      position:'sticky', top:0, zIndex:50,
      background:'rgba(255,255,255,0.92)',
      backdropFilter:'saturate(140%) blur(10px)',
      WebkitBackdropFilter:'saturate(140%) blur(10px)',
      borderBottom: scrolled ? '1px solid rgba(13,43,94,0.08)' : '1px solid transparent',
      boxShadow: scrolled ? '0 1px 2px rgba(13,43,94,0.04)' : 'none',
      transition:'border-color 220ms, box-shadow 220ms',
    }}>
      <div style={{maxWidth:1200,margin:'0 auto',display:'flex',alignItems:'center',justifyContent:'space-between',padding:'16px 24px',gap:32}}>
        {/* Brand */}
        <a onClick={()=>onNav('home')} style={{cursor:'pointer',display:'flex',alignItems:'center',gap:12,flexShrink:0}}>
          <img src="/assets/gh-logo-silver-256.png" alt="GALAHOME" style={{width:80,height:80,objectFit:'contain',flexShrink:0}}/>
          <div style={{display:'flex',flexDirection:'column',lineHeight:1}}>
            <span style={{fontFamily:'var(--gh-font-serif)',fontSize:22,color:'var(--gh-azul-profundo)',letterSpacing:1}}>GALAHOME</span>
            <span style={{fontFamily:'var(--gh-font-serif)',fontStyle:'italic',fontSize:10,color:'var(--gh-violeta)',letterSpacing:2,marginTop:2}}>Real Estate</span>
          </div>
        </a>

        {/* Nav */}
        <nav style={{display:'flex',gap:28,alignItems:'center'}}>
          {items.map(([k,label])=>{
            const active = current===k;
            return (
              <a key={k} onClick={()=>onNav(k)} style={{
                cursor:'pointer', position:'relative',
                fontSize:14, fontWeight: active ? 600 : 500,
                color: active ? 'var(--gh-azul-profundo)' : 'var(--gh-gris-carbon)',
                paddingBottom:4,
                transition:'color 200ms',
              }}
              onMouseEnter={e=>{ if(!active) e.currentTarget.style.color='var(--gh-violeta)'; }}
              onMouseLeave={e=>{ if(!active) e.currentTarget.style.color='var(--gh-gris-carbon)'; }}>
                {label}
                {active && <span style={{position:'absolute',left:0,right:0,bottom:-2,height:2,background:'var(--gh-violeta)',borderRadius:2}}/>}
              </a>
            );
          })}
        </nav>

        {/* Actions: Comprar (primary) · Vender (ghost) · Search · Contacto */}
        <div style={{display:'flex',gap:8,alignItems:'center',flexShrink:0}}>
          <BuySellPills onNav={onNav} current={current}/>
          <button onClick={()=>onNav('propiedades')} aria-label="Buscar"
            style={{border:'none',background:'transparent',cursor:'pointer',padding:8,color:'var(--gh-azul-profundo)',display:'flex',alignItems:'center',justifyContent:'center',borderRadius:8,transition:'background 180ms'}}
            onMouseEnter={e=>e.currentTarget.style.background='var(--gh-blanco-frio)'}
            onMouseLeave={e=>e.currentTarget.style.background='transparent'}>
            {ICONS.search}
          </button>
        </div>
      </div>
    </header>
  );
}

/* Pills "Comprar / Vender" — paired segmented control that lives inside the header.
   Comprar = filled violet (primary intent), Vender = outline (secondary).
   Subtle, brand-aligned, replaces the heavy dark ActionBar that broke the page. */
function BuySellPills({ onNav, current }) {
  const buyActive = current === 'propiedades';
  return (
    <div style={{display:'inline-flex',alignItems:'center',gap:6,padding:4,borderRadius:999,background:'var(--gh-blanco-frio)',border:'1px solid rgba(13,43,94,0.06)'}}>
      <button onClick={()=>onNav('propiedades')}
        style={{
          display:'inline-flex',alignItems:'center',gap:8,
          padding:'8px 16px',borderRadius:999,border:0,cursor:'pointer',
          fontFamily:'inherit',fontSize:13,fontWeight:600,letterSpacing:'.01em',
          background:'var(--gh-violeta)',color:'#fff',
          boxShadow: buyActive ? '0 4px 12px rgba(138,70,206,0.28)' : '0 1px 2px rgba(138,70,206,0.18)',
          transition:'background 180ms, box-shadow 180ms, transform 120ms',
        }}
        onMouseEnter={e=>{ e.currentTarget.style.background='var(--gh-violeta-900)'; e.currentTarget.style.boxShadow='0 6px 16px rgba(138,70,206,0.32)'; }}
        onMouseLeave={e=>{ e.currentTarget.style.background='var(--gh-violeta)'; e.currentTarget.style.boxShadow= buyActive ? '0 4px 12px rgba(138,70,206,0.28)' : '0 1px 2px rgba(138,70,206,0.18)'; }}
        onMouseDown={e=>e.currentTarget.style.transform='translateY(1px)'}
        onMouseUp={e=>e.currentTarget.style.transform='none'}>
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8"/><path d="M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg>
        Comprar
      </button>
      <button onClick={()=>onNav('contacto')}
        style={{
          display:'inline-flex',alignItems:'center',gap:8,
          padding:'8px 16px',borderRadius:999,cursor:'pointer',
          fontFamily:'inherit',fontSize:13,fontWeight:600,letterSpacing:'.01em',
          background:'transparent',color:'var(--gh-azul-profundo)',
          border:'1px solid transparent',
          transition:'background 180ms, border-color 180ms, color 180ms, transform 120ms',
        }}
        onMouseEnter={e=>{ e.currentTarget.style.background='#fff'; e.currentTarget.style.borderColor='var(--gh-lavanda)'; e.currentTarget.style.color='var(--gh-violeta)'; }}
        onMouseLeave={e=>{ e.currentTarget.style.background='transparent'; e.currentTarget.style.borderColor='transparent'; e.currentTarget.style.color='var(--gh-azul-profundo)'; }}
        onMouseDown={e=>e.currentTarget.style.transform='translateY(1px)'}
        onMouseUp={e=>e.currentTarget.style.transform='none'}>
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="m3 11 18-8-8 18-2-8-8-2Z"/></svg>
        Vender
      </button>
    </div>
  );
}

/* ActionBar kept as a no-op so existing screens that mount it continue to render
   without an extra dark band. The buy/sell affordances now live in <Header/>. */
function ActionBar() { return null; }

function Footer({ onNav }) {
  const go = (s) => (e) => { e.preventDefault(); if (onNav) onNav(s); window.scrollTo(0,0); };
  const linkStyle = {
    cursor:'pointer',color:'rgba(255,255,255,0.7)',textDecoration:'none',transition:'color 180ms',display:'inline-block',
  };
  const onHoverIn  = (e) => { e.currentTarget.style.color = '#fff'; };
  const onHoverOut = (e) => { e.currentTarget.style.color = 'rgba(255,255,255,0.7)'; };

  const contactItem = (icon, content, href) => (
    <a href={href} target={href.startsWith('http') ? '_blank' : undefined} rel={href.startsWith('http') ? 'noopener' : undefined}
       style={{...linkStyle,display:'flex',alignItems:'flex-start',gap:10,lineHeight:1.5}}
       onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>
      <span style={{flexShrink:0,marginTop:2,color:'var(--gh-lavanda, #C4A8E8)'}}>{icon}</span>
      <span>{content}</span>
    </a>
  );

  const socialBtn = (href, label, svg) => (
    <a href={href} target="_blank" rel="noopener" aria-label={label}
       style={{width:38,height:38,borderRadius:'50%',border:'1px solid rgba(255,255,255,0.2)',display:'flex',alignItems:'center',justifyContent:'center',color:'rgba(255,255,255,0.85)',transition:'all 180ms',textDecoration:'none'}}
       onMouseEnter={e=>{e.currentTarget.style.background='var(--gh-violeta)';e.currentTarget.style.borderColor='var(--gh-violeta)';e.currentTarget.style.color='#fff';e.currentTarget.style.transform='translateY(-2px)';}}
       onMouseLeave={e=>{e.currentTarget.style.background='transparent';e.currentTarget.style.borderColor='rgba(255,255,255,0.2)';e.currentTarget.style.color='rgba(255,255,255,0.85)';e.currentTarget.style.transform='none';}}>
      {svg}
    </a>
  );

  const dirEncoded = encodeURIComponent('Av. Río Churubusco 601, Xoco, Benito Juárez, 03330 Ciudad de México, CDMX');

  return (
    <footer style={{background:'var(--gh-azul-profundo)',color:'#fff',marginTop:80}}>
      <div style={{maxWidth:1152,margin:'0 auto',padding:'72px 24px 0'}}>
        <div style={{display:'grid',gridTemplateColumns:'1.6fr 1fr 1fr 1fr',gap:48}}>

          {/* Marca + contacto */}
          <div>
            <div>
              <div style={{fontFamily:'var(--gh-font-serif)',fontSize:24,letterSpacing:2}}>GALAHOME</div>
              <div style={{fontFamily:'var(--gh-font-serif)',fontStyle:'italic',fontSize:11,color:'var(--gh-lavanda, #C4A8E8)',letterSpacing:3,marginTop:2}}>Real Estate</div>
            </div>
            <p style={{marginTop:14,fontSize:13,color:'rgba(255,255,255,0.55)',lineHeight:1.6,maxWidth:300}}>
              Inmobiliaria en CDMX. Acompañamiento integral en compra, venta y renta — con asesoría legal incluida.
            </p>
            <div style={{marginTop:24,display:'flex',flexDirection:'column',gap:12,fontSize:13.5}}>
              {contactItem(ICONS.mapPin, <>Av. Río Churubusco 601, Xoco,<br/>Benito Juárez, 03330 CDMX</>, `https://www.google.com/maps/search/?api=1&query=${dirEncoded}`)}
              {contactItem(ICONS.phone, '+52 55 7122 4111', 'tel:+525571224111')}
              {contactItem(ICONS.phone, '+52 55 8083 3802', 'tel:+525580833802')}
              {contactItem(ICONS.mail, 'contacto@galahome.mx', 'mailto:contacto@galahome.mx')}
            </div>
            <div style={{marginTop:24,display:'flex',gap:10}}>
              {socialBtn('https://www.instagram.com/galahome/', 'Instagram',
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect width="20" height="20" x="2" y="2" rx="5" ry="5"/><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"/><line x1="17.5" x2="17.51" y1="6.5" y2="6.5"/></svg>
              )}
              {socialBtn('https://www.facebook.com/profile.php?id=100083097502311', 'Facebook',
                <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M22 12c0-5.52-4.48-10-10-10S2 6.48 2 12c0 4.84 3.44 8.87 8 9.8V15H8v-3h2V9.5C10 7.57 11.57 6 13.5 6H16v3h-2c-.55 0-1 .45-1 1v2h3v3h-3v6.95c5.05-.5 9-4.76 9-9.95z"/></svg>
              )}
              {socialBtn('https://wa.me/525571224111?text=Hola%20GALAHOME', 'WhatsApp',
                <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M17.6 6.32A7.86 7.86 0 0 0 12.05 4 7.95 7.95 0 0 0 4.1 11.94a7.9 7.9 0 0 0 1.06 3.96L4 20l4.22-1.11a7.94 7.94 0 0 0 3.82.97h.01a7.95 7.95 0 0 0 7.94-7.94 7.88 7.88 0 0 0-2.39-5.6zm-5.55 12.22h-.01a6.6 6.6 0 0 1-3.36-.92l-.24-.14-2.5.66.67-2.44-.16-.25a6.59 6.59 0 0 1-1.01-3.51A6.6 6.6 0 0 1 12.06 5.34a6.55 6.55 0 0 1 4.66 1.93 6.55 6.55 0 0 1 1.93 4.66 6.6 6.6 0 0 1-6.6 6.61zm3.62-4.95c-.2-.1-1.18-.58-1.36-.65-.18-.07-.31-.1-.45.1-.13.2-.51.65-.63.78-.11.13-.23.15-.43.05-.2-.1-.85-.31-1.62-1-.6-.53-1-1.19-1.12-1.39-.11-.2-.01-.31.09-.41.09-.09.2-.23.3-.35.1-.12.13-.2.2-.33.07-.13.03-.25-.02-.35-.05-.1-.45-1.08-.61-1.48-.16-.39-.33-.34-.45-.34l-.39-.01a.75.75 0 0 0-.54.25c-.18.2-.71.7-.71 1.7s.73 1.97.83 2.1c.1.13 1.43 2.18 3.46 3.06.48.21.86.33 1.16.43.49.15.93.13 1.28.08.39-.06 1.18-.48 1.35-.95.17-.46.17-.86.12-.94-.05-.08-.18-.13-.38-.23z"/></svg>
              )}
            </div>
          </div>

          {/* Navegación */}
          <div>
            <div style={{fontWeight:700,fontSize:13,marginBottom:20,letterSpacing:'.08em',textTransform:'uppercase'}}>Navegación</div>
            <div style={{display:'flex',flexDirection:'column',gap:12,fontSize:14}}>
              <a href="#" onClick={go('home')}         style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Inicio</a>
              <a href="#" onClick={go('propiedades')}  style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Propiedades</a>
              <a href="#" onClick={go('calculadoras')} style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Calculadoras</a>
              <a href="#" onClick={go('nosotros')}     style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Nosotros</a>
              <a href="#" onClick={go('blog')}         style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Blog</a>
              <a href="#" onClick={go('contacto')}     style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Contacto</a>
            </div>
          </div>

          {/* Servicios */}
          <div>
            <div style={{fontWeight:700,fontSize:13,marginBottom:20,letterSpacing:'.08em',textTransform:'uppercase'}}>Servicios</div>
            <div style={{display:'flex',flexDirection:'column',gap:12,fontSize:14}}>
              <a href="#" onClick={go('propiedades')}  style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Compra</a>
              <a href="#" onClick={go('contacto')}     style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Venta</a>
              <a href="#" onClick={go('contacto')}     style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Renta</a>
              <a href="#" onClick={go('calculadoras')} style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Crédito hipotecario</a>
              <a href="#" onClick={go('calculadoras')} style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>ROI inversión</a>
              <a href="#" onClick={go('contacto')}     style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Asesoría legal</a>
            </div>
          </div>

          {/* Legal */}
          <div>
            <div style={{fontWeight:700,fontSize:13,marginBottom:20,letterSpacing:'.08em',textTransform:'uppercase'}}>Legal</div>
            <div style={{display:'flex',flexDirection:'column',gap:12,fontSize:14}}>
              <a href="#aviso-privacidad" onClick={go('aviso-privacidad')} style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Aviso de privacidad</a>
              <a href="#aviso-privacidad" onClick={go('aviso-privacidad')} style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Términos y condiciones</a>
              <a href="#aviso-privacidad" onClick={go('aviso-privacidad')} style={linkStyle} onMouseEnter={onHoverIn} onMouseLeave={onHoverOut}>Política de cookies</a>
            </div>
          </div>

        </div>

        {/* Bottom bar */}
        <div style={{borderTop:'1px solid rgba(255,255,255,0.1)',marginTop:56,padding:'22px 0',display:'flex',justifyContent:'space-between',alignItems:'center',flexWrap:'wrap',gap:12,fontSize:12,color:'rgba(255,255,255,0.5)'}}>
          <div>© 2026 GALAHOME Real Estate. Todos los derechos reservados.</div>
          <div>Hecho con cuidado en CDMX · galahome.mx</div>
        </div>
      </div>
    </footer>
  );
}

function WhatsAppFAB() {
  const [hover, setHover] = React.useState(false);
  const phone = '525571224111'; // GALAHOME WhatsApp
  const msg = encodeURIComponent('Hola GALAHOME, me interesa saber más sobre sus propiedades.');
  return (
    <a href={`https://wa.me/${phone}?text=${msg}`} target="_blank" rel="noopener" aria-label="Chatear por WhatsApp"
       onMouseEnter={()=>setHover(true)} onMouseLeave={()=>setHover(false)}
       style={{
         position:'fixed', right:24, bottom:24, zIndex:60,
         display:'flex', alignItems:'center', gap:10,
         background:'#25D366', color:'#fff',
         padding: hover ? '14px 20px 14px 14px' : '14px',
         borderRadius:999,
         boxShadow:'0 8px 24px rgba(37,211,102,0.45), 0 2px 6px rgba(0,0,0,0.15)',
         textDecoration:'none', fontFamily:'inherit', fontWeight:600, fontSize:14,
         transition:'padding 220ms cubic-bezier(.2,.9,.3,1.2)',
         overflow:'hidden',
       }}>
      <svg width="26" height="26" viewBox="0 0 24 24" fill="currentColor" style={{flexShrink:0}}><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 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-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 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.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 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/></svg>
      {hover && <span style={{whiteSpace:'nowrap'}}>Chatea con nosotros</span>}
    </a>
  );
}

function PropertyCard({ data, onClick }) {
  return (
    <a onClick={onClick} style={{cursor:'pointer',display:'block'}}>
      <div style={{overflow:'hidden',borderRadius:12,border:'1px solid #F3F4F6',boxShadow:'var(--gh-shadow-sm)',background:'#fff',transition:'box-shadow 220ms'}}
           onMouseEnter={e=>e.currentTarget.style.boxShadow='var(--gh-shadow-lg)'}
           onMouseLeave={e=>e.currentTarget.style.boxShadow='var(--gh-shadow-sm)'}>
        <div style={{position:'relative',height:208,overflow:'hidden'}}>
          <img src={data.img} alt={data.title} style={{width:'100%',height:'100%',objectFit:'cover',transition:'transform 600ms cubic-bezier(.2,.8,.2,1)'}}
            onMouseEnter={e=>e.currentTarget.style.transform='scale(1.05)'}
            onMouseLeave={e=>e.currentTarget.style.transform='scale(1)'}/>
          <div style={{position:'absolute',inset:0,background:'linear-gradient(180deg, rgba(0,0,0,0) 60%, rgba(0,0,0,0.35) 100%)',pointerEvents:'none'}}/>
          <span style={{position:'absolute',left:12,top:12,background: data.status==='En Preventa' ? '#D97706' : 'rgba(13,43,94,0.92)',color:'#fff',fontSize:11,padding:'5px 12px',borderRadius:999,fontWeight:600,letterSpacing:'.04em',backdropFilter:'blur(6px)',boxShadow:'0 2px 8px rgba(0,0,0,0.18)'}}>{data.status}</span>
          <span style={{position:'absolute',right:12,top:12,background:'rgba(255,255,255,0.92)',color:'var(--gh-azul-profundo)',fontFamily:'var(--gh-font-serif)',fontSize:13,fontWeight:600,padding:'5px 12px',borderRadius:999,backdropFilter:'blur(6px)',boxShadow:'0 2px 8px rgba(0,0,0,0.12)'}}>{data.price}</span>
          {/* Marca de agua */}
          <div aria-hidden="true" style={{position:'absolute',bottom:10,right:12,display:'flex',flexDirection:'column',alignItems:'center',gap:2,opacity:0.55,filter:'drop-shadow(0 1px 4px rgba(0,0,0,0.5))',pointerEvents:'none',userSelect:'none'}}>
            <img src="/assets/gh-logo-silver-256.png" alt="" style={{width:54,height:54,objectFit:'contain',display:'block'}}/>
            <span style={{fontFamily:'var(--gh-font-serif)',fontSize:9,fontWeight:600,letterSpacing:'0.28em',color:'#fff',textShadow:'0 1px 3px rgba(0,0,0,0.6)',whiteSpace:'nowrap',marginTop:-2}}>GALAHOME</span>
          </div>
        </div>
        <div style={{padding:'18px 18px 20px'}}>
          <div style={{fontSize:11,color:'var(--gh-violeta)',textTransform:'uppercase',letterSpacing:'.08em',fontWeight:700,marginBottom:6}}>{data.type}</div>
          <div style={{fontFamily:'var(--gh-font-serif)',fontSize:18,color:'var(--gh-azul-profundo)',lineHeight:1.25,letterSpacing:'-0.005em'}}>{data.title}</div>
          <div style={{fontSize:13,color:'rgba(28,28,30,0.6)',marginTop:6,display:'flex',alignItems:'center',gap:5}}>{ICONS.mapPin}{data.loc}</div>
          <div style={{marginTop:14,paddingTop:14,borderTop:'1px solid #F1F2F5',display:'flex',gap:18,fontSize:12.5,color:'rgba(28,28,30,0.7)'}}>
            <span style={{display:'flex',alignItems:'center',gap:5}}>{ICONS.bed}<span><strong style={{color:'var(--gh-azul-profundo)'}}>{data.bed}</strong> rec</span></span>
            <span style={{display:'flex',alignItems:'center',gap:5}}>{ICONS.bath}<span><strong style={{color:'var(--gh-azul-profundo)'}}>{data.bath}</strong> baño</span></span>
            <span style={{display:'flex',alignItems:'center',gap:5}}>{ICONS.max}<span><strong style={{color:'var(--gh-azul-profundo)'}}>{data.area}</strong> m²</span></span>
          </div>
        </div>
      </div>
    </a>
  );
}

function HeroFilters({ open, onClose, onApply }) {
  const [op, setOp]         = useState('comprar');
  const [precio, setPrecio] = useState('cualquiera');
  const [recs, setRecs]     = useState('cualquiera');
  const [banos, setBanos]   = useState('cualquiera');
  const [m2Min, setM2Min]   = useState(0);
  const [m2Max, setM2Max]   = useState(400);
  const [zonas, setZonas]   = useState([]);
  const [tipo, setTipo]     = useState('cualquiera');

  const PRECIO_COMPRA = [
    { key:'cualquiera', label:'Cualquiera' },
    { key:'0-3M',       label:'Hasta $3M' },
    { key:'3-6M',       label:'$3M – $6M' },
    { key:'6-10M',      label:'$6M – $10M' },
    { key:'10-15M',     label:'$10M – $15M' },
    { key:'15M+',       label:'$15M+' },
  ];
  const PRECIO_RENTA = [
    { key:'cualquiera', label:'Cualquiera' },
    { key:'0-15K',      label:'Hasta $15K' },
    { key:'15-25K',     label:'$15K – $25K' },
    { key:'25-40K',     label:'$25K – $40K' },
    { key:'40-60K',     label:'$40K – $60K' },
    { key:'60K+',       label:'$60K+' },
  ];
  const ZONAS = ['Del Valle','Narvarte','Coyoacán','Mixcoac','Xoco','Portales','Mitikah'];
  const TIPOS = [
    { key:'cualquiera', label:'Cualquiera' },
    { key:'depto',      label:'Departamento' },
    { key:'casa',       label:'Casa' },
    { key:'penthouse',  label:'Penthouse' },
    { key:'loft',       label:'Loft' },
  ];
  const NUMS = ['cualquiera','1','2','3','4+'];

  const toggleZona = (z) => setZonas(arr => arr.includes(z) ? arr.filter(x=>x!==z) : [...arr, z]);
  const reset = () => { setOp('comprar'); setPrecio('cualquiera'); setRecs('cualquiera'); setBanos('cualquiera'); setM2Min(0); setM2Max(400); setZonas([]); setTipo('cualquiera'); };

  if (!open) return null;

  const seg = (val, setVal, opts) => (
    <div style={{display:'flex',gap:6,flexWrap:'wrap'}}>
      {opts.map(o => {
        const k = typeof o === 'string' ? o : o.key;
        const lbl = typeof o === 'string' ? (o==='cualquiera' ? 'Cualquiera' : o) : o.label;
        const active = val === k;
        return (
          <button key={k} type="button" onClick={()=>setVal(k)}
            style={{padding:'9px 14px',borderRadius:999,border: active ? '1px solid var(--gh-azul-profundo)' : '1px solid #E5E7EB',background: active ? 'var(--gh-azul-profundo)' : '#fff',color: active ? '#fff' : 'var(--gh-gris-carbon)',fontWeight:600,fontSize:12.5,cursor:'pointer',fontFamily:'inherit',transition:'all 160ms'}}>
            {lbl}
          </button>
        );
      })}
    </div>
  );

  const precioOpts = op === 'rentar' ? PRECIO_RENTA : PRECIO_COMPRA;

  return (
    <div onClick={onClose} style={{position:'fixed',inset:0,zIndex:300,background:'rgba(13,43,94,0.55)',backdropFilter:'blur(4px)',display:'flex',alignItems:'center',justifyContent:'center',padding:24,animation:'pm-fade 180ms'}}>
      <div onClick={e=>e.stopPropagation()}
        style={{background:'#fff',borderRadius:18,maxWidth:640,width:'100%',maxHeight:'90vh',overflowY:'auto',boxShadow:'0 30px 60px -12px rgba(13,43,94,0.45)',position:'relative',animation:'pm-lift 220ms cubic-bezier(.2,.9,.3,1.2)'}}>

        <div style={{padding:'28px 32px 18px',borderBottom:'1px solid #EEF0F3',display:'flex',alignItems:'center',justifyContent:'space-between',position:'sticky',top:0,background:'#fff',zIndex:2,borderRadius:'18px 18px 0 0'}}>
          <div>
            <div style={{fontSize:11,letterSpacing:'.16em',textTransform:'uppercase',fontWeight:700,color:'var(--gh-violeta)'}}>Filtros</div>
            <h3 style={{fontFamily:'var(--gh-font-serif)',fontSize:24,color:'var(--gh-azul-profundo)',margin:'4px 0 0'}}>Refina tu búsqueda</h3>
          </div>
          <button onClick={onClose}
            style={{width:36,height:36,borderRadius:999,background:'#F4F7FA',border:0,cursor:'pointer',display:'flex',alignItems:'center',justifyContent:'center',color:'var(--gh-azul-profundo)',fontSize:20}}>×</button>
        </div>

        <div style={{padding:'24px 32px',display:'flex',flexDirection:'column',gap:24}}>

          {/* Operación */}
          <div>
            <div style={{fontSize:11,letterSpacing:'.10em',textTransform:'uppercase',fontWeight:700,color:'rgba(28,28,30,0.55)',marginBottom:10}}>Operación</div>
            <div style={{display:'flex',gap:6,padding:4,background:'var(--gh-blanco-frio)',borderRadius:10}}>
              {[{k:'comprar',l:'Comprar'},{k:'rentar',l:'Rentar'}].map(o=>(
                <button key={o.k} type="button" onClick={()=>{ setOp(o.k); setPrecio('cualquiera'); }}
                  style={{flex:1,padding:'11px 12px',border:0,borderRadius:8,background: op===o.k ? '#fff' : 'transparent',color: op===o.k ? 'var(--gh-azul-profundo)' : 'rgba(28,28,30,0.6)',fontWeight:700,fontSize:14,cursor:'pointer',boxShadow: op===o.k ? 'var(--gh-shadow-sm)' : 'none',fontFamily:'inherit',transition:'all 180ms'}}>
                  {o.l}
                </button>
              ))}
            </div>
          </div>

          {/* Precio */}
          <div>
            <div style={{fontSize:11,letterSpacing:'.10em',textTransform:'uppercase',fontWeight:700,color:'rgba(28,28,30,0.55)',marginBottom:10}}>{op==='rentar' ? 'Renta mensual' : 'Precio'}</div>
            {seg(precio, setPrecio, precioOpts)}
          </div>

          {/* Tipo */}
          <div>
            <div style={{fontSize:11,letterSpacing:'.10em',textTransform:'uppercase',fontWeight:700,color:'rgba(28,28,30,0.55)',marginBottom:10}}>Tipo de propiedad</div>
            {seg(tipo, setTipo, TIPOS)}
          </div>

          {/* Recámaras / baños */}
          <div style={{display:'grid',gridTemplateColumns:'1fr 1fr',gap:24}}>
            <div>
              <div style={{fontSize:11,letterSpacing:'.10em',textTransform:'uppercase',fontWeight:700,color:'rgba(28,28,30,0.55)',marginBottom:10}}>Recámaras</div>
              {seg(recs, setRecs, NUMS)}
            </div>
            <div>
              <div style={{fontSize:11,letterSpacing:'.10em',textTransform:'uppercase',fontWeight:700,color:'rgba(28,28,30,0.55)',marginBottom:10}}>Baños</div>
              {seg(banos, setBanos, NUMS)}
            </div>
          </div>

          {/* m² */}
          <div>
            <div style={{display:'flex',justifyContent:'space-between',alignItems:'baseline',marginBottom:10}}>
              <div style={{fontSize:11,letterSpacing:'.10em',textTransform:'uppercase',fontWeight:700,color:'rgba(28,28,30,0.55)'}}>Metros cuadrados</div>
              <div style={{fontSize:13,color:'var(--gh-azul-profundo)',fontWeight:700}}>{m2Min} – {m2Max}{m2Max>=400?'+':''} m²</div>
            </div>
            <div style={{display:'grid',gridTemplateColumns:'1fr 1fr',gap:14}}>
              <div>
                <label style={{fontSize:11,color:'rgba(28,28,30,0.55)',display:'block',marginBottom:4}}>Mínimo</label>
                <input type="range" min={0} max={400} step={10} value={m2Min} onChange={e=>setM2Min(Math.min(Number(e.target.value), m2Max))} style={{width:'100%',accentColor:'var(--gh-violeta)'}}/>
              </div>
              <div>
                <label style={{fontSize:11,color:'rgba(28,28,30,0.55)',display:'block',marginBottom:4}}>Máximo</label>
                <input type="range" min={0} max={400} step={10} value={m2Max} onChange={e=>setM2Max(Math.max(Number(e.target.value), m2Min))} style={{width:'100%',accentColor:'var(--gh-violeta)'}}/>
              </div>
            </div>
          </div>

          {/* Zonas */}
          <div>
            <div style={{fontSize:11,letterSpacing:'.10em',textTransform:'uppercase',fontWeight:700,color:'rgba(28,28,30,0.55)',marginBottom:10}}>Zonas <span style={{textTransform:'none',letterSpacing:0,fontWeight:400,color:'rgba(28,28,30,0.5)',marginLeft:6}}>(múltiple)</span></div>
            <div style={{display:'flex',flexWrap:'wrap',gap:6}}>
              {ZONAS.map(z=>{
                const active = zonas.includes(z);
                return (
                  <button key={z} type="button" onClick={()=>toggleZona(z)}
                    style={{padding:'9px 14px',borderRadius:999,border: active ? '1px solid var(--gh-violeta)' : '1px solid #E5E7EB',background: active ? 'rgba(138,70,206,0.10)' : '#fff',color: active ? 'var(--gh-violeta)' : 'var(--gh-gris-carbon)',fontWeight:600,fontSize:12.5,cursor:'pointer',fontFamily:'inherit',transition:'all 160ms'}}>
                    {active ? '✓ ' : ''}{z}
                  </button>
                );
              })}
            </div>
          </div>
        </div>

        {/* Footer del modal */}
        <div style={{padding:'18px 32px 28px',borderTop:'1px solid #EEF0F3',display:'flex',gap:12,alignItems:'center',justifyContent:'space-between',position:'sticky',bottom:0,background:'#fff',borderRadius:'0 0 18px 18px'}}>
          <button onClick={reset} type="button"
            style={{background:'transparent',border:0,color:'rgba(28,28,30,0.6)',fontWeight:600,fontSize:13,cursor:'pointer',fontFamily:'inherit',textDecoration:'underline'}}>
            Limpiar filtros
          </button>
          <button type="button" onClick={()=>onApply({op,precio,recs,banos,m2Min,m2Max,zonas,tipo})}
            style={{padding:'14px 28px',border:0,borderRadius:999,background:'var(--gh-violeta)',color:'#fff',fontWeight:700,fontSize:14,cursor:'pointer',fontFamily:'inherit'}}>
            Ver propiedades
          </button>
        </div>
      </div>
    </div>
  );
}

function Hero({ onSearch, onNav }) {
  const imgs = [
    '/assets/propiedades/city-park-grand-p17/amenidad-01.jpg',
    '/assets/propiedades/mitikah-loft-p44/amenidad-01.jpg',
    '/assets/propiedades/city-towers-coyoacan/amenidad-01.webp',
  ];
  const [idx, setIdx] = useState(0);
  const [filtersOpen, setFiltersOpen] = useState(false);
  const [query, setQuery] = useState('');
  React.useEffect(()=>{const t=setInterval(()=>setIdx(i=>(i+1)%imgs.length),5000);return()=>clearInterval(t);},[]);

  const apply = (filters) => {
    setFiltersOpen(false);
    if (onNav) onNav('propiedades');
    else onSearch && onSearch();
  };

  return (
    <section style={{position:'relative',height:'78vh',minHeight:560,display:'flex',alignItems:'center',justifyContent:'center',overflow:'hidden'}}>
      {imgs.map((src,i)=>(
        <div key={i} style={{position:'absolute',inset:0,transition:'opacity 1200ms ease',opacity: i===idx ? 1 : 0,transform: i===idx ? 'scale(1.04)' : 'scale(1)',transitionProperty:'opacity, transform',transitionDuration:'1200ms, 8000ms'}}>
          <img src={src} alt="" style={{width:'100%',height:'100%',objectFit:'cover'}}/>
        </div>
      ))}
      <div style={{position:'absolute',inset:0,background:'linear-gradient(135deg, rgba(13,43,94,0.78) 0%, rgba(13,43,94,0.55) 45%, rgba(138,70,206,0.42) 100%)'}}/>
      <div style={{position:'absolute',inset:0,background:'linear-gradient(180deg, rgba(13,43,94,0) 60%, rgba(13,43,94,0.35) 100%)'}}/>
      <div style={{position:'relative',zIndex:10,maxWidth:920,padding:'0 24px',textAlign:'center',color:'#fff'}}>
        <div style={{display:'inline-flex',alignItems:'center',gap:8,padding:'6px 14px',borderRadius:999,background:'rgba(255,255,255,0.12)',border:'1px solid rgba(255,255,255,0.22)',backdropFilter:'blur(6px)',fontSize:12,letterSpacing:'.14em',textTransform:'uppercase',fontWeight:600,marginBottom:24}}>
          <span style={{width:6,height:6,borderRadius:'50%',background:'var(--gh-lavanda, #C4A8E8)'}}/>
          Inmobiliaria en CDMX
        </div>
        <h1 style={{fontFamily:'var(--gh-font-serif)',fontSize:64,lineHeight:1.04,letterSpacing:'-0.01em',margin:0,marginBottom:20}}>Tu próximo hogar en CDMX,<br/><span style={{fontStyle:'italic',color:'var(--gh-lavanda, #C4A8E8)'}}>sin trabas.</span></h1>
        <p style={{fontSize:18,lineHeight:1.55,color:'rgba(255,255,255,0.86)',marginBottom:36,maxWidth:580,marginLeft:'auto',marginRight:'auto'}}>Compra, venta y renta con asesoría legal incluida y reporte de mercado en cada propiedad.</p>
        <form onSubmit={e=>{e.preventDefault();onSearch();}} style={{background:'#fff',borderRadius:999,boxShadow:'var(--gh-shadow-xl)',padding:6,maxWidth:680,margin:'0 auto',display:'flex',alignItems:'center',gap:6}}>
          <input value={query} onChange={e=>setQuery(e.target.value)}
            placeholder="Colonia, zona o nombre de propiedad…"
            style={{flex:1,border:0,padding:'14px 20px',fontSize:14,background:'transparent',outline:'none',color:'var(--gh-gris-carbon)'}}/>
          <button type="button" onClick={()=>setFiltersOpen(true)}
            aria-label="Abrir filtros"
            style={{display:'flex',alignItems:'center',gap:8,padding:'12px 18px',border:'1px solid #EEF0F3',borderRadius:999,background:'#fff',color:'var(--gh-azul-profundo)',fontWeight:600,fontSize:13,cursor:'pointer',fontFamily:'inherit',whiteSpace:'nowrap',flexShrink:0,transition:'all 160ms'}}
            onMouseEnter={e=>{e.currentTarget.style.background='var(--gh-blanco-frio)';e.currentTarget.style.borderColor='var(--gh-violeta)';}}
            onMouseLeave={e=>{e.currentTarget.style.background='#fff';e.currentTarget.style.borderColor='#EEF0F3';}}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><line x1="4" y1="6" x2="20" y2="6"/><line x1="7" y1="12" x2="17" y2="12"/><line x1="10" y1="18" x2="14" y2="18"/></svg>
            Filtros
          </button>
          <button type="submit" className="gh-btn gh-btn-primary" style={{padding:'14px 28px',fontSize:14,justifyContent:'center',borderRadius:999,whiteSpace:'nowrap',flexShrink:0}}>Buscar</button>
        </form>
      </div>
      {/* Slide indicators */}
      <div style={{position:'absolute',bottom:32,left:'50%',transform:'translateX(-50%)',zIndex:10,display:'flex',gap:8,alignItems:'center'}}>
        {imgs.map((_,i)=>(
          <button key={i} onClick={()=>setIdx(i)} aria-label={`Foto ${i+1}`}
            style={{width: i===idx ? 24 : 8,height:8,borderRadius:999,border:0,padding:0,cursor:'pointer',
                    background: i===idx ? '#fff' : 'rgba(255,255,255,0.45)',
                    transition:'all 300ms cubic-bezier(.2,.8,.2,1)',flexShrink:0}}/>
        ))}
      </div>
      <HeroFilters open={filtersOpen} onClose={()=>setFiltersOpen(false)} onApply={apply}/>
    </section>
  );
}

function FeatureGrid() {
  const feats = [
    {ic:ICONS.house, t:'Portafolio curado', p:'Inventario verificado en zonas de alta plusvalía de la CDMX. Cada propiedad pasa por un check de documentación antes de publicarse.'},
    {ic:ICONS.hand,  t:'Asesoría legal incluida', p:'Acompañamiento end-to-end: revisión de escrituras, gravámenes y contratos sin costo adicional para compradores y vendedores.'},
    {ic:ICONS.trend, t:'Inteligencia de mercado', p:'Reporte de precio por m², ROI estimado y contexto de zona en cada propiedad. Decisiones con datos, no con corazonadas.'},
  ];
  return (
    <section style={{background:'var(--gh-blanco-frio)',padding:'96px 24px'}}>
      <div style={{maxWidth:1152,margin:'0 auto'}}>
        <div style={{textAlign:'center',marginBottom:56}}>
          <div style={{display:'inline-block',fontSize:11,letterSpacing:'.18em',textTransform:'uppercase',fontWeight:700,color:'var(--gh-violeta)',marginBottom:14}}>Por qué GALAHOME</div>
          <h2 style={{fontFamily:'var(--gh-font-serif)',fontSize:42,lineHeight:1.1,letterSpacing:'-0.01em',color:'var(--gh-azul-profundo)',margin:0,maxWidth:680,marginInline:'auto'}}>Tres compromisos que cambian la forma de comprar o vender</h2>
        </div>
        <div style={{display:'grid',gridTemplateColumns:'repeat(3,1fr)',gap:24}}>
          {feats.map((f,i)=>(
            <div key={i}
              style={{position:'relative',background:'#fff',border:'1px solid #ECEEF2',borderRadius:16,padding:'36px 28px 32px',transition:'transform 280ms cubic-bezier(.2,.8,.2,1), box-shadow 280ms, border-color 280ms',boxShadow:'0 1px 2px rgba(13,43,94,0.04)'}}
              onMouseEnter={e=>{e.currentTarget.style.transform='translateY(-4px)';e.currentTarget.style.boxShadow='0 18px 40px -18px rgba(13,43,94,0.22)';e.currentTarget.style.borderColor='var(--gh-lavanda, #C4A8E8)';}}
              onMouseLeave={e=>{e.currentTarget.style.transform='none';e.currentTarget.style.boxShadow='0 1px 2px rgba(13,43,94,0.04)';e.currentTarget.style.borderColor='#ECEEF2';}}>
              <div style={{position:'absolute',top:18,right:20,fontFamily:'var(--gh-font-serif)',fontSize:32,color:'rgba(13,43,94,0.08)',fontStyle:'italic',lineHeight:1}}>0{i+1}</div>
              <div style={{width:56,height:56,borderRadius:14,background:'linear-gradient(135deg, rgba(138,70,206,0.14) 0%, rgba(196,168,232,0.18) 100%)',display:'flex',alignItems:'center',justifyContent:'center',color:'var(--gh-violeta)',marginBottom:20}}>
                {React.cloneElement(f.ic, { width:28, height:28 })}
              </div>
              <h3 style={{fontFamily:'var(--gh-font-serif)',fontSize:22,fontWeight:600,color:'var(--gh-azul-profundo)',margin:'0 0 10px',letterSpacing:'-0.005em'}}>{f.t}</h3>
              <p style={{fontSize:14.5,lineHeight:1.65,color:'rgba(28,28,30,0.7)',margin:0}}>{f.p}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function Testimonial({ q, name, role }) {
  return (
    <div style={{position:'relative',borderRadius:16,background:'#fff',padding:'32px 28px 28px',boxShadow:'0 1px 2px rgba(13,43,94,0.04)',border:'1px solid #ECEEF2',transition:'transform 280ms cubic-bezier(.2,.8,.2,1), box-shadow 280ms'}}
      onMouseEnter={e=>{e.currentTarget.style.transform='translateY(-3px)';e.currentTarget.style.boxShadow='0 18px 40px -18px rgba(13,43,94,0.22)';}}
      onMouseLeave={e=>{e.currentTarget.style.transform='none';e.currentTarget.style.boxShadow='0 1px 2px rgba(13,43,94,0.04)';}}>
      <div style={{position:'absolute',top:-14,left:24,width:42,height:42,borderRadius:'50%',background:'linear-gradient(135deg, var(--gh-violeta) 0%, #6B2EA8 100%)',color:'#fff',display:'flex',alignItems:'center',justifyContent:'center',boxShadow:'0 6px 16px rgba(138,70,206,0.35)'}}>
        {React.cloneElement(ICONS.quote, { width:20, height:20 })}
      </div>
      <p style={{fontSize:15,lineHeight:1.65,color:'rgba(28,28,30,0.78)',marginTop:14,marginBottom:24,fontStyle:'italic'}}>&ldquo;{q}&rdquo;</p>
      <div style={{display:'flex',alignItems:'center',gap:12,paddingTop:16,borderTop:'1px solid #F1F2F5'}}>
        <div style={{width:42,height:42,borderRadius:999,background:'linear-gradient(135deg, rgba(138,70,206,0.18) 0%, rgba(196,168,232,0.25) 100%)',color:'var(--gh-violeta)',display:'flex',alignItems:'center',justifyContent:'center',fontWeight:700,fontFamily:'var(--gh-font-serif)',fontSize:18}}>{name[0]}</div>
        <div>
          <div style={{fontSize:14,fontWeight:700,color:'var(--gh-azul-profundo)'}}>{name}</div>
          <div style={{fontSize:12,color:'rgba(28,28,30,0.55)',marginTop:2}}>{role}</div>
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { ICONS, Header, ActionBar, Footer, WhatsAppFAB, PropertyCard, Hero, FeatureGrid, Testimonial });
