File size: 55,965 Bytes
1827f8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="sv">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Förundersökningsprotokoll</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Roboto', sans-serif;
        }
        .section-container {
            transition: all 0.3s ease;
            cursor: move;
        }
        .section-container:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .section-container.dragging {
            opacity: 0.5;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
        }
        
        /* Skadekarta Body CSS */
        .skadekarta-body {
            position: relative;
            width: 200px;
            height: 400px;
            margin: 0 auto;
            cursor: crosshair;
        }
        .skadekarta-front, .skadekarta-back {
            position: absolute;
            width: 100%;
            height: 100%;
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
        }
        .skadekarta-front {
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200"><path d="M50,10 C60,10 65,15 65,25 L65,35 C65,45 70,50 60,50 L40,50 C30,50 35,45 35,35 L35,25 C35,15 40,10 50,10 Z M30,55 L70,55 L65,75 L70,95 L65,115 L70,135 L65,155 L70,175 L35,175 L40,155 L35,135 L40,115 L35,95 L40,75 L35,55 Z M30,55 L20,65 M70,55 L80,65" fill="none" stroke="black" stroke-width="1"/><circle cx="40" cy="30" r="3" fill="black"/><circle cx="60" cy="30" r="3" fill="black"/><path d="M45,40 Q50,45 55,40" fill="none" stroke="black" stroke-width="1"/></svg>');
        }
        .skadekarta-back {
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200"><path d="M50,10 C60,10 65,15 65,25 L65,35 C65,45 70,50 60,50 L40,50 C30,50 35,45 35,35 L35,25 C35,15 40,10 50,10 Z M30,55 L70,55 L65,75 L70,95 L65,115 L70,135 L65,155 L70,175 L35,175 L40,155 L35,135 L40,115 L35,95 L40,75 L35,55 Z M30,55 L20,65 M70,55 L80,65" fill="none" stroke="black" stroke-width="1"/></svg>');
            display: none;
        }
        .skada-circle {
            position: absolute;
            width: 20px;
            height: 20px;
            border: 2px solid red;
            border-radius: 50%;
            transform: translate(-50%, -50%);
            z-index: 2;
        }
        .skada-line {
            position: absolute;
            background-color: red;
            height: 2px;
            transform-origin: left center;
            z-index: 1;
        }
        .skada-number {
            position: absolute;
            color: black;
            font-weight: bold;
            font-size: 12px;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 3;
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-8 max-w-4xl">
        <header class="mb-8 text-center">
            <h1 class="text-3xl font-bold text-blue-800 mb-2">Förundersökningsprotokoll</h1>
            <p class="text-gray-600">Fyll i formuläret nedan för att skapa ett komplett förundersökningsprotokoll</p>
        </header>

        <div class="bg-white rounded-lg shadow-md p-6 mb-8">
            <h2 class="text-xl font-semibold text-blue-700 mb-4 border-b pb-2">Grundinformation</h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="investigator">Ledande utredare</label>
                    <input type="text" id="investigator" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                </div>
                
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="victim">Målsägande</label>
                    <input type="text" id="victim" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                </div>
                
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="date">Datum</label>
                    <input type="date" id="date" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                </div>
                
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="caseNumber">Diarienummer</label>
                    <input type="text" id="caseNumber" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                </div>
                
                <div class="md:col-span-2">
                    <label class="block text-gray-700 font-medium mb-2" for="crimeType">Brottsrubricering</label>
                    <input type="text" id="crimeType" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                </div>
                
                <div class="md:col-span-2">
                    <label class="block text-gray-700 font-medium mb-2" for="suspect">Misstänkt (namn och personuppgifter)</label>
                    <textarea id="suspect" rows="2" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea>
                </div>
            </div>
        </div>

        <div id="dynamic-sections" class="space-y-6">
            <!-- Dynamic sections will be added here -->
        </div>

        <div class="mt-6 flex flex-wrap gap-3">
            <button onclick="addSection('witness')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd" />
                </svg>
                Lägg till vittnesmål
            </button>
            <button onclick="addSection('police-report')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z" />
                    <path fill-rule="evenodd" d="M4 5a2 2 0 012-2 3 3 0 003 3h2a3 3 0 003-3 2 2 0 012 2v11a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm3 4a1 1 0 000 2h.01a1 1 0 100-2H7zm3 0a1 1 0 000 2h3a1 1 0 100-2h-3zm-3 4a1 1 0 100 2h.01a1 1 0 100-2H7zm3 0a1 1 0 100 2h3a1 1 0 100-2h-3z" clip-rule="evenodd" />
                </svg>
                Lägg till polisrapport
            </button>
            <button onclick="addSection('crime-scene')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z" clip-rule="evenodd" />
                </svg>
                Lägg till brottsplatsundersökning
            </button>
            <button onclick="addSection('evidence')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2h-1V9z" clip-rule="evenodd" />
                </svg>
                Lägg till bevismaterial
            </button>
            <button onclick="addSection('skadekarta')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-3a1 1 0 00-.867.5 1 1 0 11-1.731-1A3 3 0 0113 8a3.001 3.001 0 01-2 2.83V11a1 1 0 11-2 0v-1a1 1 0 011-1 1 1 0 100-2zm0 8a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd" />
                </svg>
                Lägg till skadekarta
            </button>
            <button onclick="addSection('timeline')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                </svg>
                Lägg till händelseförlopp
            </button>
            <button onclick="addSection('persons')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path d="M13 6a3 3 0 11-6 0 3 3 0 016 0zM18 8a2 2 0 11-4 0 2 2 0 014 0zM14 15a4 4 0 00-8 0v1h8v-1zM6 8a2 2 0 11-4 0 2 2 0 014 0zM16 18v-1a5.972 5.972 0 00-.75-2.906A3.005 3.005 0 0119 15v1h-3zM4.75 12.094A5.973 5.973 0 004 15v1H1v-1a3 3 0 013.75-2.906z" />
                </svg>
                Lägg till personer inblandade
            </button>
            <button onclick="addSection('police')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path d="M11 17a1 1 0 001.447.894l4-2A1 1 0 0017 15V9.236a1 1 0 00-1.447-.894l-4 2a1 1 0 00-.553.894V17zM15.211 6.276a1 1 0 000-1.788l-4.764-2.382a1 1 0 00-.894 0L4.789 4.488a1 1 0 000 1.788l4.764 2.382a1 1 0 00.894 0l4.764-2.382zM4.447 8.342A1 1 0 003 9.236V15a1 1 0 00.553.894l4 2A1 1 0 009 17v-5.764a1 1 0 00-.553-.894l-4-2z" />
                </svg>
                Lägg till polismän inblandade
            </button>
            <button onclick="addSection('contact-persons')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884z" />
                    <path d="M18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z" />
                </svg>
                Lägg till kontaktpersoner
            </button>
            <button onclick="addSection('seized-items')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M10 2a4 4 0 00-4 4v1H5a1 1 0 00-.994.89l-1 9A1 1 0 004 18h12a1 1 0 00.994-1.11l-1-9A1 1 0 0015 7h-1V6a4 4 0 00-4-4zm2 5V6a2 2 0 10-4 0v1h4zm-6 3a1 1 0 112 0 1 1 0 01-2 0zm7-1a1 1 0 100 2 1 1 0 000-2z" clip-rule="evenodd" />
                </svg>
                Lägg till beslagtagna föremål
            </button>
            <button onclick="addSection('other')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z" clip-rule="evenodd" />
                </svg>
                Lägg till övrig dokumentation
            </button>
        </div>

        <div class="mt-10 text-center">
            <button onclick="generatePDF()" class="bg-green-600 hover:bg-green-700 text-white px-6 py-3 rounded-lg font-medium text-lg flex items-center mx-auto">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
                </svg>
                Generera PDF-protokoll
            </button>
        </div>
    </div>

    <script>
        // Global variables
        let skadaCounter = 0;
        let sectionCounter = 0;
        let currentView = 'front';
        let draggedSection = null;

        // Initialize drag and drop functionality
        function initDragAndDrop() {
            const container = document.getElementById('dynamic-sections');
            
            container.addEventListener('dragstart', function(e) {
                if (e.target.classList.contains('section-container')) {
                    draggedSection = e.target;
                    e.target.classList.add('dragging');
                    e.dataTransfer.setData('text/plain', e.target.id);
                    e.dataTransfer.effectAllowed = 'move';
                }
            });
            
            container.addEventListener('dragend', function(e) {
                if (e.target.classList.contains('section-container')) {
                    e.target.classList.remove('dragging');
                }
            });
            
            container.addEventListener('dragover', function(e) {
                e.preventDefault();
                e.dataTransfer.dropEffect = 'move';
                
                const afterElement = getDragAfterElement(container, e.clientY);
                if (afterElement == null) {
                    container.appendChild(draggedSection);
                } else {
                    container.insertBefore(draggedSection, afterElement);
                }
            });
        }
        
        function getDragAfterElement(container, y) {
            const draggableElements = [...container.querySelectorAll('.section-container:not(.dragging)')];
            
            return draggableElements.reduce((closest, child) => {
                const box = child.getBoundingClientRect();
                const offset = y - box.top - box.height / 2;
                
                if (offset < 0 && offset > closest.offset) {
                    return { offset: offset, element: child };
                } else {
                    return closest;
                }
            }, { offset: Number.NEGATIVE_INFINITY }).element;
        }

        // Add section based on type
        function addSection(type) {
            const container = document.getElementById('dynamic-sections');
            const sectionId = `section-${sectionCounter++}`;
            
            let sectionHTML = '';
            let sectionTitle = '';
            
            switch(type) {
                case 'witness':
                    sectionTitle = 'Vittnesmål';
                    sectionHTML = `
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-witness-name">Vittnes namn</label>
                            <input type="text" id="${sectionId}-witness-name" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-witness-contact">Kontaktuppgifter</label>
                            <input type="text" id="${sectionId}-witness-contact" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-witness-location">Plats för förhör</label>
                            <input type="text" id="${sectionId}-witness-location" class="w-full px-4 py-2 border rounded-lg" placeholder="Var utfördes förhöret">
                        </div>
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-witness-time">Tidpunkt för förhör</label>
                            <input type="datetime-local" id="${sectionId}-witness-time" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <div>
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-witness-statement">Vittnesutsaga</label>
                            <textarea id="${sectionId}-witness-statement" rows="4" class="w-full px-4 py-2 border rounded-lg"></textarea>
                        </div>
                    `;
                    break;
                    
                case 'police-report':
                    sectionTitle = 'Polisrapport';
                    sectionHTML = `
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-report-author">Rapportförfattare</label>
                            <input type="text" id="${sectionId}-report-author" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-report-rank">Rang</label>
                            <select id="${sectionId}-report-rank" class="w-full px-4 py-2 border rounded-lg">
                                <option value="aspirant">Aspirant</option>
                                <option value="assistent">Assistent</option>
                                <option value="inspektor">Inspektör</option>
                                <option value="kommissarie">Kommissarie</option>
                                <option value="sekreterare">Sekreterare</option>
                                <option value="intendent">Intendent</option>
                                <option value="polismästare">Polismästare</option>
                                <option value="bitr-direktör">Bitr. Direktör</option>
                                <option value="direktör">Direktör</option>
                            </select>
                        </div>
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-report-date">Datum för rapport</label>
                            <input type="date" id="${sectionId}-report-date" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <div>
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-report-content">Rapportens innehåll</label>
                            <textarea id="${sectionId}-report-content" rows="4" class="w-full px-4 py-2 border rounded-lg"></textarea>
                        </div>
                    `;
                    break;
                    
                case 'crime-scene':
                    sectionTitle = 'Brottsplatsundersökning';
                    sectionHTML = `
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-scene-location">Plats</label>
                            <input type="text" id="${sectionId}-scene-location" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-scene-date">Datum för undersökning</label>
                            <input type="date" id="${sectionId}-scene-date" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2">Kriminaltekniker</label>
                            <div id="${sectionId}-technicians" class="space-y-4">
                                <!-- Technician items will be added here -->
                            </div>
                            <button onclick="addTechnicianItem('${sectionId}')" class="mt-2 bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">
                                Lägg till kriminaltekniker
                            </button>
                        </div>
                        <div>
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-scene-findings">Anteckningar</label>
                            <textarea id="${sectionId}-scene-findings" rows="4" class="w-full px-4 py-2 border rounded-lg"></textarea>
                        </div>
                    `;
                    break;
                    
                case 'evidence':
                    sectionTitle = 'Bevismaterial';
                    sectionHTML = `
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-evidence-type">Typ av bevismaterial</label>
                            <select id="${sectionId}-evidence-type" class="w-full px-4 py-2 border rounded-lg">
                                <option value="dna">DNA-prov</option>
                                <option value="fingerprint">Fingeravtryck</option>
                                <option value="photo">Fotografier</option>
                                <option value="video">Videoinspelning</option>
                                <option value="object">Föremål</option>
                                <option value="other">Övrigt</option>
                            </select>
                        </div>
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-evidence-id">ID-nummer</label>
                            <input type="text" id="${sectionId}-evidence-id" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <div class="mb-4">
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-evidence-collected">Insamlat datum och tid</label>
                            <input type="datetime-local" id="${sectionId}-evidence-collected" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <div>
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-evidence-notes">Anteckningar</label>
                            <textarea id="${sectionId}-evidence-notes" rows="3" class="w-full px-4 py-2 border rounded-lg"></textarea>
                        </div>
                    `;
                    break;
                    
                case 'skadekarta':
                    sectionTitle = 'Skadekarta';
                    sectionHTML = `
                        <div class="mb-6">
                            <div class="flex justify-center mb-4">
                                <button onclick="toggleBodyView('${sectionId}')" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">
                                    Växla till ${currentView === 'front' ? 'baksida' : 'framsida'}
                                </button>
                            </div>
                            <div class="skadekarta-body" id="${sectionId}-body-map" onclick="addSkada(event, '${sectionId}')">
                                <div class="skadekarta-front" id="${sectionId}-body-front"></div>
                                <div class="skadekarta-back" id="${sectionId}-body-back"></div>
                            </div>
                            <div id="${sectionId}-skada-list" class="mt-6 space-y-2">
                                <!-- Skador will be listed here -->
                            </div>
                        </div>
                        <div>
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-skada-doctor">Ansvarig</label>
                            <input type="text" id="${sectionId}-skada-doctor" class="w-full px-4 py-2 border rounded-lg mb-4">
                            
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-skada-date">Datum</label>
                            <input type="date" id="${sectionId}-skada-date" class="w-full px-4 py-2 border rounded-lg mb-4">
                            
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-skada-findings">Beskrivning av skador</label>
                            <textarea id="${sectionId}-skada-findings" rows="4" class="w-full px-4 py-2 border rounded-lg"></textarea>
                        </div>
                    `;
                    break;
                    
                case 'timeline':
                    sectionTitle = 'Händelseförlopp';
                    sectionHTML = `
                        <div id="${sectionId}-timeline-items" class="space-y-4">
                            <!-- Timeline items will be added here -->
                        </div>
                        <button onclick="addTimelineItem('${sectionId}')" class="mt-4 bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">
                            Lägg till händelse
                        </button>
                    `;
                    break;
                    
                case 'persons':
                    sectionTitle = 'Personer inblandade';
                    sectionHTML = `
                        <div id="${sectionId}-person-items" class="space-y-4">
                            <!-- Person items will be added here -->
                        </div>
                        <button onclick="addPersonItem('${sectionId}')" class="mt-4 bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">
                            Lägg till person
                        </button>
                    `;
                    break;
                    
                case 'police':
                    sectionTitle = 'Polismän inblandade';
                    sectionHTML = `
                        <div id="${sectionId}-police-items" class="space-y-4">
                            <!-- Police items will be added here -->
                        </div>
                        <button onclick="addPoliceItem('${sectionId}')" class="mt-4 bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">
                            Lägg till polisman
                        </button>
                    `;
                    break;
                    
                case 'contact-persons':
                    sectionTitle = 'Kontaktpersoner';
                    sectionHTML = `
                        <div id="${sectionId}-contact-items" class="space-y-4">
                            <!-- Contact items will be added here -->
                        </div>
                        <button onclick="addContactItem('${sectionId}')" class="mt-4 bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">
                            Lägg till kontaktperson
                        </button>
                    `;
                    break;
                    
                case 'seized-items':
                    sectionTitle = 'Beslagtagna föremål';
                    sectionHTML = `
                        <div id="${sectionId}-seized-items" class="space-y-4">
                            <!-- Seized items will be added here -->
                        </div>
                        <button onclick="addSeizedItem('${sectionId}')" class="mt-4 bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">
                            Lägg till beslagtagen föremål
                        </button>
                    `;
                    break;
                    
                case 'other':
                    sectionTitle = 'Övrig dokumentation';
                    sectionHTML = `
                        <div>
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-other-title">Titel</label>
                            <input type="text" id="${sectionId}-other-title" class="w-full px-4 py-2 border rounded-lg mb-4">
                            
                            <label class="block text-gray-700 font-medium mb-2" for="${sectionId}-other-content">Innehåll</label>
                            <textarea id="${sectionId}-other-content" rows="4" class="w-full px-4 py-2 border rounded-lg"></textarea>
                        </div>
                    `;
                    break;
            }
            
            const sectionElement = document.createElement('div');
            sectionElement.id = sectionId;
            sectionElement.className = 'section-container bg-white rounded-lg shadow-md p-6';
            sectionElement.draggable = true;
            
            sectionElement.innerHTML = `
                <div class="flex justify-between items-center mb-4 border-b pb-2">
                    <h3 class="text-lg font-semibold text-blue-700">${sectionTitle}</h3>
                    <button onclick="removeSection('${sectionId}')" class="text-red-500 hover:text-red-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                        </svg>
                    </button>
                </div>
                ${sectionHTML}
            `;
            
            container.appendChild(sectionElement);
            
            // Initialize specific section functionality
            if (type === 'skadekarta') {
                initSkadekarta(sectionId);
            }
        }
        
        // Remove section
        function removeSection(sectionId) {
            const section = document.getElementById(sectionId);
            if (section) {
                section.remove();
            }
        }
        
        // Toggle body view between front and back
        function toggleBodyView(sectionId) {
            const front = document.getElementById(`${sectionId}-body-front`);
            const back = document.getElementById(`${sectionId}-body-back`);
            
            if (currentView === 'front') {
                front.style.display = 'none';
                back.style.display = 'block';
                currentView = 'back';
                document.querySelector(`button[onclick="toggleBodyView('${sectionId}')"]`).textContent = 'Växla till framsida';
            } else {
                front.style.display = 'block';
                back.style.display = 'none';
                currentView = 'front';
                document.querySelector(`button[onclick="toggleBodyView('${sectionId}')"]`).textContent = 'Växla till baksida';
            }
        }
        
        // Initialize skadekarta
        function initSkadekarta(sectionId) {
            const skadekarta = document.getElementById(`${sectionId}-body-map`);
            skadekarta.addEventListener('click', function(e) {
                addSkada(e, sectionId);
            });
        }
        
        // Add skada to skadekarta
        function addSkada(event, sectionId) {
            const skadekarta = document.getElementById(`${sectionId}-body-map`);
            const rect = skadekarta.getBoundingClientRect();
            
            // Calculate position relative to the skadekarta
            const x = event.clientX - rect.left;
            const y = event.clientY - rect.top;
            
            // Create skada marker
            const skadaId = `skada-${skadaCounter++}`;
            
            // Create circle
            const circle = document.createElement('div');
            circle.className = 'skada-circle';
            circle.style.left = `${x}px`;
            circle.style.top = `${y}px`;
            circle.id = `${skadaId}-circle`;
            
            // Create number
            const number = document.createElement('div');
            number.className = 'skada-number';
            number.textContent = skadaCounter;
            number.id = `${skadaId}-number`;
            
            // Create line (direction depends on click position)
            const line = document.createElement('div');
            line.className = 'skada-line';
            line.style.left = `${x}px`;
            line.style.top = `${y}px`;
            line.style.width = '50px';
            line.id = `${skadaId}-line`;
            
            // Position line to left or right
            if (x > rect.width / 2) {
                line.style.transform = 'rotate(180deg)';
                line.style.left = `${x - 50}px`;
            }
            
            // Add elements to skadekarta
            skadekarta.appendChild(line);
            skadekarta.appendChild(circle);
            skadekarta.appendChild(number);
            
            // Add skada to list
            addSkadaToList(sectionId, skadaId, skadaCounter, x, y);
        }
        
        // Add skada to the list below skadekarta
        function addSkadaToList(sectionId, skadaId, number, x, y) {
            const list = document.getElementById(`${sectionId}-skada-list`);
            
            const item = document.createElement('div');
            item.className = 'flex items-center justify-between bg-gray-100 p-2 rounded';
            item.id = `${skadaId}-list-item`;
            
            item.innerHTML = `
                <div class="flex items-center">
                    <span class="inline-block w-6 h-6 rounded-full bg-red-500 text-white text-center mr-2">${number}</span>
                    <input type="text" placeholder="Beskrivning av skada" class="px-2 py-1 border rounded">
                </div>
                <button onclick="removeSkada('${sectionId}', '${skadaId}')" class="text-red-500 hover:text-red-700">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                        <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                    </svg>
                </button>
            `;
            
            list.appendChild(item);
        }
        
        // Remove skada from skadekarta and list
        function removeSkada(sectionId, skadaId) {
            // Remove from skadekarta
            const circle = document.getElementById(`${skadaId}-circle`);
            const line = document.getElementById(`${skadaId}-line`);
            const number = document.getElementById(`${skadaId}-number`);
            
            if (circle) circle.remove();
            if (line) line.remove();
            if (number) number.remove();
            
            // Remove from list
            const listItem = document.getElementById(`${skadaId}-list-item`);
            if (listItem) listItem.remove();
        }
        
        // Add technician item to crime scene section
        function addTechnicianItem(sectionId) {
            const container = document.getElementById(`${sectionId}-technicians`);
            const itemId = `technician-${Date.now()}`;
            
            const item = document.createElement('div');
            item.className = 'grid grid-cols-1 md:grid-cols-3 gap-4 items-end';
            item.id = itemId;
            
            item.innerHTML = `
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-name">Namn</label>
                    <input type="text" id="${itemId}-name" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-rank">Rang</label>
                    <select id="${itemId}-rank" class="w-full px-4 py-2 border rounded-lg">
                        <option value="aspirant">Aspirant</option>
                        <option value="assistent">Assistent</option>
                        <option value="inspektor">Inspektör</option>
                        <option value="kommissarie">Kommissarie</option>
                        <option value="sekreterare">Sekreterare</option>
                        <option value="intendent">Intendent</option>
                        <option value="polismästare">Polismästare</option>
                        <option value="bitr-direktör">Bitr. Direktör</option>
                        <option value="direktör">Direktör</option>
                    </select>
                </div>
                <div class="flex items-end">
                    <div class="flex-grow">
                        <label class="block text-gray-700 font-medium mb-2" for="${itemId}-role">Roll</label>
                        <input type="text" id="${itemId}-role" class="w-full px-4 py-2 border rounded-lg">
                    </div>
                    <button onclick="removeTechnicianItem('${sectionId}', '${itemId}')" class="ml-2 text-red-500 hover:text-red-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                        </svg>
                    </button>
                </div>
            `;
            
            container.appendChild(item);
        }
        
        // Remove technician item
        function removeTechnicianItem(sectionId, itemId) {
            const item = document.getElementById(itemId);
            if (item) {
                item.remove();
            }
        }
        
        // Add timeline item
        function addTimelineItem(sectionId) {
            const container = document.getElementById(`${sectionId}-timeline-items`);
            const itemId = `timeline-${Date.now()}`;
            
            const item = document.createElement('div');
            item.className = 'grid grid-cols-1 md:grid-cols-3 gap-4 items-end';
            item.id = itemId;
            
            item.innerHTML = `
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-time">Tidpunkt</label>
                    <input type="datetime-local" id="${itemId}-time" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div class="md:col-span-2">
                    <div class="flex">
                        <div class="flex-grow">
                            <label class="block text-gray-700 font-medium mb-2" for="${itemId}-description">Händelse</label>
                            <input type="text" id="${itemId}-description" class="w-full px-4 py-2 border rounded-lg">
                        </div>
                        <button onclick="removeTimelineItem('${sectionId}', '${itemId}')" class="ml-2 text-red-500 hover:text-red-700">
                            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                                <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                            </svg>
                            </button>
                        </div>
                    </div>
                </div>
            `;
            
            container.appendChild(item);
        }
        
        // Remove timeline item
        function removeTimelineItem(sectionId, itemId) {
            const item = document.getElementById(itemId);
            if (item) {
                item.remove();
            }
        }
        
        // Add person item
        function addPersonItem(sectionId) {
            const container = document.getElementById(`${sectionId}-person-items`);
            const itemId = `person-${Date.now()}`;
            
            const item = document.createElement('div');
            item.className = 'grid grid-cols-1 md:grid-cols-3 gap-4 items-end';
            item.id = itemId;
            
            item.innerHTML = `
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-name">Namn</label>
                    <input type="text" id="${itemId}-name" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-role">Roll</label>
                    <input type="text" id="${itemId}-role" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div class="flex">
                    <div class="flex-grow">
                        <label class="block text-gray-700 font-medium mb-2" for="${itemId}-contact">Kontaktuppgifter</label>
                        <input type="text" id="${itemId}-contact" class="w-full px-4 py-2 border rounded-lg">
                    </div>
                    <button onclick="removePersonItem('${sectionId}', '${itemId}')" class="ml-2 text-red-500 hover:text-red-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                        </svg>
                    </button>
                </div>
            `;
            
            container.appendChild(item);
        }
        
        // Remove person item
        function removePersonItem(sectionId, itemId) {
            const item = document.getElementById(itemId);
            if (item) {
                item.remove();
            }
        }
        
        // Add police item
        function addPoliceItem(sectionId) {
            const container = document.getElementById(`${sectionId}-police-items`);
            const itemId = `police-${Date.now()}`;
            
            const item = document.createElement('div');
            item.className = 'grid grid-cols-1 md:grid-cols-3 gap-4 items-end';
            item.id = itemId;
            
            item.innerHTML = `
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-name">Namn</label>
                    <input type="text" id="${itemId}-name" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-rank">Rang</label>
                    <select id="${itemId}-rank" class="w-full px-4 py-2 border rounded-lg">
                        <option value="aspirant">Aspirant</option>
                        <option value="assistent">Assistent</option>
                        <option value="inspektor">Inspektör</option>
                        <option value="kommissarie">Kommissarie</option>
                        <option value="sekreterare">Sekreterare</option>
                        <option value="intendent">Intendent</option>
                        <option value="polismästare">Polismästare</option>
                        <option value="bitr-direktör">Bitr. Direktör</option>
                        <option value="direktör">Direktör</option>
                    </select>
                </div>
                <div class="flex">
                    <div class="flex-grow">
                        <label class="block text-gray-700 font-medium mb-2" for="${itemId}-role">Roll</label>
                        <input type="text" id="${itemId}-role" class="w-full px-4 py-2 border rounded-lg">
                    </div>
                    <button onclick="removePoliceItem('${sectionId}', '${itemId}')" class="ml-2 text-red-500 hover:text-red-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                        </svg>
                    </button>
                </div>
            `;
            
            container.appendChild(item);
        }
        
        // Remove police item
        function removePoliceItem(sectionId, itemId) {
            const item = document.getElementById(itemId);
            if (item) {
                item.remove();
            }
        }
        
        // Add contact item
        function addContactItem(sectionId) {
            const container = document.getElementById(`${sectionId}-contact-items`);
            const itemId = `contact-${Date.now()}`;
            
            const item = document.createElement('div');
            item.className = 'grid grid-cols-1 md:grid-cols-3 gap-4 items-end';
            item.id = itemId;
            
            item.innerHTML = `
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-name">Namn</label>
                    <input type="text" id="${itemId}-name" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-info">Kontaktuppgifter</label>
                    <input type="text" id="${itemId}-info" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div class="flex">
                    <div class="flex-grow">
                        <label class="block text-gray-700 font-medium mb-2" for="${itemId}-connection">Koppling till ärendet</label>
                        <input type="text" id="${itemId}-connection" class="w-full px-4 py-2 border rounded-lg">
                    </div>
                    <button onclick="removeContactItem('${sectionId}', '${itemId}')" class="ml-2 text-red-500 hover:text-red-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                        </svg>
                    </button>
                </div>
            `;
            
            container.appendChild(item);
        }
        
        // Remove contact item
        function removeContactItem(sectionId, itemId) {
            const item = document.getElementById(itemId);
            if (item) {
                item.remove();
            }
        }
        
        // Add seized item
        function addSeizedItem(sectionId) {
            const container = document.getElementById(`${sectionId}-seized-items`);
            const itemId = `seized-${Date.now()}`;
            
            const item = document.createElement('div');
            item.className = 'grid grid-cols-1 md:grid-cols-2 gap-4';
            item.id = itemId;
            
            item.innerHTML = `
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-item">Beslagtaget föremål</label>
                    <input type="text" id="${itemId}-item" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-location">Plats</label>
                    <input type="text" id="${itemId}-location" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-from">Från vem</label>
                    <input type="text" id="${itemId}-from" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div>
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-date">Datum och tid</label>
                    <input type="datetime-local" id="${itemId}-date" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div class="md:col-span-2">
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-reason">Anledning till beslag</label>
                    <input type="text" id="${itemId}-reason" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div class="md:col-span-2">
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-notes">Anteckningar</label>
                    <textarea id="${itemId}-notes" rows="2" class="w-full px-4 py-2 border rounded-lg"></textarea>
                </div>
                <div class="md:col-span-2">
                    <label class="block text-gray-700 font-medium mb-2" for="${itemId}-officer">Beslag utfört av</label>
                    <input type="text" id="${itemId}-officer" class="w-full px-4 py-2 border rounded-lg">
                </div>
                <div class="md:col-span-2 flex justify-end">
                    <button onclick="removeSeizedItem('${sectionId}', '${itemId}')" class="text-red-500 hover:text-red-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                        </svg>
                    </button>
                </div>
            `;
            
            container.appendChild(item);
        }
        
        // Remove seized item
        function removeSeizedItem(sectionId, itemId) {
            const item = document.getElementById(itemId);
            if (item) {
                item.remove();
            }
        }
        
        // Generate PDF
        function generatePDF() {
            const { jsPDF } = window.jspdf;
            const doc = new jsPDF();
            
            // Add title
            doc.setFontSize(20);
            doc.text('Förundersökningsprotokoll', 105, 15, { align: 'center' });
            
            // Add basic information
            doc.setFontSize(12);
            doc.text('Grundinformation', 14, 25);
            
            const investigator = document.getElementById('investigator').value;
            const victim = document.getElementById('victim').value;
            const date = document.getElementById('date').value;
            const caseNumber = document.getElementById('caseNumber').value;
            const crimeType = document.getElementById('crimeType').value;
            const suspect = document.getElementById('suspect').value;
            
            doc.text(`Ledande utredare: ${investigator}`, 14, 35);
            doc.text(`Målsägande: ${victim}`, 14, 40);
            doc.text(`Datum: ${date}`, 14, 45);
            doc.text(`Diarienummer: ${caseNumber}`, 14, 50);
            doc.text(`Brottsrubricering: ${crimeType}`, 14, 55);
            doc.text(`Misstänkt: ${suspect}`, 14, 60);
            
            // Add sections
            const sections = document.getElementById('dynamic-sections').children;
            let yPosition = 70;
            
            for (let i = 0; i < sections.length; i++) {
                const section = sections[i];
                const title = section.querySelector('h3').textContent;
                
                // Add new page if needed
                if (yPosition > 250) {
                    doc.addPage();
                    yPosition = 20;
                }
                
                doc.setFontSize(14);
                doc.text(title, 14, yPosition);
                yPosition += 10;
                
                // Add section content (simplified for this example)
                doc.setFontSize(10);
                const inputs = section.querySelectorAll('input, textarea, select');
                
                for (let j = 0; j < inputs.length; j++) {
                    const input = inputs[j];
                    const label = input.previousElementSibling.textContent;
                    const value = input.value;
                    
                    if (yPosition > 280) {
                        doc.addPage();
                        yPosition = 20;
                    }
                    
                    doc.text(`${label}: ${value}`, 20, yPosition);
                    yPosition += 7;
                }
                
                yPosition += 10;
            }
            
            // Save the PDF
            doc.save('forundersokningsprotokoll.pdf');
        }
        
        // Initialize drag and drop when page loads
        document.addEventListener('DOMContentLoaded', function() {
            initDragAndDrop();
        });
    </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=cokai/f-runders-kningsprotokoll" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>