File size: 20,980 Bytes
416c0bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>چت بات هوش مصنوعی با پنل رمزدار</title>
  <style>
    /* Reset and base */
    *, *::before, *::after { box-sizing: border-box; }
    html, body {
      margin: 0; padding: 0;
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      direction: rtl;
      background: #ffffff;
      color: #6b7280;
      font-size: 16px;
      line-height: 1.5;
      min-height: 100vh;
    }
    a { color: #2563eb; text-decoration: none; }
    a:hover, button:hover { text-decoration: underline; cursor: pointer; }

    /* Container */
    .container {
      max-width: 1200px;
      margin: 3rem auto 5rem;
      padding: 0 1rem;
    }

    /* Header & Navigation */
    header {
      position: sticky;
      top: 0;
      background: white;
      border-bottom: 1px solid #e5e7eb;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 1rem 2rem;
      z-index: 1000;
    }
    header .logo {
      font-size: 2rem;
      font-weight: 700;
      color: #111827;
      user-select: none;
    }
    nav a {
      margin-left: 2rem;
      font-weight: 600;
      color: #6b7280;
      transition: color 0.3s ease;
      font-size: 1rem;
    }
    nav a:hover { color: #111827; }
    nav .cta-btn {
      background: #111827;
      color: white;
      padding: 0.5rem 1.5rem;
      border-radius: 0.5rem;
      font-weight: 700;
      font-size: 1rem;
      text-decoration: none;
      user-select: none;
      transition: background-color 0.3s ease;
    }
    nav .cta-btn:hover {
      background: #374151;
    }

    /* Hero Section */
    .hero {
      text-align: center;
      margin-bottom: 4rem;
    }
    .hero h1 {
      font-weight: 800;
      font-size: 48px;
      color: #111827;
      margin-bottom: 1rem;
      user-select: none;
    }
    .hero p {
      font-size: 18px;
      color: #6b7280;
      max-width: 600px;
      margin: 0 auto 2rem;
    }
    .hero button {
      font-weight: 700;
      font-size: 18px;
      padding: 14px 36px;
      border-radius: 0.75rem;
      border: none;
      background: #111827;
      color: white;
      user-select: none;
      transition: background-color 0.3s ease;
    }
    .hero button:hover {
      background: #4b5563;
    }

    /* Chatbot widget */
    #chatbot {
      position: fixed;
      bottom: 24px;
      left: 24px;
      width: 350px;
      max-height: 600px;
      background: white;
      box-shadow: 0 4px 24px rgba(0,0,0,0.1);
      border-radius: 0.75rem;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      z-index: 10000;
      font-size: 16px;
      user-select: text;
      transform: translateY(120%);
      transition: transform 0.4s ease;
    }
    #chatbot.open {
      transform: translateY(0);
    }
    #chatbot-header {
      background: linear-gradient(45deg, #0088cc, #e1306c);
      color: white;
      font-weight: 700;
      font-size: 1.25rem;
      padding: 1rem 1.5rem;
      border-top-left-radius: 0.75rem;
      border-top-right-radius: 0.75rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      user-select: none;
    }
    #chatbot-header #bot-name {
      max-width: 80%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    #chatbot-close-btn {
      background: transparent;
      border: none;
      color: white;
      font-size: 1.5rem;
      line-height: 1;
      cursor: pointer;
      transition: color 0.3s ease;
    }
    #chatbot-close-btn:hover {
      color: #ffcccb;
    }
    #chat-messages {
      flex: 1;
      padding: 1rem;
      overflow-y: auto;
      background: #fafafa;
      display: flex;
      flex-direction: column;
    }
    .message {
      max-width: 80%;
      margin-bottom: 0.75rem;
      padding: 12px 16px;
      border-radius: 12px;
      font-size: 14px;
      line-height: 1.4;
      white-space: pre-wrap;
      word-break: break-word;
      box-shadow: 0 1px 4px rgb(0 0 0 / 0.05);
      animation: fadeInUp 0.3s ease forwards;
      user-select: text;
    }
    @keyframes fadeInUp {
      from {opacity: 0; transform: translateY(10px);} to {opacity:1; transform: translateY(0);}
    }
    .message.user {
      background: linear-gradient(135deg, #e1306c, #0088cc);
      color: white;
      align-self: flex-end;
      border-bottom-right-radius: 4px;
    }
    .message.bot {
      background: white;
      color: #374151;
      border: 1.5px solid #0088cc;
      align-self: flex-start;
      border-bottom-left-radius: 4px;
    }
    #chat-input-form {
      display: flex;
      border-top: 1.5px solid #0088cc;
      background: white;
      padding: 0.75rem 1rem;
    }
    #chat-input {
      flex: 1;
      border-radius: 0.5rem;
      border: 1px solid #ddd;
      padding: 10px 14px;
      font-size: 14px;
      font-family: inherit;
      resize: none;
      height: 50px;
      line-height: 1.3;
      outline-offset: 2px;
      color: #374151;
    }
    #chat-input::placeholder {
      color: #a1a1aa;
    }
    #chat-send-btn {
      background: #0088cc;
      border: none;
      color: white;
      font-weight: 700;
      font-size: 16px;
      padding: 0 18px;
      margin-left: 12px;
      border-radius: 0.5rem;
      cursor: pointer;
      user-select: none;
      transition: background-color 0.3s ease;
    }
    #chat-send-btn:hover:not(:disabled) {
      background: #e1306c;
    }
    #chat-send-btn:disabled {
      background: #ccc;
      cursor: not-allowed;
    }

    /* Typing indicator */
    .typing-indicator {
      display: flex;
      gap: 6px;
      margin-left: 4px;
      align-items: center;
      padding: 12px 16px;
    }
    .typing-indicator span {
      width: 8px;
      height: 8px;
      background: #0088cc;
      border-radius: 50%;
      opacity: 0.4;
      animation: typing-blink 1.4s infinite;
    }
    .typing-indicator span:nth-child(2) {
      animation-delay: 0.2s;
    }
    .typing-indicator span:nth-child(3) {
      animation-delay: 0.4s;
    }
    @keyframes typing-blink {
      0%, 80%, 100% {opacity: 0.4;}
      40% {opacity: 1;}
    }

    /* Developer Panel Overlay */
    #dev-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.75);
      backdrop-filter: blur(4px);
      display: none;
      justify-content: center;
      align-items: center;
      z-index: 11000;
      user-select: text;
    }
    #dev-overlay.active {
      display: flex;
    }
    #dev-panel {
      background: white;
      width: 750px;
      max-width: 95vw;
      max-height: 90vh;
      border-radius: 0.75rem;
      box-shadow: 0 10px 40px rgb(0 0 0 / 0.15);
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
    #dev-header {
      background: linear-gradient(45deg, #0088cc, #e1306c);
      color: white;
      font-size: 1.75rem;
      font-weight: 700;
      padding: 1rem 2rem;
      user-select: none;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    #dev-close-btn {
      background: transparent;
      border: none;
      font-size: 1.5rem;
      color: white;
      cursor: pointer;
      transition: color 0.3s ease;
    }
    #dev-close-btn:hover {
      color: #fca5a5;
    }
    #dev-content {
      flex: 1;
      overflow-y: auto;
      padding: 1.5rem 2rem;
      color: #374151;
      font-size: 15px;
    }
    .tabs {
      display: flex;
      border-bottom: 2px solid #ddd;
      margin-bottom: 1rem;
      gap: 1rem;
      user-select: none;
    }
    .tabs button {
      padding: 12px 20px;
      border: none;
      border-bottom: 4px solid transparent;
      font-weight: 600;
      font-size: 1rem;
      background: transparent;
      color: #6b7280;
      cursor: pointer;
      transition: border-color 0.3s ease, color 0.3s ease;
      border-radius: 0.5rem 0.5rem 0 0;
    }
    .tabs button.active {
      border-color: #e1306c;
      color: #e1306c;
      font-weight: 700;
    }
    .tabs button:hover:not(.active) {
      color: #0088cc;
    }
    .tab-panel {
      display: none;
    }
    .tab-panel.active {
      display: block;
    }
    form label {
      display: block;
      margin-top: 1rem;
      margin-bottom: .5rem;
      font-weight: 700;
      color: #374151;
    }
    input[type=text], input[type=url], textarea, select, input[type=password] {
      width: 100%;
      padding: 10px 14px;
      border: 1.5px solid #ddd;
      border-radius: 0.5rem;
      font-size: 15px;
      resize: vertical;
      font-family: inherit;
    }
    textarea {
      min-height: 100px;
    }
    button[type=submit], button.remove-btn, button.add-btn {
      margin-top: 1.25rem;
      padding: 10px 20px;
      font-weight: 700;
      font-size: 1rem;
      border-radius: 0.5rem;
      border: none;
      cursor: pointer;
      user-select: none;
      transition: background-color 0.3s ease;
    }
    button[type=submit] {
      background: linear-gradient(45deg, #0088cc, #e1306c);
      color: white;
    }
    button[type=submit]:hover {
      background: linear-gradient(45deg, #e1306c, #0088cc);
    }
    button.remove-btn {
      background: #ef4444;
      color: white;
      padding: 6px 12px;
      font-size: 14px;
    }
    button.remove-btn:hover {
      background: #b91c1c;
    }
    button.add-btn {
      background: #22c55e;
      color: white;
    }
    button.add-btn:hover {
      background: #15803d;
    }
    table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 1rem;
    }
    th, td {
      padding: 12px 10px;
      border-bottom: 1px solid #eee;
      text-align: right;
      font-weight: 600;
      font-size: 14px;
      color: #4b5563;
    }
    th {
      background: #f9fafb;
      color: #374151;
    }
    tr:hover td {
      background: #f3f4f6;
    }
    #password-message {
      margin-top: 0.5rem;
      min-height: 1.25rem;
      font-weight: 700;
    }
    #password-message.error { color: #ef4444; }
    #password-message.success { color: #22c55e; }
  </style>
