/* Triple-Column Reader Layout */
:root {
    --header-height: 70px;
    --sidebar-width: 320px;
    --chat-panel-width: 360px;
    --chat-panel-collapsed-width: 50px;
}

.reader-mode {
    background-color: var(--bg-primary);
    overflow-x: hidden;
}

/* ========================================
   Hamburger Menu Button Styles
   ======================================== */

/* Base hamburger - HIDDEN by default */
.header .mobile-nav-toggle {
    display: none !important;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    border-radius: var(--toolbar-btn-radius, 50%);
    background: var(--hamburger-bg, var(--toolbar-btn-bg, var(--bg-secondary)));
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast, 0.2s);
    flex-shrink: 0;
}

.header .mobile-nav-toggle svg {
    stroke: var(--hamburger-icon-color, var(--toolbar-btn-color, var(--text-primary)));
    fill: var(--hamburger-icon-color, var(--toolbar-btn-color, var(--text-primary)));
}

.header .mobile-nav-toggle:hover {
    background: var(--hamburger-hover-bg, var(--toolbar-btn-hover-bg, var(--bg-tertiary)));
    transform: translateY(-2px);
}

.header .mobile-nav-toggle:hover svg {
    stroke: var(--hamburger-hover-icon-color, var(--toolbar-btn-hover-color, var(--color-primary)));
    fill: var(--hamburger-hover-icon-color, var(--toolbar-btn-hover-color, var(--color-primary)));
}

/* Show hamburger on MOBILE when enabled */
@media (max-width: 767px) {
    .header .mobile-nav-toggle.show-mobile {
        display: flex !important;
    }
}

/* Show hamburger on TABLET when enabled */
@media (min-width: 768px) and (max-width: 1024px) {
    .header .mobile-nav-toggle.show-tablet {
        display: flex !important;
    }
}

/* Show hamburger on DESKTOP when enabled */
@media (min-width: 1025px) {
    .header .mobile-nav-toggle.show-desktop {
        display: flex !important;
    }
}

/* Hamburger Position - LEFT */
.header.hamburger-left .mobile-nav-toggle {
    order: -1;
}

/* Hamburger Position - RIGHT */
.header.hamburger-right .mobile-nav-toggle {
    order: 99;
}

/* Header Styles */
.header {
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    transition: top 0.3s ease;
}

/* Sticky Header */
.header.header-sticky {
    position: fixed;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0 var(--spacing-xl);
    gap: var(--spacing-md);
    position: relative;
}

/* Header Brand Section Positioning */
.header-brand-section {
    display: flex;
    align-items: center;
}

.header-brand-section.position-left {
    order: 0;
    margin-right: auto;
}

.header-brand-section.position-center {
    order: 1;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.header-brand-section.position-right {
    order: 2;
    margin-left: auto;
}

/* Header Actions Positioning */
.header-actions.position-left {
    order: 0;
    margin-right: auto;
}

.header-actions.position-center {
    order: 1;
    margin: 0 auto;
}

.header-actions.position-right {
    order: 2;
    margin-left: auto;
}

.logo {
    font-size: var(--font-size-xl);
    font-weight: 800;
    transition: transform var(--transition-normal);
}

/* Only apply default gradient if no inline style is set */
.logo:not([style]) {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo:hover {
    transform: scale(1.05);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.header-actions button,
.header-actions .btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--toolbar-btn-radius, 50%) !important;
    background: var(--toolbar-btn-bg, var(--bg-secondary)) !important;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--toolbar-btn-color, var(--text-primary));
}

.header-actions button svg,
.header-actions .btn-icon svg {
    stroke: var(--toolbar-btn-color, var(--text-primary));
}

.header-actions button:hover,
.header-actions .btn-icon:hover {
    background: var(--toolbar-btn-hover-bg, var(--bg-tertiary));
    transform: translateY(-2px);
}

.header-actions button:hover svg,
.header-actions .btn-icon:hover svg {
    stroke: var(--toolbar-btn-hover-color, var(--color-primary));
}

/* Body Layout - FIXED 2025-01-28 */
.reader-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: var(--header-height);
    /* Default: add margin for sticky header */
    min-height: calc(100vh - var(--header-height));
    width: 100%;
    position: relative;
    background: transparent; /* Test marker - remove after confirming fix works */
}

/* When header is NOT sticky, remove margin */
body:not(.has-sticky-header) .reader-body {
    margin-top: 0 !important;
    min-height: 100vh;
}

.reader-main {
    flex: 1;
    padding: var(--spacing-2xl) var(--spacing-xl);
    padding-top: var(--content-top-margin, var(--spacing-2xl));
    /* Use content-top-margin setting from admin, fallback to spacing-2xl */
    max-width: 786.5px;
    width: 786.5px;
    margin: 0 auto;
    position: relative;
}

@media (max-width: 850px) {
    .reader-main {
        width: 100%;
        max-width: 786.5px;
    }
}

aside.reader-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-inline-end: 1px solid var(--border-color);
    position: fixed !important;
    left: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 90;
    transition: transform 0.3s ease;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
    margin: 0 !important;
    padding: 0 !important;
    /* Use CSS variable from UI settings - dynamically set per book */
    top: var(--header-height, 70px) !important;
    height: calc(100vh - var(--header-height, 70px)) !important;
}

.rtl aside.reader-sidebar {
    left: auto;
    right: 0;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.08) !important;
}

/* Sidebar Components */
.sidebar-header {
    padding: 0;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    position: relative;
}

.sidebar-header.hide-search {
    padding-bottom: 0;
    border-bottom: none;
}

/* Mobile Close Button */
.sidebar-close-btn {
    display: none;
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-md);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-primary);
    border: none;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.sidebar-close-btn svg {
    stroke: white;
    width: 18px;
    height: 18px;
}

