-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.html
More file actions
1612 lines (1475 loc) · 73.2 KB
/
Copy pathcode.html
File metadata and controls
1612 lines (1475 loc) · 73.2 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" data-theme="light">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>CodeRouter AI</title>
<script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
<link href="https://fonts.googleapis.com" rel="preconnect"/>
<link crossorigin="" href="https://fonts.gstatic.com" rel="preconnect"/>
<link href="https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400..800;1,400..800&family=Manrope:wght@200..800&display=swap" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&display=swap" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css" id="prismTheme"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-javascript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-typescript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-bash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-json.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-go.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-rust.min.js"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: "#c2652a",
"on-primary": "#ffffff",
"primary-container": "#fbe8d8",
"on-primary-container": "#401a08",
"primary-fixed": "#fbe8d8",
"primary-fixed-dim": "#f0a878",
"on-primary-fixed": "#401a08",
"on-primary-fixed-variant": "#8a4518",
"inverse-primary": "#f0a878",
"surface-tint": "#c2652a",
background: "var(--color-bg)",
"on-background": "var(--color-on-bg)",
surface: "var(--color-surface)",
"surface-dim": "var(--color-surface-dim)",
"surface-bright": "var(--color-surface-bright)",
"surface-container-lowest": "var(--color-surface-lowest)",
"surface-container-low": "var(--color-surface-low)",
"surface-container": "var(--color-surface-container)",
"surface-container-high": "var(--color-surface-high)",
"surface-container-highest": "var(--color-surface-highest)",
"on-surface": "var(--color-on-surface)",
"on-surface-variant": "var(--color-on-surface-variant)",
"surface-variant": "var(--color-surface-variant)",
outline: "var(--color-outline)",
"outline-variant": "var(--color-outline-variant)",
secondary: "var(--color-secondary)",
"on-secondary": "#ffffff",
"secondary-container": "var(--color-secondary-container)",
"on-secondary-container": "var(--color-on-secondary-container)",
"secondary-fixed": "var(--color-secondary-fixed)",
"secondary-fixed-dim": "var(--color-secondary-dim)",
"on-secondary-fixed": "var(--color-on-secondary-fixed)",
"on-secondary-fixed-variant": "var(--color-on-secondary-variant)",
error: "var(--color-error)",
"on-error": "#ffffff",
"error-container": "var(--color-error-container)",
"on-error-container": "var(--color-on-error-container)",
tertiary: "#8c3c3c",
"on-tertiary": "#ffffff",
"tertiary-container": "#d47070",
"on-tertiary-container": "#3a2020"
},
fontFamily: {
headline: ["EB Garamond", "serif"],
display: ["EB Garamond", "serif"],
body: ["Manrope", "sans-serif"],
label: ["Manrope", "sans-serif"],
mono: ["ui-monospace", "SFMono-Regular", "Menlo", "Monaco", "Consolas", "Liberation Mono", "Courier New", "monospace"]
},
borderRadius: {
DEFAULT: "0.25rem",
lg: "0.5rem",
xl: "0.75rem",
"2xl": "1rem",
full: "9999px"
}
}
}
}
</script>
<style>
:root {
--color-bg: #faf5ee;
--color-on-bg: #3a302a;
--color-surface: #faf5ee;
--color-surface-dim: #dcd6cc;
--color-surface-bright: #faf5ee;
--color-surface-lowest: #ffffff;
--color-surface-low: #f6f0e8;
--color-surface-container: #f2ece4;
--color-surface-high: #ece6dc;
--color-surface-highest: #e6e0d6;
--color-on-surface: #3a302a;
--color-on-surface-variant: #605850;
--color-surface-variant: #ece6dc;
--color-outline: #9a9088;
--color-outline-variant: #d8d0c8;
--color-secondary: #78706a;
--color-secondary-container: #eae2da;
--color-on-secondary-container: #605850;
--color-secondary-fixed: #eae2da;
--color-secondary-dim: #cec6be;
--color-on-secondary-fixed: #2a2420;
--color-on-secondary-variant: #504840;
--color-error: #c0392b;
--color-error-container: #fce4e0;
--color-on-error-container: #7a1a10;
--color-scrollbar: #d8d0c8;
--color-scrollbar-hover: #9a9088;
--elevation-soft: 0 2px 16px rgba(58, 48, 42, 0.04);
--elevation-medium: 0 4px 24px rgba(58, 48, 42, 0.06);
--elevation-high: 0 8px 40px rgba(58, 48, 42, 0.1);
--overlay-bg: rgba(58, 48, 42, 0.2);
--code-bg: #f6f0e8;
--code-border: #d8d0c8;
--code-inline-bg: #ece6dc;
--bubble-assistant-bg: #ffffff;
--auth-glow-1: #fbe8d8;
--auth-glow-2: #eae2da;
--suggestion-bg: #ffffff;
--suggestion-hover: #f6f0e8;
--input-border: #d8d0c8;
--input-focus-ring: rgba(194, 101, 42, 0.1);
}
html.dark {
--color-bg: #171210;
--color-on-bg: #e8e0d8;
--color-surface: #1f1a17;
--color-surface-dim: #171210;
--color-surface-bright: #2d2723;
--color-surface-lowest: #14100e;
--color-surface-low: #1f1a17;
--color-surface-container: #25201d;
--color-surface-high: #2d2723;
--color-surface-highest: #38312d;
--color-on-surface: #e8e0d8;
--color-on-surface-variant: #b0a69c;
--color-surface-variant: #38312d;
--color-outline: #7a7268;
--color-outline-variant: #4a443e;
--color-secondary: #b0a69c;
--color-secondary-container: #38312d;
--color-on-secondary-container: #ccc2b8;
--color-secondary-fixed: #5a524a;
--color-secondary-dim: #4a443e;
--color-on-secondary-fixed: #e8e0d8;
--color-on-secondary-variant: #8a8278;
--color-error: #ff8a80;
--color-error-container: #5a1a10;
--color-on-error-container: #ffdad6;
--color-scrollbar: #4a443e;
--color-scrollbar-hover: #7a7268;
--elevation-soft: 0 2px 16px rgba(0, 0, 0, 0.2);
--elevation-medium: 0 4px 24px rgba(0, 0, 0, 0.3);
--elevation-high: 0 8px 40px rgba(0, 0, 0, 0.4);
--overlay-bg: rgba(0, 0, 0, 0.5);
--code-bg: #1f1a17;
--code-border: #38312d;
--code-inline-bg: #38312d;
--bubble-assistant-bg: #25201d;
--auth-glow-1: rgba(194, 101, 42, 0.15);
--auth-glow-2: rgba(120, 112, 106, 0.15);
--suggestion-bg: #25201d;
--suggestion-hover: #2d2723;
--input-border: #4a443e;
--input-focus-ring: rgba(194, 101, 42, 0.2);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
font-size: 16px;
transition: background-color 0.5s ease;
}
html.dark { color-scheme: dark; }
body {
font-family: 'Manrope', sans-serif;
background-color: var(--color-bg);
color: var(--color-on-bg);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
transition: background-color 0.5s ease, color 0.5s ease;
}
*, *::before, *::after {
transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease, opacity 0.4s ease, transform 0.4s ease;
}
h1, h2, h3, h4, h5, h6, .font-headline { font-family: 'EB Garamond', serif; }
.material-symbols-outlined {
font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-scrollbar); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-scrollbar-hover); }
.elevation-soft { box-shadow: var(--elevation-soft); }
.elevation-medium { box-shadow: var(--elevation-medium); }
.elevation-high { box-shadow: var(--elevation-high); }
.hairline { border: 1px solid var(--color-outline-variant); }
.hairline-b { border-bottom: 1px solid var(--color-outline-variant); }
.hairline-t { border-top: 1px solid var(--color-outline-variant); }
.hairline-r { border-right: 1px solid var(--color-outline-variant); }
.slide-up { animation: slideUp 0.35s ease forwards; }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.typing-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--color-on-surface-variant); animation: pulse 1.4s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 60%, 100% { opacity: 0.2; transform: scale(0.8); } 30% { opacity: 1; transform: scale(1); } }
.page { display: none; }
.page.active { display: flex; }
.auth-glow-1, .auth-glow-2 {
position: absolute; border-radius: 50%; filter: blur(120px);
pointer-events: none; opacity: 0.5;
transition: background-color 0.5s ease;
}
.auth-glow-1 {
top: 0; right: 0; width: 500px; height: 500px;
background: var(--auth-glow-1);
transform: translate(30%, -30%);
}
.auth-glow-2 {
bottom: 0; left: 0; width: 600px; height: 600px;
background: var(--auth-glow-2);
transform: translate(-30%, 30%);
filter: blur(150px);
}
.tab-active { color: #c2652a; }
.tab-active::after {
content: ''; position: absolute; bottom: -17px; left: 0; right: 0;
height: 2px; background: #c2652a; border-radius: 1px;
}
.tab-inactive { color: var(--color-on-surface-variant); cursor: pointer; transition: color 0.3s; }
.tab-inactive:hover { color: var(--color-on-surface); }
input.auth-input {
width: 100%; background: var(--color-surface-lowest); border: 1px solid var(--color-outline-variant);
color: var(--color-on-surface); font-size: 0.875rem; border-radius: 0.5rem;
padding: 0.75rem; transition: border-color 0.2s, box-shadow 0.2s, background-color 0.4s, color 0.4s;
outline: none; font-family: 'Manrope', sans-serif;
}
input.auth-input:focus {
border-color: #c2652a; box-shadow: 0 0 0 3px var(--input-focus-ring);
}
.msg-bubble { animation: msgIn 0.3s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.msg-user .bubble { background: #c2652a; color: #fff; border-bottom-right-radius: 3px; }
.msg-assistant .bubble { background: var(--bubble-assistant-bg); border: 1px solid var(--color-outline-variant); border-bottom-left-radius: 3px; }
.msg .bubble pre {
background: var(--code-bg); border: 1px solid var(--code-border);
border-radius: 6px; padding: 0; margin: 8px 0; overflow-x: auto;
}
.msg .bubble pre code {
background: none; padding: 12px; border: none; display: block;
font-family: 'ui-monospace', 'SFMono-Regular', monospace;
font-size: 0.8125rem; line-height: 1.6;
}
.msg .bubble :not(pre) > code {
background: var(--code-inline-bg); padding: 1px 6px; border-radius: 4px;
font-size: 0.8125rem; color: var(--color-on-surface);
}
@media (max-width: 768px) {
.sidebar { display: none; }
.chat-feed { padding: 16px !important; }
}
.btn-primary {
background: #c2652a; color: #fff; font-family: 'Manrope', sans-serif;
font-weight: 500; border-radius: 0.5rem; padding: 0.75rem 1.5rem;
border: none; cursor: pointer; transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}
.btn-primary:hover { background: #a85522; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-outline {
background: transparent; color: var(--color-on-surface); font-family: 'Manrope', sans-serif;
font-weight: 500; border-radius: 0.5rem; padding: 0.625rem 1.25rem;
border: 1px solid var(--color-outline-variant); cursor: pointer;
transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.btn-outline:hover { background: var(--color-surface-low); border-color: var(--color-outline); }
.suggestion-btn {
text-align: left; padding: 1rem 1.25rem; border: 1px solid var(--color-outline-variant);
background: var(--suggestion-bg); border-radius: 0.5rem; cursor: pointer;
transition: background 0.2s, border-color 0.2s;
font-family: 'Manrope', sans-serif;
}
.suggestion-btn:hover { background: var(--suggestion-hover); border-color: #c2652a; }
.input-area textarea {
width: 100%; background: transparent; border: none; resize: none;
color: var(--color-on-surface); font-family: 'Manrope', sans-serif;
font-size: 0.875rem; line-height: 1.5; padding: 12px 4px;
min-height: 48px; max-height: 160px; outline: none;
}
.panel-overlay {
position: fixed; inset: 0; z-index: 60;
background: var(--overlay-bg); backdrop-filter: blur(4px);
opacity: 0; pointer-events: none;
transition: opacity 0.35s ease;
}
.panel-overlay.open { opacity: 1; pointer-events: auto; }
.panel-drawer {
position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 100vw;
z-index: 70; background: var(--color-surface);
border-left: 1px solid var(--color-outline-variant);
transform: translateX(100%); transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.4s ease;
box-shadow: var(--elevation-high);
display: flex; flex-direction: column;
}
.panel-drawer.open { transform: translateX(0); }
.panel-header {
padding: 1.5rem 1.75rem; border-bottom: 1px solid var(--color-outline-variant);
display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.panel-header h2 {
font-family: 'EB Garamond', serif; font-size: 1.5rem; font-weight: 700;
color: var(--color-on-surface);
}
.panel-close {
width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
border-radius: 0.5rem; border: none; background: transparent;
color: var(--color-on-surface-variant); cursor: pointer;
transition: background 0.2s, color 0.2s;
}
.panel-close:hover { background: var(--color-surface-variant); color: var(--color-on-surface); }
.panel-body { flex: 1; overflow-y: auto; padding: 1.5rem 1.75rem; }
.session-item, .prompt-item {
padding: 1rem 1.25rem; border-radius: 0.5rem;
border: 1px solid var(--color-outline-variant);
background: var(--color-surface-low);
cursor: pointer; transition: background 0.2s, border-color 0.2s;
margin-bottom: 0.75rem;
}
.session-item:hover, .prompt-item:hover {
background: var(--color-surface-variant); border-color: var(--color-outline);
}
.session-item .title, .prompt-item .title {
font-weight: 600; color: var(--color-on-surface); font-size: 0.9rem; margin-bottom: 0.25rem;
}
.session-item .preview, .prompt-item .preview {
font-size: 0.8rem; color: var(--color-on-surface-variant);
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.session-item .meta {
display: flex; justify-content: space-between; align-items: center;
margin-top: 0.5rem; font-size: 0.75rem; color: var(--color-on-surface-variant);
}
.delete-btn {
background: none; border: none; color: var(--color-error);
cursor: pointer; font-size: 0.75rem; padding: 2px 8px;
border-radius: 4px; transition: background 0.2s;
}
.delete-btn:hover { background: var(--color-error-container); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.stat-card {
padding: 1rem; border-radius: 0.5rem;
border: 1px solid var(--color-outline-variant);
background: var(--color-surface-low);
}
.stat-card .label { font-size: 0.75rem; color: var(--color-on-surface-variant); margin-bottom: 0.25rem; }
.stat-card .value { font-family: 'EB Garamond', serif; font-size: 1.5rem; font-weight: 700; color: var(--color-on-surface); }
.stat-card.full { grid-column: 1 / -1; }
.bar-chart { display: flex; gap: 0.5rem; align-items: flex-end; height: 120px; padding-top: 0.5rem; }
.bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }
.bar-item .bar {
width: 100%; border-radius: 3px 3px 0 0;
background: #c2652a; min-height: 4px;
transition: height 0.6s ease;
}
.bar-item .bar.secondary { background: var(--color-secondary); }
.bar-item .label { font-size: 0.65rem; color: var(--color-on-surface-variant); }
.help-section { margin-bottom: 1.5rem; }
.help-section h3 {
font-family: 'EB Garamond', serif; font-size: 1.2rem; font-weight: 600;
color: var(--color-on-surface); margin-bottom: 0.75rem;
}
.help-section p, .help-section li {
font-size: 0.85rem; color: var(--color-on-surface-variant); line-height: 1.6;
}
.help-section ul { padding-left: 1.25rem; }
.help-section kbd {
background: var(--color-surface-variant); padding: 2px 8px;
border-radius: 4px; font-size: 0.75rem; font-family: 'Manrope', sans-serif;
border: 1px solid var(--color-outline-variant); color: var(--color-on-surface);
}
.setting-row {
display: flex; align-items: center; justify-content: space-between;
padding: 1rem 0; border-bottom: 1px solid var(--color-outline-variant);
}
.setting-row:last-child { border-bottom: none; }
.setting-row .info { flex: 1; }
.setting-row .info .name { font-weight: 500; color: var(--color-on-surface); font-size: 0.9rem; }
.setting-row .info .desc { font-size: 0.8rem; color: var(--color-on-surface-variant); margin-top: 0.15rem; }
.toggle-switch {
width: 44px; height: 24px; border-radius: 12px; background: var(--color-outline);
cursor: pointer; position: relative; transition: background 0.3s; flex-shrink: 0;
}
.toggle-switch.active { background: #c2652a; }
.toggle-switch::after {
content: ''; position: absolute; top: 2px; left: 2px;
width: 20px; height: 20px; border-radius: 50%; background: #fff;
transition: transform 0.3s ease; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch.active::after { transform: translateX(20px); }
.theme-toggle-btn {
width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
border-radius: 0.5rem; border: 1px solid var(--color-outline-variant);
background: var(--color-surface); color: var(--color-on-surface-variant);
cursor: pointer; transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.theme-toggle-btn:hover { background: var(--color-surface-low); color: var(--color-on-surface); }
.empty-state {
text-align: center; padding: 3rem 1rem; color: var(--color-on-surface-variant);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 0.75rem; color: var(--color-outline); }
.empty-state p { font-size: 0.9rem; }
</style>
</head>
<body class="min-h-screen flex flex-col antialiased bg-background selection:bg-primary-container selection:text-on-primary-container">
<!-- ============================== -->
<!-- AUTH PAGE -->
<!-- ============================== -->
<div class="page active flex-col min-h-screen" id="authPage">
<header class="w-full bg-background">
<div class="flex justify-between items-center px-8 py-6 max-w-7xl mx-auto w-full">
<a class="text-2xl font-headline font-bold text-on-surface hover:text-primary transition-colors duration-300" href="#">CodeRouterAI</a>
<nav class="flex items-center gap-4">
<button class="theme-toggle-btn" id="authThemeToggle" title="Toggle theme">
<span class="material-symbols-outlined text-[20px]">light_mode</span>
</button>
<a class="text-primary border-b-2 border-primary pb-1 font-body font-medium hover:text-primary transition-colors duration-300 cursor-pointer hidden md:inline" id="navSignIn">Sign In</a>
</nav>
</div>
</header>
<main class="flex-grow flex items-center justify-center py-16 px-4 sm:px-6 lg:px-8 relative overflow-hidden">
<div class="auth-glow-1"></div>
<div class="auth-glow-2"></div>
<div class="relative z-10 w-full max-w-md">
<div class="bg-surface-container-low elevation-soft rounded-xl p-8 sm:p-10 border border-outline-variant/60">
<div class="flex justify-center gap-8 mb-10 border-b border-outline-variant/40 pb-4 relative">
<button class="font-headline text-2xl font-medium focus:outline-none transition-colors duration-300 relative tab-active" id="tabSignUp">Create Account</button>
<button class="font-headline text-2xl focus:outline-none transition-colors duration-300 relative tab-inactive" id="tabSignIn">Sign In</button>
</div>
<div class="text-center mb-8">
<h1 class="font-headline text-4xl mb-2 text-on-surface" id="authTitle">Welcome.</h1>
<p class="font-body text-secondary text-sm" id="authSubtitle">Join the curated simplicity of CodeRouterAI.</p>
</div>
<form class="space-y-5" id="authForm">
<div id="nameField">
<label class="block text-sm font-medium text-on-surface-variant font-body mb-1.5" for="name">Full Name</label>
<input class="auth-input" id="name" name="name" placeholder="Jane Doe" type="text"/>
</div>
<div>
<label class="block text-sm font-medium text-on-surface-variant font-body mb-1.5" for="email">Email Address</label>
<input class="auth-input" id="email" name="email" placeholder="jane@example.com" type="email"/>
</div>
<div>
<label class="block text-sm font-medium text-on-surface-variant font-body mb-1.5" for="password">Password</label>
<div class="relative">
<input class="auth-input pr-10" id="password" name="password" placeholder="••••••••" type="password"/>
<button class="absolute inset-y-0 right-0 flex items-center pr-3 text-secondary hover:text-primary transition-colors" type="button" id="togglePass">
<span class="material-symbols-outlined text-[20px]">visibility_off</span>
</button>
</div>
</div>
<button class="btn-primary w-full text-base py-3.5 mt-4" type="submit" id="authSubmit">Get Started</button>
<p class="text-xs text-center text-secondary font-body mt-4">
By continuing, you agree to our <a class="text-primary hover:underline underline-offset-4 decoration-primary/50 transition-all duration-200" href="#">Terms</a> and <a class="text-primary hover:underline underline-offset-4 decoration-primary/50 transition-all duration-200" href="#">Privacy</a>.
</p>
</form>
<div class="mt-8">
<div class="relative">
<div class="absolute inset-0 flex items-center"><div class="w-full border-t border-outline-variant/60"></div></div>
<div class="relative flex justify-center text-sm">
<span class="px-4 bg-surface-container-low text-secondary font-body italic">Or continue with</span>
</div>
</div>
<div class="mt-5 grid grid-cols-2 gap-4">
<button class="w-full inline-flex justify-center items-center py-2.5 px-4 border border-outline-variant rounded-lg bg-surface-container-lowest text-sm font-medium text-on-surface hover:bg-surface-container transition-colors duration-200" type="button">
<svg class="h-5 w-5 mr-2" fill="currentColor" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4"/>
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853"/>
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05"/>
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335"/>
</svg> Google
</button>
<button class="w-full inline-flex justify-center items-center py-2.5 px-4 border border-outline-variant rounded-lg bg-surface-container-lowest text-sm font-medium text-on-surface hover:bg-surface-container transition-colors duration-200" type="button">
<svg class="h-5 w-5 mr-2" fill="currentColor" viewBox="0 0 24 24">
<path clip-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" fill-rule="evenodd"/>
</svg> GitHub
</button>
</div>
</div>
</div>
</div>
</main>
<footer class="w-full bg-background border-t border-outline-variant/60 mt-auto relative z-20">
<div class="flex flex-col md:flex-row justify-between items-center px-8 py-10 max-w-7xl mx-auto w-full">
<div class="mb-4 md:mb-0">
<span class="font-headline text-on-surface text-xl">CodeRouterAI</span>
<span class="font-body text-sm text-secondary ml-2">© 2026 CodeRouterAI. Curated simplicity.</span>
</div>
<nav class="flex gap-6 text-sm">
<a class="font-body text-on-secondary-container hover:underline decoration-primary/50 underline-offset-4 transition-all duration-200" href="#">Privacy</a>
<a class="font-body text-on-secondary-container hover:underline decoration-primary/50 underline-offset-4 transition-all duration-200" href="#">Terms</a>
<a class="font-body text-on-secondary-container hover:underline decoration-primary/50 underline-offset-4 transition-all duration-200" href="#">Support</a>
</nav>
</div>
</footer>
</div>
<!-- ============================== -->
<!-- CHAT PAGE -->
<!-- ============================== -->
<div class="page flex-col h-screen" id="chatPage">
<!-- Mobile Header -->
<header class="md:hidden fixed top-0 w-full z-50 flex justify-between items-center px-6 h-16 bg-surface hairline-b">
<div class="text-lg font-headline font-bold tracking-tight text-on-surface">CodeRouterAI</div>
<div class="flex items-center gap-2">
<button class="theme-toggle-btn" id="mobileThemeToggle" title="Toggle theme">
<span class="material-symbols-outlined text-[20px]">light_mode</span>
</button>
<button id="mobileMenuBtn" class="p-2 text-on-surface-variant hover:text-on-surface transition-colors">
<span class="material-symbols-outlined">menu</span>
</button>
</div>
</header>
<div class="flex w-full h-full pt-16 md:pt-0">
<!-- Sidebar -->
<aside class="sidebar flex-col w-[280px] h-full hairline-r bg-surface z-40 relative flex-shrink-0 hidden md:flex" id="sidebar">
<div class="p-8 pb-6 flex items-center justify-between">
<div>
<h1 class="text-2xl font-headline font-bold tracking-tight text-on-surface">CodeRouterAI</h1>
<p class="text-sm text-on-surface-variant mt-0.5">Cost-aware multitask assistant</p>
</div>
<button class="theme-toggle-btn" id="sidebarThemeToggle" title="Toggle theme">
<span class="material-symbols-outlined text-[20px]">light_mode</span>
</button>
</div>
<nav class="px-6 flex-1 overflow-y-auto space-y-8">
<div>
<button class="flex items-center gap-3 w-full px-4 py-3 bg-on-surface text-surface rounded-md hover:bg-on-surface/90 transition-colors font-body font-medium" id="newChatBtn">
<span class="material-symbols-outlined text-[20px]">add</span>
<span>New Chat</span>
</button>
</div>
<div>
<div class="px-4 mb-3"><span class="text-xs font-semibold text-on-surface-variant uppercase tracking-widest">History</span></div>
<div class="space-y-1">
<button class="flex items-center gap-3 w-full px-4 py-2 text-on-surface-variant hover:text-on-surface hover:bg-surface-variant transition-colors rounded-md" id="recentSessionsBtn">
<span class="material-symbols-outlined text-[18px]">history</span>
<span>Recent Sessions</span>
</button>
<button class="flex items-center gap-3 w-full px-4 py-2 text-on-surface-variant hover:text-on-surface hover:bg-surface-variant transition-colors rounded-md" id="savedPromptsBtn">
<span class="material-symbols-outlined text-[18px]">bookmark</span>
<span>Saved Prompts</span>
</button>
<button class="flex items-center gap-3 w-full px-4 py-2 text-on-surface-variant hover:text-on-surface hover:bg-surface-variant transition-colors rounded-md" id="analyticsBtn">
<span class="material-symbols-outlined text-[18px]">query_stats</span>
<span>Analytics</span>
</button>
</div>
</div>
<div class="pt-4 hairline-t">
<div class="px-4 mb-4"><span class="text-xs font-semibold text-on-surface-variant uppercase tracking-widest">Session Stats</span></div>
<div class="px-4 space-y-5">
<div class="p-4 bg-surface-container-low rounded-lg hairline">
<div class="text-xs text-on-surface-variant mb-1">Total Queries</div>
<div class="font-headline text-3xl font-bold text-on-surface" id="statTotal">0</div>
</div>
<div class="flex gap-3">
<div class="flex-1 p-3 bg-surface-container-low rounded-lg hairline">
<div class="text-xs text-on-surface-variant mb-1">Local</div>
<div class="font-headline text-xl font-bold text-on-surface" id="statLocal">0</div>
</div>
<div class="flex-1 p-3 bg-surface-container-low rounded-lg hairline">
<div class="text-xs text-on-surface-variant mb-1">Remote</div>
<div class="font-headline text-xl font-bold text-on-surface" id="statRemote">0</div>
</div>
</div>
<div class="p-4 bg-surface-container-low rounded-lg hairline">
<div class="text-xs text-on-surface-variant mb-1">Total Saved</div>
<div class="font-headline text-xl font-bold text-on-surface" id="statSaved">$0.00</div>
<div class="text-xs text-on-surface-variant mt-1" id="statSpent">Spent: $0.00</div>
</div>
<div class="p-4 bg-surface-container-low rounded-lg hairline">
<div class="text-xs text-on-surface-variant mb-1">Handled Locally</div>
<div class="w-full h-1.5 bg-surface-container-highest rounded-full overflow-hidden mt-2">
<div class="h-full bg-primary rounded-full transition-all duration-500" id="statBar" style="width:0%"></div>
</div>
<div class="flex justify-between text-xs text-on-surface-variant mt-1.5">
<span id="statPct">0%</span>
<span id="statCount">0 / 0</span>
</div>
</div>
</div>
</div>
</nav>
<div class="p-6 hairline-t space-y-3 bg-surface">
<button class="btn-outline w-full text-sm" id="settingsBtn">
<span class="material-symbols-outlined text-[18px] align-middle mr-1.5">settings</span>
Settings
</button>
<button class="btn-outline w-full text-sm" id="helpBtn">
<span class="material-symbols-outlined text-[18px] align-middle mr-1.5">help</span>
Help
</button>
<button class="btn-outline w-full text-sm" id="logoutBtn">
<span class="material-symbols-outlined text-[18px] align-middle mr-1.5">logout</span>
Sign Out
</button>
</div>
</aside>
<!-- Chat Main -->
<main class="flex-1 flex flex-col h-full bg-background relative min-w-0" id="chatMain">
<div class="flex-1 overflow-y-auto px-6 md:px-12 py-8 flex flex-col items-center" id="chatFeed">
<div class="w-full max-w-3xl flex flex-col gap-6 pb-32" id="chatMessages">
<div id="welcomeSection" class="flex flex-col items-center justify-center text-center mt-16 mb-8 slide-up">
<div class="w-12 h-12 flex items-center justify-center mb-5 bg-primary-container rounded-full">
<span class="material-symbols-outlined text-[28px] text-primary">auto_awesome</span>
</div>
<h2 class="font-headline text-4xl font-bold text-on-surface mb-3 tracking-tight">How can I assist you today?</h2>
<p class="text-base text-on-surface-variant max-w-lg font-body">Cost-aware routing between local (free) and remote (credits) models based on complexity.</p>
</div>
<div id="suggestions" class="grid grid-cols-1 sm:grid-cols-2 gap-3 w-full mb-6">
<button class="suggestion-btn" onclick="sendSuggestion(this)">
<div class="flex items-center gap-2 text-on-surface mb-1">
<span class="material-symbols-outlined text-[18px] text-primary">calculate</span>
<span class="font-semibold text-sm">Solve Math Equation</span>
</div>
<span class="text-xs text-on-surface-variant">Find derivative of x^2 + 3x</span>
</button>
<button class="suggestion-btn" onclick="sendSuggestion(this)">
<div class="flex items-center gap-2 text-on-surface mb-1">
<span class="material-symbols-outlined text-[18px] text-primary">description</span>
<span class="font-semibold text-sm">Summarize Article</span>
</div>
<span class="text-xs text-on-surface-variant">Summarize the history of DNA</span>
</button>
<button class="suggestion-btn" onclick="sendSuggestion(this)">
<div class="flex items-center gap-2 text-on-surface mb-1">
<span class="material-symbols-outlined text-[18px] text-primary">extension</span>
<span class="font-semibold text-sm">Logic Puzzle</span>
</div>
<span class="text-xs text-on-surface-variant">Solve the Monty Hall problem</span>
</button>
<button class="suggestion-btn" onclick="sendSuggestion(this)">
<div class="flex items-center gap-2 text-on-surface mb-1">
<span class="material-symbols-outlined text-[18px] text-primary">code</span>
<span class="font-semibold text-sm">Write Python Code</span>
</div>
<span class="text-xs text-on-surface-variant">Write a simple web scraper</span>
</button>
</div>
</div>
</div>
<div class="w-full px-6 md:px-12 py-6 bg-background hairline-t flex justify-center">
<div class="w-full max-w-3xl">
<div class="bg-surface border border-outline-variant rounded-xl flex items-end relative focus-within:border-primary focus-within:shadow-[0_0_0_3px_rgba(194,101,42,0.08)] transition-all duration-200" id="inputContainer">
<button class="p-3 m-1 text-on-surface-variant hover:text-on-surface transition-colors rounded-lg shrink-0 flex items-center justify-center" id="attachBtn">
<span class="material-symbols-outlined text-[20px]">attach_file</span>
</button>
<div class="flex-1 input-area">
<textarea id="chatInput" rows="1" placeholder="Ask a question..." oninput="autoResize(this)"></textarea>
</div>
<button class="p-2.5 m-1.5 bg-primary text-white rounded-lg shrink-0 flex items-center justify-center hover:bg-[#a85522] transition-colors disabled:opacity-40 disabled:cursor-not-allowed" id="sendBtn">
<span class="material-symbols-outlined text-[20px]">arrow_upward</span>
</button>
</div>
<div class="text-center mt-3">
<p class="text-xs text-on-surface-variant">CodeRouterAI may produce inaccurate information.</p>
</div>
</div>
</div>
</main>
</div>
</div>
<!-- ============================== -->
<!-- MOBILE SIDEBAR -->
<!-- ============================== -->
<div class="fixed inset-0 z-40 bg-black/20 backdrop-blur-sm hidden" id="mobileOverlay"></div>
<aside class="fixed top-0 left-0 h-full w-[280px] bg-surface z-50 transform -translate-x-full transition-transform duration-300 ease-in-out shadow-xl md:hidden" id="mobileSidebar">
<div class="p-6 hairline-b flex justify-between items-center">
<span class="font-headline text-xl font-bold text-on-surface">CodeRouterAI</span>
<button id="closeMobileMenu" class="p-1 text-on-surface-variant hover:text-on-surface">
<span class="material-symbols-outlined">close</span>
</button>
</div>
<div class="p-6 overflow-y-auto h-[calc(100%-65px)]">
<button class="flex items-center gap-3 w-full px-4 py-3 bg-on-surface text-surface rounded-md hover:bg-on-surface/90 transition-colors font-body font-medium mb-6" id="mobileNewChatBtn">
<span class="material-symbols-outlined text-[20px]">add</span>
<span>New Chat</span>
</button>
<div class="mb-6 space-y-1">
<button class="flex items-center gap-3 w-full px-4 py-2 text-on-surface-variant hover:text-on-surface hover:bg-surface-variant transition-colors rounded-md" id="mobileRecentSessionsBtn">
<span class="material-symbols-outlined text-[18px]">history</span><span>Recent Sessions</span>
</button>
<button class="flex items-center gap-3 w-full px-4 py-2 text-on-surface-variant hover:text-on-surface hover:bg-surface-variant transition-colors rounded-md" id="mobileSavedPromptsBtn">
<span class="material-symbols-outlined text-[18px]">bookmark</span><span>Saved Prompts</span>
</button>
<button class="flex items-center gap-3 w-full px-4 py-2 text-on-surface-variant hover:text-on-surface hover:bg-surface-variant transition-colors rounded-md" id="mobileAnalyticsBtn">
<span class="material-symbols-outlined text-[18px]">query_stats</span><span>Analytics</span>
</button>
</div>
<button class="btn-outline w-full text-sm flex items-center justify-center gap-2 mb-2" id="mobileSettingsBtn">
<span class="material-symbols-outlined text-[18px]">settings</span> Settings
</button>
<button class="btn-outline w-full text-sm flex items-center justify-center gap-2 mb-2" id="mobileHelpBtn">
<span class="material-symbols-outlined text-[18px]">help</span> Help
</button>
<button class="btn-outline w-full text-sm flex items-center justify-center gap-2" id="mobileLogoutBtn">
<span class="material-symbols-outlined text-[18px]">logout</span> Sign Out
</button>
</div>
</aside>
<!-- ============================== -->
<!-- PANEL OVERLAY & DRAWER -->
<!-- ============================== -->
<div class="panel-overlay" id="panelOverlay"></div>
<div class="panel-drawer" id="panelDrawer">
<div class="panel-header">
<h2 id="panelTitle">Panel</h2>
<button class="panel-close" id="panelClose"><span class="material-symbols-outlined">close</span></button>
</div>
<div class="panel-body" id="panelBody"></div>
</div>
<script>
// ================================
// THEME TOGGLE
// ================================
function getTheme() { return localStorage.getItem('coderouter-theme') || 'light'; }
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
if (theme === 'dark') { document.documentElement.classList.add('dark'); } else { document.documentElement.classList.remove('dark'); }
localStorage.setItem('coderouter-theme', theme);
const icons = document.querySelectorAll('.theme-toggle-btn .material-symbols-outlined');
icons.forEach(icon => { icon.textContent = theme === 'dark' ? 'dark_mode' : 'light_mode'; });
}
function toggleTheme() { setTheme(getTheme() === 'dark' ? 'light' : 'dark'); }
setTheme(getTheme());
document.querySelectorAll('.theme-toggle-btn').forEach(btn => {
btn.addEventListener('click', toggleTheme);
});
// ================================
// AUTH STATE
// ================================
let isSignUp = true;
let currentSessionId = null;
let messages = [];
let authToken = null;
let currentUsername = null;
function applyUserPreferences() {
if (!currentUsername) return;
const size = localStorage.getItem(`coderouter-font-size-${currentUsername}`) || 'medium';
const sizes = { small: '0.8rem', medium: '0.875rem', large: '1rem' };
chat.style.fontSize = sizes[size] || '0.875rem';
}
const authPage = document.getElementById('authPage');
const chatPage = document.getElementById('chatPage');
const tabSignUp = document.getElementById('tabSignUp');
const tabSignIn = document.getElementById('tabSignIn');
const nameField = document.getElementById('nameField');
const authTitle = document.getElementById('authTitle');
const authSubtitle = document.getElementById('authSubtitle');
const authSubmit = document.getElementById('authSubmit');
const togglePass = document.getElementById('togglePass');
const passInput = document.getElementById('password');
tabSignUp.addEventListener('click', () => {
isSignUp = true;
tabSignUp.className = 'font-headline text-2xl font-medium focus:outline-none transition-colors duration-300 relative tab-active';
tabSignIn.className = 'font-headline text-2xl focus:outline-none transition-colors duration-300 relative tab-inactive';
nameField.style.display = 'block';
authTitle.textContent = 'Welcome.';
authSubtitle.textContent = 'Join the curated simplicity of CodeRouterAI.';
authSubmit.textContent = 'Get Started';
});
tabSignIn.addEventListener('click', () => {
isSignUp = false;
tabSignIn.className = 'font-headline text-2xl font-medium focus:outline-none transition-colors duration-300 relative tab-active';
tabSignUp.className = 'font-headline text-2xl focus:outline-none transition-colors duration-300 relative tab-inactive';
nameField.style.display = 'none';
authTitle.textContent = 'Welcome back.';
authSubtitle.textContent = 'Continue your curated AI multitask experience.';
authSubmit.textContent = 'Sign In';
});
document.getElementById('navSignIn').addEventListener('click', () => {
if (isSignUp) tabSignIn.click();
});
togglePass.addEventListener('click', () => {
const type = passInput.type === 'password' ? 'text' : 'password';
passInput.type = type;
togglePass.querySelector('span').textContent = type === 'password' ? 'visibility_off' : 'visibility';
});
document.getElementById('authForm').addEventListener('submit', async (e) => {
e.preventDefault();
const username = document.getElementById('email')
? document.getElementById('email').value.trim()
: document.getElementById('authEmail')
? document.getElementById('authEmail').value.trim()
: document.querySelector('input[type="email"]').value.trim();
const password = document.getElementById('password').value;
try {
if (isSignUp) {
const reg = await fetch('/api/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
if (!reg.ok) { alert('Registration failed. Username may already exist.'); return; }
}
const res = await fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
if (!res.ok) { alert('Login failed. Check your credentials.'); return; }
const data = await res.json();
authToken = data.token;
currentUsername = data.username || username;
transitionToChat();
} catch (err) {
alert('Connection error. Make sure the server is running.');
}
});
function transitionToChat() {
authPage.classList.remove('active');
authPage.style.display = 'none';
chatPage.style.display = 'flex';
chatPage.classList.add('active');
chatPage.style.opacity = '0';
requestAnimationFrame(() => {
chatPage.style.transition = 'opacity 0.4s ease';
chatPage.style.opacity = '1';
});
fetchStats();
applyUserPreferences();
currentSessionId = Date.now().toString();
messages = [];
document.getElementById('chatInput').focus();
}
// ================================
// MOBILE SIDEBAR
// ================================
const mobileSidebar = document.getElementById('mobileSidebar');
const mobileOverlay = document.getElementById('mobileOverlay');
document.getElementById('mobileMenuBtn').addEventListener('click', () => {
mobileSidebar.classList.remove('-translate-x-full');
mobileOverlay.classList.remove('hidden');
});
document.getElementById('closeMobileMenu').addEventListener('click', closeMobileMenu);
mobileOverlay.addEventListener('click', closeMobileMenu);
function closeMobileMenu() {
mobileSidebar.classList.add('-translate-x-full');
mobileOverlay.classList.add('hidden');
}
// ================================
// PANEL SYSTEM
// ================================
const panelOverlay = document.getElementById('panelOverlay');
const panelDrawer = document.getElementById('panelDrawer');
const panelTitle = document.getElementById('panelTitle');
const panelBody = document.getElementById('panelBody');
const panelClose = document.getElementById('panelClose');
function openPanel(title, content) {
panelTitle.textContent = title;
panelBody.innerHTML = content;
panelOverlay.classList.add('open');
panelDrawer.classList.add('open');
document.body.style.overflow = 'hidden';
}
function closePanel() {
panelOverlay.classList.remove('open');
panelDrawer.classList.remove('open');
document.body.style.overflow = '';
}
panelClose.addEventListener('click', closePanel);
panelOverlay.addEventListener('click', closePanel);
// Close on Escape
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closePanel();
});
// ================================
// RECENT SESSIONS
// ================================
function getSessions() {
if (!currentUsername) return [];
try { return JSON.parse(localStorage.getItem(`coderouter-sessions-${currentUsername}`) || '[]'); } catch { return []; }
}
function saveSession(sessions) {
if (!currentUsername) return;
localStorage.setItem(`coderouter-sessions-${currentUsername}`, JSON.stringify(sessions));
}
function renderSessions() {
const sessions = getSessions();
if (sessions.length === 0) {
return `<div class="empty-state"><div class="icon material-symbols-outlined">history</div><p>No recent sessions yet. Start a conversation to see it here.</p></div>`;
}
return sessions.map(s => `
<div class="session-item" data-id="${s.id}">
<div class="title">${escapeHtml(s.title || 'Untitled Session')}</div>
<div class="preview">${escapeHtml(s.preview || 'No messages')}</div>
<div class="meta">
<span>${new Date(s.date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })}</span>
<div>
<span>${s.count || 0} msgs</span>
<button class="delete-btn" onclick="event.stopPropagation(); deleteSession('${s.id}')">Delete</button>
</div>
</div>
</div>
`).join('');
}
function deleteSession(id) {
let sessions = getSessions().filter(s => s.id !== id);
saveSession(sessions);
panelBody.innerHTML = renderSessions();
attachSessionListeners();
}
function saveCurrentSession() {
if (!messages.length) return;
const sessions = getSessions();
const firstMsg = messages.find(m => m.role === 'user');
const existing = sessions.findIndex(s => s.id === currentSessionId);