// Top-of-page sections: Nav, Hero, Logo marquee, Capabilities overview.

const { Container, Section, Pill, SectionHeader, Btn, Logo, Stars, AvatarStack, Icon, GlowCard, Hairline } = window;

// ─── Navigation ──────────────────────────────────────────────
function Nav() {
  const links = [
  { label: 'Why Xybos', href: '#why' },
  { label: 'Services', href: '#services' },
  { label: 'Process', href: '#process' },
  { label: 'Contact', href: '#contact' }];

  window.useLang();
  const [open, setOpen] = React.useState(false);

  React.useEffect(() => {
    if (!open) return;
    const onEsc = (e) => { if (e.key === 'Escape') setOpen(false); };
    document.addEventListener('keydown', onEsc);
    const prevOverflow = document.body.style.overflow;
    document.body.style.overflow = 'hidden';
    return () => { document.removeEventListener('keydown', onEsc); document.body.style.overflow = prevOverflow; };
  }, [open]);

  return (
    <React.Fragment>
      <header className="xy-header" style={{
        position: 'sticky', top: 0, zIndex: 50,
        backdropFilter: 'blur(20px)',
        background: 'rgba(6,7,10,.7)',
        borderBottom: '1px solid var(--line-soft)'
      }}>
        <Container style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '18px 32px', maxWidth: 1320, gap: 16 }}>
          {/* Hamburger — mobile only */}
          <button type="button" className="xy-burger" aria-label="Open menu" aria-expanded={open} onClick={() => setOpen(true)} style={{
            display: 'none', alignItems: 'center', justifyContent: 'center',
            width: 40, height: 40, padding: 0, borderRadius: 10,
            background: 'rgba(255,255,255,.04)', border: '1px solid var(--line)',
            color: '#fff', cursor: 'pointer', transition: 'background .2s, border-color .2s'
          }}>
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16" /></svg>
          </button>

          <Logo height={36} />

          <nav className="xy-desktop-nav" style={{ display: 'flex', gap: 32 }}>
            {links.map((l) =>
            <a key={l.label} href={l.href} className="nav-link"
            style={{ fontSize: 14, color: 'rgba(255,255,255,.7)', transition: 'color .15s', fontWeight: 400 }}>
                {window.t(l.label)}
              </a>
            )}
          </nav>
          <div className="xy-desktop-actions" style={{ display: 'flex', gap: 10, alignItems: 'center' }}>
            <window.LangToggle compact />
            <Btn variant="primary" size="sm" icon className="btn-primary"
              as="a" href="https://calendly.com/xybos/meet-greet" target="_blank" rel="noopener">{window.t('Book a call')}</Btn>
          </div>
        </Container>
      </header>

      {/* Mobile menu overlay — rendered as sibling of header so position:fixed
          escapes the header's backdrop-filter containing block. */}
      <div className={`xy-menu ${open ? 'xy-menu-open' : ''}`} role="dialog" aria-modal="true" aria-hidden={!open} onClick={(e) => { if (e.target === e.currentTarget) setOpen(false); }}>
        <div className="xy-menu-panel">
          <div className="xy-menu-head">
            <span style={{ fontFamily: 'var(--mono)', fontSize: 11, color: 'rgba(255,255,255,.55)', letterSpacing: 0.8, textTransform: 'uppercase' }}>// menu</span>
            <button type="button" className="xy-menu-close" aria-label="Close menu" onClick={() => setOpen(false)}>
              <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" /></svg>
            </button>
          </div>
          <nav className="xy-menu-nav">
            {links.map((l, i) =>
              <a key={l.label} href={l.href} onClick={() => setOpen(false)} style={{ ['--i']: i }}>
                <span className="xy-menu-num">0{i + 1}</span>
                <span className="xy-menu-lbl">{window.t(l.label)}</span>
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" className="xy-menu-arr"><path d="M5 12h14M13 6l6 6-6 6" /></svg>
              </a>
            )}
          </nav>
          <div className="xy-menu-foot">
            <window.LangToggle compact />
            <Btn variant="primary" size="md" icon className="btn-primary"
              as="a" href="https://calendly.com/xybos/meet-greet" target="_blank" rel="noopener"
              onClick={() => setOpen(false)}>{window.t('Book a call')}</Btn>
          </div>
        </div>
      </div>
    </React.Fragment>);

}

// ─── Hero — cosmic, centered, with rotating gas sphere + starfield ──
function Hero() {
  window.useLang();
  return (
    <section style={{
      position: 'relative', overflow: 'hidden',
      minHeight: 'min(880px, 100vh)',
      display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
      padding: '100px 0 64px',
      background: '#000'
    }}>
      <HeroStars />
      <HeroSphere />

      <Container style={{ position: 'relative', zIndex: 3, textAlign: 'center', maxWidth: 1100, paddingTop: 120 }}>
        <h1 className="rise rise-2" style={{
          fontSize: 'clamp(32px, 4.0vw, 56px)', fontWeight: 600,
          letterSpacing: -1.4, lineHeight: 1.1, margin: 0, color: '#fff',
          maxWidth: 960, marginInline: 'auto',
          textShadow: '0 6px 80px rgba(30,107,255,.35)'
        }}>
          {window.t('Enterprise automation.')}<br />
          {window.t('Built for demanding businesses.')}
        </h1>

        <p className="rise rise-3" style={{
          fontSize: 17, color: 'rgba(255,255,255,.7)', lineHeight: 1.6,
          margin: '26px auto 0', maxWidth: 680
        }}>
          {window.t('Machine-learning systems that run retail, manufacturing and logistics operations — enterprise engineering, your scale.')}
        </p>

        {/* Built-by proof strip */}
        <div className="rise rise-4 proof-wrap" style={{ marginTop: 40 }}>
          <span className="proof-strip" style={{
            display: 'inline-flex', alignItems: 'center', gap: 10,
            padding: '8px 14px', borderRadius: 999,
            background: 'rgba(10,11,14,.55)', border: '1px solid var(--line)',
            backdropFilter: 'blur(8px)'
          }}>
            <span className="proof-dot" style={{ width: 6, height: 6, borderRadius: 999, background: '#52E1A7', boxShadow: '0 0 10px #52E1A7', flexShrink: 0 }} />
            <span className="proof-text" style={{ fontFamily: 'var(--mono)', fontSize: 11.5, color: 'rgba(255,255,255,.78)', letterSpacing: 0.4 }}>
              <span className="proof-line proof-line-1">{window.t('Built by')} <span style={{ color: '#fff', fontWeight: 600 }}>{window.t('a team with years of experience')}</span></span>
              <span className="proof-sep"> </span>
              <span className="proof-line proof-line-2">{window.t('delivering')} <span style={{ color: '#9FBFFF' }}>{window.t('business-critical')}</span> {window.t('ML automation at scale')}</span>
            </span>
          </span>
        </div>
      </Container>
    </section>);

}

