/* =============================================================
   style.css — layout & components
   ============================================================= */

*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    font-size: 15.5px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none !important; }
}

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

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.icon {
    width: 20px; height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    display: block;
}

.kbd {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 2px 6px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    background: var(--bg-inset);
    color: var(--text-muted);
    white-space: nowrap;
}

/* ===================== Top bar ===================== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 650;
    color: var(--text);
    font-size: 15px;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 16px; }

.topbar-spacer { flex: 1; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.search-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 38px;
    padding: 0 10px 0 12px;
    min-width: 200px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-subtle);
    color: var(--text-subtle);
    cursor: pointer;
    font-size: 13.5px;
    transition: var(--transition);
}
.search-trigger:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.search-trigger .icon { width: 16px; height: 16px; }
.search-trigger-text { flex: 1; text-align: left; }

/* ===================== Layout ===================== */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
    align-items: start;
    max-width: 1600px;
    margin: 0 auto;
}

/* ===================== Sidebar ===================== */
.sidebar {
    position: sticky;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-subtle);
}
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 18px 12px 24px;
}
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-subtle);
}
.sidebar-footer code {
    font-family: var(--font-mono);
    background: var(--bg-inset);
    padding: 1px 5px;
    border-radius: 4px;
}

.nav-group { margin-bottom: 4px; }

.nav-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
}
.nav-group-header:hover { background: var(--bg-hover); }
.nav-group-header.active { color: var(--accent); }
.nav-group-header .nav-icon { width: 17px; height: 17px; color: var(--text-subtle); flex-shrink: 0; }
.nav-group-header.active .nav-icon { color: var(--accent); }
.nav-group-title { flex: 1; }
.nav-chevron {
    width: 15px; height: 15px;
    color: var(--text-subtle);
    transition: transform var(--transition);
}
.nav-group.collapsed .nav-chevron { transform: rotate(-90deg); }

.nav-sublist {
    list-style: none;
    margin: 2px 0 6px;
    padding: 0 0 0 12px;
    overflow: hidden;
    border-left: 1px solid var(--border);
    margin-left: 18px;
}
.nav-group.collapsed .nav-sublist { display: none; }

.nav-sublink {
    display: block;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13.5px;
    transition: var(--transition);
    border-left: 2px solid transparent;
    margin-left: -1px;
}
.nav-sublink:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-sublink.active {
    color: var(--accent);
    background: var(--bg-active);
    font-weight: 550;
    border-left-color: var(--accent);
}

.sidebar-skeleton { padding: 10px; }
.skeleton-line {
    height: 14px;
    border-radius: 6px;
    background: var(--bg-inset);
    margin-bottom: 14px;
    animation: pulse 1.4s ease-in-out infinite;
}
.skeleton-line:nth-child(2) { width: 70%; }
.skeleton-line:nth-child(3) { width: 85%; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* ===================== Content ===================== */
.content {
    min-width: 0;
    padding: 28px clamp(20px, 4vw, 56px) 96px;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-subtle);
    margin-bottom: 20px;
    max-width: var(--content-max);
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { color: var(--text-subtle); opacity: .6; }
.breadcrumb .current { color: var(--text); font-weight: 550; }

.doc { max-width: var(--content-max); }

/* Typography inside docs */
.doc h1, .doc h2, .doc h3, .doc h4 {
    line-height: 1.3;
    font-weight: 680;
    scroll-margin-top: calc(var(--topbar-h) + 20px);
    letter-spacing: -0.01em;
}
.doc h1 { font-size: 2rem; margin: 0 0 .6em; }
.doc h2 { font-size: 1.5rem; margin: 2em 0 .7em; padding-bottom: .35em; border-bottom: 1px solid var(--border); }
.doc h3 { font-size: 1.2rem; margin: 1.8em 0 .6em; }
.doc h4 { font-size: 1.02rem; margin: 1.5em 0 .5em; }

.doc p { margin: 0 0 1.1em; }
.doc strong { font-weight: 650; color: var(--text); }

.doc ul, .doc ol { margin: 0 0 1.1em; padding-left: 1.5em; }
.doc li { margin: .35em 0; }
.doc li::marker { color: var(--text-subtle); }

/* Anchor links on headings */
.heading-wrap { position: relative; }
.anchor-link {
    position: absolute;
    left: -1.4em;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    color: var(--text-subtle);
    font-weight: 400;
    transition: opacity var(--transition);
    padding: 0 .3em;
}
.heading-wrap:hover .anchor-link { opacity: 1; }
.anchor-link:hover { color: var(--accent); text-decoration: none; }

/* Inline code */
.doc :not(pre) > code {
    font-family: var(--font-mono);
    font-size: 0.86em;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    padding: 0.12em 0.4em;
    border-radius: 5px;
    color: var(--text);
    word-break: break-word;
}

/* ===================== Code blocks ===================== */
.code-block {
    position: relative;
    margin: 0 0 1.4em;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--code-bg);
    box-shadow: var(--shadow-sm);
}
.code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}
.code-lang {
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-subtle);
    font-size: 11px;
    font-weight: 600;
}
.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--bg-subtle);
    color: var(--text-muted);
    padding: 4px 9px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-hover); }
