File size: 34,768 Bytes
ae50c76
 
 
 
 
 
a8f47d0
 
 
ae50c76
 
 
 
 
b762726
ae50c76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd5a44b
 
 
 
 
 
 
 
9429951
 
 
a8f47d0
dd5a44b
ae50c76
66116cd
 
e696934
 
66116cd
 
 
e696934
 
66116cd
 
ae50c76
 
 
 
 
 
 
 
a8f47d0
ae50c76
 
 
 
 
 
 
 
3103a5d
 
 
ae50c76
 
 
 
 
 
989e00f
b762726
 
 
989e00f
b762726
 
 
ae50c76
 
 
16d7b02
 
 
 
ae50c76
 
 
 
 
 
b762726
 
ae50c76
 
601e4c8
 
ae50c76
 
 
 
 
 
 
 
 
 
 
66116cd
 
ae50c76
 
 
 
 
 
 
16d7b02
ae50c76
 
 
 
 
 
 
 
 
dd5a44b
 
 
 
 
 
 
 
 
a8f47d0
dd5a44b
 
9429951
 
 
e696934
 
 
 
70c5239
e696934
 
a8f47d0
3103a5d
 
e696934
 
 
 
 
 
9429951
a8f47d0
 
9429951
 
 
a8f47d0
e696934
9429951
e696934
a8f47d0
e696934
 
 
 
 
dd5a44b
 
e696934
a8f47d0
e696934
 
 
 
 
 
70c5239
 
 
 
 
 
dd5a44b
 
 
 
 
3103a5d
 
70c5239
 
 
 
dd5a44b
 
a8f47d0
e696934
dd5a44b
ae50c76
 
 
989e00f
 
 
 
a8f47d0
989e00f
 
 
 
 
 
b762726
 
 
 
989e00f
 
b762726
 
989e00f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16d7b02
989e00f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8575ce7
 
 
 
 
989e00f
 
 
ae50c76
 
 
 
 
 
 
 
 
 
 
 
 
dd5a44b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8f47d0
dd5a44b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae50c76
dd5a44b
 
 
 
 
 
 
 
 
ae50c76
dd5a44b
 
ae50c76
dd5a44b
 
 
 
 
 
 
ae50c76
dd5a44b
 
ae50c76
 
dd5a44b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae50c76
 
dd5a44b
 
 
 
 
 
 
 
 
 
9429951
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd5a44b
 
70c5239
3103a5d
70c5239
 
e696934
 
 
 
 
 
 
 
 
 
70c5239
dd5a44b
a8f47d0
dd5a44b
a8f47d0
dd5a44b
 
 
 
 
 
 
 
e696934
dd5a44b
 
 
 
 
 
 
 
 
16d7b02
dd5a44b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70c5239
dd5a44b
70c5239
e696934
dd5a44b
 
