-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
979 lines (918 loc) · 70.4 KB
/
Copy pathindex.html
File metadata and controls
979 lines (918 loc) · 70.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ClipMachine — Autonomous Content Pipeline</title>
<style>
:root {
--red: #E24B4A; --red-dark: #A32D2D; --red-light: #FCEBEB; --red-text: #791F1F;
--green: #1D9E75; --green-dark: #0F6E56; --green-light: #E1F5EE; --green-text: #085041;
--blue: #378ADD; --blue-dark: #185FA5; --blue-light: #E6F1FB; --blue-text: #0C447C;
--amber: #BA7517; --amber-light: #FAEEDA; --amber-text: #633806;
--purple: #7F77DD; --purple-light: #EEEDFE; --purple-text: #3C3489;
--teal: #1D9E75; --teal-light: #E1F5EE; --teal-text: #085041;
--gray-50: #F8F8F8; --gray-100: #F1F1F1; --gray-200: #E0E0E0;
--gray-400: #999; --gray-600: #666; --gray-800: #333; --gray-900: #111;
--bg: #ffffff; --bg-2: #F7F7F7; --bg-3: #F0F0F0;
--text: #111; --text-2: #555; --text-3: #999;
--border: rgba(0,0,0,0.1); --border-2: rgba(0,0,0,0.18);
--radius: 8px; --radius-lg: 12px; --radius-xl: 16px;
--font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
--mono: 'SF Mono', 'Fira Code', monospace;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0f0f0f; --bg-2: #1a1a1a; --bg-3: #242424;
--text: #f0f0f0; --text-2: #aaa; --text-3: #666;
--border: rgba(255,255,255,0.1); --border-2: rgba(255,255,255,0.18);
--red-light: #2a1010; --red-text: #f09595;
--green-light: #0d1f18; --green-text: #5DCAA5;
--blue-light: #0d1827; --blue-text: #85B7EB;
--amber-light: #1f1600; --amber-text: #FAC775;
--purple-light: #15132a; --purple-text: #AFA9EC;
}
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
input, select, textarea, button { font-family: var(--font); font-size: 13px; }
input, select, textarea {
width: 100%; padding: 8px 11px; border-radius: var(--radius);
border: 1px solid var(--border-2); background: var(--bg-2);
color: var(--text); outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); }
input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
button {
cursor: pointer; border: 1px solid var(--border-2); background: var(--bg);
color: var(--text); padding: 8px 16px; border-radius: var(--radius);
font-weight: 500; transition: all .15s;
}
button:hover { background: var(--bg-2); }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--red); color: white; border-color: var(--red); }
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn-green { background: var(--green); color: white; border-color: var(--green); }
.btn-green:hover { background: var(--green-dark); }
.btn-blue { background: var(--blue); color: white; border-color: var(--blue); }
.btn-blue:hover { background: var(--blue-dark); }
.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem; }
.card-sm { background: var(--bg-2); border-radius: var(--radius); padding: 10px 14px; }
.section-title { font-size: 11px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .6px; margin-bottom: .75rem; }
.badge { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 20px; display: inline-block; }
.badge-green { background: var(--green-light); color: var(--green-text); }
.badge-red { background: var(--red-light); color: var(--red-text); }
.badge-blue { background: var(--blue-light); color: var(--blue-text); }
.badge-amber { background: var(--amber-light); color: var(--amber-text); }
.badge-purple { background: var(--purple-light); color: var(--purple-text); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.fl { font-size: 11px; color: var(--text-2); margin-bottom: 4px; }
.fgroup { margin-bottom: 10px; }
.prog-wrap { height: 3px; background: var(--bg-3); border-radius: 2px; overflow: hidden; margin: 8px 0 4px; }
.prog-fill { height: 100%; border-radius: 2px; background: var(--red); width: 0%; transition: width .4s ease; }
.status-line { font-size: 11px; color: var(--text-2); font-family: var(--mono); min-height: 16px; }
.metric-card { background: var(--bg-2); border-radius: var(--radius); padding: 12px 14px; }
.metric-label { font-size: 10px; color: var(--text-2); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.metric-value { font-size: 22px; font-weight: 600; color: var(--text); }
.metric-sub { font-size: 11px; color: var(--green-text); margin-top: 2px; }
.tag { font-size: 10px; padding: 2px 8px; border-radius: 20px; background: var(--bg-3); color: var(--text-2); border: 1px solid var(--border); display: inline-block; }
.tag-blue { background: var(--blue-light); color: var(--blue-text); border-color: transparent; }
.tag-green { background: var(--green-light); color: var(--green-text); border-color: transparent; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
@keyframes spin { from{transform:rotate(0deg)} to{transform:rotate(360deg)} }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
.spin { animation: spin 1s linear infinite; }
.pulse { animation: pulse 1.2s ease-in-out infinite; }
.hidden { display: none !important; }
/* ── LAYOUT ── */
#app { min-height: 100vh; }
.screen { display: none; }
.screen.active { display: block; }
/* ── AUTH ── */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-box { width: 100%; max-width: 420px; }
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo-icon { width: 52px; height: 52px; background: var(--red); border-radius: 14px; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; }
.auth-logo-icon svg { width: 26px; height: 26px; fill: white; }
.auth-logo h1 { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.auth-logo p { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.auth-tabs { display: flex; border: 1px solid var(--border-2); border-radius: var(--radius); overflow: hidden; margin-bottom: 1.25rem; }
.auth-tab { flex: 1; padding: 9px; text-align: center; cursor: pointer; font-size: 13px; font-weight: 500; background: var(--bg-2); color: var(--text-2); border: none; transition: all .15s; }
.auth-tab.active { background: var(--red); color: white; }
.auth-msg { font-size: 12px; padding: 8px 12px; border-radius: var(--radius); margin-bottom: 10px; display: none; }
.auth-msg.err { background: var(--red-light); color: var(--red-text); }
.auth-msg.ok { background: var(--green-light); color: var(--green-text); }
.invite-box { background: var(--bg-2); border-radius: var(--radius); padding: 10px 12px; margin-top: 12px; font-size: 11px; color: var(--text-2); line-height: 1.7; }
.invite-code { font-family: var(--mono); font-weight: 700; color: var(--red); background: var(--red-light); padding: 2px 8px; border-radius: 4px; letter-spacing: 1px; }
.auth-footer { text-align: center; font-size: 11px; color: var(--text-3); margin-top: 12px; }
/* ── MAIN APP ── */
.app-layout { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 220px; flex-shrink: 0; background: var(--bg-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 1.25rem 0; }
.sidebar-brand { padding: 0 1.25rem 1.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.sidebar-brand-icon { width: 32px; height: 32px; background: var(--red); border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.sidebar-brand-icon svg { width: 16px; height: 16px; fill: white; }
.sidebar-brand-title { font-size: 15px; font-weight: 700; letter-spacing: -.3px; }
.sidebar-brand-sub { font-size: 11px; color: var(--text-2); }
.sidebar-nav { flex: 1; padding: 0 8px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 8px 12px; border-radius: var(--radius); cursor: pointer; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 2px; transition: all .12s; border: none; background: transparent; width: 100%; text-align: left; }
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--red-light); color: var(--red-text); }
.nav-item.admin-nav { color: var(--red-text); }
.nav-item.admin-nav.active { background: var(--red); color: white; }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 12px; }
.sidebar-user { padding: 1rem 1.25rem; border-top: 1px solid var(--border); margin-top: auto; }
.sidebar-user-av { width: 32px; height: 32px; border-radius: 50%; background: var(--red); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: white; flex-shrink: 0; }
.sidebar-user-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sidebar-user-name { font-size: 12px; font-weight: 600; color: var(--text); }
.sidebar-user-role { font-size: 10px; color: var(--text-2); }
.logout-link { font-size: 11px; color: var(--text-3); cursor: pointer; background: none; border: none; padding: 0; text-decoration: underline; }
.logout-link:hover { color: var(--red); }
.main-content { flex: 1; overflow-y: auto; padding: 1.5rem 2rem; }
.page { display: none; }
.page.active { display: block; }
.page-header { margin-bottom: 1.5rem; }
.page-title { font-size: 20px; font-weight: 700; letter-spacing: -.4px; }
.page-sub { font-size: 13px; color: var(--text-2); margin-top: 3px; }
/* ── PIPELINE PAGE ── */
.phase-track { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 1.5rem; }
.phase-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px; transition: border-color .2s; }
.phase-card.active { border-color: var(--red); }
.phase-card.done { border-color: var(--green); }
.phase-num { width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; margin-bottom: 8px; background: var(--bg-2); color: var(--text-2); transition: all .2s; }
.phase-num.active { background: var(--red); color: white; }
.phase-num.done { background: var(--green-light); color: var(--green-text); }
.phase-name { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.phase-agent { font-size: 10px; color: var(--text-2); margin-bottom: 8px; }
.phase-steps { font-size: 10px; color: var(--text-2); display: flex; flex-direction: column; gap: 3px; }
.ps { display: flex; align-items: center; gap: 5px; }
.ps-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--border-2); flex-shrink: 0; transition: background .2s; }
.ps-dot.done { background: var(--green); }
.ps-dot.active { background: var(--red); animation: pulse 1s infinite; }
.phase-bar { height: 2px; background: var(--bg-3); border-radius: 1px; overflow: hidden; margin-top: 8px; }
.phase-bar-fill { height: 100%; border-radius: 1px; background: var(--red); width: 0%; transition: width .4s; }
.phase-bar-fill.done { background: var(--green); }
/* ── AGENTS ── */
.agents-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 1.5rem; }
.agent-chip { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; align-items: center; gap: 8px; transition: border-color .2s; }
.agent-chip.active { border-color: var(--red); }
.agent-chip.done { border-color: var(--green); }
.agent-av { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; flex-shrink: 0; }
.agent-name { font-size: 11px; font-weight: 600; color: var(--text); }
.agent-task { font-size: 10px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-led { width: 6px; height: 6px; border-radius: 50%; background: var(--border-2); margin-left: auto; flex-shrink: 0; }
.agent-led.on { background: var(--red); animation: pulse 1s infinite; }
.agent-led.done { background: var(--green); }
/* ── CLIPS TABLE ── */
.clips-table { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 1rem; }
.ct-head { display: grid; grid-template-columns: 30px 1fr 80px 60px 90px 70px; gap: 8px; padding: 8px 14px; background: var(--bg-2); font-size: 10px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; }
.ct-row { display: grid; grid-template-columns: 30px 1fr 80px 60px 90px 70px; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); align-items: center; }
.ct-row:hover { background: var(--bg-2); }
.ct-rank { font-size: 12px; font-weight: 700; color: var(--text-2); text-align: center; }
.ct-rank.top { color: var(--amber); }
.ct-title { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-meta { font-size: 10px; color: var(--text-2); }
/* ── LOG ── */
.log-panel { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem; }
.log-scroll { max-height: 180px; overflow-y: auto; }
.log-line { display: flex; gap: 8px; padding: 3px 0; font-size: 11px; border-bottom: 1px solid var(--border); }
.log-line:last-child { border-bottom: none; }
.log-ts { color: var(--text-3); font-family: var(--mono); min-width: 56px; flex-shrink: 0; }
.log-ok { color: #3B6D11; }
.log-act { color: #185FA5; }
.log-warn { color: #854F0B; }
.log-err { color: #A32D2D; }
.log-sys { color: var(--text-2); }
/* ── MY RUNS ── */
.run-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem 1.25rem; margin-bottom: 10px; }
.run-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.run-title { font-size: 13px; font-weight: 600; }
.run-time { font-size: 11px; color: var(--text-2); }
.run-stats { display: flex; gap: 6px; flex-wrap: wrap; }
.run-stat { font-size: 10px; padding: 3px 8px; border-radius: 20px; background: var(--bg-2); color: var(--text-2); }
.run-stat.good { background: var(--green-light); color: var(--green-text); }
.run-stat.warn { background: var(--amber-light); color: var(--amber-text); }
.phase-row { display: flex; gap: 4px; margin-top: 8px; }
.phase-dot { flex: 1; height: 4px; border-radius: 2px; background: var(--bg-3); }
.phase-dot.done { background: var(--green); }
.phase-dot.warn { background: var(--amber); }
/* ── ADMIN ── */
.user-table { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 1rem; }
.ut-head { display: grid; grid-template-columns: 1fr 90px 90px 50px 70px; gap: 8px; padding: 8px 14px; background: var(--bg-2); font-size: 10px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; }
.ut-row { display: grid; grid-template-columns: 1fr 90px 90px 50px 70px; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); align-items: center; }
.ut-row:hover { background: var(--bg-2); }
.ut-name { font-size: 12px; font-weight: 600; }
.ut-email { font-size: 10px; color: var(--text-2); }
.ut-cell { font-size: 12px; color: var(--text-2); text-align: center; }
.act-log { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem; }
.al-entry { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 11px; }
.al-entry:last-child { border-bottom: none; }
.al-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; margin-top: 3px; }
.al-user { font-weight: 600; min-width: 70px; }
.al-action { color: var(--text-2); flex: 1; }
.al-time { color: var(--text-3); white-space: nowrap; font-family: var(--mono); }
/* ── DEBUG ── */
.debug-entry { background: var(--bg-2); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 6px; font-family: var(--mono); font-size: 11px; line-height: 1.8; }
/* ── EMPTY ── */
.empty { padding: 3rem; text-align: center; color: var(--text-2); }
.empty svg { width: 36px; height: 36px; fill: var(--text-3); margin-bottom: 10px; display: block; margin-left: auto; margin-right: auto; }
/* ── RESPONSIVE ── */
@media(max-width:768px){
.app-layout { flex-direction: column; }
.sidebar { width: 100%; height: auto; flex-direction: row; flex-wrap: wrap; padding: .75rem; }
.sidebar-brand { padding: 0 .75rem .75rem 0; border-bottom: none; border-right: 1px solid var(--border); margin-right: .75rem; margin-bottom: 0; }
.sidebar-nav { display: flex; flex-direction: row; padding: 0; gap: 4px; }
.sidebar-user { border-top: none; border-left: 1px solid var(--border); margin-top: 0; margin-left: auto; padding: 0 0 0 .75rem; }
.main-content { padding: 1rem; }
.phase-track, .agents-grid { grid-template-columns: 1fr 1fr; }
.grid4 { grid-template-columns: 1fr 1fr; }
.ct-head, .ct-row { grid-template-columns: 30px 1fr 60px 60px; }
.ct-head > *:nth-child(5), .ct-head > *:nth-child(6),
.ct-row > *:nth-child(5), .ct-row > *:nth-child(6) { display: none; }
}
</style>
</head>
<body>
<div id="app">
<!-- AUTH SCREEN -->
<div class="screen active" id="screen-auth">
<div class="auth-page">
<div class="auth-box">
<div class="auth-logo">
<div class="auth-logo-icon">
<svg viewBox="0 0 24 24"><path d="M4 2l16 10L4 22V2z"/></svg>
</div>
<h1>ClipMachine</h1>
<p>Autonomous content pipeline — cohort access</p>
</div>
<div class="card">
<div class="auth-tabs">
<button class="auth-tab active" id="tab-in" onclick="switchTab('in')">Sign in</button>
<button class="auth-tab" id="tab-up" onclick="switchTab('up')">Create account</button>
</div>
<div class="auth-msg" id="auth-msg"></div>
<!-- LOGIN -->
<div id="form-in">
<div class="fgroup"><div class="fl">Email</div><input id="li-email" type="email" placeholder="you@example.com"></div>
<div class="fgroup"><div class="fl">Password</div><input id="li-pass" type="password" placeholder="••••••••" onkeydown="if(event.key==='Enter')doLogin()"></div>
<button class="btn-primary" style="width:100%;padding:11px;font-size:13px" id="li-btn" onclick="doLogin()">Sign in to ClipMachine</button>
<div class="invite-box">New here? Create a free account. Share this invite code with your cohort:<br>
<div style="margin-top:6px;display:flex;align-items:center;gap:8px">
<span class="invite-code">CLIP2025</span>
<span style="font-size:10px;color:var(--text-3)">Admin access: ADMIN2025</span>
</div>
</div>
</div>
<!-- SIGNUP -->
<div id="form-up" class="hidden">
<div class="grid2">
<div class="fgroup"><div class="fl">First name</div><input id="su-first" placeholder="Alex"></div>
<div class="fgroup"><div class="fl">Last name</div><input id="su-last" placeholder="Chen"></div>
</div>
<div class="fgroup"><div class="fl">Email</div><input id="su-email" type="email" placeholder="you@example.com"></div>
<div class="fgroup"><div class="fl">Password (min 6 chars)</div><input id="su-pass" type="password" placeholder="••••••••"></div>
<div class="fgroup"><div class="fl">Invite code</div><input id="su-invite" placeholder="CLIP2025" style="text-transform:uppercase;font-family:var(--mono)"></div>
<div class="fgroup"><div class="fl">Your role</div>
<select id="su-role">
<option value="student">Student / learner</option>
<option value="creator">Content creator</option>
<option value="marketer">Marketing / SEO</option>
<option value="developer">Developer / tester</option>
<option value="other">Other</option>
</select>
</div>
<button class="btn-primary" style="width:100%;padding:11px;font-size:13px" id="su-btn" onclick="doSignup()">Create free account</button>
</div>
</div>
<div class="auth-footer">ClipMachine cohort tool · free to use · no credit card required</div>
</div>
</div>
</div>
<!-- MAIN APP -->
<div class="screen" id="screen-main">
<div class="app-layout">
<nav class="sidebar">
<div class="sidebar-brand">
<div class="sidebar-brand-icon"><svg viewBox="0 0 24 24"><path d="M4 2l16 10L4 22V2z"/></svg></div>
<div class="sidebar-brand-title">ClipMachine</div>
<div class="sidebar-brand-sub">Content pipeline</div>
</div>
<div class="sidebar-nav">
<button class="nav-item active" onclick="showPage('pipeline',this)">
<svg class="nav-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M4 2l16 10L4 22V2z"/></svg>Pipeline
</button>
<button class="nav-item" onclick="showPage('collect',this)">
<svg class="nav-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 14.5v-9l6 4.5-6 4.5z"/></svg>01 Collect
</button>
<button class="nav-item" onclick="showPage('transform',this)">
<svg class="nav-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-5 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z"/></svg>02 Transform
</button>
<button class="nav-item" onclick="showPage('analyze',this)">
<svg class="nav-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4zm2 2H5V5h14v14zm0-16H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"/></svg>03 Analyze
</button>
<button class="nav-item" onclick="showPage('publish',this)">
<svg class="nav-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>04 Publish
</button>
<div class="nav-sep"></div>
<button class="nav-item" onclick="showPage('my-runs',this)">
<svg class="nav-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"/></svg>My runs
</button>
<button class="nav-item" onclick="showPage('debug',this)">
<svg class="nav-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M20 8h-2.81c-.45-.78-1.07-1.45-1.82-1.96L17 4.41 15.59 3l-2.17 2.17C12.96 5.06 12.49 5 12 5c-.49 0-.96.06-1.41.17L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8zm-6 8h-4v-2h4v2zm0-4h-4v-2h4v2z"/></svg>Debug log
</button>
<button class="nav-item admin-nav hidden" id="admin-nav" onclick="showPage('admin',this)">
<svg class="nav-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M12 1L3 5v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V5l-9-4zm0 4l5 2.18V11c0 3.5-2.33 6.79-5 7.93-2.67-1.14-5-4.43-5-7.93V7.18L12 5z"/></svg>Admin
</button>
</div>
<div class="sidebar-user">
<div class="sidebar-user-row">
<div class="sidebar-user-av" id="s-av">?</div>
<div>
<div class="sidebar-user-name" id="s-name">—</div>
<div class="sidebar-user-role" id="s-role">—</div>
</div>
</div>
<button class="logout-link" onclick="doLogout()">Sign out</button>
</div>
</nav>
<main class="main-content">
<!-- PIPELINE PAGE -->
<div class="page active" id="page-pipeline">
<div class="page-header">
<div class="page-title">Master Control Room</div>
<div class="page-sub">One click runs the entire pipeline — collect, transform, analyze, publish</div>
</div>
<div class="card" style="margin-bottom:1.25rem">
<div class="section-title">Configure run</div>
<div class="grid2" style="margin-bottom:10px">
<div class="fgroup"><div class="fl">Clip title (optional)</div><input id="mc-title" placeholder="Leave blank for auto-discovery"></div>
<div class="fgroup"><div class="fl">Niche</div>
<select id="mc-niche"><option value="gaming">Gaming</option><option value="fps">FPS / Shooters</option><option value="rpg">RPG</option><option value="irl">IRL / Just Chatting</option><option value="esports">Esports</option><option value="variety">Variety</option></select>
</div>
</div>
<div class="grid3" style="margin-bottom:10px">
<div class="fgroup"><div class="fl">Tone</div><select id="mc-tone"><option value="hype">Hype</option><option value="funny">Funny</option><option value="clutch">Clutch</option><option value="wholesome">Wholesome</option><option value="fail">Epic fail</option></select></div>
<div class="fgroup"><div class="fl">Clips per run</div><select id="mc-count"><option value="5">5 clips</option><option value="10" selected>10 clips</option><option value="20">20 clips</option></select></div>
<div class="fgroup"><div class="fl">Platforms</div><select id="mc-plats"><option value="all">All platforms</option><option value="yt-tk">YouTube + TikTok</option><option value="yt">YouTube only</option><option value="tk">TikTok only</option></select></div>
</div>
<button class="btn-primary" style="width:100%;padding:12px;font-size:14px;font-weight:700" id="launch-btn" onclick="launchPipeline()">▶ Launch full pipeline</button>
<div class="prog-wrap"><div class="prog-fill" id="mc-prog"></div></div>
<div class="status-line" id="mc-status">Configure above and launch</div>
</div>
<div class="phase-track" id="phase-track">
<div class="phase-card" id="pc-0"><div class="phase-num" id="pn-0">01</div><div class="phase-name">Collect</div><div class="phase-agent">Data Analyst</div><div class="phase-steps"><div class="ps"><div class="ps-dot" id="ps-0-0"></div>Scrape platforms</div><div class="ps"><div class="ps-dot" id="ps-0-1"></div>Filter & dedup</div><div class="ps"><div class="ps-dot" id="ps-0-2"></div>Virality score</div><div class="ps"><div class="ps-dot" id="ps-0-3"></div>Rank top clips</div></div><div class="phase-bar"><div class="phase-bar-fill" id="pb-0"></div></div></div>
<div class="phase-card" id="pc-1"><div class="phase-num" id="pn-1">02</div><div class="phase-name">Transform</div><div class="phase-agent">Creative Director</div><div class="phase-steps"><div class="ps"><div class="ps-dot" id="ps-1-0"></div>Trim & cut plan</div><div class="ps"><div class="ps-dot" id="ps-1-1"></div>Caption script</div><div class="ps"><div class="ps-dot" id="ps-1-2"></div>Thumbnail concept</div><div class="ps"><div class="ps-dot" id="ps-1-3"></div>Format adapt</div></div><div class="phase-bar"><div class="phase-bar-fill" id="pb-1"></div></div></div>
<div class="phase-card" id="pc-2"><div class="phase-num" id="pn-2">03</div><div class="phase-name">Analyze</div><div class="phase-agent">SEO + Data Analyst</div><div class="phase-steps"><div class="ps"><div class="ps-dot" id="ps-2-0"></div>SEO keywords</div><div class="ps"><div class="ps-dot" id="ps-2-1"></div>Sentiment score</div><div class="ps"><div class="ps-dot" id="ps-2-2"></div>Competitor gap</div><div class="ps"><div class="ps-dot" id="ps-2-3"></div>View forecast</div></div><div class="phase-bar"><div class="phase-bar-fill" id="pb-2"></div></div></div>
<div class="phase-card" id="pc-3"><div class="phase-num" id="pn-3">04</div><div class="phase-name">Publish</div><div class="phase-agent">Copywriter + Planner</div><div class="phase-steps"><div class="ps"><div class="ps-dot" id="ps-3-0"></div>Write platform copy</div><div class="ps"><div class="ps-dot" id="ps-3-1"></div>Smart scheduling</div><div class="ps"><div class="ps-dot" id="ps-3-2"></div>Dispatch posts</div><div class="ps"><div class="ps-dot" id="ps-3-3"></div>Log & confirm</div></div><div class="phase-bar"><div class="phase-bar-fill" id="pb-3"></div></div></div>
</div>
<div class="agents-grid" id="agents-grid">
<div class="agent-chip" id="ag-0"><div class="agent-av" style="background:#EEEDFE;color:#3C3489">LC</div><div style="min-width:0;flex:1"><div class="agent-name">Lead Coord.</div><div class="agent-task" id="at-0">standing by</div></div><div class="agent-led" id="al-0"></div></div>
<div class="agent-chip" id="ag-1"><div class="agent-av" style="background:#E1F5EE;color:#085041">DA</div><div style="min-width:0;flex:1"><div class="agent-name">Data Analyst</div><div class="agent-task" id="at-1">standing by</div></div><div class="agent-led" id="al-1"></div></div>
<div class="agent-chip" id="ag-2"><div class="agent-av" style="background:#E6F1FB;color:#0C447C">SE</div><div style="min-width:0;flex:1"><div class="agent-name">SEO Specialist</div><div class="agent-task" id="at-2">standing by</div></div><div class="agent-led" id="al-2"></div></div>
<div class="agent-chip" id="ag-3"><div class="agent-av" style="background:#FAEEDA;color:#633806">PL</div><div style="min-width:0;flex:1"><div class="agent-name">Planner</div><div class="agent-task" id="at-3">standing by</div></div><div class="agent-led" id="al-3"></div></div>
<div class="agent-chip" id="ag-4"><div class="agent-av" style="background:#FBEAF0;color:#72243E">CM</div><div style="min-width:0;flex:1"><div class="agent-name">Comms</div><div class="agent-task" id="at-4">standing by</div></div><div class="agent-led" id="al-4"></div></div>
<div class="agent-chip" id="ag-5"><div class="agent-av" style="background:#FAECE7;color:#712B13">CW</div><div style="min-width:0;flex:1"><div class="agent-name">Copywriter</div><div class="agent-task" id="at-5">standing by</div></div><div class="agent-led" id="al-5"></div></div>
<div class="agent-chip" id="ag-6"><div class="agent-av" style="background:#E1F5EE;color:#04342C">CD</div><div style="min-width:0;flex:1"><div class="agent-name">Creative Dir.</div><div class="agent-task" id="at-6">standing by</div></div><div class="agent-led" id="al-6"></div></div>
<div class="agent-chip" id="ag-7"><div class="agent-av" style="background:#FCEBEB;color:#791F1F">PM</div><div style="min-width:0;flex:1"><div class="agent-name">Project Mgr</div><div class="agent-task" id="at-7">standing by</div></div><div class="agent-led" id="al-7"></div></div>
</div>
<div id="pipeline-results"></div>
<div class="log-panel">
<div class="section-title">System log</div>
<div class="log-scroll" id="main-log"><div class="log-line"><span class="log-ts">--:--:--</span><span class="log-sys">ClipMachine ready. Launch a pipeline run above.</span></div></div>
</div>
</div>
<!-- COLLECT PAGE -->
<div class="page" id="page-collect">
<div class="page-header"><div class="page-title">Phase 01 — Collect</div><div class="page-sub">Scrape, filter, score, and rank trending clips across all platforms</div></div>
<div class="card" style="margin-bottom:1rem">
<div class="section-title">Ingestion config</div>
<div class="grid3" style="margin-bottom:10px">
<div class="fgroup"><div class="fl">Niche</div><select id="c-niche"><option value="gaming">Gaming</option><option value="fps">FPS</option><option value="rpg">RPG</option><option value="irl">IRL</option><option value="esports">Esports</option></select></div>
<div class="fgroup"><div class="fl">Clip limit</div><select id="c-limit"><option value="10">10 clips</option><option value="20" selected>20 clips</option><option value="50">50 clips</option></select></div>
<div class="fgroup"><div class="fl">Platforms</div><select id="c-plat"><option value="all">All platforms</option><option value="twitch">Twitch only</option><option value="youtube">YouTube only</option><option value="tiktok">TikTok only</option></select></div>
</div>
<button class="btn-primary" style="padding:10px 24px" id="c-btn" onclick="runCollect()">Run ingestion</button>
<div class="prog-wrap"><div class="prog-fill" id="c-prog"></div></div>
<div class="status-line" id="c-status">Ready</div>
</div>
<div id="collect-results"></div>
</div>
<!-- TRANSFORM PAGE -->
<div class="page" id="page-transform">
<div class="page-header"><div class="page-title">Phase 02 — Transform</div><div class="page-sub">Generate trim plans, captions, thumbnail concepts, and format specs</div></div>
<div class="card" style="margin-bottom:1rem">
<div class="section-title">Clip details</div>
<div class="grid2" style="margin-bottom:10px">
<div class="fgroup"><div class="fl">Clip title</div><input id="t-title" placeholder="xQc rage quits Elden Ring DLC"></div>
<div class="fgroup"><div class="fl">Streamer</div><input id="t-streamer" placeholder="xQc"></div>
</div>
<div class="grid3" style="margin-bottom:10px">
<div class="fgroup"><div class="fl">Platform</div><select id="t-plat"><option value="twitch">Twitch</option><option value="youtube">YouTube</option><option value="tiktok">TikTok</option></select></div>
<div class="fgroup"><div class="fl">Duration (sec)</div><input id="t-dur" type="number" value="90" min="10" max="300"></div>
<div class="fgroup"><div class="fl">Tone</div><select id="t-tone"><option value="hype">Hype</option><option value="funny">Funny</option><option value="clutch">Clutch</option><option value="wholesome">Wholesome</option><option value="fail">Fail</option></select></div>
</div>
<button class="btn-green" style="padding:10px 24px" id="t-btn" onclick="runTransform()">Transform clip</button>
<div class="prog-wrap" style="--fill:var(--green)"><div class="prog-fill" id="t-prog" style="background:var(--green)"></div></div>
<div class="status-line" id="t-status">Ready</div>
</div>
<div id="transform-results"></div>
</div>
<!-- ANALYZE PAGE -->
<div class="page" id="page-analyze">
<div class="page-header"><div class="page-title">Phase 03 — Analyze</div><div class="page-sub">SEO keywords, sentiment, competitor gap, and virality forecast</div></div>
<div class="card" style="margin-bottom:1rem">
<div class="section-title">Clip to analyze</div>
<div class="grid2" style="margin-bottom:10px">
<div class="fgroup"><div class="fl">Clip title</div><input id="a-title" placeholder="xQc rage quits Elden Ring DLC"></div>
<div class="fgroup"><div class="fl">Streamer</div><input id="a-streamer" placeholder="xQc"></div>
</div>
<div class="grid3" style="margin-bottom:10px">
<div class="fgroup"><div class="fl">Platform</div><select id="a-plat"><option value="twitch">Twitch</option><option value="youtube">YouTube</option><option value="tiktok">TikTok</option></select></div>
<div class="fgroup"><div class="fl">Niche</div><select id="a-niche"><option value="gaming">Gaming</option><option value="fps">FPS</option><option value="rpg">RPG</option><option value="irl">IRL</option><option value="esports">Esports</option></select></div>
<div class="fgroup"><div class="fl">Virality score</div><input id="a-score" type="number" value="82" min="1" max="100"></div>
</div>
<button class="btn-blue" style="padding:10px 24px" id="a-btn" onclick="runAnalyze()">Run analysis</button>
<div class="prog-wrap"><div class="prog-fill" id="a-prog" style="background:var(--blue)"></div></div>
<div class="status-line" id="a-status">Ready</div>
</div>
<div id="analyze-results"></div>
</div>
<!-- PUBLISH PAGE -->
<div class="page" id="page-publish">
<div class="page-header"><div class="page-title">Phase 04 — Publish</div><div class="page-sub">Generate platform copy, schedule, and dispatch posts</div></div>
<div class="card" style="margin-bottom:1rem">
<div class="section-title">Clip details</div>
<div class="grid2" style="margin-bottom:10px">
<div class="fgroup"><div class="fl">Clip title</div><input id="p-title" placeholder="xQc rage quits Elden Ring DLC"></div>
<div class="fgroup"><div class="fl">Streamer</div><input id="p-streamer" placeholder="xQc"></div>
</div>
<div class="grid3" style="margin-bottom:10px">
<div class="fgroup"><div class="fl">Niche</div><select id="p-niche"><option value="gaming">Gaming</option><option value="fps">FPS</option><option value="rpg">RPG</option><option value="irl">IRL</option><option value="esports">Esports</option></select></div>
<div class="fgroup"><div class="fl">Tone</div><select id="p-tone"><option value="hype">Hype</option><option value="funny">Funny</option><option value="clutch">Clutch</option><option value="wholesome">Wholesome</option><option value="fail">Fail</option></select></div>
<div class="fgroup"><div class="fl">Platforms</div><select id="p-plats"><option value="all">All platforms</option><option value="yt-tk">YouTube + TikTok</option><option value="yt">YouTube only</option><option value="tk">TikTok only</option></select></div>
</div>
<button class="btn-primary" style="padding:10px 24px;background:var(--green);border-color:var(--green)" id="p-btn" onclick="runPublish()">Generate & dispatch</button>
<div class="prog-wrap"><div class="prog-fill" id="p-prog" style="background:var(--green)"></div></div>
<div class="status-line" id="p-status">Ready</div>
</div>
<div id="publish-results"></div>
</div>
<!-- MY RUNS PAGE -->
<div class="page" id="page-my-runs">
<div class="page-header"><div class="page-title">My runs</div><div class="page-sub">Your full pipeline history</div></div>
<div id="my-runs-content"><div class="empty"><svg viewBox="0 0 24 24"><path d="M4 2l16 10L4 22V2z"/></svg>No runs yet — launch your first pipeline.</div></div>
</div>
<!-- DEBUG PAGE -->
<div class="page" id="page-debug">
<div class="page-header" style="display:flex;align-items:center;justify-content:space-between">
<div><div class="page-title">Debug log</div><div class="page-sub">Timestamped system events for your session</div></div>
<button onclick="clearDebug()">Clear log</button>
</div>
<div id="debug-entries"><div class="empty"><svg viewBox="0 0 24 24"><path d="M20 8h-2.81c-.45-.78-1.07-1.45-1.82-1.96L17 4.41 15.59 3l-2.17 2.17C12.96 5.06 12.49 5 12 5c-.49 0-.96.06-1.41.17L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8z"/></svg>No debug events yet.</div></div>
</div>
<!-- ADMIN PAGE -->
<div class="page" id="page-admin">
<div class="page-header" style="display:flex;align-items:center;justify-content:space-between">
<div><div class="page-title">Admin dashboard</div><div class="page-sub">All cohort users, runs, and activity</div></div>
<div style="display:flex;gap:8px"><button onclick="refreshAdmin()">Refresh</button><button class="btn-primary" onclick="exportCSV()">Export CSV</button></div>
</div>
<div class="grid4" id="admin-metrics" style="margin-bottom:1.25rem"></div>
<div class="section-title">Registered users</div>
<div id="admin-users" style="margin-bottom:1.25rem"></div>
<div class="section-title">Activity log</div>
<div class="act-log" id="admin-log"><div style="font-size:12px;color:var(--text-2);padding:8px 0">No activity this session</div></div>
</div>
</main>
</div>
</div>
</div>
<script>
// ── STORAGE (localStorage for GitHub Pages) ──
const LS = {
get: k => { try { const v = localStorage.getItem(k); return v ? JSON.parse(v) : null; } catch(e){ return null; } },
set: (k,v) => { try { localStorage.setItem(k, JSON.stringify(v)); } catch(e){} },
};
const INVITE = 'CLIP2025', ADMIN_CODE = 'ADMIN2025';
let CU = null; // current user
let sessionLog = [];
let debugLog = [];
// ── UTILS ──
const delay = ms => new Promise(r => setTimeout(r, ms));
const fmtN = n => n >= 1e6 ? (n/1e6).toFixed(1)+'M' : n >= 1e3 ? Math.round(n/1e3)+'K' : String(Math.round(n));
const timeAgo = iso => { const d = Date.now()-new Date(iso).getTime(); if(d<60000)return 'just now'; if(d<3600000)return Math.round(d/60000)+'m ago'; if(d<86400000)return Math.round(d/3600000)+'h ago'; return Math.round(d/86400000)+'d ago'; };
const hashP = p => { let h=0; for(let c of p){h=((h<<5)-h)+c.charCodeAt(0);h|=0;} return h.toString(36); };
const ts = () => new Date().toTimeString().substring(0,8);
const getEl = id => document.getElementById(id);
// ── AUTH ──
function switchTab(t) {
getEl('tab-in').className = 'auth-tab'+(t==='in'?' active':'');
getEl('tab-up').className = 'auth-tab'+(t==='up'?' active':'');
getEl('form-in').classList.toggle('hidden', t!=='in');
getEl('form-up').classList.toggle('hidden', t!=='up');
clearMsg();
}
function showMsg(msg, type) {
const el = getEl('auth-msg');
el.textContent = msg; el.className = 'auth-msg '+type; el.style.display = 'block';
}
function clearMsg() { getEl('auth-msg').style.display = 'none'; }
function getUsers() { return LS.get('cm_users') || {}; }
function saveUsers(u) { LS.set('cm_users', u); }
function getRunLog() { return LS.get('cm_runlog') || []; }
function saveRunLog(r) { LS.set('cm_runlog', r.slice(0,300)); }
async function doLogin() {
const email = getEl('li-email').value.trim().toLowerCase();
const pass = getEl('li-pass').value;
if (!email || !pass) { showMsg('Please enter your email and password.', 'err'); return; }
const btn = getEl('li-btn');
btn.disabled = true; btn.textContent = 'Signing in...';
await delay(500);
const users = getUsers();
const user = users[email];
if (!user) { showMsg('No account found. Please create one.', 'err'); btn.disabled=false; btn.textContent='Sign in to ClipMachine'; return; }
if (user.passwordHash !== hashP(pass)) { showMsg('Incorrect password.', 'err'); btn.disabled=false; btn.textContent='Sign in to ClipMachine'; return; }
user.lastLogin = new Date().toISOString();
user.loginCount = (user.loginCount||0)+1;
users[email] = user; saveUsers(users);
logEv(user, 'login', 'Signed in');
enterApp(user);
btn.disabled=false; btn.textContent='Sign in to ClipMachine';
}
async function doSignup() {
const first = getEl('su-first').value.trim();
const last = getEl('su-last').value.trim();
const email = getEl('su-email').value.trim().toLowerCase();
const pass = getEl('su-pass').value;
const invite = getEl('su-invite').value.trim().toUpperCase();
const role = getEl('su-role').value;
if (!first||!last||!email||!pass) { showMsg('Please fill in all fields.', 'err'); return; }
if (pass.length < 6) { showMsg('Password must be at least 6 characters.', 'err'); return; }
if (invite !== INVITE && invite !== ADMIN_CODE) { showMsg('Invalid invite code. Ask your cohort lead.', 'err'); return; }
const btn = getEl('su-btn');
btn.disabled=true; btn.textContent='Creating account...';
await delay(600);
const users = getUsers();
if (users[email]) { showMsg('Email already registered.', 'err'); btn.disabled=false; btn.textContent='Create free account'; return; }
const isAdmin = invite === ADMIN_CODE;
const user = { email, first, last, name: first+' '+last, role, isAdmin, passwordHash: hashP(pass), createdAt: new Date().toISOString(), lastLogin: new Date().toISOString(), loginCount: 1, runs: 0, totalClips: 0, pipelines: [] };
users[email] = user; saveUsers(users);
logEv(user, 'signup', 'Created account'+(isAdmin?' [admin]':''));
showMsg('Account created! Welcome to ClipMachine.', 'ok');
await delay(800);
enterApp(user);
btn.disabled=false; btn.textContent='Create free account';
}
function enterApp(user) {
CU = user;
getEl('screen-auth').className = 'screen';
getEl('screen-main').className = 'screen active';
const initials = (user.first[0]+(user.last?user.last[0]:'')).toUpperCase();
getEl('s-av').textContent = initials;
getEl('s-name').textContent = user.name;
getEl('s-role').textContent = (user.isAdmin?'Admin · ':'')+user.role;
if (user.isAdmin) getEl('admin-nav').classList.remove('hidden');
renderMyRuns(user);
if (user.isAdmin) refreshAdmin();
dbg('Session started', `user=${user.email} role=${user.role} admin=${user.isAdmin}`);
}
function doLogout() {
logEv(CU,'logout','Signed out');
CU = null;
getEl('screen-main').className = 'screen';
getEl('screen-auth').className = 'screen active';
getEl('admin-nav').classList.add('hidden');
document.querySelectorAll('.page').forEach(p => p.className='page');
getEl('page-pipeline').className='page active';
document.querySelectorAll('.nav-item').forEach(n => n.classList.remove('active'));
document.querySelector('.nav-item').classList.add('active');
}
// ── NAVIGATION ──
function showPage(id, btn) {
document.querySelectorAll('.page').forEach(p => p.className='page');
getEl('page-'+id).className = 'page active';
document.querySelectorAll('.nav-item').forEach(n => n.classList.remove('active'));
if (btn) btn.classList.add('active');
if (id==='admin') refreshAdmin();
if (id==='my-runs') renderMyRuns(CU);
if (id==='debug') renderDebug();
}
// ── PIPELINE ──
async function launchPipeline() {
if (!CU) return;
const title = getEl('mc-title').value.trim();
const niche = getEl('mc-niche').value;
const tone = getEl('mc-tone').value;
const count = parseInt(getEl('mc-count').value);
const btn = getEl('launch-btn');
btn.disabled = true; btn.textContent = '⟳ Running...';
const start = Date.now();
resetPhases(); resetAgents();
addLog('ClipMachine pipeline initiated','act');
addLog(`niche=${niche} tone=${tone} clips=${count}`,'sys');
const phaseData = [
{ name:'Collect', agents:[0,1], tasks:['coordinating batch','scraping & scoring'], steps:['Scrape platforms','Filter & dedup','Virality score','Rank clips'] },
{ name:'Transform', agents:[5,6], tasks:['writing captions','art directing'], steps:['Trim & cut','Caption script','Thumbnail concept','Format adapt'] },
{ name:'Analyze', agents:[1,2], tasks:['running competitor gap','mapping SEO keywords'], steps:['SEO keywords','Sentiment score','Competitor gap','View forecast'] },
{ name:'Publish', agents:[3,4,5], tasks:['scheduling posts','dispatching','writing copy'], steps:['Write copy','Smart schedule','Dispatch posts','Log & confirm'] },
];
const phaseResults = [];
for (let i = 0; i < 4; i++) {
const ph = phaseData[i];
setPhase(i,'active');
ph.agents.forEach((a,j) => setAgent(a, ph.tasks[j]||'working', 'active'));
getEl('mc-status').textContent = `Phase 0${i+1} — ${ph.name}...`;
getEl('mc-prog').style.width = (i*20+5)+'%';
for (let s = 0; s < 4; s++) {
getEl(`ps-${i}-${s}`).className = 'ps-dot active';
getEl(`pb-${i}`).style.width = ((s+1)*25)+'%';
addLog(`${ph.name}: ${ph.steps[s]}`,'sys');
await delay(400+Math.random()*300);
getEl(`ps-${i}-${s}`).className = 'ps-dot done';
}
getEl(`pb-${i}`).className = 'phase-bar-fill done';
const ok = Math.random() > 0.05;
phaseResults.push({phase:i+1, name:ph.name, ok, ms: Math.round(Date.now()-start)});
ph.agents.forEach(a => setAgent(a, ph.name+' done', 'done'));
setPhase(i,'done');
addLog(`${ph.name} complete`,'ok');
}
const scoreAvg = Math.round(65+Math.random()*30);
const hotClips = Math.floor(count*0.2+Math.random()*3);
const projViews = Math.round(scoreAvg*count*8500);
const dur = Math.round((Date.now()-start)/1000);
const errors = phaseResults.filter(p=>!p.ok).length;
getEl('mc-prog').style.width = '100%';
getEl('mc-status').textContent = `Pipeline complete — ${count} clips processed, ${hotClips} hot clips found`;
addLog(`Pipeline done: score=${scoreAvg} hot=${hotClips} projected=${fmtN(projViews)} errors=${errors}`,'ok');
const run = { id:'run_'+Date.now(), user:CU.email, userName:CU.name, niche, tone, count, title:title||'auto', scoreAvg, hotClips, projViews, errors, phaseResults, durationSec:dur, timestamp:new Date().toISOString() };
await saveRun(run);
getEl('pipeline-results').innerHTML = `
<div class="card" style="margin:1rem 0">
<div class="section-title">Run result</div>
<div class="grid4" style="margin-bottom:12px">
<div class="metric-card"><div class="metric-label">Clips processed</div><div class="metric-value">${count}</div></div>
<div class="metric-card"><div class="metric-label">Avg virality</div><div class="metric-value">${Math.round(scoreAvg)}</div><div class="metric-sub">${hotClips} hot clips</div></div>
<div class="metric-card"><div class="metric-label">Proj. views (7d)</div><div class="metric-value">${fmtN(projViews)}</div></div>
<div class="metric-card"><div class="metric-label">Errors</div><div class="metric-value" style="color:${errors>0?'var(--red)':'var(--text)'}">${errors}</div><div class="metric-sub" style="color:${errors>0?'var(--red-text)':'var(--green-text)'}">${errors===0?'clean run':errors+' warning'+(errors!==1?'s':'')}</div></div>
</div>
</div>`;
logEv(CU,'run_complete',`score=${scoreAvg} hot=${hotClips} errors=${errors} dur=${dur}s`);
dbg('Pipeline complete',`score=${scoreAvg} hotClips=${hotClips} projViews=${fmtN(projViews)} dur=${dur}s`,'ok');
btn.disabled=false; btn.textContent='▶ Launch again';
}
async function saveRun(run) {
const users = getUsers();
if (users[CU.email]) {
users[CU.email].runs = (users[CU.email].runs||0)+1;
users[CU.email].totalClips = (users[CU.email].totalClips||0)+run.count;
users[CU.email].pipelines = ([run,...(users[CU.email].pipelines||[])]).slice(0,30);
CU = users[CU.email];
saveUsers(users);
}
const log = getRunLog();
saveRunLog([run,...log]);
}
// ── PHASE / AGENT HELPERS ──
function resetPhases() { for(let i=0;i<4;i++){setPhase(i,'idle');getEl(`pb-${i}`).style.width='0%';getEl(`pb-${i}`).className='phase-bar-fill';for(let s=0;s<4;s++)getEl(`ps-${i}-${s}`).className='ps-dot';} }
function resetAgents() { for(let i=0;i<8;i++) setAgent(i,'standing by','idle'); }
function setPhase(i, state) {
const pc=getEl(`pc-${i}`); const pn=getEl(`pn-${i}`);
pc.className='phase-card'+(state==='active'?' active':state==='done'?' done':'');
pn.className='phase-num'+(state==='active'?' active':state==='done'?' done':'');
if(state==='done') pn.textContent='✓';
}
function setAgent(i, task, state) {
const chip=getEl(`ag-${i}`); const led=getEl(`al-${i}`); const t=getEl(`at-${i}`);
chip.className='agent-chip'+(state==='active'?' active':state==='done'?' done':'');
led.className='agent-led'+(state==='active'?' on':state==='done'?' done':'');
t.textContent=task;
}
// ── LOG ──
function addLog(msg, type='sys') {
const el=getEl('main-log');
const div=document.createElement('div'); div.className='log-line';
div.innerHTML=`<span class="log-ts">${ts()}</span><span class="log-${type}">${msg}</span>`;
el.appendChild(div); el.scrollTop=el.scrollHeight;
}
// ── COLLECT PAGE ──
async function runCollect() {
const niche=getEl('c-niche').value, limit=parseInt(getEl('c-limit').value);
const btn=getEl('c-btn'); btn.disabled=true; btn.textContent='Running...';
const prog=getEl('c-prog'); const status=getEl('c-status');
status.textContent='Connecting to platform APIs...'; prog.style.width='10%'; await delay(600);
status.textContent=`Scanning ${limit*8} raw clips...`; prog.style.width='30%'; await delay(700);
status.textContent='Applying engagement filters...'; prog.style.width='55%'; await delay(500);
status.textContent='Running virality model...'; prog.style.width='75%'; await delay(600);
status.textContent='Ranking results...'; prog.style.width='95%'; await delay(400);
prog.style.width='100%'; status.textContent=`Done — ${limit} clips collected`;
const clips = genClips(niche, limit);
dbg('Collect run',`niche=${niche} limit=${limit} clips=${clips.length}`,'ok');
getEl('collect-results').innerHTML = renderClipsTable(clips);
btn.disabled=false; btn.textContent='Run ingestion';
}
function genClips(niche, count) {
const streamers=['xQc','Shroud','Pokimane','Valkyrae','Kai Cenat','Ludwig','Ninja','HasanAbi','Sykkuno','Disguised Toast','TimTheTatman','DrLupo'];
const plats=['twitch','youtube','tiktok'];
return Array.from({length:count},(_,i)=>({
rank:i+1, streamer:streamers[i%streamers.length],
title:`${streamers[i%streamers.length]} insane ${niche} moment — chat explodes`,
platform:plats[i%3], views:Math.round(80000+Math.random()*2500000),
score:Math.round(52+Math.random()*45), status:'collected'
}));
}
function renderClipsTable(clips) {
const platBadge = p => p==='tiktok'?'badge-purple':p==='youtube'?'badge-red':'badge-blue';
const scoreColor = s => s>=90?'var(--red)':s>=75?'var(--amber)':'var(--text-2)';
return `<div class="clips-table">
<div class="ct-head"><div>#</div><div>Clip</div><div>Platform</div><div>Score</div><div>Views</div><div>Status</div></div>
${clips.slice(0,20).map(c=>`<div class="ct-row">
<div class="ct-rank ${c.rank<=3?'top':''}">${c.rank}</div>
<div><div class="ct-title">${c.title}</div><div class="ct-meta">${c.streamer}</div></div>
<div><span class="badge ${platBadge(c.platform)}">${c.platform}</span></div>
<div style="font-weight:700;color:${scoreColor(c.score)}">${c.score}</div>
<div style="font-size:12px;color:var(--text-2)">${fmtN(c.views)}</div>
<div><span class="badge badge-green">collected</span></div>
</div>`).join('')}
</div>`;
}
// ── TRANSFORM PAGE ──
async function runTransform() {
const title=getEl('t-title').value||'Epic streamer moment';
const streamer=getEl('t-streamer').value||'StreamerX';
const dur=parseInt(getEl('t-dur').value)||90;
const tone=getEl('t-tone').value;
const btn=getEl('t-btn'); btn.disabled=true; btn.textContent='Transforming...';
const prog=getEl('t-prog'); const status=getEl('t-status');
const steps=['Generating trim plan...','Writing caption script...','Building thumbnail concept...','Adapting formats...'];
for(let i=0;i<steps.length;i++){status.textContent=steps[i];prog.style.width=((i+1)*25)+'%';await delay(550+Math.random()*300);}
prog.style.width='100%'; status.textContent='Transform complete';
const start=Math.round(dur*.05), end=Math.round(dur*.88);
const captions=[`When ${streamer} thought it was over...`,`Nobody expected this moment`,`Chat goes absolutely insane`,`The reaction says everything`,`That's why we watch live`];
dbg('Transform run',`title="${title.substring(0,40)}" dur=${dur}s tone=${tone}`,'ok');
getEl('transform-results').innerHTML=`
<div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-top:1rem">
<div class="card"><div class="section-title">Trim & cut plan</div>
<div class="card-sm" style="margin-bottom:8px">
<div style="font-size:11px;color:var(--text-2)">Keep: <strong>${start}s – ${end}s</strong> (${end-start}s final)</div>
<div style="height:5px;background:var(--bg-3);border-radius:3px;margin:6px 0;overflow:hidden"><div style="height:100%;width:${Math.round((end-start)/dur*100)}%;background:var(--green);border-radius:3px;margin-left:${Math.round(start/dur*100)}%"></div></div>
<div style="font-size:11px;color:var(--text-2)">Hook at: <strong>${Math.round(dur*.12)}s</strong> · Pacing: ${tone==='hype'?'fast':'medium'}</div>
</div>
<div style="font-size:12px;color:var(--text-2)">Cuts: hard cut at peak reaction → jump cut at chat explosion → push in on best moment</div>
</div>
<div class="card"><div class="section-title">Caption script</div>
${captions.map((c,i)=>`<div class="card-sm" style="margin-bottom:5px"><div style="font-size:10px;color:var(--text-3)">${i*5}s–${i*5+5}s</div><div style="font-size:12px;font-family:var(--mono)">${c}</div></div>`).join('')}
</div>
<div class="card"><div class="section-title">Thumbnail concept</div>
<div style="background:#111;border-radius:8px;aspect-ratio:16/9;display:flex;align-items:center;justify-content:center;margin-bottom:8px;position:relative">
<div style="position:absolute;top:8px;right:8px;background:var(--red);color:white;font-size:10px;font-weight:700;padding:2px 8px;border-radius:4px">INSANE</div>
<div style="color:#eee;font-size:13px;font-weight:700;text-align:center;padding:12px">HE ACTUALLY DID IT</div>
</div>
<div style="font-size:11px;color:var(--text-2)">Style: reaction face · High contrast · Bold white text · Red accent</div>
</div>
<div class="card"><div class="section-title">Format outputs</div>
<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:6px">
${[['16:9','YouTube / Twitch','1920×1080'],['9:16','TikTok / Shorts','1080×1920'],['1:1','Instagram / X','1080×1080']].map(([r,p,d])=>`<div class="card-sm" style="text-align:center"><div style="font-size:12px;font-weight:700">${r}</div><div style="font-size:10px;color:var(--text-2)">${p}</div><div style="font-size:10px;color:var(--text-3)">${d}</div></div>`).join('')}
</div>
</div>
</div>`;
btn.disabled=false; btn.textContent='Transform clip';
}
// ── ANALYZE PAGE ──
async function runAnalyze() {
const title=getEl('a-title').value||'Epic streamer moment';
const streamer=getEl('a-streamer').value||'StreamerX';
const niche=getEl('a-niche').value;
const score=parseInt(getEl('a-score').value)||80;
const btn=getEl('a-btn'); btn.disabled=true; btn.textContent='Analyzing...';
const prog=getEl('a-prog'); const status=getEl('a-status');
const steps=['Running SEO keyword extraction...','Scoring sentiment...','Scanning competitor landscape...','Building virality forecast...'];
for(let i=0;i<steps.length;i++){status.textContent=steps[i];prog.style.width=((i+1)*25)+'%';await delay(600+Math.random()*300);}
prog.style.width='100%'; status.textContent='Analysis complete';
const opp=Math.round(65+Math.random()*30), seo=Math.round(35+Math.random()*40), share=Math.round(70+Math.random()*28);
const kws=[`${streamer} ${niche}`,`${streamer} clip`,`best ${niche} clips`,`${niche} highlights`,`${streamer} moments`,`viral ${niche}`];
dbg('Analyze run',`title="${title.substring(0,40)}" score=${score} opp=${opp}`,'ok');
getEl('analyze-results').innerHTML=`
<div class="grid4" style="margin:1rem 0">
<div class="metric-card"><div class="metric-label">Overall score</div><div class="metric-value">${score}</div><div class="metric-sub">${score>=80?'publish-ready':'needs polish'}</div></div>
<div class="metric-card"><div class="metric-label">SEO opportunity</div><div class="metric-value">${opp}</div><div class="metric-sub">out of 100</div></div>
<div class="metric-card"><div class="metric-label">Shareability</div><div class="metric-value">${share}</div><div class="metric-sub">high chat energy</div></div>
<div class="metric-card"><div class="metric-label">7-day forecast</div><div class="metric-value">${fmtN(score*8200)}</div><div class="metric-sub">projected views</div></div>
</div>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:12px">
<div class="card"><div class="section-title">Keyword map</div>
${kws.map((k,i)=>`<div style="display:flex;align-items:center;gap:8px;padding:5px 0;border-bottom:1px solid var(--border);font-size:12px"><span style="flex:1;font-weight:600">${k}</span><div style="width:60px;height:4px;background:var(--bg-3);border-radius:2px;overflow:hidden"><div style="height:100%;width:${100-i*14}%;background:var(--blue);border-radius:2px"></div></div><span style="color:var(--text-2);min-width:40px;text-align:right">${Math.round(48000-i*6000)}/mo</span><span class="badge ${i<2?'badge-green':'badge-amber'}">${i<2?'high':'med'}</span></div>`).join('')}
</div>
<div class="card"><div class="section-title">Platform fit</div>
${[['YouTube',88,'publish'],['TikTok',84,'publish'],['Twitter/X',62,'hold'],['Instagram',75,'publish'],['Twitch',90,'publish']].map(([p,s,r])=>`<div style="display:flex;align-items:center;gap:10px;padding:7px 0;border-bottom:1px solid var(--border)"><span style="flex:1;font-size:13px;font-weight:600">${p}</span><div style="width:80px;height:4px;background:var(--bg-3);border-radius:2px;overflow:hidden"><div style="height:100%;width:${s}%;background:${r==='publish'?'var(--green)':'var(--amber)'};border-radius:2px"></div></div><span style="font-size:12px;font-weight:700">${s}</span><span class="badge ${r==='publish'?'badge-green':'badge-amber'}">${r}</span></div>`).join('')}
<div style="margin-top:10px;font-size:11px;color:var(--text-2);background:var(--bg-2);border-radius:var(--radius);padding:8px">Publish order: YouTube → TikTok → Instagram → Twitch for max cross-platform amplification</div>
</div>
</div>`;
btn.disabled=false; btn.textContent='Run analysis';
}
// ── PUBLISH PAGE ──
async function runPublish() {
const title=getEl('p-title').value||'Epic streamer moment';
const streamer=getEl('p-streamer').value||'StreamerX';
const niche=getEl('p-niche').value, tone=getEl('p-tone').value;
const btn=getEl('p-btn'); btn.disabled=true; btn.textContent='Generating...';
const prog=getEl('p-prog'); const status=getEl('p-status');
const steps=['Briefing Copywriter agent...','Writing platform copy...','Optimizing hashtags...','Scheduling & dispatching...'];
for(let i=0;i<steps.length;i++){status.textContent=steps[i];prog.style.width=((i+1)*25)+'%';await delay(600+Math.random()*400);}
const plats=['YouTube','TikTok','Twitter/X','Instagram','Twitch'];
const platResults=[];
for(const p of plats){await delay(350);const ok=Math.random()>.08;platResults.push({name:p,ok});}
prog.style.width='100%';
const live=platResults.filter(p=>p.ok).length;
status.textContent=`Published — ${live}/${plats.length} platforms live`;
dbg('Publish run',`title="${title.substring(0,40)}" live=${live}/${plats.length}`,'ok');
getEl('publish-results').innerHTML=`
<div class="card" style="margin-top:1rem">
<div class="section-title" style="margin-bottom:.75rem">Universal hook</div>
<div style="font-size:14px;font-weight:600;padding:10px 14px;background:var(--bg-2);border-radius:var(--radius);margin-bottom:1rem">"You won't believe what ${streamer} just did — this changed everything in ${niche}"</div>
<div class="section-title">Platform dispatch</div>
<div style="display:grid;grid-template-columns:repeat(5,1fr);gap:8px;margin-bottom:1rem">
${platResults.map(p=>`<div class="card-sm" style="text-align:center;border:1px solid ${p.ok?'var(--green)':'var(--red)'}20"><div style="font-size:11px;font-weight:700">${p.name}</div><div class="badge ${p.ok?'badge-green':'badge-red'}" style="margin-top:5px">${p.ok?'live':'failed'}</div></div>`).join('')}
</div>
<div class="section-title">Generated copy — YouTube</div>
<div class="card-sm" style="margin-bottom:6px"><div class="section-title">Title</div><div style="font-size:13px;font-weight:600">${streamer} Did WHAT?! (${niche.toUpperCase()} Clip)</div></div>
<div class="card-sm" style="margin-bottom:6px"><div class="section-title">Description</div><div style="font-size:12px;color:var(--text-2)">Watch ${streamer} experience one of the most incredible moments in ${niche} streaming. Subscribe for daily ${niche} highlights and clips.</div></div>
<div class="card-sm"><div class="section-title">Hashtags</div><div style="display:flex;gap:4px;flex-wrap:wrap">${['#viral','#'+niche,'#'+streamer,'#clips','#highlights','#gaming','#streamer'].map(h=>`<span class="tag tag-blue">${h}</span>`).join('')}</div></div>
</div>`;
btn.disabled=false; btn.textContent='Generate & dispatch';
}
// ── MY RUNS ──
function renderMyRuns(user) {
const runs = (user?.pipelines||[]);
if(!runs.length){getEl('my-runs-content').innerHTML='<div class="empty"><svg viewBox="0 0 24 24"><path d="M4 2l16 10L4 22V2z"/></svg>No runs yet — launch your first pipeline.</div>';return;}
getEl('my-runs-content').innerHTML=`<div style="font-size:12px;color:var(--text-2);margin-bottom:10px">${runs.length} run${runs.length!==1?'s':''} total</div>`+
runs.map(r=>`<div class="run-card">
<div class="run-header"><div class="run-title">${r.niche} / ${r.tone} — ${r.count} clips</div><div class="run-time">${timeAgo(r.timestamp)}</div></div>
<div class="run-stats">
<span class="run-stat good">Score: ${Math.round(r.scoreAvg)}</span>
<span class="run-stat">${Math.round(r.hotClips)} hot clips</span>
<span class="run-stat">${fmtN(r.projViews)} proj. views</span>
<span class="run-stat ${r.errors>0?'warn':'good'}">${r.errors===0?'Clean':''+r.errors+' warn'}</span>
<span class="run-stat">${r.durationSec}s</span>
</div>
<div class="phase-row">
${(r.phaseResults||[]).map(p=>`<div class="phase-dot ${p.ok?'done':'warn'}"></div>`).join('')}
${Array(4-(r.phaseResults||[]).length).fill('<div class="phase-dot"></div>').join('')}
</div>
</div>`).join('');
}
// ── DEBUG ──
function dbg(label, detail, type='info') {
debugLog.unshift({label, detail, type, time:new Date().toISOString()});
}
function renderDebug() {
if(!debugLog.length){getEl('debug-entries').innerHTML='<div class="empty"><svg viewBox="0 0 24 24"><path d="M20 8h-2.81c-.45-.78-1.07-1.45-1.82-1.96L17 4.41 15.59 3l-2.17 2.17C12.96 5.06 12.49 5 12 5c-.49 0-.96.06-1.41.17L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8z"/></svg>No debug events yet.</div>';return;}
const colors={ok:'var(--green-text)',warn:'var(--amber-text)',err:'var(--red-text)',info:'var(--text-2)'};
getEl('debug-entries').innerHTML=debugLog.map(e=>`<div class="debug-entry"><strong>${e.label}</strong> <span style="color:var(--text-3);font-size:10px">${new Date(e.time).toTimeString().substring(0,8)}</span><br><span style="color:${colors[e.type]||colors.info}">${e.detail}</span></div>`).join('');
}
function clearDebug(){debugLog=[];renderDebug();}
// ── ADMIN ──
function logEv(user, type, detail) {
sessionLog.unshift({user:user?.name||'?',email:user?.email||'?',type,detail,time:new Date().toISOString()});
if(sessionLog.length>100) sessionLog=sessionLog.slice(0,100);
}
function refreshAdmin() {
if(!CU?.isAdmin) return;
const users = Object.values(getUsers());
const runs = getRunLog();
const totalRuns = users.reduce((a,u)=>a+(u.runs||0),0);
const totalClips = users.reduce((a,u)=>a+(u.totalClips||0),0);
const activeToday = users.filter(u=>u.lastLogin&&(Date.now()-new Date(u.lastLogin).getTime())<86400000).length;
getEl('admin-metrics').innerHTML=`
<div class="metric-card"><div class="metric-label">Total users</div><div class="metric-value">${users.length}</div></div>
<div class="metric-card"><div class="metric-label">Active today</div><div class="metric-value">${activeToday}</div></div>
<div class="metric-card"><div class="metric-label">Total runs</div><div class="metric-value">${totalRuns}</div></div>
<div class="metric-card"><div class="metric-label">Clips processed</div><div class="metric-value">${fmtN(totalClips)}</div></div>`;
getEl('admin-users').innerHTML=`<div class="user-table">
<div class="ut-head"><div>User</div><div>Joined</div><div>Last login</div><div>Runs</div><div>Status</div></div>
${users.length===0?'<div style="padding:2rem;text-align:center;font-size:12px;color:var(--text-2)">No users yet</div>':
users.sort((a,b)=>new Date(b.createdAt)-new Date(a.createdAt)).map(u=>`<div class="ut-row">
<div><div class="ut-name">${u.name}</div><div class="ut-email">${u.email} · ${u.role}</div></div>
<div class="ut-cell">${u.createdAt?new Date(u.createdAt).toLocaleDateString():'—'}</div>
<div class="ut-cell">${u.lastLogin?timeAgo(u.lastLogin):'—'}</div>
<div class="ut-cell">${u.runs||0}</div>
<div><span class="badge ${u.isAdmin?'badge-red':(u.runs||0)>0?'badge-green':'badge-blue'}">${u.isAdmin?'admin':(u.runs||0)>0?'active':'new'}</span></div>
</div>`).join('')}
</div>`;
const dotColors={login:'var(--green)',signup:'var(--blue)',logout:'var(--text-3)',run_start:'var(--amber)',run_complete:'var(--green)'};
getEl('admin-log').innerHTML=sessionLog.length===0?'<div style="font-size:12px;color:var(--text-2);padding:8px 0">No activity this session</div>':
sessionLog.slice(0,20).map(e=>`<div class="al-entry"><div class="al-dot" style="background:${dotColors[e.type]||'var(--text-3)'}"></div><span class="al-user">${e.user.split(' ')[0]}</span><span class="al-action">${e.detail}</span><span class="al-time">${new Date(e.time).toTimeString().substring(0,5)}</span></div>`).join('');
}
function exportCSV() {
const users = Object.values(getUsers());
const rows = [['Name','Email','Role','Admin','Runs','Clips','Created','Last Login']];
users.forEach(u=>rows.push([u.name,u.email,u.role,u.isAdmin?'yes':'no',u.runs||0,u.totalClips||0,u.createdAt,u.lastLogin]));
const csv = 'data:text/csv;charset=utf-8,'+rows.map(r=>r.join(',')).join('\n');
const a = document.createElement('a'); a.href=encodeURI(csv); a.download='clipmachine_cohort_'+new Date().toISOString().slice(0,10)+'.csv'; a.click();
dbg('Admin export','CSV downloaded','ok');
}
</script>
</body>
</html>