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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>نانو بوت - الرسائل</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>

        :root {

            --primary-color: #4361ee;

            --primary-light: #4895ef;

            --primary-dark: #3f37c9;

            --secondary-color: #4cc9f0;

            --success-color: #4caf50;

            --danger-color: #f72585;

            --warning-color: #ff9e00;

            --info-color: #3a86ff;

            --light-color: #f8f9fa;

            --dark-color: #212529;

            --body-bg: #f0f5ff;

            --card-bg: #ffffff;

            --border-color: #e9ecef;

            --text-color: #333;

            --text-muted: #6c757d;

            --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);

            --shadow-md: 0 5px 15px rgba(0, 0, 0, 0.07);

            --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

            --transition: all 0.3s ease;

            --border-radius: 12px;

        }



        * {

            margin: 0;

            padding: 0;

            box-sizing: border-box;

            font-family: 'Tajawal', sans-serif;

        }



        body {

            background-color: var(--body-bg);

            color: var(--text-color);

            min-height: 100vh;

            display: flex;

            flex-direction: column;

        }



        /* Scrollbar Styling */

        ::-webkit-scrollbar {

            width: 8px;

            height: 8px;

        }



        ::-webkit-scrollbar-track {

            background: #f1f1f1;

            border-radius: 10px;

        }



        ::-webkit-scrollbar-thumb {

            background: var(--primary-light);

            border-radius: 10px;

        }



        ::-webkit-scrollbar-thumb:hover {

            background: var(--primary-color);

        }



        /* Navigation */

        .navbar {

            background-color: var(--card-bg);

            color: var(--text-color);

            padding: 15px 20px;

            display: flex;

            justify-content: space-between;

            align-items: center;

            box-shadow: var(--shadow-md);

            position: sticky;

            top: 0;

            z-index: 100;

        }



        .navbar-brand {

            display: flex;

            align-items: center;

            font-size: 22px;

            font-weight: 700;

            color: var(--primary-color);

        }



        .navbar-brand svg {

            width: 28px;

            height: 28px;

            margin-left: 10px;

            fill: var(--primary-color);

        }



        .navbar-nav {

            display: flex;

            align-items: center;

        }



        .nav-item {

            margin-right: 20px;

        }



        .nav-link {

            color: var(--text-color);

            text-decoration: none;

            font-weight: 500;

            transition: var(--transition);

            display: flex;

            align-items: center;

        }



        .nav-link:hover {

            color: var(--primary-color);

        }



        .nav-link svg {

            margin-left: 5px;

            width: 18px;

            height: 18px;

        }



        .container {

            max-width: 1200px;

            width: 100%;

            margin: 0 auto;

            padding: 20px;

            flex: 1;

        }



        /* Page Header */

        .page-header {

            display: flex;

            justify-content: space-between;

            align-items: center;

            margin-bottom: 20px;

            flex-wrap: wrap;

            gap: 15px;

        }



        .page-title {

            font-size: 24px;

            font-weight: 700;

            color: var(--primary-color);

            display: flex;

            align-items: center;

        }



        .page-title svg {

            margin-left: 10px;

            width: 24px;

            height: 24px;

        }



        .page-actions {

            display: flex;

            gap: 10px;

        }



        /* Messages */

        .messages-container {

            display: grid;

            grid-template-columns: 1fr;

            gap: 20px;

        }



        @media (min-width: 768px) {

            .messages-container {

                grid-template-columns: repeat(2, 1fr);

            }

        }



        @media (min-width: 1200px) {

            .messages-container {

                grid-template-columns: repeat(3, 1fr);

            }

        }



        .message-card {

            background-color: var(--card-bg);

            border-radius: var(--border-radius);

            box-shadow: var(--shadow-sm);

            transition: var(--transition);

            overflow: hidden;

            position: relative;

        }



        .message-card:hover {

            box-shadow: var(--shadow-md);

            transform: translateY(-3px);

        }



        .message-card.unread::before {

            content: '';

            position: absolute;

            top: 15px;

            left: 15px;

            width: 10px;

            height: 10px;

            background-color: var(--primary-color);

            border-radius: 50%;

        }



        .message-header {

            padding: 15px 20px;

            border-bottom: 1px solid var(--border-color);

            display: flex;

            align-items: center;

        }



        .user-avatar {

            width: 40px;

            height: 40px;

            border-radius: 50%;

            background-color: var(--primary-light);

            display: flex;

            align-items: center;

            justify-content: center;

            color: white;

            font-weight: 700;

            margin-left: 15px;

            flex-shrink: 0;

            overflow: hidden;

        }



        .user-avatar img {

            width: 100%;

            height: 100%;

            object-fit: cover;

        }



        .user-info {

            flex: 1;

        }



        .user-name {

            font-weight: 700;

            margin-bottom: 5px;

        }



        .message-time {

            font-size: 12px;

            color: var(--text-muted);

        }



        .message-body {

            padding: 20px;

            min-height: 100px;

        }



        .message-text {

            line-height: 1.6;

            margin-bottom: 15px;

        }



        .message-footer {

            padding: 15px 20px;

            border-top: 1px solid var(--border-color);

            display: flex;

            justify-content: space-between;

            align-items: center;

        }



        .message-actions {

            display: flex;

            gap: 10px;

        }



        .btn {

            display: inline-block;

            padding: 8px 16px;

            border: none;

            border-radius: 8px;

            font-size: 14px;

            font-weight: 500;

            cursor: pointer;

            transition: var(--transition);

            text-align: center;

            text-decoration: none;

        }



        .btn-primary {

            background-color: var(--primary-color);

            color: white;

        }



        .btn-primary:hover {

            background-color: var(--primary-dark);

        }



        .btn-danger {

            background-color: var(--danger-color);

            color: white;

        }



        .btn-danger:hover {

            background-color: #d61a6c;

        }



        .btn-outline {

            background-color: transparent;

            border: 1px solid var(--border-color);

            color: var(--text-color);

        }



        .btn-outline:hover {

            background-color: var(--light-color);

        }



        .btn-sm {

            padding: 6px 12px;

            font-size: 12px;

        }



        .btn svg {

            width: 16px;

            height: 16px;

            margin-left: 5px;

            vertical-align: middle;

        }



        /* Empty State */

        .empty-state {

            text-align: center;

            padding: 50px 20px;

            background-color: var(--card-bg);

            border-radius: var(--border-radius);

            box-shadow: var(--shadow-sm);

        }



        .empty-icon {

            width: 80px;

            height: 80px;

            margin: 0 auto 20px;

            color: var(--text-muted);

        }



        .empty-title {

            font-size: 20px;

            font-weight: 700;

            margin-bottom: 10px;

            color: var(--text-color);

        }



        .empty-description {

            color: var(--text-muted);

            margin-bottom: 20px;

        }



        /* Loading */

        .loading-overlay {

            position: fixed;

            top: 0;

            left: 0;

            right: 0;

            bottom: 0;

            background-color: rgba(255, 255, 255, 0.8);

            display: flex;

            justify-content: center;

            align-items: center;

            z-index: 2000;

            opacity: 0;

            visibility: hidden;

            transition: var(--transition);

        }



        .loading-overlay.active {

            opacity: 1;

            visibility: visible;

        }



        .spinner {

            width: 50px;

            height: 50px;

            border: 5px solid rgba(67, 97, 238, 0.2);

            border-radius: 50%;

            border-top-color: var(--primary-color);

            animation: spin 1s linear infinite;

        }



        @keyframes spin {

            0% { transform: rotate(0deg); }

            100% { transform: rotate(360deg); }

        }



        /* Notifications */

        .notification-container {

            position: fixed;

            top: 20px;

            left: 20px;

            right: 20px;

            z-index: 1001;

            display: flex;

            flex-direction: column;

            align-items: center;

            pointer-events: none;

        }



        .notification {

            background-color: var(--card-bg);

            border-radius: 8px;

            box-shadow: var(--shadow-md);

            padding: 15px 20px;

            margin-bottom: 10px;

            display: flex;

            align-items: center;

            width: 100%;

            max-width: 400px;

            transform: translateY(-20px);

            opacity: 0;

            transition: all 0.3s ease;

            pointer-events: auto;

        }



        .notification.show {

            transform: translateY(0);

            opacity: 1;

        }



        .notification-icon {

            width: 24px;

            height: 24px;

            margin-left: 15px;

            flex-shrink: 0;

        }



        .notification-content {

            flex: 1;

        }



        .notification-title {

            font-weight: 700;

            margin-bottom: 5px;

        }



        .notification-message {

            font-size: 14px;

            color: var(--text-muted);

        }



        .notification-close {

            background: none;

            border: none;

            cursor: pointer;

            color: var(--text-muted);

            margin-right: -5px;

        }



        .notification.success .notification-icon {

            color: var(--success-color);

        }



        .notification.error .notification-icon {

            color: var(--danger-color);

        }



        .notification.info .notification-icon {

            color: var(--info-color);

        }



        /* Responsive Adjustments */

        @media (max-width: 768px) {

            .navbar {

                padding: 10px 15px;

            }



            .navbar-brand {

                font-size: 18px;

            }



            .container {

                padding: 15px;

            }



            .page-title {

                font-size: 20px;

            }



            .message-header {

                padding: 12px 15px;

            }



            .message-body {

                padding: 15px;

            }



            .message-footer {

                padding: 12px 15px;

            }

        }



        .message-time {

    font-size: 12px;

    color: var(--text-muted);

    display: flex;

    align-items: center;

    gap: 5px;

}



