:root {
  --primary: #002B5B;
  --secondary: #5BC0EB;
  --bg: #F2F2F2;
  --text: #111827;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', 'Arial', sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container { width: min(1200px, 92%); margin: 0 auto; }
.topbar {
  background: var(--primary);
  color: white;
  padding: 1rem 0;
  box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}
.header-inner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.brand { display: flex; align-items: center; gap: 0.8rem; }
.logo { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; border: 2px solid white; }
.header-nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.header-nav a { color: white; text-decoration: none; font-weight: 600; }
.header-nav a:hover { color: var(--secondary); }

.filters-section { padding: 2rem 0; }
.filter-card { background: white; padding: 1.25rem; border-radius: 12px; box-shadow: 0 8px 20px rgba(0,0,0,0.06); }
.filter-card label { display: block; margin-bottom: 0.35rem; font-weight: 600; }
.filter-card select { width: 100%; padding: 0.8rem; border: 1px solid #cbd5e1; border-radius: 8px; }
.search-box { display: flex; gap: 0.5rem; margin-bottom: 1rem; width: 100%; }
.search-box input { flex: 1; width: 100%; padding: 0.9rem 1rem; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 1rem; }
.filter-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; align-items: end; }
.results-count { margin-top: 0.75rem; }
.btn { border: none; padding: 0.8rem 1rem; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn-primary { background: var(--primary); color: white; }
.btn-danger { background: #dc3545; color: white; }
.btn-secondary { background: #6c757d; color: white; }
.btn-block { width: 100%; display: block; }
.btn:hover { opacity: 0.92; }

.books-section { padding: 1rem 0 2rem; }
.books-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.book-card { background: white; border-radius: 12px; overflow: hidden; box-shadow: 0 8px 20px rgba(0,0,0,0.06); display: flex; flex-direction: column; }
.book-cover { height: 250px; background: #f8f9fa; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 0.5rem; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.book-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.45rem; }
.book-title { font-size: 1rem; font-weight: 700; min-height: 2.8rem; }
.book-meta { color: #4b5563; font-size: 0.9rem; }
.book-desc { color: #374151; font-size: 0.9rem; min-height: 3rem; }
.book-link { margin-top: auto; display: inline-block; text-align: center; text-decoration: none; background: var(--primary); color: white; padding: 0.7rem; border-radius: 8px; border: none; cursor: pointer; width: 100%; font-weight: 600; }
.book-badge { display: inline-block; background: var(--secondary); color: white; font-size: 0.75rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 99px; align-self: flex-start; margin-bottom: 0.25rem; }
.error-msg { color: #dc2626; font-weight: 600; }

.pagination-wrap { margin-top: 1.25rem; text-align: center; }
.pagination-inner { display: inline-flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; justify-content: center; }
.page-btn { border: 1px solid #cbd5e1; background: white; color: var(--text); padding: 0.5rem 0.85rem; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.9rem; transition: background 0.15s; }
.page-btn:hover:not(:disabled) { background: #e2e8f0; }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-ellipsis { color: #94a3b8; padding: 0 0.2rem; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: none; padding: 0; z-index: 1000; }
.modal.active { display: flex; flex-direction: column; }
.modal-card { background: white; padding: 1.25rem; border-radius: 0; width: 100%; height: 100%; max-width: none; max-height: none; overflow: auto; }
.modal-card ul { padding-left: 1rem; }
.modal-card.preview-modal { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.preview-topbar { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: 0.6rem 1rem; flex-shrink: 0; background: #f8f9fa; border-bottom: 1px solid #e5e7eb; }
.preview-topbar-info { min-width: 0; }
.preview-topbar-info h3 { margin: 0; font-size: 0.95rem; }
.preview-meta { color: #4b5563; margin: 0.1rem 0 0; font-size: 0.75rem; }
.preview-reader-full { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.preview-iframe { width: 100%; flex: 1; border: 0; background: #f8fafc; min-height: 0; }
.preview-no-reader { padding: 2rem; text-align: center; border: 1px dashed #cbd5e1; border-radius: 10px; background: #f8fafc; color: #6b7280; }

@media (max-width: 900px) {
  .filter-row { grid-template-columns: 1fr 1fr; }
  .books-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .filter-row { grid-template-columns: 1fr; }
  .books-grid { grid-template-columns: 1fr; }
}

/* PDF Viewer - Edge-style */
#pdf-viewer-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: #f3f3f3;
  z-index: 10000;
  flex-direction: column;
}
#pdf-viewer-modal.active { display: flex; }

.pdf-viewer-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Toolbar */
.pdf-toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.pdf-toolbar-section {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pdf-toolbar-section.center {
  flex: 1;
  justify-content: center;
}

.pdf-toolbar-title {
  font-size: 14px;
  font-weight: 500;
  color: #1a1a1a;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 16px;
}

.pdf-toolbar-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #5f6368;
  transition: all 0.15s ease;
  position: relative;
}

.pdf-toolbar-btn:hover {
  background: #f0f0f0;
  color: #1a1a1a;
}

.pdf-toolbar-btn:active {
  background: #e0e0e0;
  transform: scale(0.95);
}

.pdf-toolbar-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pdf-toolbar-btn:disabled:hover {
  background: transparent;
}

.pdf-toolbar-btn svg {
  width: 20px;
  height: 20px;
}

.pdf-toolbar-divider {
  width: 1px;
  height: 24px;
  background: #e0e0e0;
  margin: 0 8px;
}

/* Page input */
.pdf-page-input-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
}

.pdf-page-input {
  width: 50px;
  height: 28px;
  border: 1px solid #dadce0;
  border-radius: 4px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: #1a1a1a;
  outline: none;
  transition: border-color 0.15s;
}

.pdf-page-input:focus {
  border-color: #1a73e8;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.1);
}

.pdf-page-total {
  font-size: 13px;
  color: #5f6368;
}

/* Zoom dropdown */
.pdf-zoom-select {
  height: 28px;
  padding: 0 8px;
  border: 1px solid #dadce0;
  border-radius: 4px;
  font-size: 13px;
  color: #1a1a1a;
  background: white;
  cursor: pointer;
  outline: none;
}

.pdf-zoom-select:focus {
  border-color: #1a73e8;
}

/* Viewer body */
.pdf-viewer-body {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 40px 40px;
  background: #f3f3f3;
  user-select: none;
  -webkit-user-select: none;
  scroll-behavior: smooth;
}

.pdf-viewer-body canvas {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  background: white;
  cursor: default;
  transition: transform 0.2s ease;
}

/* Loading */
.pdf-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  z-index: 5;
}

.pdf-loading.active {
  display: flex;
}

.pdf-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e0e0e0;
  border-top-color: #1a73e8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.pdf-loading-text {
  font-size: 14px;
  color: #5f6368;
  font-weight: 500;
}

/* Progress bar */
.pdf-progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: #e0e0e0;
  z-index: 10;
}

.pdf-progress-fill {
  height: 100%;
  background: #1a73e8;
  transition: width 0.3s ease;
  width: 0%;
}

/* Tooltip */
.pdf-toolbar-btn[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: -32px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
}

/* Disable context menu */
.pdf-viewer-body,
.pdf-viewer-body canvas {
  -webkit-touch-callout: none;
}

/* Responsive */
@media (max-width: 768px) {
  .pdf-toolbar {
    height: 48px;
    padding: 0 8px;
    gap: 4px;
  }
  
  .pdf-toolbar-title {
    display: none;
  }
  
  .pdf-toolbar-btn {
    width: 32px;
    height: 32px;
  }
  
  .pdf-viewer-body {
    padding: 64px 20px 20px;
  }
  
  .pdf-page-input-group {
    padding: 0 4px;
  }
}

/* Fullscreen mode */
.pdf-viewer-container.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 10001;
}

.pdf-viewer-container.fullscreen .pdf-toolbar {
  opacity: 0;
  transition: opacity 0.3s;
}

.pdf-viewer-container.fullscreen:hover .pdf-toolbar {
  opacity: 1;
}

/* Sidebar for thumbnails */
.pdf-sidebar {
  position: absolute;
  top: 56px;
  left: 0;
  bottom: 0;
  width: 240px;
  background: white;
  border-right: 1px solid #e0e0e0;
  display: none;
  flex-direction: column;
  z-index: 9;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
}

.pdf-sidebar.active {
  display: flex;
}

.pdf-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pdf-sidebar-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
}

.pdf-sidebar-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #5f6368;
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.15s;
}

.pdf-sidebar-close:hover {
  background: #f0f0f0;
}

.pdf-sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pdf-thumbnail {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  transition: all 0.15s;
  background: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.pdf-thumbnail:hover {
  border-color: #1a73e8;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.pdf-thumbnail.active {
  border-color: #1a73e8;
}

.pdf-thumbnail canvas {
  width: 100%;
  height: auto;
  display: block;
}

.pdf-thumbnail-label {
  padding: 8px;
  text-align: center;
  font-size: 12px;
  color: #5f6368;
  background: #f8f9fa;
}

/* Bookmarks panel */
.pdf-bookmarks-panel {
  position: absolute;
  top: 56px;
  right: 0;
  bottom: 0;
  width: 300px;
  background: white;
  border-left: 1px solid #e0e0e0;
  display: none;
  flex-direction: column;
  z-index: 9;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
}

.pdf-bookmarks-panel.active {
  display: flex;
}

.pdf-bookmarks-header {
  padding: 16px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pdf-bookmarks-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
}

.pdf-bookmarks-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #5f6368;
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.15s;
}

.pdf-bookmarks-close:hover {
  background: #f0f0f0;
}

.pdf-bookmarks-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.pdf-bookmarks-empty {
  text-align: center;
  color: #5f6368;
  font-size: 14px;
  padding: 40px 20px;
}

.pdf-bookmark-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 8px;
}

.pdf-bookmark-item:hover {
  background: #f0f0f0;
}

.pdf-bookmark-icon {
  width: 32px;
  height: 32px;
  background: #1a73e8;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.pdf-bookmark-info {
  flex: 1;
  min-width: 0;
}

.pdf-bookmark-page {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 2px;
}

.pdf-bookmark-date {
  font-size: 12px;
  color: #5f6368;
}

.pdf-bookmark-remove {
  background: none;
  border: none;
  color: #5f6368;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pdf-bookmark-remove:hover {
  background: #fee;
  color: #dc2626;
}

.pdf-bookmark-remove svg {
  width: 16px;
  height: 16px;
}

.pdf-toolbar-btn.bookmarked svg {
  fill: #1a73e8;
  stroke: #1a73e8;
}
