File size: 57,231 Bytes
15c0e5a
 
 
 
9f81cba
 
0e14eed
 
15c0e5a
 
0e14eed
 
15c0e5a
5533425
0e14eed
15c0e5a
 
 
 
 
 
0e14eed
15c0e5a
 
228f8fd
 
 
 
 
 
6acba78
 
0e14eed
 
 
 
 
 
 
 
 
 
9f81cba
0e14eed
 
228f8fd
 
 
 
442f140
15c0e5a
 
 
 
0e14eed
15c0e5a
0e14eed
 
228f8fd
0e14eed
 
53057ed
f93bef0
228f8fd
9f81cba
 
 
 
 
0e14eed
228f8fd
 
 
 
15c0e5a
0e14eed
 
6acba78
0e14eed
f93bef0
 
9f81cba
 
 
228f8fd
0e14eed
 
 
15c0e5a
0e14eed
 
 
 
 
 
 
9f81cba
0e14eed
 
 
 
228f8fd
0e14eed
442f140
0e14eed
 
 
 
53057ed
0e14eed
 
 
 
 
 
 
53057ed
0e14eed
 
 
 
 
 
9f81cba
0e14eed
9f81cba
 
0e14eed
 
 
 
 
 
 
 
9f81cba
0e14eed
9f81cba
 
0e14eed
 
53057ed
0e14eed
9f81cba
0e14eed
 
 
9f81cba
0e14eed
53057ed
 
0e14eed
 
 
 
 
 
 
 
 
 
9f81cba
0e14eed
 
 
228f8fd
 
0e14eed
 
 
 
 
 
53057ed
0e14eed
 
 
 
53057ed
 
 
0e14eed
228f8fd
 
0e14eed
 
228f8fd
0e14eed
 
 
 
 
228f8fd
 
 
0e14eed
53057ed
0e14eed
 
 
228f8fd
 
0e14eed
 
 
 
228f8fd
0e14eed
 
 
 
228f8fd
 
 
0e14eed
228f8fd
0e14eed
53057ed
0e14eed
228f8fd
 
0e14eed
 
 
53057ed
0e14eed
53057ed
0e14eed
53057ed
 
0e14eed
 
 
228f8fd
0e14eed
 
 
 
 
 
 
 
53057ed
0e14eed
 
228f8fd
 
0e14eed
 
 
 
 
 
 
 
 
 
 
9f81cba
0e14eed
 
 
53057ed
 
9f81cba
 
 
 
 
 
 
f93bef0
 
 
9f81cba
 
 
 
 
 
 
 
 
53057ed
f93bef0
228f8fd
53057ed
 
 
 
 
 
 
 
 
f93bef0
228f8fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f93bef0
 
 
 
 
 
228f8fd
 
 
 
 
 
 
 
 
 
9f81cba
 
228f8fd
f93bef0
 
 
 
 
228f8fd
 
 
 
 
 
 
9f81cba
 
228f8fd
f93bef0
 
 
 
 
228f8fd
 
 
 
9f81cba
 
228f8fd
f93bef0
 
 
 
228f8fd
 
 
 
9f81cba
 
228f8fd
f93bef0
 
 
 
 
228f8fd
 
 
 
 
 
9f81cba
 
f93bef0
53057ed
 
b88039c
15c0e5a
 
9f81cba
6c8b745
0e14eed
9f81cba
0e14eed
9f81cba
 
 
 
 
 
 
0e14eed
53057ed
9f81cba
f93bef0
9f81cba
 
 
f93bef0
 
9f81cba
 
 
 
 
 
 
 
 
0e14eed
 
310e7b7
53057ed
9f81cba
 
 
 
 
 
 
310e7b7
9f81cba
0e14eed
53057ed
9f81cba
0e14eed
9f81cba
 
0e14eed
9f81cba
 
 
 
 
 
 
 
 
 
 
 
0e14eed
9f81cba
 
 
0e14eed
 
 
f93bef0
0e14eed
9f81cba
 
 
 
 
 
 
 
 
0e14eed
 
 
53057ed
9f81cba
 
 
 
 
 
 
 
 
 
0e14eed
 
 
9f81cba
 
 
 
 
 
 
 
 
 
0e14eed
 
 
9f81cba
 
 
 
 
 
 
 
 
 
0e14eed
 
 
15c0e5a
9f81cba
 
53057ed
 
 
 
0e14eed
 
 
228f8fd
9f81cba
 
 
 
 
 
 
 
 
 
f93bef0
9f81cba
 
53057ed
0e14eed
9f81cba
0e14eed
 
9f81cba
 
0e14eed
 
 
6acba78
9f81cba
 
 
 
 
0e14eed
6acba78
 
15c0e5a
9f81cba
 
 
0e14eed
 
9f81cba
 
6acba78
228f8fd
 
 
 
 
15c0e5a
 
0e14eed
15c0e5a
228f8fd
9f81cba
 
 
 
 
 
 
 
 
 
 
 
 
 
53057ed
9f81cba
 
53057ed
9f81cba
 
0e14eed
9f81cba
 
0e14eed
 
 
228f8fd
 
9f81cba
 
228f8fd
 
9f81cba
 
 
 
 
 
 
228f8fd
9f81cba
 
 
 
 
 
0e14eed
 
228f8fd
 
 
9f81cba
 
 
228f8fd
9f81cba
 
 
0e14eed
 
 
228f8fd
 
9f81cba
 
 
 
 
0e14eed
53057ed
0e14eed
442f140
228f8fd
 
9f81cba
 
 
 
 
 
 
 
 
0e14eed
 
 
442f140
15c0e5a
228f8fd
9f81cba
 
 
 
 
 
 
 
228f8fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e14eed
15c0e5a
 
310e7b7
0e14eed
5533425
 
15c0e5a
6c8b745
0e14eed
 
9f81cba
6c8b745
228f8fd
6c8b745
15c0e5a
9f81cba
228f8fd
9f81cba
 
 
 
228f8fd
0e14eed
 
 
9f81cba
0e14eed
 
 
 
 
5533425
0e14eed
 
 
 
310e7b7
9f81cba
 
 
 
228f8fd
 
9f81cba
310e7b7
 
9f81cba
0e14eed
 
53057ed
0e14eed
 
9f81cba
 
 
 
0e14eed
 
 
 
 
 
 
 
 
 
 
228f8fd
0e14eed
 
 
 
 
9f81cba
0e14eed
9f81cba
0e14eed
 
9f81cba
 
0e14eed
 
 
310e7b7
 
 
 
 
 
 
 
53057ed
310e7b7
 
 
 
 
 
 
53057ed
228f8fd
e198e3b
 
310e7b7
 
 
228f8fd
9f81cba
 
310e7b7
228f8fd
0e14eed
 
310e7b7
 
 
228f8fd
310e7b7
 
228f8fd
15c0e5a
 
 
53057ed
5533425
 
 
 
 
 
15c0e5a
 
 
5533425
15c0e5a
5533425
15c0e5a
5533425
15c0e5a
 
5533425
15c0e5a
 
5533425
 
 
 
 
 
6c8b745
5533425
 
310e7b7
5533425
 
 
6c8b745
5533425
6c8b745
 
