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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Participants - Quantals Collect</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/ag-grid-community/dist/ag-grid-community.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ag-grid-community/styles/ag-grid.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ag-grid-community/styles/ag-theme-alpine.css">
    <style>
        /* Custom styles */
        .participant-card {
            transition: transform 0.2s ease-in-out;
            min-width: 300px;
        }
        .participant-card:hover {
            transform: translateY(-2px);
        }
        .status-badge {
            padding: 0.25rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.75rem;
            font-weight: 500;
        }
        .status-consented {
            background-color: #dcfce7;
            color: #166534;
        }
        .status-withdrawn {
            background-color: #fee2e2;
            color: #991b1b;
        }
        .status-pending {
            background-color: #fef3c7;
            color: #92400e;
        }
        .tag {
            padding: 0.25rem 0.5rem;
            border-radius: 0.375rem;
            font-size: 0.75rem;
            background-color: #e5e7eb;
            color: #374151;
        }
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 50;
        }
        .modal.active {
            display: flex;
        }
        .timeline-item {
            position: relative;
            padding-left: 2rem;
        }
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 2px;
            background: #e5e7eb;
        }
        .timeline-dot {
            position: absolute;
            left: -4px;
            top: 0;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #3b82f6;
        }
        @keyframes slideUp {
            from { transform: translateY(20px); opacity: 0; }
            to { transform: translateY(0); opacity: 1; }
        }
        .slide-up {
            animation: slideUp 0.3s ease-out;
        }
        @keyframes statusPulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.1); }
            100% { transform: scale(1); }
        }
        .status-pulse {
            animation: statusPulse 0.3s ease-out 3;
        }
        .consent-preview {
            transition: transform 0.2s ease-out;
        }
        .consent-preview:hover {
            transform: scale(1.05);
        }

        /* New Action Button Styles */
        :root {
            --bg-primary: #ffffff;
            --border-color: #e5e7eb;
            --button-hover: #f3f4f6;
            --button-active: #e5e7eb;
            --button-text: #374151;
            --button-icon: #6b7280;
        }

        .participant-actions {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(min(90px, 100%), 1fr));
            gap: 0.5rem;
            padding: 0.75rem;
            background: var(--bg-primary);
            position: sticky;
            bottom: 0;
            border-top: 1px solid var(--border-color);
            min-height: 44px;
            align-items: center;
        }

        .action-button {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            padding: 0.5rem;
            border-radius: 0.375rem;
            background: transparent;
            color: var(--button-text);
            border: 1px solid var(--border-color);
            min-height: 44px;
            transition: all 0.15s ease-in-out;
            cursor: pointer;
        }

        .action-button:hover {
            background: var(--button-hover);
        }

        .action-button:active {
            background: var(--button-active);
        }

        .action-button:focus {
            outline: 2px solid #3b82f6;
            outline-offset: 2px;
        }

        .action-button svg {
            width: 1.25rem;
            height: 1.25rem;
            color: var(--button-icon);
        }

        /* Container Queries */
        @container (min-width: 600px) {
            .action-button {
                flex-direction: row;
            }
        }

        @container (max-width: 599px) {
            .action-button {
                flex-direction: column;
                width: 100%;
            }
            .action-button span {
                display: none;
            }
        }

        /* High Contrast Mode */
        @media (forced-colors: active) {
            .action-button {
                border: 2px solid CanvasText;
            }
            .action-button:focus {
                outline: 2px solid CanvasText;
            }
        }

        /* Tooltip Styles */
        .tooltip {
            position: relative;
        }

        .tooltip::after {
            content: attr(data-tooltip);
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            padding: 0.25rem 0.5rem;
            background: #1f2937;
            color: white;
            border-radius: 0.25rem;
            font-size: 0.75rem;
            white-space: nowrap;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.15s ease-in-out;
        }

        .tooltip:hover::after {
            opacity: 1;
        }

        /* Edit Modal Styles */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 50;
        }

        .modal.active {
            display: flex;
        }

        /* Focus styles */
        .focus-visible:focus-visible {
            outline: 2px solid #3b82f6;
            outline-offset: 2px;
        }

        /* Toast styles */
        .toast {
            position: fixed;
            bottom: 1rem;
            right: 1rem;
            padding: 0.75rem 1rem;
            border-radius: 0.375rem;
            background-color: white;
            box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
            z-index: 50;
        }

        .toast-success {
            background-color: #dcfce7;
            color: #166534;
        }

        .toast-error {
            background-color: #fee2e2;
            color: #991b1b;
        }

        .toast-info {
            background-color: #e0f2fe;
            color: #075985;
        }
    </style>