.seen-status {

    color: var(--text-muted);

}



.seen-status.new {

    color: var(--primary-color);

    font-weight: 500;

}



.navbar .logo-icon {

    width: 40px;

    height: 40px;

    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));

    border-radius: 12px;

    display: flex;

    align-items: center;

    justify-content: center;

    box-shadow: 0 5px 15px rgba(67, 97, 238, 0.2);

    position: relative;

    overflow: hidden;

    margin-left: 10px;

}



.navbar .logo-icon::before {

    content: '';

    position: absolute;

    top: -10px;

    left: -10px;

    right: -10px;

    bottom: -10px;

    background: linear-gradient(135deg, rgba(255,255,255,0.2), rgba(255,255,255,0));

    transform: rotate(35deg);

}



.navbar .logo-icon i {

    color: white;

    font-size: 20px;

    position: relative;

    z-index: 2;

}



.navbar .logo-text h1 {

    font-size: 18px;

    font-weight: 800;

    margin: 0;

}



.navbar .logo-text p {

    font-size: 12px;

    margin: 0;

}



.navbar-brand {

    display: flex;

    align-items: center;

}

    </style>
</head>
<body>
    <!-- Loading Overlay -->
    <div class="loading-overlay" id="loadingOverlay">
        <div class="spinner"></div>
    </div>

    <!-- Notification Container -->
    <div class="notification-container" id="notificationContainer"></div>

    <!-- Navbar -->
    <nav class="navbar">
        <div class="navbar-brand">
            <div class="logo-icon">
                <i class="fas fa-robot"></i>
            </div>
            <div class="logo-text">
                <h1>NANO  BOT</h1>
            </div>
        </div>
        <div class="navbar-nav">
            <div class="nav-item">
                <a href="{{ url_for('dashboard') }}" class="nav-link">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                        <path d="M4 13h6a1 1 0 0 0 1-1V4a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1zm-1 7a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v4zm10 0a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1v-7a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v7zm1-10h6a1 1 0 0 0 1-1V4a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1z"/>
                    </svg>
                    لوحة التحكم
                </a>
            </div>
            <div class="nav-item">
                <a href="{{ url_for('logout') }}" class="nav-link">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                        <path d="M16 13v-2H7V8l-5 4 5 4v-3z"/>
                        <path d="M20 3h-9c-1.103 0-2 .897-2 2v4h2V5h9v14h-9v-4H9v4c0 1.103.897 2 2 2h9c1.103 0 2-.897 2-2V5c0-1.103-.897-2-2-2z"/>
                    </svg>
                    تسجيل الخروج
                </a>
            </div>
        </div>
    </nav>

    <!-- Main Container -->
    <div class="container">
        <div class="page-header">
            <h1 class="page-title">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                    <path d="M20 4H4c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h16c1.103 0 2-.897 2-2V6c0-1.103-.897-2-2-2zm0 2v.511l-8 6.223-8-6.222V6h16zM4 18V9.044l7.386 5.745a.994.994 0 0 0 1.228 0L20 9.044 20.002 18H4z"/>
                </svg>
                رسائل الإدارة
            </h1>
            <div class="page-actions">
                <button class="btn btn-primary" id="refreshBtn">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                        <path d="M10 11H7.101l.001-.009a4.956 4.956 0 0 1 .752-1.787 5.054 5.054 0 0 1 2.2-1.811c.302-.128.617-.226.938-.291a5.078 5.078 0 0 1 2.018 0 4.978 4.978 0 0 1 2.525 1.361l1.416-1.412a7.036 7.036 0 0 0-2.224-1.501 6.921 6.921 0 0 0-1.315-.408 7.079 7.079 0 0 0-2.819 0 6.94 6.94 0 0 0-1.316.409 7.04 7.04 0 0 0-3.08 2.534 6.978 6.978 0 0 0-1.054 2.505c-.028.135-.043.273-.063.41H2l4 4 4-4zm4 2h2.899l-.001.008a4.976 4.976 0 0 1-2.103 3.138 4.943 4.943 0 0 1-1.787.752 5.073 5.073 0 0 1-2.017 0 4.956 4.956 0 0 1-1.787-.752 5.072 5.072 0 0 1-.74-.61L7.05 16.95a7.032 7.032 0 0 0 2.225 1.5c.424.18.867.317 1.315.408a7.07 7.07 0 0 0 2.818 0 7.031 7.031 0 0 0 4.395-2.945 6.974 6.974 0 0 0 1.053-2.503c.027-.135.043-.273.063-.41H22l-4-4-4 4z"/>
                    </svg>
                    تحديث
                </button>
            </div>
        </div>

        {% if messages|length > 0 %}
        <div class="messages-container">
            {% for message in messages %}
            <div class="message-card {% if 'seen' not in message %}unread{% endif %}" data-index="{{ loop.index0 }}">
                <div class="message-header">
                    <div class="user-avatar">
                        {{ message.full_name[0] }}
                    </div>
                    <div class="user-info">
                        <div class="user-name">{{ message.full_name }}</div>
                        <div class="message-time">
                            {% if message.timestamp %}
                                {% set timestamp = message.timestamp.split('T') %}
                                <span>{{ timestamp[0] }} {{ timestamp[1].split('.')[0] }}</span>
                                {% if 'seen' in message %}
                                <span class="seen-status">• تم القراءة</span>
                                {% else %}
                                <span class="seen-status new">• جديد</span>
                                {% endif %}
                            {% else %}
                                {% if 'seen' in message %}
                                <span>تم القراءة</span>
                                {% else %}
                                <span>جديد</span>
                                {% endif %}
                            {% endif %}
                        </div>
                    </div>
                </div>
                <div class="message-body">
                    <div class="message-text">{{ message.message }}</div>
                </div>
                <div class="message-footer">
                    <div class="message-actions">
                        {% if 'seen' not in message %}
                        <button class="btn btn-outline btn-sm mark-seen-btn" data-index="{{ loop.index0 }}">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                                <path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>
                            </svg>
                            تعليم كمقروء
                        </button>
                        {% endif %}
                    </div>
                    <button class="btn btn-danger btn-sm delete-btn" data-index="{{ loop.index0 }}">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                            <path d="M5 20a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8h2V6h-4V4a2 2 0 0 0-2-2H9a2 2 0 0 0-2 2v2H3v2h2zM9 4h6v2H9zM8 8h9v12H7V8z"/>
                            <path d="M9 10h2v8H9zm4 0h2v8h-2z"/>
                        </svg>
                        حذف
                    </button>
                </div>
            </div>
            {% endfor %}
        </div>
        {% else %}
        <div class="empty-state">
            <svg class="empty-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M20 4H4c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h16c1.103 0 2-.897 2-2V6c0-1.103-.897-2-2-2zm0 2v.511l-8 6.223-8-6.222V6h16zM4 18V9.044l7.386 5.745a.994.994 0 0 0 1.228 0L20 9.044 20.002 18H4z"/>
            </svg>
            <h3 class="empty-title">لا توجد رسائل</h3>
            <p class="empty-description">لم يتم العثور على أي رسائل من العملاء في الوقت الحالي.</p>
            <button class="btn btn-primary" id="emptyRefreshBtn">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                    <path d="M10 11H7.101l.001-.009a4.956 4.956 0 0 1 .752-1.787 5.054 5.054 0 0 1 2.2-1.811c.302-.128.617-.226.938-.291a5.078 5.078 0 0 1 2.018 0 4.978 4.978 0 0 1 2.525 1.361l1.416-1.412a7.036 7.036 0 0 0-2.224-1.501 6.921 6.921 0 0 0-1.315-.408 7.079 7.079 0 0 0-2.819 0 6.94 6.94 0 0 0-1.316.409 7.04 7.04 0 0 0-3.08 2.534 6.978 6.978 0 0 0-1.054 2.505c-.028.135-.043.273-.063.41H2l4 4 4-4zm4 2h2.899l-.001.008a4.976 4.976 0 0 1-2.103 3.138 4.943 4.943 0 0 1-1.787.752 5.073 5.073 0 0 1-2.017 0 4.956 4.956 0 0 1-1.787-.752 5.072 5.072 0 0 1-.74-.61L7.05 16.95a7.032 7.032 0 0 0 2.225 1.5c.424.18.867.317 1.315.408a7.07 7.07 0 0 0 2.818 0 7.031 7.031 0 0 0 4.395-2.945 6.974 6.974 0 0 0 1.053-2.503c.027-.135.043-.273.063-.41H22l-4-4-4 4z"/>
                </svg>
                تحديث
            </button>
        </div>
        {% endif %}
    </div>
    <!-- Confirmation Dialog -->
