File size: 48,188 Bytes
0dff816
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start session and check if user is logged in
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}

if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
    header('Location: ../../index.php');
    exit;
}

// Database connection
require_once '../../config.php';

// Function to get package details
function getPackageDetails($package_id) {
    global $pdo;
    try {
        $stmt = $pdo->prepare("SELECT * FROM packages WHERE id = ?");
        $stmt->execute([$package_id]);
        return $stmt->fetch(PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
        error_log("Error getting package details: " . $e->getMessage());
        return false;
    }
}

// Function to get all packages
function getAllPackages() {
    global $pdo;
    try {
        $stmt = $pdo->prepare("SELECT * FROM packages ORDER BY min_investment ASC");
        $stmt->execute();
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
        error_log("Error getting all packages: " . $e->getMessage());
        return [];
    }
}

// Function to get user's active investment
function getUserActiveInvestment($user_id) {
    global $pdo;
    try {
        $stmt = $pdo->prepare("
            SELECT ui.*, p.name as package_name, p.daily_return, p.duration_days 
            FROM user_investments ui 
            JOIN packages p ON ui.package_id = p.id 
            WHERE ui.user_id = ? AND ui.status = 'active' AND ui.end_date > NOW() 
            ORDER BY ui.amount DESC 
            LIMIT 1
        ");
        $stmt->execute([$user_id]);
        return $stmt->fetch(PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
        error_log("Error getting user active investment: " . $e->getMessage());
        return false;
    }
}

// Get user data from session
$username = $_SESSION['username'];
$email = $_SESSION['email'];
$tier = $_SESSION['tier'];
$package = $_SESSION['package'];
$balance = $_SESSION['balance'];
$total_deposits = $_SESSION['total_deposits'];
$total_withdrawals = $_SESSION['total_withdrawals'];
$rewards = $_SESSION['rewards'];
$earnings = $total_deposits - $total_withdrawals;
$user_id = $_SESSION['user_id'];

// Get currency settings (default to KES if not set)
$currency = isset($_SESSION['currency']) ? $_SESSION['currency'] : 'KES';
$currency_symbol = 'KSh';
$exchange_rate = 1;

// Set exchange rates and symbols based on currency
if ($currency === 'USD') {
    $currency_symbol = '$';
    $exchange_rate = 0.0078; // 1 KES = 0.0078 USD
} elseif ($currency === 'EUR') {
    $currency_symbol = '€';
    $exchange_rate = 0.0072; // 1 KES = 0.0072 EUR
} elseif ($currency === 'GBP') {
    $currency_symbol = '£';
    $exchange_rate = 0.0062; // 1 KES = 0.0062 GBP
}

// Package configurations
$package_configs = [
    'Nova' => [
        'min_investment' => 1000,
        'max_investment' => 50000,
        'daily_return' => 5,
        'duration_days' => 7,
        'features' => 'Basic Support,2% Referral Bonus'
    ],
    'Superior' => [
        'min_investment' => 2500,
        'max_investment' => 100000,
        'daily_return' => 7,
        'duration_days' => 14,
        'features' => 'Standard Support,3% Referral Bonus,Priority Withdrawal'
    ],
    'Gold' => [
        'min_investment' => 5500,
        'max_investment' => 250000,
        'daily_return' => 10,
        'duration_days' => 21,
        'features' => 'Priority Support,5% Referral Bonus,Instant Withdrawal,Advanced Tools'
    ],
    'Diamond' => [
        'min_investment' => 10000,
        'max_investment' => 500000,
        'daily_return' => 15,
        'duration_days' => 30,
        'features' => '24/7 Dedicated Support,7% Referral Bonus,Instant Withdrawal,All Advanced Tools'
    ]
];

// Convert package amounts to selected currency
foreach ($package_configs as $name => $config) {
    $package_configs[$name]['min_investment'] = $config['min_investment'] * $exchange_rate;
    $package_configs[$name]['max_investment'] = $config['max_investment'] * $exchange_rate;
}

// Get all available packages from database
$packages = getAllPackages();

// Get user's active investment
$active_investment = getUserActiveInvestment($user_id);

// Map package names to IDs for JavaScript
$package_ids = [];
foreach ($packages as $pkg) {
    $package_ids[strtolower($pkg['name'])] = $pkg['id'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Japanese Motors — Packages</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700;800&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <style>
        :root {
            --bg: #7b848d;
            --card: #7a2f3b;
            --card-2: #6f2630;
            --accent: #efdf2d;
            --muted: rgba(255,255,255,0.6);
            --glass: rgba(255,255,255,0.04);
            --promo-gradient: linear-gradient(180deg,#a13df0 0%, #ff2a79 50%, #d70b1a 100%);
            font-family: 'Poppins', system-ui, Arial;
            --banner-gradient-start: #a855f7;
            --banner-gradient-end: #ec4899;
            --spacing-unit: 1rem;
            --accent-primary: #7c3aed;
            --accent-secondary: #a855f7;
            --shadow-hover: 0 6px 18px rgba(0, 0, 0, 0.1);
            --premium-gold: #d97706;
        }
        
        body {
            background: var(--bg);
            font-family: 'Poppins', sans-serif;
            transition: all 0.3s ease;
            min-height: 100vh;
        }
        
        .sidebar {
            width: 250px;
            height: 100vh;
            background: #0d1321;
            color: #fff;
            position: fixed;
            top: 0;
            left: -250px;
            transition: all 0.3s ease;
            z-index: 1000;
            overflow-y: auto;
        }
        
        .sidebar.active {
            left: 0;
        }
        
        #content {
            margin-left: 0;
            transition: all 0.3s ease;
        }
        
        .sidebar.active ~ #content {
            margin-left: 250px;
        }
        
        header {
            background: #222;
            color: white;
            padding: 15px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: relative;
            z-index: 900;
            transition: all 0.3s ease;
        }
        
        .sidebar.active ~ #content header {
            margin-left: 250px;
        }
        
        .menu-toggle {
            background: transparent;
            border: none;
            color: white;
            font-size: 1.5rem;
            cursor: pointer;
        }
        
        .logo-section {
            padding: 15px;
            border-bottom: 1px solid #1c2230;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .brand {
            font-size: 1.2rem;
            font-weight: 700;
            color: #ff9800;
        }
        
        .subtitle {
            font-size: 0.75rem;
            color: #aaa;
        }
        
        .menu {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .faq-toggle {
            transition: transform 0.3s ease;
        }
        
        .menu li a {
            display: flex;
            align-items: center;
            padding: 12px 20px;
            color: white;
            text-decoration: none;
            transition: background 0.3s;
        }
        
        .menu li a:hover {
            background: #1c2230;
        }
        
        .menu li a i {
            margin-right: 12px;
        }
        
        .user-footer {
            padding: 15px;
            background: #222;
            display: flex;
            align-items: center;
            gap: 10px;
            position: sticky;
            bottom: 0;
        }
        
        .avatar {
            width: 35px;
            height: 35px;
            background: #444;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            color: white;
        }
        
        .banner {
            max-width: 450px;
            margin: 0 auto calc(var(--spacing-unit) * 2);
            background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
            border-radius: 12px;
            padding: calc(var(--spacing-unit) * 1.5);
            text-align: center;
            box-shadow: var(--shadow-hover);
            animation: fadeIn 0.5s ease;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes blink {
            0% { opacity: 1; }
            50% { opacity: 0.3; }
            100% { opacity: 1; }
        }

        .banner .title {
            font-size: 1.25rem;
            margin-bottom: calc(var(--spacing-unit) * 1);
            color: #ffffff;
            font-weight: 700;
            animation: blink 1.5s infinite;
        }

        .banner p {
            font-size: 0.95rem;
            line-height: 1.6;
            margin-bottom: calc(var(--spacing-unit) * 1);
            color: var(--premium-gold);
            animation: blink 1.5s infinite;
        }

        .banner .footer {
            font-size: 0.75rem;
            color: rgba(255, 255, 255, 0.9);
            font-style: italic;
            animation: blink 1.5s infinite;
        }
        
        .card {
            background: var(--card);
            border-radius: 12px;
            padding: 26px;
            color: white;
            box-shadow: 0 6px 0 rgba(0,0,0,0.08) inset;
            flex: 1;
        }
        
        .balance {
            background: rgba(255,255,255,0.03);
            padding: 14px;
            border-radius: 10px;
            margin: 18px 0;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .form-group {
            margin: 12px 0;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            color: rgba(255,255,255,0.85);
        }
        
        input, select, textarea {
            width: 100%;
            padding: 14px;
            border-radius: 10px;
            border: 1px solid rgba(255,255,255,0.05);
            background: transparent;
            color: white;
        }
        
        .btn {
            display: inline-block;
            padding: 14px 24px;
            border-radius: 10px;
            background: var(--accent);
            color: #111;
            font-weight: 700;
            border: none;
            cursor: pointer;
            width: 100%;
        }
        
        .btn-outline {
            background: transparent;
            border: 2px solid var(--accent);
            color: var(--accent);
        }
        
        .btn-sm {
            padding: 8px 16px;
            font-size: 0.875rem;
        }
        
        .btn-success {
            background: #10B981;
            color: white;
        }
        
        .btn-primary {
            background: #3B82F6;
            color: white;
        }
        
        .btn-premium {
            background: linear-gradient(135deg, #8B5CF6, #EC4899);
            color: white;
        }
        
        .dashboard-card {
            background: rgba(0,0,0,0.2);
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 20px;
        }
        
        .stat-card {
            background: rgba(0,0,0,0.15);
            border-radius: 10px;
            padding: 16px;
            margin-bottom: 16px;
        }
        
        .package-card {
            background: rgba(0,0,0,0.15);
            border-radius: 12px;
            padding: 24px;
            margin-bottom: 24px;
            transition: transform 0.3s ease;
            border: 2px solid transparent;
            position: relative;
            overflow: hidden;
        }
        
        .package-card:hover {
            transform: translateY(-5px);
        }
        
        .package-card.popular {
            border-color: var(--accent);
            transform: scale(1.02);
        }
        
        .package-card.popular::before {
            content: 'MOST POPULAR';
            position: absolute;
            top: 0;
            right: 0;
            background: var(--accent);
            color: #111;
            font-size: 0.75rem;
            font-weight: 700;
            padding: 4px 12px;
            border-bottom-left-radius: 8px;
        }
        
        .faq-item {
            background: rgba(0,0,0,0.15);
            border-radius: 10px;
            padding: 16px;
            margin-bottom: 16px;
            cursor: pointer;
        }
        
        .faq-answer {
            display: none;
            padding-top: 12px;
            color: var(--muted);
        }
        
        .active-page {
            background: #1c2230;
            border-right: 4px solid var(--accent);
        }
        
        .confirmation-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.7);
            z-index: 1000;
            justify-content: center;
            align-items: center;
        }
        
        .modal-content {
            background: var(--card);
            border-radius: 12px;
            padding: 30px;
            width: 90%;
            max-width: 500px;
            color: white;
        }
        
        .progress-bar {
            height: 6px;
            background: rgba(255,255,255,0.1);
            border-radius: 3px;
            overflow: hidden;
            margin: 15px 0;
        }
        
        .progress-fill {
            height: 100%;
            background: var(--accent);
            width: 0%;
            transition: width 0.5s ease;
        }
        
        .feature-list {
            list-style: none;
            padding: 0;
            margin: 16px 0;
        }
        
        .feature-list li {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
        }
        
        .feature-list li i {
            margin-right: 10px;
            color: var(--accent);
        }
        
        .tabs {
            display: flex;
            border-bottom: 1px solid rgba(255,255,255,0.1);
            margin-bottom: 20px;
            flex-wrap: wrap;
        }
        
        .tab {
            padding: 10px 20px;
            cursor: pointer;
            opacity: 0.7;
            transition: opacity 0.3s;
        }
        
        .tab.active {
            opacity: 1;
            border-bottom: 2px solid var(--accent);
        }
        
        .tab-content {
            display: none;
        }
        
        .tab-content.active {
            display: block;
        }
        
        .package-badge {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.75rem;
            font-weight: 600;
            margin-left: 10px;
        }
        
        .badge-basic {
            background: rgba(59, 130, 246, 0.2);
            color: #3B82F6;
        }
        
        .badge-standard {
            background: rgba(139, 92, 246, 0.2);
            color: #8B5CF6;
        }
        
        .badge-premium {
            background: rgba(236, 72, 153, 0.2);
            color: #EC4899;
        }
        
        .badge-business {
            background: rgba(245, 158, 11, 0.2);
            color: #F59E0B;
        }
        
        @media (max-width: 768px) {
            .cards {
                flex-direction: column;
            }
            
            .promo {
                width: 92%;
            }
            
            .grid-cols-2 {
                grid-template-columns: 1fr;
            }
            
            .grid-cols-3 {
                grid-template-columns: 1fr;
            }
            
            .grid-cols-4 {
                grid-template-columns: 1fr;
            }
            
            .action-buttons {
                flex-direction: column;
                gap: 8px;
            }
            
            .action-buttons button {
                width: 100%;
            }
            
            .tabs {
                overflow-x: auto;
                white-space: nowrap;
            }
        }
    </style>
</head>
<body>
    <!-- Sidebar -->
    <aside class="sidebar" id="sidebar">
        <div class="logo-section">
            <i data-feather="zap" class="text-yellow-400"></i>
            <div>
                <h2 class="brand">JMOTORS</h2>
                <p class="subtitle">Marketing Platform</p>
            </div>
        </div>

        <ul class="menu">
            <li><a href="index.php"><i data-feather="home"></i> Dashboard</a></li>
            <li><a href="meta-uploads.php"><i data-feather="upload"></i> Meta Uploads</a></li>
            <li><a href="transactions.php"><i data-feather="repeat"></i> Transactions</a></li>
            <li><a href="transfer.php"><i data-feather="send"></i> Transfer</a></li>
            <li><a href="daily-product.php"><i data-feather="shopping-bag"></i> Daily Product</a></li>
            <li><a href="withdraw.php"><i data-feather="dollar-sign"></i> Withdraw</a></li>
            <li><a href="packages.php"><i data-feather="package"></i> Packages</a></li>
            <li><a href="loan.php"><i data-feather="credit-card"></i> Loan</a></li>
            <li><a href="recharge.php"><i data-feather="battery-charging"></i> Recharge</a></li>
            <li><a href="agent-approval.php" class="active-page"><i data-feather="user-check"></i> Agent Approval</a></li>
            <li><a href="access-token.php"><i data-feather="key"></i> Access Token</a></li>
            <li><a href="agent-claim.php"><i data-feather="tag"></i> Agent Claim</a></li>
            <li><a href="team.php"><i data-feather="users"></i> Team</a></li>
        </ul>

        <ul class="menu bottom">
            <li><a href="profile.php"><i data-feather="user"></i> Profile</a></li>
            <li><a href="settings.php"><i data-feather="settings"></i> Settings</a></li>
            <li><a href="whatsapp-channel.php"><i data-feather="message-square"></i> Whatsapp Channel</a></li>
            <li><a href="customer-care.php"><i data-feather="headphones"></i> Customer Care</a></li>
        </ul>

        <div class="user-footer">
            <div class="avatar"><?php echo substr($username, 0, 2); ?></div>
            <div>
                <h4><?php echo $username; ?></h4>
                <p><?php echo $tier; ?> - Marketer</p>
            </div>
        </div>
    </aside>

    <!-- Main Content -->
    <div id="content">
        <header class="bg-gray-800 text-white p-4">
            <div class="flex items-center">
                <button class="menu-toggle" id="menu-toggle">
                    <i data-feather="menu"></i>
                </button>
                <div class="ml-4 font-bold text-xl">Jmotors</div>
            </div>
            <nav class="flex items-center space-x-6">
                <a href="transfer.php" class="hover:text-yellow-300">Transfer</a>
                <a href="loan.php" class="hover:text-yellow-300">Loans</a>
                <a href="dailyproduct.php" class="hover:text-yellow-300">New Product</a>
                <div class="w-9 h-9 rounded-full bg-gradient-to-r from-yellow-300 to-orange-400 flex items-center justify-center font-bold">MI</div>
            </nav>
        </header>
        
        <main class="p-4">
            <!-- Display active investment if exists -->
            <?php if ($active_investment): ?>
            <div class="bg-green-900 bg-opacity-50 p-4 rounded-lg mb-6 flex items-center">
                <i data-feather="award" class="text-green-400 mr-3"></i>
                <div>
                    <h3 class="font-bold">Active Investment: <?php echo $active_investment['package_name']; ?></h3>
                    <p>Amount: <?php echo number_format($active_investment['amount'], 2); ?> <?php echo $currency_symbol; ?> | 
                       Daily Earnings: <?php echo number_format($active_investment['amount'] * ($active_investment['daily_return'] / 100), 2); ?> <?php echo $currency_symbol; ?></p>
                    <p class="text-sm">Ends on: <?php echo date('M j, Y', strtotime($active_investment['end_date'])); ?></p>
                </div>
            </div>
            <?php endif; ?>

            <div class="banner">
                <div class="title">📦 Investment Packages</div>
                    <p>Choose from our range of investment packages to maximize your earnings</p>

                <div class="footer">📈 High returns &nbsp; • &nbsp; Flexible terms &nbsp; • &nbsp; Daily earnings</div>
            </div>

            <div class="tabs">
                <div class="tab active" data-tab="all-packages">All Packages</div>
                <div class="tab" data-tab="nova">Nova</div>
                <div class="tab" data-tab="superior">Superior</div>
                <div class="tab" data-tab="gold">Gold</div>
                <div class="tab" data-tab="diamond">Diamond</div>
            </div>

            <div class="tab-content active" id="all-packages-tab">
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mt-6">
                    <?php foreach ($package_configs as $name => $config): ?>
                    <div class="package-card <?php echo $name === 'Superior' ? 'popular' : ''; ?>">
                        <div class="flex justify-between items-start mb-4">
                            <h3 class="text-lg font-bold"><?php echo $name; ?></h3>
                            <span class="package-badge badge-<?php echo strtolower($name); ?>">
                                <?php echo $name === 'Superior' ? 'Popular' : ($name === 'Nova' ? 'Starter' : ($name === 'Gold' ? 'Advanced' : 'Elite')); ?>
                            </span>
                        </div>
                        <div class="text-center mb-6">
                            <div class="text-3xl font-bold"><?php echo number_format($config['min_investment'], 0); ?> <?php echo $currency_symbol; ?></div>
                            <div class="text-sm text-gray-400">Minimum Investment</div>
                        </div>
                        <ul class="feature-list">
                            <li><i data-feather="check-circle"></i> <?php echo $config['daily_return']; ?>% Daily Earnings</li>
                            <li><i data-feather="check-circle"></i> <?php echo $config['duration_days']; ?> Day Duration</li>
                            <?php
                            $features = explode(',', $config['features']);
                            foreach ($features as $feature): 
                            ?>
                            <li><i data-feather="check-circle"></i> <?php echo trim($feature); ?></li>
                            <?php endforeach; ?>
                            <?php if ($name === 'Nova'): ?>
                            <li><i data-feather="x-circle" class="text-gray-400"></i> <span class="text-gray-400">Priority Support</span></li>
                            <li><i data-feather="x-circle" class="text-gray-400"></i> <span class="text-gray-400">Advanced Tools</span></li>
                            <?php elseif ($name === 'Superior'): ?>
                            <li><i data-feather="x-circle" class="text-gray-400"></i> <span class="text-gray-400">Advanced Tools</span></li>
                            <?php endif; ?>
                        </ul>
                        <div class="text-center mt-6">
                            <?php
                            $total_return = $config['min_investment'] * ($config['daily_return'] / 100) * $config['duration_days'];
                            ?>
                            <div class="text-xl font-bold mb-2"><?php echo number_format($total_return, 0); ?> <?php echo $currency_symbol; ?></div>
                            <div class="text-sm text-gray-400">Total Return</div>
                        </div>
                        <button class="btn <?php echo $name === 'Nova' ? 'btn-outline' : ($name === 'Gold' ? 'btn-primary' : ($name === 'Diamond' ? 'btn-premium' : '')); ?> mt-4" 
                                onclick="selectPackage('<?php echo strtolower($name); ?>', <?php echo $package_ids[strtolower($name)] ?? 0; ?>, <?php echo $config['min_investment']; ?>, <?php echo $config['max_investment']; ?>, <?php echo $config['daily_return']; ?>, <?php echo $config['duration_days']; ?>)">
                            Select <?php echo $name; ?>
                        </button>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>

            <div class="dashboard-card mt-8">
                <h3 class="text-lg font-bold mb-4 flex items-center gap-2">
                    <i data-feather="bar-chart-2" class="text-green-400"></i> Package Comparison
                </h3>
                <div class="overflow-x-auto">
                    <table class="w-full">
                        <thead>
                            <tr class="border-b border-gray-700">
                                <th class="text-left py-3">Feature</th>
                                <th class="text-center py-3">Nova</th>
                                <th class="text-center py-3">Superior</th>
                                <th class="text-center py-3">Gold</th>
                                <th class="text-center py-3">Diamond</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr class="border-b border-gray-700">
                                <td class="py-3">Daily Return</td>
                                <td class="text-center py-3">5%</td>
                                <td class="text-center py-3">7%</td>
                                <td class="text-center py-3">10%</td>
                                <td class="text-center py-3">15%</td>
                            </tr>
                            <tr class="border-b border-gray-700">
                                <td class="py-3">Contract Duration</td>
                                <td class="text-center py-3">7 days</td>
                                <td class="text-center py-3">14 days</td>
                                <td class="text-center py-3">21 days</td>
                                <td class="text-center py-3">30 days</td>
                            </tr>
                            <tr class="border-b border-gray-700">
                                <td class="py-3">Referral Bonus</td>
                                <td class="text-center py-3">2%</td>
                                <td class="text-center py-3">3%</td>
                                <td class="text-center py-3">5%</td>
                                <td class="text-center py-3">7%</td>
                            </tr>
                            <tr class="border-b border-gray-700">
                                <td class="py-3">Withdrawal Speed</td>
                                <td class="text-center py-3">24-48 hours</td>
                                <td class="text-center py-3">12-24 hours</td>
                                <td class="text-center py-3">Instant</td>
                                <td class="text-center py-3">Instant</td>
                            </tr>
                            <tr class="border-b border-gray-700">
                                <td class="py-3">Support</td>
                                <td class="text-center py-3">Basic</td>
                                <td class="text-center py-3">Standard</td>
                                <td class="text-center py-3">Priority</td>
                                <td class="text-center py-3">24/7 Dedicated</td>
                            </tr>
                            <tr>
                                <td class="py-3">Minimum Investment</td>
                                <td class="text-center py-3"><?php echo number_format($package_configs['Nova']['min_investment'], 0); ?> <?php echo $currency_symbol; ?></td>
                                <td class="text-center py-3"><?php echo number_format($package_configs['Superior']['min_investment'], 0); ?> <?php echo $currency_symbol; ?></td>
                                <td class="text-center py-3"><?php echo number_format($package_configs['Gold']['min_investment'], 0); ?> <?php echo $currency_symbol; ?></td>
                                <td class="text-center py-3"><?php echo number_format($package_configs['Diamond']['min_investment'], 0); ?> <?php echo $currency_symbol; ?></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <div class="dashboard-card mt-8">
                <h3 class="text-lg font-bold mb-4 flex items-center gap-2">
                    <i data-feather="help-circle" class="text-purple-400"></i> Packages FAQ
                </h3>
                
                <div class="faq-item">
                    <div class="flex justify-between items-center">
                        <h4 class="font-bold">How do I earn from these packages?</h4>
                        <i data-feather="chevron-down" class="faq-toggle"></i>
                    </div>
                    <div class="faq-answer">
                        <p>When you invest in a package, you earn daily returns based on the percentage for that package. For example, if you invest 5,000 KES in the Standard package with 7% daily returns, you'll earn 350 KES per day. Earnings are credited to your account daily and can be withdrawn or reinvested.</p>
                    </div>
                </div>
                
                <div class="faq-item">
                    <div class="flex justify-between items-center">
                        <h4 class="font-bold">When can I withdraw my earnings?</h4>
                        <i data-feather="chevron-down" class="faq-toggle"></i>
                    </div>
                    <div class="faq-answer">
                        <p>You can withdraw your earnings anytime after they are credited to your account. However, your initial investment is locked for the duration of the package contract. Higher-tier packages offer faster withdrawal processing times.</p>
                    </div>
                </div>
                
                <div class="faq-item">
                    <div class="flex justify-between items-center">
                        <h4 class="font-bold">What happens when my package expires?</h4>
                        <i data-feather="chevron-down" class="faq-toggle"></i>
                    </div>
                    <div class="faq-answer">
                        <p>When your package contract expires, your initial investment is returned to your account balance along with any remaining earnings. You can then withdraw the full amount or reinvest in a new package to continue earning.</p>
                    </div>
                </div>

                <div class="faq-item">
                    <div class="flex justify-between items-center">
                        <h4 class="font-bold">Can I upgrade my package?</h4>
                        <i data-feather="chevron-down" class="faq-toggle"></i>
                    </div>
                    <div class="faq-answer">
                        <p>Yes, you can upgrade your package at any time by investing additional funds. The new investment will be treated as a separate package contract with its own terms and earning schedule. You can have multiple packages active simultaneously.</p>
                    </div>
                </div>
            </div>
            
        </main>
    </div>

    <!-- Package Selection Modal -->
    <div class="confirmation-modal" id="package-modal">
        <div class="modal-content">
            <h3 class="text-xl font-bold mb-4 flex items-center gap-2">
                <i data-feather="package" class="text-yellow-400"></i> Confirm Package Selection
            </h3>
            
            <div class="bg-gray-700 p-4 rounded-lg mb-4">
                <h4 class="font-bold mb-2" id="selected-package-name">Superior Package</h4>
                
                <div class="grid grid-cols-2 gap-4 mb-3">
                    <div>
                        <p class="text-xs text-gray-400">Daily Return</p>
                        <p class="text-sm font-bold" id="selected-daily-return">7%</p>
                    </div>
                    <div>
                        <p class="text-xs text-gray-400">Duration</p>
                        <p class="text-sm font-bold" id="selected-duration">14 days</p>
                    </div>
                </div>
                
                <div class="mb-3">
                    <p class="text-xs text-gray-400">Total Return</p>
                    <p class="text-sm font-bold" id="selected-total-return"><?php echo number_format($package_configs['Superior']['min_investment'] * ($package_configs['Superior']['daily_return'] / 100) * $package_configs['Superior']['duration_days'], 0); ?> <?php echo $currency_symbol; ?></p>
                </div>
                
                <div class="form-group">
                    <label for="investment-amount" class="text-xs">Investment Amount (<?php echo $currency_symbol; ?>)</label>
                    <input type="number" id="investment-amount" class="bg-gray-800" placeholder="Enter amount" oninput="calculateTotalReturn()">
                    <p class="text-xs text-gray-400 mt-1" id="min-max-amount">Min: <?php echo number_format($package_configs['Superior']['min_investment'], 0); ?> <?php echo $currency_symbol; ?> | Max: <?php echo number_format($package_configs['Superior']['max_investment'], 0); ?> <?php echo $currency_symbol; ?></p>
                </div>
            </div>
            
            <div class="form-group">
                <label for="payment-method">Payment Method</label>
                <select id="payment-method">
                    <option value="mpesa">M-Pesa</option>
                    <option value="bank">Bank Transfer</option>
                    <option value="wallet">Account Balance (<?php echo number_format($balance, 2); ?> <?php echo $currency_symbol; ?> available)</option>
                </select>
            </div>
            
            <div class="bg-yellow-400 bg-opacity-20 p-3 rounded-lg flex items-start mb-4">
                <i data-feather="info" class="text-yellow-400 mr-2 mt-1"></i>
                <p class="text-sm">Your investment will be locked for the contract duration. Earnings are paid daily and can be withdrawn anytime.</p>
            </div>
            
            <div class="flex gap-3">
                <button class="btn btn-outline flex-1" id="cancel-package">
                    <i data-feather="x" class="w-4 h-4 mr-1"></i> Cancel
                </button>
                <button class="btn btn-success flex-1" id="confirm-package">
                    <i data-feather="check" class="w-4 h-4 mr-1"></i> Confirm
                </button>
            </div>
        </div>
    </div>

    <script>
        feather.replace();
        
        // Store package IDs for JavaScript
        const packageIds = <?php echo json_encode($package_ids); ?>;
        let selectedPackageId = null;
        let selectedPackageMin = 0;
        let selectedPackageMax = 0;
        let selectedPackageDailyReturn = 0;
        let selectedPackageDuration = 0;
        const currencySymbol = '<?php echo $currency_symbol; ?>';
        
        // Package selection function
        function selectPackage(packageType, packageId = null, minAmount = 0, maxAmount = 0, dailyReturn = 0, durationDays = 0) {
            const packageModal = document.getElementById('package-modal');
            const packageName = document.getElementById('selected-package-name');
            const dailyReturnElement = document.getElementById('selected-daily-return');
            const durationElement = document.getElementById('selected-duration');
            const totalReturnElement = document.getElementById('selected-total-return');
            const minMaxAmount = document.getElementById('min-max-amount');
            const investmentAmount = document.getElementById('investment-amount');
            
            // Use provided packageId or get from mapping
            selectedPackageId = packageId || packageIds[packageType];
            selectedPackageMin = minAmount;
            selectedPackageMax = maxAmount;
            selectedPackageDailyReturn = dailyReturn;
            selectedPackageDuration = durationDays;
            
            // Set package details based on type
            switch(packageType) {
                case 'nova':
                    packageName.textContent = 'Nova Package';
                    dailyReturnElement.textContent = '5%';
                    durationElement.textContent = '7 days';
                    totalReturnElement.textContent = (minAmount * 0.05 * 7).toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    minMaxAmount.textContent = 'Min: ' + minAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol + ' | Max: ' + maxAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    investmentAmount.min = minAmount;
                    investmentAmount.max = maxAmount;
                    investmentAmount.placeholder = 'Min: ' + minAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    break;
                case 'superior':
                    packageName.textContent = 'Superior Package';
                    dailyReturnElement.textContent = '7%';
                    durationElement.textContent = '14 days';
                    totalReturnElement.textContent = (minAmount * 0.07 * 14).toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    minMaxAmount.textContent = 'Min: ' + minAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol + ' | Max: ' + maxAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    investmentAmount.min = minAmount;
                    investmentAmount.max = maxAmount;
                    investmentAmount.placeholder = 'Min: ' + minAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    break;
                case 'gold':
                    packageName.textContent = 'Gold Package';
                    dailyReturnElement.textContent = '10%';
                    durationElement.textContent = '21 days';
                    totalReturnElement.textContent = (minAmount * 0.10 * 21).toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    minMaxAmount.textContent = 'Min: ' + minAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol + ' | Max: ' + maxAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    investmentAmount.min = minAmount;
                    investmentAmount.max = maxAmount;
                    investmentAmount.placeholder = 'Min: ' + minAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    break;
                case 'diamond':
                    packageName.textContent = 'Diamond Package';
                    dailyReturnElement.textContent = '15%';
                    durationElement.textContent = '30 days';
                    totalReturnElement.textContent = (minAmount * 0.15 * 30).toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    minMaxAmount.textContent = 'Min: ' + minAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol + ' | Max: ' + maxAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    investmentAmount.min = minAmount;
                    investmentAmount.max = maxAmount;
                    investmentAmount.placeholder = 'Min: ' + minAmount.toLocaleString('en-US', {maximumFractionDigits: 0}) + ' ' + currencySymbol;
                    break;
            }
            
            // Set the investment amount to the minimum by default
            investmentAmount.value = minAmount;
            
            // Show the modal
            packageModal.style.display = 'flex';
        }
        
        // Calculate total return in real-time
        function calculateTotalReturn() {
            const investmentAmount = parseFloat(document.getElementById('investment-amount').value) || 0;
            const totalReturnElement = document.getElementById('selected-total-return');
            
            if (investmentAmount > 0 && selectedPackageDailyReturn > 0 && selectedPackageDuration > 0) {
                const totalReturn = investmentAmount * (selectedPackageDailyReturn / 100) * selectedPackageDuration;
                totalReturnElement.textContent = totalReturn.toLocaleString('en-US', {maximumFractionDigits: 2}) + ' ' + currencySymbol;
            }
        }
        
        document.addEventListener('DOMContentLoaded', function() {
            // Your existing JavaScript code for tabs, FAQ, etc.
        });

        document.addEventListener('DOMContentLoaded', function() {
            // Menu toggle functionality
            const menuToggle = document.getElementById('menu-toggle');
            const sidebar = document.getElementById('sidebar');
            
            if (menuToggle && sidebar) {
                menuToggle.addEventListener('click', function() {
                    sidebar.classList.toggle('active');
                });
            }
            
            // Tab functionality
            const tabs = document.querySelectorAll('.tab');
            tabs.forEach(tab => {
                tab.addEventListener('click', function() {
                    const tabName = this.getAttribute('data-tab');
                    
                    // Remove active class from all tabs
                    tabs.forEach(t => t.classList.remove('active'));
                    // Add active class to clicked tab
                    this.classList.add('active');
                    
                    // Hide all tab content
                    document.querySelectorAll('.tab-content').forEach(content => {
                        content.classList.remove('active');
                    });
                    
                    // Show the selected tab content
                    document.getElementById(`${tabName}-tab`).classList.add('active');
                });
            });
            
            // FAQ toggle functionality
            const faqItems = document.querySelectorAll('.faq-item');
            faqItems.forEach(item => {
                item.addEventListener('click', function() {
                    const answer = this.querySelector('.faq-answer');
                    answer.style.display = answer.style.display === 'block' ? 'none' : 'block';
                    
                    // Rotate the chevron icon
                    const icon = this.querySelector('.faq-toggle');
                    if (icon) {
                        if (answer.style.display === 'block') {
                            icon.style.transform = 'rotate(180deg)';
                        } else {
                            icon.style.transform = 'rotate(0deg)';
                        }
                    }
                });
            });
            
            // Package modal functionality
            const packageModal = document.getElementById('package-modal');
            const cancelPackageBtn = document.getElementById('cancel-package');
            const confirmPackageBtn = document.getElementById('confirm-package');
            
            // Close modal when clicking cancel
            if (cancelPackageBtn) {
                cancelPackageBtn.addEventListener('click', function() {
                    packageModal.style.display = 'none';
                });
            }
            
            // Handle package confirmation
            if (confirmPackageBtn) {
                confirmPackageBtn.addEventListener('click', function() {
                    const investmentAmount = parseFloat(document.getElementById('investment-amount').value);
                    const paymentMethod = document.getElementById('payment-method').value;
                    
                    // Validate investment amount
                    if (!investmentAmount || isNaN(investmentAmount)) {
                        alert('Please enter a valid investment amount');
                        return;
                    }
                    
                    if (investmentAmount < selectedPackageMin) {
                        alert(`Investment amount must be at least ${selectedPackageMin.toLocaleString('en-US', {maximumFractionDigits: 0})} ${currencySymbol}`);
                        return;
                    }
                    
                    if (investmentAmount > selectedPackageMax) {
                        alert(`Investment amount cannot exceed ${selectedPackageMax.toLocaleString('en-US', {maximumFractionDigits: 0})} ${currencySymbol}`);
                        return;
                    }
                    
                    // If paying with wallet, check balance
                    if (paymentMethod === 'wallet' && investmentAmount > <?php echo $balance; ?>) {
                        alert('Insufficient balance in your wallet');
                        return;
                    }
                    
                    // Process the investment (you'll need to implement this with AJAX)
                    processInvestment(selectedPackageId, investmentAmount, paymentMethod);
                });
            }
            
            // Close modal when clicking outside
            window.addEventListener('click', function(event) {
                if (event.target === packageModal) {
                    packageModal.style.display = 'none';
                }
            });
        });

        // Function to process investment (placeholder - you'll need to implement this)
        function processInvestment(packageId, amount, paymentMethod) {
            // This is where you would make an AJAX request to your server
            console.log('Processing investment:', {
                packageId: packageId,
                amount: amount,
                paymentMethod: paymentMethod
            });
            
            // Show a success message (replace with actual AJAX call)
            alert(`Investment of ${amount} ${currencySymbol} confirmed! Redirecting to payment...`);
            
            // For demonstration purposes, just close the modal
            document.getElementById('package-modal').style.display = 'none';
            
            // In a real implementation, you would:
            // 1. Make an AJAX request to your server
            // 2. Handle the payment process based on the selected method
            // 3. Update the UI accordingly
        }
    </script>
</body>
</html>