// components.jsx — Componentes compartidos para Verduras Frescas RD
// (cargado antes de pages.jsx y app.jsx)

const { useState, useEffect, useRef, useMemo } = React;

// ───────────────────────────────────────────────────────────
// Iconos minimalistas (sin emojis)
// ───────────────────────────────────────────────────────────
const Icon = ({ name, size = 18, stroke = 1.6 }) => {
  const common = { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: stroke, strokeLinecap: 'round', strokeLinejoin: 'round' };
  const paths = {
    search:   <><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></>,
    cart:     <><path d="M3 4h2l2.4 12.3a2 2 0 0 0 2 1.7h8.2a2 2 0 0 0 2-1.6L21 8H6"/><circle cx="9" cy="21" r="1"/><circle cx="18" cy="21" r="1"/></>,
    x:        <><path d="M18 6 6 18M6 6l12 12"/></>,
    plus:     <><path d="M12 5v14M5 12h14"/></>,
    minus:    <><path d="M5 12h14"/></>,
    chev:     <><path d="m9 18 6-6-6-6"/></>,
    arrow:    <><path d="M5 12h14M13 6l6 6-6 6"/></>,
    wa:       <><path d="M21 12a9 9 0 1 1-3.6-7.2L21 3l-1.2 3.6A9 9 0 0 1 21 12z"/><path d="M8 10c0 4 2 6 6 6l1.5-1.5-2-2L12 13a6 6 0 0 1-2-2l.5-1.5-2-2L7 8a3 3 0 0 1 1-2"/></>,
    mail:     <><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></>,
    pin:      <><path d="M12 22s7-7.5 7-13a7 7 0 1 0-14 0c0 5.5 7 13 7 13z"/><circle cx="12" cy="9" r="2.5"/></>,
    phone:    <><path d="M5 4h3l2 5-2.5 1.5a11 11 0 0 0 6 6L15 14l5 2v3a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2z"/></>,
    clock:    <><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></>,
    leaf:     <><path d="M5 21c0-9 7-16 16-16-1 9-7 16-16 16z"/><path d="M5 21c4-4 9-9 16-16"/></>,
    truck:    <><rect x="2" y="7" width="13" height="9" rx="1"/><path d="M15 10h4l3 3v3h-7"/><circle cx="6" cy="18" r="2"/><circle cx="18" cy="18" r="2"/></>,
    chat:     <><path d="M21 12a8 8 0 1 1-3-6.2L21 5l-.8 3A8 8 0 0 1 21 12z"/><path d="M9 11h.01M12 11h.01M15 11h.01"/></>,
    spark:    <><path d="M12 3v3M12 18v3M3 12h3M18 12h3M5.6 5.6l2.1 2.1M16.3 16.3l2.1 2.1M5.6 18.4l2.1-2.1M16.3 7.7l2.1-2.1"/></>,
    ig:       <><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="1" fill="currentColor"/></>,
    fb:       <><path d="M14 8h3V4h-3a4 4 0 0 0-4 4v3H7v4h3v7h4v-7h3l1-4h-4V8a0 0 0 0 1 0 0z"/></>,
    tk:       <><path d="M14 4v9a4 4 0 1 1-4-4"/><path d="M14 4c0 2 1.5 4 5 4"/></>,
    menu:     <><path d="M4 6h16M4 12h16M4 18h16"/></>,
    list:     <><path d="M8 6h13M8 12h13M8 18h13"/><circle cx="4" cy="6" r="1" fill="currentColor"/><circle cx="4" cy="12" r="1" fill="currentColor"/><circle cx="4" cy="18" r="1" fill="currentColor"/></>,
    user:     <><circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/></>,
    bag:      <><path d="M5 8h14l-1 12a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 8z"/><path d="M9 8a3 3 0 1 1 6 0"/></>,
  };
  return <svg {...common}>{paths[name]}</svg>;
};

