File size: 56,779 Bytes
18ed172
 
 
 
 
 
 
 
 
 
 
 
5e959ed
18ed172
 
 
 
 
 
 
 
 
 
 
 
5e959ed
18ed172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e959ed
 
769319f
18ed172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e959ed
 
18ed172
 
 
 
 
 
 
 
 
5e959ed
18ed172
 
 
5e959ed
 
18ed172
 
 
5e959ed
18ed172
 
 
 
 
 
769319f
5e959ed
18ed172
 
 
 
 
 
5e959ed
18ed172
 
 
 
 
 
5e959ed
18ed172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769319f
18ed172
5e959ed
18ed172
 
 
 
 
5e959ed
18ed172
 
 
 
 
5e959ed
18ed172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e959ed
18ed172
 
 
 
 
 
 
 
 
5e959ed
18ed172
 
 
 
 
5e959ed
18ed172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e959ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18ed172
 
 
 
5e959ed
 
 
 
 
 
 
 
 
 
18ed172
 
 
 
 
 
 
 
5e959ed
18ed172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e959ed
18ed172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pedidos de Compra</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <style>
        body {
            background-color: #1a202c;
            color: #ffffff;
            min-height: 100vh;
        }
        
        .status-badge {
            padding: 0.25rem 0.5rem;
            border-radius: 50rem;
            font-size: 0.75rem;
            font-weight: 500;
        }
        
        .status-em-elaboracao {
            background-color: #4b5563;
            color: #ffffff;
        }
        
        .status-aguardando-aprovacao {
            background-color: #f59e0b;
            color: #1e293b;
        }
        
        .status-aprovado {
            background-color: #10b981;
            color: #1e293b;
        }
        
        .status-enviado {
            background-color: #3b82f6;
            color: #ffffff;
        }
        
        .status-recebido-parcial {
            background-color: #8b5cf6;
            color: #ffffff;
        }
        
        .status-recebido-total {
            background-color: #22c55e;
            color: #1e293b;
        }
        
        .status-cancelado {
            background-color: #ef4444;
            color: #ffffff;
        }
        
        .offcanvas {
            transition: transform 0.3s ease-in-out;
            background-color: #1a202c !important;
            color: #ffffff !important;
            width: 33% !important;
        }
        
        .offcanvas-end {
            transform: translateX(100%);
        }
        
        .offcanvas.show {
            transform: translateX(0);
        }
        
        .backdrop {
            transition: opacity 0.3s ease-in-out;
            opacity: 0;
            pointer-events: none;
        }
        
        .backdrop.show {
            opacity: 1;
            pointer-events: auto;
        }
        
        .table-responsive {
            overflow-x: auto;
        }
        
        .table {
            color: #ffffff;
            background-color: transparent;
        }
        
        .table thead th {
            background-color: #2d3748;
            border-bottom: 1px solid #4a5568;
            font-size: 0.75rem;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: #ffffff;
        }
        
        .table tbody tr {
            background-color: transparent;
            color: #ffffff;
        }
        
        .table tbody tr:hover {
            background-color: rgba(45, 55, 72, 0.3);
        }
        
        .table tbody tr td {
            vertical-align: middle;
            white-space: nowrap;
            border-top: 1px solid #4a5568;
            background-color: #363e4b;
            color: #ffffff;
        }
        
        .table tfoot td {
            background-color: #2d3748;
            font-weight: 500;
            border-top: 1px solid #4a5568;
            color: #ffffff;
        }
        
        .btn-action {
            padding: 0.25rem;
            background: transparent;
            border: none;
            color: #ffffff;
        }
        
        .btn-action:hover {
            opacity: 0.8;
        }
        
        .btn-blue {
            background-color: #2563eb;
            color: white;
        }
        
        .btn-blue:hover {
            background-color: #1d4ed8;
            color: white;
        }
        
        .btn-gray {
            background-color: #4a5568;
            color: white;
        }
        
        .btn-gray:hover {
            background-color: #2d3748;
            color: white;
        }
        
        .btn-green {
            background-color: #10b981;
            color: white;
        }
        
        .btn-green:hover {
            background-color: #0d9e6e;
            color: white;
        }
        
        .btn-yellow {
            background-color: #d97706;
            color: white;
        }
        
        .btn-yellow:hover {
            background-color: #b45309;
            color: white;
        }
        
        .btn-purple {
            background-color: #7c3aed;
            color: white;
        }
        
        .btn-purple:hover {
            background-color: #6d28d9;
            color: white;
        }
        
        .btn-red {
            background-color: #dc2626;
            color: white;
        }
        
        .btn-red:hover {
            background-color: #b91c1c;
            color: white;
        }
        
        .card {
            background-color: #2a354b;
            border: 1px solid #4a5568;
            color: #ffffff;
        }
        
        .form-control, .form-select {
            background-color: #2d3748;
            border: 1px solid #4a5568;
            color: #ffffff;
        }
        
        .form-control:focus, .form-select:focus {
            background-color: #2d3748;
            border-color: #4299e1;
            color: #ffffff;
            box-shadow: 0 0 0 0.25rem rgba(66, 153, 225, 0.25);
        }
        
        .form-control::placeholder {
            color: #a0aec0;
        }
        
        .history-item {
            display: flex;
            align-items: flex-start;
            margin-bottom: 1rem;
        }
        
        .history-icon {
            flex-shrink: 0;
            width: 2rem;
            height: 2rem;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 0.75rem;
        }
        
        .history-content p {
            margin-bottom: 0;
            color: #ffffff;
        }
        
        .history-date {
            font-size: 0.875rem;
            color: #a0aec0;
        }
        
        .modal-content {
            background-color: #2d3748;
            color: #ffffff;
            border: 1px solid #4a5568;
        }
        
        .modal-header {
            border-bottom: 1px solid #4a5568;
            color: #ffffff;
        }
        
        .modal-footer {
            border-top: 1px solid #4a5568;
        }
        
        .btn-close {
            filter: invert(1);
        }
        
        #itemForm {
            display: none;
        }
        
        #itemForm.show {
            display: block;
        }
        
        .form-label {
            color: #ffffff;
        }
        
        .text-muted {
            color: #a0aec0 !important;
        }
        
        .text-primary {
            color: #3b82f6 !important;
        }
        
        .text-warning {
            color: #f59e0b !important;
        }
        
        .text-success {
            color: #10b981 !important;
        }
        
        .text-danger {
            color: #ef4444 !important;
        }
        
        .text-purple {
            color: #8b5cf6 !important;
        }
        
        .offcanvas-title {
            color: #3b82f6 !important;
        }
        
        .card-title {
            color: #3b82f6 !important;
        }
        
        .btn-link {
            color: #3b82f6 !important;
        }
        
        @media (max-width: 768px) {
            .offcanvas {
                width: 100% !important;
            }
            
            .header-buttons {
                width: 100% !important;
            }
        }
        
        @media (max-width: 992px) {
            .offcanvas {
                width: 75% !important;
            }
        }
    </style>
