/* triaz-sections-2.jsx — Servicio, Casos, Proceso, Pilares, FinalCTA, Footer */

/* ============================================================ */
/*  SERVICIO — two column                                        */
/* ============================================================ */

function Servicio() {
  return (
    <section id="servicio" style={{
      background: "var(--bone-2)",
      borderTop: "1px solid var(--line-light)",
      borderBottom: "1px solid var(--line-light)"
    }}>
      <div className="grid-2-md" style={{
        maxWidth: 1280, margin: "0 auto",
        padding: "112px 32px",
        display: "grid", gridTemplateColumns: "1.05fr 1fr",
        gap: 72, alignItems: "center"
      }}>
        <div>
          <Eyebrow>El servicio</Eyebrow>
          <h2 className="display-m" style={{ margin: "20px 0 24px" }}>
            Sabes que la IA puede cambiar tu forma de trabajar.<br />
            <span style={{ color: "var(--steel)" }}>Lo que falta es por dónde empezar.</span>
          </h2>
          <p className="lede" style={{ margin: "0 0 28px", maxWidth: 540 }}>
            La mayoría de empresas no tienen tiempo, equipo
            técnico ni claridad para aplicar IA a procesos reales. Triaz resuelve ese hueco:
            un consultor que entiende tu operación, se reúne contigo cada mes y
            convierte tareas manuales en flujos apoyados por agentes de IA.
          </p>
          <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "grid", gap: 12 }}>
            {[
            ["users", "Un consultor asignado a tu cuenta"],
            ["calendar-check", "Reunión recurrente · prioridades contigo"],
            ["trending-up", "Resultados medibles"]].
            map(([icon, text]) =>
            <li key={text} style={{ display: "flex", alignItems: "center", gap: 12 }}>
                <span style={{
                width: 28, height: 28, borderRadius: 2,
                background: "var(--bone)", border: "1px solid var(--line-light)",
                display: "inline-flex", alignItems: "center", justifyContent: "center"
              }}>
                  <Icon name={icon} size={14} color="var(--copper)" />
                </span>
                <span style={{ fontSize: 15, color: "var(--ink)", fontWeight: 500 }}>{text}</span>
              </li>
            )}
          </ul>
        </div>

        <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
          <ReviewCard />
          <PullQuote />
        </div>
      </div>
    </section>);

}

function ReviewCard() {
  return (
    <div style={{
      position: "relative",
      background: "#FBF8F2",
      border: "1px solid var(--line-light)",
      borderRadius: "var(--r-3)",
      boxShadow: "var(--shadow-2)",
      padding: 24
    }}>
      <span className="reg tl" />
      <span className="reg tr" />
      <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 18 }}>
        <span style={{ width: 7, height: 7, borderRadius: 999, background: "#4F7A4A", boxShadow: "0 0 0 3px rgba(79,122,74,0.18)" }} />
        <span className="mono" style={{
          fontSize: 10.5, color: "var(--steel)",
          letterSpacing: "0.08em", textTransform: "uppercase"
        }}>
          Sesión mensual · lun 09:30 · oficina Pavimentos
        </span>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "40px 1fr", gap: 12, marginBottom: 18 }}>
        <div style={{
          width: 40, height: 40, borderRadius: 2,
          background: "var(--copper-soft)", color: "#76542A",
          display: "inline-flex", alignItems: "center", justifyContent: "center",
          fontSize: 14, fontWeight: 500
        }}>MV</div>
        <div>
          <div style={{ fontSize: 15, fontWeight: 500, color: "var(--ink)" }}>Marc Vidal — Consultor Triaz</div>
          <div style={{ fontSize: 12.5, color: "var(--steel)", marginTop: 2 }}>
            Revisando 3 procesos · facturas, certificaciones, partes de obra
          </div>
        </div>
      </div>

      <div style={{
        background: "var(--bone)",
        border: "1px solid var(--line-light)",
        borderRadius: 2,
        padding: 14,
        display: "flex", gap: 12, alignItems: "flex-start"
      }}>
        <Icon name="message-square-text" size={16} color="var(--copper)" style={{ marginTop: 2 }} />
        <div style={{ fontSize: 14, lineHeight: 1.55, color: "var(--ink-3)" }}>
          "Este mes empezamos por <strong style={{ color: "var(--ink)", fontWeight: 600 }}>facturas recibidas</strong>:
          es donde se pierden más horas. Te lo dejamos funcionando en dos semanas."
        </div>
      </div>

      <div style={{ marginTop: 18, display: "grid", gap: 10 }}>
        {[
        ["check", "Revisión de procesos del mes anterior", "#4F7A4A"],
        ["target", "Priorización: comparativo de proveedores", "var(--copper)"],
        ["circle-dashed", "Nuevo agente: certificación + facturación", "var(--steel)"]].
        map(([icon, txt, c], i) =>
        <div key={i} style={{ display: "flex", alignItems: "center", gap: 10, fontSize: 13.5, color: "var(--ink-3)" }}>
            <Icon name={icon} size={13} color={c} />
            {txt}
          </div>
        )}
      </div>
    </div>);

}