// ───────────────────────────────────────────────────────────
// Placeholder de imagen con rayas suaves + label monoespaciado
// ───────────────────────────────────────────────────────────
const Placeholder = ({ label, tint = ['#cfe3b5', '#7fb069'], rounded = false, photo = null }) => {
  const [failed, setFailed] = useState(false);
  const [a, b] = tint;
  const bg = `radial-gradient(circle at 30% 30%, ${a}, ${b})`;
  if (photo && !failed) {
    return (
      <div className="ph ph-photo" style={{ backgroundImage: `url(${photo})`, background: bg }}>
        <img
          src={photo}
          alt={label}
          onError={() => setFailed(true)}
          style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}
        />
      </div>
    );
  }
  return (
    <div className="ph" style={{ background: bg }}>
      <div className="ph-stripes" />
      <div className="ph-label">{label}</div>
    </div>
  );
};

// ───────────────────────────────────────────────────────────
// Promo banner (controlado desde Ajustes del panel)
// ───────────────────────────────────────────────────────────
const PromoBanner = () => {
  const cv = window.CV_APPEARANCE || {};
  if (!cv.promoActivo || !cv.promoTexto) return null;
  const tones = {
    verde:     { bg: 'var(--primary)', fg: '#fff' },
    terracota: { bg: 'var(--accent)',  fg: '#fff' },
    amarillo:  { bg: 'var(--sun)',     fg: 'var(--ink)' },
    negro:     { bg: '#1a1a1a',        fg: '#fff' },
  };
  const t = tones[cv.promoColor] || tones.verde;
  return (
    <div className="promo-banner" style={{ background: t.bg, color: t.fg }}>
      <span>{cv.promoTexto}</span>
    </div>
  );
};

// ───────────────────────────────────────────────────────────
// User menu (dropdown del avatar del header)
// ───────────────────────────────────────────────────────────
const UserMenu = ({ user, onLogout }) => {
  const [open, setOpen] = useState(false);
  const ref = useRef(null);

  useEffect(() => {
    if (!open) return;
    const onDocClick = (e) => {
      if (ref.current && !ref.current.contains(e.target)) setOpen(false);
    };
    document.addEventListener('mousedown', onDocClick);
    return () => document.removeEventListener('mousedown', onDocClick);
  }, [open]);

  const firstName = user.name?.split(' ')[0] || 'Cuenta';
  const isAdmin = user.role === 'admin';

  return (
    <div ref={ref} style={{ position: 'relative' }}>
      <a
        className="login"
        style={{ cursor: 'pointer' }}
        onClick={() => setOpen((o) => !o)}
      >
        <Icon name="user" size={18} /> {firstName}
      </a>
      {open && (
        <div
          style={{
            position: 'absolute',
            top: 'calc(100% + 8px)',
            right: 0,
            background: '#fff',
            border: '1px solid var(--line, #e5e5e5)',
            borderRadius: 10,
            boxShadow: '0 8px 24px rgba(0,0,0,.08)',
            minWidth: 200,
            zIndex: 50,
            overflow: 'hidden',
          }}
        >
          <div style={{ padding: '12px 14px', borderBottom: '1px solid var(--line, #eee)', fontSize: 13 }}>
            <div style={{ fontWeight: 600 }}>{user.name}</div>
            <div style={{ color: '#777', fontSize: 12 }}>{user.email}</div>
            {isAdmin && (
              <div style={{
                marginTop: 6,
                display: 'inline-block',
                padding: '2px 8px',
                background: 'rgba(45, 74, 31, 0.1)',
                color: '#2d4a1f',
                borderRadius: 999,
                fontSize: 11,
                fontWeight: 600,
                textTransform: 'uppercase',
                letterSpacing: 0.5,
              }}>Admin</div>
            )}
          </div>
          {isAdmin && (
            <button
              onClick={() => { setOpen(false); window.location.href = 'dashboard.html'; }}
              style={{
                width: '100%', padding: '11px 14px', background: 'transparent',
                border: 'none', textAlign: 'left', cursor: 'pointer', fontSize: 14,
                display: 'flex', alignItems: 'center', gap: 10,
              }}
              onMouseEnter={(e) => e.currentTarget.style.background = '#f7f7f4'}
              onMouseLeave={(e) => e.currentTarget.style.background = 'transparent'}
            >
              <Icon name="settings" size={16} /> Panel admin
            </button>
          )}
          <button
            onClick={() => { setOpen(false); onLogout(); }}
            style={{
              width: '100%', padding: '11px 14px', background: 'transparent',
              border: 'none', textAlign: 'left', cursor: 'pointer', fontSize: 14,
              color: '#b22',
              display: 'flex', alignItems: 'center', gap: 10,
              borderTop: '1px solid var(--line, #eee)',
            }}
            onMouseEnter={(e) => e.currentTarget.style.background = '#fdf2f2'}
            onMouseLeave={(e) => e.currentTarget.style.background = 'transparent'}
          >
            Cerrar sesión
          </button>
        </div>
      )}
    </div>
  );
};

