/* global React, ReactDOM */
const { useEffect, useState } = React;

/* ========== Iconos minimal ========== */
const Icon = {
  Box: () => <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M3 7l9-4 9 4M3 7v10l9 4 9-4V7M3 7l9 4m9-4l-9 4m0 0v10" /></svg>,
  Truck: () => <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M3 7h11v9H3zM14 10h4l3 3v3h-7zM7 19a2 2 0 100-4 2 2 0 000 4zm10 0a2 2 0 100-4 2 2 0 000 4z" /></svg>,
  Boxes: () => <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M3 8l4-2 4 2v5l-4 2-4-2zM13 8l4-2 4 2v5l-4 2-4-2zM8 16l4-2 4 2v5l-4 2-4-2z" /></svg>,
  Plug: () => <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M9 7V3M15 7V3M7 7h10v4a5 5 0 01-10 0V7zM12 16v5" /></svg>,
  Refresh: () => <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M21 12a9 9 0 11-3-6.7M21 4v5h-5" /></svg>,
  Chart: () => <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M3 21h18M7 17V10M12 17V5M17 17v-9" /></svg>,
  Check: () => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M5 12l5 5L20 7" /></svg>,
  Arrow: () => <svg className="arrow" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M5 12h14M13 6l6 6-6 6" /></svg>
};

