/* =====================================================
   Documentation Markdown Styles
   Aligné sur les standards de documentation technique
   (GitHub Docs, MDN, ReadTheDocs)
   ===================================================== */

/* ===== Conteneur prose ===== */
.prose {
    max-width: 100%; /* Utilise tout l'espace disponible */
    color: var(--text-primary);
    font-size: 16px; /* Standard documentation */
    line-height: 1.6;
}

/* ===== Titres ===== */
.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.25;
    scroll-margin-top: 5rem; /* Compense le header fixe */
}

.prose h1 {
    font-size: 2rem; /* 32px */
    margin-top: 0;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-primary);
    font-weight: 700;
}

.prose h2 {
    font-size: 1.5rem; /* 24px */
    margin-top: 2rem;
    margin-bottom: 1rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border-primary);
}

.prose h3 {
    font-size: 1.25rem; /* 20px */
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

.prose h4 {
    font-size: 1rem; /* 16px */
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.prose h5,
.prose h6 {
    font-size: 0.875rem; /* 14px */
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Paragraphes ===== */
.prose p {
    margin: 1rem 0;
    line-height: 1.6;
}

.prose p:first-child {
    margin-top: 0;
}

.prose p:last-child {
    margin-bottom: 0;
}

/* ===== Liens ===== */
.prose a {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px solid var(--primary-light);
    transition: all var(--transition-fast);
}

[data-theme="dark"] .prose a {
    color: #60a5fa; /* Bleu plus clair pour dark mode */
    border-bottom-color: #3b82f6;
}

.prose a:hover {
    color: var(--primary-dark);
    border-bottom-color: var(--primary-dark);
}

[data-theme="dark"] .prose a:hover {
    color: #93c5fd; /* Bleu encore plus clair au hover */
    border-bottom-color: #60a5fa;
}

/* ===== Listes ===== */
.prose ul,
.prose ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

.prose ul {
    list-style-type: disc;
}

.prose ol {
    list-style-type: decimal;
}

.prose li {
    margin: 0.25rem 0;
    line-height: 1.6;
}

.prose li::marker {
    color: var(--primary);
}

.prose li > p {
    margin: 0.5rem 0;
}

.prose li > ul,
.prose li > ol {
    margin-top: 0.5rem;
}

.prose ul ul {
    list-style-type: circle;
}

.prose ul ul ul {
    list-style-type: square;
}

/* ===== Code ===== */
.prose code {
    background: var(--bg-tertiary);
    color: #e3116c;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.875em;
    font-weight: 500;
}

[data-theme="dark"] .prose code {
    background: var(--gray-100);
}

.prose :not(pre) > code {
    white-space: nowrap;
}

.prose pre {
    background: #282c34;
    color: #abb2bf;
    padding: 2.5rem 1rem 1rem 1rem; /* Plus d'espace en haut pour le badge */
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 1.5rem 0;
    border: 1px solid var(--gray-300);
    line-height: 1.5;
    position: relative;
    min-width: 75%; /* Largeur minimale */
    width: fit-content; /* S'adapte au contenu */
    max-width: 100%;
}

.prose pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: 0.875rem;
    font-weight: 400;
    display: block;
}

/* Scrollbar pour blocs de code */
.prose pre::-webkit-scrollbar {
    height: 8px;
}

.prose pre::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.prose pre::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.prose pre::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Bouton copier pour les blocs de code */
.code-copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: #abb2bf;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    color: #ffffff;
}

.code-copy-btn.copied {
    background: rgba(76, 175, 80, 0.2);
    border-color: rgba(76, 175, 80, 0.5);
    color: #4caf50;
}

.code-copy-btn svg {
    width: 16px;
    height: 16px;
}

/* Badge de langage */
.code-lang-badge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    color: #61afef;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: 'Consolas', 'Monaco', monospace;
}

/* ===== Tableaux ===== */
.prose table {
    width: auto; /* S'adapte au contenu */
    min-width: 50%; /* Largeur minimale */
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.875rem;
}

.prose th,
.prose td {
    padding: 0.75rem;
    text-align: left;
    border: 1px solid var(--border-primary);
    min-width: 120px; /* Largeur minimale par colonne */
    white-space: nowrap; /* Évite le retour à la ligne */
}

/* Pour les cellules avec beaucoup de texte, permettre le wrap */
.prose td.wrap,
.prose th.wrap {
    white-space: normal;
}

.prose th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
}

.prose tbody tr:hover {
    background: var(--bg-secondary);
}

