body {
    margin: 0;
    font-family: sans-serif;
    background: #f5f5f5;
}
.layout {
    display: flex;
    height: 100vh;
    flex-direction: row; /* sidebar on the right */
}

.content-wrapper {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}


.toc-sidebar {
    width: 300px;
    min-width: 280px;
    border-right: 2px solid #e0e0e0;
    background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 20px);
    max-height: calc(100vh - 20px);
    position: sticky;
    top: 10px;
    align-self: flex-start;
    order: 1; /* نمایش در سمت چپ */
    z-index: 5;
    border-radius: 8px 0 0 8px;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
    transition: width 0.3s ease, min-width 0.3s ease;
}

.toc-sidebar.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right: none;
    padding: 0;
    margin: 0;
}

.toc-sidebar.collapsed .toc-content {
    display: none;
}

.toc-sidebar.collapsed .toc-header {
    padding: 10px 8px;
}

.toc-sidebar.collapsed .toc-header h3 {
    display: none;
}

.toc-sidebar.collapsed .toc-header-buttons {
    justify-content: center;
    width: 100%;
}

.toc-sidebar.collapsed .toc-expand-all {
    display: none;
}

.book-text-wrapper {
    flex: 1;
    min-width: 0; /* برای جلوگیری از overflow */
    order: 2; /* نمایش در سمت راست */
    position: relative;
    padding: 20px;
    max-width: 900px;
    margin: 0 auto;
}

/* ایجاد حاشیه خالی در سمت راست برای جلوگیری از قرار گرفتن Floating Toolbar روی متن کتاب در نمایش دسکتاپ */
.book-text-wrapper {
    /*padding-right: 120px;*/
}