ae50c76
 
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
<!DOCTYPE html>
<html>
<head>
    <title>Tarz Price Scout</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <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=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg-main: #0a0c14; --card-bg: #131622; --input-bg: #1b1f32; --border-color: rgba(255, 255, 255, 0.08);
            --text-main: #f3f4f6; --text-muted: #9ca3af; --accent-blue: #3b82f6; --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
            --accent-green: #10b981; --glow-green: rgba(16, 185, 129, 0.2); --accent-gold: #f59e0b;
            --accent-red: #ef4444;
        }
        * { box-sizing: border-box; }
        body { 
             font-family: 'Inter', -apple-system, sans-serif; 
             padding: 40px 20px; 
             background: radial-gradient(circle at 50% 0%, #16192b 0%, #08090f 100%); 
             background-attachment: fixed; 
             color: var(--text-main); 
             max-width: 850px; 
             margin: auto; 
             line-height: 1.5; 
             -webkit-text-size-adjust: 100%;
        }
        h2 { font-size: 28px; font-weight: 700; letter-spacing: -0.025em; margin-bottom: 4px; color: #ffffff; display: flex; align-items: center; gap: 12px; }
        h3 { font-size: 18px; font-weight: 600; color: #ffffff; margin-top: 0; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
        .status-line { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--text-muted); margin-bottom: 30px; background: rgba(255,255,255,0.02); padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border-color); }
        .status-pill { width: 8px; height: 8px; background: {{ status_color }}; border-radius: 50%; box-shadow: 0 0 12px {{ status_color }}; }
        
        .tabs-nav { display: flex; gap: 8px; margin-bottom: 32px; border-bottom: 1px solid var(--border-color); padding-bottom: 12px; }
        .tab-btn { background: none; border: none; box-shadow: none; color: var(--text-muted); font-size: 14px; font-weight: 600; padding: 10px 18px; width: auto; cursor: pointer; border-radius: 8px; transition: all 0.2s ease; display: inline-flex; align-items: center; gap: 8px; }
        .tab-btn:hover { color: #ffffff; background: rgba(255, 255, 255, 0.04); }
        .tab-btn.active { color: #ffffff; background: rgba(59, 130, 246, 0.12); border: 1px solid rgba(59, 130, 246, 0.25); }
        .tab-content { display: none; }
        .tab-content.active { display: block; }
        
        .filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; margin-bottom: 24px; background: rgba(255,255,255,0.02); padding: 16px; border-radius: 12px; border: 1px solid var(--border-color); width: 100%; }
        .filter-item-box { display: flex; flex-direction: column; gap: 6px; }
        .filter-select-mini { width: 180px !important; height: 38px !important; padding: 6px 12px !important; font-size: 13px !important; background-color: var(--input-bg) !important; color: white !important; border-radius: 6px; border: 1px solid var(--border-color); }
        .filter-input-mini { width: 180px !important; height: 38px !important; padding: 6px 12px !important; font-size: 13px !important; background-color: var(--input-bg) !important; color: white !important; border-radius: 6px; border: 1px solid var(--border-color); font-family: inherit; }

        .card { background: var(--card-bg); padding: 24px; border-radius: 16px; border: 1px solid var(--border-color); margin-bottom: 24px; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4); }
        
        .search-card {
            background: #181c2e; border: 1px solid rgba(255, 255, 255, 0.12); transform: translateY(-6px);
            box-shadow: 0 20px 38px rgba(0, 0, 0, 0.55), 0 15px 12px rgba(0, 0, 0, 0.22), 0 1px 3px rgba(255, 255, 255, 0.05) inset;
            transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.4s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.4s ease;
        }
        .search-card:focus-within {
            transform: translateY(-9px); border-color: rgba(59, 130, 246, 0.35);
            box-shadow: 0 28px 50px rgba(0, 0, 0, 0.65), 0 20px 20px rgba(0, 0, 0, 0.30), 0 0 0 1px rgba(59, 130, 246, 0.15), 0 1px 3px rgba(255, 255, 255, 0.08) inset;
        }

        .input-flex { display: flex; gap: 16px; margin-bottom: 20px; align-items: flex-end; }
        .input-group { display: flex; flex-direction: column; flex-grow: 1; min-width: 0; }
        .input-group.size-group { flex-grow: 0; width: 140px; }
        .input-group.gender-group { flex-grow: 0; width: 105px; }
        .input-group.mode-group { flex-grow: 0; width: 175px; }
        label { min-height: 32px; display: flex; align-items: flex-end; margin-bottom: 8px; font-weight: 500; color: var(--text-muted); font-size: 13px; line-height: 1.2; }
        input[type="text"], select { background: var(--input-bg); border: 1px solid var(--border-color); color: white; padding: 14px 16px; border-radius: 10px; font-size: 15px; transition: all 0.3s ease; font-family: inherit; width: 100%; height: 50px; }
        .input-group.gender-group select { padding: 14px 22px 14px 12px; font-size: 14px; background-position: right 6px center; }
        select { cursor: pointer; -webkit-appearance: none; appearance: none; background-image: url('data:image/svg+xml;utf8,<svg fill="white" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>'); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
        input[type="text"]:focus, select:focus { border-color: var(--accent-blue); outline: none; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }
        button { background: var(--accent-gradient); color: white; border: none; padding: 14px 24px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 15px; transition: all 0.2s ease; display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2); font-family: inherit; }
        button:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3); }
        ul { list-style-type: none; padding: 0; margin: 0; }
        li { background: rgba(255, 255, 255, 0.02); padding: 14px 18px; border-radius: 12px; margin-bottom: 12px; border: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 12px; transition: all 0.2s ease; }
        li:hover { border-color: rgba(255, 255, 255, 0.15); background: rgba(255, 255, 255, 0.04); }
        .deal-item-header { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 16px; }
        .deal-item { border-left: 4px solid var(--accent-green); background: #161c2a; overflow: hidden; }
        
        .product-img { width: 54px; height: 54px; min-width: 54px; border-radius: 6px; object-fit: contain; aspect-ratio: 1 / 1; background: #ffffff !important; border: 1px solid var(--border-color); padding: 4px; }
        
        .deal-info { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
        .item-title { font-weight: 600; color: #ffffff; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .meta-container { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); flex-wrap: wrap; margin-top: 2px; }
        .domain-badge { background: rgba(255, 255, 255, 0.05); color: #e5e7eb; font-size: 11px; font-weight: 500; padding: 2px 6px; border-radius: 4px; text-transform: lowercase; border: 1px solid var(--border-color); white-space: nowrap; }
        .size-badge { background: rgba(59, 130, 246, 0.1); color: #60a5fa; font-size: 11px; font-weight: 500; padding: 2px 6px; border-radius: 4px; border: 1px solid rgba(59, 130, 246, 0.15); white-space: nowrap; }
        .rating-badge { background: rgba(245, 158, 11, 0.1); color: #fbbf24; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 4px; border: 1px solid rgba(245, 158, 11, 0.2); white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
        
        .shield-badge { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 4px; }
        .shield-badge.oem { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.3); }
        .shield-badge.marketplace { background: rgba(156, 163, 175, 0.1); color: #9ca3af; border: 1px solid rgba(156, 163, 175, 0.2); }
        
        .glitch-gauge { background: rgba(239, 68, 68, 0.15); color: #f87171; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 4px; border: 1px solid rgba(239, 68, 68, 0.3); box-shadow: 0 0 10px rgba(239, 68, 68, 0.15); letter-spacing: 0.01em; animation: pulse-border 2s infinite ease-in-out; }
        @keyframes pulse-border { 0%, 100% { border-color: rgba(239, 68, 68, 0.3); } 50% { border-color: rgba(239, 68, 68, 0.7); } }

        .value-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap; }
        .value-badge.best-value { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); box-shadow: 0 0 8px rgba(16, 185, 129, 0.1); }
        .value-badge.verified-retailer { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
        
        /* Updated small-link row block parameters */
        .small-link { color: #60a5fa; text-decoration: none; font-size: 12px; white-space: normal; word-break: break-all; max-width: 100%; display: block; opacity: 0.8; margin-top: 4px; }
        .small-link:hover { text-decoration: underline; color: #3b82f6; opacity: 1; }
        
        .price-tag { background: var(--accent-green); color: white; border-radius: 8px; font-weight: 700; font-size: 16px; text-align: center; white-space: nowrap; min-width: 80px; box-shadow: 0 4px 10px rgba(16, 185, 129, 0.15); padding: 0; transition: transform 0.2s ease; }
        .price-tag:hover { transform: scale(1.03); background: #059669; }
        .price-tag a { display: block; color: white; text-decoration: none; padding: 8px 14px; width: 100%; height: 100%; }
        
        .trend-indicator { font-size: 11px; font-weight: 700; font-family: monospace; margin-top: 4px; text-align: right; white-space: nowrap; }
        .trend-indicator.down { color: var(--accent-red); }
        .trend-indicator.up { color: var(--accent-green); }
        
        .error { color: #ef4444; background: rgba(239, 68, 68, 0.08); padding: 14px; border-radius: 10px; margin-bottom: 20px; border: 1px solid rgba(239, 68, 68, 0.2); font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
        .inline-coupon { background: rgba(245, 158, 11, 0.05); border: 1px dashed rgba(245, 158, 11, 0.3); padding: 8px 12px; border-radius: 8px; display: flex; align-items: center; justify-content: space-between; font-size: 12px; width: fit-content; margin-top: 4px; }
        
        details summary::-webkit-details-marker { display: none; }
        details summary { list-style: none; display: flex; align-items: center; justify-content: center; gap: 8px; background: rgba(255,255,255,0.03); border: 1px solid var(--border-color); padding: 14px; border-radius: 12px; font-size: 14px; font-weight: 600; color: #ffffff; cursor: pointer; transition: all 0.2s ease; margin-top: 15px; }
        details summary:hover { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.15); }
        .loader-box { display: none; margin-top: 20px; }
        .skeleton { background: linear-gradient(90deg, #1b1f32 25%, #252b47 50%, #1b1f32 75%); background-size: 200% 100%; animation: loading-shimmer 1.4s infinite linear; border-radius: 8px; }
        @keyframes loading-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
        svg.icon { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; }
        @media (max-width: 700px) {
            body { padding: 20px 12px; }
            h2 { font-size: 22px; }
            .card { padding: 16px; border-radius: 12px; margin-bottom: 16px; }
            .search-card { transform: translateY(-4px); }
            .search-card:focus-within { transform: translateY(-6px); }
            .input-flex { flex-direction: column; gap: 12px; margin-bottom: 16px; align-items: stretch; }
            .input-group.size-group, .input-group.gender-group, .input-group.mode-group { width: 100%; }
            label { min-height: auto; }
            .deal-item-header { flex-direction: column; align-items: flex-start; gap: 12px; }
            .product-img { width: 48px; height: 48px; min-width: 48px; }
            .deal-info { width: 100%; }
            .item-title { white-space: normal; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
            .small-link { max-width: 100%; display: block; overflow: hidden; margin-top: 4px; }
            .price-tag { width: 100%; text-align: center; }
            button { padding: 12px 16px; font-size: 14px; }
        }
    </style>
    <script>
        function triggerLoadingState() {
            document.getElementById("submit-btn").style.display = "none";
            document.getElementById("loader-zone").style.display = "block";
        }

        function switchViewTab(targetTabId) {
            document.querySelectorAll('.tab-content').forEach(element => element.classList.remove('active'));
            document.querySelectorAll('.tab-btn').forEach(element => element.classList.remove('active'));
            
            document.getElementById(targetTabId + '-view').classList.add('active');
            event.currentTarget.classList.add('active');
        }

        // Fixed Attribute-Driven Multi-Layer Filter Engine Router
        function executeCategoryFilter() {
            const selectedCategory = document.getElementById('type-filter').value;
            const sizeKeyword = document.getElementById('size-filter').value.trim().toLowerCase();
            const selectedGender = document.getElementById('gender-filter').value;
            
            const mainVisibleList = document.getElementById('popular-deals-list');
            const hiddenExtraList = document.getElementById('popular-deals-extra-list');
            const extraDrawerContainer = document.getElementById('popular-extra-details');
            const extraCounterText = document.getElementById('popular-extra-count');
            const placeholderContainer = document.getElementById('popular-empty-state');
            const storagePool = document.getElementById('popular-master-pool');
            
            // Re-route active DOM nodes back to primary master storage pool safely
            while (mainVisibleList.firstChild) { storagePool.appendChild(mainVisibleList.firstChild); }
            while (hiddenExtraList.firstChild) { storagePool.appendChild(hiddenExtraList.firstChild); }
            
            let matchedCount = 0;
            const poolItems = Array.from(storagePool.children);
            
            poolItems.forEach(item => {
                const itemCategory = item.getAttribute('data-type');
                const itemGender = item.getAttribute('data-gender');
                const itemTitle = item.getAttribute('data-title').toLowerCase();
                const itemSize = item.getAttribute('data-size').toLowerCase();
                
                const matchesCategory = (selectedCategory === 'all' || itemCategory === selectedCategory);
                const matchesGender = (selectedGender === 'all' || itemGender === selectedGender || itemGender === 'unisex');
                const matchesSize = (!sizeKeyword || itemTitle.includes(sizeKeyword) || itemSize.includes(sizeKeyword));
                
                if (matchesCategory && matchesGender && matchesSize) {
                    matchedCount++;
                    // Strict 10 + 10 ceiling allocation bounds
                    if (matchedCount <= 10) {
                        mainVisibleList.appendChild(item);
                    } else if (matchedCount <= 20) {
                        hiddenExtraList.appendChild(item);
                    }
                }
            });
            
            // Adjust folder parameters and placeholder visibilities dynamically
            if (matchedCount > 10) {
                extraDrawerContainer.style.display = 'block';
                extraCounterText.textContent = Math.min(matchedCount - 10, 10);
            } else {
                extraDrawerContainer.style.display = 'none';
            }

            if (matchedCount === 0) {
                placeholderContainer.style.display = 'block';
            } else {
                placeholderContainer.style.display = 'none';
            }
        }

        document.addEventListener("DOMContentLoaded", function() {
            const filterDropdown = document.getElementById('type-filter');
            if (filterDropdown) {
                const targetCategories = ["Clothes", "Footwear", "Fragrances", "Electronics"];
                targetCategories.forEach(category => {
                    const optElement = document.createElement('option');
                    optElement.value = category;
                    optElement.textContent = category;
                    filterDropdown.appendChild(optElement);
                });
            }
            // Fire initial run routing allocations
            executeCategoryFilter();
        });
    </script>
</head>
<body>

    {% macro render_deal_row(deal, idx, target_item, coupons, is_ref_url) %}
    <li class="deal-item">
        <div class="deal-item-header">
            <img src="{{ deal.image if deal.image else 'https://placehold.co/100x100/1a1c28/9fa4b4?text=IMG' }}" class="product-img" onerror="this.src='https://placehold.co/100x100/1a1c28/9fa4b4?text=IMG'" />
            <div class="deal-info">
                <span class="item-title">{{ deal.title if deal.title else target_item }}</span>
                <div class="meta-container">
                    <span class="domain-badge">{{ deal.source_domain }}</span>
                    <span class="size-badge">{{ deal.size if deal.size else 'Standard' }}</span>
                    
                    {% if deal.is_third_party %}
                    <span class="shield-badge marketplace">⚠️ Third-Party Merchant</span>
                    {% else %}
                    <span class="shield-badge oem">🛡️ Direct OEM</span>
                    {% endif %}

                    {% if deal.anomaly_prob and deal.anomaly_prob > 45 %}
                    <span class="glitch-gauge">🔥 {{ deal.anomaly_prob }}% Glitch Probability</span>
                    {% endif %}
                    
                    {% if deal.rating %}
                    <span class="rating-badge">
                        <svg class="icon" style="width:11px; height:11px; color:var(--accent-gold); fill:currentColor;" viewBox="0 0 24 24"><path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"/></svg>
                        {{ deal.rating }}{% if deal.reviews %} ({{ deal.reviews|int }}){% endif %}
                    </span>
                    {% endif %}
                    
                    {% if idx == 0 %}
                    <span class="value-badge best-value">
                        <svg class="icon" style="width:12px; height:12px;" viewBox="0 0 24 24"><path d="M12 23l-1.45-1.32C5.4 16.25 2 13.17 2 9.5 2 6.5 4.5 4 7.5 4c1.74 0 3.41.81 4.5 2.09C13.09 4.81 14.76 4 16.5 4 19.5 4 22 6.5 22 9.5c0 3.67-3.4 6.75-8.55 12.18L12 23z"/></svg>
                        Best Value
                    </span>
                    {% endif %}
                    
                    {% if deal.source %}
                    <span class="value-badge verified-retailer">
                        <svg class="icon" style="width:12px; height:12px;" viewBox="0 0 24 24"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/></svg>
                        Verified
                    </span>
                    {% endif %}
                    
                    {% if is_ref_url and deal.url == is_ref_url %}
                    <span class="size-badge" style="background:rgba(59,130,246,0.1); color:#60a5fa; border-color:rgba(59,130,246,0.2)">⭐ Ref Target</span>
                    {% endif %}
                </div>
                <a href="{{ deal.url }}" target="_blank" class="small-link">{{ deal.url }}</a>
            </div>
            <div style="display: flex; flex-direction: column; align-items: flex-end;">
                <span class="price-tag">
                    <a href="{{ deal.url }}" target="_blank">${{ "%.2f"|format(deal.price) }}</a>
                </span>
                {% if idx == 0 and deal.price_delta and deal.price_delta != 0.0 %}
                    {% if deal.price_delta < 0 %}
                    <span class="trend-indicator down">- $ {{ deal.price_delta|abs }}</span>
                    {% else %}
                    <span class="trend-indicator up">+ $ {{ deal.price_delta }}</span>
                    {% endif %}
                {% endif %}
            </div>
        </div>
        
        {% if deal.badge and deal.badge != 'BEST PRICE' %}
        <div class="inline-coupon" style="color: var(--accent-gold); font-weight: 600; letter-spacing: 0.02em;">
            {{ deal.badge }}
        </div>
        {% endif %}
    </li>
    {% endmacro %}

    <h2>
        <svg class="icon" style="width:28px; height:28px; color:var(--accent-blue);" viewBox="0 0 24 24"><path d="M12 2L2 22h20L12 2zm0 3.99L19.53 19H4.47L12 5.99zM13 16h-2v2h2v-2zm0-6h-2v4h2v-4z"/></svg>
        Tarz Price Scout
    </h2>
    <div class="status-line">
        <div class="status-pill"></div>
        <span>{{ status_text }}</span>
    </div>

    {% if error_msg %}
    <div class="error">{{ error_msg }}</div>
    {% endif %}

    <div class="tabs-nav">
        <button class="tab-btn {% if active_tab == 'scan' %}active{% endif %}" onclick="switchViewTab('scan')">
            <svg class="icon" viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>
            On-Demand Engine
        </button>
        <button class="tab-btn {% if active_tab == 'popular' %}active{% endif %}" onclick="switchViewTab('popular')">
            <svg class="icon" viewBox="0 0 24 24"><path d="M12 2l3.09 6.3 6.91 1-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.17 2 9.3l6.91-1L12 2z"/></svg>
            Most Popular Deals
        </button>
    </div>

    <div id="scan-view" class="tab-content {% if active_tab == 'scan' %}active{% endif %}">
        <div class="card search-card">
            <h3>
                <svg class="icon" style="color:var(--accent-blue);" viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>
                Run On-Demand Scan
            </h3>
            <p style="font-size: 12px; color: var(--text-muted); margin-top: -10px; margin-bottom: 15px;">💡 Append an asterisk to force an engine refresh (e.g. <i>nike shorts *</i>)</p>
            <form action="/search" method="post" onsubmit="triggerLoadingState()">
                <div class="input-flex">
                    <div class="input-group">
                        <label>Enter Product Details OR Paste Product Link</label>
                        <input type="text" name="product_name" value="{{ prev_name }}" placeholder="e.g., Creed Green Irish Tweed OR https://www.store.com/item" autocomplete="off" required>
                    </div>
                    <div class="input-group size-group">
                        <label>Size / Variant</label>
                        <input type="text" name="product_size" value="{{ prev_size }}" placeholder="e.g., 3.4 oz, XL, 10.5" autocomplete="off">
                    </div>
                    <div class="input-group gender-group">
                        <label>Gender</label>
                        <select name="product_gender">
                            <option value="unisex" {% if prev_gender == "unisex" %}selected{% endif %}>All</option>
                            <option value="mens" {% if prev_gender == "mens" %}selected{% endif %}>Men's</option>
                            <option value="womens" {% if prev_gender == "womens" %}selected{% endif %}>Women's</option>
                            <option value="kids" {% if prev_gender == "kids" %}selected{% endif %}>Kids'</option>
                        </select>
                    </div>
                    <div class="input-group mode-group">
                        <label>Search Strategy</label>
                        <select name="search_mode">
                            <option value="broad" {% if prev_mode == "broad" %}selected{% endif %}>Broad Exploration</option>
                            <option value="balanced" {% if prev_mode == "balanced" %}selected{% endif %}>Standard Balanced</option>
                            <option value="exact" {% if prev_mode == "exact" %}selected{% endif %}>Precision Match</option>
                        </select>
                    </div>
                </div>
                <button type="submit" id="submit-btn">
                    <svg class="icon" viewBox="0 0 24 24"><path d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z"/></svg>
                    Execute Price Scout Sweep
                </button>
                <div id="loader-zone" class="loader-box">
                    <p style="color: var(--text-muted); font-size: 14px; margin-bottom: 15px; text-align: center;">⚡ Price Scout is assembling structural pricing matrices across real-time storage nodes...</p>
                    <div style="height: 64px; width: 100%; margin-bottom: 12px;" class="skeleton"></div>
                    <div style="height: 64px; width: 100%; margin-bottom: 12px;" class="skeleton"></div>
                    <div style="height: 64px; width: 100%;" class="skeleton"></div>
                </div>
            </form>
        </div>

        {% if show_results %}
        <div class="card" style="border-color: var(--accent-green);">
            <h3>Results Matrix for: <span style="color: var(--accent-blue); margin-left: 4px;"><b>{{ target_item }}{{ size_header }}</b></span></h3>
            
            {% if deals %}
            <p style="color:var(--accent-green); font-weight:600; margin-top:-10px; font-size:15px; margin-bottom: 20px;">🏆 Lowest verified online price: ${{ "%.2f"|format(deals[0].price) }}</p>
            
            <ul style="margin-top: 15px;">
                {% for deal in deals[:10] %}
                    {{ render_deal_row(deal, loop.index0, target_item, coupons, is_ref_url) }}
                {% endfor %}
            </ul>
            
            {% if deals|length > 10 %}
            <details>
                <summary>
                    <svg class="icon" viewBox="0 0 24 24" style="width:14px; height:14px;"><path d="M7 10l5 5 5-5z"/></svg>
                    View Additional Pricing Options (+{{ deals|length - 10 }} more variants found)
                </summary>
                <ul style="margin-top: 15px;">
                    {% for deal in deals[10:20] %}
                        {{ render_deal_row(deal, loop.index0 + 10, target_item, coupons, is_ref_url) }}
                    {% endfor %}
                </ul>
            </details>
            {% endif %}
            
            {% else %}
            <p style="color: var(--text-muted); margin: 0;">⚠️ No verifiable pricing matrices were found matching this selection criteria.</p>
            {% endif %}
        </div>
        {% endif %}
    </div>

    <div id="popular-view" class="tab-content {% if active_tab == 'popular' %}active{% endif %}">
        <div class="card" style="border-color: rgba(245, 158, 11, 0.45);">
            <h3>
                <svg class="icon" style="color:var(--accent-gold);" viewBox="0 0 24 24"><path d="M12 2l3.09 6.3 6.91 1-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.17 2 9.3l6.91-1L12 2z"/></svg>
                Trending Daily Volume Leaders
            </h3>
            <p style="font-size: 12px; color: var(--text-muted); margin-top: -10px; margin-bottom: 15px;">Verified global high-velocity price drops index monitored over the last 24 hours.</p>
            
            <div class="filter-bar">
                <div class="filter-item-box">
                    <span style="font-size: 12px; font-weight: 600; color: var(--text-muted);">Product Category</span>
                    <select id="type-filter" class="filter-select-mini" onchange="executeCategoryFilter()">
                        <option value="all">Show All Categories</option>
                    </select>
                </div>
                
                <div class="filter-item-box">
                    <span style="font-size: 12px; font-weight: 600; color: var(--text-muted);">Size / Variant</span>
                    <input type="text" id="size-filter" class="filter-input-mini" placeholder="e.g. 3.4 oz, XL, 10.5" oninput="executeCategoryFilter()" autocomplete="off">
                </div>
                
                <div class="filter-item-box">
                    <span style="font-size: 12px; font-weight: 600; color: var(--text-muted);">Gender Selection</span>
                    <select id="gender-filter" class="filter-select-mini" onchange="executeCategoryFilter()">
                        <option value="all">All Genders</option>
                        <option value="mens">Men's</option>
                        <option value="womens">Women's</option>
                        <option value="kids">Kids'</option>
                    </select>
                </div>
            </div>

            <div id="popular-empty-state" style="display: none; padding: 20px 0;">
                <p style="color: var(--text-muted); font-size: 14px; margin: 0;">⚡ Syncing live market nodes. No matching products found in the current live feed window.</p>
            </div>

            <ul id="popular-deals-list" style="margin-top: 15px;"></ul>

            <details id="popular-extra-details" style="margin-top: 15px; display: none;">
                <summary>
                    <svg class="icon" viewBox="0 0 24 24" style="width:14px; height:14px;"><path d="M7 10l5 5 5-5z"/></svg>
                    View Additional Trending Options (+<span id="popular-extra-count">0</span> more variants found)
                </summary>
                <ul id="popular-deals-extra-list" style="margin-top: 15px;"></ul>
            </details>

            <ul id="popular-master-pool" style="display: none;">
                {% for deal in popular_deals %}
                <li class="deal-item popular-deal-item" data-type="{{ deal.product_type }}" data-gender="{{ deal.gender }}" data-title="{{ deal.title }}" data-size="{{ deal.size }}">
                    <div class="deal-item-header">
                        <img src="{{ deal.image }}" class="product-img" onerror="this.src='https://placehold.co/100x100/ffffff/000000?text=RETAIL'" />
                        <div class="deal-info">
                            <span class="item-title">{{ deal.title }}</span>
                            <div class="meta-container">
                                <span class="domain-badge">{{ deal.source_domain }}</span>
                                <span class="size-badge">{{ deal.size }}</span>
                                <span class="size-badge" style="background: rgba(245, 158, 11, 0.1); color: var(--accent-gold); border-color: rgba(245, 158, 11, 0.2);">{{ deal.product_type }}</span>
                                
                                {% if deal.is_third_party %}
                                <span class="shield-badge marketplace">⚠️ Third-Party</span>
                                {% else %}
                                <span class="shield-badge oem">🛡️ Direct OEM</span>
                                {% endif %}
                                
                                <span class="rating-badge">
                                    <svg class="icon" style="width:11px; height:11px; color:var(--accent-gold); fill:currentColor;" viewBox="0 0 24 24"><path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"/></svg>
                                    {{ deal.rating }} ({{ deal.reviews }})
                                </span>
                            </div>
                            <a href="{{ deal.url }}" target="_blank" class="small-link">{{ deal.url }}</a>
                        </div>
                        <div style="display: flex; flex-direction: column; align-items: flex-end;">
                            <span class="price-tag" style="background: var(--accent-gold);">
                                <a href="{{ deal.url }}" target="_blank">${{ "%.2f"|format(deal.price) }}</a>
                            </span>
                            <span class="trend-indicator down" style="color: var(--text-muted); text-decoration: line-through; font-weight: 500; font-size: 12px; margin-top: 4px;">
                                ${{ "%.2f"|format(deal.original_price) }}
                            </span>
                        </div>
                    </div>
                    {% if deal.badge %}
                    <div class="inline-coupon" style="color: var(--accent-gold); font-weight: 600; letter-spacing: 0.02em;">
                        {{ deal.badge }}
                    </div>
                    {% endif %}
                </li>
                {% endfor %}
            </ul>

        </div>
    </div>
</body>
</html>