(() => {
  const pilot = document.querySelector('body.page-category-99 #wa-top50-pilot');
  if (!pilot || pilot.dataset.catalogState) return;

  if (!document.getElementById('wa-top50-style')) {
    const style = document.createElement('style');
    style.id = 'wa-top50-style';
    style.textContent = "\n@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Nunito:wght@400;500;600;700;800&display=swap');\nbody.page-category-99 #incenterpage:has(> #wa-top50-pilot) > h1.title_page { display: none; }\nbody.page-category-99:has(#wa-top50-pilot) #page { overflow: clip !important; }\n#wa-top50-pilot {\n  --ink: var(--wa-ink, #171613);\n  --muted: var(--wa-ink-soft, #57524a);\n  --line: var(--wa-line, #ded9cf);\n  --cream: var(--wa-cream, #f3f0e9);\n  --paper: var(--wa-paper, #fffefa);\n  --wash: var(--wa-orange-wash, #fff5eb);\n  --orange: var(--wa-orange, #f0830e);\n  --orange-hover: var(--wa-orange-hover, #ce6c07);\n  --white: var(--wa-white, #fff);\n  --accent: #ad4606;\n  width: 100%; margin: 0 auto 24px; color: var(--ink);\n  font-family: var(--wa-font-sans, Manrope, 'Segoe UI', Arial, sans-serif);\n  container-type: inline-size;\n}\n#wa-top50-pilot *, #wa-top50-pilot *::before, #wa-top50-pilot *::after { box-sizing: border-box; }\n#wa-top50-pilot img { display: block; max-width: 100%; }\n#wa-top50-pilot a { text-decoration: none; }\n#wa-top50-pilot a:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }\n#wa-top50-pilot .wa-t50-hero { display: grid; grid-template-columns: minmax(0, .92fr) minmax(0, 1.08fr); min-height: 220px; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--cream); }\n#wa-top50-pilot .wa-t50-copy { display: grid; align-content: center; gap: 10px; padding: 24px clamp(24px, 4vw, 54px); }\n#wa-top50-pilot h1 { margin: 0 !important; padding: 0 !important; font-family: var(--wa-font-display, Nunito, 'Segoe UI', Arial, sans-serif); font-weight: 700 !important; font-size: clamp(36px, 4vw, 50px) !important; line-height: 1.03 !important; letter-spacing: -.04em; color: var(--ink); }\n#wa-top50-pilot .wa-t50-copy p { max-width: 350px; margin: 0 !important; color: var(--muted); font-size: 14px; line-height: 1.65; }\n#wa-top50-pilot .wa-t50-hero-photo { position: relative; display: block; }\n#wa-top50-pilot .wa-t50-hero-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 72%; }\n#wa-top50-pilot .wa-t50-caption { position: absolute; right: 10px; bottom: 10px; padding: 6px 10px; background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; font-size: 12px; font-weight: 700; }\n#wa-top50-pilot .wa-t50-filters { display: flex; inline-size: fit-content; max-inline-size: 100%; min-inline-size: 0; margin: 15px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 24px; background: var(--paper); }\n#wa-top50-pilot .wa-t50-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n#wa-top50-pilot .wa-t50-filter { position: relative; min-width: 0; }\n#wa-top50-pilot .wa-t50-filter label { display: grid; place-items: center; min-height: 40px; padding: 0 15px; margin: 0; color: var(--ink); font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer; }\n#wa-top50-pilot .wa-t50-filter:not(:last-child) label { border-inline-end: 1px solid var(--line); }\n#wa-top50-pilot .wa-t50-filter:first-of-type label { border-radius: 24px 0 0 24px; }\n#wa-top50-pilot .wa-t50-filter:last-of-type label { border-radius: 0 24px 24px 0; }\n#wa-top50-pilot .wa-t50-filter input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }\n#wa-top50-pilot:has(#wa-top50-all:checked) label[for=\"wa-top50-all\"],\n#wa-top50-pilot:has(#wa-top50-collection:checked) label[for=\"wa-top50-collection\"],\n#wa-top50-pilot:has(#wa-top50-sofa:checked) label[for=\"wa-top50-sofa\"],\n#wa-top50-pilot:has(#wa-top50-bed:checked) label[for=\"wa-top50-bed\"],\n#wa-top50-pilot:has(#wa-top50-mattress:checked) label[for=\"wa-top50-mattress\"],\n#wa-top50-pilot:has(#wa-top50-table:checked) label[for=\"wa-top50-table\"],\n#wa-top50-pilot:has(#wa-top50-chair:checked) label[for=\"wa-top50-chair\"],\n#wa-top50-pilot:has(#wa-top50-living:checked) label[for=\"wa-top50-living\"] { background: var(--orange); color: var(--white); border-color: var(--orange); font-weight: 750; }\n#wa-top50-pilot:has(#wa-top50-collection:checked) .wa-t50-card:not([data-kind=\"collection\"]),\n#wa-top50-pilot:has(#wa-top50-sofa:checked) .wa-t50-card:not([data-kind=\"sofa\"]),\n#wa-top50-pilot:has(#wa-top50-bed:checked) .wa-t50-card:not([data-kind=\"bed\"]),\n#wa-top50-pilot:has(#wa-top50-mattress:checked) .wa-t50-card:not([data-kind=\"mattress\"]),\n#wa-top50-pilot:has(#wa-top50-table:checked) .wa-t50-card:not([data-kind=\"table\"]),\n#wa-top50-pilot:has(#wa-top50-chair:checked) .wa-t50-card:not([data-kind=\"chair\"]),\n#wa-top50-pilot:has(#wa-top50-living:checked) .wa-t50-card:not([data-kind=\"living\"]) { display: none; }\n#wa-top50-pilot .wa-t50-test-note { margin: 11px 0; color: var(--muted); font-size: 12px; }\n#wa-top50-pilot .wa-t50-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 16px; }\n#wa-top50-pilot .wa-t50-card { display: flex; flex-direction: column; min-width: 0; overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: 16px; }\n#wa-top50-pilot .wa-t50-card:hover, #wa-top50-pilot .wa-t50-card:focus-within { border-color: #cfc8bc; }\n#wa-top50-pilot .wa-t50-photo { position: relative; aspect-ratio: 1.55; overflow: hidden; background: #fff; }\n#wa-top50-pilot .wa-t50-photo img { width: 100%; height: 100%; object-fit: cover; }\n#wa-top50-pilot .wa-t50-card:is([data-kind=\"table\"], [data-kind=\"bed\"], [data-kind=\"chair\"], [data-kind=\"living\"], [data-kind=\"mattress\"]) img { object-fit: contain; }\n#wa-top50-pilot .wa-t50-badge { position: absolute; top: 9px; left: 9px; padding: 4px 8px; border-radius: 999px; background: var(--wash); color: var(--accent); font-size: 11px; font-weight: 750; }\n#wa-top50-pilot .wa-t50-body { display: flex; flex: 1; flex-direction: column; padding: 12px; }\n#wa-top50-pilot h3 { margin: 0 0 7px !important; padding: 0 !important; font-size: 15px; line-height: 1.35; font-weight: 650; color: var(--ink); }\n#wa-top50-pilot .wa-t50-detail { color: var(--muted); margin: 0 0 10px !important; font-size: 13px; line-height: 1.45; }\n#wa-top50-pilot .wa-t50-price { margin: 0 0 10px !important; font-size: 20px; font-weight: 700; }\n#wa-top50-pilot .wa-t50-action { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; margin-top: auto; padding: 5px 4px; text-align: center; background: var(--orange); border: 1px solid var(--orange); border-radius: 8px; color: var(--white) !important; font-size: 13px; font-weight: 700; }\n@media (hover: hover) {\n  #wa-top50-pilot .wa-t50-filter label:hover { background: var(--orange); color: var(--white); border-color: var(--orange); }\n  #wa-top50-pilot .wa-t50-action:hover { background: var(--orange-hover); border-color: var(--orange-hover); }\n}\n@container (max-width: 760px) {\n  #wa-top50-pilot .wa-t50-filters { display: grid; inline-size: 100%; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 5px; margin-top: 9px; border: 0; background: transparent; }\n  #wa-top50-pilot .wa-t50-filter label, #wa-top50-pilot .wa-t50-filter:is(:first-of-type, :last-of-type) label { min-height: 36px; padding: 0 2px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; }\n  #wa-top50-pilot .wa-t50-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }\n}\n@container (max-width: 570px) {\n  #wa-top50-pilot .wa-t50-hero { grid-template-columns: 1fr; min-height: 0; border-radius: 14px; }\n  #wa-top50-pilot .wa-t50-copy { gap: 6px; padding: 14px 15px; }\n  #wa-top50-pilot h1 { font-size: 36px !important; }\n  #wa-top50-pilot .wa-t50-hero-photo { height: clamp(108px, 34vw, 164px); }\n  #wa-top50-pilot .wa-t50-caption { right: 6px; bottom: 6px; font-size: 10px; }\n  #wa-top50-pilot .wa-t50-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }\n  #wa-top50-pilot .wa-t50-card { border-radius: 12px; }\n  #wa-top50-pilot .wa-t50-photo { aspect-ratio: 1.4; }\n  #wa-top50-pilot .wa-t50-body { padding: 8px; }\n  #wa-top50-pilot h3 { font-size: 14px; }\n  #wa-top50-pilot .wa-t50-detail, #wa-top50-pilot .wa-t50-action { font-size: 11px; }\n  #wa-top50-pilot .wa-t50-price { font-size: 17px; }\n}\n@container (max-width: 318px) {\n  #wa-top50-pilot .wa-t50-filters { grid-template-columns: repeat(3,minmax(0,1fr)); }\n}\n\n\n#wa-top50-pilot .wa-t50-hero { min-height: 194px; }\n#wa-top50-pilot .wa-t50-copy { gap: 9px; padding-block: 20px; }\n#wa-top50-pilot .wa-t50-copy p { max-width: 410px; line-height: 1.55; text-wrap: pretty; }\n#wa-top50-pilot .wa-t50-hero-photo img { object-position: center 60%; }\n#wa-top50-pilot .wa-t50-caption { padding: 4px 8px; }\n#wa-top50-pilot .wa-t50-toolbar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 2px; padding: 10px 0; background: var(--paper); border-bottom: 1px solid var(--line); }\n#wa-top50-pilot .wa-t50-filters { margin: 0; }\n#wa-top50-pilot .wa-t50-results { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; }\n#wa-top50-pilot .wa-t50-grid { padding-top: 15px; }\n#wa-top50-pilot:not(:has(#wa-top50-all:checked)) .wa-t50-group { display: none; }\n#wa-top50-pilot .wa-t50-group {\n  grid-column: 1 / -1;\n  display: flex;\n  align-items: center;\n  gap: 11px;\n  margin: 21px 0 0;\n}\n#wa-top50-pilot .wa-t50-group:first-child { margin-top: 0; }\n#wa-top50-pilot .wa-t50-group h2 { margin: 0; font: 700 clamp(22px, 2.3vw, 32px)/1.15 var(--wa-font-display); letter-spacing: -.035em; }\n#wa-top50-pilot .wa-t50-group span { flex: none; font-size: 12px; color: var(--muted); }\n#wa-top50-pilot .wa-t50-group::after { content: ''; flex: 1; height: 1px; margin-left: 4px; background: var(--line); }\n#wa-top50-pilot .wa-t50-card { position: relative; transition: border-color .18s ease, box-shadow .18s ease; }\n#wa-top50-pilot .wa-t50-card:focus-within { border-color: var(--accent); }\n#wa-top50-pilot .wa-t50-photo { margin: 7px 7px 0; border-radius: 10px; }\n#wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] .wa-t50-badge { top: 8px; left: 8px; }\n#wa-top50-pilot .wa-t50-body { padding: 11px 12px 12px; }\n#wa-top50-pilot .wa-t50-body h3 { margin-bottom: 11px !important; line-height: 1.4; }\n#wa-top50-pilot .wa-t50-card-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-top: auto; }\n#wa-top50-pilot .wa-t50-card-footer :is(.wa-t50-detail, .wa-t50-price) { margin: 0 !important; }\n#wa-top50-pilot .wa-t50-card-footer .wa-t50-price { font-size: 17px; }\n#wa-top50-pilot .wa-t50-card-footer .wa-t50-action { margin: 0; padding-inline: 12px; }\n#wa-top50-pilot .wa-t50-card:not([data-kind=\"collection\"]) h3 { margin-bottom: 4px !important; }\n#wa-top50-pilot .wa-t50-card:has(.wa-t50-price) .wa-t50-card-footer { flex: 1; flex-flow: column nowrap; align-items: stretch; justify-content: flex-start; margin-top: 0; gap: 10px; }\n#wa-top50-pilot .wa-t50-card-footer .wa-t50-price + .wa-t50-action { margin-top: auto; }\n#wa-top50-pilot .wa-t50-card .wa-t50-action::after { content: ''; position: absolute; inset: 0; }\n#wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] h3 { font-family: var(--wa-font-display); font-size: 20px; font-weight: 750; }\n#wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] .wa-t50-body { background: var(--paper); }\n@media (hover: hover) {\n  #wa-top50-pilot .wa-t50-card:hover { box-shadow: 0 5px 15px rgba(23, 22, 19, .07); }\n}\n@media (prefers-reduced-motion: reduce) {\n  #wa-top50-pilot .wa-t50-card { transition: none; }\n}\n@container (min-width: 960px) {\n  #wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] { grid-column: span 2; }\n  #wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] .wa-t50-photo { aspect-ratio: 2.85; }\n  #wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] .wa-t50-card-footer { flex-direction: row; align-items: center; }\n  #wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] .wa-t50-action { width: fit-content; padding-inline: 16px; }\n}\n@container (max-width: 1000px) {\n  #wa-top50-pilot .wa-t50-card-footer { flex-direction: column; align-items: stretch; gap: 7px; }\n}\n@container (max-width: 850px) {\n  #wa-top50-pilot .wa-t50-toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; }\n  #wa-top50-pilot:has(#wa-top50-all:checked) .wa-t50-results { display: none; }\n}\n@container (max-width: 570px) {\n  #wa-top50-pilot .wa-t50-hero { min-height: 0; }\n  #wa-top50-pilot .wa-t50-copy { gap: 4px; padding: 9px 12px 8px; }\n  #wa-top50-pilot h1 { font-size: 30px !important; }\n  #wa-top50-pilot .wa-t50-copy p { font-size: 13px; line-height: 1.43; }\n  #wa-top50-pilot .wa-t50-hero-photo { height: clamp(72px, 23vw, 94px); }\n  #wa-top50-pilot .wa-t50-caption { right: 5px; bottom: 5px; padding: 3px 5px; }\n  #wa-top50-pilot .wa-t50-toolbar { padding: 7px 0; }\n  #wa-top50-pilot .wa-t50-grid { padding-top: 11px; }\n  #wa-top50-pilot .wa-t50-group { gap: 8px; margin-top: 16px; }\n  #wa-top50-pilot .wa-t50-group h2 { font-size: 22px; }\n  #wa-top50-pilot .wa-t50-group span { font-size: 11px; }\n  #wa-top50-pilot .wa-t50-photo { margin: 5px 5px 0; border-radius: 7px; }\n  #wa-top50-pilot .wa-t50-body { padding: 8px; }\n  #wa-top50-pilot .wa-t50-body h3 { margin-bottom: 8px !important; }\n  #wa-top50-pilot .wa-t50-card-footer .wa-t50-price { font-size: 15px; }\n  #wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] h3 { font-size: 16px; }\n  #wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] { grid-column: 1 / -1; }\n  #wa-top50-pilot .wa-t50-card[data-kind=\"collection\"] .wa-t50-photo { aspect-ratio: 2.1; }\n}\n\n  \n#wa-top50-pilot .wa-t50-group h2 { margin: 0 !important; width: auto !important; }\n\nbody.page-category-99 #incenterpage > #wa-top50-pilot { grid-column: 1 / -1 !important; }\nbody.page-category-99 #incenterpage:has(> #wa-top50-pilot:is([data-catalog-state=\"loading\"], [data-catalog-state=\"ready\"])) > :is(.products_wrap, .pagination, #products_sorting_box, #centerpage_params_filter_area) { display: none !important; }\n#wa-top50-pilot [hidden] { display: none !important; }\n#wa-top50-pilot .wa-t50-notice { margin: 12px 0 0; color: var(--muted); font-size: 14px; }\n";
    document.head.appendChild(style);
  }

  const robots = document.querySelector('head meta[name="robots"]') || document.head.appendChild(document.createElement('meta'));
  robots.name = 'robots';
  robots.content = 'noindex, follow';

  const initialOrder = [9048,7499,8619,8643,8209,1602,8204,1978,1972,4621,1639,9377,7489,11411,9547,7785,12167,7805,5490,5442,12236,8163,8169,8182,8924,12323,12324,8971,12464,12452,12457,12466,1646,1642,"Provance","Sangero",9545,11875,11877,11878,11879,11872,11713,11712,9147,6247,2048,6257,9931,8986];
  const ranks = new Map(initialOrder.map((key, index) => [key, index]));
  const groups = [
    { title: 'Sedacie súpravy', labels: ['súprava', 'súpravy', 'súprav'] },
    { title: 'Postele', labels: ['posteľ', 'postele', 'postelí'] },
    { title: 'Matrace', labels: ['matrac', 'matrace', 'matracov'] },
    { title: 'Ďalší nábytok', labels: ['položka', 'položky', 'položiek'] },
  ];
  const plurals = new Intl.PluralRules('sk');
  const pluralIndex = { one: 0, few: 1, other: 2 };
  const grid = pilot.querySelector('.wa-t50-grid');
  const categoryRoot = '#incenterpage > .products_wrap';
  const filterGroup = pilot.querySelector('.wa-t50-filters');
  const results = pilot.querySelector('.wa-t50-results');
  const toolbar = pilot.querySelector('.wa-t50-toolbar');
  const notice = pilot.querySelector('.wa-t50-notice');
  const collections = Array.from(grid.querySelectorAll('[data-kind="collection"]'));
  const template = document.createElement('template');
  template.innerHTML = "<article data-kind=\"\" class=\"wa-t50-card\">\n          <div class=\"wa-t50-photo\"><img alt=\"\" decoding=\"async\"></div>\n          <div class=\"wa-t50-body\">\n            <h3></h3>\n            <div class=\"wa-t50-card-footer\">\n              <p class=\"wa-t50-price\"></p>\n              <a class=\"wa-t50-action\">Pozrieť produkt <span aria-hidden=\"true\">→</span></a>\n            </div>\n          </div>\n        </article>";
  const hero = pilot.querySelector('.wa-t50-hero-photo');
  const origin = location.origin;

  function urlOnShop(value) {
    if (!value) return null;
    const url = new URL(value, origin);
    return url.origin === origin && /^https?:$/.test(url.protocol) ? url : null;
  }

  function classify(name) {
    const text = name.normalize('NFD').replace(/\p{M}/gu, '').toLowerCase();
    if (/\b(?:sedac\w*\s+suprav\w*|sedack\w*|modularn\w*\s+seden\w*)\b/.test(text)) return { kind: 'sofa', group: 0 };
    if (/\b(?:pohovk\w*|kresl\w*|usak\w*|taburet\w*|lavick\w*)\b/.test(text)) return { kind: 'sofa', group: 3 };
    if (/\b(?:postel\w*|valend\w*|dvojlozk\w*|jednolozk\w*)\b/.test(text)) return { kind: 'bed', group: 1 };
    if (/\b(?:matrac\w*|topper\w*)\b/.test(text)) return { kind: 'mattress', group: 2 };
    if (/\b(?:stolick\w*|jedalensk\w*\s+lavic\w*)\b/.test(text)) return { kind: 'chair', group: 3 };
    if (/\b(?:tv\s+stol\w*|stol\w*\s+pod\s+tv|vitrin\w*|skrink\w*|komod\w*|obyvac\w*\s+sten\w*)\b/.test(text)) return { kind: 'living', group: 3 };
    if (/\b(?:stol\w*|stolik\w*)\b/.test(text)) return { kind: 'table', group: 3 };
    return { kind: 'other', group: 3 };
  }

  function extractProducts(doc, products) {
    const listing = doc.querySelector(categoryRoot);
    if (!listing) throw new Error('Missing Webareal product list');
    for (const product of listing.querySelectorAll('.product[data-id]')) {
      const id = Number(product.dataset.id);
      if (!Number.isSafeInteger(id) || id <= 0 || products.has(id)) continue;
      const title = product.querySelector('.productTitle a[href]');
      const name = (title?.textContent || product.dataset.name || '').trim();
      const href = urlOnShop(title?.getAttribute('href'));
      if (!name || !href) continue;
      const photo = product.querySelector('.img_box img:not([alt="empty"])');
      const image = urlOnShop(photo?.getAttribute('data-src') || photo?.getAttribute('data-original') || photo?.getAttribute('src'));
      const price = product.querySelector('.product_price_text')?.textContent.trim() || '';
      products.set(id, { id, name, href: href.href, image: image?.href, price, ...classify(name) });
    }
  }

  async function loadCatalog() {
    const products = new Map();
    extractProducts(document, products);
    const path = location.pathname;
    const visited = new Set([Number(new URL(location.href).searchParams.get('page') || 0)]);
    const queue = new Map();
    const enqueue = doc => {
      for (const anchor of doc.querySelectorAll('#incenterpage .pagination a[data-page]')) {
        const next = urlOnShop(anchor.getAttribute('href'));
        const page = Number(anchor.dataset.page);
        if (next?.pathname === path && Number.isSafeInteger(page) && page >= 0 && !visited.has(page)) queue.set(page, next.href);
      }
    };
    enqueue(document);
    if (queue.size) {
      const controller = new AbortController();
      const timeout = setTimeout(() => controller.abort(), 12000);
      try {
        while (queue.size && visited.size < 25) {
          const [page, href] = queue.entries().next().value;
          visited.add(page);
          queue.delete(page);
          const response = await fetch(href, { cache: 'no-cache', signal: controller.signal });
          if (!response.ok) throw new Error('TOP 50 catalog page unavailable');
          const next = new DOMParser().parseFromString(await response.text(), 'text/html');
          extractProducts(next, products);
          enqueue(next);
        }
        if (queue.size) throw new Error('Too many TOP 50 catalog pages');
      } finally {
        clearTimeout(timeout);
      }
    }
    return Array.from(products.values());
  }

  function productCard(product, index) {
    const card = template.content.firstElementChild.cloneNode(true);
    card.dataset.kind = product.kind;
    card.dataset.productId = product.id;
    const image = card.querySelector('img');
    if (product.image) {
      image.src = product.image;
      if (index >= 12) image.loading = 'lazy';
    } else {
      image.remove();
    }
    card.querySelector('h3').textContent = product.name;
    card.querySelector('.wa-t50-price').textContent = product.price || 'Cena na vyžiadanie';
    const action = card.querySelector('a');
    action.href = product.href;
    action.setAttribute('aria-label', 'Pozrieť produkt ' + product.name);
    return card;
  }

  function render(products) {
    const entries = products.concat(collections.map(card => ({ id: card.querySelector('h3').textContent, group: 3, card })));
    entries.sort((a, b) => a.group - b.group || (ranks.get(a.id) ?? Infinity) - (ranks.get(b.id) ?? Infinity));
    const content = document.createDocumentFragment();
    for (const [index, group] of groups.entries()) {
      const groupCards = entries.filter(item => item.group === index);
      if (!groupCards.length) continue;
      const header = document.createElement('div');
      header.className = 'wa-t50-group';
      const title = document.createElement('h2');
      title.textContent = group.title;
      const count = document.createElement('span');
      count.textContent = `${groupCards.length} ${group.labels[pluralIndex[plurals.select(groupCards.length)]]}`;
      header.append(title, count);
      content.appendChild(header);
      for (const item of groupCards) content.appendChild(item.card || productCard(item, content.children.length));
    }
    grid.replaceChildren(content);

    const featured = entries.find(item => item.group === 0 && item.image) || entries.find(item => item.image);
    const collectionLink = collections[0].querySelector('a');
    hero.href = featured?.href || collectionLink.href;
    hero.querySelector('.wa-t50-caption-text').textContent = featured?.name || collections[0].querySelector('h3').textContent;
    if (featured?.id !== initialOrder[0]) {
      hero.querySelector('img').src = featured?.image || collections[0].querySelector('img').src;
    }
  }

  function updateFilters(fromFilter = false) {
    const checked = filterGroup.querySelector(':checked');
    const kind = checked.id.slice('wa-top50-'.length);
    const cards = Array.from(grid.querySelectorAll('.wa-t50-card'));
    const count = kind === 'all' ? cards.length : cards.filter(card => card.dataset.kind === kind).length;
    const prefix = kind === 'all' ? '' : checked.labels[0].textContent + ' · ';
    results.textContent = `${prefix}${count} ${groups[3].labels[pluralIndex[plurals.select(count)]]}`;
    notice.textContent = count ? '' : 'V tejto skupine momentálne nie sú žiadne položky.';
    notice.hidden = count > 0;
    if (fromFilter) {
      const top = toolbar.getBoundingClientRect().bottom;
      const gridTop = grid.getBoundingClientRect().top;
      if (gridTop < top) window.scrollBy({ top: gridTop - top - 8, behavior: 'instant' });
    }
  }

  async function start() {
    try {
      render(await loadCatalog());
      updateFilters();
      filterGroup.addEventListener('change', () => updateFilters(true));
      pilot.dataset.catalogState = 'ready';
    } catch (error) {
      pilot.dataset.catalogState = 'fallback';
      filterGroup.hidden = true;
      results.hidden = true;
      notice.textContent = 'Aktuálne produkty nájdete v zozname pod kolekciami.';
      notice.hidden = false;
      console.error('TOP 50 catalog', error);
    }
  }

  pilot.dataset.catalogState = 'loading';
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start, { once: true });
  else start();
})();
