/* ==========================================================================
   pdf-to-word-community.css
   Zero-FOUC isolation, Unified Vietnamese Typography, Busy-Action Locking &
   Multi-Viewport Responsive Design (320px -> 1440px+, Light & Dark Mode)
   for /chuyen-de-sang-word.
   ========================================================================== */

/* --- 1. Zero-FOUC Isolation for /chuyen-de-sang-word --- */
html.pdf-to-word-mode #app-shell-root,
body.pdf-to-word-mode #app-shell-root,
html.pdf-to-word-mode #mobile-bottom-dock,
body.pdf-to-word-mode #mobile-bottom-dock,
html.pdf-to-word-mode #auth-gate-view,
html.pdf-to-word-mode .app-header,
html.pdf-to-word-mode #teacher-dashboard,
html.pdf-to-word-mode #student-portal,
html.pdf-to-word-mode #math-ocr-view,
html.pdf-to-word-mode #standalone-assessment-studio-view {
  display: none !important;
}

html.pdf-to-word-mode #pdf-to-word-community-view {
  display: block !important;
}

/* --- 2. Unified Vietnamese-Complete Font & Design Tokens --- */
.pdf-to-word-community-view,
html.pdf-to-word-mode .modal-content,
html.pdf-to-word-mode .p2w-donation-modal-card {
  --p2w-font: var(--font-family, "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif);
  --p2w-bg: var(--canvas-bg, #f8fafc);
  --p2w-surface: var(--card-bg, #ffffff);
  --p2w-surface-alt: var(--surface-subtle, #f1f5f9);
  --p2w-border: var(--border-color, #e2e8f0);
  --p2w-text: var(--text-main, #082850);
  --p2w-muted: var(--text-muted, #64748b);
  --p2w-primary: var(--primary, #00c5df);
  --p2w-primary-dark: var(--brand-navy, #082850);
  --p2w-primary-soft: rgba(0, 197, 223, 0.12);
  --p2w-donate: #7c3aed;
  font-family: var(--p2w-font) !important;
}

.pdf-to-word-community-view {
  min-height: 100vh;
  background: var(--p2w-bg);
  color: var(--p2w-text);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Enforce 100% consistent UI font across every non-A4 element & modal */
.pdf-to-word-community-view :is(h1, h2, h3, h4, h5, h6, p, span, small, strong, em, a, li, label, summary, div, button, input, select, textarea):not(#p2w-a4-preview):not(#p2w-a4-preview *),
.pdf-to-word-community-view #p2w-a4-preview .p2w-figure-mode-bar button,
html.pdf-to-word-mode .modal-content :is(h1, h2, h3, h4, h5, h6, p, span, small, strong, label, div, button, input, select, textarea) {
  font-family: var(--p2w-font) !important;
}

[data-theme="dark"] .pdf-to-word-community-view,
[data-theme="dark"] .p2w-donation-modal-card {
  --p2w-bg: var(--canvas-bg, #051839);
  --p2w-surface: var(--card-bg, #09234e);
  --p2w-surface-alt: var(--surface-subtle, #071d42);
  --p2w-border: var(--border-color, rgba(0, 197, 223, 0.16));
  --p2w-text: var(--text-main, #f8fafc);
  --p2w-muted: var(--text-muted, #94a3b8);
  --p2w-primary: var(--primary, #00c5df);
  --p2w-primary-dark: #00b4d8;
  --p2w-primary-soft: rgba(0, 197, 223, 0.22);
  --p2w-donate: #a78bfa;
}

.p2w-container {
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 1.25rem;
  box-sizing: border-box;
}

/* --- 3. Sticky Header --- */
.p2w-header {
  position: sticky;
  top: 0;
  z-index: 90;
  background: color-mix(in srgb, var(--p2w-surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--p2w-border);
}

.p2w-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 0.85rem;
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
  flex-wrap: wrap;
}

.p2w-brand-group,
.p2w-header-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.p2w-brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--p2w-text);
}

.p2w-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.p2w-quota-badge,
.p2w-badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.28rem 0.68rem;
  border-radius: 999px;
  background: var(--p2w-primary-soft);
  color: var(--p2w-primary);
  border: 1px solid rgba(2, 132, 199, 0.24);
  white-space: nowrap;
}

/* --- 4. Unified Buttons & Controls --- */
.p2w-btn {
  min-height: 44px;
  padding: 0.5rem 0.95rem;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.25;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
  box-sizing: border-box;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.p2w-btn-xs {
  min-height: 36px;
  padding: 0.32rem 0.68rem;
  font-size: 0.77rem;
  border-radius: 8px;
}

.p2w-btn-primary {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #ffffff;
}

.p2w-btn-donate {
  background: linear-gradient(135deg, #7c3aed, #5b21b6);
  color: #ffffff;
}

.p2w-btn-outline {
  background: var(--p2w-surface);
  color: var(--p2w-text);
  border-color: var(--p2w-border);
}

.p2w-btn-ghost {
  background: transparent;
  color: var(--p2w-muted);
}

.p2w-icon-btn {
  min-width: 42px;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--p2w-border);
  background: var(--p2w-surface);
  color: var(--p2w-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

html[data-theme="dark"] #pdf-to-word-community-view .p2w-btn-outline,
html[data-theme="dark"] #pdf-to-word-community-view .p2w-icon-btn,
html[data-theme="dark"] #pdf-to-word-community-view .p2w-footer-donate-link {
  background: #1e293b !important;
  background-image: none !important;
  color: #f8fafc !important;
  border-color: #334155 !important;
}

html[data-theme="dark"] #pdf-to-word-community-view .p2w-mode-tab:not(.is-active) {
  background: #1e293b !important;
  background-image: none !important;
  color: #cbd5e1 !important;
  border-color: #334155 !important;
}

html[data-theme="dark"] #pdf-to-word-community-view .p2w-mode-tab.is-active {
  background: rgba(56, 189, 248, 0.16) !important;
  background-image: none !important;
  color: #38bdf8 !important;
  border-color: #38bdf8 !important;
}

/* --- 5. Busy / Async Action Lock State (Anti-Duplicate Protection) --- */
.pdf-to-word-community-view.is-busy #p2w-dropzone {
  pointer-events: none;
  opacity: 0.58;
  cursor: not-allowed;
}

.pdf-to-word-community-view :is(button, input, select, textarea):disabled,
.pdf-to-word-community-view [data-p2w-locked="true"] {
  cursor: not-allowed !important;
  opacity: 0.56;
}

.pdf-to-word-community-view.is-busy summary.p2w-optional-meta-summary {
  pointer-events: none;
  opacity: 0.6;
}

.pdf-to-word-community-view button.is-loading-target:disabled {
  opacity: 0.94 !important;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.22);
}

@keyframes p2wProgressPulse {
  0% { filter: brightness(0.95); }
  50% { filter: brightness(1.18); }
  100% { filter: brightness(0.95); }
}

/* --- 6. Hero & Streamlined Workbench --- */
.p2w-hero-section {
  padding: 1.55rem 0 1.35rem;
}

.p2w-hero-copy {
  text-align: center;
  max-width: 780px;
  margin: 0 auto 1.2rem;
}

.p2w-eyebrow {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--p2w-primary);
  margin-bottom: 0.38rem;
}

.p2w-hero-title {
  font-size: clamp(1.38rem, 2.7vw, 2.05rem);
  font-weight: 800;
  line-height: 1.28;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
  color: var(--p2w-text);
}

.p2w-hero-subtitle {
  font-size: 0.94rem;
  line-height: 1.58;
  color: var(--p2w-muted);
  margin: 0 auto 0.8rem;
  max-width: 680px;
}

.p2w-trust-strip {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.p2w-trust-chip {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.28rem 0.72rem;
  border-radius: 999px;
  background: var(--p2w-surface);
  border: 1px solid var(--p2w-border);
  color: var(--p2w-text);
}

.p2w-workbench-card,
.p2w-pane-card,
.p2w-feature-card {
  background: var(--p2w-surface);
  border: 1px solid var(--p2w-border);
  border-radius: 16px;
  padding: 1.2rem;
  box-shadow: 0 6px 22px rgba(15, 23, 42, 0.045);
  box-sizing: border-box;
}

.p2w-pane-card {
  min-width: 0;
  max-width: 100%;
}

.p2w-top-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.p2w-mode-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.p2w-mode-tab {
  min-height: 42px;
  padding: 0.42rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--p2w-border);
  background: var(--p2w-surface-alt);
  color: var(--p2w-muted);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.p2w-mode-tab.is-active {
  background: var(--p2w-primary-soft);
  border-color: var(--p2w-primary);
  color: var(--p2w-primary);
}

.p2w-format-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.p2w-format-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--p2w-muted);
}

.p2w-alert {
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.45;
  margin-bottom: 0.85rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

[data-theme="dark"] .p2w-alert {
  background: rgba(220, 38, 38, 0.16);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fca5a5;
}

.p2w-dropzone {
  border: 2px dashed rgba(2, 132, 199, 0.45);
  background: rgba(2, 132, 199, 0.035);
  border-radius: 14px;
  padding: 1.35rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.p2w-dropzone:hover,
.p2w-dropzone.is-dragover {
  border-color: var(--p2w-primary);
  background: var(--p2w-primary-soft);
}

.p2w-dropzone-icon {
  font-size: 1.9rem;
  line-height: 1;
  margin-bottom: 0.35rem;
}

.p2w-dropzone-title {
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.38;
  margin-bottom: 0.28rem;
  color: var(--p2w-text);
}

.p2w-dropzone-hint {
  font-size: 0.82rem;
  color: var(--p2w-muted);
  max-width: 600px;
  margin: 0 auto 0.85rem;
  line-height: 1.48;
}

.p2w-dropzone-actions {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* --- 7. Staging Strip --- */
.p2w-staging-panel {
  margin-top: 0.85rem;
  padding: 0.75rem;
  border-radius: 12px;
  background: var(--p2w-surface-alt);
  border: 1px solid var(--p2w-border);
}

.p2w-staging-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.p2w-staging-header-btns {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.p2w-staging-summary {
  font-size: 0.83rem;
  font-weight: 700;
}

.p2w-staging-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.6rem;
}

.p2w-stage-item {
  background: var(--p2w-surface);
  border: 1px solid var(--p2w-border);
  border-radius: 10px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.p2w-stage-thumb {
  height: 92px;
  border-radius: 7px;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

[data-theme="dark"] .p2w-stage-thumb {
  background: #0f172a;
}

.p2w-stage-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.2s ease;
}

.p2w-stage-controls {
  display: flex;
  justify-content: space-between;
  gap: 0.2rem;
}

.p2w-stage-ctrl-btn {
  min-width: 32px;
  min-height: 32px;
  border-radius: 6px;
  border: 1px solid var(--p2w-border);
  background: var(--p2w-surface-alt);
  color: var(--p2w-text);
  font-size: 0.74rem;
  cursor: pointer;
}

/* --- 8. Collapsible Optional Metadata & Uniform Inputs --- */
.p2w-optional-meta {
  margin-top: 0.85rem;
  border: 1px solid var(--p2w-border);
  border-radius: 12px;
  background: var(--p2w-surface-alt);
  overflow: hidden;
}

.p2w-optional-meta-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.62rem 0.9rem;
  cursor: pointer;
  user-select: none;
  min-height: 44px;
  box-sizing: border-box;
}

.p2w-optional-meta-summary::-webkit-details-marker {
  display: none;
}

.p2w-optional-meta-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--p2w-text);
}

.p2w-optional-meta-badge {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--p2w-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.p2w-optional-meta-badge::after {
  content: "▾";
  font-size: 0.85rem;
  transition: transform 0.18s ease;
}

.p2w-optional-meta[open] .p2w-optional-meta-badge::after {
  transform: rotate(180deg);
}

.p2w-optional-meta .p2w-meta-grid {
  padding: 0.75rem 0.9rem 0.9rem;
  border-top: 1px solid var(--p2w-border);
  background: var(--p2w-surface);
  margin-top: 0;
}

.p2w-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.p2w-field label,
.p2w-detail-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--p2w-muted);
  margin-bottom: 0.25rem;
}

/* Override global Apple pill-radius on <select> so inputs & selects match 100% */
.pdf-to-word-community-view input.p2w-input,
.pdf-to-word-community-view select.p2w-input {
  width: 100%;
  min-height: 42px !important;
  height: 42px;
  padding: 0.45rem 0.75rem !important;
  border-radius: 10px !important;
  border: 1px solid var(--p2w-border) !important;
  background-color: var(--p2w-surface) !important;
  color: var(--p2w-text) !important;
  font-size: 0.85rem !important;
  font-weight: 500 !important;
  box-sizing: border-box;
}

.pdf-to-word-community-view select.p2w-input {
  padding-right: 2rem !important;
}

.p2w-progress-box {
  margin-top: 0.85rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  background: var(--p2w-surface-alt);
  border: 1px solid var(--p2w-border);
}

.p2w-progress-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.25);
  overflow: hidden;
}

.p2w-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #00c5df, #0284c7, #2563eb);
  transition: width 0.25s ease;
  animation: p2wProgressPulse 1.4s ease-in-out infinite;
}

.p2w-progress-text {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--p2w-text);
  margin-top: 0.38rem;
}

.p2w-submit-row {
  margin-top: 0.95rem;
  display: flex;
  justify-content: center;
}

.p2w-btn-convert {
  width: 100%;
  max-width: 440px;
  min-height: 48px;
  background: linear-gradient(135deg, #0284c7, #1d4ed8);
  color: #ffffff;
  font-size: 0.95rem;
  box-shadow: 0 6px 18px rgba(2, 132, 199, 0.25);
}

/* --- 9. Split A4 Studio --- */
.p2w-studio-section,
.p2w-archive-section,
.p2w-backbone-section {
  padding: 1.4rem 0;
  scroll-margin-top: 84px;
}

.p2w-studio-toolbar,
.p2w-archive-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.p2w-section-title {
  font-size: 1.14rem;
  font-weight: 800;
  line-height: 1.32;
  margin: 0 0 0.2rem;
  color: var(--p2w-text);
}

.p2w-section-desc {
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--p2w-muted);
  margin: 0;
}

.p2w-studio-actions,
.p2w-archive-backup-btns {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.p2w-split-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 1rem;
}

.p2w-pane-header {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding-bottom: 0.55rem; margin-bottom: 0.7rem; border-bottom: 1px solid var(--p2w-border); font-size: 0.85rem;
}
.p2w-source-preview-body {
  min-height: 320px; max-height: 660px; overflow: auto; display: flex; align-items: flex-start; justify-content: center;
  background: var(--p2w-surface-alt); border-radius: 10px; padding: 0.75rem;
}
.p2w-source-preview-body img { max-width: 100%; height: auto; border-radius: 6px; }
.p2w-empty-hint { font-size: 0.84rem; color: var(--p2w-muted); text-align: center; padding: 1.5rem 0.75rem; }
.p2w-a4-scroll-wrap {
  max-height: 660px; overflow: auto; background: var(--p2w-surface-alt); padding: 0.75rem; border-radius: 10px; max-width: 100%;
}
.p2w-a4-sheet {
  background: #ffffff; color: #111827; font-family: "Times New Roman", Times, serif; font-size: 12pt; line-height: 1.45;
  padding: 1.1rem 1.2rem; border-radius: 6px; box-shadow: 0 2px 12px rgba(15, 23, 42, 0.1);
  overflow-wrap: break-word; word-break: normal; box-sizing: border-box;
}
.p2w-a4-sheet table th,
.p2w-a4-sheet table td { overflow-wrap: break-word; word-break: normal; hyphens: none; }
.p2w-a4-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.5rem 0;
}
.p2w-a4-table-wrap::-webkit-scrollbar {
  height: 6px;
}
.p2w-a4-table-wrap::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.4);
  border-radius: 3px;
}
@media (max-width: 480px) {
  .p2w-a4-sheet .p2w-a4-fig-row { grid-template-columns: 1fr !important; }
  .p2w-a4-sheet .p2w-a4-fig-row .p2w-figure-box img { width: 70% !important; }
}
.p2w-a4-header-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; text-align: center; margin-bottom: 0.75rem; font-size: 11pt;
}
.p2w-a4-question { margin-bottom: 0.85rem; }
.p2w-a4-options {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 0.25rem 0.75rem; margin-top: 0.3rem;
}
.p2w-figure-box { margin: 0.45rem 0; padding: 0.15rem 0; border: none; text-align: center; }
.p2w-figure-box img { max-width: 100%; max-height: 240px; object-fit: contain; }

/* Chuẩn Hóa KaTeX & Đồng Nhất Font-Size Trên Bản Xem Trước Trang A4 */
.p2w-a4-sheet .katex { font-size: 1.0em !important; font-family: KaTeX_Main, "Times New Roman", Times, serif !important; line-height: 1.2 !important; }
.p2w-a4-sheet .katex-display { margin: 0.35rem 0 !important; font-size: 1.0em !important; text-align: center; }
.p2w-a4-sheet .katex-display > .katex { font-size: 1.02em !important; display: inline-block; text-align: initial; }
.p2w-a4-sheet .katex .mfrac .vlist-t .vlist-r .vlist > span { font-size: 0.88em !important; }
.p2w-a4-sheet .katex .frac-line { border-bottom-width: 0.055em !important; }
.p2w-a4-sheet .p2w-a4-fig-row { border: none !important; outline: none !important; }

