/* ============================================================
   Document paper — always light (print-friendly), modern + classic
   ============================================================ */
.paper {
  --doc-ink: #1b211d;
  --doc-ink-2: #66706a;
  --doc-line: #e2e0d8;
  --doc-soft: #f6f7f9;
  --doc-accent: var(--accent);
  --font-sign: "Sacramento", cursive;

  background: #fff;
  color: var(--doc-ink);
  font-family: var(--font-doc);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 44px 48px 40px;
  max-width: 820px;
  margin: 0 auto;
  border: 1px solid var(--line);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* header */
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 22px; border-bottom: 2px solid var(--doc-ink); }
.paper-modern .doc-head { border-bottom: none; }
.doc-logo { width: 62px; height: 62px; border-radius: 12px; background: var(--doc-accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 24px; flex: none; }
.paper-classic .doc-logo { background: #fff; color: var(--doc-ink); border: 1.5px solid var(--doc-ink); }
.doc-co-name { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.doc-co-en { font-size: 12.5px; color: var(--doc-ink-2); margin-bottom: 6px; }
.doc-co-meta { font-size: 11.5px; color: var(--doc-ink-2); line-height: 1.55; }
.doc-title-wrap { text-align: right; flex: none; }
.doc-title { font-size: 26px; font-weight: 800; letter-spacing: -.01em; color: var(--doc-accent); }
.paper-classic .doc-title { color: var(--doc-ink); }
.doc-title-sub { font-size: 13px; color: var(--doc-ink-2); letter-spacing: .04em; text-transform: uppercase; }

/* modern accent bar */
.paper-modern { padding-top: 0; overflow: hidden; }
.paper-modern .doc-head { background: linear-gradient(180deg, color-mix(in oklab, var(--doc-accent) 8%, #fff), #fff); margin: 0 -48px; padding: 36px 48px 22px; }

/* flat: plain white header, no gradient/band/line — keeps accent title, table & total */
.paper-flat .doc-head { border-bottom: none; }
.paper-flat .doc-table th { background: var(--doc-accent); }

/* meta */
.doc-meta-grid { display: grid; grid-template-columns: 1fr 280px; gap: 30px; padding: 22px 0; }
.doc-label { font-size: 11px; font-weight: 700; color: var(--doc-ink-2); text-transform: none; letter-spacing: .02em; margin-bottom: 4px; }
.doc-meta-right { background: var(--doc-soft); border-radius: 10px; padding: 14px 16px; align-self: start; }
.doc-meta-line { display: flex; justify-content: space-between; font-size: 12.5px; padding: 3px 0; }
.doc-meta-line span { color: var(--doc-ink-2); }

/* table */
.doc-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.doc-table th { background: var(--doc-ink); color: #fff; font-size: 12px; font-weight: 600; padding: 10px 12px; text-align: left; }
.paper-modern .doc-table th { background: var(--doc-accent); }
.doc-table th:first-child { border-radius: 7px 0 0 7px; }
.doc-table th:last-child { border-radius: 0 7px 7px 0; }
.doc-table td { padding: 11px 12px; font-size: 13px; border-bottom: 1px solid var(--doc-line); }
.doc-table .doc-empty td { border-bottom: 1px solid var(--doc-line); }
.doc-table .t-right { text-align: right; }
.doc-table .t-center { text-align: center; }

/* footer */
.doc-foot { display: grid; grid-template-columns: 1fr 320px; gap: 30px; margin-top: 22px; align-items: start; }
.doc-foot-left { font-size: 12.5px; color: var(--doc-ink); }
.doc-totals { font-size: 13px; }
.doc-tot-line { display: flex; justify-content: space-between; padding: 6px 0; color: var(--doc-ink-2); }
.doc-tot-line span:last-child { color: var(--doc-ink); font-weight: 500; }
.doc-tot-sep { border-top: 1px dashed var(--doc-line); margin-top: 4px; padding-top: 8px; }
.doc-tot-grand { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; padding: 12px 14px; background: color-mix(in oklab, var(--doc-accent) 10%, #fff); border-radius: 10px; font-size: 16px; font-weight: 800; }
.paper-classic .doc-tot-grand { background: var(--doc-soft); border: 1.5px solid var(--doc-ink); }
.doc-tot-grand span:last-child { color: var(--doc-accent); }
.paper-classic .doc-tot-grand span:last-child { color: var(--doc-ink); }
.doc-baht { text-align: right; font-size: 12px; color: var(--doc-ink-2); margin-top: 8px; font-style: italic; }

/* เอกสารแนบ (รูปใบเสร็จ/สลิป) — แสดงใต้เอกสารในพรีวิว และรวมเป็นหน้าใน PDF/พิมพ์ */
.doc-attach-sheets { max-width: 794px; margin: 20px auto 0; }
.doc-attach-sheet { background: #fff; border: 1px solid var(--line, #e6e9e7); border-radius: 12px; padding: 16px; margin-top: 14px; text-align: center; }
.doc-attach-cap { font-size: 12px; color: var(--doc-ink-2, #66726b); margin-bottom: 10px; text-align: left; font-weight: 600; }
.doc-attach-sheet img { max-width: 100%; max-height: 1000px; object-fit: contain; border-radius: 6px; }

/* หลายฉบับ (ต้นฉบับ+สำเนา) เว้นระยะให้เห็นชัดบนจอ */
.paper + .paper { margin-top: 22px; }

@media print {
  .sidebar, .topbar, .scrim, [data-omelette-chrome], .twk-panel { display: none !important; }
  .app { display: block !important; height: auto !important; overflow: visible !important; }
  .main { display: block !important; overflow: visible !important; }
  .page-scroll { overflow: visible !important; height: auto !important; }
  .page { max-width: none !important; margin: 0 !important; padding: 0 !important; }
  .page > .row { display: none !important; }
  #doc-paper, .paper { box-shadow: none !important; border: none !important; max-width: none !important; position: relative !important; }
  /* ฉบับถัดไป (สำเนา) ขึ้นหน้าใหม่ */
  .paper-copy-break { break-before: page; page-break-before: always; margin-top: 0 !important; }
  /* รูปแนบ — ขึ้นหน้าใหม่ต่อท้ายเอกสาร 1 หน้า/รูป */
  .doc-attach-sheets { max-width: none !important; margin: 0 !important; }
  .doc-attach-sheet { break-before: page; page-break-before: always; border: none !important; border-radius: 0 !important; padding: 0 !important; }
  .doc-attach-sheet img { max-height: 96vh; }
  @page { margin: 12mm; }
}

@media screen and (max-width: 720px) {
  .paper { padding: 28px 22px; }
  .paper-modern .doc-head { margin: 0 -22px; padding: 26px 22px 18px; }
  .doc-head, .doc-meta-grid, .doc-foot { grid-template-columns: 1fr; flex-direction: column; }
  .doc-title-wrap { text-align: left; }
  .doc-meta-grid { gap: 16px; }
}