5533425
310e7b7
5533425
6c8b745
5533425
0e14eed
 
 
 
 
228f8fd
0e14eed
 
 
 
 
228f8fd
0e14eed
53057ed
15c0e5a
 
 
5533425
 
 
228f8fd
5533425
15c0e5a
5533425
 
15c0e5a
5533425
 
 
 
15c0e5a
 
 
5533425
15c0e5a
 
53057ed
15c0e5a
5533425
15c0e5a
 
 
5533425
 
15c0e5a
5533425
 
 
15c0e5a
5533425
15c0e5a
5533425
15c0e5a
5533425
15c0e5a
 
 
5533425
 
 
310e7b7
 
5533425
6c8b745
5533425
228f8fd
 
9f81cba
 
0e14eed
53057ed
15c0e5a
5533425
15c0e5a
5533425
15c0e5a
 
5533425
 
 
 
 
15c0e5a
5533425
15c0e5a
 
 
5533425
 
15c0e5a
 
5533425
 
 
 
 
15c0e5a
5533425
15c0e5a
5533425
 
15c0e5a
 
 
5533425
 
0e14eed
5533425
 
 
 
228f8fd
 
5533425
 
9f81cba
 
0e14eed
 
 
5533425
 
 
 
228f8fd
9f81cba
 
5533425
9f81cba
5533425
 
 
 
 
 
 
228f8fd
 
5533425
6c8b745
 
5533425
 
15c0e5a
9f81cba
228f8fd
9f81cba
 
 
228f8fd
 
9f81cba
 
