-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
1938 lines (1785 loc) · 96 KB
/
Copy pathapp.py
File metadata and controls
1938 lines (1785 loc) · 96 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
"""
SafeSpace - AI Mental Health Support Platform
Professional UI Redesign v2.0
"""
import streamlit as st
import streamlit.components.v1 as components
import requests
import time
from datetime import datetime
st.set_page_config(
page_title="SafeSpace — Mental Health Support",
page_icon="🌿",
layout="centered",
initial_sidebar_state="collapsed"
)
BACKEND_URL = "https://safespace-mental-health-app.onrender.com"
# ── DESIGN TOKENS ──────────────────────────────────────────────────────────────
CSS = """
<style>
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,500;0,700;1,500&family=Inter:wght@300;400;500;600&display=swap');
:root {
--bg: #F7F5F0;
--surface: #FFFFFF;
--border: #E8E4DC;
--green: #2E6B4F;
--green-lt: #EAF2EE;
--green-mid: #4A8C68;
--text: #1C1C1C;
--text-2: #5A5A5A;
--text-3: #9A9A9A;
--red: #C0392B;
--red-lt: #FDECEA;
--amber: #D4860A;
--amber-lt: #FEF3DC;
--radius: 14px;
--radius-sm: 8px;
--shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
--shadow-lg: 0 8px 32px rgba(0,0,0,.10);
}
/* ── RESET ── */
* { box-sizing: border-box; }
#MainMenu, footer, header, .stDeployButton,
div[data-testid="stToolbar"],
div[data-testid="stDecoration"],
div[data-testid="stStatusWidget"] { display:none !important; }
section[data-testid="stSidebar"] { display:none !important; }
.block-container {
padding: 0 !important;
max-width: 760px !important;
margin: 0 auto !important;
}
/* ── APP BG ── */
.stApp { background: var(--bg); font-family: 'Inter', sans-serif; color: var(--text); }
/* ── STREAMLIT TEXT OVERRIDES ── */
.stMarkdown, .stMarkdown p, .stMarkdown div, .stMarkdown span,
[data-testid="stMarkdownContainer"],
[data-testid="stMarkdownContainer"] p { color: var(--text) !important; }
/* ── NAVBAR ── */
.ss-nav {
background: var(--surface);
border-bottom: 1px solid var(--border);
padding: 0 40px;
height: 60px;
display: flex;
align-items: center;
justify-content: space-between;
position: sticky; top: 0; z-index: 999;
}
.ss-nav-brand {
display: flex; align-items: center; gap: 10px;
font-size: 17px; font-weight: 600; color: var(--text);
letter-spacing: -.3px;
}
.ss-nav-logo { color: var(--green); font-size: 20px; }
.ss-nav-right { display: flex; align-items: center; gap: 16px; }
.ss-nav-user { text-align: right; }
.ss-nav-name { font-size: 14px; font-weight: 600; color: var(--text); }
.ss-nav-wid { font-size: 11px; color: var(--text-3); font-family: monospace; }
/* ── PAGE CONTAINER ── */
.ss-page {
max-width: 100%;
margin: 0 auto;
padding: 32px 0 80px;
}
.ss-page-wide {
max-width: 100%;
margin: 0 auto;
padding: 32px 0 80px;
}
/* ── TYPOGRAPHY ── */
.ss-h1 {
font-family: 'Playfair Display', serif;
font-size: 38px; font-weight: 700;
line-height: 1.15; color: var(--text);
margin-bottom: 10px;
}
.ss-h1 em { color: var(--green); font-style: italic; }
.ss-h2 {
font-family: 'Playfair Display', serif;
font-size: 26px; font-weight: 500;
color: var(--text); margin-bottom: 6px;
text-align: center;
}
.ss-lead { font-size: 16px; color: var(--text-2); line-height: 1.65; margin-bottom: 32px; text-align: center; }
.ss-sub { font-size: 14px; color: var(--text-3); margin-bottom: 24px; text-align: center; }
.ss-label {
font-size: 10px; font-weight: 700; letter-spacing: 1.4px;
text-transform: uppercase; color: var(--text-3);
}
/* ── CARDS ── */
.ss-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 18px 22px;
margin-bottom: 10px;
box-shadow: var(--shadow);
transition: box-shadow .2s, transform .15s;
}
.ss-card:hover {
box-shadow: 0 4px 20px rgba(0,0,0,.09);
transform: translateY(-1px);
}
.ss-card-row {
display: flex; align-items: center;
justify-content: space-between; gap: 16px;
}
.ss-icon-box {
width: 38px; height: 38px;
background: var(--green-lt);
border-radius: 8px;
display: flex; align-items: center;
justify-content: center; font-size: 18px;
flex-shrink: 0; margin-bottom: 10px;
}
.ss-card-title {
font-family: 'Playfair Display', serif;
font-size: 17px; font-weight: 500;
color: var(--text); margin-bottom: 4px;
}
.ss-card-desc { font-size: 13px; color: var(--text-2); line-height: 1.5; }
/* ── FEATURE CARD (landing) ── */
.ss-feat {
background: rgba(255,255,255,.8);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 28px 24px; text-align: center;
margin-bottom: 12px;
}
.ss-feat-icon { font-size: 28px; margin-bottom: 10px; }
.ss-feat-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.ss-feat-desc { font-size: 13px; color: var(--text-2); line-height: 1.5; }
/* ── AUTH CARD ── */
.ss-auth {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 20px;
padding: 48px 44px;
max-width: 440px;
margin: 48px auto;
box-shadow: var(--shadow-lg);
text-align: center;
}
.ss-auth h2 {
font-family: 'Playfair Display', serif;
font-size: 30px; color: var(--text); margin-bottom: 6px;
}
.ss-auth p { font-size: 14px; color: var(--text-3); margin-bottom: 28px; }
.ss-divider {
display: flex; align-items: center; gap: 12px;
margin: 20px 0; color: var(--text-3); font-size: 13px;
}
.ss-divider::before, .ss-divider::after {
content: ''; flex: 1; height: 1px; background: var(--border);
}
.ss-link { color: var(--green); font-weight: 500; cursor: pointer; }
/* ── PILLS / BADGES ── */
.ss-pill {
display: inline-block;
padding: 4px 12px; border-radius: 50px;
font-size: 12px; font-weight: 600;
}
.ss-pill-green { background: var(--green-lt); color: var(--green); }
.ss-pill-red { background: var(--red-lt); color: var(--red); }
.ss-pill-amber { background: var(--amber-lt); color: var(--amber); }
/* ── STATS ROW ── */
.ss-stats {
display: grid; grid-template-columns: repeat(3, 1fr);
gap: 10px; margin-bottom: 16px;
}
.ss-stat {
background: var(--surface); border: 1px solid var(--border);
border-radius: var(--radius); padding: 14px 16px;
text-align: center;
}
.ss-stat-num { font-size: 24px; font-weight: 700; color: var(--green); line-height: 1; }
.ss-stat-lbl { font-size: 11px; color: var(--text-3); margin-top: 3px; letter-spacing:.3px; }
/* ── CHAT BUBBLES ── */
.ss-bubble-wrap-user { display: flex; justify-content: flex-end; margin: 6px 0; }
.ss-bubble-wrap-ai { display: flex; justify-content: flex-start; margin: 6px 0; }
.ss-bubble-user {
background: var(--green); color: #fff;
border-radius: 18px 18px 4px 18px;
padding: 11px 16px; font-size: 14px; line-height: 1.55;
max-width: 82%; box-shadow: 0 2px 8px rgba(46,107,79,.25);
}
.ss-bubble-ai {
background: var(--surface); color: var(--text);
border-radius: 18px 18px 18px 4px;
padding: 11px 16px; font-size: 14px; line-height: 1.55;
max-width: 82%; border: 1px solid var(--border);
box-shadow: var(--shadow);
}
/* ── PROGRESS ── */
.ss-progress-wrap { background: var(--border); border-radius: 6px; height: 5px; margin-bottom: 24px; overflow: hidden; }
.ss-progress-fill { background: var(--green); height: 100%; border-radius: 6px; transition: width .4s; }
/* ── CATEGORY BADGE ── */
.ss-cat-badge {
display: inline-block;
background: var(--green-lt); color: var(--green);
font-size: 11px; font-weight: 700; letter-spacing: .8px;
text-transform: uppercase; padding: 4px 12px;
border-radius: 50px; margin-bottom: 14px;
}
/* ── QUIZ OPTION ── */
.ss-quiz-opt {
background: var(--surface); border: 1px solid var(--border);
border-radius: var(--radius-sm); padding: 13px 16px;
margin-bottom: 8px; font-size: 14px; color: var(--text);
cursor: pointer; transition: border-color .15s;
}
/* ── USER ROW ── */
.ss-user-row {
display: flex; align-items: center; gap: 14px;
padding: 14px 0; border-bottom: 1px solid var(--border);
}
.ss-avatar {
width: 38px; height: 38px;
background: var(--green-lt); border-radius: 50%;
display: flex; align-items: center; justify-content: center;
font-size: 15px; flex-shrink: 0;
}
.ss-user-name { font-weight: 600; font-size: 14px; color: var(--text); }
.ss-user-wid { font-size: 11px; color: var(--text-3); font-family: monospace; }
.ss-user-role { font-size: 13px; color: var(--text-2); }
.ss-user-date { font-size: 11px; color: var(--text-3); }
/* ── PRIVACY CARD ── */
.ss-privacy {
background: var(--green-lt);
border: 1px solid #C3DDD0;
border-radius: var(--radius);
padding: 18px 22px;
display: flex; gap: 14px; align-items: flex-start;
margin-top: 8px;
}
.ss-privacy-body .title { font-weight: 600; font-size: 14px; color: var(--green); margin-bottom: 4px; }
.ss-privacy-body .body { font-size: 13px; color: #3A6B53; line-height: 1.55; }
/* ── MOOD ENTRY ── */
.ss-mood-entry {
display: flex; align-items: center; gap: 12px;
padding: 10px 0; border-bottom: 1px solid var(--border);
}
.ss-mood-time { font-size: 12px; color: var(--text-3); margin-left: auto; }
/* ── CAT SCORE ROW ── */
.ss-cat-row {
display: flex; align-items: center; gap: 12px;
padding: 10px 0; border-bottom: 1px solid var(--border);
}
.ss-cat-name { font-size: 14px; font-weight: 500; min-width: 110px; }
.ss-bar-wrap { flex: 1; background: var(--border); border-radius: 6px; height: 7px; overflow: hidden; }
.ss-bar-fill { height: 100%; border-radius: 6px; }
.ss-cat-score { font-size: 14px; font-weight: 600; min-width: 36px; text-align: right; }
/* ── BUTTON OVERRIDES ── */
.stButton > button {
font-family: 'Inter', sans-serif !important;
font-weight: 500 !important;
font-size: 13px !important;
border-radius: 8px !important;
padding: 8px 16px !important;
transition: all .15s !important;
border: none !important;
width: auto !important;
}
.stButton > button[kind="primary"] {
background: var(--green) !important;
color: white !important;
}
.stButton > button[kind="primary"]:hover {
background: #245840 !important;
transform: translateY(-1px) !important;
box-shadow: 0 3px 10px rgba(46,107,79,.25) !important;
}
.stButton > button[kind="secondary"] {
background: var(--surface) !important;
color: var(--text) !important;
border: 1px solid var(--border) !important;
}
.stButton > button[kind="secondary"]:hover { border-color: var(--green) !important; }
/* Use container width only when explicitly set */
[data-testid="stButton"] > button { min-width: 0; }
/* ── INPUT OVERRIDES ── */
.stTextInput > div > div > input,
.stTextArea > div > textarea {
border-radius: 8px !important;
border: 1px solid var(--border) !important;
padding: 11px 14px !important;
font-size: 14px !important;
font-family: 'Inter', sans-serif !important;
background: var(--surface) !important;
color: var(--text) !important;
}
.stTextInput > div > div > input:focus,
.stTextArea > div > textarea:focus {
border-color: var(--green) !important;
box-shadow: 0 0 0 3px rgba(46,107,79,.12) !important;
}
.stSelectbox > div > div {
border-radius: 8px !important;
border: 1px solid var(--border) !important;
background: var(--surface) !important;
}
.stSelectbox label, .stTextInput label, .stTextArea label,
.stSelectbox > label { color: var(--text-2) !important; font-size: 13px !important; }
/* ── TABS ── */
.stTabs [data-baseweb="tab-list"] {
background: var(--bg) !important;
border-bottom: 1px solid var(--border) !important;
gap: 0 !important; padding: 0 !important;
}
.stTabs [data-baseweb="tab"] {
font-family: 'Inter', sans-serif !important;
font-size: 14px !important; font-weight: 500 !important;
color: var(--text-2) !important;
padding: 12px 20px !important;
border-radius: 0 !important;
border-bottom: 2px solid transparent !important;
}
.stTabs [aria-selected="true"] {
color: var(--green) !important;
border-bottom: 2px solid var(--green) !important;
background: transparent !important;
}
/* ── RADIO ── */
.stRadio > div { gap: 8px !important; }
.stRadio > div > label {
background: var(--surface) !important;
border: 1px solid var(--border) !important;
border-radius: 8px !important;
padding: 12px 16px !important;
font-size: 14px !important;
color: var(--text) !important;
cursor: pointer !important;
transition: border-color .15s !important;
}
.stRadio > div > label:hover { border-color: var(--green) !important; }
/* ── EXPANDER ── */
.streamlit-expanderHeader {
background: var(--surface) !important;
border: 1px solid var(--border) !important;
border-radius: 8px !important;
font-size: 14px !important;
font-weight: 500 !important;
color: var(--text) !important;
}
.streamlit-expanderContent {
border: 1px solid var(--border) !important;
border-top: none !important;
border-radius: 0 0 8px 8px !important;
background: var(--surface) !important;
}
/* ── ALERT OVERRIDES ── */
div[data-testid="stAlert"] {
border-radius: 8px !important;
font-size: 14px !important;
}
/* ── SPINNER ── */
.stSpinner > div { border-top-color: var(--green) !important; }
/* ── GRID FOR HOME CARDS ── */
.ss-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.ss-grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; }
/* ── LANDING HERO ── */
.ss-hero {
text-align: center;
padding: 72px 20px 52px;
max-width: 600px; margin: 0 auto;
}
.ss-hero .tag {
display: inline-block;
background: var(--green-lt); color: var(--green);
font-size: 12px; font-weight: 600; letter-spacing: .5px;
padding: 5px 14px; border-radius: 50px; margin-bottom: 20px;
}
/* ── DIVIDER ── */
.ss-hr { height: 1px; background: var(--border); margin: 24px 0; }
/* ── CHAT AREA ── */
.ss-chat-area {
background: var(--bg);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 20px;
min-height: 300px;
max-height: 480px;
overflow-y: auto;
margin-bottom: 16px;
}
/* ── VOICE ORB ── */
@keyframes orb-pulse {
0% { box-shadow: 0 0 0 0 rgba(46,107,79,.4); }
70% { box-shadow: 0 0 0 14px rgba(46,107,79,0); }
100% { box-shadow: 0 0 0 0 rgba(46,107,79,0); }
}
@keyframes orb-listen {
0%,100% { transform: scale(1); }
50% { transform: scale(1.08); }
}
/* ── BACK LINK ── */
.ss-back { font-size: 13px; color: var(--text-3); cursor: pointer; }
.ss-back:hover { color: var(--green); }
/* ── CRISIS PREDICTOR WARNING ── */
.ss-predictor-low {
background: #EAF2EE; border: 1px solid #C3DDD0;
border-radius: 10px; padding: 12px 16px; margin: 8px 0;
display: flex; align-items: flex-start; gap: 10px;
}
.ss-predictor-moderate {
background: #FEF3DC; border: 1px solid #F0D090;
border-radius: 10px; padding: 12px 16px; margin: 8px 0;
display: flex; align-items: flex-start; gap: 10px;
}
.ss-predictor-high {
background: #FDECEA; border: 1px solid #EFC7C4;
border-radius: 10px; padding: 12px 16px; margin: 8px 0;
display: flex; align-items: flex-start; gap: 10px;
}
.ss-predictor-text { font-size: 13px; line-height: 1.5; }
.ss-predictor-label { font-weight: 700; font-size: 11px; letter-spacing: .5px; text-transform: uppercase; margin-bottom: 3px; }
/* ── EMOTION TAG ── */
.ss-emotion-tag {
display: inline-flex; align-items: center; gap: 5px;
padding: 3px 10px; border-radius: 50px;
font-size: 11px; font-weight: 600;
margin-top: 5px; letter-spacing: .3px;
}
.ss-emotion-positive { background: #EAF2EE; color: #2E6B4F; }
.ss-emotion-negative { background: #FDECEA; color: #C0392B; }
.ss-emotion-neutral { background: #F5F3EE; color: #9A9A9A; }
/* ── EMOTION TIMELINE ── */
.ss-timeline {
background: var(--surface); border: 1px solid var(--border);
border-radius: var(--radius); padding: 20px 24px; margin-bottom: 12px;
}
.ss-timeline-row {
display: flex; align-items: center; gap: 12px;
padding: 8px 0; border-bottom: 1px solid var(--border);
}
.ss-timeline-row:last-child { border-bottom: none; }
.ss-timeline-emoji { font-size: 20px; flex-shrink: 0; width: 28px; text-align: center; }
.ss-timeline-info { flex: 1; }
.ss-timeline-emotion { font-weight: 600; font-size: 13px; color: var(--text); }
.ss-timeline-insight { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.ss-timeline-time { font-size: 11px; color: var(--text-3); }
.ss-intensity-high { color: #C0392B; font-size: 11px; font-weight: 700; }
.ss-intensity-medium { color: #D4860A; font-size: 11px; font-weight: 700; }
.ss-intensity-low { color: #2E6B4F; font-size: 11px; font-weight: 700; }
/* ── CRISIS OVERLAY ── */
.ss-crisis-overlay {
position: fixed; top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,.65);
z-index: 9999;
display: flex; align-items: center; justify-content: center;
padding: 20px;
}
.ss-crisis-modal {
background: white; border-radius: 20px;
padding: 36px 32px; max-width: 480px; width: 100%;
box-shadow: 0 20px 60px rgba(0,0,0,.3);
text-align: center;
}
.ss-crisis-modal .icon { font-size: 48px; margin-bottom: 14px; }
.ss-crisis-modal h3 {
font-family: 'Playfair Display', serif;
font-size: 22px; color: #C0392B; margin-bottom: 10px;
}
.ss-crisis-modal .msg {
font-size: 15px; color: #5A5A5A; line-height: 1.6; margin-bottom: 20px;
}
.ss-crisis-helpline {
background: #FDECEA; border: 1px solid #EFC7C4;
border-radius: 12px; padding: 16px 18px; margin-bottom: 12px; text-align: left;
}
.ss-crisis-helpline .hl-label {
font-size: 11px; font-weight: 700; letter-spacing: .8px;
text-transform: uppercase; color: #C0392B; margin-bottom: 4px;
}
.ss-crisis-helpline .hl-name { font-weight: 600; font-size: 15px; color: #1C1C1C; }
.ss-crisis-helpline .hl-num { font-size: 18px; font-weight: 700; color: #C0392B; margin: 2px 0; }
.ss-crisis-helpline .hl-hours { font-size: 12px; color: #9A9A9A; }
/* ── RESPONSIVE ── */
@media (max-width: 640px) {
.ss-grid { grid-template-columns: 1fr !important; }
.ss-stats { grid-template-columns: repeat(3,1fr) !important; }
.ss-h1 { font-size: 28px !important; }
.ss-h2 { font-size: 22px !important; }
.ss-nav { padding: 0 16px !important; }
.block-container { padding: 0 8px !important; }
}
/* ── SMOOTH SCROLL ── */
html { scroll-behavior: smooth; }
/* ── HIDE STREAMLIT COLUMN GAPS ── */
[data-testid="column"] { padding: 0 4px !important; }
div[data-testid="stVerticalBlock"] > div { gap: 0 !important; }
/* ── FEATURE CARD ROW COMPACT ── */
.ss-card-compact { padding: 12px 16px !important; }
/* ── AI REPORT ── */
.ss-report {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 28px 32px;
margin-bottom: 12px;
line-height: 1.75;
}
.ss-report h2 {
font-family: 'Playfair Display', serif !important;
font-size: 18px !important;
color: var(--green) !important;
margin: 20px 0 8px !important;
padding-bottom: 6px;
border-bottom: 1px solid var(--border);
}
.ss-report h2:first-child { margin-top: 0 !important; }
.ss-report p { font-size: 14px; color: var(--text-2); margin-bottom: 10px; }
.ss-report ul { padding-left: 18px; margin-bottom: 10px; }
.ss-report li { font-size: 14px; color: var(--text-2); margin-bottom: 6px; }
.ss-report-header {
display: flex; align-items: center; gap: 14px;
background: var(--green-lt); border-radius: 10px;
padding: 14px 18px; margin-bottom: 20px;
}
.ss-report-header .icon { font-size: 28px; }
.ss-report-header .title { font-weight: 600; font-size: 15px; color: var(--green); }
.ss-report-header .sub { font-size: 12px; color: #4A8C68; margin-top: 2px; }
/* ── CRISIS CARD ── */
.ss-crisis {
background: var(--red-lt);
border: 1px solid #EFC7C4;
border-radius: var(--radius);
padding: 20px 24px; margin-bottom: 12px;
}
.ss-crisis .title { font-weight: 700; font-size: 15px; color: var(--red); margin-bottom: 8px; }
.ss-crisis .body { font-size: 14px; color: #7B2020; line-height: 1.7; }
/* ── BADGE CARD ── */
.ss-badge-card {
display: flex; align-items: center; gap: 16px;
background: var(--surface); border: 1px solid var(--border);
border-radius: var(--radius); padding: 16px 20px; margin-bottom: 10px;
}
.ss-badge-card.earned { border-color: var(--green); background: var(--green-lt); }
.ss-badge-icon { font-size: 28px; flex-shrink: 0; }
.ss-badge-name { font-weight: 600; font-size: 15px; color: var(--text); }
.ss-badge-desc { font-size: 13px; color: var(--text-3); }
.ss-badge-check { margin-left: auto; color: var(--green); font-size: 18px; }
</style>
"""
st.markdown(CSS, unsafe_allow_html=True)
# ── SESSION ────────────────────────────────────────────────────────────────────
def init():
for k,v in {
"page":"landing","user_id":None,"username":None,"wellness_id":None,
"is_admin":False,"conversation_id":None,"messages":[],
"screening_active":False,"current_screening":None,"screening_results":None,
"mood_log":[],"quiz_state":None,"badges":[],"total_points":0,"ai_report":None,"report_loading":False,"has_memory":False,"memory_summary":"","predictor_warning":None,"predictor_trajectory":"stable",
"mindfulness_step":0,"show_crisis_alert":False,"emotion_timeline":[],
}.items():
if k not in st.session_state: st.session_state[k] = v
init()
def nav(p): st.session_state.page = p; st.rerun()
# ── API ────────────────────────────────────────────────────────────────────────
def api(method, path, **kw):
try:
r = getattr(requests,method)(f"{BACKEND_URL}{path}", timeout=10, **kw)
if r.status_code == 200: return r.json()
except: pass
return None
def api_register(): return api("post","/api/auth/register",json={"preferred_language":"en","enable_voice_input":True})
def api_create_conv(): return api("post","/api/conversations",params={"user_id":st.session_state.user_id})
def api_send_msg(t):
try:
r = requests.post(
f"{BACKEND_URL}/api/conversations/{st.session_state.conversation_id}/messages",
params={"user_id": st.session_state.user_id},
json={"content": t, "message_type": "text"},
timeout=30
)
if r.status_code == 200: return r.json()
except: pass
return None
def check_crisis_in_message(text: str) -> bool:
"""Client-side crisis keyword check as backup"""
keywords = [
"suicide","kill myself","end my life","want to die","no reason to live",
"self-harm","hurt myself","cutting","overdose","worthless","nobody cares",
"better off dead","can't go on","give up on life"
]
text_lower = text.lower()
return any(kw in text_lower for kw in keywords)
def api_start_screening(): return api("post","/api/screening/start",params={"user_id":st.session_state.user_id})
def api_answer(qid,v): return api("post","/api/screening/answer",params={"user_id":st.session_state.user_id,"question_id":qid,"response":v})
def api_generate_report(screening_data: dict):
try:
r = requests.post(
f"{BACKEND_URL}/api/screening/generate-report",
params={"user_id": st.session_state.user_id},
json=screening_data,
timeout=60
)
if r.status_code == 200: return r.json()
except: pass
return None
def api_summarize_conversation():
"""Save conversation summary to memory"""
if not st.session_state.conversation_id: return None
try:
r = requests.post(
f"{BACKEND_URL}/api/conversations/{st.session_state.conversation_id}/summarize",
params={"user_id": st.session_state.user_id},
timeout=30
)
if r.status_code == 200: return r.json()
except: pass
return None
def api_get_memory():
"""Get user past session memory"""
try:
r = requests.get(
f"{BACKEND_URL}/api/user/{st.session_state.user_id}/memory",
timeout=5
)
if r.status_code == 200: return r.json()
except: pass
return {"memory": "", "has_memory": False}
# ── NAVBAR ─────────────────────────────────────────────────────────────────────
def navbar():
if st.session_state.username:
name = st.session_state.username
wid = st.session_state.wellness_id or ""
st.markdown(f"""
<div class="ss-nav">
<div class="ss-nav-brand">
<span class="ss-nav-logo">🌿</span> SafeSpace
</div>
<div class="ss-nav-right">
<div class="ss-nav-user">
<div class="ss-nav-name">{name}</div>
<div class="ss-nav-wid">{wid}</div>
</div>
</div>
</div>""", unsafe_allow_html=True)
col1, col2 = st.columns([8,1])
with col2:
if st.button("Sign out", key="__nav_out__", help="Sign out"):
for k in list(st.session_state.keys()): del st.session_state[k]
init(); nav("landing")
else:
st.markdown("""
<div class="ss-nav">
<div class="ss-nav-brand"><span class="ss-nav-logo">🌿</span> SafeSpace</div>
<div class="ss-nav-right">
<span style="font-size:14px;color:#5A5A5A;font-weight:500">Sign in</span>
</div>
</div>""", unsafe_allow_html=True)
# ── CRISIS ALERT ──────────────────────────────────────────────────────────────
def render_crisis_alert():
"""Show full-screen crisis overlay if triggered"""
if not st.session_state.get("show_crisis_alert", False):
return
st.markdown("""
<div class="ss-crisis-overlay" id="crisis-overlay">
<div class="ss-crisis-modal">
<div class="icon">🆘</div>
<h3>You Are Not Alone</h3>
<p class="msg">
It seems like you might be going through something really difficult right now.
You matter, and help is available — please reach out immediately.
</p>
<div class="ss-crisis-helpline">
<div class="hl-label">India — 24/7</div>
<div class="hl-name">Vandrevala Foundation</div>
<div class="hl-num">📞 1860-2662-345</div>
<div class="hl-hours">Available 24 hours, 7 days a week</div>
</div>
<div class="ss-crisis-helpline">
<div class="hl-label">India — iCall</div>
<div class="hl-name">iCall Psychosocial Helpline</div>
<div class="hl-num">📞 9152987821</div>
<div class="hl-hours">Monday to Saturday, 8am – 10pm</div>
</div>
<div class="ss-crisis-helpline">
<div class="hl-label">Global — Text</div>
<div class="hl-name">Crisis Text Line</div>
<div class="hl-num">💬 Text HOME to 741741</div>
<div class="hl-hours">Available 24/7 worldwide</div>
</div>
</div>
</div>""", unsafe_allow_html=True)
st.markdown("<div style='height:16px'></div>", unsafe_allow_html=True)
col1, col2 = st.columns(2)
with col1:
if st.button("✅ I am safe — Continue", use_container_width=True, type="primary", key="crisis_safe"):
st.session_state.show_crisis_alert = False
st.rerun()
with col2:
if st.button("📞 Call Helpline Now", use_container_width=True, key="crisis_call"):
st.markdown('<script>window.open("tel:18602662345");</script>', unsafe_allow_html=True)
# ══════════════════════════════════════════════════════════════════════════════
# LANDING
# ══════════════════════════════════════════════════════════════════════════════
def page_landing():
navbar()
st.markdown("""
<div class="ss-hero">
<div class="tag">🌿 Anonymous & Confidential</div>
<div class="ss-h1">Your Mental Wellness,<br><em>Completely Private</em></div>
<p class="ss-lead">A safe space for students to access mental health support without fear of judgment or exposure.</p>
</div>""", unsafe_allow_html=True)
st.markdown("<div style='height:8px'></div>", unsafe_allow_html=True)
_,c1,c2,_ = st.columns([1,1,1,1])
with c1:
if st.button("Get Started →", use_container_width=True, type="primary"): nav("register")
with c2:
if st.button("Admin Portal", use_container_width=True): nav("admin_login")
# ══════════════════════════════════════════════════════════════════════════════
# REGISTER
# ══════════════════════════════════════════════════════════════════════════════
def api_signin(wellness_id: str):
return api("post", "/api/auth/signin", params={"wellness_id": wellness_id})
def page_register():
navbar()
st.markdown("""
<div class="ss-auth">
<h2>Welcome</h2>
<p>Create a new account or sign in with your Wellness ID</p>
</div>""", unsafe_allow_html=True)
_,c,_ = st.columns([1,3,1])
with c:
tab_new, tab_return = st.tabs(["New Student", "Returning Student"])
with tab_new:
st.markdown("<div style='height:8px'></div>", unsafe_allow_html=True)
lang = st.selectbox("Preferred language",
["English","हिन्दी (Hindi)","தமிழ் (Tamil)","বাংলা (Bengali)","తెలుగు (Telugu)"],
key="reg_lang")
st.markdown("<div style='height:4px'></div>", unsafe_allow_html=True)
if st.button("Join as Student", use_container_width=True, type="primary", key="reg_new"):
with st.spinner("Creating your anonymous identity…"):
data = api_register()
if data:
st.session_state.user_id = data["id"]
st.session_state.username = data["username"]
st.session_state.wellness_id = data["wellness_id"]
st.session_state.is_admin = False
st.success(f"✅ Welcome, {data['username']}! Your Wellness ID: **{data['wellness_id']}** — save it to sign in later.")
time.sleep(2)
nav("home")
else:
st.error("Backend not reachable. Make sure the backend server is running.")
st.markdown("""
<p style="text-align:center;font-size:12px;color:#9A9A9A;margin:10px 0">
A unique username and Wellness ID will be auto-generated — no personal info needed.
</p>""", unsafe_allow_html=True)
with tab_return:
st.markdown("<div style='height:8px'></div>", unsafe_allow_html=True)
st.markdown("""
<div class="ss-card" style="padding:14px 18px;margin-bottom:14px;background:#EAF2EE;border-color:#C3DDD0">
<p style="font-size:13px;color:#2E6B4F;margin:0">
🔐 Enter your <strong>Wellness ID</strong> (e.g. WL123456) to pick up where you left off.
Your chat history, points and badges will be restored.
</p>
</div>""", unsafe_allow_html=True)
wid_input = st.text_input("Your Wellness ID", placeholder="e.g. WL123456", key="signin_wid")
if st.button("Sign In →", use_container_width=True, type="primary", key="reg_return"):
if wid_input.strip():
with st.spinner("Looking up your account…"):
data = api_signin(wid_input.strip())
if data:
st.session_state.user_id = data["id"]
st.session_state.username = data["username"]
st.session_state.wellness_id = data["wellness_id"]
st.session_state.is_admin = False
st.success(f"✅ Welcome back, {data['username']}!")
time.sleep(1)
nav("home")
else:
st.error("Wellness ID not found. Please check and try again, or create a new account.")
else:
st.warning("Please enter your Wellness ID.")
st.markdown('<div class="ss-divider">or</div>', unsafe_allow_html=True)
if st.button("← Back to home", use_container_width=True): nav("landing")
# ══════════════════════════════════════════════════════════════════════════════
# ADMIN LOGIN
# ══════════════════════════════════════════════════════════════════════════════
def page_admin_login():
navbar()
st.markdown("""
<div class="ss-auth">
<h2>Admin Portal</h2>
<p>Sign in with your Admin Wellness ID</p>
</div>""", unsafe_allow_html=True)
_,c,_ = st.columns([1,3,1])
with c:
aid = st.text_input("Admin Wellness ID", placeholder="e.g. WL123456")
if st.button("Access Admin Portal", use_container_width=True, type="primary"):
if aid.strip():
st.session_state.user_id = "admin_" + aid
st.session_state.username = "Admin Dashboard"
st.session_state.wellness_id = aid.upper()
st.session_state.is_admin = True
nav("admin_dashboard")
else:
st.warning("Please enter your Admin Wellness ID.")
st.markdown('<div class="ss-divider">or</div>', unsafe_allow_html=True)
if st.button("Create Admin Account", use_container_width=True):
data = api_register()
if data:
st.session_state.user_id = data["id"]
st.session_state.username = "Admin Dashboard"
st.session_state.wellness_id = data["wellness_id"]
st.session_state.is_admin = True
nav("admin_dashboard")
st.markdown("<div style='height:6px'></div>", unsafe_allow_html=True)
if st.button("← Back to home", use_container_width=True): nav("landing")
# ══════════════════════════════════════════════════════════════════════════════
# HOME
# ══════════════════════════════════════════════════════════════════════════════
def page_home():
navbar()
st.markdown('<div class="ss-page">', unsafe_allow_html=True)
pts = st.session_state.total_points
badges = len(st.session_state.badges)
badge_str = " ".join(["🏅"]*min(badges,5)) if badges else "—"
st.markdown(f"""
<div class="ss-h2" style="margin-bottom:4px">Welcome to Your Sanctuary</div>
<p class="ss-sub">A safe, anonymous space for your mental wellness journey</p>
<div class="ss-stats">
<div class="ss-stat">
<div class="ss-stat-num">{pts}</div>
<div class="ss-stat-lbl">Points</div>
</div>
<div class="ss-stat">
<div class="ss-stat-num">{badges}</div>
<div class="ss-stat-lbl">Badges</div>
</div>
<div class="ss-stat">
<div class="ss-stat-num" style="font-size:20px">{badge_str if badges else "—"}</div>
<div class="ss-stat-lbl">Recent</div>
</div>
</div>""", unsafe_allow_html=True)
# Mood quick log
st.markdown("""
<div class="ss-card" style="margin-bottom:10px;display:flex;align-items:center;gap:16px;padding:14px 18px">
<div style="font-size:22px">🌤️</div>
<div>
<div style="font-weight:600;font-size:14px;color:#1C1C1C;margin-bottom:2px">How are you feeling today?</div>
<div style="font-size:12px;color:#9A9A9A">Log your mood to earn +10 points</div>
</div>
</div>""", unsafe_allow_html=True)
m_cols = st.columns(5)
for i,(emoji,lbl) in enumerate([("😄","Great"),("🙂","Good"),("😐","Okay"),("😔","Low"),("😢","Sad")]):
with m_cols[i]:
if st.button(f"{emoji} {lbl}", key=f"hm_{i}", use_container_width=True):
st.session_state.mood_log.append({"emoji":emoji,"label":lbl,"time":datetime.now().strftime("%H:%M")})
st.session_state.total_points += 10
if "Mood Logger" not in st.session_state.badges:
st.session_state.badges.append("Mood Logger")
st.toast(f"Logged {emoji} {lbl} · +10 pts")
time.sleep(0.6); st.rerun()
st.markdown("<div style='height:4px'></div>", unsafe_allow_html=True)
# Emotion Timeline (shown if user has chatted)
if st.session_state.emotion_timeline:
recent = st.session_state.emotion_timeline[-5:]
traj = st.session_state.get("predictor_trajectory", "stable")
traj_html = {"declining": "📉 Declining", "stable": "📊 Stable", "improving": "📈 Improving"}.get(traj, "📊 Stable")
traj_color = {"declining": "#C0392B", "stable": "#9A9A9A", "improving": "#2E6B4F"}.get(traj, "#9A9A9A")
st.markdown(f"""
<div class="ss-timeline">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:14px">
<div class="ss-card-title" style="font-size:17px;margin:0">🧠 Emotion Timeline</div>
<span style="font-size:12px;font-weight:600;color:{traj_color}">{traj_html}</span>
</div>""", unsafe_allow_html=True)
for entry in reversed(recent):
sent = entry.get("sentiment","neutral")
cls = "ss-intensity-low" if sent=="positive" else "ss-intensity-high" if sent=="negative" else "ss-timeline-time"
st.markdown(f"""
<div class="ss-timeline-row">
<div class="ss-timeline-emoji">{entry['emoji']}</div>
<div class="ss-timeline-info">
<div class="ss-timeline-emotion">{entry['emotion']}</div>
<div class="ss-timeline-insight">{entry.get('insight','')}</div>
</div>
<div style="text-align:right">
<div class="{cls} ss-timeline-time">{entry.get('intensity','').upper()}</div>
<div class="ss-timeline-time">{entry.get('time','')}</div>
</div>
</div>""", unsafe_allow_html=True)
st.markdown("</div>", unsafe_allow_html=True)
if st.button("💬 Continue Chat", use_container_width=True, type="primary", key="home_chat_emotion"):
nav("chat")
# Feature grid (2 columns)
features = [
("💬","AI SUPPORT","Chat with AI","Confidential conversation with our AI therapist","chat","Start Chat"),
("📋","ASSESSMENT","Self-Screening","Know your wellness across mood, sleep, stress & behaviour","screening","Begin Screening"),
("🎮","ACTIVITIES","Wellness Games","Quizzes, mindfulness and resilience challenges","activities","Explore"),
("📚","RESOURCES","Resources & Help","Helplines, articles and professional support","resources","View Resources"),
("🗺️","LOCATION","Find Nearby Help","Locate mental health clinics near you","map","Open Map"),
]
for i in range(0, len(features), 2):
row = features[i:i+2]
cols = st.columns(len(row))
for col, (icon,lbl,title,desc,pg,btn) in zip(cols, row):
with col: