* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
    sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
  line-height: 1.6;
  overflow: hidden;
}

.app-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ===== CHAPTER NAVIGATION SIDEBAR ===== */
.chapter-nav {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 1000;
}

/* Collapsed State - Vertical Sidebar */
.chapter-nav-collapsed {
  width: 50px;
  height: 100%;
  background: #3D4B66;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 1rem;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
}

.chapter-nav-toggle {
  width: 36px;
  height: 36px;
  border: none;
  background: #2d2d2d;
  color: white;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  margin-bottom: 1.5rem;
  font-size: 1rem;
}

.chapter-nav-toggle:hover {
  background: #4a5a78;
  transform: scale(1.05);
}

.chapter-numbers {
  display: none;
}

.chapter-number-item {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #2d2d2d;
  color: #a0a0a0;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.chapter-number-item:hover {
  background: #4a5a78;
  color: white;
  transform: scale(1.1);
}

.chapter-number-item.active {
  background: white;
  color: #1a1a1a;
  border-color: white;
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.5);
}

/* Expanded State - Overlay */
.chapter-nav-expanded {
  position: absolute;
  left: 0;
  top: 0;
  width: 320px;
  height: 100%;
  background: white;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  transform: translateX(0);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.chapter-nav-expanded.hidden {
  transform: translateX(-100%);
}

.chapter-nav-header {
  padding: 1.5rem;
  min-height: 82px;
  border-bottom: 1px solid #2d2d2d;
  display: flex;
  align-items: center;
  background: #3D4B66;
  color: white;
}

.chapter-nav-header h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

.chapter-nav-close {
  display: none;
}

.chapter-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  scroll-behavior: smooth;
  background: #F8F9FA;
}

.chapter-list::-webkit-scrollbar {
  width: 6px;
}

.chapter-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.chapter-list::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

.chapter-list::-webkit-scrollbar-thumb:hover {
  background: #a0aec0;
}

.chapter-item {
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  transition: background 0.15s ease;
  border-bottom: 1px solid #E8EEF5;
  background: #F8F9FA;
}

.chapter-item:hover {
  background: #EEF1F6;
}

.chapter-item.active {
  background: #E8EEF5;
}

.chapter-item-number {
  display: inline;
  font-family: "source-sans-pro", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.9rem;
  color: #2d3748;
  font-weight: 400;
}

.chapter-item-number::after {
  content: ". ";
}

.chapter-item.active .chapter-item-number {
  color: #3D4B66;
  font-weight: 700;
}

.chapter-item-name {
  font-weight: 400;
  color: #2d3748;
  font-size: 0.9rem;
  line-height: 1.5;
  font-family: "source-sans-pro", -apple-system, BlinkMacSystemFont, sans-serif;
}

.chapter-item.active .chapter-item-name {
  color: #3D4B66;
  font-weight: 700;
}

/* Backdrop for expanded state */
.chapter-nav-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 999;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.chapter-nav-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Adjust main content to account for collapsed sidebar */
.split-container {
  margin-left: 50px;
}

/* ===== HEADER (now inside book-header) ===== */
.book-header h1 {
  font-size: 1.22rem;
  font-weight: 700;
  color: #282F38;
  letter-spacing: -0.02em;
  font-family: "source-sans-pro", -apple-system, BlinkMacSystemFont, sans-serif;
  margin: 0;
  line-height: 1.4;
}

.book-header .header-book-title {
  color: #A0A0A0;
}

.book-header .header-chapter-title {
  color: #282F38;
}

.book-header-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}


/* ===== BUTTONS ===== */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
  background: #f5f5f5;
  color: #1a1a1a;
}

.btn:hover {
  background: #e5e5e5;
}

.btn-primary {
  background: #282F38;
  color: white;
}

.btn-primary:hover {
  background: #1a2029;
}

.btn-secondary {
  background: #f5f5f5;
  color: #1a1a1a;
}

.btn-secondary:hover {
  background: #e5e5e5;
}

.btn-nav {
  background: #ffffff;
  color: #1a1a1a;
  border: 1px solid #e5e5e5;
}

.btn-nav:hover:not(:disabled) {
  background: #f5f5f5;
}

.btn-nav:disabled {
  background: #fafafa;
  color: #a3a3a3;
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-header-icon {
  background: white;
  color: #282F38;
  border: 1px solid #9CA3AF;
  border-radius: 9999px;
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 0.875rem;
}

.btn-header-icon:hover {
  background: #f5f5f5;
  border-color: #6B7280;
}

.btn-close {
  background: transparent;
  color: #6b7280;
  padding: 0.25rem;
  font-size: 1.5rem;
  border-radius: 4px;
}

.btn-close:hover {
  background: #f3f4f6;
  color: #1a1a1a;
}

/* ===== THREE COLUMN LAYOUT ===== */
.split-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  max-width: calc(100vw - 50px);
}

/* ===== RESIZE HANDLES ===== */
.resize-handle {
  flex: 0 0 1px;
  background: #e5e5e5;
  cursor: col-resize;
  position: relative;
  z-index: 10;
}

