/* Book Viewer Styles - OpenStax Inspired */

/* Book Header */
.book-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 100;

    .book-title {
        text-align: center;
        max-width: 800px;
        margin: 0 auto;

        & h1 {
            font-size: 2.5rem;
            font-weight: 700;
            margin: 0;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
            padding: 0 10px;
        }

        .book-subtitle {
            font-size: 1.1rem;
            margin: 0;
            opacity: 0.9;
            font-weight: 300;
            display: none; /* Hide subtitle */
        }
    }

    .header-controls {
        .btn {
            background-color: rgba(255, 255, 255, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            transition: all 0.3s ease;

            &:hover {
                background-color: rgba(255, 255, 255, 0.3);
                border-color: rgba(255, 255, 255, 0.5);
                color: white;
            }

            &:focus {
                outline: none;
            }
        }

        /* Remove animation from Add Book button */
        #addBookBtn {
            transition: none !important;
        }

        /* Close Book button styling */
        #closeBookBtn {
            background-color: rgba(255, 255, 255, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            transition: all 0.3s ease;
        }

        #closeBookBtn:hover {
            background-color: rgba(255, 255, 255, 0.3);
            border-color: rgba(255, 255, 255, 0.5);
            color: white;
        }
    }
}

/* Base Layout */
.book-container {
    margin-top: 0;
    min-height: calc(100vh - 70px);
    background-color: #f8f9fa;
    display: flex;
    justify-content: center;
    align-items: stretch;
}

/* Override Bootstrap row behavior */
.book-container .row {
    display: flex;
    width: 100%;
    min-height: calc(100vh - 70px);
    margin: 0;
}

.book-container .row > [class*="col-"] {
    display: flex;
    flex-direction: column;
    padding: 0;
}

/* Scroll to Top Button */
.scroll-to-top {
    position: fixed;
    bottom: 60px;
    right: 30px;
    width: 50px;
    height: 50px;
    color: #ffffff;
    border: 1px solid #000000;
    border-radius: 13px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: all 0.3s ease;
    z-index: 1000;
    opacity: 0;
    transform: translateY(20px);
    background-color: #717171;

    &.show {
        display: flex;
        opacity: 1;
        transform: translateY(0);
    }

    &:hover {
        transform: translateY(-2px);
        background-color: #555555;
    }

    &:active {
        transform: translateY(0);
    }

    & svg {
        width: 25px;
        height: 25px;
        fill: currentColor;
    }
}

.settings-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
}

.settings-btn .glyphicon {
    font-size: 18px;
    line-height: 1;
}

.book-settings-tooltip {
    min-width: 220px;
    padding: 4px 2px;
}

.book-settings-row {
    display: flex;
    align-items: center;
    justify-content: left;
    gap: 10px;
    padding: 6px 8px;
}

.book-settings-label {
    font-size: 14px;
    font-weight: 600;
    width: 75px;
}

.book-settings-font-controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.book-settings-font-controls .btn {
    min-width: 26px;
    height: 26px;
    line-height: 1;
    padding: 0;
    font-size: 14px;
    outline: none !important;
}

#settingsFontSizeValue {
    width: 64px;
    height: 26px;
    text-align: center;
    padding: 2px 4px;
    font-size: 12px;
}

/* Sticky stack: optional class-tools row (#bookProfToolsToolbarHost) + main reader toolbar (Ask AI, etc.) */
.content-top-sticky {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: -30px -30px 0 -30px;
}

.book-prof-toolbar-slot {
    &:not([hidden]) {
        padding: 10px 10px 8px;
        background-color: #e2e8ee;
        border-bottom: 1px solid #cfd6dd;
    }

    &[hidden] {
        display: none !important;
    }
}

/* My Study / My Lessons: TOC-aligned class-tools strip; nav chrome moved into slot via dash.js */
.content-wrapper.book-prof-tools-layout {
    padding: 8px 12px 12px;
    max-width: none;
    align-self: stretch;

    & .content-top-sticky {
        margin: -8px -12px 8px -12px;
    }

    & .book-prof-toolbar-slot {
        &:not([hidden]) {
            display: flex;
            align-items: center;
            padding: 16px 10px 15px;
            background-color: #eaeff2;
            border-bottom: 1px solid #e0e3e6;
            margin-bottom: 0;

            & .book-prof-embed-toolbar-row {
                width: 100%;
            }
        }
    }

    & .content-header {
        display: none !important;
    }

    /* Preview (udoc) inside #book-prof-embed-root: drop reader .content-header focus outline (grid list still uses normal chrome) */
    &:has(.book-prof-embed-root .usolver-container) .content-header {
        outline: none !important;
        outline-offset: 0 !important;
        box-shadow: none !important;
    }

    &:has(.book-prof-embed-root .usolver-container) .content-header:focus,
    &:has(.book-prof-embed-root .usolver-container) .content-header:focus-visible {
        outline: none !important;
        box-shadow: none !important;
    }
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 10px 15px;
    margin: 0;
    background-color: #eaeff2;
    border-bottom: 1px solid #e0e3e6;
    flex-wrap: wrap;
    gap: 15px;
    position: relative;

    .book-controls {
        display: flex;
        gap: 8px;

        .btn {
            border: 1px solid transparent;
            background-color: transparent;
            color: #495057;
            padding: 6px 10px;
            height: 36px;
            border-radius: 4px;
            transition: all 0.2s ease;
            font-size: calc(12px * var(--bookviewer-font-scale, 1));

            &:hover {
                background-color: #e9ecef;
                border-color: #adb5bd;
            }
        }

        .btn.btn-sm .glyphicon {
            font-size: calc(18px * var(--bookviewer-font-scale, 1));
        }

        /* Quiz button specific styling */
        #toggleQuiz {
            color: #52b9e2;
        }
    }
}

.modal-content {
    .modal-body {
        & form {
            & label {
                margin-bottom: 2px;
                margin-left: 2px;
                font-weight: 700;
                color: #797979;
                text-shadow: 1px 1px 1px white;
            }

            .form-control:not([readonly]) {
                color: #222222;
            }

            .form-control[readonly] {
                color: #797979;
            }
        }
    }
}

.btn:not(.btn-primary, .btn-success, .btn-info, .btn-warning, .btn-danger, .btn-sm) {
    background-color: #f6f6f6;
    border-color: #ced4d7;
}

