// Dalflow — all 5 pages

const { useState: useStateP, useEffect: useEffectP, useRef: useRefP } = React;

const TOOL_ICONS = {
  'Anthropic': 'anthropic', 'Gemini': 'googlegemini',
  'Make': 'make', 'n8n': 'n8n', 'Zapier': 'zapier', 'App Script': 'googleappsscript',
  'Odoo': 'odoo', 'Shopify': 'shopify', 'Supabase': 'supabase', 'Airtable': 'airtable',
  'Notion': 'notion', 'Google Sheets': 'googlesheets',
  'WhatsApp API': 'whatsapp', 'Meta API': 'meta',
  'Typeform': 'typeform', 'Calendly': 'calendly'
};

// Inline SVGs for tools whose icons are not on the simpleicons CDN
const TOOL_ICONS_INLINE = {
  'OpenAI':
  <svg viewBox="0 0 24 24" width="15" height="15" fill="currentColor" style={{ display: 'block', flexShrink: 0 }} aria-hidden="true">
      <path d="M22.282 9.821a5.985 5.985 0 0 0-.516-4.91 6.046 6.046 0 0 0-6.51-2.9A6.065 6.065 0 0 0 4.981 4.18a5.985 5.985 0 0 0-3.998 2.9 6.046 6.046 0 0 0 .743 7.097 5.98 5.98 0 0 0 .51 4.911 6.051 6.051 0 0 0 6.515 2.9A5.985 5.985 0 0 0 13.26 24a6.056 6.056 0 0 0 5.772-4.206 5.99 5.99 0 0 0 3.997-2.9 6.056 6.056 0 0 0-.747-7.073zM13.26 22.43a4.476 4.476 0 0 1-2.876-1.04l.142-.08 4.778-2.758a.795.795 0 0 0 .393-.681v-6.737l2.02 1.168a.071.071 0 0 1 .038.052v5.583a4.504 4.504 0 0 1-4.495 4.494zM3.6 18.304a4.47 4.47 0 0 1-.535-3.014l.142.085 4.783 2.759a.771.771 0 0 0 .78 0l5.843-3.369v2.332a.08.08 0 0 1-.033.062L9.74 19.95a4.5 4.5 0 0 1-6.14-1.646zM2.34 7.896a4.485 4.485 0 0 1 2.366-1.973V11.6a.766.766 0 0 0 .388.677l5.815 3.355-2.02 1.168a.076.076 0 0 1-.071 0l-4.83-2.786a4.504 4.504 0 0 1-1.65-6.142zm16.596 3.855l-5.833-3.387L15.119 7.2a.076.076 0 0 1 .071 0l4.83 2.786a4.495 4.495 0 0 1-.676 8.105v-5.678a.79.79 0 0 0-.407-.667zm2.01-3.023l-.141-.085-4.774-2.782a.776.776 0 0 0-.785 0L9.409 9.23V6.897a.066.066 0 0 1 .028-.061l4.83-2.787a4.5 4.5 0 0 1 6.681 4.66zm-12.64 4.135l-2.02-1.164a.08.08 0 0 1-.038-.057V6.075a4.5 4.5 0 0 1 7.375-3.453l-.142.08L8.704 5.46a.795.795 0 0 0-.393.682zm1.097-2.365l2.602-1.5 2.607 1.5v2.999l-2.602 1.5-2.607-1.5z" />
    </svg>,

  'Microsoft Outlook':
  <svg viewBox="0 0 24 24" width="15" height="15" fill="currentColor" style={{ display: 'block', flexShrink: 0 }} aria-hidden="true">
      <path d="M7.88 12.04q0 .45-.11.87-.1.41-.33.74-.22.33-.56.52-.34.2-.78.2-.45 0-.79-.2-.34-.2-.55-.53-.21-.34-.31-.74-.1-.41-.1-.84 0-.43.1-.86.1-.43.32-.77.22-.34.56-.55.34-.21.79-.21.45 0 .78.21.34.21.55.55.22.34.32.77.1.43.1.84zM24 12v9.38q0 .46-.33.8-.33.32-.8.32H7.13q-.46 0-.8-.33-.32-.33-.32-.8V18H1q-.41 0-.7-.3-.3-.29-.3-.7V7q0-.41.3-.7Q.58 6 1 6h6.5V2.55q0-.44.3-.75.3-.3.75-.3h13.4q.44 0 .75.3.3.3.3.75v8.3l1.24.72h.01q.1.07.18.18.07.12.07.25zm-6-8.25v3h3v-3zm0 4.5v3h3v-3zm0 4.5v1.83l3.05-1.83zm-5.25-9v3h3.75v-3zm0 4.5v3h3.75v-3zm0 4.5v2.03l2.41 1.5 1.34-.8v-2.73zM9 3.75V6h2l.13.01.12.04v-2.3zM5.98 15.98q.9 0 1.6-.3.7-.32 1.19-.86.48-.55.73-1.28.25-.74.25-1.61 0-.83-.25-1.55-.24-.71-.71-1.24t-1.15-.83q-.68-.3-1.55-.3-.92 0-1.64.3-.71.3-1.2.85-.5.54-.75 1.3-.25.74-.25 1.63 0 .85.26 1.56.26.72.74 1.23.48.52 1.17.81.69.3 1.56.3zM7.5 21h12.39L12 16.08V17q0 .41-.3.7-.29.3-.7.3H7.5zm15-.13v-7.24l-5.9 3.54z" />
    </svg>,

  'Google Workspace':
  <svg viewBox="0 0 24 24" width="15" height="15" fill="currentColor" style={{ display: 'block', flexShrink: 0 }} aria-hidden="true">
      <path d="M12.48 10.92v3.28h7.84c-.24 1.84-.853 3.187-1.787 4.133-1.147 1.147-2.933 2.4-6.053 2.4-4.827 0-8.6-3.893-8.6-8.72s3.773-8.72 8.6-8.72c2.6 0 4.507 1.027 5.907 2.347l2.307-2.307C18.747 1.44 16.133 0 12.48 0 5.867 0 .307 5.387.307 12s5.56 12 12.173 12c3.573 0 6.267-1.173 8.373-3.36 2.16-2.16 2.84-5.213 2.84-7.667 0-.76-.053-1.467-.173-2.053H12.48z" />
    </svg>

};

