/* ==========================================================================
   ISTQB CT-GenAI Master - Document & PDF Reader Styles
   ========================================================================== */

.reader-view-container {
  display: flex;
  flex: 1;
  width: 100%;
  height: calc(100vh - 64px);
  overflow: hidden;
  position: relative;
}

/* --------------------------------------------------------------------------
   SIDEBAR TABLE OF CONTENTS (Mục lục)
   -------------------------------------------------------------------------- */
.reader-sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: transform var(--transition-normal);
  z-index: 20;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.search-input-box {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.search-input-box:focus {
  border-color: var(--primary);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

/* TOC Chapter Group */
.toc-chapter-group {
  margin-bottom: 6px;
}

.toc-chapter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin: 0 8px;
  transition: background var(--transition-fast);
  user-select: none;
}

.toc-chapter-header:hover {
  background: var(--bg-subtle);
}

.toc-chapter-header.active {
  background: var(--primary-light);
  color: var(--primary);
}

.toc-sections-list {
  display: flex;
  flex-direction: column;
  padding-left: 12px;
}

.toc-item {
  padding: 7px 16px 7px 20px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all var(--transition-fast);
  line-height: 1.35;
  display: block;
}

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

.toc-item.active {
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
  background: var(--primary-light);
}

.toc-item.level-2 {
  padding-left: 32px;
  font-size: 0.78rem;
}



/* --------------------------------------------------------------------------
   READER MAIN CONTENT AREA
   -------------------------------------------------------------------------- */
.reader-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
}

.reader-toolbar {
  height: 52px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reader-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-sidebar-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
}

.toggle-sidebar-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.reader-current-chapter {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.reader-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* View Mode Switcher: E-Book vs Embedded PDF */
.reader-mode-switch {
  display: flex;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.mode-tab-btn {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mode-tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.btn-tool {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.btn-tool:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

/* E-Book Text Container (Scrollable) */
.reader-document-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px 100px 40px;
  scroll-behavior: smooth;
}

.document-page-sheet {
  max-width: 860px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 48px 56px;
  box-shadow: var(--shadow-md);
  min-height: 800px;
}

/* Document Typography & Formatting */
.doc-section-block {
  margin-bottom: 40px;
  scroll-margin-top: 70px;
  position: relative;
}

/* Target pulse animation when jumped from quiz */
.doc-section-block.target-highlight {
  animation: targetPulse 2.5s ease-out;
}

@keyframes targetPulse {
  0% { background: rgba(59, 130, 246, 0.25); border-radius: var(--radius-md); }
  50% { background: rgba(59, 130, 246, 0.15); border-radius: var(--radius-md); }
  100% { background: transparent; }
}

.doc-h1 {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 20px;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 8px;
}

.doc-h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 28px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.doc-h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-main);
  margin-top: 20px;
  margin-bottom: 10px;
}

.doc-h4 {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 14px;
  margin-bottom: 8px;
}

.document-page-sheet p {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-main);
  margin-bottom: 16px;
}

.doc-quote {
  border-left: 4px solid var(--primary);
  background: var(--bg-subtle);
  padding: 12px 18px;
  margin: 16px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-main);
}

.doc-list {
  padding-left: 24px;
  margin-bottom: 16px;
}

.doc-list li {
  margin-bottom: 6px;
  line-height: 1.6;
}

.doc-hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 28px 0;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  margin: 18px 0;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--bg-card);
}

.doc-table th, .doc-table td {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  text-align: left;
}

.doc-table th {
  background: var(--bg-subtle);
  font-weight: 700;
  color: var(--text-main);
}

/* Practice button in document */
.doc-practice-anchor {
  margin-top: 12px;
  margin-bottom: 20px;
}

.btn-doc-practice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-doc-practice:hover {
  background: var(--primary);
  color: white;
}

/* --------------------------------------------------------------------------
   PDF VIEWER CONTAINER
   -------------------------------------------------------------------------- */
.reader-pdf-viewport {
  display: none;
  flex: 1;
  height: 100%;
  background: #525659;
  position: relative;
}

.reader-pdf-viewport.active {
  display: flex;
}

.pdf-embed-frame {
  width: 100%;
  height: 100%;
  border: none;
}

/* --------------------------------------------------------------------------
   PRINT STYLESHEET (For Clean PDF Export)
   -------------------------------------------------------------------------- */
@media print {
  body {
    background: white !important;
    color: black !important;
  }
  .app-header,
  .reader-sidebar,
  .reader-toolbar,
  .btn-doc-practice,
  .toast-container,
  .modal-overlay {
    display: none !important;
  }
  .reader-view-container,
  .reader-main,
  .reader-document-viewport {
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
  }
  .document-page-sheet {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
  .doc-section-block {
    page-break-inside: avoid;
  }
}

@media (max-width: 768px), (pointer: coarse) and (max-width: 900px) {
  .reader-view-container {
    height: calc(100vh - 56px - 65px);
  }

  .reader-toolbar {
    padding: 8px 12px;
    gap: 8px;
    height: auto;
    min-height: 48px;
  }

  .toggle-sidebar-btn {
    padding: 7px 12px;
    font-size: 0.82rem;
    font-weight: 700;
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-border);
    border-radius: var(--radius-sm);
  }

  .reader-current-chapter {
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
  }

  .reader-sidebar {
    position: fixed;
    top: 56px;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    left: 0;
    width: 290px;
    max-width: 85vw;
    z-index: 500;
    box-shadow: 6px 0 25px rgba(0, 0, 0, 0.3);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .reader-sidebar.open {
    transform: translateX(0);
  }

  .document-page-sheet {
    padding: 18px 14px 40px 14px;
    font-size: 0.95rem;
    line-height: 1.6;
    border-radius: 0;
    box-shadow: none;
    border: none;
  }

  .doc-section-header h2 {
    font-size: 1.2rem;
  }

  .doc-section-header h3 {
    font-size: 1.05rem;
  }

  .btn-doc-practice {
    width: 100%;
    margin-top: 14px;
    padding: 10px;
    font-size: 0.84rem;
  }
}

