/* ========================================
   VARIABLES CSS - THÈMES
======================================== */

:root[data-theme="light"] {
    --pico-primary: #2563eb;
    --pico-primary-hover: #1d4ed8;
    --pico-background-color: #f8f9fa;
    --pico-text-color: #212529;
}

:root[data-theme="dark"] {
    --pico-primary: #60a5fa;
    --pico-primary-hover: #3b82f6;
    --pico-background-color: #212529;
    --pico-text-color: #f8f9fa;
}

:root[data-theme="amber"] {
    --pico-primary: #f59e0b;
    --pico-primary-hover: #d97706;
    --pico-background-color: #fff7ed;
    --pico-text-color: #451a03;
}

:root[data-theme="blue"] {
    --pico-primary: #3b82f6;
    --pico-primary-hover: #2563eb;
    --pico-background-color: #eff6ff;
    --pico-text-color: #1e3a8a;
}

:root[data-theme="cyan"] {
    --pico-primary: #06b6d4;
    --pico-primary-hover: #0891b2;
    --pico-background-color: #ecfeff;
    --pico-text-color: #164e63;
}

:root[data-theme="emerald"] {
    --pico-primary: #10b981;
    --pico-primary-hover: #059669;
    --pico-background-color: #ecfdf5;
    --pico-text-color: #064e3b;
}

:root[data-theme="fuchsia"] {
    --pico-primary: #d946ef;
    --pico-primary-hover: #c026d3;
    --pico-background-color: #fdf4ff;
    --pico-text-color: #701a75;
}

:root[data-theme="gray"] {
    --pico-primary: #6b7280;
    --pico-primary-hover: #4b5563;
    --pico-background-color: #f3f4f6;
    --pico-text-color: #1f2937;
}

:root[data-theme="green"] {
    --pico-primary: #16a34a;
    --pico-primary-hover: #15803d;
    --pico-background-color: #f0fdf4;
    --pico-text-color: #14532d;
}

:root[data-theme="indigo"] {
    --pico-primary: #4f46e5;
    --pico-primary-hover: #4338ca;
    --pico-background-color: #eef2ff;
    --pico-text-color: #312e81;
}

:root[data-theme="lime"] {
    --pico-primary: #84cc16;
    --pico-primary-hover: #65a30d;
    --pico-background-color: #f7fee7;
    --pico-text-color: #365314;
}

:root[data-theme="neutral"] {
    --pico-primary: #737373;
    --pico-primary-hover: #525252;
    --pico-background-color: #f5f5f5;
    --pico-text-color: #171717;
}

:root[data-theme="orange"] {
    --pico-primary: #f97316;
    --pico-primary-hover: #ea580c;
    --pico-background-color: #fff7ed;
    --pico-text-color: #7c2d12;
}

:root[data-theme="pink"] {
    --pico-primary: #ec4899;
    --pico-primary-hover: #db2777;
    --pico-background-color: #fdf2f8;
    --pico-text-color: #831843;
}

:root[data-theme="purple"] {
    --pico-primary: #9333ea;
    --pico-primary-hover: #7e22ce;
    --pico-background-color: #f5f3ff;
    --pico-text-color: #4c1d95;
}

:root[data-theme="red"] {
    --pico-primary: #ef4444;
    --pico-primary-hover: #dc2626;
    --pico-background-color: #fef2f2;
    --pico-text-color: #991b1b;
}

:root[data-theme="rose"] {
    --pico-primary: #f43f5e;
    --pico-primary-hover: #e11d48;
    --pico-background-color: #fff1f2;
    --pico-text-color: #881337;
}

:root[data-theme="sky"] {
    --pico-primary: #0ea5e9;
    --pico-primary-hover: #0284c7;
    --pico-background-color: #f0f9ff;
    --pico-text-color: #0c4a6e;
}

:root[data-theme="slate"] {
    --pico-primary: #64748b;
    --pico-primary-hover: #475569;
    --pico-background-color: #f1f5f9;
    --pico-text-color: #1e293b;
}

:root[data-theme="stone"] {
    --pico-primary: #78716c;
    --pico-primary-hover: #57534e;
    --pico-background-color: #f5f5f4;
    --pico-text-color: #292524;
}

:root[data-theme="teal"] {
    --pico-primary: #14b8a6;
    --pico-primary-hover: #0d9488;
    --pico-background-color: #f0fdfa;
    --pico-text-color: #134e4a;
}

:root[data-theme="violet"] {
    --pico-primary: #8b5cf6;
    --pico-primary-hover: #7c3aed;
    --pico-background-color: #f3e8ff;
    --pico-text-color: #4c1d95;
}

:root[data-theme="yellow"] {
    --pico-primary: #eab308;
    --pico-primary-hover: #ca8a04;
    --pico-background-color: #fefce8;
    --pico-text-color: #713f12;
}

