-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgold-standard-reviewer-v3.html
More file actions
1037 lines (956 loc) · 52.7 KB
/
gold-standard-reviewer-v3.html
File metadata and controls
1037 lines (956 loc) · 52.7 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MIDAS Gold Standard Reviewer v3</title>
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg-root: #0f0f11;
--bg-surface: #18181b;
--bg-elevated: #1e1e22;
--bg-hover: #252529;
--border: #2e2e33;
--border-subtle: #232328;
--text-primary: #fafafa;
--text-secondary: #a1a1aa;
--text-muted: #71717a;
--text-faint: #52525b;
--accent-blue: #60a5fa;
--accent-green: #4ade80;
--accent-red: #f87171;
--accent-amber: #f59e0b;
--accent-purple: #a78bfa;
--font-body: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
--font-mono: 'IBM Plex Mono', 'SF Mono', monospace;
}
* { margin:0; padding:0; box-sizing:border-box }
body { background:var(--bg-root); color:var(--text-secondary); font-family:var(--font-body); font-size:14px; line-height:1.5 }
.mono { font-family:var(--font-mono) }
/* ===== TOP BAR ===== */
.topbar {
background:var(--bg-surface); border-bottom:1px solid var(--border);
padding:10px 20px; display:flex; align-items:center; justify-content:space-between;
position:sticky; top:0; z-index:100;
}
.topbar-left { display:flex; align-items:center; gap:16px }
.topbar-right { display:flex; align-items:center; gap:10px; flex-wrap:wrap }
.progress-bar { width:160px; height:5px; background:#27272a; border-radius:3px; overflow:hidden }
.progress-fill { height:100%; border-radius:3px; transition:width 0.3s }
/* ===== BUTTONS ===== */
.btn {
font-size:12px; padding:6px 14px; background:var(--bg-elevated); border:1px solid var(--border);
color:var(--text-secondary); border-radius:5px; cursor:pointer; font-family:inherit;
transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background:var(--bg-hover); border-color:#3f3f46 }
.btn:disabled { opacity:0.35; cursor:default }
.btn-primary { background:#2563eb; border-color:#3b82f6; color:#fff }
.btn-primary:hover { background:#1d4ed8 }
/* Action buttons — text + icon, 44px tall hit targets (fix #3) */
.action-btn {
display:inline-flex; align-items:center; gap:5px;
min-height:36px; padding:4px 12px; border-radius:5px;
font-size:12px; font-weight:500; cursor:pointer; border:1px solid var(--border);
background:var(--bg-elevated); color:var(--text-secondary);
transition: all 0.15s; font-family:inherit; white-space:nowrap;
}
.action-btn:hover { background:var(--bg-hover) }
.action-btn .icon { font-size:15px; line-height:1 }
.action-btn.approve { color:var(--accent-green) }
.action-btn.approve:hover { background:#1a2e1a; border-color:#2d5a2d }
.action-btn.approve.active { background:#1a2e1a; border-color:var(--accent-green); box-shadow:0 0 0 1px rgba(74,222,128,0.2) }
.action-btn.edit { color:var(--accent-blue) }
.action-btn.edit:hover { background:#1a1a2e; border-color:#2d2d5a }
.action-btn.edit.active { background:#1a1a2e; border-color:var(--accent-blue) }
.action-btn.flag { color:var(--accent-red) }
.action-btn.flag:hover { background:#2e1a1a; border-color:#5a2d2d }
.action-btn.flag.active { background:#2e1a1a; border-color:var(--accent-red) }
.action-btn.reset { color:var(--text-muted); font-size:11px }
/* ===== LAYOUT ===== */
.layout { display:flex; height:calc(100vh - 49px) }
/* ===== SIDEBAR (fix #7) ===== */
.sidebar {
width:290px; min-width:290px; background:var(--bg-surface);
border-right:1px solid var(--border); display:flex; flex-direction:column;
}
.sidebar-header { padding:10px 14px; border-bottom:1px solid var(--border) }
.sidebar-search {
width:100%; background:var(--bg-elevated); border:1px solid var(--border);
border-radius:5px; padding:7px 10px; color:var(--text-primary); font-size:12px;
outline:none; font-family:var(--font-mono);
}
.sidebar-search::placeholder { color:var(--text-faint) }
.sidebar-sort { display:flex; gap:4px; margin-top:8px }
.sidebar-sort-btn {
font-size:10px; padding:3px 8px; border-radius:3px; cursor:pointer;
background:transparent; border:1px solid transparent; color:var(--text-muted); font-family:inherit;
}
.sidebar-sort-btn.active { background:var(--bg-elevated); border-color:var(--border); color:var(--text-secondary) }
.sidebar-list { flex:1; overflow-y:auto; padding:6px 0 }
.sidebar-item {
display:block; width:100%; text-align:left; padding:10px 14px;
background:transparent; border:none; border-left:3px solid transparent;
color:var(--text-muted); cursor:pointer; font-size:12px; line-height:1.4; font-family:inherit;
}
.sidebar-item:hover { background:var(--bg-elevated) }
.sidebar-item.active { background:var(--bg-elevated); border-left-color:var(--accent-blue); color:var(--text-secondary) }
.sidebar-id { font-weight:600; font-size:11px; color:var(--text-faint); margin-bottom:3px; font-family:var(--font-mono) }
.sidebar-item.active .sidebar-id { color:var(--accent-blue) }
.sidebar-title { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:248px }
.sidebar-meta { margin-top:5px; display:flex; align-items:center; gap:8px }
.sidebar-prog-bar { width:60px; height:3px; background:#27272a; border-radius:2px; overflow:hidden }
.sidebar-prog-fill { height:100%; border-radius:2px }
.sidebar-status-icon { font-size:11px }
/* ===== MAIN PANEL ===== */
.main { flex:1; overflow-y:auto; padding:0 }
.main-inner { max-width:1000px; margin:0 auto; padding:20px 28px }
/* ===== ABSTRACT PANEL (fix #1 + #5 + #6) ===== */
.abstract-area {
position:sticky; top:0; z-index:10; background:var(--bg-root);
padding-bottom:4px; border-bottom:1px solid var(--border);
}
.abstract-header-row { display:flex; align-items:flex-start; justify-content:space-between; margin-bottom:10px }
.abstract-meta { font-size:12px; color:var(--text-muted); font-family:var(--font-mono) }
.abstract-title { font-size:20px; font-weight:700; color:var(--text-primary); line-height:1.4; margin-top:6px }
.abstract-toggle {
display:flex; align-items:center; gap:6px; background:none; border:none;
color:var(--text-muted); cursor:pointer; font-size:12px; padding:4px 0;
margin-bottom:8px; font-family:var(--font-mono);
}
.abstract-box {
background:var(--bg-surface); border:1px solid var(--border); border-radius:8px;
padding:18px 22px; font-size:14px; line-height:2; color:#c4c4cc;
max-height:280px; overflow-y:auto; transition:border-color 0.2s;
}
.abstract-box.has-highlights { border-color:#b45309 }
/* Evidence highlight legend */
.hl-legend { display:flex; gap:14px; margin-top:8px; font-size:11px; color:var(--text-muted); align-items:center }
.hl-legend-dot { width:10px; height:10px; border-radius:2px; display:inline-block; margin-right:4px; vertical-align:middle }
mark.hl-exact { background:#854d0e; color:#fef3c7; border-radius:2px; padding:0 2px }
mark.hl-partial { background:#3b1f63; color:#d8b4fe; border-radius:2px; padding:0 2px }
/* ===== FILTER BAR (fix #4) ===== */
.filter-bar { display:flex; align-items:center; gap:6px; margin:16px 0; flex-wrap:wrap }
.filter-seg {
display:inline-flex; background:var(--bg-elevated); border:1px solid var(--border);
border-radius:6px; overflow:hidden;
}
.filter-seg-btn {
font-size:12px; padding:6px 14px; cursor:pointer; background:transparent;
border:none; color:var(--text-muted); font-family:inherit;
transition: all 0.15s; border-right:1px solid var(--border); white-space:nowrap;
}
.filter-seg-btn:last-child { border-right:none }
.filter-seg-btn:hover { color:var(--text-secondary); background:var(--bg-hover) }
.filter-seg-btn.active { background:var(--bg-hover); color:var(--text-primary); font-weight:500 }
.filter-seg-btn .count {
display:inline-block; background:var(--bg-root); border-radius:8px;
padding:0 6px; font-size:10px; margin-left:4px; color:var(--text-muted);
font-family:var(--font-mono);
}
.filter-shortcut {
font-size:11px; padding:5px 12px; border-radius:5px; cursor:pointer;
background:transparent; border:1px dashed var(--border); color:var(--text-faint); font-family:inherit;
}
.filter-shortcut:hover { border-color:var(--text-muted); color:var(--text-muted) }
.filter-shortcut.active { border-style:solid; background:var(--bg-elevated); color:var(--text-secondary) }
/* ===== SECTION GROUPING (fix #1) ===== */
.section-group { margin-bottom:8px }
.section-label {
font-size:10px; font-weight:600; letter-spacing:1.5px; text-transform:uppercase;
color:var(--text-faint); padding:12px 0 6px 4px; font-family:var(--font-mono);
}
/* ===== FIELD CARDS (fix #1, #2, #3, #6) ===== */
.field-card {
border-radius:6px; padding:14px 18px; transition:all 0.15s;
margin-bottom:5px; cursor:pointer; border:1px solid transparent;
}
.field-card:hover { border-color:#444; background:var(--bg-elevated) }
.field-card.hl-active { border-color:#b45309; box-shadow:0 0 0 1px rgba(180,83,9,0.3) }
.field-header { display:flex; align-items:flex-start; justify-content:space-between; gap:12px }
.field-name { font-size:14px; font-weight:600; color:var(--text-primary); font-family:var(--font-mono) }
.field-name-row { display:flex; align-items:center; gap:10px; margin-bottom:6px; flex-wrap:wrap }
.status-dot { width:8px; height:8px; border-radius:50%; flex-shrink:0 }
.field-body { margin-left:18px }
.tag {
font-size:12px; padding:3px 10px; background:var(--bg-elevated); border:1px solid var(--border);
border-radius:4px; color:var(--text-primary); display:inline-block; margin:2px;
}
.reasoning { font-size:12px; color:var(--text-muted); line-height:1.6; margin-top:8px }
/* Provenance badge (fix #2) */
.badge {
font-size:9px; padding:2px 7px; border-radius:3px; text-transform:uppercase;
font-weight:600; letter-spacing:0.5px;
}
.badge-explicit { background:#1a2e1a; color:#4ade80; border:1px solid #2d5a2d }
.badge-inferred { background:#2a2318; color:#f59e0b; border:1px solid #5a4a2d }
/* Review state label (fix #2) — separate from provenance */
.review-state {
font-size:10px; padding:2px 8px; border-radius:3px; text-transform:uppercase;
font-weight:600; letter-spacing:0.5px;
}
.review-state.pending { background:var(--bg-elevated); color:var(--text-faint); border:1px solid var(--border) }
.review-state.approved { background:#1a2e1a; color:var(--accent-green); border:1px solid #2d5a2d }
.review-state.flagged { background:#2e1a1a; color:var(--accent-red); border:1px solid #5a2d2d }
.review-state.edited { background:#1a1a2e; color:var(--accent-blue); border:1px solid #2d2d5a }
/* Status colors for cards */
.status-pending { background:var(--bg-root) }
.status-pending .status-dot { background:#555 }
.status-approved { background:rgba(26,46,26,0.3) }
.status-approved .status-dot { background:var(--accent-green) }
.status-flagged { background:rgba(46,26,26,0.3) }
.status-flagged .status-dot { background:var(--accent-red) }
.status-edited { background:rgba(26,26,46,0.3) }
.status-edited .status-dot { background:var(--accent-blue) }
/* Actions row — labeled buttons (fix #3) */
.actions { display:flex; gap:5px; flex-shrink:0; margin-top:2px }
/* Correction / notes */
.correction-box { margin-top:8px; padding:8px 12px; background:#1e1e3a; border:1px solid #2d2d5a; border-radius:5px }
.note-text { margin-top:4px; font-size:12px; color:var(--accent-red); font-style:italic }
/* Edit form */
.edit-form {
margin-top:12px; margin-left:18px; padding:14px 16px;
background:var(--bg-surface); border:1px solid var(--border); border-radius:6px;
}
.edit-label { display:block; font-size:11px; color:var(--text-muted); margin-bottom:5px }
.edit-input {
width:100%; background:var(--bg-elevated); border:1px solid var(--border);
border-radius:5px; padding:8px 12px; color:var(--text-primary); font-size:13px;
outline:none; font-family:var(--font-mono);
}
.edit-textarea {
width:100%; background:var(--bg-elevated); border:1px solid var(--border);
border-radius:5px; padding:8px 12px; color:var(--text-primary); font-size:13px;
outline:none; resize:vertical; font-family:inherit;
}
.edit-actions { display:flex; gap:8px; margin-top:10px }
.btn-save {
font-size:12px; padding:6px 16px; background:#2d2d5a; border:1px solid #4338ca;
color:#c4b5fd; border-radius:5px; cursor:pointer; font-family:inherit;
}
.btn-flagonly {
font-size:12px; padding:6px 16px; background:#3b1111; border:1px solid #7f1d1d;
color:#fca5a5; border-radius:5px; cursor:pointer; font-family:inherit;
}
.btn-cancel {
font-size:12px; padding:6px 16px; background:var(--bg-elevated); border:1px solid var(--border);
color:var(--text-muted); border-radius:5px; cursor:pointer; font-family:inherit;
}
/* Evidence validation warning (fix #8) */
.validation-warning {
margin-top:8px; padding:6px 10px; background:#2a2318; border:1px solid #5a4a2d;
border-radius:4px; font-size:11px; color:var(--accent-amber);
}
/* ===== v3.5 CYPHER: Evidence sentences ===== */
.evidence-block {
margin-top:10px; padding:10px 14px; background:#1a1a1e; border:1px solid #2a2a30;
border-left:3px solid var(--accent-amber); border-radius:0 5px 5px 0;
}
.evidence-label {
font-size:9px; font-weight:700; letter-spacing:1.2px; text-transform:uppercase;
color:var(--accent-amber); margin-bottom:6px; font-family:var(--font-mono);
display:flex; align-items:center; gap:6px;
}
.evidence-label .ev-count {
font-size:9px; background:#2a2318; border:1px solid #5a4a2d; border-radius:8px;
padding:0 6px; font-weight:500;
}
.evidence-sentence {
font-size:12px; line-height:1.7; color:#b8b8c0; margin-bottom:6px; padding-left:12px;
border-left:2px solid #333; position:relative;
}
.evidence-sentence:last-child { margin-bottom:0 }
.evidence-sentence::before {
content:""; position:absolute; left:-5px; top:7px;
width:6px; height:6px; border-radius:50%; background:var(--accent-amber);
}
/* ===== v3.5 CYPHER: Reasoning syntax highlighting ===== */
.cypher-reasoning { font-size:12px; color:var(--text-muted); line-height:1.8; margin-top:8px; font-family:var(--font-mono); word-break:break-word }
.cypher-node { color:#7dd3fc; font-weight:500 }
.cypher-edge { color:#fbbf24; font-weight:600; font-size:11px }
.cypher-arrow { color:#525264 }
.cypher-pipe { color:#6366f1; font-weight:700; margin:0 2px }
.cypher-converge { color:#a78bfa; font-weight:700; margin:0 2px }
.cypher-tag { font-size:10px; padding:1px 6px; border-radius:3px; font-weight:600; letter-spacing:0.3px; display:inline; margin-right:3px }
.cypher-tag-inferred { background:#2a2318; color:#f59e0b; border:1px solid #5a4a2d }
/* Evidence highlight in abstract — highest priority */
mark.hl-evidence { background:#854d0e; color:#fef3c7; border-radius:2px; padding:0 2px; border-bottom:2px solid #f59e0b }
/* Nav */
.nav-bar { display:flex; justify-content:space-between; align-items:center; margin-top:24px; padding-bottom:40px }
/* Upload */
.upload-screen { display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:100vh; padding:40px }
.upload-zone {
border:2px dashed var(--border); border-radius:12px; padding:60px 80px;
text-align:center; cursor:pointer; transition:border-color 0.2s; max-width:600px;
}
.upload-zone:hover { border-color:var(--accent-blue) }
.upload-zone.dragover { border-color:var(--accent-green); background:#1a2e1a }
/* Keyboard hints (fix #3) */
.keyboard-hint {
position:fixed; bottom:12px; right:20px; font-size:11px; color:var(--text-faint); z-index:50;
background:var(--bg-surface); border:1px solid var(--border); border-radius:6px;
padding:6px 12px; display:flex; gap:12px; align-items:center;
}
.keyboard-hint kbd {
background:var(--bg-elevated); border:1px solid var(--border); border-radius:3px;
padding:1px 6px; font-family:var(--font-mono); font-size:10px; color:var(--text-muted);
}
/* Focus ring for keyboard nav */
.field-card.kb-focused { outline:2px solid var(--accent-blue); outline-offset:2px }
/* Toast notification */
.toast {
position:fixed; bottom:60px; left:50%; transform:translateX(-50%);
background:var(--bg-surface); border:1px solid var(--accent-green);
color:var(--accent-green); padding:10px 20px; border-radius:8px;
font-size:13px; font-weight:500; z-index:999; box-shadow:0 4px 20px rgba(0,0,0,0.4);
animation:toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
}
@keyframes toastIn { from { opacity:0; transform:translateX(-50%) translateY(10px) } to { opacity:1; transform:translateX(-50%) translateY(0) } }
@keyframes toastOut { from { opacity:1 } to { opacity:0 } }
/* Tooltip */
[data-tooltip] { position:relative }
[data-tooltip]:hover::after {
content:attr(data-tooltip); position:absolute; bottom:100%; left:50%;
transform:translateX(-50%); background:var(--bg-root); border:1px solid var(--border);
color:var(--text-secondary); font-size:11px; padding:4px 8px; border-radius:4px;
white-space:nowrap; z-index:200; pointer-events:none;
}
</style>
</head>
<body>
<div id="app"></div>
<script>
const FIELD_ORDER=["model_determinism","pathogen_type","geographic_scope","historical_vs_hypothetical","study_goal_category","intervention_present","calibration_mentioned","code_available","data_used","intervention_types","model_type","pathogen_name","disease_name","host_species","primary_population","population_setting_type","geographic_units","data_source","calibration_techniques","key_outcome_measures","study_dates_start","study_dates_end"];
const FIELD_LABELS={model_determinism:"Model Determinism",pathogen_type:"Pathogen Type",geographic_scope:"Geographic Scope",historical_vs_hypothetical:"Historical vs Hypothetical",study_goal_category:"Study Goal Category",intervention_present:"Intervention Present",calibration_mentioned:"Calibration Mentioned",code_available:"Code Available",data_used:"Data Used",intervention_types:"Intervention Types",model_type:"Model Type",pathogen_name:"Pathogen Name",disease_name:"Disease Name",host_species:"Host Species",primary_population:"Primary Population",population_setting_type:"Population Setting Type",geographic_units:"Geographic Units",data_source:"Data Source",calibration_techniques:"Calibration Techniques",key_outcome_measures:"Key Outcome Measures",study_dates_start:"Study Dates Start",study_dates_end:"Study Dates End"};
// FIX #1: Section grouping for fields
const FIELD_SECTIONS = {
"Model": ["model_determinism","model_type"],
"Pathogen & Disease": ["pathogen_type","pathogen_name","disease_name"],
"Population & Geography": ["host_species","primary_population","population_setting_type","geographic_scope","geographic_units"],
"Study Design": ["historical_vs_hypothetical","study_goal_category","study_dates_start","study_dates_end"],
"Interventions": ["intervention_present","intervention_types"],
"Data & Calibration": ["data_used","data_source","calibration_mentioned","calibration_techniques"],
"Outcomes & Reproducibility": ["key_outcome_measures","code_available"],
};
let goldData=[],reviews={},currentAbstract=0,editingField=null,showAbstract=true,filterStatus="all";
let activeHighlight=null,lockedHighlight=false;
// Preserve original file metadata for round-trip export compatibility
let fileMeta={};
// FIX #7: sidebar search/sort
let sidebarSearch="",sidebarSort="default";
// FIX #4: quick filters
let showIssuesOnly=false,showUnansweredOnly=false;
// FIX #3: keyboard field navigation
let focusedFieldIdx=-1;
function loadReviews(){try{const s=localStorage.getItem("midas-gold-reviews");if(s)reviews=JSON.parse(s)}catch(e){}}
function saveReviews(){try{localStorage.setItem("midas-gold-reviews",JSON.stringify(reviews))}catch(e){}}
function rk(id,f){return id+"::"+f}
function getStatus(id,f){return(reviews[rk(id,f)]||{}).status||"pending"}
function getProgress(id){
const a=goldData.find(x=>x.id===id);if(!a)return{total:0,reviewed:0,flagged:0};
let t=0,r=0,fl=0;
FIELD_ORDER.forEach(f=>{if(a.expected[f]){t++;const s=getStatus(id,f);if(s!=="pending")r++;if(s==="flagged")fl++}});
return{total:t,reviewed:r,flagged:fl};
}
// FIX #7: Completion state per abstract
function getCompletionState(id){
const p=getProgress(id);
if(p.total===0)return"empty";
if(p.flagged>0)return"flagged";
if(p.reviewed===p.total)return"complete";
if(p.reviewed>0)return"in-progress";
return"unstarted";
}
function getTotals(){
let t=0,ap=0,fl=0,ed=0;
goldData.forEach(a=>FIELD_ORDER.forEach(f=>{if(a.expected[f]){t++;const s=getStatus(a.id,f);if(s==="approved")ap++;else if(s==="flagged")fl++;else if(s==="edited")ed++}}));
return{total:t,approved:ap,flagged:fl,edited:ed,reviewed:ap+fl+ed,pending:t-(ap+fl+ed)};
}
function esc(s){const d=document.createElement("div");d.textContent=s;return d.innerHTML}
// v3.5: Format Cypher-style reasoning with syntax highlighting
function formatCypherReasoning(reasoning){
if(!reasoning.includes("[Inferred]"))return null;
// Strip the [Inferred] tag — we render it separately as a badge
let text=reasoning.replace(/^\[Inferred\]\s*/,"");
// Escape HTML first
text=esc(text);
// Highlight Cypher syntax: (node)-[:EDGE]->(node)
// Nodes: (...)
text=text.replace(/\(([^)]+)\)/g,'<span class="cypher-node">($1)</span>');
// Edges: -[:LABEL]->
text=text.replace(/-\[:(\w+)\]->/g,'<span class="cypher-arrow">-[:</span><span class="cypher-edge">$1</span><span class="cypher-arrow">]-></span>');
// Pipe separators
text=text.replace(/\s\|\s/g,' <span class="cypher-pipe">|</span> ');
// Convergence arrow
text=text.replace(/=>\s*/g,'<span class="cypher-converge">=></span> ');
return text;
}
// Evidence type from reasoning (v3.5: also check for evidence array)
function getProvenance(exp){
const r=(exp.reasoning||"").toLowerCase();
const hasEvidence=exp.evidence&&Array.isArray(exp.evidence)&&exp.evidence.length>0;
if(r.includes("[inferred]")||hasEvidence)return"inferred";
if(r.includes("explicitly")||r.includes("explicit"))return"explicit";
return null;
}
// FIX #4: per-filter counts for current abstract
function getFieldCounts(){
const abs=goldData[currentAbstract];
const counts={all:0,pending:0,approved:0,flagged:0,edited:0};
FIELD_ORDER.forEach(f=>{
if(!abs.expected[f])return;
counts.all++;
const s=getStatus(abs.id,f);
counts[s]=(counts[s]||0)+1;
});
return counts;
}
// ===== HIGHLIGHT SYSTEM (same core, fix #5: click-based, persistent) =====
const VOCAB_EXPAND={
"parameter estimation":["estimat","parameter","reproduction number","effectiveness","scaling factor"],
"forecast/nowcast":["forecast","nowcast","predict","projection"],
"scenario analysis":["scenario","projection","hypothetical"],
"intervention evaluation":["intervention","effect","impact","effectiveness","efficacy"],
"method development":["method","develop","approach","framework","tool","workflow"],
"transmission dynamics":["transmission","dynamic","spread","infectiousness"],
"Forecasting":["forecast","predict","projection","nowcast"],
"Statistical Model":["statistical","regression","GLM","ARIMA","SARIMA","Prophet","frequentist"],
"Bayesian Model":["Bayesian","posterior","prior","MCMC","credible interval"],
"Compartmental Models":["compartmental","SEIR","SIR","susceptible","exposed","infectious","recovered"],
"Agent-based Models":["agent-based","individual-based","ABM","simulator"],
"Dynamic Models":["dynamic","transmission model","mathematical model"],
"Disease Transmission":["transmission","spread","epidemic","outbreak"],
"Parameter Estimation":["estimat","calibrat","fitting","parameter"],
"Scenario Analysis":["scenario","projection"],
"Geospatial Models":["spatial","spatiotemporal","geographic","adjacency"],
"Phylodynamics":["phylodynamic","phylogenetic","evolutionary","genome","molecular"],
"Phylogenetics":["phylogenetic","evolutionary","genome"],
"Mathematical Model":["mathematical model","mathematical"],
"Intra-host Modeling":["intrahost","viral load","within-host","viral dynamics"],
"Ensemble Specification":["ensemble","combining","averaging"],
"Case Count":["cases","confirmed","incidence","reported"],
"Surveillance":["surveillance","monitoring","reported","tracking"],
"Hospitalization":["hospital","admission","hospitalization","inpatient"],
"Mortality":["death","mortality","lives lost","died","fatal"],
"Human Movement":["mobility","movement","travel","air travel"],
"Vaccination":["vaccin","immunization","immunis"],
"Wastewater":["wastewater","sewage","viral load"],
"Time Series":["time series","daily","weekly","temporal"],
"Tests":["test","antigen","PCR","self-test"],
"Population Demographic":["age structure","population size","demographic","age-specific"],
"Contact Rates":["contact","network","household","workplace","school","transmission network"],
"Climate":["climate","temperature","weather","rainfall","circulation model"],
"Social Media":["social media","proxy","proxies"],
"Population Count":["population","density"],
"Disease Vector":["mosquito","vector","Aedes"],
"Sequence Collection":["genome","sequence","genomic"],
"Age-Stratified":["age-stratified","age-specific","age group","children","older adults"],
"Health System Capacity":["ICU","intensive care","capacity","hospital beds","health care system","overwhelm"],
"Modeling Output":["synthetic","simulated","simulation"],
"Control Strategy":["distancing","mask","quarantine","isolation","lockdown","travel restriction","contact tracing","non-pharmaceutical"],
"School Closure":["school","closing schools","school closure"],
"Event Cancellations":["public events","cancelling","gathering"],
"Bayesian inference":["Bayesian","posterior","prior distribution"],
"model fitting":["fitting","fitted","fit"],
"maximum likelihood estimation":["likelihood","MLE","maximum likelihood"],
"MCMC":["MCMC","Markov chain Monte Carlo"],
"ABC":["approximate Bayesian computation","ABC"],
"parallel tempering":["parallel tempering"],
"stochastic":["stochastic","probabilistic","random"],
"deterministic":["deterministic"],
};
const SKIP_TERMS=new Set(["not mentioned","not specified","not applicable","yes","no","both"]);
const SKIP_WORDS=new Set(["the","and","for","from","with","that","this","are","was","were","has","have","been","not","but","can","will","may","our","its","also","into","than","each","per","all","new","use","used","using","based","data","model","study","analysis","results","method","approach"]);
function getTerms(field){
const abs=goldData[currentAbstract],exp=abs.expected[field];
if(!exp)return{exact:[],partial:[]};
const exact=[],partial=[],seen=new Set();
function addUniq(arr,term){const lc=term.toLowerCase();if(!seen.has(lc)&&lc.length>2){seen.add(lc);arr.push(term)}}
exp.values.forEach(v=>{
if(SKIP_TERMS.has(v.toLowerCase()))return;
if(v.length>2)addUniq(exact,v);
const expansions=VOCAB_EXPAND[v]||[];
expansions.forEach(e=>addUniq(partial,e));
v.split(/[\s,\/\-]+/).forEach(w=>{if(w.length>=5&&!SKIP_WORDS.has(w.toLowerCase()))addUniq(partial,w)});
});
const reasoning=exp.reasoning;
(reasoning.match(/"([^"]+)"/g)||[]).forEach(q=>{const t=q.replace(/"/g,"").trim();if(t.length>2)addUniq(partial,t)});
(reasoning.match(/(?:from|of|named|references?|states?|describes?|mentions?)\s+([A-Z][A-Za-z0-9\s\-]+)/g)||[]).forEach(m=>{
const t=m.replace(/^(?:from|of|named|references?|states?|describes?|mentions?)\s+/i,"").trim();
if(t.length>3&&t.length<60)addUniq(partial,t);
});
const synMap={"SARS-CoV-2":["COVID-19","coronavirus"],"COVID-19":["SARS-CoV-2"],"monkeypox virus":["Mpox","monkeypox"],"Mpox":["monkeypox","Mpox"],"respiratory syncytial virus":["RSV","Respiratory Syncytial Virus Infection"],"Respiratory Syncytial Virus Infection":["RSV","respiratory syncytial"],"RSV":["RSV","respiratory syncytial"],"Vibrio cholerae":["Cholera"],"Cholera":["Cholera","Vibrio"],"Plasmodium":["Malaria"],"Malaria":["Malaria","Plasmodium"],"Ebola virus":["Ebola"],"Ebola":["Ebola","Ebolavirus"],"dengue virus":["Dengue"],"Dengue":["Dengue","dengue virus"],"influenza virus":["Influenza"],"Influenza":["Influenza","influenza virus"]};
exp.values.forEach(v=>{(synMap[v]||[]).forEach(s=>addUniq(partial,s))});
// v3.5: evidence sentences get priority exact highlighting
const evidenceTerms=[];
if(exp.evidence&&Array.isArray(exp.evidence)){
exp.evidence.forEach(ev=>{
const clean=ev.replace(/^\(title\)\s*/,"").trim();
if(clean.length>10)evidenceTerms.push(clean);
});
}
const exactLc=new Set(exact.map(e=>e.toLowerCase()));
return{exact,partial:partial.filter(p=>!exactLc.has(p.toLowerCase())),evidence:evidenceTerms};
}
function highlightAbstract(field){
const abs=goldData[currentAbstract];
if(!field)return esc(abs.abstract);
const{exact,partial,evidence}=getTerms(field);
if(exact.length===0&&partial.length===0&&evidence.length===0)return esc(abs.abstract);
let text=abs.abstract,marks=[];
function findAll(term,cls){
const re=new RegExp(term.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"gi");
let m;while((m=re.exec(text))!==null){marks.push({start:m.index,end:m.index+m[0].length,cls})}
}
// Evidence sentences get highest priority
evidence.forEach(t=>findAll(t,"hl-evidence"));
exact.forEach(t=>findAll(t,"hl-exact"));
partial.forEach(t=>findAll(t,"hl-partial"));
// Sort: evidence first, then exact, then partial; then by position
const clsPrio={"hl-evidence":0,"hl-exact":1,"hl-partial":2};
marks.sort((a,b)=>{if(a.start!==b.start)return a.start-b.start;if(a.cls!==b.cls)return clsPrio[a.cls]-clsPrio[b.cls];return(b.end-b.start)-(a.end-a.start)});
let filtered=[],lastEnd=-1;
marks.forEach(m=>{if(m.start>=lastEnd){filtered.push(m);lastEnd=m.end}});
let html="",pos=0;
filtered.forEach(m=>{
if(m.start>pos)html+=esc(text.slice(pos,m.start));
html+='<mark class="'+m.cls+'">'+esc(text.slice(m.start,m.end))+"</mark>";
pos=m.end;
});
if(pos<text.length)html+=esc(text.slice(pos));
return html;
}
function updateAbstractHighlight(){
const box=document.getElementById("absbox");
if(!box)return;
box.innerHTML=highlightAbstract(activeHighlight);
if(activeHighlight)box.classList.add("has-highlights");else box.classList.remove("has-highlights");
const first=box.querySelector("mark");
if(first)first.scrollIntoView({block:"nearest",behavior:"smooth"});
}
// Toast notification
function showToast(msg){
const el=document.createElement("div");
el.className="toast";el.textContent=msg;
document.body.appendChild(el);
setTimeout(()=>{if(el.parentNode)el.parentNode.removeChild(el)},3200);
}
// ===== UPLOAD SCREEN =====
function renderUpload(){
document.getElementById("app").innerHTML=`
<div class="upload-screen">
<div style="margin-bottom:40px;text-align:center">
<div class="mono" style="font-size:14px;color:var(--text-muted);letter-spacing:2px;margin-bottom:8px">MIDAS GOLD STANDARD</div>
<div style="font-size:26px;font-weight:700;color:var(--text-primary)">Annotation Reviewer</div>
<div style="font-size:14px;color:var(--text-faint);margin-top:8px">Load your gold standard JSON to begin reviewing</div>
</div>
<div class="upload-zone" id="dropzone" onclick="document.getElementById('fi').click()">
<div style="font-size:48px;margin-bottom:16px;color:var(--text-faint)">📋</div>
<div style="font-size:17px;color:var(--text-primary);margin-bottom:8px;font-weight:600">Drop JSON file here</div>
<div style="font-size:14px;color:var(--text-muted);margin-bottom:20px">or click to browse</div>
<div style="font-size:11px;color:var(--text-faint);line-height:1.8" class="mono">
Gold standard JSON (v3.5-cypher) · abstracts[].expected fields<br>
<span style="color:var(--accent-amber)">◆</span> Cypher inference chains · Evidence arrays · OWL-aligned terms<br>
<span style="color:var(--accent-green)">✓</span> Also accepts previously exported reviews to resume progress
</div>
</div>
<input type="file" id="fi" accept=".json" style="display:none">
<div style="margin-top:24px;font-size:13px;color:var(--text-faint);text-align:center">
Progress saves to localStorage · Export anytime as JSON · Re-import to resume<br>
Click field cards to highlight evidence in abstract
</div>
</div>`;
const dz=document.getElementById("dropzone"),fi=document.getElementById("fi");
dz.addEventListener("dragover",e=>{e.preventDefault();dz.classList.add("dragover")});
dz.addEventListener("dragleave",()=>dz.classList.remove("dragover"));
dz.addEventListener("drop",e=>{e.preventDefault();dz.classList.remove("dragover");if(e.dataTransfer.files[0])loadFile(e.dataTransfer.files[0])});
fi.addEventListener("change",e=>{if(e.target.files[0])loadFile(e.target.files[0])});
}
function loadFile(file){
const r=new FileReader();
r.onload=e=>{
try{
const d=JSON.parse(e.target.result);
if(d.abstracts&&Array.isArray(d.abstracts)){
// Store original metadata for round-trip export
fileMeta={};
for(const k of Object.keys(d)){
if(k!=="abstracts")fileMeta[k]=d[k];
}
goldData=d.abstracts;
// Start with localStorage progress (if any exists for these abstracts)
reviews={};
loadReviews();
// Restore review state from file if present (file takes precedence over localStorage)
let restoredCount=0;
goldData.forEach(abs=>{
if(abs.reviews&&typeof abs.reviews==="object"){
for(const[field,rev] of Object.entries(abs.reviews)){
if(rev&&rev.status&&rev.status!=="pending"){
reviews[rk(abs.id,field)]=rev;
restoredCount++;
}
}
}
});
if(restoredCount>0){
saveReviews(); // persist file reviews into localStorage
}
render();
// Notify user if reviews were restored
if(restoredCount>0){
showToast(`Restored ${restoredCount} saved review${restoredCount>1?"s":""} from file`);
}
}
else alert("Invalid format: expected object with 'abstracts' array.");
}catch(err){alert("Parse error: "+err.message)}
};r.readAsText(file);
}
// ===== FIELD CARD RENDER (fix #1, #2, #3) =====
function renderField(abs,field){
const exp=abs.expected[field],status=getStatus(abs.id,field),rev=reviews[rk(abs.id,field)]||{},isEdit=editingField===field;
const prov=getProvenance(exp);
const isActive=activeHighlight===field;
const vals=exp.values.length===0?'<span style="font-size:12px;color:var(--text-faint);font-style:italic">[ empty ]</span>':exp.values.map(v=>`<span class="tag">${esc(v)}</span>`).join(" ");
// FIX #2: Separate provenance badge from review state
let provBadge="";
if(prov==="explicit")provBadge='<span class="badge badge-explicit" data-tooltip="Value found explicitly in text">Explicit</span>';
else if(prov==="inferred")provBadge='<span class="badge badge-inferred" data-tooltip="Value inferred via Cypher chain">Inferred</span>';
let reviewLabel=`<span class="review-state ${status}">${status==="pending"?"Unreviewed":status.charAt(0).toUpperCase()+status.slice(1)}</span>`;
let extra="";
if(rev.correctedValues)extra+=`<div class="correction-box"><span style="font-size:10px;color:#818cf8;font-weight:600">CORRECTED: </span><span style="font-size:13px;color:#c4b5fd">${esc(rev.correctedValues)}</span></div>`;
if(rev.note)extra+=`<div class="note-text">Note: ${esc(rev.note)}</div>`;
// v3.5: Format reasoning — Cypher syntax highlighting for [Inferred]
const cypherHtml=formatCypherReasoning(exp.reasoning);
let reasoningHtml;
if(cypherHtml){
reasoningHtml=`<div class="cypher-reasoning"><span class="cypher-tag cypher-tag-inferred">Inferred</span> ${cypherHtml}</div>`;
} else {
reasoningHtml=`<div class="reasoning">${esc(exp.reasoning)}</div>`;
}
// v3.5: Evidence block for [Inferred] fields
let evidenceHtml="";
if(exp.evidence&&Array.isArray(exp.evidence)&&exp.evidence.length>0){
evidenceHtml=`<div class="evidence-block">
<div class="evidence-label">🔍 Evidence <span class="ev-count">${exp.evidence.length}</span></div>
${exp.evidence.map(ev=>`<div class="evidence-sentence">${esc(ev)}</div>`).join("")}
</div>`;
}
let ef="";
if(isEdit){
const editV=rev.correctedValues||exp.values.join(", "),editN=rev.note||"";
ef=`<div class="edit-form">
<div style="margin-bottom:10px"><label class="edit-label mono">CORRECTED VALUES (comma-separated)</label>
<input class="edit-input mono" id="ev" value="${esc(editV)}"></div>
<div style="margin-bottom:10px"><label class="edit-label mono">NOTE / REASON</label>
<textarea class="edit-textarea" id="en" rows="2">${esc(editN)}</textarea></div>
<div class="edit-actions">
<button class="btn-save" onclick="event.stopPropagation();doSaveEdit('${field}')">Save Correction</button>
<button class="btn-flagonly" onclick="event.stopPropagation();doFlagOnly('${field}')">Flag Only</button>
<button class="btn-cancel" onclick="event.stopPropagation();doCancel()">Cancel</button>
</div></div>`;
}
// FIX #3: Labeled text+icon action buttons with keyboard hints
return`<div class="field-card status-${status} ${isActive?"hl-active":""}" data-field="${field}"
onclick="hlLock('${field}')">
<div class="field-header"><div style="flex:1">
<div class="field-name-row">
<span class="status-dot"></span>
<span class="field-name">${FIELD_LABELS[field]||field}</span>
${reviewLabel}
${provBadge}
</div>
<div class="field-body">
<div style="display:flex;flex-wrap:wrap;gap:4px;margin-bottom:8px">${vals}</div>
${reasoningHtml}${evidenceHtml}${extra}
</div></div>
<div class="actions" onclick="event.stopPropagation()">
<button class="action-btn approve ${status==="approved"?"active":""}" onclick="doApprove('${field}')" data-tooltip="Keyboard: A">
<span class="icon">✓</span> Approve
</button>
<button class="action-btn edit ${(status==="edited")?"active":""}" onclick="doStartEdit('${field}')" data-tooltip="Keyboard: E">
<span class="icon">✎</span> Edit
</button>
<button class="action-btn flag ${(status==="flagged")?"active":""}" onclick="doFlag('${field}')" data-tooltip="Keyboard: F">
<span class="icon">⚑</span> Flag
</button>
${status!=="pending"?`<button class="action-btn reset" onclick="doReset('${field}')" data-tooltip="Reset to unreviewed">↺</button>`:""}
</div></div>${ef}</div>`;
}
// ===== MAIN RENDER =====
function render(){
const abs=goldData[currentAbstract],fields=FIELD_ORDER.filter(f=>abs.expected[f]);
const counts=getFieldCounts();
// Apply filters
let filtered=filterStatus==="all"?fields:fields.filter(f=>getStatus(abs.id,f)===filterStatus);
// FIX #4: quick filter shortcuts
if(showIssuesOnly) filtered=filtered.filter(f=>{const s=getStatus(abs.id,f);return s==="flagged"||s==="edited"});
if(showUnansweredOnly) filtered=filtered.filter(f=>getStatus(abs.id,f)==="pending");
const tot=getTotals();
const pct=tot.total>0?(tot.reviewed/tot.total*100):0;
if(!lockedHighlight)activeHighlight=null;
focusedFieldIdx=-1;
// FIX #7: filtered + sorted sidebar items
let sidebarItems=goldData.map((a,i)=>({abs:a,idx:i}));
if(sidebarSearch){
const q=sidebarSearch.toLowerCase();
sidebarItems=sidebarItems.filter(x=>x.abs.title.toLowerCase().includes(q)||x.abs.id.toLowerCase().includes(q));
}
if(sidebarSort==="incomplete"){
sidebarItems.sort((a,b)=>{const pa=getProgress(a.abs.id),pb=getProgress(b.abs.id);return(pa.reviewed/Math.max(pa.total,1))-(pb.reviewed/Math.max(pb.total,1))});
} else if(sidebarSort==="flagged"){
sidebarItems.sort((a,b)=>getProgress(b.abs.id).flagged-getProgress(a.abs.id).flagged);
}
// FIX #1: Group fields into sections
let fieldsHTML="";
const filteredSet=new Set(filtered);
for(const[section,sectionFields] of Object.entries(FIELD_SECTIONS)){
const visible=sectionFields.filter(f=>filteredSet.has(f));
if(visible.length===0)continue;
fieldsHTML+=`<div class="section-group"><div class="section-label">${esc(section)}</div>`;
visible.forEach(f=>{fieldsHTML+=renderField(abs,f);filteredSet.delete(f)});
fieldsHTML+=`</div>`;
}
// Any remaining fields not in a section
filteredSet.forEach(f=>{fieldsHTML+=renderField(abs,f)});
document.getElementById("app").innerHTML=`
<div class="topbar"><div class="topbar-left">
<span class="mono" style="font-size:13px;color:var(--text-muted);letter-spacing:1px">MIDAS GOLD STANDARD REVIEW</span>
<span style="font-size:12px;color:var(--text-faint)">${fileMeta.version?`v${fileMeta.version} · `:""}${goldData.length} abstracts · ${FIELD_ORDER.length} fields each</span>
</div><div class="topbar-right">
<span style="font-size:12px;color:var(--text-muted)">${tot.reviewed}/${tot.total}</span>
<div class="progress-bar"><div class="progress-fill" style="width:${pct}%;background:var(--accent-blue)"></div></div>
<span style="font-size:11px;color:var(--accent-green)">${tot.approved} ✓</span>
<span style="font-size:11px;color:var(--accent-blue)">${tot.edited} ✎</span>
<span style="font-size:11px;color:var(--accent-red)">${tot.flagged} ⚑</span>
<button class="btn btn-primary" onclick="doExport()">Export JSON</button>
<button class="btn" style="color:var(--text-muted)" onclick="doResetAll()">Reset All</button>
</div></div>
<div class="layout">
<!-- FIX #7: Sidebar with search + sort + completion states -->
<div class="sidebar">
<div class="sidebar-header">
<input class="sidebar-search" type="text" placeholder="Search abstracts..." value="${esc(sidebarSearch)}" oninput="sidebarSearch=this.value;render()">
<div class="sidebar-sort">
<button class="sidebar-sort-btn ${sidebarSort==="default"?"active":""}" onclick="sidebarSort='default';render()">Default</button>
<button class="sidebar-sort-btn ${sidebarSort==="incomplete"?"active":""}" onclick="sidebarSort='incomplete';render()">Incomplete first</button>
<button class="sidebar-sort-btn ${sidebarSort==="flagged"?"active":""}" onclick="sidebarSort='flagged';render()">Flagged first</button>
</div>
</div>
<div class="sidebar-list" id="sb">${sidebarItems.map(({abs:a,idx:i})=>{
const p=getProgress(a.id),ac=i===currentAbstract;
const cs=getCompletionState(a.id);
const stateIcon=cs==="complete"?"✓":cs==="flagged"?"⚑":cs==="in-progress"?"●":"○";
const stateColor=cs==="complete"?"var(--accent-green)":cs==="flagged"?"var(--accent-red)":cs==="in-progress"?"var(--accent-blue)":"var(--text-faint)";
return`<button class="sidebar-item ${ac?"active":""}" onclick="navTo(${i})">
<div style="display:flex;align-items:center;gap:6px">
<span class="sidebar-status-icon" style="color:${stateColor}">${stateIcon}</span>
<span class="sidebar-id">${String(i+1).padStart(2,"0")} · ${esc(a.id)}</span>
</div>
<div class="sidebar-title">${esc(a.title)}</div>
<div class="sidebar-meta">
<div class="sidebar-prog-bar"><div class="sidebar-prog-fill" style="width:${p.total>0?(p.reviewed/p.total*100):0}%;background:${p.reviewed===p.total&&p.total>0?"var(--accent-green)":"var(--accent-blue)"}"></div></div>
<span style="font-size:10px;color:var(--text-faint)">${p.reviewed}/${p.total}</span>
</div></button>`;
}).join("")}</div>
</div>
<div class="main"><div class="main-inner">
<!-- FIX #1 + #5 + #6: Abstract area with better hierarchy -->
<div class="abstract-area">
<div class="abstract-header-row">
<div>
<div class="abstract-meta">${esc(abs.journal||"")} · ${esc(abs.id)}</div>
<h2 class="abstract-title">${esc(abs.title)}</h2>
</div>
</div>
<button class="abstract-toggle" onclick="toggleAbs()">
<span style="transform:${showAbstract?"rotate(90deg)":"rotate(0)"};transition:transform 0.15s;display:inline-block">▶</span> ABSTRACT
${showAbstract?'<span style="font-size:11px;color:var(--text-faint);margin-left:8px">click fields below to highlight evidence</span>':""}
</button>
${showAbstract?`<div class="abstract-box" id="absbox">${highlightAbstract(activeHighlight)}</div>
<div class="hl-legend">
<span><span class="hl-legend-dot" style="background:#854d0e;border-bottom:2px solid #f59e0b"></span> evidence sentence</span>
<span><span class="hl-legend-dot" style="background:#854d0e"></span> exact value</span>
<span><span class="hl-legend-dot" style="background:#3b1f63"></span> related / synonym</span>
${lockedHighlight?'<span style="color:#b45309;font-weight:500">🔒 click field again to unlock</span>':""}
</div>`:""}
</div>
<!-- FIX #4: Segmented filter with counts + quick shortcuts -->
<div class="filter-bar">
<div class="filter-seg">
${["all","pending","approved","flagged","edited"].map(f=>{
const label=f==="pending"?"Unreviewed":f.charAt(0).toUpperCase()+f.slice(1);
return`<button class="filter-seg-btn ${filterStatus===f?"active":""}" onclick="setFilter('${f}')">${label}<span class="count">${counts[f]}</span></button>`;
}).join("")}
</div>
<button class="filter-shortcut ${showIssuesOnly?"active":""}" onclick="showIssuesOnly=!showIssuesOnly;showUnansweredOnly=false;render()">Issues only</button>
<button class="filter-shortcut ${showUnansweredOnly?"active":""}" onclick="showUnansweredOnly=!showUnansweredOnly;showIssuesOnly=false;render()">Unanswered only</button>
<span style="margin-left:auto;font-size:12px;color:var(--text-faint)">${filtered.length} fields</span>
</div>
<!-- FIX #1: Grouped fields -->
<div id="fields">${fieldsHTML}</div>
<div class="nav-bar">
<button class="btn" onclick="navTo(${Math.max(0,currentAbstract-1)})" ${currentAbstract===0?"disabled":""}>← Previous</button>
<span style="font-size:13px;color:var(--text-faint)">${currentAbstract+1} of ${goldData.length}</span>
<button class="btn" onclick="navTo(${Math.min(goldData.length-1,currentAbstract+1)})" ${currentAbstract===goldData.length-1?"disabled":""}>Next →</button>
</div>
</div></div>
</div>
<!-- FIX #3: Expanded keyboard hints -->
<div class="keyboard-hint">
<span><kbd>←</kbd> <kbd>→</kbd> navigate</span>
<span><kbd>A</kbd> approve</span>
<span><kbd>E</kbd> edit</span>
<span><kbd>F</kbd> flag</span>
<span><kbd>J</kbd> <kbd>K</kbd> prev/next field</span>
<span><kbd>Esc</kbd> unlock</span>
</div>`;
setTimeout(()=>{
const el=document.querySelector(".sidebar-item.active");
if(el)el.scrollIntoView({block:"nearest"});
},30);
}
// ===== HIGHLIGHT (FIX #5: click-to-highlight, no hover requirement) =====
function hlLock(field){
if(lockedHighlight&&activeHighlight===field){
lockedHighlight=false;activeHighlight=null;
updateAbstractHighlight();
document.querySelectorAll(".field-card").forEach(c=>c.classList.remove("hl-active"));
} else {
lockedHighlight=true;activeHighlight=field;
updateAbstractHighlight();
document.querySelectorAll(".field-card").forEach(c=>{
c.classList.toggle("hl-active",c.dataset.field===field);
});
if(!showAbstract){showAbstract=true;render()}
}
}
// ===== ACTIONS =====
function navTo(i){currentAbstract=i;editingField=null;activeHighlight=null;lockedHighlight=false;render()}
function toggleAbs(){showAbstract=!showAbstract;render()}
function setFilter(f){filterStatus=f;showIssuesOnly=false;showUnansweredOnly=false;render()}
function doApprove(f){const a=goldData[currentAbstract];reviews[rk(a.id,f)]={status:"approved",timestamp:new Date().toISOString()};saveReviews();render()}
function doFlag(f){
// Quick flag without opening edit form
const a=goldData[currentAbstract];
const existing=reviews[rk(a.id,f)]||{};
if(existing.status==="flagged"){return;} // already flagged
reviews[rk(a.id,f)]={status:"flagged",note:existing.note||"",timestamp:new Date().toISOString()};
saveReviews();render();
}
function doStartEdit(f){editingField=f;lockedHighlight=true;activeHighlight=f;render()}
function doCancel(){editingField=null;lockedHighlight=false;activeHighlight=null;render()}
function doSaveEdit(f){
const a=goldData[currentAbstract],v=document.getElementById("ev").value,n=document.getElementById("en").value;
reviews[rk(a.id,f)]={status:"edited",correctedValues:v,note:n,timestamp:new Date().toISOString()};
editingField=null;lockedHighlight=false;activeHighlight=null;saveReviews();render();
}
function doFlagOnly(f){
const a=goldData[currentAbstract],n=document.getElementById("en").value;
reviews[rk(a.id,f)]={status:"flagged",note:n,timestamp:new Date().toISOString()};
editingField=null;lockedHighlight=false;activeHighlight=null;saveReviews();render();
}
function doReset(f){const a=goldData[currentAbstract];delete reviews[rk(a.id,f)];saveReviews();render()}
function doResetAll(){if(confirm("Clear ALL review progress? This cannot be undone.")){reviews={};saveReviews();render()}}
function doExport(){
const summary={total:0,approved:0,flagged:0,edited:0,pending:0};
// Build abstracts array preserving ALL original fields + adding reviews
const abstracts=goldData.map(abs=>{
const reviewsForAbs={};
FIELD_ORDER.forEach(f=>{
if(!abs.expected[f])return;
const rev=reviews[rk(abs.id,f)];
const st=rev?rev.status:"pending";
summary.total++;
if(st==="approved")summary.approved++;
else if(st==="flagged")summary.flagged++;
else if(st==="edited")summary.edited++;
else summary.pending++;
// Only store non-pending reviews to keep the file clean
if(rev&&st!=="pending"){
const entry={status:st,timestamp:rev.timestamp};
if(rev.correctedValues)entry.correctedValues=rev.correctedValues;
if(rev.note)entry.note=rev.note;
reviewsForAbs[f]=entry;
}
});
// Preserve every original key (id, title, journal, abstract, expected, etc.)
const out={};
for(const k of Object.keys(abs)){
if(k==="reviews")continue; // we'll write our own
out[k]=abs[k];
}
// Add reviews only if there are any
if(Object.keys(reviewsForAbs).length>0){
out.reviews=reviewsForAbs;
}
return out;
});
// Build output: original metadata + abstracts + export metadata
const out={};
// Carry forward all original file metadata (version, created, description, changelog, etc.)
for(const[k,v] of Object.entries(fileMeta)){
if(k!=="exportDate"&&k!=="summary")out[k]=v;
}
out.abstracts=abstracts;
out.exportDate=new Date().toISOString();
out.summary=summary;
const blob=new Blob([JSON.stringify(out,null,2)],{type:"application/json"});
const url=URL.createObjectURL(blob);
const a=document.createElement("a");a.href=url;a.download="gold-review-"+new Date().toISOString().slice(0,10)+".json";
a.style.display="none";document.body.appendChild(a);a.click();
setTimeout(()=>{document.body.removeChild(a);URL.revokeObjectURL(url)},1000);
}
// ===== KEYBOARD NAV (FIX #3: A/E/F + J/K field nav) =====
document.addEventListener("keydown",e=>{
if(!goldData.length)return;
if(e.target.tagName==="INPUT"||e.target.tagName==="TEXTAREA")return;
if(e.key==="Escape"){
lockedHighlight=false;activeHighlight=null;editingField=null;
updateAbstractHighlight();
document.querySelectorAll(".field-card").forEach(c=>c.classList.remove("hl-active"));
focusedFieldIdx=-1;
return;
}
if(editingField)return;
// Arrow nav between abstracts
if(e.key==="ArrowLeft"&¤tAbstract>0){navTo(currentAbstract-1);return}
if(e.key==="ArrowRight"&¤tAbstract<goldData.length-1){navTo(currentAbstract+1);return}
// J/K field navigation
const abs=goldData[currentAbstract];
const visibleFields=FIELD_ORDER.filter(f=>abs.expected[f]);
if((e.key==="j"||e.key==="J")&&visibleFields.length){