/* Responsive scroll to top button */
@media (max-width: 767.98px) {
    .scroll-to-top {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
}

@media (max-width: 575.98px) {
    .scroll-to-top {
        bottom: 15px;
        right: 15px;
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
}

/* Table of Contents Styles */
.toc-column {
    background-color: #fff;
    border-right: 1px solid #e9ecef;
    min-height: calc(100vh - 70px);
    position: sticky;
    top: 0;
    z-index: 10;
    transition: transform 0.3s ease;
    width: 280px;
    flex-shrink: 0;
    padding: 0 5px;
    display: flex;
    flex-direction: column;
    flex: 1;
    align-self: flex-start;
    height: 100vh;
    overflow: hidden;
}

/* Desktop TOC hiding */
.toc-column.hidden {
    display: none;
}

.toc-column.hidden + .content-column {
    width: 100%;
    margin-left: 0;
}

/* Ensure content area expands fully when TOC is hidden */
.toc-column.hidden + .content-column .content-wrapper {
    max-width: 100%;
}

.toc-wrapper {
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 23px 5px 15px;
    background-color: #eaeff2;
    border-right: 1px solid #d5d5d5;
    border-bottom: 1px solid #e0e3e6;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.toc-header h4 {
    margin: 0 10px;
    font-size: 18px;
    color: #6e7c8a;
}

.toc-title-link {
    appearance: none;
    background: none;
    border-radius: 4px;
    border: 0;
    color: inherit;
    cursor: pointer;
    font: inherit;
    padding: 5px 10px;
}

.toc-title-link:hover,
.toc-title-link:focus-visible {
    background-color: #dce4e9;
    color: #334f69;
    outline: none;
}

.toc-toggle {
    display: none;
}

.toc-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 5px;
}

.toc-close {
    padding: 4px 8px;
    border: 1px solid transparent;
    background-color: transparent;
    color: #6c757d;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 12px;
}

.toc-close:hover {
    background-color: #fff;
    border-color: #ccc;
    color: #495057;
}

.toc-nav {
    padding: 0 4px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

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

.toc-link {
    display: block;
    padding: 8px 12px;
    color: #495057;
    text-decoration: none;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.4;
    transition: all 0.2s ease;
}

.toc-link:hover {
    background-color: #f9fafb;
    color: #2c3e50;
    text-decoration: none;
}

.toc-link.active {
    background-color: #e5eaf2;
    color: #343434;
    font-weight: normal;
    text-decoration: none;
    border-radius: 4px;
}

.toc-link-back {
    padding-left: 20px;
    color: #7d7a91;
    background-color: #f6fafc;
}

.toc-link-back:hover {
    background-color: #e6f0f8;
}

.toc-sub-list {
    list-style: none;
    padding-left: 15px;
    margin-top: 5px;
}

.toc-sub-list .toc-link {
    font-size: 13px;
    padding: 6px 12px;
}

/* New TOC structure styles */
.toc-unit-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 8px 12px;
    color: #2c3e50;
    font-weight: 600;
    font-size: 14px;
    background-color: #fff;
    border-radius: 4px;
    margin-bottom: 5px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    user-select: none;
}

.toc-unit-title:hover {
    background-color: #f8f9fa;
}

.toc-unit-toggle {
    display: inline-block;
    font-size: 12px;
    transition: transform 0.3s ease;
    transform: rotate(0deg);
    color: #6c757d;
    padding-top: 2px;
}

.toc-unit-toggle.collapsed {
    transform: rotate(-90deg);
}

.toc-unit-content {
    transition: max-height 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

.toc-unit-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
}

.toc-chapter {
    margin-bottom: 5px;
}

/* Collapsible chapter styles */
.toc-chapter-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    cursor: pointer;
    transition: background-color 0.2s ease;
    user-select: none;
    padding: 2px;
    border-radius: 4px;
}

.toc-chapter-title:hover {
    background-color: #f8f9fa;
}

.toc-chapter-toggle {
    display: inline-block;
    font-size: 10px;
    transition: transform 0.3s ease;
    transform: rotate(0deg);
    color: #6c757d;
    position: relative;
    left: -10px;
    top: 6px;
}

.toc-chapter-toggle.collapsed {
    transform: rotate(-90deg);
}

.toc-chapter-content {
    transition: max-height 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

.toc-chapter-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
}

/* Active state for chapter titles */
.toc-chapter-title .toc-link.active {
    background-color: transparent;
    color: #343434;
    font-weight: normal;
    text-decoration: none;
}

.toc-chapter-title.active {
    background-color: #e5eaf2;
}

.toc-section-list {
    list-style: none;
    padding-left: 15px;
    margin-top: 5px;
}

.toc-section-list .toc-link {
    padding: 5px 12px;
    color: #6c757d;
    margin-bottom: 2px;
}

/* Add subsection styling to existing rule */
.toc-section-list .subsection .toc-link {
    position: relative !important;
    padding-left: 26px !important;
}

.toc-section-list .subsection .toc-link:before {
    content: "•" !important;
    position: absolute !important;
    left: 15px !important;
    color: #6c757d !important;
    font-weight: bold !important;
}

.toc-section-list .toc-link:hover {
    background-color: #f1f3f4;
    color: #495057;
}

.subsection-links {
    .subsection-link-item {
        padding-left: 10px;
    }
}

.toc-overview-page .toc-overview-unit {
    margin-bottom: 28px;
}

.toc-overview-page .toc-overview-unit-title {
    color: #2c3e50;
    margin: 25px 0 20px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #e9ecef;
}

.toc-overview-page .toc-overview-unit-title .toc-overview-unit-link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.toc-overview-page .toc-overview-unit-title .toc-overview-unit-link:hover {
    color: #1a5276;
    text-decoration: underline;
}

.toc-overview-page a:focus,
.toc-overview-page a:focus-visible {
    outline: none !important;
    box-shadow: none !important;
}

.book-toc-action-buttons {
    display: flex;
    float: right;
    gap: 8px;
    margin-top: 20px;
}

.book-toc-action-button {
    background-color: #f4f2ff;
    border-color: #b8b0df;
    color: #4f467f;
}

.book-toc-action-button:hover,
.book-toc-action-button:focus {
    background-color: #e7f2ff;
    border-color: #8fb8df;
    color: #294f76;
}

.book-toc-action-button:focus,
.book-toc-action-button:active,
.book-toc-action-button:active:focus {
    outline: none !important;
    box-shadow: none !important;
}

.book-toc-action-button:active,
.book-toc-action-button:active:focus {
    background-color: #d3e7fb;
    border-color: #74a5d1;
    color: #1f4163;
}

.book-toc-action-button .glyphicon {
    color: #8c98ac;
    font-size: 17px;
    top: 3px;
}

.hamburger-menu,
.book-level-up,
.book-controls .btn,
.toc-close {
    outline: none !important;
}

.toc-link,
.toc-overview-page .toc-overview-unit-title .toc-overview-unit-link {
    outline: none !important;
    box-shadow: none !important;
}

.toc-link:focus-visible,
.toc-overview-page .toc-overview-unit-title .toc-overview-unit-link:focus-visible {
    outline: none !important;
    outline-offset: 2px;
    box-shadow: none !important;
}

.os-chapter-objective {
    padding-left: 5px;
    &:last-child {
        margin-bottom: 15px;
    }
}

.os-references-container {
    margin-top: 25px;
}