#resizeHandle1 {
  order: 2; /* Between book and side notes */
}

#resizeHandle2 {
  order: 4; /* Between side notes and chat */
}

.resize-handle:hover {
  background: #d1d5db;
}

/* ===== BOOK SECTION (LEFT) ===== */
.book-section {
  flex: 0 0 40%;
  display: flex;
  flex-direction: column;
  background: #FCF9F5;
  border-right: 1px solid #e5e5e5;
  order: 1; /* Position on left */
  min-width: 30%; /* Minimum width to ensure readability */
  overflow: hidden; /* Prevent content from expanding section */
}

/* When side notes collapsed, hide side notes and resize handle 1 */
.split-container.notes-collapsed .side-notes-section {
  flex: 0 0 0% !important;
  min-width: 0 !important;
  opacity: 0;
  pointer-events: none;
  border: none;
  overflow: hidden;
}

/* Hide handle 1 (between book and side notes) when notes are collapsed */
.split-container.notes-collapsed #resizeHandle1 {
  display: none;
}

/* Keep handle 2 visible for resizing between book and chat in 2-panel mode */
.split-container.notes-collapsed #resizeHandle2 {
  order: 2; /* Position between book and chat */
}

/* When notes are collapsed, chat section should fill remaining space and snap to right */
.split-container.notes-collapsed .chat-section {
  order: 3; /* Position after resize handle 2 in 2-panel mode */
}

/* When side notes collapsed, expand book section (width dynamically calculated in JS) */

.book-header {
  padding: 1rem 2rem;
  border-bottom: 1px solid #e5e5e5;
  min-height: 65px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0; /* Allow shrinking in flex context */
  overflow: hidden; /* Prevent content from expanding */
  background: #ffffff;
}

.book-header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chapter-name {
  flex: 1;
  font-size: 0.875rem;
  font-weight: 500;
  color: #6b7280;
  text-align: center;
}

.chapter-name:empty::before {
  content: "\00a0";
}

.book-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden; /* Prevent horizontal overflow from expanding section */
  padding: 2rem 3rem;
  padding-left: 6rem; /* Extra left padding to make room for page numbers */
  min-width: 0; /* Allow shrinking in flex context */
}

.page-content {
  max-width: 700px;
  margin: 0 auto;
  font-family: "Georgia", "Times New Roman", serif;
  font-size: 1.125rem;
  line-height: 1.75;
  color: #1a1a1a;
  min-width: 0; /* Allow shrinking */
  overflow-wrap: break-word; /* Break long words if needed */
  word-wrap: break-word; /* Legacy support */
  position: relative; /* Anchor for page number positioning */
}

.page-content p {
  margin-bottom: 1.5rem;
  text-align: justify;
}

.page-content h1,
.page-content h2,
.page-content h3 {
  margin: 2.5rem 0 1.25rem 0;
  color: #1a1a1a;
  font-family: "source-serif-pro", "Georgia", "Times New Roman", serif;
  font-weight: 400;
  line-height: 1.3;
}

.page-content h1 {
  font-size: 2rem;
  border-bottom: none;
  padding-bottom: 0;
}

.page-content .chapter-opening {
  margin: 1rem 0 2.5rem 0;
  text-align: center;
}

.page-content .chapter-opening .chapter-label {
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: #9CA3AF;
  margin: 0 0 0.5rem 0;
  font-family: "source-sans-pro", -apple-system, BlinkMacSystemFont, sans-serif;
}

.page-content .chapter-opening .chapter-title {
  font-size: 1.75rem;
  font-weight: 400;
  color: #1a1a1a;
  margin: 0;
  line-height: 1.35;
  font-family: "source-serif-pro", "Georgia", "Times New Roman", serif;
}

.page-content h2 {
  font-size: 1.5rem;
}

.page-content h3 {
  font-size: 1.25rem;
  color: #4b5563;
}

.page-content ::selection {
  background: #dbeafe;
  color: #1a1a1a;
}

/* Page anchors - markers for linking to specific pages within chapters */
.page-anchor {
  display: block;
  height: 0;
  margin: 0;
  padding: 0;
  position: relative;
  scroll-margin-top: 80px;
}

/* Visible page number in the left margin */
.page-anchor[data-display-page]::before {
  content: attr(data-display-page);
  position: absolute;
  left: -90px;
  top: 0.5rem;
  color: #A0A0A0;
  font-size: 1.22rem;
  font-family: "source-sans-pro", -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 600;
  line-height: 2rem;
  pointer-events: none;
}

.book-footer {
  padding: 1rem 2rem;
  border-top: 1px solid #e5e5e5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-width: 0; /* Allow shrinking in flex context */
  overflow: hidden; /* Prevent content from expanding */
  background: #ffffff;
}

#progressIndicator {
  margin-left: 6rem;
  display: none;
}