/* ========== Ilustración hero — persona empacando + camión ========== */
function PackingIllustration() {
  return (
    <svg className="packing-svg" viewBox="0 0 480 480" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
      <defs>
        <pattern id="np-stripes" patternUnits="userSpaceOnUse" width="6" height="6" patternTransform="rotate(45)">
          <line x1="0" y1="0" x2="0" y2="6" stroke="var(--violet)" strokeWidth="1" opacity="0.18" />
        </pattern>
      </defs>

      {/* Fondo coral redondeado */}
      <rect x="0" y="0" width="480" height="480" rx="24" fill="var(--coral-soft)" />
      <rect x="0" y="0" width="480" height="480" rx="24" fill="url(#np-stripes)" />

      {/* Suelo */}
      <line x1="20" y1="380" x2="460" y2="380" stroke="var(--ink)" strokeWidth="2" />

      {/* Camión al fondo */}
      <g transform="translate(280, 230)">
        {/* Sombra */}
        <ellipse cx="80" cy="156" rx="90" ry="6" fill="var(--ink)" opacity="0.08" />
        {/* Caja del camión */}
        <rect x="10" y="40" width="100" height="100" fill="var(--violet)" stroke="var(--ink)" strokeWidth="2.5" rx="4" />
        {/* Líneas de la caja */}
        <line x1="60" y1="42" x2="60" y2="138" stroke="var(--ink)" strokeWidth="2" opacity="0.3" />
        <rect x="20" y="55" width="32" height="22" fill="var(--coral)" stroke="var(--ink)" strokeWidth="1.5" rx="2" />
        {/* Logo del camión: rombo */}
        <rect x="78" y="100" width="18" height="18" fill="var(--coral)" stroke="var(--ink)" strokeWidth="1.5" transform="rotate(45 87 109)" />
        {/* Cabina */}
        <path d="M 110 70 L 160 70 L 175 95 L 175 140 L 110 140 Z" fill="var(--bg-card)" stroke="var(--ink)" strokeWidth="2.5" />
        {/* Ventana cabina */}
        <path d="M 118 78 L 155 78 L 165 95 L 118 95 Z" fill="var(--violet-soft)" stroke="var(--ink)" strokeWidth="1.5" />
        {/* Ruedas */}
        <circle cx="40" cy="148" r="14" fill="var(--ink)" />
        <circle cx="40" cy="148" r="6" fill="var(--bg-card)" />
        <circle cx="90" cy="148" r="14" fill="var(--ink)" />
        <circle cx="90" cy="148" r="6" fill="var(--bg-card)" />
        <circle cx="150" cy="148" r="14" fill="var(--ink)" />
        <circle cx="150" cy="148" r="6" fill="var(--bg-card)" />
        {/* Líneas de movimiento */}
        <line x1="-22" y1="80" x2="-2" y2="80" stroke="var(--ink)" strokeWidth="2.5" strokeLinecap="round" />
        <line x1="-30" y1="100" x2="-5" y2="100" stroke="var(--ink)" strokeWidth="2.5" strokeLinecap="round" />
        <line x1="-18" y1="120" x2="-2" y2="120" stroke="var(--ink)" strokeWidth="2.5" strokeLinecap="round" />
      </g>

      {/* Pila de cajas atrás-izquierda */}
      <g transform="translate(40, 290)">
        <rect x="0" y="0" width="60" height="50" fill="var(--bg-card)" stroke="var(--ink)" strokeWidth="2" />
        <line x1="0" y1="14" x2="60" y2="14" stroke="var(--ink)" strokeWidth="1.5" opacity="0.4" />
        <rect x="22" y="-3" width="16" height="6" fill="var(--coral)" stroke="var(--ink)" strokeWidth="1.5" />

        <rect x="-8" y="50" width="76" height="40" fill="var(--violet-tint)" stroke="var(--ink)" strokeWidth="2" />
        <rect x="20" y="58" width="20" height="14" fill="var(--bg-card)" stroke="var(--ink)" strokeWidth="1.5" />
        <text x="22" y="69" fontFamily="monospace" fontSize="9" fill="var(--ink)" fontWeight="600">NP</text>
      </g>

      {/* Persona empacando — al frente, centrado */}
      <g transform="translate(140, 130)">
        {/* Mesa */}
        <rect x="-20" y="200" width="200" height="14" fill="var(--ink)" rx="2" />
        <rect x="-15" y="214" width="6" height="60" fill="var(--ink)" />
        <rect x="170" y="214" width="6" height="60" fill="var(--ink)" />

        {/* Caja en la mesa */}
        <rect x="40" y="158" width="100" height="50" fill="var(--bg-card)" stroke="var(--ink)" strokeWidth="2.5" />
        <line x1="90" y1="158" x2="90" y2="208" stroke="var(--ink)" strokeWidth="1.5" opacity="0.3" />
        {/* Cinta sobre caja */}
        <rect x="40" y="178" width="100" height="8" fill="var(--coral)" stroke="var(--ink)" strokeWidth="1.5" />
        <text x="74" y="184" fontFamily="monospace" fontSize="6" fill="var(--ink)" fontWeight="700">NODOPACK</text>

        {/* Cuerpo */}
        <path d="M 60 100 Q 55 110 55 140 L 55 180 Q 50 195 30 200 L -10 200 Q -20 195 -10 185 L 30 178 L 30 140 Q 30 105 60 100 Z"
          fill="var(--violet)" stroke="var(--ink)" strokeWidth="2.5" />

        {/* Brazo derecho hacia la caja */}
        <path d="M 60 130 Q 90 138 100 158 L 90 165 Q 75 150 55 145 Z"
          fill="var(--violet)" stroke="var(--ink)" strokeWidth="2.5" />
        {/* Mano derecha */}
        <circle cx="92" cy="165" r="9" fill="var(--coral)" stroke="var(--ink)" strokeWidth="2" />

        {/* Mano izquierda (sosteniendo el rollo de cinta) */}
        <circle cx="-12" cy="195" r="9" fill="var(--coral)" stroke="var(--ink)" strokeWidth="2" />

        {/* Cabeza */}
        <circle cx="58" cy="78" r="26" fill="var(--coral)" stroke="var(--ink)" strokeWidth="2.5" />
        {/* Pelo */}
        <path d="M 35 70 Q 38 50 60 50 Q 82 50 84 72 Q 80 60 70 58 Q 62 60 58 64 Q 50 65 45 72 Z"
          fill="var(--ink)" />
        {/* Ojo */}
        <circle cx="68" cy="78" r="2" fill="var(--ink)" />
        {/* Sonrisa */}
        <path d="M 62 88 Q 68 92 74 88" stroke="var(--ink)" strokeWidth="2" fill="none" strokeLinecap="round" />
        {/* Cuello */}
        <rect x="52" y="100" width="14" height="8" fill="var(--coral)" stroke="var(--ink)" strokeWidth="2" />
      </g>

      {/* Estrellas/sparks decorativos */}
      <g fill="var(--violet)">
        <path d="M 60 60 L 62 70 L 72 72 L 62 74 L 60 84 L 58 74 L 48 72 L 58 70 Z" />
        <path d="M 420 80 L 421 86 L 427 87 L 421 88 L 420 94 L 419 88 L 413 87 L 419 86 Z" />
      </g>
    </svg>);

}

/* ========== Carrusel de testimonios en video vertical ========== */
const REVIEWS = [
  {
    name: "Carla Espinoza",
    handle: "@tiendabambu",
    src: "./videos/testimonios/carla-espinoza.mp4"
  },
  {
    name: "Diego Tapia",
    handle: "@kitsdiegotech",
    src: "./videos/testimonios/diego-tapia.mp4"
  },
  {
    name: "Antonia Vidal",
    handle: "@aguaviva",
    src: "./videos/testimonios/antonia-vidal.mp4"
  },
  {
    name: "Javiera Núñez",
    handle: "@piel.cl",
    src: "./videos/testimonios/javiera-nunez.mp4"
  },
  {
    name: "Matías Rojas",
    handle: "@verdesalvaje",
    src: "./videos/testimonios/matias-rojas.mp4"
  }
];

