/**
 * Filtered Cards Modal
 *
 * Shared modal that displays a grid of cards filtered by some criterion
 * (e.g. "cards with trait X", "cards by artist Y"). Card click opens the
 * unified CardModalManager so the user can pivot into the full detail
 * view, navigate, etc.
 *
 * Used by:
 *   - card-stats page (filter by trait / effect / source title / etc.)
 *   - admin-artists page (filter by artist, including extra credits)
 *
 * Originally lived inside styles/pages/card_stats.css; extracted on
 * 2026-05-13 when admin-artists started reusing the pattern. Selectors
 * are intentionally generic — no page namespace.
 */

.filtered-cards-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filtered-cards-modal.hidden {
    display: none;
}

.filtered-cards-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.filtered-cards-content {
    position: relative;
    width: 90%;
    max-width: 1200px;
    max-height: 85vh;
    background: var(--surface-primary, #1a1a2e);
    border-radius: var(--radius-lg, 12px);
    border: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.filtered-cards-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-primary);
    background: var(--surface-secondary);
}

.filtered-cards-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.filtered-cards-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.filtered-cards-header .btn-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: var(--radius-sm, 4px);
    transition: background 0.2s, color 0.2s;
}

.filtered-cards-header .btn-close:hover {
    background: var(--surface-tertiary);
    color: var(--text-primary);
}

.filtered-cards-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    flex: 1;
}

.filtered-cards-loading.hidden {
    display: none !important;
}

.filtered-cards-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-primary);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.filtered-cards-loading p {
    margin-top: 1rem;
    color: var(--text-secondary);
}

.filtered-cards-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 200px;
    align-content: flex-start;
}

.filtered-card-item {
    cursor: pointer;
    transition: transform 0.2s;
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
    background: var(--surface-secondary);
    width: calc((100% - 6rem) / 7); /* 7 columns with 1rem gaps */
    flex-shrink: 0;
}

.filtered-card-item:hover {
    transform: scale(1.05);
    z-index: 10;
}

.filtered-card-item img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: var(--radius-md, 8px);
}

.filtered-card-item .card-name {
    padding: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-primary);
    text-align: center;
    background: var(--surface-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filtered-cards-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

/* Base Cards Only Toggle (in the modal header) */
.base-cards-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    user-select: none;
}

.base-cards-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--color-primary);
}

.base-cards-toggle .toggle-label {
    white-space: nowrap;
}

.base-cards-toggle:hover {
    color: var(--text-primary);
}

/* Hidden state when the toggle is suppressed via component options. */
.filtered-cards-actions .base-cards-toggle.hidden {
    display: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .filtered-cards-content {
        width: 95%;
        max-height: 90vh;
    }

    .filtered-cards-grid {
        gap: 0.75rem;
        padding: 1rem;
    }

    .filtered-card-item {
        width: calc((100% - 3rem) / 5); /* 5 columns on tablet */
    }

    .filtered-cards-header {
        padding: 0.75rem 1rem;
    }

    .filtered-cards-header h2 {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .filtered-card-item {
        width: calc((100% - 1.5rem) / 3); /* 3 columns on mobile */
    }

    .filtered-cards-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .base-cards-toggle {
        order: 3;
        width: 100%;
        justify-content: flex-end;
    }
}
