/* ===== SYSTÈME DE SAUVEGARDE ===== */

/* Indicateur de sauvegarde */
.autosave-indicator {
    background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    margin: 15px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 15px rgba(26, 35, 126, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: slideInDown 0.3s ease;
}

.autosave-status {
    display: flex;
    align-items: center;
    gap: 12px;
}

.autosave-icon {
    font-size: 1.2rem;
    animation: pulse 2s infinite;
}

.autosave-text {
    font-weight: 600;
    font-size: 14px;
}

.autosave-time {
    font-size: 12px;
    opacity: 0.8;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
}

.autosave-actions {
    display: flex;
    gap: 8px;
}

.autosave-actions button {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.autosave-actions button:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

/* Modal de récupération */
.recovery-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10010;
    backdrop-filter: blur(5px);
}

.recovery-modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
}

.recovery-header {
    background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.recovery-header h3 {
    margin: 0;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.recovery-tab {
    flex: 1;
    padding: 15px;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 600;
    color: #666;
    transition: all 0.2s ease;
    border-bottom: 3px solid transparent;
}

.recovery-tab:hover {
    background: #e9ecef;
    color: #333;
}

.recovery-tab.active {
    color: #1a237e;
    border-bottom-color: #1a237e;
    background: white;
}

.recovery-tab-content {
    padding: 25px;
    max-height: 60vh;
    overflow-y: auto;
}

.recovery-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.recovery-stat {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.stat-value {
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.recovery-preview {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    margin: 20px 0;
}

.preview-header {
    background: #f8f9fa;
    padding: 12px 15px;
    font-weight: 600;
    border-bottom: 1px solid #e0e0e0;
    color: #1a237e;
}

.preview-content {
    padding: 15px;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    font-size: 13px;
    line-height: 1.5;
}

.preview-content img {
    max-width: 100px;
    height: auto;
    margin: 5px;
}

.recovery-actions {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

/* Historique des sauvegardes */
.history-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 10px;
    background: white;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-item:hover {
    border-color: #2196f3;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.1);
}

.history-info {
    flex: 1;
}

.history-time {
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.history-size {
    font-size: 12px;
    color: #666;
}

.history-actions {
    display: flex;
    gap: 8px;
}

/* Modal de comparaison */
.compare-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10011;
}

.compare-modal-content {
    background: white;
    border-radius: 12px;
    width: 95%;
    max-width: 1200px;
    max-height: 90vh;
    overflow: hidden;
}

.compare-header {
    background: linear-gradient(135deg, #2196f3 0%, #0d47a1 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.compare-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 20px;
    max-height: 50vh;
    overflow-y: auto;
}

.compare-side {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.compare-side h4 {
    background: #f8f9fa;
    padding: 12px;
    margin: 0;
    border-bottom: 1px solid #e0e0e0;
    color: #333;
}

.compare-content {
    padding: 15px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.5;
}

.compare-diff {
    padding: 20px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    max-height: 150px;
    overflow-y: auto;
}

.compare-actions {
    padding: 20px;
    display: flex;
    gap: 15px;
    border-top: 1px solid #e0e0e0;
}

/* Notification de sauvegarde */
.save-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #4caf50;
    color: white;
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(76, 175, 80, 0.3);
    z-index: 10012;
    display: none;
    animation: slideInRight 0.3s ease;
}

.save-notification-content {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
}

.save-icon {
    font-size: 1.5rem;
}

.save-message {
    font-weight: 500;
    flex: 1;
}

.save-progress {
    font-size: 12px;
    opacity: 0.9;
}

/* Animation de sauvegarde */
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

@keyframes slideInDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-30px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* Styles pour les différences */
.diff-added {
    background: #e8f5e9;
    color: #2e7d32;
    padding: 2px;
    border-radius: 2px;
}

.diff-removed {
    background: #ffebee;
    color: #c62828;
    padding: 2px;
    border-radius: 2px;
    text-decoration: line-through;
}

.diff-changed {
    background: #fff3e0;
    color: #ef6c00;
    padding: 2px;
    border-radius: 2px;
}

/* Responsive */
@media (max-width: 768px) {
    .autosave-indicator {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }
    
    .autosave-actions {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .recovery-modal-content {
        width: 95%;
        margin: 10px;
    }
    
    .compare-layout {
        grid-template-columns: 1fr;
        max-height: 60vh;
    }
    
    .compare-content {
        max-height: 150px;
    }
}

/* État d'erreur */
.save-error {
    background: #f44336 !important;
}

.save-success {
    background: #4caf50 !important;
}

.save-warning {
    background: #ff9800 !important;
}

/* ===== TRAINING CONTENT STYLE CONDITIONNEL ===== */

/* Style de base pour le contenu */
.rich-content-wrapper {
    font-size: 1.1rem;
    line-height: 1.6;
    color: #333;
    max-width: 800px;
    margin: 0 auto;
    text-align: justify;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Préservation des styles inline des éléments */
.rich-content-wrapper * {
    box-sizing: border-box;
}

/* Images avec styles inline préservés */
.rich-content-wrapper img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 15px 0;
    display: inline-block;
}

/* Images avec alignement spécifique (classes) */
.rich-content-wrapper img.align-left,
.rich-content-wrapper figure.align-left img {
    float: left !important;
    margin: 0 20px 15px 0 !important;
    max-width: 50% !important;
}

.rich-content-wrapper img.align-right,
.rich-content-wrapper figure.align-right img {
    float: right !important;
    margin: 0 0 15px 20px !important;
    max-width: 50% !important;
}

.rich-content-wrapper img.align-center,
.rich-content-wrapper figure.align-center img {
    display: block !important;
    margin: 15px auto !important;
    float: none !important;
    max-width: 80% !important;
}

/* Images avec styles inline d'alignement (override) */
.rich-content-wrapper img[style*="float: left"],
.rich-content-wrapper img[style*="float:left"] {
    float: left !important;
    margin-right: 20px !important;
    margin-bottom: 15px !important;
}

.rich-content-wrapper img[style*="float: right"],
.rich-content-wrapper img[style*="float:right"] {
    float: right !important;
    margin-left: 20px !important;
    margin-bottom: 15px !important;
}

.rich-content-wrapper img[style*="margin: auto"],
.rich-content-wrapper img[style*="margin:auto"],
.rich-content-wrapper img[style*="margin-left: auto"],
.rich-content-wrapper img[style*="margin-right: auto"] {
    display: block !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

/* Figures - styles conditionnels basés sur les classes */
.rich-content-wrapper figure {
    margin: 2px 0;
    padding: 11px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e0e0e0;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

/* Figures avec shadow (option) */
.rich-content-wrapper figure[style*="box-shadow"],
.rich-content-wrapper figure.shadow {
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
}

/* Figures avec border (option) */
.rich-content-wrapper figure[style*="border:"],
.rich-content-wrapper figure.bordered {
    border-width: 2px;
    background: #f9f9f9;
    padding: 1px;
}

/* Alignement des figures */
.rich-content-wrapper figure.align-left {
    float: left;
    margin-right: 25px;
    margin-bottom: 15px;
    max-width: 45%;
}

.rich-content-wrapper figure.align-right {
    float: right;
    margin-left: 25px;
    margin-bottom: 15px;
    max-width: 45%;
}

.rich-content-wrapper figure.align-center {
    display: block;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    max-width: 75%;
}

/* Images dans les figures */
.rich-content-wrapper figure img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 0 0 10px 0;
    display: block;
}

/* Légendes - styles conditionnels */
.rich-content-wrapper figcaption {
    font-size: 0.95em;
    color: #666;
    font-style: italic;
    text-align: center;
    margin-top: 10px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    border-top: 1px solid #e0e0e0;
    line-height: 1.5;
}

/* Légendes avec styles inline préservés */
.rich-content-wrapper figcaption[style] {
    /* Les styles inline du contenu HTML sont prioritaires */
}

/* Clearfix pour conteneur principal */
.rich-content-wrapper:after {
    content: "";
    display: table;
    clear: both;
}

/* Clearfix pour paragraphes avec images flottantes */
.rich-content-wrapper p:after,
.rich-content-wrapper div:after {
    content: "";
    display: table;
    clear: both;
}

/* Pour les paragraphes suivant les éléments flottants */
.rich-content-wrapper p,
.rich-content-wrapper div {
    overflow: hidden;
    margin-bottom: 1em;
}

/* Styles de texte conditionnels */
.rich-content-wrapper .highlight {
    background: linear-gradient(120deg, #ffd54f80 0%, #ffd54f80 100%);
    padding: 2px 4px;
    border-radius: 3px;
}

.rich-content-wrapper .text-left { text-align: left !important; }
.rich-content-wrapper .text-center { text-align: center !important; }
.rich-content-wrapper .text-right { text-align: right !important; }
.rich-content-wrapper .text-justify { text-align: justify !important; }

/* Styles pour éléments avec bordures spéciales */
.rich-content-wrapper .bordered {
    border: 2px solid #e0e0e0 !important;
    padding: 15px !important;
    border-radius: 8px !important;
    background: #f9f9f9 !important;
}

.rich-content-wrapper .shadow {
    box-shadow: 0 5px 20px rgba(0,0,0,0.15) !important;
}

/* Responsive - toujours appliquer en mobile */
@media (max-width: 768px) {
    /* Désactiver les flottants en mobile */
    .rich-content-wrapper img.align-left,
    .rich-content-wrapper img.align-right,
    .rich-content-wrapper img[style*="float: left"],
    .rich-content-wrapper img[style*="float:right"],
    .rich-content-wrapper figure.align-left,
    .rich-content-wrapper figure.align-right {
        float: none !important;
        margin: 10px auto !important;
        max-width: 100% !important;
        display: block !important;
    }
    
    /* Ajuster les figures en mobile */
    .rich-content-wrapper figure {
        padding: 12px;
        margin: 10px auto;
        max-width: 95% !important;
    }
    
    .rich-content-wrapper figure.align-center {
        max-width: 95% !important;
    }
    
    .rich-content-wrapper figcaption {
        font-size: 0.85em;
        padding: 8px;
    }
    
    /* Ajuster les marges des images */
    .rich-content-wrapper img {
        margin: 10px auto !important;
        max-width: 100% !important;
    }
}

/* Animation pour hover (optionnel) */
.rich-content-wrapper figure:hover {
    border-color: #2196f3;
    box-shadow: 0 8px 25px rgba(33, 150, 243, 0.15);
}

/* Barre de couleur pour figures (optionnel) */
.rich-content-wrapper figure.premium::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #2196f3, #4caf50);
}

/* Garder la priorité des styles inline */
.rich-content-wrapper *[style] {
    /* Les styles inline ont toujours priorité sur le CSS */
}

/* Classes utilitaires pour l'alignement du texte */
.rich-content-wrapper .align-text-left { text-align: left; }
.rich-content-wrapper .align-text-center { text-align: center; }
.rich-content-wrapper .align-text-right { text-align: right; }

/* Menu contextuel pour images */
.image-context-menu {
    animation: fadeInScale 0.15s ease;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.image-context-menu button:hover {
    background: #f0f9ff !important;
    color: #2196f3;
}

.image-context-menu button:active {
    background: #e3f2fd !important;
}

/* Fin training content style*/

/* ===== STYLES POUR L'ALIGNEMENT DANS L'ÉDITEUR ===== */

/* Images dans l'éditeur */
.editor-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
    transition: all 0.3s ease;
}

.editor-content img:hover {
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

/* Images alignées à gauche dans l'éditeur */
.editor-content img.align-left,
.editor-content .align-left img {
    float: left !important;
    margin: 0 15px 10px 0 !important;
    max-width: 50% !important;
}

/* Images alignées à droite dans l'éditeur */
.editor-content img.align-right,
.editor-content .align-right img {
    float: right !important;
    margin: 0 0 10px 15px !important;
    max-width: 50% !important;
}

/* Images centrées dans l'éditeur */
.editor-content img.align-center,
.editor-content .align-center img {
    display: block !important;
    margin: 10px auto !important;
    float: none !important;
    max-width: 80% !important;
}

/* Clearfix pour l'éditeur */
.editor-content:after {
    content: "";
    display: table;
    clear: both;
}

/* Indicateur visuel pour l'alignement */
.editor-content img.align-left::after,
.editor-content img.align-right::after,
.editor-content img.align-center::after {
    content: attr(class);
    position: absolute;
    top: -10px;
    right: -10px;
    background: rgba(33, 150, 243, 0.9);
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.editor-content img:hover::after {
    opacity: 1;
}

/* Figures dans l'éditeur */
.editor-content figure {
    margin: 15px 0;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.editor-content figure.align-left {
    float: left;
    margin-right: 20px;
    margin-bottom: 10px;
    max-width: 50%;
}

.editor-content figure.align-right {
    float: right;
    margin-left: 20px;
    margin-bottom: 10px;
    max-width: 50%;
}

.editor-content figure.align-center {
    display: block;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    max-width: 80%;
}

.editor-content figcaption {
    font-size: 13px;
    color: #666;
    font-style: italic;
    text-align: center;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #ddd;
}

/* Interface pour ajouter des légendes */
.caption-input {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px;
    font-size: 12px;
    display: none;
}

figure:hover .caption-input {
    display: block;
}


/* ===== STYLES POUR L'ÉDITEUR AVEC FIGURES ET LÉGENDES ===== */

/* Figures dans l'éditeur */
.editor-content figure {
    margin: 20px 0;
    transition: all 0.3s ease;
    position: relative;
}

.editor-content figure:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 40px rgba(0,0,0,0.15) !important;
}

.editor-content figure::before {
    content: '🖼️ Figure';
    position: absolute;
    top: -25px;
    left: 0;
    font-size: 11px;
    color: #666;
    background: #f5f5f5;
    padding: 2px 8px;
    border-radius: 10px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.editor-content figure:hover::before {
    opacity: 1;
}

/* Images dans les figures */
.editor-content figure img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 0;
}

/* Légendes dans l'éditeur */
.editor-content figcaption {
    font-size: 14px;
    color: #666;
    font-style: italic;
    text-align: center;
    padding: 10px;
    margin-top: 5px;
    background: linear-gradient(to bottom, #f9f9f9, #f0f0f0);
    border-radius: 0 0 8px 8px;
    border-top: 1px solid #e0e0e0;
    position: relative;
}

.editor-content figcaption:hover {
    background: #fff8e1;
    cursor: text;
}

.editor-content figcaption:empty::before {
    content: 'Cliquez pour ajouter une légende...';
    color: #999;
    font-style: italic;
}

/* Alignement des figures */
.editor-content figure.align-left {
    float: left;
    margin-right: 20px;
    margin-bottom: 15px;
    max-width: 50%;
}

.editor-content figure.align-right {
    float: right;
    margin-left: 20px;
    margin-bottom: 15px;
    max-width: 50%;
}

.editor-content figure.align-center {
    display: block;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    max-width: 80%;
}

/* Boutons de contrôle sur les figures */
.figure-controls {
    position: absolute;
    top: -10px;
    right: -10px;
    display: none;
    gap: 5px;
    z-index: 10;
}

.editor-content figure:hover .figure-controls {
    display: flex;
}

.control-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s ease;
}

.control-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 12px rgba(0,0,0,0.3);
}

.control-btn.edit-caption {
    background: #2196f3;
    color: white;
}

.control-btn.change-alignment {
    background: #4caf50;
    color: white;
}

.control-btn.remove-figure {
    background: #f44336;
    color: white;
}

/* Clearfix */
.editor-content .clearfix {
    clear: both;
}

/* État d'édition */
.editor-content figcaption.editing {
    background: #fffde7;
    border: 1px dashed #ffd600;
    outline: none;
}