function ReviewCarousel() {
  const [active, setActive] = useState(0);
  const [hovered, setHovered] = useState(null);
  const videoRefs = React.useRef([]);

  useEffect(() => {
    if (hovered !== null) return;
    const t = setTimeout(() => {
      setActive((a) => (a + 1) % REVIEWS.length);
    }, 7000);
    return () => clearTimeout(t);
  }, [active, hovered]);

  useEffect(() => {
    const playing = hovered !== null ? hovered : active;

    videoRefs.current.forEach((video, i) => {
      if (!video) return;

      video.muted = true;
      video.volume = 0;
      video.controls = false;
      video.disablePictureInPicture = true;

      if (i === playing) {
        if (video.currentTime >= 10) video.currentTime = 0;
        video.play().catch(() => {});
      } else {
        video.pause();
      }
    });
  }, [active, hovered]);

  useEffect(() => {
    const interval = setInterval(() => {
      const playing = hovered !== null ? hovered : active;
      const video = videoRefs.current[playing];

      if (!video) return;

      video.muted = true;
      video.volume = 0;
      video.controls = false;

      const duration = video.duration || 0;

      if (duration && duration < 10 && video.currentTime >= duration - 0.25) {
        video.currentTime = Math.max(duration - 1, 0);
        video.play().catch(() => {});
        return;
      }

      if (video.currentTime >= 10) {
        video.currentTime = 0;
        video.play().catch(() => {});
      }
    }, 250);

    return () => clearInterval(interval);
  }, [active, hovered]);

  return (
    <div className="reviews-carousel">
      <div className="reviews-track">
        {REVIEWS.map((r, i) => {
          const isPlaying = (hovered !== null ? hovered : active) === i;
          return (
            <div
              key={i}
              className={`review-card${isPlaying ? ' is-playing' : ''}`}
              onMouseEnter={() => setHovered(i)}
              onMouseLeave={() => setHovered(null)}
              onClick={() => setActive(i)}
            >
              <video
                ref={(el) => (videoRefs.current[i] = el)}
                src={r.src}
                muted
                loop
                playsInline
                autoPlay={i === 0}
                preload="metadata"
                controls={false}
                disablePictureInPicture
                controlsList="nodownload nofullscreen noremoteplayback"
                onContextMenu={(event) => event.preventDefault()}
              ></video>

              <div className="review-overlay">
                <div className="review-name">{r.name}</div>
                <div className="review-handle">{r.handle}</div>
              </div>

              {isPlaying && (
                <div className="review-live">
                  <span className="dot"></span>EN VIVO
                </div>
              )}
            </div>
          );
        })}
      </div>

      <div className="reviews-dots">
        {REVIEWS.map((_, i) => (
          <button
            key={i}
            className={`reviews-dot${i === active ? ' active' : ''}`}
            onClick={() => setActive(i)}
            aria-label={`Ver testimonio ${i + 1}`}
          ></button>
        ))}
      </div>
    </div>
  );
}

/* ========== Datos ========== */
const SERVICES = [
{ num: "01", title: "Almacenamiento", body: "Tu inventario en racks asegurados y paletizados, con conteo cíclico semanal.", variant: "default" },
{ num: "02", title: "Picking & packing", body: "Preparamos cada pedido con embalaje pro: cartón, relleno y cinta marcada.", variant: "featured" },
{ num: "03", title: "Última milla", body: "Despachos con Starken y Chilexpress. Tú eliges courier por zona.", variant: "default" },
{ num: "04", title: "Devoluciones", body: "Recibimos, inspeccionamos y reingresamos al stock o desechamos según tu regla.", variant: "violet" },
{ num: "05", title: "Integraciones", body: "Conectamos Shopify, WooCommerce y MercadoLibre. Las órdenes entran solas al WMS.", variant: "default" },
{ num: "06", title: "Reportes en vivo", body: "Dashboard con stock por SKU, rotación, despachos del día y alertas de quiebre.", variant: "coral" }];


const HOW_STEPS = [
{ tag: "01 — Tú", title: "Nos envías tu stock", body: "Recibimos en Pudahuel y registramos cada SKU en nuestro WMS. Te llega el inventario inicial al correo.", icon: <Icon.Box /> },
{ tag: "02 — Conectas", title: "Integramos tu tienda", body: "Shopify, Woo o MercadoLibre. Las órdenes entran al sistema en tiempo real, sin que muevas un dedo.", icon: <Icon.Plug /> },
{ tag: "03 — Operamos", title: "Pickeamos y empacamos", body: "Cada pedido se prepara el mismo día hábil antes de las 14:00 hrs. Embalaje listo para courier.", icon: <Icon.Boxes /> },
{ tag: "04 — Despachamos", title: "Sale a destino", body: "Despachamos con el courier que elijas. Tu cliente recibe tracking y tú ves todo desde el panel.", icon: <Icon.Truck /> }];