<div class="confirmation-dialog" id="confirmationDialog">
    <div class="confirmation-content">
        <div class="confirmation-header">
            <h3>تأكيد الحذف</h3>
            <button class="close-btn" id="closeConfirmBtn">&times;</button>
        </div>
        <div class="confirmation-body">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="confirmation-icon">
                <path d="M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"/>
                <path d="M13 7h-2v6h2zm0 8h-2v2h2z"/>
            </svg>
            <p>هل أنت متأكد من حذف هذه الرسالة؟</p>
            <p class="confirmation-note">لا يمكن التراجع عن هذا الإجراء.</p>
        </div>
        <div class="confirmation-footer">
            <button class="btn btn-outline" id="cancelDeleteBtn">إلغاء</button>
            <button class="btn btn-danger" id="confirmDeleteBtn">تأكيد الحذف</button>
        </div>
    </div>
</div>

<style>

    /* Confirmation Dialog */

.confirmation-dialog {

    position: fixed;

    top: 0;

    left: 0;

    right: 0;

    bottom: 0;

    background-color: rgba(0, 0, 0, 0.5);

    display: flex;

    justify-content: center;

    align-items: center;

    z-index: 2000;

    opacity: 0;

    visibility: hidden;

    transition: var(--transition);

}



.confirmation-dialog.active {

    opacity: 1;

    visibility: visible;

}