15c0e5a
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
    <meta name="theme-color" content="#1a0d07">
    <title>Cafe AI — کافه هوشمند تبریز</title>

    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Lalezar&family=Vazirmatn:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">

    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>

    <script>
        tailwind.config = {
            theme: {
                extend: {
                    fontFamily: {
                        sans: ['Vazirmatn', 'sans-serif'],
                        display: ['Lalezar', 'serif'],
                    },
                    colors: {
                        bazaar: { 950: '#1a0d07', 900: '#2d1810', 800: '#3d2418', 700: '#5c3a2a', 600: '#7a4e3a', 500: '#9c6b4f', 400: '#b8856a', 300: '#d4a88c' },
                        azure: { 950: '#051a2e', 900: '#0a2540', 800: '#123a5e', 700: '#1e4976', 600: '#2d6ca8', 500: '#3d8bc4', 400: '#6ba7d4', 300: '#a3c8e4' },
                        turk: { DEFAULT: '#0d9488', light: '#2dd4bf', glow: '#5eead4', deep: '#134e4a' },
                        rug: { DEFAULT: '#8b1e3f', light: '#c23d5f', dark: '#5a1028', glow: '#e85d7e' },
                        ochre: { DEFAULT: '#c9a961', light: '#e4c97a', dark: '#9c7d3a', pale: '#f0dca3' },
                        ivory: '#faf3e7', cream: '#f5e6d3', saffron: '#d97706',
                    },
                    boxShadow: {
                        'carpet': '0 10px 40px -10px rgba(139, 30, 63, 0.35), 0 0 0 1px rgba(201, 169, 97, 0.15)',
                        'mosque': '0 10px 40px -10px rgba(13, 148, 136, 0.4), 0 0 0 1px rgba(45, 212, 191, 0.2)',
                        'bazaar-glow': '0 0 60px rgba(201, 169, 97, 0.25), inset 0 1px 0 rgba(244, 228, 163, 0.1)',
                        'inner-soft': 'inset 0 2px 8px rgba(0,0,0,0.35)',
                        'inner-gold': 'inset 0 0 20px rgba(201, 169, 97, 0.15)',
                    },
                    animation: {
                        'float': 'float 6s ease-in-out infinite',
                        'shimmer': 'shimmer 3s ease-in-out infinite',
                        'pulse-glow': 'pulseGlow 2.5s ease-in-out infinite',
                        'fade-in': 'fadeIn 0.35s ease-out',
                    },
                    keyframes: {
                        float: { '0%, 100%': { transform: 'translateY(0px)' }, '50%': { transform: 'translateY(-12px)' } },
                        shimmer: { '0%, 100%': { opacity: '0.7' }, '50%': { opacity: '1' } },
                        pulseGlow: { '0%, 100%': { boxShadow: '0 0 20px rgba(201, 169, 97, 0.3)' }, '50%': { boxShadow: '0 0 40px rgba(201, 169, 97, 0.6)' } },
                        fadeIn: { '0%': { opacity: '0', transform: 'translateY(8px)' }, '100%': { opacity: '1', transform: 'translateY(0)' } },
                    },
                }
            }
        }
    </script>

    <style>
        :root {
            --pattern-url: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23c9a961' stroke-width='0.6' opacity='0.08'%3E%3Cpath d='M40 10 L50 20 L60 10 L70 20 L60 30 L70 40 L60 50 L70 60 L60 70 L50 60 L40 70 L30 60 L20 70 L10 60 L20 50 L10 40 L20 30 L10 20 L20 10 L30 20 Z'/%3E%3Ccircle cx='40' cy='40' r='12'/%3E%3Ccircle cx='40' cy='40' r='6'/%3E%3Cpath d='M40 28 L40 52 M28 40 L52 40'/%3E%3C/g%3E%3C/svg%3E");
            --vh: 1vh;
        }

        * { box-sizing: border-box; }

        html, body {
            height: 100%;
            overflow: hidden;
            overscroll-behavior: none;
            -webkit-overflow-scrolling: touch;
        }

        @supports (height: 100dvh) {
            html, body { height: 100dvh; }
        }

        body {
            background-color: #1a0d07;
            color: #f5e6d3;
            -webkit-tap-highlight-color: transparent;
            font-feature-settings: "ss01", "cv01";
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        .bg-pattern { background-image: var(--pattern-url); background-size: 80px 80px; }

        .bg-pattern-fine {
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cg fill='none' stroke='%23c9a961' stroke-width='0.4' opacity='0.1'%3E%3Cpath d='M20 0 L20 40 M0 20 L40 20'/%3E%3Ccircle cx='20' cy='20' r='3'/%3E%3Ccircle cx='0' cy='0' r='2'/%3E%3Ccircle cx='40' cy='0' r='2'/%3E%3Ccircle cx='0' cy='40' r='2'/%3E%3Ccircle cx='40' cy='40' r='2'/%3E%3C/g%3E%3C/svg%3E");
        }

        .bg-arch {
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Cg fill='none' stroke='%230d9488' stroke-width='0.5' opacity='0.06'%3E%3Cpath d='M100 20 Q 40 40, 40 100 Q 40 180, 100 180 Q 160 180, 160 100 Q 160 40, 100 20 Z'/%3E%3Cpath d='M100 50 Q 65 65, 65 100 Q 65 155, 100 155 Q 135 155, 135 100 Q 135 65, 100 50 Z'/%3E%3Cpath d='M100 80 Q 85 90, 85 100 Q 85 130, 100 130 Q 115 130, 115 100 Q 115 90, 100 80 Z'/%3E%3C/g%3E%3C/svg%3E");
            background-size: 200px 200px;
        }

        ::-webkit-scrollbar { width: 6px; height: 6px; }
        ::-webkit-scrollbar-track { background: transparent; }
        ::-webkit-scrollbar-thumb {
            background: linear-gradient(180deg, #c9a961, #8b1e3f);
            border-radius: 4px;
        }
        ::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, #e4c97a, #c23d5f); }

        .glass-card {
            background: linear-gradient(135deg, rgba(45, 24, 16, 0.82) 0%, rgba(26, 13, 7, 0.78) 100%);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border: 1px solid rgba(201, 169, 97, 0.18);
            box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(244, 228, 163, 0.08);
        }

        .glass-card-azure {
            background: linear-gradient(135deg, rgba(10, 37, 64, 0.78) 0%, rgba(5, 26, 46, 0.82) 100%);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border: 1px solid rgba(45, 212, 191, 0.2);
            box-shadow: 0 20px 50px -20px rgba(13, 148, 136, 0.2), inset 0 1px 0 rgba(94, 234, 212, 0.1);
        }

        .table-btn {
            position: relative;
            background: linear-gradient(145deg, rgba(139, 30, 63, 0.15), rgba(90, 16, 40, 0.25));
            border: 1px solid rgba(201, 169, 97, 0.25);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            overflow: hidden;
            -webkit-user-select: none;
            user-select: none;
        }
        .table-btn::before {
            content: '';
            position: absolute;
            inset: 4px;
            border: 1px dashed rgba(201, 169, 97, 0.2);
            border-radius: inherit;
            pointer-events: none;
            transition: all 0.3s ease;
        }
        .table-btn:hover, .table-btn:focus-visible {
            transform: translateY(-3px) scale(1.02);
            background: linear-gradient(145deg, rgba(194, 61, 95, 0.35), rgba(139, 30, 63, 0.45));
            border-color: rgba(201, 169, 97, 0.6);
            box-shadow: 0 15px 30px -8px rgba(139, 30, 63, 0.5), 0 0 0 1px rgba(201, 169, 97, 0.4), inset 0 1px 0 rgba(244, 228, 163, 0.2);
        }
        .table-btn:hover::before, .table-btn:focus-visible::before {
            border-color: rgba(201, 169, 97, 0.5);
            inset: 6px;
        }
        .table-btn:active { transform: translateY(-1px) scale(1); }

        .ornament-divider { position: relative; text-align: center; }
        .ornament-divider::before, .ornament-divider::after {
            content: '';
            position: absolute;
            top: 50%;
            width: 30%;
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(201, 169, 97, 0.5), transparent);
        }
        .ornament-divider::before { left: 0; }
        .ornament-divider::after { right: 0; }

        .chat-markdown { line-height: 1.85; word-wrap: break-word; overflow-wrap: break-word; }
        .chat-markdown > * + * { margin-top: 0.6em; }
        .chat-markdown h1, .chat-markdown h2, .chat-markdown h3,
        .chat-markdown h4, .chat-markdown h5, .chat-markdown h6 {
            font-family: 'Lalezar', serif; color: #e4c97a;
            margin-top: 1em; margin-bottom: 0.4em; line-height: 1.3;
        }
        .chat-markdown h1 { font-size: 1.4em; }
        .chat-markdown h2 { font-size: 1.25em; }
        .chat-markdown h3 { font-size: 1.15em; color: #5eead4; }
        .chat-markdown h4, .chat-markdown h5, .chat-markdown h6 { font-size: 1.05em; }
        .chat-markdown p { margin-bottom: 0.5em; }
        .chat-markdown ul, .chat-markdown ol { padding-right: 1.4em; margin: 0.4em 0; }
        .chat-markdown ul { list-style-type: '❋  '; }
        .chat-markdown ol { list-style-type: persian; }
        .chat-markdown li { margin-bottom: 0.3em; padding-right: 0.2em; }
        .chat-markdown li::marker { color: #c9a961; }
        .chat-markdown strong { color: #f0dca3; font-weight: 700; text-shadow: 0 0 8px rgba(201, 169, 97, 0.3); }
        .chat-markdown em { color: #5eead4; font-style: italic; }
        .chat-markdown a { color: #2dd4bf; text-decoration: underline; text-underline-offset: 3px; }
        .chat-markdown code {
            background: rgba(13, 148, 136, 0.18); color: #5eead4;
            padding: 0.15em 0.4em; border-radius: 5px; font-size: 0.88em;
            border: 1px solid rgba(45, 212, 191, 0.2);
            font-family: 'Courier New', monospace;
            direction: ltr; display: inline-block;
        }
        .chat-markdown pre {
            background: rgba(5, 26, 46, 0.7);
            border: 1px solid rgba(45, 212, 191, 0.25);
            border-right: 3px solid #0d9488;
            padding: 0.9em 1em; border-radius: 8px;
            overflow-x: auto; margin: 0.6em 0;
            direction: ltr; text-align: left;
        }
        .chat-markdown pre code { background: transparent; border: none; padding: 0; color: #a3c8e4; font-size: 0.85em; }
        .chat-markdown blockquote {
            border-right: 3px solid #c9a961;
            background: linear-gradient(90deg, rgba(201, 169, 97, 0.08), transparent);
            padding: 0.5em 1em; margin: 0.6em 0;
            color: #f0dca3; font-style: italic;
            border-radius: 0 8px 8px 0;
        }
        .chat-markdown blockquote p { margin: 0; }
        .chat-markdown hr {
            border: none; height: 1px;
            background: linear-gradient(90deg, transparent, rgba(201, 169, 97, 0.5), transparent);
            margin: 1em 0;
        }
        .chat-markdown table {
            width: 100%; border-collapse: collapse; margin: 0.6em 0;
            font-size: 0.92em; background: rgba(45, 24, 16, 0.5);
            border-radius: 8px; overflow: hidden;
            border: 1px solid rgba(201, 169, 97, 0.25);
            display: block; overflow-x: auto;
        }
        .chat-markdown thead { background: linear-gradient(90deg, rgba(139, 30, 63, 0.4), rgba(201, 169, 97, 0.2)); }
        .chat-markdown th {
            padding: 0.55em 0.8em; text-align: right;
            color: #e4c97a; font-weight: 700;
            border-bottom: 1px solid rgba(201, 169, 97, 0.3);
            font-family: 'Lalezar', serif;
        }
        .chat-markdown td { padding: 0.5em 0.8em; border-bottom: 1px solid rgba(201, 169, 97, 0.1); }
        .chat-markdown tr:last-child td { border-bottom: none; }
        .chat-markdown img { max-width: 100%; border-radius: 10px; border: 2px solid rgba(201, 169, 97, 0.3); }

        .table-number-glow { text-shadow: 0 0 10px rgba(201, 169, 97, 0.8), 0 0 20px rgba(201, 169, 97, 0.4); }
        .arch-shape { border-radius: 50% 50% 1rem 1rem / 35% 35% 1rem 1rem; }

        .btn-primary {
            background: linear-gradient(135deg, #c9a961 0%, #9c7d3a 100%);
            color: #1a0d07; font-weight: 800;
            transition: all 0.3s ease;
            box-shadow: 0 8px 20px -5px rgba(201, 169, 97, 0.4);
        }
        .btn-primary:hover {
            background: linear-gradient(135deg, #e4c97a 0%, #c9a961 100%);
            transform: translateY(-2px);
            box-shadow: 0 12px 28px -5px rgba(201, 169, 97, 0.6);
        }
        .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

        .typing-dots span {
            display: inline-block; width: 6px; height: 6px;
            border-radius: 50%; background: #c9a961;
            animation: typing 1.4s infinite;
        }
        .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
        .typing-dots span:nth-child(3) { animation-delay: 0.4s; }
        @keyframes typing {
            0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
            30% { transform: translateY(-8px); opacity: 1; }
        }

        input:focus {
            outline: none;
            border-color: rgba(201, 169, 97, 0.6) !important;
            box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.15);
        }

        .view-hidden { display: none !important; }
        .view-visible { display: flex !important; animation: fadeIn 0.35s ease-out; }

        .view-container {
            position: fixed;
            inset: 0;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            width: 100%;
            height: 100vh;
            height: 100dvh;
        }

        .scroll-area {
            overflow-y: auto;
            overflow-x: hidden;
            overscroll-behavior: contain;
            -webkit-overflow-scrolling: touch;
        }

        button, .no-select { -webkit-user-select: none; user-select: none; }

        /* ============ FOOTER ============ */
        .app-footer {
            flex-shrink: 0;
            position: relative;
            z-index: 20;
            background: linear-gradient(180deg, rgba(26, 13, 7, 0.85), rgba(26, 13, 7, 0.98));
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border-top: 1px solid rgba(201, 169, 97, 0.15);
        }

        /* ============ CHAT COLUMN - KEY FIX ============ */
        .chat-column {
            display: flex;
            flex-direction: column;
            min-height: 0;
            overflow: hidden;
        }

        .chat-messages-container {
            flex: 1;
            min-height: 0;
            overflow-y: auto;
            overflow-x: hidden;
            overscroll-behavior: contain;
            -webkit-overflow-scrolling: touch;
        }

        .chat-header-box,
        .chat-loader-box,
        .chat-input-box {
            flex-shrink: 0;
        }

        /* ============ RESPONSIVE HEIGHTS ============ */

        /* Mobile (< 640px) */
        @media (max-width: 639px) {
            .hero-title { font-size: 2.5rem !important; }
            .hero-logo { width: 70px !important; height: 70px !important; }
            .tables-grid { grid-template-columns: repeat(4, 1fr) !important; gap: 0.5rem !important; }
            .table-btn span { font-size: 1.5rem !important; }
            .info-cards { grid-template-columns: 1fr !important; }
            .chat-column {
                height: 65vh;
                height: calc(var(--vh, 1vh) * 65);
                min-height: 380px;
                max-height: 550px;
                flex-shrink: 0;
            }
            .chat-input-area {
                padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)) !important;
            }
        }

        /* Tablet (640px - 1023px) */
        @media (min-width: 640px) and (max-width: 1023px) {
            .hero-title { font-size: 3.5rem !important; }
            .hero-logo { width: 90px !important; height: 90px !important; }
            .tables-grid { grid-template-columns: repeat(5, 1fr) !important; }
            .info-cards { grid-template-columns: repeat(2, 1fr) !important; }
            .chat-column {
                height: 70vh;
                height: calc(var(--vh, 1vh) * 70);
                min-height: 420px;
                max-height: 620px;
                flex-shrink: 0;
            }
        }

        /* Desktop (>= 1024px) - چت کل ارتفاع را می‌گیرد */
        @media (min-width: 1024px) {
            .hero-title { font-size: 4.5rem !important; }
            .hero-logo { width: 100px !important; height: 100px !important; }
            .tables-grid { grid-template-columns: repeat(10, 1fr) !important; }
            .info-cards { grid-template-columns: repeat(3, 1fr) !important; }
            .chat-column {
                height: 100%;
                max-height: 100%;
            }
        }

        /* Landscape mobile */
        @media (max-height: 500px) and (orientation: landscape) {
            .hero-title { font-size: 2rem !important; }
            .hero-logo { width: 50px !important; height: 50px !important; }
            .hero-header { padding-top: 0.5rem !important; padding-bottom: 0.25rem !important; }
            .chat-column {
                height: 75vh !important;
                min-height: 280px !important;
            }
        }

        /* Small mobile */
        @media (max-width: 380px) {
            .tables-grid { grid-template-columns: repeat(4, 1fr) !important; }
            .table-btn { padding: 0.375rem !important; }
            .table-btn span { font-size: 1.25rem !important; }
            .hero-title { font-size: 2rem !important; }
            .chat-column {
                height: 60vh;
                height: calc(var(--vh, 1vh) * 60);
                min-height: 340px;
                max-height: 500px;
            }
        }

        @supports (padding-bottom: env(safe-area-inset-bottom)) {
            .safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
            .safe-top { padding-top: env(safe-area-inset-top); }
        }
    </style>
</head>
<body class="font-sans selection:bg-ochre selection:text-bazaar-950 antialiased">

    <!-- ============ VIEW 1: TABLE SELECTION ============ -->
    <section id="view-table-selection" class="view-container view-visible">

        <div class="absolute inset-0 overflow-hidden pointer-events-none z-0">
            <div class="absolute inset-0 bg-gradient-to-br from-bazaar-950 via-bazaar-900 to-azure-950"></div>
            <div class="absolute inset-0 bg-pattern opacity-40"></div>
            <div class="absolute -top-40 -right-40 w-[600px] h-[600px] rounded-full bg-rug/10 blur-[140px] animate-float"></div>
            <div class="absolute -bottom-40 -left-40 w-[600px] h-[600px] rounded-full bg-turk/10 blur-[140px] animate-float" style="animation-delay: -3s;"></div>
            <div class="absolute top-1/3 left-1/4 w-[400px] h-[400px] rounded-full bg-ochre/8 blur-[120px] animate-shimmer"></div>
        </div>

        <div class="scroll-area flex-1 min-h-0 relative z-10">

            <header class="hero-header px-4 pt-6 pb-3 md:pt-10 md:pb-4 text-center relative flex-shrink-0">
                <div class="max-w-4xl mx-auto">
                    <div class="inline-flex items-center gap-4 mb-4 animate-float">
                        <div class="relative">
                            <div class="hero-logo w-20 h-20 md:w-24 md:h-24 arch-shape bg-gradient-to-br from-rug via-rug-dark to-bazaar-900 border-2 border-ochre/60 flex items-center justify-center shadow-carpet">
                                <svg class="w-10 h-10 md:w-12 md:h-12 text-ochre-light" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
                                    <path d="M17 8h1a4 4 0 1 1 0 8h-1" stroke-linecap="round"/>
                                    <path d="M3 8h14v9a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4Z" stroke-linecap="round"/>
                                    <line x1="6" y1="2" x2="6" y2="4" stroke-linecap="round"/>
                                    <line x1="10" y1="2" x2="10" y2="4" stroke-linecap="round"/>
                                    <line x1="14" y1="2" x2="14" y2="4" stroke-linecap="round"/>
                                    <path d="M7 13h6" stroke-linecap="round" opacity="0.6"/>
                                </svg>
                            </div>
                            <div class="absolute -bottom-1 -right-1 w-5 h-5 rounded-full bg-turk border-2 border-ochre animate-pulse-glow"></div>
                        </div>
                    </div>

                    <h1 class="hero-title font-display text-4xl md:text-6xl text-ochre-light mb-2 tracking-wide drop-shadow-lg">کافه آی</h1>
                    <div class="ornament-divider inline-block mb-3">
                        <span class="px-4 text-ochre/80 text-sm font-display tracking-widest">✦ تبریز ✦</span>
                    </div>
                    <p class="text-cream/90 text-sm md:text-base max-w-xl mx-auto leading-relaxed font-light px-2">
                        دستیار هوشمند سفارش، با الهام از <span class="text-turk-light font-semibold">کاشی‌کاری‌های مسجد کبود</span>
                        و گرمای <span class="text-rug-light font-semibold">بازار سرپوشیده</span>
                    </p>
                </div>
            </header>

            <main class="px-4 md:px-8 pb-8 relative">
                <div class="max-w-5xl mx-auto">

                    <div class="glass-card rounded-3xl p-4 md:p-6 mb-4 relative overflow-hidden">
                        <div class="absolute inset-0 bg-arch opacity-30 pointer-events-none"></div>

                        <div class="relative">
                            <div class="flex items-center justify-between mb-4 flex-wrap gap-2">
                                <div class="flex items-center gap-2.5">
                                    <div class="w-9 h-9 rounded-xl bg-ochre/15 border border-ochre/30 flex items-center justify-center flex-shrink-0">
                                        <svg class="w-5 h-5 text-ochre-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                            <path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"/>
                                        </svg>
                                    </div>
                                    <div>
                                        <h2 class="font-display text-xl md:text-2xl text-ochre-light">شماره میز خود را برگزینید</h2>
                                        <p class="text-[10px] text-cream/60 mt-0.5">با انتخاب میز، دستیار نیلا در خدمت شماست</p>
                                    </div>
                                </div>
                                <div class="flex items-center gap-2 px-2.5 py-1 rounded-full bg-turk/10 border border-turk/30 text-[10px]">
                                    <span class="w-1.5 h-1.5 rounded-full bg-turk-light animate-pulse"></span>
                                    <span class="text-turk-light font-medium">۲۰ میز آماده</span>
                                </div>
                            </div>

                            <div id="tablesGrid" class="tables-grid grid grid-cols-4 sm:grid-cols-5 md:grid-cols-5 lg:grid-cols-10 gap-2 md:gap-3"></div>

                            <div class="mt-4 pt-3 border-t border-ochre/15 flex items-center justify-between text-[10px] text-cream/50 flex-wrap gap-1.5">
                                <span class="flex items-center gap-1.5">
                                    <svg class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                    </svg>
                                    با لمس هر میز، به گپ هوشمند منتقل می‌شوید
                                </span>
                                <span>طراحی با عشق از تبریز 🏛️</span>
                            </div>
                        </div>
                    </div>

                    <div class="info-cards grid grid-cols-1 md:grid-cols-3 gap-3 mb-6">
                        <div class="glass-card rounded-2xl p-4 relative overflow-hidden group">
                            <div class="absolute top-0 right-0 w-20 h-20 bg-rug/15 rounded-full blur-2xl group-hover:bg-rug/25 transition-all"></div>
                            <div class="relative">
                                <div class="w-9 h-9 rounded-lg bg-rug/20 border border-rug/40 flex items-center justify-center mb-2">
                                    <svg class="w-5 h-5 text-rug-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"/>
                                    </svg>
                                </div>
                                <h3 class="font-display text-base text-ochre-light mb-1">گفتگوی هوشمند</h3>
                                <p class="text-[11px] text-cream/70 leading-relaxed">با نیلا به زبان طبیعی سفارش دهید</p>
                            </div>
                        </div>

                        <div class="glass-card rounded-2xl p-4 relative overflow-hidden group">
                            <div class="absolute top-0 right-0 w-20 h-20 bg-turk/15 rounded-full blur-2xl group-hover:bg-turk/25 transition-all"></div>
                            <div class="relative">
                                <div class="w-9 h-9 rounded-lg bg-turk/20 border border-turk/40 flex items-center justify-center mb-2">
                                    <svg class="w-5 h-5 text-turk-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
                                    </svg>
                                </div>
                                <h3 class="font-display text-base text-ochre-light mb-1">پیش‌نویس زنده</h3>
                                <p class="text-[11px] text-cream/70 leading-relaxed">سفارش قبل از ثبت نهایی، قابل ویرایش</p>
                            </div>
                        </div>

                        <div class="glass-card rounded-2xl p-4 relative overflow-hidden group">
                            <div class="absolute top-0 right-0 w-20 h-20 bg-ochre/15 rounded-full blur-2xl group-hover:bg-ochre/25 transition-all"></div>
                            <div class="relative">
                                <div class="w-9 h-9 rounded-lg bg-ochre/20 border border-ochre/40 flex items-center justify-center mb-2">
                                    <svg class="w-5 h-5 text-ochre-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M13 10V3L4 14h7v7l9-11h-7z"/>
                                    </svg>
                                </div>
                                <h3 class="font-display text-base text-ochre-light mb-1">ارسال آنی</h3>
                                <p class="text-[11px] text-cream/70 leading-relaxed">ارسال مستقیم به آشپزخانه</p>
                            </div>
                        </div>
                    </div>
                </div>
            </main>
        </div>

        <footer class="app-footer py-3 text-center text-[10px] text-cream/40 safe-top safe-bottom">
            طراحی و توسعه توسط الگوریتم داده نسترن | با الهام از فرهنگ تبریز © ۲۰۲۶
        </footer>
    </section>


    <!-- ============ VIEW 2: CHAT ============ -->
    <section id="view-chat" class="view-container view-hidden">

        <div class="absolute inset-0 overflow-hidden pointer-events-none z-0">
            <div class="absolute inset-0 bg-gradient-to-br from-bazaar-950 via-bazaar-900 to-azure-950"></div>
            <div class="absolute inset-0 bg-pattern opacity-30"></div>
            <div class="absolute -top-40 -right-40 w-[500px] h-[500px] rounded-full bg-rug/10 blur-[140px]"></div>
            <div class="absolute -bottom-40 -left-40 w-[500px] h-[500px] rounded-full bg-turk/10 blur-[140px]"></div>
        </div>

        <!-- Header -->
        <header class="flex-shrink-0 border-b border-ochre/20 bg-bazaar-900/70 backdrop-blur-2xl z-20 px-3 py-2.5 md:px-6 md:py-3 shadow-lg safe-top">
            <div class="max-w-5xl mx-auto flex items-center justify-between gap-2">
                <div class="flex items-center gap-2 min-w-0">
                    <button onclick="backToTables()" class="p-2 text-ochre/70 hover:text-ochre-light transition-colors rounded-lg hover:bg-bazaar-800/50 flex-shrink-0" title="بازگشت">
                        <svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7"/>
                        </svg>
                    </button>
                    <div class="w-9 h-9 rounded-xl bg-gradient-to-br from-rug/30 to-ochre/15 border border-ochre/30 flex items-center justify-center shadow-carpet flex-shrink-0">
                        <svg class="w-5 h-5 text-ochre-light" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
                            <path d="M17 8h1a4 4 0 1 1 0 8h-1" stroke-linecap="round"/>
                            <path d="M3 8h14v9a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4Z" stroke-linecap="round"/>
                        </svg>
                    </div>
                    <div class="min-w-0">
                        <h1 class="text-xs md:text-sm font-display text-ochre-light tracking-wide flex items-center gap-1.5 truncate">
                            <span class="text-rug-light flex-shrink-0">Cafe AI</span>
                            <span class="text-cream/40 flex-shrink-0">|</span>
                            <span class="text-cream/80 text-[10px] md:text-xs font-sans font-normal truncate">کافه هوشمند تبریز</span>
                        </h1>
                    </div>
                </div>

                <div class="flex items-center gap-1.5 flex-shrink-0">
                    <div class="flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-bazaar-950/70 border border-ochre/30 shadow-inner-gold">
                        <svg class="w-3.5 h-3.5 text-ochre flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"/>
                        </svg>
                        <span class="text-[10px] text-cream/60">میز</span>
                        <span id="tableNumberDisplay" class="text-base md:text-lg font-display text-ochre-light table-number-glow">---</span>
                    </div>
                    <button onclick="backToTables()" class="p-1.5 text-turk/60 hover:text-ochre-light transition-colors rounded-lg hover:bg-bazaar-800/50" title="تغییر میز">
                        <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/>
                        </svg>
                    </button>
                </div>
            </div>
        </header>

        <!-- Main content with controlled height -->
        <main class="flex-1 flex flex-col min-h-0 p-2.5 md:p-4 lg:p-6 z-10 relative gap-3 overflow-hidden">
            <div class="max-w-5xl w-full mx-auto flex-1 flex flex-col min-h-0 gap-3">

                <!-- Draft order panel -->
                <div id="draftOrderPanel" class="glass-card rounded-2xl p-3 md:p-4 hidden transition-all duration-300 relative overflow-hidden flex-shrink-0">
                    <div class="absolute inset-0 bg-pattern-fine opacity-30 pointer-events-none"></div>
                    <div class="relative">
                        <div class="flex items-center justify-between border-b border-ochre/25 pb-2 mb-2">
                            <h3 class="text-sm md:text-base font-display text-ochre-light flex items-center gap-2 tracking-wide">
                                <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                    <path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
                                </svg>
                                پیش‌نویس سفارش · میز <span id="draftTableNumber" class="text-rug-light">---</span>
                            </h3>
                            <span class="text-[9px] md:text-[10px] text-turk/70 bg-turk/10 px-2 py-1 rounded-md border border-turk/20">جهت تأیید نهایی</span>
                        </div>
                        <div id="draftItems" class="space-y-1.5 mb-3 max-h-40 overflow-y-auto scroll-area"></div>
                        <button id="confirmOrderBtn" onclick="confirmOrder()" class="btn-primary w-full py-2.5 md:py-3 rounded-xl text-xs md:text-sm transition-all flex items-center justify-center gap-2">
                            <svg class="w-4 h-4 md:w-5 md:h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/>
                            </svg>
                            تأیید نهایی و ارسال به آشپزخانه
                        </button>
                    </div>
                </div>

                <!-- Chat column (fixed height controlled by CSS) -->
                <div class="chat-column glass-card-azure rounded-2xl md:rounded-3xl shadow-xl relative">
                    <div class="absolute inset-0 bg-arch opacity-20 pointer-events-none"></div>

                    <!-- Chat header (flex-shrink-0) -->
                    <div class="chat-header-box relative px-3.5 md:px-5 py-2.5 md:py-3 border-b border-turk/25 flex items-center gap-2.5 bg-gradient-to-l from-azure-950/60 to-azure-900/40">
                        <div class="w-9 h-9 md:w-10 md:h-10 rounded-xl bg-gradient-to-br from-turk/30 to-azure-700/30 border border-turk/40 flex items-center justify-center shadow-mosque flex-shrink-0">
                            <svg class="w-5 h-5 md:w-6 md:h-6 text-turk-glow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
                                <circle cx="12" cy="8" r="4"/>
                                <path d="M5 20v-1a7 7 0 0114 0v1" stroke-linecap="round"/>
                                <path d="M9 10l2 2 4-4" stroke-linecap="round" stroke-linejoin="round" opacity="0.7"/>
                            </svg>
                        </div>
                        <div class="min-w-0 flex-1">
                            <h3 class="text-xs md:text-sm font-display text-ochre-light tracking-wide">نیلا، دستیار کافه</h3>
                            <p class="text-[9px] md:text-[10px] text-turk-light/80 font-medium flex items-center gap-1.5">
                                <span class="w-1.5 h-1.5 rounded-full bg-turk-light animate-pulse"></span>
                                <span class="truncate">برای سفارش از منو، با من گفتگو کنید ☕️</span>
                            </p>
                        </div>
                    </div>

                    <!-- Chat messages (SCROLLABLE - key fix) -->
                    <div id="chatMessages" class="chat-messages-container p-3 md:p-4 space-y-3 relative">
                        <div class="flex gap-2 md:gap-2.5 max-w-[88%]">
                            <div class="w-7 h-7 md:w-8 md:h-8 rounded-xl bg-gradient-to-br from-turk/20 to-azure-700/20 border border-turk/30 flex items-center justify-center flex-shrink-0">
                                <span class="text-ochre-light font-display text-[10px] md:text-[11px]">ن</span>
                            </div>
                            <div class="bg-bazaar-950/70 border border-ochre/20 text-cream text-xs md:text-sm rounded-2xl rounded-tr-none px-3 py-2 md:px-3.5 md:py-2.5 leading-relaxed shadow-inner-soft chat-markdown break-words" style="flex: 1; max-width: calc(100% - 2.5rem);">
                                سلام! من <strong>نیلا</strong> هستم، دستیار هوشمند کافه آی. به میزتون خوش اومدید 🌸<br>
                                چه نوشیدنی، غذا یا شیرینی‌ای می‌پسندید؟ <em>منوی امروز</em> رو می‌تونم براتون بگم. 😊
                            </div>
                        </div>
                    </div>

                    <!-- Chat loader (flex-shrink-0) -->
                    <div id="chatLoader" class="chat-loader-box hidden relative px-3 py-2 md:px-4 md:py-2.5 flex items-center justify-between bg-azure-950/70 text-[9px] md:text-[10px] text-turk-light font-semibold border-t border-turk/20">
                        <div class="flex items-center gap-2">
                            <div class="typing-dots flex gap-1">
                                <span></span><span></span><span></span>
                            </div>
                            <span>نیلا در حال فکر کردن...</span>
                        </div>
                        <button onclick="stopGeneration()" class="px-2.5 py-1 md:px-3 md:py-1.5 bg-rug-dark/40 border border-rug/40 hover:bg-rug/40 rounded-lg text-[9px] md:text-[10px] text-rug-light font-bold transition-all">توقف</button>
                    </div>

                    <!-- Chat input (flex-shrink-0) -->
                    <form id="chatForm" onsubmit="sendCustomerMessage(event)" class="chat-input-box relative p-2 md:p-3 border-t border-turk/20 bg-bazaar-950/60 flex gap-2 chat-input-area safe-bottom">
                        <input type="text" id="chatInput" placeholder="پیام خود را بنویسید..." autocomplete="off"
                               class="flex-1 min-w-0 bg-azure-950/60 border border-azure-700/40 text-xs md:text-sm text-cream placeholder-ochre/40 rounded-xl px-3.5 py-2.5 md:py-3 focus:outline-none focus:border-ochre/60 transition-all duration-300">
                        <button type="submit" id="sendBtn" class="btn-primary px-3.5 md:px-4 py-2.5 md:py-3 rounded-xl text-xs flex items-center justify-center flex-shrink-0">
                            <svg class="w-4 h-4 md:w-5 md:h-5 rotate-180" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M14 5l7 7m0 0l-7 7m7-7H3"/>
                            </svg>
                        </button>
                    </form>
                </div>
            </div>
        </main>
    </section>

    <script>
        // ============ VIEWPORT HEIGHT FIX ============
        function setVh() {
            const vh = window.innerHeight * 0.01;
            document.documentElement.style.setProperty('--vh', `${vh}px`);
        }
        setVh();
        window.addEventListener('resize', setVh);
        window.addEventListener('orientationchange', () => setTimeout(setVh, 100));

        // ============ AUTO SCROLL HELPER ============
        function scrollChatToBottom(smooth = true) {
            const chatScroll = document.getElementById('chatMessages');
            if (chatScroll) {
                if (smooth) {
                    chatScroll.scrollTo({ top: chatScroll.scrollHeight, behavior: 'smooth' });
                } else {
                    chatScroll.scrollTop = chatScroll.scrollHeight;
                }
            }
        }

        window.addEventListener('resize', () => {
            setVh();
            setTimeout(scrollChatToBottom, 150);
        });

        // ============ CONFIG ============
        let currentTable = "{{ table_number }}" !== "None" && "{{ table_number }}" !== "" ? "{{ table_number }}" : null;
        let abortController = null;
        let isGenerating = false;
        let currentDraft = null;
        const TOTAL_TABLES = 20;

        marked.setOptions({ sanitize: true, breaks: true });

        window.addEventListener('DOMContentLoaded', () => {
            renderTablesGrid();
            if (currentTable && currentTable.trim() !== '') {
                enterChatView(currentTable, false);
            }
            setTimeout(scrollChatToBottom, 100);
        });

        document.addEventListener('touchmove', function(e) {
            if (!e.target.closest('.scroll-area') && !e.target.closest('.chat-messages-container')) {
                e.preventDefault();
            }
        }, { passive: false });

        // ============ VIEW MANAGEMENT ============
        function switchView(targetView) {
            const sel = document.getElementById('view-table-selection');
            const chat = document.getElementById('view-chat');

            if (targetView === 'chat') {
                sel.classList.remove('view-visible');
                sel.classList.add('view-hidden');
                chat.classList.remove('view-hidden');
                chat.classList.add('view-visible');
            } else {
                chat.classList.remove('view-visible');
                chat.classList.add('view-hidden');
                sel.classList.remove('view-hidden');
                sel.classList.add('view-visible');
            }

            window.scrollTo(0, 0);
            const tablesScroll = sel.querySelector('.scroll-area');
            if (tablesScroll) tablesScroll.scrollTop = 0;
            if (targetView === 'chat') {
                setTimeout(scrollChatToBottom, 100);
            }
        }

        function enterChatView(tableNumber, updateUrl = true) {
            currentTable = tableNumber;
            updateTableNumberDisplay(tableNumber);
            if (updateUrl) window.history.replaceState(null, '', `/customer/${tableNumber}`);
            switchView('chat');
            initializeChatSession(tableNumber);
            setTimeout(() => {
                const input = document.getElementById('chatInput');
                if (input && window.innerWidth > 768) input.focus();
            }, 400);
        }

        function backToTables() {
            stopGeneration();
            switchView('table-selection');
            window.history.replaceState(null, '', '/customer');
            currentTable = null;
            currentDraft = null;
            document.getElementById('draftOrderPanel').classList.add('hidden');
        }

        // ============ TABLES GRID ============
        function renderTablesGrid() {
            const grid = document.getElementById('tablesGrid');
            grid.innerHTML = '';
            for (let i = 1; i <= TOTAL_TABLES; i++) {
                const btn = document.createElement('button');
                btn.className = 'table-btn arch-shape aspect-[3/4] flex flex-col items-center justify-center gap-0.5 p-1.5 md:p-2 group focus:outline-none';
                btn.innerHTML = `
                    <svg class="w-3.5 h-3.5 md:w-4 md:h-4 text-ochre/60 group-hover:text-ochre-light transition-colors" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.8">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"/>
                    </svg>
                    <span class="font-display text-xl md:text-2xl lg:text-3xl text-ochre-light group-hover:text-ochre-pale transition-colors leading-none">${i}</span>
                    <span class="text-[8px] md:text-[9px] text-cream/50 group-hover:text-cream/80 transition-colors tracking-wide">میز</span>
                `;
                btn.onclick = () => enterChatView(String(i));
                grid.appendChild(btn);
            }
        }

        function updateTableNumberDisplay(number) {
            document.getElementById('tableNumberDisplay').textContent = number;
        }

        async function initializeChatSession(table) {
            try { await fetch(`/api/customer/stop/${table}`, { method: 'POST' }); } catch (e) {}
        }

        function resetChat() {
            appendInitialGreeting();
            document.getElementById('draftOrderPanel').classList.add('hidden');
            currentDraft = null;
            stopGeneration();
            if (currentTable) fetch(`/api/customer/stop/${currentTable}`, { method: 'POST' }).catch(() => {});
            setTimeout(scrollChatToBottom, 100);
        }

        function appendInitialGreeting() {
            const container = document.getElementById('chatMessages');
            container.innerHTML = `
                <div class="flex gap-2 md:gap-2.5 max-w-[88%]">
                    <div class="w-7 h-7 md:w-8 md:h-8 rounded-xl bg-gradient-to-br from-turk/20 to-azure-700/20 border border-turk/30 flex items-center justify-center flex-shrink-0">
                        <span class="text-ochre-light font-display text-[10px] md:text-[11px]">ن</span>
                    </div>
                    <div class="bg-bazaar-950/70 border border-ochre/20 text-cream text-xs md:text-sm rounded-2xl rounded-tr-none px-3 py-2 md:px-3.5 md:py-2.5 leading-relaxed shadow-inner-soft chat-markdown break-words" style="flex: 1; max-width: calc(100% - 2.5rem);">
                        سلام! من <strong>نیلا</strong> هستم، دستیار هوشمند کافه آی. به میزتون خوش اومدید 🌸<br>
                        چه نوشیدنی، غذا یا شیرینی‌ای می‌پسندید؟ <em>منوی امروز</em> رو می‌تونم براتون بگم. 😊
                    </div>
                </div>
            `;
            setTimeout(scrollChatToBottom, 50);
        }

        // ============ CHAT FUNCTIONS ============
        async function sendCustomerMessage(e) {
            e.preventDefault();
            if (isGenerating) return;
            if (!currentTable) { backToTables(); return; }

            const input = document.getElementById('chatInput');
            const text = input.value.trim();
            if (!text) return;

            appendChatMessage('user', text);
            input.value = '';

            isGenerating = true;
            toggleChatLoading(true);
            abortController = new AbortController();

            try {
                const response = await fetch(`/api/customer/chat_stream/${currentTable}`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ message: text }),
                    signal: abortController.signal
                });

                if (!response.ok) {
                    const errData = await response.json();
                    throw new Error(errData.error || 'خطای سرور');
                }

                const reader = response.body.getReader();
                const decoder = new TextDecoder();
                let buffer = '';
                let botBubbleId = appendChatMessage('model', '');
                let botBubble = document.getElementById(botBubbleId);
                let fullText = '';

                while (true) {
                    const { done, value } = await reader.read();
                    if (done) break;
                    buffer += decoder.decode(value, { stream: true });
                    const lines = buffer.split('\n');
                    buffer = lines.pop();

                    for (const line of lines) {
                        if (line.startsWith('data: ')) {
                            try {
                                const data = JSON.parse(line.slice(6));
                                if (data.type === 'text') {
                                    fullText += data.content;
                                    botBubble.textContent = fullText;
                                    scrollChatToBottom(false);
                                } else if (data.type === 'draft') {
                                    currentDraft = data.items;
                                    showDraftPanel(currentDraft);
                                } else if (data.type === 'error') {
                                    botBubble.textContent = '⚠️ ' + data.content;
                                    scrollChatToBottom(false);
                                }
                            } catch (parseErr) {}
                        }
                    }
                }

                botBubble.textContent = '';
                botBubble.innerHTML = marked.parse(fullText);
                scrollChatToBottom(true);

            } catch (err) {
                if (err.name !== 'AbortError') {
                    appendChatMessage('model', '❌ عدم دریافت پاسخ: ' + err.message);
                }
            } finally {
                toggleChatLoading(false);
                isGenerating = false;
                abortController = null;
            }
        }

        function stopGeneration() {
            if (abortController) {
                abortController.abort();
                if (currentTable) fetch(`/api/customer/stop/${currentTable}`, { method: 'POST' }).catch(() => {});
            }
            toggleChatLoading(false);
            isGenerating = false;
        }

        function toggleChatLoading(loading) {
            const loader = document.getElementById('chatLoader');
            const sendBtn = document.getElementById('sendBtn');
            const input = document.getElementById('chatInput');
            if (loading) {
                loader.classList.remove('hidden');
                sendBtn.disabled = true;
                input.disabled = true;
            } else {
                loader.classList.add('hidden');
                sendBtn.disabled = false;
                input.disabled = false;
            }
        }

        function showDraftPanel(items) {
            const panel = document.getElementById('draftOrderPanel');
            const draftItems = document.getElementById('draftItems');
            const draftTableSpan = document.getElementById('draftTableNumber');
            draftTableSpan.textContent = currentTable || '---';
            draftItems.innerHTML = '';
            items.forEach(item => {
                draftItems.innerHTML += `
                    <div class="flex items-center justify-between text-[11px] md:text-xs bg-bazaar-900/70 px-2.5 py-2 rounded-lg border border-ochre/20">
                        <span class="text-cream font-bold flex items-center gap-2 min-w-0">
                            <span class="w-1 h-5 bg-gradient-to-b from-rug to-ochre rounded-full flex-shrink-0"></span>
                            <span class="truncate">${escapeHtml(item.name)}</span>
                        </span>
                        <span class="text-ochre-light bg-ochre/10 px-2 py-0.5 rounded-md font-display text-[10px] border border-ochre/25 flex-shrink-0 mr-2">×${item.quantity}</span>
                    </div>
                `;
            });
            panel.classList.remove('hidden');
        }

        async function confirmOrder() {
            if (!currentDraft || currentDraft.length === 0) {
                alert("پیش‌نویس سفارشی وجود ندارد.");
                return;
            }
            try {
                const res = await fetch('/api/confirm_order', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({
                        table_number: currentTable,
                        items: currentDraft
                    })
                });
                const result = await res.json();
                if (res.ok && result.success) {
                    document.getElementById('draftOrderPanel').classList.add('hidden');
                    currentDraft = null;
                    appendChatMessage('model', '✅ سفارش شما با موفقیت ثبت شد و به آشپزخانه ارسال گردید. از همراهی شما سپاسگزاریم! 🌟');
                } else {
                    alert(result.error || 'خطا در ثبت سفارش');
                }
            } catch (e) {
                alert('خطای شبکه: ' + e.message);
            }
        }

        function appendChatMessage(role, content) {
            const container = document.getElementById('chatMessages');
            const bubbleId = 'bubble-' + Date.now() + '-' + Math.random().toString(36).substr(2, 5);
            let html = '';

            if (role === 'user') {
                html = `
                    <div class="flex justify-end gap-2 md:gap-2.5 max-w-[88%] mr-auto">
                        <div class="bg-gradient-to-br from-rug/20 to-rug-dark/30 border border-rug/30 text-cream text-xs md:text-sm rounded-2xl rounded-tl-none px-3 py-2 md:px-3.5 md:py-2.5 leading-relaxed shadow-inner-soft break-words" style="flex: 1; max-width: calc(100% - 2.5rem);">
                            ${escapeHtml(content)}
                        </div>
                        <div class="w-7 h-7 md:w-8 md:h-8 rounded-xl bg-gradient-to-br from-ochre/30 to-rug/20 border border-ochre/40 flex items-center justify-center flex-shrink-0">
                            <svg class="w-3.5 h-3.5 md:w-4 md:h-4 text-ochre-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                            </svg>
                        </div>
                    </div>
                `;
            } else {
                html = `
                    <div class="flex gap-2 md:gap-2.5 max-w-[88%]">
                        <div class="w-7 h-7 md:w-8 md:h-8 rounded-xl bg-gradient-to-br from-turk/20 to-azure-700/20 border border-turk/30 flex items-center justify-center flex-shrink-0">
                            <span class="text-ochre-light font-display text-[10px] md:text-[11px]">ن</span>
                        </div>
                        <div id="${bubbleId}" class="bg-bazaar-950/70 border border-ochre/20 text-cream text-xs md:text-sm rounded-2xl rounded-tr-none px-3 py-2 md:px-3.5 md:py-2.5 leading-relaxed shadow-inner-soft chat-markdown min-w-0 break-words" style="flex: 1; max-width: calc(100% - 2.5rem);">
                            ${content ? marked.parse(content) : ''}
                        </div>
                    </div>
                `;
            }

            container.insertAdjacentHTML('beforeend', html);
            // Always scroll to bottom after adding message
            scrollChatToBottom(true);
            return bubbleId;
        }

        function escapeHtml(text) {
            return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
        }

        // Mobile keyboard handling
        const chatInput = document.getElementById('chatInput');
        if (chatInput) {
            chatInput.addEventListener('focus', () => {
                setTimeout(scrollChatToBottom, 300);
                setTimeout(scrollChatToBottom, 600);
            });
        }
    </script>
</body>
</html>