.toc-reopen-btn {
    position: fixed;
    left: 20px; /* برای RTL در سمت چپ */
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 20px;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toc-reopen-btn:hover {
    background: linear-gradient(135deg, #f57c00 0%, #e65100 100%);
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 6px 16px rgba(255, 152, 0, 0.5);
}

.toc-reopen-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.toc-header {
    padding: 10px 12px;
    border-bottom: 2px solid #e0e0e0;
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

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

.toc-header h3 {
    margin: 0;
    font-size: 18px;
    color: #333;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toc-icon {
    font-size: 18px;
}

.toc-toggle-sidebar {
    background: #ff9800;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(255, 152, 0, 0.3);
    min-width: 36px;
}

.toc-toggle-sidebar:hover {
    background: #f57c00;
    transform: scale(1.05);
    box-shadow: 0 3px 6px rgba(255, 152, 0, 0.4);
}

.toc-toggle-sidebar:active {
    transform: scale(0.95);
}

.toc-expand-all {
    background: #2196f3;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
}

.toc-expand-all:hover {
    background: #1976d2;
    transform: scale(1.05);
    box-shadow: 0 3px 6px rgba(33, 150, 243, 0.4);
}

.toc-expand-all:active {
    transform: scale(0.95);
}

.toc-content {
    flex: 1;
    overflow-y: auto;
    padding: 5px 0;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 #f7fafc;
}

.toc-content::-webkit-scrollbar {
    width: 8px;
}

.toc-content::-webkit-scrollbar-track {
    background: #f7fafc;
    border-radius: 4px;
}

.toc-content::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.toc-content::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.table-selector {
    padding: 12px 16px;
    border-bottom: 1px solid #ddd;
    background: #fff;
}

.table-selector label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #666;
}

.table-buttons {
    display: flex;
    gap: 8px;
}

.table-btn {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #2196f3;
    background: #fff;
    color: #2196f3;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.table-btn:hover {
    background: #e3f2fd;
    transform: translateY(-1px);
}

.table-btn.active {
    background: #2196f3;
    color: #fff;
    box-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
}

.table-btn.active:hover {
    background: #1976d2;
}

/* رنگ‌های مختلف برای کتابخانه‌ها */
.table-btn[data-table="bookscontents"].active {
    background: #4caf50;
    border-color: #4caf50;
    opacity: 1;
}

.table-btn[data-table="bookscontents"].active:hover {
    background: #45a049;
    opacity: 1;
}

.table-btn[data-table="bookscontents"]:not(.active) {
    border-color: #bdbdbd;
    color: #757575;
    background: #f5f5f5;
}

.table-btn[data-table="bookscontents"]:not(.active):hover {
    background: #eeeeee;
    border-color: #9e9e9e;
    color: #616161;
}

.table-btn[data-table="bookscontents2"].active {
    background: #ff9800;
    border-color: #ff9800;
    opacity: 1;
}

.table-btn[data-table="bookscontents2"].active:hover {
    background: #f57c00;
    opacity: 1;
}

.table-btn[data-table="bookscontents2"]:not(.active) {
    border-color: #bdbdbd;
    color: #757575;
    background: #f5f5f5;
}

.table-btn[data-table="bookscontents2"]:not(.active):hover {
    background: #eeeeee;
    border-color: #9e9e9e;
    color: #616161;
}

/* رنگ لیست کتاب‌ها بر اساس کتابخانه انتخاب شده */
.sidebar.library-1 {
    border-right: 2px solid #4caf50;
}

.sidebar.library-1 .list li:hover,
.sidebar.library-1 .list li.active {
    background: #e8f5e9;
    border-right: 3px solid #4caf50;
}

.sidebar.library-2 {
    border-right: 2px solid #ff9800;
}

.sidebar.library-2 .list li:hover,
.sidebar.library-2 .list li.active {
    background: #fff3e0;
    border-right: 3px solid #ff9800;
}

.sidebar {
    width: 280px;
    border-right: 1px solid #ddd;
    background: #fafafa;
    overflow-y: auto;
    order: 2; /* نمایش در سمت راست */
    transition: border-color 0.3s ease;
}

/* حالت جمع‌شده برای sidebar اصلی لیست کتاب‌ها */
.sidebar.collapsed {
    width: 0;
    min-width: 0;
    padding: 0;
    border-right: none;
    overflow: hidden;
}

.sidebar.collapsed .table-selector,
.sidebar.collapsed .books-header,
.sidebar.collapsed .search,
.sidebar.collapsed .sort-controls,
.sidebar.collapsed .status,
.sidebar.collapsed .list {
    display: none;
}

.content {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    background: #fff;
    order: 1; /* نمایش در سمت چپ */
    scrollbar-width: auto;
    scrollbar-color: #888 #f0f0f0;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.content::-webkit-scrollbar {
    width: 20px;
}

.content::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 10px;
    border: 2px solid #e0e0e0;
}

.content::-webkit-scrollbar-thumb {
    background: #666;
    border-radius: 10px;
    border: 3px solid #f0f0f0;
    min-height: 50px;
}

.content::-webkit-scrollbar-thumb:hover {
    background: #444;
    border: 2px solid #f0f0f0;
}

.sidebar .search {
    padding: 12px 16px;
    border-bottom: 1px solid #ddd;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    position: sticky;
    top: 0;
    background: #fafafa;
    z-index: 10;
}
.sort-controls {
    padding: 8px 16px;
    border-bottom: 1px solid #ddd;
}

.sort-btn {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #2196f3;
    background: #2196f3;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s;
}

.sort-btn:hover {
    background: #1976d2;
}

.books-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #ddd;
}

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

.books-header h2 {
    margin: 0;
    flex: 1;
}

.global-search-trigger-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.global-search-trigger-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.4);
}

.global-search-trigger-btn:active {
    transform: scale(0.95);
}

.sidebar-toggle-btn {
    background: #9e9e9e;
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(158, 158, 158, 0.3);
}

.sidebar-toggle-btn:hover {
    background: #757575;
    box-shadow: 0 4px 8px rgba(97, 97, 97, 0.4);
}

.sidebar-toggle-btn:active {
    transform: scale(0.95);
}

.sidebar-reopen-btn {
    position: fixed;
    right: 16px;
    top: 80px;
    background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
    color: #fff;
    border: none;
    border-radius: 20px;
    width: 48px;
    height: 48px;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
    z-index: 120;
    transition: all 0.3s ease;
}

.sidebar-reopen-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(76, 175, 80, 0.5);
}