</head>
<body>

<header>
  <div class="logo" aria-label="لوگوی چت بات هوش مصنوعی">AI ChatBot</div>
  <nav>
    <a href="#features">ویژگی‌ها</a>
    <a href="#usage">نحوه استفاده</a>
    <a href="#contact">تماس</a>
    <a href="javascript:void(0)" id="open-chat-btn" class="cta-btn" aria-expanded="false" aria-controls="chatbot">شروع چت</a>
  </nav>
</header>

<main class="container" role="main">
  <section id="features" aria-label="ویژگی های چت بات">
    <h1>چت بات هوش مصنوعی با پنل توسعه‌دهنده رمزدار</h1>
    <p>افزودن پایگاه دانش، مدیریت چند ربات، انتخاب تم و تنظیمات پیشرفته بدون نیاز به سرور و با استفاده از هوش مصنوعی Hugging Face.</p>
  </section>

  <section id="usage" aria-label="نحوه استفاده">
    <h2>کد کوتاه برای افزودن به سایت شما:</h2>
    <pre style="background:#f3f4f6;padding:1rem;border-radius:0.5rem;user-select:text;">
&lt;div id="ai-chatbot-container"&gt;&lt;/div&gt;
&lt;script src="PATH_TO_THIS_FILE_OR_EMBED_JS" defer&gt;&lt;/script&gt;
    </pre>
  </section>

  <section id="contact" aria-label="تماس">
    <h2>تماس با ما</h2>
    <p>برای همکاری، میزبانی یا راهنمایی، ایمیل بزنید: <a href="mailto:support@example.com">support@example.com</a></p>
  </section>
