File size: 64,769 Bytes
65830d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="theme-color" content="#6366f1">
    <meta name="description" content="Smart email summarization for busy professionals">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="apple-mobile-web-app-title" content="InboxDigest">
    <title>InboxDigest - Smart Email Summarization</title>
    
    <!-- PWA Manifest -->
    <link rel="manifest" href="/manifest.json">
    
    <!-- Favicons -->
    <link rel="icon" href="/favicon.ico" sizes="32x32">
    <link rel="apple-touch-icon" href="/icon-192.png">
    
    <!-- Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: {
                            50: '#f0f9ff',
                            100: '#e0f2fe',
                            200: '#bae6fd',
                            300: '#7dd3fc',
                            400: '#38bdf8',
                            500: '#0ea5e9',
                            600: '#0284c7',
                            700: '#0369a1',
                            800: '#075985',
                            900: '#0c4a6e',
                        }
                    }
                }
            }
        }
    </script>
    
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <style>
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .animate-fade-in {
            animation: fadeIn 0.3s ease-out forwards;
        }
        .gradient-bg {
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
        }
        .email-card:hover {
            transform: translateY(-3px);
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .summary-text {
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        .slide-in {
            animation: slideIn 0.3s ease-out forwards;
        }
        @keyframes slideIn {
            from { transform: translateX(100%); opacity: 0; }
            to { transform: translateX(0); opacity: 1; }
        }
        .progress-bar {
            height: 4px;
            background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 100%);
            width: 0%;
            transition: width 0.3s ease;
        }
        
        /* PWA specific styles */
        body {
            -webkit-tap-highlight-color: transparent;
            overscroll-behavior-y: none;
        }
        .pwa-install-btn {
            display: none;
        }
        @media (display-mode: standalone) {
            header {
                padding-top: env(safe-area-inset-top);
            }
            .pwa-install-btn {
                display: none !important;
            }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen font-sans antialiased">
    <!-- Install Prompt -->
    <div id="install-container" class="fixed bottom-0 left-0 right-0 bg-white shadow-lg rounded-t-xl p-4 z-50 hidden">
        <div class="flex items-center justify-between">
            <div class="flex items-center space-x-3">
                <div class="w-10 h-10 rounded-lg bg-indigo-100 flex items-center justify-center">
                    <i class="fas fa-download text-indigo-600"></i>
                </div>
                <div>
                    <h3 class="font-medium text-gray-800">Install InboxDigest</h3>
                    <p class="text-xs text-gray-500">Add to your home screen for faster access</p>
                </div>
            </div>
            <div class="flex space-x-2">
                <button id="cancel-install" class="px-4 py-2 text-gray-700 rounded-lg">Not Now</button>
                <button id="install-btn" class="px-4 py-2 bg-indigo-600 text-white rounded-lg">Install</button>
            </div>
        </div>
    </div>

    <!-- Main App Container -->
    <div class="flex flex-col min-h-screen">
        <!-- Loading Indicator -->
        <div id="loading-bar" class="progress-bar fixed top-0 left-0 right-0 z-50"></div>

        <!-- Header -->
        <header class="gradient-bg text-white shadow-lg">
            <div class="container mx-auto px-4 py-4">
                <div class="flex justify-between items-center">
                    <div class="flex items-center space-x-3">
                        <div class="w-10 h-10 rounded-lg bg-white/10 flex items-center justify-center">
                            <i class="fas fa-inbox text-xl"></i>
                        </div>
                        <h1 class="text-xl font-bold">InboxDigest</h1>
                    </div>
                    <div class="flex items-center space-x-4">
                        <button id="pwa-install-btn" class="pwa-install-btn p-2 rounded-full hover:bg-white/10 transition" title="Install">
                            <i class="fas fa-download"></i>
                        </button>
                        <button id="help-btn" class="p-2 rounded-full hover:bg-white/10 transition" title="Help">
                            <i class="fas fa-question-circle"></i>
                        </button>
                        <button id="settings-btn" class="p-2 rounded-full hover:bg-white/10 transition" title="Settings">
                            <i class="fas fa-cog"></i>
                        </button>
                        <div class="relative">
                            <button id="profile-btn" class="w-8 h-8 rounded-full bg-white/20 flex items-center justify-center">
                                <i class="fas fa-user"></i>
                            </button>
                            <div id="profile-dropdown" class="hidden absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg py-1 z-50">
                                <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">My Account</a>
                                <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Sign Out</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="mt-2 flex items-center justify-between">
                    <div class="text-sm opacity-90">
                        <span id="account-status">No accounts connected</span>
                    </div>
                    <button id="add-account-btn" class="text-xs bg-white/20 hover:bg-white/30 px-3 py-1 rounded-full transition flex items-center">
                        <i class="fas fa-plus mr-1"></i> Add Account
                    </button>
                </div>
            </div>
        </header>

        <!-- Main Content -->
        <main class="flex-grow container mx-auto px-4 py-6">
            <!-- Onboarding Screen (shown when no accounts connected) -->
            <div id="onboarding" class="max-w-2xl mx-auto">
                <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                    <div class="gradient-bg text-white p-6 text-center">
                        <i class="fas fa-inbox text-5xl mb-4"></i>
                        <h2 class="text-2xl font-bold mb-2">Welcome to InboxDigest</h2>
                        <p class="opacity-90">Your smart email assistant that summarizes and organizes your inbox</p>
                    </div>
                    <div class="p-6 md:p-8">
                        <div class="mb-8">
                            <h3 class="font-semibold text-gray-800 mb-4">How it works</h3>
                            <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                                <div class="bg-gray-50 rounded-lg p-4 text-center">
                                    <div class="w-12 h-12 bg-indigo-100 text-indigo-600 rounded-full flex items-center justify-center mx-auto mb-3">
                                        <i class="fas fa-plug"></i>
                                    </div>
                                    <h4 class="font-medium text-gray-800 mb-1">1. Connect</h4>
                                    <p class="text-sm text-gray-600">Securely link your email accounts</p>
                                </div>
                                <div class="bg-gray-50 rounded-lg p-4 text-center">
                                    <div class="w-12 h-12 bg-indigo-100 text-indigo-600 rounded-full flex items-center justify-center mx-auto mb-3">
                                        <i class="fas fa-robot"></i>
                                    </div>
                                    <h4 class="font-medium text-gray-800 mb-1">2. Analyze</h4>
                                    <p class="text-sm text-gray-600">We process and summarize your emails</p>
                                </div>
                                <div class="bg-gray-50 rounded-lg p-4 text-center">
                                    <div class="w-12 h-12 bg-indigo-100 text-indigo-600 rounded-full flex items-center justify-center mx-auto mb-3">
                                        <i class="fas fa-chart-line"></i>
                                    </div>
                                    <h4 class="font-medium text-gray-800 mb-1">3. Digest</h4>
                                    <p class="text-sm text-gray-600">Get concise daily summaries</p>
                                </div>
                            </div>
                        </div>
                        
                        <div class="space-y-4">
                            <button id="connect-gmail" class="w-full bg-red-500 hover:bg-red-600 text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center space-x-3 transition shadow-md">
                                <i class="fab fa-google text-xl"></i>
                                <span>Connect with Gmail</span>
                            </button>
                            
                            <button id="connect-outlook" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center space-x-3 transition shadow-md">
                                <i class="fab fa-microsoft text-xl"></i>
                                <span>Connect with Outlook</span>
                            </button>

                            <button id="connect-imap" class="w-full bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-3 px-6 rounded-lg flex items-center justify-center space-x-3 transition">
                                <i class="fas fa-server text-xl"></i>
                                <span>Advanced IMAP Setup</span>
                            </button>
                        </div>
                        
                        <div class="mt-8 pt-6 border-t border-gray-200 text-center">
                            <p class="text-xs text-gray-500">
                                <i class="fas fa-lock mr-1"></i> Your email credentials are never stored. We use secure OAuth connections.
                            </p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Digest View (hidden initially) -->
            <div id="digest-view" class="hidden">
                <!-- Digest Header -->
                <div class="flex flex-col md:flex-row md:items-center md:justify-between mb-6 gap-4">
                    <div>
                        <h2 class="text-2xl font-bold text-gray-800">Today's Digest</h2>
                        <div class="flex items-center space-x-2 mt-1">
                            <span class="text-sm text-gray-500">Generated at 8:00 AM</span>
                            <span class="text-xs bg-indigo-100 text-indigo-800 px-2 py-0.5 rounded-full">3 new</span>
                        </div>
                    </div>
                    <div class="flex space-x-3">
                        <div class="relative">
                            <button id="filter-btn" class="bg-white hover:bg-gray-50 text-gray-700 font-medium py-2 px-4 border border-gray-300 rounded-lg flex items-center space-x-2 transition">
                                <i class="fas fa-filter"></i>
                                <span>Filter</span>
                            </button>
                            <div id="filter-dropdown" class="hidden absolute right-0 mt-2 w-56 bg-white rounded-md shadow-lg py-1 z-50 border border-gray-200">
                                <div class="px-4 py-2 text-sm text-gray-700">Filter by:</div>
                                <div class="border-t border-gray-200"></div>
                                <label class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
                                    <input type="checkbox" class="mr-2" checked>
                                    <span>Important</span>
                                </label>
                                <label class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
                                    <input type="checkbox" class="mr-2" checked>
                                    <span>Unread</span>
                                </label>
                                <label class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
                                    <input type="checkbox" class="mr-2" checked>
                                    <span>Updates</span>
                                </label>
                                <div class="border-t border-gray-200"></div>
                                <button id="apply-filters" class="w-full text-left px-4 py-2 text-sm text-indigo-600 hover:bg-gray-100">
                                    Apply Filters
                                </button>
                            </div>
                        </div>
                        <button id="refresh-btn" class="bg-white hover:bg-gray-50 text-gray-700 font-medium py-2 px-4 border border-gray-300 rounded-lg flex items-center space-x-2 transition">
                            <i class="fas fa-sync-alt"></i>
                            <span>Refresh</span>
                        </button>
                    </div>
                </div>

                <!-- Priority Summary -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden mb-6">
                    <div class="bg-indigo-50 px-6 py-4 border-b border-indigo-100">
                        <div class="flex items-center">
                            <div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-3">
                                <i class="fas fa-exclamation"></i>
                            </div>
                            <h3 class="font-semibold text-gray-800">Priority Summary</h3>
                        </div>
                    </div>
                    <div class="p-6">
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                            <div class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition">
                                <div class="flex items-center mb-3">
                                    <div class="w-10 h-10 rounded-full bg-red-100 text-red-600 flex items-center justify-center mr-3">
                                        <i class="fas fa-calendar-times"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-medium text-gray-800">Urgent</h4>
                                        <p class="text-xs text-gray-500">Requires immediate action</p>
                                    </div>
                                </div>
                                <div class="space-y-3">
                                    <div class="flex items-start">
                                        <div class="w-2 h-2 rounded-full bg-red-500 mt-1.5 mr-2"></div>
                                        <p class="text-sm text-gray-700">Meeting cancellation from <span class="font-medium">John Smith</span></p>
                                    </div>
                                    <div class="flex items-start">
                                        <div class="w-2 h-2 rounded-full bg-red-500 mt=1.5 mr-2"></div>
                                        <p class="text-sm text-gray-700">Project deadline extension request</p>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition">
                                <div class="flex items-center mb-3">
                                    <div class="w-10 h-10 rounded-full bg-yellow-100 text-yellow-600 flex items-center justify-center mr=3">
                                        <i class="fas fa-clock"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-medium text-gray-800">Today</h4>
                                        <p class="text-xs text-gray=500">Action needed today</p>
                                    </div>
                                </div>
                                <div class="space-y-3">
                                    <div class="flex items-start">
                                        <div class="w-2 h-2 rounded-full bg-yellow-500 mt-1.5 mr-2"></div>
                                        <p class="text-sm text-gray-700">Team sync agenda from <span class="font-medium">Sarah</span></p>
                                    </div>
                                    <div class="flex items-start">
                                        <div class="w-2 h-2 rounded-full bg-yellow-500 mt-1.5 mr-2"></div>
                                        <p class="text-sm text-gray-700">Expense report approval</p>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition">
                                <div class="flex items-center mb-3">
                                    <div class="w-10 h-10 rounded-full bg-green-100 text-green-600 flex items-center justify-center mr-3">
                                        <i class="fas fa-calendar-week"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-medium text-gray-800">This Week</h4>
                                        <p class="text-xs text-gray-500">Upcoming deadlines</p>
                                    </div>
                                </div>
                                <div class="space-y-3">
                                    <div class="flex items-start">
                                        <div class="w=2 h-2 rounded-full bg-green-500 mt-1.5 mr-2"></div>
                                        <p class="text-sm text-gray-700">Quarterly planning session invite</p>
                                    </div>
                                    <div class="flex items-start">
                                        <div class="w-2 h-2 rounded-full bg-green-500 mt-1.5 mr-2"></div>
                                        <p class="text-sm text-gray-700">Performance review schedule</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Email Categories -->
                <div class="mb-8">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="text-lg font-semibold text-gray-800">Email Categories</h3>
                        <button id="view-all-btn" class="text-sm text-indigo-600 hover:text-indigo-800">View All</button>
                    </div>
                    
                    <div class="grid grid-cols-2 md:grid-cols-4 gap-4">
                        <button class="category-btn bg-white rounded-lg shadow-sm p-4 text-center hover:shadow-md transition cursor-pointer" data-category="work">
                            <div class="w-12 h-12 bg-indigo-100 text-indigo-600 rounded-full flex items-center justify-center mx-auto mb-3">
                                <i class="fas fa-briefcase"></i>
                            </div>
                            <h4 class="font-medium text-gray-800 mb-1">Work</h4>
                            <p class="text-xs text-gray-500">12 emails</p>
                        </button>
                        
                        <button class="category-btn bg-white rounded-lg shadow-sm p-4 text-center hover:shadow-md transition cursor-pointer" data-category="social">
                            <div class="w-12 h-12 bg-blue-100 text-blue-600 rounded-full flex items-center justify-center mx-auto mb-3">
                                <i class="fas fa-users"></i>
                            </div>
                            <h4 class="font-medium text-gray-800 mb-1">Social</h4>
                            <p class="text-xs text-gray-500">8 emails</p>
                        </button>
                        
                        <button class="category-btn bg-white rounded-lg shadow-sm p-4 text-center hover:shadow-md transition cursor-pointer" data-category="promotions">
                            <div class="w-12 h-12 bg-green-100 text-green-600 rounded-full flex items-center justify-center mx-auto mb-3">
                                <i class="fas fa-tag"></i>
                            </div>
                            <h4 class="font-medium text-gray-800 mb-1">Promotions</h4>
                            <p class="text-xs text-gray-500">14 emails</p>
                        </button>
                        
                        <button class="category-btn bg-white rounded-lg shadow-sm p-4 text-center hover:shadow-md transition cursor-pointer" data-category="updates">
                            <div class="w-12 h-12 bg-purple-100 text-purple-600 rounded-full flex items-center justify-center mx-auto mb-3">
                                <i class="fas fa-newspaper"></i>
                            </div>
                            <h4 class="font-medium text-gray-800 mb-1">Updates</h4>
                            <p class="text-xs text-gray-500">5 emails</p>
                        </button>
                    </div>
                </div>

                <!-- Email List -->
                <div>
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="text-lg font-semibold text-gray-800">Recent Emails</h3>
                        <div class="flex items-center space-x-2">
                            <span class="text-sm text-gray-500">Sorted by:</span>
                            <select id="sort-select" class="text-sm border border-gray-300 rounded-md px-2 py-1 bg-white">
                                <option>Most Recent</option>
                                <option>Priority</option>
                                <option>Unread First</option>
                            </select>
                        </div>
                    </div>
                    
                    <div class="space-y-4" id="email-list">
                        <!-- Email Card 1 -->
                        <div class="email-card bg-white rounded-xl shadow-sm p-6 transition cursor-pointer hover:border-indigo-200 border border-transparent" data-id="1" data-category="work" data-priority="high" data-read="false">
                            <div class="flex items-start">
                                <div class="w-10 h-10 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4 mt-1">
                                    <i class="fas fa-briefcase"></i>
                                </div>
                                <div class="flex-grow">
                                    <div class="flex items-center justify-between mb-1">
                                        <h4 class="font-medium text-gray-800">John Smith</h4>
                                        <span class="text-xs text-gray-500">10:45 AM</span>
                                    </div>
                                    <h3 class="font-semibold text-gray-900 mb-2">Project Update: Q3 Marketing Campaign</h3>
                                    <p class="text-sm text-gray-600 summary-text">
                                        Here's the latest update on our Q3 marketing campaign. We've seen a 15% increase in engagement since implementing the new strategy. The creative team has finalized the assets, and we're on track to launch next week. Please review the attached report and provide feedback by EOD.
                                    </p>
                                    <div class="flex items-center mt-3 space-x-3">
                                        <span class="text-xs px-2 py-1 bg-indigo-100 text-indigo-800 rounded-full">Work</span>
                                        <span class="text-xs px-2 py-1 bg-yellow-100 text-yellow-800 rounded-full">Today</span>
                                        <i class="fas fa-paperclip text-gray-400 ml-auto"></i>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Email Card 2 -->
                        <div class="email-card bg-white rounded-xl shadow-sm p-6 transition cursor-pointer hover:border-indigo-200 border border-transparent" data-id="2" data-category="social" data-priority="medium" data-read="true">
                            <div class="flex items-start">
                                <div class="w-10 h-10 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center mr-4 mt-1">
                                    <i class="fas fa-users"></i>
                                </div>
                                <div class="flex-grow">
                                    <div class="flex items-center justify-between mb-1">
                                        <h4 class="font-medium text-gray-800">LinkedIn</h4>
                                        <span class="text-xs text-gray-500">9:30 AM</span>
                                    </div>
                                    <h3 class="font-semibold text-gray-900 mb-2">You have 5 new connection requests</h3>
                                    <p class="text-sm text-gray-600 summary-text">
                                        You have 5 new connection requests waiting for your response. People you may know include Sarah Johnson from TechCorp, Michael Brown from DesignHub, and 3 others. Growing your network can help you discover new opportunities and stay updated with industry trends.
                                    </p>
                                    <div class="flex items-center mt-3 space-x-3">
                                        <span class="text-xs px-2 py-1 bg-blue-100 text-blue-800 rounded-full">Social</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Email Card 3 -->
                        <div class="email-card bg-white rounded-xl shadow-sm p-6 transition cursor-pointer hover:border-indigo-200 border border-transparent" data-id="3" data-category="promotions" data-priority="low" data-read="true">
                            <div class="flex items-start">
                                <div class="w-10 h-10 rounded-full bg-green-100 text-green-600 flex items-center justify-center mr-4 mt-1">
                                    <i class="fas fa-tag"></i>
                                </div>
                                <div class="flex-grow">
                                    <div class="flex items-center justify-between mb-1">
                                        <h4 class="font-medium text-gray-800">Amazon</h4>
                                        <span class="text-xs text-gray-500">Yesterday</span>
                                    </div>
                                    <h3 class="font-semibold text-gray-900 mb-2">Your order has shipped!</h3>
                                    <p class="text-sm text-gray-600 summary-text">
                                        Your recent order #123-4567890 has shipped and is on its way to you. Expected delivery date is Friday, June 10. Track your package using the link below. We've also included some exclusive deals on similar products you might be interested in.
                                    </p>
                                    <div class="flex items-center mt-3 space-x-3">
                                        <span class="text-xs px-2 py-1 bg-green-100 text-green-800 rounded-full">Promotions</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-6 flex justify-center">
                        <button id="load-more-btn" class="px-4 py-2 bg-white border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition">
                            Load More
                        </button>
                    </div>
                </div>
            </div>
        </main>

        <!-- Footer -->
        <footer class="bg-white border-t border-gray-200 py-4">
            <div class="container mx-auto px-4">
                <div class="flex flex-col md:flex-row justify-between items-center">
                    <div class="text-sm text-gray-500 mb-2 md:mb-0">
                        © 2023 InboxDigest. All rights reserved.
                    </div>
                    <div class="flex space-x-4">
                        <a href="#" class="text-sm text-gray-500 hover:text-indigo-600 transition">Privacy</a>
                        <a href="#" class="text-sm text-gray-500 hover:text-indigo-600 transition">Terms</a>
                        <a href="#" class="text-sm text-gray-500 hover:text-indigo-600 transition">Help</a>
                    </div>
                </div>
            </div>
        </footer>
    </div>

    <!-- Settings Modal -->
    <div id="settings-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-xl shadow-xl w-full max-w-md max-h-[90vh] overflow-y-auto">
            <div class="p-6 border-b border-gray-200">
                <div class="flex items-center justify-between">
                    <h3 class="text-lg font-semibold text-gray-800">Settings</h3>
                    <button id="close-settings" class="text-gray-500 hover:text-gray-700">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
            </div>
            <div class="p-6">
                <div class="space-y-6">
                    <div>
                        <h4 class="font-medium text-gray-800 mb-3">Notification Preferences</h4>
                        <div class="space-y-3">
                            <label class="flex items-center">
                                <input type="checkbox" id="email-summaries" class="rounded text-indigo-600 mr-2" checked>
                                <span class="text-sm text-gray-700">Email summaries</span>
                            </label>
                            <label class="flex items-center">
                                <input type="checkbox" id="priority-alerts" class="rounded text-indigo-600 mr-2" checked>
                                <span class="text-sm text-gray-700">Priority alerts</span>
                            </label>
                            <label class="flex items-center">
                                <input type="checkbox" id="promotional-emails" class="rounded text-indigo-600 mr-2">
                                <span class="text-sm text-gray-700">Promotional emails</span>
                            </label>
                        </div>
                    </div>
                    
                    <div>
                        <h4 class="font-medium text-gray-800 mb-3">Digest Schedule</h4>
                        <select id="digest-schedule" class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm">
                            <option>Daily at 8:00 AM</option>
                            <option>Daily at 7:00 AM</option>
                            <option>Daily at 9:00 AM</option>
                            <option>Twice a day</option>
                        </select>
                    </div>
                    
                    <div>
                        <h4 class="font-medium text-gray-800 mb-3">Connected Accounts</h4>
                        <div class="space-y-3">
                            <div class="flex items-center justify-between bg-gray-50 p-3 rounded-lg">
                                <div class="flex items-center">
                                    <i class="fab fa-google text-red-500 mr-3"></i>
                                    <span class="text-sm text-gray-700">john.doe@gmail.com</span>
                                </div>
                                <button class="text-sm text-red-500 hover:text-red-700 remove-account">Remove</button>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="mt-8 pt-4 border-t border-gray-200">
                    <button id="save-settings" class="w-full py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition">
                        Save Changes
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Help Modal -->
    <div id="help-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-xl shadow-xl w-full max-w-md max-h-[90vh] overflow-y-auto">
            <div class="p-6 border-b border-gray-200">
                <div class="flex items-center justify-between">
                    <h3 class="text-lg font-semibold text-gray-800">Help & Support</h3>
                    <button id="close-help" class="text-gray-500 hover:text-gray-700">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
            </div>
            <div class="p-6">
                <div class="space-y-4">
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">Getting Started</h4>
                        <p class="text-sm text-gray-600">
                            Connect your email accounts to begin receiving daily digests. We support Gmail, Outlook, and other IMAP-compatible providers.
                        </p>
                    </div>
                    
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">Frequently Asked Questions</h4>
                        <div class="space-y-3">
                            <div class="border-b border-gray-100 pb-3">
                                <h5 class="text-sm font-medium text-gray-700">How secure is my data?</h5>
                                <p class="text-xs text-gray-500 mt-1">
                                    We use OAuth for authentication and never store your email credentials. All data is encrypted in transit and at rest.
                                </p>
                            </div>
                            <div class="border-b border-gray-100 pb-3">
                                <h5 class="text-sm font-medium text-gray-700">Can I customize what's included in my digest?</h5>
                                <p class="text-xs text-gray-500 mt-1">
                                    Yes! Go to Settings to adjust your preferences for what types of emails are included and how they're categorized.
                                </p>
                            </div>
                        </div>
                    </div>
                    
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">Contact Support</h4>
                        <p class="text-sm text-gray-600 mb-3">
                            Need more help? Our team is available 24/7 to assist you.
                        </p>
                        <button id="contact-support" class="w-full py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition">
                            <i class="fas fa-envelope mr-2"></i> Email Support
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Add Account Modal -->
    <div id="add-account-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-xl shadow-xl w-full max-w-md max-h-[90vh] overflow-y-auto">
            <div class="p-6 border-b border-gray-200">
                <div class="flex items-center justify-between">
                    <h3 class="text-lg font-semibold text-gray-800">Add Email Account</h3>
                    <button id="close-add-account" class="text-gray-500 hover:text-gray-700">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
            </div>
            <div class="p-6">
                <div class="space-y-4">
                    <button id="modal-connect-gmail" class="w-full bg-red-500 hover:bg-red-600 text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center space-x-3 transition shadow-md">
                        <i class="fab fa-google text-xl"></i>
                        <span>Connect with Gmail</span>
                    </button>
                    
                    <button id="modal-connect-outlook" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center space-x-3 transition shadow-md">
                        <i class="fab fa-microsoft text-xl"></i>
                        <span>Connect with Outlook</span>
                    </button>

                    <button id="modal-connect-imap" class="w-full bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-3 px-6 rounded-lg flex items-center justify-center space-x-3 transition">
                        <i class="fas fa-server text-xl"></i>
                        <span>Advanced IMAP Setup</span>
                    </button>
                </div>
                
                <div class="mt-6 pt-4 border-t border-gray-200 text-center">
                    <p class="text-xs text-gray-500">
                        <i class="fas fa-lock mr-1"></i> Your email credentials are never stored. We use secure OAuth connections.
                    </p>
                </div>
            </div>
        </div>
    </div>

    <!-- Email Detail Modal -->
    <div id="email-detail-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-xl shadow-xl w-full max-w-3xl max-h-[90vh] overflow-y-auto">
            <div class="p-6 border-b border-gray-200">
                <div class="flex items-center justify-between">
                    <h3 id="email-detail-subject" class="text-lg font-semibold text-gray-800">Email Details</h3>
                    <button id="close-email-detail" class="text-gray-500 hover:text-gray-700">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
            </div>
            <div class="p-6">
                <div class="flex items-start mb-6">
                    <div class="w-12 h-12 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                        <i id="email-detail-icon" class="fas fa-envelope"></i>
                    </div>
                    <div class="flex-grow">
                        <div class="flex items-center justify-between mb-1">
                            <h4 id="email-detail-from" class="font-medium text-gray-800">From: John Smith</h4>
                            <span id="email-detail-time" class="text-xs text-gray-500">10:45 AM</span>
                        </div>
                        <div class="flex items-center space-x-2 mb-4">
                            <span id="email-detail-category" class="text-xs px-2 py-1 bg-indigo-100 text-indigo-800 rounded-full">Work</span>
                            <span id="email-detail-priority" class="text-xs px-2 py-1 bg-yellow-100 text-yellow-800 rounded-full">Today</span>
                        </div>
                    </div>
                </div>
                
                <div id="email-detail-body" class="prose max-w-none text-gray-700">
                    <p>Here's the full content of the email...</p>
                </div>
                
                <div id="email-detail-attachments" class="mt-6 pt-4 border-t border-gray-200 hidden">
                    <h4 class="text-sm font-medium text-gray-800 mb-3">Attachments</h4>
                    <div class="flex space-x-3">
                        <div class="flex items-center bg-gray-50 rounded-lg p-3">
                            <i class="fas fa-file-pdf text-red-500 mr-2"></i>
                            <span class="text-sm">Marketing_Report.pdf</span>
                        </div>
                    </div>
                </div>
                
                <div class="mt-6 pt-4 border-t border-gray-200 flex space-x-3">
                    <button class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition">
                        <i class="fas fa-reply mr-2"></i> Reply
                    </button>
                    <button class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition">
                        <i class="fas fa-forward mr-2"></i> Forward
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Service Worker Registration -->
    <script>
        // Register service worker
        if ('serviceWorker' in navigator) {
            window.addEventListener('load', () => {
                navigator.serviceWorker.register('/sw.js')
                    .then(registration => {
                        console.log('ServiceWorker registration successful');
                    })
                    .catch(err => {
                        console.log('ServiceWorker registration failed: ', err);
                    });
            });
        }
    </script>

    <!-- App JavaScript -->
    <script>
        // DOM Elements
        const onboarding = document.getElementById('onboarding');
        const digestView = document.getElementById('digest-view');
        const accountStatus = document.getElementById('account-status');
        const addAccountBtn = document.getElementById('add-account-btn');
        const settingsBtn = document.getElementById('settings-btn');
        const helpBtn = document.getElementById('help-btn');
        const profileBtn = document.getElementById('profile-btn');
        const profileDropdown = document.getElementById('profile-dropdown');
        const settingsModal = document.getElementById('settings-modal');
        const helpModal = document.getElementById('help-modal');
        const addAccountModal = document.getElementById('add-account-modal');
        const emailDetailModal = document.getElementById('email-detail-modal');
        const closeSettings = document.getElementById('close-settings');
        const closeHelp = document.getElementById('close-help');
        const closeAddAccount = document.getElementById('close-add-account');
        const closeEmailDetail = document.getElementById('close-email-detail');
        const connectGmail = document.getElementById('connect-gmail');
        const connectOutlook = document.getElementById('connect-outlook');
        const connectImap = document.getElementById('connect-imap');
        const modalConnectGmail = document.getElementById('modal-connect-gmail');
        const modalConnectOutlook = document.getElementById('modal-connect-outlook');
        const modalConnectImap = document.getElementById('modal-connect-imap');
        const filterBtn = document.getElementById('filter-btn');
        const filterDropdown = document.getElementById('filter-dropdown');
        const applyFilters = document.getElementById('apply-filters');
        const refreshBtn = document.getElementById('refresh-btn');
        const loadingBar = document.getElementById('loading-bar');
        const installContainer = document.getElementById('install-container');
        const installBtn = document.getElementById('install-btn');
        const cancelInstall = document.getElementById('cancel-install');
        const pwaInstallBtn = document.getElementById('pwa-install-btn');
        const emailSummaries = document.getElementById('email-summaries');
        const priorityAlerts = document.getElementById('priority-alerts');
        const promotionalEmails = document.getElementById('promotional-emails');
        const digestSchedule = document.getElementById('digest-schedule');
        const saveSettings = document.getElementById('save-settings');
        const removeAccount = document.querySelector('.remove-account');
        const contactSupport = document.getElementById('contact-support');
        const viewAllBtn = document.getElementById('view-all-btn');
        const categoryBtns = document.querySelectorAll('.category-btn');
        const sortSelect = document.getElementById('sort-select');
        const emailList = document.getElementById('email-list');
        const loadMoreBtn = document.getElementById('load-more-btn');
        const emailCards = document.querySelectorAll('.email-card');
        const emailDetailSubject = document.getElementById('email-detail-subject');
        const emailDetailFrom = document.getElementById('email-detail-from');
        const emailDetailTime = document.getElementById('email-detail-time');
        const emailDetailCategory = document.getElementById('email-detail-category');
        const emailDetailPriority = document.getElementById('email-detail-priority');
        const emailDetailBody = document.getElementById('email-detail-body');
        const emailDetailAttachments = document.getElementById('email-detail-attachments');
        const emailDetailIcon = document.getElementById('email-detail-icon');

        // App State
        let hasAccounts = false;
        let deferredPrompt = null;
        let currentFilter = 'all';
        let currentSort = 'most-recent';
        let displayedEmails = 3;
        const totalEmails = 10; // Simulated total emails

        // Sample email data
        const emailData = {
            1: {
                from: "John Smith",
                subject: "Project Update: Q3 Marketing Campaign",
                time: "10:45 AM",
                category: "Work",
                priority: "Today",
                icon: "briefcase",
                body: `
                    <p>Hi Team,</p>
                    <p>Here's the latest update on our Q3 marketing campaign. We've seen a 15% increase in engagement since implementing the new strategy.</p>
                    <p>The creative team has finalized the assets, and we're on track to launch next week. Please review the attached report and provide feedback by EOD.</p>
                    <p>Key highlights:</p>
                    <ul>
                        <li>15% increase in engagement metrics</li>
                        <li>Creative assets finalized and approved</li>
                        <li>Launch scheduled for next Monday</li>
                        <li>Budget tracking on target</li>
                    </ul>
                    <p>Let me know if you have any questions.</p>
                    <p>Best regards,<br>John</p>
                `,
                hasAttachment: true
            },
            2: {
                from: "LinkedIn",
                subject: "You have 5 new connection requests",
                time: "9:30 AM",
                category: "Social",
                priority: "Low",
                icon: "users",
                body: `
                    <p>You have 5 new connection requests waiting for your response:</p>
                    <p><strong>Sarah Johnson</strong> - Marketing Director at TechCorp<br>
                    <strong>Michael Brown</strong> - UX Designer at DesignHub<br>
                    <strong>Lisa Wong</strong> - Product Manager at Innovate Inc.<br>
                    <strong>David Kim</strong> - CTO at Startup Labs<br>
                    <strong>Emma Wilson</strong> - Senior Developer at CodeCraft</p>
                    <p>Growing your network can help you discover new opportunities and stay updated with industry trends.</p>
                    <p>Click below to view and respond to these requests:</p>
                    <button class="mt-4 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">
                        View Connection Requests
                    </button>
                `,
                hasAttachment: false
            },
            3: {
                from: "Amazon",
                subject: "Your order has shipped!",
                time: "Yesterday",
                category: "Promotions",
                priority: "Low",
                icon: "tag",
                body: `
                    <p>Hello,</p>
                    <p>Your recent order <strong>#123-4567890</strong> has shipped and is on its way to you.</p>
                    <p><strong>Expected delivery date:</strong> Friday, June 10</p>
                    <p><strong>Tracking number:</strong> 1Z23456X8901234567</p>
                    <p>Track your package using the link below:</p>
                    <button class="mt-4 px-4 py-2 bg-yellow-400 text-gray-800 rounded-lg hover:bg-yellow-500 transition">
                        Track Package
                    </button>
                    <p class="mt-4">We've also included some exclusive deals on similar products you might be interested in:</p>
                    <div class="grid grid-cols-2 gap-4 mt-4">
                        <div class="border border-gray-200 rounded-lg p-3">
                            <div class="h-24 bg-gray-100 mb-2"></div>
                            <p class="text-sm">Wireless Earbuds</p>
                            <p class="text-xs text-gray-500">$59.99</p>
                        </div>
                        <div class="border border-gray-200 rounded-lg p-3">
                            <div class="h-24 bg-gray-100 mb-2"></div>
                            <p class="text-sm">Phone Stand</p>
                            <p class="text-xs text-gray-500">$12.99</p>
                        </div>
                    </div>
                `,
                hasAttachment: false
            }
        };

        // Initialize UI
        function initUI() {
            // Check if accounts are connected (simulated)
            if (hasAccounts) {
                onboarding.classList.add('hidden');
                digestView.classList.remove('hidden');
                accountStatus.textContent = "1 account connected";
            } else {
                onboarding.classList.remove('hidden');
                digestView.classList.add('hidden');
                accountStatus.textContent = "No accounts connected";
            }
        }

        // Event Listeners
        addAccountBtn.addEventListener('click', () => {
            addAccountModal.classList.remove('hidden');
        });

        settingsBtn.addEventListener('click', () => {
            settingsModal.classList.remove('hidden');
        });

        helpBtn.addEventListener('click', () => {
            helpModal.classList.remove('hidden');
        });

        profileBtn.addEventListener('click', () => {
            profileDropdown.classList.toggle('hidden');
        });

        closeSettings.addEventListener('click', () => {
            settingsModal.classList.add('hidden');
        });

        closeHelp.addEventListener('click', () => {
            helpModal.classList.add('hidden');
        });

        closeAddAccount.addEventListener('click', () => {
            addAccountModal.classList.add('hidden');
        });

        closeEmailDetail.addEventListener('click', () => {
            emailDetailModal.classList.add('hidden');
        });

        filterBtn.addEventListener('click', () => {
            filterDropdown.classList.toggle('hidden');
        });

        refreshBtn.addEventListener('click', () => {
            loadingBar.style.width = '100%';
            setTimeout(() => {
                loadingBar.style.width = '0%';
                // Simulate refresh
                showToast('Emails refreshed successfully');
            }, 1000);
        });

        // Connect account buttons
        connectGmail.addEventListener('click', () => {
            simulateAccountConnection('Gmail');
        });

        connectOutlook.addEventListener('click', () => {
            simulateAccountConnection('Outlook');
        });

        connectImap.addEventListener('click', () => {
            simulateAccountConnection('IMAP');
        });

        modalConnectGmail.addEventListener('click', () => {
            simulateAccountConnection('Gmail');
        });

        modalConnectOutlook.addEventListener('click', () => {
            simulateAccountConnection('Outlook');
        });

        modalConnectImap.addEventListener('click', () => {
            simulateAccountConnection('IMAP');
        });

        // Apply filters
        applyFilters.addEventListener('click', () => {
            filterDropdown.classList.add('hidden');
            showToast('Filters applied successfully');
        });

        // Save settings
        saveSettings.addEventListener('click', () => {
            settingsModal.classList.add('hidden');
            showToast('Settings saved successfully');
        });

        // Remove account
        removeAccount.addEventListener('click', () => {
            if (confirm('Are you sure you want to remove this account?')) {
                hasAccounts = false;
                initUI();
                showToast('Account removed successfully');
            }
        });

        // Contact support
        contactSupport.addEventListener('click', () => {
            window.location.href = 'mailto:support@inboxdigest.com';
        });

        // View all emails
        viewAllBtn.addEventListener('click', () => {
            currentFilter = 'all';
            filterEmails();
        });

        // Category buttons
        categoryBtns.forEach(btn => {
            btn.addEventListener('click', () => {
                currentFilter = btn.dataset.category;
                filterEmails();
            });
        });

        // Sort emails
        sortSelect.addEventListener('change', () => {
            currentSort = sortSelect.value.toLowerCase().replace(' ', '-');
            sortEmails();
        });

        // Email card click
        emailCards.forEach(card => {
            card.addEventListener('click', () => {
                const emailId = card.dataset.id;
                showEmailDetail(emailId);
                // Mark as read
                card.dataset.read = 'true';
            });
        });

        // Load more emails
        loadMoreBtn.addEventListener('click', () => {
            if (displayedEmails < totalEmails) {
                displayedEmails += 3;
                // In a real app, we would fetch more emails from the server
                showToast(`Loaded ${Math.min(3, totalEmails - displayedEmails + 3)} more emails`);
                
                if (displayedEmails >= totalEmails) {
                    loadMoreBtn.disabled = true;
                    loadMoreBtn.textContent = 'No more emails';
                }
            }
        });

        // Show email detail
        function showEmailDetail(emailId) {
            const email = emailData[emailId];
            if (!email) return;
            
            emailDetailSubject.textContent = email.subject;
            emailDetailFrom.textContent = `From: ${email.from}`;
            emailDetailTime.textContent = email.time;
            emailDetailCategory.textContent = email.category;
            emailDetailPriority.textContent = email.priority;
            emailDetailBody.innerHTML = email.body;
            emailDetailIcon.className = `fas fa-${email.icon}`;
            
            // Update category badge color
            const categoryColors = {
                'Work': 'bg-indigo-100 text-indigo-800',
                'Social': 'bg-blue-100 text-blue-800',
                'Promotions': 'bg-green-100 text-green-800',
                'Updates': 'bg-purple-100 text-purple-800'
            };
            emailDetailCategory.className = `text-xs px-2 py-1 rounded-full ${categoryColors[email.category] || 'bg-gray-100 text-gray-800'}`;
            
            // Update priority badge color
            const priorityColors = {
                'Urgent': 'bg-red-100 text-red-800',
                'Today': 'bg-yellow-100 text-yellow-800',
                'This Week': 'bg-green-100 text-green-800',
                'Low': 'bg-gray-100 text-gray-800'
            };
            emailDetailPriority.className = `text-xs px-2 py-1 rounded-full ${priorityColors[email.priority] || 'bg-gray-100 text-gray-800'}`;
            
            // Show/hide attachments
            if (email.hasAttachment) {
                emailDetailAttachments.classList.remove('hidden');
            } else {
                emailDetailAttachments.classList.add('hidden');
            }
            
            emailDetailModal.classList.remove('hidden');
        }

        // Filter emails by category
        function filterEmails() {
            emailCards.forEach(card => {
                if (currentFilter === 'all' || card.dataset.category === currentFilter) {
                    card.style.display = 'block';
                } else {
                    card.style.display = 'none';
                }
            });
            showToast(`Showing ${currentFilter === 'all' ? 'all' : currentFilter} emails`);
        }

        // Sort emails
        function sortEmails() {
            const cards = Array.from(emailCards);
            
            cards.sort((a, b) => {
                if (currentSort === 'most-recent') {
                    return new Date(b.dataset.time) - new Date(a.dataset.time);
                } else if (currentSort === 'priority') {
                    const priorityOrder = { high: 3, medium: 2, low: 1 };
                    return priorityOrder[b.dataset.priority] - priorityOrder[a.dataset.priority];
                } else if (currentSort === 'unread-first') {
                    return a.dataset.read === 'false' ? -1 : 1;
                }
                return 0;
            });
            
            // Re-append sorted emails
            cards.forEach(card => emailList.appendChild(card));
            showToast(`Sorted by ${currentSort.replace('-', ' ')}`);
        }

        // Simulate account connection
        function simulateAccountConnection(provider) {
            loadingBar.style.width = '30%';
            
            setTimeout(() => {
                loadingBar.style.width = '70%';
                
                setTimeout(() => {
                    loadingBar.style.width = '100%';
                    hasAccounts = true;
                    initUI();
                    addAccountModal.classList.add('hidden');
                    
                    setTimeout(() => {
                        loadingBar.style.width = '0%';
                        showToast(`${provider} account connected successfully`);
                    }, 300);
                }, 500);
            }, 500);
        }

        // Show toast notification
        function showToast(message) {
            const toast = document.createElement('div');
            toast.className = 'fixed bottom-4 left-1/2 transform -translate-x-1/2 bg-gray-800 text-white px-4 py-2 rounded-lg shadow-lg animate-fade-in';
            toast.textContent = message;
            document.body.appendChild(toast);
            
            setTimeout(() => {
                toast.remove();
            }, 3000);
        }

        // PWA Installation
        window.addEventListener('beforeinstallprompt', (e) => {
            e.preventDefault();
            deferredPrompt = e;
            
            // Show install button if not in standalone mode
            if (window.matchMedia('(display-mode: standalone)').matches) {
                pwaInstallBtn.style.display = 'none';
            } else {
                pwaInstallBtn.style.display = 'block';
            }
        });

        pwaInstallBtn.addEventListener('click', () => {
            if (deferredPrompt) {
                deferredPrompt.prompt();
                
                deferredPrompt.userChoice.then((choiceResult) => {
                    if (choiceResult.outcome === 'accepted') {
                        showToast('InboxDigest installed successfully');
                    } else {
                        showToast('Installation cancelled');
                    }
                    deferredPrompt = null;
                });
            }
        });

        // Show install prompt on mobile
        function showInstallPrompt() {
            if (deferredPrompt && !window.matchMedia('(display-mode: standalone)').matches) {
                installContainer.classList.remove('hidden');
            }
        }

        installBtn.addEventListener('click', () => {
            if (deferredPrompt) {
                deferredPrompt.prompt();
                installContainer.classList.add('hidden');
            }
        });

        cancelInstall.addEventListener('click', () => {
            installContainer.classList.add('hidden');
        });

        // Show install prompt after some time
        setTimeout(showInstallPrompt, 10000);

        // Close dropdowns when clicking outside
        document.addEventListener('click', (e) => {
            if (!profileBtn.contains(e.target) && !profileDropdown.contains(e.target)) {
                profileDropdown.classList.add('hidden');
            }
            
            if (!filterBtn.contains(e.target) && !filterDropdown.contains(e.target)) {
                filterDropdown.classList.add('hidden');
            }
        });

        // Initialize the app
        initUI();
    </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=Ziantech/ziantech" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>