const PRICING = [
{
  name: "Aquí comenzamos", amount: "7", unit: "/ mes + variable",
  desc: "Ideal si recién partes o despachas hasta 100 pedidos al mes.",
  feats: ["Hasta 2 m³ de almacenaje", "100 pedidos incluidos", "1 integración e-commerce", "Reportes básicos", "Soporte por correo"],
  popular: false, cta: "Empezar"
},
{
  name: "Aquí crecemos", amount: "12", unit: "/ mes + variable",
  desc: "Para tiendas que ya tienen volumen y quieren ordenar la operación.",
  feats: ["Hasta 8 m³ de almacenaje", "500 pedidos incluidos", "Integraciones ilimitadas", "Dashboard en vivo", "Gestión de devoluciones", "Soporte prioritario WhatsApp"],
  popular: true, cta: "Tomar este plan"
},
{
  name: "Aquí escalamos", amount: "—", unit: "a la medida",
  desc: "Volumen alto, kits, B2B o reglas especiales. Cotización personalizada.",
  feats: ["Almacenaje sin tope", "Pedidos ilimitados", "SLA personalizado", "Account manager dedicado", "Tarifas de courier negociadas", "API directa"],
  popular: false, cta: "Hablar con ventas"
}];


const TESTIMONIALS = [
{ stat: "+38% pedidos/mes", quote: "Pasamos de armar pedidos en la pieza de mi mamá a tener todo en NodoPack. Mismo día, sin estrés. Recuperé los fines de semana.", name: "Camila Rojas", role: "Fundadora, Botánica Verde", initials: "CR", featured: true },
{ stat: "0 errores en 3 meses", quote: "El picking es impecable. Antes tenía 2-3 reclamos por semana, ahora cero.", name: "Diego Salinas", role: "Owner, Casa Salinas", initials: "DS" },
{ stat: "Despacho mismo día", quote: "Conecté Shopify en 10 min. Las órdenes salen sin que yo entre al panel.", name: "Fran Toledo", role: "CEO, Polerón Club", initials: "FT" }];


const FAQS = [
{ q: "¿Dónde está la bodega?", a: "En Pudahuel, Santiago de Chile. Operamos solo dentro de Chile por ahora, con despacho a todas las regiones vía courier." },
{ q: "¿Cuál es el tiempo de despacho?", a: "Pedidos recibidos antes de las 14:00 hrs salen el mismo día hábil. Después de esa hora, salen al día siguiente." },
{ q: "¿Cómo te envío mi stock?", a: "Coordinamos una cita de recepción. Llegas tú o tu transportista y nosotros revisamos, contamos e ingresamos al sistema. Te llega un acta de recepción al correo." },
{ q: "¿Qué couriers usan?", a: "Trabajamos principalmente con Starken y Chilexpress. Puedes definir reglas por zona según tu operación y cobertura." },
{ q: "¿Hay contrato mínimo?", a: "No. Mes a mes. Si te quieres ir, avisas con 30 días y retiras tu stock cuando quieras." },
{ q: "¿Cómo veo mi inventario?", a: "Tienes acceso a un dashboard con stock por SKU, despachos del día, devoluciones y alertas de quiebre. Actualizado en tiempo real." },
{ q: "¿Manejan productos frágiles o grandes?", a: "Sí, con embalaje reforzado. Productos sobre 30 kg o frágiles especiales tienen un cargo adicional pequeño que cotizamos antes." }];


/* ========== Nav ========== */
function Nav() {
  return (
    <nav className="nav">
      <div className="wrap nav-inner">
        <a href="#top" className="logo">
          <span className="logo-mark"></span>
          <span>NodoPack</span>
        </a>
        <div className="nav-links">
          <a href="#como-funciona">Cómo funciona</a>
          <a href="#servicios">Servicios</a>
          <a href="#precios">Precios</a>
          <a href="#casos">Casos</a>
          <a href="#faq">FAQ</a>
        </div>
        <div className="nav-cta">
          <details className="header-popover tracking-popover">
  <summary className="btn btn-soft header-popover-summary">
    <span>Sigue tu pedido</span>
    <span className="to-up-icon">↗</span>
  </summary>
  <form className="header-popover-panel" onSubmit={(event) => { event.preventDefault(); }}>
    <input
      type="text"
      name="trackingCode"
      placeholder="N° seguimiento"
      aria-label="Número de seguimiento"
    />
    <button type="submit">Ir</button>
  </form>
</details>
          <a href="#contacto" className="btn btn-soft header-seller-btn"><span>Acceso Sellers</span><span className="to-up-icon">↗</span></a>
          <a href="#contacto" className="btn btn-primary">Cotizar <Icon.Arrow /></a>
        </div>
      </div>
    </nav>);

}

