File size: 28,496 Bytes
4b3a33f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff85727
4b3a33f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff85727
 
 
d998071
 
ff85727
 
 
d998071
ff85727
 
 
d998071
ff85727
 
 
d998071
ff85727
 
 
 
 
 
 
 
 
 
 
d998071
ff85727
 
 
 
 
 
 
 
 
d998071
ff85727
 
d998071
ff85727
 
 
 
 
 
 
4b3a33f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff85727
 
 
 
4b3a33f
ff85727
 
 
 
 
 
 
 
 
 
 
4b3a33f
 
ff85727
4b3a33f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
import React, { useState, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { supabase } from '../../supabaseClient';
import FullProfileOverlay from '../FullProfileOverlay';

// ─── Icons ───────────────────────────────────────────────────────────────────
const ClusterIcon = () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
        <circle cx="12" cy="12" r="3" /><circle cx="4" cy="6" r="3" /><circle cx="20" cy="6" r="3" />
        <circle cx="4" cy="18" r="3" /><circle cx="20" cy="18" r="3" />
        <line x1="12" y1="9" x2="4" y2="7" /><line x1="12" y1="9" x2="20" y2="7" />
        <line x1="12" y1="15" x2="4" y2="17" /><line x1="12" y1="15" x2="20" y2="17" />
    </svg>
);

const UsersIcon = () => (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
        <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2" /><circle cx="9" cy="7" r="4" />
        <path d="M23 21v-2a4 4 0 0 0-3-3.87" /><path d="M16 3.13a4 4 0 0 1 0 7.75" />
    </svg>
);

const SearchIcon = () => (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
        <circle cx="11" cy="11" r="8" /><line x1="21" y1="21" x2="16.65" y2="16.65" />
    </svg>
);

const ChevronDown = ({ open }) => (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"
        style={{ transform: open ? 'rotate(180deg)' : 'rotate(0deg)', transition: 'transform 0.3s ease' }}>
        <polyline points="6 9 12 15 18 9" />
    </svg>
);

const XIcon = () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
        <line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
    </svg>
);

// ─── Cluster colour palette ───────────────────────────────────────────────────
const CLUSTER_COLORS = [
    { accent: '#EF4444', glow: 'rgba(239,68,68,0.15)', border: 'rgba(239,68,68,0.3)' },
    { accent: '#8B5CF6', glow: 'rgba(139,92,246,0.15)', border: 'rgba(139,92,246,0.3)' },
    { accent: '#06B6D4', glow: 'rgba(6,182,212,0.15)', border: 'rgba(6,182,212,0.3)' },
    { accent: '#10B981', glow: 'rgba(16,185,129,0.15)', border: 'rgba(16,185,129,0.3)' },
    { accent: '#F59E0B', glow: 'rgba(245,158,11,0.15)', border: 'rgba(245,158,11,0.3)' },
    { accent: '#EC4899', glow: 'rgba(236,72,153,0.15)', border: 'rgba(236,72,153,0.3)' },
];

const getColor = (idx) => CLUSTER_COLORS[idx % CLUSTER_COLORS.length];

