/* ============================================================
   media-thumbnail.css
   Scoped styles for the Media Thumbnail editor component.
   Placed alongside MediaThumbnail.razor in Tevarai.Base.Presentation
   ============================================================ */

/* --- Root wrapper ------------------------------------------ */
.media-thumbnail-wrapper {
    --thumb-radius: 6px;
    --thumb-border: 1px solid #e0e0e0;
    --thumb-bg: #f7f7f8;
    --thumb-icon-color: #8a8fa8;
    --thumb-text-color: #555;
    --thumb-shadow: 0 1px 4px rgba(0,0,0,0.08);
    --thumb-overlay-bg: rgba(15,15,20,0.55);
    --thumb-transition: 0.18s ease;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--thumb-radius);
    background: var(--bs-body-bg);
	border: 1px solid rgba(var(--midgrey),0.5);
    overflow: hidden;
    position: relative;
    transition: box-shadow var(--thumb-transition);
}

.media-thumbnail-wrapper:hover {
	border: 1px solid rgba(var(--midgrey),0.5);
}

/* --- Sizes -------------------------------------------------- */
.media-thumb-sm {
    width: 48px;
    height: 48px;
    min-width: 48px;
}

.media-thumb-md {
    width: 80px;
    height: 80px;
    min-width: 80px;
}

.media-thumb-lg {
    width: 200px;
    height: 160px;
    min-width: 200px;
}

/* --- List View cell (MediaCellThumbnail) ------------------- */
.media-cell-thumb {
    display: inline-block;
    padding: 0;
    background: none;
    width: 48px;
    height: 48px;
    border-radius: 6px;
    border: 1px solid rgba(var(--midgrey), 0.5);
    overflow: hidden;
    cursor: zoom-in;
    vertical-align: middle;
}

.media-cell-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-cell-thumb.is-missing {
    cursor: default;
}

.media-cell-thumb-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    opacity: 0.6;
}

/* --- Skeleton / Loading ------------------------------------- */

.media-thumbnail-wrapper.is-loading {
    align-items: stretch;
    justify-content: stretch;
}

.media-thumbnail-skeleton {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #ececec;
}

.skeleton-shimmer {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255,255,255,0.55) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s ease-in-out infinite;
}

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

/* --- Image -------------------------------------------------- */
.media-thumbnail-image-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.media-thumbnail-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform var(--thumb-transition);
}

.media-thumbnail-wrapper:hover .media-thumbnail-img {
    transform: scale(1.04);
}

/* Date overlay on images */
.media-thumbnail-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--thumb-overlay-bg);
    padding: 3px 5px;
    opacity: 0;
    transition: opacity var(--thumb-transition);
}

.media-thumbnail-wrapper:hover .media-thumbnail-overlay {
    opacity: 1;
}

.media-filename-overlay {
    font-size: 9px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

/* --- Placeholder (file icon) -------------------------------- */
.media-thumbnail-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
    height: 100%;
    padding: 8px;
    box-sizing: border-box;
}

.media-type-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--thumb-icon-color);
    transition: color var(--thumb-transition);
}

.media-thumbnail-wrapper:hover .media-type-icon {
    color: #5a6282;
}

/* Scale icon SVG relative to container */
.media-thumb-sm .media-type-icon svg  { width: 24px; height: 24px; }
.media-thumb-md .media-type-icon svg  { width: 36px; height: 36px; }
.media-thumb-lg .media-type-icon svg  { width: 52px; height: 52px; }

/* --- Date label --------------------------------------------- */
.media-filename {
    font-size: 9px;
    color: var(--thumb-text-color);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
}

.media-thumb-sm .media-filename {
    display: none; /* too small for label */
}

/* --- Error state -------------------------------------------- */
.media-thumbnail-wrapper.has-error {
    border-color: #f5c2c7;
    background: #fff5f5;
}

.media-thumbnail-wrapper.has-error .media-type-icon {
    color: #c5808a;
}

.media-thumbnail-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 250px;
    aspect-ratio: 1;
    position: relative;
    border: 1px solid rgba(var(--midgrey), 0.5);
    border-radius: 8px;
    overflow: hidden;
    background-color: var(--bs-body-bg);
    cursor: pointer;
}

