File size: 77,468 Bytes
8c33324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
 
 
 
 
 
 
 
 
 
 
f80f4a9
8c33324
 
 
 
 
 
 
 
f80f4a9
 
 
 
 
 
 
 
 
 
8c33324
 
 
 
 
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
 
f80f4a9
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
 
 
 
 
 
 
f80f4a9
 
8c33324
 
 
 
 
 
 
 
 
 
 
 
 
 
f80f4a9
8c33324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f80f4a9
 
 
8c33324
 
 
f80f4a9
8c33324
 
 
 
 
 
 
 
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
 
 
 
 
 
 
 
 
 
 
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
8c33324
f80f4a9
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
 
 
8c33324
f80f4a9
 
 
 
8c33324
f80f4a9
 
 
 
8c33324
f80f4a9
 
 
 
8c33324
 
 
f80f4a9
8c33324
 
 
 
 
 
f80f4a9
8c33324
 
 
f80f4a9
 
 
 
 
 
 
8c33324
 
 
 
f80f4a9
 
 
 
8c33324
 
 
 
 
f80f4a9
 
 
 
8c33324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f80f4a9
8c33324
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
8c33324
 
 
 
 
 
f80f4a9
 
 
8c33324
 
 
 
 
 
 
f80f4a9
8c33324
 
 
 
 
 
 
 
 
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f80f4a9
 
 
 
 
8c33324
f80f4a9
 
 
8c33324
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
f80f4a9
 
 
8c33324
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
 
f80f4a9
 
 
 
 
 
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
8c33324
f80f4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c33324
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>StockMaster - Gestion de Stock</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">
    <style>
        /* Animation pour les notifications */
        @keyframes slideIn {
            from { transform: translateX(100%); }
            to { transform: translateX(0); }
        }
        
        @keyframes fadeOut {
            from { opacity: 1; }
            to { opacity: 0; }
        }
        
        .notification {
            animation: slideIn 0.3s ease-out;
        }
        
        .notification.hide {
            animation: fadeOut 0.5s ease-out forwards;
        }
        
        /* Style personnalisé pour le tableau */
        .table-container {
            max-height: 500px;
            overflow-y: auto;
        }
        
        .table-container::-webkit-scrollbar {
            width: 8px;
        }
        
        .table-container::-webkit-scrollbar-track {
            background: #f1f1f1;
        }
        
        .table-container::-webkit-scrollbar-thumb {
            background: #888;
            border-radius: 4px;
        }
        
        .table-container::-webkit-scrollbar-thumb:hover {
            background: #555;
        }

        /* Style pour les onglets */
        .tab-content {
            display: none;
        }
        
        .tab-content.active {
            display: block;
        }
        
        .tab-button {
            position: relative;
        }
        
        .tab-button.active::after {
            content: '';
            position: absolute;
            bottom: -1px;
            left: 0;
            width: 100%;
            height: 2px;
            background-color: #3b82f6;
        }

        /* Style pour les badges de statut */
        .status-badge {
            font-size: 0.75rem;
            padding: 0.25rem 0.5rem;
            border-radius: 9999px;
        }
        
        .status-active {
            background-color: #d1fae5;
            color: #065f46;
        }
        
        .status-inactive {
            background-color: #fee2e2;
            color: #b91c1c;
        }
    </style>