function PullQuote() {
  return (
    <div className="on-ink" style={{
      background: "var(--ink)", color: "var(--bone)",
      borderRadius: "var(--r-3)",
      padding: 28, position: "relative", overflow: "hidden"
    }}>
      <div style={{
        position: "absolute", top: -22, right: 22,
        fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 120,
        color: "var(--copper)", opacity: 0.18, lineHeight: 1
      }}>"</div>
      <p style={{
        margin: 0, fontSize: 22, lineHeight: 1.32, fontWeight: 500,
        color: "var(--bone)", letterSpacing: "-0.018em"
      }}>
        No contratas una herramienta más. <span style={{ color: "var(--copper)" }}>Incorporas una capacidad nueva dentro de tu empresa.</span>
      </p>
    </div>);

}

/* ============================================================ */
/*  CASOS — 9 use case cards                                     */
/* ============================================================ */

function Casos() {
  const items = [
  { icon: "briefcase", title: "Estudios y gestión comercial",
    body: "Preparar ofertas, comparar históricos y reaprovechar partidas. Llegas a la propuesta con menos olvidos.",
    entra: "pliegos, fichas técnicas e históricos",
    sale: "borrador de oferta listo para revisar" },
  { icon: "wallet", title: "Presupuestos",
    body: "Borradores iniciales a partir del estudio, revisión de partidas y reconciliación con el contrato firmado.",
    entra: "estudio aprobado + contrato",
    sale: "presupuesto reconciliado contra contrato" },
  { icon: "truck", title: "Comparativo de proveedores",
    body: "Pedir, recibir y ordenar ofertas. La IA pone precios, plazos y condiciones lado a lado.",
    entra: "ofertas en PDF, email o WhatsApp",
    sale: "tabla comparada con recomendación" },
  { icon: "calendar-clock", title: "Planificación",
    body: "Mantener el cronograma vivo: hitos, dependencias y reproyecciones cuando algo se mueve.",
    entra: "hitos, dependencias y partes diarios",
    sale: "cronograma actualizado + avisos" },
  { icon: "clipboard-list", title: "Partes de trabajo",
    body: "Pedir horas e incidencias, estructurar respuestas y actualizar todo sin perseguir por WhatsApp.",
    entra: "WhatsApp, audios o formulario",
    sale: "parte cerrado y estructurado" },
  { icon: "receipt", title: "Facturas recibidas",
    body: "Leer facturas del email, extraer los datos y vincularlas con proveedor y concepto.",
    entra: "emails con facturas adjuntas",
    sale: "factura vinculada y lista para validar" },
  { icon: "shield-check", title: "Certificación y facturación",
    body: "Componer certificaciones a cliente, cruzarlas con el contrato y dejar la factura lista para emitir.",
    entra: "avance + partes + contrato",
    sale: "certificación + factura para revisar" },
  { icon: "trending-up", title: "Control económico",
    body: "Cruzar presupuesto, costes reales, horas y facturas para detectar desviaciones antes de que sea tarde.",
    entra: "presupuesto, costes, horas y facturas",
    sale: "alertas accionables tempranas" },
  { icon: "credit-card", title: "Cobros y pagos",
    body: "Seguir vencimientos, conciliar movimientos del banco y avisar de lo que está por cobrar o pagar.",
    entra: "extractos, facturas y vencimientos",
    sale: "estado de tesorería al día" },
  { icon: "user-round", title: "Recursos humanos",
    body: "Recoger ausencias, vacaciones y altas, y mantener los datos del equipo ordenados y accesibles.",
    entra: "solicitudes, partes y documentos",
    sale: "calendario y fichas actualizados" },
  { icon: "file-text", title: "Administración",
    body: "Redactar, clasificar y responder documentación repetitiva: contratos, escritos y formularios.",
    entra: "plantillas y correos entrantes",
    sale: "documento redactado para revisar" },
  { icon: "folder", title: "Documentación",
    body: "Ordenar, buscar y vincular contratos, certificados, informes y archivos de toda la empresa.",
    entra: "contratos, certificados, informes",
    sale: "documento encontrado en segundos" }];

  return (
    <section id="casos" style={{
      background: "var(--bone)",
      borderTop: "1px solid var(--line-light)",
      borderBottom: "1px solid var(--line-light)"
    }}>
      <div style={{ maxWidth: 1280, margin: "0 auto", padding: "112px 32px" }}>
        <div className="grid-2-md" style={{
          display: "grid", gridTemplateColumns: "1.1fr 1fr",
          alignItems: "flex-end", justifyContent: "space-between",
          gap: 32, marginBottom: 56
        }}>
          <div>
            <Eyebrow>Casos de uso</Eyebrow>
            <h2 className="display-m" style={{ margin: "16px 0 0" }}>
              Aplicamos IA <span style={{ color: "var(--copper)" }}>donde tú decidas.</span>
            </h2>
          </div>
          <p className="lede" style={{ margin: 0 }}>
            Los agentes <strong style={{ color: "var(--ink)", fontWeight: 600 }}>leen</strong> información de tu correo y tus documentos,
            <strong style={{ color: "var(--ink)", fontWeight: 600 }}> ejecutan</strong> acciones, razonan y replanifican, y
            <strong style={{ color: "var(--ink)", fontWeight: 600 }}> devuelven</strong> resultados de negocio listos para usar.
          </p>
        </div>

        <div className="grid-3-md" style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 16 }}>
          {items.map((it) =>
          <div key={it.title} className="card-hover" style={{
            background: "#FBF8F2",
            border: "1px solid var(--line-light)",
            borderRadius: "var(--r-2)",
            padding: "22px 22px 18px",
            display: "flex", flexDirection: "column",
            boxShadow: "var(--shadow-1)"
          }}>
              <div style={{
              display: "flex", alignItems: "center",
              marginBottom: 16
            }}>
                <span style={{
                width: 36, height: 36, borderRadius: 2,
                background: "var(--bone-2)", border: "1px solid var(--line-light)",
                display: "inline-flex", alignItems: "center", justifyContent: "center"
              }}>
                  <Icon name={it.icon} size={18} color="var(--ink)" />
                </span>
              </div>
              <h3 style={{
              margin: "0 0 8px",
              fontSize: 16, fontWeight: 500,
              color: "var(--ink)", letterSpacing: "-0.012em"
            }}>{it.title}</h3>
              <p style={{ margin: 0, fontSize: 13.5, lineHeight: 1.55, color: "var(--steel)", flex: 1 }}>{it.body}</p>

              <div style={{
              marginTop: 16, paddingTop: 14,
              borderTop: "1px dashed var(--line-light)",
              display: "grid", gap: 6
            }}>
                <FlowRow label="Entra" value={it.entra} />
                <FlowRow label="Sale" value={it.sale} highlight />
              </div>
            </div>
          )}
        </div>

        <div style={{
          marginTop: 44, textAlign: "center",
          fontSize: 19, lineHeight: 1.5, color: "var(--steel)",
          maxWidth: 720, marginLeft: "auto", marginRight: "auto",
          letterSpacing: "-0.01em"
        }}>
          Estos son solo <strong style={{ color: "var(--ink)", fontWeight: 600 }}>ejemplos</strong>. Creamos un agente a medida para{" "}
          <strong style={{ color: "var(--ink)", fontWeight: 600 }}>cada proceso o flujo de trabajo</strong> que tu empresa necesite.
        </div>
      </div>
    </section>);

}