// Real-cosmos starfield — masked out where the sphere sits so the sphere
// reads as a clean object in space, not transparent through the ring.
// Slow, all-stars-twinkle blinking on long varied clocks for a calm dark-sky feel.
function HeroStars() {
  const data = React.useMemo(() => {
    const rng = (i, salt) => {
      let h = i * 2654435761 + salt * 374761393 >>> 0;
      h = Math.imul(h ^ h >>> 15, 0x85ebca6b);
      h = Math.imul(h ^ h >>> 13, 0xc2b2ae35);
      return ((h ^ h >>> 16) >>> 0) / 4294967296;
    };

    const stars = [];
    const haloPositions = [];
    const minDist = 320;

    for (let i = 0; i < 1100; i++) {
      const tier = rng(i, 99);
      let size, baseOp, bright;
      if (tier > 0.97) {
        size = 1.2 + rng(i, 17) * 1.0;
        baseOp = 0.85 + rng(i, 19) * 0.15;
        bright = true;
      } else if (tier > 0.78) {
        size = 0.55 + rng(i, 17) * 0.45;
        baseOp = 0.45 + rng(i, 19) * 0.35;
        bright = false;
      } else {
        size = 0.22 + rng(i, 17) * 0.32;
        baseOp = 0.14 + rng(i, 19) * 0.3;
        bright = false;
      }

      const x = rng(i, 7) * 1920;
      const y = rng(i, 13) * 1080;

      if (bright) {
        const tooClose = haloPositions.some(([px, py]) => (px - x) ** 2 + (py - y) ** 2 < minDist * minDist);
        if (tooClose) {bright = false;size = 0.7;} else
        haloPositions.push([x, y]);
      }

      const tintRoll = rng(i, 71);
      const fill = tintRoll > 0.92 ? '#FFE4C4' :
      tintRoll > 0.82 ? '#C4D8FF' :
      '#FFFFFF';

      stars.push({
        x, y, size, baseOp, bright, fill,
        // All stars blink now — slow, varied so they're not in sync
        twDur: 4 + rng(i, 29) * 10, // 4–14s
        twDelay: -rng(i, 31) * 12,
        twAmpLow: 0.12 + rng(i, 53) * 0.38 // dims to 12–50% of base
      });
    }

    const nebulae = [
    { x: 320, y: 280, r: 380, c: '#4D8BFF', op: 0.06 },
    { x: 1620, y: 760, r: 420, c: '#1E6BFF', op: 0.05 },
    { x: 1340, y: 220, r: 260, c: '#9FBFFF', op: 0.04 }];


    return { stars, nebulae };
  }, []);

  return (
    <svg style={{
      position: 'absolute', inset: 0, width: '100%', height: '100%',
      zIndex: 1, pointerEvents: 'none',
      // Hide stars where the sphere sits — radius matches the sphere's outer extent
      WebkitMaskImage: 'radial-gradient(circle at 50% 50%, transparent 0, transparent calc(min(820px, 90vw) * 0.30), rgba(0,0,0,.4) calc(min(820px, 90vw) * 0.34), #000 calc(min(820px, 90vw) * 0.40))',
      maskImage: 'radial-gradient(circle at 50% 50%, transparent 0, transparent calc(min(820px, 90vw) * 0.30), rgba(0,0,0,.4) calc(min(820px, 90vw) * 0.34), #000 calc(min(820px, 90vw) * 0.40))'
    }} preserveAspectRatio="xMidYMid slice" viewBox="0 0 1920 1080">
      <defs>
        <radialGradient id="starHalo" cx="50%" cy="50%" r="50%">
          <stop offset="0%" stopColor="#fff" stopOpacity="0.7" />
          <stop offset="40%" stopColor="#9FBFFF" stopOpacity="0.25" />
          <stop offset="100%" stopColor="#1E6BFF" stopOpacity="0" />
        </radialGradient>
        <filter id="nebBlur" x="-50%" y="-50%" width="200%" height="200%">
          <feGaussianBlur stdDeviation="50" />
        </filter>
      </defs>

      <g filter="url(#nebBlur)">
        {data.nebulae.map((n, i) =>
        <circle key={i} cx={n.x} cy={n.y} r={n.r} fill={n.c} opacity={n.op} />
        )}
      </g>

      {data.stars.map((s, i) => {
        const dim = (s.baseOp * s.twAmpLow).toFixed(3);
        const max = s.baseOp.toFixed(3);
        return (
          <g key={i}>
            {s.bright &&
            <circle cx={s.x} cy={s.y} r={s.size * 4}
            fill="url(#starHalo)" opacity={s.baseOp * 0.4} />
            }
            <circle cx={s.x} cy={s.y} r={s.size * 1.4} fill={s.fill} opacity={s.baseOp}>
              <animate attributeName="opacity"
              values={`${dim};${max};${dim}`}
              dur={`${s.twDur}s`}
              begin={`${s.twDelay}s`}
              keyTimes="0;0.5;1"
              calcMode="spline"
              keySplines="0.4 0 0.6 1;0.4 0 0.6 1"
              repeatCount="indefinite" />
            </circle>
          </g>);

      })}

      {/* Two shooting stars on separate clocks */}
      <g>
        <line x1="0" y1="0" x2="120" y2="40" stroke="#fff" strokeWidth="1.2" strokeLinecap="round" opacity="0">
          <animate attributeName="opacity" values="0;0;0.8;0;0" keyTimes="0;0.4;0.5;0.65;1" dur="14s" repeatCount="indefinite" />
          <animateTransform attributeName="transform" type="translate"
          values="0 0; 0 0; 1700 540; 1700 540" keyTimes="0;0.4;0.65;1" dur="14s" repeatCount="indefinite" />
        </line>
        <line x1="0" y1="0" x2="-90" y2="50" stroke="#9FBFFF" strokeWidth="1" strokeLinecap="round" opacity="0">
          <animate attributeName="opacity" values="0;0;0.7;0;0" keyTimes="0;0.55;0.65;0.8;1" dur="22s" begin="6s" repeatCount="indefinite" />
          <animateTransform attributeName="transform" type="translate"
          values="1900 200; 1900 200; 200 900; 200 900" keyTimes="0;0.55;0.8;1" dur="22s" begin="6s" repeatCount="indefinite" />
        </line>
      </g>
    </svg>);

}