/* ========== Hero variants ========== */
function HeroBold() {
  return (
    <section className="hero" data-variant="bold">
      <div className="hero-bold">
        <div className="wrap">
          <div className="hero-bold-grid">
            <div className="hero-bold-copy">
              <div className="tag" style={{ marginBottom: 28 }}>
                <span className="tag-dot"></span>Operando en Pudahuel · Santiago
              </div>
              <h1 className="hero-bold-title">
                Empacado,<br />
                etiquetado y<br />
                <span className="accent">despachado hoy.</span>
              </h1>
              <p className="lead" style={{marginTop: 24}}>Tu pedido sale de bodega el mismo día que entra. Sin filas, sin demoras, sin <em style={{fontStyle:'italic', fontFamily:'var(--font-serif)'}}>«mañana lo despacho»</em>.</p>
              <div className="hero-bold-cta">
                <a href="#contacto" className="btn btn-primary">Cotizar mi operación <Icon.Arrow /></a>
                <a href="#como-funciona" className="btn btn-secondary">Cómo funciona</a>
              </div>
            </div>
            <div className="hero-bold-illu">
              <ReviewCarousel />
            </div>
          </div>
          <div className="hero-bold-meta">
            <div className="hero-bold-stat">
              <div className="num">14:00</div>
              <div className="lbl">Cierre despacho mismo día</div>
            </div>
            <div className="hero-bold-stat">
              <div className="num">99.6<span style={{ fontSize: 28 }}>%</span></div>
              <div className="lbl">Precisión de picking</div>
            </div>
            <div className="hero-bold-stat">
              <div className="num">24h</div>
              <div className="lbl">Onboarding listo</div>
            </div>
            <div className="hero-bold-stat">
              <div className="num">100<span style={{ fontSize: 28 }}>%</span></div>
              <div className="lbl">Cobertura Chile</div>
            </div>
          </div>
        </div>
      </div>
    </section>);

}

function HeroSplit() {
  return (
    <section className="hero" data-variant="split">
      <div className="hero-split">
        <div className="hero-split-left">
          <div className="tag"><span className="tag-dot"></span>Fulfillment para e-commerce</div>
          <h1 className="h-display">
            Vende. Nosotros nos<br />encargamos del resto.
          </h1>
          <p className="lead">Recibimos tu stock, integramos tu tienda y despachamos cada pedido el mismo día. Tú te enfocas en crecer, no en armar cajas.</p>
          <div className="hero-bold-cta">
            <a href="#contacto" className="btn btn-primary">Empezar <Icon.Arrow /></a>
            <a href="#precios" className="btn btn-secondary">Ver precios</a>
          </div>
        </div>
        <div className="hero-split-right">
          <div style={{ position: 'relative', zIndex: 2 }}>
            <div className="eyebrow coral" style={{ color: 'var(--coral)' }}>Un pedido en NodoPack</div>
            <h2 className="h2" style={{ color: 'var(--bg)', marginTop: 12 }}>De clic a puerta en 4 pasos.</h2>
          </div>
          <div className="hero-split-flow">
            <div className="flow-row"><span className="step-num">01</span><span className="step-name">Pedido entra desde Shopify</span><span className="step-time">10:42</span></div>
            <div className="flow-row"><span className="step-num">02</span><span className="step-name">Picking en bodega</span><span className="step-time">11:15</span></div>
            <div className="flow-row"><span className="step-num">03</span><span className="step-name">Empaque y etiquetado</span><span className="step-time">11:28</span></div>
            <div className="flow-row"><span className="step-num">04</span><span className="step-name">Retira Starken</span><span className="step-time">13:45</span></div>
          </div>
        </div>
      </div>
    </section>);

}

function HeroEditorial() {
  return (
    <section className="hero" data-variant="editorial">
      <div className="hero-editorial">
        <div className="wrap">
          <div className="hero-editorial-top">
            <div className="issue">N° 001 · Abril 2026</div>
            <div className="center">Fulfillment, hecho en Pudahuel.</div>
            <div className="issue" style={{ textAlign: 'right' }}>NodoPack — Chile</div>
          </div>
          <div className="hero-editorial-grid">
            <h1 className="hero-editorial-headline">
              Despacha como una <span className="ital">marca grande,</span> sin serlo todavía.
            </h1>
            <div className="hero-editorial-side">
              <p className="lead">Tercerizamos toda tu logística: almacenamos tu inventario, preparamos los pedidos y los enviamos a tu cliente final. Tú te dedicas a vender. Nosotros, a que cada caja salga perfecta.</p>
              <div className="hero-editorial-cta">
                <a href="#contacto" className="btn btn-primary">Cotizar <Icon.Arrow /></a>
                <a href="#como-funciona" className="btn btn-secondary">Cómo funciona</a>
              </div>
            </div>
          </div>
          <div className="hero-editorial-stats">
            <div><div className="num">~24h</div><div className="lbl">Onboarding</div></div>
            <div><div className="num">14:00</div><div className="lbl">Cut-off mismo día</div></div>
            <div><div className="num">3</div><div className="lbl">Integraciones nativas</div></div>
            <div><div className="num">100%</div><div className="lbl">Cobertura Chile</div></div>
          </div>
        </div>
      </div>
    </section>);

}