.sidebar-close-btn:hover {
    background: var(--color-secondary);
    transform: scale(1.05);
}

.sidebar-close-btn:active {
    transform: scale(0.95);
}

/* RTL: Move close button to left */
.rtl .sidebar-close-btn {
    right: auto;
    left: var(--spacing-md);
}

/* Show close button on mobile */
@media (max-width: 1024px) {
    .sidebar-close-btn {
        display: flex;
    }
    
    .sidebar-search {
        padding-right: 50px;
    }
    
    .rtl .sidebar-search {
        padding-right: 0;
        padding-left: 50px;
    }
}

.sidebar-search {
    display: block;
    padding: 12px 16px;
}

.sidebar-search.hidden {
    display: none;
}

.sidebar-search input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sidebar-search input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.1);
}

.sidebar-toc {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 16px 32px;
    direction: ltr;
    background: var(--toc-bg-color, var(--bg-secondary));
    overscroll-behavior: contain;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

/* TOC Title */
.sidebar-toc-title {
    font-size: var(--toc-title-size, 0.85rem);
    font-weight: var(--toc-title-weight, 600);
    color: var(--toc-title-color, var(--text-secondary));
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 16px 0;
    padding-top: 16px; /* Breathing room at the top */
    padding-bottom: 8px;
    border-bottom: 2px solid var(--toc-title-border-color, var(--border-color));
}

.sidebar-toc-title.no-uppercase {
    text-transform: none;
    letter-spacing: normal;
}

/* LTR books - title should align left */
.ltr .sidebar-toc-title {
    text-align: left;
    direction: ltr;
}

/* RTL books - title should align right */
.rtl .sidebar-toc-title {
    text-align: right;
    direction: rtl;
}

/* Restore text direction inside */
.sidebar-toc .toc-list {
    direction: rtl;
}

.ltr .sidebar-toc {
    direction: ltr;
}

.ltr .sidebar-toc .toc-list {
    direction: ltr;
}

/* Custom scrollbar for sidebar - VISIBLE */
.sidebar-toc::-webkit-scrollbar {
    width: 8px;
}

.sidebar-toc::-webkit-scrollbar-track {
    background: transparent;
    margin: 4px 0;
}

.sidebar-toc::-webkit-scrollbar-thumb {
    background: var(--toc-scrollbar-color, var(--border-color));
    border-radius: 4px;
}

.sidebar-toc::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
}

/* Show scrollbar for Firefox */
.sidebar-toc {
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--toc-scrollbar-color, var(--border-color)) transparent;
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-item {
    margin-bottom: var(--spacing-xs);
}

/* TOC Item Header - contains toggle and link */
.toc-item-header {
    display: flex;
    align-items: center;
    gap: 0;
}