</head>
<body class="bg-gray-100 font-sans">
    <!-- Barre de navigation -->
    <nav class="bg-blue-600 text-white shadow-lg">
        <div class="container mx-auto px-4 py-3 flex justify-between items-center">
            <div class="flex items-center space-x-2">
                <i class="fas fa-boxes text-2xl"></i>
                <h1 class="text-2xl font-bold">StockMaster</h1>
            </div>
            <div class="flex items-center space-x-4">
                <div class="relative">
                    <input type="text" id="global-search" placeholder="Rechercher..." 
                           class="px-4 py-2 rounded-full text-gray-800 focus:outline-none focus:ring-2 focus:ring-blue-300">
                    <button class="absolute right-3 top-2 text-gray-500">
                        <i class="fas fa-search"></i>
                    </button>
                </div>
                <button id="dark-mode-toggle" class="p-2 rounded-full hover:bg-blue-700 transition">
                    <i class="fas fa-moon"></i>
                </button>
                <div class="relative group">
                    <button class="flex items-center space-x-1 p-2 rounded-full hover:bg-blue-700 transition">
                        <i class="fas fa-user-circle text-xl"></i>
                    </button>
                    <div class="absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg py-1 z-50 hidden group-hover:block">
                        <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Mon profil</a>
                        <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Paramètres</a>
                        <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Déconnexion</a>
                    </div>
                </div>
            </div>
        </div>
    </nav>

    <!-- Contenu principal -->
    <div class="container mx-auto px-4 py-6">
        <!-- Onglets -->
        <div class="flex border-b mb-6">
            <button class="tab-button px-4 py-2 font-medium text-gray-600 hover:text-blue-600 transition active" data-tab="products">
                <i class="fas fa-boxes mr-2"></i>Produits
            </button>
            <button class="tab-button px-4 py-2 font-medium text-gray-600 hover:text-blue-600 transition" data-tab="categories">
                <i class="fas fa-tags mr-2"></i>Catégories
            </button>
            <button class="tab-button px-4 py-2 font-medium text-gray-600 hover:text-blue-600 transition" data-tab="users">
                <i class="fas fa-users mr-2"></i>Utilisateurs
            </button>
            <button class="tab-button px-4 py-2 font-medium text-gray-600 hover:text-blue-600 transition" data-tab="attributes">
                <i class="fas fa-list mr-2"></i>Attributs
            </button>
        </div>

        <!-- Contenu des onglets -->
        <div id="tab-contents">
            <!-- Onglet Produits -->
            <div id="products-tab" class="tab-content active">
                <!-- En-tête et boutons d'action -->
                <div class="flex justify-between items-center mb-6">
                    <h2 class="text-2xl font-semibold text-gray-800">Gestion du Stock</h2>
                    <div class="flex space-x-3">
                        <button id="add-product-btn" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg flex items-center space-x-2 transition">
                            <i class="fas fa-plus"></i>
                            <span>Ajouter un produit</span>
                        </button>
                        <button id="export-btn" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg flex items-center space-x-2 transition">
                            <i class="fas fa-file-export"></i>
                            <span>Exporter</span>
                        </button>
                    </div>
                </div>

                <!-- Statistiques -->
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
                    <div class="bg-white p-4 rounded-lg shadow flex items-center justify-between">
                        <div>
                            <p class="text-gray-500">Produits en stock</p>
                            <h3 class="text-2xl font-bold" id="total-products">0</h3>
                        </div>
                        <div class="bg-blue-100 p-3 rounded-full">
                            <i class="fas fa-boxes text-blue-500 text-xl"></i>
                        </div>
                    </div>
                    <div class="bg-white p-4 rounded-lg shadow flex items-center justify-between">
                        <div>
                            <p class="text-gray-500">Valeur totale</p>
                            <h3 class="text-2xl font-bold" id="total-value">0 €</h3>
                        </div>
                        <div class="bg-green-100 p-3 rounded-full">
                            <i class="fas fa-euro-sign text-green-500 text-xl"></i>
                        </div>
                    </div>
                    <div class="bg-white p-4 rounded-lg shadow flex items-center justify-between">
                        <div>
                            <p class="text-gray-500">Stock faible</p>
                            <h3 class="text-2xl font-bold" id="low-stock">0</h3>
                        </div>
                        <div class="bg-yellow-100 p-3 rounded-full">
                            <i class="fas fa-exclamation-triangle text-yellow-500 text-xl"></i>
                        </div>
                    </div>
                    <div class="bg-white p-4 rounded-lg shadow flex items-center justify-between">
                        <div>
                            <p class="text-gray-500">Produits épuisés</p>
                            <h3 class="text-2xl font-bold" id="out-of-stock">0</h3>
                        </div>
                        <div class="bg-red-100 p-3 rounded-full">
                            <i class="fas fa-times-circle text-red-500 text-xl"></i>
                        </div>
                    </div>
                </div>

                <!-- Tableau des produits -->
                <div class="bg-white rounded-lg shadow overflow-hidden">
                    <div class="p-4 border-b flex justify-between items-center">
                        <div class="flex items-center space-x-4">
                            <h3 class="font-semibold text-lg">Liste des produits</h3>
                            <div class="relative">
                                <select id="filter-category" class="appearance-none bg-gray-100 border border-gray-300 rounded px-3 py-1 pr-8 focus:outline-none focus:ring-2 focus:ring-blue-300">
                                    <option value="all">Toutes catégories</option>
                                    <!-- Les options seront ajoutées dynamiquement -->
                                </select>
                                <div class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
                                    <i class="fas fa-chevron-down text-gray-500"></i>
                                </div>
                            </div>
                        </div>
                        <div class="flex items-center space-x-2">
                            <div class="relative">
                                <input type="text" id="search-products" placeholder="Rechercher..." 
                                       class="px-3 py-1 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300">
                                <button class="absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-500">
                                    <i class="fas fa-search"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="table-container">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nom</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Catégorie</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Quantité</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Prix unitaire</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Valeur</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="products-table-body" class="bg-white divide-y divide-gray-200">
                                <!-- Les produits seront ajoutés ici dynamiquement -->
                            </tbody>
                        </table>
                    </div>
                    <div class="p-4 border-t flex justify-between items-center">
                        <div class="text-sm text-gray-500">
                            Affichage de <span id="displayed-items">0</span> sur <span id="total-items">0</span> produits
                        </div>
                        <div class="flex space-x-2">
                            <button id="prev-page" class="px-3 py-1 border rounded disabled:opacity-50" disabled>
                                <i class="fas fa-chevron-left"></i>
                            </button>
                            <button id="next-page" class="px-3 py-1 border rounded disabled:opacity-50" disabled>
                                <i class="fas fa-chevron-right"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Onglet Catégories -->
            <div id="categories-tab" class="tab-content">
                <div class="flex justify-between items-center mb-6">
                    <h2 class="text-2xl font-semibold text-gray-800">Gestion des Catégories</h2>
                    <button id="add-category-btn" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg flex items-center space-x-2 transition">
                        <i class="fas fa-plus"></i>
                        <span>Ajouter une catégorie</span>
                    </button>
                </div>

                <!-- Tableau des catégories -->
                <div class="bg-white rounded-lg shadow overflow-hidden">
                    <div class="p-4 border-b flex justify-between items-center">
                        <h3 class="font-semibold text-lg">Liste des catégories</h3>
                        <div class="relative">
                            <input type="text" id="search-categories" placeholder="Rechercher..." 
                                   class="px-3 py-1 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300">
                            <button class="absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-500">
                                <i class="fas fa-search"></i>
                            </button>
                        </div>
                    </div>
                    <div class="table-container">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nom</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Description</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Statut</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Produits</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="categories-table-body" class="bg-white divide-y divide-gray-200">
                                <!-- Les catégories seront ajoutées ici dynamiquement -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <!-- Onglet Utilisateurs -->
            <div id="users-tab" class="tab-content">
                <div class="flex justify-between items-center mb-6">
                    <h2 class="text-2xl font-semibold text-gray-800">Gestion des Utilisateurs</h2>
                    <button id="add-user-btn" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg flex items-center space-x-2 transition">
                        <i class="fas fa-plus"></i>
                        <span>Ajouter un utilisateur</span>
                    </button>
                </div>

                <!-- Tableau des utilisateurs -->
                <div class="bg-white rounded-lg shadow overflow-hidden">
                    <div class="p-4 border-b flex justify-between items-center">
                        <h3 class="font-semibold text-lg">Liste des utilisateurs</h3>
                        <div class="relative">
                            <input type="text" id="search-users" placeholder="Rechercher..." 
                                   class="px-3 py-1 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300">
                            <button class="absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-500">
                                <i class="fas fa-search"></i>
                            </button>
                        </div>
                    </div>
                    <div class="table-container">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nom</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Rôle</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Statut</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="users-table-body" class="bg-white divide-y divide-gray-200">
                                <!-- Les utilisateurs seront ajoutées ici dynamiquement -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <!-- Onglet Attributs -->
            <div id="attributes-tab" class="tab-content">
                <div class="flex justify-between items-center mb-6">
                    <h2 class="text-2xl font-semibold text-gray-800">Gestion des Attributs</h2>
                    <button id="add-attribute-btn" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg flex items-center space-x-2 transition">
                        <i class="fas fa-plus"></i>
                        <span>Ajouter un attribut</span>
                    </button>
                </div>

                <!-- Tableau des attributs -->
                <div class="bg-white rounded-lg shadow overflow-hidden">
                    <div class="p-4 border-b flex justify-between items-center">
                        <h3 class="font-semibold text-lg">Liste des attributs</h3>
                        <div class="relative">
                            <input type="text" id="search-attributes" placeholder="Rechercher..." 
                                   class="px-3 py-1 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300">
                            <button class="absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-500">
                                <i class="fas fa-search"></i>
                            </button>
                        </div>
                    </div>
                    <div class="table-container">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nom</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Type</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Valeurs</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Catégories</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="attributes-table-body" class="bg-white divide-y divide-gray-200">
                                <!-- Les attributs seront ajoutées ici dynamiquement -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Modal pour ajouter/modifier un produit -->
    <div id="product-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg shadow-xl w-full max-w-md">
            <div class="p-4 border-b flex justify-between items-center">
                <h3 class="text-lg font-semibold" id="modal-product-title">Ajouter un produit</h3>
                <button class="close-modal text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="p-4">
                <form id="product-form">
                    <input type="hidden" id="product-id">
                    <div class="mb-4">
                        <label for="product-name" class="block text-gray-700 mb-2">Nom du produit</label>
                        <input type="text" id="product-name" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                    </div>
                    <div class="mb-4">
                        <label for="product-category" class="block text-gray-700 mb-2">Catégorie</label>
                        <select id="product-category" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                            <option value="">Sélectionner une catégorie</option>
                            <!-- Les options seront ajoutées dynamiquement -->
                        </select>
                    </div>
                    <div class="grid grid-cols-2 gap-4 mb-4">
                        <div>
                            <label for="product-quantity" class="block text-gray-700 mb-2">Quantité</label>
                            <input type="number" id="product-quantity" min="0" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                        </div>
                        <div>
                            <label for="product-price" class="block text-gray-700 mb-2">Prix unitaire (€)</label>
                            <input type="number" id="product-price" min="0" step="0.01" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                        </div>
                    </div>
                    <div class="mb-4">
                        <label for="product-description" class="block text-gray-700 mb-2">Description</label>
                        <textarea id="product-description" rows="3" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300"></textarea>
                    </div>
                    <div class="mb-4" id="product-attributes-container">
                        <!-- Les attributs spécifiques seront ajoutés ici dynamiquement -->
                    </div>
                </form>
            </div>
            <div class="p-4 border-t flex justify-end space-x-3">
                <button class="cancel-modal px-4 py-2 border rounded-lg text-gray-700 hover:bg-gray-100 transition">
                    Annuler
                </button>
                <button id="save-product" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition">
                    Enregistrer
                </button>
            </div>
        </div>
    </div>

    <!-- Modal pour ajouter/modifier une catégorie -->
    <div id="category-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg shadow-xl w-full max-w-md">
            <div class="p-4 border-b flex justify-between items-center">
                <h3 class="text-lg font-semibold" id="modal-category-title">Ajouter une catégorie</h3>
                <button class="close-modal text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="p-4">
                <form id="category-form">
                    <input type="hidden" id="category-id">
                    <div class="mb-4">
                        <label for="category-name" class="block text-gray-700 mb-2">Nom de la catégorie</label>
                        <input type="text" id="category-name" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                    </div>
                    <div class="mb-4">
                        <label for="category-description" class="block text-gray-700 mb-2">Description</label>
                        <textarea id="category-description" rows="3" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300"></textarea>
                    </div>
                    <div class="mb-4">
                        <label for="category-status" class="block text-gray-700 mb-2">Statut</label>
                        <select id="category-status" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                            <option value="active">Active</option>
                            <option value="inactive">Inactive</option>
                        </select>
                    </div>
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Attributs associés</label>
                        <div id="category-attributes-container" class="space-y-2">
                            <!-- Les attributs seront ajoutés ici dynamiquement -->
                        </div>
                    </div>
                </form>
            </div>
            <div class="p-4 border-t flex justify-end space-x-3">
                <button class="cancel-modal px-4 py-2 border rounded-lg text-gray-700 hover:bg-gray-100 transition">
                    Annuler
                </button>
                <button id="save-category" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition">
                    Enregistrer
                </button>
            </div>
        </div>
    </div>

    <!-- Modal pour ajouter/modifier un utilisateur -->
    <div id="user-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg shadow-xl w-full max-w-md">
            <div class="p-4 border-b flex justify-between items-center">
                <h3 class="text-lg font-semibold" id="modal-user-title">Ajouter un utilisateur</h3>
                <button class="close-modal text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="p-4">
                <form id="user-form">
                    <input type="hidden" id="user-id">
                    <div class="mb-4">
                        <label for="user-firstname" class="block text-gray-700 mb-2">Prénom</label>
                        <input type="text" id="user-firstname" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                    </div>
                    <div class="mb-4">
                        <label for="user-lastname" class="block text-gray-700 mb-2">Nom</label>
                        <input type="text" id="user-lastname" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                    </div>
                    <div class="mb-4">
                        <label for="user-email" class="block text-gray-700 mb-2">Email</label>
                        <input type="email" id="user-email" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                    </div>
                    <div class="mb-4">
                        <label for="user-role" class="block text-gray-700 mb-2">Rôle</label>
                        <select id="user-role" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                            <option value="admin">Administrateur</option>
                            <option value="manager">Gestionnaire</option>
                            <option value="user">Utilisateur</option>
                        </select>
                    </div>
                    <div class="mb-4">
                        <label for="user-status" class="block text-gray-700 mb-2">Statut</label>
                        <select id="user-status" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                            <option value="active">Actif</option>
                            <option value="inactive">Inactif</option>
                        </select>
                    </div>
                    <div class="mb-4" id="user-password-container">
                        <label for="user-password" class="block text-gray-700 mb-2">Mot de passe</label>
                        <input type="password" id="user-password" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300">
                        <p class="text-xs text-gray-500 mt-1">Laissez vide pour ne pas modifier</p>
                    </div>
                </form>
            </div>
            <div class="p-4 border-t flex justify-end space-x-3">
                <button class="cancel-modal px-4 py-2 border rounded-lg text-gray-700 hover:bg-gray-100 transition">
                    Annuler
                </button>
                <button id="save-user" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition">
                    Enregistrer
                </button>
            </div>
        </div>
    </div>

    <!-- Modal pour ajouter/modifier un attribut -->
    <div id="attribute-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg shadow-xl w-full max-w-md">
            <div class="p-4 border-b flex justify-between items-center">
                <h3 class="text-lg font-semibold" id="modal-attribute-title">Ajouter un attribut</h3>
                <button class="close-modal text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="p-4">
                <form id="attribute-form">
                    <input type="hidden" id="attribute-id">
                    <div class="mb-4">
                        <label for="attribute-name" class="block text-gray-700 mb-2">Nom de l'attribut</label>
                        <input type="text" id="attribute-name" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                    </div>
                    <div class="mb-4">
                        <label for="attribute-type" class="block text-gray-700 mb-2">Type</label>
                        <select id="attribute-type" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300" required>
                            <option value="text">Texte</option>
                            <option value="number">Nombre</option>
                            <option value="select">Liste déroulante</option>
                            <option value="checkbox">Case à cocher</option>
                        </select>
                    </div>
                    <div class="mb-4 hidden" id="attribute-values-container">
                        <label for="attribute-values" class="block text-gray-700 mb-2">Valeurs possibles (séparées par des virgules)</label>
                        <textarea id="attribute-values" rows="2" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300"></textarea>
                        <p class="text-xs text-gray-500 mt-1">Exemple: Rouge,Bleu,Vert</p>
                    </div>
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Catégories associées</label>
                        <div id="attribute-categories-container" class="space-y-2">
                            <!-- Les catégories seront ajoutées ici dynamiquement -->
                        </div>
                    </div>
                </form>
            </div>
            <div class="p-4 border-t flex justify-end space-x-3">
                <button class="cancel-modal px-4 py-2 border rounded-lg text-gray-700 hover:bg-gray-100 transition">
                    Annuler
                </button>
                <button id="save-attribute" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition">
                    Enregistrer
                </button>
            </div>
        </div>
    </div>

    <!-- Zone de notifications -->
    <div id="notifications" class="fixed bottom-4 right-4 space-y-2 z-50"></div>

    <script>
        // Données de l'application
        let products = JSON.parse(localStorage.getItem('products')) || [
            { id: 1, name: "Ordinateur portable", category: "Electronique", quantity: 15, price: 899.99, description: "PC portable 15 pouces, 16GB RAM, SSD 512GB" },
            { id: 2, name: "Smartphone", category: "Electronique", quantity: 32, price: 699.50, description: "Smartphone haut de gamme avec écran AMOLED" },
            { id: 3, name: "T-shirt", category: "Vêtements", quantity: 45, price: 19.99, description: "T-shirt en coton bio" },
            { id: 4, name: "Chocolat noir", category: "Alimentaire", quantity: 8, price: 3.50, description: "Tablette de chocolat noir 70%" },
            { id: 5, name: "Chaise de bureau", category: "Meubles", quantity: 12, price: 129.99, description: "Chaise ergonomique pour bureau" }
        ];

        let categories = JSON.parse(localStorage.getItem('categories')) || [
            { id: 1, name: "Electronique", description: "Appareils électroniques et informatiques", status: "active", attributes: [1, 2] },
            { id: 2, name: "Alimentaire", description: "Produits alimentaires et consommables", status: "active", attributes: [3] },
            { id: 3, name: "Vêtements", description: "Vêtements et accessoires", status: "active", attributes: [4, 5] },
            { id: 4, name: "Meubles", description: "Meubles et décoration", status: "active", attributes: [6] }
        ];

        let users = JSON.parse(localStorage.getItem('users')) || [
            { id: 1, firstname: "Admin", lastname: "System", email: "admin@stockmaster.com", role: "admin", status: "active", password: "admin123" },
            { id: 2, firstname: "Manager", lastname: "Stock", email: "manager@stockmaster.com", role: "manager", status: "active", password: "manager123" },
            { id: 3, firstname: "Utilisateur", lastname: "Test", email: "user@stockmaster.com", role: "user", status: "active", password: "user123" }
        ];

        let attributes = JSON.parse(localStorage.getItem('attributes')) || [
            { id: 1, name: "Marque", type: "select", values: "Apple,Samsung,Sony,LG", categories: [1] },
            { id: 2, name: "Couleur", type: "select", values: "Noir,Blanc,Gris,Bleu,Rouge", categories: [1, 3] },
            { id: 3, name: "Poids", type: "number", values: "", categories: [2] },
            { id: 4, name: "Taille", type: "select", values: "XS,S,M,L,XL,XXL", categories: [3] },
            { id: 5, name: "Matériau", type: "select", values: "Coton,Polyester,Laine,Soie", categories: [3] },
            { id: 6, name: "Dimensions", type: "text", values: "", categories: [4] }
        ];

        // Éléments du DOM
        const productsTableBody = document.getElementById('products-table-body');
        const categoriesTableBody = document.getElementById('categories-table-body');
        const usersTableBody = document.getElementById('users-table-body');
        const attributesTableBody = document.getElementById('attributes-table-body');
        
        const productForm = document.getElementById('product-form');
        const categoryForm = document.getElementById('category-form');
        const userForm = document.getElementById('user-form');
        const attributeForm = document.getElementById('attribute-form');
        
        const productModal = document.getElementById('product-modal');
        const categoryModal = document.getElementById('category-modal');
        const userModal = document.getElementById('user-modal');
        const attributeModal = document.getElementById('attribute-modal');
        
        const modalProductTitle = document.getElementById('modal-product-title');
        const modalCategoryTitle = document.getElementById('modal-category-title');
        const modalUserTitle = document.getElementById('modal-user-title');
        const modalAttributeTitle = document.getElementById('modal-attribute-title');
        
        const addProductBtn = document.getElementById('add-product-btn');
        const addCategoryBtn = document.getElementById('add-category-btn');
        const addUserBtn = document.getElementById('add-user-btn');
        const addAttributeBtn = document.getElementById('add-attribute-btn');
        
        const saveProductBtn = document.getElementById('save-product');
        const saveCategoryBtn = document.getElementById('save-category');
        const saveUserBtn = document.getElementById('save-user');
        const saveAttributeBtn = document.getElementById('save-attribute');
        
        const searchProductsInput = document.getElementById('search-products');
        const searchCategoriesInput = document.getElementById('search-categories');
        const searchUsersInput = document.getElementById('search-users');
        const searchAttributesInput = document.getElementById('search-attributes');
        
        const filterCategorySelect = document.getElementById('filter-category');
        const darkModeToggle = document.getElementById('dark-mode-toggle');
        const notificationsContainer = document.getElementById('notifications');
        
        const totalProductsElement = document.getElementById('total-products');
        const totalValueElement = document.getElementById('total-value');
        const lowStockElement = document.getElementById('low-stock');
        const outOfStockElement = document.getElementById('out-of-stock');
        const displayedItemsElement = document.getElementById('displayed-items');
        const totalItemsElement = document.getElementById('total-items');
        
        const prevPageBtn = document.getElementById('prev-page');
        const nextPageBtn = document.getElementById('next-page');
        const exportBtn = document.getElementById('export-btn');
        
        const productAttributesContainer = document.getElementById('product-attributes-container');
        const categoryAttributesContainer = document.getElementById('category-attributes-container');
        const attributeValuesContainer = document.getElementById('attribute-values-container');
        const attributeCategoriesContainer = document.getElementById('attribute-categories-container');
        const attributeTypeSelect = document.getElementById('attribute-type');
        
        // Variables pour la pagination
        let currentPage = 1;
        const itemsPerPage = 5;
        let filteredProducts = [];
        
        // Variables pour les onglets
        const tabButtons = document.querySelectorAll('.tab-button');
        const tabContents = document.querySelectorAll('.tab-content');

        // Initialisation de l'application
        document.addEventListener('DOMContentLoaded', () => {
            updateStatistics();
            renderProductsTable();
            renderCategoriesTable();
            renderUsersTable();
            renderAttributesTable();
            populateCategoryFilter();
            
            // Vérifier le mode sombre dans le localStorage
            if (localStorage.getItem('darkMode') === 'enabled') {
                document.body.classList.add('dark');
                darkModeToggle.innerHTML = '<i class="fas fa-sun"></i>';
            }
        });

        // Fonction pour afficher une notification
        function showNotification(message, type = 'success') {
            const notification = document.createElement('div');
            notification.className = `notification bg-${type === 'success' ? 'green' : type === 'error' ? 'red' : 'blue'}-500 text-white px-4 py-3 rounded-lg shadow-lg flex items-center justify-between`;
            
            notification.innerHTML = `
                <span>${message}</span>
                <button class="close-notification ml-4">
                    <i class="fas fa-times"></i>
                </button>
            `;
            
            notificationsContainer.appendChild(notification);
            
            // Fermer la notification après 5 secondes
            setTimeout(() => {
                notification.classList.add('hide');
                setTimeout(() => notification.remove(), 500);
            }, 5000);
            
            // Fermer la notification au clic
            notification.querySelector('.close-notification').addEventListener('click', () => {
                notification.classList.add('hide');
                setTimeout(() => notification.remove(), 500);
            });
        }

        // Fonction pour mettre à jour les statistiques
        function updateStatistics() {
            const totalProducts = products.length;
            const totalValue = products.reduce((sum, product) => sum + (product.quantity * product.price), 0);
            const lowStock = products.filter(product => product.quantity > 0 && product.quantity <= 5).length;
            const outOfStock = products.filter(product => product.quantity === 0).length;
            
            totalProductsElement.textContent = totalProducts;
            totalValueElement.textContent = totalValue.toFixed(2) + ' €';
            lowStockElement.textContent = lowStock;
            outOfStockElement.textContent = outOfStock;
            
            // Sauvegarder les données dans le localStorage
            localStorage.setItem('products', JSON.stringify(products));
            localStorage.setItem('categories', JSON.stringify(categories));
            localStorage.setItem('users', JSON.stringify(users));
            localStorage.setItem('attributes', JSON.stringify(attributes));
        }

        // Fonction pour remplir le filtre des catégories
        function populateCategoryFilter() {
            filterCategorySelect.innerHTML = '<option value="all">Toutes catégories</option>';
            categories.forEach(category => {
                if (category.status === 'active') {
                    const option = document.createElement('option');
                    option.value = category.name;
                    option.textContent = category.name;
                    filterCategorySelect.appendChild(option);
                }
            });
            
            // Remplir aussi le select dans le modal produit
            const productCategorySelect = document.getElementById('product-category');
            productCategorySelect.innerHTML = '<option value="">Sélectionner une catégorie</option>';
            categories.forEach(category => {
                if (category.status === 'active') {
                    const option = document.createElement('option');
                    option.value = category.name;
                    option.textContent = category.name;
                    productCategorySelect.appendChild(option);
                }
            });
        }

        // Fonction pour rendre le tableau des produits
        function renderProductsTable(productsToRender = products) {
            filteredProducts = productsToRender;
            totalItemsElement.textContent = filteredProducts.length;
            
            // Pagination
            const startIndex = (currentPage - 1) * itemsPerPage;
            const endIndex = startIndex + itemsPerPage;
            const paginatedProducts = filteredProducts.slice(startIndex, endIndex);
            
            displayedItemsElement.textContent = paginatedProducts.length;
            
            // Activer/désactiver les boutons de pagination
            prevPageBtn.disabled = currentPage === 1;
            nextPageBtn.disabled = endIndex >= filteredProducts.length;
            
            productsTableBody.innerHTML = '';
            
            if (paginatedProducts.length === 0) {
                productsTableBody.innerHTML = `
                    <tr>
                        <td colspan="7" class="px-6 py-4 text-center text-gray-500">
                            Aucun produit trouvé. Ajoutez un nouveau produit en cliquant sur le bouton "Ajouter un produit".
                        </td>
                    </tr>
                `;
                return;
            }
            
            paginatedProducts.forEach(product => {
                const row = document.createElement('tr');
                const value = product.quantity * product.price;
                const quantityClass = product.quantity === 0 ? 'bg-red-100 text-red-800' : 
                                      product.quantity <= 5 ? 'bg-yellow-100 text-yellow-800' : '';
                
                row.innerHTML = `
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${product.id}</td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="text-sm font-medium text-gray-900">${product.name}</div>
                        <div class="text-sm text-gray-500 truncate max-w-xs">${product.description || 'Aucune description'}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                        <span class="px-2 py-1 bg-blue-100 text-blue-800 rounded-full text-xs">${product.category}</span>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <span class="px-2 py-1 rounded-full text-xs font-medium ${quantityClass}">${product.quantity}</span>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${product.price.toFixed(2)} €</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${value.toFixed(2)} €</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                        <button class="edit-product text-blue-600 hover:text-blue-900 mr-3" data-id="${product.id}">
                            <i class="fas fa-edit"></i>
                        </button>
                        <button class="delete-product text-red-600 hover:text-red-900" data-id="${product.id}">
                            <i class="fas fa-trash"></i>
                        </button>
                    </td>
                `;
                
                productsTableBody.appendChild(row);
            });
            
            // Ajouter les événements aux boutons d'édition et de suppression
            document.querySelectorAll('.edit-product').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const productId = parseInt(e.currentTarget.getAttribute('data-id'));
                    editProduct(productId);
                });
            });
            
            document.querySelectorAll('.delete-product').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const productId = parseInt(e.currentTarget.getAttribute('data-id'));
                    deleteProduct(productId);
                });
            });
        }

        // Fonction pour rendre le tableau des catégories
        function renderCategoriesTable(categoriesToRender = categories) {
            categoriesTableBody.innerHTML = '';
            
            if (categoriesToRender.length === 0) {
                categoriesTableBody.innerHTML = `
                    <tr>
                        <td colspan="6" class="px-6 py-4 text-center text-gray-500">
                            Aucune catégorie trouvée. Ajoutez une nouvelle catégorie en cliquant sur le bouton "Ajouter une catégorie".
                        </td>
                    </tr>
                `;
                return;
            }
            
            categoriesToRender.forEach(category => {
                const productsCount = products.filter(p => p.category === category.name).length;
                const statusClass = category.status === 'active' ? 'status-active' : 'status-inactive';
                const statusText = category.status === 'active' ? 'Active' : 'Inactive';
                
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${category.id}</td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="text-sm font-medium text-gray-900">${category.name}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                        ${category.description || 'Aucune description'}
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <span class="status-badge ${statusClass}">${statusText}</span>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${productsCount}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                        <button class="edit-category text-blue-600 hover:text-blue-900 mr-3" data-id="${category.id}">
                            <i class="fas fa-edit"></i>
                        </button>
                        <button class="delete-category text-red-600 hover:text-red-900" data-id="${category.id}">
                            <i class="fas fa-trash"></i>
                        </button>
                    </td>
                `;
                
                categoriesTableBody.appendChild(row);
            });
            
            // Ajouter les événements aux boutons d'édition et de suppression
            document.querySelectorAll('.edit-category').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const categoryId = parseInt(e.currentTarget.getAttribute('data-id'));
                    editCategory(categoryId);
                });
            });
            
            document.querySelectorAll('.delete-category').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const categoryId = parseInt(e.currentTarget.getAttribute('data-id'));
                    deleteCategory(categoryId);
                });
            });
        }

        // Fonction pour rendre le tableau des utilisateurs
        function renderUsersTable(usersToRender = users) {
            usersTableBody.innerHTML = '';
            
            if (usersToRender.length === 0) {
                usersTableBody.innerHTML = `
                    <tr>
                        <td colspan="6" class="px-6 py-4 text-center text-gray-500">
                            Aucun utilisateur trouvé. Ajoutez un nouvel utilisateur en cliquant sur le bouton "Ajouter un utilisateur".
                        </td>
                    </tr>
                `;
                return;
            }
            
            usersToRender.forEach(user => {
                const statusClass = user.status === 'active' ? 'status-active' : 'status-inactive';
                const statusText = user.status === 'active' ? 'Actif' : 'Inactif';
                const roleText = user.role === 'admin' ? 'Administrateur' : 
                                user.role === 'manager' ? 'Gestionnaire' : 'Utilisateur';
                
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${user.id}</td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="text-sm font-medium text-gray-900">${user.firstname} ${user.lastname}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${user.email}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${roleText}</td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <span class="status-badge ${statusClass}">${statusText}</span>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                        <button class="edit-user text-blue-600 hover:text-blue-900 mr-3" data-id="${user.id}">
                            <i class="fas fa-edit"></i>
                        </button>
                        <button class="delete-user text-red-600 hover:text-red-900" data-id="${user.id}">
                            <i class="fas fa-trash"></i>
                        </button>
                    </td>
                `;
                
                usersTableBody.appendChild(row);
            });
            
            // Ajouter les événements aux boutons d'édition et de suppression
            document.querySelectorAll('.edit-user').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const userId = parseInt(e.currentTarget.getAttribute('data-id'));
                    editUser(userId);
                });
            });
            
            document.querySelectorAll('.delete-user').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const userId = parseInt(e.currentTarget.getAttribute('data-id'));
                    deleteUser(userId);
                });
            });
        }

        // Fonction pour rendre le tableau des attributs
        function renderAttributesTable(attributesToRender = attributes) {
            attributesTableBody.innerHTML = '';
            
            if (attributesToRender.length === 0) {
                attributesTableBody.innerHTML = `
                    <tr>
                        <td colspan="6" class="px-6 py-4 text-center text-gray-500">
                            Aucun attribut trouvé. Ajoutez un nouvel attribut en cliquant sur le bouton "Ajouter un attribut".
                        </td>
                    </tr>
                `;
                return;
            }
            
            attributesToRender.forEach(attribute => {
                const typeText = attribute.type === 'select' ? 'Liste déroulante' : 
                               attribute.type === 'text' ? 'Texte' : 
                               attribute.type === 'number' ? 'Nombre' : 'Case à cocher';
                
                const categoryNames = attribute.categories.map(catId => {
                    const category = categories.find(c => c.id === catId);
                    return category ? category.name : 'Inconnue';
                }).join(', ');
                
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${attribute.id}</td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="text-sm font-medium text-gray-900">${attribute.name}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${typeText}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                        ${attribute.values || 'Aucune valeur prédéfinie'}
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                        ${categoryNames || 'Aucune catégorie'}
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                        <button class="edit-attribute text-blue-600 hover:text-blue-900 mr-3" data-id="${attribute.id}">
                            <i class="fas fa-edit"></i>
                        </button>
                        <button class="delete-attribute text-red-600 hover:text-red-900" data-id="${attribute.id}">
                            <i class="fas fa-trash"></i>
                        </button>
                    </td>
                `;
                
                attributesTableBody.appendChild(row);
            });
            
            // Ajouter les événements aux boutons d'édition et de suppression
            document.querySelectorAll('.edit-attribute').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const attributeId = parseInt(e.currentTarget.getAttribute('data-id'));
                    editAttribute(attributeId);
                });
            });
            
            document.querySelectorAll('.delete-attribute').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const attributeId = parseInt(e.currentTarget.getAttribute('data-id'));
                    deleteAttribute(attributeId);
                });
            });
        }

        // Fonction pour ajouter un nouveau produit
        function addProduct() {
            modalProductTitle.textContent = 'Ajouter un produit';
            productForm.reset();
            productModal.classList.remove('hidden');
            
            // Générer un nouvel ID
            const newId = products.length > 0 ? Math.max(...products.map(p => p.id)) + 1 : 1;
            document.getElementById('product-id').value = newId;
            
            // Ajouter les champs d'attributs dynamiques
            updateProductAttributes();
        }

        // Fonction pour éditer un produit existant
        function editProduct(id) {
            const product = products.find(p => p.id === id);
            if (!product) return;
            
            modalProductTitle.textContent = 'Modifier le produit';
            productForm.reset();
            
            document.getElementById('product-id').value = product.id;
            document.getElementById('product-name').value = product.name;
            document.getElementById('product-category').value = product.category;
            document.getElementById('product-quantity').value = product.quantity;
            document.getElementById('product-price').value = product.price;
            document.getElementById('product-description').value = product.description || '';
            
            productModal.classList.remove('hidden');
            
            // Ajouter les champs d'attributs dynamiques
            updateProductAttributes(product.category);
        }

        // Fonction pour mettre à jour les attributs du produit
        function updateProductAttributes(categoryName = null) {
            productAttributesContainer.innerHTML = '';
            
            if (!categoryName) return;
            
            const category = categories.find(c => c.name === categoryName);
            if (!category || !category.attributes || category.attributes.length === 0) return;
            
            category.attributes.forEach(attrId => {
                const attribute = attributes.find(a => a.id === attrId);
                if (!attribute) return;
                
                const div = document.createElement('div');
                div.className = 'mb-4';
                
                const label = document.createElement('label');
                label.className = 'block text-gray-700 mb-2';
                label.textContent = attribute.name;
                div.appendChild(label);
                
                let input;
                
                if (attribute.type === 'select') {
                    input = document.createElement('select');
                    input.className = 'w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300';
                    
                    const defaultOption = document.createElement('option');
                    defaultOption.value = '';
                    defaultOption.textContent = 'Sélectionner une option';
                    input.appendChild(defaultOption);
                    
                    const values = attribute.values.split(',');
                    values.forEach(val => {
                        const option = document.createElement('option');
                        option.value = val.trim();
                        option.textContent = val.trim();
                        input.appendChild(option);
                    });
                } else if (attribute.type === 'checkbox') {
                    const container = document.createElement('div');
                    container.className = 'flex items-center';
                    
                    input = document.createElement('input');
                    input.type = 'checkbox';
                    input.className = 'h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded';
                    
                    const labelSpan = document.createElement('span');
                    labelSpan.className = 'ml-2 text-gray-700';
                    labelSpan.textContent = attribute.name;
                    
                    container.appendChild(input);
                    container.appendChild(labelSpan);
                    div.appendChild(container);
                } else {
                    input = document.createElement('input');
                    input.type = attribute.type;
                    input.className = 'w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300';
                }
                
                if (attribute.type !== 'checkbox') {
                    div.appendChild(input);
                }
                
                productAttributesContainer.appendChild(div);
            });
        }

        // Fonction pour sauvegarder un produit (ajout ou modification)
        function saveProduct() {
            const id = parseInt(document.getElementById('product-id').value);
            const name = document.getElementById('product-name').value.trim();
            const category = document.getElementById('product-category').value;
            const quantity = parseInt(document.getElementById('product-quantity').value);
            const price = parseFloat(document.getElementById('product-price').value);
            const description = document.getElementById('product-description').value.trim();
            
            if (!name || !category || isNaN(quantity) || isNaN(price)) {
                showNotification('Veuillez remplir tous les champs obligatoires', 'error');
                return;
            }
            
            const productData = {
                id,
                name,
                category,
                quantity,
                price,
                description: description || undefined
            };
            
            // Vérifier si c'est une modification ou un ajout
            const existingProductIndex = products.findIndex(p => p.id === id);
            
            if (existingProductIndex !== -1) {
                // Modification
                products[existingProductIndex] = productData;
                showNotification('Produit modifié avec succès', 'success');
            } else {
                // Ajout
                products.push(productData);
                showNotification('Produit ajouté avec succès', 'success');
            }
            
            // Fermer le modal et mettre à jour l'interface
            productModal.classList.add('hidden');
            updateStatistics();
            renderProductsTable(filteredProducts);
        }

        // Fonction pour supprimer un produit
        function deleteProduct(id) {
            if (confirm('Êtes-vous sûr de vouloir supprimer ce produit ?')) {
                products = products.filter(p => p.id !== id);
                showNotification('Produit supprimé avec succès', 'success');
                updateStatistics();
                
                // Si la page actuelle est vide après suppression, revenir à la page précédente
                const startIndex = (currentPage - 1) * itemsPerPage;
                if (startIndex >= filteredProducts.length && currentPage > 1) {
                    currentPage--;
                }
                
                renderProductsTable(filteredProducts);
            }
        }

        // Fonction pour ajouter une nouvelle catégorie
        function addCategory() {
            modalCategoryTitle.textContent = 'Ajouter une catégorie';
            categoryForm.reset();
            categoryModal.classList.remove('hidden');
            
            // Générer un nouvel ID
            const newId = categories.length > 0 ? Math.max(...categories.map(c => c.id)) + 1 : 1;
            document.getElementById('category-id').value = newId;
            
            // Mettre à jour les attributs disponibles
            updateCategoryAttributes();
        }

        // Fonction pour éditer une catégorie existante
        function editCategory(id) {
            const category = categories.find(c => c.id === id);
            if (!category) return;
            
            modalCategoryTitle.textContent = 'Modifier la catégorie';
            categoryForm.reset();
            
            document.getElementById('category-id').value = category.id;
            document.getElementById('category-name').value = category.name;
            document.getElementById('category-description').value = category.description || '';
            document.getElementById('category-status').value = category.status;
            
            categoryModal.classList.remove('hidden');
            
            // Mettre à jour les attributs disponibles
            updateCategoryAttributes(category.attributes);
        }

        // Fonction pour mettre à jour les attributs de la catégorie
        function updateCategoryAttributes(selectedAttributes = []) {
            categoryAttributesContainer.innerHTML = '';
            
            if (attributes.length === 0) {
                categoryAttributesContainer.innerHTML = '<p class="text-sm text-gray-500">Aucun attribut disponible</p>';
                return;
            }
            
            attributes.forEach(attribute => {
                const div = document.createElement('div');
                div.className = 'flex items-center';
                
                const checkbox = document.createElement('input');
                checkbox.type = 'checkbox';
                checkbox.id = `attr-${attribute.id}`;
                checkbox.name = 'category-attributes';
                checkbox.value = attribute.id;
                checkbox.className = 'h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded';
                
                if (selectedAttributes.includes(attribute.id)) {
                    checkbox.checked = true;
                }
                
                const label = document.createElement('label');
                label.htmlFor = `attr-${attribute.id}`;
                label.className = 'ml-2 text-sm text-gray-700';
                label.textContent = `${attribute.name} (${attribute.type})`;
                
                div.appendChild(checkbox);
                div.appendChild(label);
                categoryAttributesContainer.appendChild(div);
            });
        }

        // Fonction pour sauvegarder une catégorie (ajout ou modification)
        function saveCategory() {
            const id = parseInt(document.getElementById('category-id').value);
            const name = document.getElementById('category-name').value.trim();
            const description = document.getElementById('category-description').value.trim();
            const status = document.getElementById('category-status').value;
            
            if (!name) {
                showNotification('Veuillez remplir tous les champs obligatoires', 'error');
                return;
            }
            
            // Récupérer les attributs sélectionnés
            const selectedAttributes = [];
            document.querySelectorAll('input[name="category-attributes"]:checked').forEach(checkbox => {
                selectedAttributes.push(parseInt(checkbox.value));
            });
            
            const categoryData = {
                id,
                name,
                description: description || undefined,
                status,
                attributes: selectedAttributes
            };
            
            // Vérifier si c'est une modification ou un ajout
            const existingCategoryIndex = categories.findIndex(c => c.id === id);
            
            if (existingCategoryIndex !== -1) {
                // Modification
                categories[existingCategoryIndex] = categoryData;
                showNotification('Catégorie modifiée avec succès', 'success');
            } else {
                // Ajout
                categories.push(categoryData);
                showNotification('Catégorie ajoutée avec succès', 'success');
            }
            
            // Fermer le modal et mettre à jour l'interface
            categoryModal.classList.add('hidden');
            updateStatistics();
            renderCategoriesTable();
            populateCategoryFilter();
            
            // Si on est sur l'onglet produits, recharger les produits pour mettre à jour les catégories
            if (document.querySelector('.tab-button.active').dataset.tab === 'products') {
                renderProductsTable();
            }
        }

        // Fonction pour supprimer une catégorie
        function deleteCategory(id) {
            // Vérifier si la catégorie est utilisée par des produits
            const category = categories.find(c => c.id === id);
            if (!category) return;
            
            const productsUsingCategory = products.filter(p => p.category === category.name);
            
            if (productsUsingCategory.length > 0) {
                showNotification('Cette catégorie est utilisée par des produits et ne peut pas être supprimée', 'error');
                return;
            }
            
            if (confirm('Êtes-vous sûr de vouloir supprimer cette catégorie ?')) {
                categories = categories.filter(c => c.id !== id);
                showNotification('Catégorie supprimée avec succès', 'success');
                updateStatistics();
                renderCategoriesTable();
                populateCategoryFilter();
            }
        }

        // Fonction pour ajouter un nouvel utilisateur
        function addUser() {
            modalUserTitle.textContent = 'Ajouter un utilisateur';
            userForm.reset();
            userModal.classList.remove('hidden');
            
            // Générer un nouvel ID
            const newId = users.length > 0 ? Math.max(...users.map(u => u.id)) + 1 : 1;
            document.getElementById('user-id').value = newId;
            
            // Afficher le champ mot de passe et le rendre obligatoire pour un nouvel utilisateur
            document.getElementById('user-password').required = true;
        }

        // Fonction pour éditer un utilisateur existant
        function editUser(id) {
            const user = users.find(u => u.id === id);
            if (!user) return;
            
            modalUserTitle.textContent = 'Modifier l\'utilisateur';
            userForm.reset();
            
            document.getElementById('user-id').value = user.id;
            document.getElementById('user-firstname').value = user.firstname;
            document.getElementById('user-lastname').value = user.lastname;
            document.getElementById('user-email').value = user.email;
            document.getElementById('user-role').value = user.role;
            document.getElementById('user-status').value = user.status;
            
            // Cacher le champ mot de passe et le rendre non obligatoire pour la modification
            document.getElementById('user-password').required = false;
            
            userModal.classList.remove('hidden');
        }

        // Fonction pour sauvegarder un utilisateur (ajout ou modification)
        function saveUser() {
            const id = parseInt(document.getElementById('user-id').value);
            const firstname = document.getElementById('user-firstname').value.trim();
            const lastname = document.getElementById('user-lastname').value.trim();
            const email = document.getElementById('user-email').value.trim();
            const role = document.getElementById('user-role').value;
            const status = document.getElementById('user-status').value;
            const password = document.getElementById('user-password').value;
            
            if (!firstname || !lastname || !email || !role || !status) {
                showNotification('Veuillez remplir tous les champs obligatoires', 'error');
                return;
            }
            
            // Pour un nouvel utilisateur, vérifier le mot de passe
            const isNewUser = !users.some(u => u.id === id);
            if (isNewUser && !password) {
                showNotification('Veuillez saisir un mot de passe', 'error');
                return;
            }
            
            const userData = {
                id,
                firstname,
                lastname,
                email,
                role,
                status
            };
            
            // Si un mot de passe est fourni, l'ajouter/modifier
            if (password) {
                userData.password = password;
            } else if (isNewUser) {
                // Pour un nouvel utilisateur, générer un mot de passe aléatoire
                userData.password = Math.random().toString(36).slice(-8);
            }
            
            // Vérifier si c'est une modification ou un ajout
            const existingUserIndex = users.findIndex(u => u.id === id);
            
            if (existingUserIndex !== -1) {
                // Modification - conserver le mot de passe existant si aucun nouveau n'est fourni
                if (!password) {
                    userData.password = users[existingUserIndex].password;
                }
                
                users[existingUserIndex] = userData;
                showNotification('Utilisateur modifié avec succès', 'success');
            } else {
                // Ajout
                users.push(userData);
                showNotification('Utilisateur ajouté avec succès', 'success');
            }
            
            // Fermer le modal et mettre à jour l'interface
            userModal.classList.add('hidden');
            updateStatistics();
            renderUsersTable();
        }

        // Fonction pour supprimer un utilisateur
        function deleteUser(id) {
            // Empêcher la suppression de l'utilisateur admin principal
            if (id === 1) {
               
</html>