:root {
    /* GitBook Dark Theme Variables */
    --bg-main: #0E1117;
    --bg-sidebar: #161B22;
    --bg-hover: #21262D;
    --bg-search: #010409;
    --text-main: #C9D1D9;
    --text-muted: #8B949E;
    --text-heading: #F0F6FC;
    --text-active: #58A6FF;
    --border-color: #30363D;
    --sidebar-width: 300px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
}

.gitbook-layout {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--text-heading);
}

.logo-icon {
    background: linear-gradient(135deg, #10B981, #3B82F6);
    color: white;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 14px;
}

.search-bar {
    background-color: var(--bg-search);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    cursor: text;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

/* Scrollbar styling */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

ul {
    list-style: none;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.75rem;
    color: var(--text-main);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background-color 0.2s, color 0.2s;
    margin-bottom: 2px;
}

.nav-link:hover {
    background-color: var(--bg-hover);
}

.nav-link.active {
    color: var(--text-active);
    background-color: var(--bg-hover);
    font-weight: 500;
}

.nav-link .icon {
    margin-right: 0.75rem;
    font-size: 1.1rem;
    display: inline-block;
    width: 20px;
    text-align: center;
}

.nav-group {
    margin-top: 1.5rem;
}

.group-title {
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

.group-items {
    margin-left: 0.5rem;
}

.nav-link .arrow {
    margin-left: auto;
    color: var(--text-muted);
}

.sub-items {
    list-style: none;
    padding-left: 0;
    margin: 4px 0 8px 30px;
    border-left: 1px solid var(--border-color);
}

.sub-items .nav-link {
    font-size: 0.85rem;
    padding: 6px 12px;
    color: var(--text-muted);
}

.sub-items .nav-link.active {
    color: var(--text-active);
    font-weight: 500;
}

/* Main Content */
.content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background-color: var(--bg-main);
}

.content-header {
    display: none;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.content-header p.text-lg {
    color: var(--primary);
    font-weight: 500;
    opacity: 0.9;
}

.menu-toggle {
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    border-radius: 4px;
}

.menu-toggle:hover {
    background-color: var(--bg-hover);
}

.markdown-body {
    max-width: 800px;
    margin: 0 auto;
    padding: 3rem 2rem;
    width: 100%;
}

.markdown-body h1 {
    font-size: 2.25rem;
    color: var(--text-heading);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 700;
}

.icon-lg {
    font-size: 2.5rem;
}

.description {
    font-size: 1.125rem;
    color: var(--text-main);
    max-width: 650px;
    margin-bottom: 3rem;
}

/* Footer / Prev-Next Links */
.page-footer {
    margin-top: 4rem;
    border-top: 1px solid var(--border-color);
    padding-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.next-link-container {
    display: flex;
    justify-content: flex-end;
}

.next-link {
    display: block;
    text-decoration: none;
    text-align: right;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    transition: all 0.2s;
    min-width: 200px;
}

.next-link:hover {
    border-color: var(--text-active);
}

.next-link .link-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.next-link .link-title {
    color: var(--text-active);
    font-weight: 500;
    font-size: 1.1rem;
}

.last-updated {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .content-header {
        display: flex;
    }

    .markdown-body {
        padding: 2rem 1.5rem;
    }
}

/* Custom Search Additions */
.search-container {
    position: relative;
}

.search-bar {
    background-color: var(--bg-search);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
}

.search-bar input {
    background: transparent;
    border: none;
    color: var(--text-main);
    width: 100%;
    outline: none;
    font-size: 0.875rem;
    font-family: inherit;
}

.search-results {
    display: none;
    position: absolute;
    top: 110%;
    left: 0;
    width: 100%;
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
}

.search-item {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.search-item:last-child {
    border-bottom: none;
}

.search-item:hover {
    background-color: var(--bg-hover);
}

.search-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-active);
    margin-bottom: 0.2rem;
}

.search-snippet {
    font-size: 0.75rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-snippet mark {
    background-color: rgba(88, 166, 255, 0.3);
    color: white;
    font-weight: bold;
    padding: 0 2px;
    border-radius: 2px;
}

.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 1.5rem 0;
}

.markdown-body p {
    margin-bottom: 1rem;
}

.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--text-heading);
    font-weight: 600;
}

.markdown-body pre {
    background-color: var(--bg-search);
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 1.5rem;
}

.page-scroll-container {
    height: 100%;
    overflow-y: auto;
    flex: 1;
}

/* =========================================
   GITBOOK HTML CLEANUP & FIXES 
   ========================================= */

/* 1. Prevent SVGs from expanding to giant sizes */
.markdown-body svg {
    width: 1.2em !important;
    height: 1.2em !important;
    max-width: 100%;
    display: inline-block;
    vertical-align: middle;
}

/* 2. Hide Gitbook's internal UI buttons like 'Ask' or 'Assistant' */
.markdown-body header button {
    display: none !important;
}

/* 3. Hide Gitbook's native anchor '#' elements which we replace dynamically */
.markdown-body .hash {
    display: none !important;
}

/* 4. Custom blue-dot lists override for Native & GitBook */
.markdown-body ul,
.markdown-body ol {
    margin-bottom: 1.5rem;
}

.markdown-body ul {
    list-style: none;
    /* Remove native to use pseudo-element */
    padding-left: 0;
}

.markdown-body ol {
    padding-left: 1.5rem;
    list-style-type: decimal;
}

.markdown-body ul li {
    position: relative;
    padding-left: 1.25rem;
    margin-bottom: 0.5rem;
}

.markdown-body ul li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.6em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--text-active);
}

