payfrit-portal/scan.html
Zara f8ea11601e Add Payfrit User Portal — scanner, dashboard, compare pages
Consumer-facing portal with mobile-first design:
- scan.html: Barcode scanner with product search, health score ring animation, and healthier alternatives display
- dashboard.html: User dashboard with recent scans, health trends chart, favorites grid, Connected Apps section, and settings
- compare.html: Side-by-side product comparison with winner banner, nutrition breakdown, and ingredient highlights
- products.json: Sample product data with scores, descriptions, and alternatives

Connected Apps section lets users manage third-party integrations
(Apple Health, MyFitnessPal, Google Fit, etc.) with permission controls.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 05:54:19 +00:00

488 lines
17 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Payfrit — Scan Product</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #f5f7fa;
color: #1a1a2e;
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* Header */
.header {
background: #16213e;
color: #fff;
padding: 16px 20px;
display: flex;
align-items: center;
justify-content: space-between;
position: sticky;
top: 0;
z-index: 100;
}
.header .logo { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.header .logo span { color: #4ecca3; }
.header .user-icon {
width: 32px; height: 32px; border-radius: 50%;
background: #4ecca3; display: flex; align-items: center;
justify-content: center; font-size: 14px; font-weight: 600; color: #16213e;
}
/* Scan Area */
.scan-section {
padding: 28px 20px 16px;
text-align: center;
flex-shrink: 0;
}
.scan-section h1 {
font-size: 22px; font-weight: 700; margin-bottom: 6px;
}
.scan-section p {
font-size: 14px; color: #666; margin-bottom: 20px;
}
.scan-btn {
display: inline-flex; align-items: center; gap: 10px;
background: #4ecca3; color: #16213e;
border: none; border-radius: 16px;
padding: 16px 36px; font-size: 17px; font-weight: 700;
cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
box-shadow: 0 4px 16px rgba(78,204,163,0.3);
}
.scan-btn:active { transform: scale(0.96); }
.scan-btn svg { width: 22px; height: 22px; }
/* Search Bar */
.search-section {
padding: 12px 20px 20px;
}
.search-wrap {
position: relative;
}
.search-wrap svg {
position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
width: 18px; height: 18px; color: #999; pointer-events: none;
}
.search-input {
width: 100%; padding: 13px 14px 13px 42px;
border: 1.5px solid #e0e0e0; border-radius: 14px;
font-size: 15px; background: #fff; color: #1a1a2e;
outline: none; transition: border-color 0.2s;
-webkit-appearance: none;
}
.search-input:focus { border-color: #4ecca3; }
.search-input::placeholder { color: #bbb; }
/* Product List */
.product-list {
padding: 0 16px 24px;
}
.list-label {
font-size: 12px; font-weight: 600; color: #999;
text-transform: uppercase; letter-spacing: 0.6px;
margin-bottom: 12px; padding-left: 4px;
}
.list-item {
display: flex; align-items: center; gap: 12px;
background: #fff; border-radius: 16px;
padding: 14px; margin-bottom: 10px;
box-shadow: 0 1px 6px rgba(0,0,0,0.06);
cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
}
.list-item:active { transform: scale(0.98); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.list-emoji {
width: 52px; height: 52px; border-radius: 12px;
background: #f0faf6; display: flex; align-items: center;
justify-content: center; font-size: 26px; flex-shrink: 0;
}
.list-info { flex: 1; min-width: 0; }
.list-info .li-brand { font-size: 11px; color: #999; text-transform: uppercase; letter-spacing: 0.4px; }
.list-info .li-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-info .li-cat { font-size: 12px; color: #aaa; margin-top: 2px; }
.list-score {
font-size: 17px; font-weight: 800; border-radius: 10px;
padding: 6px 10px; flex-shrink: 0;
}
.no-results {
text-align: center; padding: 40px 20px;
color: #999; font-size: 15px;
}
/* Loading */
.loading { display: none; padding: 40px 20px; text-align: center; }
.loading.active { display: block; }
.spinner {
width: 40px; height: 40px; border: 4px solid #e0e0e0;
border-top-color: #4ecca3; border-radius: 50%;
animation: spin 0.7s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Result Card */
.result { display: none; padding: 0 16px 24px; }
.result.active { display: block; }
.product-card {
background: #fff; border-radius: 20px;
box-shadow: 0 2px 20px rgba(0,0,0,0.08);
overflow: hidden;
}
.product-header {
padding: 20px; display: flex; gap: 16px; align-items: center;
}
.product-img {
width: 72px; height: 72px; border-radius: 14px;
background: #e8f5e9; display: flex; align-items: center;
justify-content: center; font-size: 32px; flex-shrink: 0;
}
.product-info { flex: 1; }
.product-info .brand { font-size: 12px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; }
.product-info .name { font-size: 18px; font-weight: 700; margin-top: 2px; }
.product-info .category { font-size: 13px; color: #666; margin-top: 4px; }
/* Health Score */
.score-section {
padding: 0 20px 20px; display: flex; align-items: center; gap: 16px;
}
.score-ring {
position: relative; width: 72px; height: 72px; flex-shrink: 0;
}
.score-ring svg { transform: rotate(-90deg); }
.score-ring .bg { stroke: #e8e8e8; }
.score-ring .fill { stroke-linecap: round; transition: stroke-dashoffset 1s ease; }
.score-value {
position: absolute; inset: 0; display: flex; align-items: center;
justify-content: center; font-size: 24px; font-weight: 800;
}
.score-label { flex: 1; }
.score-label .title { font-size: 15px; font-weight: 700; }
.score-label .desc { font-size: 13px; color: #666; margin-top: 2px; line-height: 1.4; }
/* Divider */
.divider { height: 1px; background: #f0f0f0; margin: 0 20px; }
/* Alternatives */
.alternatives { padding: 20px; }
.alternatives h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; color: #16213e; }
.alt-item {
display: flex; align-items: center; gap: 12px;
padding: 12px; background: #f8faf9; border-radius: 14px;
margin-bottom: 10px; cursor: pointer;
transition: background 0.15s;
}
.alt-item:active { background: #edf5f0; }
.alt-icon {
width: 48px; height: 48px; border-radius: 12px;
background: #e8f5e9; display: flex; align-items: center;
justify-content: center; font-size: 22px; flex-shrink: 0;
}
.alt-info { flex: 1; }
.alt-info .alt-name { font-size: 15px; font-weight: 600; }
.alt-info .alt-brand { font-size: 12px; color: #888; }
.alt-score {
font-size: 18px; font-weight: 800; color: #4ecca3;
background: #e8f5e9; border-radius: 10px; padding: 6px 10px;
}
/* Back / Scan Again */
.action-row {
text-align: center; padding: 8px 20px 32px;
display: flex; gap: 12px; justify-content: center;
}
.action-row button {
background: none; border: 2px solid #16213e;
border-radius: 12px; padding: 12px 24px;
font-size: 15px; font-weight: 600; color: #16213e;
cursor: pointer; flex: 1; max-width: 200px;
}
.action-row button.primary {
background: #4ecca3; border-color: #4ecca3; color: #16213e;
}
.action-row button:active { opacity: 0.8; }
/* Error toast */
.toast {
display: none; position: fixed; bottom: 24px; left: 50%;
transform: translateX(-50%); background: #e53e3e;
color: #fff; border-radius: 12px; padding: 12px 20px;
font-size: 14px; font-weight: 500; z-index: 999;
white-space: nowrap;
}
.toast.show { display: block; animation: fadeIn 0.3s ease; }
/* Animations */
.fade-in { animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
/* Score color helpers */
.score-high { color: #22c55e; }
.score-mid { color: #f59e0b; }
.score-low { color: #ef4444; }
.score-bg-high { background: #dcfce7; }
.score-bg-mid { background: #fef3c7; }
.score-bg-low { background: #fee2e2; }
</style>
</head>
<body>
<div class="header">
<div class="logo">pay<span>frit</span></div>
<div class="user-icon">Z</div>
</div>
<!-- STATE: Home (scan + search) -->
<div id="homeView">
<div class="scan-section">
<h1>Scan a Product</h1>
<p>Point your camera at any barcode to get<br>instant health insights</p>
<button class="scan-btn" id="scanBtn" onclick="startScan()">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round">
<path d="M3 7V5a2 2 0 012-2h2M17 3h2a2 2 0 012 2v2M21 17v2a2 2 0 01-2 2h-2M7 21H5a2 2 0 01-2-2v-2"/>
<line x1="7" y1="8" x2="7" y2="16"/><line x1="11" y1="8" x2="11" y2="16"/>
<line x1="15" y1="8" x2="15" y2="16"/><line x1="19" y1="8" x2="19" y2="16"/>
</svg>
Scan Barcode
</button>
</div>
<div class="search-section">
<div class="search-wrap">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/>
</svg>
<input
type="search"
class="search-input"
id="searchInput"
placeholder="Search products…"
autocomplete="off"
oninput="handleSearch(this.value)"
>
</div>
</div>
<div class="product-list" id="productList">
<div class="list-label">All Products</div>
<div id="listItems"></div>
</div>
</div>
<!-- STATE: Loading -->
<div class="loading" id="loading">
<div class="spinner"></div>
<p style="color:#888; font-size:14px;">Looking up product…</p>
</div>
<!-- STATE: Result -->
<div class="result" id="resultView">
<div class="product-card fade-in" id="productCard">
<!-- injected by JS -->
</div>
<div class="action-row">
<button onclick="goBack()">← Back</button>
<button class="primary" onclick="startScan()">Scan Again</button>
</div>
</div>
<!-- Error toast -->
<div class="toast" id="toast"></div>
<script>
// ─── State ───────────────────────────────────────────────────────────────────
let allProducts = [];
// ─── Boot: load products.json ─────────────────────────────────────────────
async function loadProducts() {
try {
const res = await fetch('products.json');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
allProducts = data.products;
renderList(allProducts);
} catch (err) {
showToast('Could not load product data');
console.error('loadProducts:', err);
}
}
// ─── Render product list ──────────────────────────────────────────────────
function renderList(products) {
const container = document.getElementById('listItems');
if (!products.length) {
container.innerHTML = '<div class="no-results">No products found</div>';
return;
}
container.innerHTML = products.map(p => {
const cls = scoreClass(p.score);
return `
<div class="list-item" onclick="showProduct('${p.id}')">
<div class="list-emoji">${p.emoji}</div>
<div class="list-info">
<div class="li-brand">${p.brand}</div>
<div class="li-name">${p.name}</div>
<div class="li-cat">${p.category} · ${p.size}</div>
</div>
<div class="list-score ${cls.text} ${cls.bg}">${p.score}</div>
</div>`;
}).join('');
}
// ─── Search filter ────────────────────────────────────────────────────────
function handleSearch(query) {
const q = query.trim().toLowerCase();
const label = document.querySelector('.list-label');
if (!q) {
label.textContent = 'All Products';
renderList(allProducts);
return;
}
const filtered = allProducts.filter(p =>
p.name.toLowerCase().includes(q) ||
p.brand.toLowerCase().includes(q) ||
p.category.toLowerCase().includes(q)
);
label.textContent = `Results for "${query.trim()}"`;
renderList(filtered);
}
// ─── Show product detail ──────────────────────────────────────────────────
function showProduct(id) {
const product = allProducts.find(p => p.id === id);
if (!product) return;
// Transition: home → loading → result
hide('homeView');
showEl('loading');
setTimeout(() => {
hide('loading');
renderProductCard(product);
showEl('resultView');
}, 800);
}
function renderProductCard(p) {
const cls = scoreClass(p.score);
const altsHtml = p.alternatives.map(a => {
const ac = scoreClass(a.score);
return `
<div class="alt-item">
<div class="alt-icon">${a.emoji}</div>
<div class="alt-info">
<div class="alt-name">${a.name}</div>
<div class="alt-brand">${a.brand}</div>
</div>
<div class="alt-score ${ac.text} ${ac.bg}">${a.score}</div>
</div>`;
}).join('');
document.getElementById('productCard').innerHTML = `
<div class="product-header">
<div class="product-img">${p.emoji}</div>
<div class="product-info">
<div class="brand">${p.brand}</div>
<div class="name">${p.name}</div>
<div class="category">${p.category} · ${p.size}</div>
</div>
</div>
<div class="score-section">
<div class="score-ring">
<svg width="72" height="72" viewBox="0 0 72 72">
<circle class="bg" cx="36" cy="36" r="30" fill="none" stroke-width="7"/>
<circle class="fill" id="scoreCircle" cx="36" cy="36" r="30" fill="none" stroke-width="7"
stroke="${scoreColor(p.score)}" stroke-dasharray="188.5" stroke-dashoffset="188.5"/>
</svg>
<div class="score-value ${cls.text}" id="scoreValue">0</div>
</div>
<div class="score-label">
<div class="title">Health Score</div>
<div class="desc">${p.scoreDesc}</div>
</div>
</div>
<div class="divider"></div>
<div class="alternatives">
<h3>🌿 Healthier Alternatives</h3>
${altsHtml}
</div>`;
animateScore(p.score);
}
// ─── Scan button (random product) ────────────────────────────────────────
function startScan() {
if (!allProducts.length) {
showToast('Products not loaded yet');
return;
}
hide('homeView');
hide('resultView');
showEl('loading');
setTimeout(() => {
hide('loading');
// Pick a random product to simulate a real scan
const p = allProducts[Math.floor(Math.random() * allProducts.length)];
renderProductCard(p);
showEl('resultView');
}, 1200);
}
// ─── Back to home ─────────────────────────────────────────────────────────
function goBack() {
hide('resultView');
hide('loading');
showEl('homeView');
document.getElementById('searchInput').value = '';
renderList(allProducts);
document.querySelector('.list-label').textContent = 'All Products';
}
// ─── Score helpers ────────────────────────────────────────────────────────
function scoreClass(score) {
if (score >= 7) return { text: 'score-high', bg: 'score-bg-high' };
if (score >= 5) return { text: 'score-mid', bg: 'score-bg-mid' };
return { text: 'score-low', bg: 'score-bg-low' };
}
function scoreColor(score) {
if (score >= 7) return '#22c55e';
if (score >= 5) return '#f59e0b';
return '#ef4444';
}
function animateScore(score) {
const circle = document.getElementById('scoreCircle');
const value = document.getElementById('scoreValue');
const circumference = 188.5;
circle.style.strokeDashoffset = circumference - (score / 10) * circumference;
let current = 0;
const step = score / 30;
const iv = setInterval(() => {
current = Math.min(current + step, score);
value.textContent = current.toFixed(1);
if (current >= score) clearInterval(iv);
}, 25);
}
// ─── Utility ──────────────────────────────────────────────────────────────
function showEl(id) { document.getElementById(id).style.display = ''; }
function hide(id) { document.getElementById(id).style.display = 'none'; }
function showToast(msg) {
const t = document.getElementById('toast');
t.textContent = msg;
t.classList.add('show');
setTimeout(() => t.classList.remove('show'), 3000);
}
// ─── Init ─────────────────────────────────────────────────────────────────
loadProducts();
</script>
</body>
</html>