:root {
    --primary: #9d86ff;
    --primary-light: #f3f0ff;
    --secondary: #86b6ff;
    --light: #f8f9fa;
    --dark: #343a40;
    --gray: #6c757d;
    --border-radius: 8px;
    --box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    line-height: 1.6;
    color: var(--dark);
    background-color: #fefefe;
    overflow-y: scroll;
    /* Force la barre de défilement pour éviter les sauts */
}

/* Header fixe mais sans perturber le layout */
header {
    background: white;
    padding: 1rem 0;
    text-align: center;
    box-shadow: var(--box-shadow);
    position: relative;
    z-index: 10;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.container a {
    text-decoration: none;
    color: var(--primary);
}

header h1 {
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--gray);
    font-size: 0.9rem;
}

/* Search Bar (sticky mais sans décalage) */
.search-container {
    position: sticky;
    top: 0;
    background: white;
    padding: 1rem 0;
    box-shadow: var(--box-shadow);
    z-index: 9;
    margin-bottom: 1rem;
}

#search {
    width: 90%;
    max-width: 600px;
    padding: 0.75rem 1rem;
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius);
    font-size: 1rem;
    margin: 0 auto;
    display: block;
}

/* Layout principal avec flexbox stable */
.main-layout {
    display: flex;
    gap: 2rem;
    margin: 1rem 0;
    position: relative;
    /* Évite les conflits avec les éléments sticky */
}

/* Table des matières (TOC) */
#toc {
    flex: 0 0 280px;
    background: white;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    height: fit-content;
    position: sticky;
    top: 80px;
    /* Position sous la barre de recherche */
    align-self: flex-start;
    overflow-y: auto;
    max-height: calc(100vh - 100px);
    /* Évite le débordement */
}

#toc h2 {
    color: var(--primary);
    font-size: 1.2rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 0.5rem;
}

#toc ul {
    list-style: none;
}

#toc li {
    margin-bottom: 0.5rem;
}

#toc a {
    color: var(--gray);
    text-decoration: none;
    display: block;
    padding: 0.3rem 0;
    border-radius: 4px;
    transition: var(--transition);
    font-size: 0.9rem;
}

#toc a:hover {
    color: var(--primary);
    background-color: var(--primary-light);
}

/* Contenu principal */
.content {
    flex: 1;
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    min-width: 0;
    /* Évite le débordement sur mobile */
}

.content h1 {
    color: var(--primary);
    font-size: 2rem;
    margin: 1.5rem 0 1rem;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 0.5rem;
}

.content h2 {
    color: var(--secondary);
    font-size: 1.5rem;
    margin: 1.2rem 0 0.8rem;
}

.content h3 {
    color: var(--dark);
    font-size: 1.2rem;
    margin: 1rem 0 0.6rem;
}

.content p {
    margin-bottom: 1rem;
    line-height: 1.7;
}

.content a {
    color: var(--primary);
    text-decoration: none;
}

.content a:hover {
    text-decoration: underline;
}

.content pre {
    background: #f5f5f5;
    padding: 1rem;
    border-radius: var(--border-radius);
    overflow-x: auto;
    margin: 1rem 0;
    font-size: 0.9rem;
    border: 1px solid #e0e0e0;
}

.content code {
    font-family: 'Courier New', monospace;
    background: #f5f5f5;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Autocomplete (corrigé pour éviter les décalages) */
.autocomplete-items {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    margin: 0 auto;
}

.autocomplete-items div {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

.autocomplete-items div:hover {
    background: var(--primary-light);
}

/* Responsive (sans décalage) */
@media (max-width: 992px) {
    .main-layout {
        flex-direction: column;
    }

    #toc {
        position: static;
        width: 100%;
        margin-bottom: 1rem;
    }

    .autocomplete-items {
        width: 95%;
        top: 120px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 0.5rem;
    }

    .content {
        padding: 1rem;
    }

    #search {
        width: 95%;
    }
}

/* État de chargement */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--gray);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    margin: 0 0.2rem;
}

.badge-primary {
    background: var(--primary);
    color: white;
}