:root[data-theme="zinc"] {
    --pico-primary: #71717a;
    --pico-primary-hover: #52525b;
    --pico-background-color: #f4f4f5;
    --pico-text-color: #27272a;
}

/* ========================================
   BASE & ÉLÉMENTS GLOBAUX
======================================== */

body {
    background-color: var(--pico-background-color);
    color: var(--pico-text-color);
    transition: background-color 0.3s, color 0.3s;
}

/* Boutons et éléments interactifs */
[role="button"], 
[type="submit"], 
button {
    background-color: var(--pico-primary);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
    transition: background-color 0.3s;
    border: none;
}

[role="button"]:hover, 
[type="submit"]:hover, 
button:hover {
    background-color: var(--pico-primary-hover);
}

/* Champs de recherche */
input[type="search"] {
    background-color: var(--pico-background-color);
    border: 1px solid var(--pico-primary);
    color: var(--pico-text-color);
    padding: 0.5rem;
    border-radius: 4px;
    transition: border-color 0.3s, background-color 0.3s;
}

input[type="search"]:focus {
    border-color: var(--pico-primary-hover);
    outline: none;
}

/* Icônes SVG globales */
svg.icon {
    width: 16px;
    height: 16px;
    vertical-align: middle;
}

/* ========================================
   HEADER & NAVIGATION
======================================== */

header {
    position: relative;
    z-index: 100;
}

header.sticky,
header[data-sticky="true"] {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--pico-background-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

header nav {
    position: relative;
    z-index: 100;
}

/* Titre du site avec lien */
header nav ul li hgroup h2 a {
    color: #000 !important;
    font-size: 1.2em;
    text-decoration: none !important;
    transition: color 0.2s ease;
}

header nav ul li hgroup h2 a:hover {
    color: var(--pico-primary-hover) !important;
    text-decoration: none !important;
}

/* Animation fusée */
@keyframes rocketFloat {
    0%, 100% { 
        transform: translateY(0px); 
    }
    50% { 
        transform: translateY(-4px); 
    }
}

header nav ul li hgroup h2 a .rocket-emoji {
    display: inline-block;
    animation: rocketFloat 3s ease-in-out infinite;
    margin-right: 0.5rem;
    font-size: 1.5em;
}

/* ========================================
   LAYOUT ARTICLE & WRAPPER
======================================== */

.article-wrapper {
    display: grid;
    grid-template-columns: 1fr;
    gap: 40px;
    align-items: start;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

.article-wrapper:has(#toc-container) {
    grid-template-columns: 1fr 320px;
}

.article-wrapper article {
    min-width: 0;
}

/* ========================================
   MÉTADONNÉES D'ARTICLE
======================================== */

.post-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
    color: #555;
    margin: 0.5rem 0;
}

.post-meta .icon {
    vertical-align: middle;
    margin-right: 0.2rem;
    stroke: #555;
    width: 16px;
    height: 16px;
}

/* ========================================
   TAGS
======================================== */

.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.tag {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    background-color: #f5f5f5;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #333;
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
}

.tag:hover {
    background-color: #e0e0e0;
    color: #000;
}

/* ========================================
   BOUTONS DE PARTAGE
======================================== */

.share-links {
    margin: 1rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.share-links p {
    margin: 0;
    font-size: 0.9rem;
    color: #555;
}

.share-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background-color: #f5f5f5;
    transition: background-color 0.2s;
}

.share-button:hover {
    background-color: #e0e0e0;
}

.share-button svg {
    width: 20px;
    height: 20px;
    stroke: #333;
}

/* ========================================
   BOUTON RETOUR EN HAUT
======================================== */

#backToTop {
    display: none;
    position: fixed;
    bottom: 30px;
    right: 100px;
    z-index: 100;
    background: var(--pico-primary);
    color: var(--pico-text-color);
    border: none;
    border-radius: 50%;
    padding: 6px 16px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: background 0.3s, transform 0.3s;
}

#backToTop:hover {
    background: var(--pico-primary-hover);
    transform: scale(1.1);
}

/* ========================================
   TABLE DES MATIÈRES (TOC)
======================================== */

#toc-container {
    position: sticky;
    top: 140px;
    width: 100%;
    max-height: calc(100vh - 180px);
    overflow: visible; /* CORRECTION: permet aux tooltips de dépasser */
    background: var(--pico-background-color, #f8f9fa);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
    scrollbar-gutter: stable;
    display: flex;
    flex-direction: column;
}

/* Scrollbar personnalisée */
#toc-container::-webkit-scrollbar {
    width: 6px;
}

#toc-container::-webkit-scrollbar-track {
    background: transparent;
}