.page-info {
  font-size: 0.8125rem;
  color: #6b7280;
  font-weight: 500;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== SIDE NOTES SECTION (CENTER) ===== */
.side-notes-section {
  flex: 0 0 25%;
  display: flex;
  flex-direction: column;
  background: #fefce8;
  border-right: 1px solid #e5e5e5;
  position: relative;
  order: 3; /* Position in center */
  min-width: 0; /* Allow shrinking below content width */
  overflow: hidden; /* Prevent content from expanding section */
}

/* Legacy collapsed class - now handled by .split-container.notes-collapsed instead */

.side-notes-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e5e5e5;
  background: #fef9c3;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0; /* Prevent header from shrinking */
}

.side-notes-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: #78350f;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Side Notes Toggle in Book Header */
.side-notes-toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  cursor: pointer;
  padding: 0.375rem 0.625rem;
  border-radius: 6px;
  background: #fef3c7;
  border: 1px solid #fde047;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.side-notes-toggle:hover {
  background: #fde047;
  border-color: #fbbf24;
}

.side-notes-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: #f59e0b;
  margin: 0;
}

.side-notes-toggle .toggle-label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: #78350f;
  font-weight: 500;
  user-select: none;
  white-space: nowrap;
}

.side-notes-toggle .toggle-label i {
  font-size: 0.813rem;
  color: #f59e0b;
}

.side-notes-toggle input[type="checkbox"]:checked + .toggle-label {
  color: #713f12;
}

.btn-configure-notes {
  background: #fef3c7;
  color: #78350f;
  padding: 0.375rem 0.625rem;
  font-size: 0.875rem;
  border: 1px solid #fde047;
}

.btn-configure-notes:hover {
  background: #fde047;
  color: #713f12;
}

.side-notes-content {
  flex: 1;
  overflow-y: auto; /* Allow scrolling */
  overflow-x: hidden;
  padding: 0; /* Remove padding to allow precise positioning */
  transition: opacity 0.3s ease;
  position: relative; /* Enable absolute positioning for children */
}

.side-notes-section.collapsed .side-notes-content {
  opacity: 0;
  display: none;
}

/* Container for absolutely positioned notes */
.side-notes-positioned-container {
  position: relative;
  width: 100%;
  min-height: 100%; /* Match height of scrollable content */
  padding: 1rem 1rem 1rem 0; /* No left padding for arrow space */
  box-sizing: border-box;
}

.side-notes-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 2rem;
  height: 100%;
}

.side-notes-empty-state i {
  font-size: 3rem;
  color: #fbbf24;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.side-notes-empty-state h4 {
  font-size: 1rem;
  font-weight: 600;
  color: #78350f;
  margin-bottom: 0.5rem;
}

.side-notes-empty-state p {
  font-size: 0.875rem;
  color: #92400e;
  margin-bottom: 1.5rem;
  line-height: 1.5;
  max-width: 300px;
}

/* Side Notes Items */
.side-note-item {
  background: #ffffff;
  border: 1px solid #fde047;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  cursor: pointer; /* Indicate clickability */
}

/* Positioned mode - absolute positioning for scroll sync */
.side-note-item.positioned {
  position: absolute;
  left: 1rem;
  right: 1rem;
  width: auto;
  opacity: 1 !important; /* Always fully visible */
  transform: translateY(
    -50%
  ); /* Center vertically at the calculated position */
  transition: box-shadow 0.2s ease, border-color 0.2s ease, z-index 0.1s ease,
    top 0.1s ease;
  margin-bottom: 0; /* No margin-bottom needed with absolute positioning */
  z-index: 1; /* Default z-index */
}

/* Top-aligned notes (when centering would crop the top) */
.side-note-item.positioned.top-aligned {
  transform: translateY(0); /* No vertical centering */
}

/* Bottom-aligned notes (when centering would crop the bottom) */
.side-note-item.positioned.bottom-aligned {
  transform: translateY(0); /* No vertical centering */
}

/* Active note - brought to front when clicked */
.side-note-item.positioned.active {
  z-index: 10; /* Higher z-index to appear on top */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-color: #f59e0b;
  border-width: 2px;
  /* transform set by JS based on alignment */
}

/* Active top-aligned notes */
.side-note-item.positioned.active.top-aligned {
  transform: translateY(0);
}

/* Active bottom-aligned notes */
.side-note-item.positioned.active.bottom-aligned {
  transform: translateY(0);
}

/* Active centered notes */
.side-note-item.positioned.active:not(.top-aligned):not(.bottom-aligned) {
  transform: translateY(-50%);
}

/* Optional: Add subtle highlight for notes in viewport (reserved for future use) */

/* Add left border indicator when positioned */
.side-note-item.positioned::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 10px solid #fde047;
  opacity: 0.7;
  transition: opacity 0.3s ease, border-right-color 0.3s ease,
    border-width 0.2s ease;
}

/* Arrow for top-aligned notes - position at note center, not paragraph center */
.side-note-item.positioned.top-aligned::before {
  top: 2rem; /* Position arrow near top of note instead of center */
}

/* Active note arrow - more prominent */
.side-note-item.positioned.active::before {
  border-right: 12px solid #f59e0b;
  opacity: 1;
}

.side-note-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border-color: #fbbf24;
}

/* Positioned notes are always at full opacity on hover */

