/* ==========================================================================
   EXPORT & PREVIEW MODAL STYLING (WORD & EXCEL)
   Sổ tay Báo cáo Hán Ngữ (TTTH4 & TTTH8)
   ========================================================================== */

/* Fullscreen modal modifier */
.lesson-modal-content.fullscreen-modal {
  width: 98vw !important;
  max-width: 98vw !important;
  height: 96vh !important;
  max-height: 96vh !important;
  border-radius: var(--radius-sm);
}

/* Export Modal Specifics */
.export-modal-content {
  max-width: 1160px;
  width: 94vw;
  height: 92vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.export-modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.export-header-title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.export-badge-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.5px;
}

.export-modal-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.btn-modal-action.gold {
  background: linear-gradient(135deg, #b5733a, #cf8d4c);
  color: #fff;
  border-color: #b5733a;
  box-shadow: var(--shadow-sm);
}
.btn-modal-action.gold:hover {
  background: linear-gradient(135deg, #9b5c27, #b5733a);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Controls Bar */
.export-controls-bar {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.export-control-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

.export-scope-dropdown {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: var(--ui-font);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  max-width: 290px;
}
.export-scope-dropdown:focus {
  border-color: var(--primary);
}

/* Format Switcher Pills */
.export-format-switch {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 3px;
}

.btn-format-pill {
  background: transparent;
  border: none;
  font-family: var(--ui-font);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
}

.btn-format-pill.active {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.export-checkbox-group {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
}

.cb-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
}

.export-search-input {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: var(--ui-font);
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  outline: none;
  width: 200px;
  transition: var(--transition);
}
.export-search-input:focus {
  border-color: var(--primary);
  width: 240px;
}

.export-stats-container {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
}

.preview-stat-pill {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.preview-stat-pill b {
  color: var(--primary);
}

/* Preview Content Body */
.export-preview-body {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-main);
  padding: 1.5rem;
}

/* Word Preview: Realistic Paper Sheet View */
.word-preview-paper-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.word-preview-notice-bar {
  width: 100%;
  max-width: 900px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.88rem;
  color: var(--text-main);
}

.btn-preview-quick-dl {
  background: var(--primary);
  color: #fff;
  border: none;
  font-family: var(--ui-font);
  font-size: 0.84rem;
  font-weight: 700;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}
.btn-preview-quick-dl:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}
.btn-preview-quick-dl.excel {
  background: #107c41; /* Excel Signature Green */
}
.btn-preview-quick-dl.excel:hover {
  background: #0b582e;
}

.word-preview-paper {
  background: #ffffff;
  color: #221a14;
  width: 100%;
  max-width: 900px;
  padding: 3rem 3.5rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  border-radius: 4px;
  line-height: 1.5;
  font-family: 'Times New Roman', 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
}

/* Excel Preview: High-Fidelity Table View */
.excel-preview-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.excel-subnav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.excel-subnav-tabs {
  display: flex;
  gap: 6px;
}

.excel-tab-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: var(--ui-font);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.excel-tab-btn:hover {
  color: var(--text-main);
  border-color: var(--primary);
}
.excel-tab-btn.active {
  background: #107c41;
  color: #ffffff;
  border-color: #107c41;
}

.excel-quick-dl-group {
  display: flex;
  align-items: center;
}

.excel-table-scroll-container {
  overflow-x: auto;
  max-height: 60vh;
}

.excel-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  text-align: left;
}

.excel-preview-table thead {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #107c41;
  color: #ffffff;
}

.excel-preview-table th {
  padding: 0.65rem 0.8rem;
  font-weight: 700;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  white-space: nowrap;
}

.excel-preview-table td {
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  vertical-align: top;
}

.excel-preview-table tbody tr:nth-child(even) {
  background: var(--bg-card-hover);
}

.excel-preview-table tbody tr:hover {
  background: var(--primary-light);
}

.excel-hanzi {
  font-family: var(--hanzi-font);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
}

.excel-pinyin {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.86rem;
}

.table-badge {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.excel-pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-color);
}

.pagination-buttons {
  display: flex;
  gap: 8px;
}

.btn-page-nav {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.btn-page-nav:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}
.btn-page-nav:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Toast Notifications */
.export-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.export-toast {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--success);
  color: var(--text-main);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(16px);
  transition: all 0.25s ease;
  pointer-events: auto;
  max-width: 420px;
}

.export-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.export-toast.info {
  border-left-color: var(--primary);
}

/* Print Styles - Universal A4 Portrait */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm 12mm 10mm 12mm;
  }

  /* CRITICAL: Hide all background UI elements so they do NOT take up vertical layout space! */
  .app-header,
  .volume-banner,
  .main-layout,
  .curriculum-toolbar,
  .curriculum-master-bar,
  #lesson-grid-container,
  #score-modal-overlay,
  #lexibot-key-modal,
  .export-toast-container,
  .export-modal-header,
  .export-controls-bar,
  .word-preview-notice-bar,
  .excel-subnav-bar,
  .excel-pagination-bar {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #221a14 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  /* When printing from the preview modal */
  #export-preview-modal-overlay {
    display: block !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  .export-modal-content {
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    display: block !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .export-preview-body {
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    display: block !important;
    background: transparent !important;
    height: auto !important;
    max-height: none !important;
  }

  .word-preview-paper-wrapper {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .word-preview-paper {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    background: #ffffff !important;
    color: #111111 !important;
    line-height: 1.4 !important;
    font-size: 9.5pt !important;
  }

  table {
    width: 100% !important;
    border-collapse: collapse !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
    margin-bottom: 10pt !important;
  }

  tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    page-break-after: auto !important;
  }

  thead {
    display: table-header-group !important;
  }

  tfoot {
    display: table-footer-group !important;
  }

  .page-break {
    page-break-before: always !important;
    break-before: page !important;
  }

  .lesson-banner, .section-heading, .detail-section-title {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  .grammar-card, .lesson-text-block {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-bottom: 8pt !important;
  }
}

