/* ==========================================================================
   STYLES POUR LES BLOCS DE CODE
   ========================================================================== */
.code-container {
    margin: 16px 0;
    border: 1px solid var(--code-bordure);
    border-radius: var(--rayon);
    background: var(--code-fond);
    overflow: hidden;
    position: relative;
}

.code-container.html-court {
    /* Styles spéciaux pour les petits blocs HTML */
}

.code-header {
    padding: 8px 12px;
    background: var(--fond-tertiaire);
    border-bottom: 1px solid var(--code-bordure);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    position: relative;
    z-index: 1;
}

.code-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.code-chevron {
    transition: transform 0.2s;
    font-size: 10px;
}

.code-container.replie .code-chevron {
    transform: rotate(-90deg);
}

.code-filename {
    font-weight: 500;
    color: var(--texte-principal);
}

.code-langage {
    color: var(--accent);
    font-weight: 600;
}

.code-lignes {
    color: var(--texte-secondaire);
    font-size: 11px;
}

.code-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.code-container:hover .code-actions {
    opacity: 1;
}

.btn-voir-code, .btn-comparer-code, .btn-telecharger-code-inline, .btn-copier-code, .btn-renommer-fichier, .btn-wrap-code {
    padding: 4px 8px;
    border: 1px solid var(--bordure);
    background: var(--fond-principal);
    color: var(--texte-secondaire);
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    transition: var(--transition);
}

.btn-voir-code:hover, .btn-comparer-code:hover, .btn-telecharger-code-inline:hover, .btn-copier-code:hover, .btn-renommer-fichier:hover, .btn-wrap-code:hover {
    background: var(--fond-tertiaire);
    color: var(--accent);
}

.btn-wrap-code.actif {
    background: var(--accent-leger);
    color: var(--accent);
    border-color: var(--accent);
}

.btn-renommer-fichier {
    background: #e8f4fd;
    color: #1976d2;
    border-color: #bbdefb;
}

.btn-renommer-fichier:hover {
    background: #1976d2;
    color: white;
    border-color: #1565c0;
}

.code-container pre {
    margin: 0;
    padding: 12px;
    background: transparent;
    overflow-x: auto;
    display: block;
    position: relative;
}

/* Règle corrigée pour le retour à la ligne */
body.code-wrap-globally-enabled .code-container pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-all;
    overflow-x: hidden;
}

.code-container.replie pre {
    display: none;
}

body.code-limit-height .code-container:not(.html-court):not(.streaming) pre {
    max-height: calc(var(--code-max-lines, 15) * 1.4em + 24px);
    overflow-y: auto;
    scrollbar-width: thin;
}

body.code-limit-height .code-container:not(.html-court):not(.streaming) pre::-webkit-scrollbar {
    width: 8px;
}

body.code-limit-height .code-container:not(.html-court):not(.streaming) pre::-webkit-scrollbar-track {
    background: transparent;
}

body.code-limit-height .code-container:not(.html-court):not(.streaming) pre::-webkit-scrollbar-thumb {
    background: var(--bordure);
    border-radius: 4px;
}

body.code-limit-height .code-container:not(.html-court):not(.streaming) pre::-webkit-scrollbar-thumb:hover {
    background: var(--texte-tertiaire);
}

body.code-limit-height .code-container:not(.html-court):not(.streaming) pre code {
    display: block;
}

/* Correction pour l'alternance des lignes Prism avec scroll */
body.code-limit-height .code-container:not(.html-court):not(.streaming) pre code.language-* {
    /* Force un rendu cohérent des lignes */
    line-height: 1.4 !important;
    display: block;
    width: 100%;
    /* Empêche les problèmes d'alignement de Prism */
    counter-reset: linenumber;
}

/* Correction spécifique pour prism-coy qui a des problèmes d'alternance */
body.code-limit-height .code-container:not(.html-court):not(.streaming) pre[class*="language-"] {
    /* Force un rendu consistant */
    background-attachment: local !important;
    position: relative;
}

/* Force Prism à bien gérer le scroll en désactivant certains styles problématiques */
body.code-limit-height pre[class*="language-"]::before,
body.code-limit-height pre[class*="language-"]::after {
    display: none !important;
}

/* Assure une alternance propre même avec le scroll */
body.code-limit-height pre[class*="language-"] code[class*="language-"] {
    background: transparent !important;
    /* Empêche les conflits avec l'alternance de Prism */
}

/* Désactive complètement l'alternance prism-coy problématique avec scroll */
body.code-limit-height pre[class*="language-"]:before {
    box-shadow: none !important;
    background: none !important;
}

/* Force un fond uni pour éviter les artefacts de scroll */
body.code-limit-height pre[class*="language-"] {
    background: var(--code-fond) !important;
    box-shadow: none !important;
    border: none !important;
    border-left: none !important;
    border-right: none !important;
    border-top: none !important;
    border-bottom: none !important;
}

