#ebook-app {
display: flex;
flex-direction: row;
background: var(--background);
color: var(--text-color);
font-family: var(--global-font);
font-size: var(--text-normal);
width: 100%;
height: 100%;
overflow: hidden;
}

/* ===== SIDEBAR ===== */
.ebook-sidebar {
    position: relative; /* changed from fixed */
    top: 0;
    left: 0;
    height: 100%;
    width: 280px;
    background: var(--bright-color);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
    overflow-y: auto;
    padding: var(--double-pad) var(--standard-pad);
    z-index: 10;
}

.sidebar-back {
    display: none;
}

.ebook-menu-toggle {
    display: none;
}

.ebook-header {
    margin-bottom: var(--double-pad);
}

.ebook-title {
}

.ebook-toc {
    display: flex;
    flex-direction: column;
    gap: var(--standard-pad);
}

/* TOC chapters */
.toc-chapter {
    border-left: 3px solid transparent;
    padding-left: var(--standard-pad);
    transition: border-color 0.2s, background 0.2s;
}

.toc-chapter.active {
    border-left-color: var(--primary-color);
    background: var(--primary-color-light);
    padding: 1rem;
}

.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

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

.toc-number {
    font-weight: bold;
    margin-right: 0.5em;
    color: var(--primary-color);
}

.toc-title {
    flex: 1;
}

.toc-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    font-size: 1em;
    margin-left: 0.5em;
    transition: transform 0.2s;
}

.toc-toggle.open {
}

.toc-subheadings {
    list-style: none;
    padding-left: 1.2em;
    margin: var(--half-pad) 0 0;
    display: none;
    flex-direction: column;
    gap: 0.3em;
}

.toc-subheadings.open {
    display: flex;
}

.toc-subheadings li {
    cursor: pointer;
    font-size: var(--text-small);
    color: var(--text-color);
    transition: color 0.2s;
}

.toc-subheadings li:hover {
    color: var(--primary-color);
}

/* ===== MAIN CONTENT ===== */
.ebook-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%; /* changed from min-height */
    width: 100%;
    overflow-x: hidden;
    background: var(--background);
}

.ebook-main-header {
    padding: var(--double-pad) var(--window-gap) var(--standard-pad) var(--double-pad);
    background: var(--bright-color);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.ebook-chapter-title {
    font-size: var(--page-content-title);
    font-family: var(--title-font);
    color: var(--title-color);
    margin: 0;
}

.ebook-content {
    flex: 1;
    padding: var(--standard-pad);
    background: var(--bright-color);
    color: var(--text-color);
    line-height: 1.6;
    width: 100%;
    overflow-y: auto; /* allow scrolling inside iframe */
}

/* ===== FOOTER ===== */
.ebook-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--standard-pad) var(--double-pad);
    background: var(--bright-color);
    border-top: 1px solid #ddd;
}

.ebook-footer button {
    background: var(--primary-color);
    color: var(--bright-color);
    border: none;
    border-radius: var(--standard-radius);
    padding: 0.6em 1.2em;
    font-size: var(--text-normal);
    cursor: pointer;
    transition: background 0.2s;
}

.ebook-footer button:hover {
    background: var(--secondary-color);
}

.ebook-footer button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ===== MOBILE ===== */
@media (max-width: 1000px) {

        /* Full-screen overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease;
        z-index: 900;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Sidebar slides over main content */
    .ebook-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        background: var(--bright-color);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto; /* allow vertical scrolling */
        padding: var(--double-pad) var(--standard-pad);
    }

    .ebook-sidebar.open {
        transform: translateX(0);
    }

    /* Back button in sidebar */
    .sidebar-back {
        display: block;
        margin-bottom: var(--standard-pad);
        background: var(--primary-color);
        color: white;
        border: none;
        padding: 0.5em 1em;
        font-size: 1em;
        border-radius: var(--standard-radius);
        cursor: pointer;
    }

    /* Main hamburger toggle */
    .ebook-menu-toggle {
        display: flex !important;
        background: var(--primary-color);
        color: white;
        border: none;
        font-size: 1.5rem;
        cursor: pointer;
        transition: opacity 0.2s ease;
    }

    .ebook-menu-toggle.hidden {
        opacity: 0;
        pointer-events: none;
    }

    .ebook-main-header {
        padding-left: 4rem;
    }

    .ebook-main {
        margin-left: 0;
    }

    .ebook-footer{
        padding: 2rem 1rem 2rem 1rem;
    }

    .ebook-next{
        font-size: var(--text-small);
        text-align: right;
    }

    .ebook-prev{
        font-size: var(--text-small);
        text-align: left;
    }
}

/* ===== SCROLLBARS ===== */
.ebook-sidebar::-webkit-scrollbar {
    width: 6px;
}
.ebook-sidebar::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}