// Black hole — pitch-black event horizon, sharp photon-ring outline, with
// soft drifting mist around it. Slow, calm motion; nothing sudden.
function HeroSphere() {
  return (
    <div style={{
      position: 'absolute', top: '50%', left: '50%',
      transform: 'translate(-50%, -50%)',
      width: 'min(820px, 90vw)', height: 'min(820px, 90vw)',
      zIndex: 2, pointerEvents: 'none',
      animation: 'sphereDrift 24s ease-in-out infinite'
    }}>
      {/* 1. Far cosmic glow — extra-wide, very gradual fade so the outer
               boundary never reads as a visible circle edge. */}
      <div style={{
        position: 'absolute', inset: '-70%',
        borderRadius: '50%',
        background: 'radial-gradient(circle, rgba(30,107,255,.16) 0%, rgba(30,107,255,.08) 22%, rgba(30,107,255,.035) 42%, rgba(30,107,255,.012) 62%, transparent 92%)',
        filter: 'blur(80px)',
        animation: 'breath1 14s ease-in-out infinite'
      }} />

      {/* 2. MIST LAYER A — soft cloud-like patches drifting slowly clockwise.
               Patches are radial-gradient hot spots inside a ring-masked div, so
               they look like detached wisps of fog encircling the black hole.
               Outer mask fade lengthened so the layer dissolves into the void. */}
      <div style={{
        position: 'absolute', inset: '-30%',
        borderRadius: '50%',
        background:
        'radial-gradient(circle at 28% 32%, rgba(159,191,255,.30) 0%, transparent 18%),' +
        'radial-gradient(circle at 72% 38%, rgba(77,139,255,.36) 0%, transparent 20%),' +
        'radial-gradient(circle at 75% 70%, rgba(30,107,255,.30) 0%, transparent 18%),' +
        'radial-gradient(circle at 22% 68%, rgba(159,191,255,.25) 0%, transparent 16%),' +
        'radial-gradient(circle at 50% 88%, rgba(77,139,255,.28) 0%, transparent 14%)',
        WebkitMaskImage: 'radial-gradient(circle, transparent 28%, #000 40%, #000 52%, transparent 96%)',
        maskImage: 'radial-gradient(circle, transparent 28%, #000 40%, #000 52%, transparent 96%)',
        filter: 'blur(36px)',
        animation: 'spin 180s linear infinite, mistBreath 16s ease-in-out infinite'
      }} />

      {/* 3. MIST LAYER B — fewer, larger patches, counter-rotating even slower */}
      <div style={{
        position: 'absolute', inset: '-40%',
        borderRadius: '50%',
        background:
        'radial-gradient(circle at 18% 50%, rgba(77,139,255,.32) 0%, transparent 22%),' +
        'radial-gradient(circle at 82% 50%, rgba(30,107,255,.28) 0%, transparent 22%),' +
        'radial-gradient(circle at 50% 18%, rgba(159,191,255,.22) 0%, transparent 18%)',
        WebkitMaskImage: 'radial-gradient(circle, transparent 28%, #000 42%, #000 55%, transparent 100%)',
        maskImage: 'radial-gradient(circle, transparent 28%, #000 42%, #000 55%, transparent 100%)',
        filter: 'blur(52px)',
        opacity: 0.85,
        animation: 'spinRev 260s linear infinite, mistBreath2 22s ease-in-out infinite'
      }} />

      {/* 4. Subtle inner color halo right around the event horizon */}
      <div style={{
        position: 'absolute', inset: 0,
        borderRadius: '50%',
        background: 'radial-gradient(circle, transparent 35%, rgba(77,139,255,.18) 42%, rgba(30,107,255,.08) 52%, transparent 66%)',
        filter: 'blur(14px)',
        animation: 'breath5 10s ease-in-out infinite'
      }} />

      {/* 5. EVENT HORIZON — pitch black core. */}
      <div style={{
        position: 'absolute', inset: '26%',
        borderRadius: '50%',
        background: '#000',
        boxShadow: 'inset 0 0 30px 4px #000, 0 0 24px 6px rgba(0,0,0,.9)',
        zIndex: 3
      }} />

      {/* 6. PHOTON RING — sharp glowing outline at the void's edge. */}
      <div style={{
        position: 'absolute', inset: '25%',
        borderRadius: '50%',
        border: '1.5px solid rgba(255,255,255,.92)',
        zIndex: 4,
        animation: 'photonPulse 4s ease-in-out infinite'
      }} />
    </div>);

}

