/* All Weather 單據樣式 — 依 AWA Quotation Template.xlsx 版面。
   A4 直向，A–H 欄比例：3.7 / 10.7 / 9.7 / 13.5 / 3.7 / 15.7 / 8.8 / 15.7（合計 81.5）。
   主色 #3D5437。內文 Comfortaa、標題與表頭 Lexend、項目列 Arial。 */

.awa-doc {
  --awa-green: #3d5437;
  --awa-ink: #000;
  position: relative;
  width: 210mm;
  min-height: 297mm;
  padding: 12mm 14mm 12mm 14mm;
  box-sizing: border-box;
  background: #fff;
  color: var(--awa-ink);
  font-family: 'Comfortaa', 'Nunito', sans-serif;
  font-size: 10pt;
  line-height: 1.35;
  overflow: hidden;
}

.awa-watermark {
  position: absolute;
  inset: 0;
  overflow: hidden; /* 旋轉文字不可超出頁面，否則列印時會被縮放 */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  user-select: none;
}
.awa-watermark span {
  font-family: 'Lexend', sans-serif;
  font-size: 110pt;
  font-weight: 700;
  color: rgba(61, 84, 55, 0.08);
  transform: rotate(-30deg);
}

/* 頁首：標誌左、標題右（E1:H2） */
.awa-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  height: 30mm;
}
.awa-logo {
  height: 26mm;
  width: auto;
  margin-top: -3mm;
  margin-left: -2mm;
}
.awa-title {
  font-family: 'Comfortaa', sans-serif;
  font-size: 40pt;
  font-weight: 400;
  color: var(--awa-green);
  line-height: 1;
  padding-top: 2mm;
  letter-spacing: 0.5px;
}

/* 收件人與單據資料（列 6–10） */
.awa-meta {
  display: grid;
  grid-template-columns: 51.4% 48.6%; /* A–D 對 E–H */
  margin-top: 6mm;
  min-height: 34mm;
}
.awa-label {
  font-family: 'Lexend', sans-serif;
  font-weight: 700;
  font-size: 10pt;
  margin-bottom: 1.5mm;
}
.awa-to > div:not(.awa-label) {
  padding-left: 4.5%; /* B 欄起 */
  min-height: 5.5mm;
}
.awa-client-name {
  font-size: 11pt;
}
.awa-kv {
  border-collapse: collapse;
  width: auto;
  table-layout: auto;
}
.awa-kv td {
  padding: 0.6mm 0;
  vertical-align: top;
}
.awa-kv td:first-child {
  padding-left: 9mm; /* F 欄起 */
  padding-right: 4mm;
  white-space: nowrap;
}
.awa-number {
  font-size: 11pt;
}

/* 項目表（列 13 起） */
.awa-items {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4mm;
  table-layout: fixed;
}
.awa-items col.c-no { width: 4.5%; }
.awa-items th,
.awa-items td {
  vertical-align: top;
}
.awa-items thead th {
  background: var(--awa-green);
  color: #fff;
  font-family: 'Lexend', sans-serif;
  font-weight: 700;
  font-size: 11pt;
  height: 30px;
  padding: 0 2mm;
  text-align: center;
  line-height: 30px;
}
.awa-items thead th.c-desc { text-align: left; }
.awa-items thead th.c-no { padding: 0; }
.awa-items .c-no { width: 4.5%; text-align: center; }
.awa-items .c-desc { width: 46.9%; }
.awa-items .c-price { width: 19.3%; text-align: right; }
.awa-items .c-qty { width: 10.8%; text-align: center; }
.awa-items .c-total { width: 19.3%; text-align: right; }
.awa-items tbody tr.item td {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10pt;
  padding: 2mm 2mm;
  height: 18mm;
  border-bottom: 1px solid #d9ddd6;
}
.awa-items tbody tr.item td.c-desc {
  padding-left: 2mm;
  white-space: pre-wrap;
  word-break: break-word;
}
/* 折扣時的小計／折扣列（白底，位於 TOTAL 之上） */
.awa-items tfoot .awa-subtotal td,
.awa-items tfoot .awa-discount td {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10pt;
  height: 8mm;
  line-height: 8mm;
  padding: 0 2mm;
  text-align: right;
}
.awa-items tfoot .awa-sub-label {
  font-family: 'Lexend', sans-serif;
  font-weight: 700;
}
.awa-items tfoot .awa-total td {
  font-family: 'Lexend', sans-serif;
  font-weight: 700;
  font-size: 13pt;
  color: #fff;
  height: 42px;
  line-height: 42px;
  padding: 0 2mm;
}
.awa-items tfoot .awa-total-label {
  background: var(--awa-green);
  text-align: right;
}
.awa-items tfoot .awa-total-value {
  background: var(--awa-green);
  text-align: right;
}