// ───────────────────────────────────────────────────────────
// Header
// ───────────────────────────────────────────────────────────
const Header = ({ route, navigate, cartCount, openCart, searchQuery, setSearchQuery, showImages, user, onLogout }) => {
  const cv = window.CV_APPEARANCE || {};
  const brandName = cv.nombre || 'Casa Viva SRL';
  return (
    <header className="hdr">
      <div className="hdr-inner">
        <div className="brand" onClick={() => navigate('home')}>
          <div className="brand-mark">
            {cv.logo ? (
              <img src={cv.logo} alt={brandName} style={{ width: 36, height: 36, objectFit: 'contain', borderRadius: 8 }} />
            ) : (
              <svg width="28" height="34" viewBox="0 0 28 34" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
                <path d="M14 31 V14"/>
                <path d="M14 14 C 14 7, 7 4, 3 6 C 4 11, 9 15, 14 14 Z" fill="currentColor" fillOpacity="0.9"/>
                <path d="M14 14 C 14 9, 18 5, 23 5 C 23 11, 19 15, 14 14 Z" fill="currentColor" fillOpacity="0.7"/>
                <path d="M14 20 C 14 17, 11 15, 8 15 C 8 18, 11 21, 14 20 Z" fill="currentColor" fillOpacity="0.9"/>
                <path d="M14 26 C 14 23, 17 21, 21 21 C 21 24, 18 27, 14 26 Z" fill="currentColor" fillOpacity="0.7"/>
              </svg>
            )}
          </div>
          <div>
            <div>{brandName.split(' ')[0]}</div>
            <div>{brandName.split(' ').slice(1).join(' ') || ''}</div>
          </div>
        </div>
        <nav className="nav">
          <a aria-current={route === 'home'} onClick={() => navigate('home')}>Home</a>
          <a aria-current={route === 'contacto'} onClick={() => navigate('contacto')}>Sobre Nosotros</a>
          <a aria-current={route === 'productos' || route === 'detalle'} onClick={() => navigate('productos')}>Shop</a>
        </nav>
        <div className="hdr-tools">
          {user ? (
            <UserMenu user={user} onLogout={onLogout} />
          ) : (
            <a
              className="login"
              style={{ cursor: 'pointer' }}
              onClick={() => navigate('login')}
            >
              <Icon name="user" size={18} /> Log In
            </a>
          )}
          <button className="icon-btn" onClick={openCart} aria-label="Carrito">
            <Icon name="bag" size={20} />
            {cartCount > 0 && <span className="cart-count">{cartCount}</span>}
          </button>
          <button className="hdr-cta" onClick={() => navigate('productos')}>Cotiza Ya</button>
        </div>
      </div>
    </header>
  );
};

