/* ส่งห้าง (PO) — สไตล์หน้าทีมขาย/รายงาน (admin-po.js) + @media print ของหน้าตัวอย่างรายงาน
   โทเค็นสีทั้งหมดมาจาก :root ของ app.css (ไม่เพิ่มสีใหม่ → คู่สีที่ใช้ล้วนอยู่ในตารางของ test/ui-contrast.test.js แล้ว:
   warning/warning-soft · primary/primary-soft · case/case-soft · success-dark/success-soft · text-muted/surface-muted) */

/* ---------- ป้ายสถานะใบ PO ---------- */
.po-status {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.po-status-open { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.po-status-picked { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.po-status-shipping { background: var(--case-soft); color: var(--case); border-color: var(--case); }
.po-status-shipped { background: var(--success-soft); color: var(--success-dark); border-color: var(--success-dark); }
.po-status-cancelled { background: var(--surface-muted); color: var(--text-muted); border-color: var(--border-strong); }

/* ---------- รายการ PO (ตาราง) ---------- */
.po-table td { vertical-align: middle; }
.po-code { font-weight: 700; color: var(--primary); text-decoration: none; white-space: nowrap; }
.po-code:hover { text-decoration: underline; }
.po-muted { color: var(--text-faint); }
.po-lot { font-variant-numeric: tabular-nums; font-weight: 600; }
.po-lot-ok { color: var(--success-dark); }
.po-table .badge { margin-left: 0; }
.po-modal-sub { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.po-stores-actions { margin-bottom: 12px; }
.po-stores-actions .btn-primary { width: auto; }

/* ---------- ทะเบียนห้าง: ตารางสาขาซ้อนใต้ห้าง ---------- */
.po-branch-row > td { background: var(--surface-muted); white-space: normal; }
.po-subtable { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 10px; background: var(--surface); }
.po-subtable th, .po-subtable td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.po-subtable th { color: var(--text-muted); font-weight: 700; }
.po-subtable td.empty { color: var(--text-muted); text-align: center; }

/* ---------- ฟอร์มใบ PO ---------- */
.po-line-row select { flex: 1 1 200px; min-width: 0; }
.po-qty { width: 110px; min-width: 110px; }
.po-line-row .line-unit { flex: 0 0 96px; width: 96px; min-width: 0; }
.po-cancel-card { margin-top: 12px; }
.po-parsed-hint { margin-top: 10px; }
.po-line-row .btn-del { margin-left: auto; }
.po-note { font-size: 12px; color: var(--text-muted); margin: 2px 0 8px; }

/* ---------- หน้ารายงาน (ตัวกรอง + สรุป) ---------- */
.po-filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 12px; margin-bottom: 8px; }
.po-report-card .admin-btn-row .btn-primary { width: auto; }
.po-total-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; align-items: start; }
.po-total-grid h3 { font-size: 14px; margin: 0 0 6px; color: var(--text-muted); }
.po-sum-head { margin: 0 0 10px; font-size: 15px; }
.po-num { text-align: right; font-variant-numeric: tabular-nums; }
.po-sum-table th.po-num { text-align: right; }

/* ---------- ตัวอย่างรายงานแบบ A4 (บนจอ) ----------
   .report-page = กระดาษขาวกว้าง 297mm (A4 แนวนอน — ตารางมี 14 คอลัมน์ แนวตั้งแน่นเกินไป) กึ่งกลางจอ · มือถือ: กระดาษกว้างเต็มจอและเลื่อนซ้ายขวาได้ */
.report-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.report-toolbar .btn-primary { width: auto; }
.report-toolbar-hint { font-size: 12px; color: var(--text-muted); }
.report-loading { color: var(--text-muted); }
.report-page {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  margin: 0 auto 24px;
  padding: 16px;
  max-width: 297mm;
  overflow-x: auto;
  font-size: 14px;
}
@media (min-width: 860px) { .report-page { padding: 12mm; } }
.report-head { margin-bottom: 12px; }
.report-title { font-size: 22px; margin: 0 0 8px; }
.report-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 4px 20px; margin: 0; }
.report-meta div { display: flex; gap: 8px; }
.report-meta dt { color: var(--text-muted); white-space: nowrap; }
.report-meta dt::after { content: ":"; }
.report-meta dd { margin: 0; font-weight: 600; }
.report-table { width: 100%; min-width: 900px; border-collapse: collapse; font-size: 12.5px; margin-bottom: 14px; }
.report-table th, .report-table td { border: 1px solid var(--border-strong); padding: 4px 6px; text-align: left; vertical-align: top; }
.report-table th { background: var(--surface-muted); color: var(--text-muted); font-weight: 700; }
.report-table .report-num { text-align: right; font-variant-numeric: tabular-nums; }
.report-table .report-nowrap { white-space: nowrap; }
.report-table td.report-empty { text-align: center; color: var(--text-muted); padding: 18px; }
.report-totals h2 { font-size: 16px; margin: 6px 0 6px; }
.report-totals h3 { font-size: 13px; margin: 0 0 4px; color: var(--text-muted); }
.report-po-count { margin: 0 0 8px; }
.report-totals-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.report-table.report-sum { min-width: 0; margin-bottom: 0; }
.report-foot { margin: 12px 0 0; font-size: 12px; color: var(--text-muted); }

/* ---------- พิมพ์ / บันทึกเป็น PDF ----------
   ซ่อนทุกอย่างที่ไม่ใช่กระดาษรายงาน (แถบผู้ใช้ เมนู แถบปุ่ม toast กล่อง popup) · A4 ขอบ 12mm · หัวตารางซ้ำทุกหน้า · แถวไม่ถูกตัดกลาง ·
   ตัวอักษร 11pt (ตารางหลักลดเป็น 9.5pt เพราะ 14 คอลัมน์) · app.css ขยาย body ด้วย zoom บนจอคอม (1.2/1.35) — พิมพ์ต้องเป็น 1 เสมอ
   ไม่งั้นกระดาษล้นขอบ · @page ชื่อ po-report = A4 แนวนอน เฉพาะหน้านี้ (เบราว์เซอร์ที่ไม่รู้จักหน้าที่ตั้งชื่อ ใช้ค่าที่ผู้ใช้เลือกในหน้าต่างพิมพ์) */
@page { margin: 12mm; }
@page po-report { size: A4 landscape; margin: 12mm; }
@media print {
  .user-bar, .admin-nav, .report-toolbar, .toast, #po-modal, .admin-subnav { display: none !important; }
  html, body { background: #fff !important; }
  body { zoom: 1 !important; font-size: 11pt; }
  #app, .app-shell, .admin-page, .admin-page.admin-page-wide { max-width: none !important; width: auto !important; margin: 0 !important; padding: 0 !important; }
  .report-page {
    page: po-report;
    border: 0; border-radius: 0; box-shadow: none; padding: 0; margin: 0; max-width: none; overflow: visible;
    font-size: 11pt; background: #fff; color: #000;
  }
  .report-title { font-size: 16pt; }
  .report-table { min-width: 0; width: 100%; font-size: 9.5pt; }
  .report-table th { background: #eee !important; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .report-table thead { display: table-header-group; }
  .report-table tr { page-break-inside: avoid; break-inside: avoid; }
  .report-totals, .report-head { page-break-inside: avoid; break-inside: avoid; }
  .report-foot, .report-meta dt { color: #000; }
}
