Spaces:
Sleeping

File size: 25,340 Bytes
3011f70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2c2c95
3011f70
b2c2c95
3011f70
b2c2c95
 
3011f70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13750df
 
 
46acc57
 
 
 
 
 
 
 
 
 
 
3011f70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e331bf
 
 
 
 
 
 
 
 
3011f70
c7d6810
 
 
 
 
9e331bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3011f70
 
13750df
3011f70
 
 
 
13750df
3011f70
 
 
 
 
 
 
 
9e331bf
13750df
3011f70
13750df
 
 
 
c7d6810
 
 
13750df
c7d6810
 
13750df
c7d6810
3011f70
c7d6810
3011f70
c7d6810
3011f70
 
 
 
c7d6810
3011f70
 
 
 
 
 
 
46acc57
3011f70
c7d6810
 
 
 
 
 
3011f70
 
 
 
 
 
 
13750df
 
 
 
 
 
 
 
 
 
3011f70
c7d6810
 
 
 
 
 
 
 
 
 
 
 
 
 
46acc57
c7d6810
46acc57
 
b2c2c95
 
 
c7d6810
b2c2c95
 
c7d6810
b2c2c95
 
3011f70
 
 
46acc57
13750df
 
3011f70
46acc57
 
 
 
 
 
9e331bf
46acc57
c7d6810
 
 
 
 
 
 
 
 
 
 
 
 
 
3011f70
c7d6810
 
 
 
 
 
 
 
 
 
 
 
 
 
3011f70
 
13750df
3011f70
 
 
 
13750df
 
46acc57
3011f70
13750df
 
3011f70
 
13750df
3011f70
 
13750df
 
 
3011f70
 
 
c7d6810
 
 
 
 
 
 
 
 
 
 
 
 
 
3011f70
 
46acc57
3011f70
 
46acc57
 
13750df
46acc57
 
9e331bf
46acc57
 
 
 
 
 
 
 