function FlowRow({ label, value, highlight }) {
  return (
    <div style={{ display: "grid", gridTemplateColumns: "44px 1fr", gap: 10, alignItems: "baseline" }}>
      <span className="mono" style={{
        fontSize: 10, letterSpacing: "0.08em", textTransform: "uppercase",
        color: highlight ? "var(--copper)" : "var(--steel)"
      }}>
        {label}
      </span>
      <span className="mono" style={{
        fontSize: 11.5, lineHeight: 1.5,
        color: highlight ? "var(--ink)" : "var(--ink-3)"
      }}>
        {value}
      </span>
    </div>);

}

/* ============================================================ */
/*  PROCESO — 4 steps, dark section                              */
/* ============================================================ */

function Proceso() {
  const steps = [
  { n: "01", icon: "search", title: "Diagnóstico", body: "Detectamos dónde se pierde tiempo: recursos humanos, control económico, stock, compras, presupuestación, planificación, facturación…" },
  { n: "02", icon: "target", title: "Análisis", body: "Priorizamos los procesos donde la digitalización en la plataforma o los agentes de IA pueden generar un impacto rápido y medible." },
  { n: "03", icon: "sparkles", title: "Configuración de agentes", body: "Conectamos datos, flujos y agentes de IA sobre la plataforma para automatizar análisis, seguimiento, validaciones y reporting." },
  { n: "04", icon: "refresh-cw", title: "Acompañamiento continuo", body: "Un consultor experto revisa contigo resultados, ajusta agentes y propone nuevas automatizaciones cada mes." }];

  return (
    <section id="proceso" className="on-ink" style={{ background: "var(--ink)", color: "var(--bone)" }}>
      <div style={{ maxWidth: 1280, margin: "0 auto", padding: "112px 32px" }}>
        <div className="grid-2-md" style={{
          display: "grid", gridTemplateColumns: "1.5fr 1fr",
          alignItems: "flex-end", justifyContent: "space-between",
          gap: 32, marginBottom: 64
        }}>
          <div>
            <Eyebrow tone="dark">Cómo funciona</Eyebrow>
            <h2 className="display-m" style={{ margin: "16px 0 0", color: "var(--bone)" }}>
              En marcha en quince días,<br />
              <span style={{ color: "var(--copper)" }}>no en meses.</span>
            </h2>
          </div>
        </div>

        <div className="grid-4-md" style={{
          display: "grid", gridTemplateColumns: "repeat(4, 1fr)",
          gap: 24, position: "relative"
        }}>
          <div style={{
            position: "absolute", top: 32, left: 32, right: 32,
            height: 1, background: "rgba(184,136,74,0.32)", zIndex: 0
          }} />
          {steps.map((s, i) =>
          <div key={s.n} style={{ position: "relative", zIndex: 1 }}>
              <div style={{
              width: 64, height: 64, borderRadius: 2,
              background: i === 0 ? "var(--copper)" : "var(--ink-2)",
              border: i === 0 ? "none" : "1px solid var(--ink-3)",
              display: "inline-flex", alignItems: "center", justifyContent: "center",
              marginBottom: 24
            }}>
                <Icon name={s.icon} size={22} color={i === 0 ? "var(--ink)" : "var(--copper)"} />
              </div>
              <div className="mono" style={{
              fontSize: 10.5, color: "var(--copper)",
              letterSpacing: "0.08em", textTransform: "uppercase",
              marginBottom: 8
            }}>
                Paso {s.n}
              </div>
              <h3 style={{
              margin: "0 0 10px",
              fontSize: 20, fontWeight: 500, color: "var(--bone)",
              letterSpacing: "-0.018em"
            }}>{s.title}</h3>
              <p style={{ margin: 0, fontSize: 14, lineHeight: 1.6, color: "var(--steel-2)" }}>{s.body}</p>
            </div>
          )}
        </div>
      </div>
    </section>);

}

