/* axiomtrade-rs Documentation Theme */
/* Modern, accessible dual-theme design (light + dark) */

/*
    Color variables
    - Light defaults live in :root
    - Dark overrides for mdBook's dark themes (.navy/.ayu/.coal) and prefers-color-scheme
*/

:root {
    /* Brand */
    --brand: #4F46E5;
    --brand-strong: #4338CA;

    /* Base colors (light) */
    --bg-color: #FFFFFF;
    --bg-elev: #F8FAFC;
    --text-color: #0F172A;
    --text-muted: #475569;
    --border-color: #E5E7EB;
    --code-bg: #F3F4F6;

    /* Sidebar & nav */
    --sidebar-bg: #FFFFFF;
    --sidebar-text: #0F172A;
    --sidebar-active-bg: #EEF2FF;
    --sidebar-active-border: var(--brand);
    --nav-bg: #FFFFFF;
    /* Max width cap for resizable sidebar */
    --sidebar-max-width: 360px;

    /* Links */
    --link: var(--brand);
    --link-hover: #3730A3;

    /* Semantic */
    --success-color: #16A34A;
    --warning-color: #F59E0B;
    --error-color: #DC2626;
}

/* Dark theme overrides (mdBook sets class on <html>) */
html.navy, html.ayu, html.coal {
    --bg-color: #0B1220;
    --bg-elev: #0F172A;
    --text-color: #E5E7EB;
    --text-muted: #9CA3AF;
    --border-color: #1F2937;
    --code-bg: #0D1324;

    --sidebar-bg: #0D1426;
    --sidebar-text: #E5E7EB;
    --sidebar-active-bg: #111C36;
    --sidebar-active-border: #A5B4FC;
    --nav-bg: #0B1220;

    --link: #A5B4FC;
    --link-hover: #C7D2FE;
}

/* Respect system dark preference even if theme class not applied */
@media (prefers-color-scheme: dark) {
    html:not(.light):not(.rust) {
        --bg-color: #0B1220;
        --bg-elev: #0F172A;
        --text-color: #E5E7EB;
        --text-muted: #9CA3AF;
        --border-color: #1F2937;
        --code-bg: #0D1324;
        --sidebar-bg: #0D1426;
        --sidebar-text: #E5E7EB;
        --sidebar-active-bg: #111C36;
        --sidebar-active-border: #A5B4FC;
        --nav-bg: #0B1220;
        --link: #A5B4FC;
        --link-hover: #C7D2FE;
    }
}

/* Ensure the sidebar cannot exceed a sensible maximum */
:root {
    --sidebar-width: min(var(--sidebar-target-width), var(--sidebar-max-width), 80vw);
}

/* Base typography & layout */
body, .content {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif !important;
    line-height: 1.65;
    color: var(--text-color) !important;
    background-color: var(--bg-color);
}