.copy-btn.copied { color: var(--success); border-color: var(--success-border); }
.copy-btn .icon { width: 14px; height: 14px; }

.code-block pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.65;
    tab-size: 4;
}
.code-block code { font-family: inherit; white-space: pre; }

/* ===================== Terminal ===================== */
.terminal {
    margin: 0 0 1.4em;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--terminal-bg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-strong);
}
.terminal-head {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.terminal-dot { width: 11px; height: 11px; border-radius: 50%; }
.terminal-dot.red { background: #ff5f56; }
.terminal-dot.yellow { background: #ffbd2e; }
.terminal-dot.green { background: #27c93f; }
.terminal-title {
    margin-left: 8px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
}
.terminal-copy {
    margin-left: auto;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.45);
    cursor: pointer;
    padding: 2px;
    display: inline-flex;
}
.terminal-copy:hover { color: rgba(255, 255, 255, 0.85); }
.terminal-copy .icon { width: 15px; height: 15px; }
.terminal-copy.copied { color: var(--success); }
.terminal-body {
    margin: 0;
    padding: 14px 16px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.7;
    color: var(--terminal-text);
}
.terminal-line { display: flex; gap: 10px; white-space: pre; }
.terminal-prompt { color: #27c93f; user-select: none; flex-shrink: 0; }

/* ===================== Notes / callouts ===================== */
.note {
    display: flex;
    gap: 12px;
    margin: 0 0 1.4em;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius);
    background: var(--bg-subtle);
}
.note-icon { flex-shrink: 0; margin-top: 1px; }
.note-icon .icon { width: 19px; height: 19px; }
.note-body { min-width: 0; }
.note-body > *:last-child { margin-bottom: 0; }
.note-title { font-weight: 650; margin-bottom: 3px; }

.note.info    { border-color: var(--info-border);    background: var(--info-bg); }
.note.info    .note-icon, .note.info .note-title    { color: var(--info); }
.note.tip     { border-color: var(--tip-border);     background: var(--tip-bg); }
.note.tip     .note-icon, .note.tip .note-title     { color: var(--tip); }
.note.success { border-color: var(--success-border); background: var(--success-bg); }
.note.success .note-icon, .note.success .note-title { color: var(--success); }
.note.warning { border-color: var(--warning-border); background: var(--warning-bg); }
.note.warning .note-icon, .note.warning .note-title { color: var(--warning); }
.note.danger  { border-color: var(--danger-border);  background: var(--danger-bg); }
.note.danger  .note-icon, .note.danger .note-title  { color: var(--danger); }

/* Callout card */
.callout {
    margin: 0 0 1.4em;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    box-shadow: var(--shadow-sm);
}
.callout-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 680;
    margin-bottom: 6px;
}
.callout-title .icon { width: 18px; height: 18px; color: var(--accent); }
.callout-body > *:last-child { margin-bottom: 0; }

/* ===================== Quote ===================== */
.doc blockquote,
.quote {
    margin: 0 0 1.4em;
    padding: 6px 18px;
    border-left: 3px solid var(--accent);
    color: var(--text-muted);
    font-style: italic;
}
.quote-cite { display: block; margin-top: 6px; font-style: normal; font-size: 13px; color: var(--text-subtle); }
.quote-cite::before { content: "— "; }

/* ===================== Divider ===================== */
.doc hr,
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2em 0;
}

/* ===================== Image ===================== */
.doc-figure { margin: 0 0 1.4em; text-align: center; }
.doc-figure img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.doc-figure figcaption {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-subtle);
}

/* ===================== Tables ===================== */
.table-wrap { overflow-x: auto; margin: 0 0 1.4em; border-radius: var(--radius); border: 1px solid var(--border); }
.doc table { border-collapse: collapse; width: 100%; font-size: 14px; }
.doc th, .doc td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.doc th { background: var(--bg-subtle); font-weight: 650; color: var(--text); white-space: nowrap; }
.doc tr:last-child td { border-bottom: none; }
.doc tbody tr:hover { background: var(--bg-hover); }

/* ===================== Checklist ===================== */
.checklist { list-style: none; padding: 0; margin: 0 0 1.4em; }
.checklist li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 0;
}
.checklist .check {
    flex-shrink: 0;
    width: 20px; height: 20px;
    border-radius: 6px;
    border: 1.5px solid var(--border-strong);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
    color: transparent;
}
.checklist li.checked .check {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}
.checklist li.checked .check .icon { width: 13px; height: 13px; stroke-width: 3; }
.checklist li.checked .check-text { color: var(--text-subtle); text-decoration: line-through; }
.check .icon { display: none; }
.checklist li.checked .check .icon { display: block; }