</head>
<body class="bg-gray-50 font-sans">
    <div class="flex h-screen overflow-hidden">
        <!-- Sidebar -->
        <div class="sidebar bg-indigo-800 text-white w-64 flex flex-col">
            <div class="p-4 flex items-center space-x-3 border-b border-indigo-700">
                <div class="bg-white p-2 rounded-lg">
                    <i class="fas fa-microscope text-indigo-800 text-xl"></i>
                </div>
                <h1 class="text-xl font-bold">Quantals Collect</h1>
            </div>
            
            <nav class="flex-1 p-4 space-y-2">
                <a href="index.html" class="flex items-center space-x-3 p-2 rounded-lg text-indigo-200 hover:bg-indigo-700 hover:text-white">
                    <i class="fas fa-home"></i>
                    <span>Dashboard</span>
                </a>
                <a href="projects.html" class="flex items-center space-x-3 p-2 rounded-lg text-indigo-200 hover:bg-indigo-700 hover:text-white">
                    <i class="fas fa-project-diagram"></i>
                    <span>Projects</span>
                </a>
                <a href="participants.html" class="flex items-center space-x-3 p-2 rounded-lg bg-indigo-700 text-white">
                    <i class="fas fa-users"></i>
                    <span>Participants</span>
                </a>
                <a href="interviews.html" class="flex items-center space-x-3 p-2 rounded-lg text-indigo-200 hover:bg-indigo-700 hover:text-white">
                    <i class="fas fa-microphone"></i>
                    <span>Interviews</span>
                </a>
                <a href="notes.html" class="flex items-center space-x-3 p-2 rounded-lg text-indigo-200 hover:bg-indigo-700 hover:text-white">
                    <i class="fas fa-sticky-note"></i>
                    <span>Notes</span>
                </a>
                <a href="analysis.html" class="flex items-center space-x-3 p-2 rounded-lg text-indigo-200 hover:bg-indigo-700 hover:text-white">
                    <i class="fas fa-chart-pie"></i>
                    <span>Analysis</span>
                </a>
                <a href="ai-assist.html" class="flex items-center space-x-3 p-2 rounded-lg text-indigo-200 hover:bg-indigo-700 hover:text-white">
                    <i class="fas fa-robot"></i>
                    <span>AI Assist</span>
                </a>
                <a href="transcriber.html" class="flex items-center space-x-3 p-2 rounded-lg text-indigo-200 hover:bg-indigo-700 hover:text-white">
                    <i class="fas fa-keyboard"></i>
                    <span>Transcriber</span>
                </a>
            </nav>
            
            <div class="p-4 border-t border-indigo-700">
                <a href="settings.html" class="flex items-center space-x-3 p-2 rounded-lg text-indigo-200 hover:bg-indigo-700 hover:text-white">
                    <i class="fas fa-cog"></i>
                    <span>Settings</span>
                </a>
            </div>
        </div>

        <!-- Main Content -->
        <div class="flex-1 flex flex-col overflow-hidden">
            <!-- Header -->
            <header class="bg-white shadow-sm p-4 flex justify-between items-center">
                <div class="flex items-center space-x-4">
                    <h2 class="text-xl font-semibold text-gray-800">Participants</h2>
                    <div class="offline-indicator hidden px-3 py-1 bg-yellow-100 text-yellow-800 rounded-full text-sm">
                        <i class="fas fa-wifi-slash mr-1"></i> Offline
                    </div>
                </div>
                <div class="flex items-center space-x-4">
                    <button class="p-2 rounded-full hover:bg-gray-100 relative">
                        <i class="fas fa-bell text-gray-600"></i>
                        <span class="absolute top-0 right-0 w-2 h-2 bg-red-500 rounded-full"></span>
                    </button>
                    <div class="flex items-center space-x-2">
                        <div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center">
                            <span class="text-xs font-medium text-indigo-800">RS</span>
                        </div>
                        <span class="text-sm">Research Team</span>
                    </div>
                </div>
            </header>

            <!-- Main Content Area -->
            <main class="flex-1 overflow-y-auto p-6">
                <div class="max-w-7xl mx-auto">
                    <!-- Sticky Toolbar -->
                    <div class="sticky top-0 bg-white p-4 rounded-lg shadow-sm mb-6 z-10">
                        <div class="flex justify-between items-center">
                            <div class="flex space-x-4 flex-1">
                                <div class="relative flex-1 max-w-md">
                                    <input type="text" placeholder="Search participants..." class="w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent">
                                    <i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
                                </div>
                                <button class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors flex items-center space-x-2" onclick="openNewParticipantModal()">
                                    <i class="fas fa-user-plus"></i>
                                    <span>Add Participant</span>
                                </button>
                            </div>
                            <div class="flex space-x-2">
                                <button class="p-2 rounded-lg hover:bg-gray-100" onclick="toggleView()" title="Toggle View">
                                    <i class="fas fa-th-large text-gray-600"></i>
                                </button>
                                <button class="px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-50 flex items-center space-x-2">
                                    <i class="fas fa-download"></i>
                                    <span>Export CSV</span>
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- Card View -->
                    <div id="cardView" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                        <!-- Participant Card Template -->
                        <div class="participant-card bg-white rounded-lg shadow-sm p-6 slide-up">
                            <div class="flex justify-between items-start mb-4">
                                <div class="flex items-center space-x-3">
                                    <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center">
                                        <span class="text-lg font-medium text-indigo-800">P-12</span>
                                    </div>
                                    <div>
                                        <h3 class="text-lg font-semibold text-gray-800">Participant #12</h3>
                                        <p class="text-sm text-gray-500">Enrolled: Jan 15, 2024</p>
                                    </div>
                                </div>
                                <span class="status-badge status-consented">Consented</span>
                            </div>
                            
                            <div class="space-y-4">
                                <div>
                                    <h4 class="text-sm font-medium text-gray-700 mb-2">Demographics</h4>
                                    <div class="grid grid-cols-2 gap-2 text-sm">
                                        <div>
                                            <span class="text-gray-500">Age:</span>
                                            <span class="text-gray-800">32</span>
                                        </div>
                                        <div>
                                            <span class="text-gray-500">Gender:</span>
                                            <span class="text-gray-800">Female</span>
                                        </div>
                                        <div>
                                            <span class="text-gray-500">Language:</span>
                                            <span class="text-gray-800">English (Native)</span>
                                        </div>
                                    </div>
                                </div>

                                <div>
                                    <h4 class="text-sm font-medium text-gray-700 mb-2">Activity</h4>
                                    <div class="flex items-center space-x-4 text-sm">
                                        <div>
                                            <span class="text-gray-500">Interviews:</span>
                                            <span class="text-gray-800">3</span>
                                        </div>
                                        <div>
                                            <span class="text-gray-500">Last Session:</span>
                                            <span class="text-gray-800">Feb 1, 2024</span>
                                        </div>
                                    </div>
                                </div>

                                <div>
                                    <h4 class="text-sm font-medium text-gray-700 mb-2">Tags</h4>
                                    <div class="flex flex-wrap gap-2">
                                        <span class="tag">High-frequency user</span>
                                        <span class="tag">Urban</span>
                                        <span class="tag">Tech-savvy</span>
                                    </div>
                                </div>
                            </div>

                            <div class="participant-actions">
                                <button 
                                    class="action-button tooltip" 
                                    onclick="handleEdit('P-12')"
                                    data-tooltip="Edit participant"
                                    aria-label="Edit participant">
                                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                        <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
                                        <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
                                    </svg>
                                    <span>Edit</span>
                                </button>
                                <button 
                                    class="action-button tooltip" 
                                    onclick="handleNewSession('P-12')"
                                    data-tooltip="Create new session"
                                    aria-label="Create new session">
                                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                        <path d="M12 5v14M5 12h14"></path>
                                    </svg>
                                    <span>New Session</span>
                                </button>
                                <button 
                                    class="action-button tooltip" 
                                    onclick="handleConsent('P-12')"
                                    data-tooltip="Manage consent forms"
                                    aria-label="Manage consent forms">
                                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                        <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
                                        <path d="M14 2v6h6"></path>
                                        <path d="M16 13H8"></path>
                                        <path d="M16 17H8"></path>
                                        <path d="M10 9H8"></path>
                                    </svg>
                                    <span>Consent</span>
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- Table View (Hidden by default) -->
                    <div id="tableView" class="hidden">
                        <div id="participantsGrid" class="ag-theme-alpine" style="height: 600px;"></div>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <!-- New Participant Modal -->
    <div id="newParticipantModal" class="modal">
        <div class="bg-white rounded-lg shadow-xl max-w-2xl w-full mx-auto my-8">
            <div class="p-6">
                <div class="flex justify-between items-center mb-4">
                    <h3 class="text-xl font-semibold text-gray-800">Add New Participant</h3>
                    <button onclick="closeNewParticipantModal()" class="text-gray-400 hover:text-gray-600">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
                <form class="space-y-4">
                    <!-- Identity Management -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Participant ID</label>
                        <input type="text" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500" value="P-13" readonly>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Contact Information (Optional)</label>
                        <input type="text" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500" placeholder="Encrypted storage">
                    </div>

                    <!-- Demographics -->
                    <div class="grid grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Age</label>
                            <input type="number" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Gender</label>
                            <select class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                                <option>Prefer not to say</option>
                                <option>Male</option>
                                <option>Female</option>
                                <option>Other</option>
                            </select>
                        </div>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Language Preference</label>
                        <select class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                            <option>English</option>
                            <option>Bemba</option>
                            <option>Nyanja</option>
                            <option>Tonga</option>
                            <option>Lozi</option>
                        </select>
                    </div>

                    <!-- Ethical Compliance -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Consent Status</label>
                        <div class="flex items-center space-x-4">
                            <label class="inline-flex items-center">
                                <input type="checkbox" class="form-checkbox text-indigo-600">
                                <span class="ml-2">Consent Obtained</span>
                            </label>
                            <button type="button" class="text-indigo-600 hover:text-indigo-700 text-sm">
                                <i class="fas fa-upload mr-1"></i>
                                Upload Consent Form
                            </button>
                        </div>
                    </div>

                    <!-- Custom Fields -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Custom Tags</label>
                        <input type="text" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500" placeholder="Add tags separated by commas">
                    </div>

                    <!-- Researcher Notes -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Researcher Notes (Private)</label>
                        <textarea class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500" rows="3"></textarea>
                    </div>

                    <div class="flex justify-end space-x-3">
                        <button type="button" onclick="closeNewParticipantModal()" class="px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-50">Cancel</button>
                        <button type="submit" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700">Add Participant</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Add Edit Modal Template -->
    <div id="editParticipantModal" class="modal" role="dialog" aria-labelledby="edit-participant-title">
        <div class="bg-white rounded-lg shadow-xl max-w-2xl w-full mx-auto my-8">
            <div class="p-6">
                <div class="flex justify-between items-center mb-4">
                    <h2 id="edit-participant-title" class="text-xl font-semibold text-gray-800">Edit Participant</h2>
                    <button onclick="closeEditModal()" class="text-gray-400 hover:text-gray-600" aria-label="Close modal">
                        <i class="fas fa-times"></i>
                    </button>
                </div>

                <!-- Live Region for Screen Readers -->
                <div aria-live="polite" class="sr-only">
                    Editing participant, tab to navigate fields
                </div>

                <form id="editParticipantForm" class="space-y-6" onsubmit="handleEditSubmit(event)">
                    <!-- Core Metadata Section -->
                    <div class="space-y-4">
                        <h3 class="text-lg font-medium text-gray-900">Core Metadata</h3>
                        <div class="grid grid-cols-2 gap-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700">Participant ID</label>
                                <input type="text" id="participantId" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm bg-gray-50" disabled>
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700">Status</label>
                                <select id="participantStatus" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" required>
                                    <option value="ACTIVE">Active</option>
                                    <option value="PENDING">Pending</option>
                                    <option value="WITHDRAWN">Withdrawn</option>
                                    <option value="ARCHIVED">Archived</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <!-- Demographics Section -->
                    <div class="space-y-4">
                        <h3 class="text-lg font-medium text-gray-900">Demographics</h3>
                        <div class="grid grid-cols-2 gap-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700">Age</label>
                                <input type="number" id="participantAge" min="18" max="120" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" required>
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700">Language</label>
                                <select id="participantLanguage" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" required>
                                    <option value="en">English</option>
                                    <option value="bem">Bemba</option>
                                    <option value="nya">Nyanja</option>
                                    <option value="ton">Tonga</option>
                                    <option value="loz">Lozi</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <!-- Contact Section -->
                    <div class="space-y-4">
                        <h3 class="text-lg font-medium text-gray-900">Contact Information</h3>
                        <div class="flex items-center space-x-2">
                            <input type="checkbox" id="showContact" class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">
                            <label for="showContact" class="text-sm text-gray-700">Show contact information</label>
                        </div>
                        <div id="contactFields" class="hidden space-y-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700">Email</label>
                                <input type="email" id="participantEmail" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500">
                            </div>
                        </div>
                    </div>

                    <!-- Custom Fields Section -->
                    <div class="space-y-4">
                        <h3 class="text-lg font-medium text-gray-900">Custom Fields</h3>
                        <div id="customFields" class="space-y-4">
                            <!-- Custom fields will be dynamically inserted here -->
                        </div>
                    </div>

                    <!-- Form Actions -->
                    <div class="flex justify-end space-x-3">
                        <button type="button" onclick="closeEditModal()" class="px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                            Cancel
                        </button>
                        <button type="submit" class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                            Save Changes
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        // View Toggle
        function toggleView() {
            const cardView = document.getElementById('cardView');
            const tableView = document.getElementById('tableView');
            const toggleButton = document.querySelector('[title="Toggle View"] i');
            
            if (cardView.classList.contains('hidden')) {
                cardView.classList.remove('hidden');
                tableView.classList.add('hidden');
                toggleButton.classList.remove('fa-list');
                toggleButton.classList.add('fa-th-large');
            } else {
                cardView.classList.add('hidden');
                tableView.classList.remove('hidden');
                toggleButton.classList.remove('fa-th-large');
                toggleButton.classList.add('fa-list');
                initGrid();
            }
        }

        // AG Grid Initialization
        function initGrid() {
            const gridDiv = document.querySelector('#participantsGrid');
            const gridOptions = {
                columnDefs: [
                    { field: 'id', headerName: 'ID', width: 100 },
                    { field: 'status', headerName: 'Status', width: 120 },
                    { field: 'enrollmentDate', headerName: 'Enrolled', width: 120 },
                    { field: 'age', headerName: 'Age', width: 80 },
                    { field: 'gender', headerName: 'Gender', width: 120 },
                    { field: 'language', headerName: 'Language', width: 150 },
                    { field: 'interviews', headerName: 'Interviews', width: 100 },
                    { field: 'lastSession', headerName: 'Last Session', width: 120 },
                    { field: 'tags', headerName: 'Tags', width: 200 }
                ],
                defaultColDef: {
                    sortable: true,
                    filter: true,
                    resizable: true
                },
                rowData: [
                    {
                        id: 'P-12',
                        status: 'Consented',
                        enrollmentDate: 'Jan 15, 2024',
                        age: 32,
                        gender: 'Female',
                        language: 'English (Native)',
                        interviews: 3,
                        lastSession: 'Feb 1, 2024',
                        tags: 'High-frequency user, Urban, Tech-savvy'
                    }
                    // Add more row data as needed
                ]
            };
            new agGrid.Grid(gridDiv, gridOptions);
        }

        // Modal Functions
        function openNewParticipantModal() {
            document.getElementById('newParticipantModal').classList.add('active');
        }

        function closeNewParticipantModal() {
            document.getElementById('newParticipantModal').classList.remove('active');
        }

        // Close modal when clicking outside
        window.onclick = function(event) {
            const modal = document.getElementById('newParticipantModal');
            if (event.target === modal) {
                closeNewParticipantModal();
            }
        }

        // Status Change Animation
        function animateStatusChange(element) {
            element.classList.add('status-pulse');
            setTimeout(() => {
                element.classList.remove('status-pulse');
            }, 1000);
        }

        // Add new button handler functions
        function handleEdit(participantId) {
            openEditModal(participantId);
        }

        function handleNewSession(participantId) {
            // Check consent status first
            const participant = fetchParticipant(participantId);
            if (!participant.hasValidConsent) {
                showError('Participant withdrew consent (Code: ETH-403)');
                return;
            }

            // Check for incomplete sessions
            const incompleteSessions = getIncompleteSessions(participantId);
            if (incompleteSessions.length >= 3) {
                if (!confirm('Participant has 3+ incomplete sessions. Continue?')) {
                    return;
                }
            }

            navigate(`/sessions/new?participant=${participantId}`, {
                state: { 
                    preset: getParticipantPreferences(participantId) 
                }
            });
        }

        function handleConsent(participantId) {
            openWizard({
                steps: [
                    { 
                        title: "Verify Identity", 
                        component: IdentityVerification 
                    },
                    {
                        title: "Consent Form",
                        component: ConsentManager,
                        props: {
                            versions: fetchConsentForms(participantId),
                            eSign: supportsDigitalSignature()
                        }
                    }
                ]
            });
        }

        // Utility functions
        function fetchParticipant(id) {
            // Implementation for fetching participant data
            return {
                id,
                hasValidConsent: true,
                // ... other participant data
            };
        }

        function getIncompleteSessions(participantId) {
            // Implementation for getting incomplete sessions
            return [];
        }

        function getParticipantPreferences(participantId) {
            // Implementation for getting participant preferences
            return {
                language: 'en',
                // ... other preferences
            };
        }

        function supportsDigitalSignature() {
            // Implementation for checking digital signature support
            return true;
        }

        function showError(message) {
            // Implementation for showing error messages
            alert(message);
        }

        // Container query setup
        document.querySelectorAll('.participant-card').forEach(card => {
            const container = document.createElement('div');
            container.style.containerType = 'inline-size';
            card.parentNode.insertBefore(container, card);
            container.appendChild(card);
        });

        // Edit Modal Functions
        let originalData = null;
        let editModal = null;

        function openEditModal(participantId) {
            const participant = fetchParticipant(participantId);
            
            // Check if participant is archived
            if (participant.status === 'ARCHIVED') {
                showToast('Archived participants cannot be edited');
                return;
            }

            // Store original data for diff comparison
            originalData = { ...participant };

            // Populate form fields
            document.getElementById('participantId').value = participant.id;
            document.getElementById('participantStatus').value = participant.status;
            document.getElementById('participantAge').value = participant.age;
            document.getElementById('participantLanguage').value = participant.language;

            // Handle contact information visibility
            const showContact = document.getElementById('showContact');
            const contactFields = document.getElementById('contactFields');
            if (hasPermission('VIEW_PII')) {
                showContact.checked = true;
                contactFields.classList.remove('hidden');
                document.getElementById('participantEmail').value = decrypt(participant.encryptedEmail);
            }

            // Populate custom fields
            populateCustomFields(participant.customFields);

            // Show modal
            editModal = document.getElementById('editParticipantModal');
            editModal.classList.add('active');
            
            // Focus trap
            focusTrap(editModal);
        }

        function closeEditModal() {
            if (editModal) {
                editModal.classList.remove('active');
                // Return focus to edit button
                document.querySelector(`[data-participant-id="${originalData.id}"]`).focus();
            }
        }

        async function handleEditSubmit(event) {
            event.preventDefault();
            
            const formData = new FormData(event.target);
            const editedData = Object.fromEntries(formData.entries());
            
            // Check for changes
            const changes = deepDiff(originalData, editedData);
            if (Object.keys(changes).length === 0) {
                closeEditModal();
                return;
            }

            // Ethical compliance check
            if (changes.status === 'WITHDRAWN') {
                const approved = await requireEthicalApproval('WITHDRAWAL');
                if (!approved) return;
            }

            try {
                // Save changes
                const response = await saveParticipantChanges(originalData.id, changes);
                
                // Update UI
                updateParticipantCard(response.data);
                showSuccessToast(`Participant ${originalData.id} updated`);
                
                // Log audit trail
                logAuditEvent('PARTICIPANT_EDIT', {
                    id: originalData.id,
                    changes: maskPII(changes)
                });

                closeEditModal();
            } catch (error) {
                handleEditError(error);
            }
        }

        // Utility Functions
        function deepDiff(original, edited) {
            const changes = {};
            for (const key in edited) {
                if (JSON.stringify(original[key]) !== JSON.stringify(edited[key])) {
                    changes[key] = edited[key];
                }
            }
            return changes;
        }

        function focusTrap(modal) {
            const focusableElements = modal.querySelectorAll(
                'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
            );
            const firstFocusable = focusableElements[0];
            const lastFocusable = focusableElements[focusableElements.length - 1];

            modal.addEventListener('keydown', (e) => {
                if (e.key === 'Tab') {
                    if (e.shiftKey) {
                        if (document.activeElement === firstFocusable) {
                            lastFocusable.focus();
                            e.preventDefault();
                        }
                    } else {
                        if (document.activeElement === lastFocusable) {
                            firstFocusable.focus();
                            e.preventDefault();
                        }
                    }
                }
            });

            firstFocusable.focus();
        }

        function showToast(message, type = 'info') {
            // Implementation for showing toast messages
            console.log(`${type.toUpperCase()}: ${message}`);
        }

        function showSuccessToast(message) {
            showToast(message, 'success');
        }

        function hasPermission(permission) {
            // Implementation for permission checking
            return true; // Placeholder
        }

        function decrypt(encrypted) {
            // Implementation for decryption
            return encrypted; // Placeholder
        }

        function maskPII(data) {
            // Implementation for masking PII in audit logs
            return data; // Placeholder
        }

        async function requireEthicalApproval(action) {
            // Implementation for ethical approval workflow
            return true; // Placeholder
        }

        async function saveParticipantChanges(id, changes) {
            // Implementation for saving changes
            return { data: { ...originalData, ...changes } }; // Placeholder
        }

        function updateParticipantCard(data) {
            // Implementation for updating the participant card in the UI
            console.log('Updating card with:', data);
        }

        function logAuditEvent(action, data) {
            // Implementation for audit logging
            console.log('Audit:', action, data);
        }

        function handleEditError(error) {
            if (error.status === 403) {
                showToast('Permission denied', 'error');
            } else if (error.status === 409) {
                showVersionConflictUI(error);
            } else if (isOffline()) {
                queueForSync(error.data);
                showToast('Changes queued for sync', 'info');
            } else {
                showToast('An error occurred', 'error');
            }
        }

        function populateCustomFields(fields) {
            const container = document.getElementById('customFields');
            container.innerHTML = ''; // Clear existing fields
            
            fields.forEach(field => {
                const fieldElement = createCustomFieldElement(field);
                container.appendChild(fieldElement);
            });
        }

        function createCustomFieldElement(field) {
            const div = document.createElement('div');
            div.className = 'space-y-1';
            
            const label = document.createElement('label');
            label.className = 'block text-sm font-medium text-gray-700';
            label.textContent = field.label;
            
            const input = document.createElement('input');
            input.type = field.type || 'text';
            input.name = field.name;
            input.value = field.value;
            input.className = 'mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500';
            
            if (field.required) input.required = true;
            if (field.pattern) input.pattern = field.pattern;
            
            div.appendChild(label);
            div.appendChild(input);
            
            return div;
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=dataquantals/quantals-collect-version-2" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>