/* Dropdown Toggle Button */
.toc-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    margin: 0;
    margin-inline-end: 4px;
    background: var(--bg-tertiary, rgba(0, 0, 0, 0.05));
    border: 1px solid var(--toc-border-color, var(--border-color, #ddd));
    cursor: pointer;
    color: var(--toc-toggle-color, var(--text-secondary));
    border-radius: var(--radius-sm, 4px);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.toc-toggle:hover {
    background: var(--bg-secondary);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

/* Toggle color when chapter is active */
.toc-item.active .toc-toggle {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.toc-toggle-icon {
    transition: transform 0.3s ease;
}

/* Rotate arrow when expanded */
.toc-toggle[aria-expanded="true"] .toc-toggle-icon {
    transform: rotate(180deg);
}

/* RTL support for toggle */
.rtl .toc-toggle-icon {
    transform: rotate(0deg);
}

.rtl .toc-toggle[aria-expanded="true"] .toc-toggle-icon {
    transform: rotate(180deg);
}

.toc-link {
    display: flex;
    align-items: center;
    padding: var(--spacing-md);
    text-decoration: none;
    color: var(--toc-item-color, var(--text-secondary));
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    font-size: var(--toc-item-font-size, var(--font-size-sm));
    font-weight: 500;
    flex: 1;
}

.toc-link:hover {
    background: var(--toc-item-hover-bg, var(--bg-tertiary));
    color: var(--toc-item-hover-color, var(--text-primary));
    padding-inline-start: var(--spacing-lg);
}

.toc-link.active {
    background: var(--toc-active-bg, var(--color-primary));
    color: var(--toc-active-color, white);
    box-shadow: 0 4px 12px rgba(var(--color-primary-rgb), 0.3);
}

.toc-progress-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-gray-300);
    margin-inline-end: var(--spacing-md);
    flex-shrink: 0;
    transition: all 0.2s;
}

.toc-link.active .toc-progress-dot {
    background: white;
    transform: scale(1.2);
}

/* Section Infusion (Sub-Navigation) */
.toc-sublist {
    margin: 0;
    padding: 0;
    padding-inline-start: var(--spacing-2xl);
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s ease;
    opacity: 0;
}

/* Show sublist when expanded */
.toc-sublist.expanded {
    max-height: 2000px;
    margin-top: 5px;
    opacity: 1;
}

.toc-sublink {
    display: block;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-xs);
    color: var(--toc-item-color, var(--text-muted));
    border-inline-start: 1px solid var(--toc-subitem-border-color, var(--border-color));
    transition: all 0.2s;
}

.toc-sublink:hover {
    color: var(--color-primary);
    border-inline-start-color: var(--color-primary);
}

/* Chapter Styles */
.chapter-content {
    background: var(--bg-primary);
}

.chapter-title {
    font-size: var(--font-size-5xl);
    margin-top: 0;
    margin-bottom: var(--spacing-2xl);
    text-align: center;
    font-weight: 800;
}

/* Base content-body styles - only apply when accessibility font size is NOT set */
body:not([data-font-size]) .content-body {
    font-size: var(--font-size-lg);
    line-height: var(--line-height-relaxed);
    color: var(--text-primary);
}

/* When accessibility font size IS set, only apply color (not font-size/line-height) */
body[data-font-size] .content-body {
    color: var(--text-primary);
}

/* Custom Drop Cap Support */
/* Custom Drop Cap & First Word Support */
/* Industry-standard drop cap styling based on traditional typography */
.styling-drop-cap p:first-of-type::first-letter {
    float: var(--direction-start);
    font-size: var(--drop-cap-size, 3.5em);
    line-height: 0.85;
    font-weight: 700;
    color: var(--styling-color, var(--color-primary));
    margin-right: 0.08em;
    margin-top: 0.05em;
    padding: 0;
    font-family: var(--font-family-heading);
}

/* LTR-specific adjustments */
[dir="ltr"] .styling-drop-cap p:first-of-type::first-letter {
    margin-right: 0.08em;
    margin-left: 0;
}

/* RTL-specific adjustments */
[dir="rtl"] .styling-drop-cap p:first-of-type::first-letter {
    margin-left: 0.08em;
    margin-right: 0;
}

/* Arabic-friendly first word styling - floated like traditional Arabic books */
.first-word {
    font-size: var(--first-word-size, 1.65em);
    font-weight: bold;
    color: var(--styling-color, var(--accent-color));
    font-family: var(--font-headings);
    float: right;
    line-height: 1;
    margin-left: 0.3em;
    margin-bottom: 0.1em;
    margin-top: 0.75rem;
    /* Pushe down to sit between lines */
    padding: 0.1em 0 0.1em 0.1em;
    /* display: inline-block prevents ::first-letter from applying to parent p */
    display: inline-block;
}

.rtl .first-word {
    float: right;
    margin-left: 0.3em;
    margin-right: 0;
}

.ltr .first-word {
    float: left;
    margin-right: 0.3em;
    margin-left: 0;
}

/* Responsive */
@media (max-width: 1024px) {
    .header-content {
        padding: 0 var(--spacing-md);
    }

    .reader-body {
        flex-direction: column;
    }

    .reader-sidebar {
        transform: translateX(-100%);
        width: 85%;
        max-width: 400px;
        z-index: 1000;
        /* Higher than audio player (500) on mobile */
    }

    .rtl .reader-sidebar {
        transform: translateX(100%);
    }

    .reader-sidebar.active {
        transform: translateX(0);
    }

    .reader-main {
        padding: var(--spacing-xl) var(--spacing-md);
        padding-top: var(--content-top-margin, var(--spacing-xl));
        /* Use content-top-margin setting from admin, fallback to spacing-xl on mobile */
    }
}

/* Desktop sidebar toggle - when hamburger is shown on desktop */
@media (min-width: 1025px) {
    .reader-sidebar.sidebar-hidden {
        transform: translateX(-100%);
    }

    .rtl .reader-sidebar.sidebar-hidden {
        transform: translateX(100%);
    }

    /* Expand main content when sidebar is hidden */
    body:has(.reader-sidebar.sidebar-hidden) .reader-main {
        max-width: 1200px;
    }
}

/* Overlay for mobile when sidebar is open */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    /* Just below sidebar (1000) */
    opacity: 0;
    transition: opacity 0.3s ease;
}

@media (max-width: 1024px) {
    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }
}

/* Section Separators */
.section-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: var(--spacing-2xl) auto;
    width: 100%;
    max-width: 100%;
    /* Force width */
    color: var(--separator-color, #ccc);
    opacity: 0.8;
}

/* Style: Simple Line */
.section-separator.style-line::before {
    content: "";
    flex: 1;
    display: block;
    /* Ensure block display for flex child */
    min-width: 50px;
    /* Minimum width to force rendering */
    height: 1px;
    background-color: currentColor;
    margin: 0 var(--spacing-md);
}

/* Style: Star (Line -- * -- Line) */
.section-separator.style-star::before,
.section-separator.style-star::after {
    content: "";
    flex: 1;
    display: block;
    min-width: 50px;
    height: 1px;
    background-color: currentColor;
}

.section-separator.style-star::before {
    margin-inline-end: var(--spacing-md);
}

.section-separator.style-star::after {
    margin-inline-start: var(--spacing-md);
}

.section-separator-icon {
    font-size: 1.5rem;
    line-height: 1;
    color: inherit;
    font-weight: bold;
}

/* Style: Diamond */
.section-separator.style-diamond::before,
.section-separator.style-diamond::after {
    content: "";
    flex: 1;
    display: block;
    min-width: 50px;
    height: 1px;
    background-color: currentColor;
}

.section-separator.style-diamond .section-separator-icon {
    font-size: 1.2rem;
    transform: rotate(45deg);
    display: inline-block;
    padding: 0 10px;
}

/* Style: Flower/Ornament */
.section-separator.style-flower::before,
.section-separator.style-flower::after {
    content: "";
    flex: 1;
    display: block;
    min-width: 50px;
    height: 1px;
    border-top: 1px dashed currentColor;
}

.section-separator.style-flower .section-separator-icon {
    font-size: 1.8rem;
    padding: 0 15px;
}

/* Section Heading Underline Control */
.heading-with-underline {
    position: relative;
    display: inline-block;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--underline-color, #e74c3c);
    width: auto;
    /* Allow it to fit text or full width depending on look */
    min-width: 100px;
    /* Minimum width for short titles */
}

/* ========================================
   Header Branding Styles
   ======================================== */

/* Brand container base */
.header-brand {
    display: flex;
    align-items: center;
    gap: var(--spacing-md, 1rem);
    text-decoration: none;
    transition: transform var(--transition-fast, 0.2s), opacity var(--transition-fast, 0.2s);
    /* Ensure no background bleeds through */
    background: transparent;
}