.side-note-item.positioned:hover::before {
  border-right-color: #fbbf24;
  opacity: 1;
}

.side-note-item.loading {
  background: #fffbeb;
  border-style: dashed;
  opacity: 0.7;
}

/* Loading Placeholder for Notes Being Generated */
.side-note-item.loading-placeholder {
  background: linear-gradient(135deg, #fefce8 0%, #fffbeb 100%);
  border: 2px solid #fcd34d;
  border-radius: 10px;
  padding: 1rem;
  box-shadow: 0 2px 8px rgba(251, 191, 36, 0.15);
  min-height: 100px;
}

.side-note-item.loading-placeholder .loading-header {
  margin-bottom: 0.75rem;
}

.side-note-item.loading-placeholder .side-note-icon {
  color: #f59e0b;
  font-size: 1rem;
}

.side-note-item.loading-placeholder .side-note-type {
  color: #92400e;
  font-weight: 600;
  font-size: 0.8rem;
}

.side-note-item.loading-placeholder .loading-text {
  color: #451a03;
}

/* Skeleton loading bars */
.loading-skeleton {
  height: 12px;
  background: linear-gradient(90deg, #fde68a 25%, #fef3c7 50%, #fde68a 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.loading-skeleton.short {
  width: 60%;
  height: 10px;
}

.loading-message-small {
  font-size: 0.7rem;
  color: #92400e;
  margin-top: 0.5rem;
  font-style: italic;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@keyframes pulse-opacity {
  0%,
  100% {
    opacity: 0.7;
  }
  50% {
    opacity: 0.9;
  }
}

/* Pulse animation for the search icon */
.fa-pulse {
  animation: fa-pulse 1s ease-in-out infinite;
}

@keyframes fa-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(0.95);
  }
}

.side-note-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.side-note-icon {
  font-size: 0.875rem;
  color: #f59e0b;
}

.side-note-type {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #92400e;
  letter-spacing: 0.05em;
}

.side-note-content {
  font-size: 0.875rem;
  color: #451a03;
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.side-note-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.813rem;
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  background: #eff6ff;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.side-note-link:hover {
  background: #dbeafe;
  color: #1d4ed8;
}

.side-note-link i {
  font-size: 0.75rem;
}

/* Merged Notes Styles */
.side-note-item.merged {
  border-left: 3px solid #f59e0b;
}

/* Active merged note */
.side-note-item.merged.active {
  border-left-width: 4px;
  border-left-color: #d97706;
}

.merged-notes-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid #fef3c7;
}

.merged-notes-header i {
  font-size: 0.875rem;
  color: #f59e0b;
}

.merged-notes-count {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #92400e;
  letter-spacing: 0.05em;
}

.merged-note-section {
  margin-bottom: 1rem;
}

.merged-note-section:last-child {
  margin-bottom: 0;
}

.merged-note-section.with-divider {
  padding-top: 1rem;
  border-top: 1px solid #fef3c7;
}

.merged-note-section .side-note-header {
  margin-bottom: 0.5rem;
}

.merged-note-section .side-note-content {
  margin-bottom: 0.5rem;
}

.merged-note-section .side-note-link {
  margin-top: 0.5rem;
}

/* ===== CHAT SECTION (RIGHT) ===== */
.chat-section {
  flex: 0 0 35%;
  display: flex;
  flex-direction: column;
  background: #FCF9F5;
  border-right: none; /* No border on the right since it's rightmost */
  order: 5; /* Position on right */
  min-width: 0; /* Allow shrinking below content width */
  overflow: hidden; /* Prevent content from expanding section */
}

/* When side notes collapsed, chat section maintains its width (dynamically calculated in JS) */

.chat-header {
  padding: 1rem 2rem;
  border-bottom: 1px solid #e5e5e5;
  background: #ffffff;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0; /* Allow shrinking in flex context */
  overflow: hidden; /* Prevent content from expanding */
}

.chat-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #282F38;
  font-family: "source-sans-pro", -apple-system, BlinkMacSystemFont, sans-serif;
}

.selected-text-display {
  display: none !important;

  background: #fef3c7;
  border-left: 3px solid #fbbf24;
  padding: 0.75rem 1rem;
  margin: 1rem 1.5rem;
  font-size: 0.875rem;
  color: #78350f;
  border-radius: 4px;
  max-height: 5rem;
  overflow-y: auto;
  word-wrap: break-word;
  line-height: 1.5;
}

.selected-text-display.hidden {
  display: none;
}

.selected-text-count {
  font-size: 0.75rem;
  color: #92400e;
  font-weight: normal;
  opacity: 0.8;
  margin-left: 0.5rem;
}

.chat-messages {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  overflow-x: hidden; /* Prevent horizontal overflow */
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0; /* Allow shrinking in flex context */
}

/* Empty State for Chat */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  text-align: center;
}

.chat-empty-state h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 0.5rem;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

.chat-empty-state p {
  color: #6b7280;
  font-size: 0.8125rem;
  margin-bottom: 2rem;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

.example-prompts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  width: 100%;
  max-width: 500px;
}