/* 條款（列 20–23） */
.awa-terms {
  margin-top: 12mm;
}
.awa-terms p {
  margin: 0 0 1.2mm 0;
  min-height: 5.5mm;
}

/* Remark（條款下方，有內容才顯示） */
.awa-remark {
  margin-top: 6mm;
}
.awa-remark p {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 頁尾（列 25–26）：單頁時貼底（.fits-page 由 app.js 量度後加上），多頁時跟在條款後 */
.awa-foot {
  margin-top: 10mm;
  text-align: center;
  break-inside: avoid;
}
.awa-doc.fits-page .awa-foot {
  position: absolute;
  left: 14mm;
  right: 14mm;
  bottom: 14mm;
  margin-top: 0;
}
.awa-items tr { break-inside: avoid; }
.awa-foot div {
  min-height: 5.5mm;
}
.awa-foot .awa-contact {
  white-space: nowrap;
  font-size: 8.5pt; /* 加入 Website 後略縮，維持一行 */
  letter-spacing: -0.1px;
}

/* ===== 發票／收據專用 ===== */

/* 付款資料表（Bank：Bank / Account… ；P-Card：Merchant Name / Number） */
.awa-kv2 {
  border-collapse: collapse;
  margin-top: 1mm;
}
.awa-kv2 td {
  padding: 0.6mm 0;
  vertical-align: top;
}
.awa-kv2 td:first-child {
  width: 40mm;
  padding-right: 3mm;
  font-weight: 700; /* 範本中 P-Card 的標籤為粗體 */
  white-space: nowrap;
}
.awa-bank .awa-kv2 td:first-child {
  font-weight: 400;
}
.awa-terms p {
  margin: 0 0 1.2mm 0;
}
.awa-bank p {
  margin-top: 2mm;
}

/* Accepted by（P-Card 發票，右下）：空白簽署／蓋章區給收件方。
   兩行（Accepted by / Date）用同一個標籤欄寬，兩條底線左右對齊。 */
.awa-accept {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-top: 10mm;
}
.awa-accept-row {
  display: flex;
  align-items: flex-end;
  width: 100mm;
}
.awa-accept-label {
  font-family: 'Lexend', sans-serif;
  font-weight: 700;
  width: 30mm;
  text-align: right;
  padding-right: 4mm;
  box-sizing: border-box;
  white-space: nowrap;
}
.awa-accept-field {
  flex: 1;
  text-align: center;
}
.awa-accept-row:first-child .awa-accept-label {
  padding-bottom: 5.5mm; /* 讓標籤貼近簽署線，而非壓在說明文字下 */
}
.awa-accept-field .awa-sign-line {
  height: 22mm; /* 留足夠位置蓋章 */
}
.awa-accept-row + .awa-accept-row {
  margin-top: 5.5mm; /* 兩條線之間較多空間 */
}
.awa-accept-row:last-child .awa-accept-label {
  font-weight: 400;
  font-family: 'Comfortaa', sans-serif;
  font-size: 9pt;
}
.awa-date-line {
  border-bottom: 1px solid #000;
  height: 5mm;
}

/* 收據／薪單共用簽署區：單頁時貼近頁尾，多頁時留在內容後。
   實際印章直徑 21.2mm；簽署線穿過其底部 1/4（約 5.3mm）。 */
.awa-prepared {
  position: relative;
  width: 100mm;
  height: 28mm;
  margin-left: auto;
  margin-top: 6mm;
  flex-shrink: 0;
  break-inside: avoid;
}
.awa-prepared-row {
  position: absolute;
  top: 11mm;
  left: 0;
  display: flex;
  align-items: flex-end;
  width: 100mm;
}
.awa-prepared-label {
  font-family: 'Lexend', sans-serif;
  font-weight: 700;
  width: 30mm;
  text-align: right;
  padding-right: 4mm;
  box-sizing: border-box;
  white-space: nowrap;
}
.awa-prepared-field {
  flex: 1;
}
.awa-prepared-field .awa-sign-line {
  height: 8mm;
}
.awa-prepared-box {
  position: absolute;
  top: 3mm;
  left: 59mm;
  z-index: 1;
}
.awa-sign-line {
  border-bottom: 1px solid #000;
  height: 8mm;
}
.awa-sign-caption {
  font-size: 8pt;
  margin-top: 1mm;
}

/* 只有收據及薪單有簽署區；用 flex 把它推到固定頁尾上方，避免與內容重疊。 */
.awa-doc.fits-page:where(.awa-receipt, .awa-payslip):has(.awa-prepared) {
  display: flex;
  flex-direction: column;
}
.awa-doc.fits-page:where(.awa-receipt, .awa-payslip):has(.awa-prepared) .awa-prepared {
  margin-top: auto;
}
.awa-doc.fits-page:where(.awa-receipt, .awa-payslip):has(.awa-prepared) .awa-foot {
  position: static;
  margin-top: 4mm;
}
/* 收據的簽署區較接近紙張底部；預留更多頁底空間給瀏覽器列印邊距。 */
.awa-receipt.fits-page:has(.awa-prepared) {
  padding-bottom: 16mm;
}
@media print {
  /* Chrome 的「Minimum」邊距會縮小 A4 可印範圍；避免頁腳被擠到第二頁。 */
  .awa-receipt.fits-page:has(.awa-prepared) {
    min-height: 280mm;
  }
}

/* ===== 薪單專用 ===== */

/* Prepared by 印章（收據及薪單 Regular／Freelance 都用）。
   chop.png 原圖四周留有大片透明邊（實際印章僅佔中央約 62.7%×49.7%），
   直接用原圖會令印章與簽署線之間留一大段空白。
   這裡用一個裁切窗（.awa-chop-crop，尺寸＝印章實際大小）搭配內部絕對定位、放大置中的圖片，
   把透明邊裁掉，印章的底部 1/4 才能準確壓在線上。 */
.awa-chop-crop {
  position: relative;
  width: 21.3mm;
  height: 21.2mm;
  margin: 0 auto;
  overflow: hidden;
}
.awa-chop-crop img {
  position: absolute;
  top: -10.23mm;
  left: -7.14mm;
  width: 34mm; /* 與 .awa-chop 同一原圖顯示寬度，僅裁切透明邊，印章視覺大小不變 */
  height: auto;
  opacity: 0.95;
}

/* Earning／Deduction／Details 項目表沿用 .awa-items，彼此留一點間距 */
.awa-payslip-table {
  margin-top: 6mm;
}
/* 最終 NET PAY：沒有項目列，只留 tfoot 的 TOTAL 列，靠 colgroup 撐開跟其他項目表同一欄寬，
   TOTAL 字樣與金額因此與上方 TOTAL EARNING／TOTAL DEDUCTION 完全對齊、同一格式。 */
.awa-net-pay-table {
  margin-top: 3mm;
}
