/* Shared Order Documents (Hoá đơn VAT) */
.modal.compact-modal.order-documents-modal,
.order-documents-modal { position: fixed; inset: 0; z-index: 1000; padding: 0 !important; }
.order-documents-modal.hidden { display: none !important; }
.order-documents-sheet .history-heading, .order-result-sheet .history-heading { flex: 0 0 auto; margin: 0; }
.order-documents-sheet .close-button,
.order-result-sheet .close-button {
  background: rgba(255, 255, 255, 0.14) !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  color: #ffffff !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35) !important;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}
.order-documents-sheet .close-button:hover,
.order-result-sheet .close-button:hover {
  background: rgba(255, 255, 255, 0.24) !important;
  border-color: rgba(255, 255, 255, 0.38) !important;
  color: #ffffff !important;
}
.order-documents-sheet .close-button:active,
.order-result-sheet .close-button:active {
  background: rgba(255, 255, 255, 0.32) !important;
  color: #ffffff !important;
  transform: scale(0.96);
}
.order-document-tabs { margin: 0; padding: 0; border: 0; }
.order-document-heading-title {
  display: inline-block;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100vw - 120px);
}
.order-document-tabs::-webkit-scrollbar { display: none; }
/* Vùng xem: gốc định vị cho lớp tải; trang luôn được dựng ở kích thước cuối khi còn ẩn rồi mới mờ dần hiện ra. */
.order-document-preview { position: relative; touch-action: pan-x pan-y; }
.order-document-frame { display: block; width: 100%; height: 100%; border: 0; outline: 0; background: #323639; opacity: 0; transition: opacity .28s cubic-bezier(.2,.7,.2,1); }
.order-document-frame.is-ready { opacity: 1; }
.order-document-frame.hidden { display: none !important; }


/* Lớp tải: vòng xoay không chữ, chính giữa vùng xem; hiện sau 140ms để tài liệu có sẵn không bị nháy. */
.order-document-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 1;
  transition: opacity .24s ease, visibility 0s linear 0s;
}
.order-document-state[data-mode="idle"] { opacity: 0; visibility: hidden; transition: opacity .24s ease, visibility 0s linear .24s; }
.order-document-state[data-mode="idle"] * { animation-play-state: paused !important; }
.order-document-state:not([data-mode="error"]) .order-document-error { display: none; }
.order-document-state[data-mode="error"] .doc-loader { display: none; }
.order-document-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.order-document-state[data-mode="error"] .order-document-sr { display: none; }
.doc-loader {
  display: grid;
  place-items: center;
  animation: order-doc-appear .3s ease .14s both;
}
.doc-loader svg { width: 44px; height: 44px; animation: order-doc-spin .9s linear infinite; }
.doc-loader circle { fill: none; stroke-width: 3.5; }
.doc-loader-track { stroke: rgba(255, 255, 255, 0.12); }
.doc-loader-arc { stroke: #2dd4bf; stroke-linecap: round; stroke-dasharray: 30 100; }
.order-document-error {
  pointer-events: auto;
  min-width: 260px;
  max-width: min(420px, calc(100% - 32px));
  padding: 26px 30px;
  border-radius: 14px;
  background: #16181d;
  color: #f1f3f4;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  animation: order-doc-appear .2s ease both;
}
.order-document-error p { margin: 0; color: #e8eaed; font-size: 14px; line-height: 1.45; }
.order-document-error button {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 0 18px;
  min-height: 36px;
}
.order-document-error button:hover { background: rgba(255, 255, 255, 0.2); }
@keyframes order-doc-appear { from { opacity: 0; } to { opacity: 1; } }
@keyframes order-doc-spin { to { transform: rotate(360deg); } }

/* Trang PDF thật (PDF.js): canvas nét theo mức zoom + lớp chữ thật để bôi đen/sao chép. */
.order-document-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin: auto;
  padding: 16px 0;
  flex-shrink: 0;
  opacity: 0;
  transform: translateY(6px) scale(.992);
  transition: opacity .28s cubic-bezier(.2,.7,.2,1), transform .32s cubic-bezier(.2,.7,.2,1);
  will-change: opacity, transform;
}
.order-document-pages.is-ready { opacity: 1; transform: none; will-change: auto; }
.order-document-pages.hidden { display: none !important; }
.order-document-page {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  background: #ffffff;
  border-radius: 3px;
  box-shadow: 0 16px 56px rgba(0, 0, 0, 0.95), 0 2px 10px rgba(0, 0, 0, 0.6);
}
.order-document-svg { display: block; width: 100%; height: 100%; user-select: text !important; -webkit-user-select: text !important; }
.order-document-svg :is(text, tspan) { user-select: text !important; -webkit-user-select: text !important; cursor: text; }
.order-document-svg ::selection { background: rgba(0, 105, 255, .32); }
.order-document-page-canvas { display: block; width: 100%; height: 100%; pointer-events: none; }
.order-document-textlayer {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: clip;
  line-height: 1;
  text-align: initial;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}
.order-document-textlayer :is(span, br) { position: absolute; color: transparent; white-space: pre; cursor: text; transform-origin: 0 0; }
.order-document-page, .order-document-textlayer, .order-document-textlayer :is(span, br) { user-select: text !important; -webkit-user-select: text !important; }
/* Kích thước chữ, độ co giãn và góc xoay do PDF.js đặt qua biến CSS; thiếu các dòng này thì ô bôi đen lệch khỏi chữ. */
.order-document-textlayer > :not(.markedContent),
.order-document-textlayer .markedContent span:not(.markedContent) {
  z-index: 1;
  --font-height: 0;
  font-size: calc(var(--total-scale-factor) * var(--font-height));
  --scale-x: 1;
  --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x));
}
.order-document-textlayer .markedContent { display: contents; }
.order-document-textlayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; user-select: none !important; -webkit-user-select: none !important; }
.order-document-textlayer.selecting .endOfContent { top: 0; }
.order-document-textlayer span.markedContent { top: 0; height: 0; }
.order-document-textlayer ::selection { background: rgba(0, 102, 204, 0.35); color: transparent; }
.order-document-textlayer br::selection { background: transparent; }