.markdown-body li.flex {
    display: block !important;
    /* Cancel Tailwind flex wrapper */
}

.markdown-body li.flex>div:first-child {
    display: none !important;
    /* Hide legacy GitBook bullet string hack */
}

/* 5. Fix text and background artifacts from Tailwind */
.markdown-body .text-tint {
    color: var(--text-main) !important;
    /* Re-illuminate generic gray text */
}

.markdown-body .text-tint-strong {
    color: var(--text-heading) !important;
}

.markdown-body .bg-tint-base {
    background-color: transparent !important;
}

.markdown-body .border-tint-subtle {
    border-color: var(--border-color) !important;
}

/* 6. Clean up summary/dropdown chevrons and hide anchor '#' */
.markdown-body details summary {
    position: relative;
    padding-left: 2rem;
    list-style: none;
    /* Hide default triangle */
}

.markdown-body details summary::-webkit-details-marker {
    display: none;
}

/* Re-position the legitimate chevron icon */
.markdown-body details summary>svg:first-child {
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-active) !important;
}

.markdown-body details[open] summary>svg:first-child {
    transform: translateY(-50%) rotate(90deg);
}

/* Hide GitBook's overlapping anchor hashtags completely */
.markdown-body details summary>a,
.markdown-body details summary a[aria-label="Direct link to heading"] {
    display: none !important;
}

/* 7. Heading Scale Homestead */
.markdown-body h1 {
    font-size: 2.25rem !important;
    font-weight: 700 !important;
    margin-bottom: 1.5rem !important;
}

.markdown-body h2 {
    font-size: 1.75rem !important;
    font-weight: 600 !important;
    margin-top: 2rem !important;
    margin-bottom: 1rem !important;
}

.markdown-body h3 {
    font-size: 1.25rem !important;
    font-weight: 600 !important;
    margin-top: 1.5rem !important;
    margin-bottom: 0.75rem !important;
}

/* =========================================
   MARKDOWN ELEMENTS DESIGN AESTHETICS
   ========================================= */

/* Blockquotes (Citations) */
.markdown-body blockquote {
    border-left: 3px solid var(--text-active);
    /* Blue accent like references */
    margin: 1.5rem 0;
    padding-left: 1.25rem;
    color: var(--text-muted);
}

