/**
 * Generated Images Styling
 * Responsive styles for AI-generated images in chat interface
 */

/* Image Container */
.generated-image-wrapper {
    position: relative;
    margin: 1rem 0;
    border-radius: 8px;
    overflow: hidden;
    background: #f8f9fa;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.generated-image-wrapper:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* Generated Image */
.generated-image {
    width: 100%;
    height: auto;
    display: block;
    max-width: 768px;
    opacity: 0;
    transition: opacity 0.3s ease;
    cursor: pointer;
}

.generated-image:hover {
    opacity: 0.9;
}

.generated-image-wrapper.image-loaded .generated-image {
    opacity: 1;
}

/* Image Caption */
.image-caption {
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    font-size: 0.9rem;
    font-style: italic;
    border-top: 1px solid #e0e0e0;
}

/* Download Button */
.image-download-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.generated-image-wrapper:hover .image-download-btn {
    opacity: 1;
}

.image-download-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

.image-download-btn:active {
    transform: scale(0.95);
}

/* Loading State */
.generated-image-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    color: white;
    text-align: center;
    min-height: 200px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.loading-text {
    font-size: 1rem;
    font-weight: 600;
    margin: 0.5rem 0;
    max-width: 400px;
}

.loading-subtext {
    font-size: 0.85rem;
    opacity: 0.9;
    margin: 0.25rem 0;
}

/* Error State */
.generated-image-error,
.generated-image-wrapper.image-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: #fee;
    border: 2px dashed #fcc;
    border-radius: 8px;
    min-height: 150px;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.error-message {
    color: #c33;
    font-weight: 600;
    margin: 0.5rem 0;
}

.error-subtext {
    color: #666;
    font-size: 0.85rem;
    margin: 0.25rem 0;
}

.image-error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.image-error-message .error-icon {
    font-size: 2rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .generated-image-wrapper {
        margin: 0.75rem 0;
    }

    .generated-image {
        max-width: 100%;
    }

    .image-caption {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .image-download-btn {
        opacity: 1;
        top: 5px;
        right: 5px;
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .loading-text {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .generated-image-loading {
        padding: 2rem 1rem;
        min-height: 150px;
    }

    .loading-spinner {
        width: 40px;
        height: 40px;
    }

    .loading-text {
        font-size: 0.85rem;
    }

    .loading-subtext {
        font-size: 0.75rem;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .generated-image-wrapper {
        background: #2d3748;
    }

    .image-caption {
        background: rgba(45, 55, 72, 0.95);
        color: #e2e8f0;
        border-top-color: #4a5568;
    }

    .generated-image-error,
    .generated-image-wrapper.image-error {
        background: #742a2a;
        border-color: #c53030;
    }

    .error-message {
        color: #fc8181;
    }

    .error-subtext {
        color: #e2e8f0;
    }
}

/* Accessibility */
.generated-image:focus,
.image-download-btn:focus {
    outline: 2px solid #4299e1;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .image-download-btn {
        display: none;
    }

    .generated-image-wrapper {
        box-shadow: none;
        page-break-inside: avoid;
    }
}

/* Lightbox Modal - z-index 10100+ to appear above picker modal (10000) */
.image-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-lightbox.active {
    display: flex;
    opacity: 1;
    align-items: center;
    justify-content: center;
}

.lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.lightbox-content {
    position: relative;
    z-index: 10101;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

.lightbox-image {
    max-width: 100%;
    max-height: calc(95vh - 100px);
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    font-size: 32px;
    line-height: 1;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 10102;
}

.lightbox-close:hover {
    background: white;
    transform: scale(1.1);
}

.lightbox-close:active {
    transform: scale(0.95);
}

.lightbox-caption {
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    border-radius: 8px;
    font-size: 0.95rem;
    font-style: italic;
    text-align: center;
    max-width: 90vw;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Lightbox Responsive */
@media (max-width: 768px) {
    .lightbox-content {
        padding: 10px;
    }

    .lightbox-image {
        max-height: calc(95vh - 80px);
    }

    .lightbox-close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 28px;
    }

    .lightbox-caption {
        font-size: 0.85rem;
        padding: 0.5rem 1rem;
    }
}

/* Lightbox Dark Mode */
@media (prefers-color-scheme: dark) {
    .lightbox-caption {
        background: rgba(45, 55, 72, 0.95);
        color: #e2e8f0;
    }

    .lightbox-close {
        background: rgba(45, 55, 72, 0.9);
        color: #e2e8f0;
    }

    .lightbox-close:hover {
        background: rgba(45, 55, 72, 1);
    }
}

/* ===================================
   IMAGE EDIT UI STYLES
   =================================== */

/* Image Buttons Container */
.image-buttons {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.generated-image-wrapper:hover .image-buttons,
.edited-image-wrapper:hover .image-buttons {
    opacity: 1;
}

/* Move download button into container */
.image-buttons .image-download-btn {
    position: static;
    opacity: 1;
}

/* Edit Button */
.image-edit-btn {
    padding: 0.5rem 1rem;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s ease;
}

.image-edit-btn:hover {
    background: rgba(102, 126, 234, 1);
}

.image-edit-btn:active {
    transform: scale(0.95);
}

/* Selected Images Panel (above input) */
.image-edit-selected-panel {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin: 0 1rem 0.75rem 1rem;
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.image-edit-selected-panel.hidden {
    display: none;
}

.selected-images-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.mode-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
}

.mode-icon {
    font-size: 1.3rem;
}

.selected-actions {
    display: flex;
    gap: 0.5rem;
}

.selected-actions button {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.2s ease, transform 0.1s ease;
}

.selected-actions button:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-1px);
}

.selected-actions button:active {
    transform: translateY(0);
}

.selected-images-container {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    padding-top: 0.5rem;
}

.selected-image-item {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 10px;
    overflow: hidden;
    border: 3px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.selected-image-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

.selected-image-item .remove-selected {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.selected-image-item:hover .remove-selected {
    opacity: 1;
}

/* Image Picker Modal */
.image-picker-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-picker-modal.hidden {
    display: none;
}

.picker-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    cursor: pointer;
}

.picker-content {
    position: relative;
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e0e0e0;
}

.picker-header h3 {
    margin: 0;
    color: #333;
}

.picker-close {
    width: 36px;
    height: 36px;
    background: #f0f0f0;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
}

.picker-close:hover {
    background: #e0e0e0;
}

.picker-tabs {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
}

.picker-tab {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 0.95rem;
    cursor: pointer;
    color: #666;
    transition: all 0.2s ease;
}

.picker-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
    font-weight: 600;
}

.picker-tab:hover:not(.active) {
    background: #f8f9fa;
}

.picker-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.picker-tab-content {
    display: none;
}

.picker-tab-content.active {
    display: block;
}

/* Images Grid */
.images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.images-grid.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: #666;
}

.image-grid-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 3px solid transparent;
}

.image-grid-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.image-grid-item.selected {
    border-color: #667eea;
}

.image-thumb-wrapper {
    position: relative;
    aspect-ratio: 1;
    background: #f0f0f0;
}

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

.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(102, 126, 234, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.image-grid-item.selected .image-overlay {
    opacity: 1;
}

.image-overlay i {
    color: white;
    font-size: 2rem;
}

.image-info {
    padding: 0.5rem;
    background: white;
}

.image-date {
    font-size: 0.75rem;
    color: #999;
}

.image-prompt {
    font-size: 0.8rem;
    color: #666;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.no-images {
    text-align: center;
    color: #999;
    padding: 2rem;
}

/* Upload Area */
.upload-area {
    text-align: center;
}

.upload-dropzone {
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 3rem 2rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.05);
}

.upload-dropzone i {
    font-size: 3rem;
    color: #667eea;
    margin-bottom: 1rem;
}

.upload-dropzone p {
    margin: 0.5rem 0;
    color: #666;
}

.upload-hint {
    font-size: 0.85rem;
    color: #999;
}

.upload-input {
    display: none;
}

.uploaded-previews {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.upload-preview {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #667eea;
}

.upload-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-upload {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.picker-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
}

.selection-count {
    color: #666;
    font-size: 0.9rem;
}

.picker-actions {
    display: flex;
    gap: 0.75rem;
}

.btn-cancel {
    padding: 0.6rem 1.2rem;
    background: #f0f0f0;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: #666;
}

.btn-cancel:hover {
    background: #e0e0e0;
}

.btn-confirm {
    padding: 0.6rem 1.2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: white;
    font-weight: 600;
}

.btn-confirm:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-confirm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Image Edit Loading State */
.image-edit-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border-radius: 8px;
    color: white;
    text-align: center;
    min-height: 200px;
}

.edit-source-thumbnails {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.edit-source-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

/* Edited Image Wrapper */
.edited-image-wrapper {
    position: relative;
    margin: 1rem 0;
    border-radius: 8px;
    overflow: hidden;
    background: #f8f9fa;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.edit-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 0.3rem 0.6rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    z-index: 10;
}

.edit-badge.composite {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.edited-image {
    width: 100%;
    height: auto;
    display: block;
    max-width: 768px;
    cursor: pointer;
}

/* Responsive Image Edit UI */
@media (max-width: 768px) {
    .picker-content {
        width: 95%;
        max-height: 90vh;
    }

    .images-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .selected-image-item {
        width: 60px;
        height: 60px;
    }

    .image-buttons {
        opacity: 1;
        position: static;
        margin-top: 0.5rem;
        padding: 0.5rem;
        background: rgba(255, 255, 255, 0.9);
    }

    .upload-dropzone {
        padding: 2rem 1rem;
    }
}

/* Dark Mode for Image Edit UI */
@media (prefers-color-scheme: dark) {
    .picker-content {
        background: #1a202c;
    }

    .picker-header {
        border-bottom-color: #2d3748;
    }

    .picker-header h3 {
        color: #e2e8f0;
    }

    .picker-close {
        background: #2d3748;
        color: #e2e8f0;
    }

    .picker-tabs {
        border-bottom-color: #2d3748;
    }

    .picker-tab {
        color: #a0aec0;
    }

    .picker-tab.active {
        color: #667eea;
    }

    .picker-tab:hover:not(.active) {
        background: #2d3748;
    }

    .image-info {
        background: #2d3748;
    }

    .image-date {
        color: #a0aec0;
    }

    .image-prompt {
        color: #e2e8f0;
    }

    .picker-footer {
        border-top-color: #2d3748;
    }

    .selection-count {
        color: #a0aec0;
    }

    .btn-cancel {
        background: #2d3748;
        color: #e2e8f0;
    }

    .upload-dropzone {
        border-color: #4a5568;
    }

    .upload-dropzone:hover,
    .upload-dropzone.dragover {
        background: rgba(102, 126, 234, 0.1);
    }

    .upload-dropzone p {
        color: #a0aec0;
    }

    .edited-image-wrapper {
        background: #2d3748;
    }
}

/* Welcome Screen Edit Button */
.welcome-edit-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.welcome-edit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.welcome-edit-btn:active {
    transform: translateY(0);
}

/* Welcome Mode Cards Responsive */
@media (max-width: 600px) {
    .welcome-mode-cards {
        grid-template-columns: 1fr !important;
    }
}

/* ===== Image Grid Ellipsis Menu ===== */

/* Ellipsis menu button on grid items */
.image-grid-menu-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
    z-index: 5;
    line-height: 1;
    padding: 0;
}

.image-grid-item:hover .image-grid-menu-btn {
    opacity: 1;
}

.image-grid-menu-btn:hover {
    background: rgba(0, 0, 0, 0.85);
}

/* Popup menu for image options */
.image-grid-popup {
    position: fixed;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 170px;
    animation: popupFadeIn 0.15s ease-out;
    z-index: 10001;
}

.image-grid-popup-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    color: #374151;
    font-size: 14px;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.image-grid-popup-option:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

.image-grid-popup-option.delete:hover {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

.image-grid-popup-option .option-icon {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

/* Dark mode for popup menu */
@media (prefers-color-scheme: dark) {
    .image-grid-popup {
        background: rgba(45, 55, 72, 0.98);
        border-color: rgba(102, 126, 234, 0.4);
    }

    .image-grid-popup-option {
        color: #e2e8f0;
    }

    .image-grid-popup-option:hover {
        background: rgba(102, 126, 234, 0.2);
    }

    .image-grid-popup-option.delete:hover {
        background: rgba(220, 53, 69, 0.2);
    }
}
