/**
 * 報價單 A4 列印樣式
 * ============================================
 * 螢幕上：報價單編輯器沿用既有 css tokens，本檔只負責「列印檢視」的排版。
 * 觸發：編輯器點「列印 / 輸出 PDF」→ 在 body 加 class `is-quote-printing`
 *       + 動態塞入 #quote-print-root（列印用 DOM）→ window.print()。
 *
 * 規格（契約 §5）：
 *   - A4 直式，第 1 頁總表＋條款＋公司資訊＋簽章欄
 *   - 第 2 頁起各類別細項，每頁重複表頭
 *   - 成本 / 毛利欄位「絕不」出現（列印 DOM 根本不產生這些欄）
 *   - 金額千分位、無小數；數量一位小數
 *
 * @media print 時隱藏整個 App 外殼（nav / header / fab / view-outlet），只留列印根。
 */

/* 列印根：螢幕上永遠隱藏（只有列印時或預覽時才顯示） */
#quote-print-root { display: none; }

/* ============ 螢幕預覽（點列印前先給使用者看一眼，非必要但體驗較好） ============ */
body.is-quote-printing #quote-print-root {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 9999;
  overflow: auto;
  background: #f4f4f4;
  padding: 24px 0;
}
body.is-quote-printing #quote-print-root .qp-page {
  background: #fff;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto 16px;
  padding: 14mm 14mm 16mm;
  box-shadow: 0 4px 18px rgba(0,0,0,0.15);
  box-sizing: border-box;
}
/* 螢幕預覽時把 App 外殼淡出（避免捲動穿透干擾） */
body.is-quote-printing .app-shell,
body.is-quote-printing #view-outlet,
body.is-quote-printing .app-nav,
body.is-quote-printing .app-header,
body.is-quote-printing .fab,
body.is-quote-printing .bottom-nav {
  filter: none;
}
/* 螢幕預覽的關閉列 */
.qp-toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10000;
  display: none;
  gap: 12px;
  justify-content: center;
  align-items: center;
  padding: 10px;
  background: #334E5A;
  color: #fff;
}
body.is-quote-printing .qp-toolbar { display: flex; }
.qp-toolbar button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 8px 18px;
  cursor: pointer;
  background: #fff;
  color: #334E5A;
  font-weight: 700;
}
.qp-toolbar button.qp-toolbar__ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.6);
}
body.is-quote-printing #quote-print-root { padding-top: 60px; }

/* ============ 列印排版本體（螢幕預覽與實體列印共用） ============ */
.qp-doc {
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: #000;
  font-size: 12px;
  line-height: 1.5;
}
.qp-doc * { box-sizing: border-box; }

.qp-title {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 4px;
  margin: 0 0 6px;
}
.qp-subhead {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
}
.qp-meta {
  margin-bottom: 8px;
  font-size: 12px;
}
.qp-meta div { margin-bottom: 2px; }

/* 表格 */
.qp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}
.qp-table th, .qp-table td {
  border: 1px solid #000;
  padding: 4px 6px;
  vertical-align: top;
  word-break: break-word;
}
.qp-table thead th {
  background: #eee;
  font-weight: 700;
  text-align: center;
}
.qp-num   { text-align: right;  white-space: nowrap; }
.qp-center{ text-align: center; }
.qp-cat-row td {
  background: #f3f3f3;
  font-weight: 700;
}
.qp-note-row td {
  font-size: 11px;
  color: #333;
  font-style: italic;
}
.qp-subtotal-row td {
  font-weight: 700;
  text-align: right;
}

/* 總表彙總列 */
.qp-summary-row td { font-weight: 700; }
.qp-summary-row .qp-sum-label { text-align: right; }

/* 條款 */
.qp-terms {
  margin-top: 10px;
  font-size: 11px;
  line-height: 1.6;
}
.qp-terms h3 { font-size: 12px; margin: 0 0 4px; }
.qp-terms ol { margin: 0; padding-left: 18px; }
.qp-terms li { margin-bottom: 2px; }

/* 公司資訊 */
.qp-company {
  margin-top: 12px;
  font-size: 11px;
  line-height: 1.7;
  border-top: 1px solid #000;
  padding-top: 8px;
}
.qp-company div { margin-bottom: 1px; }

/* 簽章欄 */
.qp-sign {
  margin-top: 22px;
  font-size: 12px;
}
.qp-sign__line {
  display: inline-block;
  border-bottom: 1px solid #000;
  min-width: 220px;
  margin-left: 8px;
}

/* 細項頁表頭區塊 */
.qp-detail-head {
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
}

/* 類別避免跨頁截斷（盡力） */
.qp-cat-block { break-inside: avoid; page-break-inside: avoid; }

/* ============ 實體列印 ============ */
@media print {
  /* A4 直式，邊界交給 .qp-page padding 控制 */
  @page { size: A4 portrait; margin: 12mm; }

  /* 隱藏整個 App 外殼與預覽 chrome */
  body.is-quote-printing > *:not(#quote-print-root) { display: none !important; }
  .app-shell, #view-outlet, .app-nav, .app-header,
  .fab, .bottom-nav, .app-topbar, .qp-toolbar { display: none !important; }

  html, body { background: #fff !important; }

  #quote-print-root {
    display: block !important;
    position: static !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
  }
  .qp-page {
    width: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    /* 每頁分頁 */
    page-break-after: always;
  }
  .qp-page:last-child { page-break-after: auto; }

  /* 細項頁的表頭在每個列印頁重複 */
  .qp-table thead { display: table-header-group; }
  .qp-table tr { page-break-inside: avoid; }
}