// ─── Hero scene — floating composition of tech UI elements ──
function HeroScene() {
  return (
    <div style={{ position: 'absolute', inset: 0 }}>
      {/* Decorative dotted connectors behind elements */}
      <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', pointerEvents: 'none', opacity: 0.4 }} viewBox="0 0 560 620" preserveAspectRatio="none">
        <path d="M 60 60 Q 160 30 260 80" stroke="var(--blue)" strokeWidth="1" strokeDasharray="2 4" fill="none" />
        <path d="M 220 270 Q 280 320 370 300" stroke="var(--blue)" strokeWidth="1" strokeDasharray="2 4" fill="none" />
        <path d="M 280 470 Q 360 500 470 460" stroke="var(--blue)" strokeWidth="1" strokeDasharray="2 4" fill="none" />
      </svg>

      {/* Glow nodes */}
      <GlowNode style={{ top: 40, left: 30 }} size={8} />
      <GlowNode style={{ top: 290, left: 250 }} size={6} />
      <GlowNode style={{ top: 470, right: 80 }} size={7} />

      {/* Live status — top left */}
      <div style={{ position: 'absolute', top: 0, left: 0, zIndex: 5 }}>
        <LiveChip />
      </div>

      {/* Main console card — top right */}
      <div style={{ position: 'absolute', top: 56, right: 0, width: 380, zIndex: 3 }}>
        <CompactConsole />
      </div>

      {/* Metric chip — overlapping console left side */}
      <div style={{ position: 'absolute', top: 260, left: 0, width: 220, zIndex: 5 }}>
        <MetricCard />
      </div>

      {/* Integrations panel — bottom right, slightly tucked under console */}
      <div style={{ position: 'absolute', bottom: 24, right: 24, width: 220, zIndex: 4 }}>
        <IntegrationsCard />
      </div>

      {/* Alert / agent card — bottom left */}
      <div style={{ position: 'absolute', bottom: 0, left: 40, width: 270, zIndex: 5 }}>
        <AlertCard />
      </div>
    </div>);

}

function GlowNode({ style, size = 8 }) {
  return (
    <div style={{
      position: 'absolute', width: size, height: size, borderRadius: 999,
      background: 'var(--blue)', boxShadow: `0 0 ${size * 2}px var(--blue), 0 0 ${size * 4}px var(--blue-glow)`,
      ...style
    }} />);

}

// Live system pill with pulsing dot
function LiveChip() {
  return (
    <div style={{
      display: 'inline-flex', alignItems: 'center', gap: 10,
      padding: '8px 14px', borderRadius: 999,
      background: 'rgba(6,7,10,.7)', border: '1px solid var(--line)',
      backdropFilter: 'blur(8px)',
      boxShadow: '0 8px 32px rgba(0,0,0,.4)'
    }}>
      <span style={{ position: 'relative', display: 'inline-flex' }}>
        <span style={{ width: 8, height: 8, borderRadius: 999, background: '#52E1A7', boxShadow: '0 0 10px #52E1A7' }} />
        <span style={{ position: 'absolute', inset: 0, borderRadius: 999, background: '#52E1A7', animation: 'ping 1.8s ease-out infinite' }} />
      </span>
      <span style={{ fontFamily: 'var(--mono)', fontSize: 12, color: '#fff', letterSpacing: 0.4 }}>
        Live · 42 systems running
      </span>
    </div>);

}

// Big metric card with avatar
function MetricCard() {
  return (
    <div style={{
      width: '100%', padding: 18,
      background: 'linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.01))',
      border: '1px solid var(--line)', borderRadius: 14,
      boxShadow: '0 16px 48px rgba(0,0,0,.45), 0 0 0 1px rgba(30,107,255,.12)',
      backdropFilter: 'blur(10px)'
    }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 10 }}>
        <Avatar initials="N" palette={5} size={28} ringColor="transparent" ring={0} />
        <div style={{ fontFamily: 'var(--mono)', fontSize: 11, color: 'rgba(255,255,255,.65)', letterSpacing: 0.6 }}>NORDLY · billing</div>
      </div>
      <div style={{ fontSize: 36, fontWeight: 600, color: '#fff', letterSpacing: -1, lineHeight: 1 }}>
        <span style={{ color: '#52E1A7' }}>+87%</span>
      </div>
      <div style={{ marginTop: 6, fontSize: 12.5, color: 'rgba(255,255,255,.6)', lineHeight: 1.4 }}>
        manual ops time saved · 4 weeks to production
      </div>
      <div style={{ marginTop: 12, height: 32, position: 'relative' }}>
        <MiniSpark />
      </div>
    </div>);

}