// ===== Thematic service illustrations =====
function AutoArt() {
  return (
    <svg viewBox="0 0 320 400" fill="none" xmlns="http://www.w3.org/2000/svg">
      <rect x="110" y="32" width="100" height="52" rx="12" fill="var(--surface-rise)" stroke="var(--border-strong)" strokeWidth="1.5" />
      <text x="160" y="62" textAnchor="middle" fill="var(--ink-dim)" fontFamily="var(--font-mono)" fontSize="11" letterSpacing="0.08em">EMAIL / LEAD</text>
      <line x1="160" y1="84" x2="160" y2="120" stroke="var(--accent)" strokeWidth="1.5" strokeDasharray="4 3" />
      <circle cx="160" cy="148" r="28" fill="rgba(200,255,61,0.08)" stroke="var(--accent)" strokeWidth="1.5" />
      <text x="160" y="144" textAnchor="middle" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.06em">AI</text>
      <text x="160" y="157" textAnchor="middle" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.06em">AGENT</text>
      <line x1="136" y1="172" x2="88" y2="222" stroke="var(--border-strong)" strokeWidth="1.2" />
      <line x1="184" y1="172" x2="232" y2="222" stroke="var(--border-strong)" strokeWidth="1.2" />
      <rect x="40" y="222" width="96" height="46" rx="10" fill="var(--surface-rise)" stroke="var(--border)" strokeWidth="1" />
      <text x="88" y="241" textAnchor="middle" fill="var(--ink-dim)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.06em">AUTO-REPLY</text>
      <text x="88" y="255" textAnchor="middle" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.06em">EMAIL ✓</text>
      <rect x="184" y="222" width="96" height="46" rx="10" fill="var(--surface-rise)" stroke="var(--border)" strokeWidth="1" />
      <text x="232" y="241" textAnchor="middle" fill="var(--ink-dim)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.06em">CRM</text>
      <text x="232" y="255" textAnchor="middle" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.06em">ASSIGNAT ✓</text>
      <line x1="88" y1="268" x2="88" y2="304" stroke="var(--border)" strokeWidth="1" strokeDasharray="3 3" />
      <line x1="232" y1="268" x2="232" y2="304" stroke="var(--border)" strokeWidth="1" strokeDasharray="3 3" />
      <rect x="56" y="304" width="64" height="34" rx="8" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <text x="88" y="326" textAnchor="middle" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="9">NOTIF.</text>
      <rect x="200" y="304" width="64" height="34" rx="8" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <text x="232" y="326" textAnchor="middle" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="9">FOLLOW-UP</text>
      <circle cx="160" cy="148" r="4" fill="var(--accent)">
        <animate attributeName="opacity" values="1;0.3;1" dur="2.4s" repeatCount="indefinite" />
      </circle>
    </svg>);

}

function IntegArt() {
  const spokes = [
  { angle: -90, label: 'ERP' },
  { angle: -30, label: 'CRM' },
  { angle: 30, label: 'EMAIL' },
  { angle: 90, label: 'SHEETS' },
  { angle: 150, label: 'SHOP' },
  { angle: 210, label: 'MKTPL' }];

  const cx = 160,cy = 200,r = 110,nodeR = 34;
  return (
    <svg viewBox="0 0 320 400" fill="none" xmlns="http://www.w3.org/2000/svg">
      {spokes.map((s, i) => {
        const rad = s.angle * Math.PI / 180;
        const x = cx + r * Math.cos(rad);
        const y = cy + r * Math.sin(rad);
        return (
          <g key={i}>
            <line x1={cx} y1={cy} x2={x} y2={y} stroke="var(--border-strong)" strokeWidth="1" strokeDasharray="4 3" />
            <rect x={x - nodeR} y={y - 18} width={nodeR * 2} height="36" rx="9" fill="var(--surface-rise)" stroke="var(--border)" strokeWidth="1" />
            <text x={x} y={y + 4} textAnchor="middle" fill="var(--ink-dim)" fontFamily="var(--font-mono)" fontSize="9.5" letterSpacing="0.06em">{s.label}</text>
          </g>);

      })}
      <circle cx={cx} cy={cy} r="36" fill="rgba(200,255,61,0.06)" stroke="var(--accent)" strokeWidth="1.5" />
      <circle cx={cx} cy={cy} r="6" fill="var(--accent)">
        <animate attributeName="r" values="6;9;6" dur="2s" repeatCount="indefinite" />
        <animate attributeName="opacity" values="1;0.5;1" dur="2s" repeatCount="indefinite" />
      </circle>
      <text x={cx} y={cy - 10} textAnchor="middle" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="8" letterSpacing="0.1em">SYNC</text>
      <text x={cx} y={cy + 18} textAnchor="middle" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="7.5" letterSpacing="0.08em">REAL-TIME</text>
    </svg>);

}

