File size: 67,582 Bytes
4cf9ea5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FinTrack - Personal Finance Tracker</title>
    <meta name="description" content="Track your income, expenses, debts and credits with this offline PWA">
    <meta name="theme-color" content="#3B82F6">
    <link rel="manifest" href="/manifest.json">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/gsap.min.js"></script>
    <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-fadeIn {
            animation: fadeIn 0.3s ease-out forwards;
        }
        .transaction-item {
            transition: all 0.2s ease;
        }
        .transaction-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        .dark .transaction-item:hover {
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
        }
        .tab-active {
            position: relative;
        }
        .tab-active:after {
            content: '';
            position: absolute;
            bottom: -1px;
            left: 0;
            right: 0;
            height: 3px;
            background-color: #3B82F6;
            border-radius: 3px 3px 0 0;
        }
        .no-scrollbar::-webkit-scrollbar {
            display: none;
        }
        .no-scrollbar {
            -ms-overflow-style: none;
            scrollbar-width: none;
        }
        .skeleton {
            background-color: #e5e7eb;
            background-image: linear-gradient(90deg, #e5e7eb, #f3f4f6, #e5e7eb);
            background-size: 200% 100%;
            animation: shimmer 1.5s infinite;
        }
        .dark .skeleton {
            background-color: #374151;
            background-image: linear-gradient(90deg, #374151, #4b5563, #374151);
        }
        @keyframes shimmer {
            0% { background-position: 200% 0; }
            100% { background-position: -200% 0; }
        }
    </style>
</head>
<body class="bg-gray-50 dark:bg-gray-900 text-gray-800 dark:text-gray-200 transition-colors duration-200 min-h-screen">
    <div class="container mx-auto px-4 py-6 max-w-6xl">
        <!-- Header -->
        <header class="flex justify-between items-center mb-6">
            <div class="flex items-center space-x-3">
                <div class="w-10 h-10 rounded-full bg-blue-500 flex items-center justify-center">
                    <i class="fas fa-wallet text-white text-xl"></i>
                </div>
                <div>
                    <h1 class="text-xl font-bold">FinTrack</h1>
                    <p class="text-xs text-gray-500 dark:text-gray-400">Personal Finance Tracker</p>
                </div>
            </div>
            <div class="flex items-center space-x-3">
                <button id="themeToggle" class="w-10 h-10 rounded-full flex items-center justify-center hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors">
                    <i class="fas fa-moon dark:hidden"></i>
                    <i class="fas fa-sun hidden dark:inline"></i>
                </button>
                <div class="relative">
                    <select id="currencySelect" class="appearance-none bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg px-3 py-1 pr-8 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
                        <option value="₺">₺ TRY</option>
                        <option value="MK">MK MWK</option>
                        <option value="$" selected>$ USD</option>
                        <option value="€">€ EUR</option>
                    </select>
                    <div class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
                        <i class="fas fa-chevron-down text-xs text-gray-500"></i>
                    </div>
                </div>
            </div>
        </header>

        <!-- Desktop Tabs -->
        <div class="hidden md:flex mb-6 bg-white dark:bg-gray-800 rounded-xl shadow-sm overflow-hidden">
            <button data-tab="dashboard" class="tab-btn flex-1 py-3 px-4 text-center font-medium hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors tab-active">
                <i class="fas fa-home mr-2"></i>Dashboard
            </button>
            <button data-tab="transactions" class="tab-btn flex-1 py-3 px-4 text-center font-medium hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">
                <i class="fas fa-exchange-alt mr-2"></i>Transactions
            </button>
            <button data-tab="charts" class="tab-btn flex-1 py-3 px-4 text-center font-medium hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">
                <i class="fas fa-chart-bar mr-2"></i>Analytics
            </button>
            <button data-tab="settings" class="tab-btn flex-1 py-3 px-4 text-center font-medium hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">
                <i class="fas fa-cog mr-2"></i>Settings
            </button>
        </div>

        <!-- Main Content -->
        <main id="contentArea" class="bg-white dark:bg-gray-800 rounded-xl shadow-sm p-5 mb-20 min-h-[60vh]">
            <!-- Dashboard content will be loaded here -->
            <div class="flex flex-col items-center justify-center h-full">
                <div class="w-16 h-16 rounded-full bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center mb-4">
                    <i class="fas fa-circle-notch fa-spin text-blue-500 text-2xl"></i>
                </div>
                <p class="text-gray-500 dark:text-gray-400">Loading your financial data...</p>
            </div>
        </main>

        <!-- Add Transaction FAB -->
        <button id="addTransactionBtn" class="fixed right-6 bottom-24 md:right-8 md:bottom-8 w-14 h-14 rounded-full bg-blue-500 text-white shadow-lg flex items-center justify-center hover:bg-blue-600 transition-colors z-40">
            <i class="fas fa-plus text-xl"></i>
        </button>

        <!-- Mobile Bottom Nav -->
        <div class="mobile-bottom-nav md:hidden flex justify-around items-center py-3 bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 fixed bottom-0 left-0 right-0 z-30">
            <button data-tab="dashboard" class="tab-btn flex flex-col items-center text-xs p-2 text-blue-500">
                <i class="fas fa-home mb-1 text-lg"></i>
                <span>Home</span>
            </button>
            <button data-tab="transactions" class="tab-btn flex flex-col items-center text-xs p-2 text-gray-500 dark:text-gray-400">
                <i class="fas fa-exchange-alt mb-1 text-lg"></i>
                <span>Transactions</span>
            </button>
            <button data-tab="charts" class="tab-btn flex flex-col items-center text-xs p-2 text-gray-500 dark:text-gray-400">
                <i class="fas fa-chart-bar mb-1 text-lg"></i>
                <span>Analytics</span>
            </button>
            <button data-tab="settings" class="tab-btn flex flex-col items-center text-xs p-2 text-gray-500 dark:text-gray-400">
                <i class="fas fa-cog mb-1 text-lg"></i>
                <span>Settings</span>
            </button>
        </div>

        <!-- Add Transaction Modal -->
        <div id="addTransactionModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[90vh] overflow-y-auto">
                <div class="sticky top-0 bg-white dark:bg-gray-800 px-6 py-4 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center">
                    <h3 class="text-lg font-semibold">Add Transaction</h3>
                    <button id="closeModal" class="text-gray-500 hover:text-gray-700 dark:hover:text-gray-300">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
                <form id="transactionForm" class="p-6 space-y-4">
                    <div>
                        <label class="block text-sm font-medium mb-2">Type</label>
                        <div class="grid grid-cols-2 gap-2">
                            <button type="button" data-type="income" class="type-btn flex items-center justify-center py-3 px-4 rounded-lg border-2 border-green-500 text-green-500 hover:bg-green-50 dark:hover:bg-green-900/10 transition-colors">
                                <i class="fas fa-money-bill-wave mr-2"></i> Income
                            </button>
                            <button type="button" data-type="expense" class="type-btn flex items-center justify-center py-3 px-4 rounded-lg border-2 border-red-500 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/10 transition-colors">
                                <i class="fas fa-shopping-cart mr-2"></i> Expense
                            </button>
                            <button type="button" data-type="debt" class="type-btn flex items-center justify-center py-3 px-4 rounded-lg border-2 border-yellow-500 text-yellow-500 hover:bg-yellow-50 dark:hover:bg-yellow-900/10 transition-colors">
                                <i class="fas fa-hand-holding-usd mr-2"></i> Debt
                            </button>
                            <button type="button" data-type="credit" class="type-btn flex items-center justify-center py-3 px-4 rounded-lg border-2 border-blue-500 text-blue-500 hover:bg-blue-50 dark:hover:bg-blue-900/10 transition-colors">
                                <i class="fas fa-hand-holding-heart mr-2"></i> Credit
                            </button>
                        </div>
                    </div>
                    <div>
                        <label for="amount" class="block text-sm font-medium mb-2">Amount</label>
                        <div class="relative">
                            <span id="currencySymbol" class="absolute left-3 top-1/2 transform -translate-y-1/2">$</span>
                            <input type="number" id="amount" class="w-full pl-8 pr-3 py-3 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="0.00" step="0.01" min="0" required>
                        </div>
                    </div>
                    <div>
                        <label for="description" class="block text-sm font-medium mb-2">Description</label>
                        <input type="text" id="description" class="w-full px-3 py-3 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="e.g. Groceries, Salary" required>
                    </div>
                    <div>
                        <label for="category" class="block text-sm font-medium mb-2">Category</label>
                        <select id="category" class="w-full px-3 py-3 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 appearance-none">
                            <option value="" disabled selected>Select a category</option>
                            <option value="Food">Food</option>
                            <option value="Transport">Transport</option>
                            <option value="Housing">Housing</option>
                            <option value="Utilities">Utilities</option>
                            <option value="Entertainment">Entertainment</option>
                            <option value="Healthcare">Healthcare</option>
                            <option value="Education">Education</option>
                            <option value="Shopping">Shopping</option>
                            <option value="Salary">Salary</option>
                            <option value="Other">Other</option>
                        </select>
                        <div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
                            <i class="fas fa-chevron-down text-gray-500"></i>
                        </div>
                    </div>
                    <div>
                        <label for="date" class="block text-sm font-medium mb-2">Date</label>
                        <input type="date" id="date" class="w-full px-3 py-3 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500" required>
                    </div>
                    <div class="flex justify-end space-x-3 pt-4">
                        <button type="button" id="cancelTransaction" class="px-5 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">Cancel</button>
                        <button type="submit" class="px-5 py-2.5 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors flex items-center">
                            <i class="fas fa-save mr-2"></i> Save
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <!-- Confirmation Modal -->
        <div id="confirmationModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow-xl w-full max-w-sm mx-4">
                <div class="p-6 text-center">
                    <div class="w-16 h-16 rounded-full bg-red-100 dark:bg-red-900/20 flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-exclamation-circle text-2xl text-red-500"></i>
                    </div>
                    <h3 class="text-lg font-semibold mb-2" id="confirmationTitle">Are you sure?</h3>
                    <p class="text-gray-600 dark:text-gray-300 mb-6" id="confirmationMessage">This action cannot be undone.</p>
                    <div class="flex justify-center space-x-4">
                        <button id="confirmCancel" class="px-5 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">Cancel</button>
                        <button id="confirmAction" class="px-5 py-2.5 bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors">Confirm</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Toast Notification -->
        <div id="toast" class="fixed bottom-20 left-1/2 transform -translate-x-1/2 bg-gray-800 text-white px-4 py-2 rounded-lg shadow-lg flex items-center hidden z-50">
            <i class="fas fa-check-circle mr-2 text-green-400"></i>
            <span id="toastMessage">Transaction added successfully</span>
        </div>
    </div>

    <script>
        // Initialize the app when DOM is loaded
        document.addEventListener('DOMContentLoaded', function() {
            // Check for service worker support
            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);
                    });
                });
            }

            // Initialize variables
            let currentTab = 'dashboard';
            let selectedType = 'expense';
            let transactions = JSON.parse(localStorage.getItem('transactions')) || [];
            let currencySymbol = localStorage.getItem('currency') || '$';
            let darkMode = localStorage.getItem('darkMode') === 'true';
            let pendingAction = null;

            // Set initial UI state
            document.getElementById('currencySelect').value = currencySymbol;
            if (darkMode) {
                document.documentElement.classList.add('dark');
            } else {
                document.documentElement.classList.remove('dark');
            }

            // Load the initial tab
            loadTab(currentTab);

            // Event listeners
            document.getElementById('themeToggle').addEventListener('click', toggleDarkMode);
            document.getElementById('currencySelect').addEventListener('change', updateCurrency);
            document.querySelectorAll('.tab-btn').forEach(btn => {
                btn.addEventListener('click', function() {
                    currentTab = this.getAttribute('data-tab');
                    loadTab(currentTab);
                    highlightActiveTab();
                });
            });

            // Transaction form related events
            document.querySelectorAll('.type-btn').forEach(btn => {
                btn.addEventListener('click', function() {
                    selectedType = this.getAttribute('data-type');
                    document.querySelectorAll('.type-btn').forEach(b => {
                        b.classList.remove(
                            'bg-green-500', 'text-white', 'border-green-500',
                            'bg-red-500', 'text-white', 'border-red-500',
                            'bg-yellow-500', 'text-white', 'border-yellow-500',
                            'bg-blue-500', 'text-white', 'border-blue-500'
                        );
                    });
                    this.classList.add(
                        selectedType === 'income' ? 'bg-green-500 text-white border-green-500' :
                        selectedType === 'expense' ? 'bg-red-500 text-white border-red-500' :
                        selectedType === 'debt' ? 'bg-yellow-500 text-white border-yellow-500' : 
                        'bg-blue-500 text-white border-blue-500'
                    );
                });
            });

            document.getElementById('addTransactionBtn').addEventListener('click', showModal);
            document.getElementById('transactionForm').addEventListener('submit', addTransaction);
            document.getElementById('cancelTransaction').addEventListener('click', closeModal);
            document.getElementById('closeModal').addEventListener('click', closeModal);
            document.getElementById('confirmCancel').addEventListener('click', closeConfirmation);
            document.getElementById('confirmAction').addEventListener('click', executeConfirmedAction);

            // Set today's date as default
            document.getElementById('date').valueAsDate = new Date();

            // Highlight the active tab
            highlightActiveTab();

            // Functions
            function toggleDarkMode() {
                darkMode = !darkMode;
                localStorage.setItem('darkMode', darkMode);
                document.documentElement.classList.toggle('dark');
            }

            function updateCurrency() {
                currencySymbol = document.getElementById('currencySelect').value;
                localStorage.setItem('currency', currencySymbol);
                document.getElementById('currencySymbol').textContent = currencySymbol;
                loadTab(currentTab);
            }

            function highlightActiveTab() {
                document.querySelectorAll('.tab-btn').forEach(btn => {
                    if (btn.getAttribute('data-tab') === currentTab) {
                        btn.classList.add('text-blue-500', 'tab-active');
                        btn.classList.remove('text-gray-500', 'dark:text-gray-400');
                    } else {
                        btn.classList.remove('text-blue-500', 'tab-active');
                        btn.classList.add('text-gray-500', 'dark:text-gray-400');
                    }
                });
            }

            function loadTab(tab) {
                const contentArea = document.getElementById('contentArea');
                
                // Show loading state
                contentArea.innerHTML = `
                    <div class="flex flex-col items-center justify-center h-full">
                        <div class="w-16 h-16 rounded-full bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center mb-4">
                            <i class="fas fa-circle-notch fa-spin text-blue-500 text-2xl"></i>
                        </div>
                        <p class="text-gray-500 dark:text-gray-400">Loading your financial data...</p>
                    </div>
                `;
                
                // Simulate loading delay for better UX
                setTimeout(() => {
                    // Load new content
                    let html = '';
                    switch(tab) {
                        case 'dashboard':
                            html = getDashboardHTML();
                            break;
                        case 'transactions':
                            html = getTransactionsHTML();
                            break;
                        case 'charts':
                            html = getChartsHTML();
                            break;
                        case 'settings':
                            html = getSettingsHTML();
                            break;
                    }
                    
                    contentArea.innerHTML = html;
                    
                    // Initialize any tab-specific functionality
                    if (tab === 'transactions') {
                        setupTransactionList();
                    } else if (tab === 'charts') {
                        renderCharts();
                    }
                    
                    // Animate content in
                    gsap.from(contentArea.children, {
                        opacity: 0,
                        y: 10,
                        duration: 0.3,
                        stagger: 0.1,
                        ease: "power2.out"
                    });
                }, 300);
            }

            function getDashboardHTML() {
                const today = new Date();
                const currentMonth = today.getMonth();
                const currentYear = today.getFullYear();
                
                const monthlyTransactions = transactions.filter(t => {
                    const transactionDate = new Date(t.date);
                    return transactionDate.getMonth() === currentMonth && 
                           transactionDate.getFullYear() === currentYear;
                });
                
                const income = monthlyTransactions.filter(t => t.type === 'income').reduce((sum, t) => sum + t.amount, 0);
                const expenses = monthlyTransactions.filter(t => t.type === 'expense').reduce((sum, t) => sum + t.amount, 0);
                const debts = monthlyTransactions.filter(t => t.type === 'debt').reduce((sum, t) => sum + t.amount, 0);
                const credits = monthlyTransactions.filter(t => t.type === 'credit').reduce((sum, t) => sum + t.amount, 0);
                
                const balance = income - expenses;
                
                // Recent transactions (last 5)
                const recentTransactions = [...transactions].sort((a, b) => new Date(b.date) - new Date(a.date)).slice(0, 5);
                
                return `
                    <div class="space-y-6 animate-fadeIn">
                        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
                            <div class="bg-green-50 dark:bg-green-900/10 p-5 rounded-xl border border-green-100 dark:border-green-800/50">
                                <div class="flex justify-between items-start">
                                    <div>
                                        <p class="text-sm font-medium text-green-800 dark:text-green-200 mb-1">Income</p>
                                        <p class="text-2xl font-bold">${currencySymbol}${income.toFixed(2)}</p>
                                    </div>
                                    <div class="w-10 h-10 rounded-full bg-green-100 dark:bg-green-900/20 flex items-center justify-center">
                                        <i class="fas fa-money-bill-wave text-green-500 dark:text-green-400"></i>
                                    </div>
                                </div>
                                <p class="text-xs text-green-600 dark:text-green-300 mt-3">This month</p>
                            </div>
                            <div class="bg-red-50 dark:bg-red-900/10 p-5 rounded-xl border border-red-100 dark:border-red-800/50">
                                <div class="flex justify-between items-start">
                                    <div>
                                        <p class="text-sm font-medium text-red-800 dark:text-red-200 mb-1">Expenses</p>
                                        <p class="text-2xl font-bold">${currencySymbol}${expenses.toFixed(2)}</p>
                                    </div>
                                    <div class="w-10 h-10 rounded-full bg-red-100 dark:bg-red-900/20 flex items-center justify-center">
                                        <i class="fas fa-shopping-cart text-red-500 dark:text-red-400"></i>
                                    </div>
                                </div>
                                <p class="text-xs text-red-600 dark:text-red-300 mt-3">This month</p>
                            </div>
                            <div class="bg-yellow-50 dark:bg-yellow-900/10 p-5 rounded-xl border border-yellow-100 dark:border-yellow-800/50">
                                <div class="flex justify-between items-start">
                                    <div>
                                        <p class="text-sm font-medium text-yellow-800 dark:text-yellow-200 mb-1">Debts</p>
                                        <p class="text-2xl font-bold">${currencySymbol}${debts.toFixed(2)}</p>
                                    </div>
                                    <div class="w-10 h-10 rounded-full bg-yellow-100 dark:bg-yellow-900/20 flex items-center justify-center">
                                        <i class="fas fa-hand-holding-usd text-yellow-500 dark:text-yellow-400"></i>
                                    </div>
                                </div>
                                <p class="text-xs text-yellow-600 dark:text-yellow-300 mt-3">Total</p>
                            </div>
                            <div class="bg-blue-50 dark:bg-blue-900/10 p-5 rounded-xl border border-blue-100 dark:border-blue-800/50">
                                <div class="flex justify-between items-start">
                                    <div>
                                        <p class="text-sm font-medium text-blue-800 dark:text-blue-200 mb-1">Credits</p>
                                        <p class="text-2xl font-bold">${currencySymbol}${credits.toFixed(2)}</p>
                                    </div>
                                    <div class="w-10 h-10 rounded-full bg-blue-100 dark:bg-blue-900/20 flex items-center justify-center">
                                        <i class="fas fa-hand-holding-heart text-blue-500 dark:text-blue-400"></i>
                                    </div>
                                </div>
                                <p class="text-xs text-blue-600 dark:text-blue-300 mt-3">Total</p>
                            </div>
                        </div>
                        
                        <div class="bg-gray-50 dark:bg-gray-800/50 p-5 rounded-xl border border-gray-200 dark:border-gray-700">
                            <div class="flex justify-between items-center mb-3">
                                <h3 class="text-lg font-semibold">Current Balance</h3>
                                <span class="text-xs px-2 py-1 rounded-full ${balance >= 0 ? 'bg-green-100 dark:bg-green-900/20 text-green-800 dark:text-green-200' : 'bg-red-100 dark:bg-red-900/20 text-red-800 dark:text-red-200'}">
                                    ${balance >= 0 ? 'Positive' : 'Negative'}
                                </span>
                            </div>
                            <p class="text-3xl font-bold ${balance >= 0 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'}">
                                ${balance >= 0 ? '+' : ''}${currencySymbol}${Math.abs(balance).toFixed(2)}
                            </p>
                            <div class="mt-4 h-2 rounded-full bg-gray-200 dark:bg-gray-700 overflow-hidden">
                                <div class="h-full ${balance >= 0 ? 'bg-green-500' : 'bg-red-500'}" style="width: ${Math.min(100, Math.abs(balance) / (income || 1) * 100)}%"></div>
                            </div>
                        </div>
                        
                        <div class="bg-white dark:bg-gray-800/50 p-5 rounded-xl border border-gray-200 dark:border-gray-700">
                            <div class="flex justify-between items-center mb-4">
                                <h3 class="text-lg font-semibold">Recent Transactions</h3>
                                <button onclick="loadTab('transactions')" class="text-sm text-blue-500 hover:text-blue-700 dark:hover:text-blue-400 flex items-center">
                                    View All <i class="fas fa-arrow-right ml-1"></i>
                                </button>
                            </div>
                            <div class="space-y-3">
                                ${recentTransactions.length > 0 ? 
                                    recentTransactions.map(t => `
                                        <div class="transaction-item bg-gray-50 dark:bg-gray-800 p-4 rounded-lg flex justify-between items-center">
                                            <div class="flex items-center">
                                                <div class="w-10 h-10 rounded-full flex items-center justify-center 
                                                    ${t.type === 'income' ? 'bg-green-100 dark:bg-green-900/20 text-green-600 dark:text-green-300' : 
                                                      t.type === 'expense' ? 'bg-red-100 dark:bg-red-900/20 text-red-600 dark:text-red-300' : 
                                                      t.type === 'debt' ? 'bg-yellow-100 dark:bg-yellow-900/20 text-yellow-600 dark:text-yellow-300' : 
                                                      'bg-blue-100 dark:bg-blue-900/20 text-blue-600 dark:text-blue-300'}">
                                                    <i class="fas ${
                                                        t.type === 'income' ? 'fa-money-bill-wave' : 
                                                        t.type === 'expense' ? 'fa-shopping-cart' : 
                                                        t.type === 'debt' ? 'fa-hand-holding-usd' : 'fa-hand-holding-heart'
                                                    }"></i>
                                                </div>
                                                <div class="ml-3">
                                                    <p class="font-medium">${t.description}</p>
                                                    <p class="text-xs text-gray-500 dark:text-gray-400">${t.category} • ${new Date(t.date).toLocaleDateString()}</p>
                                                </div>
                                            </div>
                                            <p class="font-semibold ${
                                                t.type === 'income' ? 'text-green-600 dark:text-green-400' : 
                                                t.type === 'expense' ? 'text-red-600 dark:text-red-400' : 
                                                t.type === 'debt' ? 'text-yellow-600 dark:text-yellow-400' : 'text-blue-600 dark:text-blue-400'
                                            }">
                                                ${t.type === 'income' ? '+' : '-'}${currencySymbol}${t.amount.toFixed(2)}
                                            </p>
                                        </div>
                                    `).join('') : 
                                    '<div class="text-center py-8"><p class="text-gray-500 dark:text-gray-400">No transactions yet</p><button onclick="showModal()" class="mt-4 px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors">Add your first transaction</button></div>'
                                }
                            </div>
                        </div>
                    </div>
                `;
            }

            function getTransactionsHTML() {
                // Group transactions by month
                const groupedTransactions = {};
                transactions.forEach(t => {
                    const date = new Date(t.date);
                    const monthYear = `${date.toLocaleString('default', { month: 'long' })} ${date.getFullYear()}`;
                    
                    if (!groupedTransactions[monthYear]) {
                        groupedTransactions[monthYear] = [];
                    }
                    groupedTransactions[monthYear].push(t);
                });
                
                return `
                    <div class="space-y-6 animate-fadeIn">
                        <div class="flex justify-between items-center">
                            <h2 class="text-xl font-bold">All Transactions</h2>
                            <div class="flex items-center space-x-2">
                                <button onclick="showModal()" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg flex items-center transition-colors">
                                    <i class="fas fa-plus mr-2"></i> Add
                                </button>
                            </div>
                        </div>
                        
                        ${transactions.length > 0 ? 
                            Object.entries(groupedTransactions).map(([monthYear, monthTransactions]) => `
                                <div class="mb-6">
                                    <h3 class="text-lg font-semibold mb-3">${monthYear}</h3>
                                    <div class="bg-white dark:bg-gray-800/50 rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden">
                                        ${monthTransactions.map((t, i) => `
                                            <div class="transaction-item grid grid-cols-12 p-4 items-center border-b border-gray-100 dark:border-gray-700 last:border-0" data-id="${i}">
                                                <div class="col-span-1">
                                                    <div class="w-8 h-8 rounded-full flex items-center justify-center 
                                                        ${t.type === 'income' ? 'bg-green-100 dark:bg-green-900/20 text-green-600 dark:text-green-300' : 
                                                          t.type === 'expense' ? 'bg-red-100 dark:bg-red-900/20 text-red-600 dark:text-red-300' : 
                                                          t.type === 'debt' ? 'bg-yellow-100 dark:bg-yellow-900/20 text-yellow-600 dark:text-yellow-300' : 
                                                          'bg-blue-100 dark:bg-blue-900/20 text-blue-600 dark:text-blue-300'}">
                                                        <i class="fas ${
                                                            t.type === 'income' ? 'fa-money-bill-wave' : 
                                                            t.type === 'expense' ? 'fa-shopping-cart' : 
                                                            t.type === 'debt' ? 'fa-hand-holding-usd' : 'fa-hand-holding-heart'
                                                        } text-xs"></i>
                                                    </div>
                                                </div>
                                                <div class="col-span-5 md:col-span-6">
                                                    <p class="font-medium truncate">${t.description}</p>
                                                    <p class="text-xs text-gray-500 dark:text-gray-400">${t.category}</p>
                                                </div>
                                                <div class="col-span-4 md:col-span-3 text-right font-medium ${
                                                    t.type === 'income' ? 'text-green-600 dark:text-green-400' : 
                                                    t.type === 'expense' ? 'text-red-600 dark:text-red-400' : 
                                                    t.type === 'debt' ? 'text-yellow-600 dark:text-yellow-400' : 'text-blue-600 dark:text-blue-400'
                                                }">
                                                    ${t.type === 'income' ? '+' : '-'}${currencySymbol}${t.amount.toFixed(2)}
                                                </div>
                                                <div class="col-span-2 text-right">
                                                    <button onclick="deleteTransaction(${i})" class="text-gray-400 hover:text-red-500 dark:hover:text-red-400 transition-colors">
                                                        <i class="fas fa-trash"></i>
                                                    </button>
                                                </div>
                                            </div>
                                        `).join('')}
                                    </div>
                                </div>
                            `).join('') : 
                            '<div class="text-center py-12"><p class="text-gray-500 dark:text-gray-400 mb-4">No transactions yet</p><button onclick="showModal()" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors">Add your first transaction</button></div>'
                        }
                    </div>
                `;
            }

            function getChartsHTML() {
                return `
                    <div class="space-y-6 animate-fadeIn">
                        <h2 class="text-xl font-bold">Financial Analytics</h2>
                        
                        <div class="bg-white dark:bg-gray-800/50 p-5 rounded-xl border border-gray-200 dark:border-gray-700">
                            <h3 class="font-medium mb-4">Income vs Expenses (This Month)</h3>
                            <div class="h-64">
                                <canvas id="incomeExpenseChart"></canvas>
                            </div>
                        </div>
                        
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div class="bg-white dark:bg-gray-800/50 p-5 rounded-xl border border-gray-200 dark:border-gray-700">
                                <h3 class="font-medium mb-4">Expense Categories</h3>
                                <div class="h-64">
                                    <canvas id="expenseCategoriesChart"></canvas>
                                </div>
                            </div>
                            <div class="bg-white dark:bg-gray-800/50 p-5 rounded-xl border border-gray-200 dark:border-gray-700">
                                <h3 class="font-medium mb-4">Debts vs Credits</h3>
                                <div class="h-64">
                                    <canvas id="debtCreditChart"></canvas>
                                </div>
                            </div>
                        </div>
                        
                        <div class="bg-white dark:bg-gray-800/50 p-5 rounded-xl border border-gray-200 dark:border-gray-700">
                            <h3 class="font-medium mb-4">Monthly Summary</h3>
                            <div class="h-64">
                                <canvas id="monthlySummaryChart"></canvas>
                            </div>
                        </div>
                    </div>
                `;
            }

            function getSettingsHTML() {
                return `
                    <div class="space-y-6 animate-fadeIn">
                        <h2 class="text-xl font-bold">Settings</h2>
                        
                        <div class="bg-white dark:bg-gray-800/50 p-5 rounded-xl border border-gray-200 dark:border-gray-700">
                            <h3 class="font-medium mb-4">Appearance</h3>
                            <div class="space-y-4">
                                <div class="flex items-center justify-between">
                                    <div>
                                        <p class="font-medium">Dark Mode</p>
                                        <p class="text-sm text-gray-500 dark:text-gray-400">Toggle between light and dark theme</p>
                                    </div>
                                    <label class="relative inline-flex items-center cursor-pointer">
                                        <input type="checkbox" id="darkModeToggle" class="sr-only peer" ${darkMode ? 'checked' : ''}>
                                        <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-500"></div>
                                    </label>
                                </div>
                                <div>
                                    <label class="block mb-2 font-medium">Currency</label>
                                    <select id="settingsCurrency" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500">
                                        <option value="₺" ${currencySymbol === '₺' ? 'selected' : ''}>₺ Turkish Lira</option>
                                        <option value="MK" ${currencySymbol === 'MK' ? 'selected' : ''}>MK Malawi Kwacha</option>
                                        <option value="$" ${currencySymbol === '$' ? 'selected' : ''}>$ US Dollar</option>
                                        <option value="€" ${currencySymbol === '€' ? 'selected' : ''}>€ Euro</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        
                        <div class="bg-white dark:bg-gray-800/50 p-5 rounded-xl border border-gray-200 dark:border-gray-700">
                            <h3 class="font-medium mb-4">Data Management</h3>
                            <div class="space-y-3">
                                <button onclick="exportData()" class="w-full bg-blue-500 hover:bg-blue-600 text-white px-4 py-2.5 rounded-lg flex items-center justify-center transition-colors">
                                    <i class="fas fa-file-export mr-2"></i> Export Data
                                </button>
                                <label class="block">
                                    <span class="sr-only">Import Data</span>
                                    <input type="file" id="importFile" class="hidden" accept=".json">
                                    <button onclick="document.getElementById('importFile').click()" class="w-full bg-green-500 hover:bg-green-600 text-white px-4 py-2.5 rounded-lg flex items-center justify-center transition-colors">
                                        <i class="fas fa-file-import mr-2"></i> Import Data
                                    </button>
                                </label>
                                <button onclick="showConfirmation('Clear all data?', 'This will permanently delete all your transactions.', clearAllData)" class="w-full bg-red-500 hover:bg-red-600 text-white px-4 py-2.5 rounded-lg flex items-center justify-center transition-colors">
                                    <i class="fas fa-trash mr-2"></i> Clear All Data
                                </button>
                            </div>
                        </div>
                        
                        <div class="bg-white dark:bg-gray-800/50 p-5 rounded-xl border border-gray-200 dark:border-gray-700">
                            <h3 class="font-medium mb-4">About</h3>
                            <div class="space-y-2">
                                <p class="flex items-center">
                                    <i class="fas fa-info-circle mr-2 text-blue-500"></i>
                                    <span>FinTrack v1.0.0</span>
                                </p>
                                <p class="flex items-center text-sm text-gray-500 dark:text-gray-400">
                                    <i class="fas fa-mobile-alt mr-2"></i>
                                    <span>PWA - Works offline</span>
                                </p>
                                <p class="flex items-center text-sm text-gray-500 dark:text-gray-400">
                                    <i class="fas fa-database mr-2"></i>
                                    <span>Data stored locally</span>
                                </p>
                            </div>
                        </div>
                    </div>
                `;
            }

            function setupTransactionList() {
                document.getElementById('importFile').addEventListener('change', importData);
                document.getElementById('darkModeToggle').addEventListener('change', toggleDarkMode);
                document.getElementById('settingsCurrency').addEventListener('change', function() {
                    currencySymbol = this.value;
                    localStorage.setItem('currency', currencySymbol);
                    document.getElementById('currencySelect').value = currencySymbol;
                    document.getElementById('currencySymbol').textContent = currencySymbol;
                    loadTab(currentTab);
                });
            }

            function renderCharts() {
                const today = new Date();
                const currentMonth = today.getMonth();
                const currentYear = today.getFullYear();
                
                // Filter transactions for current month
                const monthlyTransactions = transactions.filter(t => {
                    const transactionDate = new Date(t.date);
                    return transactionDate.getMonth() === currentMonth && 
                           transactionDate.getFullYear() === currentYear;
                });
                
                // Income vs Expense Chart
                const incomeExpenseCtx = document.getElementById('incomeExpenseChart').getContext('2d');
                const income = monthlyTransactions.filter(t => t.type === 'income').reduce((sum, t) => sum + t.amount, 0);
                const expenses = monthlyTransactions.filter(t => t.type === 'expense').reduce((sum, t) => sum + t.amount, 0);
                
                new Chart(incomeExpenseCtx, {
                    type: 'bar',
                    data: {
                        labels: ['Income', 'Expenses'],
                        datasets: [{
                            label: 'Amount',
                            data: [income, expenses],
                            backgroundColor: [
                                'rgba(16, 185, 129, 0.7)',
                                'rgba(239, 68, 68, 0.7)'
                            ],
                            borderColor: [
                                'rgba(16, 185, 129, 1)',
                                'rgba(239, 68, 68, 1)'
                            ],
                            borderWidth: 1
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: {
                            legend: {
                                display: false
                            },
                            tooltip: {
                                callbacks: {
                                    label: function(context) {
                                        return `${context.dataset.label}: ${currencySymbol}${context.raw.toFixed(2)}`;
                                    }
                                }
                            }
                        },
                        scales: {
                            y: {
                                beginAtZero: true,
                                ticks: {
                                    callback: function(value) {
                                        return currencySymbol + value;
                                    }
                                }
                            }
                        }
                    }
                });
                
                // Expense Categories Chart
                const expenseCategoriesCtx = document.getElementById('expenseCategoriesChart').getContext('2d');
                const expenseCategories = {};
                monthlyTransactions
                    .filter(t => t.type === 'expense')
                    .forEach(t => {
                        expenseCategories[t.category] = (expenseCategories[t.category] || 0) + t.amount;
                    });
                
                const categoryLabels = Object.keys(expenseCategories);
                const categoryData = Object.values(expenseCategories);
                const categoryColors = [
                    'rgba(239, 68, 68, 0.7)',
                    'rgba(234, 88, 12, 0.7)',
                    'rgba(217, 119, 6, 0.7)',
                    'rgba(202, 138, 4, 0.7)',
                    'rgba(101, 163, 13, 0.7)',
                    'rgba(5, 150, 105, 0.7)',
                    'rgba(13, 148, 136, 0.7)',
                    'rgba(8, 145, 178, 0.7)'
                ];
                
                new Chart(expenseCategoriesCtx, {
                    type: 'doughnut',
                    data: {
                        labels: categoryLabels,
                        datasets: [{
                            data: categoryData,
                            backgroundColor: categoryColors,
                            borderWidth: 1
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: {
                            legend: {
                                position: 'right'
                            },
                            tooltip: {
                                callbacks: {
                                    label: function(context) {
                                        const value = context.raw;
                                        const total = context.dataset.data.reduce((a, b) => a + b, 0);
                                        const percentage = Math.round((value / total) * 100);
                                        return `${context.label}: ${currencySymbol}${value.toFixed(2)} (${percentage}%)`;
                                    }
                                }
                            }
                        }
                    }
                });
                
                // Monthly Summary Chart (last 6 months)
                const monthlySummaryCtx = document.getElementById('monthlySummaryChart').getContext('2d');
                const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
                const last6Months = [];
                
                for (let i = 5; i >= 0; i--) {
                    const date = new Date();
                    date.setMonth(date.getMonth() - i);
                    last6Months.push({
                        month: date.getMonth(),
                        year: date.getFullYear(),
                        label: `${monthNames[date.getMonth()]} ${date.getFullYear()}`
                    });
                }
                
                const monthlyIncomeData = last6Months.map(m => {
                    return transactions
                        .filter(t => {
                            const d = new Date(t.date);
                            return d.getMonth() === m.month && d.getFullYear() === m.year && t.type === 'income';
                        })
                        .reduce((sum, t) => sum + t.amount, 0);
                });
                
                const monthlyExpenseData = last6Months.map(m => {
                    return transactions
                        .filter(t => {
                            const d = new Date(t.date);
                            return d.getMonth() === m.month && d.getFullYear() === m.year && t.type === 'expense';
                        })
                        .reduce((sum, t) => sum + t.amount, 0);
                });
                
                new Chart(monthlySummaryCtx, {
                    type: 'line',
                    data: {
                        labels: last6Months.map(m => m.label),
                        datasets: [
                            {
                                label: 'Income',
                                data: monthlyIncomeData,
                                borderColor: 'rgba(16, 185, 129, 1)',
                                backgroundColor: 'rgba(16, 185, 129, 0.1)',
                                tension: 0.3,
                                fill: true
                            },
                            {
                                label: 'Expenses',
                                data: monthlyExpenseData,
                                borderColor: 'rgba(239, 68, 68, 1)',
                                backgroundColor: 'rgba(239, 68, 68, 0.1)',
                                tension: 0.3,
                                fill: true
                            }
                        ]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: {
                            tooltip: {
                                callbacks: {
                                    label: function(context) {
                                        return `${context.dataset.label}: ${currencySymbol}${context.raw.toFixed(2)}`;
                                    }
                                }
                            }
                        },
                        scales: {
                            y: {
                                beginAtZero: true,
                                ticks: {
                                    callback: function(value) {
                                        return currencySymbol + value;
                                    }
                                }
                            }
                        }
                    }
                });
                
                // Debt vs Credit Chart
                const debtCreditCtx = document.getElementById('debtCreditChart').getContext('2d');
                const debts = transactions.filter(t => t.type === 'debt').reduce((sum, t) => sum + t.amount, 0);
                const credits = transactions.filter(t => t.type === 'credit').reduce((sum, t) => sum + t.amount, 0);
                
                new Chart(debtCreditCtx, {
                    type: 'pie',
                    data: {
                        labels: ['Debts', 'Credits'],
                        datasets: [{
                            data: [debts, credits],
                            backgroundColor: [
                                'rgba(234, 179, 8, 0.7)',
                                'rgba(59, 130, 246, 0.7)'
                            ],
                            borderWidth: 1
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: {
                            tooltip: {
                                callbacks: {
                                    label: function(context) {
                                        return `${context.label}: ${currencySymbol}${context.raw.toFixed(2)}`;
                                    }
                                }
                            }
                        }
                    }
                });
            }

            function showModal() {
                document.getElementById('addTransactionModal').classList.remove('hidden');
                document.getElementById('transactionForm').reset();
                document.querySelectorAll('.type-btn').forEach(b => b.classList.remove('bg-green-500', 'bg-red-500', 'bg-yellow-500', 'bg-blue-500', 'text-white'));
                document.getElementById('date').valueAsDate = new Date();
                
                gsap.fromTo('#addTransactionModal > div', 
                    { opacity: 0, y: 50 }, 
                    { opacity: 1, y: 0, duration: 0.3, ease: "back.out" }
                );
            }

            function closeModal() {
                gsap.to('#addTransactionModal > div', {
                    opacity: 0, 
                    y: 50, 
                    duration: 0.2,
                    onComplete: () => {
                        document.getElementById('addTransactionModal').classList.add('hidden');
                    }
                });
            }

            function addTransaction(e) {
                e.preventDefault();
                
                const amount = parseFloat(document.getElementById('amount').value);
                const description = document.getElementById('description').value.trim();
                const category = document.getElementById('category').value;
                const date = document.getElementById('date').value;
                
                if (!selectedType || isNaN(amount) || amount <= 0 || !description || !date) {
                    showToast('Please fill all fields correctly', 'error');
                    return;
                }
                
                const transaction = {
                    type: selectedType,
                    amount: amount,
                    description: description,
                    category: category,
                    date: date
                };
                
                transactions.push(transaction);
                saveTransactions();
                closeModal();
                showToast('Transaction added successfully', 'success');
                loadTab(currentTab);
            }

            function deleteTransaction(index) {
                showConfirmation(
                    'Delete transaction?', 
                    'This will permanently delete this transaction.', 
                    () => {
                        transactions.splice(index, 1);
                        saveTransactions();
                        showToast('Transaction deleted', 'success');
                        loadTab(currentTab);
                    }
                );
            }

            function saveTransactions() {
                localStorage.setItem('transactions', JSON.stringify(transactions));
            }

            function showConfirmation(title, message, callback) {
                document.getElementById('confirmationTitle').textContent = title;
                document.getElementById('confirmationMessage').textContent = message;
                document.getElementById('confirmationModal').classList.remove('hidden');
                pendingAction = callback;
                
                gsap.fromTo('#confirmationModal > div', 
                    { opacity: 0, y: 50 }, 
                    { opacity: 1, y: 0, duration: 0.3, ease: "back.out" }
                );
            }

            function closeConfirmation() {
                gsap.to('#confirmationModal > div', {
                    opacity: 0, 
                    y: 50, 
                    duration: 0.2,
                    onComplete: () => {
                        document.getElementById('confirmationModal').classList.add('hidden');
                        pendingAction = null;
                    }
                });
            }

            function executeConfirmedAction() {
                if (pendingAction && typeof pendingAction === 'function') {
                    pendingAction();
                }
                closeConfirmation();
            }

            function clearAllData() {
                transactions = [];
                saveTransactions();
                showToast('All data cleared', 'success');
                loadTab(currentTab);
            }

            function exportData() {
                const dataStr = JSON.stringify(transactions, null, 2);
                const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr);
                
                const exportFileDefaultName = `fintrack-export-${new Date().toISOString().slice(0,10)}.json`;
                
                const linkElement = document.createElement('a');
                linkElement.setAttribute('href', dataUri);
                linkElement.setAttribute('download', exportFileDefaultName);
                linkElement.click();
                
                showToast('Data exported successfully', 'success');
            }

            function importData(e) {
                const file = e.target.files[0];
                if (!file) return;
                
                const reader = new FileReader();
                reader.onload = function(e) {
                    try {
                        const importedData = JSON.parse(e.target.result);
                        if (Array.isArray(importedData)) {
                            showConfirmation(
                                'Import transactions?', 
                                `This will add ${importedData.length} new transactions.`,
                                () => {
                                    transactions = [...transactions, ...importedData];
                                    saveTransactions();
                                    showToast(`${importedData.length} transactions imported`, 'success');
                                    loadTab(currentTab);
                                    e.target.value = ''; // Reset file input
                                }
                            );
                        } else {
                            showToast('Invalid data format', 'error');
                        }
                    } catch (error) {
                        showToast('Error parsing file', 'error');
                    }
                };
                reader.readAsText(file);
            }

            function showToast(message, type = 'success') {
                const toast = document.getElementById('toast');
                const toastMessage = document.getElementById('toastMessage');
                
                toastMessage.textContent = message;
                
                // Set toast color based on type
                if (type === 'error') {
                    toast.classList.remove('bg-gray-800');
                    toast.classList.add('bg-red-500');
                    toast.querySelector('i').className = 'fas fa-exclamation-circle mr-2';
                } else {
                    toast.classList.remove('bg-red-500');
                    toast.classList.add('bg-gray-800');
                    toast.querySelector('i').className = 'fas fa-check-circle mr-2 text-green-400';
                }
                
                // Show toast
                toast.classList.remove('hidden');
                gsap.fromTo(toast, 
                    { opacity: 0, y: 20 }, 
                    { opacity: 1, y: 0, duration: 0.3 }
                );
                
                // Hide toast after 3 seconds
                setTimeout(() => {
                    gsap.to(toast, {
                        opacity: 0, 
                        y: 20, 
                        duration: 0.3,
                        onComplete: () => {
                            toast.classList.add('hidden');
                        }
                    });
                }, 3000);
            }

            // Make functions available globally for inline event handlers
            window.loadTab = loadTab;
            window.showModal = showModal;
            window.deleteTransaction = deleteTransaction;
            window.showConfirmation = showConfirmation;
            window.clearAllData = clearAllData;
            window.exportData = exportData;
            window.importData = importData;
            window.showToast = showToast;
        });

        // Service worker registration (would be in a separate sw.js file)
        // This is just a placeholder for the PWA functionality
        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>
<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=dervanbey/fintrack" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>