#toc-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

#toc-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* En-tête TOC */
#toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--pico-primary, #2563eb);
    gap: 10px;
}

#toc-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: var(--pico-text-color, #333);
    flex: 1;
}

/* Bouton scroll to bottom */
#toc-scroll-bottom {
    background: var(--pico-primary, #2563eb) !important;
    border: none !important;
    cursor: pointer;
    padding: 8px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    color: white !important;
    transition: all 0.2s ease;
    border-radius: 6px !important;
    min-width: 36px;
    height: 36px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
}

/* Forcer la tooltip à être visible au-dessus de la TOC */
#toc-scroll-bottom[data-tooltip]::before,
#toc-scroll-bottom[data-tooltip]::after {
    z-index: 999;
}

#toc-scroll-bottom:hover {
    background: var(--pico-primary-hover, #1d4ed8) !important;
    transform: translateY(2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

#toc-scroll-bottom svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2.5;
    fill: none;
}

/* Conteneur liste TOC */
#toc-list-container {
    flex: 1;
    overflow-y: auto; /* Le scroll reste uniquement sur la liste */
    margin-right: -8px;
    padding-right: 8px;
    max-height: calc(100vh - 280px); /* Limite la hauteur pour permettre le scroll */
}

/* Listes - Suppression des puces */
#toc-container ul,
#toc-container ul ul,
#toc-container ul ul ul {
    list-style-type: none !important;
    list-style: none !important;
    padding: 0;
    margin: 0;
}

#toc-list-container > ul {
    margin-top: 10px;
    counter-reset: toc-counter;
}

#toc-container li {
    margin: 0;
    padding: 0;
    width: 100%;
    position: relative;
    list-style: none !important;
}

#toc-list-container > ul > li {
    counter-increment: toc-counter;
}

/* Liens TOC */
#toc-container a {
    display: block;
    padding: 8px 12px 8px 40px;
    margin: 2px 0;
    color: var(--pico-text-color, #555);
    text-decoration: none;
    font-size: 0.9rem;
    line-height: 1.4;
    border-radius: 6px;
    transition: all 0.2s ease;
    position: relative;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Numérotation premier niveau */
#toc-list-container > ul > li > a::before {
    content: counter(toc-counter) ".";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-weight: 700;
    color: var(--pico-primary, #2563eb);
    font-size: 0.95rem;
    min-width: 24px;
}

/* Sous-listes (H3) */
#toc-container ul ul {
    margin-left: 20px;
    margin-top: 4px;
    border-left: 2px solid rgba(0, 0, 0, 0.1);
    padding-left: 8px;
    counter-reset: toc-subcounter;
}

#toc-container ul ul li {
    counter-increment: toc-subcounter;
}

#toc-container ul ul a {
    font-size: 0.85rem;
    padding: 6px 10px 6px 40px;
}

#toc-container ul ul a::before {
    content: counter(toc-counter) "." counter(toc-subcounter);
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-weight: 600;
    color: var(--pico-primary, #2563eb);
    font-size: 0.85rem;
    min-width: 24px;
}

/* Barre indicateur */
#toc-container a::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: var(--pico-primary, #2563eb);
    border-radius: 2px;
    transition: height 0.2s ease;
}

/* États hover et actif */
#toc-container a:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--pico-primary, #2563eb);
}

#toc-container a:hover::after {
    height: 60%;
}

#toc-container a.active {
    background: var(--pico-primary, #2563eb);
    color: white;
    font-weight: 600;
}

#toc-container a.active::before {
    color: white;
    font-weight: 800;
}

#toc-container a.active::after {
    height: 80%;
    background: white;
}

#toc-container a.focus-visible {
    outline: 2px solid var(--pico-primary, #2563eb);
    outline-offset: 2px;
}

/* ========================================
   MODE SOMBRE
======================================== */

:root[data-theme="dark"] #toc-container {
    background: #1a1a1a;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

:root[data-theme="dark"] #toc-container a {
    color: #e0e0e0;
}

:root[data-theme="dark"] #toc-container a:hover {
    background: rgba(255, 255, 255, 0.1);
}

:root[data-theme="dark"] #toc-container ul ul {
    border-left-color: rgba(255, 255, 255, 0.2);
}

:root[data-theme="dark"] #toc-scroll-bottom {
    background: var(--pico-primary, #60a5fa) !important;
}

:root[data-theme="dark"] #toc-scroll-bottom:hover {
    background: var(--pico-primary-hover, #3b82f6) !important;
}

:root[data-theme="dark"] #toc-container a.active {
    background: var(--pico-primary, #60a5fa);
    color: #000;
}

:root[data-theme="dark"] #toc-container a.active::before {
    color: #000;
}