</main>

<!-- Chatbot Widget -->
<div id="chatbot" role="dialog" aria-modal="true" aria-label="پنجره چت بات هوش مصنوعی" tabindex="-1" aria-hidden="true" >
  <div id="chatbot-header">
    <span id="bot-name" aria-live="polite" aria-atomic="true" aria-relevant="additions">ربات من</span>
    <button aria-label="بستن چت بات" id="chatbot-close-btn" title="بستن چت بات">&times;</button>
  </div>
  <div id="chat-messages" tabindex="0" aria-live="polite" aria-atomic="false"></div>
  <form id="chat-input-form" aria-label="فرم ارسال پیام چت">
    <textarea id="chat-input" autocomplete="off" placeholder="پیام خود را اینجا بنویسید..." rows="2" required></textarea>
    <button type="submit" id="chat-send-btn" disabled>ارسال</button>
  </form>
  <button id="open-dev-panel-btn" title="پنل توسعه‌دهنده" aria-label="باز کردن پنل توسعه‌دهنده" style="position:absolute;top:0.75rem;left:0.75rem;background:none;border:none;font-size:1.5rem;color:white;cursor:pointer;user-select:none;">⚙️</button>
</div>

<!-- Developer Panel Overlay -->
<div id="dev-overlay" role="dialog" aria-modal="true" aria-labelledby="dev-header-title" tabindex="-1" aria-hidden="true">
  <div id="dev-panel">
    <div id="dev-header">
      <span id="dev-header-title">پنل توسعه‌دهنده</span>
      <button id="dev-close-btn" aria-label="بستن پنل توسعه‌دهنده" title="بستن پنل توسعه‌دهنده">&times;</button>
    </div>
    <div id="dev-content">
      <div class="tabs" role="tablist" aria-label="تب‌های پنل توسعه‌دهنده">
        <button role="tab" aria-selected="true" aria-controls="tab-kb" id="tab-kb-btn" class="active">پایگاه دانش</button>
        <button role="tab" aria-selected="false" aria-controls="tab-settings" id="tab-settings-btn">تنظیمات ربات</button>
        <button role="tab" aria-selected="false" aria-controls="tab-bots" id="tab-bots-btn">ربات‌ها</button>
      </div>
      <section id="tab-kb" class="tab-panel active" role="tabpanel" aria-labelledby="tab-kb-btn" tabindex="0">
        <form id="kb-form" aria-label="فرم افزودن سوال و پاسخ به پایگاه دانش">
          <label for="kb-question">سوال</label>
          <input type="text" id="kb-question" autocomplete="off" placeholder="سوال خود را وارد کنید" required/>
          <label for="kb-answer">پاسخ</label>
          <textarea id="kb-answer" placeholder="پاسخ خود را وارد کنید" required></textarea>
          <button type="submit">افزودن به پایگاه دانش</button>
        </form>
        <table aria-label="لیست سوال و پاسخ‌ها">
          <thead>
            <tr><th>سوال</th><th>پاسخ</th><th>حذف</th></tr>
          </thead>
          <tbody id="kb-list"></tbody>
        </table>
      </section>
      <section id="tab-settings" class="tab-panel" role="tabpanel" aria-labelledby="tab-settings-btn" tabindex="0" hidden>
        <form id="settings-form" aria-label="فرم تنظیمات ربات">
          <label for="bot-name-input">نام ربات</label>
          <input type="text" id="bot-name-input" placeholder="نام ربات" />
          <label for="response-type-select">نوع پاسخ‌دهی ربات</label>
          <select id="response-type-select" aria-label="نوع پاسخ‌دهی ربات">
            <option value="knowledge-base">پاسخ بر اساس پایگاه دانش</option>
            <option value="ai">پاسخ با هوش مصنوعی</option>
            <option value="hybrid">ترکیبی از هر دو</option>
          </select>
          <label for="allow-profanity-select">مجاز بودن فحش</label>
          <select id="allow-profanity-select" aria-label="تنظیم مجاز بودن فحش">
            <option value="false" selected>غیرمجاز</option>
            <option value="true">مجاز</option>
          </select>
          <label for="bot-image-url">آدرس تصویر ربات (URL)</label>
          <input type="url" id="bot-image-url" placeholder="https://example.com/avatar.png" />
          <fieldset style="border:1px solid #ddd; padding:1rem; margin-top:2rem; border-radius:0.5rem;">
            <legend>تغییر رمز پنل توسعه‌دهنده</legend>
            <label for="mother-password">رمز مادر (برای غیرفعال کردن رمز)</label>
            <input type="password" id="mother-password" placeholder="رمز مادر" autocomplete="new-password" />
            <label for="current-password">رمز فعلی</label>
            <input type="password" id="current-password" placeholder="رمز فعلی" autocomplete="current-password" />
            <label for="new-password">رمز جدید</label>
            <input type="password" id="new-password" placeholder="رمز جدید" autocomplete="new-password" />
            <label for="confirm-password">تکرار رمز جدید</label>
            <input type="password" id="confirm-password" placeholder="تکرار رمز جدید" />
            <button type="button" id="change-password-btn">تغییر رمز</button>
            <p id="password-message" aria-live="polite"></p>
          </fieldset>
          <button type="submit">ذخیره تنظیمات</button>
        </form>
      </section>
      <section id="tab-bots" class="tab-panel" role="tabpanel" aria-labelledby="tab-bots-btn" tabindex="0" hidden>
        <button id="create-bot-btn" class="add-btn">ساخت ربات جدید</button>
        <table aria-label="لیست ربات‌ها">
          <thead>
            <tr><th>نام ربات</th><th>فعالسازی</th><th>حذف</th></tr>
          </thead>
          <tbody id="bots-list"></tbody>
        </table>
      </section>
    </div>
  </div>