.header-brand:hover {
    transform: scale(1.02);
    opacity: 0.9;
}

/* Text-only brand (uses existing .logo styles but enhanced) */
.header-brand-text {
    font-weight: 700;
    text-decoration: none;
    transition: transform var(--transition-normal, 0.3s);
}

/* Text-only brand with border support */
.header-brand-text.has-border {
    padding: 6px 12px;
    border: 2px solid var(--brand-border-color, #e74c3c);
    display: inline-block;
}

.header-brand-text.has-border.border-solid {
    border-style: solid;
    border-radius: var(--radius-sm, 4px);
}

.header-brand-text.has-border.border-rounded {
    border-style: solid;
    border-radius: var(--radius-lg, 12px);
}

.header-brand-text.has-border.border-pill {
    border-style: solid;
    border-radius: 50px;
    padding: 6px 16px;
}

.header-brand-text.has-border.border-glow {
    border-style: solid;
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 0 10px var(--brand-border-color, #e74c3c),
        0 0 20px var(--brand-border-color, #e74c3c),
        0 0 30px color-mix(in srgb, var(--brand-border-color, #e74c3c) 30%, transparent);
    animation: brand-glow-pulse 2s ease-in-out infinite alternate;
}

/* Cover image in brand */
.header-brand-cover {
    object-fit: cover;
    border-radius: var(--radius-sm, 4px);
    transition: transform var(--transition-fast, 0.2s);
    background: var(--bg-primary, #ffffff);
    /* Remove any dark borders from images */
    box-shadow: none;
    border: none;
}

.header-brand-cover-only .header-brand-cover {
    border-radius: var(--radius-md, 8px);
}

/* Brand title text */
.header-brand-title {
    font-weight: 700;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
    line-height: 1.2;
    display: flex;
    flex-direction: column;
}

/* Individual title lines for advanced styling */
.header-brand-title .title-line1,
.header-brand-title .title-line2 {
    display: block;
    line-height: 1.15;
}

.header-brand-title .title-line1 {
    /* First line defaults - can be overridden by inline styles */
}

.header-brand-title .title-line2 {
    /* Second line defaults - can be overridden by inline styles */
}

/* Logo image */
.header-brand-logo-img {
    object-fit: contain;
}

/* Brand border/frame styles */
.header-brand.has-border {
    padding: 4px;
    border: 2px solid var(--brand-border-color, #e74c3c);
}

.header-brand.has-border.border-solid {
    border-style: solid;
    border-radius: var(--radius-sm, 4px);
}

.header-brand.has-border.border-rounded {
    border-style: solid;
    border-radius: var(--radius-lg, 12px);
}

.header-brand.has-border.border-pill {
    border-style: solid;
    border-radius: 50px;
    padding: 4px 12px;
}

.header-brand.has-border.border-glow {
    border-style: solid;
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 0 10px var(--brand-border-color, #e74c3c),
        0 0 20px var(--brand-border-color, #e74c3c),
        0 0 30px color-mix(in srgb, var(--brand-border-color, #e74c3c) 30%, transparent);
    animation: brand-glow-pulse 2s ease-in-out infinite alternate;
}

@keyframes brand-glow-pulse {
    from {
        box-shadow: 0 0 10px var(--brand-border-color, #e74c3c),
            0 0 20px var(--brand-border-color, #e74c3c);
    }

    to {
        box-shadow: 0 0 15px var(--brand-border-color, #e74c3c),
            0 0 30px var(--brand-border-color, #e74c3c),
            0 0 40px var(--brand-border-color, #e74c3c);
    }
}

/* ========================================
   Header Decoration Styles
   ======================================== */

/* Base header with decoration support */
.header {
    --header-border-color: var(--header-bottom-color, #e74c3c);
    --header-border-thickness: var(--header-bottom-thickness, 2px);
}

/* None - no bottom decoration */
.header.header-decoration-none {
    border-bottom: none;
}

/* Simple Line */
.header.header-decoration-line {
    border-bottom: var(--header-border-thickness) solid var(--header-border-color);
}

/* Gradient Line */
.header.header-decoration-gradient {
    border-bottom: none;
    /* Don't set position here - it breaks sticky header */
}

.header.header-decoration-gradient::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--header-border-thickness);
    background: linear-gradient(90deg,
            transparent 0%,
            var(--header-border-color) 20%,
            var(--header-border-color) 80%,
            transparent 100%);
}

/* Drop Shadow */
.header.header-decoration-shadow {
    border-bottom: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15),
        0 2px 4px var(--header-border-color);
}

/* Double Line */
.header.header-decoration-double {
    border-bottom: var(--header-border-thickness) double var(--header-border-color);
}

/* Responsive adjustments for brand */
@media (max-width: 768px) {

    /* Mobile Header: Absolute positioning for hamburger and actions toggle */
    .header-content {
        position: relative;
        padding: 0 !important;
        display: flex !important;
        justify-content: center !important;
        width: 100%;
    }

    /* Hamburger menu - absolute left */
    #mobile-menu-toggle {
        position: absolute !important;
        left: -8px !important;
        /* Push to edge (counteract 12px padding - 4px visual gap) */
        top: 50%;
        transform: translateY(-50%);
        z-index: 10;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        color: #ffffff !important;
        width: 40px !important;
        height: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Force icon color to white for hamburger */
    #mobile-menu-toggle svg {
        stroke: #ffffff !important;
        fill: transparent !important;
        /* Ensure fill doesn't turn black if used */
        color: #ffffff !important;
    }

    /* Actions toggle - absolute right - MULTIPLE SELECTORS FOR SPECIFICITY */
    #mobile-actions-toggle,
    button#mobile-actions-toggle,
    .mobile-actions-toggle,
    .header-slot-right .mobile-actions-toggle,
    .header-slot-right #mobile-actions-toggle {
        position: absolute !important;
        right: -8px !important;
        /* Push to edge (counteract 12px padding) */
        left: auto !important;
        /* Override any left positioning */
        top: 50%;
        transform: translateY(-50%);
        z-index: 10;
        margin-right: 0 !important;
        /* Remove any margin */
    }

    /* RTL Support for Mobile Header */
    /* Swap toggle positions: Hamburger Right, Actions Left */
    html[dir="rtl"] #mobile-menu-toggle,
    body.rtl #mobile-menu-toggle {
        left: auto !important;
        right: -8px !important;
    }

    html[dir="rtl"] .mobile-actions-toggle,
    html[dir="rtl"] #mobile-actions-toggle,
    body.rtl .mobile-actions-toggle,
    body.rtl #mobile-actions-toggle {
        right: auto !important;
        left: -8px !important;
    }

    /* Center brand section - add padding to avoid overlap with absolute buttons */
    .header-slot-center,
    .header-brand-section {
        padding: 0 60px;
        /* Space for absolute buttons on both sides */
        justify-content: center;
    }

    .header-brand-title,
    .header-brand-text,
    .logo.header-brand-text {
        max-width: var(--mobile-brand-max-width, 120px);
        font-size: var(--mobile-brand-font-size, 0.9rem);
        text-align: center !important;
    }

    .header-brand-cover {
        display: none !important;
    }

    .header-brand.has-border.border-pill {
        padding: 2px 8px;
    }

    /* Hide regular header actions on mobile */
    .header-actions {
        display: none !important;
    }

    /* Show mobile actions toggle */
    .mobile-actions-toggle {
        display: flex !important;
    }

    /* Mobile header height override */
    .header {
        height: var(--mobile-header-height, var(--header-height, 70px));
        padding: 0 var(--mobile-header-padding, 12px);
    }

    /* Hide brand on mobile if configured */
    .header.mobile-hide-brand .header-brand-section {
        display: none !important;
    }
}

/* Mobile actions toggle button - hidden on desktop */
.mobile-actions-toggle {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--toolbar-btn-radius, 50%);
    cursor: pointer;
    color: #ffffff !important;
    transition: all 0.2s;
}

.mobile-actions-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.mobile-actions-toggle svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

/* ========================================
   MOBILE ACTIONS PANEL - INDUSTRY STANDARD
   ======================================== */

/* Base panel - hidden by default, positioned fixed */
.mobile-actions-panel {
    display: none;
    visibility: hidden;
    position: fixed;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: var(--spacing-md);
    padding-top: calc(var(--spacing-md) + 8px); /* Extra space for close button */
    z-index: 1001; /* Above header to stay visible when header hides */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                top 0.3s ease; /* Smooth transition when header hides */
}

/* Close button - Industry standard top-right position */
.mobile-actions-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    z-index: 10;
}

.mobile-actions-close:hover {
    background: var(--bg-tertiary);
    color: var(--color-primary);
}

.mobile-actions-close svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

/* RTL: Move close button to left */
[dir="rtl"] .mobile-actions-close {
    right: auto;
    left: 8px;
}

/* Dropdown Style - Industry Standard (slides down from top) */
.mobile-actions-panel.mobile-actions-dropdown {
    top: 0; /* Always stick to top of viewport */
    transform: translateY(-100%);
    opacity: 0;
}

.mobile-actions-panel.mobile-actions-dropdown.active {
    transform: translateY(0);
    opacity: 1;
}

/* When header is visible, position below it */
body:not(.header-hidden) .mobile-actions-panel.mobile-actions-dropdown {
    top: var(--mobile-header-height, var(--header-height, 70px));
}

/* When header is hidden (scrolled up), stick to top */
body.header-hidden .mobile-actions-panel.mobile-actions-dropdown {
    top: 0;
}

/* Bottom Sheet Style - Material Design (slides up from bottom) */
.mobile-actions-panel.mobile-actions-bottom-sheet {
    top: auto;
    bottom: 0;
    border-top: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    opacity: 0;
    max-height: 60vh;
    overflow-y: auto;
}

.mobile-actions-panel.mobile-actions-bottom-sheet.active {
    transform: translateY(0);
    opacity: 1;
}

/* Inline Style - Always visible in header */
.mobile-actions-panel.mobile-actions-inline {
    position: static;
    display: flex;
    visibility: visible;
    opacity: 1;
    transform: none;
    border: none;
    box-shadow: none;
    padding: 0;
    background: transparent;
}

/* Mobile Actions Grid */
.mobile-actions-grid {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-sm, 0.5rem);
    flex-wrap: wrap;
}

.mobile-actions-panel.mobile-actions-inline .mobile-actions-grid {
    pointer-events: all;
}

/* Mobile Action Buttons */
.mobile-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px; /* iOS minimum touch target */
    height: 44px;
    border-radius: var(--toolbar-btn-radius, 50%);
    background: var(--toolbar-btn-bg, var(--bg-secondary));
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    text-decoration: none;
    color: var(--text-primary);
}

.mobile-action-btn:hover,
.mobile-action-btn:active {
    background: var(--toolbar-btn-hover-bg, var(--bg-tertiary));
    border-color: var(--color-primary);
    transform: scale(1.05);
}

.mobile-action-btn svg {
    width: 20px;
    height: 20px;
    stroke: var(--toolbar-btn-color, var(--text-primary));
    transition: stroke 0.2s;
}

.mobile-action-btn:hover svg {
    stroke: var(--toolbar-btn-hover-color, var(--color-primary));
}

/* Bookmark count badge */
.mobile-bookmark-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--color-primary);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    display: none;
}

.mobile-bookmark-count.has-bookmarks {
    display: block;
}

/* Actions divider */
.mobile-actions-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 var(--spacing-xs, 0.25rem);
}

/* Mobile: Show panel */
@media (max-width: 768px) {
    .mobile-actions-panel {
        visibility: visible;
    }
    
    /* Dropdown and Bottom Sheet: show when active */
    .mobile-actions-panel.mobile-actions-dropdown.active,
    .mobile-actions-panel.mobile-actions-bottom-sheet.active {
        display: block;
    }
    
    /* Inline: always visible */
    .mobile-actions-panel.mobile-actions-inline {
        display: flex;
    }
}
    border-bottom: none;
    border-top: 2px solid var(--border-color);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    opacity: 0;
    z-index: 9999 !important;
    /* Ensure it's above everything */
}

.mobile-actions-panel.mobile-actions-bottom-sheet.active {
    transform: translateY(0) !important;
    opacity: 1 !important;
    z-index: 10000 !important;
    display: block !important;
}

/* Inline Style - always visible in header, no toggle needed */
.mobile-actions-panel.mobile-actions-inline {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height, 70px);
    border: none;
    box-shadow: none;
    padding: 0 var(--mobile-header-padding, 12px);
    transform: none;
    opacity: 1;
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    background: transparent;
    z-index: 1001;
    /* Above header */
    pointer-events: none;
    /* Allow clicks to pass through to header */
}

.mobile-actions-panel.mobile-actions-inline .mobile-actions-grid {
    pointer-events: all;
    /* Re-enable clicks on buttons */
    gap: var(--spacing-xs);
    padding-right: var(--spacing-sm);
    /* Add right padding to prevent touching edge */
}

.mobile-actions-panel.mobile-actions-inline .mobile-action-btn {
    width: var(--mobile-actions-btn-size, 40px);
    height: var(--mobile-actions-btn-size, 40px);
}

/* Ensure SVGs in mobile panel are always constrained */
.mobile-actions-panel svg {
    width: 20px !important;
    height: 20px !important;
    max-width: 20px !important;
    max-height: 20px !important;
}

.mobile-actions-panel .mobile-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--toolbar-btn-radius, 50%);
    cursor: pointer;
    color: var(--text-primary);
    text-decoration: none;
    width: var(--mobile-actions-btn-size, 40px);
    height: var(--mobile-actions-btn-size, 40px);
    transition: all 0.2s;
}