/* Dark Theme */
.dark-theme {
    background-color: #1a1a1a;
    color: #e9ecef;

    & body,
    & html {
        background-color: #1a1a1a;
    }

    .book-container {
        background-color: #1a1a1a;
    }

    .toc-column {
        background-color: #2d2d2d;
        border-right-color: #404040;
    }

    .content-column {
        background-color: #1a1a1a;
    }

    .content-wrapper {
        background-color: #2d2d2d;
        color: #e9ecef;

        & p {
            color: #b9baba;
        }
    }

    .content-body {
        color: #e9ecef;
        & h1, & h2, & h3, & h4 {
            color: #ddd !important;
        }

        .os-table {
            & table {
                & th,
                & td {
                    border-color: #515151;
                }
                & th {
                    background-color: #383838;
                }
            }
        }
    }

    .toc-header {
        background-color: #242424;
        border-bottom-color: #404040;
        border-right-color: #404040;

        & h4 {
            color: #b1b1b1;
        }
    }

    .toc-link {
        color: #adb5bd;

        &:hover {
            background-color: #404040;
            color: #fff;
            text-decoration: none;
        }

        &.active {
            background-color: #44464b;
            color: #d5dde4;
            text-shadow: 0 0 black;
            text-decoration: none;
            border-radius: 4px;
        }

        &:focus-visible {
            outline-color: #ced4da;
        }
    }

    .toc-overview-page .toc-overview-unit-title {
        color: #ddd;
        border-bottom-color: #404040;
    }

    .toc-overview-page .toc-overview-unit-title .toc-overview-unit-link:hover {
        color: #fff;
    }

    .toc-overview-page .toc-overview-unit-title .toc-overview-unit-link:focus-visible {
        outline-color: #ced4da;
    }

    .toc-chapter-title {
        &:hover {
            background-color: #404040;
        }

        &.active {
            background-color: #44464b;
        }

        .toc-link.active {
            background-color: transparent;
            color: #d5dde4;
            text-shadow: 0 0 black;
            text-decoration: none;
        }
    }

    .toc-section-list .subsection .toc-link:before {
        color: #adb5bd !important;
    }

    .toc-unit-title {
        color: #e9ecef;
        background-color: #2d2d2d;

        &:hover {
            background-color: #404040;
        }
    }

    .toc-unit-toggle {
        color: #adb5bd;
    }

    .toc-chapter-toggle {
        color: #adb5bd;
    }

    .callout-box {
        background-color: #404040;
        border-left-color: #007bff;
    }

    .step {
        background-color: #404040;
        border-left-color: #007bff;
    }

    .hamburger-menu,
    .book-level-up,
    .book-controls .btn,
    .toc-close {
        background-color: transparent;
        border-color: transparent;
        color: #e9ecef;

        &:hover {
            background-color: #404040;
            border-color: #555555;
            color: #fff;
        }
    }

    .toc-link-back {
        background-color: #414344;
    }

    .book-level-up:disabled {
        opacity: 0.4;
    }

    .hamburger-menu.active {
        background-color: #007bff;
        border-color: #007bff;
        color: #fff;
    }

    .book-prof-toolbar-slot {
        &:not([hidden]) {
            background-color: #2a2a2a;
            border-bottom-color: #404040;
        }
    }

    .content-wrapper.book-prof-tools-layout {
        & .book-prof-toolbar-slot {
            &:not([hidden]) {
                background-color: #242424;
                border-bottom-color: #404040;
            }
        }
    }

    .content-header {
        border-bottom-color: #404040;
        border-left-color: #404040;
        background-color: #242424;
    }

    .figure-caption {
        color: #adb5bd;
    }

    .chapter-subtitle {
        color: #adb5bd;
    }

    .scroll-to-top {
        background-color: #636363;
        border-color: #959595;

        &:hover {
            background-color: #7b7b7b;
        }
    }

    /* Header AI Input Dark Theme */
    .ai-input-container {
        .ai-input-icon {
            color: #adb5bd !important;
        }
        .form-control.ai-input {
            background-color: #373737 !important;
            border-color: #454b4f !important;
            color: #e9ecef !important;

            &:focus {
                border-color: #75818d !important;
                background-color: #202020 !important;
                box-shadow: 0 0 4px 0 #afbccacf !important;
            }

            &::placeholder {
                color: #72767b !important;
            }
        }
    }
    .ai-dialog-overlay {
        background-color: #2d2d2d;
        border-color: #404040;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);

        .ai-dialog-header {
            background-color: #404040;
            border-bottom-color: #555555;

            .ai-dialog-title {
                color: #e9ecef;
            }

            .ai-dialog-controls .btn {
                background-color: #2d2d2d;
                border-color: #555555;
                color: #adb5bd;

                &:hover {
                    background-color: #555555;
                    border-color: #666666;
                    color: #fff;
                }
            }
        }

        .ai-dialog-content .ai-messages {
            background-color: #2d2d2d;
            color: #e9ecef;

            /* Dark theme scrollbar styles */
            &::-webkit-scrollbar {
                width: 8px;
            }

            &::-webkit-scrollbar-track {
                background: #404040;
                border-radius: 4px;
            }

            &::-webkit-scrollbar-thumb {
                background: #666666;
                border-radius: 4px;

                &:hover {
                    background: #777777;
                }
            }

            /* Firefox scrollbar styles */
            scrollbar-width: thin;
            scrollbar-color: #666666 #404040;
        }

        .ai-dialog-input-container {
            background-color: #404040 !important;
            border-top-color: #555555 !important;
        }

        .ai-dialog-input {
            background-color: #2d2d2d;
            border-color: #555555;
            color: #e9ecef;

            &:focus {
                border-color: #007bff;
                background-color: #2d2d2d;
            }

            &::placeholder {
                color: #adb5bd;
            }
        }

        .ai-dialog-send {
            background-color: #007bff;

            &:hover {
                background-color: #0056b3;
            }
        }

        .ai-dialog-resize-handle {
            background: linear-gradient(-45deg, transparent 30%, #666 30%, #666 40%, transparent 40%, transparent 60%, #666 60%, #666 70%, transparent 70%);
        }

        .ai-dialog-resize-handle:hover {
            background: linear-gradient(-45deg, transparent 30%, #888 30%, #888 40%, transparent 40%, transparent 60%, #888 60%, #888 70%, transparent 70%);
        }
    }
}

/* Restore selection link styling */
.restore-selection {
    color: #007bff;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.2s ease;
}

.restore-selection:hover {
    color: #0056b3;
    text-decoration: underline;
}

.restore-selection:active {
    color: #004085;
}

/* Content Column Styles */
.content-column {
    background-color: #fff;
    min-height: calc(100vh - 70px);
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    width: 900px;
    flex-shrink: 0;
    flex: 3;
}

/* Content Area Image Styles */
.content-column img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 5px 0;
    border-radius: 6px;
}

/* Only apply 100% width to images that don't have specific width attributes */
.content-column img:not([width]) {
    width: 100%;
}

/* Responsive image adjustments */
@media (max-width: 768px) {
    .content-column img {
        margin: 10px 0;
        border-radius: 4px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    }
}

.content-column figure img {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
}

.content-wrapper {
    padding: 30px;
    max-width: 900px;
    width: 100%;
    align-self: flex-start;
}

/* Content area typography and spacing */
.content-wrapper h1,
.content-wrapper h2,
.content-wrapper h3,
.content-wrapper h4,
.content-wrapper h5,
.content-wrapper h6 {
    color: #2c3e50;
}

.content-wrapper p {
    margin-bottom: 1em;
    line-height: 1.6;
    color: #495057;
}

.content-wrapper ul,
.content-wrapper ol {
    margin-bottom: 1em;
    padding-left: 1.5em;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hamburger-menu,
.book-level-up {
    padding: 8px 12px;
    border: 1px solid #c0cad3;
    background-color: #fff;
    color: #495057;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: calc(16px * var(--bookviewer-font-scale, 1));
    line-height: 1;
}

.hamburger-menu:hover,
.book-level-up:hover:not(:disabled) {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

.hamburger-menu.active {
    background-color: #007bff;
    color: #fff;
    border-color: #007bff;
}

.book-level-up:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Level-up stays visible; hamburger toggles with TOC on desktop */
.hamburger-menu,
.book-level-up {
    display: block;
}

/* Hide hamburger only when TOC is visible on desktop (level-up stays visible) */
@media (min-width: 992px) {
    .toc-column.show ~ .content-column .hamburger-menu {
        display: none;
    }

    .toc-column:not(.hidden) ~ .content-column .hamburger-menu {
        display: none;
    }

    .toc-column.hidden ~ .content-column .hamburger-menu {
        display: block;
    }
}

/* Book Content Styles */
.content-body {
    font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.7;
    color: #2c3e50;

    & h1 {
        font-size: 2.6rem;
        margin-top: 25px;
        margin-bottom: 30px;
        text-align: left;
    }

    & h2 {
        font-size: 2rem;
        font-weight: 600;
        color: #2c3e50;
        border-bottom: 2px solid #e9ecef;
        margin: 30px 0 15px -6px;
        padding: 0 6px 6px;
    }

    h3, h4 {
        font-size: 1.7rem;
        font-weight: 600;
        color: #2c3e50;
        margin-top: 28px;
        margin-bottom: 14px;
    }

    & p {
        margin-bottom: 20px;
    }

    ul, ol {
        margin-bottom: 20px;
        padding-left: 25px;
    }

    & li {
        margin-bottom: 8px;
    }


}

.toc-content {
    font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chapter-header {
    margin-bottom: 40px;
    text-align: center;
}

.chapter-header-row {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 20px;
}

.chapter-header-row::after {
    display: none;
}

.chapter-header-row .chapter-header {
    margin-bottom: 0;
    text-align: left;
    line-height: 42px;
    order: 1;
    flex: 0 1 auto;
    min-width: 0;
}

.chapter-header-row .section-navigation-inline {
    float: right;
}

.chapter-header-row .chapter-tabs-btn-wrap {
    display: inline-block;
    margin-top: 0;
    margin-left: 40px;
}

.chapter-header-row .chapter-tabs-btn-group {
    margin-top: 0;
}

/* Header prev/next arrows: not selectable */
.chapter-header-row .nav-link-icon,
.chapter-header-row .nav-link-icon .nav-arrow {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.chapter-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 10px;
    line-height: 1.2;
}

.chapter-subtitle {
    font-size: 1.2rem;
    color: #6c757d;
    font-weight: 400;
    margin: 0;
}

/* Figure Styles */
.figure {
    margin: 30px 0;
    text-align: center;
}

.figure-img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Ensure all images in content are responsive */
.content-column img[data-media-type] {
    max-width: 100%;
    height: auto;
}

/* Additional OpenStax content styling */
.content-column {
    .os-caption-container {
        margin-top: 20px;
        text-align: center;
        font-size: 0.9em;
        color: #6c757d;
        font-style: italic;
        .os-title-label,

        .os-number {
            display: inline;
            font-weight: 600;
            color: #2c3e50;
            font-style: normal;
        }
        .os-title {
            display: inline;
            font-weight: 600;
            color: #2c3e50;
            font-style: normal;
        }
        .os-divider {
            border-right: 1px solid #92a5b7;
            margin: 0 10px 0 7px;
        }
        .os-caption {
            display: inline;
        }
    }

    .os-table-title {
        text-align: center;
        font-weight: bold;
        font-size: 1.05em;
    }

    .os-table .os-caption-container .os-divider {
        border-right: none;
    }

    .os-figure {
        padding: 30px 0;
        /* border-bottom: 1px solid #8ec9ee; */
        /* border-top: 1px solid #8ec9ee; */
        margin: 20px 0;
        text-align: center;

        & img {
            max-width: 100%;
            height: auto;
            display: block;
            margin: 0;
            border-radius: 0;
            box-shadow: none;
        }

        &.has-splash img {
            max-width: 100%;
            height: auto;
            width: auto;
        }

        &.scaled-down img {
            max-width: 100%;
            height: auto;
            width: auto;
        }

        /* Ensure OpenStax figures maintain their original appearance */
        & figure {
            margin: 0;
            padding: 0;

            & img {
                display: inline-block;
                vertical-align: top;
            }
        }
    }

    .os-table {
        margin: 30px 0;

        & table {
            width: 100%;
            border-collapse: collapse;
            border: 1px solid #bfc6cb;

            & th,
            & td {
                border: 1px solid #bfc6cb;
                padding: 8px 12px;
            }

            & th {
                background-color: #f8f8f8;
            }
        }
    }
}

.figure-caption {
    margin-top: 15px;
    font-size: 14px;
    color: #6c757d;
    font-style: italic;
    text-align: center;
}

/* Callout Box */
.callout-box {
    background-color: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 25px 0;
    border-radius: 0 4px 4px 0;
}

.callout-box h4 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 1.1rem;
}

.callout-box ul {
    margin-bottom: 0;
}

/* Process Steps */
.process-steps {
    margin: 30px 0;
}

.step {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #007bff;
}

.step-number {
    background-color: #007bff;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    margin-right: 15px;
    flex-shrink: 0;
}

.step-content h4 {
    margin: 0 0 8px 0;
    color: #2c3e50;
    font-size: 1.1rem;
}

.step-content p {
    margin: 0;
    color: #495057;
}

/* Responsive Design */
@media (max-width: 1199.98px) and (min-width: 992px) {
    .book-container {
        justify-content: flex-start;
    }

    .toc-column {
        position: sticky;
        top: 0;
        width: 250px;
        flex-shrink: 0;
        min-height: calc(100vh - 70px);
        display: flex;
        flex-direction: column;
        flex: 1;
        align-self: flex-start;
        height: 100vh;
        overflow: hidden;
    }

    .content-column {
        width: calc(100% - 250px);
        flex-shrink: 0;
        flex: 3;
    }

    .content-wrapper {
        padding: 20px;
        max-width: 100%;
    }

    /* Make toolbar width match content width at this breakpoint */
    .content-top-sticky {
        margin-left: -20px;
        margin-right: -20px;
    }

    .content-header {
        padding-left: 20px;
        padding-right: 20px;
    }

    /* Make TOC header height match content header at this breakpoint */
    .toc-header {
        padding: 20px 0px 8px;
    }

    .content-wrapper.book-prof-tools-layout {
        & .book-prof-toolbar-slot {
            &:not([hidden]) {
                padding: 20px 10px 8px;
            }
        }
    }

    .toc-toggle {
        display: none;
    }

    .hamburger-menu,
    .book-level-up {
        display: block;
    }
}

@media (max-width: 991.98px) {
    .book-container {
        justify-content: flex-start;
    }

    .book-container .container {
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
        padding-left: 0;
        padding-right: 0;
    }

    .content-top-sticky {
        margin: -20px -20px 0 -20px;
    }

    .toc-column {
        position: fixed;
        top: 0;
        left: 0;
        transform: translateX(-100%);
        width: 280px;
        z-index: 1300;
        height: 100vh;
        background-color: #fff;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .toc-column.show {
        transform: translateX(0);
    }

    .content-column {
        width: 100%;
        justify-content: flex-start;
        align-items: flex-start;
        margin-left: 0;
        transition: margin-left 0.3s ease;
    }

    .toc-toggle {
        display: none;
    }

    .hamburger-menu,
    .book-level-up {
        display: block !important;
    }

    /* Hide hamburger only when TOC drawer is open; level-up stays in the toolbar */
    .toc-column.show ~ .content-column .hamburger-menu {
        display: none !important;
    }

    .toc-column:not(.show) ~ .content-column .hamburger-menu {
        display: block !important;
    }

    /* Remove margins from book list container on mobile for full width */
    .book-list-container .container {
        padding-left: 0;
        padding-right: 0;
        margin-left: 0;
        margin-right: 0;
        width: 100%;
    }

    .chapter-header h1 {
        font-size: 2rem;
    }

    .content-wrapper {
        padding: 20px;
    }

    /* Mobile-specific TOC styles */
    .toc-wrapper {
        padding: 0;
        height: 100vh;
        max-height: 100vh;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .toc-header {
        padding: 20px 0px 15px;
        border-bottom: 1px solid #e9ecef;
        margin-bottom: 0;
        flex-shrink: 0;
        background-color: #fff;
    }

    .content-wrapper.book-prof-tools-layout {
        & .book-prof-toolbar-slot {
            &:not([hidden]) {
                padding: 20px 12px 15px;
                background-color: #fff;
                border-bottom: 1px solid #e9ecef;
            }
        }
    }

    .toc-nav {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 20px 0px 20px;
    }

    /* Mobile dark theme TOC styles */
    .dark-theme .toc-column {
        background-color: #2d2d2d;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }

    .dark-theme .toc-header {
        background-color: #2d2d2d;
        border-bottom-color: #404040;
    }

    .dark-theme .content-wrapper.book-prof-tools-layout {
        & .book-prof-toolbar-slot {
            &:not([hidden]) {
                background-color: #2d2d2d;
                border-bottom-color: #404040;
            }
        }
    }
}

@media (max-width: 767.98px) {
    .book-header {
        padding: 15px 0;
    }

    .book-title h1 {
        font-size: 2rem;
    }

    .book-subtitle {
        font-size: 1rem;
    }

    .book-container {
        justify-content: flex-start;
    }

    .content-column {
        justify-content: flex-start;
        align-items: flex-start;
    }

    .content-top-sticky {
        margin-top: -20px;
        margin-left: -15px;
        margin-right: -15px;
        position: sticky;
        top: 0;
        z-index: 1200;
    }

    .content-header {
        flex-direction: row;
        align-items: center;
        gap: 15px;
        justify-content: space-between;
        margin: 0;
        padding-left: 15px;
        padding-right: 15px;
        position: relative;
        top: auto;
        z-index: auto;
    }

    .header-left {
        order: 1;
    }

    .book-controls {
        order: 2;
    }

    .chapter-header h1 {
        font-size: 1.8rem;
    }

    .content-body h2 {
        font-size: 1.9rem;
    }

    .content-wrapper {
        padding: 15px;
    }

    .content-body {
        font-size: 15px;
    }
}

@media (max-width: 575.98px) {
    .book-header {
        padding: 10px 0;
    }

    .book-title h1 {
        font-size: 1.5rem;
    }

    .book-subtitle {
        font-size: 0.9rem;
    }

    .book-container {
        justify-content: flex-start;
    }

    /* Remove Bootstrap container margins on mobile for full width */
    .book-container .container {
        padding-left: 0;
        padding-right: 0;
        margin-left: 0;
        margin-right: 0;
        width: 100%;
    }

    .content-column {
        justify-content: flex-start;
        align-items: flex-start;
    }

    .toc-column {
        width: 100%;
    }

    .content-top-sticky {
        margin-top: -10px;
        margin-left: -10px;
        margin-right: -10px;
        position: sticky;
        top: 0;
        z-index: 1200;
    }

    .content-header {
        flex-direction: row;
        align-items: center;
        gap: 10px;
        justify-content: space-between;
        margin: 0;
        padding-left: 10px;
        padding-right: 10px;
        position: relative;
        top: auto;
        z-index: auto;
    }

    .header-left {
        order: 1;
    }

    .book-controls {
        order: 2;
    }

    .chapter-header h1 {
        font-size: 1.6rem;
    }

    .content-wrapper {
        padding: 10px;
    }

    .content-body {
        font-size: 14px;
    }

    .step {
        flex-direction: column;
        text-align: center;
    }

    .step-number {
        margin-right: 0;
        margin-bottom: 10px;
        align-self: center;
    }
}

/* AI Input Field Styles */
.ai-input-container {
    margin-left: 0px;
    flex: 1;
    max-width: 460px;
    display: flex;
    align-items: center;

    .ai-input-wrapper {
        position: relative;
        width: 100%;
        display: flex;
        align-items: center;

        .ai-input-icon {
            position: absolute;
            left: 10px;
            top: 50%;
            transform: translateY(-50%);
            color: #6c757d;
            z-index: 2;
            pointer-events: none;
        }

        /* Override Bootstrap form-control styles with higher specificity */
        .form-control.ai-input {
            display: block;
            height: 36px;
            width: 300px;
            padding: 5px 10px 5px 35px;
            font-size: 14px;
            transition: all 0.1s ease;
            background-color: #fafafa;
            border: 1px solid #c2c8cf;
            box-shadow: none;
        }

        .form-control.ai-input:focus {
            outline: none;
            border-color: #6998b6;
            box-shadow: 0 0 4px 0px rgb(23 140 255 / 83%);
            background-color: #fff;
        }

        .form-control.ai-input::placeholder {
            color: #6c757d;
            font-style: italic;
        }
    }
}

/* Selection Indicator Styles */
#selectionIndicator {
    background-color: #17a2b8 !important;
    color: white !important;
    padding: 0 10px !important;
    min-height: 30px !important;
    line-height: 28px !important;
    border-radius: 4px !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    margin-left: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    vertical-align: middle !important;
    text-shadow: 0 0 1px black !important;
    animation: fadeIn 0.3s ease-in-out !important;
    box-sizing: border-box !important;
}

.text-to-speech-btn {
    background: #f7f7f7 !important;
    border: 1px solid #c0cad3;
    color: #6e618e !important;
    cursor: pointer !important;
    padding: 0 10px !important;
    min-height: 30px !important;
    line-height: 1 !important;
    margin-left: 8px !important;
    font-size: 12px !important;
    border-radius: 4px !important;
    vertical-align: middle !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    text-shadow: 0 0 1px #ffffff !important;

    &:hover {
        background-color: #fefefe !important;
        border-color: #c5c5c5 !important;
        transform: scale(1.05) !important;
    }

    &:active {
        border-color: #b2b2b2 !important;
        background-color: #eaeaea !important;
        transform: scale(1.05) !important;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-2px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* AI Dialog Overlay Styles */
.ai-dialog-overlay {
    position: fixed;
    bottom: 10px;
    right: 10px;
    width: 400px;
    max-height: calc(100vh - 60px); /* Ensure dialog doesn't exceed viewport height minus margins */
    height: 500px;
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    display: none;
    flex-direction: column;
    cursor: default;
    resize: none; /* Prevent browser default resize */

    &.show {
        display: flex;
    }

    &.minimized {
        bottom: 5px !important;
        top: auto !important;
        /* Remove fixed positioning to allow JavaScript to control positioning */
        /* right: 25px !important; */
        /* left: auto !important; */
        height: 47px !important;
        width: 220px !important;

        .ai-dialog-content {
            display: none;
        }

        /* Hide resize handle when minimized */
        .ai-dialog-resize-handle {
            display: none;
        }
    }

    .ai-dialog-minimize:active,
    .ai-dialog-close:active {
        outline: none !important;
    }

    .ai-dialog-minimize:focus,
    .ai-dialog-close:focus {
        outline: none !important;
    }

    /* Resize handle */
    .ai-dialog-resize-handle {
        position: absolute;
        bottom: 0;
        right: 0;
        width: 15px;
        height: 15px;
        cursor: nw-resize;
        background: linear-gradient(-45deg, transparent 30%, #ccc 30%, #ccc 40%, transparent 40%, transparent 60%, #ccc 60%, #ccc 70%, transparent 70%);
        border-radius: 0 0 8px 0;
        z-index: 10;
    }

    .ai-dialog-resize-handle:hover {
        background: linear-gradient(-45deg, transparent 30%, #999 30%, #999 40%, transparent 40%, transparent 60%, #999 60%, #999 70%, transparent 70%);
    }

    .ai-dialog-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 12px;
        background-color: #6c757d;
        border-bottom: 1px solid #495057;
        border-radius: 8px 8px 0 0;
        cursor: move;

        .ai-dialog-title {
            font-weight: 600;
            color: #ffffff;
            font-size: 15px;
            text-shadow: 1px 0px 1px black;
        }

        .ai-dialog-controls {
            display: flex;
            gap: 4px;

            .btn {
                padding: 4px 8px;
                font-size: 12px;
                border: 1px solid #495057;
                background-color: #495057;
                color: #ffffff;
                border-radius: 4px;
                transition: all 0.2s ease;

                &:hover {
                    background-color: #343a40;
                    border-color: #212529;
                }
            }
        }
    }

    .ai-dialog-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: auto;
        height: calc(100% - 40px);

        .ai-messages {
            flex: 1;
            padding: 16px;
            overflow-y: auto;
            background-color: #fff;
        }

        .ai-dialog-input-container {
            padding: 16px;
            border-top: 1px solid #dee2e6;
            background-color: #f8f9fa;
            border-radius: 0 0 8px 8px;
        }

        .ai-dialog-input-wrapper {
            display: flex;
            gap: 8px;
            align-items: center;
        }

        .ai-dialog-input {
            flex: 1;
            border: 1px solid #ced4da;
            border-radius: 20px;
            padding: 8px 16px;
            font-size: 14px;
            transition: border-color 0.2s ease;

            &:focus {
                border-color: #007bff;
                box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
                outline: none;
            }
        }

        .ai-dialog-send {
            padding: 7px 12px 8px 8px;
            border-radius: 20px;
            width: 45px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: none;
            background-color: #007bff;
            color: white;
            transition: background-color 0.2s ease;

            &:hover {
                background-color: #0056b3;
            }

            &:active {
                background-color: #004085;
            }

            .glyphicon {
                font-size: 15px;
            }
        }
    }
}

/* AI Message Styles */
.ai-message {
    margin-bottom: 16px;
    padding: 12px;
    border-radius: 8px;
    max-width: 100%;

    &.user-message {
        background-color: #e3f2fd;
        border-left: 4px solid #2196f3;
        margin-left: 20px;
    }

    &.ai-response {
        background-color: #f3e5f5;
        border-left: 4px solid #9c27b0;
        margin-right: 20px;

        .message-content strong {
            color: #7b1fa2;
        }
    }

    .message-content {
        font-size: 14px;
        line-height: 1.4;
        color: #333;

        & strong {
            color: #355d72;
        }

        & > strong:first-child {
            color: #000;
        }

        ul, ol {
            margin-left: -18px;
        }
    }
}

/* Responsive adjustments for AI input */
@media (max-width: 768px) {
    .ai-input-container {
        max-width: 200px;
        margin-left: 10px;
    }

    .ai-dialog-overlay {
        width: 90vw;
        right: 5vw;
        left: 5vw;
        bottom: 10px;
        max-height: calc(100vh - 40px); /* Adjust for mobile margins */
    }

    .ai-dialog-overlay.minimized {
        width: 90vw;
        right: 10px;
        left: 10px;
        bottom: 10px;
    }

    .ai-dialog-input-container {
        padding: 12px;
    }

    .ai-dialog-input-wrapper {
        gap: 6px;
    }

    .ai-dialog-input {
        padding: 6px 12px;
        font-size: 13px;
    }

    .ai-dialog-send {
        width: 32px;
        height: 32px;
        padding: 6px 10px;
    }
}

/* Additional responsive adjustments for very small screens */
@media (max-height: 600px) {
    .ai-dialog-overlay {
        height: calc(100vh - 60px);
        max-height: calc(100vh - 60px);
    }
}

/* Ensure dialog is visible on medium screens */
@media (min-width: 769px) and (max-width: 1024px) {
    .ai-dialog-overlay {
        width: 350px;
        right: 10px;
        bottom: 10px;
    }
}

.toc-icon {
    margin-right: 6px;
    font-size: 15px;
    position: relative;
    top: 3px;
    color: #929292;
}

.activities-icon {
    margin-right: 6px;
    font-size: 15px;
    position: relative;
    top: 3px;
    color: #929292;
}

/* Podcast Player Styles */
.podcast-player-container {
    padding: 20px 0;
    max-width: 500px;

    .podcast-player {
        background-color: #f8f9fa;
        border: 1px solid #dee2e6;
        border-radius: 65px;
        padding: 10px 16px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        margin-top: 0;
    }

    .podcast-controls {
        display: flex;
        align-items: center;
        gap: 20px;
        flex-wrap: wrap;
    }

    .podcast-btn {
        background-color: #007bff;
        color: white;
        border: none;
        border-radius: 35px;
        width: 42px;
        height: 42px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
        font-size: 0;
        position: relative;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

        &:hover {
            background-color: #0056b3;
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        }

        &:active {
            transform: translateY(0);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .play-icon::before {
            content: '';
            width: 0;
            height: 0;
            border-left: 12px solid white;
            border-top: 8px solid transparent;
            border-bottom: 8px solid transparent;
            margin-left: 3px;
        }

        .pause-icon {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 3px;

            &::before,
            &::after {
                content: '';
                width: 3px;
                height: 16px;
                background-color: white;
                border-radius: 1px;
            }
        }
    }

    .podcast-progress-container {
        flex: 1;
        display: flex;
        align-items: center;
        gap: 12px;
        min-width: 140px;
    }

    .podcast-time-display {
        font-size: 14px;
        font-weight: 500;
        color: #495057;
        min-width: 40px;
        text-align: center;
    }

    .podcast-progress-bar {
        flex: 1;
        height: 8px;
        background-color: #e9ecef;
        border-radius: 4px;
        position: relative;
        cursor: pointer;
        overflow: hidden;
    }

    .podcast-progress {
        height: 100%;
        background-color: #007bff;
        border-radius: 4px;
        width: 0%;
        transition: width 0.1s ease;
    }

    .podcast-progress-handle {
        position: absolute;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 16px;
        height: 16px;
        background-color: #007bff;
        border-radius: 50%;
        cursor: pointer;
        left: 0%;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        transition: left 0.1s ease;

        &:hover {
            background-color: #0056b3;
            transform: translate(-50%, -50%) scale(1.1);
        }
    }

    .podcast-speed-control {
        position: relative;
    }

    .speed-btn {
        background-color: #6c757d;
        border: none;
        border-radius: 30px;
        width: 62px;
        height: 28px;
        font-size: 13px;
        color: white;
        cursor: pointer;
        transition: all 0.2s ease;
        position: relative;

        &:hover {
            background-color: #5a6268;
        }

        &::after {
            content: '▼';
            font-size: 10px;
            margin-left: 4px;
        }
    }

    .speed-menu {
        position: absolute;
        top: -220px;
        left: 50%;
        transform: translateX(-50%);
        background-color: white;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        display: none;
        flex-direction: column;
        width: 80px;
        z-index: 1000;
        max-height: 200px;
        overflow-y: auto;
        overflow-x: hidden;

        &.show {
            display: flex;
        }

        & button {
            border: none;
            background-color: transparent;
            padding: 8px 12px;
            cursor: pointer;
            transition: background-color 0.2s ease;
            font-size: 13px;
            text-align: center;
            color: #495057;
            white-space: nowrap;
            width: 100%;
            box-sizing: border-box;

            &:hover {
                background-color: #f8f9fa;
            }

            &.active {
                background-color: #007bff;
                color: white;
            }

            &:first-child {
                border-radius: 8px 8px 0 0;
            }

            &:last-child {
                border-radius: 0 0 8px 8px;
            }
        }
    }
}

/* Dark Theme Podcast Styles */
.dark-theme {
    .podcast-link {
        border-top-color: #404040;
    }

    .podcast-toc-link {
        color: #adb5bd;

        &:hover {
            background-color: #404040;
            color: #fff;
            text-decoration: none;
        }

        &.active {
            background-color: #44464b;
            color: #d5dde4;
            text-shadow: 0 0 black;
            text-decoration: none;
            border-radius: 4px;
        }
    }

    .podcast-player {
        background-color: #404040;
        border-color: #555555;
    }

    .podcast-time-display {
        color: #adb5bd;
    }

    .podcast-progress-bar {
        background-color: #555555;
    }

    .speed-menu {
        background-color: #2d2d2d;
        border-color: #555555;

        & button {
            &:hover {
                background-color: #404040;
                color: #e9ecef;
            }

            &.active {
                background-color: #007bff;
                color: white;
            }
        }
    }
}

/* Activities Page Styles */
.activities-container {
    padding: 0;

    .activities-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
        margin-bottom: 30px;
        align-items: stretch;

        .activity-tile {
            background-color: #fff;
            border: 1px solid #e9ecef;
            border-radius: 8px;
            padding: 0;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            text-align: center;
            overflow: hidden;
            position: relative;
            display: flex;
            flex-direction: column;
            height: 100%;

            &:hover {
                transform: translateY(-2px);
                box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
                border-color: #87a4c2;
            }

            &:active {
                transform: translateY(0);
                box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            }

            .activity-image {
                width: 100%;
                position: relative;
                aspect-ratio: 16/11; /* to make tiles of same height */
                overflow: hidden;

                & img {
                    width: 100%;
                    height: 100%;
                    object-fit: cover;
                    object-position: top left;
                    display: block;
                    border: none;
                    border-radius: 8px 8px 0 0;
                }
            }

            .activity-info {
                background: #f8f8f8;
                color: #3d3d3d;
                padding: 10px;
                text-align: center;
                flex: 1;
                display: flex
;
                align-items: center;
                justify-content: center;
                border-top: 1px solid #d2d2d2;

                .activity-title {
                    margin: 0;
                    line-height: 1.3;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    width: 100%;
                }

                .activity-desc {
                    display: none;
                }
            }

        }
    }

    .activity-content-area {
        .activity-header {
            margin-top: 10px;
            margin-bottom: 5px;

            .back-to-activities {
                background-color: #f6f6f6;
                border-color: #c8cbd0;
                color: #4d4d4d;
                padding: 8px 16px;
                border-radius: 4px;
                font-size: 14px;
                transition: all 0.2s ease;
                &:hover {
                    background-color: #e1e6ec;
                    border-color: #a4a7ac;
                    text-decoration: none;
                }

                &:focus {
                    outline: none;
                }
            }
        }
    }
}

/* Dark Theme Activities Styles */
.dark-theme {
    .activities-toc-link {
        color: #adb5bd;

        &:hover {
            background-color: #404040;
            color: #fff;
            text-decoration: none;
        }

        &.active {
            background-color: #44464b;
            color: #d5dde4;
            text-shadow: 0 0 black;
            text-decoration: none;
            border-radius: 4px;
        }
    }

    .content-body h2 {
        border-bottom: 2px solid #696d72;
    }

    .os-title-label,
    .os-number,
    .os-title {
        color: #aebbc8 !important;
    }

    .os-caption {
        color: #b5bbc0 !important;
    }

    .activities-container {
        .activities-grid {
            .activity-tile {
                background-color: #2d2d2d;
                border-color: #404040;
                color: #e9ecef;

                &:hover {
                    /* border-color: #007bff; */
                    background-color: #444444;
                }

                .activity-image {
                    & img {
                        border: none;
                    }
                }

                .activity-info {
                    .activity-title {
                        color: #333333;
                    }

                    .activity-desc {
                        display: none;
                    }
                }
            }
        }

        .activity-content-area {
            .activity-header {
                .back-to-activities {
                    color: #d8d8d8;
                    background-color: #495057;
                    border-color: #495057;

                    &:hover {
                        background-color: #343a40;
                        border-color: #343a40;
                    }
                }
            }
        }
    }
}

/* Responsive Activities Styles */
@media (max-width: 768px) {
    .activities-container {
        .activities-grid {
            grid-template-columns: repeat(2, 1fr);
            gap: 15px;
            align-items: stretch;

            .activity-tile {
                .activity-info {
                    .activity-title {
                        font-size: 1rem;
                    }
                }
            }
        }
    }
}

@media (max-width: 575px) {
    .activities-container {
        .activities-grid {
            grid-template-columns: 1fr;
            gap: 12px;
            align-items: stretch;

            .activity-tile {
                .activity-info {
                    .activity-title {
                        font-size: 0.95rem;
                    }
                }
            }
        }
    }
}

/* Section Navigation Styles */
.section-navigation {
    margin-top: 40px;
    padding: 30px 0 20px;
    border-top: 2px solid #e9ecef;
}

.nav-links {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    text-decoration: none;
    color: #495057;
    transition: all 0.3s ease;
    min-width: 200px;
    max-width: 300px;
    flex: 1;

    &:hover {
        background-color: #e9ecef;
        border-color: #adb5bd;
        text-decoration: none;
        color: #2c3e50;
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    &:active {
        transform: translateY(0);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
}

.poll-start {
    display: inline-block;
    width: 82px;
    & a {
        display: inline-block;
        text-align: center;
        width: 68px;
        height: 55px;
        margin: 4px 10px 5px 0;
        padding: 5px 13px;
        line-height: 1.2;
        background-color: #fbfcfa;
        border: 1px solid #d1decd;
        border-radius: 4px;
        text-decoration: none;


        &:hover {
            background-color: #e9f9dc;
            border: 1px solid #7eab6d;
        }

        &:active {
            background-color: #c2deaa;
            border: 1px solid #3a8b1c;
        }
    }
}

.nav-prev {
    justify-content: flex-start;
    text-align: left;
}

.nav-next {
    justify-content: flex-end;
    text-align: right;
}

.nav-arrow {
    font-size: calc(20px * var(--bookviewer-font-scale, 1));
    font-weight: bold;
    color: #6c757d;
    flex-shrink: 0;
}

.nav-prev .nav-arrow {
    margin-right: 12px;
}

.nav-next .nav-arrow {
    margin-left: 12px;
}

.nav-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-label {
    font-size: 12px;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-title {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
    color: #2c3e50;
}

.nav-spacer {
    flex: 1;
    min-width: 200px;
}

/* Compact inline navigation for generated unit/chapter pages */
.section-navigation-inline {
    margin-top: 0;
    margin-bottom: 16px;
    padding: 0;
    border-top: 0;
    display: flex;
    justify-content: flex-end;
}

.nav-links-inline {
    justify-content: flex-end;
    gap: 10px;
}

.nav-link-icon {
    min-width: auto;
    max-width: none;
    width: calc(42px * var(--bookviewer-font-scale, 1));
    height: calc(42px * var(--bookviewer-font-scale, 1));
    padding: 0;
    border-radius: 10px;
    justify-content: center;
    flex: 0 0 calc(42px * var(--bookviewer-font-scale, 1));
}

.nav-link-icon .nav-arrow {
    margin: 0 !important;
}

.nav-link-disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: auto;
    transform: none !important;
    box-shadow: none !important;
}

/* Dark Theme Navigation Styles */
.dark-theme {
    .section-navigation {
        border-top-color: #404040;
    }

    .nav-link {
        background-color: #2d2d2d;
        border-color: #404040;
        color: #adb5bd;

        &:hover {
            background-color: #404040;
            border-color: #555555;
            color: #e9ecef;
        }
    }

    .nav-arrow {
        color: #adb5bd;
    }

    .nav-label {
        color: #adb5bd;
    }

    .nav-title {
        color: #e9ecef;
    }
}

/* Responsive Navigation Styles */
@media (max-width: 768px) {
    .nav-links {
        flex-direction: column;
        gap: 15px;
    }

    .nav-link {
        max-width: 100%;
        min-width: auto;
        width: 100%;
    }

    .nav-prev, .nav-next {
        justify-content: center;
        text-align: center;
    }

    .nav-spacer {
        display: none;
    }

    .section-navigation-inline {
        margin-bottom: 12px;
    }

    .nav-links-inline {
        flex-direction: row;
        justify-content: flex-end;
    }

    .nav-link-icon {
        width: calc(36px * var(--bookviewer-font-scale, 1));
        height: calc(36px * var(--bookviewer-font-scale, 1));
        flex-basis: calc(36px * var(--bookviewer-font-scale, 1));
        border-radius: 9px;
    }

    .chapter-header-row {
        position: relative;
        align-items: center;
        margin-bottom: 20px;
    }

    .chapter-header-row .chapter-header {
        margin-bottom: 0;
        text-align: left;
        line-height: 36px;
    }

    .chapter-header-row .section-navigation-inline {
        float: right;
        margin-top: 0;
    }

    .chapter-header-row .chapter-tabs-btn-wrap {
        display: inline-block;
        margin-top: 0;
        margin-left: 20px;
    }

    .chapter-header-row .chapter-tabs-btn-group {
        margin-top: 0;
    }
}

@media (max-width: 575px) {
    .section-navigation {
        margin-top: 30px;
        padding: 20px 0 15px;
    }

    .nav-link {
        padding: 12px 15px;
    }

    .nav-title {
        font-size: 13px;
    }

    .nav-arrow {
        font-size: 18px;
    }

    .nav-prev .nav-arrow {
        margin-right: 8px;
    }

    .nav-next .nav-arrow {
        margin-left: 8px;
    }
}

.fa-regular {
    font-size: 17px;
    margin-top: 3px;
}