/* ========================================
   RESPONSIVE - TABLETTES (≤ 992px)
======================================== */

@media (max-width: 992px) {
    .article-wrapper,
    .article-wrapper:has(#toc-container) {
        grid-template-columns: 1fr 280px;
        gap: 30px;
    }
    
    #toc-container {
        top: 100px;
        max-height: calc(100vh - 140px);
    }
    
    #backToTop {
        right: 40px;
        bottom: 25px;
    }
}

/* ========================================
   RESPONSIVE - MOBILE (≤ 768px)
======================================== */

@media (max-width: 768px) {
    /* Layout article en une colonne */
    .article-wrapper,
    .article-wrapper:has(#toc-container) {
        grid-template-columns: 1fr !important;
        gap: 20px;
        padding: 0 15px;
    }
    
    /* Header navigation */
    header nav {
        flex-direction: column;
        gap: 1rem;
    }
    
    header nav ul {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }
    
    /* Back to top repositionné */
    #backToTop {
        right: 20px;
        bottom: 90px;
    }
    
    /* TOC Mobile */
    #toc-container {
        position: fixed;
        bottom: 60px;
        left: 20px;
        right: 20px;
        width: auto;
        max-height: 70vh;
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transform: translateY(calc(100% + 20px));
        transition: opacity 0.3s, transform 0.3s, visibility 0s 0.3s;
    }
    
    #toc-container.toc-mobile-visible {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        transition: opacity 0.3s, transform 0.3s;
    }
    
    /* Post meta plus compact */
    .post-meta {
        font-size: 0.85rem;
        gap: 0.4rem;
    }
    
    .post-meta .icon {
        width: 14px;
        height: 14px;
    }
}

/* ========================================
   RESPONSIVE - PETITS MOBILES (≤ 480px)
======================================== */

@media (max-width: 480px) {
    /* Padding réduit */
    .article-wrapper {
        padding: 0 12px;
        gap: 15px;
    }
    
    /* Header titre plus petit */
    header nav ul li hgroup h2 a {
        font-size: 1em;
    }
    
    header nav ul li hgroup h2 a .rocket-emoji {
        font-size: 1.2em;
        margin-right: 0.3rem;
    }
    
    /* Post meta encore plus compact */
    .post-meta {
        font-size: 0.8rem;
        gap: 0.3rem;
    }
    
    .post-meta .icon {
        width: 12px;
        height: 12px;
    }
    
    /* Share links centré */
    .share-links {
        justify-content: center;
        flex-direction: column;
        align-items: center;
    }
    
    .share-links p {
        width: 100%;
        text-align: center;
        margin-bottom: 0.5rem;
    }
    
    /* Tags plus petits */
    .tag {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    
    /* Back to top plus petit */
    #backToTop {
        padding: 4px 12px;
        font-size: 18px;
        bottom: 80px;
        right: 15px;
    }
    
    /* TOC mobile optimisée */
    #toc-container {
        left: 10px;
        right: 10px;
        bottom: 50px;
        padding: 15px;
    }
    
    #toc-header h2 {
        font-size: 1rem;
    }
    
    #toc-scroll-bottom {
        min-width: 32px;
        height: 32px;
        padding: 6px !important;
    }
    
    #toc-container a {
        font-size: 0.85rem;
        padding: 6px 10px 6px 36px;
    }
    
    #toc-container ul ul a {
        font-size: 0.8rem;
        padding: 5px 8px 5px 36px;
    }
}

/* ========================================
   PRINT
======================================== */

@media print {
    #toc-container,
    #backToTop,
    #toc-toggle,
    .share-links {
        display: none !important;
    }
    
    .article-wrapper,
    .article-wrapper:has(#toc-container) {
        grid-template-columns: 1fr !important;
    }
}

/* ========================================
   SURBRILLANCE RECHERCHE
======================================== */

mark.search-highlight {
    background-color: #fff3cd;
    color: inherit;
    padding: 0 0.1em;
}

mark.search-highlight-main {
    background-color: #ffe066; /* Jaune plus marqué pour le match 100% */
    color: inherit;
    padding: 0 0.1em;
}

/* ========================================
   COPIE DES BLOCS DE CODE
======================================== */

.code-block-wrapper {
    position: relative;
}

.copy-code-btn {
    position: absolute;
    top: 0.4rem;
    right: 0.6rem;
    padding: 0.15rem 0.55rem;
    font-size: 0.75rem;
    border-radius: 0.25rem;
    border: none;
    background: var(--pico-muted-border-color, #ddd);
    color: inherit;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s, background-color 0.15s;
    z-index: 2;
}

.code-block-wrapper:hover .copy-code-btn {
    opacity: 1;
}

.copy-code-btn.copied {
    background: #22c55e;
    color: #fff;
}