/* ========== Logos / Integraciones ========== */
function LogosStrip() {
  return (
    <div className="logos-strip">
      <div className="wrap logos-row">
        <span className="label">Integramos con</span>
        <div className="logos-list">
          <span className="logo-item"><span className="dot"></span>Shopify</span>
          <span className="logo-item"><span className="dot"></span>WooCommerce</span>
          <span className="logo-item"><span className="dot"></span>MercadoLibre</span>
          <span className="logo-item"><span className="dot"></span>Starken</span>
          <span className="logo-item"><span className="dot"></span>Chilexpress</span>
        </div>
      </div>
    </div>);

}

/* ========== Cómo funciona ========== */
function HowItWorks() {
  return (
    <section className="section" id="como-funciona">
      <div className="wrap">
        <div className="services-head">
          <div>
            <div className="eyebrow">Cómo funciona</div>
            <h2 className="h1" style={{ marginTop: 12 }}>Cuatro pasos. Sin enredos.</h2>
          </div>
          <p className="lead">Te onboardeamos en menos de 24 horas. Una vez conectado, no tienes que volver a tocar la operación: las órdenes entran solas, salen solas.</p>
        </div>
        <div className="how-grid">
          {HOW_STEPS.map((s, i) =>
          <div className="how-step" key={i}>
              <div className="step-tag">{s.tag}</div>
              <h3>{s.title}</h3>
              <p>{s.body}</p>
              <div className="step-icon">{s.icon}</div>
            </div>
          )}
        </div>
      </div>
    </section>);

}

/* ========== Servicios ========== */
function Services() {
  return (
    <section className="section" id="servicios" style={{ paddingTop: 0 }}>
      <div className="wrap">
        <div className="services-head">
          <div>
            <div className="eyebrow coral">Servicios</div>
            <h2 className="h1" style={{ marginTop: 12 }}>Todo lo que necesitas para no tocar una caja.</h2>
          </div>
          <p className="lead">Un solo proveedor para almacenamiento, despacho, devoluciones y reportes. Nada de coordinar tres empresas distintas.</p>
        </div>
        <div className="services-grid">
          {SERVICES.map((s) =>
          <div className={`service-card ${s.variant}`} key={s.num}>
              <div className="num">{s.num}</div>
              <h3>{s.title}</h3>
              <p>{s.body}</p>
            </div>
          )}
        </div>
      </div>
    </section>);

}

/* ========== Pricing ========== */
function Pricing() {
  return (
    <section className="section" id="precios" style={{ background: 'var(--violet-soft)' }}>
      <div className="wrap">
        <div className="pricing-head">
          <div className="eyebrow">Planes</div>
          <h2 className="h1" style={{ marginTop: 12 }}>Precios claros. Sin letra chica.</h2>
          <p className="lead">Una mensualidad fija + variable por pedido y volumen de almacenaje. Lo que ves es lo que pagas.</p>
        </div>
        <div className="pricing-grid">
          {PRICING.map((p) =>
          <div className={`price-card ${p.popular ? 'popular' : ''}`} key={p.name}>
              {p.popular && <div className="price-badge">Más popular</div>}
              <div className="price-name">{p.name}</div>
              <div className="price-amount">
                {p.amount === "—" ? <span className="num-big">—</span> :
              <>
                    <span className="cur">UF</span>
                    <span className="num-big">{p.amount}</span>
                  </>
              }
              </div>
              <div className="price-unit">{p.unit}</div>
              <p>{p.desc}</p>
              <ul className="price-feats">
                {p.feats.map((f, i) =>
              <li className="price-feat" key={i}><Icon.Check />{f}</li>
              )}
              </ul>
              <a href="#contacto" className="btn btn-primary">{p.cta} <Icon.Arrow /></a>
            </div>
          )}
        </div>
        <div className="price-foot">
          Variable: desde UF 0,025 por pedido preparado · UF 0,8 por m³/mes adicional. <a href="#contacto">Ver detalle</a>
        </div>
      </div>
    </section>);

}

/* ========== Testimonios ========== */
function Testimonials() {
  return (
    <section className="section" id="casos">
      <div className="wrap">
        <div className="services-head">
          <div>
            <div className="eyebrow coral">Casos</div>
            <h2 className="h1" style={{ marginTop: 12 }}>Tiendas sin preocupaciones.</h2>
          </div>
          <p className="lead">Pequeñas marcas que crecieron sin contratar bodega ni equipo extra. Solo conectaron y delegaron.</p>
        </div>
        <div className="testimonial-grid">
          {TESTIMONIALS.map((t, i) =>
          <div className={`testimonial ${t.featured ? 'featured' : ''}`} key={i}>
              <div>
                <div className="t-stat">{t.stat}</div>
                <p className="testimonial-quote">"{t.quote}"</p>
              </div>
              <div className="testimonial-meta">
                <div className="t-avatar">{t.initials}</div>
                <div>
                  <div className="t-meta-name">{t.name}</div>
                  <div className="t-meta-role">{t.role}</div>
                </div>
              </div>
            </div>
          )}
        </div>
      </div>
    </section>);

}

