AnesKAM commited on
Commit
c546535
ยท
verified ยท
1 Parent(s): 8844aea

Update static/style.css

Browse files
Files changed (1) hide show
  1. static/style.css +495 -427
static/style.css CHANGED
@@ -10,15 +10,16 @@
10
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.css"/>
11
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.js"></script>
12
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/auto-render.min.js"></script>
 
 
13
  <style>
14
- /* ========== ุงู„ู…ุชุบูŠุฑุงุช ูˆุงู„ุชู†ุณูŠู‚ุงุช ุงู„ุฃุณุงุณูŠุฉ ========== */
15
  :root {
16
  --bg: #0d0f14; --surface: #161920; --surface2: #1e2230; --surface3: #252a3a;
17
  --border: #2a2f42; --border2: #333a52;
18
  --accent: #4f8ef7; --accent2: #7c5cf7; --accent-soft: rgba(79,142,247,0.12);
19
  --text: #e8eaf2; --text2: #9aa3be; --text3: #5c6480;
20
  --user-bubble: #1a2340; --bot-bubble: #161920;
21
- --danger: #f75f5f;
22
  --radius: 28px; --radius-sm: 18px; --radius-pill: 50px;
23
  --sidebar-w: 280px; --tr: 0.3s cubic-bezier(.4,0,.2,1);
24
  }
@@ -29,120 +30,104 @@
29
  --user-bubble: #dde6ff; --bot-bubble: #fff; --accent-soft: rgba(79,142,247,0.1);
30
  }
31
  *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
32
- html,body{height:100%;font-family:'Cairo',sans-serif;background:var(--bg);color:var(--text); scroll-behavior: smooth;}
33
  ::-webkit-scrollbar{width:6px}::-webkit-scrollbar-track{background:transparent}
34
  ::-webkit-scrollbar-thumb{background:var(--border2);border-radius:var(--radius-pill)}
35
 
 
 
 
 
 
36
  .app{display:flex;height:100vh;overflow:hidden}
37
 
38
  /* SIDEBAR */
39
  .sidebar{width:var(--sidebar-w);min-width:var(--sidebar-w);background:var(--surface);
40
  border-right:1px solid var(--border);display:flex;flex-direction:column;
41
  transition:width var(--tr),min-width var(--tr);overflow:hidden;
42
- border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius);}
43
- [dir="rtl"] .sidebar { border-right:none; border-left:1px solid var(--border); border-radius: 0 var(--radius) var(--radius) 0; }
44
  .sidebar.collapsed{width:0;min-width:0;border:none}
45
  .sidebar-header{padding:24px 20px 16px;display:flex;align-items:center;gap:12px;}
46
  .s-logo{display:flex;align-items:center;gap:12px;flex:1}
47
- .s-logo img{width:36px;height:36px;border-radius:12px;object-fit:cover; box-shadow: 0 4px 12px var(--accent-soft);}
48
  .s-logo-name{font-size:1.2rem;font-weight:700;background:linear-gradient(135deg,var(--accent),var(--accent2));-webkit-background-clip:text;-webkit-text-fill-color:transparent}
49
-
50
- /* ุฒุฑ ุงู„ุฅุบู„ุงู‚ ุงู„ุฏุงุฎู„ูŠ */
51
- .close-sidebar-btn {
52
- background: none; border: none; color: var(--text2); font-size: 1.4rem;
53
- cursor: pointer; padding: 6px 10px; border-radius: var(--radius-pill);
54
- transition: all 0.2s; display: flex; align-items: center; justify-content: center;
55
- width: 36px; height: 36px;
56
- }
57
- .close-sidebar-btn:hover { background: var(--surface2); color: var(--danger); transform: scale(1.1); }
58
 
59
  .btn-new{margin:12px 16px;padding:12px 16px;background:linear-gradient(135deg,var(--accent),var(--accent2));
60
  color:#fff;border:none;border-radius:var(--radius-pill);cursor:pointer;font-family:'Cairo',sans-serif;
61
- font-size:.95rem;font-weight:600;display:flex;align-items:center;gap:8px; justify-content:center;
62
- transition:all var(--tr); box-shadow: 0 4px 15px var(--accent-soft);}
63
  .btn-new:hover{opacity:.9;transform:translateY(-2px)}
64
  .s-label{padding:10px 20px;font-size:.75rem;font-weight:700;color:var(--text3);letter-spacing:.08em;text-transform:uppercase}
65
  .chats-list{flex:1;overflow-y:auto;padding:4px 12px;display:flex;flex-direction:column;gap:6px}
66
  .chat-item{padding:10px 16px;border-radius:var(--radius-sm);cursor:pointer;font-size:.9rem;color:var(--text2);
67
- display:flex;align-items:center;gap:10px;transition:all var(--tr);
68
- white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
69
- .chat-item:hover{background:var(--surface2);color:var(--text); transform: translateX(4px);}[dir="rtl"] .chat-item:hover {transform: translateX(-4px);}
70
  .chat-item.active{background:var(--accent-soft);color:var(--accent);font-weight:600;}
71
  .chat-item .ct{flex:1;overflow:hidden;text-overflow:ellipsis}
72
- .del-btn{opacity:0;background:none;border:none;color:var(--danger);cursor:pointer;font-size:.9rem;
73
- padding:4px;border-radius:50%;transition:all var(--tr); display:flex; align-items:center; justify-content:center;}
74
  .chat-item:hover .del-btn{opacity:1}
75
- .del-btn:hover{background:rgba(247,95,95,.15); transform:scale(1.1);}
76
- .s-footer{padding:16px;display:flex;align-items:center;gap:12px; justify-content: center;}
77
- .btn-icon{width:42px;height:42px;background:var(--surface2);border:none;
78
- border-radius:var(--radius-pill);color:var(--text2);cursor:pointer;display:flex;
79
- align-items:center;justify-content:center;font-size:1.1rem;transition:all var(--tr)}
80
- .btn-icon:hover{background:var(--surface3);color:var(--text); transform:rotate(10deg);}
81
 
82
  /* MAIN */
83
- .main{flex:1;display:flex;flex-direction:column;overflow:hidden;min-width:0; background: var(--bg);}
84
- .topbar{height:70px;padding:0 24px;display:flex;align-items:center;gap:16px; flex-shrink:0}
85
  .topbar-title{flex:1;font-size:1.05rem;font-weight:600;color:var(--text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
86
 
87
  /* CHAT AREA */
88
- .chat-area{flex:1;overflow-y:auto;padding:20px 0 40px;display:flex;flex-direction:column; scroll-behavior: smooth;}
89
  .welcome{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;
90
- gap:20px;padding:40px 24px;text-align:center; animation: fadeSlideUp 0.6s ease;}
91
  .w-logo{width:85px;height:85px;border-radius:24px;object-fit:cover;box-shadow:0 12px 40px var(--accent-soft)}
92
- .w-title{font-size:2.4rem;font-weight:700;background:linear-gradient(135deg,var(--accent),var(--accent2));
93
- -webkit-background-clip:text;-webkit-text-fill-color:transparent}
94
  .w-sub{color:var(--text2);font-size:1.05rem}
95
  .chips{display:flex;flex-wrap:wrap;justify-content:center;gap:10px;margin-top:12px;max-width:600px}
96
  .chip{padding:10px 20px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-pill);
97
- font-size:.9rem;color:var(--text);cursor:pointer;transition:all var(--tr); box-shadow: 0 4px 12px rgba(0,0,0,0.05);}
98
- .chip:hover{background:var(--accent-soft);border-color:var(--accent);color:var(--accent); transform:translateY(-2px);}
 
 
 
99
 
100
- /* MESSAGES & ANIMATIONS */
101
- .msg-row{display:flex;padding:8px 30px;gap:16px; animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;}
102
- @keyframes popIn { from { opacity: 0; transform: translateY(15px) scale(0.98); filter: blur(4px); } to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); } }
103
- @keyframes fadeSlideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
104
  .msg-row.user{flex-direction:row-reverse}
105
  .msg-av{width:38px;height:38px;border-radius:14px;flex-shrink:0;display:flex;align-items:center;
106
- justify-content:center;font-size:1.1rem;font-weight:700;margin-top:2px;overflow:hidden;
107
- box-shadow: 0 4px 10px rgba(0,0,0,0.1);}
108
  .msg-row.bot .msg-av{background:linear-gradient(135deg,var(--accent),var(--accent2))}
109
  .msg-row.bot .msg-av img{width:100%;height:100%;object-fit:cover}
110
  .msg-row.user .msg-av{background:var(--surface3);color:var(--text)}
111
-
112
- .bubble{max-width:min(700px,80vw);padding:16px 22px;border-radius:var(--radius);
113
- font-size:.98rem;line-height:1.75;word-break:break-word; box-shadow: 0 4px 15px rgba(0,0,0,0.03);}
114
- .msg-row.bot .bubble{background:transparent;border:none;padding:8px 4px;box-shadow:none;border-top-left-radius:var(--radius);}[dir="rtl"] .msg-row.bot .bubble { border-top-left-radius:var(--radius); border-top-right-radius:var(--radius); }
115
- .msg-row.user .bubble{background:var(--user-bubble);border:none; border-top-right-radius:6px}[dir="rtl"] .msg-row.user .bubble { border-top-right-radius:var(--radius); border-top-left-radius:6px; }
116
-
117
- .bubble img {
118
- max-width: 100%; height: auto; border-radius: 16px; margin: 12px 0;
119
- box-shadow: 0 8px 25px rgba(0,0,0,0.15); cursor: zoom-in; transition: transform 0.2s;
120
- border: 1px solid var(--border);
121
- }
122
- .bubble img:active { transform: scale(1.02); }
123
 