// ───────────────────────────────────────────────────────────
// Footer
// ───────────────────────────────────────────────────────────
const Footer = ({ navigate, contact }) => (
  <footer className="foot">
    <div className="foot-inner">
      <div className="foot-brand" onClick={() => navigate('home')} style={{ cursor: 'pointer' }}>
        <svg className="foot-mark" width="38" height="44" viewBox="0 0 28 34" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
          <path d="M14 31 V14"/>
          <path d="M14 14 C 14 7, 7 4, 3 6 C 4 11, 9 15, 14 14 Z" fill="currentColor" fillOpacity="0.9"/>
          <path d="M14 14 C 14 9, 18 5, 23 5 C 23 11, 19 15, 14 14 Z" fill="currentColor" fillOpacity="0.7"/>
          <path d="M14 20 C 14 17, 11 15, 8 15 C 8 18, 11 21, 14 20 Z" fill="currentColor" fillOpacity="0.9"/>
          <path d="M14 26 C 14 23, 17 21, 21 21 C 21 24, 18 27, 14 26 Z" fill="currentColor" fillOpacity="0.7"/>
        </svg>
        <div className="foot-brand-text">
          <span>Casa</span>
          <span>Viva SRL</span>
        </div>
      </div>
      <div className="foot-center">
        <b>Verduras frescas, calidad siempre</b>
        <span>{contact.address}</span>
      </div>
      <div className="socials">
        <a className="fb" aria-label="Facebook"><Icon name="fb" size={14} stroke={0.5} /></a>
        <a className="ig" aria-label="Instagram"><Icon name="ig" size={14} stroke={1.5} /></a>
        <a className="yt" aria-label="YouTube"><svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M23 8s-.2-1.5-.9-2.2c-.8-.9-1.7-.9-2.1-1C16.9 4.5 12 4.5 12 4.5s-4.9 0-7.9.3c-.4 0-1.3 0-2.1 1C1.2 6.5 1 8 1 8s-.2 1.7-.2 3.5v1.7c0 1.7.2 3.4.2 3.4s.2 1.5.9 2.2c.8.9 1.9.8 2.4.9 1.7.2 7.7.3 7.7.3s4.9 0 7.9-.3c.4 0 1.3 0 2.1-1 .7-.7.9-2.2.9-2.2s.2-1.7.2-3.5v-1.6c0-1.8-.2-3.4-.2-3.4z"/><path d="M10 8.5v6l5-3z" fill="#fff"/></svg></a>
        <a className="x"  aria-label="X"><svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2H21.5l-7.535 8.61L23 22h-7.094l-5.556-7.273L4 22H.74l8.06-9.21L1 2h7.25l5.022 6.625L18.244 2zm-2.488 18.094h1.85L7.34 3.806H5.355l10.4 16.288z"/></svg></a>
        <a className="li" aria-label="LinkedIn"><svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M19 3a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h14zM8.5 18v-7H6v7h2.5zM7.25 9.8a1.45 1.45 0 1 0 0-2.9 1.45 1.45 0 0 0 0 2.9zM18 18v-3.7c0-2.34-1.25-3.43-2.92-3.43-1.34 0-1.94.74-2.28 1.26V11H10.5v7H13v-3.83c0-.99.74-1.62 1.67-1.62.93 0 1.33.62 1.33 1.62V18H18z"/></svg></a>
        <a className="tk" aria-label="TikTok"><Icon name="tk" size={14} stroke={1.6} /></a>
      </div>
    </div>
    <div className="foot-bottom">
      <span>© 2026 Casa Viva SRL. Todos los derechos.</span>
    </div>
  </footer>
);

// ───────────────────────────────────────────────────────────
// ProductCard
// ───────────────────────────────────────────────────────────
const ProductCard = ({ p, onAdd, onOpen, justAdded, showImages }) => (
  <div className="prod-card">
    {p.badge && <div className="prod-badge">{p.badge}</div>}
    {showImages && (
      <div className="prod-media" onClick={() => onOpen(p.id)}>
        <Placeholder label={`${p.name.toLowerCase()}.jpg`} tint={p.tint} photo={p.photo} />
      </div>
    )}
    <h3 className="h-card" onClick={() => onOpen(p.id)}>{p.name}</h3>
    <div className="prod-meta">
      <span className="prod-origin">{p.origin}</span>
      <span className="prod-unit">por {p.unit}</span>
    </div>
    <button
      className={`add-btn ${justAdded ? 'added' : ''}`}
      onClick={() => onAdd(p)}
      aria-label={`Agregar ${p.name}`}
    >
      {justAdded ? '✓ Agregado al carrito' : 'Agregar al carrito para cotizar'}
    </button>
  </div>
);

// ───────────────────────────────────────────────────────────
// CartDrawer
// ───────────────────────────────────────────────────────────
const formatCurrency = (n) => `RD$${n.toLocaleString('es-DO', { minimumFractionDigits: 0, maximumFractionDigits: 0 })}`;

