/* Container principal */
#img-desc-container-v3 {
    max-width: 1000px;
    margin: 20px 0;
    padding: 20px;
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.id-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.id-header h3 {
    margin: 0;
    color: #1e1e1e;
}

/* Boutons */
.id-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.id-btn-primary {
    background: #2271b1;
    color: white;
}
.id-btn-primary:hover {
    background: #135e96;
}

.id-btn-success {
    background: #28a745;
    color: white;
}
.id-btn-success:hover {
    background: #1e7e34;
}
.id-btn-success:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.id-btn-secondary {
    background: #f8f9fa;
    color: #333;
    border: 1px solid #ddd;
}
.id-btn-secondary:hover {
    background: #e9ecef;
}

.id-btn-warning {
    background: #ffc107;
    color: #333;
}
.id-btn-warning:hover {
    background: #e0a800;
}

.id-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}
.id-btn:disabled:hover {
    transform: none !important;
}

/* Galerie */
.id-gallery-v3 {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
    margin: 15px 0;
    max-height: 500px;
    overflow-y: auto;
    padding: 10px;
    background: #fafafa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.id-empty {
    grid-column: 1/-1;
    text-align: center;
    padding: 40px;
    color: #888;
}

.id-gallery-item-v3 {
    position: relative;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s;
    aspect-ratio: 1;
    background: #f8f9fa;
}

.id-gallery-item-v3:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.id-gallery-item-v3.selected {
    border-color: #2271b1;
    box-shadow: 0 0 0 3px rgba(34,113,177,0.3);
}

.id-gallery-item-v3.has-description {
    border-color: #28a745;
    box-shadow: 0 0 0 3px rgba(40,167,69,0.3);
}

.id-gallery-item-v3 img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.id-gallery-item-v3 .id-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    background: rgba(0,0,0,0.7);
    pointer-events: none;
}

.id-gallery-item-v3 .id-badge.has-desc {
    background: #28a745;
}

.id-gallery-item-v3 .id-badge.selected-badge {
    background: #2271b1;
}

.id-gallery-item-v3 .id-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: rgba(0,0,0,0.7);
    color: white;
    font-size: 11px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.id-gallery-item-v3:hover .id-overlay {
    opacity: 1;
}

.id-gallery-item-v3 .id-overlay-actions {
    display: flex;
    gap: 5px;
    justify-content: center;
}

.id-gallery-item-v3 .id-overlay-actions button {
    padding: 2px 10px;
    border: none;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
}

/* ============================================================ */
/* PREVIEW - TOUJOURS VISIBLE                                   */
/* ============================================================ */

.id-preview-v3 {
    margin: 15px 0;
    padding: 16px 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    /* ✅ PAS DE display:none ici */
}

.id-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.id-preview-title {
    font-size: 15px;
    font-weight: 600;
    color: #1e1e1e;
}

/* ============================================================ */
/* PREVIEW CONTENT - UN SEUL ÉLÉMENT AVEC CLASSES DYNAMIQUES   */
/* ============================================================ */

#id-preview-content {
    min-height: 60px;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.6;
    transition: all 0.3s ease;
    background: #ffffff;
    border: 1px solid #e9ecef;
    overflow-y: auto;
    max-height: 300px;
    word-wrap: break-word;
}

/* ✅ État vide - classe appliquée par JS */
#id-preview-content.id-preview-content-empty {
    background: #f8fafc;
    border: 1px dashed #d1d5db;
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-style: italic;
}

/* ✅ État chargement - classe appliquée par JS */
#id-preview-content.id-preview-content-loading {
    background: #f8fafc;
    border: 1px dashed #4f46e5;
    color: #4f46e5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
}

#id-preview-content.id-preview-content-loading::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #e2e8f0;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: id-spin 0.6s linear infinite;
    margin-right: 10px;
}

@keyframes id-spin {
    to { transform: rotate(360deg); }
}

/* ✅ État erreur - classe appliquée par JS */
#id-preview-content.id-preview-content-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #dc2626;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ✅ État description - classe appliquée par JS */
#id-preview-content.id-preview-content-description {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: #1a1a2e;
    min-height: 40px;
    padding: 10px 14px;
    line-height: 1.7;
    font-size: 14px;
    white-space: pre-wrap;
    display: block;
}

#id-preview-content.id-preview-content-description br {
    display: block;
    content: "";
    margin: 4px 0;
}

#id-preview-content.id-preview-content-description h1,
#id-preview-content.id-preview-content-description h2,
#id-preview-content.id-preview-content-description h3,
#id-preview-content.id-preview-content-description h4 {
    margin: 8px 0 4px 0;
    color: #1a1a2e;
}

#id-preview-content.id-preview-content-description h1 { font-size: 20px; }
#id-preview-content.id-preview-content-description h2 { font-size: 18px; }
#id-preview-content.id-preview-content-description h3 { font-size: 16px; }
#id-preview-content.id-preview-content-description h4 { font-size: 14px; }

#id-preview-content.id-preview-content-description ul,
#id-preview-content.id-preview-content-description ol {
    margin: 4px 0 8px 0;
    padding-left: 20px;
}

#id-preview-content.id-preview-content-description li {
    margin: 2px 0;
}

#id-preview-content.id-preview-content-description p {
    margin: 4px 0;
}

#id-preview-content.id-preview-content-description strong {
    font-weight: 600;
    color: #1a1a2e;
}

#id-preview-content.id-preview-content-description em {
    font-style: italic;
}

#id-preview-content.id-preview-content-description blockquote {
    margin: 8px 0;
    padding: 4px 12px;
    border-left: 3px solid #4f46e5;
    background: #f8fafc;
}

#id-preview-content.id-preview-content-description code {
    background: #f1f5f9;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 13px;
}

#id-preview-content.id-preview-content-description pre {
    background: #f1f5f9;
    padding: 8px 12px;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 13px;
    margin: 4px 0;
}

/* ============================================================ */
/* PREVIEW ACTIONS                                              */
/* ============================================================ */

.id-preview-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.id-preview-actions select {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    background: white;
    cursor: pointer;
    min-height: 38px;
    flex: 1;
    min-width: 150px;
}

.id-preview-actions select:hover {
    border-color: #2271b1;
}

.id-preview-actions select:focus {
    border-color: #2271b1;
    outline: none;
    box-shadow: 0 0 0 3px rgba(34,113,177,0.1);
}

.id-preview-actions .id-btn {
    min-height: 38px;
    min-width: 120px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* ============================================================ */
/* RESPONSIVE                                                   */
/* ============================================================ */

@media (max-width: 600px) {
    .id-gallery-v3 {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .id-header {
        flex-direction: column;
        gap: 10px;
    }
    
    .id-preview-actions {
        flex-direction: column;
        align-items: stretch;
    }
    
    .id-preview-actions select {
        min-width: 100%;
    }
    
    .id-preview-actions .id-btn {
        width: 100%;
    }
    
    #id-preview-content {
        min-height: 50px;
        font-size: 13px;
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    #img-desc-container-v3 {
        padding: 12px;
    }
    
    .id-preview-v3 {
        padding: 12px 14px;
    }
    
    #id-preview-content.id-preview-content-description {
        font-size: 13px;
        padding: 8px 10px;
    }
}