.markdown-body blockquote p {
    margin-bottom: 0;
}

/* Inline Code Elements */
.markdown-body code {
    background-color: var(--bg-hover) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px !important;
    padding: 0.2rem 0.4rem !important;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace !important;
    font-size: 0.85em !important;
    color: var(--text-heading) !important;
}

.markdown-body pre code {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
}

/* Info Bubbles (Hint / info class) */
.markdown-body .hint,
.markdown-body .info {
    background-color: rgba(255, 255, 255, 0.04) !important;
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
    border-radius: 8px !important;
    display: flex !important;
    align-items: flex-start;
    margin: 1.5rem 0;
    font-size: 0.95rem;
    box-shadow: none !important;
}

/* GitBook structure */
.markdown-body .hint>div:first-child {
    padding: 1rem 0 1rem 1rem !important;
    color: var(--text-muted) !important;
}

.markdown-body .hint>div:last-child {
    padding: 1rem !important;
    flex: 1;
}

/* Custom minimal info blocks */
.markdown-body .info {
    padding: 1rem 1rem 1rem 3.5rem !important;
    position: relative;
    color: var(--text-main);
}

.markdown-body .info::before {
    content: 'ⓘ';
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-weight: bold;
    font-family: inherit;
    font-size: 1.25rem;
}

.markdown-body .info p {
    margin: 0;
}

/* 8. Fix Original GitBook Footer (Previous/Next) */
.markdown-body>div.flex.flex-col.md\:flex-row.mt-6 {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.markdown-body>div.flex.flex-col.md\:flex-row.mt-6>a.flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    min-width: 200px;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none !important;
    background: transparent;
    transition: border-color 0.2s ease, transform 0.2s ease;
    gap: 1rem;
}

.markdown-body>div.flex.flex-col.md\:flex-row.mt-6>a.flex:hover {
    border-color: var(--text-active);
}

.markdown-body>div.flex.flex-col.md\:flex-row.mt-6>a.flex svg {
    color: white !important;
    transition: color 0.2s ease;
}

.markdown-body>div.flex.flex-col.md\:flex-row.mt-6>a.flex:hover svg {
    color: var(--text-active) !important;
}

.markdown-body>div.flex.flex-col.md\:flex-row.mt-6>a.flex-row-reverse {
    flex-direction: row-reverse;
}

