// services.jsx - "How we move your business forward".
// Impact-led (not product-led): four problems we solve, end-to-end.
// 2×2 grid of static glass cards (>3 cards → no hover-lift, per the glass rule);
// the brand-gradient edge still comes alive on hover. Unified CTA bridge to Contact.

const SVC_MONO = 'ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace';

const SERVICES = [
  {
    n: '01',
    title: "Software your team can't buy off the shelf",
    body: "No off-the-shelf SaaS fits how you actually work. We build the system that does, and you own it.",
    tags: ['Built around your workflow', 'Owned by you'],
  },
  {
    n: '02',
    title: 'AI that does the boring work, not the demo',
    body: 'Most AI impresses in a meeting and never ships. We build the few automations that remove real hours.',
    tags: ['Automate the repetitive', 'Ship in weeks, not quarters'],
  },
  {
    n: '03',
    title: 'Make your tools talk to each other',
    body: 'Salesforce, QuickBooks, HubSpot, Slack: all in silos. We connect them into one operation, not fifteen.',
    tags: ['Connect your stack', 'One source of truth'],
  },
  {
    n: '04',
    title: 'The old system nobody wants to touch',
    body: 'Every company has the codebase that breaks if you touch it. We stabilize, document, and modernize it.',
    tags: ['Stop the bleeding first', 'Modernize piece by piece'],
  },
];

function SvcChip({ children }) {
  return (
    <span style={{
      fontSize: 11.5, lineHeight: 1.3, padding: '5px 11px', borderRadius: 999,
      background: 'color-mix(in srgb, var(--fg) 4%, transparent)',
      color: 'var(--fg-muted)', border: '1px solid var(--hairline)', whiteSpace: 'nowrap',
    }}>{children}</span>
  );
}

function ServiceCard({ item, index }) {
  const [open, setOpen] = React.useState(false);
  const [hover, setHover] = React.useState(false);
  const shown = open || hover;
  return (
    <Reveal delay={index * 80} className="glass eglass eglass-soft svc-card"
      onClick={() => setOpen((o) => !o)}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{ borderRadius: 20, padding: 'clamp(14px, 2vh, 22px)', display: 'flex', flexDirection: 'column', gap: 'clamp(6px, 0.9vh, 10px)' }}>
      {/* top row: number + interactive affordance */}
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <span style={{ fontFamily: SVC_MONO, fontSize: 12, letterSpacing: '0.18em', color: 'var(--accent)' }}>{item.n}</span>
        <span aria-hidden="true" style={{ display: 'inline-flex', color: shown ? 'var(--accent)' : 'var(--fg-faint)',
          transform: shown ? 'rotate(45deg)' : 'none',
          transition: 'transform 340ms cubic-bezier(0.16,1,0.3,1), color 200ms ease' }}>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="square"><line x1="12" y1="5" x2="12" y2="19" /><line x1="5" y1="12" x2="19" y2="12" /></svg>
        </span>
      </div>

      <h3 style={{
        fontFamily: 'var(--font-display)', fontWeight: 600,
        fontSize: 'clamp(1rem, 1.45vw, 1.25rem)', lineHeight: 1.2,
        letterSpacing: '-0.01em', color: 'var(--fg)', margin: 0,
      }}>{item.title}</h3>

      {/* lower region: chips (default) crossfade to body (hover/open) */}
      <div className="svc-lower">
        <div className="svc-tags" style={{ opacity: shown ? 0 : 1, transition: 'opacity 300ms ease' }}>
          {item.tags.map((tg) => <SvcChip key={tg}>{tg}</SvcChip>)}
        </div>
        <div className="svc-body" style={{ opacity: shown ? 1 : 0, transition: 'opacity 300ms ease' }}>
          <p style={{ fontSize: 14, lineHeight: 1.55, color: 'var(--fg-muted)', margin: 0 }}>{item.body}</p>
        </div>
      </div>
    </Reveal>
  );
}

function Services() {
  const goToContact = (e) => {
    e.preventDefault();
    const el = document.getElementById('contact');
    if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
  };

  return (
    <section id="services" data-screen-label="Services" className="sec" aria-labelledby="svc-h"
      style={{ minHeight: 'calc(100svh - 72px)', display: 'flex', flexDirection: 'column', justifyContent: 'center', paddingBlock: 'clamp(24px, 3.5vh, 56px)' }}>
      <div className="sec-wrap" style={{ width: '100%' }}>
        <SectionHead eyebrow="Where we help" align="center" max={680} style={{ marginBottom: 'clamp(22px, 3.2vh, 38px)' }}
          sub="Four problems we see again and again. Each one solved end-to-end.">
          <span id="svc-h">How we move your business <span className="accent">forward</span></span>
        </SectionHead>

        <div className="grid-2 svc-grid">
          {SERVICES.map((item, i) => (
            <ServiceCard key={item.n} item={item} index={i} />
          ))}
        </div>

        {/* unified CTA bridge → Contact */}
        <Reveal delay={160} style={{
          marginTop: 'clamp(20px, 3vh, 36px)', display: 'flex', alignItems: 'center', justifyContent: 'center',
          gap: 18, flexWrap: 'wrap', flexShrink: 0,
        }}>
          <span style={{ fontSize: 15, color: 'var(--fg-muted)' }}>Not sure which one is you?</span>
          <a href="#contact" onClick={goToContact} className="gcta" style={{
            display: 'inline-flex', alignItems: 'center', gap: 10,
            padding: 'clamp(10px, 1.4vh, 15px) clamp(22px, 2.4vh, 28px)', borderRadius: 14, fontWeight: 600, fontSize: 15,
            background: 'var(--violet)', color: 'var(--platinum)', textDecoration: 'none',
            transition: 'transform 200ms ease, background 200ms ease, box-shadow 200ms ease',
          }}
            onMouseEnter={(e) => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 14px 40px rgba(66,83,175,0.32)'; }}
            onMouseLeave={(e) => { e.currentTarget.style.transform = 'none'; e.currentTarget.style.boxShadow = 'none'; }}
          >Book a 30-minute qualification call
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="square"><path d="M5 12h14M13 6l6 6-6 6" /></svg>
          </a>
        </Reveal>
      </div>
    </section>
  );
}

window.Services = Services;