</head>
<body>
    <div class="container-fluid px-4 py-5">
        <!-- Header -->
        <div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-5 gap-3">
            <h1 class="text-primary mb-0">Pedidos de Compra</h1>
            <div class="d-flex flex-column flex-sm-row gap-3 header-buttons w-md-auto justify-content-end">
                <button id="newOrderBtn" class="btn btn-blue d-flex align-items-center gap-2">
                    <i class="fas fa-plus"></i> Novo Pedido de Compra
                </button>
            </div>
        </div>

        <!-- Filters (always visible) -->
        <div id="filters" class="card mb-5">
            <div class="card-body">
                <div class="row g-4">
                    <div class="col-12 col-md-6 col-lg-3">
                        <label class="form-label">Fornecedor</label>
                        <select class="form-select">
                            <option>Todos</option>
                            <option>Fornecedor A</option>
                            <option>Fornecedor B</option>
                            <option>Fornecedor C</option>
                        </select>
                    </div>
                    <div class="col-12 col-md-6 col-lg-3">
                        <label class="form-label">Status</label>
                        <select class="form-select">
                            <option>Todos</option>
                            <option>Em Elaboração</option>
                            <option>Aguardando Aprovação</option>
                            <option>Aprovado</option>
                            <option>Enviado</option>
                            <option>Recebido Parcial</option>
                            <option>Recebido Total</option>
                            <option>Cancelado</option>
                        </select>
                    </div>
                    <div class="col-12 col-md-6 col-lg-3">
                        <label class="form-label">Responsável</label>
                        <select class="form-select">
                            <option>Todos</option>
                            <option>João Silva</option>
                            <option>Maria Souza</option>
                            <option>Carlos Oliveira</option>
                        </select>
                    </div>
                    <div class="col-12 col-md-6 col-lg-3">
                        <label class="form-label">Período</label>
                        <input type="date" class="form-control">
                    </div>
                </div>
                <div class="d-flex justify-content-end mt-4 gap-2">
                    <button class="btn btn-gray">Limpar</button>
                    <button class="btn btn-blue">Aplicar</button>
                </div>
            </div>
        </div>

        <!-- Orders Table -->
        <div class="card shadow-lg">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th class="ps-4">Nº Pedido</th>
                            <th>Fornecedor</th>
                            <th>Responsável</th>
                            <th>Emissão</th>
                            <th>Previsão Entrega</th>
                            <th>Status</th>
                            <th>Valor Total</th>
                            <th class="text-end pe-4">Ações</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="ps-4">PC-2023-001</td>
                            <td>Fornecedor A</td>
                            <td>João Silva</td>
                            <td>10/05/2023</td>
                            <td>25/05/2023</td>
                            <td>
                                <span class="status-badge status-recebido-total">Recebido Total</span>
                            </td>
                            <td>R$ 5.245,00</td>
                            <td class="text-end pe-4">
                                <div class="d-flex justify-content-end gap-2">
                                    <button onclick="viewOrder('PC-2023-001')" class="btn-action text-primary">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                    <button class="btn-action text-warning">
                                        <i class="fas fa-print"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="ps-4">PC-2023-002</td>
                            <td>Fornecedor B</td>
                            <td>Maria Souza</td>
                            <td>15/05/2023</td>
                            <td>30/05/2023</td>
                            <td>
                                <span class="status-badge status-enviado">Enviado</span>
                            </td>
                            <td>R$ 3.780,50</td>
                            <td class="text-end pe-4">
                                <div class="d-flex justify-content-end gap-2">
                                    <button onclick="viewOrder('PC-2023-002')" class="btn-action text-primary">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                    <button class="btn-action text-warning">
                                        <i class="fas fa-print"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="ps-4">PC-2023-003</td>
                            <td>Fornecedor C</td>
                            <td>Carlos Oliveira</td>
                            <td>18/05/2023</td>
                            <td>05/06/2023</td>
                            <td>
                                <span class="status-badge status-aguardando-aprovacao">Aguardando Aprovação</span>
                            </td>
                            <td>R$ 12.450,00</td>
                            <td class="text-end pe-4">
                                <div class="d-flex justify-content-end gap-2">
                                    <button onclick="viewOrder('PC-2023-003')" class="btn-action text-primary">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                    <button class="btn-action text-warning">
                                        <i class="fas fa-print"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="ps-4">PC-2023-004</td>
                            <td>Fornecedor A</td>
                            <td>João Silva</td>
                            <td>20/05/2023</td>
                            <td>10/06/2023</td>
                            <td>
                                <span class="status-badge status-em-elaboracao">Em Elaboração</span>
                            </td>
                            <td>R$ 7.890,25</td>
                            <td class="text-end pe-4">
                                <div class="d-flex justify-content-end gap-2">
                                    <button onclick="viewOrder('PC-2023-004')" class="btn-action text-primary">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                    <button class="btn-action text-success">
                                        <i class="fas fa-edit"></i>
                                    </button>
                                    <button onclick="cancelOrder('PC-2023-004')" class="btn-action text-danger">
                                        <i class="fas fa-times"></i>
                                    </button>
                                    <button class="btn-action text-warning">
                                        <i class="fas fa-print"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="ps-4">PC-2023-005</td>
                            <td>Fornecedor B</td>
                            <td>Maria Souza</td>
                            <td>22/05/2023</td>
                            <td>15/06/2023</td>
                            <td>
                                <span class="status-badge status-recebido-parcial">Recebido Parcial</span>
                            </td>
                            <td>R$ 9.120,75</td>
                            <td class="text-end pe-4">
                                <div class="d-flex justify-content-end gap-2">
                                    <button onclick="viewOrder('PC-2023-005')" class="btn-action text-primary">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                    <button onclick="registerReceipt('PC-2023-005')" class="btn-action text-purple">
                                        <i class="fas fa-truck-loading"></i>
                                    </button>
                                    <button class="btn-action text-warning">
                                        <i class="fas fa-print"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="card-footer d-flex align-items-center justify-content-between">
                <div class="text-muted">
                    Mostrando <span class="fw-bold">1</span> a <span class="fw-bold">5</span> de <span class="fw-bold">15</span> resultados
                </div>
                <div class="d-flex gap-1">
                    <button class="btn btn-gray btn-sm">
                        <i class="fas fa-chevron-left"></i>
                    </button>
                    <button class="btn btn-blue btn-sm">1</button>
                    <button class="btn btn-gray btn-sm">2</button>
                    <button class="btn btn-gray btn-sm">3</button>
                    <button class="btn btn-gray btn-sm">
                        <i class="fas fa-chevron-right"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Order Detail Modal -->
    <div id="orderModal" class="modal fade" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-xl">
            <div class="modal-content">
                <div class="modal-header">
                    <h3 class="modal-title text-primary" id="modalOrderNumber">Pedido PC-2023-001</h3>
                    <button type="button" class="btn-close" onclick="closeModal()"></button>
                </div>
                <div class="modal-body">
                    <!-- Order Info -->
                    <div class="row g-4 mt-3">
                        <div class="col-12 col-md-4">
                            <div class="card h-100">
                                <div class="card-body">
                                    <h4 class="card-title text-primary mb-3">Fornecedor</h4>
                                    <p id="modalSupplier">Fornecedor A</p>
                                    <p id="modalSupplierContact">[email protected]</p>
                                    <p id="modalSupplierPhone">(11) 9999-9999</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-12 col-md-4">
                            <div class="card h-100">
                                <div class="card-body">
                                    <h4 class="card-title text-primary mb-3">Responsável</h4>
                                    <p id="modalResponsible">João Silva</p>
                                    <p id="modalDepartment">Compras</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-12 col-md-4">
                            <div class="card h-100">
                                <div class="card-body">
                                    <h4 class="card-title text-primary mb-3">Datas</h4>
                                    <div class="row g-2">
                                        <div class="col-6">
                                            <p class="text-muted small mb-0">Emissão:</p>
                                            <p id="modalEmissionDate">10/05/2023</p>
                                        </div>
                                        <div class="col-6">
                                            <p class="text-muted small mb-0">Previsão Entrega:</p>
                                            <p id="modalDeliveryDate">25/05/2023</p>
                                        </div>
                                        <div class="col-6">
                                            <p class="text-muted small mb-0">Pagamento:</p>
                                            <p id="modalPayment">30 dias</p>
                                        </div>
                                        <div class="col-6">
                                            <p class="text-muted small mb-0">Status:</p>
                                            <p id="modalStatus"><span class="status-badge status-recebido-total">Recebido Total</span></p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Order Items -->
                    <div class="mt-5">
                        <div class="d-flex justify-content-between align-items-center mb-4">
                            <h4 class="mb-0">Itens do Pedido</h4>
                            <button id="addItemBtn" class="btn btn-blue btn-sm">
                                <i class="fas fa-plus me-1"></i> Adicionar Item
                            </button>
                        </div>
                        
                        <!-- Item Form (hidden by default) -->
                        <div id="itemForm" class="card mb-4">
                            <div class="card-body">
                                <div class="row g-4 mb-4">
                                    <div class="col-12 col-md-6">
                                        <label class="form-label">Produto *</label>
                                        <select class="form-select">
                                            <option>Selecione um produto</option>
                                            <option>Notebook Dell XPS 15</option>
                                            <option>Monitor 27" 4K</option>
                                            <option>Teclado Mecânico</option>
                                        </select>
                                    </div>
                                    <div class="col-12 col-md-6">
                                        <label class="form-label">Quantidade *</label>
                                        <input type="number" min="1" value="1" class="form-control">
                                    </div>
                                </div>
                                <div class="row g-4">
                                    <div class="col-12 col-md-6">
                                        <label class="form-label">Valor Unitário *</label>
                                        <input type="text" placeholder="R$ 0,00" class="form-control">
                                    </div>
                                    <div class="col-12 col-md-6">
                                        <label class="form-label">Valor Total</label>
                                        <input type="text" placeholder="R$ 0,00" readonly class="form-control">
                                    </div>
                                </div>
                                <div class="d-flex justify-content-end mt-4 gap-2">
                                    <button type="button" onclick="hideItemForm()" class="btn btn-gray btn-sm">
                                        Cancelar
                                    </button>
                                    <button type="button" class="btn btn-green btn-sm">
                                        <i class="fas fa-save me-1"></i> Salvar
                                    </button>
                                </div>
                            </div>
                        </div>
                        
                        <div class="table-responsive">
                            <table class="table">
                                <thead>
                                    <tr>
                                        <th>Produto</th>
                                        <th>Categoria</th>
                                        <th>Quantidade</th>
                                        <th>Unitário</th>
                                        <th>Total</th>
                                        <th>Recebido</th>
                                        <th>Status</th>
                                        <th class="text-end">Ações</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>Notebook Dell XPS 15</td>
                                        <td>Informática</td>
                                        <td>2</td>
                                        <td>R$ 4.500,00</td>
                                        <td>R$ 9.000,00</td>
                                        <td>2</td>
                                        <td>
                                            <span class="status-badge bg-success text-white">Recebido</span>
                                        </td>
                                        <td class="text-end">
                                            <div class="d-flex justify-content-end gap-1">
                                                <button onclick="editItem('Notebook Dell XPS 15', 2, 4500)" class="btn-action text-primary">
                                                    <i class="fas fa-edit"></i>
                                                </button>
                                                <button onclick="deleteItem('Notebook Dell XPS 15')" class="btn-action text-danger">
                                                    <i class="fas fa-trash"></i>
                                                </button>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Monitor 27" 4K</td>
                                        <td>Informática</td>
                                        <td>5</td>
                                        <td>R$ 1.250,00</td>
                                        <td>R$ 6.250,00</td>
                                        <td>5</td>
                                        <td>
                                            <span class="status-badge bg-success text-white">Recebido</span>
                                        </td>
                                        <td class="text-end">
                                            <div class="d-flex justify-content-end gap-1">
                                                <button onclick="editItem('Monitor 27\" 4K', 5, 1250)" class="btn-action text-primary">
                                                    <i class="fas fa-edit"></i>
                                                </button>
                                                <button onclick="deleteItem('Monitor 27\" 4K')" class="btn-action text-danger">
                                                    <i class="fas fa-trash"></i>
                                                </button>
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <td colspan="3" class="text-end fw-bold">Total:</td>
                                        <td colspan="5">R$ 15.250,00</td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                    
                    <!-- Order Notes -->
                    <div class="mt-5">
                        <h4 class="mb-3">Observações</h4>
                        <div class="card">
                            <div class="card-body">
                                <p id="modalNotes">Entregar na recepção do prédio A, das 8h às 17h. Favor embalar com cuidado os equipamentos eletrônicos.</p>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Order History -->
                    <div class="mt-5">
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <h4 class="mb-0">Histórico</h4>
                            <button onclick="showAllHistory()" class="btn btn-link text-primary p-0">
                                Ver todos <i class="fas fa-chevron-down ms-1"></i>
                            </button>
                        </div>
                        <div id="historyItems">
                            <div class="history-item">
                                <div class="history-icon bg-primary">
                                    <i class="fas fa-check text-white"></i>
                                </div>
                                <div class="history-content">
                                    <p class="fw-medium">Pedido recebido totalmente</p>
                                    <p class="history-date">25/05/2023 14:30 - Por João Silva</p>
                                </div>
                            </div>
                            <div class="history-item">
                                <div class="history-icon bg-purple">
                                    <i class="fas fa-truck text-white"></i>
                                </div>
                                <div class="history-content">
                                    <p class="fw-medium">Pedido enviado pelo fornecedor</p>
                                    <p class="history-date">20/05/2023 09:15 - Por Fornecedor A</p>
                                </div>
                            </div>
                            <div class="history-item">
                                <div class="history-icon bg-success">
                                    <i class="fas fa-thumbs-up text-white"></i>
                                </div>
                                <div class="history-content">
                                    <p class="fw-medium">Pedido aprovado</p>
                                    <p class="history-date">12/05/2023 16:45 - Por Maria Souza (Gerente)</p>
                                </div>
                            </div>
                            <div class="history-item">
                                <div class="history-icon bg-warning">
                                    <i class="fas fa-paper-plane text-white"></i>
                                </div>
                                <div class="history-content">
                                    <p class="fw-medium">Pedido enviado para aprovação</p>
                                    <p class="history-date">10/05/2023 17:30 - Por João Silva</p>
                                </div>
                            </div>
                            <div class="history-item">
                                <div class="history-icon bg-secondary">
                                    <i class="fas fa-file-alt text-white"></i>
                                </div>
                                <div class="history-content">
                                    <p class="fw-medium">Pedido criado</p>
                                    <p class="history-date">10/05/2023 14:00 - Por João Silva</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button id="sendApprovalBtn" type="button" onclick="confirmSendForApproval()" class="btn btn-yellow">
                        <i class="fas fa-paper-plane me-2"></i> Enviar para Aprovação
                    </button>
                    <button id="registerReceiptBtn" type="button" class="btn btn-purple">
                        <i class="fas fa-truck-loading me-2"></i> Registrar Recebimento
                    </button>
                    <button onclick="cancelOrder('PC-2023-001')" type="button" class="btn btn-gray">
                        <i class="fas fa-times me-2"></i> Cancelar Pedido
                    </button>
                    <button onclick="closeModal()" type="button" class="btn btn-gray">
                        Fechar
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Edit Item Modal -->
    <div id="editItemModal" class="modal fade" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h3 class="modal-title text-primary">Editar Item</h3>
                    <button type="button" class="btn-close" onclick="closeEditItemModal()"></button>
                </div>
                <div class="modal-body">
                    <div class="row g-4">
                        <div class="col-12">
                            <label class="form-label">Produto</label>
                            <input type="text" id="editProductName" readonly class="form-control">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Quantidade *</label>
                            <input type="number" id="editQuantity" min="1" class="form-control">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Valor Unitário *</label>
                            <input type="text" id="editUnitPrice" placeholder="R$ 0,00" class="form-control">
                        </div>
                        <div class="col-12">
                            <label class="form-label">Valor Total</label>
                            <input type="text" id="editTotalPrice" placeholder="R$ 0,00" readonly class="form-control">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" onclick="saveItemChanges()" class="btn btn-green">
                        <i class="fas fa-save me-2"></i> Salvar Alterações
                    </button>
                    <button type="button" onclick="closeEditItemModal()" class="btn btn-gray">
                        Cancelar
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- New Order Offcanvas -->
    <div id="backdrop" class="backdrop fixed-top start-0 w-100 h-100 bg-black bg-opacity-50 z-40"></div>
    
    <div id="newOrderOffcanvas" class="offcanvas offcanvas-end" tabindex="-1">
        <div class="offcanvas-header">
            <h2 class="offcanvas-title text-primary">Novo Pedido de Compra</h2>
            <button type="button" class="btn-close text-reset" onclick="closeOffcanvas()"></button>
        </div>
        <div class="offcanvas-body">
            <form>
                <div class="mb-4">
                    <label class="form-label">Fornecedor *</label>
                    <select class="form-select">
                        <option>Selecione um fornecedor</option>
                        <option>Fornecedor A</option>
                        <option>Fornecedor B</option>
                        <option>Fornecedor C</option>
                    </select>
                </div>
                
                <div class="mb-4">
                    <label class="form-label">Responsável *</label>
                    <select class="form-select">
                        <option>Selecione um responsável</option>
                        <option>João Silva</option>
                        <option>Maria Souza</option>
                        <option>Carlos Oliveira</option>
                    </select>
                </div>
                
                <div class="row g-3 mb-4">
                    <div class="col-12 col-md-6">
                        <label class="form-label">Data de Emissão *</label>
                        <input type="date" class="form-control">
                    </div>
                    <div class="col-12 col-md-6">
                        <label class="form-label">Previsão de Entrega *</label>
                        <input type="date" class="form-control">
                    </div>
                </div>
                
                <div class="mb-4">
                    <label class="form-label">Condição de Pagamento *</label>
                    <select class="form-select">
                        <option>À vista</option>
                        <option>7 dias</option>
                        <option>15 dias</option>
                        <option>30 dias</option>
                        <option>60 dias</option>
                    </select>
                </div>
                
                <div class="mb-4">
                    <label class="form-label">Observações</label>
                    <textarea rows="3" class="form-control"></textarea>
                </div>
                
                <div class="pt-4 border-top">
                    <h3 class="mb-4">Itens do Pedido</h3>
                    
                    <div class="mb-4">
                        <div class="card">
                            <div class="card-body">
                                <div class="row g-3 mb-4">
                                    <div class="col-12 col-md-6">
                                        <label class="form-label">Produto *</label>
                                        <select class="form-select">
                                            <option>Selecione um produto</option>
                                            <option>Notebook Dell XPS 15</option>
                                            <option>Monitor 27" 4K</option>
                                            <option>Teclado Mecânico</option>
                                            <option>Mouse Sem Fio</option>
                                        </select>
                                    </div>
                                    <div class="col-12 col-md-6">
                                        <label class="form-label">Quantidade *</label>
                                        <input type="number" min="1" value="1" class="form-control">
                                    </div>
                                </div>
                                <div class="row g-3">
                                    <div class="col-12 col-md-6">
                                        <label class="form-label">Valor Unitário *</label>
                                        <input type="text" placeholder="R$ 0,00" class="form-control">
                                    </div>
                                    <div class="col-12 col-md-6">
                                        <label class="form-label">Valor Total</label>
                                        <input type="text" placeholder="R$ 0,00" readonly class="form-control">
                                    </div>
                                </div>
                                <div class="d-flex justify-content-end mt-4">
                                    <button type="button" class="btn btn-red btn-sm">
                                        <i class="fas fa-trash me-1"></i> Remover
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <button type="button" class="btn btn-gray w-100 d-flex align-items-center justify-content-center gap-2">
                        <i class="fas fa-plus"></i> Adicionar Item
                    </button>
                </div>
                
                <div class="d-flex justify-content-end gap-3 pt-5">
                    <button type="button" onclick="closeOffcanvas()" class="btn btn-gray">
                        Cancelar
                    </button>
                    <button type="button" class="btn btn-blue">
                        <i class="fas fa-save me-2"></i> Salvar Pedido
                    </button>
                </div>
            </form>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Initialize Bootstrap components
        var orderModal = new bootstrap.Modal(document.getElementById('orderModal'));
        var editItemModal = new bootstrap.Modal(document.getElementById('editItemModal'));
        var newOrderOffcanvas = new bootstrap.Offcanvas(document.getElementById('newOrderOffcanvas'));
        
        // Toggle item form
        document.getElementById('addItemBtn').addEventListener('click', function() {
            document.getElementById('itemForm').classList.add('show');
        });

        function hideItemForm() {
            document.getElementById('itemForm').classList.remove('show');
        }

        // Open new order offcanvas
        document.getElementById('newOrderBtn').addEventListener('click', function() {
            document.getElementById('backdrop').classList.add('show');
            newOrderOffcanvas.show();
        });

        // Close offcanvas
        function closeOffcanvas() {
            document.getElementById('backdrop').classList.remove('show');
            newOrderOffcanvas.hide();
        }

        // Close modal
        function closeModal() {
            orderModal.hide();
        }

        // View order modal
        function viewOrder(orderNumber) {
            // In a real app, we would fetch order details based on orderNumber
            document.getElementById('modalOrderNumber').textContent = `Pedido ${orderNumber}`;
            
            // Update buttons based on status
            const status = document.getElementById('modalStatus').textContent.trim();
            const sendApprovalBtn = document.getElementById('sendApprovalBtn');
            const registerReceiptBtn = document.getElementById('registerReceiptBtn');
            
            sendApprovalBtn.style.display = status === 'Em Elaboração' ? 'block' : 'none';
            registerReceiptBtn.style.display = (status === 'Em Elaboração' || status === 'Cancelado') ? 'none' : 'block';
            
            orderModal.show();
        }

        // Show all history items
        function showAllHistory() {
            // In a real app, we would fetch all history items here
            Swal.fire({
                title: 'Histórico Completo',
                html: `
                    <div class="text-left" style="max-height: 24rem; overflow-y: auto;">
                        <div class="d-flex align-items-start mb-3">
                            <div class="flex-shrink-0 bg-primary rounded-circle p-2 me-3">
                                <i class="fas fa-check text-white"></i>
                            </div>
                            <div>
                                <p class="fw-medium mb-0">Pedido recebido totalmente</p>
                                <p class="text-muted small">25/05/2023 14:30 - Por João Silva</p>
                            </div>
                        </div>
                        <div class="d-flex align-items-start mb-3">
                            <div class="flex-shrink-0 bg-purple rounded-circle p-2 me-3">
                                <i class="fas fa-truck text-white"></i>
                            </div>
                            <div>
                                <p class="fw-medium mb-0">Pedido enviado pelo fornecedor</p>
                                <p class="text-muted small">20/05/2023 09:15 - Por Fornecedor A</p>
                            </div>
                        </div>
                        <div class="d-flex align-items-start mb-3">
                            <div class="flex-shrink-0 bg-success rounded-circle p-2 me-3">
                                <i class="fas fa-thumbs-up text-white"></i>
                            </div>
                            <div>
                                <p class="fw-medium mb-0">Pedido aprovado</p>
                                <p class="text-muted small">12/05/2023 16:45 - Por Maria Souza (Gerente)</p>
                            </div>
                        </div>
                        <div class="d-flex align-items-start mb-3">
                            <div class="flex-shrink-0 bg-warning rounded-circle p-2 me-3">
                                <i class="fas fa-paper-plane text-white"></i>
                            </div>
                            <div>
                                <p class="fw-medium mb-0">Pedido enviado para aprovação</p>
                                <p class="text-muted small">10/05/2023 17:30 - Por João Silva</p>
                            </div>
                        </div>
                        <div class="d-flex align-items-start mb-3">
                            <div class="flex-shrink-0 bg-secondary rounded-circle p-2 me-3">
                                <i class="fas fa-file-alt text-white"></i>
                            </div>
                            <div>
                                <p class="fw-medium mb-0">Pedido criado</p>
                                <p class="text-muted small">10/05/2023 14:00 - Por João Silva</p>
                            </div>
                        </div>
                        <div class="d-flex align-items-start">
                            <div class="flex-shrink-0 bg-info rounded-circle p-2 me-3">
                                <i class="fas fa-comment text-white"></i>
                            </div>
                            <div>
                                <p class="fw-medium mb-0">Observação adicionada</p>
                                <p class="text-muted small">10/05/2023 14:05 - Por João Silva</p>
                                <p class="fst-italic small">"Entregar na recepção do prédio A"</p>
                            </div>
                        </div>
                    </div>
                `,
                background: '#1f2937',
                color: '#f3f4f6',
                confirmButtonColor: '#3b82f6',
                width: '600px'
            });
        }

        // Confirm send for approval
        function confirmSendForApproval() {
            Swal.fire({
                title: 'Enviar para Aprovação',
                text: 'Tem certeza que deseja enviar este pedido para aprovação? Esta ação não pode ser desfeita.',
                icon: 'question',
                showCancelButton: true,
                confirmButtonColor: '#3b82f6',
                cancelButtonColor: '#6b7280',
                confirmButtonText: 'Sim, enviar!',
                cancelButtonText: 'Cancelar',
                background: '#1f2937',
                color: '#f3f4f6'
            }).then((result) => {
                if (result.isConfirmed) {
                    Swal.fire({
                        title: 'Enviado!',
                        text: 'O pedido foi enviado para aprovação com sucesso.',
                        icon: 'success',
                        background: '#1f2937',
                        color: '#f3f4f6'
                    });
                }
            });
        }

        // Cancel order confirmation
        function cancelOrder(orderNumber) {
            Swal.fire({
                title: 'Cancelar Pedido',
                text: `Tem certeza que deseja cancelar o pedido ${orderNumber}? Esta ação não pode ser desfeita.`,
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#ef4444',
                cancelButtonColor: '#6b7280',
                confirmButtonText: 'Sim, cancelar!',
                cancelButtonText: 'Não, manter',
                background: '#1f2937',
                color: '#f3f4f6'
            }).then((result) => {
                if (result.isConfirmed) {
                    Swal.fire({
                        title: 'Cancelado!',
                        text: `O pedido ${orderNumber} foi cancelado.`,
                        icon: 'success',
                        background: '#1f2937',
                        color: '#f3f4f6'
                    });
                }
            });
        }

        // Register receipt
        function registerReceipt(orderNumber) {
            Swal.fire({
                title: 'Registrar Recebimento',
                html: `
                    <div class="text-left">
                        <div class="mb-3">
                            <label class="form-label">Tipo de Recebimento</label>
                            <select id="receiptType" class="form-select">
                                <option value="partial">Parcial</option>
                                <option value="total">Total</option>
                            </select>
                        </div>
                        <div id="partialFields">
                            <div class="mb-3">
                                <label class="form-label">Quantidade Recebida</label>
                                <input type="number" id="receivedQty" class="form-control">
                            </div>
                            <div class="mb-3">
                                <label class="form-label">Nota Fiscal</label>
                                <input type="text" id="invoiceNumber" class="form-control">
                            </div>
                        </div>
                    </div>
                `,
                showCancelButton: true,
                confirmButtonText: 'Registrar',
                cancelButtonText: 'Cancelar',
                background: '#1f2937',
                color: '#f3f4f6',
                preConfirm: () => {
                    const type = document.getElementById('receiptType').value;
                    const qty = document.getElementById('receivedQty').value;
                    const invoice = document.getElementById('invoiceNumber').value;
                    
                    if (type === 'partial' && (!qty || qty <= 0)) {
                        Swal.showValidationMessage('Informe a quantidade recebida');
                    }
                    
                    return { type, qty, invoice };
                }
            }).then((result) => {
                if (result.isConfirmed) {
                    Swal.fire({
                        title: 'Sucesso!',
                        text: 'Recebimento registrado com sucesso.',
                        icon: 'success',
                        background: '#1f2937',
                        color: '#f3f4f6'
                    });
                }
            });
        }

        // Edit item modal functions
        function editItem(productName, quantity, unitPrice) {
            document.getElementById('editProductName').value = productName;
            document.getElementById('editQuantity').value = quantity;
            document.getElementById('editUnitPrice').value = `R$ ${unitPrice.toFixed(2).replace('.', ',')}`;
            document.getElementById('editTotalPrice').value = `R$ ${(quantity * unitPrice).toFixed(2).replace('.', ',')}`;
            
            editItemModal.show();
        }

        function closeEditItemModal() {
            editItemModal.hide();
        }

        function saveItemChanges() {
            const productName = document.getElementById('editProductName').value;
            const quantity = document.getElementById('editQuantity').value;
            const unitPrice = document.getElementById('editUnitPrice').value;
            
            // Here you would save the changes to your data/API
            Swal.fire({
                title: 'Item Atualizado!',
                text: `O item ${productName} foi atualizado com sucesso.`,
                icon: 'success',
                background: '#1f2937',
                color: '#f3f4f6'
            });
            
            closeEditItemModal();
        }

        function deleteItem(productName) {
            Swal.fire({
                title: 'Excluir Item',
                text: `Tem certeza que deseja excluir o item ${productName}?`,
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#ef4444',
                cancelButtonColor: '#6b7280',
                confirmButtonText: 'Sim, excluir!',
                cancelButtonText: 'Cancelar',
                background: '#1f2937',
                color: '#f3f4f6'
            }).then((result) => {
                if (result.isConfirmed) {
                    Swal.fire({
                        title: 'Excluído!',
                        text: `O item ${productName} foi removido do pedido.`,
                        icon: 'success',
                        background: '#1f2937',
                        color: '#f3f4f6'
                    });
                }
            });
        }

        // Close offcanvas when clicking on backdrop
        document.getElementById('backdrop').addEventListener('click', closeOffcanvas);

        // Calculate total price when editing
        document.getElementById('editQuantity').addEventListener('input', calculateTotal);
        document.getElementById('editUnitPrice').addEventListener('input', calculateTotal);

        function calculateTotal() {
            const quantity = parseFloat(document.getElementById('editQuantity').value) || 0;
            const unitPriceStr = document.getElementById('editUnitPrice').value.replace('R$ ', '').replace(',', '.');
            const unitPrice = parseFloat(unitPriceStr) || 0;
            
            const total = quantity * unitPrice;
            document.getElementById('editTotalPrice').value = `R$ ${total.toFixed(2).replace('.', ',')}`;
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=gallabs/pedido-de-compra-bootstrap532" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>