// ─── Profile Card ─────────────────────────────────────────────────────────────
const ProfileCard = ({ profile, accent, onView }) => {
    const [hovered, setHovered] = useState(false);
    const skills = Array.isArray(profile.technical_skills)
        ? profile.technical_skills.slice(0, 4)
        : typeof profile.technical_skills === 'string'
            ? profile.technical_skills.split(',').slice(0, 4).map(s => s.trim())
            : [];

    return (
        <motion.div
            onMouseEnter={() => setHovered(true)}
            onMouseLeave={() => setHovered(false)}
            whileHover={{ y: -4, scale: 1.01 }}
            onClick={() => onView(profile)}
            style={{
                backgroundColor: hovered ? 'rgba(255,255,255,0.06)' : 'rgba(255,255,255,0.03)',
                border: `1px solid ${hovered ? accent : 'rgba(255,255,255,0.08)'}`,
                borderRadius: '12px',
                padding: '1rem',
                cursor: 'pointer',
                transition: 'border-color 0.2s',
                boxShadow: hovered ? `0 4px 20px ${accent}30` : 'none',
            }}
        >
            <div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem', marginBottom: '0.6rem' }}>
                <img
                    src={profile.avatar_url || `https://ui-avatars.com/api/?name=${encodeURIComponent(profile.full_name || 'User')}&background=random&size=48`}
                    alt={profile.full_name}
                    style={{ width: 40, height: 40, borderRadius: '50%', objectFit: 'cover', border: `2px solid ${accent}55` }}
                />
                <div>
                    <p style={{ fontWeight: '700', color: '#fff', fontSize: '0.9rem', marginBottom: 2 }}>{profile.full_name || 'Unknown'}</p>
                    <p style={{ fontSize: '0.75rem', color: '#94a3b8' }}>{profile.headline || profile.role || 'β€”'}</p>
                </div>
            </div>

            <p style={{ fontSize: '0.75rem', color: '#64748b', marginBottom: '0.5rem' }}>
                {profile.experience_years ? `${profile.experience_years} yrs exp` : 'No experience listed'}
            </p>

            {skills.length > 0 && (
                <div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.3rem' }}>
                    {skills.map((s, i) => (
                        <span key={i} style={{
                            fontSize: '0.7rem', padding: '2px 8px', borderRadius: '4px',
                            backgroundColor: `${accent}20`, color: accent,
                            border: `1px solid ${accent}40`
                        }}>{s}</span>
                    ))}
                </div>
            )}
        </motion.div>
    );
};

// ─── Cluster Card ─────────────────────────────────────────────────────────────
const ClusterCard = ({ label, profiles, colorIdx, searchQuery, onViewProfile }) => {
    const [expanded, setExpanded] = useState(true);
    const color = getColor(colorIdx);

    const filtered = profiles.filter(p => {
        const q = searchQuery.toLowerCase();
        return (
            (p.full_name || '').toLowerCase().includes(q) ||
            (p.headline || '').toLowerCase().includes(q) ||
            (p.role || '').toLowerCase().includes(q)
        );
    });

    if (searchQuery && filtered.length === 0) return null;

    return (
        <motion.div
            initial={{ opacity: 0, y: 20 }}
            animate={{ opacity: 1, y: 0 }}
            style={{
                backgroundColor: color.glow,
                border: `1px solid ${color.border}`,
                borderRadius: '16px',
                overflow: 'hidden',
                marginBottom: '1.5rem',
            }}
        >
            {/* Header */}
            <button
                onClick={() => setExpanded(e => !e)}
                style={{
                    width: '100%', background: 'none', border: 'none', cursor: 'pointer',
                    padding: '1.25rem 1.5rem',
                    display: 'flex', alignItems: 'center', justifyContent: 'space-between',
                    color: '#fff',
                }}
            >
                <div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem' }}>
                    <div style={{
                        width: 36, height: 36, borderRadius: '10px',
                        backgroundColor: `${color.accent}22`, display: 'flex', alignItems: 'center', justifyContent: 'center',
                        border: `1px solid ${color.accent}55`
                    }}>
                        <ClusterIcon style={{ color: color.accent }} />
                    </div>
                    <div style={{ textAlign: 'left' }}>
                        <h3 style={{ fontSize: '1.05rem', fontWeight: '700', color: '#fff', margin: 0 }}>{label}</h3>
                        <div style={{ display: 'flex', alignItems: 'center', gap: '4px', color: '#94a3b8', fontSize: '0.8rem', marginTop: 2 }}>
                            <UsersIcon />
                            <span>{filtered.length} {filtered.length === 1 ? 'profile' : 'profiles'}</span>
                        </div>
                    </div>
                </div>
                <div style={{ color: color.accent }}>
                    <ChevronDown open={expanded} />
                </div>
            </button>

            {/* Body */}
            <AnimatePresence initial={false}>
                {expanded && (
                    <motion.div
                        key="body"
                        initial={{ height: 0, opacity: 0 }}
                        animate={{ height: 'auto', opacity: 1 }}
                        exit={{ height: 0, opacity: 0 }}
                        transition={{ duration: 0.3 }}
                        style={{ overflow: 'hidden' }}
                    >
                        <div style={{
                            padding: '0 1.5rem 1.5rem',
                            display: 'grid',
                            gridTemplateColumns: 'repeat(auto-fill, minmax(220px, 1fr))',
                            gap: '0.75rem'
                        }}>
                            {filtered.map(p => (
                                <ProfileCard
                                    key={p.id}
                                    profile={p}
                                    accent={color.accent}
                                    onView={onViewProfile}
                                />
                            ))}
                        </div>
                    </motion.div>
                )}
            </AnimatePresence>
        </motion.div>
    );
};