.content {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

/* Headers */
h1 {
    color: var(--text-color) !important;
    font-size: 2.4rem;
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 1.25rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.6rem;
}

h2 {
    color: var(--text-color) !important;
    font-size: 1.75rem;
    font-weight: 650;
    margin-top: 2rem;
    margin-bottom: 0.9rem;
    border-left: 4px solid var(--brand);
    padding-left: 0.9rem;
}

.content h3 {
    color: var(--text-muted);
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1.4rem;
    margin-bottom: 0.6rem;
}

.content h4, .content h5, .content h6 {
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

/* Sidebar */
.sidebar {
    background-color: var(--sidebar-bg) !important;
    border-right: 1px solid var(--border-color);
    /* Respect mdBook's responsive sidebar width so resizing works */
    width: var(--sidebar-width);
}

.sidebar-scrollbox {
    background-color: var(--sidebar-bg) !important;
    /* Horizontal padding adds space between the resize line and text */
    padding: 0.75rem 1rem;
}

.chapter { margin: 0; }

.chapter-item { color: var(--sidebar-text) !important; margin: 0; }

.chapter-item a {
    color: var(--sidebar-text) !important;
    text-decoration: none;
    padding: 0.6rem 1.25rem;
    display: block;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    font-weight: 500;
}

.chapter-item a:hover {
    background-color: var(--sidebar-active-bg) !important;
    color: var(--link) !important;
    border-left-color: var(--sidebar-active-border) !important;
}

.chapter-item.expanded > a,
.chapter-item > a.active {
    background-color: var(--sidebar-active-bg) !important;
    color: var(--link) !important;
    border-left-color: var(--sidebar-active-border) !important;
    font-weight: 700;
}

.chapter-item.part-title {
    color: var(--text-muted) !important;
    background-color: var(--bg-elev) !important;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    padding: 0.5rem 1.25rem;
    margin-top: 0.8rem;
    border-left: 3px solid var(--text-muted);
}

.chapter-item.part-title:first-child { margin-top: 0; }

/* Top navigation */
.nav-wrapper { background-color: var(--nav-bg); border-bottom: 1px solid var(--border-color); }
.nav-chapters { color: var(--sidebar-text); }

/* Body copy */
p { color: var(--text-color); }

/* Links */
a {
    color: var(--link) !important;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color .15s ease, border-bottom-color .15s ease;
}

a:hover { border-bottom-color: var(--link); color: var(--link-hover) !important; }

/* Code */
.content pre {
    background-color: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.content code {
    background-color: var(--code-bg);
    padding: 0.18rem 0.4rem;
    border-radius: 4px;
    font-family: "JetBrains Mono", "Fira Code", Menlo, Consolas, Monaco, "Ubuntu Mono", monospace;
    font-size: 0.92em;
}

.content pre code { background-color: transparent; padding: 0; }

.code-language-label {
    background-color: var(--nav-bg);
    color: var(--text-muted);
}

/* Tables */
.content table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
.content table th,
.content table td { border: 1px solid var(--border-color); padding: 0.75rem; text-align: left; }
.content table th { background-color: var(--bg-elev); font-weight: 700; color: var(--text-color); }
.content table tr:nth-child(even) { background-color: var(--bg-elev); }

/* Callouts */
.content .warning { background-color: #FFF7ED; border: 1px solid #FED7AA; border-left: 4px solid var(--warning-color); padding: 1rem; margin: 1rem 0; border-radius: 6px; }
.content .info { background-color: #ECFDF5; border: 1px solid #A7F3D0; border-left: 4px solid var(--success-color); padding: 1rem; margin: 1rem 0; border-radius: 6px; }
.content .error { background-color: #FEF2F2; border: 1px solid #FECACA; border-left: 4px solid var(--error-color); padding: 1rem; margin: 1rem 0; border-radius: 6px; }

/* Lists */
.content ul, .content ol { padding-left: 1.5rem; }
.content li { margin-bottom: 0.35rem; }

/* Buttons */
.btn {
    background-color: var(--brand);
    color: #FFFFFF;
    padding: 0.55rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-weight: 600;
    transition: background-color .15s ease, transform .06s ease;
}
.btn:hover { background-color: var(--brand-strong); color: #FFFFFF; border-bottom: none; }
.btn:active { transform: translateY(1px); }
.btn-secondary { background-color: var(--text-muted); color: #FFFFFF; }
.btn-secondary:hover { background-color: #6B7280; }

/* Search */
#searchresults { background-color: var(--bg-color); border: 1px solid var(--border-color); }
.searchresult-header { background-color: var(--bg-elev); color: var(--text-color); padding: 0.5rem; font-weight: 700; }

/* Responsive */
@media (max-width: 768px) {
    .content { padding: 1rem; }
    .content h1 { font-size: 2rem; }
    .content h2 { font-size: 1.4rem; }
    .content pre { font-size: 0.88rem; }
}

/* Print */
@media print {
    .sidebar, .nav-wrapper { display: none; }
    .content { margin: 0; padding: 0; }
    .content a { color: var(--text-color); text-decoration: underline; }
}

/* Misc */
html { scroll-behavior: smooth; }
button:focus, a:focus, input:focus { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Fully hide the border when collapsed so no sliver remains */
#sidebar-toggle-anchor:not(:checked) ~ .sidebar { border-right: 0 !important; }