.sidebar-reopen-btn:active {
    transform: scale(0.95);
}

.sidebar .status {
    padding: 0 16px 12px;
    color: #666;
    font-size: 13px;
}
.sidebar input[type="text"],
.sidebar select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
}
.sidebar button {
    padding: 8px 12px;
    border: 1px solid #1976d2;
    background: #2196f3;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}
.sidebar button:hover {
    background: #1976d2;
}
.sidebar h2 {
    margin: 0;
    padding: 16px;
    border-bottom: 1px solid #ddd;
    font-size: 16px;
}
mark {
    background: #ffeb3b;
    color: #000;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600; /* کلمات هایلایت شده پررنگ‌تر */
}
.list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.list li {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}
.list li:hover,
.list li.active {
    background: #e8f0fe;
}
.title {
    font-weight: bold;
    margin-bottom: 8px;
}
.empty {
    color: #888;
    padding: 20px;
}


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

.toc-sublist {
    list-style: none;
    margin: 0;
    padding: 0;
    padding-right: 8px;
    margin-top: 2px;
}

.toc-item {
    margin-bottom: 2px;
    border-radius: 6px;
    transition: all 0.2s ease;
    font-size: 16px;
    line-height: 1.6;
    position: relative;
}

.toc-item-content {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.toc-item:hover .toc-item-content {
    background: linear-gradient(90deg, #e8f0fe 0%, #f0f7ff 100%);
    transform: translateX(-2px);
}

.toc-item.active .toc-item-content {
    background: linear-gradient(90deg, #e3f2fd 0%, #bbdefb 100%);
    border-right: 4px solid #2196f3;
    box-shadow: 0 2px 4px rgba(33, 150, 243, 0.2);
    font-weight: 600;
}

.toc-item.active .toc-item-text {
    color: #1976d2;
}

.toc-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    font-size: 12px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    border-radius: 3px;
    user-select: none;
}

.toc-toggle:hover {
    background: rgba(33, 150, 243, 0.1);
    color: #2196f3;
    transform: scale(1.1);
}

.toc-toggle-spacer {
    display: inline-block;
    width: 24px;
    flex-shrink: 0;
}

.toc-item-text {
    flex: 1;
    color: #333;
    transition: color 0.2s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.toc-item-has-children .toc-item-text {
    font-weight: 500;
}

.toc-item-expanded .toc-toggle {
    color: #2196f3;
}

.toc-item-number {
    font-weight: 600;
    color: #666;
    margin-left: 4px;
    flex-shrink: 0;
}

.toc-level-1 .toc-item-number {
    font-weight: 700;
    color: #333;
    font-size: 17px;
}

.toc-level-2 .toc-item-number {
    font-size: 16px;
}

.toc-level-3 .toc-item-number,
.toc-level-4 .toc-item-number,
.toc-level-5 .toc-item-number,
.toc-level-6 .toc-item-number {
    font-size: 15px;
}

.toc-level-1 .toc-item-content {
    font-weight: 700;
    font-size: 17px;
    padding: 10px 12px;
    background: linear-gradient(90deg, #f5f5f5 0%, #fafafa 100%);
    border-right: 2px solid #e0e0e0;
}

.toc-level-1:hover .toc-item-content {
    background: linear-gradient(90deg, #e8f0fe 0%, #f0f7ff 100%);
    border-right-color: #2196f3;
}

.toc-level-1.active .toc-item-content {
    background: linear-gradient(90deg, #e3f2fd 0%, #bbdefb 100%);
    border-right: 4px solid #2196f3;
}

.toc-level-2 .toc-item-content {
    padding-right: 16px;
    font-size: 16px;
}

.toc-level-3 .toc-item-content {
    padding-right: 24px;
    font-size: 15px;
    color: #555;
}

.toc-level-4 .toc-item-content {
    padding-right: 32px;
    font-size: 15px;
    color: #666;
}

.toc-level-5 .toc-item-content {
    padding-right: 40px;
    font-size: 14px;
    color: #666;
}

.toc-level-6 .toc-item-content {
    padding-right: 48px;
    font-size: 14px;
    color: #666;
}

.book-content {
    line-height: 2.2; /* افزایش برای خوانایی بهتر */
    padding-bottom: 50px; /* فاصله اضافی در انتها برای اسکرول راحت‌تر */
    font-size: 18px; /* فونت پیش‌فرض بزرگ‌تر */
    letter-spacing: 0.5px; /* فاصله بین حروف */
    word-spacing: 2px; /* فاصله بین کلمات */
    color: #1a1a1a; /* متن تیره‌تر برای کنتراست بهتر */
    text-align: justify; /* تراز متن */
}

.book-content.content-dimmed {
    filter: brightness(0.5);
}

.book-content.content-dimmed mark {
    filter: brightness(2);
}

.book-content p {
    margin-bottom: 1.5em; /* فاصله بیشتر بین پاراگراف‌ها */
    text-indent: 1.5em; /* تورفتگی اول پاراگراف */
}

.book-content h1, .book-content h2, .book-content h3, 
.book-content h4, .book-content h5, .book-content h6 {
    margin-top: 2em;
    margin-bottom: 1em;
    line-height: 1.5;
    color: #2c3e50;
    font-weight: 700;
}

.book-content h1 {
    font-size: 2em;
}

.book-content h2 {
    font-size: 1.75em;
}

.book-content h3 {
    font-size: 1.5em;
}

.book-content h4 {
    font-size: 1.3em;
}

.book-content h5, .book-content h6 {
    font-size: 1.2em;
}

.book-search {
    margin-bottom: 10px;
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 10;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.book-search-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.book-search-row input[type="text"] {
    flex: 1;
    min-width: 140px;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
}

.scroll-progress-inline {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.scroll-progress-inline .scroll-progress-text {
    margin: 0;
}

.content-search-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    padding: 4px 0;
    font-size: 13px;
}

.book-nav-controls {
    display: none; /* مخفی کردن toolbar قدیمی */
}

/* Floating Toolbar - نوار ابزار شناور */
.floating-toolbar {
    position: fixed;
    right: 20px; /* برای RTL در سمت راست */
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border-radius: 16px;
    padding: 12px 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 99; /* کمتر از TOC reopen button (100) و global search (10000) */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    animation: slideInRight 0.4s ease-out;
}

.floating-toolbar-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 28px; /* فضا برای دکمه ضربدر */
}

.toolbar-close-btn {
    position: absolute;
    top: 6px;
    right: 6px; /* در RTL سمت راست نوار = ابتدای نوار */
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(0, 0, 0, 0.08);
    color: #555;
    font-size: 20px;
    line-height: 1;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    padding: 0;
}

.toolbar-close-btn:hover {
    background: rgba(0, 0, 0, 0.14);
    color: #333;
}

.toolbar-open-btn {
    width: 48px;
    height: 48px;
    border: none;
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    color: #fff;
    font-size: 22px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3);
    transition: all 0.2s ease;
    padding: 0;
}

.toolbar-open-btn:hover {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

/* حالت جمع‌شده: فقط دکمه باز کردن */
.floating-toolbar.collapsed {
    padding: 8px;
}

.floating-toolbar.collapsed .toolbar-close-btn,
.floating-toolbar.collapsed .floating-toolbar-body {
    display: none !important;
}

.floating-toolbar.collapsed .toolbar-open-btn {
    display: flex !important;
}

.floating-toolbar.collapsed:hover {
    transform: translateY(-50%) scale(1.02);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

.floating-toolbar:hover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
    transform: translateY(-50%) scale(1.02);
}

.toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toolbar-divider {
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, #e0e0e0, transparent);
    margin: 4px 0;
}

.toolbar-btn {
    width: 48px;
    height: 48px;
    border: none;
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    color: #fff;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3);
    position: relative;
}

.toolbar-btn:hover {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

.toolbar-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(33, 150, 243, 0.3);
}

.toolbar-btn::after {
    content: attr(title);
    position: absolute;
    right: 60px;
    top: 50%;
    transform: translateY(-50%);
    background: #333;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1001;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.toolbar-btn::before {
    content: '';
    position: absolute;
    right: 54px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 0 6px 6px;
    border-color: transparent transparent transparent #333;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1001;
}

.toolbar-btn:hover::after,
.toolbar-btn:hover::before {
    opacity: 1;
}

/* استایل خاص برای دکمه‌های مختلف */
#reading-mode.toolbar-btn {
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.3);
}

#reading-mode.toolbar-btn:hover {
    background: linear-gradient(135deg, #f57c00 0%, #e65100 100%);
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
}

#theme-toggle.toolbar-btn {
    background: linear-gradient(135deg, #9c27b0 0%, #7b1fa2 100%);
    box-shadow: 0 2px 8px rgba(156, 39, 176, 0.3);
}

#theme-toggle.toolbar-btn:hover {
    background: linear-gradient(135deg, #7b1fa2 0%, #6a1b9a 100%);
    box-shadow: 0 4px 12px rgba(156, 39, 176, 0.4);
}

#font-reset.toolbar-btn {
    background: linear-gradient(135deg, #607d8b 0%, #455a64 100%);
    box-shadow: 0 2px 8px rgba(96, 125, 139, 0.3);
}

#font-reset.toolbar-btn:hover {
    background: linear-gradient(135deg, #455a64 0%, #37474f 100%);
    box-shadow: 0 4px 12px rgba(96, 125, 139, 0.4);
}

.scroll-progress-wrapper {
    display: flex;
    align-items: center;
    margin-top: 8px;
    position: relative;
}

.scroll-progress-bar {
    flex: 1;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.scroll-progress-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--progress-width, 0%);
    background: linear-gradient(90deg, #2196f3 0%, #1976d2 100%);
    border-radius: 4px;
    transition: width 0.15s ease-out;
    box-shadow: 0 1px 3px rgba(33, 150, 243, 0.3);
}

.scroll-progress-text {
    min-width: 42px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #2196f3;
    background: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #2196f3;
    display: inline-block;
}

.search-results-count {
    color: #666;
    font-weight: 500;
    flex: 1;
}

.search-results-count .search-stat-click {
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    color: #1976d2;
}

.search-results-count .search-stat-click:hover {
    color: #0d47a1;
}

.search-nav-btn {
    padding: 4px 12px;
    border: 1px solid #2196f3;
    background: #2196f3;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: background-color 0.2s;
}

.search-nav-btn:hover {
    background: #1976d2;
}

.search-nav-btn:disabled {
    background: #ccc;
    border-color: #ccc;
    cursor: not-allowed;
}

.book-heading {
    margin-top: 20px;
    margin-bottom: 10px;
    color: #333;
}

.book-heading h1 {
    font-size: 24px;
    font-weight: bold;
}

.book-heading h2 {
    font-size: 20px;
    font-weight: bold;
}

.book-heading h3 {
    font-size: 18px;
    font-weight: 600;
}

.book-heading h4,
.book-heading h5,
.book-heading h6 {
    font-size: 16px;
    font-weight: 600;
}

/* استایل پاپ‌آپ جستجوی سراسری */
.global-search-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.global-search-popup.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.global-search-popup-content {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

.global-search-popup-header {
    padding: 20px;
    border-bottom: 2px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px 12px 0 0;
}

.global-search-popup-header h3 {
    margin: 0;
    color: #fff;
    font-size: 18px;
    font-weight: 600;
}

.global-search-popup-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    font-size: 28px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
}

.global-search-popup-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.global-search-popup-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.global-search-library-selector {
    margin-bottom: 20px;
    padding: 15px;
    background: #f5f5f5;
    border-radius: 8px;
}

.global-search-library-selector label {
    display: block;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.global-search-library-buttons {
    display: flex;
    gap: 10px;
}

.global-search-lib-btn {
    flex: 1;
    padding: 10px 16px;
    border: 2px solid #ddd;
    background: #fff;
    color: #666;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.global-search-lib-btn:hover {
    border-color: #667eea;
    color: #667eea;
}

.global-search-lib-btn.active {
    background: #667eea;
    border-color: #667eea;
    color: #fff;
}

.global-search-input-wrapper {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.global-search-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
    direction: rtl;
}

.global-search-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.global-search-btn {
    padding: 12px 24px;
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.global-search-btn:hover {
    background: #5568d3;
    transform: translateY(-1px);
}

.global-search-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.global-search-results {
    max-height: 400px;
    overflow-y: auto;
}

.global-search-summary {
    margin-bottom: 12px;
    padding: 10px 14px;
    background: #f5f5f5;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    font-size: 13px;
    color: #333;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.global-search-summary strong {
    font-weight: 700;
}

.global-search-summary-separator {
    color: #999;
}

.global-search-book-result {
    margin-bottom: 20px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s ease;
}

.global-search-book-result:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.global-search-book-header {
    padding: 12px 16px;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.global-search-book-header:hover {
    background: #eeeeee;
}

.global-search-book-title {
    flex: 1;
}

.global-search-book-count {
    background: #667eea;
    color: #fff;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    display: none;
    
}

.global-search-book-snippets {
    padding: 12px 16px;
    display: none;
}

.global-search-book-result.expanded .global-search-book-snippets {
    display: block;
}

.global-search-snippet {
    padding: 10px;
    margin-bottom: 8px;
    background: #fafafa;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    direction: rtl;
    border-right: 3px solid transparent;
}

.global-search-snippet:hover {
    background: #f0f0f0;
    border-right-color: #667eea;
}

.global-search-snippet-text {
    color: #333;
    font-size: 14px;
    line-height: 1.6;
}

.global-search-snippet-text mark {
    background: #ffeb3b;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
}

.global-search-loading {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.global-search-empty {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

/* حالت خواندن (Reading Mode) */
.book-content.reading-mode {
    background: #fef9e7 !important; /* پس‌زمینه کرم */
    color: #2c3e50 !important; /* متن تیره‌تر */
    padding: 30px !important;
    border-radius: 8px;
    max-width: 800px;
    margin: 0 auto;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.book-content.reading-mode p {
    margin-bottom: 1.8em;
}

.book-content.reading-mode h1, 
.book-content.reading-mode h2, 
.book-content.reading-mode h3 {
    color: #1a472a;
}

/* تم شب (Dark Theme) */
.dark-theme .book-content {
    background: #1e1e1e !important;
    color: #e0e0e0 !important;
}

.dark-theme .book-content h1, 
.dark-theme .book-content h2, 
.dark-theme .book-content h3 {
    color: #ffffff;
}

.dark-theme .book-content.reading-mode {
    background: #2d2d2d !important;
    color: #f0f0f0 !important;
}

.dark-theme .book-content mark {
    background: #ffd700;
    color: #000;
}

.dark-theme .content {
    background: #1a1a1a;
}

.dark-theme .book-search {
    background: #2a2a2a;
    border-bottom-color: #444;
}

.dark-theme .book-search input[type="text"] {
    background: #333;
    color: #fff;
    border-color: #555;
}

.dark-theme .search-nav-btn {
    background: #444;
    border-color: #555;
    color: #fff;
}

.dark-theme .search-nav-btn:hover {
    background: #555;
}

.dark-theme .floating-toolbar {
    background: linear-gradient(135deg, #2a2a2a 0%, #1e1e1e 100%);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.dark-theme .toolbar-divider {
    background: linear-gradient(90deg, transparent, #444, transparent);
}

.dark-theme .toolbar-btn::after {
    background: #1a1a1a;
    color: #fff;
    border: 1px solid #444;
}

/* استایل toolbar در حالت خواندن */
.floating-toolbar.reading-mode-active {
    background: linear-gradient(135deg, #fef9e7 0%, #fdf4d8 100%);
    border-color: rgba(26, 71, 42, 0.2);
}

.floating-toolbar.reading-mode-active .toolbar-btn {
    box-shadow: 0 2px 8px rgba(26, 71, 42, 0.2);
}

/* بهبود tooltip برای RTL */
.toolbar-btn::after {
    direction: rtl;
    text-align: right;
}

/* بهبود دکمه‌ها برای لمس راحت‌تر */
.book-nav-controls .search-nav-btn {
    min-height: 48px;
    min-width: 48px;
    padding: 10px 16px;
    font-size: 16px;
    font-weight: 600;
}