.example-prompt {
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 1rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}

.example-prompt:hover {
  background: #f9fafb;
  border-color: #282F38;
  transform: translateY(-1px);
}

.example-prompt-text {
  font-size: 0.875rem;
  color: #1a1a1a;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.example-prompt-description {
  font-size: 0.75rem;
  color: #6b7280;
}

/* Messages */
.message {
  position: relative;
  padding: 0.875rem 1rem;
  border-radius: 8px;
  max-width: 85%;
  word-wrap: break-word;
}

.message.user {
  background: #282F38;
  color: white;
  align-self: flex-end;
  margin-left: auto;
}

.message.assistant {
  background: #ffffff;
  color: #1a1a1a;
  align-self: flex-start;
  border: 1px solid #e5e5e5;
}

.message-content {
  line-height: 1.6;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  margin: 1rem 0 0.5rem 0;
  font-weight: 600;
}

.message-content h1 {
  font-size: 1.25rem;
}
.message-content h2 {
  font-size: 1.125rem;
}
.message-content h3 {
  font-size: 1rem;
}
.message-content h4 {
  font-size: 0.875rem;
}

.message-content p {
  margin: 0.5rem 0;
}

.message-content ul,
.message-content ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.message-content li {
  margin: 0.25rem 0;
}

.message-content code {
  background: #f3f4f6;
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  font-family: "Monaco", "Courier New", monospace;
  font-size: 0.875em;
}

.message-content pre {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 0.75rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message-content pre code {
  background: none;
  padding: 0;
}

.message-content a {
  overflow-wrap: anywhere;
}

/* Book passage links - inline bracket style */
.book-passage-link {
  color: #2563eb;
  font-size: 0.85em;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: normal;
}

.book-passage-link:hover {
  color: #1d4ed8;
  background: #eff6ff;
  border-radius: 3px;
  padding: 1px 3px;
  margin: 0 -3px;
}

.book-link-context {
  color: #9ca3af;
  font-size: 0.8em;
}

/* Highlight flash effect when navigating to a passage */
.highlight-flash {
  animation: highlightFlash 2s ease-out;
}

@keyframes highlightFlash {
  0% {
    background-color: #fef3c7;
    box-shadow: 0 0 0 4px #fef3c7;
  }
  100% {
    background-color: transparent;
    box-shadow: none;
  }
}

/* Navigation Toast */
.navigation-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1a1a1a;
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}

.navigation-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.message-meta {
  font-size: 0.75rem;
  color: #9ca3af;
  margin-top: 0.5rem;
}

.message.user .message-meta {
  color: rgba(255, 255, 255, 0.7);
}

.message.smart-model {
  padding: 2rem 1rem;
}

.smart-model-badge {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #000;
  background: #fafafa;
  border: 1px solid #ccc;
  border-radius: 9999px;
  padding: 0.15rem 0.5rem;
  line-height: 1.4;
  z-index: 1;
}

.smart-model-badge::before {
  content: "✦";
  font-size: 0.55rem;
}

/* Web search citation sources */
.web-citations {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e5e7eb;
}

.web-citations-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.web-citations-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.web-citation-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.625rem;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  font-size: 0.8125rem;
  transition: all 0.15s ease;
  max-width: 280px;
}

.web-citation-link:hover {
  background: #f0f4ff;
  border-color: #c7d2fe;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.web-citation-favicon {
  flex-shrink: 0;
  border-radius: 2px;
}

.web-citation-info {
  overflow: hidden;
  min-width: 0;
}

