/* Reader page styles */
.page-reader {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Navbar reader mode styles */
.navbar .file-title {
  font-size: 0.9375rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  color: var(--text-primary);
}

.navbar .back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  transition: all 0.15s;
  flex-shrink: 0;
  text-decoration: none;
}

.navbar .back-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.navbar .zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all 0.15s;
}

.navbar .zoom-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.navbar .zoom-level {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  min-width: 44px;
  text-align: center;
}

.reader-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Table of Contents sidebar */
.toc-panel {
  width: 240px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 16px 0;
  transition: width 0.2s ease, padding 0.2s ease;
}

.toc-panel .toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 8px;
}

.toc-panel .toc-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

/* Resize handle between TOC and doc */
.toc-resize-handle {
  width: 10px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.toc-resize-handle:hover {
  background: var(--border-light);
}

.toc-resize-handle:active {
  background: var(--border-color);
}

.toc-resize-grip {
  display: flex;
  flex-direction: column;
  gap: 3px;
  opacity: 0.4;
  padding: 4px;
  border-radius: 3px;
  transition: opacity 0.15s, background 0.15s;
}

.toc-resize-handle:hover .toc-resize-grip {
  opacity: 0.7;
  background: var(--border-light);
}

.toc-resize-handle:active .toc-resize-grip {
  opacity: 1;
  background: var(--border-color);
}

.toc-resize-grip span {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-secondary);
}

/* Expand button (shown when TOC is collapsed) */
.toc-expand-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 40px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-left: none;
  border-radius: 0 6px 6px 0;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
  z-index: 10;
}

.toc-expand-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.toc-panel .toc-item {
  display: block;
  padding: 6px 16px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-panel .toc-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.toc-panel .toc-item.level-2 { padding-left: 28px; }
.toc-panel .toc-item.level-3 { padding-left: 40px; }

/* Document content area */
.doc-container {
  flex: 1;
  overflow: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.doc-content {
  width: 100%;
  max-width: 900px;
  min-height: 200px;
  overflow: auto;
}

/* PDF mode: allow canvas to exceed container width for zoom */
.doc-content.pdf-mode {
  max-width: none;
  overflow: auto;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  margin-top: auto;
}

.page-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all 0.15s;
}

.page-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-info {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* PDF canvas */
.pdf-canvas-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.pdf-canvas-wrapper canvas {
  box-shadow: var(--shadow-sm);
}

/* Markdown content */
.md-content {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text-primary);
}

.md-content h1, .md-content h2, .md-content h3,
.md-content h4, .md-content h5, .md-content h6 {
  margin: 1.5em 0 0.5em;
  font-weight: 700;
  line-height: 1.3;
}

.md-content h1 { font-size: 1.75rem; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.md-content h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border-light); padding-bottom: 6px; }
.md-content h3 { font-size: 1.25rem; }

.md-content p { margin: 0.75em 0; }
.md-content a { color: var(--accent); }

.md-content code {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.875em;
}

.md-content pre {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
  margin: 1em 0;
}

.md-content pre code {
  background: none;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.6;
}

.md-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin: 1em 0;
  color: var(--text-secondary);
  background: var(--bg-hover);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.md-content ul, .md-content ol {
  padding-left: 24px;
  margin: 0.75em 0;
}

.md-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
}

.md-content th, .md-content td {
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  text-align: left;
}

.md-content th {
  background: var(--bg-hover);
  font-weight: 600;
}

.md-content img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* Error state */
.reader-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 16px;
  flex: 1;
}

.reader-error .error-icon {
  font-size: 3rem;
  opacity: 0.5;
}

.reader-error h3 {
  color: var(--text-primary);
}

.reader-error p {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.reader-error .download-btn {
  padding: 8px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  transition: background 0.2s;
}

.reader-error .download-btn:hover {
  background: var(--accent-hover);
}

/* Loading */
.reader-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-muted);
  gap: 8px;
  font-size: 0.9375rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Responsive */
@media (max-width: 767px) {
  .toc-panel,
  .toc-resize-handle,
  .toc-expand-btn {
    display: none !important;
  }

  .navbar .file-title {
    font-size: 0.875rem;
  }

  .navbar .zoom-btn,
  .navbar .zoom-level {
    display: none;
  }

  .doc-container {
    padding: 16px;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .toc-panel {
    width: 200px;
  }
}