</div>

<script>
  (async () => {
    // Utility
    const $ = id => document.getElementById(id);
    function delay(ms) { return new Promise(r => setTimeout(r, ms)); }
    async function sha256(msg) {
      const buf = new TextEncoder().encode(msg);
      const hash = await crypto.subtle.digest('SHA-256', buf);
      return Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2,'0')).join('');
    }
    function sanitize(str) {
      const div = document.createElement('div');
      div.textContent = str;
      return div.innerHTML;
    }

    // DOM Elements
    const chatbot = $('chatbot');
    const openChatBtn = $('open-chat-btn');
    const closeChatBtn = $('chatbot-close-btn');
    const chatMessages = $('chat-messages');
    const chatInput = $('chat-input');
    const chatSendBtn = $('chat-send-btn');
    const openDevPanelBtn = $('open-dev-panel-btn');
    const devOverlay = $('dev-overlay');
    const devCloseBtn = $('dev-close-btn');

    // Developer panel elements
    const tabs = {
      kbBtn: $('tab-kb-btn'),
      settingsBtn: $('tab-settings-btn'),
      botsBtn: $('tab-bots-btn'),
      kbPanel: $('tab-kb'),
      settingsPanel: $('tab-settings'),
      botsPanel: $('tab-bots'),
    };
    const kbForm = $('kb-form');
    const kbQuestion = $('kb-question');
    const kbAnswer = $('kb-answer');
    const kbList = $('kb-list');

    const settingsForm = $('settings-form');
    const botNameInput = $('bot-name-input');
    const responseTypeSelect = $('response-type-select');
    const allowProfanitySelect = $('allow-profanity-select');
    const botImageUrlInput = $('bot-image-url');
    const motherPasswordInput = $('mother-password');
    const currentPasswordInput = $('current-password');
    const newPasswordInput = $('new-password');
    const confirmPasswordInput = $('confirm-password');
    const changePasswordBtn = $('change-password-btn');
    const passwordMessage = $('password-message');

    const botsList = $('bots-list');
    const createBotBtn = $('create-bot-btn');

    const botNameDisplay = $('bot-name');

    // Persistent keys and default passwords
    const STORAGE_KEY = 'ai_chatbot_app_state';
    const PASSWORD_HASH_KEY = 'ai_chatbot_dev_password_hash';
    const MOTHER_PASS_HASH_KEY = 'ai_chatbot_mother_pass_hash';
    const DEFAULT_PASSWORD = '1234';
    const MASTER_PASSWORD = '12340000';

    // State
    let state = {
      bots: {},
      activeBotId: '',
      devPanelOpen: false,
      authenticated: false
    };

    // Initialize default bot
    function defaultBotTemplate() {
      return {
        id: 'default-bot',
        name: 'ربات من',
        kb: [],
        settings: {
          responseType: 'hybrid',
          allowProfanity: false,
          botImageUrl: ''
        }
      };
    }

    // Load state from localStorage
    async function loadState() {
      const data = localStorage.getItem(STORAGE_KEY);
      if (data) {
        try {
          state = JSON.parse(data);
          if (!state.bots || Object.keys(state.bots).length === 0) {
            state.bots = {[defaultBotTemplate().id]: defaultBotTemplate()};
            state.activeBotId = defaultBotTemplate().id;
          }
          if (!state.activeBotId || !state.bots[state.activeBotId]) {
            state.activeBotId = Obje