.web-citation-title {
  font-weight: 500;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.web-citation-domain {
  font-size: 0.6875rem;
  color: #9ca3af;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-references {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e5e5e5;
}

.reference-link {
  display: flex;
  width: 100%;
  padding: 0.875rem 1rem;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #374151;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.reference-link:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #1f2937;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.reference-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}

.reference-title {
  font-weight: 600;
  font-size: 0.8125rem;
  color: #1f2937;
  line-height: 1.3;
}

.reference-summary {
  font-weight: 400;
  font-size: 0.75rem;
  color: #6b7280;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

.chat-input-container {
  padding: 1.5rem;
  border-top: 1px solid #e5e5e5;
  display: flex;
  gap: 0.75rem;
  background: #ffffff;
  min-width: 0; /* Allow shrinking in flex context */
  overflow: visible;
}

.chat-input-container input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  font-size: 0.875rem;
  background: #ffffff;
}

.chat-input-container input:focus {
  outline: none;
  border-color: #282F38;
}

/* ===== QUICK ACCESS PROMPT MENU ===== */
.quick-access-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-access-btn:hover {
  background: #e8e8ff;
  border-color: #c7c7ff;
}

.quick-access-btn.active {
  background: #e8e8ff;
  border-color: #818cf8;
}

.quick-access-btn-icon {
  font-size: 1.1rem;
  color: #6366f1;
  line-height: 1;
}

.quick-access-menu {
  position: absolute;
  bottom: calc(100%);
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid #e5e5e5;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.1);
  z-index: 50;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.quick-access-menu.hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.quick-access-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem 0.75rem;
}

.quick-access-icon {
  font-size: 1rem;
  color: #6366f1;
}

.quick-access-title {
  font-size: 0.925rem;
  font-weight: 700;
  color: #1a1a1a;
  flex: 1;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

.quick-access-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: #9ca3af;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.quick-access-close:hover {
  color: #1a1a1a;
  background: #f3f4f6;
}

.quick-access-options {
  padding: 0 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.quick-access-option {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 0.875rem;
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.15s ease;
}

.quick-access-option:hover {
  background: #f9fafb;
}

.quick-access-option-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  margin-top: 0.0625rem;
}

.quick-access-option-content {
  display: flex;
  flex-direction: column;
  gap: 0.1875rem;
}

.quick-access-option-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #1a1a1a;
  line-height: 1.3;
}

.quick-access-option-desc {
  font-size: 0.8125rem;
  color: #6b7280;
  line-height: 1.4;
}

/* Position chat-input-container as anchor for the quick access menu */
.chat-input-container {
  position: relative;
}

/* ===== MODAL ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow: hidden;
}

.modal-header {
  background: #ffffff;
  border-bottom: 1px solid #e5e5e5;
  padding: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-body {
  padding: 1.5rem;
}

.modal-body input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.modal-body input:focus {
  outline: none;
  border-color: #2563eb;
}

.search-results {
  max-height: 500px;
  overflow-y: auto;
  margin-top: 1rem;
}

.search-result {
  padding: 1rem;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
  background: white;
}

.search-result:hover {
  background: #f9fafb;
  border-color: #2563eb;
}

.search-result-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.search-result-page {
  font-weight: 600;
  color: #2563eb;
}

.search-result-content {
  color: #4b5563;
  line-height: 1.6;
  font-size: 0.875rem;
}

.search-result-chapter {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 0.5rem;
}

/* ===== LOADING & ERRORS ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  color: #6b7280;
}

.loading-spinner {
  border: 2px solid #e5e5e5;
  border-top: 2px solid #282F38;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  /* animation: spin 1s linear infinite; */
  display: inline-block;
  margin-right: 0.5rem;
}

.chat-section .message-content .loading-spinner {
  animation: spin 1s linear infinite;
}

.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.thinking-text {
  font-size: 0.9rem;
  color: #6b7280;
  transition: opacity 0.2s ease;
}

.thinking-text.thinking-fade {
  opacity: 0;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.error {
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 1rem;
  border-radius: 8px;
  margin: 1rem 0;
}

/* ===== IMAGE SUPPORT ===== */
.image-container {
  text-align: center;
  margin: 2rem 0;
}

.book-image {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  cursor: pointer;
}

.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.image-modal.hidden {
  display: none;
}

.image-modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
}

.image-modal-img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 8px;
}

.image-modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 5px 15px;
  border-radius: 4px;
}

.image-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ===== TEXT SELECTION DROPDOWN ===== */
.text-selection-dropdown {
  position: fixed;
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  min-width: 260px;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.15s ease;
  pointer-events: none;
}

.text-selection-dropdown.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

.dropdown-header {
  padding: 0.75rem;
  border-bottom: 1px solid #e5e5e5;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dropdown-header > i {
  color: #6b7280;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.dropdown-selected-text {
  font-size: 0.75rem;
  color: #6b7280;
  flex: 1;
  font-style: italic;
}

.dropdown-hint {
  background: #f3f4f6;
  color: #6b7280;
  font-size: 0.625rem;
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  font-family: monospace;
}

.dropdown-close {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  padding: 0.25rem;
  margin-left: auto;
}

.dropdown-close:hover {
  color: #1a1a1a;
}

.dropdown-actions {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.dropdown-action {
  display: flex;
  align-items: flex-start;
  padding: 0.75rem;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.15s ease;
  gap: 0.75rem;
}

.dropdown-action:hover {
  background: #f9fafb;
}

.dropdown-action i {
  margin-top: 0.125rem;
  color: #6b7280;
  flex-shrink: 0;
}

.dropdown-action > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.dropdown-action div:not(small) {
  font-weight: 500;
  color: #1a1a1a;
  font-size: 0.875rem;
}

.dropdown-action small {
  color: #6b7280;
  font-size: 0.75rem;
  display: block;
}

/* ===== STORAGE & HISTORY ===== */
.clear-history-btn {
  background: #382E28 !important;
  color: white !important;
  border-radius: 6px;
}

.clear-history-btn:hover {
  background: #2a211c !important;
}

.chat-restoration-notice {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: #4b5563;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.clear-history-inline {
  background: #ef4444;
  color: white;
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
}

.clear-history-inline:hover {
  background: #dc2626;
}

/* ===== SIDE NOTES CONFIGURATION MODAL ===== */
.modal-large {
  max-width: 700px;
}

.config-instructions {
  background: #eff6ff;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.config-instructions i {
  color: #2563eb;
  font-size: 1.25rem;
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.config-instructions p {
  font-size: 0.875rem;
  color: #1e40af;
  line-height: 1.6;
  margin: 0;
}

.config-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 0.5rem;
}

.config-textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
    sans-serif;
  line-height: 1.6;
  resize: vertical;
  min-height: 150px;
}

