{% macro anime_card(anime, in_watchlist=False, lang='vostfr') %}
<div class="card card-compact bg-base-200 shadow-lg hover:shadow-xl transition-all cursor-pointer w-40 shrink-0 group"
     id="anime-{{ anime.url | hash }}"
     @click="activeTab = 'anime'; window.dispatchEvent(new CustomEvent('set-tab', { detail: { tab: 'anime' } })); $nextTick(() => { const input = document.getElementById('animeSearchInput'); if (input) { input.value = '{{ anime.title | e }}'; htmx.trigger(input, 'keyup'); } });">
    <figure class="relative overflow-hidden rounded-t-lg aspect-[2/3]">
        {% set poster = anime.cover_image or (anime.metadata.poster_image if anime.metadata else None) or 'https://placehold.co/400x600/e6e8e6/f15025?text=No+Image' %}
        <img src="{{ poster }}" alt="{{ anime.title }}" loading="lazy" referrerpolicy="no-referrer"
             class="w-full h-full object-cover"
             onerror="this.src='https://placehold.co/400x600/e6e8e6/f15025?text=Error'; this.onerror=null;">
        {% if anime.metadata and anime.metadata.rating %}
        <span class="badge badge-warning badge-sm absolute top-2 left-2 gap-1">
            <i class="fa-solid fa-star text-[10px]"></i> {{ anime.metadata.rating }}
        </span>
        {% endif %}
        <div class="absolute inset-0 bg-primary/20 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center">
            <div class="btn btn-circle btn-sm bg-primary/80 border-primary text-primary-content">
                <i class="fa-solid fa-magnifying-glass"></i>
            </div>
        </div>
    </figure>
    <div class="card-body p-3">
        <span class="badge badge-outline badge-xs">{{ anime.provider_id or 'Anime' }}</span>
        <p class="text-xs font-semibold truncate mt-1">{{ anime.title }}</p>
    </div>
</div>
{% endmacro %}