/* Nút thao tác giữ nguyên màu khi đang tải (như cũ); chỉ mờ đi khi chứng từ lỗi. */
.order-document-footer button:disabled { opacity: 1 !important; cursor: default; }
.order-document-footer .secondary-button:disabled { background: rgba(255, 255, 255, 0.12) !important; color: #ffffff !important; border: 1px solid rgba(255, 255, 255, 0.22) !important; }
.order-document-footer .primary-button:disabled { background: #0f766e !important; color: #ffffff !important; border: 1px solid #14b8a6 !important; }
.order-documents-workspace:has(.order-document-state[data-mode="error"]) .order-document-footer button:disabled { opacity: .45 !important; cursor: not-allowed; }
.order-document-share { display: inline-flex; justify-content: center; align-items: center; gap: 6px; }
.order-document-footer svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; flex-shrink: 0; }
#orderDocumentPrint { display: none; }
/* 1. Mobile (< 1100px): Full-Screen Photo Lightbox Style like PC */
@media (max-width: 1099px) {
  .order-documents-modal {
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    background: #000000;
    padding: 0;
  }
  .order-documents-modal .backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.96);
    backdrop-filter: blur(10px);
  }
  .order-documents-modal.compact-modal .order-documents-sheet,
  .order-result-modal.order-documents-modal .order-result-sheet {
    position: relative;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    background: #000000 !important;
    box-shadow: none !important;
    overflow: hidden !important;
  }
  .order-documents-sheet .history-heading,
  .order-result-sheet .history-heading {
    height: 52px;
    min-height: 52px;
    flex: 0 0 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 16px;
    padding-top: var(--safe-top, 0px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(13, 14, 18, 0.95);
    margin: 0;
  }
  .order-documents-modal .sheet-card .history-heading h2.order-document-tabs {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    display: flex;
    align-items: center;
  }
  .order-documents-sheet .close-button,
  .order-result-sheet .close-button {
    position: static;
    flex: 0 0 auto;
  }
  .order-documents-workspace {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #000000;
    overflow: hidden;
  }
  .order-document-preview {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
    border: 0;
    border-radius: 0;
    padding: 0 !important;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #000000;
    -webkit-overflow-scrolling: touch;
  }
  .order-document-preview.is-frame {
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 0 !important;
    border-radius: 0 !important;
    background: #000000;
    scrollbar-gutter: stable;
  }
  .order-document-pages { padding: 12px 0; gap: 10px; }

  .order-document-footer {
    display: grid;
    grid-template-columns: 1fr 1fr 1.25fr;
    gap: 8px;
    flex: 0 0 auto;
    padding: 8px 12px calc(8px + var(--safe-bottom, 0px)) 12px;
    background: rgba(13, 14, 18, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
  .order-document-footer button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 42px;
    min-height: 42px;
    margin: 0;
    padding: 0 8px;
    border-radius: 10px;
    font-size: 12.5px;
    font-weight: 650;
    white-space: nowrap;
  }
  .order-document-footer .secondary-button {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: none;
  }
  .order-document-footer .primary-button {
    background: #0f766e;
    color: #ffffff;
    border: 1px solid #14b8a6;
  }
}

/* 2. PC / Desktop (>= 1100px): Facebook Full-Screen Photo Lightbox Style */
@media (min-width: 1100px) {
  .order-documents-modal {
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    background: #000000;
    padding: 0;
  }
  .order-documents-modal .backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.96);
    backdrop-filter: blur(10px);
  }
  .order-documents-modal.compact-modal .order-documents-sheet,
  .order-result-modal.order-documents-modal .order-result-sheet {
    position: relative;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    background: #000000 !important;
    box-shadow: none !important;
    overflow: hidden !important;
  }
  /* Sleek top header bar */
  .order-documents-sheet .history-heading,
  .order-result-sheet .history-heading {
    position: relative;
    z-index: 5;
    height: 56px;
    min-height: 56px;
    flex: 0 0 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    margin: 0;
    background: rgba(13, 14, 18, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  }
  .order-documents-modal .sheet-card .history-heading h2.order-document-tabs {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    display: flex;
    align-items: center;
  }
  .order-document-heading-title {
    color: #ffffff;
    font-size: 16px;
    font-weight: 750;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100vw - 420px);
  }
  .order-documents-sheet .close-button,
  .order-result-sheet .close-button {
    position: absolute;
    top: 10px;
    right: 20px;
    z-index: 6;
    width: 32px;
    min-width: 32px;
    height: 36px;
    min-height: 36px;
  }
  /* Workspace fills all space below the header */
  .order-documents-workspace {
    position: static;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #000000;
  }
  /* Floating Action Buttons docked at top right next to X button */
  .order-document-footer {
    position: absolute;
    top: 10px;
    right: 66px;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 0;
  }
  .order-document-footer button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 36px;
    min-height: 36px;
    margin: 0;
    padding: 0 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, opacity .15s ease;
  }
  .order-document-footer .secondary-button {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  }
  .order-document-footer .secondary-button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.38);
    color: #ffffff;
  }
  .order-document-footer .primary-button {
    background: #0f766e;
    color: #ffffff;
    border: 1px solid #14b8a6;
    box-shadow: 0 2px 8px rgba(15, 118, 110, 0.35);
  }
  .order-document-footer .primary-button:hover:not(:disabled) {
    background: #115e59;
    border-color: #2dd4bf;
    box-shadow: 0 3px 12px rgba(15, 118, 110, 0.45);
  }
  /* Full-Screen Photo Lightbox Preview Canvas Area */
  .order-document-preview {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    background: #000000;
    border: 0;
    border-radius: 0;
    overflow: auto;
    padding: 0 !important;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .order-document-preview.is-frame {
    padding: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: stretch !important;
    background: #000000;
  }

}

@keyframes telegram-sheet-slide-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
    .order-documents-modal.compact-modal .order-documents-sheet,
  .order-result-modal.order-documents-modal .order-result-sheet {
    animation: none !important;
  }
}

@media print {
  @page { size: A4; margin: 0; }
  body.is-document-printing { margin: 0 !important; padding: 0 !important; overflow: visible !important; background: white !important; }
  body.is-document-printing > :not(#orderDocumentPrint) { display: none !important; }
  body.is-document-printing #orderDocumentPrint { display: block; }
  #orderDocumentPrint canvas { display: block; width: 210mm; height: 297mm; break-after: page; page-break-after: always; }
  #orderDocumentPrint canvas:last-child { break-after: auto; page-break-after: auto; }
}

/* Phóng to rồi kéo bằng chuột để xem vị trí cần xem; giữ Shift để bôi đen chữ. */
.order-document-preview.is-pannable, .order-document-preview.is-pannable * { cursor: grab; }
.order-document-preview.is-panning, .order-document-preview.is-panning * { cursor: grabbing !important; user-select: none !important; -webkit-user-select: none !important; }