/* Correction spécifique pour prism-coy theme */
body.code-limit-height pre[class*="language-"]:not(.line-numbers):before {
    display: none !important;
}

/* Assure une continuité visuelle du code même en scrollant */
body.code-limit-height pre[class*="language-"] code {
    /* Fond uniforme pour éviter les coupures visuelles */
    background: transparent !important;
    box-shadow: none !important;
}

/* CORRECTION COMPLÈTE: Désactive tous les effets visuels prism-coy avec scroll */
body.code-limit-height .code-container {
    /* Assure que le conteneur n'a pas de styles conflictuels */
    border-left: 1px solid var(--code-bordure) !important;
}

body.code-limit-height pre[class*="language-"],
body.code-limit-height pre[class*="language-"] *,
body.code-limit-height code[class*="language-"],
body.code-limit-height code[class*="language-"] * {
    /* Force la suppression de tous les effets prism-coy */
    border-left: none !important;
    border-right: none !important;
    box-shadow: none !important;
    background-attachment: scroll !important;
}

/* Remplace la bordure prism-coy par notre propre bordure stable */
body.code-limit-height .code-container pre {
    border-left: 4px solid var(--accent) !important;
    padding-left: 16px !important;
}

.code-container pre::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: transparent;
}

.code-container code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    line-height: 1.4;
    color: var(--code-texte);
    display: block;
    width: 100%;
}

.code-container pre code {
    overflow: visible;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.code-container.streaming {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-leger);
}

.code-container.streaming .code-header {
    background: linear-gradient(90deg, var(--fond-tertiaire), var(--accent-leger), var(--fond-tertiaire));
    background-size: 200% 100%;
    animation: streaming-gradient 2s linear infinite;
}

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

/* Styles spécifiques pour la zone d'outils */
.tool-panel-content .code-display {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.code-display-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--bordure);
    background: var(--fond-principal);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.code-display-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.code-filename-large {
    font-weight: 600;
    font-size: 16px;
    color: var(--texte-principal);
}

.code-meta {
    font-size: 12px;
    color: var(--texte-secondaire);
}

.code-display-content {
    flex: 1;
    overflow: auto;
    background: var(--code-fond);
}

.code-pre {
    margin: 0;
    padding: 16px;
    background: transparent;
    overflow-x: auto;
    height: 100%;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
}

.html-preview {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

/* Comparateur de code */
.code-comparator {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.comparator-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--bordure);
    background: var(--fond-principal);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.comparator-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.comparator-filename {
    color: var(--texte-principal);
}

.comparator-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.version-control {
    display: flex;
    align-items: center;
    gap: 4px;
}

.version-select {
    padding: 4px 8px;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--fond-principal);
    color: var(--texte-principal);
    font-size: 12px;
}

.comparator-arrow {
    color: var(--texte-tertiaire);
    margin: 0 8px;
}

.btn-mode-diff {
    padding: 6px 12px;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--fond-principal);
    color: var(--texte-secondaire);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-mode-diff:hover {
    background: var(--fond-tertiaire);
    color: var(--accent);
}

.btn-telecharger-code {
    padding: 6px 12px;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--accent);
    color: white;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-telecharger-code:hover {
    background: var(--accent-hover);
}

.comparator-content {
    flex: 1;
    overflow: auto;
    background: var(--code-fond);
}

/* Styles pour les diffs */
.diff-container {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    line-height: 1.4;
    padding: 16px;
    background: var(--code-fond);
    overflow-x: auto;
}

.diff-container.diff-mots {
    overflow-x: visible;
}

/* Lignes en mode mots */
.diff-word-line {
    display: flex;
    padding: 2px 0;
    margin: 1px 0;
    min-height: 20px;
    align-items: flex-start;
}

.diff-word-line .line-num {
    align-self: flex-start;
}

.diff-word-content {
    flex: 1;
    padding-left: 8px;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
}

.diff-word-content ins,
.diff-word-content del {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.diff-header {
    background: var(--fond-tertiaire);
    padding: 8px 12px;
    margin: 8px 0;
    border-radius: var(--rayon);
    font-weight: 500;
    color: var(--texte-secondaire);
    border-left: 4px solid var(--accent);
}

.diff-addition {
    background: var(--diff-addition);
    color: var(--diff-addition-text);
    display: flex;
    align-items: flex-start;
    padding: 2px 0;
    margin: 1px 0;
}

.diff-deletion {
    background: var(--diff-deletion);
    color: var(--diff-deletion-text);
    display: flex;
    align-items: flex-start;
    padding: 2px 0;
    margin: 1px 0;
}

.diff-context {
    display: flex;
    align-items: flex-start;
    color: var(--texte-principal);
    padding: 1px 0;
}

.diff-marker {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    user-select: none;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.1);
}

.diff-content {
    flex: 1;
    padding-left: 8px;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
}