function DashArt() {
  const bars = [62, 85, 48, 94, 70, 55, 88];
  const bw = 22,gap = 8,startX = 42,baseY = 290,maxH = 120;
  return (
    <svg viewBox="0 0 320 400" fill="none" xmlns="http://www.w3.org/2000/svg">
      <rect x="28" y="28" width="264" height="344" rx="14" fill="var(--surface-rise)" stroke="var(--border)" strokeWidth="1" />
      <rect x="44" y="46" width="100" height="52" rx="9" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <text x="94" y="68" textAnchor="middle" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.06em">HORES / MES</text>
      <text x="94" y="87" textAnchor="middle" fill="var(--accent)" fontFamily="var(--font-sans)" fontSize="22" fontWeight="500" letterSpacing="-0.03em">40h+</text>
      <rect x="164" y="46" width="112" height="52" rx="9" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <text x="220" y="68" textAnchor="middle" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.06em">ERRORS</text>
      <text x="220" y="87" textAnchor="middle" fill="var(--ink)" fontFamily="var(--font-sans)" fontSize="22" fontWeight="500" letterSpacing="-0.03em">−90%</text>
      <rect x="44" y="114" width="232" height="12" rx="4" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <rect x="44" y="114" width="165" height="12" rx="4" fill="var(--accent)" opacity="0.8" />
      <text x="44" y="144" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.06em">ROI TARGET</text>
      <text x="276" y="144" textAnchor="end" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="9">71%</text>
      {bars.map((pct, i) => {
        const h = pct / 100 * maxH;
        const x = startX + i * (bw + gap);
        return (
          <g key={i}>
            <rect x={x} y={baseY - h} width={bw} height={h} rx="4"
            fill={i === 3 ? 'var(--accent)' : 'var(--surface)'}
            stroke={i === 3 ? 'var(--accent)' : 'var(--border)'}
            strokeWidth="1" opacity={i === 3 ? 1 : 0.85} />
          </g>);

      })}
      <line x1="42" y1={baseY} x2="278" y2={baseY} stroke="var(--border)" strokeWidth="1" />
      <rect x="44" y="310" width="232" height="44" rx="9" fill="rgba(200,255,61,0.04)" stroke="rgba(200,255,61,0.2)" strokeWidth="1" />
      <text x="160" y="334" textAnchor="middle" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.08em">REPORT GENERAT AUTOMÀTICAMENT</text>
      <text x="160" y="347" textAnchor="middle" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="8.5">cada dilluns · 08:00</text>
    </svg>);

}

function PortalArt() {
  return (
    <svg viewBox="0 0 320 400" fill="none" xmlns="http://www.w3.org/2000/svg">
      <rect x="28" y="32" width="264" height="336" rx="14" fill="var(--surface-rise)" stroke="var(--border)" strokeWidth="1" />
      {/* top bar */}
      <rect x="28" y="32" width="264" height="36" fill="var(--surface)" />
      <line x1="28" y1="68" x2="292" y2="68" stroke="var(--border)" strokeWidth="1" />
      <circle cx="44" cy="50" r="3.2" fill="var(--ink-mute)" />
      <circle cx="55" cy="50" r="3.2" fill="var(--ink-mute)" />
      <circle cx="66" cy="50" r="3.2" fill="var(--ink-mute)" />
      <rect x="170" y="42" width="108" height="16" rx="7" fill="var(--surface-rise)" stroke="var(--border)" strokeWidth="1" />
      <text x="224" y="53" textAnchor="middle" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="8.5" letterSpacing="0.04em">app.dalflow.io</text>
      {/* sidebar */}
      <line x1="108" y1="68" x2="108" y2="368" stroke="var(--border)" strokeWidth="1" />
      <rect x="40" y="88" width="56" height="10" rx="5" fill="var(--accent)" opacity="0.3" />
      <rect x="40" y="110" width="44" height="8" rx="4" fill="var(--ink-mute)" opacity="0.5" />
      <rect x="40" y="128" width="52" height="8" rx="4" fill="var(--ink-mute)" opacity="0.5" />
      <rect x="40" y="146" width="48" height="8" rx="4" fill="var(--ink-mute)" opacity="0.5" />
      <rect x="40" y="164" width="40" height="8" rx="4" fill="var(--ink-mute)" opacity="0.5" />
      {/* main: header */}
      <text x="124" y="100" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="8.5" letterSpacing="0.08em">/ NOVA PROFORMA</text>
      {/* form */}
      <text x="124" y="126" fill="var(--ink-dim)" fontFamily="var(--font-mono)" fontSize="8" letterSpacing="0.04em">CLIENT</text>
      <rect x="124" y="132" width="152" height="22" rx="5" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <text x="132" y="147" fill="var(--ink)" fontFamily="var(--font-mono)" fontSize="9">Restaurant Cafè Marina S.L.</text>
      <text x="124" y="172" fill="var(--ink-dim)" fontFamily="var(--font-mono)" fontSize="8" letterSpacing="0.04em">CONCEPTE</text>
      <rect x="124" y="178" width="152" height="22" rx="5" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <text x="132" y="193" fill="var(--ink)" fontFamily="var(--font-mono)" fontSize="9">Implementació Odoo + integració</text>
      <text x="124" y="218" fill="var(--ink-dim)" fontFamily="var(--font-mono)" fontSize="8" letterSpacing="0.04em">IMPORT</text>
      <rect x="124" y="224" width="72" height="22" rx="5" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <text x="160" y="239" textAnchor="middle" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="10" fontWeight="500">4.800€</text>
      {/* generate button */}
      <rect x="124" y="266" width="112" height="30" rx="7" fill="var(--accent)" />
      <text x="180" y="285" textAnchor="middle" fill="var(--accent-ink)" fontFamily="var(--font-sans)" fontSize="11" fontWeight="600" letterSpacing="0.02em">GENERAR PDF</text>
      {/* history */}
      <text x="124" y="318" fill="var(--ink-mute)" fontFamily="var(--font-mono)" fontSize="8" letterSpacing="0.06em">ÚLTIMES PROFORMES</text>
      <rect x="124" y="324" width="152" height="16" rx="4" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <text x="130" y="335" fill="var(--ink-dim)" fontFamily="var(--font-mono)" fontSize="8">PRF-0143 · Eurast</text>
      <text x="270" y="335" textAnchor="end" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="7">✓</text>
      <rect x="124" y="344" width="152" height="16" rx="4" fill="var(--surface)" stroke="var(--border)" strokeWidth="1" />
      <text x="130" y="355" fill="var(--ink-dim)" fontFamily="var(--font-mono)" fontSize="8">PRF-0142 · Airea Travel</text>
      <text x="270" y="355" textAnchor="end" fill="var(--accent)" fontFamily="var(--font-mono)" fontSize="7">✓</text>
    </svg>);

}