/* ============================================================ */
/*  PILARES — 3 cards with blueprint sketches                    */
/* ============================================================ */

function Pilares() {
  const pilares = [
  {
    n: "01", code: "CONSULTOR", sketch: <ConsultorSketch />,
    title: "Un consultor que conoce negocios como el tuyo",
    body: "Alguien de Triaz con experiencia en tu sector te acompaña cada mes: prioriza qué automatizar, revisa contigo los resultados y va incorporando IA en nuevas áreas."
  },
  {
    n: "02", code: "AGENTES", sketch: <AgenteSketch />,
    title: "Agentes de IA aplicados a procesos reales",
    body: "No hablamos de IA en abstracto. Agentes que leen facturas, recogen partes, comparan ofertas, preparan certificaciones, vigilan el control económico y mantienen la documentación al día."
  },
  {
    n: "03", code: "PLATAFORMA", sketch: <PlataformaSketch />,
    title: "Una sola plataforma",
    body: "Datos, procesos, agentes, automatizaciones, documentos, conversaciones, permisos y trazabilidad viven en un mismo lugar. No necesitas contratar un ERP ni software de terceros."
  }];

  return (
    <section id="pilares" style={{ maxWidth: 1280, margin: "0 auto", padding: "112px 32px" }}>
      <div className="grid-2-md" style={{
        display: "grid", gridTemplateColumns: "1.4fr 1fr",
        alignItems: "flex-end", justifyContent: "space-between",
        gap: 32, marginBottom: 56
      }}>
        <div>
          <Eyebrow>Tres ejes · un resultado</Eyebrow>
          <h2 className="display-m" style={{ margin: "16px 0 0" }}>
            Tres pilares. <span style={{ color: "var(--steel)" }}>Una sola relación.</span>
          </h2>
        </div>
        <p className="lede" style={{ margin: 0 }}>
          Un consultor que entiende tu negocio, agentes de IA sobre tus procesos reales y
          una sola plataforma donde vive todo.
        </p>
      </div>

      <div className="grid-3-md" style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 16 }}>
        {pilares.map((p) =>
        <div key={p.n} className="card-hover" style={{
          background: "#FBF8F2",
          border: "1px solid var(--line-light)",
          borderRadius: "var(--r-3)",
          boxShadow: "var(--shadow-1)",
          overflow: "hidden",
          display: "flex", flexDirection: "column"
        }}>
            <div style={{
            position: "relative",
            height: 168,
            background: "radial-gradient(92% 96% at 80% 14%, rgba(184,136,74,0.16), transparent 60%), var(--bone-2)",
            borderBottom: "1px solid var(--line-light)",
            boxShadow: "inset 0 -1px 0 rgba(184,136,74,0.45)",
            overflow: "hidden"
          }}>
              {p.sketch}
            </div>
            <div style={{ padding: 28, display: "flex", flexDirection: "column", flex: 1 }}>
              <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 16 }}>
                <span className="mono" style={{
                fontSize: 10.5, color: "var(--copper)", fontWeight: 500, letterSpacing: "0.08em",
                background: "var(--copper-soft)", padding: "3px 10px", borderRadius: 2
              }}>
                  {p.n}
                </span>
                <span className="mono" style={{
                fontSize: 10, color: "var(--steel)",
                letterSpacing: "0.1em", textTransform: "uppercase"
              }}>
                  {p.code}
                </span>
              </div>
              <h3 style={{
              margin: "0 0 12px",
              fontSize: 19, fontWeight: 500, lineHeight: 1.25,
              color: "var(--ink)", letterSpacing: "-0.014em"
            }}>{p.title}</h3>
              <p style={{ margin: 0, fontSize: 14.5, lineHeight: 1.6, color: "var(--steel)" }}>{p.body}</p>
            </div>
          </div>
        )}
      </div>
    </section>);

}

/* ============================================================ */
/*  Pillar brand-plates — full-bleed Ink panels built from the   */
/*  TRIAZ echelon-plane motif. Art, not diagrams.                */
/* ============================================================ */

const PLATE_GROUND = "#E8E3D9";
const PLATE_INK   = "#0B0B0C";
const PLATE_INK2  = "#3A3A3F";
const PLATE_LINE  = "rgba(11,11,12,0.40)";
const PLATE_LINE2 = "rgba(11,11,12,0.22)";
const PLATE_BONE  = "#F2EEE7";
const PLATE_COP   = "#B8884A";
const PLATE_COP2  = "#C9985A";
const PLATE_ISO_D = "M25.9023 95L45.4023 105.5L26.0537 118.823L6.90234 108.5L25.9023 95ZM60.4023 72.5L116.402 104.5L98.4023 117L41.4023 85.5L60.4023 72.5ZM53.9385 64.5L0.402344 100.5L0 76.1514L53.9385 40.7871V64.5ZM100.402 61.5L120.402 74V96L100.402 84.7969V61.5ZM63.4023 0L84.4023 12V75.2812L63.4023 63V0ZM53.4053 22.7656L33.4053 35.5V35.499L33.4043 35.5V35.498L33.4023 35.5V13L53.4023 0V0.000976562L53.4053 0V22.7656Z";

/* leaning parallelogram (echoes the isotype shear) */
function planePoints(x, y, w, h, s) {
  return `${x + s},${y} ${x + s + w},${y} ${x + w},${y + h} ${x},${y + h}`;
}

