File size: 38,750 Bytes
e131a76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ExamTrack - Test Tracker</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#4F46E5',
                        secondary: '#10B981',
                        danger: '#EF4444',
                        warning: '#F59E0B'
                    }
                }
            }
        }
    </script>
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #4F46E5 0%, #10B981 100%);
        }
        .progress-bar {
            transition: width 0.5s ease-in-out;
        }
        .fade-in {
            animation: fadeIn 0.3s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <!-- Header -->
    <header class="gradient-bg text-white shadow-lg">
        <div class="container mx-auto px-4 py-6">
            <div class="flex justify-between items-center">
                <div class="flex items-center space-x-2">
                    <i class="fas fa-book-open text-2xl"></i>
                    <h1 class="text-2xl font-bold">ExamTrack</h1>
                </div>
                <div class="flex items-center space-x-4">
                    <button id="theme-toggle" class="p-2 rounded-full bg-white bg-opacity-10 hover:bg-opacity-20 transition">
                        <i class="fas fa-moon"></i>
                    </button>
                    <div class="relative">
                        <img src="https://ui-avatars.com/api/?name=User&background=random" alt="User" class="w-10 h-10 rounded-full cursor-pointer">
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="container mx-auto px-4 py-8">
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            <!-- Left Column -->
            <div class="lg:col-span-2 space-y-6">
                <!-- Add Test Form -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all duration-300 card-hover">
                    <div class="p-6">
                        <h2 class="text-xl font-semibold text-gray-800 mb-4">Add New Test</h2>
                        <form id="add-test-form" class="space-y-4">
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                <div>
                                    <label for="test-name" class="block text-sm font-medium text-gray-700 mb-1">Test Name</label>
                                    <input type="text" id="test-name" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="e.g. Biology Midterm" required>
                                </div>
                                <div>
                                    <label for="test-subject" class="block text-sm font-medium text-gray-700 mb-1">Subject</label>
                                    <input type="text" id="test-subject" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="e.g. Biology" required>
                                </div>
                            </div>
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                <div>
                                    <label for="test-date" class="block text-sm font-medium text-gray-700 mb-1">Test Date</label>
                                    <input type="date" id="test-date" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" required>
                                </div>
                                <div>
                                    <label for="study-days" class="block text-sm font-medium text-gray-700 mb-1">Days Needed to Study</label>
                                    <input type="number" id="study-days" min="1" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="e.g. 14" required>
                                </div>
                            </div>
                            <div>
                                <label for="test-notes" class="block text-sm font-medium text-gray-700 mb-1">Notes</label>
                                <textarea id="test-notes" rows="2" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="Any important details..."></textarea>
                            </div>
                            <div class="flex justify-end">
                                <button type="submit" class="px-6 py-2 bg-primary text-white font-medium rounded-lg hover:bg-opacity-90 transition flex items-center space-x-2">
                                    <i class="fas fa-plus"></i>
                                    <span>Add Test</span>
                                </button>
                            </div>
                        </form>
                    </div>
                </div>

                <!-- Upcoming Tests -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all duration-300 card-hover">
                    <div class="p-6">
                        <div class="flex justify-between items-center mb-4">
                            <h2 class="text-xl font-semibold text-gray-800">Upcoming Tests</h2>
                            <div class="flex space-x-2">
                                <button id="sort-date" class="px-3 py-1 text-sm bg-gray-100 rounded-lg hover:bg-gray-200 transition">Sort by Date</button>
                                <button id="sort-priority" class="px-3 py-1 text-sm bg-gray-100 rounded-lg hover:bg-gray-200 transition">Sort by Priority</button>
                            </div>
                        </div>
                        <div id="upcoming-tests" class="space-y-4">
                            <!-- Test items will be added here dynamically -->
                            <div class="text-center py-8 text-gray-500" id="no-tests-message">
                                <i class="fas fa-calendar-check text-4xl mb-3"></i>
                                <p>No upcoming tests. Add a test to get started!</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Right Column -->
            <div class="space-y-6">
                <!-- Study Timeline -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all duration-300 card-hover">
                    <div class="p-6">
                        <h2 class="text-xl font-semibold text-gray-800 mb-4">Study Timeline</h2>
                        <div id="study-timeline" class="space-y-4">
                            <div class="text-center py-8 text-gray-500">
                                <i class="fas fa-clock text-4xl mb-3"></i>
                                <p>Add a test to see your study timeline</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Progress Stats -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all duration-300 card-hover">
                    <div class="p-6">
                        <h2 class="text-xl font-semibold text-gray-800 mb-4">Your Progress</h2>
                        <div class="space-y-4">
                            <div>
                                <div class="flex justify-between mb-1">
                                    <span class="text-sm font-medium text-gray-700">Tests Completed</span>
                                    <span class="text-sm font-medium text-gray-700" id="completed-count">0</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div id="completed-bar" class="bg-secondary h-2.5 rounded-full progress-bar" style="width: 0%"></div>
                                </div>
                            </div>
                            <div>
                                <div class="flex justify-between mb-1">
                                    <span class="text-sm font-medium text-gray-700">Tests Pending</span>
                                    <span class="text-sm font-medium text-gray-700" id="pending-count">0</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div id="pending-bar" class="bg-warning h-2.5 rounded-full progress-bar" style="width: 0%"></div>
                                </div>
                            </div>
                            <div>
                                <div class="flex justify-between mb-1">
                                    <span class="text-sm font-medium text-gray-700">Study Days Remaining</span>
                                    <span class="text-sm font-medium text-gray-700" id="study-days-remaining">0</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div id="study-days-bar" class="bg-primary h-2.5 rounded-full progress-bar" style="width: 0%"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Quick Actions -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all duration-300 card-hover">
                    <div class="p-6">
                        <h2 class="text-xl font-semibold text-gray-800 mb-4">Quick Actions</h2>
                        <div class="grid grid-cols-2 gap-3">
                            <button id="mark-completed" class="p-3 bg-green-50 text-green-700 rounded-lg hover:bg-green-100 transition flex flex-col items-center">
                                <i class="fas fa-check-circle text-2xl mb-1"></i>
                                <span class="text-sm">Mark Completed</span>
                            </button>
                            <button id="add-reminder" class="p-3 bg-blue-50 text-blue-700 rounded-lg hover:bg-blue-100 transition flex flex-col items-center">
                                <i class="fas fa-bell text-2xl mb-1"></i>
                                <span class="text-sm">Add Reminder</span>
                            </button>
                            <button id="export-data" class="p-3 bg-purple-50 text-purple-700 rounded-lg hover:bg-purple-100 transition flex flex-col items-center">
                                <i class="fas fa-file-export text-2xl mb-1"></i>
                                <span class="text-sm">Export Data</span>
                            </button>
                            <button id="import-data" class="p-3 bg-yellow-50 text-yellow-700 rounded-lg hover:bg-yellow-100 transition flex flex-col items-center">
                                <i class="fas fa-file-import text-2xl mb-1"></i>
                                <span class="text-sm">Import Data</span>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <!-- Modal -->
    <div id="test-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 mx-4 fade-in">
            <div class="p-6">
                <div class="flex justify-between items-center mb-4">
                    <h3 id="modal-title" class="text-xl font-semibold text-gray-800">Test Details</h3>
                    <button id="close-modal" class="text-gray-500 hover:text-gray-700">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
                <div id="modal-content" class="space-y-4">
                    <!-- Content will be filled dynamically -->
                </div>
            </div>
        </div>
    </div>

    <script>
        // Sample data structure
        let tests = JSON.parse(localStorage.getItem('tests')) || [];
        let completedTests = JSON.parse(localStorage.getItem('completedTests')) || [];

        // DOM Elements
        const addTestForm = document.getElementById('add-test-form');
        const upcomingTestsContainer = document.getElementById('upcoming-tests');
        const noTestsMessage = document.getElementById('no-tests-message');
        const studyTimelineContainer = document.getElementById('study-timeline');
        const completedCount = document.getElementById('completed-count');
        const pendingCount = document.getElementById('pending-count');
        const studyDaysRemaining = document.getElementById('study-days-remaining');
        const completedBar = document.getElementById('completed-bar');
        const pendingBar = document.getElementById('pending-bar');
        const studyDaysBar = document.getElementById('study-days-bar');
        const testModal = document.getElementById('test-modal');
        const closeModal = document.getElementById('close-modal');
        const modalTitle = document.getElementById('modal-title');
        const modalContent = document.getElementById('modal-content');
        const themeToggle = document.getElementById('theme-toggle');
        const sortDateBtn = document.getElementById('sort-date');
        const sortPriorityBtn = document.getElementById('sort-priority');

        // Initialize the app
        document.addEventListener('DOMContentLoaded', () => {
            renderTests();
            updateStats();
            checkDarkModePreference();

            // Set minimum date to today
            const today = new Date().toISOString().split('T')[0];
            document.getElementById('test-date').min = today;
        });

        // Event Listeners
        addTestForm.addEventListener('submit', handleAddTest);
        closeModal.addEventListener('click', () => testModal.classList.add('hidden'));
        themeToggle.addEventListener('click', toggleDarkMode);
        sortDateBtn.addEventListener('click', () => sortTests('date'));
        sortPriorityBtn.addEventListener('click', () => sortTests('priority'));

        // Functions
        function handleAddTest(e) {
            e.preventDefault();
            
            const testName = document.getElementById('test-name').value;
            const testSubject = document.getElementById('test-subject').value;
            const testDate = document.getElementById('test-date').value;
            const studyDays = parseInt(document.getElementById('study-days').value);
            const testNotes = document.getElementById('test-notes').value;
            
            const studyStartDate = calculateStudyStartDate(testDate, studyDays);
            
            const newTest = {
                id: Date.now(),
                name: testName,
                subject: testSubject,
                date: testDate,
                studyDays: studyDays,
                studyStartDate: studyStartDate,
                notes: testNotes,
                priority: calculatePriority(testDate, studyDays),
                completed: false
            };
            
            tests.push(newTest);
            saveTests();
            renderTests();
            updateStats();
            
            // Reset form
            addTestForm.reset();
            
            // Show success message
            showToast('Test added successfully!', 'success');
        }

        function calculateStudyStartDate(testDate, studyDays) {
            const date = new Date(testDate);
            date.setDate(date.getDate() - studyDays);
            return date.toISOString().split('T')[0];
        }

        function calculatePriority(testDate, studyDays) {
            const today = new Date();
            const testDateObj = new Date(testDate);
            const daysUntilTest = Math.ceil((testDateObj - today) / (1000 * 60 * 60 * 24));
            
            if (daysUntilTest <= studyDays) {
                return 'high'; // Should have started studying already
            } else if (daysUntilTest <= studyDays + 7) {
                return 'medium'; // Should start studying soon
            } else {
                return 'low'; // Plenty of time
            }
        }

        function renderTests() {
            if (tests.length === 0) {
                noTestsMessage.classList.remove('hidden');
                upcomingTestsContainer.innerHTML = '';
                upcomingTestsContainer.appendChild(noTestsMessage);
                renderStudyTimeline();
                return;
            }
            
            noTestsMessage.classList.add('hidden');
            upcomingTestsContainer.innerHTML = '';
            
            // Sort tests by date (soonest first)
            const sortedTests = [...tests].sort((a, b) => new Date(a.date) - new Date(b.date));
            
            sortedTests.forEach(test => {
                const testElement = createTestElement(test);
                upcomingTestsContainer.appendChild(testElement);
            });
            
            renderStudyTimeline();
        }

        function createTestElement(test) {
            const today = new Date();
            const testDate = new Date(test.date);
            const daysUntilTest = Math.ceil((testDate - today) / (1000 * 60 * 60 * 24));
            const studyStartDate = new Date(test.studyStartDate);
            const daysUntilStudy = Math.ceil((studyStartDate - today) / (1000 * 60 * 60 * 24));
            
            const testElement = document.createElement('div');
            testElement.className = 'bg-gray-50 rounded-lg p-4 border border-gray-200 fade-in';
            testElement.dataset.id = test.id;
            
            let priorityBadge = '';
            if (test.priority === 'high') {
                priorityBadge = '<span class="px-2 py-1 text-xs font-semibold bg-danger text-white rounded-full">High Priority</span>';
            } else if (test.priority === 'medium') {
                priorityBadge = '<span class="px-2 py-1 text-xs font-semibold bg-warning text-white rounded-full">Medium Priority</span>';
            } else {
                priorityBadge = '<span class="px-2 py-1 text-xs font-semibold bg-secondary text-white rounded-full">Low Priority</span>';
            }
            
            testElement.innerHTML = `
                <div class="flex justify-between items-start mb-2">
                    <h3 class="font-semibold text-gray-800">${test.name}</h3>
                    ${priorityBadge}
                </div>
                <div class="flex items-center text-sm text-gray-600 mb-2">
                    <i class="fas fa-book mr-2"></i>
                    <span>${test.subject}</span>
                </div>
                <div class="flex items-center text-sm text-gray-600 mb-3">
                    <i class="fas fa-calendar-day mr-2"></i>
                    <span>${formatDate(test.date)} (${daysUntilTest} ${daysUntilTest === 1 ? 'day' : 'days'} away)</span>
                </div>
                <div class="flex justify-between items-center">
                    <button class="view-details px-3 py-1 text-sm bg-primary text-white rounded-lg hover:bg-opacity-90 transition">
                        View Details
                    </button>
                    <div class="flex space-x-2">
                        <button class="edit-test p-2 text-gray-500 hover:text-primary transition">
                            <i class="fas fa-edit"></i>
                        </button>
                        <button class="delete-test p-2 text-gray-500 hover:text-danger transition">
                            <i class="fas fa-trash-alt"></i>
                        </button>
                    </div>
                </div>
            `;
            
            // Add event listeners to buttons
            testElement.querySelector('.view-details').addEventListener('click', () => showTestDetails(test));
            testElement.querySelector('.edit-test').addEventListener('click', (e) => {
                e.stopPropagation();
                editTest(test.id);
            });
            testElement.querySelector('.delete-test').addEventListener('click', (e) => {
                e.stopPropagation();
                deleteTest(test.id);
            });
            
            return testElement;
        }

        function renderStudyTimeline() {
            if (tests.length === 0) {
                studyTimelineContainer.innerHTML = `
                    <div class="text-center py-8 text-gray-500">
                        <i class="fas fa-clock text-4xl mb-3"></i>
                        <p>Add a test to see your study timeline</p>
                    </div>
                `;
                return;
            }
            
            // Sort tests by study start date (earliest first)
            const sortedTests = [...tests].sort((a, b) => new Date(a.studyStartDate) - new Date(b.studyStartDate));
            
            studyTimelineContainer.innerHTML = '';
            
            sortedTests.forEach(test => {
                const today = new Date();
                const studyStartDate = new Date(test.studyStartDate);
                const daysUntilStudy = Math.ceil((studyStartDate - today) / (1000 * 60 * 60 * 24));
                
                const timelineItem = document.createElement('div');
                timelineItem.className = 'fade-in';
                
                timelineItem.innerHTML = `
                    <div class="flex items-start">
                        <div class="flex flex-col items-center mr-3">
                            <div class="w-8 h-8 rounded-full bg-primary flex items-center justify-center text-white">
                                <i class="fas fa-book text-sm"></i>
                            </div>
                            <div class="w-0.5 h-12 bg-gray-200 mt-1"></div>
                        </div>
                        <div class="flex-1 pt-1">
                            <h4 class="font-medium text-gray-800">${test.name}</h4>
                            <p class="text-sm text-gray-600 mb-1">${test.subject}</p>
                            <div class="flex items-center text-sm ${daysUntilStudy <= 0 ? 'text-danger' : 'text-gray-500'}">
                                <i class="fas fa-calendar-day mr-1"></i>
                                <span>Start studying ${formatDate(test.studyStartDate)} (${daysUntilStudy <= 0 ? 'Start now!' : daysUntilStudy + ' days'})</span>
                            </div>
                        </div>
                    </div>
                `;
                
                studyTimelineContainer.appendChild(timelineItem);
            });
        }

        function showTestDetails(test) {
            const today = new Date();
            const testDate = new Date(test.date);
            const daysUntilTest = Math.ceil((testDate - today) / (1000 * 60 * 60 * 24));
            const studyStartDate = new Date(test.studyStartDate);
            const daysUntilStudy = Math.ceil((studyStartDate - today) / (1000 * 60 * 60 * 24));
            
            modalTitle.textContent = test.name;
            
            let priorityText = '';
            if (test.priority === 'high') {
                priorityText = 'High Priority - Start studying now!';
            } else if (test.priority === 'medium') {
                priorityText = 'Medium Priority - Start studying soon';
            } else {
                priorityText = 'Low Priority - You have plenty of time';
            }
            
            modalContent.innerHTML = `
                <div class="space-y-4">
                    <div class="flex items-center text-gray-700">
                        <i class="fas fa-book mr-3 w-5 text-center"></i>
                        <span>Subject: ${test.subject}</span>
                    </div>
                    <div class="flex items-center text-gray-700">
                        <i class="fas fa-calendar-day mr-3 w-5 text-center"></i>
                        <span>Test Date: ${formatDate(test.date)} (${daysUntilTest} ${daysUntilTest === 1 ? 'day' : 'days'} away)</span>
                    </div>
                    <div class="flex items-center text-gray-700">
                        <i class="fas fa-clock mr-3 w-5 text-center"></i>
                        <span>Study Days Needed: ${test.studyDays}</span>
                    </div>
                    <div class="flex items-center ${test.priority === 'high' ? 'text-danger' : test.priority === 'medium' ? 'text-warning' : 'text-secondary'}">
                        <i class="fas fa-exclamation-circle mr-3 w-5 text-center"></i>
                        <span>${priorityText}</span>
                    </div>
                    <div class="flex items-center text-gray-700">
                        <i class="fas fa-calendar-check mr-3 w-5 text-center"></i>
                        <span>Start Studying: ${formatDate(test.studyStartDate)} (${daysUntilStudy <= 0 ? 'Start now!' : daysUntilStudy + ' days'})</span>
                    </div>
                    ${test.notes ? `
                    <div>
                        <h4 class="font-medium text-gray-800 mb-1">Notes:</h4>
                        <p class="text-gray-700 bg-gray-50 p-3 rounded-lg">${test.notes}</p>
                    </div>
                    ` : ''}
                    <div class="pt-4 flex justify-between">
                        <button id="mark-as-completed" class="px-4 py-2 bg-secondary text-white rounded-lg hover:bg-opacity-90 transition">
                            Mark as Completed
                        </button>
                        <button id="add-reminder-btn" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-opacity-90 transition">
                            <i class="fas fa-bell mr-1"></i> Add Reminder
                        </button>
                    </div>
                </div>
            `;
            
            // Add event listeners to modal buttons
            document.getElementById('mark-as-completed').addEventListener('click', () => {
                markTestAsCompleted(test.id);
                testModal.classList.add('hidden');
            });
            
            document.getElementById('add-reminder-btn').addEventListener('click', () => {
                addReminderForTest(test);
                testModal.classList.add('hidden');
            });
            
            testModal.classList.remove('hidden');
        }

        function editTest(testId) {
            const test = tests.find(t => t.id === testId);
            if (!test) return;
            
            modalTitle.textContent = `Edit ${test.name}`;
            
            modalContent.innerHTML = `
                <form id="edit-test-form" class="space-y-4">
                    <div>
                        <label for="edit-test-name" class="block text-sm font-medium text-gray-700 mb-1">Test Name</label>
                        <input type="text" id="edit-test-name" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" value="${test.name}" required>
                    </div>
                    <div>
                        <label for="edit-test-subject" class="block text-sm font-medium text-gray-700 mb-1">Subject</label>
                        <input type="text" id="edit-test-subject" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" value="${test.subject}" required>
                    </div>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div>
                            <label for="edit-test-date" class="block text-sm font-medium text-gray-700 mb-1">Test Date</label>
                            <input type="date" id="edit-test-date" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" value="${test.date}" required>
                        </div>
                        <div>
                            <label for="edit-study-days" class="block text-sm font-medium text-gray-700 mb-1">Days Needed to Study</label>
                            <input type="number" id="edit-study-days" min="1" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" value="${test.studyDays}" required>
                        </div>
                    </div>
                    <div>
                        <label for="edit-test-notes" class="block text-sm font-medium text-gray-700 mb-1">Notes</label>
                        <textarea id="edit-test-notes" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent">${test.notes || ''}</textarea>
                    </div>
                    <div class="flex justify-between pt-2">
                        <button type="button" id="cancel-edit" class="px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-100 transition">
                            Cancel
                        </button>
                        <button type="submit" class="px-6 py-2 bg-primary text-white font-medium rounded-lg hover:bg-opacity-90 transition">
                            Save Changes
                        </button>
                    </div>
                </form>
            `;
            
            const editForm = document.getElementById('edit-test-form');
            const cancelEdit = document.getElementById('cancel-edit');
            
            editForm.addEventListener('submit', (e) => {
                e.preventDefault();
                
                test.name = document.getElementById('edit-test-name').value;
                test.subject = document.getElementById('edit-test-subject').value;
                test.date = document.getElementById('edit-test-date').value;
                test.studyDays = parseInt(document.getElementById('edit-study-days').value);
                test.notes = document.getElementById('edit-test-notes').value;
                test.studyStartDate = calculateStudyStartDate(test.date, test.studyDays);
                test.priority = calculatePriority(test.date, test.studyDays);
                
                saveTests();
                renderTests();
                updateStats();
                testModal.classList.add('hidden');
                
                showToast('Test updated successfully!', 'success');
            });
            
            cancelEdit.addEventListener('click', () => {
                testModal.classList.add('hidden');
            });
            
            testModal.classList.remove('hidden');
        }

        function deleteTest(testId) {
            if (confirm('Are you sure you want to delete this test?')) {
                tests = tests.filter(test => test.id !== testId);
                saveTests();
                renderTests();
                updateStats();
                showToast('Test deleted successfully!', 'success');
            }
        }

        function markTestAsCompleted(testId) {
            const testIndex = tests.findIndex(t => t.id === testId);
            if (testIndex === -1) return;
            
            const completedTest = tests[testIndex];
            completedTest.completed = true;
            completedTest.completedDate = new Date().toISOString().split('T')[0];
            
            tests.splice(testIndex, 1);
            completedTests.push(completedTest);
            
            saveTests();
            saveCompletedTests();
            renderTests();
            updateStats();
            
            showToast('Test marked as completed!', 'success');
        }

        function addReminderForTest(test) {
            // In a real app, this would integrate with a calendar API
            alert(`Reminder added for ${test.name} on ${formatDate(test.studyStartDate)}`);
            showToast('Reminder added to your calendar!', 'success');
        }

        function sortTests(criteria) {
            if (criteria === 'date') {
                tests.sort((a, b) => new Date(a.date) - new Date(b.date));
                showToast('Tests sorted by date', 'info');
            } else if (criteria === 'priority') {
                const priorityOrder = { 'high': 1, 'medium': 2, 'low': 3 };
                tests.sort((a, b) => priorityOrder[a.priority] - priorityOrder[b.priority]);
                showToast('Tests sorted by priority', 'info');
            }
            
            renderTests();
        }

        function updateStats() {
            const totalTests = tests.length + completedTests.length;
            const completedPercentage = totalTests > 0 ? Math.round((completedTests.length / totalTests) * 100) : 0;
            const pendingPercentage = totalTests > 0 ? Math.round((tests.length / totalTests) * 100) : 0;
            
            // Calculate total study days remaining across all tests
            const today = new Date();
            let totalStudyDaysRemaining = 0;
            let activeStudyDays = 0;
            
            tests.forEach(test => {
                const studyStartDate = new Date(test.studyStartDate);
                const daysUntilStudy = Math.ceil((studyStartDate - today) / (1000 * 60 * 60 * 24));
                
                if (daysUntilStudy <= 0) {
                    activeStudyDays += test.studyDays;
                } else {
                    totalStudyDaysRemaining += daysUntilStudy;
                }
            });
            
            // Calculate a progress percentage for study days
            const totalStudyDays = activeStudyDays + totalStudyDaysRemaining;
            const studyDaysPercentage = totalStudyDays > 0 ? Math.round((activeStudyDays / totalStudyDays) * 100) : 0;
            
            // Update DOM
            completedCount.textContent = `${completedTests.length} / ${totalTests}`;
            pendingCount.textContent = `${tests.length} / ${totalTests}`;
            studyDaysRemaining.textContent = `${totalStudyDaysRemaining} days`;
            
            // Animate progress bars
            setTimeout(() => {
                completedBar.style.width = `${completedPercentage}%`;
                pendingBar.style.width = `${pendingPercentage}%`;
                studyDaysBar.style.width = `${studyDaysPercentage}%`;
            }, 100);
        }

        function saveTests() {
            localStorage.setItem('tests', JSON.stringify(tests));
        }

        function saveCompletedTests() {
            localStorage.setItem('completedTests', JSON.stringify(completedTests));
        }

        function formatDate(dateString) {
            const options = { year: 'numeric', month: 'short', day: 'numeric' };
            return new Date(dateString).toLocaleDateString(undefined, options);
        }

        function showToast(message, type) {
            const toast = document.createElement('div');
            toast.className = `fixed bottom-4 right-4 px-6 py-3 rounded-lg shadow-lg text-white font-medium flex items-center space-x-2 fade-in ${
                type === 'success' ? 'bg-secondary' : 
                type === 'error' ? 'bg-danger' : 
                'bg-primary'
            }`;
            
            toast.innerHTML = `
                <i class="fas ${type === 'success' ? 'fa-check-circle' : type === 'error' ? 'fa-exclamation-circle' : 'fa-info-circle'}"></i>
                <span>${message}</span>
            `;
            
            document.body.appendChild(toast);
            
            setTimeout(() => {
                toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
                setTimeout(() => toast.remove(), 300);
            }, 3000);
        }

        function toggleDarkMode() {
            const html = document.documentElement;
            const isDark = html.classList.toggle('dark');
            
            localStorage.setItem('darkMode', isDark);
            
            if (isDark) {
                themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
            } else {
                themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
            }
        }

        function checkDarkModePreference() {
            const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
            const storedPreference = localStorage.getItem('darkMode');
            
            if (storedPreference === 'true' || (storedPreference === null && prefersDark)) {
                document.documentElement.classList.add('dark');
                themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
            }
        }
    </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=Administrator4321/test-tracker" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>