.config-textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.config-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.config-status {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  text-align: center;
}

.config-status.success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.config-status.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.config-status.hidden {
  display: none;
}

/* ===== MOBILE CHAT BUBBLE ===== */
.chat-bubble-btn {
  display: none;
  position: fixed;
  bottom: 75px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #282F38;
  color: #ffffff;
  border: none;
  cursor: pointer;
  z-index: 1001;
  box-shadow: 0 4px 12px rgba(40, 47, 56, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.chat-bubble-btn.dragging {
  opacity: 0.85;
  transition: none;
}

.chat-bubble-btn:active:not(.dragging) {
  transform: scale(0.92);
}

.chat-bubble-btn .chat-bubble-close-icon {
  display: none;
}

.chat-bubble-btn.chat-open .chat-bubble-icon {
  display: none;
}

.chat-bubble-btn.chat-open .chat-bubble-close-icon {
  display: inline;
}

.chat-bubble-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #ffffff;
}

.chat-bubble-badge.hidden {
  display: none;
}

.chat-bubble-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.chat-bubble-backdrop.visible {
  opacity: 1;
}

.chat-bubble-backdrop.hidden {
  display: none;
}

/* ===== MOBILE CHAPTER NAV ARROWS (header) ===== */
.btn-nav-mobile {
  display: none;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 1400px) {
  .book-section {
    flex: 0 0 35%;
  }

  .side-notes-section {
    flex: 0 0 30%;
  }

  .chat-section {
    flex: 0 0 35%;
  }
}

@media (max-width: 1024px) {
  .chapter-nav {
    display: none;
  }

  .chapter-nav-backdrop {
    display: none !important;
  }

  .split-container {
    margin-left: 0;
    max-width: 100vw;
  }

  .book-section {
    flex: 1 1 100% !important;
    max-height: none;
    border-right: none;
  }

  .side-notes-section {
    border-right: none;
    border-bottom: 1px solid #e5e5e5;
  }

  .side-notes-section.collapsed {
    max-height: 0;
    min-height: 0;
    padding: 0;
    border: none;
  }

  #resizeHandle2 {
    display: none !important;
  }

  .book-footer {
    display: none;
  }

  .book-content {
    padding-left: 3rem;
  }

  .page-anchor[data-display-page]::before {
    display: none;
  }

  .btn-nav-mobile {
    display: flex;
  }

  .chat-section {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 85vh;
    max-height: none;
    flex: none !important;
    z-index: 1000;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    order: unset;
  }

  .chat-section.chat-open {
    transform: translateY(0);
  }

  .chat-bubble-btn {
    display: flex;
  }

  .chat-bubble-backdrop {
    display: block;
  }

  .chat-bubble-backdrop.hidden {
    display: none;
  }
}

@media (max-width: 768px) {
  .book-header {
    padding: 0.5rem 0.5rem;
    gap: 0.25rem;
    min-height: auto;
  }

  .book-header h1 {
    font-size: 0.95rem;
  }

  .header-book-title {
    display: none;
  }

  .book-header-title {
    overflow: hidden;
  }

  .book-header-title h1 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-buttons {
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .header-buttons .btn-audio,
  .header-buttons .btn-header-icon {
    width: 32px;
    height: 32px;
    font-size: 0.75rem;
  }

  .book-content {
    padding: 1.5rem;
  }

  .page-content {
    font-size: 1rem;
  }

  .page-anchor[data-display-page]::before {
    display: none;
  }

  .book-footer {
    padding: 1rem;
  }

  .chat-section {
    height: 90vh;
  }

  .chat-bubble-btn {
    bottom: 75px;
    right: 20px;
  }
}

/* ===== AUDIO PLAYER ===== */
.header-buttons {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.btn-audio {
  background: white;
  color: #282F38;
  border: 1px solid #9CA3AF;
  border-radius: 9999px;
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-audio i {
  margin-right: 0;
}

.btn-audio #audioBtnText {
  display: none;
}

.btn-audio:hover {
  background: #f5f5f5;
  border-color: #6B7280;
}

.btn-audio.playing {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
}

.btn-audio.playing:hover {
  background: #dc2626;
  border-color: #dc2626;
}

.audio-player-container {
  display: none !important;
}

.audio-player-container.hidden {
  display: none !important;
}

.audio-player {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e5e5e5;
}

.audio-control-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: #667eea;
  transition: all 0.2s ease;
  padding: 0.5rem;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.audio-control-btn:hover {
  background: #667eea;
  color: white;
}

.audio-progress-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.audio-progress-bar {
  width: 100%;
  height: 6px;
  background: #e5e5e5;
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.audio-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s linear;
}

.audio-time {
  font-size: 0.75rem;
  color: #666;
  font-variant-numeric: tabular-nums;
}

.audio-controls-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#audioSpeedBtn {
  font-size: 0.875rem;
  font-weight: 600;
  width: auto;
  padding: 0.5rem 0.75rem;
}

.audio-status {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: #666;
  text-align: center;
}

.audio-status.loading {
  color: #667eea;
}

.audio-status.error {
  color: #dc3545;
}

.audio-status.success {
  color: #28a745;
}

/* ===== TEXT HIGHLIGHTING FOR AUDIO ===== */
.reading-highlight {
  background: #3b82f6 !important; /* Modern blue */
  color: #ffffff !important; /* White text */
  padding: 0.5rem 1rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* Make paragraphs targetable for highlighting */
.page-content p,
.page-content h1,
.page-content h2,
.page-content h3,
.page-content h4,
.page-content h5,
.page-content h6 {
  scroll-margin-top: 2rem;
}

/* Loading spinner for audio generation */
.audio-loading-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-left: 0.5rem;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Audio Loading Overlay */
.audio-loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.audio-loading-overlay.hidden {
  display: none;
}

.audio-loading-content {
  text-align: center;
  padding: 2rem;
}

.audio-loading-spinner-large {
  width: 60px;
  height: 60px;
  border: 4px solid #e5e7eb;
  border-top: 4px solid #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1.5rem;
}

.audio-loading-text {
  font-size: 1.125rem;
  color: #1f2937;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.audio-loading-subtext {
  font-size: 0.875rem;
  color: #6b7280;
}

/* ===== WEB SEARCH FEATURES ===== */

/* Chat Header Controls */
.chat-header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Web Search Toggle (compact for header) */
.web-search-toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  cursor: pointer;
  padding: 0.375rem 0.625rem;
  border-radius: 6px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.web-search-toggle:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.web-search-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: #3b82f6;
  margin: 0;
}

.web-search-toggle .toggle-label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: #4b5563;
  font-weight: 500;
  user-select: none;
  white-space: nowrap;
}