.thumbnail-skeleton {
    width: 100%;
    height: 100%;
    background-color: #eee;
    position: relative;
    overflow: hidden;
}

.skeleton-shimmer {
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        left: -100%;
    }

    100% {
        left: 100%;
    }
}

.thumbnail-placeholder,
.thumbnail-file {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #777;
    font-size: 2rem;
}

.thumbnail-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-thumbnail-wrapper {
    position: relative;
    width: 220px;
    height: 220px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bs-body-bg);
    cursor: pointer;
}

.thumbnail-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    font-size: 28px;
    color: #888;
}

.thumbnail-file {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.file-overlay {
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 6px;
    font-size: 12px;
    background: rgba(0,0,0,0.5);
    color: #fff;
}

.upload-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: all;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.progress-bar-container {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 6px;
    width: 100%;
    background: rgba(255,255,255,0.3);
    z-index: 15;
}

.progress-bar-fill {
    height: 100%;
    background: #0d6efd;
    transition: width 0.2s ease;
}

.media-actions {
    position: absolute;
    right: 8px;
    top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 20;
}

.media-gallery-actions {
    position: absolute;
    right: 50px;
    top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 20;
}

.media-thumbnail-actions {
    position: absolute;
    right: 5px;
    top: 5px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 20;
}

.media-btn.active,
.media-small-btn.active {
    background: var(--bs-primary) !important;
}
.media-small-btn {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bs-body-bg);
	border: 1px solid rgba(var(--midgrey),0.5);
    transition: all 0.2s ease;
}

.media-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bs-body-bg);
	border: 1px solid rgba(var(--midgrey),0.5);
    transition: all 0.2s ease;
	opacity: .5;
}
.media-btn img {
	filter: var(--icon-filter);
}

    .media-btn:hover {
        transform: scale(1.1);
		opacity: 1;
    }

    .media-btn.change {
        color: #0d6efd;
    }

    .media-btn.remove {
        color: #dc3545;
    }

.media-thumbnail-wrapper.is-uploading {
    pointer-events: none;
    opacity: 0.8;
}
.file-overlay,
.file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
    font-size: 0.85rem;
    text-align: center;
    pointer-events: none;
}

.thumbnail-image .file-overlay,
.thumbnail-placeholder .file-name,
.thumbnail-file .file-name {
    background-color: rgba(0, 0, 0, 0.5);
    color: #fff;
    padding: 6px;
    border-radius: 2px;
    margin-top: 4px;
}

.media-upload-btn {
    width: 80px;
    height: 80px;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}


/* --- Dark theme support (XAF Blazor dark mode) -------------- */
@media (prefers-color-scheme: dark) {
    .media-thumbnail-wrapper {
        --thumb-border: 1px solid #3a3a4a;
        --thumb-bg: #1e1e2a;
        --thumb-icon-color: #7a7f9a;
        --thumb-text-color: #aaa;
        --thumb-shadow: 0 1px 4px rgba(0,0,0,0.3);
    }

    .media-thumbnail-skeleton {
        background: #2a2a38;
    }

    .media-thumbnail-wrapper.has-error {
        border-color: #6b3040;
        background: #2a1a1e;
    }
}
/* --- Photo editor (MediaPhotoPropertyEditor) ----------------
   Empty slot: a camera, with a plus while a photo can be added.
   Filled slot: a corner button opening Change / Remove upward, inside
   the box, because the wrapper clips anything that spills out of it. */
.media-photo-empty {
    cursor: default;
}

.media-photo-empty.can-add {
    cursor: pointer;
}

.media-photo-empty .icon-upload {
    display: flex;
    color: rgba(var(--midgrey), 0.9);
    transition: color 0.18s ease, transform 0.18s ease;
}

.media-photo-empty .icon-upload svg {
    width: 64px;
    height: 64px;
}

.media-photo-empty.can-add:hover .icon-upload {
    color: var(--bs-primary);
    transform: scale(1.05);
}

