/*
 * CUSTOM CSS OVERRIDES
 *
 * This file is for customizing the appearance of your wiki.
 */

/* --- Sidebar 1.5× wider --- */
:root {
    --sidebar-width: 420px !important;
    --sidebar-right-width: 420px;
    --toc-bg: #fafafa;
}

[data-theme="dark"] {
    --toc-bg: #1e1e1e;
}

/* --- Content centered between two sidebars --- */
.content {
    margin-left: calc(var(--sidebar-width) + (100vw - var(--sidebar-width) - var(--sidebar-right-width) - var(--content-max-width)) / 2) !important;
    width: var(--content-max-width) !important;
}

/* --- Justify text --- */
.markdown-content p,
.markdown-content li,
.content p,
.content li {
    text-align: justify;
}

/* --- Headings: progressive sizes, left-aligned, h6 = normal text size --- */
.content h1,
.content h2,
.content h3,
.content h4,
.content h5,
.content h6 {
    text-align: left !important;
    font-weight: 600;
}

.content h1 { font-size: 32px; }
.content h2 { font-size: 28px; }
.content h3 { font-size: 24px; }
.content h4 { font-size: 20px; }
.content h5 { font-size: 18px; }
.content h6 { font-size: 16px; }

/* --- Left sidebar: normal font weight, not bold --- */
.nav-item a,
.nav-item.directory > a {
    font-weight: 400 !important;
}

/* --- Right sidebar: table of contents --- */
.toc-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    width: var(--sidebar-right-width);
    height: 100vh;
    background: var(--toc-bg);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    z-index: 100;
    padding: 24px 20px;
    box-sizing: border-box;
    font-size: 14px;
    line-height: 1.5;
    transition: transform 0.3s ease;
}

.toc-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
}

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

.toc-sidebar li {
    margin: 0;
}

.toc-sidebar a {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    padding: 4px 0;
    border-radius: 4px;
    transition: color 0.15s ease;
    overflow-wrap: break-word;
    word-break: break-word;
}

.toc-sidebar a:hover {
    color: var(--primary-color);
}

.toc-sidebar a.active {
    color: var(--primary-color);
    font-weight: 500;
}

li.toc-h2 { padding-left: 0; }
li.toc-h3 { padding-left: 2ch; }
li.toc-h4 { padding-left: 4ch; }
li.toc-h5 { padding-left: 6ch; }
li.toc-h6 { padding-left: 8ch; }


/* ================================================================
   COLLAPSIBLE SIDEBARS — FLOATING TOGGLE BUTTONS
   ================================================================ */

/* Desktop transition for left sidebar */
@media (min-width: 951px) {
    .sidebar {
        transition: transform 0.3s ease;
    }
}

/* --- Left sidebar collapse --- */
body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}

body.sidebar-collapsed .breadcrumbs {
    left: 0;
}

/* --- Right TOC sidebar collapse --- */
body.toc-collapsed .toc-sidebar {
    transform: translateX(100%);
}

/* ================================================================
   FLOATING TOGGLE BUTTONS (fixed, always on top, independent)
   ================================================================ */

/* --- Left sidebar toggle --- */
.sidebar-toggle-float {
    position: fixed;
    left: var(--sidebar-width);
    top: 50%;
    transform: translateY(-50%);
    z-index: 2000;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    width: 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    padding: 0;
    margin: 0;
    transition: left 0.3s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    user-select: none;
    opacity: 1;
}

.sidebar-toggle-float:hover {
    background: var(--primary-color);
    color: #fff;
    box-shadow: 2px 0 14px rgba(0,0,0,0.2);
}

/* Move to screen edge when sidebar collapsed */
body.sidebar-collapsed .sidebar-toggle-float {
    left: 0;
    border-left: 1px solid var(--border-color);
    border-radius: 0 8px 8px 0;
}

/* --- Right TOC toggle --- */
.toc-toggle-float {
    position: fixed;
    right: var(--sidebar-right-width);
    top: 50%;
    transform: translateY(-50%);
    z-index: 2000;
    background: var(--toc-bg);
    border: 1px solid var(--border-color);
    border-right: none;
    border-radius: 8px 0 0 8px;
    cursor: pointer;
    width: 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    padding: 0;
    margin: 0;
    transition: right 0.3s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: -2px 0 8px rgba(0,0,0,0.1);
    user-select: none;
    opacity: 1;
}

.toc-toggle-float:hover {
    background: var(--primary-color);
    color: #fff;
    box-shadow: -2px 0 14px rgba(0,0,0,0.2);
}

/* Move to screen edge when TOC collapsed */
body.toc-collapsed .toc-toggle-float {
    right: 0;
    border-right: 1px solid var(--border-color);
    border-radius: 8px 0 0 8px;
}


/* ================================================================
   RESPONSIVE
   ================================================================ */

/* --- Narrow screens: hide TOC, keep left sidebar --- */
@media (max-width: 1200px) {
    .toc-sidebar {
        display: none !important;
    }
    .toc-toggle-float {
        display: none !important;
    }
    .content {
        margin-left: calc(var(--sidebar-width) + (100vw - var(--sidebar-width) - var(--content-max-width)) / 2) !important;
    }
}

/* --- Mobile: hide floating buttons, disable collapse, use original hamburger --- */
@media (max-width: 950px) {
    .sidebar-toggle-float {
        display: none !important;
    }
    .toc-toggle-float {
        display: none !important;
    }

    body.sidebar-collapsed .sidebar {
        transform: none;
    }
    body.sidebar-collapsed .breadcrumbs {
        left: 47px;
    }

    body.sidebar-collapsed .content,
    body.toc-collapsed .content,
    body.sidebar-collapsed.toc-collapsed .content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}
