const BLUEPRINTS = [
  { icon: 'phone-incoming', blurb: 'Answers every inbound call, qualifies against your criteria and books the meeting straight into a rep calendar.', cat: 'AI Agents', short: 'Voice Qualification', title: 'Inbound Voice Qualification & CRM Booking System', parts: ['Voice agent with qualification script', 'CRM lead + deal creation', 'Calendar booking & SMS confirm'], steps: [['phone-incoming', 'Call answered', 'Voice agent greets, captures need and location.'], ['list-checks', 'Qualification', 'Scores against your criteria; low confidence escalates to a person.'], ['database', 'CRM write', 'Creates lead, deal and call transcript in your CRM.'], ['calendar-check', 'Booking', 'Offers rep availability and books the slot.'], ['message-circle', 'Confirmation', 'SMS/WhatsApp confirmation with reschedule link.']] },
  { icon: 'messages-square', blurb: 'Event-driven follow-ups that move across WhatsApp, email and SMS, and stop the moment a customer replies.', cat: 'AI Agents', short: 'Follow-Up Engine', title: 'Multi-Channel Follow-Up Engine (WhatsApp + SMS + Email)', parts: ['Event-based triggers', 'Channel fallback rules', 'Reply detection & stop'], steps: [['zap', 'Trigger', 'Quote sent, call missed or form abandoned.'], ['message-circle', 'WhatsApp', 'Template message within approved window.'], ['mail', 'Email', 'Fallback after 24h with summary and attachment.'], ['smartphone', 'SMS', 'Final reminder; sequence stops on any reply.'], ['user-round-check', 'Handoff', 'Replies route to the owning rep with history.']] },
  { icon: 'layout-dashboard', blurb: 'One tested data model behind a role-based dashboard and a weekly digest leadership actually reads.', cat: 'Software', short: 'Exec Dashboard', title: 'Executive Operational Dashboard & Reporting Pipeline', parts: ['Warehouse + ETL jobs', 'Role-based dashboard', 'Scheduled PDF/Slack digests'], steps: [['plug', 'Connect', 'Read-only connectors to CRM, ERP and billing.'], ['git-merge', 'Model', 'Clean, joined tables in PostgreSQL with tests.'], ['layout-dashboard', 'Dashboard', 'KPI views by role, drill-down to records.'], ['send', 'Digest', 'Weekly summary to leadership via email or Slack.']] },
  { icon: 'server', blurb: 'Put an API in front of the old system, rebuild screens module by module, and cut over only when numbers match.', cat: 'Software', short: 'Legacy Modernization', title: 'Legacy Tool Modernization & API Gateway', parts: ['API layer over legacy DB', 'Incremental web modules', 'Parallel-run & cutover plan'], steps: [['server', 'Wrap', 'Gateway exposes the legacy database as a REST API.'], ['app-window', 'Rebuild', 'Replace screens one module at a time on the web.'], ['git-compare', 'Parallel run', 'Old and new run side by side with diff checks.'], ['check-circle', 'Cutover', 'Retire the legacy module once numbers match.']] },
  { icon: 'file-check', blurb: 'Invoices and POs parsed, validated and approved by a named person before anything posts to the ERP.', cat: 'Ops Automation', short: 'Approval & Doc Sync', title: 'Back-Office Approval & Document Sync Workflow', parts: ['Document parsing', 'Approval cards with audit log', 'ERP + drive sync'], steps: [['file-input', 'Intake', 'Invoices or POs arrive by email or upload.'], ['scan-text', 'Extract', 'Fields parsed and validated against master data.'], ['shield-check', 'Approve', 'Manager approves or requests edits; every action logged.'], ['folder-sync', 'Sync', 'Record posted to ERP; file filed in shared drive.']] },
  { icon: 'clapperboard', blurb: 'A research-backed draft queue for blogs, captions and Reel scripts, with an editor gate before publishing.', cat: 'Digital Marketing', short: 'Content Ops Desk', title: 'Human-Reviewed Content & Short-Form Video Ops Desk', parts: ['Research-backed draft queue', 'Reel script templates', 'Review gate before publish'], steps: [['search', 'Research', 'Sources gathered and attached to each brief.'], ['file-text', 'Draft', 'Blog, caption and Reel script drafts generated.'], ['user-check', 'Review', 'Editor checks claims, voice and visuals.'], ['calendar', 'Schedule', 'Only approved items enter the publishing calendar.']] },
];

