:root {
  --reader-bg: #f8f9fa;
  --reader-text: #212529;
  --reader-sidebar: #fff;
  --reader-chat: #fff;
  --accent: #2563eb;
  --accent-light: #e0e7ff;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --bubble-user: #e3f2fd;
  --bubble-ai: #f5f5f5;
}

body {
  background-color: var(--reader-bg);
  color: var(--reader-text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.7;
}

.sticky-top, .navbar {
  position: sticky !important;
  top: 0;
  z-index: 1050;
  background: #fff;
  box-shadow: var(--shadow);
}

/* Ensure Bootstrap dropdowns work properly in book reader */
.navbar .dropdown-menu {
  z-index: 1055;
}

/* Ensure dropdown toggles work */
.navbar .dropdown-toggle[data-bs-toggle="dropdown"] {
  cursor: pointer;
}

/* Ensure dropdowns are visible and properly positioned */
.navbar .dropdown-menu.show {
  display: block !important;
}

/* Prevent any overflow issues that might hide dropdowns */
.navbar {
  overflow: visible !important;
}

.navbar-nav {
  overflow: visible !important;
}

.reader-container {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
  gap: 1.5rem;
  padding: 1.5rem 1.5rem 1.5rem 1.5rem;
}

.toc-sidebar {
  background: var(--reader-sidebar);
  border-radius: 12px;
  padding: 1.5rem 1rem;
  box-shadow: var(--shadow);
  min-width: 220px;
  max-width: 260px;
  position: sticky;
  top: 90px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  transition: transform 0.3s;
}

/* Custom scrollbar for TOC */
.toc-sidebar::-webkit-scrollbar {
  width: 6px;
}

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

.toc-sidebar::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.toc-sidebar::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.toc-toggle-btn {
  position: fixed;
  left: 16px;
  top: 80px;
  z-index: 1100;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
}

.toc-toggle-btn.hide {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.content-area {
  background: var(--reader-sidebar);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
  max-width: 800px;
  flex: 1 1 0%;
  margin: 0 auto;
  min-width: 0;
}

.chat-sidebar {
  background: var(--reader-chat);
  border-radius: 12px;
  padding: 1.5rem 1rem;
  box-shadow: var(--shadow);
  min-width: 300px;
  max-width: 370px;
  display: flex;
  flex-direction: column;
  height: 80vh;
  position: sticky;
  top: 90px;
}

/* Enhanced TOC Styling */
.toc-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-nav li {
  margin-bottom: 0.25rem;
}

.toc-nav a {
  color: var(--reader-text);
  text-decoration: none;
  display: block;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  position: relative;
}

.toc-nav a:hover, .toc-nav .active {
  background: linear-gradient(135deg, var(--accent-light) 0%, #dbeafe 100%);
  color: var(--accent);
  font-weight: 500;
  transform: translateX(4px);
}

.toc-nav a.chapter-link {
  font-weight: 600;
  font-size: 1rem;
  color: #1e293b;
  border-left: 3px solid transparent;
}

/* Remove chapter numbering from chapter links */

.toc-nav a.chapter-link:hover,
.toc-nav a.chapter-link.active {
  border-left-color: var(--accent);
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.toc-nav a.section-link {
  font-size: 0.9rem;
  color: #64748b;
  padding-left: 2.5rem;
  position: relative;
}

.toc-nav a.section-link::before {
  content: '•';
  position: absolute;
  left: 1.5rem;
  color: #94a3b8;
}

.toc-nav a.section-link:hover,
.toc-nav a.section-link.active {
  color: var(--accent);
  background: #f8fafc;
}

/* Collapsible TOC Sections */
.toc-chapter {
  margin-bottom: 0.5rem;
}

.toc-chapter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  font-weight: 600;
  font-size: 1rem;
  color: #1e293b;
  border-left: 3px solid transparent;
}

/* Remove chapter numbering from TOC */

.toc-chapter-header:hover {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-left-color: var(--accent);
}

.toc-chapter-header .toggle-icon {
  font-size: 0.8rem;
  color: #94a3b8;
  transition: transform 0.2s ease;
}

.toc-chapter-header.expanded .toggle-icon {
  transform: rotate(90deg);
}

.toc-sections {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  margin-left: 1rem;
  border-left: 2px solid #e2e8f0;
  padding-left: 0.5rem;
}

.toc-sections.expanded {
  max-height: 500px;
}

.toc-sections a {
  font-size: 0.85rem;
  color: #64748b;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.25rem;
  border-radius: 6px;
  transition: all 0.2s ease;
  position: relative;
}

.toc-sections a::before {
  content: '•';
  position: absolute;
  left: -0.5rem;
  color: #94a3b8;
}

.toc-sections a:hover,
.toc-sections a.active {
  color: var(--accent);
  background: #f8fafc;
  transform: translateX(2px);
}

/* Ensure nested TOC lists are properly styled */
.toc-nav .toc-nav {
  margin-left: 1rem;
  border-left: 2px solid #e5e7eb;
  padding-left: 0.5rem;
}

.version-switcher {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e5e7eb;
}

.chat-messages {
  flex-grow: 1;
  overflow-y: auto;
  margin-bottom: 1rem;
  min-height: 180px;
  max-height: 60vh;
  background: #f6f8fa;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-bubble {
  max-width: 80%;
  padding: 0.75em 1em;
  border-radius: 18px;
  margin-bottom: 0.25em;
  position: relative;
  word-break: break-word;
  font-size: 1.05em;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.chat-bubble.user {
  background: var(--bubble-user);
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  margin-left: auto;
}

.chat-bubble.ai {
  background: var(--bubble-ai);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  margin-right: auto;
}

.chat-bubble .context-chip {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 12px;
  font-size: 0.85em;
  padding: 0.1em 0.7em;
  margin-bottom: 0.3em;
  margin-right: 0.5em;
  font-weight: 500;
}

.chat-bubble .meta {
  font-size: 0.8em;
  color: #888;
  margin-top: 0.2em;
  text-align: right;
}

.chat-input {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.chat-input textarea {
  flex-grow: 1;
  resize: none;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  padding: 0.75rem;
  min-height: 44px;
  font-size: 1rem;
}

.context-chip {
  display: inline-flex;
  align-items: center;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 16px;
  padding: 0.25em 0.75em;
  font-size: 0.95em;
  margin-bottom: 0.5em;
  margin-right: 0.5em;
  font-weight: 500;
}

.context-chip .remove-context {
  margin-left: 0.5em;
  color: #888;
  background: none;
  border: none;
  font-size: 1.1em;
  cursor: pointer;
}

.thread-list {
  margin-top: 1.5em;
  border-top: 1px solid #e5e7eb;
  padding-top: 1em;
  max-height: 120px;
  overflow-y: auto;
}

.thread-row {
  padding: 0.5em 0.75em;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 1em;
  color: var(--accent);
  font-weight: 500;
}

.thread-row:hover, .thread-row.active {
  background: var(--accent-light);
}

.new-chat-btn {
  margin-bottom: 1em;
  width: 100%;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1.05em;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5em 0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

/* Enhanced Chapter and Section Styling */
.chapter-content {
  margin-bottom: 4rem;
  padding: 2rem;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  position: relative;
  overflow: hidden;
}

.chapter-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent) 0%, #3b82f6 100%);
}

.chapter-content h2 {
  font-size: 2rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid #e2e8f0;
  position: relative;
  text-align: left;
}

/* Remove chapter numbering from UI */

.section-content {
  margin-bottom: 2rem;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  transition: none;
}

.section-content:hover {
  box-shadow: none;
  transform: none;
}

.section-content h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #f1f5f9;
}

.section-text {
  line-height: 1.8;
  color: #475569;
  font-size: 1.05rem;
}

.section-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

.section-actions .btn-group {
  box-shadow: none;
}

.section-actions button {
  font-size: 0.95rem;
  border-radius: 6px;
}

.social-share .btn {
  padding: 0.25rem 0.5rem;
}

.social-share .btn i {
  font-size: 1.1rem;
}

.rating-input {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-start;
  gap: 0.5rem;
  margin: 1rem 0;
}

.rating-input input {
  display: none;
}

.rating-input label {
  cursor: pointer;
  font-size: 2rem;
  color: #ddd;
  transition: color 0.2s;
}

.rating-input label:hover,
.rating-input label:hover ~ label,
.rating-input input:checked ~ label {
  color: #ffc107;
}

/* Social Sharing Styles */
.book-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e5e7eb;
}

.social-share .btn-group {
  box-shadow: none;
}

.social-share .btn {
  padding: 0.25rem 0.5rem;
}

.social-share .btn i {
  font-size: 1.1rem;
}

/* Book Actions Styles */
.book-actions-end {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid #e5e7eb;
  background-color: var(--reader-sidebar);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.book-actions-end .book-info {
  flex-grow: 1;
}

.book-actions-end .book-info h2 {
  margin-bottom: 0.5rem;
  font-size: 1.5rem;
}

.book-actions-end .book-info p {
  color: #666;
  margin-bottom: 0;
}

.book-actions-end .actions {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.book-end-actions {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid #e5e7eb;
  text-align: center;
}

.book-end-actions h3 {
  margin-bottom: 1rem;
  color: #666;
}

.book-end-actions .btn-group {
  margin-top: 1rem;
}

/* Markdown styling for chat bubbles */
.chat-bubble.ai div {
  line-height: 1.5;
}

.chat-bubble.ai h1,
.chat-bubble.ai h2,
.chat-bubble.ai h3,
.chat-bubble.ai h4,
.chat-bubble.ai h5,
.chat-bubble.ai h6 {
  margin: 0.5em 0 0.3em 0;
  font-weight: 600;
  color: #333;
}

.chat-bubble.ai h1 { font-size: 1.3em; }
.chat-bubble.ai h2 { font-size: 1.2em; }
.chat-bubble.ai h3 { font-size: 1.1em; }
.chat-bubble.ai h4 { font-size: 1.0em; }
.chat-bubble.ai h5 { font-size: 0.9em; }
.chat-bubble.ai h6 { font-size: 0.8em; }

.chat-bubble.ai p {
  margin: 0.3em 0;
}

.chat-bubble.ai ul,
.chat-bubble.ai ol {
  margin: 0.3em 0;
  padding-left: 1.5em;
}

.chat-bubble.ai li {
  margin: 0.2em 0;
}

.chat-bubble.ai code {
  background: #f1f3f4;
  padding: 0.1em 0.3em;
  border-radius: 3px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.9em;
}

.chat-bubble.ai pre {
  background: #f6f8fa;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  padding: 0.8em;
  margin: 0.5em 0;
  overflow-x: auto;
}

.chat-bubble.ai pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

.chat-bubble.ai blockquote {
  border-left: 4px solid #dfe2e5;
  margin: 0.5em 0;
  padding-left: 1em;
  color: #6a737d;
}

.chat-bubble.ai strong {
  font-weight: 600;
}

.chat-bubble.ai em {
  font-style: italic;
}

.chat-bubble.ai a {
  color: #0366d6;
  text-decoration: none;
}

.chat-bubble.ai a:hover {
  text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 1200px) {
  .reader-container {
    flex-direction: column;
    gap: 0;
  }
  .toc-sidebar, .chat-sidebar {
    position: static;
    max-width: 100%;
    min-width: 0;
    width: 100%;
    margin-bottom: 1rem;
    top: unset;
  }
  .content-area {
    max-width: 100%;
    padding: 1rem;
  }
}

@media (max-width: 768px) {
  .reader-container {
    flex-direction: column;
    padding: 0.5rem;
  }
  .toc-sidebar {
    display: none;
    width: 100%;
    margin-bottom: 1rem;
  }
  .toc-toggle-btn {
    display: flex;
    width: 44px;
    height: 44px;
    left: 10px;
    top: 70px;
    position: fixed;
  }
  .chat-sidebar {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-bottom: 1rem;
    height: auto;
    min-height: 200px;
  }
  .content-area {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 0.5rem;
  }
  
  .chapter-content {
    padding: 1.5rem;
    margin-bottom: 3rem;
  }
  
  .section-content {
    padding: 1rem;
    margin-bottom: 2rem;
  }
  
  .chapter-content h2 {
    font-size: 1.75rem;
  }
  
  .section-content h3 {
    font-size: 1.25rem;
  }
}

/* Additional styles for inline elements */
.book-authors {
  color: #666;
  font-size: 1.1em;
}

.chat-topbar {
  gap: 0.5em;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.3em;
  line-height: 1;
}

.chat-title {
  font-weight: 600;
  font-size: 1.1em;
}

.thread-list-hidden {
  display: none;
}

.chat-input-container {
  position: relative;
  flex-direction: column;
  align-items: stretch;
}

.context-chip-container {
  margin-bottom: 0.25em;
}

.chat-input-field {
  text-align: left;
}

.chat-teaser {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 2em 1em;
}

.chat-teaser img {
  width: 48px;
  height: 48px;
  margin-bottom: 1em;
  opacity: 0.7;
}

.chat-teaser h6 {
  font-weight: 600;
  color: #2563eb;
  margin-bottom: 0.5em;
}

.chat-teaser p {
  color: #444;
  font-size: 1em;
  margin-bottom: 1.5em;
}

.chat-teaser .btn {
  border-radius: 8px;
  font-weight: 500;
}

.last-section-id {
  display: none;
}

/* Book Cover Styles */
.book-cover-toc {
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 1rem;
}

.cover-thumbnail {
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cover-thumbnail:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.cover-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}

.book-cover-section {
  margin-bottom: 3rem;
  text-align: center;
}

.cover-display {
  position: relative;
  display: inline-block;
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  max-width: 300px;
}

.cover-display:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.cover-main-img {
  width: 100%;
  height: auto;
  display: block;
  max-height: 400px;
  object-fit: contain;
}

.cover-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.7);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  font-size: 0.9rem;
}

.cover-display:hover .cover-overlay {
  opacity: 1;
}

.cover-overlay i {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.cover-modal-img {
  max-height: 70vh;
  object-fit: contain;
}

/* Responsive adjustments for cover */
@media (max-width: 768px) {
  .cover-img {
    height: 100px;
  }
  
  .cover-display {
    max-width: 250px;
  }
  
  .cover-main-img {
    max-height: 300px;
  }
}

/* Code Block Styles with Copy Button */
.code-block-container {
  position: relative;
  margin: 1rem 0;
  border-radius: 8px;
  overflow: hidden;
  background: #f6f8fa;
  border: 1px solid #e1e4e8;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: #f1f3f4;
  border-bottom: 1px solid #e1e4e8;
  font-size: 0.875rem;
  color: #586069;
}

.code-block-title {
  font-weight: 500;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.copy-button {
  background: #fff;
  border: 1px solid #d1d5da;
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  color: #586069;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.copy-button:hover {
  background: #f6f8fa;
  border-color: #0366d6;
  color: #0366d6;
}

.copy-button:active {
  background: #e1f5fe;
}

.copy-button.copied {
  background: #28a745;
  border-color: #28a745;
  color: #fff;
}

.code-block-content {
  padding: 1rem;
  overflow-x: auto;
  background: #f6f8fa;
}

.code-block-content pre {
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.code-block-content code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* Responsive adjustments for code blocks */
@media (max-width: 768px) {
  .code-block-container {
    margin: 0.5rem 0;
  }
  
  .code-block-header {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
  }
  
  .code-block-content {
    padding: 0.75rem;
  }
  
  .code-block-content pre {
    font-size: 0.8rem;
  }
} 