// ============ LIVE FLOW DEMO ============
function LiveFlowDemo({ t }) {
  const scenarios = t.home.liveDemo.scenarios;
  const [idx, setIdx] = useStateP(0);
  useEffectP(() => {
    const id = setInterval(() => setIdx((i) => (i + 1) % scenarios.length), 6500);
    return () => clearInterval(id);
  }, [scenarios.length]);
  const s = scenarios[idx];
  return (
    <>
      <div className="trust__label">{t.home.liveDemo.label}</div>
      <div className="live-flow__stage" key={idx}>
        <div className="live-node live-node--input">
          <div className="live-node__tag">{s.input.tag}</div>
          <div className="live-node__title">{s.input.title}</div>
          <div className="live-node__detail">{s.input.detail}</div>
        </div>
        <div className="live-flow__conn live-flow__conn--in" aria-hidden="true">
          <svg viewBox="0 0 100 40" preserveAspectRatio="none">
            <line x1="0" y1="20" x2="100" y2="20" className="live-flow__line live-flow__line--active" />
          </svg>
        </div>
        <div className="live-flow__vconn" aria-hidden="true">
          <svg viewBox="0 0 40 40" preserveAspectRatio="none">
            <line x1="20" y1="0" x2="20" y2="34" className="live-flow__line live-flow__line--active" />
            <polygon points="15,30 25,30 20,40" className="live-flow__arrow" />
          </svg>
        </div>
        <div className="live-flow__core">
          <svg viewBox="0 0 100 100">
            <circle cx="50" cy="50" r="44" className="live-flow__core-ring" />
            <circle cx="50" cy="50" r="36" className="live-flow__core-ring live-flow__core-ring--anim" />
            <circle cx="50" cy="50" r="22" className="live-flow__core-fill" />
            <circle cx="50" cy="50" r="6" className="live-flow__core-dot" />
          </svg>
          <div className="live-flow__core-label">AI · AGENT</div>
        </div>
        <div className="live-flow__conn live-flow__conn--out" aria-hidden="true">
          <svg viewBox="0 0 100 220" preserveAspectRatio="none">
            <path d="M0,110 C 40,110 40,30 100,30" className="live-flow__line live-flow__line--active" />
            <path d="M0,110 L 100,110" className="live-flow__line live-flow__line--active" />
            <path d="M0,110 C 40,110 40,190 100,190" className="live-flow__line live-flow__line--active" />
          </svg>
        </div>
        <div className="live-flow__vconn" aria-hidden="true">
          <svg viewBox="0 0 40 40" preserveAspectRatio="none">
            <line x1="20" y1="0" x2="20" y2="34" className="live-flow__line live-flow__line--active" />
            <polygon points="15,30 25,30 20,40" className="live-flow__arrow" />
          </svg>
        </div>
        <div className="live-flow__outputs">
          {s.outputs.map((o, i) =>
          <div key={i} className={`live-node live-node--out live-node--out-${i + 1}`}>
              <div className="live-node__tag">{o.tag}</div>
              <div className="live-node__detail">{o.detail}</div>
              <span className="live-node__check" aria-hidden="true">✓</span>
            </div>
          )}
        </div>
      </div>
    </>);
}

