/* ============================================================
   RAPPORT LAYOUT
   ============================================================ */

/* --- Layout: sidebar + content --- */
.rapport-layout {
    display: flex;
    min-height: calc(100vh - var(--header-h));
    padding-top: var(--header-h);
}

/* --- Sidebar --- */
.rapport-sidebar {
    position: sticky;
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
    width: 280px;
    min-width: 280px;
    overflow-y: auto;
    padding: 2rem 1.25rem;
    border-right: 1px solid var(--color-border);
    background: var(--color-bg-card);
}

.toc-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-heading);
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-border);
}

.toc-title a {
    color: inherit;
    text-decoration: none;
}

.toc-title a:hover {
    color: var(--color-accent);
}

.rapport-toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.rapport-toc li {
    margin-bottom: 0.15rem;
}

.rapport-toc li a {
    display: block;
    padding: 0.4rem 0.6rem;
    font-size: 0.82rem;
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: 4px;
    line-height: 1.4;
    transition: color 0.2s, background 0.2s;
}

.rapport-toc li a:hover {
    color: var(--color-heading);
    background: rgba(255, 255, 255, 0.04);
}

.rapport-toc li.active a {
    color: var(--color-accent);
    background: rgba(59, 130, 246, 0.08);
    font-weight: 500;
}

/* --- Main content area --- */
.rapport-content {
    flex: 1;
    max-width: 800px;
    margin: 0 auto;
    padding: 2.5rem 2rem 4rem;
    min-width: 0;
    overflow-x: hidden;
}

/* --- Google Docs content overrides --- */
.gdocs-content {
    color: var(--color-text);
    line-height: 1.75;
    font-size: 0.95rem;
    overflow-wrap: break-word;
    word-wrap: break-word;
    overflow-x: hidden;
}

/* Force all Google Docs elements to respect container width */
.gdocs-content * {
    max-width: 100% !important;
    box-sizing: border-box;
}

.gdocs-content img {
    height: auto !important;
    display: block;
    margin: 1.5rem auto;
}

/* Force image wrapper spans to block layout (Google Docs uses inline-block) */
.gdocs-content p > span[style*="display: inline-block"],
.gdocs-content h2 > span[style*="display: inline-block"],
.gdocs-content h3 > span[style*="display: inline-block"],
.gdocs-content span[style*="overflow: hidden"][style*="display: inline-block"] {
    display: block !important;
    margin: 1.5rem auto !important;
    float: none !important;
    height: auto !important;
    width: auto !important;
}

.gdocs-content table {
    table-layout: fixed;
}

/* Override Google Docs backgrounds to dark theme */
.gdocs-content,
.gdocs-content *,
.gdocs-content p,
.gdocs-content span,
.gdocs-content li,
.gdocs-content td,
.gdocs-content th,
.gdocs-content div,
.gdocs-content h1,
.gdocs-content h2,
.gdocs-content h3,
.gdocs-content h4 {
    background-color: transparent !important;
    background: transparent !important;
}

/* Override text color - Google Docs uses #000 */
.gdocs-content p,
.gdocs-content p span,
.gdocs-content li,
.gdocs-content li span,
.gdocs-content td,
.gdocs-content td span {
    color: var(--color-text) !important;
}

/* Force all heading colors regardless of Google Docs classes */
.gdocs-content h1,
.gdocs-content h1 *,
.gdocs-content h2,
.gdocs-content h2 *,
.gdocs-content h3,
.gdocs-content h3 *,
.gdocs-content h4,
.gdocs-content h4 * {
    color: var(--color-heading) !important;
}

.gdocs-content h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--color-heading) !important;
    margin: 2.5rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.gdocs-content h2 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--color-heading) !important;
    margin: 2rem 0 0.75rem;
}

.gdocs-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-heading) !important;
    margin: 1.5rem 0 0.5rem;
}
}

.gdocs-content p {
    margin-bottom: 0.85rem;
}

.gdocs-content a {
    color: var(--color-accent) !important;
    text-decoration: underline;
    text-decoration-color: rgba(59, 130, 246, 0.3);
    text-underline-offset: 2px;
}

.gdocs-content a:hover {
    text-decoration-color: var(--color-accent);
}

.gdocs-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 1rem 0;
}

.gdocs-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.85rem;
}

.gdocs-content table td,
.gdocs-content table th {
    border: 1px solid var(--color-border) !important;
    padding: 0.5rem 0.75rem;
}

.gdocs-content table th {
    background: rgba(255, 255, 255, 0.04) !important;
    font-weight: 600;
}

.gdocs-content sup {
    color: var(--color-accent) !important;
}

.gdocs-content sup a {
    text-decoration: none;
}

/* Footnotes section */
.gdocs-content hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 2rem 0;
}

/* --- Chapter navigation --- */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--color-border);
}

.chapter-nav a {
    font-size: 0.9rem;
    color: var(--color-accent);
    text-decoration: none;
    padding: 0.5rem 0;
    transition: opacity 0.2s;
}

.chapter-nav a:hover {
    opacity: 0.8;
}

.chapter-nav .nav-next {
    margin-left: auto;
    text-align: right;
}

/* --- Index page --- */
.rapport-index {
    max-width: 600px;
    margin: 0 auto;
}

.chapter-list {
    padding-left: 1.25rem;
    margin: 0 0 2rem;
}

.chapter-list li {
    margin-bottom: 0.5rem;
}

.chapter-list a {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 1rem;
    transition: color 0.2s;
}

.chapter-list a:hover {
    color: var(--color-accent);
}

.rapport-download {
    text-align: center;
    margin: 2rem 0;
}

/* --- Mobile responsive --- */

/* Topbar for mobile TOC toggle */
.rapport-topbar {
    display: none;
    position: sticky;
    top: var(--header-h);
    z-index: 100;
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    padding: 0.6rem 1rem;
}

.toc-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.2s, border-color 0.2s;
}

.toc-toggle:hover {
    color: var(--color-heading);
    border-color: var(--color-accent);
}

@media (max-width: 900px) {
    .rapport-topbar {
        display: block;
    }

    .rapport-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        border-right: 1px solid var(--color-border);
        padding-top: calc(var(--header-h) + 1rem);
    }

    .rapport-sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 999;
    }

    .sidebar-overlay.is-visible {
        display: block;
    }

    .rapport-content {
        padding: 1.5rem 1rem 3rem;
    }
}
