/* รอบ 33: ขายเชื่อที่หน้าขาย/ลูกค้า/ใบเสร็จ/รายการขาย/แดชบอร์ด (prefix crp-)
   สีหนี้ใช้โทนเหลืองอำพัน (--warn-soft / --warn-text) เกินกำหนดใช้ --danger ทั้งหมดใช้ตัวแปร dark mode จึงตามอัตโนมัติ */

/* ---------- หน้าขาย: ชิปลูกค้าในตะกร้า ---------- */
.posa-chip small.crp-chip-debt { color: var(--warn-text, #7a5300); font-weight: 700; opacity: 1; }

/* ---------- แผ่นชำระเงิน: กล่องขายเชื่อ (ขนาดเท่ากล่องแต้ม ไม่ให้แผ่นยาวจนต้องเลื่อน) ---------- */
.crp-pay {
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  transition: border-color .15s, background-color .15s;
}
.crp-pay.on { border-color: rgba(var(--brand-rgb), .45); background: var(--brand-tint); }
.crp-pay-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 10px; font-size: .86rem; min-width: 0; }
.crp-pay-title { font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.crp-pay-title::before {
  content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--warn-text, #b07100); flex: none;
}
.crp-pay-stat { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0 12px; color: var(--muted); font-size: .8rem; min-width: 0; }
.crp-pay-stat > span { white-space: nowrap; }
.crp-pay-due { color: var(--ink); font-weight: 600; }
/* มือถือ: ชื่อ + ตัวเลขไหลต่อกันในแถวเดียว (ประหยัดความสูงของแผ่นชำระเงิน) */
@media (max-width: 1024px) {
  .crp-pay-head { justify-content: flex-start; gap: 0 12px; }
  .crp-pay-stat { display: contents; }
}
.crp-pay-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.crp-pay-input {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 4px 0 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); margin: 0;
}
.crp-pay-input:focus-within { outline: 2px solid var(--brand); border-color: transparent; }
.crp-pay-label { flex: none; font-size: .82rem; font-weight: 600; color: var(--muted); }
.crp-pay .crp-pay-input input {
  flex: 1 1 auto; width: 100%; min-width: 0; height: 100%; padding: 0 6px; border: 0; outline: none; background: transparent;
  font: inherit; font-size: 16px; font-weight: 700; text-align: right; color: var(--ink); box-shadow: none; min-height: 0;
}
.crp-pay-clear {
  flex: none; width: 32px; height: 32px; border: 0; border-radius: 999px; background: var(--chip); color: var(--ink);
  font: inherit; font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.crp-pay-full {
  flex: none; height: 40px; padding: 0 12px; border: 1px solid transparent; border-radius: 12px;
  background: var(--brand-soft); color: var(--brand-strong, var(--brand)); font: inherit; font-size: .85rem; font-weight: 700;
  cursor: pointer; white-space: nowrap;
}
.crp-pay-full.on { background: var(--brand); color: var(--brand-ink, #fff); }
.crp-pay-msg { line-height: 1.3; }
.crp-warn { color: var(--warn-text, #7a5300); font-weight: 600; }
.crp-pay-hint { margin: -2px 2px 0; line-height: 1.3; }

/* การ์ดยอด: เชื่อเท่าไร / ต้องเก็บตอนนี้เท่าไร */
.crp-due-split { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; width: 100%; color: var(--muted); }
.crp-due-split strong { color: var(--ink); font-size: inherit !important; font-weight: 700; line-height: inherit !important; }
@media (max-width: 1024px) {
  .posl-pay .paysheet-due .crp-due-split { flex: 1 1 100%; }
}

/* คอลัมน์รับเงิน: ขายเชื่อทั้งบิล ไม่ต้องรับเงิน */
.crp-nopay {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  min-height: 160px; padding: 18px 16px; border: 1.5px dashed rgba(var(--brand-rgb), .4); border-radius: 18px;
  background: var(--brand-tint);
}
.crp-nopay strong { font-size: 1.05rem; }
.crp-nopay-ico {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-strong, var(--brand));
}
@media (min-width: 1025px) {
  .crp-nopay { flex: 1 1 auto; min-height: 220px; }
}
@media (max-width: 1024px) {
  .crp-nopay { min-height: 0; flex-direction: row; flex-wrap: wrap; justify-content: flex-start; text-align: left; padding: 12px 14px; gap: 4px 12px; }
  .crp-nopay-ico { width: 40px; height: 40px; }
  .crp-nopay strong { flex: 1 1 0; min-width: 0; }
  .crp-nopay > .small { flex: 1 1 100%; }
}
.posl-pay .paysheet-result.crp-result { background: var(--warn-soft); }
.posl-pay .paysheet-result.crp-result span { color: var(--warn-text, #7a5300); font-weight: 600; }
.posl-pay .paysheet-result.crp-result strong { color: var(--warn-text, #7a5300); }

/* ---------- ตัวเลือกลูกค้า + หน้ารายชื่อลูกค้า ---------- */
.crp-row-debt, .crp-row-tag {
  flex: none; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap;
}
.crp-row-debt { background: var(--warn-soft); color: var(--warn-text, #7a5300); }
.crp-row-tag { background: var(--chip); color: var(--muted); }
.posa-cust-row .crp-row-debt, .posa-cust-row .crp-row-tag { margin-left: auto; }
.posa-cust-row .loy-row-pts + .crp-row-debt, .posa-cust-row .loy-row-pts + .crp-row-tag { margin-left: 0; }

.crp-debt-link {
  display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--warn-soft);
  color: var(--warn-text, #7a5300); font-weight: 700; text-decoration: none; white-space: nowrap;
}
.crp-debt-link:hover { text-decoration: underline; text-underline-offset: 2px; }
.crp-debt-wrap { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 0; }
.crp-term { font-size: .74rem; line-height: 1.3; }
@media (min-width: 761px) {
  /* จอคอม: เงื่อนไขเครดิตอยู่ใน tooltip ของช่อง (ไม่ให้ตารางสูง/คอลัมน์ชื่อแคบ) */
  .crp-debt-cell .crp-term { display: none; }
  .fitc-custs .fitc-stats:has(.crp-stat) { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); }
}
.fit-stat.crp-stat strong { color: var(--warn-text, #7a5300); }

/* ฟอร์มลูกค้า: ตั้งค่าขายเชื่อ */
.crp-set {
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--brand-tint);
}
.crp-set-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.crp-set .plan-lock-note { margin: 0; }

/* รอบ 104: ช่องตั้งค่าขายเชื่อชุดเดียว <CreditTermsFields> (ฟอร์มลูกค้า + ป๊อปอัปตั้งค่าเครดิตของหน้าลูกหนี้) */
.crt { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.crt-on { font-weight: 600; }
.crt-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.crt-grid .field small { font-weight: 400; }
@media (max-width: 480px) {
  .crt-grid { grid-template-columns: 1fr; }
}

/* ---------- รายการขาย ---------- */
.sla-chip.crp-owing { background: var(--warn-soft); color: var(--warn-text, #7a5300); }
.sla-chip.crp-paid { background: var(--ok-soft); color: var(--ok); }
.crp-drw h3 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.crp-drw-link { font-weight: 600; color: var(--brand-strong, var(--brand)); }
.crp-drw-out dd strong { font-size: 1.05rem; }
.crp-overdue {
  display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: 999px;
  background: var(--danger-soft); color: var(--danger); font-size: .78rem; font-weight: 700; white-space: nowrap;
}
.crp-refund-hint { display: block; line-height: 1.35; }

/* ---------- แดชบอร์ด: การ์ดลูกหนี้ในงานที่รอ ---------- */
.dash-tile.crp-dash.on { background: var(--warn-soft); border-color: transparent; }
.dash-tile.crp-dash.on .dash-tile-val strong { color: var(--warn-text, #7a5300); }
.dash-tile.crp-dash.over { background: var(--danger-soft); border-color: transparent; }
.dash-tile.crp-dash.over .dash-tile-val strong { color: var(--danger); }
/* 4 การ์ด (มีกะ + ลูกหนี้) แถวเดียวแคบเกินไป → 2×2 */
.dash-task-tiles:has(> .crp-dash):has(> :nth-child(4)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dash-tile.crp-dash .dash-tile-val { flex-wrap: wrap; row-gap: 0; }
.crp-dash-over {
  min-width: 0; padding: 0 8px; border-radius: 999px; background: var(--surface); color: var(--danger);
  font-size: .74rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- ใบเสร็จ ---------- */
.crp-r-box { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px dashed var(--line); }
.crp-r-box .crp-r-credit strong { color: var(--warn-text, #7a5300); }
@media print {
  .crp-r-box { border-top-color: #999; }
  .crp-r-box .crp-r-credit { font-weight: 700; }
  .crp-r-box .crp-r-credit strong { color: inherit; }
  .crp-r-sign { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 10mm; font-size: 11px; break-inside: avoid; }
  .crp-r-sign-line { display: block; width: 80%; border-top: 1px solid #111; }
  html[data-print="a4"] .crp-r-box { gap: 1.5mm; padding-top: 2mm; }
}
.reprint .crp-r-sign { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 28px; font-size: .85rem; color: var(--muted); }
.reprint .crp-r-sign-line { display: block; width: 70%; border-top: 1px solid var(--line); }