124
- .gemini-cursor { display: inline-block; width: 14px; height: 14px; margin-inline-start: 6px; background: linear-gradient(135deg, var(--accent), var(--accent2)); mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 0l2.5 9.5L24 12l-9.5 2.5L12 24l-2.5-9.5L0 12l9.5-2.5z"/></svg>'); -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 0l2.5 9.5L24 12l-9.5 2.5L12 24l-2.5-9.5L0 12l9.5-2.5z"/></svg>'); mask-size: cover; -webkit-mask-size: cover; animation: spinPulse 1s infinite linear; transform-origin: center; vertical-align: middle; }
125
- @keyframes spinPulse { 0% { transform: scale(0.8) rotate(0deg); opacity: 0.5; } 50% { transform: scale(1.2) rotate(90deg); opacity: 1; filter: drop-shadow(0 0 5px var(--accent)); } 100% { transform: scale(0.8) rotate(180deg); opacity: 0.5; } }
 
 
126
 
127
- .skeleton-img {
128
- width: 100%; max-width: 400px; height: 350px; margin: 15px auto; border-radius: 18px;
129
- background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
130
- background-size: 200% 100%; animation: skeletonLoading 1.5s infinite linear;
131
- box-shadow: 0 8px 25px rgba(0,0,0,0.1); display: flex; align-items: center; justify-content: center;
132
- color: var(--text3); font-size: 2rem;
133
- }
134
- @keyframes skeletonLoading { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
135
 
136
- /* MARKDOWN STYLES */
137
  .bubble p{margin-bottom:12px}.bubble p:last-child{margin-bottom:0}
138
  .bubble ul,.bubble ol{padding-inline-start:24px;margin:12px 0}
139
- .bubble li {margin-bottom: 6px;}
140
  .bubble .table-wrapper{width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;margin:16px 0;border-radius:var(--radius-sm);border:1px solid var(--border);}
141
  .bubble table{width:100%;border-collapse:collapse;min-width:400px;}
142
  .bubble th,.bubble td{border:1px solid var(--border);padding:10px 14px;text-align:start;white-space:nowrap;}
143
  .bubble th{background:var(--surface3);font-weight:600;}
144
 
145
- /* Code Blocks */
146
  .code-container{position:relative;margin:16px 0;background:var(--surface3);border-radius:var(--radius-sm);border:1px solid var(--border);overflow:hidden;max-width:100%;}
147
  .code-header{display:flex;justify-content:space-between;align-items:center;background:#12141a;padding:8px 16px;font-size:0.8rem;color:var(--text2);font-family:'JetBrains Mono',monospace;}
148
  .copy-btn{background:var(--surface2);border:none;color:var(--text);cursor:pointer;display:flex;align-items:center;gap:6px;font-size:0.8rem;padding:4px 10px;border-radius:var(--radius-pill);transition:all 0.2s;}
@@ -151,119 +136,100 @@
151
  .code-container pre code{white-space:pre;display:block;}
152
  .bubble code:not(pre code){font-family:'JetBrains Mono',monospace;font-size:.85rem;background:var(--surface3);padding:3px 6px;border-radius:6px;color:var(--accent);}
153
 
154
- /* KaTeX */
155
  .katex-display{overflow-x:auto;overflow-y:hidden;padding:8px 0;-webkit-overflow-scrolling:touch;}
156
  .katex{font-size:1.05em;}
157
 
158
- /* Files */
159
- .file-chip {display:inline-flex; align-items:center; gap:6px; background:var(--surface2); border:1px solid var(--border); border-radius:var(--radius-pill); padding:4px 12px; font-size:0.85rem; margin:0 4px 8px 0; color:var(--text);}
160
- .file-chip button {background:none; border:none; color:var(--danger); cursor:pointer; font-size:1rem; padding:0; margin-left:4px; transition:transform 0.2s;}
161
- .file-chip button:hover {transform:scale(1.2);}
162
- .file-prev {display:flex; align-items:center; gap:8px; background:var(--surface3); padding:8px 12px; border-radius:8px; margin-bottom:8px; font-size:0.85rem;}
163
-
164
- .mem-badge{font-size:.75rem;color:var(--text3);padding:4px 30px 10px;display:flex;align-items:center;gap:6px; font-weight: 600;}
165
 
166
  /* INPUT */
167
- .input-area{padding:0 24px 30px; display:flex; flex-direction:column; align-items:center; flex-shrink:0;}
168
- .input-wrapper{width:100%; max-width:850px; position:relative;}
169
- .file-chips-container {width:100%; max-width:850px; display:flex; flex-wrap:wrap; margin-bottom:8px;}
170
- .input-box{display:flex;align-items:flex-end;gap:12px;background:var(--surface);
171
- border:1px solid var(--border);border-radius:32px;padding:12px 16px 12px 16px;
172
- transition:all var(--tr); box-shadow: 0 8px 30px rgba(0,0,0,0.15);}
173
- .input-box:focus-within{border-color:var(--accent); box-shadow: 0 8px 30px var(--accent-soft), 0 0 0 3px var(--accent-soft);}
174
-
175
- .btn-attach{background:none; border:none; color:var(--text3); cursor:pointer; font-size:1.3rem; padding:6px; border-radius:50%; transition:all var(--tr); display:flex; align-items:center; justify-content:center;}
176
- .btn-attach:hover{color:var(--accent); background:var(--surface2);}
177
-
178
- .input-box textarea{flex:1;background:none;border:none;outline:none;color:var(--text);
179
- font-family:'Cairo',sans-serif;font-size:.98rem;resize:none;max-height:160px;line-height:1.6; padding: 6px 0;}
180
  .input-box textarea::placeholder{color:var(--text3)}
181
-
182
- /* ุฃุฒุฑุงุฑ ุงู„ุฅุฑุณุงู„ ูˆุงู„ู…ูŠูƒุฑูˆููˆู† ูˆุงู„ุฅูŠู‚ุงู */
183
- .btn-send, .btn-stop, .btn-voice {
184
- width:42px;height:42px; border:none;border-radius:50%;cursor:pointer;
185
- display:flex;align-items:center;justify-content:center;font-size:1.1rem;
186
- transition:all var(--tr); flex-shrink:0; margin-bottom: 2px;
187
- }
188
-
189
- .btn-send {background:linear-gradient(135deg,var(--accent),var(--accent2)); color:#fff;}
190
- .btn-send:hover{opacity:.9;transform:scale(1.08) rotate(-10deg);}[dir="rtl"] .btn-send:hover{transform:scale(1.08) rotate(10deg);}
191
  .btn-send:disabled{opacity:.4;cursor:not-allowed;transform:none;}
192
-
193
- .btn-stop {background:var(--surface3); color:var(--text); border:1px solid var(--border);}
194
- .btn-stop:hover {background:var(--danger); color:#fff; transform:scale(1.05);}
195
-
196
- /* ุฒุฑ ุงู„ุชุญุฏุซ ุงู„ุฌุฏูŠุฏ */
197
- .btn-voice {background:var(--surface2); color:var(--text2);}
198
- .btn-voice:hover {background:var(--surface3); color:var(--accent); transform:scale(1.05);}
199
-
200
- /* ุฃู†ูŠู…ูŠุดู† ุงู„ุชุณุฌูŠู„ ุงู„ุตูˆุชูŠ */
201
- .btn-voice.recording {
202
- background:var(--danger); color:#fff;
203
- animation: pulseRecord 1.5s infinite;
204
- }
205
- @keyframes pulseRecord {
206
- 0% { box-shadow: 0 0 0 0 rgba(247, 95, 95, 0.4); }
207
- 70% { box-shadow: 0 0 0 12px rgba(247, 95, 95, 0); }
208
- 100% { box-shadow: 0 0 0 0 rgba(247, 95, 95, 0); }
209
- }
 
 
 
 
 
 
 
210
 
211
  /* MODAL */
212
- .overlay{position:fixed;inset:0;z-index:999;background:rgba(0,0,0,.6);display:flex;
213
- align-items:center;justify-content:center;backdrop-filter:blur(8px);
214
- opacity:0;pointer-events:none;transition:opacity var(--tr)}
215
  .overlay.open{opacity:1;pointer-events:all}
216
- .modal{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:32px;
217
- width:min(440px,90vw);box-shadow:0 30px 80px rgba(0,0,0,.5);
218
- transform:translateY(20px) scale(0.95);transition:all var(--tr)}
219
  .overlay.open .modal{transform:translateY(0) scale(1)}
220
  .m-header{display:flex;align-items:center;gap:12px;margin-bottom:24px}
221
  .m-title{font-size:1.3rem;font-weight:700;flex:1}
222
- .m-close{background:var(--surface2);border:none;color:var(--text);cursor:pointer;width:36px;height:36px; border-radius:50%; display:flex; align-items:center; justify-content:center; transition:background var(--tr);}
223
- .m-close:hover{background:var(--danger); color:#fff;}
224
  .s-row{display:flex;align-items:center;justify-content:space-between;padding:16px 0;border-bottom:1px solid var(--border)}
225
  .s-lbl{font-size:.95rem;font-weight:600;color:var(--text)}
226
  .s-desc{font-size:.8rem;color:var(--text3);margin-top:4px}
227
  .toggle{position:relative;width:48px;height:26px}
228
  .toggle input{opacity:0;width:0;height:0}
229
  .tslider{position:absolute;inset:0;background:var(--surface3);border-radius:var(--radius-pill);cursor:pointer;transition:all var(--tr)}
230
- .tslider::before{content:'';position:absolute;width:20px;height:20px;border-radius:50%;
231
- background:#fff;top:3px;left:4px;transition:all var(--tr); box-shadow: 0 2px 5px rgba(0,0,0,0.2);}
232
  .toggle input:checked+.tslider{background:var(--accent)}
233
  .toggle input:checked+.tslider::before{transform:translateX(20px)}
234
-
235
- select.s-input { width:auto; padding:8px 16px; background:var(--surface2); border:1px solid var(--border); border-radius:var(--radius-pill); color:var(--text); cursor:pointer; font-family:'Cairo',sans-serif; font-weight:600;}
236
- .btn-save{width:100%;margin-top:24px;padding:14px;background:linear-gradient(135deg,var(--accent),var(--accent2));
237
- color:#fff;border:none;border-radius:var(--radius-pill);cursor:pointer;font-family:'Cairo',sans-serif;font-size:1rem;font-weight:700; transition:opacity var(--tr);}
238
  .btn-save:hover{opacity:.9}
239
- .btn-danger{padding:8px 18px;background:rgba(247,95,95,.12);border:1px solid var(--danger);
240
- color:var(--danger);border-radius:var(--radius-pill);cursor:pointer;font-size:.9rem;font-weight:600;font-family:'Cairo',sans-serif; transition:all var(--tr);}
241
- .btn-danger:hover{background:var(--danger); color:#fff;}
242
 
243
- /* โ•โ• RESPONSIVE MOBILE โ•โ• */
244
  @media (max-width: 640px) {
245
- .msg-row { padding: 6px 12px; gap: 10px; }
246
- .bubble { max-width: 92vw; padding: 12px 14px; font-size: .93rem; }
247
- .msg-row.bot .bubble { padding: 6px 2px; }
248
- .topbar { height: 56px; padding: 0 14px; }
249
- .input-area { padding: 0 10px 18px; }
250
- .code-container pre { font-size: 0.78rem; padding: 12px; }
251
- .bubble th, .bubble td { font-size: 0.85rem; padding: 8px 10px; }
252
- .w-title { font-size: 1.8rem; }
253
- .chips { gap: 8px; }
254
- .chip { font-size: .82rem; padding: 8px 14px; }
255
-
256
- /* ุฌุนู„ ุงู„ุณุงูŠุฏุจุงุฑ ุทุจู‚ุฉ ู…ู†ุฒู„ู‚ุฉ ุนู„ู‰ ุงู„ู‡ูˆุงุชู */
257
- .sidebar {
258
- position: fixed; top: 0; bottom: 0; left: 0; z-index: 100; height: 100vh;
259
- box-shadow: 4px 0 20px rgba(0,0,0,0.2); transition: transform 0.3s ease, width 0.3s ease;
260
- }
261
- [dir="rtl"] .sidebar { left: auto; right: 0; }
262
- .sidebar.collapsed {
263
- transform: translateX(-100%); width: var(--sidebar-w) !important; min-width: var(--sidebar-w) !important;
264
- }
265
- [dir="rtl"] .sidebar.collapsed { transform: translateX(100%); }
266
- .sidebar:not(.collapsed) { transform: translateX(0); }
267
  }
268
  </style>
269
  </head>
@@ -275,36 +241,59 @@
275
  <img src="https://copilot.microsoft.com/th/id/BCO.f29916dd-b0c1-4089-87cd-43d099a7d1a6.png" alt="Genisi"/>
276
  <span class="s-logo-name">Genisi AI</span>
277
  </div>
278
- <button class="close-sidebar-btn" onclick="toggleSidebar()" title="ุฅุฎูุงุก ุงู„ู‚ุงุฆู…ุฉ">โœ•</button>
 
 
279
  </div>
280
- <button class="btn-new" onclick="newChat()" id="i18n-new-chat">โœฆ New Chat</button>
 
 
 
281
  <div class="s-label" id="i18n-chats-label">CHATS</div>
282
  <div class="chats-list" id="chats-list"></div>
283
  <div class="s-footer">
284
- <button class="btn-icon" onclick="openSettings()">โš™</button>
285
- <button class="btn-icon" id="theme-btn" onclick="toggleTheme()">๐ŸŒ™</button>
 
 
 
 
286
  </div>
287
  </aside>
288
 
289
  <main class="main">
290
  <div class="topbar">
291
- <button class="btn-icon" id="menu-toggle-btn" onclick="toggleSidebar()">โ˜ฐ</button>
 
 
292
  <div class="topbar-title" id="topbar-title">Genisi AI</div>
293
  </div>
294
  <div class="chat-area" id="chat-area"></div>
295
  <div class="input-area">
 
 
 
 
 
 
 
296
  <div class="file-chips-container" id="file-chips"></div>
297
  <div class="input-wrapper">
298
  <div class="input-box">
299
  <input type="file" id="file-input" multiple hidden onchange="handleFiles(this.files)" />
300
- <button class="btn-attach" onclick="document.getElementById('file-input').click()">+</button>
 
 
301
  <textarea id="msg-input" rows="1" onkeydown="handleKey(event)" oninput="autoResize(this)" placeholder="Type a message..."></textarea>
302
-
303
- <!-- ุฒุฑ ุงู„ุชุญุฏุซ ุงู„ุตูˆุชูŠ (ู…ุถุงู ุญุฏูŠุซุงู‹) -->
304
- <button class="btn-voice" id="voice-btn" onclick="toggleVoiceRecord()" title="ุชุญุฏุซ ุจุงู„ุตูˆุช">๐ŸŽค</button>
305
-
306
- <button class="btn-send" id="send-btn" onclick="sendMessage()">โžค</button>
307
- <button class="btn-stop" id="stop-btn" onclick="stopGeneration()" style="display:none;">โน</button>
 
 
 
308
  </div>
309
  </div>
310
  </div>
@@ -316,7 +305,9 @@
316
  <div class="modal">
317
  <div class="m-header">
318
  <div class="m-title" id="i18n-settings-title">Settings</div>
319
- <button class="m-close" onclick="closeSettings()">โœ•</button>
 
 
320
  </div>
321
  <div class="s-row">
322
  <div class="s-lbl" id="i18n-lang-lbl">Language</div>
@@ -334,24 +325,36 @@
334
  <span class="tslider"></span>
335
  </label>
336
  </div>
 
 
 
 
 
 
 
 
 
 
337
  <div class="s-row">
338
  <div>
339
  <div class="s-lbl" id="i18n-del-lbl">Delete All Chats</div>
340
  <div class="s-desc" id="i18n-del-desc">This action cannot be undone</div>
341
  </div>
342
- <button class="btn-danger" onclick="clearAllChats()" id="i18n-del-btn">๐Ÿ—‘ Delete</button>
 
 
343
  </div>
344
- <button class="btn-save" onclick="closeSettings()" id="i18n-save-btn">๐Ÿ’พ Close</button>
345
  </div>
346
  </div>
347
 
348
  <script>
349
  // โ•โ•โ•โ•โ•โ•โ•โ• i18n โ•โ•โ•โ•โ•โ•โ•โ•
350
  const i18n = {
351
- en: { newChat: "โœฆ New Chat", chatsLabel: "CHATS", settings: "Settings", lang: "Language", dark: "Dark Mode", del: "Delete All Chats", delDesc: "This action cannot be undone", delBtn: "๐Ÿ—‘ Delete", saveBtn: "๐Ÿ’พ Close", placeholder: "Type your message... (Enter to send)", welcomeTitle: "Welcome to Genisi", welcomeSub: "Your smart assistant by AnesNT โ€” Batna ๐Ÿ‡ฉ๐Ÿ‡ฟ", c1: "What is AI?", c2: "Write Python code", c3: "Summarize a topic", c4: "Design an image in space ๐Ÿš€", errConnect: "Connection Error", memBadge: "Memory: {c}/{t} messages", stopMsg: "[Generation stopped by user]", vMsg: "๐ŸŽค Voice Message", vThink: "๐Ÿ”Š Thinking...", vPlay: "๐Ÿ”Š Playing Response...", vEnd: "๐Ÿ”Š Voice Response Ended" },
352
- ar: { newChat: "โœฆ ู…ุญุงุฏุซุฉ ุฌุฏูŠุฏุฉ", chatsLabel: "ุงู„ู…ุญุงุฏุซุงุช", settings: "ุงู„ุฅุนุฏุงุฏุงุช", lang: "ุงู„ู„ุบุฉ", dark: "ุงู„ูˆุถุน ุงู„ู„ูŠู„ูŠ", del: "ุญุฐู ุฌู…ูŠุน ุงู„ู…ุญุงุฏุซุงุช", delDesc: "ู„ุง ูŠู…ูƒู† ุงู„ุชุฑุงุฌุน ุนู† ู‡ุฐุง ุงู„ุฅุฌุฑุงุก", delBtn: "๐Ÿ—‘ ุญุฐู", saveBtn: "๐Ÿ’พ ุฅุบู„ุงู‚", placeholder: "ุงูƒุชุจ ุฑุณุงู„ุชูƒ... (Enter ู„ู„ุฅุฑุณุงู„)", welcomeTitle: "ู…ุฑุญุจู‹ุง ููŠ Genisi", welcomeSub: "ุฃู†ุง GenisiุŒ ู…ุณุงุนุฏูƒ ุงู„ุฐูƒูŠ ู…ู† AnesNT โ€” ุจุงุชู†ุฉ ๐Ÿ‡ฉ๐Ÿ‡ฟ", c1: "ู…ุง ู‡ูˆ ุงู„ุฐูƒุงุก ุงู„ุงุตุทู†ุงุนูŠุŸ", c2: "ุงูƒุชุจ ูƒูˆุฏ ุจุงูŠุซูˆู†", c3: "ู„ุฎุต ู„ูŠ ู…ูˆุถูˆุนุงู‹", c4: "ุตู…ู… ุตูˆุฑุฉ ุจุงู„ูุถุงุก ๐Ÿš€", errConnect: "ุฎุทุฃ ููŠ ุงู„ุงุชุตุงู„", memBadge: "ุงู„ุฐุงูƒุฑุฉ: {c}/{t} ุฑุณุงุฆู„", stopMsg: "[ุชู… ุฅูŠู‚ุงู ุงู„ุชูˆู„ูŠุฏ]", vMsg: "๐ŸŽค ุฑุณุงู„ุฉ ุตูˆุชูŠุฉ", vThink: "๐Ÿ”Š ุฌุงุฑูŠ ุงู„ุชููƒูŠุฑ...", vPlay: "๐Ÿ”Š ูŠุณุชู…ุน ูˆูŠุชุญุฏุซ ุงู„ุขู†...", vEnd: "๐Ÿ”Š ุงู†ุชู‡ู‰ ุงู„ุฑุฏ ุงู„ุตูˆุชูŠ" },
353
- fr: { newChat: "โœฆ Nouvelle Disc.", chatsLabel: "DISCUSSIONS", settings: "Paramรจtres", lang: "Langue", dark: "Mode Sombre", del: "Supprimer Tout", delDesc: "Action irrรฉversible", delBtn: "๐Ÿ—‘ Supprimer", saveBtn: "๐Ÿ’พ Fermer", placeholder: "ร‰crivez votre message...", welcomeTitle: "Bienvenue sur Genisi", welcomeSub: "Votre assistant intelligent par AnesNT โ€” Batna ๐Ÿ‡ฉ๐Ÿ‡ฟ", c1: "Qu'est-ce que l'IA?", c2: "Code Python", c3: "Rรฉsumer un sujet", c4: "Crรฉer une image ๐Ÿš€", errConnect: "Erreur de connexion", memBadge: "Mรฉmoire: {c}/{t} msgs", stopMsg: "[Gรฉnรฉration arrรชtรฉe]", vMsg: "๐ŸŽค Message Vocal", vThink: "๐Ÿ”Š Rรฉflexion...", vPlay: "๐Ÿ”Š Lecture...", vEnd: "๐Ÿ”Š Fin de la rรฉponse vocale" },
354
- es: { newChat: "โœฆ Nuevo Chat", chatsLabel: "CHATS", settings: "Ajustes", lang: "Idioma", dark: "Modo Oscuro", del: "Borrar Todo", delDesc: "Acciรณn irreversible", delBtn: "๐Ÿ—‘ Borrar", saveBtn: "๐Ÿ’พ Cerrar", placeholder: "Escribe tu mensaje...", welcomeTitle: "Bienvenido a Genisi", welcomeSub: "Tu asistente por AnesNT โ€” Batna ๐Ÿ‡ฉ๐Ÿ‡ฟ", c1: "ยฟQuรฉ es la IA?", c2: "Cรณdigo Python", c3: "Resumir", c4: "Diseรฑar imagen ๐Ÿš€", errConnect: "Error de conexiรณn", memBadge: "Memoria: {c}/{t} msgs", stopMsg: "[Generaciรณn detenida]", vMsg: "๐ŸŽค Mensaje de Voz", vThink: "๐Ÿ”Š Pensando...", vPlay: "๐Ÿ”Š Reproduciendo...", vEnd: "๐Ÿ”Š Fin de la respuesta de voz" }
355
  };
356
 
357
  let currentLang = localStorage.getItem('genisi_lang') || 'en';
@@ -360,376 +363,441 @@ function applyI18n() {
360
  const t = i18n[currentLang];
361
  document.documentElement.dir = currentLang === 'ar' ? 'rtl' : 'ltr';
362
  document.documentElement.lang = currentLang;
363
-
364
- document.getElementById('i18n-new-chat').textContent = t.newChat;
365
  document.getElementById('i18n-chats-label').textContent = t.chatsLabel;
366
  document.getElementById('i18n-settings-title').textContent = t.settings;
367
  document.getElementById('i18n-lang-lbl').textContent = t.lang;
368
  document.getElementById('i18n-dark-lbl').textContent = t.dark;
 
 
369
  document.getElementById('i18n-del-lbl').textContent = t.del;
370
  document.getElementById('i18n-del-desc').textContent = t.delDesc;
371
- document.getElementById('i18n-del-btn').textContent = t.delBtn;
372
  document.getElementById('i18n-save-btn').textContent = t.saveBtn;
373
  document.getElementById('msg-input').placeholder = t.placeholder;
374
-
375
  if(!activeChatId) renderWelcome();
376
  renderChatList();
377
  }
378
- function changeLanguage(val) { currentLang = val; localStorage.setItem('genisi_lang', val); applyI18n(); }
379
 
380
- // โ•โ•โ•โ•โ•โ•โ•โ• STATE & CONFIG โ•โ•โ•โ•โ•โ•โ•โ•
381
- const genId = () => Date.now().toString(36) + Math.random().toString(36).substring(2, 6);
382
  let userId = localStorage.getItem('genisi_user_id');
383
- if (!userId) { userId = 'user_' + genId(); localStorage.setItem('genisi_user_id', userId); }
384
 
385
- let chats = JSON.parse(localStorage.getItem('genisi_chats') || '[]');
386
  let activeChatId = null;
387
  let isGenerating = false;
388
- let pendingFiles =[];
389
  let currentAbortController = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
 
391
- // ุงู„ู…ุชุบูŠุฑุงุช ุงู„ุฎุงุตุฉ ุจุงู„ุชุณุฌูŠู„ ุงู„ุตูˆุชูŠ
392
- let mediaRecorder;
393
- let audioChunks =[];
394
- let isRecording = false;
 
 
 
 
 
 
 
 
 
395
 
396
- // โ•โ•โ•โ•โ•โ•โ•โ• MARKDOWN & PARSER โ•โ•โ•โ•โ•โ•โ•โ•
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  const renderer = new marked.Renderer();
398
  renderer.code = function(token) {
399
  const codeText = typeof token === 'string' ? token : token.text || '';
400
  const lang = typeof token === 'string' ? arguments[1] : token.lang || 'text';
401
- const escapedCode = String(codeText).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
402
- return `<div class="code-container"><div class="code-header"><span>${lang}</span><button class="copy-btn" onclick="copyCode(this, '${encodeURIComponent(codeText)}')">๐Ÿ“‹ Copy</button></div><pre><code class="language-${lang}">${escapedCode}</code></pre></div>`;
403
  };
404
  renderer.table = function(header, body) {
405
- if (typeof header === 'object' && header !== null && 'header' in header) {
406
- const token = header;
407
- const hdr = token.header.map(cell => `<th>${cell.tokens.map(t=>t.raw||'').join('')}</th>`).join('');
408
- const rows = (token.rows ||[]).map(row => `<tr>${row.map(cell => `<td>${cell.tokens.map(t=>t.raw||'').join('')}</td>`).join('')}</tr>`).join('');
409
  return `<div class="table-wrapper"><table><thead><tr>${hdr}</tr></thead><tbody>${rows}</tbody></table></div>`;
410
  }
411
  return `<div class="table-wrapper"><table><thead>${header}</thead><tbody>${body}</tbody></table></div>`;
412
  };
413
- renderer.html = function(html) { return html; };
414
- marked.setOptions({ renderer: renderer, breaks: true, gfm: true });
415
 
416
- function safeMarked(text) {
417
- if (!text) return '';
418
- const rawHtml = marked.parse(text);
419
- return DOMPurify.sanitize(rawHtml, { USE_PROFILES: { html: true } });
420
  }
421
-
422
- function renderKaTeX(el) {
423
- if (window.renderMathInElement) {
424
- renderMathInElement(el, { delimiters:[{left: '$$', right: '$$', display: true},{left: '$', right: '$', display: false},{left: '\\(', right: '\\)', display: false},{left: '\\[', right: '\\]', display: true}], throwOnError: false });
425
- }
426
  }
427
- function copyCode(btn, encodedCode) {
428
- navigator.clipboard.writeText(decodeURIComponent(encodedCode)).then(() => {
429
- const originalText = btn.innerHTML;
430
- btn.innerHTML = "โœ… Copied!";
431
- setTimeout(() => btn.innerHTML = originalText, 2000);
 
432
  });
433
  }
434
- function removeGeminiCursor() { document.querySelectorAll('.gemini-cursor').forEach(el => el.remove()); }
435
 
436
- // โ•โ•โ•โ•โ•โ•โ•โ• UTILS & FILES โ•โ•โ•โ•โ•โ•โ•โ•
437
- const saveChats = () => localStorage.setItem('genisi_chats', JSON.stringify(chats));
438
- const getChat = (id) => chats.find(c => c.id === (id ?? activeChatId));
439
  function esc(t){ return String(t).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
440
-
441
- function scrollToBottom() { const area = document.getElementById('chat-area'); area.scrollTop = area.scrollHeight; }
442
-
443
- async function handleFiles(files) {
444
- for (let f of files) {
445
- const isText = f.type.startsWith('text/') || f.name.match(/\.(py|js|html|css|json|md|txt|csv|cpp|java)$/i);
446
- const reader = new FileReader();
447
- reader.onload = (e) => {
448
- let data = e.target.result;
449
- if (!isText) data = data.split(',')[1];
450
- pendingFiles.push({ name: f.name, type: f.type || 'application/octet-stream', data: data, isText: isText });
451
- renderFileChips();
452
- };
453
- if (isText) reader.readAsText(f); else reader.readAsDataURL(f);
454
- }
455
- document.getElementById('file-input').value = '';
456
  }
457
- function renderFileChips() {
458
- const container = document.getElementById('file-chips'); container.innerHTML = '';
459
- pendingFiles.forEach((f, idx) => {
460
- const icon = f.isText ? '๐Ÿ“„' : '๐Ÿ–ผ๏ธ';
461
- container.innerHTML += `<div class="file-chip">${icon} ${f.name} <button onclick="removeFile(${idx})">ร—</button></div>`;
462
- });
 
463
  }
464
- function removeFile(idx) { pendingFiles.splice(idx, 1); renderFileChips(); }
465
 
466
- // โ•โ•โ•โ•โ•โ•โ•โ• THEME & UI โ•โ•โ•โ•โ•โ•โ•โ•
467
  function applyTheme(t){
468
  document.documentElement.setAttribute('data-theme',t);
469
  localStorage.setItem('genisi_theme',t);
470
- document.getElementById('theme-btn').textContent = t==='dark'?'๐ŸŒ™':'โ˜€๏ธ';
471
  document.getElementById('dark-toggle').checked = t==='dark';
 
 
 
472
  }
473
  function toggleTheme(){ applyTheme(document.documentElement.getAttribute('data-theme')==='dark'?'light':'dark'); }
474
  function applyThemeToggle(){ applyTheme(document.getElementById('dark-toggle').checked?'dark':'light'); }
475
 
476
- function updateMenuIcon() {
477
- const btn = document.getElementById('menu-toggle-btn');
478
- const sidebar = document.getElementById('sidebar');
479
- btn.textContent = sidebar.classList.contains('collapsed') ? 'โ˜ฐ' : 'โœ•';
 
 
480
  }
481
- function toggleSidebar() {
482
- const sidebar = document.getElementById('sidebar');
483
- sidebar.classList.toggle('collapsed');
484
- updateMenuIcon();
485
- }
486
- function initSidebarState() {
487
- const sidebar = document.getElementById('sidebar');
488
- if (window.innerWidth <= 640) sidebar.classList.add('collapsed');
489
  else sidebar.classList.remove('collapsed');
490
  updateMenuIcon();
491
  }
492
- window.addEventListener('resize', () => {
493
- const sidebar = document.getElementById('sidebar');
494
- if (window.innerWidth > 640) sidebar.classList.remove('collapsed');
495
  else sidebar.classList.add('collapsed');
496
  updateMenuIcon();
497
  });
498
 
499
- function openSettings(){ document.getElementById('settings-modal').classList.add('open'); document.getElementById('lang-select').value=currentLang;}
 
500
  function closeSettings(){ document.getElementById('settings-modal').classList.remove('open'); }
501
 
 
502
  function renderChatList(){
503
  const list=document.getElementById('chats-list'); list.innerHTML='';
504
  [...chats].reverse().forEach(chat=>{
505
  const div=document.createElement('div');
506
  div.className='chat-item'+(chat.id===activeChatId?' active':'');
507
- div.innerHTML=`<span>๐Ÿ’ฌ</span><span class="ct">${esc(chat.title||'Chat')}</span><button class="del-btn" onclick="deleteChat('${chat.id}',event)">โœ•</button>`;
508
- div.onclick = () => loadChat(chat.id);
509
  list.appendChild(div);
510
  });
 
511
  }
 
512
  function renderWelcome(){
513
- const t = i18n[currentLang];
514
  document.getElementById('topbar-title').textContent='Genisi AI';
515
  document.getElementById('chat-area').innerHTML=`<div class="welcome" id="welcome"><img src="https://copilot.microsoft.com/th/id/BCO.f29916dd-b0c1-4089-87cd-43d099a7d1a6.png" class="w-logo" alt="Genisi"/><div class="w-title">${t.welcomeTitle}</div><div class="w-sub">${t.welcomeSub}</div><div class="chips"><div class="chip" onclick="quickSend('${t.c1}')">${t.c1}</div><div class="chip" onclick="quickSend('${t.c2}')">${t.c2}</div><div class="chip" onclick="quickSend('${t.c3}')">${t.c3}</div><div class="chip" onclick="quickSend('${t.c4}')">${t.c4}</div></div></div>`;
516
  }
 
517
  function newChat(){ activeChatId=null; pendingFiles=[]; renderFileChips(); document.getElementById('msg-input').value=''; renderWelcome(); renderChatList(); }
 
518
  function loadChat(id){
519
  activeChatId=id; const chat=getChat(id); if(!chat) return;
520
  document.getElementById('topbar-title').textContent=chat.title;
521
  const area=document.getElementById('chat-area'); area.innerHTML='';
522
- chat.history.forEach((entry)=>{ appendBubble('user', entry.user, false, entry.uiFiles); appendBubble('bot', entry.bot, true); });
523
- if (chat.history.length) appendMemBadge(chat.history.length, chat.history.length);
524
  scrollToBottom(); renderChatList();
525
  }
526
  function deleteChat(id,e){ e.stopPropagation(); chats=chats.filter(c=>c.id!==id); saveChats(); if(activeChatId===id) newChat(); else renderChatList(); }
527
  function clearAllChats(){ chats=[]; saveChats(); newChat(); closeSettings(); }
528
-
529
- function stopGeneration() { if (currentAbortController) currentAbortController.abort(); }
530
-
531
  function quickSend(text){ document.getElementById('msg-input').value=text; sendMessage(); }
532
  function handleKey(e){ if(e.key==='Enter'&&!e.shiftKey){e.preventDefault();sendMessage();} }
533
  function autoResize(el){ el.style.height='auto'; el.style.height=Math.min(el.scrollHeight,160)+'px'; }
534
 
535
- // โ•โ•โ•โ•โ•โ•โ•โ• MESSAGING & STREAMING (TEXT) โ•โ•โ•โ•โ•โ•โ•โ•
536
  async function sendMessage(){
537
- if(isGenerating || isRecording) return;
538
- const input = document.getElementById('msg-input'); let text = input.value.trim();
539
- if(!text && pendingFiles.length === 0) return;
540
- const welcome = document.getElementById('welcome'); if(welcome) welcome.remove();
541
  input.value=''; input.style.height='auto';
 
542
 
543
  if(!activeChatId){
544
- activeChatId = genId();
545
- const chatTitle = text ? text.slice(0,35)+'...' : (pendingFiles[0] ? pendingFiles[0].name : 'Chat');
546
- chats.push({id:activeChatId, title:chatTitle, history:[]});
547
  document.getElementById('topbar-title').textContent=chatTitle;
548
  }
549
- const chat = getChat();
550
- const uiFiles = pendingFiles.map(f => f.name); const binaryFiles =[];
551
- pendingFiles.forEach(f => {
552
- if(f.isText) { text += `\n\n\`\`\`${f.name.split('.').pop()}\n// File: ${f.name}\n${f.data}\n\`\`\``; }
553
- else { binaryFiles.push({ name: f.name, mime_type: f.type, data: f.data }); }
554
  });
555
- appendBubble('user', text, false, uiFiles);
556
- pendingFiles =[]; renderFileChips();
557
-
558
- isGenerating = true;
559
- document.getElementById('send-btn').style.display = 'none';
560
- document.getElementById('stop-btn').style.display = 'flex';
561
- const botContentDiv = appendBubble('bot', '', true);
562
-
563
- const imageTriggers =["ุงุฑุณู…", "ุตู…ู…", "ุชุฎูŠู„", "ุตูˆุฑุฉ ู„", "draw", "generate", "imagine", "create an image", "ุชุตู…ูŠู…"];
564
- const isImageRequest = imageTriggers.some(trigger => text.toLowerCase().startsWith(trigger));
565
- currentAbortController = new AbortController();
566
- let fullBotResponse = "";
567
 
568
  try {
569
- const response = await fetch('/chat', {
570
- method: 'POST', headers: {'Content-Type':'application/json'},
571
- body: JSON.stringify({ user_id: userId, message: text, history: chat.history, files: binaryFiles }),
572
- signal: currentAbortController.signal
573
  });
574
  if(!response.ok) throw new Error("Server Error");
575
- const reader = response.body.getReader();
576
- const decoder = new TextDecoder("utf-8");
577
-
578
- while(true) {
579
- const { value, done } = await reader.read();
580
  if(done) break;
581
- const chunk = decoder.decode(value, {stream: true});
582
- fullBotResponse += chunk;
583
- let safeHtml = safeMarked(fullBotResponse);
584
- botContentDiv.innerHTML = safeHtml;
585
- if (isImageRequest && !botContentDiv.querySelector('img')) botContentDiv.innerHTML += '<div class="skeleton-img">๐ŸŽจ ุฌุงุฑูŠ ุงู„ุชุฎูŠู„ ูˆุงู„ุชุตู…ูŠู…...</div>';
586
- else botContentDiv.innerHTML += '<span class="gemini-cursor"></span>';
587
  renderKaTeX(botContentDiv); scrollToBottom();
588
  }
589
- let finalHtml = safeMarked(fullBotResponse);
590
- botContentDiv.innerHTML = finalHtml;
591
  renderKaTeX(botContentDiv);
592
- chat.history.push({ user: text, bot: fullBotResponse, uiFiles: uiFiles });
593
- saveChats(); appendMemBadge(chat.history.length, chat.history.length);
 
 
 
 
594
  } catch(err){
595
  removeGeminiCursor();
596
- if (err.name === 'AbortError') {
597
- let finalHtml = safeMarked(fullBotResponse) + `<br><br><span style="color:var(--text3); font-style:italic;">${i18n[currentLang].stopMsg}</span>`;
598
- botContentDiv.innerHTML = finalHtml; renderKaTeX(botContentDiv);
599
- chat.history.push({ user: text, bot: fullBotResponse + "\n\n*" + i18n[currentLang].stopMsg + "*", uiFiles: uiFiles });
600
- saveChats();
601
- } else { botContentDiv.innerHTML = `<span style="color:var(--danger)">โš ๏ธ ${i18n[currentLang].errConnect}: ${err.message}</span>`; }
602
  } finally {
603
- removeGeminiCursor(); isGenerating = false;
604
- document.getElementById('send-btn').style.display = 'flex';
605
- document.getElementById('stop-btn').style.display = 'none';
606
- renderChatList(); scrollToBottom();
 
607
  }
608
  }
609
 
610
- // โ•โ•โ•โ•โ•โ•โ•โ• VOICE RECORDING (NEW FEATURE) โ•โ•โ•โ•โ•โ•โ•โ•
611
- async function toggleVoiceRecord() {
612
- const voiceBtn = document.getElementById('voice-btn');
613
- const t = i18n[currentLang];
614
-
615
- // ุฅุฐุง ูƒุงู† ูŠุณุฌู„ ุญุงู„ูŠุงู‹ุŒ ู‚ู… ุจุฅูŠู‚ุงู ุงู„ุชุณุฌูŠู„
616
- if (isRecording) {
617
- mediaRecorder.stop();
618
- isRecording = false;
619
- voiceBtn.classList.remove('recording');
620
- voiceBtn.textContent = 'โณ';
621
- voiceBtn.disabled = true;
622
- return;
623
- }
624
-
625
- // ุฅุฐุง ู„ู… ูŠูƒู† ูŠุณุฌู„ุŒ ุงุจุฏุฃ ุงู„ุชุณุฌูŠู„
626
- try {
627
- const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
628
- mediaRecorder = new MediaRecorder(stream);
629
- audioChunks =[];
630
-
631
- mediaRecorder.ondataavailable = event => {
632
- audioChunks.push(event.data);
633
- };
634
-
635
- mediaRecorder.onstop = async () => {
636
- const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
637
- const reader = new FileReader();
638
- reader.readAsDataURL(audioBlob);
639
- reader.onloadend = async () => {
640
- const base64data = reader.result.split(',')[1];
641
-
642
- const welcome = document.getElementById('welcome');
643
- if(welcome) welcome.remove();
644
-
645
- // ุนุฑุถ ู…ุคุดุฑ ู„ู„ู…ุณุชุฎุฏู… ููŠ ุงู„ู…ุญุงุฏุซุฉ
646
- appendBubble('user', t.vMsg, false);
647
- const botContentDiv = appendBubble('bot', t.vThink, false);
648
-
649
- try {
650
- const response = await fetch('/voice-chat', {
651
- method: 'POST',
652
- headers: { 'Content-Type': 'application/json' },
653
- body: JSON.stringify({ audio_b64: base64data, mime_type: 'audio/webm' })
654
- });
655
-
656
- const data = await response.json();
657
-
658
- if (data.status === "success") {
659
- botContentDiv.innerHTML = t.vPlay;
660
-
661
- // ุชุดุบูŠู„ ุงู„ุตูˆุช ุชู„ู‚ุงุฆูŠุงู‹
662
- const botAudio = new Audio(`data:${data.mime_type};base64,${data.audio_b64}`);
663
- botAudio.play();
664
-
665
- // ุนู†ุฏ ุงู†ุชู‡ุงุก ุงู„ุตูˆุช
666
- botAudio.onended = () => {
667
- botContentDiv.innerHTML = t.vEnd;
668
- };
669
- } else {
670
- botContentDiv.innerHTML = `<span style="color:var(--danger)">โš ๏ธ ุฎุทุฃ: ${data.message}</span>`;
671
- }
672
- } catch (err) {
673
- botContentDiv.innerHTML = `<span style="color:var(--danger)">โš ๏ธ ${t.errConnect}</span>`;
674
- } finally {
675
- voiceBtn.textContent = '๐ŸŽค';
676
- voiceBtn.disabled = false;
677
- scrollToBottom();
678
- stream.getTracks().forEach(track => track.stop()); // ุฅุบู„ุงู‚ ุงู„ู…ุงูŠูƒุฑูˆููˆู†
679
- }
680
- };
681
- };
682
-
683
- mediaRecorder.start();
684
- isRecording = true;
685
- voiceBtn.classList.add('recording');
686
- voiceBtn.textContent = 'โน'; // ุฃูŠู‚ูˆู†ุฉ ุงู„ุฅูŠู‚ุงู
687
- } catch (err) {
688
- alert('ูŠุฑุฌู‰ ุงู„ุณู…ุงุญ ุจุงุณุชุฎุฏุงู… ุงู„ู…ูŠูƒุฑูˆููˆู† ู„ู„ุชู…ูƒู† ู…ู† ุงู„ุชุญุฏุซ.');
689
- console.error(err);
690
  }
 
 
691
  }
692
 
693
- // โ•โ•โ•โ•โ•โ•โ•โ• UI BUBBLES โ•โ•โ•โ•โ•โ•โ•โ•
694
- function appendBubble(role, text, isMarkdown, filesList =[]){
695
  const area=document.getElementById('chat-area');
696
  const row=document.createElement('div'); row.className=`msg-row ${role}`;
697
  const av=document.createElement('div'); av.className='msg-av';
698
- if(role==='bot') av.innerHTML=`<img src="https://copilot.microsoft.com/th/id/BCO.f29916dd-b0c1-4089-87cd-43d099a7d1a6.png" alt="G"/>`;
699
- else av.textContent='๐Ÿ‘ค';
700
  const bub=document.createElement('div'); bub.className='bubble';
701
- if(filesList && filesList.length > 0) filesList.forEach(name => { bub.innerHTML += `<div class="file-prev">๐Ÿ“Ž ${esc(name)}</div>`; });
702
- const contentDiv = document.createElement('div');
703
-
704
- contentDiv.dir = 'auto';
705
- contentDiv.style.unicodeBidi = 'plaintext';
706
- if(text) {
707
- contentDiv.innerHTML = isMarkdown ? safeMarked(text) : esc(text).replace(/\n/g, '<br/>');
708
- if (isMarkdown) renderKaTeX(contentDiv);
709
  }
710
- bub.appendChild(contentDiv);
711
- row.appendChild(av); row.appendChild(bub);
712
- area.appendChild(row);
713
- if (role === 'bot') {
714
- const images = bub.querySelectorAll('img');
715
- if (images.length) Promise.all(Array.from(images).map(img => img.complete ? Promise.resolve() : new Promise(r => img.onload = r))).then(() => scrollToBottom());
716
- else scrollToBottom();
717
  } else scrollToBottom();
718
- return contentDiv;
719
  }
720
 
721
- function appendMemBadge(count, total){
722
  const area=document.getElementById('chat-area'); const b=document.createElement('div'); b.className='mem-badge';
723
- b.innerHTML=`๐Ÿง  ${i18n[currentLang].memBadge.replace('{c}', count).replace('{t}', total)}`;
724
- area.appendChild(b); scrollToBottom();
 
 
725
  }
726
 
727
  // โ•โ•โ•โ•โ•โ•โ•โ• INIT โ•โ•โ•โ•โ•โ•โ•โ•
728
- applyTheme(localStorage.getItem('genisi_theme')||'dark');
729
- document.getElementById('lang-select').value = currentLang;
730
- applyI18n();
731
- initSidebarState();
732
- if (typeof DOMPurify === 'undefined') console.warn("DOMPurify not loaded - XSS protection disabled");
 
 
 
 
733
  </script>
734
  </body>
735
  </html>
 
10
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.css"/>
11
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.js"></script>
12
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/auto-render.min.js"></script>
13
+ <!-- Lucide Icons -->
14
+ <script src="https://unpkg.com/lucide@latest/dist/umd/lucide.min.js"></script>
15
  <style>
 
16
  :root {
17
  --bg: #0d0f14; --surface: #161920; --surface2: #1e2230; --surface3: #252a3a;
18
  --border: #2a2f42; --border2: #333a52;
19
  --accent: #4f8ef7; --accent2: #7c5cf7; --accent-soft: rgba(79,142,247,0.12);
20
  --text: #e8eaf2; --text2: #9aa3be; --text3: #5c6480;
21
  --user-bubble: #1a2340; --bot-bubble: #161920;
22
+ --danger: #f75f5f;
23
  --radius: 28px; --radius-sm: 18px; --radius-pill: 50px;
24
  --sidebar-w: 280px; --tr: 0.3s cubic-bezier(.4,0,.2,1);
25
  }
 
30
  --user-bubble: #dde6ff; --bot-bubble: #fff; --accent-soft: rgba(79,142,247,0.1);
31
  }
32
  *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
33
+ html,body{height:100%;font-family:'Cairo',sans-serif;background:var(--bg);color:var(--text);scroll-behavior:smooth;}
34
  ::-webkit-scrollbar{width:6px}::-webkit-scrollbar-track{background:transparent}
35
  ::-webkit-scrollbar-thumb{background:var(--border2);border-radius:var(--radius-pill)}
36
 
37
+ /* Lucide icon base style */
38
+ .icon { width:20px; height:20px; stroke:currentColor; fill:none; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; pointer-events:none; flex-shrink:0; }
39
+ .icon-sm { width:16px; height:16px; }
40
+ .icon-lg { width:22px; height:22px; }
41
+
42
  .app{display:flex;height:100vh;overflow:hidden}
43
 
44
  /* SIDEBAR */
45
  .sidebar{width:var(--sidebar-w);min-width:var(--sidebar-w);background:var(--surface);
46
  border-right:1px solid var(--border);display:flex;flex-direction:column;
47
  transition:width var(--tr),min-width var(--tr);overflow:hidden;
48
+ border-top-right-radius:var(--radius);border-bottom-right-radius:var(--radius);}
49
+ [dir="rtl"] .sidebar{border-right:none;border-left:1px solid var(--border);border-radius:0 var(--radius) var(--radius) 0;}
50
  .sidebar.collapsed{width:0;min-width:0;border:none}
51
  .sidebar-header{padding:24px 20px 16px;display:flex;align-items:center;gap:12px;}
52
  .s-logo{display:flex;align-items:center;gap:12px;flex:1}
53
+ .s-logo img{width:36px;height:36px;border-radius:12px;object-fit:cover;box-shadow:0 4px 12px var(--accent-soft);}
54
  .s-logo-name{font-size:1.2rem;font-weight:700;background:linear-gradient(135deg,var(--accent),var(--accent2));-webkit-background-clip:text;-webkit-text-fill-color:transparent}
55
+
56
+ .close-sidebar-btn{background:none;border:none;color:var(--text2);cursor:pointer;padding:8px;border-radius:var(--radius-pill);transition:all 0.2s;display:flex;align-items:center;justify-content:center;width:36px;height:36px;}
57
+ .close-sidebar-btn:hover{background:var(--surface2);color:var(--danger);transform:scale(1.1);}
 
 
 
 
 
 
58
 
59
  .btn-new{margin:12px 16px;padding:12px 16px;background:linear-gradient(135deg,var(--accent),var(--accent2));
60
  color:#fff;border:none;border-radius:var(--radius-pill);cursor:pointer;font-family:'Cairo',sans-serif;
61
+ font-size:.95rem;font-weight:600;display:flex;align-items:center;gap:8px;justify-content:center;
62
+ transition:all var(--tr);box-shadow:0 4px 15px var(--accent-soft);}
63
  .btn-new:hover{opacity:.9;transform:translateY(-2px)}
64
  .s-label{padding:10px 20px;font-size:.75rem;font-weight:700;color:var(--text3);letter-spacing:.08em;text-transform:uppercase}
65
  .chats-list{flex:1;overflow-y:auto;padding:4px 12px;display:flex;flex-direction:column;gap:6px}
66
  .chat-item{padding:10px 16px;border-radius:var(--radius-sm);cursor:pointer;font-size:.9rem;color:var(--text2);
67
+ display:flex;align-items:center;gap:10px;transition:all var(--tr);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
68
+ .chat-item:hover{background:var(--surface2);color:var(--text);transform:translateX(4px);}
69
+ [dir="rtl"] .chat-item:hover{transform:translateX(-4px);}
70
  .chat-item.active{background:var(--accent-soft);color:var(--accent);font-weight:600;}
71
  .chat-item .ct{flex:1;overflow:hidden;text-overflow:ellipsis}
72
+ .del-btn{opacity:0;background:none;border:none;color:var(--danger);cursor:pointer;padding:4px;border-radius:50%;transition:all var(--tr);display:flex;align-items:center;justify-content:center;}
 
73
  .chat-item:hover .del-btn{opacity:1}
74
+ .del-btn:hover{background:rgba(247,95,95,.15);transform:scale(1.1);}
75
+ .s-footer{padding:16px;display:flex;align-items:center;gap:12px;justify-content:center;}
76
+ .btn-icon{width:42px;height:42px;background:var(--surface2);border:none;border-radius:var(--radius-pill);
77
+ color:var(--text2);cursor:pointer;display:flex;align-items:center;justify-content:center;
78
+ transition:all var(--tr)}
79
+ .btn-icon:hover{background:var(--surface3);color:var(--text);transform:rotate(10deg);}
80
 
81
  /* MAIN */
82
+ .main{flex:1;display:flex;flex-direction:column;overflow:hidden;min-width:0;background:var(--bg);}
83
+ .topbar{height:70px;padding:0 24px;display:flex;align-items:center;gap:16px;flex-shrink:0}
84
  .topbar-title{flex:1;font-size:1.05rem;font-weight:600;color:var(--text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
85
 
86
  /* CHAT AREA */
87
+ .chat-area{flex:1;overflow-y:auto;padding:20px 0 40px;display:flex;flex-direction:column;scroll-behavior:smooth;}
88
  .welcome{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;
89
+ gap:20px;padding:40px 24px;text-align:center;animation:fadeSlideUp 0.6s ease;}
90
  .w-logo{width:85px;height:85px;border-radius:24px;object-fit:cover;box-shadow:0 12px 40px var(--accent-soft)}
91
+ .w-title{font-size:2.4rem;font-weight:700;background:linear-gradient(135deg,var(--accent),var(--accent2));-webkit-background-clip:text;-webkit-text-fill-color:transparent}
 
92
  .w-sub{color:var(--text2);font-size:1.05rem}
93
  .chips{display:flex;flex-wrap:wrap;justify-content:center;gap:10px;margin-top:12px;max-width:600px}
94
  .chip{padding:10px 20px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-pill);
95
+ font-size:.9rem;color:var(--text);cursor:pointer;transition:all var(--tr);box-shadow:0 4px 12px rgba(0,0,0,0.05);}
96
+ .chip:hover{background:var(--accent-soft);border-color:var(--accent);color:var(--accent);transform:translateY(-2px);}
97
+
98
+ @keyframes popIn{from{opacity:0;transform:translateY(15px) scale(0.98);filter:blur(4px);}to{opacity:1;transform:translateY(0) scale(1);filter:blur(0);}}
99
+ @keyframes fadeSlideUp{from{opacity:0;transform:translateY(20px);}to{opacity:1;transform:translateY(0);}}
100
 
101
+ .msg-row{display:flex;padding:8px 30px;gap:16px;animation:popIn 0.4s cubic-bezier(0.16,1,0.3,1) forwards;}
 
 
 
102
  .msg-row.user{flex-direction:row-reverse}
103
  .msg-av{width:38px;height:38px;border-radius:14px;flex-shrink:0;display:flex;align-items:center;
104
+ justify-content:center;font-size:1.1rem;font-weight:700;margin-top:2px;overflow:hidden;box-shadow:0 4px 10px rgba(0,0,0,0.1);}
 
105
  .msg-row.bot .msg-av{background:linear-gradient(135deg,var(--accent),var(--accent2))}
106
  .msg-row.bot .msg-av img{width:100%;height:100%;object-fit:cover}
107
  .msg-row.user .msg-av{background:var(--surface3);color:var(--text)}
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
+ .bubble{max-width:min(700px,80vw);padding:16px 22px;border-radius:var(--radius);font-size:.98rem;line-height:1.75;word-break:break-word;box-shadow:0 4px 15px rgba(0,0,0,0.03);}
110
+ .msg-row.bot .bubble{background:transparent;border:none;padding:8px 4px;box-shadow:none;border-top-left-radius:var(--radius);}
111
+ .msg-row.user .bubble{background:var(--user-bubble);border:none;border-top-right-radius:6px}
112
+ [dir="rtl"] .msg-row.user .bubble{border-top-right-radius:var(--radius);border-top-left-radius:6px;}
113
 
114
+ .bubble img{max-width:100%;height:auto;border-radius:16px;margin:12px 0;box-shadow:0 8px 25px rgba(0,0,0,0.15);cursor:zoom-in;transition:transform 0.2s;border:1px solid var(--border);}
115
+ .bubble img:active{transform:scale(1.02);}
116
+
117
+ .gemini-cursor{display:inline-block;width:14px;height:14px;margin-inline-start:6px;background:linear-gradient(135deg,var(--accent),var(--accent2));mask-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 0l2.5 9.5L24 12l-9.5 2.5L12 24l-2.5-9.5L0 12l9.5-2.5z"/></svg>');-webkit-mask-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 0l2.5 9.5L24 12l-9.5 2.5L12 24l-2.5-9.5L0 12l9.5-2.5z"/></svg>');mask-size:cover;-webkit-mask-size:cover;animation:spinPulse 1s infinite linear;transform-origin:center;vertical-align:middle;}
118
+ @keyframes spinPulse{0%{transform:scale(0.8) rotate(0deg);opacity:0.5;}50%{transform:scale(1.2) rotate(90deg);opacity:1;filter:drop-shadow(0 0 5px var(--accent));}100%{transform:scale(0.8) rotate(180deg);opacity:0.5;}}
119
+
120
+ .skeleton-img{width:100%;max-width:400px;height:350px;margin:15px auto;border-radius:18px;background:linear-gradient(90deg,var(--surface2) 25%,var(--surface3) 50%,var(--surface2) 75%);background-size:200% 100%;animation:skeletonLoading 1.5s infinite linear;box-shadow:0 8px 25px rgba(0,0,0,0.1);display:flex;align-items:center;justify-content:center;color:var(--text3);font-size:2rem;}
121
+ @keyframes skeletonLoading{0%{background-position:200% 0;}100%{background-position:-200% 0;}}
122
 
 
123
  .bubble p{margin-bottom:12px}.bubble p:last-child{margin-bottom:0}
124
  .bubble ul,.bubble ol{padding-inline-start:24px;margin:12px 0}
125
+ .bubble li{margin-bottom:6px;}
126
  .bubble .table-wrapper{width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;margin:16px 0;border-radius:var(--radius-sm);border:1px solid var(--border);}
127
  .bubble table{width:100%;border-collapse:collapse;min-width:400px;}
128
  .bubble th,.bubble td{border:1px solid var(--border);padding:10px 14px;text-align:start;white-space:nowrap;}
129
  .bubble th{background:var(--surface3);font-weight:600;}
130
 
 
131
  .code-container{position:relative;margin:16px 0;background:var(--surface3);border-radius:var(--radius-sm);border:1px solid var(--border);overflow:hidden;max-width:100%;}
132
  .code-header{display:flex;justify-content:space-between;align-items:center;background:#12141a;padding:8px 16px;font-size:0.8rem;color:var(--text2);font-family:'JetBrains Mono',monospace;}
133
  .copy-btn{background:var(--surface2);border:none;color:var(--text);cursor:pointer;display:flex;align-items:center;gap:6px;font-size:0.8rem;padding:4px 10px;border-radius:var(--radius-pill);transition:all 0.2s;}
 
136
  .code-container pre code{white-space:pre;display:block;}
137
  .bubble code:not(pre code){font-family:'JetBrains Mono',monospace;font-size:.85rem;background:var(--surface3);padding:3px 6px;border-radius:6px;color:var(--accent);}
138
 
 
139
  .katex-display{overflow-x:auto;overflow-y:hidden;padding:8px 0;-webkit-overflow-scrolling:touch;}
140
  .katex{font-size:1.05em;}
141
 
142
+ .file-chip{display:inline-flex;align-items:center;gap:6px;background:var(--surface2);border:1px solid var(--border);border-radius:var(--radius-pill);padding:4px 12px;font-size:0.85rem;margin:0 4px 8px 0;color:var(--text);}
143
+ .file-chip button{background:none;border:none;color:var(--danger);cursor:pointer;font-size:1rem;padding:0;margin-left:4px;transition:transform 0.2s;}
144
+ .file-chip button:hover{transform:scale(1.2);}
145
+ .file-prev{display:flex;align-items:center;gap:8px;background:var(--surface3);padding:8px 12px;border-radius:8px;margin-bottom:8px;font-size:0.85rem;}
146
+ .mem-badge{font-size:.75rem;color:var(--text3);padding:4px 30px 10px;display:flex;align-items:center;gap:6px;font-weight:600;}
 
 
147
 
148
  /* INPUT */
149
+ .input-area{padding:0 24px 30px;display:flex;flex-direction:column;align-items:center;flex-shrink:0;}
150
+ .input-wrapper{width:100%;max-width:850px;position:relative;}
151
+ .file-chips-container{width:100%;max-width:850px;display:flex;flex-wrap:wrap;margin-bottom:8px;}
152
+ .input-box{display:flex;align-items:flex-end;gap:10px;background:var(--surface);border:1px solid var(--border);border-radius:32px;padding:10px 14px;transition:all var(--tr);box-shadow:0 8px 30px rgba(0,0,0,0.15);}
153
+ .input-box:focus-within{border-color:var(--accent);box-shadow:0 8px 30px var(--accent-soft),0 0 0 3px var(--accent-soft);}
154
+
155
+ .btn-attach{background:none;border:none;color:var(--text3);cursor:pointer;padding:8px;border-radius:50%;transition:all var(--tr);display:flex;align-items:center;justify-content:center;width:38px;height:38px;}
156
+ .btn-attach:hover{color:var(--accent);background:var(--surface2);}
157
+
158
+ .input-box textarea{flex:1;background:none;border:none;outline:none;color:var(--text);font-family:'Cairo',sans-serif;font-size:.98rem;resize:none;max-height:160px;line-height:1.6;padding:8px 0;}
 
 
 
159
  .input-box textarea::placeholder{color:var(--text3)}
160
+
161
+ /* Action buttons in input */
162
+ .btn-send,.btn-stop,.btn-voice{width:38px;height:38px;border:none;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all var(--tr);flex-shrink:0;margin-bottom:2px;}
163
+ .btn-send{background:linear-gradient(135deg,var(--accent),var(--accent2));color:#fff;}
164
+ .btn-send:hover{opacity:.9;transform:scale(1.08) rotate(-10deg);}
165
+ [dir="rtl"] .btn-send:hover{transform:scale(1.08) rotate(10deg);}
 
 
 
 
166
  .btn-send:disabled{opacity:.4;cursor:not-allowed;transform:none;}
167
+ .btn-stop{background:var(--surface3);color:var(--text);border:1px solid var(--border);}
168
+ .btn-stop:hover{background:var(--danger);color:#fff;transform:scale(1.05);}
169
+ .btn-voice{background:var(--surface2);color:var(--text2);}
170
+ .btn-voice:hover{background:var(--surface3);color:var(--accent);transform:scale(1.05);}
171
+
172
+ /* Recording state */
173
+ .btn-voice.recording{background:var(--danger);color:#fff;animation:pulseRecord 1.5s infinite;}
174
+ @keyframes pulseRecord{0%{box-shadow:0 0 0 0 rgba(247,95,95,0.4);}70%{box-shadow:0 0 0 12px rgba(247,95,95,0);}100%{box-shadow:0 0 0 0 rgba(247,95,95,0);}}
175
+
176
+ /* STT status banner */
177
+ .stt-status{display:none;align-items:center;gap:10px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-pill);padding:8px 18px;font-size:.85rem;color:var(--text2);width:100%;max-width:850px;margin-bottom:8px;box-shadow:0 4px 15px rgba(0,0,0,0.1);}
178
+ .stt-status.visible{display:flex;}
179
+ .stt-dot{width:10px;height:10px;border-radius:50%;background:var(--danger);animation:pulseRecord 1.5s infinite;flex-shrink:0;}
180
+ .stt-text{flex:1;font-style:italic;}
181
+ /* TTS playing indicator */
182
+ .tts-badge{display:inline-flex;align-items:center;gap:6px;background:linear-gradient(135deg,rgba(79,142,247,0.15),rgba(124,92,247,0.15));border:1px solid var(--border);border-radius:var(--radius-pill);padding:5px 14px;font-size:.8rem;color:var(--accent);margin-top:8px;cursor:pointer;}
183
+ .tts-badge:hover{background:var(--accent-soft);}
184
+ .tts-wave{display:flex;align-items:center;gap:2px;height:14px;}
185
+ .tts-wave span{display:block;width:3px;border-radius:2px;background:var(--accent);animation:wave 1s ease-in-out infinite;}
186
+ .tts-wave span:nth-child(1){height:5px;animation-delay:0s;}
187
+ .tts-wave span:nth-child(2){height:10px;animation-delay:0.15s;}
188
+ .tts-wave span:nth-child(3){height:14px;animation-delay:0.3s;}
189
+ .tts-wave span:nth-child(4){height:10px;animation-delay:0.45s;}
190
+ .tts-wave span:nth-child(5){height:5px;animation-delay:0.6s;}
191
+ @keyframes wave{0%,100%{transform:scaleY(0.5);}50%{transform:scaleY(1);}}
192
 
193
  /* MODAL */
194
+ .overlay{position:fixed;inset:0;z-index:999;background:rgba(0,0,0,.6);display:flex;align-items:center;justify-content:center;backdrop-filter:blur(8px);opacity:0;pointer-events:none;transition:opacity var(--tr)}
 
 
195
  .overlay.open{opacity:1;pointer-events:all}
196
+ .modal{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:32px;width:min(440px,90vw);box-shadow:0 30px 80px rgba(0,0,0,.5);transform:translateY(20px) scale(0.95);transition:all var(--tr)}
 
 
197
  .overlay.open .modal{transform:translateY(0) scale(1)}
198
  .m-header{display:flex;align-items:center;gap:12px;margin-bottom:24px}
199
  .m-title{font-size:1.3rem;font-weight:700;flex:1}
200
+ .m-close{background:var(--surface2);border:none;color:var(--text);cursor:pointer;width:36px;height:36px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:background var(--tr);}
201
+ .m-close:hover{background:var(--danger);color:#fff;}
202
  .s-row{display:flex;align-items:center;justify-content:space-between;padding:16px 0;border-bottom:1px solid var(--border)}
203
  .s-lbl{font-size:.95rem;font-weight:600;color:var(--text)}
204
  .s-desc{font-size:.8rem;color:var(--text3);margin-top:4px}
205
  .toggle{position:relative;width:48px;height:26px}
206
  .toggle input{opacity:0;width:0;height:0}
207
  .tslider{position:absolute;inset:0;background:var(--surface3);border-radius:var(--radius-pill);cursor:pointer;transition:all var(--tr)}
208
+ .tslider::before{content:'';position:absolute;width:20px;height:20px;border-radius:50%;background:#fff;top:3px;left:4px;transition:all var(--tr);box-shadow:0 2px 5px rgba(0,0,0,0.2);}
 
209
  .toggle input:checked+.tslider{background:var(--accent)}
210
  .toggle input:checked+.tslider::before{transform:translateX(20px)}
211
+ select.s-input{width:auto;padding:8px 16px;background:var(--surface2);border:1px solid var(--border);border-radius:var(--radius-pill);color:var(--text);cursor:pointer;font-family:'Cairo',sans-serif;font-weight:600;}
212
+ .btn-save{width:100%;margin-top:24px;padding:14px;background:linear-gradient(135deg,var(--accent),var(--accent2));color:#fff;border:none;border-radius:var(--radius-pill);cursor:pointer;font-family:'Cairo',sans-serif;font-size:1rem;font-weight:700;transition:opacity var(--tr);}
 
 
213
  .btn-save:hover{opacity:.9}
214
+ .btn-danger{padding:8px 18px;background:rgba(247,95,95,.12);border:1px solid var(--danger);color:var(--danger);border-radius:var(--radius-pill);cursor:pointer;font-size:.9rem;font-weight:600;font-family:'Cairo',sans-serif;transition:all var(--tr);}
215
+ .btn-danger:hover{background:var(--danger);color:#fff;}
 
216
 
 
217
  @media (max-width: 640px) {
218
+ .msg-row{padding:6px 12px;gap:10px;}
219
+ .bubble{max-width:92vw;padding:12px 14px;font-size:.93rem;}
220
+ .msg-row.bot .bubble{padding:6px 2px;}
221
+ .topbar{height:56px;padding:0 14px;}
222
+ .input-area{padding:0 10px 18px;}
223
+ .code-container pre{font-size:0.78rem;padding:12px;}
224
+ .bubble th,.bubble td{font-size:0.85rem;padding:8px 10px;}
225
+ .w-title{font-size:1.8rem;}
226
+ .chips{gap:8px;}
227
+ .chip{font-size:.82rem;padding:8px 14px;}
228
+ .sidebar{position:fixed;top:0;bottom:0;left:0;z-index:100;height:100vh;box-shadow:4px 0 20px rgba(0,0,0,0.2);transition:transform 0.3s ease,width 0.3s ease;}
229
+ [dir="rtl"] .sidebar{left:auto;right:0;}
230
+ .sidebar.collapsed{transform:translateX(-100%);width:var(--sidebar-w) !important;min-width:var(--sidebar-w) !important;}
231
+ [dir="rtl"] .sidebar.collapsed{transform:translateX(100%);}
232
+ .sidebar:not(.collapsed){transform:translateX(0);}
 
 
 
 
 
 
 
233
  }
234
  </style>
235
  </head>
 
241
  <img src="https://copilot.microsoft.com/th/id/BCO.f29916dd-b0c1-4089-87cd-43d099a7d1a6.png" alt="Genisi"/>
242
  <span class="s-logo-name">Genisi AI</span>
243
  </div>
244
+ <button class="close-sidebar-btn" onclick="toggleSidebar()" title="ุฅุฎูุงุก ุงู„ู‚ุงุฆู…ุฉ">
245
+ <i data-lucide="x" class="icon"></i>
246
+ </button>
247
  </div>
248
+ <button class="btn-new" onclick="newChat()" id="i18n-new-chat">
249
+ <i data-lucide="sparkles" class="icon-sm"></i>
250
+ <span>New Chat</span>
251
+ </button>
252
  <div class="s-label" id="i18n-chats-label">CHATS</div>
253
  <div class="chats-list" id="chats-list"></div>
254
  <div class="s-footer">
255
+ <button class="btn-icon" onclick="openSettings()" title="Settings">
256
+ <i data-lucide="settings" class="icon"></i>
257
+ </button>
258
+ <button class="btn-icon" id="theme-btn" onclick="toggleTheme()" title="Toggle theme">
259
+ <i data-lucide="moon" class="icon" id="theme-icon"></i>
260
+ </button>
261
  </div>
262
  </aside>
263
 
264
  <main class="main">
265
  <div class="topbar">
266
+ <button class="btn-icon" id="menu-toggle-btn" onclick="toggleSidebar()">
267
+ <i data-lucide="menu" class="icon" id="menu-icon"></i>
268
+ </button>
269
  <div class="topbar-title" id="topbar-title">Genisi AI</div>
270
  </div>
271
  <div class="chat-area" id="chat-area"></div>
272
  <div class="input-area">
273
+ <div class="stt-status" id="stt-status">
274
+ <div class="stt-dot"></div>
275
+ <span class="stt-text" id="stt-text">Listening...</span>
276
+ <button class="btn-icon" style="width:28px;height:28px;" onclick="stopSpeechInput()" title="Stop">
277
+ <i data-lucide="square" class="icon-sm"></i>
278
+ </button>
279
+ </div>
280
  <div class="file-chips-container" id="file-chips"></div>
281
  <div class="input-wrapper">
282
  <div class="input-box">
283
  <input type="file" id="file-input" multiple hidden onchange="handleFiles(this.files)" />
284
+ <button class="btn-attach" onclick="document.getElementById('file-input').click()" title="Attach file">
285
+ <i data-lucide="paperclip" class="icon"></i>
286
+ </button>
287
  <textarea id="msg-input" rows="1" onkeydown="handleKey(event)" oninput="autoResize(this)" placeholder="Type a message..."></textarea>
288
+ <button class="btn-voice" id="voice-btn" onclick="toggleSpeechInput()" title="Voice input">
289
+ <i data-lucide="mic" class="icon" id="mic-icon"></i>
290
+ </button>
291
+ <button class="btn-send" id="send-btn" onclick="sendMessage()" title="Send">
292
+ <i data-lucide="send" class="icon"></i>
293
+ </button>
294
+ <button class="btn-stop" id="stop-btn" onclick="stopGeneration()" style="display:none;" title="Stop generation">
295
+ <i data-lucide="square" class="icon"></i>
296
+ </button>
297
  </div>
298
  </div>
299
  </div>
 
305
  <div class="modal">
306
  <div class="m-header">
307
  <div class="m-title" id="i18n-settings-title">Settings</div>
308
+ <button class="m-close" onclick="closeSettings()">
309
+ <i data-lucide="x" class="icon-sm"></i>
310
+ </button>
311
  </div>
312
  <div class="s-row">
313
  <div class="s-lbl" id="i18n-lang-lbl">Language</div>
 
325
  <span class="tslider"></span>
326
  </label>
327
  </div>
328
+ <div class="s-row">
329
+ <div>
330
+ <div class="s-lbl" id="i18n-tts-lbl">Auto-speak Responses</div>
331
+ <div class="s-desc" id="i18n-tts-desc">Read bot responses aloud automatically</div>
332
+ </div>
333
+ <label class="toggle">
334
+ <input type="checkbox" id="tts-toggle" onchange="saveTtsSetting()"/>
335
+ <span class="tslider"></span>
336
+ </label>
337
+ </div>
338
  <div class="s-row">
339
  <div>
340
  <div class="s-lbl" id="i18n-del-lbl">Delete All Chats</div>
341
  <div class="s-desc" id="i18n-del-desc">This action cannot be undone</div>
342
  </div>
343
+ <button class="btn-danger" onclick="clearAllChats()" id="i18n-del-btn">
344
+ <i data-lucide="trash-2" class="icon-sm" style="display:inline;vertical-align:middle;margin-right:4px;"></i>Delete
345
+ </button>
346
  </div>
347
+ <button class="btn-save" onclick="closeSettings()" id="i18n-save-btn">Close</button>
348
  </div>
349
  </div>
350
 
351
  <script>
352
  // โ•โ•โ•โ•โ•โ•โ•โ• i18n โ•โ•โ•โ•โ•โ•โ•โ•
353
  const i18n = {
354
+ en: { newChat:"โœฆ New Chat", chatsLabel:"CHATS", settings:"Settings", lang:"Language", dark:"Dark Mode", ttsLabel:"Auto-speak Responses", ttsDesc:"Read bot responses aloud automatically", del:"Delete All Chats", delDesc:"This action cannot be undone", delBtn:"Delete", saveBtn:"Close", placeholder:"Type your message... (Enter to send)", welcomeTitle:"Welcome to Genisi", welcomeSub:"Your smart assistant by AnesNT โ€” Batna ๐Ÿ‡ฉ๐Ÿ‡ฟ", c1:"What is AI?", c2:"Write Python code", c3:"Summarize a topic", c4:"Design an image in space ๐Ÿš€", errConnect:"Connection Error", memBadge:"Memory: {c}/{t} messages", stopMsg:"[Generation stopped by user]", vListening:"Listening... speak now", vProcessing:"Processing your voice...", vPlay:"Speaking response...", vEnd:"Done speaking", vNotSupported:"Voice input not supported in this browser" },
355
+ ar: { newChat:"โœฆ ู…ุญุงุฏุซุฉ ุฌุฏูŠุฏุฉ", chatsLabel:"ุงู„ู…ุญุงุฏุซุงุช", settings:"ุงู„ุฅุนุฏุงุฏุงุช", lang:"ุงู„ู„ุบุฉ", dark:"ุงู„ูˆุถุน ุงู„ู„ูŠู„ูŠ", ttsLabel:"ู‚ุฑุงุกุฉ ุงู„ุฑุฏูˆุฏ ุตูˆุชูŠุงู‹", ttsDesc:"ุงู‚ุฑุฃ ุฑุฏูˆุฏ ุงู„ุฐูƒุงุก ุงู„ุงุตุทู†ุงุนูŠ ุจุตูˆุช ุชู„ู‚ุงุฆูŠ", del:"ุญุฐู ุฌู…ูŠุน ุงู„ู…ุญุงุฏุซุงุช", delDesc:"ู„ุง ูŠู…ูƒู† ุงู„ุชุฑุงุฌุน ุนู† ู‡ุฐุง ุงู„ุฅุฌุฑุงุก", delBtn:"ุญุฐู", saveBtn:"ุฅุบู„ุงู‚", placeholder:"ุงูƒุชุจ ุฑุณุงู„ุชูƒ... (Enter ู„ู„ุฅุฑุณุงู„)", welcomeTitle:"ู…ุฑุญุจู‹ุง ููŠ Genisi", welcomeSub:"ุฃู†ุง GenisiุŒ ู…ุณุงุนุฏูƒ ุงู„ุฐูƒูŠ ู…ู† AnesNT โ€” ุจุงุชู†ุฉ ๐Ÿ‡ฉ๐Ÿ‡ฟ", c1:"ู…ุง ู‡ูˆ ุงู„ุฐูƒุงุก ุงู„ุงุตุทู†ุงุนูŠุŸ", c2:"ุงูƒุชุจ ูƒูˆุฏ ุจุงูŠุซูˆู†", c3:"ู„ุฎุต ู„ูŠ ู…ูˆุถูˆุนุงู‹", c4:"ุตู…ู… ุตูˆุฑุฉ ุจุงู„ูุถุงุก ๐Ÿš€", errConnect:"ุฎุทุฃ ููŠ ุงู„ุงุชุตุงู„", memBadge:"ุงู„ุฐุงูƒุฑุฉ: {c}/{t} ุฑุณุงุฆู„", stopMsg:"[ุชู… ุฅูŠู‚ุงู ุงู„ุชูˆู„ูŠุฏ]", vListening:"ุงุณุชู…ุน... ุชุญุฏุซ ุงู„ุขู†", vProcessing:"ุฌุงุฑูŠ ู…ุนุงู„ุฌุฉ ุตูˆุชูƒ...", vPlay:"ูŠู‚ุฑุฃ ุงู„ุฑุฏ ุงู„ุขู†...", vEnd:"ุงู†ุชู‡ุช ุงู„ู‚ุฑุงุกุฉ ุงู„ุตูˆุชูŠุฉ", vNotSupported:"ุงู„ุชุนุฑู ุนู„ู‰ ุงู„ูƒู„ุงู… ุบูŠุฑ ู…ุฏุนูˆู… ููŠ ู‡ุฐุง ุงู„ู…ุชุตูุญ" },
356
+ fr: { newChat:"โœฆ Nouveau", chatsLabel:"DISCUSSIONS", settings:"Paramรจtres", lang:"Langue", dark:"Mode Sombre", ttsLabel:"Lire les rรฉponses", ttsDesc:"Lire les rรฉponses du bot ร  voix haute", del:"Supprimer Tout", delDesc:"Action irrรฉversible", delBtn:"Supprimer", saveBtn:"Fermer", placeholder:"ร‰crivez votre message...", welcomeTitle:"Bienvenue sur Genisi", welcomeSub:"Votre assistant par AnesNT โ€” Batna ๐Ÿ‡ฉ๐Ÿ‡ฟ", c1:"Qu'est-ce que l'IA?", c2:"Code Python", c3:"Rรฉsumer un sujet", c4:"Crรฉer une image ๐Ÿš€", errConnect:"Erreur de connexion", memBadge:"Mรฉmoire: {c}/{t} msgs", stopMsg:"[Gรฉnรฉration arrรชtรฉe]", vListening:"ร‰coute... parlez maintenant", vProcessing:"Traitement de votre voix...", vPlay:"Lecture en cours...", vEnd:"Fin de la lecture", vNotSupported:"Reconnaissance vocale non supportรฉe" },
357
+ es: { newChat:"โœฆ Nuevo Chat", chatsLabel:"CHATS", settings:"Ajustes", lang:"Idioma", dark:"Modo Oscuro", ttsLabel:"Leer respuestas", ttsDesc:"Leer respuestas del bot en voz alta", del:"Borrar Todo", delDesc:"Acciรณn irreversible", delBtn:"Borrar", saveBtn:"Cerrar", placeholder:"Escribe tu mensaje...", welcomeTitle:"Bienvenido a Genisi", welcomeSub:"Tu asistente por AnesNT โ€” Batna ๐Ÿ‡ฉ๐Ÿ‡ฟ", c1:"ยฟQuรฉ es la IA?", c2:"Cรณdigo Python", c3:"Resumir", c4:"Diseรฑar imagen ๐Ÿš€", errConnect:"Error de conexiรณn", memBadge:"Memoria: {c}/{t} msgs", stopMsg:"[Generaciรณn detenida]", vListening:"Escuchando... habla ahora", vProcessing:"Procesando tu voz...", vPlay:"Leyendo respuesta...", vEnd:"Fin de la lectura", vNotSupported:"Reconocimiento de voz no soportado" }
358
  };
359
 
360
  let currentLang = localStorage.getItem('genisi_lang') || 'en';
 
363
  const t = i18n[currentLang];
364
  document.documentElement.dir = currentLang === 'ar' ? 'rtl' : 'ltr';
365
  document.documentElement.lang = currentLang;
366
+ const newChatBtn = document.getElementById('i18n-new-chat');
367
+ newChatBtn.querySelector('span').textContent = t.newChat;
368
  document.getElementById('i18n-chats-label').textContent = t.chatsLabel;
369
  document.getElementById('i18n-settings-title').textContent = t.settings;
370
  document.getElementById('i18n-lang-lbl').textContent = t.lang;
371
  document.getElementById('i18n-dark-lbl').textContent = t.dark;
372
+ document.getElementById('i18n-tts-lbl').textContent = t.ttsLabel;
373
+ document.getElementById('i18n-tts-desc').textContent = t.ttsDesc;
374
  document.getElementById('i18n-del-lbl').textContent = t.del;
375
  document.getElementById('i18n-del-desc').textContent = t.delDesc;
 
376
  document.getElementById('i18n-save-btn').textContent = t.saveBtn;
377
  document.getElementById('msg-input').placeholder = t.placeholder;
 
378
  if(!activeChatId) renderWelcome();
379
  renderChatList();
380
  }
381
+ function changeLanguage(val){ currentLang=val; localStorage.setItem('genisi_lang',val); applyI18n(); }
382
 
383
+ // โ•โ•โ•โ•โ•โ•โ•โ• STATE โ•โ•โ•โ•โ•โ•โ•โ•
384
+ const genId = () => Date.now().toString(36)+Math.random().toString(36).substring(2,6);
385
  let userId = localStorage.getItem('genisi_user_id');
386
+ if(!userId){ userId='user_'+genId(); localStorage.setItem('genisi_user_id',userId); }
387
 
388
+ let chats = JSON.parse(localStorage.getItem('genisi_chats')||'[]');
389
  let activeChatId = null;
390
  let isGenerating = false;
391
+ let pendingFiles = [];
392
  let currentAbortController = null;
393
+ let autoTTS = localStorage.getItem('genisi_tts') !== 'false';
394
+ let currentUtterance = null;
395
+
396
+ // โ•โ•โ•โ•โ•โ•โ•โ• SPEECH RECOGNITION (STT) โ•โ•โ•โ•โ•โ•โ•โ•
397
+ let recognition = null;
398
+ let isListening = false;
399
+
400
+ function initSpeechRecognition() {
401
+ const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
402
+ if (!SpeechRecognition) return null;
403
+ const rec = new SpeechRecognition();
404
+ rec.continuous = false;
405
+ rec.interimResults = true;
406
+ // Set language based on current UI language
407
+ const langMap = { en: 'en-US', ar: 'ar-DZ', fr: 'fr-FR', es: 'es-ES' };
408
+ rec.lang = langMap[currentLang] || 'en-US';
409
+
410
+ rec.onstart = () => {
411
+ isListening = true;
412
+ document.getElementById('stt-status').classList.add('visible');
413
+ document.getElementById('stt-text').textContent = i18n[currentLang].vListening;
414
+ const voiceBtn = document.getElementById('voice-btn');
415
+ voiceBtn.classList.add('recording');
416
+ // swap mic icon to mic-off
417
+ lucide.createIcons({ icons: { 'mic-off': lucide.icons['mic-off'] }, attrs: { class: 'icon' } });
418
+ const micIcon = document.getElementById('mic-icon');
419
+ micIcon.setAttribute('data-lucide', 'mic-off');
420
+ lucide.createIcons({ nameAttr: 'data-lucide', attrs: { class: 'icon' } });
421
+ };
422
+
423
+ rec.onresult = (event) => {
424
+ let interim = '';
425
+ let final = '';
426
+ for (let i = event.resultIndex; i < event.results.length; i++) {
427
+ if (event.results[i].isFinal) final += event.results[i][0].transcript;
428
+ else interim += event.results[i][0].transcript;
429
+ }
430
+ const input = document.getElementById('msg-input');
431
+ input.value = (final || interim);
432
+ autoResize(input);
433
+ if (final) document.getElementById('stt-text').textContent = final;
434
+ else document.getElementById('stt-text').textContent = interim || i18n[currentLang].vListening;
435
+ };
436
+
437
+ rec.onend = () => {
438
+ isListening = false;
439
+ document.getElementById('stt-status').classList.remove('visible');
440
+ const voiceBtn = document.getElementById('voice-btn');
441
+ voiceBtn.classList.remove('recording');
442
+ const micIcon = document.getElementById('mic-icon');
443
+ micIcon.setAttribute('data-lucide', 'mic');
444
+ lucide.createIcons({ nameAttr: 'data-lucide', attrs: { class: 'icon' } });
445
+ // Auto-send if there's text
446
+ const input = document.getElementById('msg-input');
447
+ if (input.value.trim()) sendMessage();
448
+ };
449
+
450
+ rec.onerror = (event) => {
451
+ console.error('STT error:', event.error);
452
+ isListening = false;
453
+ document.getElementById('stt-status').classList.remove('visible');
454
+ const voiceBtn = document.getElementById('voice-btn');
455
+ voiceBtn.classList.remove('recording');
456
+ const micIcon = document.getElementById('mic-icon');
457
+ micIcon.setAttribute('data-lucide', 'mic');
458
+ lucide.createIcons({ nameAttr: 'data-lucide', attrs: { class: 'icon' } });
459
+ };
460
+
461
+ return rec;
462
+ }
463
 
464
+ function toggleSpeechInput() {
465
+ const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
466
+ if (!SpeechRecognition) {
467
+ alert(i18n[currentLang].vNotSupported);
468
+ return;
469
+ }
470
+ if (isListening) {
471
+ stopSpeechInput();
472
+ return;
473
+ }
474
+ recognition = initSpeechRecognition();
475
+ if (recognition) recognition.start();
476
+ }
477
 
478
+ function stopSpeechInput() {
479
+ if (recognition && isListening) recognition.stop();
480
+ }
481
+
482
+ // โ•โ•โ•โ•โ•โ•โ•โ• TTS (Text-to-Speech) โ•โ•โ•โ•โ•โ•โ•โ•
483
+ function saveTtsSetting() {
484
+ autoTTS = document.getElementById('tts-toggle').checked;
485
+ localStorage.setItem('genisi_tts', autoTTS);
486
+ }
487
+
488
+ function speakText(text) {
489
+ if (!window.speechSynthesis) return;
490
+ // Cancel any ongoing speech
491
+ window.speechSynthesis.cancel();
492
+ // Strip markdown symbols for cleaner speech
493
+ const clean = text
494
+ .replace(/```[\s\S]*?```/g, 'code block.')
495
+ .replace(/`([^`]+)`/g, '$1')
496
+ .replace(/\*\*([^*]+)\*\*/g, '$1')
497
+ .replace(/\*([^*]+)\*/g, '$1')
498
+ .replace(/#{1,6}\s/g, '')
499
+ .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
500
+ .replace(/!\[([^\]]+)\]\([^)]+\)/g, 'image.')
501
+ .replace(/\n+/g, '. ')
502
+ .trim();
503
+
504
+ const utterance = new SpeechSynthesisUtterance(clean);
505
+ const langMap = { en: 'en-US', ar: 'ar-SA', fr: 'fr-FR', es: 'es-ES' };
506
+ utterance.lang = langMap[currentLang] || 'en-US';
507
+ utterance.rate = 1.0;
508
+ utterance.pitch = 1.0;
509
+ currentUtterance = utterance;
510
+ window.speechSynthesis.speak(utterance);
511
+ return utterance;
512
+ }
513
+
514
+ function stopTTS() {
515
+ if (window.speechSynthesis) window.speechSynthesis.cancel();
516
+ }
517
+
518
+ // โ•โ•โ•โ•โ•โ•โ•โ• MARKDOWN โ•โ•โ•โ•โ•โ•โ•โ•
519
  const renderer = new marked.Renderer();
520
  renderer.code = function(token) {
521
  const codeText = typeof token === 'string' ? token : token.text || '';
522
  const lang = typeof token === 'string' ? arguments[1] : token.lang || 'text';
523
+ const escapedCode = String(codeText).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;');
524
+ return `<div class="code-container"><div class="code-header"><span>${lang}</span><button class="copy-btn" onclick="copyCode(this,'${encodeURIComponent(codeText)}')"><i data-lucide="copy" class="icon-sm"></i> Copy</button></div><pre><code class="language-${lang}">${escapedCode}</code></pre></div>`;
525
  };
526
  renderer.table = function(header, body) {
527
+ if(typeof header==='object'&&header!==null&&'header' in header){
528
+ const token=header;
529
+ const hdr=token.header.map(cell=>`<th>${cell.tokens.map(t=>t.raw||'').join('')}</th>`).join('');
530
+ const rows=(token.rows||[]).map(row=>`<tr>${row.map(cell=>`<td>${cell.tokens.map(t=>t.raw||'').join('')}</td>`).join('')}</tr>`).join('');
531
  return `<div class="table-wrapper"><table><thead><tr>${hdr}</tr></thead><tbody>${rows}</tbody></table></div>`;
532
  }
533
  return `<div class="table-wrapper"><table><thead>${header}</thead><tbody>${body}</tbody></table></div>`;
534
  };
535
+ renderer.html = function(html){ return html; };
536
+ marked.setOptions({ renderer, breaks:true, gfm:true });
537
 
538
+ function safeMarked(text){
539
+ if(!text) return '';
540
+ return DOMPurify.sanitize(marked.parse(text),{USE_PROFILES:{html:true}});
 
541
  }
542
+ function renderKaTeX(el){
543
+ if(window.renderMathInElement) renderMathInElement(el,{delimiters:[{left:'$$',right:'$$',display:true},{left:'$',right:'$',display:false},{left:'\\(',right:'\\)',display:false},{left:'\\[',right:'\\]',display:true}],throwOnError:false});
 
 
 
544
  }
545
+ function copyCode(btn, encodedCode){
546
+ navigator.clipboard.writeText(decodeURIComponent(encodedCode)).then(()=>{
547
+ const orig = btn.innerHTML;
548
+ btn.innerHTML = '<i data-lucide="check" class="icon-sm" style="color:var(--accent)"></i> Copied!';
549
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon-sm'} });
550
+ setTimeout(()=>{btn.innerHTML=orig; lucide.createIcons({nameAttr:'data-lucide',attrs:{class:'icon-sm'}});},2000);
551
  });
552
  }
553
+ function removeGeminiCursor(){ document.querySelectorAll('.gemini-cursor').forEach(el=>el.remove()); }
554
 
555
+ // โ•โ•โ•โ•โ•โ•โ•โ• UTILS โ•โ•โ•โ•โ•โ•โ•โ•
556
+ const saveChats = () => localStorage.setItem('genisi_chats',JSON.stringify(chats));
557
+ const getChat = (id) => chats.find(c=>c.id===(id??activeChatId));
558
  function esc(t){ return String(t).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
559
+ function scrollToBottom(){ const area=document.getElementById('chat-area'); area.scrollTop=area.scrollHeight; }
560
+
561
+ async function handleFiles(files){
562
+ for(let f of files){
563
+ const isText = f.type.startsWith('text/')||f.name.match(/\.(py|js|html|css|json|md|txt|csv|cpp|java)$/i);
564
+ const reader = new FileReader();
565
+ reader.onload = (e)=>{
566
+ let data=e.target.result;
567
+ if(!isText) data=data.split(',')[1];
568
+ pendingFiles.push({name:f.name,type:f.type||'application/octet-stream',data,isText});
569
+ renderFileChips();
570
+ };
571
+ if(isText) reader.readAsText(f); else reader.readAsDataURL(f);
572
+ }
573
+ document.getElementById('file-input').value='';
 
574
  }
575
+ function renderFileChips(){
576
+ const c=document.getElementById('file-chips'); c.innerHTML='';
577
+ pendingFiles.forEach((f,idx)=>{
578
+ const icon = f.isText ? 'file-text' : 'image';
579
+ c.innerHTML += `<div class="file-chip"><i data-lucide="${icon}" class="icon-sm"></i>${f.name}<button onclick="removeFile(${idx})"><i data-lucide="x" class="icon-sm"></i></button></div>`;
580
+ });
581
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon-sm'} });
582
  }
583
+ function removeFile(idx){ pendingFiles.splice(idx,1); renderFileChips(); }
584
 
585
+ // โ•โ•โ•โ•โ•โ•โ•โ• THEME โ•โ•โ•โ•โ•โ•โ•โ•
586
  function applyTheme(t){
587
  document.documentElement.setAttribute('data-theme',t);
588
  localStorage.setItem('genisi_theme',t);
 
589
  document.getElementById('dark-toggle').checked = t==='dark';
590
+ const themeIcon = document.getElementById('theme-icon');
591
+ themeIcon.setAttribute('data-lucide', t==='dark'?'moon':'sun');
592
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon'} });
593
  }
594
  function toggleTheme(){ applyTheme(document.documentElement.getAttribute('data-theme')==='dark'?'light':'dark'); }
595
  function applyThemeToggle(){ applyTheme(document.getElementById('dark-toggle').checked?'dark':'light'); }
596
 
597
+ // โ•โ•โ•โ•โ•โ•โ•โ• SIDEBAR โ•โ•โ•โ•โ•โ•โ•โ•
598
+ function updateMenuIcon(){
599
+ const sidebar=document.getElementById('sidebar');
600
+ const menuIcon=document.getElementById('menu-icon');
601
+ menuIcon.setAttribute('data-lucide', sidebar.classList.contains('collapsed')?'menu':'x');
602
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon'} });
603
  }
604
+ function toggleSidebar(){ document.getElementById('sidebar').classList.toggle('collapsed'); updateMenuIcon(); }
605
+ function initSidebarState(){
606
+ const sidebar=document.getElementById('sidebar');
607
+ if(window.innerWidth<=640) sidebar.classList.add('collapsed');
 
 
 
 
608
  else sidebar.classList.remove('collapsed');
609
  updateMenuIcon();
610
  }
611
+ window.addEventListener('resize',()=>{
612
+ const sidebar=document.getElementById('sidebar');
613
+ if(window.innerWidth>640) sidebar.classList.remove('collapsed');
614
  else sidebar.classList.add('collapsed');
615
  updateMenuIcon();
616
  });
617
 
618
+ // โ•โ•โ•โ•โ•โ•โ•โ• SETTINGS โ•โ•โ•โ•โ•โ•โ•โ•
619
+ function openSettings(){ document.getElementById('settings-modal').classList.add('open'); document.getElementById('lang-select').value=currentLang; document.getElementById('tts-toggle').checked=autoTTS; }
620
  function closeSettings(){ document.getElementById('settings-modal').classList.remove('open'); }
621
 
622
+ // โ•โ•โ•โ•โ•โ•โ•โ• CHAT LIST โ•โ•โ•โ•โ•โ•โ•โ•
623
  function renderChatList(){
624
  const list=document.getElementById('chats-list'); list.innerHTML='';
625
  [...chats].reverse().forEach(chat=>{
626
  const div=document.createElement('div');
627
  div.className='chat-item'+(chat.id===activeChatId?' active':'');
628
+ div.innerHTML=`<i data-lucide="message-circle" class="icon-sm"></i><span class="ct">${esc(chat.title||'Chat')}</span><button class="del-btn" onclick="deleteChat('${chat.id}',event)"><i data-lucide="x" class="icon-sm"></i></button>`;
629
+ div.onclick = ()=>loadChat(chat.id);
630
  list.appendChild(div);
631
  });
632
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon-sm'} });
633
  }
634
+
635
  function renderWelcome(){
636
+ const t=i18n[currentLang];
637
  document.getElementById('topbar-title').textContent='Genisi AI';
638
  document.getElementById('chat-area').innerHTML=`<div class="welcome" id="welcome"><img src="https://copilot.microsoft.com/th/id/BCO.f29916dd-b0c1-4089-87cd-43d099a7d1a6.png" class="w-logo" alt="Genisi"/><div class="w-title">${t.welcomeTitle}</div><div class="w-sub">${t.welcomeSub}</div><div class="chips"><div class="chip" onclick="quickSend('${t.c1}')">${t.c1}</div><div class="chip" onclick="quickSend('${t.c2}')">${t.c2}</div><div class="chip" onclick="quickSend('${t.c3}')">${t.c3}</div><div class="chip" onclick="quickSend('${t.c4}')">${t.c4}</div></div></div>`;
639
  }
640
+
641
  function newChat(){ activeChatId=null; pendingFiles=[]; renderFileChips(); document.getElementById('msg-input').value=''; renderWelcome(); renderChatList(); }
642
+
643
  function loadChat(id){
644
  activeChatId=id; const chat=getChat(id); if(!chat) return;
645
  document.getElementById('topbar-title').textContent=chat.title;
646
  const area=document.getElementById('chat-area'); area.innerHTML='';
647
+ chat.history.forEach(entry=>{ appendBubble('user',entry.user,false,entry.uiFiles); appendBubble('bot',entry.bot,true); });
648
+ if(chat.history.length) appendMemBadge(chat.history.length,chat.history.length);
649
  scrollToBottom(); renderChatList();
650
  }
651
  function deleteChat(id,e){ e.stopPropagation(); chats=chats.filter(c=>c.id!==id); saveChats(); if(activeChatId===id) newChat(); else renderChatList(); }
652
  function clearAllChats(){ chats=[]; saveChats(); newChat(); closeSettings(); }
653
+ function stopGeneration(){ if(currentAbortController) currentAbortController.abort(); }
 
 
654
  function quickSend(text){ document.getElementById('msg-input').value=text; sendMessage(); }
655
  function handleKey(e){ if(e.key==='Enter'&&!e.shiftKey){e.preventDefault();sendMessage();} }
656
  function autoResize(el){ el.style.height='auto'; el.style.height=Math.min(el.scrollHeight,160)+'px'; }
657
 
658
+ // โ•โ•โ•โ•โ•โ•โ•โ• SEND MESSAGE โ•โ•โ•โ•โ•โ•โ•โ•
659
  async function sendMessage(){
660
+ if(isGenerating||isListening) return;
661
+ const input=document.getElementById('msg-input'); let text=input.value.trim();
662
+ if(!text&&pendingFiles.length===0) return;
663
+ const welcome=document.getElementById('welcome'); if(welcome) welcome.remove();
664
  input.value=''; input.style.height='auto';
665
+ stopTTS();
666
 
667
  if(!activeChatId){
668
+ activeChatId=genId();
669
+ const chatTitle=text?text.slice(0,35)+'...':(pendingFiles[0]?pendingFiles[0].name:'Chat');
670
+ chats.push({id:activeChatId,title:chatTitle,history:[]});
671
  document.getElementById('topbar-title').textContent=chatTitle;
672
  }
673
+ const chat=getChat();
674
+ const uiFiles=pendingFiles.map(f=>f.name); const binaryFiles=[];
675
+ pendingFiles.forEach(f=>{
676
+ if(f.isText){ text+=`\n\n\`\`\`${f.name.split('.').pop()}\n// File: ${f.name}\n${f.data}\n\`\`\``; }
677
+ else{ binaryFiles.push({name:f.name,mime_type:f.type,data:f.data}); }
678
  });
679
+ appendBubble('user',text,false,uiFiles);
680
+ pendingFiles=[]; renderFileChips();
681
+
682
+ isGenerating=true;
683
+ document.getElementById('send-btn').style.display='none';
684
+ document.getElementById('stop-btn').style.display='flex';
685
+ const botContentDiv=appendBubble('bot','',true);
686
+
687
+ const imageTriggers=["ุงุฑุณู…","ุตู…ู…","ุชุฎูŠู„","ุตูˆุฑุฉ ู„","draw","generate","imagine","create an image","ุชุตู…ูŠู…"];
688
+ const isImageRequest=imageTriggers.some(trigger=>text.toLowerCase().startsWith(trigger));
689
+ currentAbortController=new AbortController();
690
+ let fullBotResponse="";
691
 
692
  try {
693
+ const response=await fetch('/chat',{
694
+ method:'POST',headers:{'Content-Type':'application/json'},
695
+ body:JSON.stringify({user_id:userId,message:text,history:chat.history,files:binaryFiles}),
696
+ signal:currentAbortController.signal
697
  });
698
  if(!response.ok) throw new Error("Server Error");
699
+ const reader=response.body.getReader();
700
+ const decoder=new TextDecoder("utf-8");
701
+ while(true){
702
+ const{value,done}=await reader.read();
 
703
  if(done) break;
704
+ fullBotResponse+=decoder.decode(value,{stream:true});
705
+ let safeHtml=safeMarked(fullBotResponse);
706
+ botContentDiv.innerHTML=safeHtml;
707
+ if(isImageRequest&&!botContentDiv.querySelector('img')) botContentDiv.innerHTML+='<div class="skeleton-img">๐ŸŽจ ุฌุงุฑูŠ ุงู„ุชุฎูŠู„...</div>';
708
+ else botContentDiv.innerHTML+='<span class="gemini-cursor"></span>';
 
709
  renderKaTeX(botContentDiv); scrollToBottom();
710
  }
711
+ botContentDiv.innerHTML=safeMarked(fullBotResponse);
 
712
  renderKaTeX(botContentDiv);
713
+ // Add TTS play button
714
+ appendTTSBadge(botContentDiv, fullBotResponse);
715
+ // Auto TTS
716
+ if(autoTTS) speakText(fullBotResponse);
717
+ chat.history.push({user:text,bot:fullBotResponse,uiFiles});
718
+ saveChats(); appendMemBadge(chat.history.length,chat.history.length);
719
  } catch(err){
720
  removeGeminiCursor();
721
+ if(err.name==='AbortError'){
722
+ botContentDiv.innerHTML=safeMarked(fullBotResponse)+`<br><br><span style="color:var(--text3);font-style:italic;">${i18n[currentLang].stopMsg}</span>`;
723
+ renderKaTeX(botContentDiv);
724
+ chat.history.push({user:text,bot:fullBotResponse+"\n\n*"+i18n[currentLang].stopMsg+"*",uiFiles});
725
+ saveChats();
726
+ } else { botContentDiv.innerHTML=`<span style="color:var(--danger)">โš ๏ธ ${i18n[currentLang].errConnect}: ${err.message}</span>`; }
727
  } finally {
728
+ removeGeminiCursor(); isGenerating=false;
729
+ document.getElementById('send-btn').style.display='flex';
730
+ document.getElementById('stop-btn').style.display='none';
731
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon'} });
732
+ renderChatList(); scrollToBottom();
733
  }
734
  }
735
 
736
+ // โ•โ•โ•โ•โ•โ•โ•โ• TTS BADGE โ•โ•โ•โ•โ•โ•โ•โ•
737
+ function appendTTSBadge(container, text) {
738
+ if (!window.speechSynthesis) return;
739
+ const badge = document.createElement('div');
740
+ badge.className = 'tts-badge';
741
+ badge.title = 'Click to play / stop';
742
+ badge.innerHTML = `<div class="tts-wave"><span></span><span></span><span></span><span></span><span></span></div><span id="tts-label-${Date.now()}">Play</span>`;
743
+ let playing = false;
744
+ badge.onclick = () => {
745
+ if (playing) {
746
+ stopTTS(); playing = false;
747
+ badge.querySelector('span:last-child').textContent = 'Play';
748
+ } else {
749
+ const utt = speakText(text); playing = true;
750
+ badge.querySelector('span:last-child').textContent = i18n[currentLang].vPlay;
751
+ if (utt) utt.onend = () => { playing=false; badge.querySelector('span:last-child').textContent='Play'; };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
752
  }
753
+ };
754
+ container.appendChild(badge);
755
  }
756
 
757
+ // โ•โ•โ•โ•โ•โ•โ•โ• BUBBLES โ•โ•โ•โ•โ•โ•โ•โ•
758
+ function appendBubble(role,text,isMarkdown,filesList=[]){
759
  const area=document.getElementById('chat-area');
760
  const row=document.createElement('div'); row.className=`msg-row ${role}`;
761
  const av=document.createElement('div'); av.className='msg-av';
762
+ if(role==='bot') av.innerHTML=`<img src="https://copilot.microsoft.com/th/id/BCO.f29916dd-b0c1-4089-87cd-43d099a7d1a6.png" alt="G"/>`;
763
+ else av.innerHTML=`<i data-lucide="user" class="icon"></i>`;
764
  const bub=document.createElement('div'); bub.className='bubble';
765
+ if(filesList&&filesList.length>0) filesList.forEach(name=>{ bub.innerHTML+=`<div class="file-prev"><i data-lucide="paperclip" class="icon-sm"></i>${esc(name)}</div>`; });
766
+ const contentDiv=document.createElement('div');
767
+ contentDiv.dir='auto'; contentDiv.style.unicodeBidi='plaintext';
768
+ if(text){
769
+ contentDiv.innerHTML=isMarkdown?safeMarked(text):esc(text).replace(/\n/g,'<br/>');
770
+ if(isMarkdown) renderKaTeX(contentDiv);
 
 
771
  }
772
+ bub.appendChild(contentDiv); row.appendChild(av); row.appendChild(bub); area.appendChild(row);
773
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon'} });
774
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon-sm'} });
775
+ if(role==='bot'){
776
+ const images=bub.querySelectorAll('img');
777
+ if(images.length) Promise.all(Array.from(images).map(img=>img.complete?Promise.resolve():new Promise(r=>img.onload=r))).then(()=>scrollToBottom());
778
+ else scrollToBottom();
779
  } else scrollToBottom();
780
+ return contentDiv;
781
  }
782
 
783
+ function appendMemBadge(count,total){
784
  const area=document.getElementById('chat-area'); const b=document.createElement('div'); b.className='mem-badge';
785
+ b.innerHTML=`<i data-lucide="brain" class="icon-sm"></i>${i18n[currentLang].memBadge.replace('{c}',count).replace('{t}',total)}`;
786
+ area.appendChild(b);
787
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon-sm'} });
788
+ scrollToBottom();
789
  }
790
 
791
  // โ•โ•โ•โ•โ•โ•โ•โ• INIT โ•โ•โ•โ•โ•โ•โ•โ•
792
+ window.addEventListener('DOMContentLoaded', ()=>{
793
+ applyTheme(localStorage.getItem('genisi_theme')||'dark');
794
+ document.getElementById('lang-select').value=currentLang;
795
+ document.getElementById('tts-toggle').checked=autoTTS;
796
+ applyI18n();
797
+ initSidebarState();
798
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon'} });
799
+ lucide.createIcons({ nameAttr:'data-lucide', attrs:{class:'icon-sm'} });
800
+ });
801
  </script>
802
  </body>
803
  </html>