/* 4-point AI sparkle */
function sparkle(cx, cy, outer, inner) {
  const pts = [];
  for (let i = 0; i < 8; i++) {
    const ang = (Math.PI / 4) * i - Math.PI / 2;
    const r = i % 2 === 0 ? outer : inner;
    pts.push(`${(cx + r * Math.cos(ang)).toFixed(1)},${(cy + r * Math.sin(ang)).toFixed(1)}`);
  }
  return pts.join(" ");
}

/* arrowhead triangle: tip at (tx,ty), pointing along unit dir (dx,dy) */
function arrowTri(tx, ty, dx, dy, len = 9, half = 5) {
  const bx = tx - dx * len, by = ty - dy * len;
  const px = -dy, py = dx;
  return `${tx.toFixed(1)},${ty.toFixed(1)} ${(bx + px * half).toFixed(1)},${(by + py * half).toFixed(1)} ${(bx - px * half).toFixed(1)},${(by - py * half).toFixed(1)}`;
}

/* shared canvas: icon-only SVG, fit with margins (ground/glow live on the panel) */
function PlateBase({ children }) {
  return (
    <svg viewBox="0 0 300 168" width="100%" height="100%" preserveAspectRatio="xMidYMid meet"
      style={{ display: "block", position: "absolute", inset: 0 }} aria-hidden="true">
      {children}
    </svg>);

}

/* ① EXPERTO A TU LADO — two peers; the Triaz expert (copper) beside you (ink) */
function ConsultorSketch() {
  const ex = 121, you = 185, hy = 60, hr = 17, base = 130;
  return (
    <PlateBase>
      {/* shared ground */}
      <line x1="70" y1={base} x2="232" y2={base} stroke={PLATE_LINE2} strokeWidth="1.4" />

      {/* YOU — ink line figure */}
      <g stroke={PLATE_INK} strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" fill="none">
        <circle cx={you} cy={hy} r={hr} />
        <path d={`M ${you - 31} ${base} C ${you - 31} ${hy + 22}, ${you + 31} ${hy + 22}, ${you + 31} ${base}`} />
      </g>

      {/* EXPERT — solid copper figure, forward */}
      <circle cx={ex} cy={hy} r={hr + 1} fill={PLATE_COP} />
      <path d={`M ${ex - 34} ${base} C ${ex - 34} ${hy + 20}, ${ex + 34} ${hy + 20}, ${ex + 34} ${base} Z`} fill={PLATE_COP} />
    </PlateBase>);

}

/* ② AGENTE IA AUTOMATIZANDO UN PROCESO — AI core inside an automation cycle */
function AgenteSketch() {
  const cx = 150, cy = 84, R = 44;
  return (
    <PlateBase>
      {/* automation double-arrow cycle */}
      <g fill="none" stroke={PLATE_COP} strokeWidth="2.4" strokeLinecap="round">
        <path d={`M ${cx - 41.3} ${cy - 19} A ${R} ${R} 0 0 1 ${cx + 41.3} ${cy - 19}`} />
        <path d={`M ${cx + 41.3} ${cy + 19} A ${R} ${R} 0 0 1 ${cx - 41.3} ${cy + 19}`} />
      </g>
      <polygon points={arrowTri(cx + 41.3, cy - 19, 0.42, 0.91)} fill={PLATE_COP} />
      <polygon points={arrowTri(cx - 41.3, cy + 19, -0.42, -0.91)} fill={PLATE_COP} />

      {/* AI processor core */}
      <g stroke={PLATE_INK} strokeWidth="2.4" strokeLinecap="round">
        {[-12, 0, 12].map((d, i) =>
        <line key={"t" + i} x1={cx + d} y1={cy - 19} x2={cx + d} y2={cy - 26} />
        )}
        {[-12, 0, 12].map((d, i) =>
        <line key={"b" + i} x1={cx + d} y1={cy + 19} x2={cx + d} y2={cy + 26} />
        )}
        {[-7, 7].map((d, i) =>
        <line key={"l" + i} x1={cx - 19} y1={cy + d} x2={cx - 26} y2={cy + d} />
        )}
        {[-7, 7].map((d, i) =>
        <line key={"r" + i} x1={cx + 19} y1={cy + d} x2={cx + 26} y2={cy + d} />
        )}
      </g>
      <rect x={cx - 19} y={cy - 19} width="38" height="38" rx="7" fill={PLATE_INK} />
      <polygon points={sparkle(cx, cy, 11.5, 4.2)} fill={PLATE_COP} />
    </PlateBase>);

}

/* ③ PLATAFORMA — every stream of the business converging into one place */
function PlataformaSketch() {
  const sources = [
  { x: 50, y: 40 },
  { x: 44, y: 84 },
  { x: 54, y: 128 },
  { x: 250, y: 42 },
  { x: 256, y: 86 },
  { x: 246, y: 130 }];

  const cx = 150, cy = 84;
  return (
    <PlateBase>
      {/* converging streams + inward arrowheads */}
      {sources.map((s, i) => {
        const dx = cx - s.x, dy = cy - s.y;
        const len = Math.sqrt(dx * dx + dy * dy);
        const ux = dx / len, uy = dy / len;
        const ex = s.x + ux * (len - 40), ey = s.y + uy * (len - 40);
        return (
          <g key={i}>
            <line x1={s.x + ux * 9} y1={s.y + uy * 9} x2={ex} y2={ey} stroke={PLATE_LINE2} strokeWidth="1.4" />
            <polygon points={arrowTri(ex, ey, ux, uy, 7, 4)} fill={PLATE_LINE} />
            <rect x={s.x - 8} y={s.y - 7} width="16" height="14" rx="2.5"
              fill={PLATE_GROUND} stroke={PLATE_INK} strokeWidth="1.8" />
          </g>);

      })}
      {/* the single platform — copper hub holding the isotype */}
      <rect x={cx - 35} y={cy - 31} width="70" height="62" rx="6" fill={PLATE_COP} />
      <g transform={`translate(${cx - 17.5} ${cy - 16}) scale(0.27)`}>
        <path d={PLATE_ISO_D} fill={PLATE_INK} />
      </g>
    </PlateBase>);

}

/* ============================================================ */
/*  CTA FINAL — form                                             */
/* ============================================================ */

function FinalCTA() {
  return (
    <section id="cta" className="on-ink" style={{ background: "var(--ink)", color: "var(--bone)" }}>
      <div style={{ maxWidth: 1280, margin: "0 auto", padding: "112px 32px", position: "relative" }}>
        <div style={{
          position: "absolute", top: 0, right: 0, width: 540, height: 380,
          background: "radial-gradient(50% 50% at 70% 50%, rgba(184,136,74,0.22), transparent 70%)",
          pointerEvents: "none"
        }} />
        <div style={{ position: "relative", maxWidth: 880, marginBottom: 48 }}>
          <Eyebrow tone="dark">¿Hablamos?</Eyebrow>
          <h2 className="display-m" style={{
            margin: "16px 0 0", color: "var(--bone)"
          }}>
            Cuéntanos sobre tu empresa. <span style={{ color: "var(--steel-2)" }}>Son 2 minutos. Sin compromiso.</span>
          </h2>
        </div>

        <div className="grid-2-md" style={{
          position: "relative",
          display: "grid", gridTemplateColumns: "0.85fr 1.15fr",
          gap: 20, alignItems: "stretch"
        }}>
          <ValueCard />
          <ContactForm />
        </div>
      </div>
    </section>);

}

function ValueCard() {
  return (
    <div style={{
      background: "var(--ink-2)",
      border: "1px solid var(--ink-3)",
      borderRadius: "var(--r-3)",
      padding: 32,
      display: "flex", flexDirection: "column",
      position: "relative", overflow: "hidden"
    }}>
      <div style={{
        position: "absolute", top: -80, right: -80, width: 280, height: 280,
        background: "radial-gradient(50% 50% at 50% 50%, rgba(184,136,74,0.42), transparent 70%)",
        pointerEvents: "none"
      }} />
      <div style={{ position: "relative", zIndex: 1, display: "flex", alignItems: "center", gap: 12 }}>
        <TriazTile size={42} bg="var(--bone)" fg="var(--ink)" radius={4} />
        <TriazWordmark height={18} fill="var(--bone)" />
      </div>
      <h3 style={{
        position: "relative", zIndex: 1,
        margin: "28px 0 16px",
        fontSize: 22, fontWeight: 500, color: "var(--bone)",
        letterSpacing: "-0.018em", lineHeight: 1.25
      }}>
        Diagnóstico inicial.<br />
        <span style={{ color: "var(--copper)" }}>Lo que te llevas:</span>
      </h3>
      <ul style={{
        position: "relative", zIndex: 1,
        listStyle: "none", padding: 0, margin: "0 0 32px",
        display: "grid", gap: 14
      }}>
        {[
        "Mapa de procesos priorizados por impacto",
        "Estimación de ahorro mensual realista",
        "Plan de implantación en 2 semanas",
        "Quién te acompaña por nuestra parte"].
        map((t) =>
        <li key={t} style={{
          display: "flex", alignItems: "flex-start", gap: 12,
          fontSize: 14.5, color: "var(--bone)", lineHeight: 1.5
        }}>
            <span style={{
            width: 22, height: 22, borderRadius: 2,
            background: "rgba(184,136,74,0.22)",
            display: "inline-flex", alignItems: "center", justifyContent: "center",
            flexShrink: 0, marginTop: 1
          }}>
              <Icon name="check" size={12} color="var(--copper)" />
            </span>
            {t}
          </li>
        )}
      </ul>
    </div>);

}

/* HubSpot Forms — submission endpoint (public, CORS-enabled) */
const HUBSPOT_PORTAL_ID = "143803870";
const HUBSPOT_FORM_GUID = "a1b69c32-837f-4067-a87f-72dafec77eba";
const HUBSPOT_ENDPOINT = `https://api.hsforms.com/submissions/v3/integration/submit/${HUBSPOT_PORTAL_ID}/${HUBSPOT_FORM_GUID}`;

