/******* Do not edit this file *******
Simple Custom CSS and JS - by Silkypress.com
Saved: Sep 28 2025 | 12:17:19 */
<!-- INÍCIO: Botões de Categorias - visual violeta (cole tudo num bloco HTML personalizado) -->
<style>
  :root{
    --violet-1:#8b5cf6;
    --violet-2:#6d28d9;
    --violet-3:#4c1d95;
    --muted:#efe7ff;
  }
  .rx-cats-wrap{ max-width:1100px; margin:28px auto; padding:0 16px 40px; font-family:Inter,system-ui,Arial,Helvetica; }
  .rx-cats-controls{ display:flex; gap:12px; align-items:center; margin-bottom:16px; }
  .rx-cats-title{ font-size:1.5rem; font-weight:800; color:var(--violet-3); }
  .rx-cats-search input{ padding:10px 12px; border-radius:10px; border:1px solid rgba(43,4,59,0.12); min-width:200px; outline:none; }

  /* container para botões (grid fluido) */
  .rx-cats-buttons {
    display:grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap:12px;
  }

  /* cada botão/card */
  .rx-cat-btn {
    display:flex;
    flex-direction:column;
    justify-content:space-between;
    text-decoration:none;
    color:#fff;
    padding:14px 16px;
    border-radius:12px;
    min-height:84px;
    box-shadow: 0 10px 30px rgba(76,29,149,0.12);
    background: linear-gradient(135deg, var(--violet-1) 0%, var(--violet-2) 55%, var(--violet-3) 100%);
    transition: transform .25s ease, box-shadow .25s ease;
    border: 1px solid rgba(255,255,255,0.06);
  }
  .rx-cat-btn:focus, .rx-cat-btn:hover {
    transform: translateY(-6px);
    box-shadow: 0 20px 48px rgba(76,29,149,0.18);
    outline: none;
  }

  .rx-cat-top { display:flex; justify-content:space-between; align-items:center; gap:8px; }
  .rx-cat-name{ font-weight:700; font-size:1.02rem; display:flex; align-items:center; gap:10px; text-shadow: 0 2px 14px rgba(0,0,0,0.18); }
  .rx-cat-emoji{ font-size:1.35rem; transform:translateY(1px); }
  .rx-cat-count{ background: rgba(255,255,255,0.12); padding:6px 10px; border-radius:999px; font-weight:700; font-size:0.85rem; }

  .rx-cat-sub{ margin-top:8px; font-size:0.88rem; opacity:0.95; }

  /* versão grande — um botão por linha (opcional) */
  .rx-cats-list-style .rx-cats-buttons { grid-template-columns: 1fr; }
  .rx-cats-compact .rx-cats-buttons { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

  .rx-cats-empty{ padding:18px; border-radius:10px; background:var(--muted); color:var(--violet-3); text-align:center; }

  .rx-fallback { margin-top:12px; padding:12px; border-radius:10px; background:#fff; box-shadow: 0 4px 18px rgba(43,4,59,0.06); }
  .rx-fallback textarea{ width:100%; min-height:90px; padding:8px; border-radius:8px; border:1px solid #eee; }
  .rx-btn { display:inline-block; padding:8px 12px; border-radius:10px; background:var(--violet-2); color:#fff; text-decoration:none; cursor:pointer; border:none; }
  @media (max-width:560px){ .rx-cats-title{font-size:1.2rem} }
</style>

<div class="rx-cats-wrap rx-cats-list-style" id="rx-cats-wrap">
  <div class="rx-cats-controls">
    <div class="rx-cats-title">Categorias</div>
    <div class="rx-cats-search"><input id="rx-cat-filter" type="search" placeholder="Pesquisar categorias..."></div>
  </div>

  <div id="rx-cats-buttons" class="rx-cats-buttons" aria-live="polite"></div>
  <div id="rx-cats-empty" class="rx-cats-empty" style="display:none">Nenhuma categoria encontrada automaticamente.</div>

  <div class="rx-fallback" id="rx-fallback" style="display:none">
    <strong>Fallback manual:</strong>
    <p>Cole suas categorias no formato <code>Nome|URL|Count</code>, uma por linha:</p>
    <textarea id="rx-manual-data" placeholder="Marketing|https://99rateioscursos.com/categoria/marketing/|120"></textarea>
    <div style="margin-top:8px">
      <button id="rx-manual-apply" class="rx-btn">Aplicar</button>
      <button id="rx-show-debug" style="margin-left:8px" class="rx-btn">Ver console</button>
    </div>
  </div>
</div>

<script>
(function(){
  const DEBUG = true;
  function clog(){ if(!DEBUG) return; console.log.apply(console, ['%c[RX-CATS]','color:#6d28d9;font-weight:700;'].concat(Array.from(arguments))); }
  function textClean(s){ return (s||'').replace(/\\s+/g,' ').trim(); }
  function extractCount(text){
    if(!text) return '';
    const m = text.match(/\\(?(\\d{1,6})\\)?\\s*(?:produtos)?$/i) || text.match(/(\\d{1,6})/);
    return m ? m[1] : '';
  }

  // heurísticas para encontrar lista (mesmas do bloco anterior, simplificado)
  function findList(){
    // tentar por seletores comuns
    const sels = ['ul.product-categories','ul.categories','ul.cat-list','.widget_product_categories','.widget_categories','.wp-block-categories','ul.category-list','.term-list'];
    for(const s of sels){ const el = document.querySelector(s); if(el && el.children.length) return el; }
    // tentar por heading "Categoria|Categorias"
    const headers = Array.from(document.querySelectorAll('h1,h2,h3,h4,.page-title,.entry-title'));
    for(const h of headers){
      if(h.textContent && h.textContent.toLowerCase().includes('categoria')){
        let el = h.nextElementSibling;
        for(let i=0;i<8 && el;i++){
          if(el.tagName && (el.tagName.toLowerCase()==='ul' || el.tagName.toLowerCase()==='ol')) return el;
          const inside = el.querySelector && el.querySelector('ul,ol');
          if(inside) return inside;
          el = el.nextElementSibling;
        }
        const insideParent = h.parentElement && h.parentElement.querySelector('ul,ol');
        if(insideParent) return insideParent;
      }
    }
    // heurística por anchors com '/categoria' no href
    const anchors = Array.from(document.querySelectorAll('a[href]')).filter(a=> /categoria|category|cat\\//i.test(a.getAttribute('href')||'') && (a.textContent||'').trim().length < 70);
    if(anchors.length){
      // criar wrapper temporário
      const wrap = document.createElement('div');
      anchors.forEach(a=>{
        const li = document.createElement('div');
        li.className = 'rx-temp';
        const clone = a.cloneNode(true);
        li.appendChild(clone);
        wrap.appendChild(li);
      });
      return wrap;
    }
    return null;
  }

  function extractItems(listEl){
    const items = [];
    if(!listEl) return items;
    const children = Array.from(listEl.children).filter(Boolean);
    for(const ch of children){
      const a = ch.querySelector && ch.querySelector('a[href]');
      let name='', href='#', count='';
      if(a){
        name = textClean(a.textContent || a.innerText || '');
        href = a.href || a.getAttribute('href') || '#';
        count = extractCount(ch.textContent || a.textContent);
      } else {
        const txt = textClean(ch.textContent || '');
        const m = txt.match(/^(.+?)\\s*\\(?\\s*(\\d{1,6})\\s*\\)?$/);
        if(m){ name = m[1].trim(); count = m[2]; } else name = txt;
      }
      if(name) items.push({name, href, count});
    }
    // se nada, tentar anchors diretos
    if(!items.length){
      const anchors = Array.from(listEl.querySelectorAll && listEl.querySelectorAll('a[href]') || []);
      const seen = new Set();
      anchors.forEach(a=>{
        const href = a.href || a.getAttribute('href') || '#';
        if(seen.has(href)) return;
        seen.add(href);
        const name = textClean(a.textContent||'');
        if(!name) return;
        const count = extractCount(a.textContent || a.parentElement && a.parentElement.textContent);
        items.push({name, href, count});
      });
    }
    return items;
  }

  const container = document.getElementById('rx-cats-buttons');
  const emptyBox = document.getElementById('rx-cats-empty');

  function render(items){
    container.innerHTML = '';
    if(!items || !items.length){
      emptyBox.style.display = 'block';
      return;
    }
    emptyBox.style.display = 'none';
    items.forEach(it=>{
      const a = document.createElement('a');
      a.className = 'rx-cat-btn';
      a.href = it.href || '#';
      a.setAttribute('role','button');
      a.setAttribute('aria-label', it.name + (it.count ? (' — '+it.count+' produtos') : ''));
      a.innerHTML = `
        <div class="rx-cat-top">
          <div class="rx-cat-name"><span class="rx-cat-emoji">${pickEmoji(it.name)}</span><span>${it.name}</span></div>
          <div class="rx-cat-count">${it.count ? it.count : ''}</div>
        </div>
        <div class="rx-cat-sub">Clique para ver os conteúdos</div>
      `;
      container.appendChild(a);
    });
  }

  // emoji rápido
  const emojiMap = { marketing:'📣', design:'🎨', fotografia:'📸', audiovisual:'🎬', programacao:'💻', cursos:'📚', finanças:'💰', saúde:'⚕️', idiomas:'🗣️' };
  function pickEmoji(name){
    const k = (name||'').toLowerCase();
    for(const key in emojiMap) if(k.includes(key)) return emojiMap[key];
    return '📁';
  }

  // busca robusta com retry curto
  function run(){
    clog('Tentando localizar as categorias...');
    const found = findList();
    if(!found){
      clog('Não encontrou automaticamente — mostrando fallback.');
      document.getElementById('rx-fallback').style.display='block';
      render([]);
      return;
    }
    clog('Elemento encontrado:', found);
    const items = extractItems(found);
    clog('Itens extraídos:', items);
    if(items && items.length){
      render(items);
      // esconder original se for ul/ol
      try{ if(found.tagName && (found.tagName.toLowerCase()==='ul' || found.tagName.toLowerCase()==='ol' || found.classList.contains('product-categories'))) { found.style.display='none'; } }catch(e){}
      // ativar busca
      const filter = document.getElementById('rx-cat-filter');
      filter.addEventListener('input', function(e){
        const q = (e.target.value||'').trim().toLowerCase();
        if(!q) return render(items);
        const filtered = items.filter(x=> x.name.toLowerCase().includes(q));
        render(filtered);
      });
    } else {
      clog('Não extraiu itens — mostrando fallback.');
      document.getElementById('rx-fallback').style.display='block';
      render([]);
    }
  }

  // tentar imediatamente e depois retry curto se conteúdo carregar dinamicamente
  run();
  setTimeout(run, 1200);
  setTimeout(run, 3000);

  // fallback manual: parse e aplicar
  document.getElementById('rx-manual-apply').addEventListener('click', function(){
    const raw = document.getElementById('rx-manual-data').value.trim();
    if(!raw) return alert('Cole pelo menos uma linha com Nome|URL|Count');
    const lines = raw.split('\\n').map(s=>s.trim()).filter(Boolean);
    const parsed = [];
    for(const ln of lines){
      const parts = ln.split('|').map(p=>p.trim());
      const name = parts[0] || 'Sem nome';
      const href = parts[1] || '#';
      const count = parts[2] || '';
      parsed.push({name, href, count});
    }
    render(parsed);
  });

  document.getElementById('rx-show-debug').addEventListener('click', function(){
    alert('Abra o console (F12 → Console) e procure por mensagens "[RX-CATS]".');
    clog('Usuário pediu logs — verifique o console.');
  });

})();
</script>
<!-- FIM: Botões de Categorias -->

