// HomeV3 — Hero centrado con logo real, banner interactivo, cards femeninas,
//          Sobre Mí con foto protagonista, reseñas por categoría, CTA agenda destacado

const LOGO_IMG = 'uploads/el-arte-de-quererte-brief-claude-design.jpg';

// ── Helpers ──────────────────────────────────────────────────
const SectionLabel = ({ text }) => (
  <div style={{ fontFamily: "'Outfit', sans-serif", fontSize: 10, letterSpacing: 5, color: '#88C9C1', textTransform: 'uppercase', fontWeight: 600, marginBottom: 18 }}>{text}</div>
);

const SectionTitle = ({ children, center = false, italic = true }) => (
  <h2 style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 'clamp(36px,4vw,58px)', fontWeight: italic ? 400 : 700, fontStyle: italic ? 'italic' : 'normal', color: '#1a1a1a', lineHeight: 1.05, margin: '0 0 24px', textAlign: center ? 'center' : 'left' }}>{children}</h2>
);

// ── SERVICE CARD (feminine, rounded, hover magic) ─────────────
const ServiceCardV3 = ({ name, desc, price, duration, tag, img, needsCoordination, onBook }) => {
  const [hovered, setHovered] = React.useState(false);
  
  const handleBook = (e) => {
    if (e) e.stopPropagation();
    if (needsCoordination) {
      const waUrl = `https://wa.me/56983059044?text=${encodeURIComponent(
        `Hola Fran! Me interesó el servicio de *${name}* y me gustaría coordinar una hora.`
      )}`;
      window.open(waUrl, '_blank');
    } else {
      onBook();
    }
  };

  return (
    <div onMouseEnter={() => setHovered(true)} onMouseLeave={() => setHovered(false)}
      style={{ background: '#fff', borderRadius: 24, overflow: 'hidden', boxShadow: hovered ? (needsCoordination ? '0 24px 64px rgba(37,211,102,0.22)' : '0 24px 64px rgba(136,201,193,0.22)') : '0 4px 20px rgba(0,0,0,0.05)', transition: 'all 0.45s cubic-bezier(0.16,1,0.3,1)', transform: hovered ? 'translateY(-8px)' : 'none', cursor: 'default', display: 'flex', flexDirection: 'column' }}>
      {/* Image */}
      <div style={{ position: 'relative', height: 200, overflow: 'hidden', background: 'linear-gradient(135deg, #E8F5F3 0%, #FCE8EC 100%)' }}>
        <img src={img && img.trim() !== '' ? img : `https://picsum.photos/seed/${(name || 'spa').toLowerCase().replace(/\s+/g, '-')}/600/400`} alt={name} style={{ width: '100%', height: '100%', objectFit: 'cover', transition: 'transform 0.6s cubic-bezier(0.16,1,0.3,1)', transform: hovered ? 'scale(1.07)' : 'scale(1)' }}
          onError={e => { e.target.style.display='none'; }}
        />
        {/* Soft overlay on hover */}
        <div style={{ position: 'absolute', inset: 0, background: needsCoordination ? 'linear-gradient(to top, rgba(37,211,102,0.35) 0%, transparent 60%)' : 'linear-gradient(to top, rgba(136,201,193,0.35) 0%, transparent 60%)', opacity: hovered ? 1 : 0, transition: 'opacity 0.4s' }}/>
        {tag && <span style={{ position: 'absolute', top: 14, left: 14, background: 'rgba(250,250,248,0.92)', backdropFilter: 'blur(8px)', color: '#88C9C1', fontSize: 10, fontFamily: "'Outfit', sans-serif", fontWeight: 700, letterSpacing: 2, padding: '5px 14px', borderRadius: 40, textTransform: 'uppercase' }}>{tag}</span>}
      </div>
      {/* Content */}
      <div style={{ padding: '22px 26px 26px', flex: 1, display: 'flex', flexDirection: 'column' }}>
        <h3 style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 23, fontWeight: 600, color: '#1a1a1a', margin: '0 0 8px', lineHeight: 1.2 }}>{name}</h3>
        <p style={{ fontFamily: "'Outfit', sans-serif", fontSize: 13, color: '#7a7a7a', lineHeight: 1.7, margin: '0 0 14px', flex: 1 }}>{desc}</p>
        {duration && <div style={{ fontFamily: "'Outfit', sans-serif", fontSize: 11, color: '#88C9C1', letterSpacing: 1.5, textTransform: 'uppercase', marginBottom: 18 }}>{duration}</div>}
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
          <span style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 28, fontWeight: 700, color: '#1a1a1a' }}>{price}</span>
          <button onClick={handleBook} style={{
            background: hovered ? (needsCoordination ? '#25D366' : '#88C9C1') : 'transparent', 
            color: hovered ? '#fff' : (needsCoordination ? '#25D366' : '#88C9C1'),
            border: `1.5px solid ${needsCoordination ? 'rgba(37,211,102,0.6)' : 'rgba(136,201,193,0.6)'}`, 
            cursor: 'pointer',
            fontFamily: "'Outfit', sans-serif", fontSize: 10, letterSpacing: 2, fontWeight: 700,
            padding: '10px 22px', borderRadius: 40, textTransform: 'uppercase',
            transition: 'all 0.35s cubic-bezier(0.16,1,0.3,1)',
          }}>{needsCoordination ? 'Coordinar' : 'Reservar'}</button>
        </div>
      </div>
    </div>
  );
};