// ============ HOME ============
function HomePage({ t, tweaks }) {
  const isSerif = tweaks.heroVariant === 'serif';
  const SerifSpan = ({ children }) => isSerif ?
  <span className="serif">{children}</span> :
  <span style={{ color: 'var(--accent)' }}>{children}</span>;

  return (
    <>
      {/* HERO */}
      <section className="hero">
        <div className="hero__glow" />
        <div className="hero__grid" />
        <div className="container hero__inner">
          <span className="eyebrow" data-comment-anchor="cb3841d17f-span-149-11">{t.home.eyebrow}</span>
          <h1 className="h-display" style={{ marginTop: 28 }}>
            {t.home.heroA}<br />
            <SerifSpan>{t.home.heroB}</SerifSpan>
          </h1>
          <p className="hero__sub">{t.home.heroSub}</p>
          <div className="hero__ctas">
            <a href="#/contact" className="btn btn--primary">
              {t.home.ctaPrimary}
              <span className="arrow">→</span>
            </a>
            <a href="#/cases" className="btn btn--ghost">
              {t.home.ctaSecondary}
            </a>
          </div>
        </div>
      </section>

      {/* LIVE ACTIVITY FEED */}
      <div className="container">
        <div className="trust" data-comment-anchor="8ed0b617d6-div-164-9">
          <LiveFlowDemo t={t} />
        </div>
      </div>

      {/* PITCH */}
      <section className="section">
        <div className="container">
          <div className="pitch">
            <h2>
              {t.home.pitchA} <span className="ital">{t.home.pitchB}</span>
              {t.home.pitchC} <span className="accent">{t.home.pitchD}</span>
              {t.home.pitchE} <span className="accent">{t.home.pitchF}</span>{t.home.pitchG}
            </h2>
          </div>

          {/* Stats row */}
          <div className="stats-row">
            <div className="stats-row__intro">
              <div className="section-label">{t.home.statsIntroLabel}</div>
              <h3 className="h-3" style={{ fontWeight: 500 }}>
                {t.home.statsIntroA}<br />
                <span style={{ fontFamily: 'var(--font-serif)', fontStyle: 'italic', color: 'var(--accent)' }}>{t.home.statsIntroB}</span>
              </h3>
              <div style={{ position: 'absolute', right: -40, bottom: -40, opacity: 0.4, pointerEvents: 'none' }}>
                <svg width="200" height="200" viewBox="0 0 200 200">
                  <circle cx="100" cy="100" r="80" stroke="var(--accent)" strokeWidth="1" fill="none" opacity="0.4" />
                  <circle cx="100" cy="100" r="60" stroke="var(--accent)" strokeWidth="0.6" fill="none" opacity="0.3" />
                  <circle cx="100" cy="100" r="40" stroke="var(--accent)" strokeWidth="0.5" fill="none" opacity="0.25" />
                </svg>
              </div>
            </div>
            {t.home.stats.map((s, i) =>
            <div key={i} className={`stat ${i === 0 ? 'stat--feature' : ''}`}>
                <div className="stat__value">{s.value}</div>
                <div className="stat__label">{s.label}</div>
              </div>
            )}
          </div>
        </div>
      </section>

      {/* WHY DALFLOW */}
      <section className="section section--tight">
        <div className="container">
          <div className="two-col" style={{ alignItems: 'end' }}>
            <div>
              <div className="section-label">/02 — Why Dalflow</div>
              <h2 className="h-1" style={{ marginTop: 14, maxWidth: '14ch' }}>
                {t.home.whyTitle}
              </h2>
            </div>
            <div>
              <p className="lede" style={{ margin: 0 }}>{t.home.whySub}</p>
            </div>
          </div>
          <div className="why-grid">
            {t.home.why.map((w, i) => {
              const glyphs = ['founder', 'speed', 'simple', 'roi'];
              return (
                <div key={i} className="why-card">
                  <div className="why-card__glyph">
                    <ServiceIcon kind={glyphs[i]} size={32} />
                  </div>
                  <div className="why-card__t">{w.t}</div>
                  <div className="why-card__d">{w.d}</div>
                </div>);

            })}
          </div>
        </div>
      </section>

      {/* TOOLS COMPATIBILITY */}
      <section className="section section--tight">
        <div className="container">
          <div className="two-col" style={{ alignItems: 'end' }}>
            <div>
              <div className="section-label">{t.home.toolsSectionLabel}</div>
              <h2 className="h-1" style={{ marginTop: 14, maxWidth: '16ch' }}>
                {t.home.toolsTitle}
              </h2>
            </div>
            <p className="lede" style={{ margin: 0 }}>{t.home.toolsSub}</p>
          </div>
          <div className="stack-grid" style={{ marginTop: 36 }}>
            {t.about.stack.map((s, i) => {
              const inline = TOOL_ICONS_INLINE[s];
              const slug = TOOL_ICONS[s];
              return (
                <span key={i} className="stack-chip">
                  {inline ? inline : slug &&
                  <img
                    src={`https://cdn.simpleicons.org/${slug}/FFFFFF`}
                    width="15" height="15"
                    style={{ display: 'block', flexShrink: 0 }}
                    onError={(e) => {e.target.style.display = 'none';}} />

                  }
                  {s}
                </span>);

            })}
          </div>
        </div>
      </section>

      {/* SERVICES OVERVIEW */}
      <section className="section section--tight">
        <div className="container">
          <div className="two-col" style={{ alignItems: 'end', marginBottom: 8 }}>
            <div>
              <div className="section-label">/04 — Services</div>
              <h2 className="h-1" style={{ marginTop: 14 }}>
                {t.home.servicesTitle}
              </h2>
            </div>
            <div>
              <p className="lede" style={{ margin: 0 }}>{t.home.servicesIntro}</p>
              <a href="#/services" className="btn btn--primary btn--sm" style={{ marginTop: 18 }}>
                {t.home.seeAll}
                <span className="arrow">→</span>
              </a>
            </div>
          </div>
          <div className="svc-grid" data-comment-anchor="10a0cf86ff-div-305-11">
            {t.services.items.map((s, i) => {
              const kinds = ['auto', 'integ', 'dash', 'portal'];
              return (
                <div key={i} className="svc-card">
                  <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
                    <span className="svc-card__tag">{s.tag}</span>
                    <div style={{ color: 'var(--accent)' }}>
                      <ServiceIcon kind={kinds[i]} size={32} />
                    </div>
                  </div>
                  <div className="svc-card__title">{s.title}</div>
                  <div className="svc-card__desc">{s.desc}</div>
                  <ul className="svc-card__bullets">
                    {s.bullets.slice(0, 3).map((b, j) => <li key={j}>{b}</li>)}
                  </ul>
                </div>);
            })}
          </div>
        </div>
      </section>

      {/* PROCESS */}
      <section className="section">
        <div className="container">
          <div className="section-label">/05 — Process</div>
          <h2 className="h-1" style={{ marginTop: 14, maxWidth: '20ch' }}>
            {t.home.processTitle}
          </h2>
          <p className="lede" style={{ marginTop: 16 }}>{t.home.processSub}</p>
          <div className="process-grid">
            {t.home.process.map((p, i) =>
            <div key={i} className={`step ${i === 0 ? 'step--accent' : ''}`}>
                <div className="step__n">{p.n}</div>
                <div className="step__title">{p.t}</div>
                <div className="step__desc">{p.d}</div>
              </div>
            )}
          </div>
        </div>
      </section>

      {/* FAQ */}
      <section className="section section--tight">
        <div className="container">
          <div className="two-col">
            <div>
              <div className="section-label">/06 — FAQ</div>
              <h2 className="h-1" style={{ marginTop: 14, maxWidth: '14ch' }}>
                {t.home.faqTitle}
              </h2>
            </div>
            <div className="faq-list">
              {t.home.faqs.map((f, i) =>
              <details key={i} className="faq" open={i === 0}>
                  <summary>{f.q}</summary>
                  <div className="faq__body">{f.a}</div>
                </details>
              )}
            </div>
          </div>
        </div>
      </section>

      {/* FINAL CTA */}
      {tweaks.showFinalCta &&
      <section className="section section--tight">
          <div className="container">
            <div className="final-cta">
              <h2>
                {t.home.finalCtaTitle.split(' ').slice(0, -1).join(' ')}{' '}
                <span className="ital">{t.home.finalCtaTitle.split(' ').slice(-1)[0]}</span>
              </h2>
              <p>{t.home.finalCtaSub}</p>
              <div className="final-cta__row">
                <a href="#/contact" className="btn btn--dark">
                  {t.nav.cta}
                  <span className="arrow">→</span>
                </a>
                <a href="mailto:armand.dalmau@gmail.com" className="btn btn--ghost">
                  armand.dalmau@gmail.com
                </a>
              </div>
            </div>
          </div>
        </section>
      }
    </>);
}