function Blueprints() {
  const { SectionHeader, Tabs, Badge, Button, Icon } = DS;
  const wide = useMedia('(min-width: 1040px)');
  const [f, setF] = React.useState('All');
  const list = BLUEPRINTS.filter((b) => f === 'All' || b.cat === f);
  const [sel, setSel] = React.useState(BLUEPRINTS[0].title);
  const [hov, setHov] = React.useState(null);
  const cur = list.find((b) => b.title === sel) || list[0];
  const Screen = BLUEPRINT_SCREENS[BLUEPRINTS.indexOf(cur)];
  return (
    <section id="blueprints" style={{ background: 'transparent', padding: `${wide ? 112 : 72}px 0`, borderBottom: '1px solid var(--yk-lavender)' }}>
      <Container>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', gap: 24, flexWrap: 'wrap' }}>
          <Reveal><SectionHeader eyebrow="Blueprints" title="Deployable systems, already mapped." lead="Starting architectures we adapt to your stack. Select a blueprint to see what it includes and the screens your team will use." /></Reveal>
          <Reveal delay={0.07} style={{ maxWidth: '100%' }}><Tabs value={f} onChange={setF} tabs={['All', 'Software', 'AI Agents', 'Ops Automation', 'Digital Marketing']} style={{ background: '#fff' }} /></Reveal>
        </div>
        <Reveal delay={0.1}>
          <div role="tablist" aria-label="Blueprints" style={{ display: 'grid', gridTemplateColumns: `repeat(auto-fit, minmax(${wide ? 150 : 140}px, 1fr))`, gap: 10, marginTop: 44 }}>
            {list.map((b) => {
              const on = b.title === cur.title;
              return (
                <button key={b.title} type="button" role="tab" aria-selected={on} onClick={() => setSel(b.title)} onMouseEnter={() => setHov(b.title)} onMouseLeave={() => setHov(null)} style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 10, padding: '14px 14px 16px', textAlign: 'left', cursor: 'pointer', borderRadius: 14, background: on ? 'var(--yk-indigo)' : 'var(--glass-bg)', backdropFilter: 'var(--glass-blur)', WebkitBackdropFilter: 'var(--glass-blur)', border: '1px solid ' + (on ? 'var(--yk-indigo)' : hov === b.title ? 'var(--border-accent)' : 'var(--glass-border)'), boxShadow: on ? 'var(--shadow-md)' : 'var(--glass-shadow)', transform: hov === b.title && !on ? 'translateY(-2px)' : 'none', transition: 'all .25s cubic-bezier(.22,1,.36,1)', position: 'relative', minWidth: 0 }}>
                  <span style={{ width: 32, height: 32, borderRadius: 9, display: 'grid', placeItems: 'center', background: on ? 'linear-gradient(135deg,#7C3AED,#2563EB 50%,#06B6D4)' : 'var(--yk-lavender)', color: on ? '#fff' : 'var(--yk-violet)' }}><Icon name={b.icon} size={16} /></span>
                  <span style={{ font: '600 14px/1.3 var(--font-display)', color: on ? '#fff' : 'var(--yk-indigo)' }}>{b.short}</span>
                  <span style={{ font: '500 10.5px var(--font-mono)', letterSpacing: '.04em', textTransform: 'uppercase', color: on ? '#A5F3FC' : 'var(--yk-charcoal)' }}>{b.cat} · {b.steps.length} steps</span>
                </button>
              );
            })}
          </div>
          <div style={{ position: 'relative', marginTop: 14, paddingBottom: 24 }}>
          {[2, 1].map((d) => <div key={d} aria-hidden style={{ position: 'absolute', left: d * 22, right: d * 22, top: 0, bottom: 24 - d * 12, borderRadius: 18, background: d === 2 ? 'rgba(255,255,255,.3)' : 'rgba(255,255,255,.5)', border: '1px solid var(--glass-border)', backdropFilter: 'var(--glass-blur)', WebkitBackdropFilter: 'var(--glass-blur)', boxShadow: 'var(--glass-shadow)', transform: `translateY(${d * 12}px)` }} />)}
          <div key={cur.title} style={{ position: 'relative',  background: 'var(--glass-bg-strong)', backdropFilter: 'var(--glass-blur)', WebkitBackdropFilter: 'var(--glass-blur)', border: '1px solid var(--glass-border)', borderRadius: 18, boxShadow: 'var(--glass-shadow)', display: 'grid', gridTemplateColumns: wide ? 'minmax(0,1fr) minmax(0,1.15fr)' : '1fr', gap: wide ? 40 : 20, padding: wide ? 36 : 18, animation: 'yk-fade-up .45s cubic-bezier(.22,1,.36,1) both' }}>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 16, minWidth: 0 }}>
              <Badge tone="violet" size="sm" style={{ alignSelf: 'flex-start' }}>{cur.cat}</Badge>
              <h3 style={{ font: `600 ${wide ? 30 : 22}px/1.2 var(--font-display)`, letterSpacing: '-0.02em', color: 'var(--yk-indigo)', margin: 0, textWrap: 'pretty' }}>{cur.title}</h3>
              <p style={{ font: '400 16px/1.6 var(--font-body)', color: 'var(--yk-charcoal)', margin: 0 }}>{cur.blurb}</p>
              <div><MonoLabel color="var(--yk-violet)">INCLUDED</MonoLabel>
                <ul style={{ listStyle: 'none', margin: '8px 0 0', padding: 0, display: 'grid', gap: 8 }}>
                  {cur.parts.map((p) => <li key={p} style={{ display: 'flex', gap: 8, font: '400 14px/1.5 var(--font-body)', color: 'var(--yk-charcoal)' }}><Icon name="check" size={16} color="var(--yk-sky-700)" style={{ marginTop: 2, flexShrink: 0 }} />{p}</li>)}
                </ul>
              </div>
              <div style={{ marginTop: 'auto' }}><Button arrow onClick={() => kitScroll('scope')}>Scope this blueprint</Button></div>
            </div>
            <div style={{ minWidth: 0, height: wide ? 420 : 'auto', minHeight: wide ? 0 : 420 }}><Screen live wide={wide} /></div>
          </div>
          </div>
        </Reveal>
      </Container>
    </section>
  );
}

Object.assign(window, { Blueprints });