// ─── Profile Detail Modal ─────────────────────────────────────────────────────
const ProfileModal = ({ profile, onClose }) => {
    if (!profile) return null;
    const skills = Array.isArray(profile.technical_skills)
        ? profile.technical_skills
        : typeof profile.technical_skills === 'string'
            ? profile.technical_skills.split(',').map(s => s.trim())
            : [];

    return (
        <AnimatePresence>
            <motion.div
                initial={{ opacity: 0 }}
                animate={{ opacity: 1 }}
                exit={{ opacity: 0 }}
                onClick={onClose}
                style={{
                    position: 'fixed', inset: 0, backgroundColor: 'rgba(0,0,0,0.7)',
                    backdropFilter: 'blur(6px)', zIndex: 100, display: 'flex',
                    alignItems: 'center', justifyContent: 'center', padding: '1rem'
                }}
            >
                <motion.div
                    initial={{ scale: 0.9, opacity: 0 }}
                    animate={{ scale: 1, opacity: 1 }}
                    exit={{ scale: 0.9, opacity: 0 }}
                    onClick={e => e.stopPropagation()}
                    style={{
                        backgroundColor: '#0f172a',
                        backgroundImage: `
                            radial-gradient(at 0% 0%, rgba(139,92,246,0.2) 0px, transparent 50%),
                            radial-gradient(at 100% 100%, rgba(239,68,68,0.2) 0px, transparent 50%)
                        `,
                        border: '1px solid rgba(255,255,255,0.1)',
                        borderRadius: '20px',
                        width: '100%', maxWidth: '540px',
                        maxHeight: '80vh', overflowY: 'auto',
                        boxShadow: '0 25px 50px rgba(0,0,0,0.5)',
                        padding: '2rem',
                    }}
                >
                    {/* Close */}
                    <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '1.5rem' }}>
                        <div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>
                            <img
                                src={profile.avatar_url || `https://ui-avatars.com/api/?name=${encodeURIComponent(profile.full_name || 'User')}&background=random&size=80`}
                                alt={profile.full_name}
                                style={{ width: 56, height: 56, borderRadius: '50%', objectFit: 'cover', border: '2px solid rgba(239,68,68,0.4)' }}
                            />
                            <div>
                                <h2 style={{ fontSize: '1.4rem', fontWeight: '800', color: '#fff', margin: 0 }}>{profile.full_name}</h2>
                                <p style={{ color: '#94a3b8', fontSize: '0.85rem', margin: 0 }}>{profile.headline || profile.role || 'β€”'}</p>
                            </div>
                        </div>
                        <button onClick={onClose} style={{ background: 'none', border: 'none', color: '#64748b', cursor: 'pointer' }}>
                            <XIcon />
                        </button>
                    </div>

                    {/* Stats Row */}
                    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: '0.75rem', marginBottom: '1.5rem' }}>
                        {[
                            { label: 'Experience', value: profile.experience_years ? `${profile.experience_years} yrs` : 'β€”' },
                            { label: 'Cluster', value: profile.cluster_label || 'β€”' },
                            { label: 'Email', value: profile.email ? profile.email.split('@')[0] : 'β€”' },
                        ].map(({ label, value }) => (
                            <div key={label} style={{
                                backgroundColor: 'rgba(255,255,255,0.05)', borderRadius: '10px',
                                padding: '0.75rem', border: '1px solid rgba(255,255,255,0.08)'
                            }}>
                                <p style={{ fontSize: '0.7rem', color: '#64748b', textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 4 }}>{label}</p>
                                <p style={{ fontSize: '0.85rem', fontWeight: '600', color: '#e2e8f0', wordBreak: 'break-all' }}>{value}</p>
                            </div>
                        ))}
                    </div>

                    {/* Summary */}
                    {profile.summary && (
                        <div style={{ marginBottom: '1.5rem' }}>
                            <h4 style={{ fontSize: '0.85rem', color: '#94a3b8', fontWeight: '600', marginBottom: '0.5rem', textTransform: 'uppercase', letterSpacing: '0.05em' }}>Summary</h4>
                            <p style={{ fontSize: '0.9rem', lineHeight: '1.6', color: '#cbd5e1', backgroundColor: 'rgba(255,255,255,0.04)', padding: '0.75rem', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.05)' }}>
                                {profile.summary}
                            </p>
                        </div>
                    )}

                    {/* Skills */}
                    {skills.length > 0 && (
                        <div style={{ marginBottom: '1.5rem' }}>
                            <h4 style={{ fontSize: '0.85rem', color: '#94a3b8', fontWeight: '600', marginBottom: '0.5rem', textTransform: 'uppercase', letterSpacing: '0.05em' }}>Technical Skills</h4>
                            <div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.4rem' }}>
                                {skills.map((s, i) => (
                                    <span key={i} style={{
                                        fontSize: '0.8rem', padding: '4px 10px', borderRadius: '6px',
                                        backgroundColor: 'rgba(239,68,68,0.1)', color: '#EF4444',
                                        border: '1px solid rgba(239,68,68,0.2)'
                                    }}>{s}</span>
                                ))}
                            </div>
                        </div>
                    )}

                    {/* Education */}
                    {profile.education && (
                        <div>
                            <h4 style={{ fontSize: '0.85rem', color: '#94a3b8', fontWeight: '600', marginBottom: '0.5rem', textTransform: 'uppercase', letterSpacing: '0.05em' }}>Education</h4>
                            <p style={{ fontSize: '0.85rem', color: '#cbd5e1' }}>
                                {typeof profile.education === 'string' ? profile.education : JSON.stringify(profile.education)}
                            </p>
                        </div>
                    )}
                </motion.div>
            </motion.div>
        </AnimatePresence>
    );
};

