// Demo products and supporting data
const DEMO_PRODUCTS = {
  mugen: {
    id: "mugen",
    query: "ท่อ Brand MUGEN SX32221GSA",
    resolvedName: "MUGEN SX32221GSA Exhaust Tip",
    thai: "ปลายท่อไอเสีย MUGEN SX32221GSA",
    category: "Automotive / Aftermarket",
    sku: "SX32221GSA",
    brand: "MUGEN",
    origin: "Japan (mfg) / Shenzhen (distrib)",
    hsCode: "8708.92.60",
    image: "EXHAUST TIP",
    tier: "Mid-tier aftermarket",
    expectedConfidence: 0.62,
    candidates: [
      { name: "MUGEN SX32221GSA — Titanium Slash-Cut", variant: "Ø 60mm · 380mm", match: 0.91, note: "Exact SKU match on 1688", selected: true },
      { name: "MUGEN SX32221G — Steel Dual-Wall",     variant: "Ø 60mm · 380mm", match: 0.74, note: "Earlier revision (no 'SA' suffix)" },
      { name: "MUGEN-STYLE SX32-22 Replica",           variant: "Ø 57mm · 360mm", match: 0.41, note: "OEM replica, different dimensions" },
    ],
    landed: { fob_cny: 62, fob_usd: 8.6, freight_thb: 95, duty_pct: 20, vat_pct: 7, extra_thb: 40, landed_thb: 320 },
    recommended: [890, 1450],
    confidence: {
      overall: 0.62,
      product_identification: 0.95,
      th_market_coverage: 0.30,
      variant_match: 0.80,
      price_source_quality: 0.70,
      synthesis_reasoning: 0.85,
    },
    competitors: [
      { source: "Shopee TH",    price_thb: 890,  seller: "MUGEN_TH_Official", seller_type: "official", listings: 3, stock: "in stock" },
      { source: "Shopee TH",    price_thb: 1190, seller: "JDM_Bangkok",       seller_type: "reseller", listings: 11, stock: "in stock" },
      { source: "Lazada TH",    price_thb: 1200, seller: "CarPartsMall",      seller_type: "reseller", listings: 4, stock: "limited" },
      { source: "Lazada TH",    price_thb: 1450, seller: "DriftGarageTH",     seller_type: "reseller", listings: 2, stock: "in stock" },
      { source: "TikTok Shop",  price_thb: null, seller: "—",                 seller_type: "—",         listings: 0, stock: "no match" },
      { source: "Priceza",      price_thb: 1080, seller: "aggregated median", seller_type: "—",        listings: 7, stock: "—" },
    ],
    china: [
      { source: "1688.com",   price_cny: 62, price_usd: 8.6, moq: 10, supplier: "Shenzhen JD Auto" },
      { source: "1688.com",   price_cny: 71, price_usd: 9.8, moq: 5,  supplier: "Guangzhou KR Parts" },
      { source: "Alibaba",    price_cny: 84, price_usd: 11.6, moq: 20, supplier: "Ningbo Export Co." },
    ],
    warnings: [
      "No TikTok Shop match — skip TT retail signal",
      "Shopee official store undercuts resellers by ~25% (anchor low-end)",
      "Only 6 TH listings total — thin market",
    ],
    timeline: [
      { t: "00:00.0", step: "RESOLVE",       detail: "Odoo MCP query · 0 matches · vector search · 2 fuzzy matches below threshold" },
      { t: "00:01.3", step: "DISAMBIGUATE",  detail: "Web pre-flight · 3 candidates surfaced · ฿1.10 spent" },
      { t: "00:08.4", step: "USER CONFIRM",  detail: "Variant #1 confirmed (SX32221GSA Titanium)" },
      { t: "00:08.7", step: "DISPATCH",      detail: "6 browser agents spawned via Playwright + TH residential proxy" },
      { t: "00:22.1", step: "SHOPEE TH",     detail: "2 listings captured · median ฿1040" },
      { t: "00:24.8", step: "LAZADA TH",     detail: "2 listings captured · median ฿1325" },
      { t: "00:26.2", step: "TIKTOK SHOP",   detail: "Apify actor returned 0 results" },
      { t: "00:31.0", step: "1688.COM",      detail: "FOB baseline locked at ¥62" },
      { t: "00:33.4", step: "ALIBABA",       detail: "Fallback reference ¥84" },
      { t: "00:35.9", step: "PRICEZA",       detail: "Aggregated median ฿1080" },
      { t: "00:38.2", step: "SYNTHESIS",     detail: "Sonnet 4.5 · 4.2k input / 1.1k output tokens" },
      { t: "00:41.0", step: "COMPLETE",      detail: "Recommendation band ฿890–฿1450 · confidence 0.62 · log-only" },
    ],
    cost: { haiku_thb: 3.40, sonnet_thb: 8.10, proxy_thb: 2.20, apify_thb: 0.80, search_thb: 1.10, total_thb: 15.60 },
  },

  xiaomi: {
    id: "xiaomi",
    query: "Xiaomi Robot Vacuum X20+",
    resolvedName: "Xiaomi Robot Vacuum X20+",
    thai: "หุ่นยนต์ดูดฝุ่น Xiaomi X20+",
    category: "Smart Home / Appliance",
    sku: "BHR7491EU",
    brand: "Xiaomi",
    origin: "Shenzhen, CN",
    hsCode: "8508.11.00",
    image: "ROBOT VACUUM",
    tier: "Branded consumer electronics",
    expectedConfidence: 0.88,
    candidates: [
      { name: "Xiaomi Robot Vacuum X20+",        variant: "White · EU plug", match: 0.97, note: "Exact SKU on Shopee Mall, Lazada Mall", selected: true },
      { name: "Xiaomi Robot Vacuum X20",          variant: "White · EU plug", match: 0.82, note: "Non-plus variant, slightly weaker suction" },
      { name: "Xiaomi Robot Vacuum S20+ Pro",     variant: "Black · CN plug",  match: 0.55, note: "Different model line" },
    ],
    landed: { fob_cny: 1450, fob_usd: 200, freight_thb: 420, duty_pct: 0, vat_pct: 7, extra_thb: 180, landed_thb: 7920 },
    recommended: [10900, 12490],
    confidence: {
      overall: 0.88,
      product_identification: 0.98,
      th_market_coverage: 0.92,
      variant_match: 0.95,
      price_source_quality: 0.86,
      synthesis_reasoning: 0.90,
    },
    competitors: [
      { source: "Shopee TH",    price_thb: 10990, seller: "Xiaomi Official Store", seller_type: "official", listings: 1,  stock: "in stock" },
      { source: "Shopee TH",    price_thb: 11590, seller: "Mi Thailand",           seller_type: "official", listings: 2,  stock: "in stock" },
      { source: "Lazada TH",    price_thb: 11990, seller: "Xiaomi LazMall",        seller_type: "official", listings: 3,  stock: "in stock" },
      { source: "Lazada TH",    price_thb: 12490, seller: "HomeTech TH",           seller_type: "reseller", listings: 8,  stock: "in stock" },
      { source: "TikTok Shop",  price_thb: 11290, seller: "Xiaomi TT Official",    seller_type: "official", listings: 4,  stock: "in stock" },
      { source: "Priceza",      price_thb: 11590, seller: "aggregated median",     seller_type: "—",        listings: 34, stock: "—" },
    ],
    china: [
      { source: "1688.com",   price_cny: 1450, price_usd: 200.2, moq: 1, supplier: "Xiaomi Authorized" },
      { source: "1688.com",   price_cny: 1520, price_usd: 209.8, moq: 2, supplier: "SZ Bulk Dist." },
      { source: "Alibaba",    price_cny: 1680, price_usd: 231.9, moq: 5, supplier: "Global Home Export" },
    ],
    warnings: [
      "Tight margin · official store price only 38% above landed",
      "Xiaomi TH enforces MAP — reseller undercutting risk low",
    ],
    timeline: [
      { t: "00:00.0", step: "RESOLVE",       detail: "Odoo match · existing record · last_synced 12 days ago" },
      { t: "00:00.8", step: "DISAMBIGUATE",  detail: "Web pre-flight · 3 candidates · ฿0.90 spent" },
      { t: "00:06.2", step: "USER CONFIRM",  detail: "Variant #1 confirmed (X20+)" },
      { t: "00:06.4", step: "DISPATCH",      detail: "6 browser agents spawned" },
      { t: "00:18.2", step: "SHOPEE TH",     detail: "2 listings · median ฿11290" },
      { t: "00:20.1", step: "LAZADA TH",     detail: "2 listings · median ฿12240" },
      { t: "00:22.9", step: "TIKTOK SHOP",   detail: "1 listing · ฿11290" },
      { t: "00:28.3", step: "1688.COM",      detail: "FOB ¥1450" },
      { t: "00:30.8", step: "ALIBABA",       detail: "Fallback ¥1680" },
      { t: "00:32.1", step: "PRICEZA",       detail: "34-listing median ฿11590" },
      { t: "00:35.4", step: "SYNTHESIS",     detail: "Sonnet 4.5 · 5.1k / 1.4k tokens" },
      { t: "00:38.1", step: "COMPLETE",      detail: "Band ฿10900–฿12490 · confidence 0.88 · AUTO-PERSIST" },
    ],
    cost: { haiku_thb: 4.10, sonnet_thb: 9.60, proxy_thb: 2.40, apify_thb: 0.80, search_thb: 0.90, total_thb: 17.80 },
  },

  oem: {
    id: "oem",
    query: "白标 蓝牙音箱 BT-X77 IP67",
    resolvedName: "Generic OEM Bluetooth Speaker BT-X77 (white label)",
    thai: "ลำโพงบลูทูธ OEM BT-X77",
    category: "Consumer Electronics / OEM",
    sku: "BT-X77",
    brand: "Unbranded / white-label",
    origin: "Shenzhen, CN",
    hsCode: "8518.22.00",
    image: "BT SPEAKER",
    tier: "OEM / white-label",
    expectedConfidence: 0.37,
    candidates: [
      { name: "BT-X77 IP67 Bluetooth Speaker (unbranded)", variant: "10W · 2000mAh", match: 0.61, note: "Matches on 1688 generic listing", selected: true },
      { name: "Generic BT-X77 — rebadged by 6 sellers",     variant: "10W · 2000mAh", match: 0.58, note: "Same hardware, different brands" },
      { name: "BT-X77A (updated 20W)",                      variant: "20W · 3200mAh", match: 0.33, note: "Newer revision" },
    ],
    landed: { fob_cny: 28, fob_usd: 3.9, freight_thb: 45, duty_pct: 20, vat_pct: 7, extra_thb: 25, landed_thb: 228 },
    recommended: [380, 890],
    confidence: {
      overall: 0.37,
      product_identification: 0.45,
      th_market_coverage: 0.20,
      variant_match: 0.55,
      price_source_quality: 0.35,
      synthesis_reasoning: 0.55,
    },
    competitors: [
      { source: "Shopee TH",    price_thb: 389, seller: "ChinaDropTH",       seller_type: "drop-shipper", listings: 24, stock: "in stock" },
      { source: "Shopee TH",    price_thb: 599, seller: "EcoBassMart",       seller_type: "drop-shipper", listings: 12, stock: "in stock" },
      { source: "Lazada TH",    price_thb: 890, seller: "SoundGearTH",       seller_type: "reseller",      listings: 3,  stock: "low" },
      { source: "TikTok Shop",  price_thb: 420, seller: "live-stream seller",seller_type: "drop-shipper", listings: 6,  stock: "in stock" },
      { source: "Priceza",      price_thb: 499, seller: "aggregated median", seller_type: "—",            listings: 19, stock: "—" },
    ],
    china: [
      { source: "1688.com", price_cny: 28, price_usd: 3.9, moq: 50,  supplier: "Shenzhen Audio Tech" },
      { source: "1688.com", price_cny: 32, price_usd: 4.4, moq: 20,  supplier: "Huaqiangbei OEM" },
      { source: "Alibaba",  price_cny: 41, price_usd: 5.7, moq: 100, supplier: "Global Audio Export" },
    ],
    warnings: [
      "Only drop-shipper listings found — no official brand anchor",
      "Wide price spread (฿389–฿890) — suggests arbitrage, not stable market",
      "Variant match only 61% — multiple rebadged versions exist",
      "Below 75% threshold — log only, not persisted to Odoo",
    ],
    timeline: [
      { t: "00:00.0", step: "RESOLVE",       detail: "Odoo · 0 matches · vector search · 1 weak match (0.44 cosine)" },
      { t: "00:01.8", step: "DISAMBIGUATE",  detail: "Web pre-flight · 3 ambiguous candidates · ฿1.30" },
      { t: "00:11.2", step: "USER CONFIRM",  detail: "Variant #1 selected (generic, best available)" },
      { t: "00:11.5", step: "DISPATCH",      detail: "6 agents spawned" },
      { t: "00:24.9", step: "SHOPEE TH",     detail: "2 listings · dropshipper chatter" },
      { t: "00:27.1", step: "LAZADA TH",     detail: "1 listing · low confidence seller" },
      { t: "00:29.8", step: "TIKTOK SHOP",   detail: "1 listing · live-stream flash price" },
      { t: "00:34.2", step: "1688.COM",      detail: "FOB ¥28 · 12 comparable suppliers" },
      { t: "00:36.7", step: "ALIBABA",       detail: "Fallback ¥41" },
      { t: "00:38.9", step: "PRICEZA",       detail: "Noisy 19-listing median" },
      { t: "00:42.1", step: "SYNTHESIS",     detail: "Sonnet 4.5 · flagged low confidence" },
      { t: "00:45.0", step: "COMPLETE",      detail: "Band ฿380–฿890 · confidence 0.37 · LOG ONLY" },
    ],
    cost: { haiku_thb: 3.90, sonnet_thb: 8.40, proxy_thb: 2.30, apify_thb: 0.80, search_thb: 1.30, total_thb: 16.70 },
  },
};