.markdown-body>div.flex.flex-col.md\:flex-row.mt-6>a.flex>span.flex {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.markdown-body>div.flex.flex-col.md\:flex-row.mt-6>a.flex-row-reverse>span.flex {
    text-align: right;
}

.markdown-body>div.flex.flex-col.md\:flex-row.mt-6 .text-xs {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.markdown-body>div.flex.flex-col.md\:flex-row.mt-6 .text-tint-strong {
    color: var(--text-main);
    font-weight: 600;
}

/* 9. Fix Last Updated Layout */
.markdown-body>div.mx-auto.mt-6 {
    margin-top: 2rem;
    padding-bottom: 2rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* 10. Universal Typography Homogeneity */
.markdown-body,
.markdown-body *:not(code):not(pre):not(kbd) {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
}

/* 11. Custom Grid Cards for index categories (like Règlement Illégal) */
.markdown-body>div.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin: 2rem 0;
}

.markdown-body>div.grid>a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    color: var(--text-main);
    text-decoration: none !important;
    transition: transform 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.markdown-body>div.grid>a:hover {
    border-color: var(--text-active);
    background-color: rgba(255, 255, 255, 0.05);
    transform: translateY(-2px);
}

.markdown-body>div.grid>a svg {
    color: var(--text-muted);
    transition: color 0.2s ease, transform 0.2s ease;
}

.markdown-body>div.grid>a:hover svg {
    color: var(--text-active);
    transform: translateX(4px);
}

/* 12. Tabs Functionality */
[role="tablist"] {
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    margin-bottom: 1.5rem;
    padding-bottom: 0px;
}

[role="tab"] {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    transition: all 0.2s ease;
}

[role="tab"]:hover {
    background-color: var(--bg-hover);
    color: var(--text-main);
}

.active-tab button {
    color: var(--primary) !important;
    background-color: rgba(62, 168, 255, 0.1) !important;
    box-shadow: inset 0 -2px 0 var(--primary) !important;
    font-weight: 600;
}

/* 13. Mobile Responsiveness */
@media (max-width: 768px) {
    .markdown-body h1 {
        font-size: 1.8rem !important;
        margin-bottom: 1rem !important;
    }

    .markdown-body h2 {
        font-size: 1.5rem !important;
        margin-top: 1.5rem !important;
    }

    .markdown-body h3 {
        font-size: 1.25rem !important;
    }

    .markdown-body>div.grid {
        grid-template-columns: 1fr;
    }
}

/* 14. Hint Boxes (Alerts) */
.hint p {
    margin-bottom: 0 !important;
    margin-top: 0 !important;
}

.hint {
    align-items: center;
}

/* 15. Block redundant GitBook headings above Tabs */
.flex-col>h1:has(+ div [role='tablist']),
.flex-col>h2:has(+ div [role='tablist']),
.flex-col>h3:has(+ div [role='tablist']),
.flex-col>h4:has(+ div [role='tablist']) {
    display: none !important;
}

/* Custom Link Colorization */
.markdown-body p a,
.markdown-body li a,
.markdown-body .hint a {
    color: var(--text-active) !important;
    text-decoration: underline !important;
    text-decoration-color: rgba(88, 166, 255, 0.4) !important;
    text-underline-offset: 3px;
    transition: color 0.2s, text-decoration-color 0.2s;
}

.markdown-body p a:hover,
.markdown-body li a:hover,
.markdown-body .hint a:hover {
    color: #8cb4ff !important;
    /* Lighter blue */
    text-decoration-color: #8cb4ff !important;
}


/* MOBILE OVERLAY & CLOSE BUTTON */
.sidebar-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.logo {
    margin-bottom: 0 !important;
}

.close-sidebar {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
}

.close-sidebar:hover {
    color: var(--text-heading);
}

@media (max-width: 768px) {
    .sidebar {
        z-index: 200;
    }

    .close-sidebar {
        display: flex;
    }

    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 150;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .mobile-overlay.open {
        opacity: 1;
        visibility: visible;
    }
}


/* LEGAL DOCUMENTS STYLING */
.is-legal-doc {
    font-family: 'Inter', sans-serif;
}

.is-legal-doc p {
    text-align: justify;
    line-height: 1.8;
    color: var(--text-color);
    margin-bottom: 1.25rem;
}

.is-legal-doc h2 {
    color: var(--text-active);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-top: 2.5rem;
    font-weight: 700;
    font-size: 1.75rem;
}

.is-legal-doc h3 {
    color: var(--text-heading);
    font-size: 1.25rem;
    margin-top: 2rem;
    border-left: 4px solid var(--text-active);
    padding-left: 1rem;
    background: linear-gradient(to right, rgba(88, 166, 255, 0.1), transparent);
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    border-radius: 0 4px 4px 0;
}

.is-legal-doc p strong {
    color: var(--text-active);
    font-weight: 700;
}

.is-legal-doc table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    font-size: 0.9rem;
}

.is-legal-doc th {
    background-color: var(--bg-secondary);
    color: var(--text-heading);
    font-weight: 700;
    text-align: left;
    padding: 1rem;
    border: 1px solid var(--border-color);
}

.is-legal-doc td {
    padding: 1rem;
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.is-legal-doc tr:nth-child(even) td {
    background-color: rgba(255, 255, 255, 0.02);
}