/* ===== Citations (blockquote) ===== */
.prose blockquote {
    margin: 1.5rem 0;
    padding: 0.75rem 1rem;
    border-left: 4px solid var(--border-primary);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.prose blockquote p {
    margin: 0.5rem 0;
}

.prose blockquote p:first-child {
    margin-top: 0;
}

.prose blockquote p:last-child {
    margin-bottom: 0;
}

/* ===== Callouts (Note, Important, Tip, Exemple) ===== */
.prose .note,
.prose .important,
.prose .tip,
.prose .exemple {
    padding: 1rem;
    margin: 1.5rem 0;
    border-left: 4px solid;
    border-radius: var(--radius-md);
    background: var(--white);
    width: fit-content; /* S'adapte au contenu */
    min-width: 50%; /* Largeur minimale */
    max-width: 100%; /* Ne dépasse pas le conteneur */
    color: var(--text-primary);
}

.prose .note::before,
.prose .important::before,
.prose .tip::before,
.prose .exemple::before {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.prose .note {
    background: color-mix(in srgb, var(--info) 5%, white);
    border-color: var(--info);
}

[data-theme="dark"] .prose .note {
    background: color-mix(in srgb, var(--info) 15%, #1F2937);
}

.prose .note::before {
    content: "📘 Note";
    color: var(--info);
}

.prose .important {
    background: color-mix(in srgb, var(--warning) 5%, white);
    border-color: var(--warning);
}

[data-theme="dark"] .prose .important {
    background: color-mix(in srgb, var(--warning) 15%, #1F2937);
}

.prose .important::before {
    content: "⚠️ Important";
    color: var(--warning);
}

.prose .tip {
    background: color-mix(in srgb, var(--success) 5%, white);
    border-color: var(--success);
}

[data-theme="dark"] .prose .tip {
    background: color-mix(in srgb, var(--success) 15%, #1F2937);
}

.prose .tip::before {
    content: "💡 Astuce";
    color: var(--success);
}

.prose .exemple {
    background: color-mix(in srgb, var(--gray-400) 5%, white);
    border-color: var(--gray-400);
}

[data-theme="dark"] .prose .exemple {
    background: color-mix(in srgb, var(--gray-400) 15%, #1F2937);
}

.prose .exemple::before {
    content: "📝 Exemple";
    color: var(--text-secondary);
}

/* ===== Images ===== */
.prose img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: 1.5rem 0;
    border: 1px solid var(--border-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.prose img:hover {
    box-shadow: var(--shadow-md);
    transform: scale(1.02);
}

/* Tailles d'images */
.prose img.img-small {
    max-width: 300px;
}

.prose img.img-medium {
    max-width: 600px;
}

.prose img.img-large {
    max-width: 900px;
}

.prose img.img-full {
    max-width: 100%;
}

/* Alignements d'images */
.prose img.img-align-left {
    display: block;
    margin-left: 0;
    margin-right: auto;
}

.prose img.img-align-center {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.prose img.img-align-right {
    display: block;
    margin-left: auto;
    margin-right: 0;
}

/* Figures avec captions */
.prose figure {
    margin: 1.5rem 0;
    display: inline-block;
    max-width: 100%;
}

.prose figure.img-figure-left {
    display: block;
    width: fit-content; /* S'adapte à la largeur de l'image */
    max-width: 100%;
    margin-left: 0;
    margin-right: auto;
}

.prose figure.img-figure-center {
    display: block;
    width: fit-content; /* S'adapte à la largeur de l'image */
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.prose figure.img-figure-right {
    display: block;
    width: fit-content; /* S'adapte à la largeur de l'image */
    max-width: 100%;
    margin-left: auto;
    margin-right: 0;
}

.prose figure img {
    margin: 0; /* Reset margin pour les images dans figure */
}

.prose figcaption {
    margin-top: 0.75rem;
    padding: 0 0.5rem;
    text-align: center; /* Légende toujours centrée sous l'image */
    font-size: 0.875rem;
    color: var(--text-tertiary);
    font-style: italic;
    line-height: 1.4;
}

/* ===== Ligne horizontale ===== */
.prose hr {
    border: none;
    border-top: 1px solid var(--border-primary);
    margin: 2rem 0;
}

/* ===== Accordéons (details/summary) ===== */
.prose details {
    margin: 1rem 0;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.prose summary {
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    cursor: pointer;
    font-weight: 600;
    user-select: none;
    transition: background var(--transition-fast);
}

.prose summary:hover {
    background: var(--bg-secondary);
}

.prose details[open] summary {
    border-bottom: 1px solid var(--border-primary);
}

.prose details > *:not(summary) {
    padding: 1rem;
}

/* Réajuster le padding des listes dans les accordéons */
.prose details ul,
.prose details ol {
    padding-left: 2rem;
    margin: 0;
}

/* ===== Touches clavier (kbd) ===== */
.prose kbd {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.875em;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 3px;
    box-shadow: 0 1px 0 var(--border-secondary);
}

/* ===== Éléments sémantiques ===== */
.prose mark {
    background: #fef08a;
    color: #1F2937;
    padding: 0.125rem 0.25rem;
    border-radius: 2px;
}

[data-theme="dark"] .prose mark {
    background: #854d0e;
    color: #fef08a;
}

.prose strong {
    font-weight: 600;
    color: var(--text-primary);
}

.prose em {
    font-style: italic;
}

.prose small {
    font-size: 0.875em;
    color: var(--text-tertiary);
}

.prose sup {
    vertical-align: super;
    font-size: 0.75em;
}

.prose sub {
    vertical-align: sub;
    font-size: 0.75em;
}

.prose abbr[title] {
    text-decoration: underline dotted;
    cursor: help;
}

/* ===== Listes de définitions ===== */
.prose dl {
    margin: 1rem 0;
}

.prose dt {
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 1rem;
}

.prose dt:first-child {
    margin-top: 0;
}

.prose dd {
    margin-left: 2rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* ===== Steps / Étapes numérotées ===== */
.prose .steps {
    counter-reset: step-counter;
    list-style: none;
    padding-left: 0;
}

.prose .steps > li {
    counter-increment: step-counter;
    position: relative;
    padding-left: 3rem;
    margin-bottom: 1.5rem;
}

.prose .steps > li::before {
    content: counter(step-counter);
    position: absolute;
    left: 0;
    top: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: var(--white);
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 50%;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .prose {
        font-size: 15px;
    }

    .prose h1 {
        font-size: 1.75rem;
    }

    .prose h2 {
        font-size: 1.375rem;
    }

    .prose h3 {
        font-size: 1.125rem;
    }

    .prose pre {
        padding: 0.75rem;
        font-size: 0.8125rem;
    }

    .prose table {
        font-size: 0.8125rem;
    }

    .prose th,
    .prose td {
        padding: 0.5rem;
    }
}