/* Markdown-produced task lists */
.md-tasklist { list-style: none; padding-left: 0; }
.md-tasklist li { display: flex; align-items: flex-start; gap: 8px; }
.md-tasklist input[type="checkbox"] { margin-top: 6px; accent-color: var(--accent); }
.md-task.checked { color: var(--text-subtle); text-decoration: line-through; }
.md-block > *:first-child { margin-top: 0; }

/* Highlighted search matches inside content */
mark, .hl {
    background: var(--mark);
    color: var(--mark-text);
    border-radius: 3px;
    padding: 0 2px;
}

/* ===================== Table of contents ===================== */
.toc {
    position: sticky;
    top: var(--topbar-h);
    max-height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    padding: 28px 16px 40px;
    font-size: 13px;
}
.toc-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-subtle);
    margin-bottom: 12px;
}
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list a {
    display: block;
    padding: 4px 10px;
    color: var(--text-muted);
    border-left: 2px solid var(--border);
    transition: var(--transition);
    line-height: 1.5;
}
.toc-list a:hover { color: var(--text); text-decoration: none; }
.toc-list a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 550; }
.toc-list .toc-h3 { padding-left: 22px; font-size: 12.5px; }
.toc-empty { color: var(--text-subtle); font-size: 12.5px; }

/* ===================== Pager (prev/next) ===================== */
.pager {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    max-width: var(--content-max);
    margin-top: 48px;
}
.pager-link {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-subtle);
    transition: var(--transition);
}
.pager-link:hover { border-color: var(--accent); background: var(--bg-hover); text-decoration: none; }
.pager-link.next { text-align: right; }
.pager-dir { font-size: 12px; color: var(--text-subtle); }
.pager-title { font-weight: 600; color: var(--text); }

/* ===================== Back to top ===================== */
.to-top {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 30;
    width: 42px; height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-muted);
    cursor: pointer;
    box-shadow: var(--shadow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: var(--transition);
}
.to-top.show { opacity: 1; visibility: visible; transform: translateY(0); }
.to-top:hover { color: var(--accent); border-color: var(--accent); }

/* ===================== Search modal ===================== */
.search-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    padding-top: 12vh;
    justify-content: center;
}
.search-modal.open { display: flex; }
.search-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    animation: fade var(--transition);
}
.search-panel {
    position: relative;
    width: min(640px, 92vw);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: pop var(--transition);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.98) translateY(-6px); } }

.search-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.search-input-row .icon { color: var(--text-subtle); flex-shrink: 0; }
.search-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    outline: none;
}
.search-results { overflow-y: auto; padding: 8px; }
.search-hint, .search-empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--text-subtle);
    font-size: 13.5px;
}
.search-result {
    display: block;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}
.search-result:hover, .search-result.active { background: var(--bg-active); text-decoration: none; }
.search-result-top {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-subtle);
    margin-bottom: 2px;
}
.search-result-cat { color: var(--accent); font-weight: 600; }
.search-result-title { font-weight: 600; color: var(--text); font-size: 14.5px; }
.search-result-snippet {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 3px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.search-count { padding: 6px 12px 10px; font-size: 12px; color: var(--text-subtle); }

/* ===================== Empty / error states ===================== */
.doc-state {
    max-width: var(--content-max);
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
}
.doc-state h2 { border: none; margin-top: 0; }
.doc-state .icon { width: 40px; height: 40px; margin: 0 auto 16px; color: var(--text-subtle); }

/* ===================== Responsive ===================== */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 44;
}

/* Hide TOC on medium screens */
@media (max-width: 1180px) {
    .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
    .toc { display: none; }
}

/* Mobile: sidebar becomes an overlay drawer */
@media (max-width: 860px) {
    .layout { grid-template-columns: minmax(0, 1fr); }
    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        bottom: 0;
        width: min(84vw, var(--sidebar-w));
        height: auto;
        z-index: 45;
        transform: translateX(-100%);
        transition: transform var(--transition);
        box-shadow: var(--shadow-lg);
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { display: block; }
    .search-trigger { min-width: 0; }
    .search-trigger-text, .search-trigger .kbd { display: none; }
}

@media (min-width: 861px) {
    /* On desktop, the toggle collapses the sidebar entirely */
    body.sidebar-collapsed .sidebar { display: none; }
    body.sidebar-collapsed .layout { grid-template-columns: minmax(0, 1fr) var(--toc-w); }
    body.sidebar-collapsed .layout.no-toc { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 560px) {
    body { font-size: 15px; }
    .brand-text { display: none; }
    .pager { grid-template-columns: 1fr; }
    .content { padding: 20px 16px 80px; }
    .doc h1 { font-size: 1.6rem; }
}