/* ========== FAQ ========== */
function FAQ() {
  return (
    <section className="section" id="faq" style={{ paddingTop: 0 }}>
      <div className="wrap">
        <div className="faq-grid">
          <div>
            <div className="eyebrow">Preguntas frecuentes</div>
            <h2 className="h1" style={{ marginTop: 12 }}>Lo que todos<br />nos preguntan.</h2>
            <p className="lead" style={{ marginTop: 16 }}>¿Te falta algo? Escríbenos y te respondemos en menos de 4 horas hábiles.</p>
          </div>
          <div className="faq-list">
            {FAQS.map((item, i) =>
            <details className="faq-item" key={i} {...i === 0 ? { open: true } : {}}>
                <summary>{item.q}</summary>
                <p>{item.a}</p>
              </details>
            )}
          </div>
        </div>
      </div>
    </section>);

}

/* ========== Contacto ========== */
function Contact() {
  const [sent, setSent] = useState(false);
  return (
    <section className="section" id="contacto">
      <div className="wrap">
        <div className="contact">
          <div className="contact-info">
            <div className="eyebrow" style={{ color: 'var(--coral)' }}>Hablemos</div>
            <h2 className="h1" style={{ marginTop: 12, color: 'var(--bg)' }}>Cuéntanos qué vendes.</h2>
            <p className="lead">Te respondemos en menos de 4 horas hábiles con una propuesta clara: cuánto te cuesta, qué incluye y cuándo podemos partir.</p>
            <div className="contact-detail">
              <div className="contact-detail-row">
                <div className="contact-detail-label">Bodega</div>
                <div className="contact-detail-val">Pudahuel<br />Santiago, Chile</div>
              </div>
              <div className="contact-detail-row">
                <div className="contact-detail-label">Correo</div>
                <div className="contact-detail-val">hola@nodopack.cl</div>
              </div>
              <div className="contact-detail-row">
                <div className="contact-detail-label">WhatsApp</div>
                <div className="contact-detail-val">+56 9 1234 5678</div>
              </div>
              <div className="contact-detail-row">
                <div className="contact-detail-label">Horario</div>
                <div className="contact-detail-val">Lun a Vie, 9:00 — 18:00</div>
              </div>
            </div>
          </div>
          <form className="contact-form" onSubmit={(e) => {e.preventDefault();setSent(true);}}>
            <div className="field-row">
              <div className="field"><label>Nombre</label><input required placeholder="Camila Rojas" /></div>
              <div className="field"><label>Tienda</label><input required placeholder="Botánica Verde" /></div>
            </div>
            <div className="field-row">
              <div className="field"><label>Correo</label><input type="email" required placeholder="hola@tutienda.cl" /></div>
              <div className="field"><label>Pedidos / mes</label>
                <select>
                  <option>Menos de 50</option>
                  <option>50 — 200</option>
                  <option>200 — 500</option>
                  <option>500 — 1.500</option>
                  <option>Más de 1.500</option>
                </select>
              </div>
            </div>
            <div className="field"><label>Plataforma</label>
              <select>
                <option>Shopify</option>
                <option>WooCommerce</option>
                <option>MercadoLibre</option>
                <option>Otra / propia</option>
                <option>Aún no tengo</option>
              </select>
            </div>
            <div className="field"><label>Cuéntanos brevemente</label><textarea rows="3" placeholder="¿Qué vendes? ¿Qué problema quieres resolver?"></textarea></div>
            <button type="submit" className="btn">{sent ? "✓ Enviado, te contactamos" : "Enviar solicitud →"}</button>
          </form>
        </div>
      </div>
    </section>);

}

/* ========== Footer ========== */
function Footer() {
  return (
    <footer className="footer">
      <div className="wrap">
        <div className="footer-grid">
          <div className="footer-brand">
            <div className="logo"><span className="logo-mark"></span><span>NodoPack</span></div>
            <p>Fulfillment para tiendas chilenas que ya no quieren empacar de noche. Operamos en Pudahuel, despachamos a todo Chile.</p>
          </div>
          <div className="footer-col">
            <h4>Producto</h4>
            <ul>
              <li><a href="#servicios">Servicios</a></li>
              <li><a href="#precios">Precios</a></li>
              <li><a href="#como-funciona">Cómo funciona</a></li>
              <li><a href="#faq">FAQ</a></li>
            </ul>
          </div>
          <div className="footer-col">
            <h4>Empresa</h4>
            <ul>
              <li><a href="#casos">Casos</a></li>
              <li><a href="#contacto">Contacto</a></li>
              <li><a href="#">Trabaja con nosotros</a></li>
            </ul>
          </div>
          <div className="footer-col">
            <h4>Contacto</h4>
            <ul>
              <li><a href="mailto:hola@nodopack.cl">hola@nodopack.cl</a></li>
              <li><a href="#">+56 9 1234 5678</a></li>
              <li><a href="#">Pudahuel, Santiago</a></li>
            </ul>
          </div>
        </div>
        <div className="footer-bottom">
          <span>© 2026 NodoPack SpA · Santiago de Chile</span>
          <span>Nos preocupamos de tus pedidos como si fueran nuestros ◆</span>
        </div>
      </div>
    </footer>);

}

/* ========== Tweaks ========== */
const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "hero": "bold",
  "btnStyle": "pill",
  "showLogos": true,
  "accentSwap": false
} /*EDITMODE-END*/;

function Tweaks() {
  const [tweaks, setTweak] = window.useTweaks(TWEAK_DEFAULTS);

  useEffect(() => {
    document.body.setAttribute("data-hero", tweaks.hero);
    document.body.setAttribute("data-btn", tweaks.btnStyle);
    if (tweaks.accentSwap) {
      document.documentElement.style.setProperty("--violet", "oklch(0.72 0.17 25)");
      document.documentElement.style.setProperty("--violet-deep", "oklch(0.62 0.20 25)");
      document.documentElement.style.setProperty("--violet-soft", "oklch(0.95 0.04 25)");
      document.documentElement.style.setProperty("--violet-tint", "oklch(0.88 0.08 25)");
      document.documentElement.style.setProperty("--coral", "oklch(0.55 0.20 295)");
      document.documentElement.style.setProperty("--coral-deep", "oklch(0.42 0.22 295)");
      document.documentElement.style.setProperty("--coral-soft", "oklch(0.95 0.04 295)");
    } else {
      document.documentElement.style.removeProperty("--violet");
      document.documentElement.style.removeProperty("--violet-deep");
      document.documentElement.style.removeProperty("--violet-soft");
      document.documentElement.style.removeProperty("--violet-tint");
      document.documentElement.style.removeProperty("--coral");
      document.documentElement.style.removeProperty("--coral-deep");
      document.documentElement.style.removeProperty("--coral-soft");
    }
  }, [tweaks]);

  const T = window.TweaksPanel;
  const Section = window.TweakSection;
  const Radio = window.TweakRadio;
  const Toggle = window.TweakToggle;

  return (
    <T title="Tweaks">
      <Section title="Hero">
        <Radio
          label="Variante"
          value={tweaks.hero}
          onChange={(v) => setTweak("hero", v)}
          options={[
          { value: "bold", label: "Bold" },
          { value: "split", label: "Bold" },
          { value: "editorial", label: "Editorial" }]
          } />
        
      </Section>
      <Section title="Botones">
        <Radio
          label="Estilo"
          value={tweaks.btnStyle}
          onChange={(v) => setTweak("btnStyle", v)}
          options={[
          { value: "pill", label: "Pill" },
          { value: "soft", label: "Soft" },
          { value: "square", label: "Square" },
          { value: "bracket", label: "[ ]" }]
          } />
        
      </Section>
      <Section title="Color">
        <Toggle
          label="Invertir violeta ↔ coral"
          checked={tweaks.accentSwap}
          onChange={(v) => setTweak("accentSwap", v)} />
        
      </Section>
      <Section title="Layout">
        <Toggle
          label="Mostrar tira de integraciones"
          checked={tweaks.showLogos}
          onChange={(v) => setTweak("showLogos", v)} />
        
      </Section>
    </T>);

}

/* ========== App ========== */


function FloatingToTop() {
  return (
    <a href="#" className="floating-to-top" aria-label="Subir arriba">
      ↑
    </a>
  );
}

function App() {
  // hidrata estado inicial al body para que CSS funcione antes de mount
  useEffect(() => {
    if (!document.body.dataset.hero) document.body.dataset.hero = TWEAK_DEFAULTS.hero;
    if (!document.body.dataset.btn) document.body.dataset.btn = TWEAK_DEFAULTS.btnStyle;
  }, []);

  const [showLogos, setShowLogos] = useState(TWEAK_DEFAULTS.showLogos);
  useEffect(() => {
    const handler = (ev) => {
      const d = ev.data;
      if (d && d.type === "__edit_mode_set_keys" && d.edits && "showLogos" in d.edits) {
        setShowLogos(!!d.edits.showLogos);
      }
    };
    window.addEventListener("message", handler);
    return () => window.removeEventListener("message", handler);
  }, []);

  return (
    <>
      <Nav />
      <div id="top">
        <HeroBold />
        <HeroSplit />
        <HeroEditorial />
      </div>
      {showLogos && <LogosStrip />}
      <HowItWorks />
      <Services />
      <Pricing />
      <Testimonials />
      <FAQ />
      <Contact />
      <Footer />
      <FloatingToTop />
      <Tweaks />
    </>);

}

ReactDOM.createRoot(document.getElementById("app")).render(<App />);