/* =================================================================
   entity-image-picker.css — Web-image search picker for the per-entity
   user-image feature. Sibling to entity-image-crop.css: this picker
   shows search-result thumbnails; clicking one downloads the URL to a
   temp file and feeds it to the crop modal.

   Visual idiom mirrors entity-image-crop.css and modals.css — same
   surface tokens, button classes (.settings-btn*), border radii, and
   border-subtle dividers. z-index 6050 sits between coverViewer (6000)
   and the crop modal (6100) so a stacked picker→crop flow renders in
   the right Z order.
   ================================================================= */

.entity-picker-modal {
    position: fixed;
    inset: 0;
    background: var(--surface-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 6050;
    padding: 20px;
    animation: fadeIn 0.15s ease-out;
}

.entity-picker-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    width: 720px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.entity-picker-header {
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--border-subtle);
    flex: 0 0 auto;
}

.entity-picker-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entity-picker-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.entity-picker-close:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.entity-picker-grid {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.entity-picker-tile {
    width: 100%;
    aspect-ratio: 1;
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    padding: 0;
    transition: transform 120ms ease, border-color 120ms ease;
}

.entity-picker-tile:hover {
    transform: translateY(-2px);
    border-color: var(--accent-primary);
}

.entity-picker-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.entity-picker-tile-badge {
    position: absolute;
    bottom: 6px;
    left: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Spinner overlay shown on the chosen tile while we download to temp.
   Pure-CSS rotating ring — no external SVG so the visual stays in sync
   with the rest of the picker even on a cold paint. */
.entity-picker-tile.tile-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

.entity-picker-tile.tile-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    animation: entity-picker-spin 0.9s linear infinite;
    z-index: 1;
}

@keyframes entity-picker-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.entity-picker-skeleton {
    width: 100%;
    aspect-ratio: 1;
    background: linear-gradient(
        90deg,
        var(--surface-card) 0%,
        var(--overlay-hover) 50%,
        var(--surface-card) 100%
    );
    background-size: 200% 100%;
    animation: entity-picker-skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
}

@keyframes entity-picker-skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.entity-picker-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
}

.entity-picker-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.entity-picker-load-more {
    /* Inherits .settings-btn — keep this rule for ordering / overrides. */
}

.entity-picker-cancel {
    /* Inherits .settings-btn. Sits at the right of the footer; the
       space-between in .entity-picker-footer pushes Load-more to the
       left and Cancel to the right naturally. */
    margin-left: auto;
}

/* When the picker is mid-fetch the whole grid + Load-more should be
   inert and dimmed — the chosen tile keeps its spinner overlay on top.
   pointer-events: none on the grid blocks click delegation; opacity
   is the visual cue that the UI is busy. */
.entity-picker-modal.is-disabled .entity-picker-grid,
.entity-picker-modal.is-disabled .entity-picker-load-more {
    pointer-events: none;
    opacity: 0.6;
}
