/* Dark Mode Template Cards for Home & Templates Pages */
.template-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    /* Default to 3 columns */
    gap: 2rem;
    justify-content: center;
    animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.template-card {
    background: var(--bg-card, #242426);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
    border-radius: 16px;
    overflow: visible;
    transition: all 0.2s ease;
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.template-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary, #a855f7);
    box-shadow: 0 0 0 1px var(--primary-glow, rgba(168, 85, 247, 0.15));
}

/* Featured Card Purple Border */
.template-card.featured-flame {
    border: 2.5px solid rgba(168, 85, 247, 0.7);
    box-shadow: 0 0 16px rgba(168, 85, 247, 0.2), 0 0 0 1px rgba(168, 85, 247, 0.15);
}

.template-card.featured-flame:hover {
    border-color: rgba(168, 85, 247, 1);
    box-shadow: 0 0 24px rgba(168, 85, 247, 0.35), 0 0 0 2px rgba(168, 85, 247, 0.4);
}

.template-card.menu-open {
    z-index: 100 !important;
}

.template-card .template-image {
    width: 100%;
    height: 220px;
    object-fit: cover;
    transition: transform 0.5s ease;
    border-radius: 20px 20px 0 0;
}

.template-card:hover .template-image {
    transform: scale(1.05);
}

.template-content {
    padding: 0.8rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0;
    /* Gap handled by child margins */
    min-height: auto;
    /* Reduced for more compact cards */
    overflow: visible;
    /* CRITICAL: Allow dropdown to escape content box */
    justify-content: flex-start;
}

/* Header Elements: Price, Creator, Dots */
.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
    width: 100%;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    align-items: flex-start;
    /* CRITICAL: Prevent tags from stretching wide */
}

/* Header Elements: Price */
.price {
    font-size: 1rem;
    font-weight: 800;
    background: var(--gradient-1);
    color: var(--neon-cyan);
    /* -webkit-background-clip: text; Remove this */
    /* -webkit-text-fill-color: transparent; Remove this to ensure visibility */
    background-clip: unset;
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    white-space: nowrap;
    margin-bottom: 0.2rem;
}

.price-npr {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    -webkit-text-fill-color: var(--text-secondary);
    white-space: nowrap;
}

/* Pricing Discount Styles */
.disc-price {
    color: var(--neon-cyan);
    font-weight: 800;
}

.orig-price-strikethrough {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-decoration: line-through;
    opacity: 0.7;
    margin-left: 2px;
}

.price-separator {
    margin: 0 4px;
    color: var(--text-secondary);
    opacity: 0.5;
    font-weight: 400;
}

.disc-price-sec {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.orig-price-strikethrough-sec {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-decoration: line-through;
    opacity: 0.5;
    margin-left: 1px;
}

/* Base Creator Tag Styles */
.creator-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    vertical-align: middle;
    line-height: 1;
}

.creator-tag.desktop-new {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.1rem 0.35rem;
    /* Reduced horizontal padding */
    border-radius: 6px;
    min-height: 22px;
    transition: all 0.2s ease;
}

.creator-tag:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
    transform: scale(1.02);
}

/* Shared Avatar Styling */
.creator-avatar,
.creator-avatar-new {
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    min-height: 18px !important;
    max-width: 18px !important;
    max-height: 18px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    border: 1.5px solid var(--bg-card);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
    flex-shrink: 0 !important;
}