// Tiny line chart
function MiniSpark() {
  const pts = [8, 10, 9, 14, 12, 18, 16, 22, 20, 26, 24, 30];
  const W = 184,H = 30;
  const max = Math.max(...pts),min = Math.min(...pts);
  const xy = pts.map((v, i) => [i * (W / (pts.length - 1)), H - (v - min) / (max - min) * H * 0.85 - 2]);
  const line = xy.map(([x, y], i) => (i ? 'L' : 'M') + x.toFixed(1) + ' ' + y.toFixed(1)).join(' ');
  return (
    <svg viewBox={`0 0 ${W} ${H}`} preserveAspectRatio="none" style={{ width: '100%', height: '100%' }}>
      <path d={line + ` L ${W} ${H} L 0 ${H} Z`} fill="rgba(82,225,167,.18)" />
      <path d={line} stroke="#52E1A7" strokeWidth="1.6" fill="none" strokeLinecap="round" />
    </svg>);

}

// Integrations card showing connector list
function IntegrationsCard() {
  const stack = [
  { n: 'Stripe', c: '#635BFF' },
  { n: 'Snowflake', c: '#29B5E8' },
  { n: 'Postgres', c: '#336791' },
  { n: 'Slack', c: '#E01E5A' }];

  return (
    <div style={{
      width: '100%', padding: 16,
      background: 'rgba(10,11,14,.85)',
      border: '1px solid var(--line)', borderRadius: 14,
      backdropFilter: 'blur(12px)',
      boxShadow: '0 16px 48px rgba(0,0,0,.4)'
    }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 12 }}>
        <span style={{ fontFamily: 'var(--mono)', fontSize: 10, color: 'rgba(255,255,255,.5)', letterSpacing: 0.6, textTransform: 'uppercase' }}>// connectors</span>
        <span style={{ fontFamily: 'var(--mono)', fontSize: 10, color: '#52E1A7' }}>4 · linked</span>
      </div>
      {stack.map((s) =>
      <div key={s.n} style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '7px 0', borderTop: '1px solid var(--line-soft)' }}>
          <span style={{ width: 22, height: 22, borderRadius: 6, background: s.c, display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--mono)', fontSize: 11, fontWeight: 700, color: '#fff' }}>{s.n[0]}</span>
          <span style={{ fontSize: 13, color: '#fff', flex: 1 }}>{s.n}</span>
          <Icon name="check" size={14} color="#52E1A7" stroke={2.4} />
        </div>
      )}
    </div>);

}

// Anomaly / agent alert card
function AlertCard() {
  return (
    <div style={{
      width: '100%', padding: 16,
      background: 'rgba(10,11,14,.88)',
      border: '1px solid rgba(30,107,255,.35)', borderRadius: 14,
      boxShadow: '0 0 0 1px rgba(30,107,255,.15), 0 24px 60px rgba(30,107,255,.18)',
      backdropFilter: 'blur(12px)'
    }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 10 }}>
        <span style={{
          width: 30, height: 30, borderRadius: 8,
          background: 'rgba(30,107,255,.15)', border: '1px solid rgba(30,107,255,.3)',
          display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#9FBFFF'
        }}>
          <Icon name="spark" size={15} stroke={2} />
        </span>
        <span style={{ fontFamily: 'var(--mono)', fontSize: 11, color: '#9FBFFF', letterSpacing: 0.6, textTransform: 'uppercase' }}>// forecast agent</span>
      </div>
      <div style={{ fontSize: 14, color: '#fff', lineHeight: 1.4, fontWeight: 500 }}>
        Q3 churn variance crossed −2σ.
      </div>
      <div style={{ marginTop: 4, fontSize: 12.5, color: 'rgba(255,255,255,.6)', lineHeight: 1.45 }}>
        Drafted a remediation playbook in #cs-ops.
      </div>
      <div style={{ marginTop: 12, display: 'flex', gap: 6 }}>
        <span style={{ padding: '4px 10px', borderRadius: 999, background: 'rgba(30,107,255,.12)', border: '1px solid rgba(30,107,255,.35)', fontSize: 11, color: '#9FBFFF', fontFamily: 'var(--mono)', letterSpacing: 0.4 }}>Auto-resolve</span>
        <span style={{ padding: '4px 10px', borderRadius: 999, background: 'transparent', border: '1px solid var(--line)', fontSize: 11, color: 'rgba(255,255,255,.7)', fontFamily: 'var(--mono)', letterSpacing: 0.4 }}>Snooze</span>
      </div>
    </div>);

}