.confirmation-content {

    background-color: var(--card-bg);

    border-radius: var(--border-radius);

    box-shadow: var(--shadow-lg);

    width: 90%;

    max-width: 400px;

    transform: translateY(-20px);

    transition: transform 0.3s ease;

}



.confirmation-dialog.active .confirmation-content {

    transform: translateY(0);

}



.confirmation-header {

    padding: 15px 20px;

    border-bottom: 1px solid var(--border-color);

    display: flex;

    justify-content: space-between;

    align-items: center;

}



.confirmation-header h3 {

    margin: 0;

    color: var(--danger-color);

    font-weight: 700;

}



.close-btn {

    background: none;

    border: none;

    font-size: 24px;

    cursor: pointer;

    color: var(--text-muted);

}



.confirmation-body {

    padding: 20px;

    text-align: center;

}



.confirmation-icon {

    width: 60px;

    height: 60px;

    margin-bottom: 15px;

    color: var(--danger-color);

}



.confirmation-note {

    font-size: 14px;

    color: var(--text-muted);

    margin-top: 10px;

}



.confirmation-footer {

    padding: 15px 20px;

    border-top: 1px solid var(--border-color);

    display: flex;

    justify-content: flex-end;

    gap: 10px;

}

</style>

<script>

    // DOM Elements

    const loadingOverlay = document.getElementById('loadingOverlay');

    const notificationContainer = document.getElementById('notificationContainer');

    const refreshBtn = document.getElementById('refreshBtn');

    const emptyRefreshBtn = document.getElementById('emptyRefreshBtn');

    const markSeenBtns = document.querySelectorAll('.mark-seen-btn');

    const deleteBtns = document.querySelectorAll('.delete-btn');

    let confirmationDialog;

    let closeConfirmBtn;

    let cancelDeleteBtn;

    let confirmDeleteBtn;

    let messageToDelete = null;



    // WebSocket Connection

    let socket;

    let recentActions = new Set(); // Track recent actions to prevent duplicate notifications



    function connectWebSocket() {

        socket = io.connect(window.location.origin);



        socket.on('connect', function() {

            console.log('WebSocket connected');

        });



        socket.on('message_seen', function(data) {

            const actionKey = `seen_${data.page_id}_${data.index}`;

            // Only show notification if this wasn't a local action

            if (!recentActions.has(actionKey)) {

                showNotification('تم تحديث الحالة', 'تم تعليم الرسالة كمقروءة', 'success');



                // Update UI if needed

                const messageCard = document.querySelector(`.message-card[data-index="${data.index}"]`);

                if (messageCard) {

                    messageCard.classList.remove('unread');

                    const markSeenBtn = messageCard.querySelector('.mark-seen-btn');

                    if (markSeenBtn) {

                        markSeenBtn.remove();

                    }

                    const seenStatus = messageCard.querySelector('.seen-status');

                    if (seenStatus) {

                        seenStatus.textContent = '• تم القراءة';

                        seenStatus.classList.remove('new');

                    }

                }

            }

        });



        socket.on('message_deleted', function(data) {

            const actionKey = `delete_${data.page_id}_${data.index}`;

            // Only show notification if this wasn't a local action

            if (!recentActions.has(actionKey)) {

                showNotification('تم الحذف', 'تم حذف الرسالة بنجاح', 'success');



                // Remove message card from UI if needed

                const messageCard = document.querySelector(`.message-card[data-index="${data.index}"]`);

                if (messageCard) {

                    messageCard.style.opacity = '0';

                    messageCard.style.transform = 'translateY(20px)';

                    setTimeout(() => {

                        messageCard.remove();



                        // Check if there are no more messages

                        const remainingMessages = document.querySelectorAll('.message-card');

                        if (remainingMessages.length === 0) {

                            // Reload the page to show empty state

                            window.location.reload();

                        }

                    }, 300);

                }

            }

        });



        socket.on('data_refreshed', function(data) {

            const actionKey = `refresh_${data.type}`;

            // Only show notification if this wasn't a local action

            if (!recentActions.has(actionKey)) {

                showNotification('تم التحديث', 'تم تحديث الرسائل بنجاح', 'info');

                setTimeout(() => {

                    window.location.reload();

                }, 1000);

            }

        });

    }



    // Helper function to track recent actions

    function trackAction(actionType, pageId, index) {

        const actionKey = `${actionType}_${pageId}_${index}`;

        recentActions.add(actionKey);



        // Remove from tracking after 5 seconds

        setTimeout(() => {

            recentActions.delete(actionKey);

        }, 5000);



        return actionKey;

    }



    // Initialize

    document.addEventListener('DOMContentLoaded', function() {

        // Connect WebSocket

        connectWebSocket();



        // Get confirmation dialog elements

        confirmationDialog = document.getElementById('confirmationDialog');

        closeConfirmBtn = document.getElementById('closeConfirmBtn');

        cancelDeleteBtn = document.getElementById('cancelDeleteBtn');

        confirmDeleteBtn = document.getElementById('confirmDeleteBtn');



        // Set up confirmation dialog buttons

        closeConfirmBtn.addEventListener('click', closeConfirmation);

        cancelDeleteBtn.addEventListener('click', closeConfirmation);

        confirmDeleteBtn.addEventListener('click', function() {

            if (messageToDelete !== null) {

                proceedWithDelete(messageToDelete);

                closeConfirmation();

            }

        });



        // Refresh Button

        if (refreshBtn) {

            refreshBtn.addEventListener('click', function() {

                refreshMessages();

            });

        }



        // Empty Refresh Button

        if (emptyRefreshBtn) {

            emptyRefreshBtn.addEventListener('click', function() {

                refreshMessages();

            });

        }



        // Mark Seen Buttons

        markSeenBtns.forEach(btn => {

            btn.addEventListener('click', function() {

                const index = this.getAttribute('data-index');

                markMessageAsSeen(index);

            });

        });



        // Delete Buttons

        deleteBtns.forEach(btn => {

            btn.addEventListener('click', function() {

                const index = this.getAttribute('data-index');

                showDeleteConfirmation(index);

            });

        });

    });



    // Functions

    function showLoading() {

        loadingOverlay.classList.add('active');

    }



    function hideLoading() {

        loadingOverlay.classList.remove('active');

    }



    function showNotification(title, message, type = 'info') {

        const notification = document.createElement('div');

        notification.className = `notification ${type}`;



        let iconSvg;

        if (type === 'success') {

            iconSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="notification-icon">

                <path d="M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"/>

                <path d="M9.999 13.587 7.7 11.292l-1.412 1.416 3.713 3.705 6.706-6.706-1.414-1.414z"/>

            </svg>`;

        } else if (type === 'error') {

            iconSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="notification-icon">

                <path d="M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"/>

                <path d="M13 7h-2v7h2zm0 8h-2v2h2z"/>

            </svg>`;

        } else {

            iconSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="notification-icon">

                <path d="M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"/>

                <path d="M11 11h2v6h-2zm0-4h2v2h-2z"/>

            </svg>`;

        }



        notification.innerHTML = `

            ${iconSvg}

            <div class="notification-content">

                <div class="notification-title">${title}</div>

                <div class="notification-message">${message}</div>

            </div>

            <button class="notification-close">&times;</button>

        `;



        notificationContainer.appendChild(notification);



        // Show notification with animation

        setTimeout(() => {

            notification.classList.add('show');

        }, 10);



        // Auto close after 5 seconds

        setTimeout(() => {

            closeNotification(notification);

        }, 5000);



        // Close button

        notification.querySelector('.notification-close').addEventListener('click', function() {

            closeNotification(notification);

        });

    }



    function closeNotification(notification) {

        notification.classList.remove('show');

        setTimeout(() => {

            notification.remove();

        }, 300);

    }



    function refreshMessages() {

        // Track this action to prevent duplicate notifications

        trackAction('refresh', 'messages', null);



        showLoading();



        fetch('/api/refresh_data', {

            method: 'POST',

            headers: {

                'Content-Type': 'application/json',

            },

            body: JSON.stringify({ type: 'messages' }),

        })

        .then(response => response.json())

        .then(data => {

            hideLoading();

            if (data.success) {

                showNotification('تم التحديث', 'تم تحديث الرسائل بنجاح', 'success');

                setTimeout(() => {

                    window.location.reload();

                }, 1500);

            } else {

                showNotification('خطأ', data.message, 'error');

            }

        })

        .catch(error => {

            hideLoading();

            showNotification('خطأ', 'حدث خطأ أثناء تحديث الرسائل', 'error');

            console.error('Error:', error);

        });

    }



    function markMessageAsSeen(index) {

        // Ensure index is a number

        index = parseInt(index, 10);



        // Track this action to prevent duplicate notifications

        const pageId = '{{ page.page_id }}'; // Get page_id from template

        trackAction('seen', pageId, index);



        showLoading();



        fetch('/api/mark_message_seen', {

            method: 'POST',

            headers: {

                'Content-Type': 'application/json',

            },

            body: JSON.stringify({ index: index }),

        })

        .then(response => response.json())

        .then(data => {

            hideLoading();

            if (data.success) {

                showNotification('تم التحديث', 'تم تعليم الرسالة كمقروءة', 'success');



                // Update UI

                const messageCard = document.querySelector(`.message-card[data-index="${index}"]`);

                if (messageCard) {

                    messageCard.classList.remove('unread'); // Remove unread class

                    const markSeenBtn = messageCard.querySelector('.mark-seen-btn');

                    if (markSeenBtn) {

                        markSeenBtn.remove(); // Remove the "Mark as Seen" button

                    }

                    const seenStatus = messageCard.querySelector('.seen-status');

                    if (seenStatus) {

                        seenStatus.textContent = '• تم القراءة';

                        seenStatus.classList.remove('new');

                    }

                }

            } else {

                showNotification('خطأ', data.message, 'error');

            }

        })

        .catch(error => {

            hideLoading();

            showNotification('خطأ', 'حدث خطأ أثناء تعليم الرسالة كمقروءة', 'error');

            console.error('Error:', error);

        });

    }



    function showDeleteConfirmation(index) {

        messageToDelete = index;

        confirmationDialog.classList.add('active');

        // Prevent scrolling on the body

        document.body.style.overflow = 'hidden';

    }



    function closeConfirmation() {

        confirmationDialog.classList.remove('active');

        // Re-enable scrolling

        document.body.style.overflow = '';

        // Reset the message to delete

        setTimeout(() => {

            messageToDelete = null;

        }, 300);

    }



    function proceedWithDelete(index) {

        // Track this action to prevent duplicate notifications

        const pageId = '{{ page.page_id }}'; // Get page_id from template

        trackAction('delete', pageId, index);



        showLoading();



        fetch('/api/delete_message', {

            method: 'POST',

            headers: {

                'Content-Type': 'application/json',

            },

            body: JSON.stringify({ index: index }),

        })

        .then(response => response.json())

        .then(data => {

            hideLoading();

            if (data.success) {

                showNotification('تم الحذف', 'تم حذف الرسالة بنجاح', 'success');



                // Remove message card from UI

                const messageCard = document.querySelector(`.message-card[data-index="${index}"]`);

                if (messageCard) {

                    messageCard.style.opacity = '0';

                    messageCard.style.transform = 'translateY(20px)';

                    setTimeout(() => {

                        messageCard.remove();



                        // Check if there are no more messages

                        const remainingMessages = document.querySelectorAll('.message-card');

                        if (remainingMessages.length === 0) {

                            // Reload the page to show empty state

                            window.location.reload();

                        }

                    }, 300);

                }

            } else {

                showNotification('خطأ', data.message, 'error');

            }

        })

        .catch(error => {

            hideLoading();

            showNotification('خطأ', 'حدث خطأ أثناء حذف الرسالة', 'error');

            console.error('Error:', error);

        });

    }

</script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
</body>
</html>