const CartItemRow = ({ item, onInc, onDec, onRemove, onUnit }) => {
  const product = window.PRODUCTS.find(p => p.id === item.id);
  if (!product) return null;
  return (
    <div className="cart-item">
      <div className="cart-item-img">
        <Placeholder label={item.id} tint={product.tint} photo={product.photo} />
      </div>
      <div className="cart-item-body">
        <h4 className="cart-item-name">{product.name}</h4>
        <div className="cart-item-meta">{item.qty} {item.unit} · {product.origin}</div>
        <div className="qty" style={{ marginTop: 4, alignSelf: 'flex-start' }}>
          <button onClick={() => onDec(item.id)} aria-label="Reducir">−</button>
          <span>{item.qty}</span>
          <button onClick={() => onInc(item.id)} aria-label="Aumentar">+</button>
        </div>
      </div>
      <div className="cart-item-right">
        <button className="x-btn" onClick={() => onRemove(item.id)}>Quitar</button>
      </div>
    </div>
  );
};

const CartDrawer = ({ open, onClose, cart, onInc, onDec, onRemove, total, navigate, contact, openEmailForm }) => {
  if (!open) return null;
  const sendWA = () => {
    let msg = 'Hola, quiero cotizar estos productos:\n\n';
    cart.forEach((it, i) => {
      const p = window.PRODUCTS.find(x => x.id === it.id);
      msg += `${i + 1}. ${p.name}, ${it.qty} ${it.unit}\n`;
    });
    msg += `\nMi nombre:\nMi dirección:\nComentario adicional:`;
    const url = `https://wa.me/${contact.waRaw}?text=${encodeURIComponent(msg)}`;
    window.open(url, '_blank');
  };
  return (
    <>
      <div className="drawer-bg" onClick={onClose} />
      <aside className="drawer">
        <div className="drawer-hd">
          <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
            <h3>Tu cotización</h3>
            {cart.length > 0 && <span className="count-pill">{cart.length} {cart.length === 1 ? 'item' : 'items'}</span>}
          </div>
          <button className="close-btn" onClick={onClose} aria-label="Cerrar"><Icon name="x" size={16} /></button>
        </div>
        <div className="drawer-body">
          {cart.length === 0 ? (
            <div className="empty">
              <div className="empty-ill">∅</div>
              <h4>Tu carrito está vacío</h4>
              <p>Agrega productos para armar tu cotización. Lo confirmamos por WhatsApp o correo.</p>
              <button className="btn btn-primary" onClick={() => { onClose(); navigate('productos'); }}>
                Ver productos <Icon name="arrow" size={16} />
              </button>
            </div>
          ) : (
            cart.map(it => (
              <CartItemRow key={it.id} item={it} onInc={onInc} onDec={onDec} onRemove={onRemove} />
            ))
          )}
        </div>
        {cart.length > 0 && (
          <div className="drawer-foot">
            <div className="summary">
              <div className="summary-row"><span>Productos</span><span>{cart.length} en lista</span></div>
              <div className="summary-row"><span>Unidades</span><span>{cart.reduce((s, i) => s + i.qty, 0)} unidades</span></div>
              <div className="summary-row"><span>Entrega estimada</span><span>Por confirmar</span></div>
            </div>
            <div className="note">
              Te confirmaremos disponibilidad y precio por WhatsApp o correo en cuanto recibamos tu solicitud.
            </div>
            <button className="btn btn-wa btn-block" onClick={sendWA}>
              <Icon name="wa" size={18} /> Cotizar por WhatsApp
            </button>
            <button className="btn btn-secondary btn-block" onClick={() => { onClose(); openEmailForm(); }}>
              <Icon name="mail" size={16} /> Cotizar por correo
            </button>
            <button className="btn btn-ghost btn-block btn-sm" onClick={() => { onClose(); navigate('carrito'); }}>
              Ver carrito completo
            </button>
          </div>
        )}
      </aside>
    </>
  );
};