.media-photo-actions {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

/* Sit above the file-name strip rather than on it. */
.media-thumbnail-wrapper:has(.file-overlay) .media-photo-actions {
    bottom: 42px;
}

.media-photo-fab {
    position: relative;
    z-index: 32;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bs-primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.media-photo-fab svg {
    width: 18px;
    height: 18px;
}

.media-thumbnail-wrapper:hover .media-photo-fab,
.media-photo-actions.is-open .media-photo-fab,
.media-photo-fab:focus-visible {
    opacity: 1;
}

.media-photo-fab:hover {
    transform: scale(1.08);
}

.media-photo-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    cursor: default;
}

.media-photo-menu {
    position: relative;
    z-index: 31;
    min-width: 140px;
    padding: 4px 0;
    border: 1px solid rgba(var(--midgrey), 0.5);
    border-radius: 6px;
    background: var(--bs-body-bg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.media-photo-menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--bs-body-color);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
}

.media-photo-menu-item:hover,
.media-photo-menu-item:focus-visible {
    background: rgba(var(--midgrey), 0.15);
}

.media-photo-menu-item img {
    width: 16px;
    height: 16px;
    filter: var(--icon-filter);
}

.media-photo-menu-item.remove {
    color: var(--bs-danger);
}

/* Quick views show the photo only. */
.ssqv-view .media-photo-actions {
    display: none;
}

/* --- Photo editor: upload in progress ------------------------------------------------------ */
.media-thumbnail-wrapper .upload-overlay {
    z-index: 40; /* above the corner button and the file-name strip */
    flex-direction: column;
    gap: 8px;
    border-radius: inherit;
}

.upload-percent {
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.media-thumbnail-wrapper .progress-bar-container {
    z-index: 41;
}

/* The empty slot's camera would show through the overlay, under the spinner. */
.media-thumbnail-wrapper:has(.upload-overlay) .media-photo-empty .icon-upload {
    visibility: hidden;
}

/* --- Media field: file card, menu icons, drag and drop -------------------------------------- */
.media-photo-menu-item svg {
    width: 16px;
    height: 16px;
    flex: none;
}

a.media-photo-menu-item,
a.media-photo-menu-item:hover {
    text-decoration: none;
}

.media-file-card {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px;
    text-align: center;
    color: var(--bs-body-color);
    cursor: default;
}

.media-file-card.is-clickable {
    cursor: pointer;
}

.media-file-card-icon {
    display: flex;
    color: var(--bs-primary);
    margin-bottom: 4px;
}

.media-file-card-name {
    max-width: 100%;
    font-size: 0.85rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.media-file-card-meta {
    font-size: 0.75rem;
    color: rgba(var(--midgrey), 1);
    font-variant-numeric: tabular-nums;
}

.media-drop-hint {
    position: absolute;
    inset: 0;
    z-index: 35;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 2px dashed var(--bs-primary);
    border-radius: inherit;
    background: color-mix(in srgb, var(--bs-body-bg) 88%, var(--bs-primary));
    color: var(--bs-primary);
    font-size: 0.85rem;
    font-weight: 600;
    pointer-events: none;
}

.media-drop-hint svg {
    width: 40px;
    height: 40px;
}

.media-thumbnail-wrapper.is-drag-over .media-drop-hint {
    display: flex;
}

.ssqv-view .media-drop-hint {
    display: none !important;
}

/* --- Media set (MediaSetEditor): files gathered one at a time ----------------- */

.media-set {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 4px;
    border-radius: 8px;
}

.media-set.is-drag-over {
    outline: 2px dashed var(--bs-primary);
    outline-offset: 2px;
}

.media-set-tile {
    position: relative;
    width: 160px;
    height: 140px;
    border: 1px solid rgba(var(--midgrey), 0.5);
    border-radius: 8px;
    overflow: hidden;
}

.media-set-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    padding: 3px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    cursor: pointer;
}

.media-set-add {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-style: dashed;
    cursor: pointer;
    color: var(--bs-primary);
    font-size: 0.85rem;
}

.media-set-add-icon svg {
    width: 32px;
    height: 32px;
}

.media-set-drop-hint {
    font-size: 0.75rem;
    opacity: 0.7;
}
