/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-bg: #ffffff;
    --color-surface: #f6f8fa;
    --color-border: #d0d7de;
    --color-text: #1f2328;
    --color-text-secondary: #656d76;
    --color-link: #0969da;
    --color-link-hover: #0550ae;
    --color-accent: #0550ae;
    --color-code-bg: #f6f8fa;
    --color-code-border: #d0d7de;
    --max-width: 1280px;
    --sidebar-width: 240px;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
                 Roboto, Helvetica, Arial, sans-serif;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--color-link); text-decoration: none; }
a:hover { color: var(--color-link-hover); text-decoration: underline; }

/* ===== Layout ===== */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    width: 100%;
}

/* ===== Header ===== */
.site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}

.site-nav a {
    margin-left: 1.5rem;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
}

.site-nav a:hover { color: var(--color-link); }

/* ===== Main ===== */
.site-main {
    flex: 1;
    padding: 2rem 0;
}

/* ===== Footer ===== */
.site-footer {
    border-top: 1px solid var(--color-border);
    padding: 1.5rem 0;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
}

/* ===== Doc Page ===== */
.doc-page {}

.doc-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}

.doc-breadcrumb {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

.doc-breadcrumb .current { color: var(--color-text); font-weight: 600; }
.doc-breadcrumb .sep { margin: 0 0.35rem; }

.doc-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.doc-meta {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}

.btn {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    transition: background 0.15s;
}

.btn:hover {
    background: #e9ecef;
    text-decoration: none;
}

.btn-sm { font-size: 0.8rem; padding: 0.25rem 0.6rem; }

/* ===== Doc Body with Sidebar ===== */
.doc-body {
    display: flex;
    gap: 2.5rem;
    align-items: flex-start;
}

.doc-body.has-sidebar .doc-content {
    flex: 1;
    min-width: 0;
}

/* ===== TOC Sidebar ===== */
.doc-toc {
    width: var(--sidebar-width);
    flex-shrink: 0;
    position: sticky;
    top: 5rem;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
}

.toc-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

.toc-list {
    list-style: none;
    border-left: 2px solid var(--color-border);
}

.toc-list li {
    padding: 0.15rem 0 0.15rem 0.75rem;
}

.toc-list a {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toc-list a:hover {
    color: var(--color-link);
    text-decoration: none;
}

.toc-level-3 { padding-left: 1.25rem; }
.toc-level-4 { padding-left: 1.75rem; }

/* ===== Doc Content (rendered Markdown) ===== */
.doc-content {
    max-width: 100%;
    word-wrap: break-word;
}

/* Headings */
.doc-content h1 {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.doc-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 2rem 0 0.75rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--color-border);
}

.doc-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 1.5rem 0 0.5rem;
}

.doc-content h4 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 1.25rem 0 0.5rem;
}

.doc-content h5, .doc-content h6 {
    font-size: 1rem;
    font-weight: 600;
    margin: 1rem 0 0.4rem;
}

/* Heading anchor */
.doc-content .heading-anchor {
    color: var(--color-link);
    opacity: 0;
    margin-left: 0.3rem;
    font-weight: normal;
    text-decoration: none;
}

.doc-content h2:hover .heading-anchor,
.doc-content h3:hover .heading-anchor,
.doc-content h4:hover .heading-anchor {
    opacity: 1;
}

/* Paragraphs */
.doc-content p {
    margin: 0 0 1rem;
}

/* Links */
.doc-content a {
    color: var(--color-link);
    text-decoration: none;
}

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

/* Lists */
.doc-content ul, .doc-content ol {
    margin: 0 0 1rem;
    padding-left: 2rem;
}

.doc-content li { margin-bottom: 0.25rem; }
.doc-content li > ul, .doc-content li > ol { margin-top: 0.25rem; margin-bottom: 0; }

/* Task lists */
.doc-content ul.task-list {
    list-style: none;
    padding-left: 1.25rem;
}
.doc-content .task-list-item input[type="checkbox"] {
    margin-right: 0.5rem;
}

/* Code */
.doc-content code {
    background: var(--color-code-bg);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 85%;
    font-family: "SFMono-Regular", "Consolas", "Liberation Mono", "Menlo", monospace;
}

.doc-content pre {
    background: var(--color-code-bg);
    border: 1px solid var(--color-code-border);
    border-radius: 6px;
    padding: 1rem;
    overflow-x: auto;
    margin: 0 0 1rem;
    line-height: 1.45;
}

.doc-content pre code {
    background: none;
    padding: 0;
    font-size: 100%;
    border-radius: 0;
}

/* Blockquote */
.doc-content blockquote {
    border-left: 4px solid var(--color-border);
    padding: 0.5rem 1rem;
    margin: 0 0 1rem;
    color: var(--color-text-secondary);
    background: var(--color-surface);
    border-radius: 0 6px 6px 0;
}

.doc-content blockquote p:last-child { margin-bottom: 0; }

/* Tables */
.doc-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0 0 1rem;
    overflow-x: auto;
    display: block;
}

.doc-content th, .doc-content td {
    border: 1px solid var(--color-border);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.doc-content th {
    background: var(--color-surface);
    font-weight: 600;
}

.doc-content tr:nth-child(even) {
    background: var(--color-surface);
}

/* Horizontal rule */
.doc-content hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 1.5rem 0;
}

/* Images */
.doc-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

/* Del (strikethrough) */
.doc-content del { color: var(--color-text-secondary); }

/* ===== Error Page ===== */
.doc-error {
    text-align: center;
    padding: 4rem 1rem;
}

.doc-error h1 { font-size: 3rem; border: none; }
.doc-error p { color: var(--color-text-secondary); margin-top: 1rem; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .doc-body { flex-direction: column; }

    .doc-toc {
        width: 100%;
        position: static;
        max-height: none;
        margin-bottom: 1.5rem;
        padding: 1rem;
        background: var(--color-surface);
        border-radius: 6px;
        border: 1px solid var(--color-border);
    }

    .toc-list {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem 1rem;
        border-left: none;
        padding-left: 0;
    }

    .toc-list li { padding: 0; }
    .toc-level-3, .toc-level-4 { padding-left: 0; }
}

@media (max-width: 600px) {
    .doc-toolbar { flex-direction: column; align-items: flex-start; }
    .doc-content h1 { font-size: 1.5rem; }
    .doc-content h2 { font-size: 1.25rem; }
}