// Compact console card for hero (smaller than full ConsolePreview)
function CompactConsole() {
  return (
    <div style={{
      borderRadius: 14, overflow: 'hidden',
      border: '1px solid var(--line)',
      background: 'linear-gradient(180deg, #0E1117, #06070A)',
      boxShadow: '0 40px 100px rgba(0,0,0,.6), 0 0 0 1px rgba(30,107,255,.12), 0 0 60px rgba(30,107,255,.08)'
    }}>
      {/* Window chrome */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '10px 14px', borderBottom: '1px solid var(--line)' }}>
        <span style={{ width: 9, height: 9, borderRadius: 999, background: '#FF5F57' }} />
        <span style={{ width: 9, height: 9, borderRadius: 999, background: '#FFBD2E' }} />
        <span style={{ width: 9, height: 9, borderRadius: 999, background: '#28C840' }} />
        <div style={{ marginLeft: 12, fontFamily: 'var(--mono)', fontSize: 11, color: 'rgba(255,255,255,.5)' }}>billing-reconciler · prod</div>
      </div>

      <div style={{ padding: 18 }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 14 }}>
          <div>
            <div style={{ fontSize: 14, fontWeight: 500, color: '#fff' }}>Run history · 24h</div>
            <div style={{ fontFamily: 'var(--mono)', fontSize: 10, color: 'rgba(255,255,255,.45)', marginTop: 3, letterSpacing: 0.4 }}>1,432 INVOICES · 0 FAILURES</div>
          </div>
          <span style={{ fontFamily: 'var(--mono)', fontSize: 10, color: '#52E1A7', display: 'inline-flex', alignItems: 'center', gap: 5 }}>
            <span style={{ width: 6, height: 6, borderRadius: 999, background: '#52E1A7', boxShadow: '0 0 6px #52E1A7' }} /> running
          </span>
        </div>

        {/* Chart */}
        <div style={{ height: 110, background: 'rgba(255,255,255,.015)', border: '1px solid var(--line)', borderRadius: 8, padding: 10, overflow: 'hidden' }}>
          <Sparkline />
        </div>

        {/* Recent runs */}
        <div style={{ marginTop: 12, border: '1px solid var(--line)', borderRadius: 8, overflow: 'hidden' }}>
          {[
          ['11:42 UTC', '247 invoices reconciled', '#52E1A7'],
          ['10:42 UTC', '312 invoices reconciled', '#52E1A7'],
          ['09:42 UTC', '188 reconciled · 1 retry', '#FFB948']].
          map(([t, msg, c], i) =>
          <div key={i} style={{
            display: 'grid', gridTemplateColumns: '90px 1fr 60px', padding: '8px 12px', alignItems: 'center', gap: 8,
            borderTop: i ? '1px solid var(--line-soft)' : 'none', fontFamily: 'var(--mono)', fontSize: 11, color: 'rgba(255,255,255,.7)'
          }}>
              <span>{t}</span>
              <span style={{ color: '#fff', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{msg}</span>
              <span style={{ color: c, textAlign: 'right' }}>● ok</span>
            </div>
          )}
        </div>
      </div>
    </div>);

}

// Decorative "system" console card under hero (kept for re-use, no longer rendered by Hero)
function ConsolePreview() {
  return (
    <div style={{
      borderRadius: 16, overflow: 'hidden',
      border: '1px solid var(--line)',
      background: 'linear-gradient(180deg, #0E1117, #06070A)',
      boxShadow: '0 40px 120px rgba(30,107,255,.18), 0 0 0 1px rgba(30,107,255,.15)'
    }}>
      {/* Window chrome */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '12px 16px', borderBottom: '1px solid var(--line)' }}>
        <span style={{ width: 10, height: 10, borderRadius: 999, background: '#FF5F57' }} />
        <span style={{ width: 10, height: 10, borderRadius: 999, background: '#FFBD2E' }} />
        <span style={{ width: 10, height: 10, borderRadius: 999, background: '#28C840' }} />
        <div style={{ marginLeft: 16, fontFamily: 'var(--mono)', fontSize: 12, color: 'rgba(255,255,255,.5)' }}>xybos · billing-reconciler · prod</div>
        <div style={{ marginLeft: 'auto', display: 'flex', gap: 14, alignItems: 'center' }}>
          <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontFamily: 'var(--mono)', fontSize: 11, color: '#52E1A7' }}>
            <span style={{ width: 6, height: 6, borderRadius: 999, background: '#52E1A7', boxShadow: '0 0 8px #52E1A7' }} />
            running
          </span>
        </div>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: '240px 1fr', minHeight: 360 }}>
        {/* Sidebar */}
        <div style={{ padding: 18, borderRight: '1px solid var(--line)', display: 'flex', flexDirection: 'column', gap: 4 }}>
          {[
          ['Overview', false], ['Runs', true], ['Sources', false], ['Schedule', false],
          ['Alerts', false], ['Settings', false]].
          map(([n, on]) =>
          <div key={n} style={{
            padding: '8px 10px', borderRadius: 7, fontSize: 13,
            color: on ? '#fff' : 'rgba(255,255,255,.5)',
            background: on ? 'rgba(30,107,255,.12)' : 'transparent',
            fontWeight: on ? 500 : 400
          }}>{n}</div>
          )}
          <div style={{ marginTop: 16, padding: '8px 10px', fontFamily: 'var(--mono)', fontSize: 10, color: 'rgba(255,255,255,.4)', letterSpacing: 0.6, textTransform: 'uppercase' }}>Connectors</div>
          {['Stripe', 'Snowflake', 'Slack', 'PostgreSQL'].map((n) =>
          <div key={n} style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '6px 10px', fontSize: 12.5, color: 'rgba(255,255,255,.65)' }}>
              <span style={{ width: 6, height: 6, borderRadius: 999, background: 'var(--blue)' }} />{n}
            </div>
          )}
        </div>

        {/* Main area */}
        <div style={{ padding: 24, display: 'flex', flexDirection: 'column', gap: 16 }}>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
            <div>
              <div style={{ fontSize: 17, fontWeight: 500, color: '#fff' }}>Run history · last 24h</div>
              <div style={{ fontFamily: 'var(--mono)', fontSize: 11, color: 'rgba(255,255,255,.45)', marginTop: 4 }}>HOURLY · 1,432 INVOICES PROCESSED · 0 FAILURES</div>
            </div>
            <Btn variant="secondary" size="sm">Trigger run</Btn>
          </div>

          {/* Chart */}
          <div style={{ position: 'relative', height: 140, background: 'rgba(255,255,255,.02)', border: '1px solid var(--line)', borderRadius: 10, padding: 16, overflow: 'hidden' }}>
            <Sparkline />
          </div>

          {/* Recent runs */}
          <div style={{ border: '1px solid var(--line)', borderRadius: 10, overflow: 'hidden' }}>
            {[
            ['11:42 UTC', '1.2s', '↳ 247 invoices reconciled', '#52E1A7'],
            ['10:42 UTC', '0.9s', '↳ 312 invoices reconciled', '#52E1A7'],
            ['09:42 UTC', '1.4s', '↳ 188 invoices reconciled · 1 retry', '#FFB948'],
            ['08:42 UTC', '0.8s', '↳ 401 invoices reconciled', '#52E1A7']].
            map(([t, d, msg, c], i) =>
            <div key={i} style={{
              display: 'grid', gridTemplateColumns: '110px 70px 1fr 90px', padding: '11px 16px', alignItems: 'center', gap: 12,
              borderTop: i ? '1px solid var(--line-soft)' : 'none', fontFamily: 'var(--mono)', fontSize: 12, color: 'rgba(255,255,255,.75)'
            }}>
                <span>{t}</span>
                <span style={{ color: 'rgba(255,255,255,.5)' }}>{d}</span>
                <span style={{ color: '#fff' }}>{msg}</span>
                <span style={{ color: c, textAlign: 'right' }}>● ok</span>
              </div>
            )}
          </div>
        </div>
      </div>
    </div>);

}