// ============ SERVICES ============
function ServicesPage({ t, tweaks }) {
  const thematicArts = [AutoArt, IntegArt, DashArt, PortalArt];
  return (
    <>
      <section className="page-intro">
        <div className="page-intro__glow" />
        <div className="container page-intro__inner">
          <div className="section-label">/ Services</div>
          <h1 className="h-display" style={{ marginTop: 14 }}>
            {t.services.title}
          </h1>
          <p className="page-intro__lede">{t.services.lede}</p>
        </div>
      </section>

      {/* SERVICE ROWS */}
      <section className="section section--tight" style={{ paddingTop: 0 }}>
        <div className="container">
          {t.services.items.map((s, i) => {
            const Art = thematicArts[i];
            const reversed = i % 2 === 1;
            return (
              <div key={i} className={`service-row${reversed ? ' service-row--reversed' : ''}`}>
                {!reversed &&
                <div className="service-row__art">
                    <div className="art-wrap"><Art /></div>
                  </div>
                }
                <div>
                  <div className="section-label" style={{ color: 'var(--accent)' }}>{s.tag}</div>
                  <h3 style={{ marginTop: 14 }}>{s.title}</h3>
                  <p className="service-row__desc">{s.desc}</p>
                  <div className="service-row__example">{s.example}</div>
                  <ul className="service-row__bullets">
                    {s.bullets.map((b, j) => <li key={j}>{b}</li>)}
                  </ul>
                </div>
                {reversed &&
                <div className="service-row__art">
                    <div className="art-wrap"><Art /></div>
                  </div>
                }
              </div>);
          })}
        </div>
      </section>

      {/* DEPARTMENTS */}
      <section className="section section--tight">
        <div className="container">
          <div className="section-label">/ Per departament</div>
          <div className="two-col" style={{ alignItems: 'end', marginBottom: 36 }}>
            <h2 className="h-1" style={{ marginTop: 14 }}>{t.services.deptTitle}</h2>
            <p className="lede" style={{ margin: 0 }}>{t.services.deptSub}</p>
          </div>
          <div className="dept-grid">
            {t.services.depts.map((d, i) =>
            <div key={i} className="dept-card">
                <div className="dept-card__name">{d.dept}</div>
                <ul className="dept-card__list">
                  {d.examples.map((ex, j) =>
                <li key={j}>{ex}</li>
                )}
                </ul>
              </div>
            )}
          </div>
        </div>
      </section>

      {/* HOW WE WORK TOGETHER */}
      <section className="section section--tight">
        <div className="container">
          <div className="section-label">/ Com col·laborem</div>
          <div className="two-col" style={{ alignItems: 'end', marginBottom: 36 }}>
            <h2 className="h-1" style={{ marginTop: 14 }}>{t.services.colabTitle}</h2>
            <p className="lede" style={{ margin: 0 }}>{t.services.colabSub}</p>
          </div>
          <div className="packs-grid">
            {t.services.colab.map((c, i) =>
            <div key={i} className={`pack ${c.featured ? 'pack--featured' : ''}`}>
                <div className="pack__name">{c.name}</div>
                <div className="pack__price">{c.tag}</div>
                <div className="pack__desc">{c.desc}</div>
                <ul className="pack__features">
                  {c.features.map((f, j) => <li key={j}>{f}</li>)}
                </ul>
                <a href="#/contact" className={`btn ${c.featured ? 'btn--primary' : 'btn--ghost'}`}>
                  {c.cta}
                  <span className="arrow">→</span>
                </a>
              </div>
            )}
          </div>
        </div>
      </section>

      {tweaks.showFinalCta &&
      <section className="section section--tight">
          <div className="container">
            <div className="final-cta">
              <h2>
                {t.home.finalCtaTitle.split(' ').slice(0, -1).join(' ')}{' '}
                <span className="ital">{t.home.finalCtaTitle.split(' ').slice(-1)[0]}</span>
              </h2>
              <p>{t.home.finalCtaSub}</p>
              <div className="final-cta__row">
                <a href="#/contact" className="btn btn--dark">{t.nav.cta} <span className="arrow">→</span></a>
              </div>
            </div>
          </div>
        </section>
      }
    </>);
}