.mobile-actions-panel .mobile-action-btn:hover,
.mobile-actions-panel .mobile-action-btn:active {
    background: var(--bg-tertiary);
    border-color: var(--color-primary);
}

.mobile-actions-panel .mobile-action-btn svg {
    stroke: var(--text-primary);
}

.mobile-actions-panel .mobile-actions-grid {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 0;
}

.mobile-actions-divider {
    color: var(--border-color);
    font-size: 1.5rem;
    font-weight: 300;
    margin: 0 var(--spacing-xs);
}


/* Mobile: show panel when active */
@media (max-width: 768px) {
    .mobile-actions-panel {
        visibility: visible !important;
    }

    /* Dropdown and Bottom Sheet: show when active */
    .mobile-actions-panel.mobile-actions-dropdown.active,
    .mobile-actions-panel.mobile-actions-bottom-sheet.active {
        display: block !important;
    }

    /* Inline: always visible, no toggle needed */
    .mobile-actions-panel.mobile-actions-inline {
        display: flex !important;
    }

    /* Hide toggle button when inline style is active */
    body:has(.mobile-actions-inline) .mobile-actions-toggle {
        display: none !important;
    }
}


/* ========================================
   Reader Footer Styles
   ======================================== */

.reader-footer {
    width: 100%;
    background: var(--footer-bg, #34495e);
    color: var(--footer-text, #ecf0f1);
    padding: var(--spacing-3xl) 0 0;
    margin-top: auto;
    position: relative;
    z-index: 1100;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-xl);
}

.footer-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-3xl);
    margin-bottom: var(--spacing-2xl);
}