const HISTORY = [
  { ts: "2026-04-20 14:22", product: "MUGEN SX32221GSA exhaust tip",      conf: 0.62, band: "฿890–1450",   status: "LOG"  },
  { ts: "2026-04-20 13:51", product: "Anker 735 GaNPrime 65W",             conf: 0.91, band: "฿1890–2190",  status: "AUTO" },
  { ts: "2026-04-20 12:08", product: "Xiaomi Robot Vacuum X20+",            conf: 0.88, band: "฿10900–12490",status: "AUTO" },
  { ts: "2026-04-20 11:33", product: "Generic BT-X77 IP67 Bluetooth spkr", conf: 0.37, band: "฿380–890",    status: "LOG"  },
  { ts: "2026-04-20 10:47", product: "JVC HA-S20BT headphones",            conf: 0.74, band: "฿590–790",    status: "QUEUE"},
  { ts: "2026-04-20 09:55", product: "Unbranded Ø60 silencer adapter",     conf: 0.31, band: "฿120–340",    status: "LOG"  },
  { ts: "2026-04-19 17:21", product: "Baseus 100W USB-C cable 2m",          conf: 0.84, band: "฿290–390",    status: "AUTO" },
  { ts: "2026-04-19 16:02", product: "HOTONE Ampero II Stomp",              conf: 0.79, band: "฿13900–15900",status: "QUEUE"},
  { ts: "2026-04-19 14:11", product: "Generic mini dashcam 1080p",          conf: 0.44, band: "฿450–1290",   status: "LOG"  },
  { ts: "2026-04-19 11:30", product: "Tronsmart Bang Max",                  conf: 0.81, band: "฿4290–4890",  status: "QUEUE"},
];