// Inline sparkline SVG — area chart with a gradient
function Sparkline() {
  const pts = [22, 28, 24, 32, 30, 38, 34, 42, 40, 48, 46, 54, 52, 60, 58, 68, 64, 72, 70, 78, 74];
  const W = 880,H = 110,max = Math.max(...pts),min = Math.min(...pts);
  const xy = pts.map((v, i) => [i * (W / (pts.length - 1)), H - (v - min) / (max - min) * (H - 20) - 8]);
  const line = xy.map(([x, y], i) => (i ? 'L' : 'M') + x.toFixed(1) + ' ' + y.toFixed(1)).join(' ');
  const area = line + ` L ${W} ${H} L 0 ${H} Z`;
  return (
    <svg viewBox={`0 0 ${W} ${H}`} preserveAspectRatio="none" style={{ width: '100%', height: '100%' }}>
      <defs>
        <linearGradient id="spArea" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="rgba(30,107,255,.45)" />
          <stop offset="100%" stopColor="rgba(30,107,255,0)" />
        </linearGradient>
      </defs>
      <path d={area} fill="url(#spArea)" />
      <path d={line} stroke="#4D8BFF" strokeWidth="1.8" fill="none" strokeLinecap="round" strokeLinejoin="round"
      style={{ filter: 'drop-shadow(0 0 8px rgba(77,139,255,.5))' }} />
      <circle cx={xy[xy.length - 1][0]} cy={xy[xy.length - 1][1]} r="4" fill="#fff" stroke="#1E6BFF" strokeWidth="2" />
    </svg>);

}

// ─── Logo marquee ────────────────────────────────────────────
function LogoMarquee() {
  const logos = [
  'NORDLY', 'KOENIG·CO', 'AXIS·LABS', 'ENVOY/FI', 'HELIO', 'MORPHIC',
  'NUMERA', 'PARLEY', 'STRATA', 'CIRCUIT·9', 'OASIS', 'DELTAQ'];

  const doubled = [...logos, ...logos];
  return (
    <Section style={{ padding: '24px 0 64px', overflow: 'hidden' }}>
      <Container>
        <div style={{ textAlign: 'center', marginBottom: 28 }}>
          <span style={{ fontFamily: 'var(--mono)', fontSize: 11, color: 'rgba(255,255,255,.45)', letterSpacing: 0.8, textTransform: 'uppercase' }}>
            Teams we&apos;ve built with
          </span>
        </div>
        <div style={{
          position: 'relative', overflow: 'hidden',
          WebkitMaskImage: 'linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent)',
          maskImage: 'linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent)'
        }}>
          <div className="marquee-track">
            {doubled.map((n, i) =>
            <div key={i} style={{ fontFamily: 'var(--mono)', fontSize: 16, fontWeight: 600, color: 'rgba(255,255,255,.65)', letterSpacing: 1.5, whiteSpace: 'nowrap' }}>
                {n}
              </div>
            )}
          </div>
        </div>
      </Container>
    </Section>);

}

// ─── Why Xybos ───────────────────────────────────────────────
function WhyUs() {
  const pillars = [
  {
    title: 'Enterprise engineering, your scale',
    body: 'The same engineering principles found in global enterprise systems — applied to your business. We deliver the system, run it, and keep improving it. You get the outcome, not the team to manage.'
  },
  {
    title: 'Secure, modern, built to last',
    body: 'Modern technologies, secure by default. Your data stays encrypted in transit and at rest, dependencies stay patched, the framework keeps receiving security updates for years. We make engineering choices today with what they cost you tomorrow.'
  },
  {
    title: 'Specialists, not generalists.',
    body: 'Operational automation for retail, manufacturing, and logistics. Nothing else lands on our desk. That focus is why we ship faster — and why our systems still run two years in.'
  }];

  window.useLang();
  return (
    <Section id="why">
      <Container>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 80, alignItems: 'flex-end', marginBottom: 64 }}>
          <SectionHeader
            eyebrow={window.t('[ 01 · WHY XYBOS ]')}
            title={<>{window.t('Most automation projects fail.')} <span style={{ color: '#4D8BFF' }}>{window.t("Ours don't.")}</span></>} />

          <p style={{ fontSize: 16, color: 'rgba(255,255,255,.65)', lineHeight: 1.65, margin: 0 }}>{window.t("Most automation projects fail in execution, not in the tech. We've spent years building production ML systems at enterprise scale — the kind where downtime costs tens of thousands a day. We bring that same engineering expertise to your project.")}</p>
        </div>

        <div data-stagger style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 20 }}>
          {pillars.map((p, i) =>
          <GlowCard key={i} style={{ padding: 32 }}>
              <div style={{ fontFamily: 'var(--mono)', fontSize: 11, color: '#9FBFFF', letterSpacing: 0.6, marginBottom: 18 }}>
                [ 0{i + 1} ]
              </div>
              <h3 style={{ fontSize: 22, fontWeight: 500, letterSpacing: -0.5, lineHeight: 1.2, margin: '0 0 14px', color: '#fff' }}>
                {window.t(p.title)}
              </h3>
              <p style={{ fontSize: 14.5, color: 'rgba(255,255,255,.62)', lineHeight: 1.6, margin: 0 }}>{window.t(p.body)}</p>
            </GlowCard>
          )}
        </div>
      </Container>
    </Section>);

}