// ───────────────────────────────────────────────────────────
// Email cotización modal
// ───────────────────────────────────────────────────────────
const EmailQuoteForm = ({ open, onClose, cart, total }) => {
  const [submitted, setSubmitted] = useState(false);
  const [loading, setLoading] = useState(false);
  const [form, setForm] = useState({ name: '', phone: '', email: '', address: '', note: '' });
  
  if (!open) return null;
  
  const submit = async (e) => {
    e.preventDefault();
    setLoading(true);
    
    try {
      const response = await api.quotationAPI.requestQuotation(form.email, form.name, form.phone);
      if (response.success) {
        setSubmitted(true);
      } else {
        alert('Error: ' + response.error);
      }
    } catch (error) {
      alert('Error enviando cotización: ' + error.message);
    } finally {
      setLoading(false);
    }
  };
  
  return (
    <div className="modal-bg" onClick={onClose}>
      <div className="modal" onClick={(e) => e.stopPropagation()}>
        {submitted ? (
          <>
            <div className="modal-hd">
              <h3>¡Solicitud enviada!</h3>
              <button className="close-btn" onClick={onClose}><Icon name="x" size={16} /></button>
            </div>
            <div className="modal-body">
              <p style={{ color: 'var(--ink-soft)', fontSize: 16, lineHeight: 1.55 }}>
                Gracias, <b>{form.name}</b>. Recibimos tu solicitud de cotización con <b>{cart.length} productos</b>.
              </p>
              <p style={{ color: 'var(--ink-soft)', fontSize: 16, lineHeight: 1.55, marginTop: 12 }}>
                Te responderemos en menos de <b>2 horas hábiles</b> al correo <b>{form.email}</b> con disponibilidad y precio final.
              </p>
              <div className="note" style={{ marginTop: 18 }}>
                ¿Prefieres WhatsApp? Escríbenos y te atendemos de una.
              </div>
            </div>
            <div className="modal-foot">
              <button className="btn btn-primary btn-block" onClick={onClose}>Listo</button>
            </div>
          </>
        ) : (
          <>
            <div className="modal-hd">
              <div>
                <div className="eyebrow" style={{ marginBottom: 6 }}>Cotización por correo</div>
                <h3>Solicita tu cotización</h3>
              </div>
              <button className="close-btn" onClick={onClose}><Icon name="x" size={16} /></button>
            </div>
            <form className="modal-body form" onSubmit={submit}>
              <div className="field">
                <label>Nombre completo</label>
                <input required value={form.name} onChange={(e) => setForm({ ...form, name: e.target.value })} placeholder="Ej: María Pérez" />
              </div>
              <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
                <div className="field">
                  <label>Teléfono</label>
                  <input required value={form.phone} onChange={(e) => setForm({ ...form, phone: e.target.value })} placeholder="809 555 0000" />
                </div>
                <div className="field">
                  <label>Correo</label>
                  <input required type="email" value={form.email} onChange={(e) => setForm({ ...form, email: e.target.value })} placeholder="tu@correo.com" />
                </div>
              </div>
              <div className="field">
                <label>Dirección de entrega</label>
                <input required value={form.address} onChange={(e) => setForm({ ...form, address: e.target.value })} placeholder="Calle, sector, ciudad" />
              </div>
              <div className="field">
                <label>Comentario adicional</label>
                <textarea value={form.note} onChange={(e) => setForm({ ...form, note: e.target.value })} placeholder="Horario de entrega preferido, observaciones, etc." />
              </div>
              <div className="note" style={{ marginTop: 4 }}>
                <b>Productos en tu cotización:</b>
                <div style={{ marginTop: 6, fontFamily: 'var(--font-mono)', fontSize: 11.5, lineHeight: 1.7 }}>
                  {cart.map((it, i) => {
                    const p = window.PRODUCTS.find(x => x.id === it.id);
                    return <div key={it.id}>{i + 1}. {p?.name} — {it.qty} {it.unit}</div>;
                  })}
                </div>
              </div>
              <button type="submit" disabled={loading} className="btn btn-primary btn-block">
                <Icon name="mail" size={16} /> {loading ? 'Enviando...' : 'Enviar solicitud de cotización'}
              </button>
            </form>
          </>
        )}
      </div>
    </div>
  );
};

// ───────────────────────────────────────────────────────────
// Floating WhatsApp
// ───────────────────────────────────────────────────────────
const FloatingWA = ({ contact }) => (
  <a className="wa-float" href={`https://wa.me/${contact.waRaw}`} target="_blank" rel="noopener" aria-label="WhatsApp">
    <Icon name="wa" size={26} />
  </a>
);

Object.assign(window, {
  Icon, Placeholder, Header, Footer, PromoBanner,
  ProductCard, CartDrawer, CartItemRow,
  EmailQuoteForm, FloatingWA, formatCurrency,
});
