/**
 * PXMBoard Image Upload Styles
 */

/* Upload button */
.btn-image-upload {
    background: linear-gradient(to bottom, #5a9fd4, #4a8bc4);
    color: #fff;
    border: 1px solid #3a7bb4;
    border-radius: 3px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 12px;
}

.btn-image-upload:hover {
    background: linear-gradient(to bottom, #6aafE4, #5a9bd4);
}

/* Drop overlay */
.image-drop-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(74, 139, 196, 0.9);
    border: 3px dashed #fff;
    border-radius: 5px;
    z-index: 100;
    pointer-events: none;
}

.image-drop-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-drop-overlay .drop-message {
    color: #fff;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Make form position relative for overlay */
.messageform {
    position: relative;
}

/* Preview container */
.image-upload-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 0;
    min-height: 0;
}

.image-upload-preview:empty {
    display: none;
}

/* Preview item */
.preview-item {
    position: relative;
    width: 100px;
    height: 100px;
    border: 1px solid #ccc;
    border-radius: 4px;
    overflow: hidden;
    background: #f5f5f5;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-item.loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Loading spinner */
.preview-loading {
    text-align: center;
    padding: 10px;
}

.preview-loading .spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #e0e0e0;
    border-top-color: #4a8bc4;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 8px;
}

.preview-loading .filename {
    font-size: 10px;
    color: #666;
    word-break: break-all;
    display: block;
    max-height: 30px;
    overflow: hidden;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Remove button */
.preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    background: rgba(220, 53, 69, 0.9);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 14px;
    line-height: 18px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.preview-item:hover .preview-remove {
    opacity: 1;
}

.preview-remove:hover {
    background: #c82333;
}

/* Filename label */
.preview-filename {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 9px;
    padding: 2px 4px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

/* Message notifications */
.image-upload-message {
    padding: 8px 12px;
    margin: 5px 0;
    border-radius: 4px;
    font-size: 13px;
}

.image-upload-message.error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.image-upload-message.warning {
    background: #fff3cd;
    border: 1px solid #ffeeba;
    color: #856404;
}

.image-upload-message.success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

/* ========================================
   Displayed images in posts
   ======================================== */

/* Single uploaded image */
.uploaded-image {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.uploaded-image:hover {
    opacity: 0.9;
}

/* Deleted image placeholder */
.image-deleted {
    display: inline-block;
    padding: 10px 15px;
    background: #f5f5f5;
    border: 1px dashed #ccc;
    color: #999;
    font-style: italic;
    border-radius: 4px;
}

/* ========================================
   Image Gallery Grid
   ======================================== */

.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin: 10px 0;
    max-width: 100%;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 4px;
    background: #f0f0f0;
}

.gallery-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.gallery-item:hover .gallery-thumb {
    transform: scale(1.05);
}

/* Gallery deleted placeholder */
.gallery-deleted {
    display: block;
    padding: 10px;
    background: #f5f5f5;
    border: 1px dashed #ccc;
    color: #999;
    font-style: italic;
    text-align: center;
    border-radius: 4px;
}

/* Gallery as text links (in quotes) */
.gallery-links {
    padding: 5px 0;
}

.gallery-links a {
    margin-right: 8px;
}

/* ========================================
   GLightbox customizations
   ======================================== */

/* Ensure lightbox works well with our images */
.glightbox-container .gslide-image img {
    max-height: 90vh;
    object-fit: contain;
}

/* ========================================
   Mobile Responsive
   ======================================== */

@media (max-width: 600px) {
    .image-upload-preview {
        gap: 5px;
    }

    .preview-item {
        width: 80px;
        height: 80px;
    }

    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 5px;
    }

    .image-drop-overlay .drop-message {
        font-size: 16px;
    }
}

/* ========================================
   Dark mode support (if applicable)
   ======================================== */

@media (prefers-color-scheme: dark) {
    .preview-item {
        background: #2a2a2a;
        border-color: #444;
    }

    .preview-loading .filename {
        color: #aaa;
    }

    .image-deleted,
    .gallery-deleted {
        background: #2a2a2a;
        border-color: #444;
        color: #888;
    }

    .image-upload-message.error {
        background: #4a1c24;
        border-color: #752535;
        color: #f8d7da;
    }

    .image-upload-message.warning {
        background: #4a3c04;
        border-color: #756204;
        color: #fff3cd;
    }
}