// ============ CASES ============
function CasesPage({ t, tweaks }) {
  const arts = [LatticeArt, FlowArt, TapeArt, MeshArt];
  const BRANDS = {
    eurast: { img: 'assets/eurast-logo.png', bg: '#141210' },
    airea: { img: 'assets/airea-logo.png', bg: '#39443a' },
    hrlovers: { img: 'assets/hrlovers-logo.png', bg: '#f2b707' }
  };
  const renderArt = (c, i, Art) => {
    const b = c.logo ? BRANDS[c.logo] : null;
    if (b) {
      return (
        <div className="case-row__art" style={{ background: b.bg, border: 'none' }}>
          <div className="case-logo-panel">
            <img src={b.img} alt={c.client} className="case-logo-img" />
          </div>
        </div>);

    }
    return (
      <div className="case-row__art">
        <div className="art-wrap"><Art seed={i + 2} /></div>
      </div>);

  };
  const renderLhs = (c, i, Art) => {
    const quote = c.quote ?
    <div className="case-quote">
        <div className="case-quote__avatar">
          <image-slot
          id={`case-quote-photo-${c.logo || i}`}
          shape="circle"
          placeholder="Foto">
          </image-slot>
        </div>
        <div className="case-quote__body">
          <div className="case-quote__text">{c.quote}</div>
          <div className="case-quote__attr">
            <span className="case-quote__attr-name">{c.quoteName}</span> · {c.quoteRole}
          </div>
        </div>
      </div> : null;
    return (
      <div className="case-row__lhs">
        {renderArt(c, i, Art)}
        {quote}
      </div>);
  };
  return (
    <>
      <section className="page-intro">
        <div className="page-intro__glow" />
        <div className="container page-intro__inner">
          <div className="section-label">/ Cases</div>
          <h1 className="h-display" style={{ marginTop: 14 }}>
            {t.cases.title}
          </h1>
          <p className="page-intro__lede">{t.cases.lede}</p>
        </div>
      </section>

      <section className="section section--tight" style={{ paddingTop: 0 }}>
        <div className="container">
          {t.cases.items.map((c, i) => {
            const Art = arts[i];
            const reversed = i % 2 === 1;
            return (
              <div key={i} className={`case-row${reversed ? ' case-row--reversed' : ''}`}>
                {!reversed && renderLhs(c, i, Art)}
                <div>
                  {c.sector && <div className="case-row__sector">{c.sector}</div>}
                  <div className="case-row__head">
                    <div className="case-row__client">{c.client}</div>
                    <div className="case-row__role">{c.role}</div>
                  </div>
                  <p className="case-row__tagline">{c.tagline}</p>
                  <p className="case-row__summary">{c.summary}</p>
                  <div className="case-row__metrics">
                    {c.metrics.map((m, j) =>
                    <div key={j} className="metric">
                        <div className="metric__v">{m.v}</div>
                        <div className="metric__k">{m.k}</div>
                      </div>
                    )}
                  </div>
                </div>
                {reversed && renderLhs(c, i, Art)}
              </div>);

          })}
        </div>
      </section>

      {tweaks.showFinalCta &&
      <section className="section section--tight">
          <div className="container">
            <div className="final-cta">
              <h2>
                {t.home.finalCtaTitle.split(' ').slice(0, -1).join(' ')}{' '}
                <span className="ital">{t.home.finalCtaTitle.split(' ').slice(-1)[0]}</span>
              </h2>
              <p>{t.home.finalCtaSub}</p>
              <div className="final-cta__row">
                <a href="#/contact" className="btn btn--dark">{t.nav.cta} <span className="arrow">→</span></a>
              </div>
            </div>
          </div>
        </section>
      }
    </>);
}

// ============ ABOUT ============
function AboutPage({ t, tweaks }) {
  return (
    <>
      <section className="page-intro">
        <div className="page-intro__glow" />
        <div className="container page-intro__inner">
          <div className="section-label">/ About</div>
          <h1 className="h-display" style={{ marginTop: 14 }}>
            {t.about.title}
          </h1>
          <p className="page-intro__lede">{t.about.lede}</p>
        </div>
      </section>

      <section className="section section--tight" style={{ paddingTop: 0 }}>
        <div className="container">
          <div className="two-col" style={{ alignItems: 'start' }}>
            {/* Portrait */}
            <div className="about-portrait">
              <img
                src={window.__resources && window.__resources.armandPhoto || 'assets/armand.png'}
                alt="Armand Dalmau"
                className="about-portrait__img"
                loading="eager" />
              
              <div className="about-portrait__label">
                <span>armand.dalmau</span>
                <span>barcelona / 2026</span>
              </div>
            </div>

            {/* Body */}
            <div>
              <p style={{ fontSize: 20, lineHeight: 1.5, color: 'var(--ink)', margin: 0, textWrap: 'pretty' }}>{t.about.bodyA}</p>
              <p style={{ fontSize: 18, lineHeight: 1.5, color: 'var(--ink-dim)', marginTop: 18 }}>{t.about.bodyB}</p>
              <p style={{ fontSize: 18, lineHeight: 1.5, color: 'var(--ink-dim)', marginTop: 18 }}>{t.about.bodyC}</p>

              <div style={{ marginTop: 28, display: 'flex', gap: 10, flexWrap: 'wrap' }}>
                <a href="https://www.linkedin.com/in/armanddalmau/" target="_blank" rel="noreferrer" className="btn btn--ghost btn--sm">
                  LinkedIn
                  <span className="arrow">↗</span>
                </a>
                <a href="mailto:armand.dalmau@gmail.com" className="btn btn--ghost btn--sm">
                  Email
                  <span className="arrow">↗</span>
                </a>
                <a href="#/contact" className="btn btn--primary btn--sm">{t.nav.cta} <span className="arrow">→</span></a>
              </div>
            </div>
          </div>
        </div>
      </section>

      <section className="section section--tight">
        <div className="container">
          <div className="section-label">/ Background</div>
          <h2 className="h-1" style={{ marginTop: 14, maxWidth: '14ch' }}>
            {t.about.careerTitle}
          </h2>
          <div className="career-list">
            {t.about.career.map((c, i) =>
            <div key={i} className="career-item">
                <div className="career-years">{c.years}</div>
                <div>
                  <div>
                    <span className="career-role">{c.role}</span>
                    <span className="career-org">{c.org}</span>
                  </div>
                  <div className="career-detail">{c.detail}</div>
                </div>
              </div>
            )}
          </div>
        </div>
      </section>

      <section className="section section--tight">
        <div className="container">
          <div className="section-label">/ Principles</div>
          <h2 className="h-1" style={{ marginTop: 14, maxWidth: '14ch' }}>
            {t.about.principlesTitle}
          </h2>
          <div className="principles">
            {t.about.principles.map((p, i) => {
              const [head, ...rest] = p.t.split(' ');
              return (
                <div key={i} className="principle">
                  <div className="principle__t">
                    <span className="accent" style={{ color: 'var(--accent)' }}>{head}</span> {rest.join(' ')}
                  </div>
                  <div className="principle__d">{p.d}</div>
                </div>);
            })}
          </div>
        </div>
      </section>

      <section className="section section--tight">
        <div className="container">
          <div className="section-label">/ Stack</div>
          <h2 className="h-2" style={{ marginTop: 14 }}>{t.about.stackTitle}</h2>
          <p className="lede" style={{ marginTop: 12 }}>{t.about.stackSub}</p>
          <div className="stack-grid">
            {t.about.stack.map((s, i) =>
            <span key={i} className="stack-chip">{s}</span>
            )}
          </div>
        </div>
      </section>

      {tweaks.showFinalCta &&
      <section className="section section--tight">
          <div className="container">
            <div className="final-cta">
              <h2>
                {t.home.finalCtaTitle.split(' ').slice(0, -1).join(' ')}{' '}
                <span className="ital">{t.home.finalCtaTitle.split(' ').slice(-1)[0]}</span>
              </h2>
              <p>{t.home.finalCtaSub}</p>
              <div className="final-cta__row">
                <a href="#/contact" className="btn btn--dark">{t.nav.cta} <span className="arrow">→</span></a>
              </div>
            </div>
          </div>
        </section>
      }
    </>);
}

