/* General Styles */
body {
    font-family: sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    background-color: #f8f9fa;
    color: #333;
}

header {
    background-color: #343a40;
    color: #fff;
    padding: 1rem 2rem;
    text-align: center;
}

h1, h2, h3, h4 {
    color: #495057;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

h1 { font-size: 2.2em; }
h2 { font-size: 1.8em; border-bottom: 1px solid #dee2e6; padding-bottom: 0.3em; }
h3 { font-size: 1.4em; }
h4 { font-size: 1.1em; font-weight: bold; }

p {
    margin-bottom: 1em;
}

ul, ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

a {
    color: #007bff;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

strong {
    font-weight: bold;
}

/* Layout */
.container {
    display: flex;
    max-width: 1400px;
    margin: 20px auto;
    background-color: #fff;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

/* Sidebar Navigation */
#toc {
    width: 250px;
    padding: 20px;
    border-right: 1px solid #dee2e6;
    background-color: #f1f3f5;
    position: sticky;
    top: 0;
    height: 100vh; /* Make sidebar sticky */
    overflow-y: auto; /* Allow scrolling if content overflows */
}

#toc h2 {
    margin-top: 0;
    font-size: 1.5em;
    border-bottom: none;
}

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

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

#toc a {
    display: block;
    padding: 5px 10px;
    border-radius: 4px;
    color: #495057;
}

#toc a:hover,
#toc a.active { /* Style for active link (requires JS) */
    background-color: #e9ecef;
    color: #0056b3;
}

/* Main Content Area */
main {
    flex: 1; /* Take remaining space */
    padding: 20px 40px;
    overflow-x: hidden; /* Prevent horizontal scroll on main content */
}

main section {
    margin-bottom: 2em;
}

/* Code Blocks */
pre {
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 15px;
    overflow-x: auto; /* Enable horizontal scrolling for long code lines */
    margin-bottom: 1em;
}

code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.95em;
    background-color: #f1f3f5; /* Light background for inline code */
    padding: 0.2em 0.4em;
    border-radius: 3px;
}

pre code {
    background-color: transparent; /* Remove background for code inside pre */
    padding: 0;
    border-radius: 0;
    white-space: pre; /* Ensure whitespace is preserved */
}

/* Footer */
footer {
    text-align: center;
    margin-top: 2rem;
    padding: 1rem;
    font-size: 0.9em;
    color: #6c757d;
    border-top: 1px solid #dee2e6;
}

/* Printer-Friendly Styles */
@media print {
    body {
        font-family: serif; /* Use serif font for better print readability */
        background-color: #fff;
        color: #000;
        font-size: 12pt; /* Adjust base font size for print */
    }

    header, #toc, footer {
        display: none; /* Hide header, sidebar, and footer */
    }

    .container {
        display: block; /* Remove flex layout */
        max-width: none;
        margin: 0;
        box-shadow: none;
        border: none;
    }

    main {
        width: 100%;
        padding: 0;
        margin: 0;
        overflow: visible; /* Ensure all content is visible */
    }

    h1, h2, h3, h4 {
        color: #000;
        page-break-after: avoid; /* Try to keep headings with the content below */
    }

    a {
        color: #000;
        text-decoration: none; /* Remove underlines for cleaner print */
    }

    /* Optionally show URLs for links */
    /* a[href^="http"]:after {
        content: " (" attr(href) ")";
        font-size: 90%;
        color: #555;
    } */

    pre {
        background-color: #f8f8f8; /* Lighter background for print */
        border: 1px solid #ccc;
        page-break-inside: avoid; /* Try to keep code blocks on one page */
        white-space: pre-wrap; /* Wrap long lines in code blocks */
        word-wrap: break-word;
    }

    code {
        background-color: #f8f8f8;
        color: #000;
        font-size: 10pt; /* Slightly smaller code font for print */
    }

    pre code {
        background-color: transparent;
    }

    ul, ol {
        padding-left: 1.5em;
    }
}