.diff-word-added {
    background: #d4f4dd;
    color: #0d7a2d;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 500;
}

.diff-word-removed {
    background: #fee2e2;
    color: #b91c1c;
    padding: 2px 4px;
    border-radius: 3px;
    text-decoration: line-through;
    font-weight: 500;
}

.diff-empty {
    text-align: center;
    padding: 40px;
    color: var(--texte-tertiaire);
    font-style: italic;
    background: var(--fond-tertiaire);
    border-radius: var(--rayon);
    margin: 16px;
}

/* Numérotation des lignes */
.line-num {
    min-width: 50px;
    text-align: right;
    padding: 0 8px;
    background: rgba(0, 0, 0, 0.15);
    color: var(--texte-tertiaire);
    user-select: none;
    border-right: 1px solid var(--bordure);
    font-size: 11px;
    flex-shrink: 0;
}

.line-num.old {
    border-right: none;
}

.line-num.new {
    border-right: 1px solid var(--bordure);
}

/* Hover sur lignes */
.diff-line {
    display: flex;
    position: relative;
}

.diff-line:hover {
    background: rgba(255, 255, 255, 0.05) !important;
    transition: background 75ms;
}

/* Statistiques diff */
.diff-stats {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 16px;
    font-size: 12px;
}

.stat-additions {
    color: #22c55e;
    font-weight: 600;
}

.stat-deletions {
    color: #ef4444;
    font-weight: 600;
}

.stat-bar {
    display: flex;
    width: 80px;
    height: 8px;
    background: var(--fond-tertiaire);
    border-radius: 4px;
    overflow: hidden;
}

.bar-add {
    background: #22c55e;
    height: 100%;
}

.bar-del {
    background: #ef4444;
    height: 100%;
}

/* Bouton copie par ligne */
.copy-line-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    padding: 4px 8px;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--fond-principal);
    color: var(--texte-secondaire);
    cursor: pointer;
    transition: opacity 0.2s, background 0.2s;
    font-size: 11px;
    z-index: 10;
}

.diff-line:hover .copy-line-btn {
    opacity: 1;
}

.copy-line-btn:hover {
    background: var(--accent);
    color: white;
}

/* Navigation entre diffs */
.diff-navigation {
    display: flex;
    gap: 2px;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    overflow: hidden;
}

.btn-prev-diff,
.btn-next-diff {
    padding: 6px 10px;
    background: var(--fond-principal);
    color: var(--texte-secondaire);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    font-size: 12px;
}

.btn-prev-diff:hover,
.btn-next-diff:hover {
    background: var(--fond-tertiaire);
    color: var(--accent);
}

.btn-prev-diff {
    border-right: 1px solid var(--bordure);
}

/* Highlight temporaire lors de la navigation */
.diff-highlight {
    animation: highlightPulse 1s ease-out;
}

@keyframes highlightPulse {
    0% {
        background: var(--accent);
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
    }
    100% {
        background: inherit;
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
    }
}

/* ========================================
   RESPONSIVE MOBILE - BOUTONS CODE
   ======================================== */

@media (max-width: 768px) {
    /* Header code plus compact */
    .code-header {
        padding: 6px 10px;
        flex-wrap: wrap;
        gap: 6px;
    }

    .code-info {
        gap: 6px;
        font-size: 11px;
        flex: 1;
        min-width: 0;
    }

    .code-filename {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 120px;
    }

    /* Boutons toujours visibles sur mobile - icônes seules */
    .code-actions {
        opacity: 1 !important;
        flex-wrap: nowrap;
        gap: 2px;
        justify-content: flex-end;
    }

    /* Boutons compacts: icônes seules */
    .btn-voir-code, .btn-comparer-code, .btn-telecharger-code-inline,
    .btn-copier-code, .btn-renommer-fichier, .btn-wrap-code {
        padding: 4px 6px;
        font-size: 11px;
    }

    /* Cacher texte des boutons code sur mobile */
    .code-actions .btn-texte {
        display: none;
    }

    .code-actions button i {
        margin-right: 0 !important;
    }

    /* Tooltip au survol sur mobile */
    .code-actions button:hover .btn-texte,
    .code-actions button:focus .btn-texte {
        display: inline;
        margin-left: 4px;
    }

    /* Code container */
    .code-container {
        margin: 10px 0;
    }

    .code-container pre {
        padding: 8px;
        font-size: 12px;
    }

    /* Comparateur plus compact */
    .comparator-header {
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .comparator-controls {
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
        justify-content: flex-start;
    }

    .version-select {
        font-size: 11px;
        padding: 3px 6px;
    }

    .btn-mode-diff, .btn-telecharger-code {
        font-size: 11px;
        padding: 4px 8px;
    }

    .diff-stats {
        margin-left: 0;
        width: 100%;
        margin-top: 6px;
    }
}