function ContactForm() {
  const sizes = [
  { label: "< 5", value: "1-4" },
  { label: "5-11", value: "5-11" },
  { label: "11-50", value: "11-50" },
  { label: "51-200", value: "51-200" },
  { label: "> 200", value: "201-500" }];

  const [size, setSize] = React.useState(null);
  const [form, setForm] = React.useState({
    firstname: "", lastname: "", company: "", jobtitle: "", email: "",
    dial: "ES +34", phone: ""
  });
  const [status, setStatus] = React.useState("idle"); // idle | submitting | success | error
  const [errorMsg, setErrorMsg] = React.useState("");

  const set = (key) => (e) => setForm((f) => ({ ...f, [key]: e.target.value }));

  async function handleSubmit(e) {
    e.preventDefault();
    if (status === "submitting") return;
    setStatus("submitting");
    setErrorMsg("");

    const dialCode = (form.dial.match(/\+\d+/) || [""])[0];
    const fullPhone = [dialCode, form.phone.trim()].filter(Boolean).join(" ");

    const fields = [
      { name: "firstname", value: form.firstname.trim() },
      { name: "lastname",  value: form.lastname.trim() },
      { name: "company",   value: form.company.trim() },
      { name: "jobtitle",  value: form.jobtitle.trim() },
      { name: "email",     value: form.email.trim() },
      { name: "phone",     value: fullPhone },
      { name: "numemployees", value: size || "" }
    ].filter((f) => f.value !== "");

    const payload = {
      fields,
      context: {
        pageUri: typeof window !== "undefined" ? window.location.href : "",
        pageName: "Triaz — Landing"
      }
    };

    try {
      const res = await fetch(HUBSPOT_ENDPOINT, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(payload)
      });
      if (res.ok) {
        setStatus("success");
      } else {
        let detail = "";
        try {
          const j = await res.json();
          detail = (j.errors && j.errors[0] && (j.errors[0].message || j.errors[0].errorType)) || j.message || "";
        } catch (_) {}
        setStatus("error");
        setErrorMsg(detail || "No se pudo enviar. Inténtalo de nuevo en unos minutos.");
      }
    } catch (err) {
      setStatus("error");
      setErrorMsg("No hay conexión con el servidor. Revisa tu red e inténtalo de nuevo.");
    }
  }

  if (status === "success") {
    return (
      <div style={{
        background: "var(--bone)",
        border: "1px solid var(--line-light)",
        borderRadius: "var(--r-3)",
        padding: 32,
        color: "var(--ink)",
        minHeight: 420,
        display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", textAlign: "center"
      }}>
        <span style={{
          width: 54, height: 54, borderRadius: 4,
          background: "var(--copper)",
          display: "inline-flex", alignItems: "center", justifyContent: "center", marginBottom: 22
        }}>
          <Icon name="check" size={26} color="var(--ink)" />
        </span>
        <h3 style={{ fontSize: 22, fontWeight: 500, letterSpacing: "-0.018em", margin: "0 0 10px" }}>
          ¡Gracias{form.firstname ? `, ${form.firstname}` : ""}!
        </h3>
        <p style={{ margin: "0 0 24px", fontSize: 15, color: "var(--steel)", maxWidth: 360, lineHeight: 1.55 }}>
          Hemos recibido tu consulta. Un partner de Triaz se pondrá en contacto contigo muy pronto.
        </p>
        <button type="button" className="btn btn-secondary"
          onClick={() => { setStatus("idle"); setForm({ firstname: "", lastname: "", company: "", jobtitle: "", email: "", dial: "ES +34", phone: "" }); setSize(null); }}>
          Enviar otra consulta
        </button>
      </div>);

  }

  const submitting = status === "submitting";

  return (
    <form
      onSubmit={handleSubmit}
      style={{
        background: "var(--bone)",
        border: "1px solid var(--line-light)",
        borderRadius: "var(--r-3)",
        padding: 32,
        color: "var(--ink)"
      }}>
      
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 18 }}>
        <Field label="Nombre" placeholder="Juan" value={form.firstname} onChange={set("firstname")} required />
        <Field label="Apellidos" placeholder="García" value={form.lastname} onChange={set("lastname")} />
        <Field label="Empresa" placeholder="Constructora S.L." value={form.company} onChange={set("company")} />
        <Field label="Cargo" placeholder="Director de operaciones" value={form.jobtitle} onChange={set("jobtitle")} />
        <Field label="Email" placeholder="juan@empresa.es" type="email" value={form.email} onChange={set("email")} required />
        <PhoneField dial={form.dial} phone={form.phone} onDial={set("dial")} onPhone={set("phone")} />
      </div>

      <div style={{ marginTop: 24 }}>
        <FieldLabel>Número de empleados</FieldLabel>
        <div style={{ display: "flex", gap: 8, flexWrap: "wrap", marginTop: 10 }}>
          {sizes.map((s) =>
          <button key={s.value} type="button"
          className={"size-pill" + (size === s.value ? " active" : "")}
          onClick={() => setSize(s.value)}>
              {s.label}
            </button>
          )}
        </div>
      </div>

      {status === "error" &&
      <div style={{
        marginTop: 22, padding: "12px 14px",
        background: "rgba(154,58,46,0.08)",
        border: "1px solid rgba(154,58,46,0.32)",
        borderRadius: "var(--r-2)",
        display: "flex", alignItems: "flex-start", gap: 10,
        fontSize: 13, lineHeight: 1.5, color: "#7E2D23"
      }}>
          <Icon name="circle-dashed" size={15} color="#9A3A2E" style={{ marginTop: 1, flexShrink: 0 }} />
          {errorMsg}
        </div>}

      <button
        type="submit"
        className="btn btn-primary"
        disabled={submitting}
        style={{
          width: "100%", height: 54,
          marginTop: status === "error" ? 16 : 28, fontSize: 15, fontWeight: 500,
          background: "var(--ink)",
          opacity: submitting ? 0.7 : 1,
          cursor: submitting ? "default" : "pointer"
        }}>
        {submitting ? "Enviando…" : "Enviar consulta"}
        {!submitting && <Icon name="arrow-right" size={15} />}
      </button>

      <div style={{
        marginTop: 14, fontFamily: "var(--font-mono)", fontSize: 11,
        color: "var(--steel)", letterSpacing: "0.04em",
        display: "flex", alignItems: "center", gap: 8, justifyContent: "center"
      }}>
        <Icon name="lock" size={11} color="var(--steel)" />
        Tus datos solo se usan para responderte. Sin spam, sin venta a terceros.
      </div>
    </form>);

}