const CALIBRATION = [
  { bucket: "Branded well-known", expected: 0.88, actual: 0.87, n: 18 },
  { bucket: "Mid-tier CN brand",  expected: 0.72, actual: 0.69, n: 34 },
  { bucket: "OEM / white-label",  expected: 0.50, actual: 0.47, n: 28 },
  { bucket: "Obscure SKU",        expected: 0.35, actual: 0.33, n: 20 },
];

const SOURCES_META = [
  { key: "shopee",   label: "Shopee TH",     role: "TH retail · primary",    color: "#E30613" },
  { key: "lazada",   label: "Lazada TH",     role: "TH retail · secondary",  color: "#2E5BFF" },
  { key: "tiktok",   label: "TikTok Shop",   role: "TH retail · Apify",      color: "#0A0A0A" },
  { key: "a1688",    label: "1688.com",      role: "CN FOB · primary",       color: "#FFD400" },
  { key: "alibaba",  label: "Alibaba",       role: "CN FOB · fallback",      color: "#17A34A" },
  { key: "priceza",  label: "Priceza",       role: "TH aggregator",          color: "#F59E0B" },
];

window.DEMO_PRODUCTS = DEMO_PRODUCTS;
window.HISTORY = HISTORY;
window.CALIBRATION = CALIBRATION;
window.SOURCES_META = SOURCES_META;