// ============ CONTACT ============
function ContactPage({ t }) {
  const [sent, setSent] = useStateP(false);
  const [form, setForm] = useStateP({ name: '', company: '', email: '', message: '' });
  const submit = (e) => {
    e.preventDefault();
    setSent(true);
    setTimeout(() => {
      window.location.href = `mailto:armand.dalmau@gmail.com?subject=Dalflow%20-%20${encodeURIComponent(form.name)}&body=${encodeURIComponent(`Empresa: ${form.company}\nEmail: ${form.email}\n\n${form.message}`)}`;
    }, 800);
  };

  return (
    <>
      <section className="page-intro">
        <div className="page-intro__glow" />
        <div className="container page-intro__inner">
          <div className="section-label">/ Contact</div>
          <h1 className="h-display" style={{ marginTop: 14 }}>
            {t.contact.title.split('.')[0]}
            <span style={{ color: 'var(--accent)' }}>.</span>
          </h1>
          <p className="page-intro__lede">{t.contact.lede}</p>
        </div>
      </section>

      <section className="section section--tight" style={{ paddingTop: 0 }}>
        <div className="container">
          <div className="contact-grid">
            {/* Book a call card */}
            <div className="contact-book">
              <div>
                <div className="section-label">/ Direct line</div>
                <h3 style={{ marginTop: 14 }}>
                  {t.contact.bookTitle.split(' ').slice(0, -1).join(' ')}{' '}
                  <span className="ital">{t.contact.bookTitle.split(' ').slice(-1)[0]}</span>
                </h3>
                <p style={{ marginTop: 18 }}>{t.contact.bookSub}</p>
              </div>
              <div style={{ display: 'flex', gap: 10, flexWrap: 'wrap' }}>
                <a href="https://www.linkedin.com/in/armanddalmau/" target="_blank" rel="noreferrer" className="btn btn--dark">
                  {t.contact.bookCta}
                  <span className="arrow">→</span>
                </a>
                <a href="mailto:armand.dalmau@gmail.com" className="btn btn--ghost">
                  {t.contact.orEmail}
                </a>
              </div>
              {/* Decorative shape */}
              <div style={{ position: 'absolute', right: -60, bottom: -60, pointerEvents: 'none', opacity: 0.28 }}>
                <svg width="260" height="260" viewBox="0 0 260 260">
                  <circle cx="130" cy="130" r="120" stroke="var(--accent)" strokeWidth="1.5" fill="none" />
                  <circle cx="130" cy="130" r="90" stroke="var(--accent)" strokeWidth="1" fill="none" />
                  <circle cx="130" cy="130" r="60" stroke="var(--accent)" strokeWidth="0.8" fill="none" />
                  <circle cx="130" cy="130" r="6" fill="var(--accent)" />
                </svg>
              </div>
            </div>

            {/* Form */}
            <form className="contact-form" onSubmit={submit}>
              <h3>{t.contact.orEmail}</h3>
              <div className="field-row">
                <input className="input" placeholder={t.contact.formName} value={form.name} onChange={(e) => setForm((f) => ({ ...f, name: e.target.value }))} required />
                <input className="input" placeholder={t.contact.formCompany} value={form.company} onChange={(e) => setForm((f) => ({ ...f, company: e.target.value }))} />
              </div>
              <input className="input" type="email" placeholder={t.contact.formEmail} value={form.email} onChange={(e) => setForm((f) => ({ ...f, email: e.target.value }))} required />
              <textarea className="textarea" placeholder={t.contact.formMessage} value={form.message} onChange={(e) => setForm((f) => ({ ...f, message: e.target.value }))} required />
              <button className={`btn ${sent ? 'btn--ghost' : 'btn--primary'}`} type="submit" style={{ alignSelf: 'flex-start', marginTop: 6 }}>
                {sent ? t.contact.formSent : t.contact.formSend}
                <span className="arrow">{sent ? '✓' : '→'}</span>
              </button>
            </form>
          </div>

          {/* Meta cells */}
          <div className="contact-meta">
            <div className="contact-meta__cell">
              <div className="contact-meta__label">{t.contact.whereTitle}</div>
              <div className="contact-meta__value">{t.contact.whereCity}</div>
              <div className="tiny" style={{ marginTop: 6 }}>{t.contact.whereTime}</div>
            </div>
            <div className="contact-meta__cell">
              <div className="contact-meta__label">Email</div>
              <div className="contact-meta__value">
                <a href="mailto:armand.dalmau@gmail.com">armand.dalmau@gmail.com</a>
              </div>
              <div className="tiny" style={{ marginTop: 6 }}>Resposta &lt; 24h</div>
            </div>
            <div className="contact-meta__cell">
              <div className="contact-meta__label">LinkedIn</div>
              <div className="contact-meta__value">
                <a href="https://www.linkedin.com/in/armanddalmau/" target="_blank" rel="noreferrer">@armanddalmau</a>
              </div>
              <div className="tiny" style={{ marginTop: 6 }}>Armand Dalmau</div>
            </div>
          </div>
        </div>
      </section>
    </>);
}

// Register pages
window.DALFLOW_PAGES = {
  home: HomePage,
  services: ServicesPage,
  cases: CasesPage,
  about: AboutPage,
  contact: ContactPage
};