// ─── MAIN PAGE ────────────────────────────────────────────────────────────────
export default function TalentClusters() {
    const [clusters, setClusters] = useState({});       // { labelName: [profiles] }
    const [isLoading, setIsLoading] = useState(true);
    const [searchQuery, setSearchQuery] = useState('');
    const [selectedProfile, setSelectedProfile] = useState(null);
    const [error, setError] = useState(null);
    const [isClusteringRunning, setIsClusteringRunning] = useState(false);

    useEffect(() => {
        fetchClusters();
    }, []);

    const fetchClusters = async () => {
        setIsLoading(true);
        setError(null);
        try {
            const { data, error } = await supabase
                .from('profiles')
                .select('id, full_name, email, avatar_url, headline, role, experience_years, technical_skills, summary, education, cluster_label')
                .not('cluster_label', 'is', null);

            if (error) throw error;

            // Group by cluster_label
            const grouped = {};
            data.forEach(profile => {
                const label = profile.cluster_label || 'Uncategorized';
                if (!grouped[label]) grouped[label] = [];
                grouped[label].push(profile);
            });

            setClusters(grouped);
        } catch (err) {
            console.error('Failed to fetch clusters:', err);
            setError('Failed to load talent clusters. Please try again.');
        } finally {
            setIsLoading(false);
        }
    };

    const runClustering = async () => {
        setIsClusteringRunning(true);
        try {
            const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000';
            const response = await fetch(`${API_URL}/run-clustering`, {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' }
            });

            if (!response.ok) {
                throw new Error('Failed to start clustering');
            }

            const data = await response.json();
            console.log('βœ… Clustering started:', data);
            alert('Clustering pipeline started! This may take a few minutes. You will be notified when complete.');

            // Poll for completion (check every 5 seconds for up to 5 minutes)
            const pollInterval = setInterval(async () => {
                try {
                    await fetchClusters();
                    // If we get here and setClusters worked, clustering likely complete
                    // Check if there are actually clusters now
                    const { data: profiles } = await supabase
                        .from('profiles')
                        .select('cluster_label')
                        .not('cluster_label', 'is', null)
                        .limit(1);

                    if (profiles && profiles.length > 0) {
                        clearInterval(pollInterval);
                        setIsClusteringRunning(false);
                        alert('βœ… Clustering complete! Clusters loaded.');
                    }
                } catch (err) {
                    console.log('Still clustering...');
                }
            }, 5000);

            // Clear interval after 5 minutes
            setTimeout(() => clearInterval(pollInterval), 5 * 60 * 1000);

        } catch (err) {
            console.error('Error starting clustering:', err);
            alert('Failed to start clustering. Check the backend logs.');
            setIsClusteringRunning(false);
        }
    };

    const clusterEntries = Object.entries(clusters).sort((a, b) => b[1].length - a[1].length);
    const totalProfiles = Object.values(clusters).reduce((s, arr) => s + arr.length, 0);

    return (
        <div style={{ paddingBottom: '4rem' }}>
            <style>{`
                .hide-scrollbar::-webkit-scrollbar { display: none; }
                .hide-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
                @keyframes spin { 100% { transform: rotate(360deg); } }
                @keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
            `}</style>

            {/* Header */}
            <header style={{ marginBottom: '2rem' }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem', marginBottom: '0.5rem' }}>
                    <div style={{ color: '#EF4444' }}><ClusterIcon /></div>
                    <h1 style={{ fontSize: '1.875rem', fontWeight: 'bold', margin: 0 }}>Talent Clusters</h1>
                </div>
                <p style={{ color: '#64748b', fontSize: '0.9rem' }}>
                    AI-grouped candidate profiles based on skills and experience similarity.
                </p>
            </header>

            {/* Stats Bar */}
            <div style={{ display: 'flex', gap: '1rem', marginBottom: '2rem', flexWrap: 'wrap' }}>
                {[
                    { label: 'Total Clusters', value: clusterEntries.length, color: '#EF4444' },
                    { label: 'Total Profiles', value: totalProfiles, color: '#8B5CF6' },
                    { label: 'Avg. Cluster Size', value: clusterEntries.length ? Math.round(totalProfiles / clusterEntries.length) : 0, color: '#06B6D4' },
                ].map(({ label, value, color }) => (
                    <div key={label} style={{
                        flex: 1, minWidth: 140,
                        backgroundColor: 'rgba(255,255,255,0.03)',
                        border: '1px solid rgba(255,255,255,0.08)',
                        borderRadius: '12px', padding: '1rem 1.25rem',
                    }}>
                        <p style={{ fontSize: '0.75rem', color: '#64748b', textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 4 }}>{label}</p>
                        <p style={{ fontSize: '1.8rem', fontWeight: '800', color, margin: 0, lineHeight: 1 }}>{isLoading ? 'β€”' : value}</p>
                    </div>
                ))}
            </div>

            {/* Search + Refresh */}
            <div style={{ display: 'flex', gap: '0.75rem', marginBottom: '2rem', alignItems: 'center' }}>
                <div style={{ position: 'relative', flexGrow: 1 }}>
                    <div style={{ position: 'absolute', left: 12, top: '50%', transform: 'translateY(-50%)', color: '#64748b' }}>
                        <SearchIcon />
                    </div>
                    <input
                        type="text"
                        placeholder="Search by name, role, or headline..."
                        value={searchQuery}
                        onChange={e => setSearchQuery(e.target.value)}
                        style={{
                            width: '100%', padding: '0.75rem 0.75rem 0.75rem 2.25rem',
                            borderRadius: '0.5rem', border: '1px solid rgba(239,68,68,0.3)',
                            backgroundColor: 'rgba(255,255,255,0.04)', color: 'white',
                            fontSize: '0.9rem', outline: 'none', boxSizing: 'border-box'
                        }}
                    />
                </div>
                <motion.button
                    onClick={runClustering}
                    disabled={isClusteringRunning}
                    whileHover={!isClusteringRunning ? { scale: 1.04 } : {}}
                    whileTap={!isClusteringRunning ? { scale: 0.96 } : {}}
                    style={{
                        backgroundColor: isClusteringRunning ? 'rgba(139,92,246,0.15)' : 'rgba(139,92,246,0.15)',
                        border: '1px solid rgba(139,92,246,0.4)',
                        color: isClusteringRunning ? '#94a3b8' : '#8B5CF6',
                        padding: '0.75rem 1.25rem',
                        borderRadius: '0.5rem',
                        cursor: isClusteringRunning ? 'not-allowed' : 'pointer',
                        fontWeight: '600',
                        fontSize: '0.85rem',
                        whiteSpace: 'nowrap',
                        opacity: isClusteringRunning ? 0.6 : 1,
                        transition: 'all 0.2s ease'
                    }}
                >
                    {isClusteringRunning ? '⟳ Clustering...' : '⚑ Run Clustering'}
                </motion.button>
            </div>

            {/* Content */}
            {isLoading ? (
                <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', height: '300px', gap: '1rem' }}>
                    <div style={{
                        width: 40, height: 40, border: '3px solid rgba(239,68,68,0.2)',
                        borderTopColor: '#EF4444', borderRadius: '50%',
                        animation: 'spin 0.8s linear infinite'
                    }} />
                    <p style={{ color: '#64748b' }}>Loading talent clusters…</p>
                </div>
            ) : error ? (
                <div style={{ textAlign: 'center', padding: '3rem', color: '#EF4444' }}>
                    <p>{error}</p>
                    <button onClick={fetchClusters} style={{ marginTop: '1rem', backgroundColor: '#EF4444', color: 'white', border: 'none', padding: '0.5rem 1.5rem', borderRadius: '6px', cursor: 'pointer', fontWeight: '600' }}>
                        Retry
                    </button>
                </div>
            ) : clusterEntries.length === 0 ? (
                <div style={{ textAlign: 'center', padding: '4rem', color: '#64748b' }}>
                    <ClusterIcon />
                    <p style={{ marginTop: '1rem' }}>No clusters found. Run the clustering pipeline first.</p>
                </div>
            ) : (
                <>
                    {/* Cluster grid legend */}
                    <div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.5rem', marginBottom: '1.5rem' }}>
                        {clusterEntries.map(([label, profiles], idx) => {
                            const color = getColor(idx);
                            return (
                                <span key={label} style={{
                                    fontSize: '0.78rem', padding: '4px 12px', borderRadius: '99px',
                                    backgroundColor: `${color.accent}18`, color: color.accent,
                                    border: `1px solid ${color.accent}44`, fontWeight: '600'
                                }}>
                                    {label} ({profiles.length})
                                </span>
                            );
                        })}
                    </div>

                    {/* Cluster cards */}
                    {clusterEntries.map(([label, profiles], idx) => (
                        <ClusterCard
                            key={label}
                            label={label}
                            profiles={profiles}
                            colorIdx={idx}
                            searchQuery={searchQuery}
                            onViewProfile={setSelectedProfile}
                        />
                    ))}
                </>
            )}

            {/* Profile modal */}
            <AnimatePresence>
                {selectedProfile && (
                    <ProfileModal profile={selectedProfile} onClose={() => setSelectedProfile(null)} />
                )}
            </AnimatePresence>
        </div>
    );
}