c7d6810
9e331bf
c7d6810
 
 
 
 
46acc57
 
 
9e331bf
c7d6810
4696116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fenix Inventory Tracker</title>
<script src="https://unpkg.com/react@18/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
<style>
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  html, body, #root { min-height: 100vh; }
  body { background: #0A0C0F; color: #E8EBF0; font-family: 'Inter', system-ui, sans-serif; overflow-x: hidden; }
  
  ::-webkit-scrollbar { width: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: #FF6B2B55; border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: #FF6B2B88; }
  
  #bg-video {
    position: fixed;
    top: 50%; left: 50%;
    min-width: 100%; min-height: 100%;
    width: auto; height: auto;
    transform: translate(-50%, -50%) scale(1.08);
    z-index: 0;
    filter: blur(14px) brightness(0.18) saturate(1.4);
    pointer-events: none;
  }
  #root { position: relative; z-index: 1; }
  .glass {
    background: rgba(17, 20, 24, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,107,43,0.12);
    border-radius: 10px;
  }
  input, button { font-family: 'Inter', system-ui, sans-serif; }
  input:focus { outline: none; border-color: #FF6B2B !important; }
  @keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
  @keyframes pulse-glow {
    0%,100% { box-shadow: 0 0 12px rgba(255,107,43,0.3); }
    50%      { box-shadow: 0 0 28px rgba(255,107,43,0.6); }
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  .fade-in { animation: fadeIn 0.35s ease both; }
  .nav-btn { background: transparent; border: none; color: #6B7585; font-size: 14px; font-weight: 600; cursor: pointer; padding: 6px 12px; transition: color 0.2s; }
  .nav-btn.active { color: #FF6B2B; border-bottom: 2px solid #FF6B2B; }
  .nav-btn:hover { color: #E8EBF0; }
  
  .filter-pill {
    padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 500; cursor: pointer;
    transition: all 0.2s; border: 1px solid rgba(255,107,43,0.12); background: transparent; color: #6B7585;
  }
  .filter-pill.active {
    border-color: #FF6B2B; background: rgba(255,107,43,0.15); color: #FF6B2B;
  }
  .filter-pill:hover:not(.active) {
    border-color: rgba(255,107,43,0.4); color: #E8EBF0;
  }
</style>
</head>
<body>

<video id="bg-video" autoplay muted loop playsinline>
  <source src="https://aneftqjfbfryvdhdvyiv.supabase.co/storage/v1/object/public/media/Fenixengine.mp4" type="video/mp4" />
</video>

<div id="root"></div>

<script type="text/babel">
const { useState, useMemo, useCallback, useEffect } = React;

const F = {
  bg:         '#0A0C0F',
  card:       'rgba(17,20,24,0.85)',
  hover:      'rgba(24,29,36,0.9)',
  border:     'rgba(255,107,43,0.12)',
  borderHot:  '#FF6B2B',
  accent:     '#FF6B2B',
  accentDim:  '#C44E18',
  accentGlow: 'rgba(255,107,43,0.15)',
  text:       '#E8EBF0',
  muted:      '#6B7585',
  dim:        '#3D4553',
  gold:       '#FFB800',
};

const RARITY_COLORS = {
  'Consumer Grade': '#B0C3D9', 'Base Grade': '#B0C3D9',
  'Industrial Grade': '#5E98D9',
  'Mil-Spec Grade': '#4B69FF', 'High Grade': '#4B69FF',
  'Restricted': '#8847FF', 'Remarkable': '#8847FF',
  'Classified': '#D32CE6', 'Exotic': '#D32CE6',
  'Covert': '#EB4B4B', 'Extraordinary': '#EB4B4B',
  'Gold': '#FFD700', 'Contraband': '#E4AE33',
  'Normal': '#6B7585'
};
const RARITY_WEIGHT = {
  'Normal': 0, 'Base Grade': 1, 'Consumer Grade': 1, 'Industrial Grade': 2,
  'High Grade': 3, 'Mil-Spec Grade': 3, 'Remarkable': 4, 'Restricted': 4,
  'Exotic': 5, 'Classified': 5, 'Extraordinary': 6, 'Covert': 6, 'Contraband': 7, 'Gold': 8
};
const rc = r => RARITY_COLORS[r] || RARITY_COLORS['Normal'];

function getDisplayRarity(item) {
  if (item.isKnife || item.isGlove) return 'Gold';
  
  const r = (item.rarity || '').toLowerCase();
  const wt = (item.weaponType || '').toLowerCase();
  const isWeapon = wt.includes('pistol') || wt.includes('rifle') || 
                   wt.includes('smg') || wt.includes('shotgun') || 
                   wt.includes('machine') || wt.includes('weapon');
                   
  if (r.includes('common') && !r.includes('uncommon')) return isWeapon ? 'Consumer Grade' : 'Base Grade';
  if (r.includes('uncommon')) return 'Industrial Grade';
  if (r.includes('rare')) return isWeapon ? 'Mil-Spec Grade' : 'High Grade';
  if (r.includes('mythical')) return isWeapon ? 'Restricted' : 'Remarkable';
  if (r.includes('legendary')) return isWeapon ? 'Classified' : 'Exotic';
  if (r.includes('ancient')) return isWeapon ? 'Covert' : 'Extraordinary';
  if (r.includes('contraband')) return 'Contraband';
  
  return item.rarity.replace(/ Weapon/gi, '').replace(/_/g, ' '); 
}

function Spinner() {
  return <div style={{width:20,height:20,border:`2px solid ${F.accentGlow}`,borderTopColor:F.accent,borderRadius:'50%',animation:'spin 0.7s linear infinite',display:'inline-block'}} />;
}

function Badge({children, color, bg}) {
  return (
    <span style={{fontSize:10,fontWeight:700,letterSpacing:'0.07em',padding:'2px 7px',borderRadius:4,border:`1px solid ${color}44`,background:bg||`${color}18`,color,whiteSpace:'nowrap'}}>
      {children}
    </span>
  );
}

const PAGE_SIZE = 20;

function App() {
  const [view, setView]       = useState('tracker');
  const [url, setUrl]         = useState('https://steamcommunity.com/id/NotnFaZe');
  const [loading, setLoading] = useState(false);
  const [items, setItems]     = useState([]);
  const [error, setError]     = useState('');
  const [search, setSearch]   = useState('');
  const [fType, setFType]     = useState('All');
  
  // Sorttaus-tila, jota vaihdellaan yläpalkkia klikkaamalla
  const [sortCfg, setSortCfg] = useState({ key: 'price', dir: 'desc' });
  const [page, setPage]       = useState(1);
  const [cachedMsg, setCachedMsg] = useState('');
  
  const [recentChanges, setRecentChanges] = useState([]);
  const [changesFilter, setChangesFilter] = useState('Latest'); // Latest, Most Gained, Most Lost

  const handleScan = useCallback(async (force = false) => {
    if (!url.trim() || loading) return;
    setLoading(true); setError(''); setCachedMsg(''); setView('tracker');
    try {
      const res = await fetch('/api/scrape', {
        method:'POST',
        headers:{'Content-Type':'application/json'},
        body: JSON.stringify({steam_url: url.trim(), force: force}),
      });
      if (!res.ok) {
        const data = await res.json().catch(()=>({}));
        throw new Error(data.detail || `HTTP ${res.status}`);
      }
      const data = await res.json();
      setItems(data.items);
      setUrl(data.resolved_url);
      setPage(1);
      
      if (data.cached) {
        setCachedMsg('Loaded instantly from 24h cache.');
      } else {
        setCachedMsg('Fresh data successfully synced.');
      }
    } catch(e) {
      setError(e.message || 'Failed to fetch inventory.');
    } finally {
      setLoading(false);
    }
  }, [url, loading]);

  const loadRecentChanges = async () => {
    setView('changes');
    try {
      const res = await fetch('/api/recent_changes');
      const data = await res.json();
      setRecentChanges(data.changes || []);
    } catch(e) {
      console.error(e);
    }
  };

  const handleSort = (key) => {
    if (sortCfg.key === key) {
      setSortCfg({ key, dir: sortCfg.dir === 'asc' ? 'desc' : 'asc' });
    } else {
      setSortCfg({ key, dir: 'desc' }); // Oletuksena uusi kolumni alkaa isoimmasta
    }
    setPage(1);
  };
  
  const renderSortIcon = (key) => {
    if (sortCfg.key !== key) return <span style={{opacity:0.2, marginLeft:4}}>↕</span>;
    return <span style={{color:F.accent, marginLeft:4}}>{sortCfg.dir === 'asc' ? '↑' : '↓'}</span>;
  };

  const stats = useMemo(() => {
    return { count: items.length, value: items.reduce((sum, item) => sum + item.price, 0) };
  }, [items]);

  const bulkItems = useMemo(() => {
    const counts = {};
    items.forEach(item => {
      if (!counts[item.name]) counts[item.name] = { name: item.name, count: 0 };
      counts[item.name].count += 1;
    });
    return Object.values(counts).filter(x => x.count > 3).sort((a, b) => b.count - a.count);
  }, [items]);

  const filtered = useMemo(() => {
    let list = [...items];
    if (search) list = list.filter(i => i.name.toLowerCase().includes(search.toLowerCase()));
    
    if (fType === 'Knives') list = list.filter(i => i.isKnife);
    if (fType === 'Gloves') list = list.filter(i => i.isGlove);
    if (fType === 'StatTrak') list = list.filter(i => i.type==='StatTrak');
    if (fType === 'Souvenir') list = list.filter(i => i.type==='Souvenir' && !i.name.includes('Souvenir Package'));
    if (fType === 'Cases') list = list.filter(i => i.weaponType === 'Container' || (i.name.includes('Case') && !i.name.includes('Hardened') && !i.name.includes('Capsule')));
    if (fType === 'Souvenir Packages') list = list.filter(i => i.name.includes('Souvenir Package'));
    if (fType === 'Capsules') list = list.filter(i => i.name.includes('Capsule'));
    if (fType === 'Stickers') list = list.filter(i => i.name.includes('Sticker |'));
    if (fType === 'Graffitis') list = list.filter(i => i.name.includes('Graffiti |') || i.name.includes('Sealed Graffiti'));
    if (fType === 'Keychains') list = list.filter(i => i.name.includes('Charm |')); 
    
    // Sorttaus nouseva/laskeva 
    list.sort((a,b) => {
      let result = 0;
      if (sortCfg.key === 'price') result = b.price - a.price;
      else if (sortCfg.key === 'name') result = a.name.localeCompare(b.name);
      else if (sortCfg.key === 'type') result = a.weaponType.localeCompare(b.weaponType);
      else if (sortCfg.key === 'rarity') {
        const valA = RARITY_WEIGHT[getDisplayRarity(a)] || 0;
        const valB = RARITY_WEIGHT[getDisplayRarity(b)] || 0;
        result = valB - valA;
      }
      return sortCfg.dir === 'asc' ? -result : result; // Kääntää suunnan
    });
    
    return list;
  }, [items, search, fType, sortCfg]);
  
  // Lajitellaan muutoslogi riippuen filtteristä
  const sortedChanges = useMemo(() => {
    let list = [...recentChanges];
    if (changesFilter === 'Most Gained') {
      list.sort((a, b) => b.total_gained - a.total_gained);
      list = list.filter(c => c.total_gained > 0);
    } else if (changesFilter === 'Most Lost') {
      list.sort((a, b) => b.total_lost - a.total_lost);
      list = list.filter(c => c.total_lost > 0);
    }
    return list;
  }, [recentChanges, changesFilter]);

  const totalPages = Math.max(1, Math.ceil(filtered.length / PAGE_SIZE));
  const pageItems = filtered.slice((page-1)*PAGE_SIZE, page*PAGE_SIZE);
  const fmtVal = v => '$' + v.toLocaleString('en-US',{minimumFractionDigits:2,maximumFractionDigits:2});

  return (
    <div style={{minHeight:'100vh',paddingBottom:60}}>
      {/* HEADER */}
      <div style={{position:'sticky',top:0,zIndex:100,background:'rgba(8,10,13,0.88)',backdropFilter:'blur(20px)',borderBottom:`1px solid ${F.border}`,padding:'18px 32px'}}>
        <div style={{maxWidth:1400,margin:'0 auto',display:'flex',alignItems:'center',justifyContent:'space-between',flexWrap:'wrap',gap:14}}>
          <div style={{display:'flex',alignItems:'center',gap:14}}>
            <div style={{width:46,height:46,borderRadius:10,overflow:'hidden',boxShadow:`0 0 22px rgba(255,107,43,0.5)`,animation:'pulse-glow 3s ease-in-out infinite',border:`1px solid rgba(255,107,43,0.35)`}}>
              <img src="/Fenix_red_and_orange.png" alt="Fenix" style={{width:'100%',height:'100%',objectFit:'cover',display:'block'}} />
            </div>
            <div>
              <div style={{fontSize:22,fontWeight:700,fontFamily:"'Bebas Neue',Impact,sans-serif",letterSpacing:'0.08em',color:F.text,lineHeight:1}}>
                FENIX INVENTORY
              </div>
              <div style={{display:'flex', gap:'12px', marginTop:'6px'}}>
                <button className={`nav-btn ${view==='tracker'?'active':''}`} onClick={()=>setView('tracker')}>TRACKER</button>
                <button className={`nav-btn ${view==='changes'?'active':''}`} onClick={loadRecentChanges}>RECENT CHANGES</button>
              </div>
            </div>
          </div>
          
          <div style={{display:'flex', flexDirection:'column', gap:6, flex:'1 1 380px', maxWidth:650}}>
            <div style={{display:'flex',gap:10}}>
              <input value={url} onChange={e=>setUrl(e.target.value)} onKeyDown={e=>e.key==='Enter' && handleScan()} placeholder="Steam profile or Custom URL (/id/name)..." style={{flex:1,background:'rgba(255,255,255,0.05)',border:`1px solid ${F.border}`,borderRadius:8,padding:'10px 14px',color:F.text,fontSize:13}} />
              
              <button onClick={() => handleScan(false)} disabled={loading} style={{padding:'10px 24px',borderRadius:8,fontSize:13,fontWeight:700,border:'none',cursor:loading?'not-allowed':'pointer',background: loading ? F.accentDim : `linear-gradient(135deg, #FF6B2B 0%, #C44E18 100%)`,color:'#fff'}}>
                {loading ? <><Spinner /> SCANNING</> : 'SCAN'}
              </button>
              
              <button onClick={() => handleScan(true)} disabled={loading} style={{padding:'10px 16px',borderRadius:8,fontSize:13,fontWeight:600,border:`1px solid ${F.border}`,cursor:loading?'not-allowed':'pointer',background: 'transparent', color: F.muted}} title="Force full update instead of using cache">
                FORCE
              </button>
            </div>
            {cachedMsg && <div style={{fontSize:11, color:F.accent, paddingLeft:4}}>{cachedMsg}</div>}
          </div>
        </div>
        {error && <div style={{maxWidth:1400,margin:'10px auto 0',padding:'10px 16px',borderRadius:8,background:'rgba(255,68,68,0.12)',border:'1px solid rgba(255,68,68,0.3)',color:'#FF6666',fontSize:13}}>⚠ {error}</div>}
      </div>

      {/* CONTENT AREA */}
      <div style={{maxWidth:1400,margin:'0 auto',padding:'24px'}}>
        {view === 'tracker' && (
          <div style={{ display: 'flex', gap: '24px', alignItems: 'flex-start', flexWrap: 'wrap' }}>
            
            {/* VASEN PUOLI */}
            <div style={{ flex: '1 1 60%', minWidth: '0' }}>
              <div className="glass" style={{display:'flex',gap:12,marginBottom:14,padding:'14px 18px',flexWrap:'wrap',alignItems:'center'}}>
                <input value={search} onChange={e=>{setSearch(e.target.value); setPage(1)}} placeholder="🔍 Search items…" style={{background:'rgba(255,255,255,0.04)',border:`1px solid ${F.border}`,borderRadius:7,padding:'8px 14px',color:F.text,fontSize:13,width:220}} />
                {['All','Knives','Gloves','StatTrak','Souvenir'].map(f=>
                  <button key={f} className={`filter-pill ${fType===f ? 'active' : ''}`} onClick={()=>{setFType(f);setPage(1)}}>{f}</button>
                )}
              </div>

              {/* TÄSSÄ UUSI KLIKKATTAVA LAJITTELU (SORTING) */}
              <div style={{display:'grid',gridTemplateColumns:'40px 3fr 130px 120px 90px',gap:12,padding:'8px 16px',fontSize:10,color:F.muted,letterSpacing:'0.1em',textTransform:'uppercase',borderBottom:`1px solid ${F.border}`,marginBottom:4}}>
                <div style={{textAlign:'right'}}>#</div>
                <div style={{cursor:'pointer', userSelect:'none'}} onClick={()=>handleSort('name')}>NAME {renderSortIcon('name')}</div>
                <div style={{cursor:'pointer', userSelect:'none'}} onClick={()=>handleSort('rarity')}>RARITY {renderSortIcon('rarity')}</div>
                <div style={{cursor:'pointer', userSelect:'none'}} onClick={()=>handleSort('type')}>TYPE {renderSortIcon('type')}</div>
                <div style={{textAlign:'right', cursor:'pointer', userSelect:'none'}} onClick={()=>handleSort('price')}>PRICE {renderSortIcon('price')}</div>
              </div>

              {pageItems.length === 0 ? <div style={{padding:'60px 0',textAlign:'center',color:F.muted}}>No items found. Scan an inventory or clear filters.</div> :
                pageItems.map((item,i) => {
                  const rName = getDisplayRarity(item);
                  return (
                    <div key={`${item.assetId}-${i}`} style={{display:'grid',gridTemplateColumns:'40px 3fr 130px 120px 90px',alignItems:'center',gap:12,padding:'11px 16px',borderRadius:8,borderBottom:`1px solid rgba(255,255,255,0.02)`}}>
                      <div style={{fontSize:12,color:F.dim,textAlign:'right'}}>{(page-1)*PAGE_SIZE+i+1}</div>
                      <div style={{display:'flex',alignItems:'center',gap:8}}>
                        <span style={{width:7,height:7,borderRadius:'50%',background:rc(rName),flexShrink:0}} />
                        <span style={{fontSize:13,color:F.text,whiteSpace:'nowrap',overflow:'hidden',textOverflow:'ellipsis'}}>{item.name}</span>
                      </div>
                      <div><Badge color={rc(rName)}>{rName}</Badge></div>
                      <div style={{fontSize:12,color:F.muted}}>{item.weaponType}</div>
                      <div style={{fontSize:14,fontWeight:700,textAlign:'right',color:item.price>=100?F.accent:F.text}}>${item.price.toFixed(2)}</div>
                    </div>
                  );
                })}

              {totalPages > 1 && (
                <div style={{display:'flex',justifyContent:'center',alignItems:'center',gap:12,padding:'30px 0'}}>
                  <button onClick={()=>setPage(p=>Math.max(1,p-1))} disabled={page===1} style={{padding:'8px 16px',borderRadius:6,border:`1px solid ${F.border}`,background:'transparent',color:page===1?F.dim:F.text,cursor:page===1?'not-allowed':'pointer',fontSize:13}}>← Prev</button>
                  <span style={{color:F.muted,fontSize:13}}>Page <b style={{color:F.text}}>{page}</b> of {totalPages}</span>
                  <button onClick={()=>setPage(p=>Math.min(totalPages,p+1))} disabled={page===totalPages} style={{padding:'8px 16px',borderRadius:6,border:`1px solid ${F.border}`,background:'transparent',color:page===totalPages?F.dim:F.text,cursor:page===totalPages?'not-allowed':'pointer',fontSize:13}}>Next →</button>
                </div>
              )}
            </div>

            {/* OIKEA PUOLI */}
            <div className="glass" style={{ flex: '0 0 320px', position: 'sticky', top: '100px', padding: '24px', display: 'flex', flexDirection: 'column', gap: '28px' }}>
              <div>
                <h3 style={{ fontSize: 12, color: F.muted, letterSpacing: '0.1em', textTransform: 'uppercase', marginBottom: 12, borderBottom: `1px solid ${F.border}`, paddingBottom: 8 }}>Inventory Stats</h3>
                <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
                  <div style={{ background: 'rgba(255,255,255,0.03)', padding: '16px', borderRadius: 8, border: `1px solid ${F.border}` }}>
                    <div style={{ fontSize: 11, color: F.muted, textTransform: 'uppercase', marginBottom: 4 }}>Total Items</div>
                    <div style={{ fontSize: 24, fontWeight: 700, color: F.text, fontFamily: "'Bebas Neue',Impact,sans-serif", letterSpacing: '0.04em' }}>{stats.count}</div>
                  </div>
                  <div style={{ background: 'rgba(255,107,43,0.04)', padding: '16px', borderRadius: 8, border: `1px solid ${F.borderHot}`, boxShadow: `0 0 20px ${F.accentGlow}` }}>
                    <div style={{ fontSize: 11, color: F.accent, textTransform: 'uppercase', marginBottom: 4 }}>Total Value</div>
                    <div style={{ fontSize: 28, fontWeight: 700, color: F.accent, fontFamily: "'Bebas Neue',Impact,sans-serif", letterSpacing: '0.04em' }}>{fmtVal(stats.value)}</div>
                  </div>
                </div>
              </div>

              <div>
                <h3 style={{ fontSize: 12, color: F.muted, letterSpacing: '0.1em', textTransform: 'uppercase', marginBottom: 12, borderBottom: `1px solid ${F.border}`, paddingBottom: 8 }}>Categories</h3>
                <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
                  {['Cases', 'Souvenir Packages', 'Capsules', 'Stickers', 'Graffitis', 'Keychains'].map(f => (
                    <button key={f} onClick={() => { setFType(f); setPage(1); }}
                      style={{ padding: '10px 16px', borderRadius: 6, fontSize: 13, fontWeight: 600, cursor: 'pointer', textAlign: 'left', transition: 'all 0.2s', background: fType === f ? F.accentGlow : 'rgba(255,255,255,0.02)', color: fType === f ? F.accent : F.text, border: `1px solid ${fType === f ? F.borderHot : 'transparent'}`, borderLeft: fType === f ? `3px solid ${F.accent}` : '3px solid transparent' }}>
                      {f}
                    </button>
                  ))}
                </div>
              </div>

              {bulkItems.length > 0 && (
                <div>
                  <h3 style={{ fontSize: 12, color: F.muted, letterSpacing: '0.1em', textTransform: 'uppercase', marginBottom: 12, borderBottom: `1px solid ${F.border}`, paddingBottom: 8 }}>Bulk Items (&gt;3)</h3>
                  <div style={{ display: 'flex', flexDirection: 'column', gap: 8, maxHeight: '300px', overflowY: 'auto', paddingRight: '4px' }}>
                    {bulkItems.map(b => (
                      <div key={b.name} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', background: 'rgba(255,255,255,0.02)', padding: '8px 12px', borderRadius: 6, border: `1px solid ${F.border}` }}>
                        <span style={{ fontSize: 12, color: F.text, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', marginRight: 8 }} title={b.name}>{b.name}</span>
                        <span style={{ fontSize: 11, fontWeight: 700, color: F.accent, background: F.accentGlow, padding: '2px 6px', borderRadius: 4, flexShrink: 0 }}>{b.count}x</span>
                      </div>
                    ))}
                  </div>
                </div>
              )}
            </div>
          </div>
        )}

        {view === 'changes' && (
          <div className="glass fade-in" style={{padding: '24px'}}>
            <div style={{display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '20px'}}>
              <h2 style={{color: F.accent, fontSize: 20, textTransform: 'uppercase', letterSpacing: '0.05em'}}>24H Inventory Changes</h2>
              
              <div style={{display:'flex', gap:10}}>
                {['Latest', 'Most Gained', 'Most Lost'].map(filt => (
                  <button key={filt} className={`filter-pill ${changesFilter === filt ? 'active' : ''}`} onClick={() => setChangesFilter(filt)}>
                    {filt}
                  </button>
                ))}
              </div>
            </div>
            
            <div style={{display:'grid',gridTemplateColumns:'1.5fr 1fr 1fr 2fr',gap:12,padding:'8px 16px',fontSize:10,color:F.muted,textTransform:'uppercase',borderBottom:`1px solid ${F.border}`}}>
              <div>Profile URL</div><div>Time</div><div>Summary</div><div>Details (Top 3)</div>
            </div>
            
            {sortedChanges.length === 0 ? <div style={{padding:'40px 0',textAlign:'center',color:F.muted}}>No recent changes matching filters.</div> :
              sortedChanges.map((c, i) => (
                <div key={i} style={{display:'grid',gridTemplateColumns:'1.5fr 1fr 1fr 2fr',alignItems:'center',gap:12,padding:'14px 16px',borderBottom:`1px solid rgba(255,255,255,0.02)`}}>
                  <div style={{fontSize:13, overflow:'hidden', textOverflow:'ellipsis'}}><a href={c.url} target="_blank" style={{color:F.text,textDecoration:'none'}}>{c.url}</a></div>
                  <div style={{fontSize:12,color:F.muted}}>{new Date(c.time * 1000).toLocaleString()}</div>
                  <div style={{fontSize:13, display:'flex', gap:8}}>
                    {c.total_gained > 0 && <span style={{color:'#4CAF50', fontWeight:600}}>+{c.total_gained} Gained</span>}
                    {c.total_lost > 0 && <span style={{color:'#F44336', fontWeight:600}}>-{c.total_lost} Lost</span>}
                    {c.total_gained === 0 && c.total_lost === 0 && <span style={{color:F.muted}}>Unchanged</span>}
                  </div>
                  <div style={{fontSize:12, color:F.dim, display:'flex', flexDirection:'column', gap:4}}>
                    {c.gained.slice(0,3).map((item, idx) => <span key={'g'+idx} style={{color:'#4CAF50'}}>+{item.amount} {item.name}</span>)}
                    {c.lost.slice(0,3).map((item, idx) => <span key={'l'+idx} style={{color:'#F44336'}}>-{item.amount} {item.name}</span>)}
                  </div>
                </div>
              ))}
          </div>
        )}
      </div>
    </div>
  );
}
ReactDOM.createRoot(document.getElementById('root')).render(<App />);
</script>
</body>
</html>