.creator-name,
.creator-name-new {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Compact Rating Display */
.template-rating-compact {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: #fbbf24;
    /* Amber star color */
    margin-top: -2px;
}

.rating-count {
    color: var(--text-secondary);
    font-size: 0.7rem;
}

.template-name-compact {
    font-size: 1rem;
    /* Reduced size */
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    /* Strictly 1 line */
    line-clamp: 1;
    -webkit-box-orient: vertical;
}

/* Categories Section - One line with cutoff */
.card-categories {
    margin: 4px 0 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 22px;
    overflow: hidden;
    position: relative;
}

/* Fade-out effect at the edge */
.card-categories::after {
    content: '...';
    position: absolute;
    right: 0;
    top: 0;
    background: linear-gradient(to right, transparent, var(--bg-card, #242426) 50%);
    padding-left: 15px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 22px;
}

.category-pill {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.08);
    white-space: nowrap;
}

/* Unified Footer Row */
.card-footer-unified {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    width: 100%;
}

.rating-compact-single {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fbbf24;
}

.footer-right-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Tiny Creator Tag with Purple Outline */
.creator-tag-tiny {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border: 1px solid rgba(168, 85, 247, 0.4);
    /* Pronounced purple outline */
    border-radius: 6px;
    background: rgba(168, 85, 247, 0.08);
    /* Subtle purple tint */
    height: 22px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.creator-tag-tiny:hover {
    border-color: #c084fc;
    background: rgba(168, 85, 247, 0.15);
    transform: translateY(-1px);
}

.creator-avatar-tiny {
    width: 14px !important;
    height: 14px !important;
    min-width: 14px !important;
    min-height: 14px !important;
    max-width: 14px !important;
    max-height: 14px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    flex-shrink: 0 !important;
}

.creator-name-tiny {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Menu Popover Styles */
.menu-dots-container {
    position: relative;
    display: inline-block;
}

.btn-menu-dots {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 32px;
    /* Smaller button */
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    transition: all 0.3s ease;
}

.btn-menu-dots:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.card-menu-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    /* Opens downwards from parent button */
    right: 0;
    background: #1e1b4b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0.5rem;
    min-width: 160px;
    /* Slightly wider for wishlist text */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    /* High z-index to stay on top */
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    /* Animate from slightly above */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-menu-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.card-menu-dropdown button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.75rem 1rem;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.card-menu-dropdown button:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.card-menu-dropdown .btn-buy-menu {
    color: #10b981;
    font-weight: 700;
}

.card-menu-dropdown .btn-buy-menu:hover {
    background: rgba(16, 185, 129, 0.1);
    color: #34d399;
}

/* Badge Styles */
.badge-featured-tiny,
.badge-new,
.badge-purchased {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 800;
    z-index: 10;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.badge-featured-tiny {
    background: var(--gradient-1);
    color: white;
    top: 0.5rem;
    left: 0.5rem;
    padding: 0.15rem 0.4rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}


.badge-new {
    background: #3b82f6;
    color: white;
}

.badge-purchased {
    background: #10b981;
    color: white;
    right: 0.75rem;
    left: auto;
}

.badge-version-green {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 800;
    z-index: 10;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    white-space: nowrap;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.badge-purchased-mini {
    top: 0.5rem;
    right: 0.5rem;
    padding: 2px 6px;
    font-size: 0.55rem;
    border-radius: 4px;
    opacity: 0.9;
    box-shadow: none;
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.btn-download-single:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 243, 255, 0.3);
    filter: brightness(1.1);
}

/* Wishlist Button */
.wishlist-btn {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 15;
    font-size: 1rem;
}

.wishlist-btn:hover {
    background: var(--accent);
    transform: scale(1.1);
}

/* Visibility Utilities */
.desktop-only {
    display: inline-block;
}

.mobile-only {
    display: none;
}

/* Global Hide Refinements */
.template-footer,
.template-actions,
.btn-primary.add-to-cart,
.add-to-cart,
.mobile-template-actions,
.template-desc,
.wishlist-btn {
    display: none !important;
}

/* RESPONSIVE DESIGN */

@media (max-width: 1024px) {
    .template-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
        padding: 0.5rem 1rem;
        width: 100%;
        overflow: visible;
    }

    .template-card {
        border-radius: 12px;
    }

    .template-card .template-image {
        height: 120px;
        border-radius: 12px 12px 0 0;
    }

    .template-content {
        padding: 0.6rem 0.75rem;
        min-height: 155px;
        /* Unified minimum height */
    }

    .btn-menu-dots {
        width: 44px;
        /* Better touch target for mobile */
        height: 44px;
        margin-right: -8px;
        /* Offset large target */
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: inline-block !important;
    }

    .price {
        flex-direction: row !important;
        align-items: baseline !important;
    }

    /* Fix creator tag scaling on small screens */
    .creator-tag-tiny {
        padding: 1px 4px !important;
        height: 18px !important;
        border-radius: 4px !important;
    }

    .creator-avatar-tiny {
        width: 12px !important;
        height: 12px !important;
    }

    .creator-name-tiny {
        font-size: 0.6rem !important;
    }

    .rating-compact-single {
        font-size: 0.7rem !important;
    }
}

@media (max-width: 600px) {
    .template-card .template-image {
        height: 100px;
    }
}

/* Specific Details Page Helper */
.header-categories {
    display: inline-flex;
    gap: 6px;
    margin-left: 12px;
    vertical-align: middle;
}

.header-cat-pill {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(168, 85, 247, 0.1);
    color: #c084fc;
    border: 1px solid rgba(168, 85, 247, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* Early Access Item Styling (Subtle) */
.card-ea-item {
    border: 1px solid rgba(234, 179, 8, 0.3) !important;
    transition: all 0.3s ease;
}

.card-ea-item:hover {
    border-color: rgba(234, 179, 8, 0.6) !important;
    box-shadow: 0 0 15px rgba(234, 179, 8, 0.15) !important;
}

.card-restricted {
    position: relative;
    cursor: not-allowed !important;
}

.card-restricted::after {
    content: '🔒';
    position: absolute;
    bottom: 12px;
    right: 12px;
    font-size: 1.2rem;
    z-index: 20;
    opacity: 0.8;
}

.card-restricted:hover {
    transform: none !important;
    border-color: rgba(234, 179, 8, 0.5) !important;
    box-shadow: none !important;
}

/* ========================================
   TEMPLATE HOVER PREVIEW (DESKTOP ONLY)
   ======================================== */

@media (min-width: 1025px) {
    .template-preview-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0, 0, 0, 0.85);
        backdrop-filter: blur(8px);
        z-index: 999999;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .template-preview-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    .preview-container {
        width: 85%;
        max-width: 1200px;
        height: 85vh;
        /* Increased slightly for metadata slot */
        background: var(--bg-card, #1a1a1c);
        border-radius: 20px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 1), 0 0 30px rgba(168, 85, 247, 0.1);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        transform: scale(0.95) translateY(20px);
        transition: all 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    }

    .template-preview-overlay.active .preview-container {
        transform: scale(1) translateY(0);
    }

    /* Header */
    .preview-header {
        padding: 1.25rem 2rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: rgba(30, 30, 35, 0.7);
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        position: relative;
        /* Static in flow */
        z-index: 10;
        backdrop-filter: blur(10px);
    }

    .preview-title {
        font-size: 1.5rem;
        font-weight: 800;
        color: #fff;
        text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    }

    .preview-close {
        background: rgba(255, 255, 255, 0.1);
        border: none;
        color: white;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        transition: all 0.2s ease;
        backdrop-filter: blur(4px);
    }

    .preview-close:hover {
        background: rgba(255, 255, 255, 0.2);
        transform: rotate(90deg);
    }

    /* Body / Iframe */
    .preview-body {
        flex: 1;
        position: relative;
        background: #000;
    }

    .preview-body iframe {
        width: 100%;
        height: 100%;
        border: none;
    }

    .preview-loader {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: var(--primary, #a855f7);
        font-size: 1.2rem;
        display: flex;
        align-items: center;
        gap: 10px;
        font-weight: 600;
    }

    /* Footer & Actions */
    .preview-footer {
        padding: 1.25rem 2.5rem;
        background: rgba(30, 30, 35, 0.7);
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        position: relative;
        /* Static in flow */
        z-index: 10;
        display: flex;
        justify-content: space-between;
        /* Space for name/actions if needed */
        align-items: center;
        backdrop-filter: blur(10px);
    }

    .preview-actions {
        display: flex;
        gap: 1rem;
    }

    .btn-retouch,
    .btn-details {
        padding: 0.8rem 1.75rem;
        border-radius: 12px;
        font-weight: 700;
        font-size: 1rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 8px;
        transition: all 0.3s ease;
    }

    .btn-retouch {
        background: var(--primary, #a855f7);
        color: white;
        border: none;
        box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
    }

    .btn-retouch:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(168, 85, 247, 0.4);
        filter: brightness(1.1);
    }

    .btn-details {
        background: rgba(255, 255, 255, 0.1);
        color: white;
        border: 1px solid rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(10px);
    }

    .btn-details:hover {
        background: rgba(255, 255, 255, 0.2);
        transform: translateY(-2px);
    }
}

@media (max-width: 1024px) {
    .template-preview-overlay {
        display: none !important;
    }
}