.web-search-toggle .toggle-label i {
  font-size: 0.813rem;
  color: #3b82f6;
}

.web-search-toggle input[type="checkbox"]:checked + .toggle-label {
  color: #1f2937;
}

/* Supporting Links Button */
.btn-links {
  background: #f9fafb;
  color: #4b5563;
  border: 1px solid #e5e7eb;
  padding: 0.375rem 0.625rem;
  font-size: 0.813rem;
}

.btn-links:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #1f2937;
}

.btn-links i {
  font-size: 0.875rem;
}

/* Web Search Badge in Messages */
.web-search-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.375rem;
  background: #dbeafe;
  color: #1e40af;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.web-search-badge i {
  font-size: 0.7rem;
}

/* Supporting Links Modal Content */
.supporting-links-content {
  max-height: 70vh;
  overflow-y: auto;
}

.supporting-links-header {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid #e5e7eb;
}

.supporting-links-header h4 {
  font-size: 1.125rem;
  color: #111827;
  margin-bottom: 0.25rem;
}

.supporting-links-header .chapter-info {
  font-size: 0.875rem;
  color: #6b7280;
}

/* Supporting Links List */
.supporting-links-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.support-link-item {
  padding: 1rem;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  transition: all 0.15s ease;
}

.support-link-item:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.link-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.link-header i {
  font-size: 1rem;
  color: #3b82f6;
  flex-shrink: 0;
}

.link-title {
  flex: 1;
  font-size: 0.938rem;
  font-weight: 600;
  color: #1f2937;
  text-decoration: none;
  line-height: 1.4;
}

.link-title:hover {
  color: #2563eb;
  text-decoration: underline;
}

.link-type-badge {
  padding: 0.125rem 0.5rem;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 12px;
  font-size: 0.688rem;
  font-weight: 600;
  text-transform: uppercase;
  flex-shrink: 0;
}

.link-description {
  font-size: 0.875rem;
  color: #4b5563;
  line-height: 1.5;
  margin-left: 1.5rem;
}

.links-footer {
  text-align: center;
  padding-top: 1rem;
  margin-top: 1rem;
  border-top: 1px solid #e5e7eb;
  font-size: 0.75rem;
  color: #9ca3af;
}

/* Empty State for Links */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
}

.empty-state i {
  font-size: 3rem;
  color: #d1d5db;
  margin-bottom: 1rem;
}

.empty-state p {
  font-size: 0.938rem;
  color: #6b7280;
  margin-bottom: 1.5rem;
}

/* Error Message for Links */
.error-message {
  text-align: center;
  padding: 2rem;
}

.error-message i {
  font-size: 2.5rem;
  color: #ef4444;
  margin-bottom: 1rem;
}

.error-message p {
  font-size: 0.938rem;
  color: #6b7280;
  margin-bottom: 1.5rem;
}

/* Loading State */
.loading {
  text-align: center;
  padding: 2rem;
  color: #6b7280;
}

.loading i {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .chat-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .chat-header-controls {
    width: 100%;
    justify-content: flex-end;
  }

  .web-search-toggle .toggle-label {
    font-size: 0.688rem;
  }

  .btn-links {
    padding: 0.375rem 0.5rem;
  }
}