// ── TESTIMONIAL CARD ──────────────────────────────────────────
const TestiCard = ({ name, loc, text, featured }) => (
  <div style={{ background: featured ? 'linear-gradient(135deg, #88C9C1 0%, #6bb5ac 100%)' : '#fff', borderRadius: 20, padding: featured ? '40px 36px' : '32px 30px', boxShadow: '0 4px 20px rgba(0,0,0,0.06)', display: 'flex', flexDirection: 'column', justifyContent: 'space-between', minHeight: 220 }}>
    <div>
      <div style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 48, color: featured ? 'rgba(255,255,255,0.25)' : 'rgba(136,201,193,0.25)', lineHeight: 0.9, marginBottom: 18 }}>"</div>
      <p style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: featured ? 22 : 19, fontStyle: 'italic', color: featured ? '#fff' : '#1a1a1a', lineHeight: 1.65, margin: 0 }}>{text}</p>
    </div>
    <div style={{ marginTop: 28, paddingTop: 20, borderTop: `1px solid ${featured ? 'rgba(255,255,255,0.2)' : 'rgba(136,201,193,0.2)'}` }}>
      <div style={{ fontFamily: "'Outfit', sans-serif", fontSize: 12, fontWeight: 700, color: featured ? '#fff' : '#1a1a1a', letterSpacing: 0.5 }}>{name}</div>
      <div style={{ fontFamily: "'Outfit', sans-serif", fontSize: 11, color: featured ? 'rgba(255,255,255,0.65)' : '#88C9C1', marginTop: 3, letterSpacing: 1 }}>{loc}</div>
    </div>
  </div>
);

// ── HERO SECTION — self-contained, no external deps ──────────

