/* Enhanced Asset Grid with True Square Thumbnails */

/* Asset Library Container with Visible Scrollbar */
#asset-grid {
    max-height: calc(100vh - 280px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 8px;
    /* Custom scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: #667eea #f0f0f0;
}

/* Webkit scrollbar (Chrome, Safari, Edge) */
#asset-grid::-webkit-scrollbar {
    width: 10px;
}

#asset-grid::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 5px;
}

#asset-grid::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 5px;
    border: 2px solid #f0f0f0;
}

#asset-grid::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

/* Thumbnail View Grid - Square Layout */
#asset-grid.thumbnail-view {
    padding: 1rem;
}

.asset-grid-container.square-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    padding: 0;
    /* Performance: Use CSS containment to isolate layout and paint */
    contain: layout style;
}

/* Square Card Container */
.asset-card.square-card {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 100%; /* Creates 1:1 aspect ratio */
    background: #fff;
    border-radius: 12px;
    overflow: visible; /* Changed from hidden to show source label */
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    /* Performance: Isolate layout/paint operations per card */
    contain: layout style paint;
    will-change: transform;
}

/* Source Label Below Thumbnail */
.asset-source-label {
    position: absolute;
    bottom: -28px; /* Position below the square card */
    left: 0;
    right: 0;
    padding: 4px 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
    border-radius: 0 0 8px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.asset-source-label:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
}

/* Source Badge on Thumbnail (corner badge) - BOTTOM LEFT to avoid checkbox */
.source-badge-corner {
    position: absolute;
    bottom: 8px;
    left: 8px;
    padding: 3px 8px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: white;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    z-index: 5;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.asset-card:hover .source-badge-corner {
    transform: scale(1.05);
}

/* Source-specific colors for badges */
.source-badge-corner[data-source="redgifs"],
.asset-source-label[data-source="redgifs"] { background: linear-gradient(135deg, #ff4757 0%, #c93b3b 100%); }

.source-badge-corner[data-source="motherless"],
.asset-source-label[data-source="motherless"] { background: linear-gradient(135deg, #2c2c2c 0%, #1a1a1a 100%); }

.source-badge-corner[data-source="pornhub"],
.asset-source-label[data-source="pornhub"] { background: linear-gradient(135deg, #ffa500 0%, #ff8c00 100%); color: #000; }

.source-badge-corner[data-source="xvideos"],
.asset-source-label[data-source="xvideos"] { background: linear-gradient(135deg, #c4302b 0%, #8b1a1a 100%); }

.source-badge-corner[data-source="e621"],
.asset-source-label[data-source="e621"] { background: linear-gradient(135deg, #00549e 0%, #003366 100%); }

.source-badge-corner[data-source="rule34"],
.asset-source-label[data-source="rule34"] { background: linear-gradient(135deg, #aad450 0%, #7cb342 100%); color: #000; }

.source-badge-corner[data-source="gelbooru"],
.asset-source-label[data-source="gelbooru"] { background: linear-gradient(135deg, #0073e6 0%, #004a94 100%); }

.source-badge-corner[data-source="danbooru"],
.asset-source-label[data-source="danbooru"] { background: linear-gradient(135deg, #0288d1 0%, #01579b 100%); }

.source-badge-corner[data-source="unsplash"],
.asset-source-label[data-source="unsplash"] { background: linear-gradient(135deg, #111111 0%, #333333 100%); }

.source-badge-corner[data-source="pexels"],
.asset-source-label[data-source="pexels"] { background: linear-gradient(135deg, #05a081 0%, #047857 100%); }

.source-badge-corner[data-source="pixabay"],
.asset-source-label[data-source="pixabay"] { background: linear-gradient(135deg, #00ab6c 0%, #007a4d 100%); }

.source-badge-corner[data-source="erogarga"],
.asset-source-label[data-source="erogarga"] { background: linear-gradient(135deg, #8b4513 0%, #654321 100%); }

.source-badge-corner[data-source="reddit"],
.asset-source-label[data-source="reddit"] { background: linear-gradient(135deg, #ff4500 0%, #cc3700 100%); }

.source-badge-corner[data-source="imgur"],
.asset-source-label[data-source="imgur"] { background: linear-gradient(135deg, #1bb76e 0%, #159d5b 100%); }

.source-badge-corner[data-source="spankbang"],
.asset-source-label[data-source="spankbang"] { background: linear-gradient(135deg, #e91e63 0%, #c2185b 100%); }

.source-badge-corner[data-source="xhamster"],
.asset-source-label[data-source="xhamster"] { background: linear-gradient(135deg, #f9a825 0%, #f57f17 100%); color: #000; }

.asset-card.square-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
}

/* Inner Content Container */
.asset-card-inner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Media Container */
.thumbnail-media {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    flex-grow: 1;
}

.thumbnail-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Performance: Decode images asynchronously */
    image-rendering: auto;
    content-visibility: auto;
}

.thumbnail-media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Performance: Reduce video element overhead */
    content-visibility: auto;
}

/* Lazy loading placeholder state */
.thumbnail-media img.lazy-load,
.thumbnail-media video.lazy-load {
    background: linear-gradient(135deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.thumbnail-media.file-icon {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.thumbnail-media.file-icon i {
    font-size: 3rem;
    opacity: 0.9;
}

/* Video Overlay */
.video-preview {
    position: relative;
    width: 100%;
    height: 100%;
}

.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.asset-card:hover .video-overlay {
    opacity: 0;
}

.video-overlay i {
    font-size: 3rem;
    color: white;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Asset Info Overlay */
.asset-overlay {
    display: none !important;
}

.asset-card:hover .asset-overlay {
    display: none !important;
}

.asset-name {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 8px;
}

.asset-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 10px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Focus State for Keyboard Navigation */
.asset-card.square-card.focused {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

/* List View Styles */
#asset-grid.list-view {
    padding: 1rem;
}

.asset-list-container {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.asset-list-container table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.asset-list-container thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.asset-list-container th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
}

.asset-list-container tbody tr {
    cursor: pointer;
    transition: background 0.2s ease;
}

.asset-list-container tbody tr:hover {
    background: #f8f9fa;
}

.asset-list-container td {
    padding: 12px;
    border-bottom: 1px solid #e9ecef;
}

.list-thumbnail {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.list-thumbnail-icon {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: #6c757d;
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h4 {
    margin-bottom: 0.5rem;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .asset-grid-container.square-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }
}

@media (max-width: 768px) {
    .asset-grid-container.square-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }
    
    .asset-overlay {
        padding: 8px;
    }
    
    .asset-name {
        font-size: 0.8rem;
    }
    
    .btn-icon {
        padding: 4px 8px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .asset-grid-container.square-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }
}