.footer-column-title {
    color: var(--footer-title, #f39c12);
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-lg);
}

/* About Column */
.footer-about-text {
    font-size: var(--font-size-sm);
    line-height: 1.8;
    margin-bottom: var(--spacing-lg);
    color: var(--footer-text, #ecf0f1);
}

.footer-featured {
    margin-top: var(--spacing-lg);
    text-align: center;
}

.footer-separator {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--footer-link, #bdc3c7), transparent);
    margin: var(--spacing-xl) 0;
    opacity: 0.5;
}

.footer-featured a {
    display: inline-block;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.footer-featured a:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.footer-featured-label {
    font-size: var(--font-size-base);
    font-weight: 600;
    margin-bottom: var(--spacing-lg);
    opacity: 0.9;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.footer-logo-container {
    display: inline-block;
    padding: var(--spacing-lg);
    transition: all var(--transition-normal);
}

/* Frame Styles */
.footer-logo-frame-solid {
    border: 3px solid;
    border-color: var(--frame-color, #f39c12);
    border-radius: var(--radius-md);
}

.footer-logo-frame-gradient {
    border: 3px solid transparent;
    background: linear-gradient(var(--footer-bg, #34495e), var(--footer-bg, #34495e)) padding-box,
        linear-gradient(135deg, var(--gradient-start, #f39c12), var(--gradient-end, #e74c3c)) border-box;
    border-radius: var(--radius-md);
}

.footer-logo-frame-double {
    border: 3px double;
    border-color: var(--frame-color, #f39c12);
    border-radius: var(--radius-md);
}

.footer-logo-frame-dashed {
    border: 3px dashed;
    border-color: var(--frame-color, #f39c12);
    border-radius: var(--radius-md);
}

.footer-logo-frame-dotted {
    border: 3px dotted;
    border-color: var(--frame-color, #f39c12);
    border-radius: var(--radius-md);
}

.footer-logo-frame-glow {
    border-radius: var(--radius-md);
    box-shadow: 0 0 20px var(--frame-color, #f39c12),
        0 0 40px var(--frame-color, #f39c12);
}

.footer-logo-frame-shadow {
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3),
        0 0 0 1px var(--frame-color, #f39c12);
}

.footer-logo-container a {
    display: inline-block;
    transition: transform 0.3s ease, filter 0.3s ease;
}

.footer-logo-container a:hover {
    transform: scale(1.05) translateY(-2px);
    filter: brightness(1.1);
}

.footer-logo-container a:hover .footer-logo {
    animation: logo-pulse 0.6s ease-in-out;
}

@keyframes logo-pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.03);
    }
}

.footer-logo {
    max-width: 180px;
    max-height: 120px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    transition: transform 0.3s ease;
}

/* Contents Column */
.footer-nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-nav-list li {
    margin-bottom: var(--spacing-sm);
}

.footer-nav-list a {
    color: var(--footer-link, #bdc3c7);
    text-decoration: none;
    font-size: var(--font-size-sm);
    transition: color var(--transition-fast);
    display: inline-block;
}

.footer-nav-list a:hover {
    color: var(--footer-link-hover, #f39c12);
}

/* Contact Column */
.footer-contact-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.footer-input,
.footer-textarea {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--footer-form-bg, rgba(255, 255, 255, 0.1));
    border: 1px solid var(--footer-form-border, rgba(255, 255, 255, 0.2));
    border-radius: var(--radius-md);
    color: var(--footer-form-text, #ffffff);
    font-size: var(--font-size-sm);
    font-family: inherit;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.footer-input::placeholder,
.footer-textarea::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.footer-input:focus,
.footer-textarea:focus {
    outline: none;
    border-color: var(--footer-title, #f39c12);
    background: var(--footer-form-bg, rgba(255, 255, 255, 0.15));
}

.footer-textarea {
    resize: vertical;
    min-height: 100px;
}

.footer-submit-btn {
    padding: var(--spacing-md) var(--spacing-xl);
    background: var(--footer-btn-bg, #f39c12);
    color: var(--footer-btn-text, #ffffff);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.footer-submit-btn:hover {
    background: var(--footer-btn-hover-bg, #e67e22);
    transform: translateY(-2px);
}

.footer-submit-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

/* Form Messages */
.form-message {
    margin-top: var(--spacing-md);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    text-align: center;
}

.form-success {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.form-error {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Copyright Bar */
.footer-copyright {
    background: var(--footer-copyright-bg, rgba(0, 0, 0, 0.2));
    padding: var(--spacing-lg) 0;
    text-align: center;
    margin-top: var(--spacing-2xl);
    width: 100%;
}

.footer-copyright p {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--footer-text, #ecf0f1);
}

.footer-copyright a {
    color: var(--footer-link-hover, #f39c12);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
    position: relative;
}

.footer-copyright a:hover {
    color: #ffffff;
    text-shadow: 0 0 10px var(--footer-link-hover, #f39c12),
        0 0 20px var(--footer-link-hover, #f39c12);
}

/* Responsive Footer */
@media (max-width: 1024px) {
    .footer-columns {
        grid-template-columns: 1fr;
        gap: var(--spacing-2xl);
    }

    .footer-column {
        max-width: 100%;
        margin: 0;
        padding: 0;
    }

    /* Make contact form wider on mobile */
    .footer-contact-form {
        max-width: 100%;
        width: 100%;
    }

    .footer-input,
    .footer-textarea {
        font-size: 16px;
        padding: 1rem;
        width: 100%;
        box-sizing: border-box;
    }

    .footer-textarea {
        min-height: 140px;
    }
}

@media (max-width: 768px) {
    .footer-content {
        padding: 0 var(--spacing-md);
    }

    .footer-logo {
        max-width: 150px;
        max-height: 100px;
    }

    /* Ensure form takes full width on small mobile */
    .footer-column {
        max-width: 100%;
        padding: 0;
        margin: 0;
    }

    .footer-contact-form {
        width: 100%;
    }

    .footer-input,
    .footer-textarea {
        font-size: 16px;
        width: 100%;
        box-sizing: border-box;
    }
}


/* ========================================
   MOBILE CHAT INTEGRATION
   ======================================== */

/* When chat is open on mobile, prevent body scroll */
@media (max-width: 768px) {
    body.chat-open {
        overflow: hidden;
    }

    /* Ensure reader content is accessible when chat is collapsed */
    .reader-main {
        padding-bottom: 80px;
        /* Space for FAB */
    }

    /* Adjust footer to not overlap with chat FAB */
    .reader-footer {
        padding-bottom: 80px;
    }
}

/* Chat panel overlay for mobile */
.chat-panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1999;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.chat-panel-overlay.active {
    display: block;
    opacity: 1;
}

/* Hide overlay on desktop */
@media (min-width: 769px) {
    .chat-panel-overlay {
        display: none !important;
    }
}

/* Ensure chat panel is always visible (not hidden by reader-layout rules) */
.chat-panel {
    display: flex !important;
    visibility: visible !important;
    z-index: 10000 !important;
    /* Ensure it's above everything */
}

.chat-panel.collapsed {
    display: flex !important;
    visibility: visible !important;
    z-index: 10000 !important;
}

/* Ensure mobile FAB is visible */
@media (max-width: 768px) {
    .chat-panel.collapsed {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        z-index: 10000 !important;
    }
}


/* ========================================
   CHAPTER NAVIGATION BUTTONS
   ======================================== */

.chapter-navigation {
    margin-top: var(--spacing-3xl);
    padding-top: var(--spacing-2xl);
    border-top: 1px solid var(--border-color);
}

.chapter-nav-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-lg);
    flex-wrap: wrap;
}

.chapter-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 28px;
    font-size: var(--font-size-base);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 160px;
    text-align: center;

    /* Use CSS variables for theming */
    background: var(--nav-button-bg-color, #f39c12);
    color: var(--nav-button-text-color, #ffffff);
    border-radius: var(--nav-button-border-radius, 50px);
    border: none;
}

/* Gradient style override */
.chapter-nav-btn.gradient-style {
    background: linear-gradient(135deg, var(--nav-button-bg-color, #f39c12), var(--nav-button-bg-color-dark, #e67e22));
}

/* Solid style override */
.chapter-nav-btn.solid-style {
    background: var(--nav-button-bg-color, #f39c12);
}

/* Outline style override */
.chapter-nav-btn.outline-style {
    background: transparent;
    border: 2px solid var(--nav-button-bg-color, #f39c12);
    color: var(--nav-button-text-color, #ffffff);
}

.chapter-nav-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    filter: brightness(1.1);
}

.chapter-nav-btn:active {
    transform: translateY(-1px);
}

/* RTL Support */
[dir="rtl"] .chapter-nav-buttons {
    flex-direction: row;
}

/* Responsive */
@media (max-width: 768px) {
    .chapter-nav-buttons {
        flex-direction: column;
        gap: var(--spacing-md);
    }

    .chapter-nav-btn {
        width: 100%;
        max-width: 300px;
    }

    [dir="rtl"] .chapter-nav-buttons {
        flex-direction: column;
    }
}


/* ============================================
   DARK MODE OVERRIDES FOR TOC AND SIDEBAR
   ============================================ */

[data-theme="dark"] .reader-sidebar {
    background: var(--bg-primary, #1a1a1a);
    border-inline-end-color: var(--border-color, #333);
}

[data-theme="dark"] .sidebar-header {
    background: var(--bg-primary, #1a1a1a);
    border-bottom-color: var(--border-color, #333);
}

[data-theme="dark"] .sidebar-search input {
    background: var(--bg-secondary, #2a2a2a);
    border-color: var(--border-color, #444);
    color: var(--text-primary, #e0e0e0);
}

[data-theme="dark"] .sidebar-search input::placeholder {
    color: var(--text-muted, #888);
}

[data-theme="dark"] .sidebar-toc {
    background: var(--bg-primary, #1a1a1a);
}

[data-theme="dark"] .sidebar-toc-title {
    color: var(--text-primary, #e0e0e0);
}

[data-theme="dark"] .toc-link {
    color: var(--text-secondary, #b0b0b0);
}

[data-theme="dark"] .toc-link:hover {
    background: var(--bg-tertiary, #333);
    color: var(--text-primary, #fff);
}

[data-theme="dark"] .toc-link.active {
    background: var(--color-primary);
    color: white;
}

[data-theme="dark"] .toc-toggle {
    color: var(--text-secondary, #b0b0b0);
    border-color: var(--border-color, #444);
}

[data-theme="dark"] .toc-toggle:hover {
    background: var(--bg-secondary, #2a2a2a);
    color: var(--color-primary);
}

[data-theme="dark"] .toc-item.active .toc-toggle {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

[data-theme="dark"] .toc-progress-dot {
    background: var(--color-gray-600, #555);
}

[data-theme="dark"] .toc-sublink {
    color: var(--text-muted, #888);
    border-inline-start-color: var(--border-color, #444);
}

[data-theme="dark"] .toc-sublink:hover {
    color: var(--color-primary);
    border-inline-start-color: var(--color-primary);
}

[data-theme="dark"] .sidebar-toc::-webkit-scrollbar-track {
    background: transparent;
}

[data-theme="dark"] .sidebar-toc::-webkit-scrollbar-thumb {
    background: var(--border-color, #444);
}

[data-theme="dark"] .sidebar-toc::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
}

/* Sepia Mode Overrides */
[data-theme="sepia"] .reader-sidebar {
    background: var(--bg-primary, #f4ecd8);
    border-inline-end-color: var(--border-color, #d4c4a8);
}

[data-theme="sepia"] .sidebar-header {
    background: var(--bg-primary, #f4ecd8);
    border-bottom-color: var(--border-color, #d4c4a8);
}

[data-theme="sepia"] .sidebar-toc {
    background: var(--bg-primary, #f4ecd8);
}

/* High Contrast Mode Overrides */
[data-theme="high-contrast"] .reader-sidebar {
    background: white;
    border-inline-end: 2px solid black;
}

[data-theme="high-contrast"] .sidebar-header {
    background: white;
    border-bottom: 2px solid black;
}

[data-theme="high-contrast"] .sidebar-toc {
    background: white;
}

[data-theme="high-contrast"] .toc-link {
    color: black;
}

[data-theme="high-contrast"] .toc-link:hover {
    background: #ffff00;
    color: black;
}

[data-theme="high-contrast"] .toc-link.active {
    background: black;
    color: white;
    border: 2px solid black;
}


/* ========================================
   CRITICAL LAYOUT FIXES
   ======================================== */

/* Fix 1: Ensure chatbot is always visible */
.chat-panel {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 10000 !important;
}

.chat-panel.collapsed {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 10000 !important;
}

.chat-panel.collapsed .chat-collapse-bar {
    display: flex !important;
    visibility: visible !important;
}

/* Fix 2: Ensure TOC sidebar is visible */
.reader-sidebar {
    display: flex !important;
    visibility: visible !important;
}

.reader-sidebar.active {
    display: flex !important;
    visibility: visible !important;
    transform: translateX(0) !important;
}

/* Fix 3: Ensure TOC content is visible */
.sidebar-toc {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.toc-list {
    display: block !important;
    visibility: visible !important;
}