const HeroSection = ({ setPage, config }) => {
  const phrases = (config && config.heroPhrases) ? config.heroPhrases : ['Tu espacio de bienestar'];
  const quote = (config && config.heroQuote) ? config.heroQuote : 'Permítete ese momento de paz';
  const [mouse, setMouse] = React.useState({ x: 50, y: 50 });
  const [phraseIdx, setPhraseIdx] = React.useState(0);
  const [phrasePhase, setPhrasePhase] = React.useState('visible'); // 'visible' | 'exiting' | 'entering'
  const heroRef = React.useRef(null);

  const onMouseMove = (e) => {
    const r = (heroRef.current && heroRef.current.getBoundingClientRect());
    if (!r) return;
    setMouse({ x: ((e.clientX - r.left) / r.width) * 100, y: ((e.clientY - r.top) / r.height) * 100 });
  };

  React.useEffect(() => {
    const cycle = setInterval(() => {
      // 1. Exit upward
      setPhrasePhase('exiting');
      // 2. Swap phrase + start entering from below
      setTimeout(() => {
        setPhraseIdx(i => (i + 1) % phrases.length);
        setPhrasePhase('entering');
        // 3. Snap to entering start, then animate to visible
        setTimeout(() => setPhrasePhase('visible'), 30);
      }, 550);
    }, 5600);
    return () => clearInterval(cycle);
  }, []);

  return (
    <section ref={heroRef} onMouseMove={onMouseMove}
      style={{ position: 'relative', minHeight: '100dvh', overflow: 'hidden', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', textAlign: 'center' }}>

      <style>{`
        @keyframes kenBurns { from { transform:scale(1.0); } to { transform:scale(1.09) translateY(-2%); } }
        @keyframes shimmerSweep { 0% { left:-100%; } 55%,100% { left:160%; } }
        @keyframes scrollPulse { 0%,100% { opacity:0.3; } 50% { opacity:0.85; } }
        @keyframes heroFadeUp { from { opacity:0; transform:translateY(22px); } to { opacity:1; transform:translateY(0); } }
        .h-el-0 { animation: heroFadeUp 0.8s cubic-bezier(0.16,1,0.3,1) 0.1s both; }
        .h-el-1 { animation: heroFadeUp 0.8s cubic-bezier(0.16,1,0.3,1) 0.25s both; }
        .h-el-2 { animation: heroFadeUp 0.8s cubic-bezier(0.16,1,0.3,1) 0.4s both; }
        .h-el-3 { animation: heroFadeUp 0.8s cubic-bezier(0.16,1,0.3,1) 0.55s both; }
        .h-el-4 { animation: heroFadeUp 0.8s cubic-bezier(0.16,1,0.3,1) 0.7s both; }
      `}</style>

      {/* Ken Burns bg — shifted down by nav height so logo clears the nav */}
      <div style={{ position: 'absolute', inset: '-9%', zIndex: 0,
        animation: 'kenBurns 16s ease-in-out infinite alternate',
        backgroundImage: `url('uploads/Gemini_Generated_Image_8j2b908j2b908j2b.png')`,
        backgroundSize: 'cover', backgroundPosition: 'center 74px',
      }}/>

      {/* Overlay — stronger for readability */}
      <div style={{ position: 'absolute', inset: 0, zIndex: 1,
        background: 'linear-gradient(160deg, rgba(5,20,18,0.45) 0%, rgba(5,20,18,0.62) 50%, rgba(5,20,18,0.80) 100%)',
      }}/>

      {/* Mouse spotlight */}
      <div style={{ position: 'absolute', inset: 0, zIndex: 2, pointerEvents: 'none',
        background: `radial-gradient(ellipse 480px 360px at ${mouse.x}% ${mouse.y}%, rgba(136,201,193,0.10) 0%, transparent 68%)`,
        transition: 'background 0.08s linear',
      }}/>

      {/* Shimmer sweep */}
      <div style={{ position: 'absolute', inset: 0, zIndex: 2, pointerEvents: 'none', overflow: 'hidden' }}>
        <div style={{ position: 'absolute', top: 0, left: '-100%', width: '55%', height: '100%',
          background: 'linear-gradient(105deg, transparent 38%, rgba(255,255,255,0.03) 50%, transparent 62%)',
          animation: 'shimmerSweep 10s ease-in-out infinite',
        }}/>
      </div>

      {/* ── CONTENT — z-index 10 ensures it's always on top ── */}
      <div style={{ position: 'relative', zIndex: 10, padding: '148px 24px 80px', maxWidth: 820, width: '100%' }}>

        {/* Label pill */}
        <div className="h-el-0" style={{ marginBottom: 40 }}>
          <span style={{
            display: 'inline-block',
            fontFamily: "'Outfit', sans-serif", fontSize: 11, letterSpacing: 7,
            color: '#fff', textTransform: 'uppercase', fontWeight: 600,
            background: 'rgba(136,201,193,0.22)',
            backdropFilter: 'blur(12px)', WebkitBackdropFilter: 'blur(12px)',
            border: '1px solid rgba(136,201,193,0.5)',
            padding: '11px 32px', borderRadius: 50,
            boxShadow: '0 0 28px rgba(136,201,193,0.2), inset 0 1px 0 rgba(255,255,255,0.1)',
          }}>Cosmetología &nbsp;·&nbsp; Masoterapia</span>
        </div>

        {/* Quote */}
        <div className="h-el-1" style={{ marginBottom: 56 }}>
          <p style={{
            fontFamily: "'Cormorant Garamond', serif",
            fontSize: 'clamp(28px, 3.8vw, 48px)',
            fontWeight: 600, fontStyle: 'italic',
            color: '#C9A96E',
            textShadow: '0 0 48px rgba(201,169,110,0.5), 0 2px 20px rgba(0,0,0,0.6)',
            lineHeight: 1.25, margin: '0 0 18px',
          }}>"{quote}"</p>
          <div style={{ width: 56, height: 1.5, background: 'linear-gradient(90deg, transparent, rgba(201,169,110,0.65), transparent)', margin: '0 auto' }}/>
        </div>

        {/* CTAs */}
        <div className="h-el-2" style={{ display: 'flex', gap: 14, justifyContent: 'center', flexWrap: 'wrap', marginBottom: 56 }}>
          <button onClick={() => setPage('agenda')} style={{
            background: '#88C9C1', color: '#fff', border: 'none', cursor: 'pointer',
            fontFamily: "'Outfit', sans-serif", fontSize: 11, letterSpacing: 2.5,
            textTransform: 'uppercase', fontWeight: 700,
            padding: '16px 44px', borderRadius: 50,
            boxShadow: '0 8px 32px rgba(136,201,193,0.5)',
            transition: 'all 0.35s cubic-bezier(0.16,1,0.3,1)',
          }}
          onMouseEnter={e => { e.currentTarget.style.background='#6bb5ac'; e.currentTarget.style.transform='translateY(-3px)'; e.currentTarget.style.boxShadow='0 16px 44px rgba(136,201,193,0.6)'; }}
          onMouseLeave={e => { e.currentTarget.style.background='#88C9C1'; e.currentTarget.style.transform='none'; e.currentTarget.style.boxShadow='0 8px 32px rgba(136,201,193,0.5)'; }}
          >Agenda tu Cita</button>

          <button onClick={() => setPage('servicios')} style={{
            background: 'rgba(255,255,255,0.12)', color: '#fff',
            border: '1.5px solid rgba(255,255,255,0.4)', cursor: 'pointer',
            fontFamily: "'Outfit', sans-serif", fontSize: 11, letterSpacing: 2.5,
            textTransform: 'uppercase', fontWeight: 600,
            padding: '16px 36px', borderRadius: 50,
            backdropFilter: 'blur(12px)', WebkitBackdropFilter: 'blur(12px)',
            transition: 'all 0.3s cubic-bezier(0.16,1,0.3,1)',
          }}
          onMouseEnter={e => { e.currentTarget.style.background='rgba(255,255,255,0.22)'; e.currentTarget.style.borderColor='rgba(255,255,255,0.65)'; }}
          onMouseLeave={e => { e.currentTarget.style.background='rgba(255,255,255,0.12)'; e.currentTarget.style.borderColor='rgba(255,255,255,0.4)'; }}
          >Ver Servicios</button>
        </div>

        {/* Rotating phrase — glass card */}
        <div className="h-el-3" style={{ display: 'flex', justifyContent: 'center' }}>
          <div style={{
            background: 'rgba(5,20,18,0.45)',
            backdropFilter: 'blur(24px)', WebkitBackdropFilter: 'blur(24px)',
            border: '1px solid rgba(255,255,255,0.12)',
            boxShadow: 'inset 0 1px 0 rgba(255,255,255,0.08)',
            borderRadius: 14, padding: '20px 36px',
            maxWidth: 640, width: '100%', minHeight: 68,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            overflow: 'hidden',
          }}>
            <p style={{
              fontFamily: "'Cormorant Garamond', serif",
              fontSize: 'clamp(13px, 1.25vw, 15px)',
              fontStyle: 'italic', color: 'rgba(255,255,255,0.92)',
              lineHeight: 1.55, margin: 0, maxWidth: '100%',
              opacity: phrasePhase === 'visible' ? 1 : 0,
              transform: phrasePhase === 'exiting'  ? 'translateY(-20px)'
                       : phrasePhase === 'entering' ? 'translateY(20px)'
                       : 'translateY(0)',
              transition: phrasePhase === 'visible'
                ? 'opacity 0.65s cubic-bezier(0.16,1,0.3,1), transform 0.65s cubic-bezier(0.16,1,0.3,1)'
                : phrasePhase === 'exiting'
                ? 'opacity 0.45s ease-in, transform 0.45s ease-in'
                : 'none',
            }}>
              {phrases[phraseIdx]}
            </p>
          </div>
        </div>
      </div>

      {/* Scroll indicator */}
      <div className="h-el-4" style={{ position: 'absolute', bottom: 28, left: '50%', transform: 'translateX(-50%)', zIndex: 10, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 8 }}>
        <div style={{ fontFamily: "'Outfit', sans-serif", fontSize: 9, letterSpacing: 4, color: 'rgba(255,255,255,0.4)', textTransform: 'uppercase' }}>Descubrir</div>
        <div style={{ width: 1, height: 36, background: 'linear-gradient(to bottom, rgba(136,201,193,0.7), transparent)', animation: 'scrollPulse 2s ease-in-out infinite' }}/>
      </div>
    </section>
  );
};

// ── HOME V3 ───────────────────────────────────────────────────
const HomeV3 = ({ setPage }) => {
  const [siteConfig, setSiteConfig] = React.useState(null);

  React.useEffect(() => {
    fetch('/api/config')
      .then(res => res.json())
      .then(setSiteConfig)
      .catch(console.error);
  }, []);
  const [mounted, setMounted] = React.useState(false);
  const [promoHover, setPromoHover] = React.useState(null);
  const [testiCat, setTestiCat] = React.useState('todos');

  React.useEffect(() => { setTimeout(() => setMounted(true), 80); }, []);

    const [services, setServices] = React.useState(() => {
    try {
      const stored = localStorage.getItem('eadq_services');
      if (stored) {
        const parsed = JSON.parse(stored);
        return parsed.filter(s => s.show_on_home).sort((a,b) => (a.home_order || 0) - (b.home_order || 0)).slice(0, 6);
      }
    } catch (e) {}
    return [];
  });

  React.useEffect(() => {
    fetch('/api/services')
      .then(res => res.json())
      .then(data => {
        if (Array.isArray(data)) {
          const homeServices = data.filter(s => s.show_on_home).sort((a,b) => (a.home_order || 0) - (b.home_order || 0)).slice(0, 6);
          if (homeServices.length > 0) {
            const mapped = homeServices.map(s => ({
              ...s,
              desc: s.description || s.desc || '',
              needsCoordination: s.needs_coordination !== undefined ? s.needs_coordination : s.needsCoordination
            }));
            setServices(mapped);
          }
        }
      })
      .catch(console.error);
  }, []);

  React.useEffect(() => {
    const fetchServices = async () => {
      try {
        const response = await fetch('/api/services');
        if (!response.ok) throw new Error('Failed to fetch services from API');
        const data = await response.json();
        if (Array.isArray(data) && data.length > 0) {
          const mapped = data.map(s => ({
            ...s,
            desc: s.description || s.desc || '',
            needsCoordination: s.needs_coordination !== undefined ? s.needs_coordination : s.needsCoordination
          }));
          setServices(mapped);
          localStorage.setItem('eadq_services', JSON.stringify(mapped));
          return;
        }
      } catch (err) {
        console.warn('⚠️ No se pudo obtener servicios del servidor, usando fallback local:', err);
      }

      // Fallback a localStorage
      try {
        const stored = localStorage.getItem('eadq_services');
        if (stored) {
          setServices(JSON.parse(stored));
        }
      } catch (e) {
        console.error('Error al cargar de localStorage:', e);
      }
    };

    fetchServices();
  }, []);

  const promos = (siteConfig && siteConfig.home && siteConfig.home.promos) ? siteConfig.home.promos : [];

  const fallbackTestis = [
    { cat: 'faciales', name: 'Camila Rojas', loc: 'La Florida', text: 'Salí con la piel increíble. El ambiente es completamente acogedor y Fran sabe exactamente qué necesita cada piel.', featured: true },
    { cat: 'masajes', name: 'Valentina Morales', loc: 'Ñuñoa', text: 'El masaje de relajación fue lo que mi cuerpo pedía hace meses. Ya agendé el próximo sin dudarlo.' },
    { cat: 'pestañas', name: 'Daniela Pizarro', loc: 'Las Condes', text: 'El lash lifting quedó natural pero con un efecto impresionante. Muy profesional y detallista.' },
    { cat: 'masajes', name: 'Sofía Herrera', loc: 'Peñalolén', text: 'El masaje descontracturante fue increíble. Las contracturas que tenía desde hace meses desaparecieron.' },
    { cat: 'faciales', name: 'Isabela Contreras', loc: 'Macul', text: 'La limpieza facial me dejó la piel brillante. Fran explica todo el proceso y se nota su amor por lo que hace.' },
  ];
  const allTestis = (siteConfig && siteConfig.reviews && siteConfig.reviews.length > 0)
    ? siteConfig.reviews.sort((a,b) => a.order - b.order).map(r => ({
        cat: 'todos', name: r.name, loc: r.city, text: r.message, featured: r.order === 1, rating: r.rating
      }))
    : fallbackTestis;

  const testiCats = (siteConfig && siteConfig.reviews && siteConfig.reviews.length > 0) ? ['todos'] : ['todos', 'faciales', 'masajes', 'pestañas'];
  const visibleTestis = testiCat === 'todos' ? allTestis : allTestis.filter(t => t.cat === testiCat);

  const fade = (i, delay = 0) => mounted ? { animation: `fadeUpHome 0.7s cubic-bezier(0.16,1,0.3,1) ${i * 0.1 + delay}s both` } : { opacity: 0 };

  return (
    <div>
      <style>{`
        @keyframes fadeUpHome { from { opacity:0; transform:translateY(24px); } to { opacity:1; transform:translateY(0); } }
        @keyframes shimmer { 0%,100% { opacity:0.6; } 50% { opacity:1; } }
        @keyframes marqueeScroll { from { transform:translateX(0); } to { transform:translateX(-50%); } }
        @keyframes floatLogo { 0%,100% { transform:translateY(0px); } 50% { transform:translateY(-10px); } }
        .service-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(300px,1fr)); gap:24px; }
        .promo-card { cursor:pointer; transition:all 0.4s cubic-bezier(0.16,1,0.3,1); }
        .promo-card:hover { transform:translateY(-6px); box-shadow:0 20px 48px rgba(0,0,0,0.12) !important; }
        .testi-grid { display:grid; grid-template-columns:2fr 1fr 1fr; gap:20px; }
        @media (max-width:900px) { .testi-grid { grid-template-columns:1fr !important; } }
        @media (max-width:640px) { .service-grid { grid-template-columns:1fr !important; } }
        .sobre-wrap { display:grid; grid-template-columns:1fr 1fr; gap:0; min-height:600px; }
        @media (max-width:768px) { .sobre-wrap { grid-template-columns:1fr !important; } .sobre-wrap>div:first-child { height:320px; } }
        .schedule-table { display:grid; grid-template-columns:1fr 1fr; gap:0; }
        @media (max-width:560px) { .schedule-table { grid-template-columns:1fr !important; } }
      `}</style>

      {/* ── HERO — full-bleed image + spotlight + Ken Burns ── */}
      <HeroSection setPage={setPage} config={siteConfig ? siteConfig.home : null} />

      {/* ── PROMO BANNER — interactive cards ─────────────── */}
      <section style={{ background: '#1a1a1a', padding: '0' }}>
        {/* Scrolling label */}
        <div style={{ overflow: 'hidden', whiteSpace: 'nowrap', borderBottom: '1px solid rgba(255,255,255,0.06)', padding: '12px 0' }}>
          <div className="marquee-text" style={{ display: 'inline-block', animation: 'marqueeScroll 30s linear infinite' }}>
            {Array(4).fill('Limpieza Facial  ·  Masaje de Relajación  ·  Lash Lifting 20% OFF  ·  Tratamiento Reductor  ·  Gift Cards  ·  ').join('')}
          </div>
          <style>{`.marquee-text { font-family:\'Outfit\',sans-serif; font-size:11px; letter-spacing:3px; color:rgba(255,255,255,0.3); text-transform:uppercase; }`}</style>
        </div>

        {/* Promo cards */}
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 0 }} className="promo-3col">
          {promos.map((p, i) => (
            <div key={i} className="promo-card" onClick={() => setPage(p.page)}
              style={{ padding: '44px 40px', background: promoHover === i ? p.color : 'transparent', borderRight: i < 2 ? '1px solid rgba(255,255,255,0.08)' : 'none', position: 'relative', overflow: 'hidden' }}
              onMouseEnter={() => setPromoHover(i)} onMouseLeave={() => setPromoHover(null)}
            >
              <div style={{ position: 'absolute', inset: 0, background: p.color, opacity: promoHover === i ? 1 : 0, transition: 'opacity 0.4s cubic-bezier(0.16,1,0.3,1)' }}/>
              <div style={{ position: 'relative', zIndex: 1 }}>
                <div style={{ fontFamily: "'Outfit', sans-serif", fontSize: 10, letterSpacing: 3, color: promoHover === i ? p.accent : 'rgba(255,255,255,0.45)', textTransform: 'uppercase', fontWeight: 700, marginBottom: 14, transition: 'color 0.3s' }}>{p.label}</div>
                <div style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 28, fontWeight: 600, color: promoHover === i ? '#1a1a1a' : '#fff', lineHeight: 1.15, marginBottom: 12, transition: 'color 0.3s' }}>{p.title}</div>
                {p.badge && <div style={{ fontFamily: "'Outfit', sans-serif", fontSize: 10, letterSpacing: 2, color: p.accent, textTransform: 'uppercase', fontWeight: 700, marginBottom: 8 }}>{p.badge}</div>}
                <div style={{ display: 'flex', alignItems: 'baseline', gap: 10 }}>
                  <span style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 36, fontWeight: 700, color: promoHover === i ? p.accent : '#88C9C1', transition: 'color 0.3s' }}>{p.price}</span>
                  {p.og && <span style={{ fontFamily: "'Outfit', sans-serif", fontSize: 13, color: promoHover === i ? '#7a7a7a' : 'rgba(255,255,255,0.3)', textDecoration: 'line-through', transition: 'color 0.3s' }}>{p.og}</span>}
                </div>
                <div style={{ marginTop: 20, fontFamily: "'Outfit', sans-serif", fontSize: 11, letterSpacing: 2, color: promoHover === i ? p.accent : 'rgba(255,255,255,0.4)', textTransform: 'uppercase', transition: 'color 0.3s' }}>Ver más →</div>
              </div>
            </div>
          ))}
        </div>
        <style>{`.promo-3col { } @media (max-width:768px) { .promo-3col { grid-template-columns:1fr !important; } .promo-3col > div { border-right:none !important; border-bottom:1px solid rgba(255,255,255,0.08); } }`}</style>
      </section>

      {/* ── SERVICIOS cards ───────────────────────────────── */}
      <section style={{ padding: '100px 24px', background: '#FAFAF8' }}>
        <div style={{ maxWidth: 1200, margin: '0 auto' }}>
          <div style={{ textAlign: 'center', marginBottom: 60 }}>
            <SectionLabel text="Tratamientos" />
            <SectionTitle center italic>Diseñados para ti</SectionTitle>
            <p style={{ fontFamily: "'Outfit', sans-serif", fontSize: 15, color: '#7a7a7a', lineHeight: 1.75, maxWidth: '50ch', margin: '0 auto' }}>Cada servicio pensado para nutrir tu piel, relajar tu cuerpo y reconectar con tu bienestar.</p>
          </div>
          <div className="service-grid">
            {services.map((s, i) => (
              <div key={s.name} style={{ animation: `fadeUpHome 0.6s cubic-bezier(0.16,1,0.3,1) ${i * 0.08}s both` }}>
                <ServiceCardV3 {...s} onBook={() => setPage('agenda')} />
              </div>
            ))}
          </div>
        </div>
      </section>



      {/* ── TESTIMONIOS — por categoría ───────────────────── */}
      <section style={{ padding: '100px 24px', background: '#F7F5F2' }}>
        <div style={{ maxWidth: 1200, margin: '0 auto' }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 24, marginBottom: 48 }}>
            <div>
              <SectionLabel text="Reseñas" />
              <SectionTitle italic>Lo que dicen<br/>nuestras clientas</SectionTitle>
            </div>
            {/* Category tabs */}
            <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
              {testiCats.map(c => (
                <button key={c} onClick={() => setTestiCat(c)} style={{
                  background: testiCat === c ? '#1a1a1a' : '#fff',
                  color: testiCat === c ? '#fff' : '#7a7a7a',
                  border: '1.5px solid rgba(58,58,58,0.15)', cursor: 'pointer',
                  fontFamily: "'Outfit', sans-serif", fontSize: 11, letterSpacing: 1.5, fontWeight: 600,
                  padding: '9px 22px', borderRadius: 40, textTransform: 'capitalize',
                  transition: 'all 0.25s cubic-bezier(0.16,1,0.3,1)',
                }}>{c.charAt(0).toUpperCase() + c.slice(1)}</button>
              ))}
            </div>
          </div>

          {visibleTestis.length > 0 ? (
            <div className="testi-grid">
              {visibleTestis.slice(0,3).map((t, i) => (
                <div key={t.name + i} style={{ animation: 'fadeUpHome 0.5s cubic-bezier(0.16,1,0.3,1) both' }}>
                  <TestiCard {...t} featured={i === 0 && testiCat === 'todos'} />
                </div>
              ))}
            </div>
          ) : (
            <div style={{ textAlign: 'center', padding: '60px 0', color: '#7a7a7a', fontFamily: "'Outfit', sans-serif", fontSize: 14 }}>No hay reseñas en esta categoría aún.</div>
          )}
        </div>
      </section>

      {/* ── AGENDA / HORARIOS ─────────────────────────────── */}
      <section style={{ padding: '100px 24px', background: '#fff' }}>
        <div style={{ maxWidth: 900, margin: '0 auto', textAlign: 'center' }}>
          <SectionLabel text="Disponibilidad" />
          <SectionTitle center italic>Horarios de atención</SectionTitle>
          <p style={{ fontFamily: "'Outfit', sans-serif", fontSize: 15, color: '#7a7a7a', lineHeight: 1.75, maxWidth: '46ch', margin: '0 auto 56px' }}>Reserva tu cita online en cualquier momento. Disponible 24/7.</p>

          {/* Schedule cards */}
          <div className="schedule-table">
            {(siteConfig && siteConfig.schedule && siteConfig.schedule.blocks ? siteConfig.schedule.blocks : [
              { days: ['Lunes','Miércoles','Viernes'], time: '16:00 – 20:00', isClosed: false },
              { days: ['Martes','Jueves',''], time: '08:00 – 20:00', isClosed: false },
              { days: ['Sábado','',''], time: '09:00 – 15:00', isClosed: false },
              { days: ['Domingo','',''], time: 'Cerrado', isClosed: true }
            ]).map((block, i) => {
              const bg = block.isClosed ? '#F5F5F5' : (i % 2 === 0 ? '#E8F5F3' : '#FCE8EC');
              const color = block.isClosed ? '#ccc' : (i % 2 === 0 ? '#88C9C1' : '#F4B8C1');
              const daysStr = block.days.filter(d => d).join(' · ');
              const timeStr = block.isClosed ? 'Cerrado' : block.time;
              return (
              <div key={i} style={{ background: bg, padding: '32px', borderRadius: 0, border: '2px solid #fff', transition: 'transform 0.3s', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 8 }}
                onMouseEnter={e => e.currentTarget.style.transform='scale(1.02)'}
                onMouseLeave={e => e.currentTarget.style.transform='scale(1)'}
              >
                <div style={{ fontFamily: "'Outfit', sans-serif", fontSize: 12, color: '#7a7a7a', letterSpacing: 1.5, textTransform: 'uppercase', fontWeight: 600, textAlign: 'center' }}>{daysStr}</div>
                <div style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 30, fontWeight: 700, color: color }}>{timeStr}</div>
              </div>
            )})}

          </div>

          <div style={{ marginTop: 32, fontFamily: "'Outfit', sans-serif", fontSize: 13, color: '#7a7a7a', lineHeight: 1.8 }}>
            {siteConfig && siteConfig.schedule ? siteConfig.schedule.address : 'Mariano Sánchez Fontecilla 11950, Peñalolén'} · {siteConfig && siteConfig.schedule ? siteConfig.schedule.phone : '+56 9 8305 9044'}
          </div>
        </div>
      </section>

      {/* ── CTA AGENDA ────────────────────────────────────── */}
      <section style={{ padding: '100px 24px', background: 'linear-gradient(135deg, #88C9C1 0%, #6bb5ac 60%, #5aa89e 100%)', textAlign: 'center', position: 'relative', overflow: 'hidden' }}>
        <div style={{ position: 'absolute', top: -80, right: -80, width: 400, height: 400, borderRadius: '50%', background: 'rgba(255,255,255,0.06)', pointerEvents: 'none' }}/>
        <div style={{ position: 'absolute', bottom: -60, left: -60, width: 300, height: 300, borderRadius: '50%', background: 'rgba(244,184,193,0.12)', pointerEvents: 'none' }}/>
        <div style={{ maxWidth: 640, margin: '0 auto', position: 'relative', zIndex: 1 }}>
          <p style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 24, fontStyle: 'italic', color: 'rgba(255,255,255,0.8)', marginBottom: 16 }}>¿Lista para darte el momento que mereces?</p>
          <h2 style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 'clamp(40px,5vw,68px)', fontWeight: 400, color: '#fff', lineHeight: 1.05, margin: '0 0 20px' }}>Agenda tu sesión<br/>en minutos</h2>
          <p style={{ fontFamily: "'Outfit', sans-serif", fontSize: 14, color: 'rgba(255,255,255,0.8)', lineHeight: 1.7, maxWidth: '42ch', margin: '0 auto 48px' }}>Elige tu horario, selecciona tu servicio y confirma en segundos. Te esperamos pronto.</p>
          <button onClick={() => setPage('agenda')} style={{ background: '#fff', color: '#88C9C1', border: 'none', cursor: 'pointer', fontFamily: "'Outfit', sans-serif", fontSize: 12, letterSpacing: 2.5, textTransform: 'uppercase', fontWeight: 700, padding: '18px 52px', borderRadius: 50, transition: 'all 0.35s cubic-bezier(0.16,1,0.3,1)', boxShadow: '0 8px 32px rgba(0,0,0,0.12)' }}
            onMouseEnter={e => { e.currentTarget.style.transform='translateY(-3px)'; e.currentTarget.style.boxShadow='0 16px 48px rgba(0,0,0,0.18)'; }}
            onMouseLeave={e => { e.currentTarget.style.transform='none'; e.currentTarget.style.boxShadow='0 8px 32px rgba(0,0,0,0.12)'; }}
          >Agendar mi Cita</button>
        </div>
      </section>
    </div>
  );
};

Object.assign(window, { HomeV3 });
