// Homepage section: AI / Claude Skills & Projects teaser

const csHomeStyles = {
  wrap: { padding: 'var(--section-y) 32px', position: 'relative', overflow: 'hidden', background: 'var(--paper-deep)', borderTop: '1px solid var(--line-soft)', borderBottom: '1px solid var(--line-soft)' },
  bg: { position: 'absolute', inset: 0, pointerEvents: 'none', background: 'radial-gradient(50% 60% at 90% 50%, rgba(29,78,137,0.05) 0%, transparent 60%)' },
  inner: { maxWidth: 1280, margin: '0 auto', position: 'relative' },

  panel: {
    background: 'transparent',
    border: 'none',
    borderRadius: 0,
    padding: 0,
    display: 'flex', flexDirection: 'column', gap: 48,
    boxShadow: 'none',
    position: 'relative',
    overflow: 'visible',
  },

  panelGrid: {
    display: 'grid', gridTemplateColumns: '1.1fr 1fr', gap: 56, alignItems: 'center',
  },

  // --- Human-in-the-loop orbital diagram (top of panel) ---
  cycleWrap: {
    position: 'relative',
  },
  cycleHead: {
    display: 'flex', alignItems: 'baseline', justifyContent: 'space-between',
    marginBottom: 24, gap: 24, flexWrap: 'wrap',
  },
  cycleEyebrow: {
    fontFamily: "'Outfit', system-ui, sans-serif",
    fontSize: 11, color: 'var(--blue-deep)',
    letterSpacing: '0.08em', textTransform: 'uppercase',
    fontWeight: 500, whiteSpace: 'nowrap',
  },
  cycleTagline: {
    fontSize: 13, color: 'var(--ink-muted)', whiteSpace: 'nowrap',
  },

  // Setup heading + card sitting above the orbit
  setupHeading: {
    fontFamily: "'Outfit', system-ui, sans-serif",
    fontSize: 28, lineHeight: 1.12, letterSpacing: '-0.02em',
    fontWeight: 600, color: 'var(--ink)',
    textAlign: 'center', marginBottom: 20,
  },
  setupHeadingBlue: { color: 'var(--blue)' },
  setupRow: {
    display: 'flex', justifyContent: 'center', position: 'relative', zIndex: 5,
  },
  setupCard: {
    background: '#fff',
    border: '1.5px solid var(--blue)',
    borderRadius: 14,
    padding: '14px 22px',
    display: 'inline-flex', alignItems: 'center', gap: 14,
    boxShadow: '0 0 0 5px rgba(8,120,216,0.08), var(--shadow-sm)',
    maxWidth: 460,
  },
  setupIcon: {
    width: 38, height: 38, borderRadius: 10,
    background: 'var(--blue)', color: '#fff',
    display: 'grid', placeItems: 'center', flex: 'none',
  },
  setupWho: {
    fontFamily: "'Outfit', system-ui, sans-serif",
    fontSize: 10, fontWeight: 500, letterSpacing: '0.08em', textTransform: 'uppercase',
    color: 'var(--blue)', marginBottom: 3,
  },
  setupTitle: { fontSize: 14.5, fontWeight: 600, letterSpacing: '-0.01em', color: 'var(--ink)' },
  setupDesc: { fontSize: 12.5, color: 'var(--ink-muted)', marginTop: 3, lineHeight: 1.5 },
  entryArrow: {
    display: 'flex', justifyContent: 'center',
    height: 36, color: 'var(--blue)',
  },

  // Orbital diagram
  orbitColumn: { display: 'flex', flexDirection: 'column', gap: 14 },
  orbitOuter: {
    width: '100%', display: 'flex', justifyContent: 'center',
  },
  orbitDiagram: {
    position: 'relative',
    width: '100%', maxWidth: 560,
    aspectRatio: '680 / 540',
    margin: '4px auto',
  },
  orbitSvg: {
    position: 'absolute', inset: 0, width: '100%', height: '100%',
    pointerEvents: 'none', overflow: 'visible',
  },
  // Step cards positioned around the orbit
  orbitCard: (pos, highlight) => {
    const base = {
      position: 'absolute',
      width: '27%', minWidth: 132, maxWidth: 180,
      background: '#fff',
      border: highlight ? '1.5px solid var(--blue)' : '1px solid var(--line-soft)',
      borderRadius: 13,
      padding: '10px 12px',
      boxShadow: highlight ? '0 8px 24px rgba(8,120,216,0.14)' : 'var(--shadow-sm)',
      transition: 'transform .18s, box-shadow .18s',
    };
    const placements = {
      top:    { left: '50%', top: '0%',  transform: 'translate(-50%, -22%)' },
      right:  { right: '0%', top: '50%', transform: 'translate(0, -50%)' },
      bottom: { left: '50%', bottom: '0%', transform: 'translate(-50%, 22%)' },
      left:   { left: '0%',  top: '50%', transform: 'translate(0, -50%)' },
    };
    return { ...base, ...placements[pos] };
  },
  orbitWho: (variant) => ({
    display: 'inline-flex', alignItems: 'center', gap: 5,
    fontFamily: "'Outfit', system-ui, sans-serif",
    fontSize: 10, fontWeight: 600, letterSpacing: '0.08em', textTransform: 'uppercase',
    borderRadius: 999, padding: '2px 8px', marginBottom: 6,
    background: variant === 'va' ? 'var(--blue)' : 'var(--blue-soft)',
    color: variant === 'va' ? '#fff' : 'var(--blue-deep)',
    whiteSpace: 'nowrap',
  }),
  orbitStepLbl: {
    fontFamily: "'Outfit', system-ui, sans-serif", fontVariantNumeric: 'tabular-nums',
    fontSize: 10, fontWeight: 500, letterSpacing: '0.08em', textTransform: 'uppercase',
    color: 'var(--ink-muted)', marginBottom: 4,
  },
  orbitCardTitle: { fontSize: 13, fontWeight: 600, letterSpacing: '-0.01em', color: 'var(--ink)', lineHeight: 1.25, marginBottom: 3 },
  orbitCardDesc: { fontSize: 12, color: 'var(--ink-muted)', lineHeight: 1.45, minHeight: '2.9em' },

  // Center hub
  orbitHub: {
    position: 'absolute',
    width: '28%', aspectRatio: '1 / 1',
    left: '50%', top: '50%', transform: 'translate(-50%, -50%)',
    borderRadius: '50%', overflow: 'hidden',
    border: '3px solid var(--blue)',
    boxShadow: '0 0 0 8px rgba(8,120,216,0.08), 0 0 0 16px rgba(8,120,216,0.035)',
    background: 'linear-gradient(180deg, #fff 0%, var(--blue-soft) 100%)',
  },
  orbitHubImg: { width: '108%', height: '108%', objectFit: 'cover', objectPosition: '50% 22%', display: 'block', marginLeft: '-4%', marginTop: '-2%' },
  orbitHubLabel: {
    position: 'absolute',
    left: '50%', top: 'calc(50% + 13%)',
    transform: 'translate(-50%, 0)',
    background: 'var(--blue)', color: '#fff',
    padding: '7px 14px', borderRadius: 11,
    textAlign: 'center', maxWidth: '70%',
    boxShadow: '0 8px 20px -8px rgba(8,120,216,0.5)',
    whiteSpace: 'nowrap',
  },
  orbitHubLabelTitle: {
    fontFamily: "'Outfit', system-ui, sans-serif", fontVariantNumeric: 'tabular-nums',
    fontSize: 10, fontWeight: 700, letterSpacing: '0.06em', textTransform: 'uppercase',
    display: 'inline-flex', alignItems: 'center', gap: 5,
    whiteSpace: 'nowrap',
  },
  orbitHubLabelSub: { fontSize: 10.5, color: 'rgba(255,255,255,0.85)', marginTop: 2, lineHeight: 1.3, whiteSpace: 'nowrap' },

  // Final tagline below the orbit
  orbitTagline: {
    display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
    marginTop: 18,
    background: 'var(--paper-deep)',
    border: '1px solid var(--line-soft)',
    borderRadius: 12,
    padding: '12px 20px',
  },
  orbitTagTxt: {
    fontFamily: "'Outfit', system-ui, sans-serif",
    fontSize: 14, fontWeight: 600, letterSpacing: '-0.01em', color: 'var(--ink)',
  },
  orbitTagTxtBlue: { color: 'var(--blue)' },

  // left
  eyebrow: { display: 'inline-flex', alignItems: 'center', gap: 8, fontSize: 12, color: 'var(--blue)', fontWeight: 500, padding: '5px 12px', borderRadius: 999, background: 'var(--blue-soft)', border: '1px solid rgba(29,78,137,0.12)', marginBottom: 22, fontFamily: "'Outfit', system-ui, sans-serif", fontVariantNumeric: 'tabular-nums', letterSpacing: '0.06em', textTransform: 'uppercase' },
  eyebrowDot: { width: 6, height: 6, borderRadius: 3, background: 'var(--blue)' },
  h2: { fontFamily: "'Outfit', system-ui, sans-serif", fontSize: 52, lineHeight: 1.05, letterSpacing: '-0.03em', fontWeight: 600, marginBottom: 18 },
  italic: { color: 'var(--blue)' },
  p: { fontSize: 17, lineHeight: 1.55, color: 'var(--ink-muted)', maxWidth: 520, marginBottom: 28 },
  bullets: { display: 'flex', flexDirection: 'column', gap: 10, marginBottom: 32 },
  bullet: { display: 'flex', gap: 12, alignItems: 'flex-start', fontSize: 15, color: 'var(--ink-soft)' },
  bulletDot: { flex: 'none', width: 22, height: 22, borderRadius: 6, background: 'var(--blue-soft)', color: 'var(--blue-deep)', display: 'grid', placeItems: 'center' },
  ctas: { display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' },
  primary: { background: 'var(--ink)', color: '#fff', padding: '14px 22px', borderRadius: 12, fontSize: 15, fontWeight: 500, display: 'inline-flex', alignItems: 'center', gap: 8, transition: 'background .2s' },
  ghost: { background: 'transparent', color: 'var(--ink)', padding: '14px 22px', borderRadius: 12, fontSize: 15, fontWeight: 500, border: '1px solid var(--line)', display: 'inline-flex', alignItems: 'center', gap: 8, transition: 'background .2s, border-color .2s' },

  // right: stack of 4 cards
  stack: { position: 'relative', display: 'flex', flexDirection: 'column', gap: 12 },
  cardOuter: { background: '#fff', border: '1px solid var(--line-soft)', borderRadius: 14, padding: '16px 18px', display: 'flex', alignItems: 'center', gap: 14, boxShadow: 'var(--shadow-sm)', transition: 'transform .2s, box-shadow .2s' },
  cardIcon: { width: 36, height: 36, borderRadius: 9, display: 'grid', placeItems: 'center', flex: 'none' },
  cardLabel: { fontFamily: "'Outfit', system-ui, sans-serif", fontVariantNumeric: 'tabular-nums', fontSize: 10, color: 'var(--blue)', letterSpacing: '0.08em', textTransform: 'uppercase', marginBottom: 3 },
  cardTitle: { fontSize: 15, fontWeight: 600, letterSpacing: '-0.01em', marginBottom: 2 },
  cardDesc: { fontSize: 13, color: 'var(--ink-muted)', lineHeight: 1.45 },
  cardArrow: { color: 'var(--ink-muted)', flex: 'none' },
};

function HumanLoopCycle({ outputDesc }) {
  // 4 orbiting steps. Three are owned by the human VA — that's the point.
  const steps = [
    { pos: 'top',    n: '01', who: 'AI',      whoVariant: 'ai', label: 'AI runs',  title: 'Output generated',         desc: outputDesc || 'Drafts, research, and summaries generated at scale.' },
    { pos: 'right',  n: '02', who: 'Your VA', whoVariant: 'va', label: 'Review',   title: 'VA checks every output',  desc: 'Edits, proofreads, and flags issues before they ship.' },
    { pos: 'bottom', n: '03', who: 'Your VA', whoVariant: 'va', label: 'Deliver',  title: 'VA ships the work',       desc: 'Approved output sent on your behalf, on time.' },
    { pos: 'left',   n: '04', who: 'Your VA', whoVariant: 'va', label: 'Improve',  title: 'VA tunes the system',     desc: 'Refines prompts, adds context, and learns as it goes.' },
  ];

  return (
    <div style={csHomeStyles.cycleWrap}>
      <div style={csHomeStyles.setupRow}>
        <div style={csHomeStyles.setupCard} className="bm-hil-setup-card">
          <div style={csHomeStyles.setupIcon}>
            <Icon name="settings" size={20} color="#fff" stroke={2} />
          </div>
          <div>
            <div style={csHomeStyles.setupWho}>VA &amp; You · One time</div>
            <div style={csHomeStyles.setupTitle}>Build the system</div>
            <div style={csHomeStyles.setupDesc}>Prompt, project, workflow, and rules created once, then handed off to the loop.</div>
          </div>
        </div>
      </div>
      <div style={csHomeStyles.entryArrow} aria-hidden="true">
        <svg width="14" height="36" viewBox="0 0 14 36" fill="none">
          <path d="M7 1 L7 28" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeDasharray="3 4"/>
          <path d="M2 26 L7 33 L12 26" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" fill="none"/>
        </svg>
      </div>

      {/* Orbital diagram */}
      <div style={csHomeStyles.orbitOuter}>
        <div style={csHomeStyles.orbitDiagram} className="bm-hil-orbit">
          <svg style={csHomeStyles.orbitSvg} viewBox="0 0 680 540" preserveAspectRatio="xMidYMid meet">
            <defs>
              <marker id="bmOrbitArrowBlue" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="5" markerHeight="5" orient="auto-start-reverse">
                <path d="M2 2 L8 5 L2 8" fill="none" stroke="var(--blue)" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
              </marker>
              <marker id="bmOrbitArrowSoft" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="5" markerHeight="5" orient="auto-start-reverse">
                <path d="M2 2 L8 5 L2 8" fill="none" stroke="#B8D4EE" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
              </marker>
            </defs>

            {/* Faint orbit ring */}
            <circle cx="340" cy="270" r="190" stroke="var(--line)" strokeWidth="1" strokeDasharray="5 7" fill="none"/>

            {/* Step markers (numbered chips) */}
            <g>
              <circle cx="340" cy="80" r="14" fill="#B8D4EE"/>
              <text x="340" y="84.5" fill="var(--blue-deep)" fontFamily="Outfit, system-ui, sans-serif" fontWeight="600" fontSize="11" letterSpacing="0.02em" textAnchor="middle">01</text>
              <circle cx="530" cy="270" r="14" fill="var(--blue)"/>
              <text x="530" y="274.5" fill="#fff" fontFamily="Outfit, system-ui, sans-serif" fontWeight="600" fontSize="11" letterSpacing="0.02em" textAnchor="middle">02</text>
              <circle cx="340" cy="460" r="14" fill="var(--blue)"/>
              <text x="340" y="464.5" fill="#fff" fontFamily="Outfit, system-ui, sans-serif" fontWeight="600" fontSize="11" letterSpacing="0.02em" textAnchor="middle">03</text>
              <circle cx="150" cy="270" r="14" fill="var(--blue)"/>
              <text x="150" y="274.5" fill="#fff" fontFamily="Outfit, system-ui, sans-serif" fontWeight="600" fontSize="11" letterSpacing="0.02em" textAnchor="middle">04</text>
            </g>

            {/* Animated path arcs */}
            <path id="bmOrbitP12" fill="none" stroke="#B8D4EE" strokeWidth="1.8" strokeDasharray="4 6" d="M 357 72 A 190 190 0 0 1 524 254" markerEnd="url(#bmOrbitArrowSoft)"/>
            <path id="bmOrbitP23" fill="none" stroke="var(--blue)" strokeWidth="1.8" strokeDasharray="5 5" d="M 532 287 A 190 190 0 0 1 357 453" markerEnd="url(#bmOrbitArrowBlue)"/>
            <path id="bmOrbitP34" fill="none" stroke="var(--blue)" strokeWidth="1.8" strokeDasharray="5 5" d="M 323 455 A 190 190 0 0 1 156 287" markerEnd="url(#bmOrbitArrowBlue)"/>
            <path id="bmOrbitP41" fill="none" stroke="var(--blue)" strokeWidth="2.2" strokeDasharray="5 5" d="M 148 254 A 190 190 0 0 1 323 73" markerEnd="url(#bmOrbitArrowBlue)"/>

            {/* Travelling dots */}
            <circle r="3.5" fill="#9BCFF5" opacity="0.75"><animateMotion dur="2.4s" repeatCount="indefinite" rotate="auto"><mpath href="#bmOrbitP12"/></animateMotion></circle>
            <circle r="4"   fill="var(--blue)" opacity="0.9"><animateMotion dur="2.2s" begin="0.55s" repeatCount="indefinite" rotate="auto"><mpath href="#bmOrbitP23"/></animateMotion></circle>
            <circle r="4"   fill="var(--blue)" opacity="0.9"><animateMotion dur="2.2s" begin="1.1s"  repeatCount="indefinite" rotate="auto"><mpath href="#bmOrbitP34"/></animateMotion></circle>
            <circle r="4.5" fill="var(--blue)" opacity="0.95"><animateMotion dur="2.2s" begin="1.65s" repeatCount="indefinite" rotate="auto"><mpath href="#bmOrbitP41"/></animateMotion></circle>
          </svg>

          {/* 4 step cards orbiting */}
          {steps.map((s) => (
            <div key={s.n} style={csHomeStyles.orbitCard(s.pos, s.whoVariant === 'va')} className="bm-hil-orbit-card">
              <span style={csHomeStyles.orbitWho(s.whoVariant)}>
                {s.whoVariant === 'va'
                  ? <Icon name="users" size={10} color="#fff" stroke={2} />
                  : <Icon name="sparkle" size={10} color="var(--blue-deep)" stroke={2} />}
                {s.who}
              </span>
              <div style={csHomeStyles.orbitStepLbl}>{s.n} · {s.label}</div>
              <div style={csHomeStyles.orbitCardTitle}>{s.title}</div>
              <div style={csHomeStyles.orbitCardDesc}>{s.desc}</div>
            </div>
          ))}

          {/* Center hub: the human */}
          <div style={csHomeStyles.orbitHub} className="bm-hil-orbit-hub">
            <img src="brand/team-hero-va.png" alt="BlueMoso VA, your human in the loop" style={csHomeStyles.orbitHubImg} />
          </div>
        </div>
      </div>

    </div>
  );
}

function HumanInLoop({ copy }) {
  // copy is optional — when provided (e.g. from an ICP page) it overrides the
  // default homepage copy. ICP pages opt out of the bullet list entirely by
  // simply omitting `bullets`; only the homepage (no copy prop) shows defaults.
  const isIcpPage = !!copy;
  const c = copy || {};
  const eyebrow = c.eyebrow || 'Jobs powered by AI';
  const h2Lead = c.h2Lead || 'Creating new jobs';
  const h2Accent = c.h2Accent || 'with AI.';
  const bodyHtml = c.bodyHtml || `We provide a high performing <strong style="color:var(--ink);font-weight:600;">BlueMoso VA</strong> who manages and supports your AI systems day to day, helping your business run smoother while giving you your time back.`;
  const bullets = Array.isArray(c.bullets)
    ? c.bullets
    : isIcpPage
      ? []
      : [
          'A real human to communicate with',
          'A vetted VA who runs and manages your AI',
          'Builds prompts, workflows, and repeatable systems',
          'Reviews outputs for mistakes, accuracy, and quality',
        ];
  return (
    <section id="human-in-the-loop" style={csHomeStyles.wrap} className="reveal bm-section">
      <div style={csHomeStyles.bg} />
      <div style={csHomeStyles.inner}>
        <div style={csHomeStyles.panel} className="bm-hil-panel">
          <div style={csHomeStyles.panelGrid} className="bm-hil-grid">
          {/* Left */}
          <div>
            <div style={csHomeStyles.eyebrow}>
              <span style={csHomeStyles.eyebrowDot}></span>
              {eyebrow}
            </div>
            <h2 style={csHomeStyles.h2}>
              {h2Lead} <span style={csHomeStyles.italic}>{h2Accent}</span>
            </h2>
            <p style={csHomeStyles.p} dangerouslySetInnerHTML={{ __html: bodyHtml }} />
            {bullets.length > 0 && (
              <div style={csHomeStyles.bullets}>
                {bullets.map(b => (
                  <div key={b} style={csHomeStyles.bullet}>
                    <span style={csHomeStyles.bulletDot}>
                      <svg width="11" height="11" viewBox="0 0 10 10" fill="none"><path d="M2 5.2 4.2 7.4 8 3.2" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round"/></svg>
                    </span>
                    {b}
                  </div>
                ))}
              </div>
            )}
            <div style={csHomeStyles.ctas}>
              <a href="human-in-the-loop.html" style={csHomeStyles.primary}
                 onMouseEnter={e => e.currentTarget.style.background = 'var(--blue)'}
                 onMouseLeave={e => e.currentTarget.style.background = 'var(--ink)'}>
                See the role in action <Icon name="arrow" size={15} />
              </a>
              <a href="#cta" data-booking-modal-trigger data-booking-source="human_in_loop_cta" style={csHomeStyles.ghost}
                 onMouseEnter={e => { e.currentTarget.style.background = 'var(--paper-deep)'; e.currentTarget.style.borderColor = 'var(--ink-soft)'; }}
                 onMouseLeave={e => { e.currentTarget.style.background = 'transparent'; e.currentTarget.style.borderColor = 'var(--line)'; }}>
                Talk to a real human
              </a>
            </div>
          </div>

          {/* Right: human-in-the-loop orbital diagram */}
          <div style={csHomeStyles.orbitColumn}>
            <HumanLoopCycle outputDesc={c.outputDesc} />
          </div>
          </div>
        </div>
      </div>
      <style>{`
        @keyframes csCyclePulse {
          0%, 100% { box-shadow: 0 0 0 5px rgba(8,120,216,0.18); }
          50% { box-shadow: 0 0 0 10px rgba(8,120,216,0.05); }
        }
        .bm-hil-orbit-card { font-size: 100%; }
        @media (max-width: 980px) {
          .bm-hil-grid { grid-template-columns: 1fr !important; gap: 32px !important; }
          .bm-hil-panel { padding: 36px 24px !important; gap: 32px !important; }
          /* Collapse orbit to vertical list on small screens */
          .bm-hil-orbit { aspect-ratio: auto !important; max-width: 520px !important; display: flex !important; flex-direction: column !important; gap: 12px; }
          .bm-hil-orbit svg, .bm-hil-orbit-hub, .bm-hil-orbit-hub-label { display: none !important; }
          .bm-hil-orbit-card { position: static !important; width: 100% !important; max-width: none !important; transform: none !important; }
        }
      `}</style>
    </section>
  );
}

Object.assign(window, { HumanInLoop, HumanLoopCycle });