// ─── Services / capabilities ─────────────────────────────────
function Services() {
  const items = [
  { icon: 'cube', title: <>{window.t('Store Ordering')} <span style={{ color: '#4D8BFF' }}>{window.t('Automation')}</span></>,
    tag: 'RETAIL · ORDERING',
    body: 'Most retailers lose 5–15% of revenue to stockouts and another 10–20% to overstock. Our ordering engine combines your sales history, current stock levels, supplier lead times and seasonality into a daily ML-driven recommendation — or fully automated order placement.',
    bullets: ['30–60% fewer stockouts', '15–25% lower inventory holding cost', '4–13% higher turnover'] },
  { icon: 'database', title: <>{window.t('Warehouse')} <span style={{ color: '#4D8BFF' }}>{window.t('Automation')}</span></>,
    tag: 'LOGISTICS · OPS',
    body: 'We build an automated warehouse system: inventory tracking, ML demand forecasts that account for seasonality and supplier lead times, purchase orders generated automatically when thresholds are crossed. Your team stops chasing spreadsheets — they oversee a system that handles the calculations, the timing, and the paperwork.',
    bullets: ['Pick-path optimisation', 'Predictive replenishment', 'WMS / ERP integration '] },
  { icon: 'chart', title: <><span style={{ color: '#4D8BFF' }}>{window.t('AI-Powered')}</span> {window.t('Business Intelligence')}</>,
    tag: 'INSIGHT · DECISION',
    body: 'Dashboards are not insight. We build BI systems that flag what matters, predict what\'s coming, and tell your team what to do about it — instead of leaving them to interpret another chart.',
    bullets: ['Predictive forecasts, not retrospective charts', 'Action-flagged alerts', 'Built on your data warehouse'] },
  { icon: 'flow', title: <>{window.t('Custom')} <span style={{ color: '#4D8BFF' }}>{window.t('Process Automation')}</span></>,
    tag: 'OPERATIONS · BACK-OFFICE',
    body: 'The work nobody wants to do but everyone has to: invoice reconciliation, supplier matching, demand forecasting, quality-control flagging, document processing. Where there\'s a clear rule, we code it. Where there isn\'t, we let ML learn the pattern from your data.',
    bullets: ['Rules where they fit, ML where they don\'t', '70%+ of manual work eliminated', 'Catches errors humans miss'] }];

  window.useLang();
  return (
    <Section id="services">
      <Container>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 80, alignItems: 'end', marginBottom: 64 }}>
          <SectionHeader
            eyebrow={window.t('[ 02 · WHAT WE BUILD ]')}
            title={<><span style={{ color: '#4D8BFF' }}>{window.t('Four core services.')}</span> {window.t('Each starts with a specific problem.')}</>} />
          
          <p style={{ fontSize: 16, color: 'rgba(255,255,255,.55)', lineHeight: 1.6, margin: 0 }}>{window.t('Each one ends with a system that pays for itself. No products, no templates — every engagement is built from scratch, then deployed and maintained. You see the outcome in your operation; we carry the engineering.')}</p>
        </div>

        <div data-stagger style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 20 }}>
          {items.map((it, i) =>
          <GlowCard key={i} style={{ padding: 36 }}>
              <div className="service-tophead" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 28, gap: 16 }}>
                <div style={{
                width: 52, height: 52, borderRadius: 12,
                background: 'rgba(30,107,255,.10)', border: '1px solid rgba(30,107,255,.3)',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                color: '#9FBFFF',
                boxShadow: '0 0 24px rgba(30,107,255,.25), inset 0 0 16px rgba(30,107,255,.1)'
              }}>
                  <Icon name={it.icon} size={26} stroke={1.6} />
                </div>
                <span className="service-tag" style={{ fontFamily: 'var(--mono)', fontSize: 10, color: 'rgba(255,255,255,.4)', letterSpacing: 0.8, textAlign: 'right', lineHeight: 1.5, maxWidth: '60%' }}>
                  [ 0{i + 1} · {window.t(it.tag)} ]
                </span>
              </div>
              <h3 style={{ fontSize: 28, fontWeight: 500, letterSpacing: -0.8, lineHeight: 1.1, margin: '0 0 14px', color: '#fff' }}>
                {it.title}
              </h3>
              <p style={{ fontSize: 15, color: 'rgba(255,255,255,.6)', lineHeight: 1.55, margin: 0 }}>{window.t(it.body)}</p>
              <ul style={{ margin: '24px 0 0', padding: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 10 }}>
                {it.bullets.map((b) =>
              <li key={b} style={{ display: 'flex', alignItems: 'center', gap: 10, fontSize: 14, color: 'rgba(255,255,255,.7)' }}>
                    <Icon name="check" size={16} color="var(--blue-bright)" stroke={2} />{window.t(b)}
                  </li>
              )}
              </ul>
            </GlowCard>
          )}
        </div>
      </Container>
    </Section>);

}

Object.assign(window, { Nav, Hero, LogoMarquee, WhyUs, Services });