function Field({ label, type = "text", placeholder, value, onChange, required }) {
  return (
    <div>
      <FieldLabel>{label}</FieldLabel>
      <input className="input" type={type} placeholder={placeholder}
        value={value} onChange={onChange} required={required} />
    </div>);

}

function PhoneField({ dial, phone, onDial, onPhone }) {
  return (
    <div>
      <FieldLabel>Teléfono</FieldLabel>
      <div style={{ display: "flex", gap: 8 }}>
        <select className="input" style={{ flex: "0 0 100px", paddingLeft: 10, paddingRight: 6 }}
          value={dial} onChange={onDial}>
          <option>ES +34</option>
          <option>FR +33</option>
          <option>PT +351</option>
          <option>UK +44</option>
          <option>DE +49</option>
          <option>IT +39</option>
        </select>
        <input className="input" type="tel" placeholder="Tu número de teléfono" style={{ flex: 1 }}
          value={phone} onChange={onPhone} />
      </div>
    </div>);

}

function FieldLabel({ children }) {
  return (
    <label className="mono" style={{
      display: "block", fontSize: 10.5, fontWeight: 500,
      letterSpacing: "0.08em", textTransform: "uppercase",
      color: "var(--steel)", marginBottom: 8
    }}>
      {children}
    </label>);

}

/* ============================================================ */
/*  FOOTER                                                       */
/* ============================================================ */

function Footer() {
  return (
    <footer style={{
      background: "var(--bone-2)",
      borderTop: "1px solid var(--line-light)"
    }}>
      <div style={{ maxWidth: 1280, margin: "0 auto", padding: "56px 32px 32px" }}>
        <div className="grid-4-md" style={{
          display: "grid", gridTemplateColumns: "1.7fr 1fr 1fr 1fr",
          gap: 40, marginBottom: 48
        }}>
          <div>
            <div style={{ marginBottom: 16 }}>
              <TriazWordmark height={22} fill="var(--ink)" />
            </div>
            <p style={{
              margin: 0, fontSize: 13.5, color: "var(--steel)",
              maxWidth: 360, lineHeight: 1.6
            }}>IA aplicada a la operación de empresas. Consultor experto, plataforma única y agentes especializados, en una sola relación.


            </p>
          </div>

          {/* Sectores */}
          <div>
            <div className="mono" style={{
              fontSize: 10.5, color: "var(--steel)",
              letterSpacing: "0.08em", textTransform: "uppercase",
              marginBottom: 16
            }}>Sectores</div>
            <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "grid", gap: 10 }}>
              <li>
                <a href="/construccion" style={{
                  fontSize: 14, color: "var(--ink)",
                  display: "inline-flex", alignItems: "center", gap: 8
                }}>
                  Construcción
                  <Icon name="arrow-right" size={12} color="var(--copper)" />
                </a>
              </li>
              {["Ingeniería", "Instalaciones", "Industria"].map((s) =>
              <li key={s} style={{
                fontSize: 14, color: "var(--steel-2)",
                display: "flex", alignItems: "center", gap: 8
              }}>
                  {s}
                  <span className="mono" style={{
                  fontSize: 9, letterSpacing: "0.08em", textTransform: "uppercase",
                  color: "var(--steel)", border: "1px solid var(--line-light)",
                  borderRadius: 2, padding: "1px 5px"
                }}>pronto</span>
                </li>
              )}
            </ul>
          </div>

          {[
          { h: "Producto", l: ["Plataforma", "Agentes", "Casos de uso"] },
          { h: "Empresa", l: ["Sobre Triaz", "Contacto", "LinkedIn", "Instagram"] }].
          map((col) =>
          <div key={col.h}>
              <div className="mono" style={{
              fontSize: 10.5, color: "var(--steel)",
              letterSpacing: "0.08em", textTransform: "uppercase",
              marginBottom: 16
            }}>{col.h}</div>
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "grid", gap: 10 }}>
                {col.l.map((a) =>
              <li key={a}>
                    <a href={a === "LinkedIn" ? "https://www.linkedin.com/company/triaz" : a === "Instagram" ? "https://www.instagram.com/triaz.io/" : a === "Contacto" ? "#cta" : "#"}
                       target={(a === "LinkedIn" || a === "Instagram") ? "_blank" : undefined}
                       rel={(a === "LinkedIn" || a === "Instagram") ? "noopener noreferrer" : undefined}
                       style={{ fontSize: 14, color: "var(--ink)" }}>{a}</a>
                  </li>
              )}
              </ul>
            </div>
          )}
        </div>
        <div style={{
          paddingTop: 22, borderTop: "1px solid var(--line-light)",
          display: "flex", justifyContent: "space-between", flexWrap: "wrap", gap: 16,
          fontFamily: "var(--font-mono)", fontSize: 10.5,
          color: "var(--steel)", letterSpacing: "0.05em", textTransform: "uppercase"
        }}>
          <span>© 2026 Triaz · Sevilla</span>
          <div style={{ display: "flex", gap: 28 }}>
            <a href="#">Aviso legal</a>
            <a href="#">Privacidad</a>
            <a href="#">Cookies</a>
          </div>
        </div>
      </div>
    </footer>);

}

Object.assign(window, { Servicio, Pilares, Proceso, Casos, FinalCTA, Footer });