/* AR invoice entry (ลูกหนี้การค้า / ลูกหนี้อื่น): laid out like the source document —
   customer on the left, document details on the right, totals attached under the lines. */

#modalAROther .modal-dialog { max-width: min(1240px, calc(100vw - 32px)); }
#modalAROther .modal-content { border-radius: 14px; overflow: hidden; }
#modalAROther .form-label-custom { text-transform: none; letter-spacing: 0; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
#modalAROther .input-custom { min-height: 38px; }
#modalAROther .input-custom:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
#modalAROther .input-custom.no-focus-border:focus { box-shadow: none; }

/* Header */
.aro-modal-head { display: flex; align-items: center; gap: 16px; padding: 14px 22px; border-color: var(--border-color); background: var(--bg-card); }
.aro-head-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.aro-head-title > i { flex-shrink: 0; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-size: 20px; }
#aro-modal-title-text { font-size: 16px; font-weight: 700; line-height: 1.4; }
.aro-head-title small { display: block; font-size: 12px; color: var(--text-muted); }
.aro-head-meta { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.aro-internal-no { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.aro-internal-no b { font-weight: 500; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.aro-body { padding: 20px 24px 24px; display: flex; flex-direction: column; gap: 20px; background: var(--bg-main); }

/* Document card */
.aro-doc { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 12px; box-shadow: 0 1px 2px rgb(32 34 37 / 4%); }
.aro-doc-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.aro-doc-party, .aro-doc-meta { display: flex; flex-direction: column; gap: 12px; padding: 18px 22px 20px; min-width: 0; }
.aro-doc-meta { border-left: 1px solid var(--border-color); }
.aro-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; }
.aro-sec-title { font-size: 13px; font-weight: 700; color: var(--text-primary); display: inline-flex; align-items: center; gap: 6px; }
.aro-field { min-width: 0; }
.aro-req { color: var(--danger); }
.aro-opt { font-weight: 400; color: var(--text-muted); }
.aro-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.aro-hint:empty { display: none; }
.aro-hint.is-ok { color: var(--success); }
.aro-hint.is-warn { color: var(--warning); }
.aro-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.aro-row-date { grid-template-columns: minmax(0, 1fr) 132px; }
.aro-inline { display: flex; align-items: center; gap: 8px; min-width: 0; }
.aro-inline > select { flex: 1; min-width: 0; }
.aro-add-btn { flex-shrink: 0; width: 38px; height: 38px; }
.aro-rate-custom { width: 84px !important; flex-shrink: 0; }
.aro-num { text-align: right; font-variant-numeric: tabular-nums; }
.aro-strong { font-weight: 600; font-size: 14px !important; }
.aro-icon-input { position: relative; }
.aro-icon-input > input { padding-right: 34px; cursor: pointer; }
.aro-icon-input > i { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.aro-money-input { position: relative; }
.aro-money-input > input { padding-right: 46px; font-size: 16px !important; }
.aro-money-input > span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--text-muted); pointer-events: none; }
textarea.aro-autogrow { resize: none; overflow: hidden; line-height: 1.6; transition: height .18s ease; min-height: 38px; }

/* Customer type segmented control */
.aro-seg { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border-color); border-radius: 9px; background: var(--bg-main); }
.aro-seg .aro-term-pill { padding: 4px 12px; font-size: 12px; border-radius: 7px; }
.aro-seg .aro-term-pill.active { background: var(--bg-card); color: var(--brand); }

/* Terms + references strip (inside the document card) */
.aro-doc-terms { display: flex; flex-direction: column; gap: 14px; padding: 16px 22px 18px; border-top: 1px solid var(--border-color); background: color-mix(in srgb, var(--bg-main) 55%, var(--bg-card)); border-radius: 0 0 12px 12px; }
.aro-terms-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 12px 16px; align-items: end; }
.aro-terms-refs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.aro-terms-pay .aro-inline { flex-wrap: wrap; }
.aro-doc-terms .aro-term-toggle { background: var(--bg-card); border: 1px solid var(--border-color); }
.aro-doc-terms .aro-term-pill { padding: 6px 12px; }
.aro-credit-days { display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); background: var(--bg-card); }
.aro-credit-days input { width: 56px; border: 0; background: transparent; outline: none; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.aro-credit-days span { font-size: 12px; color: var(--text-muted); }
.aro-readonly { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 12px; border: 1px dashed var(--border-color); border-radius: var(--radius-sm); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.aro-readonly i { color: var(--brand); }
.aro-install > div { margin-top: 0 !important; }

/* Lines */
.aro-lines { display: flex; flex-direction: column; }
.aro-lines-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.aro-lines-head .aro-hint { margin: 0; }
.aro-add-line { margin-left: auto; font-size: 12px !important; padding: 6px 12px !important; }
.aro-lines-scroll { overflow-x: auto; border: 1px solid var(--border-color); border-radius: 12px 12px 0 0; background: var(--bg-card); }
.aro-grid-head, .aro-line-grid { display: grid; gap: 8px; align-items: center; min-width: 940px; }
.aro-grid-head { padding: 9px 12px; border-bottom: 1px solid var(--border-color); background: var(--bg-main); font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.aro-grid-head .c-strong { color: var(--text-primary); }
.c-right { text-align: right; } .c-center { text-align: center; }
.aro-line-wrap { border-bottom: 1px solid var(--border-color); }
.aro-line-wrap:last-child { border-bottom: 0; }
.aro-line-grid { padding: 10px 12px; }
.aro-line-no { text-align: center; font-size: 12px; font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.aro-line-desc { display: flex; align-items: flex-start; gap: 6px; min-width: 0; }
.aro-line-add-pcc { flex-shrink: 0; width: 30px !important; height: 30px !important; margin-top: 4px; font-size: 13px !important; }
/* Description: shows up to two lines when not editing; the real input sits on top and appears on focus. */
.aro-desc-field { position: relative; flex: 1; min-width: 0; }
.aro-desc-preview {
  /* spacing comes from transparent borders so overflow clipping hides any third line; outline draws the edge */
  min-height: 38px; padding: 0; border: solid transparent; border-width: 8px 12px; border-radius: var(--radius-sm);
  outline: 1px solid var(--border-color); outline-offset: -1px;
  background: var(--input-bg); font-size: 13px; line-height: 1.45; color: var(--text-primary);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word;
}
.aro-desc-preview:empty::before { content: attr(data-placeholder); color: var(--text-muted); }
.aro-desc-field > input { position: absolute; inset: 0; width: 100%; height: 100%; }
.aro-desc-field > input:not(:focus) { opacity: 0 !important; }
.aro-desc-field > input:disabled + .aro-desc-preview, .aro-desc-field:has(input:disabled) .aro-desc-preview { opacity: .7; }
.aro-line-num { height: 38px; text-align: right; font-size: 14px !important; font-weight: 600; font-variant-numeric: tabular-nums; }
.aro-line-qty { font-size: 15px !important; }
.aro-line-cell-right { text-align: right; overflow: hidden; }
.aro-line-gross { font-size: 13px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; font-variant-numeric: tabular-nums; }
.aro-line-discbaht { font-size: 12px; font-weight: 600; color: var(--warning); white-space: nowrap; font-variant-numeric: tabular-nums; }
.aro-line-net { font-size: 14px; font-weight: 700; color: var(--text-primary); white-space: nowrap; font-variant-numeric: tabular-nums; }
.aro-line-vat-badge { font-size: 10.5px; font-weight: 500; margin-top: 2px; white-space: nowrap; }
.aro-line-disc { position: relative; }
.aro-line-disc input { height: 38px; text-align: center; padding-right: 8px; font-variant-numeric: tabular-nums; } /* #44: หน่วยดูจากปุ่มกลม (ไม่มีสัญลักษณ์ซ้อนในช่อง) */
.aro-disc-type-btn {
  position: absolute; right: -7px; bottom: -7px; z-index: 3; width: 18px; height: 18px; padding: 0;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
  border: 1px solid var(--border-color); background: var(--bg-card); color: var(--brand);
  font-size: 10px; font-weight: 700; line-height: 1; cursor: pointer; box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
}
.aro-line-remove { width: 30px !important; height: 30px !important; font-size: 13px !important; color: var(--text-muted); }
.aro-line-remove:hover { color: var(--danger); }

/* Under the lines: notes + attachments (left), totals attached to the table (right) */
.aro-under { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); border: 1px solid var(--border-color); border-top: 0; border-radius: 0 0 12px 12px; background: var(--bg-card); }
.aro-under-left { display: flex; flex-direction: column; gap: 14px; padding: 16px 18px; min-width: 0; }
#aro-attach-zone {
  display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 56px; padding: 10px 14px;
  border: 1.5px dashed var(--border-color); border-radius: var(--radius-sm); background: var(--bg-main);
  color: var(--text-muted); font-size: 12.5px; cursor: pointer; transition: border-color .15s, background .15s;
}
#aro-attach-zone:hover, #aro-attach-zone.is-drag { border-color: var(--brand); background: var(--brand-soft); color: var(--text-secondary); }
#aro-attach-zone i { font-size: 20px; }
#aro-attach-zone small { display: block; font-size: 11px; }
.aro-attach-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.aro-attach-list:empty { display: none; }
.aro-summary { padding: 16px 20px; border-left: 1px solid var(--border-color); background: color-mix(in srgb, var(--bg-main) 55%, var(--bg-card)); border-radius: 0 0 12px 0; font-variant-numeric: tabular-nums; }
.aro-sum-row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 4px 0; font-size: 13px; color: var(--text-secondary); }
.aro-sum-row b { font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.aro-sum-row small { font-size: 11px; font-weight: 400; color: var(--text-muted); }
.aro-sum-row.is-neg b { color: var(--danger); }
/* R-092 (#126): ส่วนลดท้ายบิล กรอกในสรุปมูลค่า */
.aro-billdisc-row { align-items: center; }
.aro-billdisc-row b { display: inline-flex; align-items: center; gap: 4px; }
.aro-billdisc-input { width: 120px; height: 30px; padding: 4px 8px; text-align: right; font-size: 13px; font-weight: 600; color: var(--danger); }
.aro-billdisc-input:disabled { opacity: .55; cursor: not-allowed; }
.aro-sum-row.is-total { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--text-primary); font-size: 14px; font-weight: 700; color: var(--text-primary); }
.aro-sum-row.is-total b { font-size: 18px; font-weight: 700; }
.aro-sum-row.is-wht b { color: var(--danger); font-weight: 500; }
.aro-sum-row.is-net { padding-top: 6px; border-top: 1px dashed var(--border-color); font-weight: 600; color: var(--text-primary); }
.aro-sum-row.is-net b { color: var(--brand); font-size: 15px; }
.aro-sum-adjust { flex-direction: column; margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--warning); }

[data-theme="dark"] .aro-term-pill.active, [data-theme="dark"] .aro-term-pill:has(input:checked) { background: var(--bg-main); }

/* Small screens: stack the two halves */
@media (max-width: 991.98px) {
  .aro-doc-grid { grid-template-columns: 1fr; }
  .aro-doc-meta { border-left: 0; border-top: 1px solid var(--border-color); }
  .aro-terms-grid, .aro-terms-refs { grid-template-columns: 1fr 1fr; }
  .aro-terms-pay { grid-column: 1 / -1; }
  .aro-under { grid-template-columns: 1fr; }
  .aro-summary { border-left: 0; border-top: 1px solid var(--border-color); border-radius: 0 0 12px 12px; }
}
@media (max-width: 575.98px) {
  .aro-body { padding: 14px; }
  .aro-doc-party, .aro-doc-meta, .aro-doc-terms { padding: 14px; }
  .aro-row-2, .aro-terms-grid, .aro-terms-refs { grid-template-columns: 1fr; }
  .aro-lines-head .aro-hint { display: none; }
  .aro-internal-no { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  textarea.aro-autogrow { transition: none; }
}

/* Payment-type picker (remark tag only) */
.aro-seg-wide { display: flex; width: 100%; }
.aro-seg-wide .aro-term-pill { flex: 1; justify-content: center; padding: 7px 10px; }

/* ── AI scan review: same document pattern as the entry form ── */
.ai-review-stack { display: flex; flex-direction: column; gap: 12px; }
.ai-doc .form-label-custom, .ai-lines .form-label-custom { text-transform: none; letter-spacing: 0; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.ai-doc .input-custom, .ai-lines .input-custom { min-height: 38px; }
.ai-doc-total { justify-content: space-between; border-style: solid; background: var(--bg-main); }
.ai-doc-total span { font-size: 16px; font-weight: 700; }
.ai-doc-total small { font-size: 11px; font-weight: 400; color: var(--text-muted); }
.ai-doc-warn { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 1px solid #fcd34d; border-radius: var(--radius-sm); background: #fffbeb; font-size: 12px; color: #92400e; }
.ai-doc-warn-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-doc-warn-head > i { font-size: 18px; color: #d97706; }
.ai-doc-warn-head > div { flex: 1; min-width: 160px; }
.ai-doc-warn-head small, .ai-doc-near small { display: block; font-size: 11px; opacity: .85; }
.ai-doc-near { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 8px; border-top: 1px dashed #fcd34d; }
[data-theme="dark"] .ai-doc-warn { background: #3a3020; border-color: #6b5520; color: #f5d78a; }
.ai-lines-box { border: 1px solid var(--border-color); border-radius: 12px 12px 0 0; background: var(--bg-card); overflow-x: auto; }
.ai-line-row { display: grid; grid-template-columns: 28px minmax(170px, 1fr) 118px 92px 150px 112px; gap: 8px; align-items: start; padding: 10px 12px; min-width: 740px; border-top: 1px solid var(--border-color); }
.ai-line-head { align-items: center; border-top: 0; background: var(--bg-main); font-size: 11.5px; font-weight: 600; color: var(--text-secondary); padding: 9px 12px; }
.ai-line-row .aro-line-no { padding-top: 10px; }
.ai-line-desc { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ai-line-desc select { font-size: 12px; color: var(--text-secondary); }
.ai-line-sub { margin-top: 4px; font-size: 11px; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.ai-line-wht { display: grid; grid-template-columns: 56px 1fr; gap: 6px; }
.ai-line-group { border-top: 1px solid var(--border-color); }
.ai-line-group:first-of-type { border-top: 0; }
.ai-line-group-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px 2px; }
.ai-line-group-title { font-size: 11.5px; font-weight: 600; color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }
.ai-line-group.is-missing { background: #fffdf5; }
[data-theme="dark"] .ai-line-group.is-missing { background: #2b2719; }
.ai-line-group-note { padding: 4px 12px 0; font-size: 11.5px; color: #92400e; }
.ai-line-group .ai-rule-detail-box { margin: 8px 12px 0; }
.ai-line-group .ai-line-row { border-top: 0; }

/* Doc total computed from lines */
#aro-doc-total.is-auto { background: var(--bg-main); color: var(--text-primary); cursor: default; border-style: dashed; }

/* Recording employee (ตาม Login) at the end of entry forms */
.doc-recorder { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 22px; margin-top: 4px; padding-top: 12px; border-top: 1px dashed var(--border-color); font-size: 12.5px; color: var(--text-muted); }
.doc-recorder b { color: var(--text-primary); font-weight: 600; }
.doc-recorder-item { display: inline-flex; align-items: center; gap: 6px; }

/* ── AR credit / debit note: same document pattern ── */
#modalCreditNote .modal-dialog { max-width: min(1240px, calc(100vw - 32px)); }
#modalCreditNote .modal-content { border-radius: 14px; overflow: hidden; }
#modalCreditNote .form-label-custom { text-transform: none; letter-spacing: 0; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
#modalCreditNote .input-custom { min-height: 38px; }
#modalCreditNote .input-custom:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.dcn-pick { padding: 16px 22px; display: flex; flex-direction: column; gap: 8px; }
.dcn-pick-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; }
.dcn-detail { display: flex; flex-direction: column; gap: 20px; }
.dcn-lock { font-size: 11.5px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }
.dcn-ro { border-style: solid; background: var(--bg-main); font-weight: 500; }
.dcn-ro-multi { min-height: 56px; align-items: flex-start; padding-top: 8px; padding-bottom: 8px; line-height: 1.55; }
.dcn-orig-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; font-variant-numeric: tabular-nums; }
.dcn-orig-grid small { display: block; font-size: 11.5px; color: var(--text-muted); }
.dcn-orig-grid b { font-size: 15px; font-weight: 700; }
.dcn-prev-list { display: flex; flex-wrap: wrap; gap: 6px; }
.dcn-prev-list:empty { display: none; }
.dcn-prev-chip { font-size: 11.5px; padding: 2px 10px; border-radius: 20px; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--success); }
.dcn-prev-chip.is-debit { color: var(--warning); }
.dcn-line { display: grid; grid-template-columns: 40px minmax(240px, 1fr) 110px 140px 130px 40px; gap: 8px; align-items: center; padding: 10px 12px; min-width: 760px; border-top: 1px solid var(--border-color); } /* R-146: ตัดมูลค่าคงเหลือ · ปุ่มลบรายการ */
.dcn-desc-input { width: 100%; min-height: 34px; resize: none; font-size: 13px; line-height: 1.5; }
.dcn-del { color: var(--text-muted); }
.dcn-del:hover { color: var(--danger); }
.dcn-line-head { border-top: 0; background: var(--bg-main); font-size: 11.5px; font-weight: 600; color: var(--text-secondary); padding: 9px 12px; }
.dcn-line:not(.is-on) .dcn-line-desc, .dcn-line:not(.is-on) .dcn-num { color: var(--text-muted); }
.dcn-line.is-on { background: color-mix(in srgb, var(--brand-soft) 45%, var(--bg-card)); }
.dcn-line-desc { font-size: 13px; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.dcn-line-desc small { display: block; font-size: 11px; font-weight: 400; color: var(--text-muted); }
.dcn-num { font-variant-numeric: tabular-nums; font-size: 13px; }
.dcn-over { display: block; font-size: 11px; color: var(--danger); }
.dcn-free { max-width: 420px; padding: 14px 16px; border: 1px solid var(--border-color); border-radius: 12px 12px 0 0; background: var(--bg-card); }
@media (max-width: 767.98px) {
  .dcn-pick-grid, .dcn-orig-grid { grid-template-columns: 1fr 1fr; }
}
.dcn-over:empty { display: none; }

/* ── Customer deposit + deposit refund: same document pattern ── */
#modalDeposit .modal-dialog, #modalDepositRefund .modal-dialog { max-width: min(1240px, calc(100vw - 32px)); }
#modalDeposit .modal-content, #modalDepositRefund .modal-content { border-radius: 14px; overflow: hidden; }
#modalDeposit .form-label-custom, #modalDepositRefund .form-label-custom { text-transform: none; letter-spacing: 0; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
#modalDeposit .input-custom, #modalDepositRefund .input-custom { min-height: 38px; }
#modalDeposit .input-custom:focus, #modalDepositRefund .input-custom:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.dep-status-chip { font-size: 11.5px; padding: 2px 10px; border-radius: 20px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.dep-flow { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.dep-flow li { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--border-color); border-radius: 20px; background: var(--bg-card); font-size: 12.5px; color: var(--text-secondary); }
.dep-flow li b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--bg-main); font-size: 11px; }
.dep-flow li small { font-size: 11px; color: var(--text-muted); }
.dep-flow li.is-current { border-color: var(--brand); color: var(--text-primary); font-weight: 600; }
.dep-flow li.is-current b { background: var(--brand); color: var(--brand-ink); }
.dep-flow li.is-done b { background: var(--success); color: #fff; }
.dep-paid-strip { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 12.5px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.dep-paid-strip b { color: var(--text-primary); }
.dep-lines-box { border: 1px solid var(--border-color); border-radius: 12px 12px 0 0; background: var(--bg-card); overflow-x: auto; padding-bottom: 4px; }
.dep-lines-box #dep-product-lines > * { margin: 0 8px; }
.dep-lines-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 24px; color: var(--text-muted); font-size: 13px; }
.dep-lines-empty i { font-size: 24px; opacity: .5; }
.depref-no { width: 150px; border: 0; background: transparent; font: inherit; font-weight: 500; color: var(--text-secondary); outline: none; }
.depref-amounts { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.depref-amounts .is-key b { color: var(--brand); }
.depref-line { display: grid; grid-template-columns: 40px minmax(200px, 1fr) 100px 150px 150px; gap: 8px; align-items: center; padding: 9px 12px; min-width: 680px; border-top: 1px solid var(--border-color); }
.depref-line-head { border-top: 0; background: var(--bg-main); font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.depref-under .aro-under-left > .aro-sec-title { margin-bottom: -4px; }
.depref-fill { margin-top: 4px; padding: 0; border: 0; background: none; color: var(--brand); font-size: 12px; cursor: pointer; }
.depref-fill:hover { text-decoration: underline; }
#depref-sum-after.is-over { color: var(--danger); }
#modalDepositRefund .aro-seg .aro-term-pill i { font-size: 15px; }
.dcn-ro-multi { white-space: pre-line; }
@media (max-width: 767.98px) {
  .depref-amounts { grid-template-columns: 1fr 1fr; }
}

/* ── Receipt cards (AP/AR): same document pattern ── */
#modalAddReceipt .modal-dialog, #modalAddARReceipt .modal-dialog { max-width: min(1240px, calc(100vw - 32px)); }
.rcp-doc-body { display: flex; flex-direction: column; gap: 16px; padding: 16px; background: var(--bg-main); }
.rcp-doc-body .form-label-custom { text-transform: none; letter-spacing: 0; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.rcp-doc-body .input-custom { min-height: 38px; }
.rcp-doc-body .input-custom:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.rcp-doc-body .select2-container .select2-selection--single { min-height: 38px; }
.rcp-amounts .form-label-custom { white-space: nowrap; }
.rcp-channels-box { border: 1px solid var(--border-color); border-radius: 12px 12px 0 0; background: var(--bg-card); padding: 12px; }
.rcp-channels { display: flex; flex-direction: column; gap: 8px; }
.rcp-attach-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.rcp-attach-list:empty { display: none; }
.rcp-file { padding: 6px 8px; font-size: 12px; }
.rcp-doc-body .aro-summary > div:first-child:empty { display: none; }
.rcp-ch-row { margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--border-color); }
/* one scrollbar: the dialog scrolls, not a 480px box inside it (older cards collapse automatically) */
#crcp-receipt-section-body, #ar-receipt-section-body { max-height: none !important; overflow: visible !important; }

/* Receipt line items */
.rcp-lines-box { border: 1px solid var(--border-color); border-radius: 12px; background: var(--bg-card); overflow-x: auto; }
.rcp-line { display: grid; grid-template-columns: 32px minmax(180px, 1fr) 80px 130px 110px 120px 120px 34px; gap: 8px; align-items: center; padding: 8px 12px; min-width: 900px; border-top: 1px solid var(--border-color); }
.rcp-line-head { border-top: 0; background: var(--bg-main); font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.rcp-line-desc { min-width: 0; }
.rcp-line-calc small { display: block; font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.rcp-doc-body .is-auto { background: var(--bg-main) !important; border-style: dashed !important; }

/* ใบเสร็จ: ราคาที่กรอก รวม / ไม่รวม VAT + ยอดรวม VAT ของรายการ */
.rcp-price-mode { margin-left: auto; margin-right: 8px; }
.rcp-price-mode[hidden] { display: none; }
.rcp-line-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
/* การ์ดใบเสร็จแคบ (ครึ่งจอ): รายการแสดง 3 แถว — รายละเอียด / จำนวน · ราคา · ส่วนลด / ยอดรวม VAT · VAT แทนตารางเลื่อนแนวนอน */
@container rcwbuilder (max-width: 760px) {
  .rcp-lines-box { overflow-x: visible; }
  .rcp-line-head { display: none !important; }
  .rcp-line { min-width: 0; grid-template-columns: 26px repeat(3, minmax(0, 1fr)) 30px; row-gap: 6px; }
  .rcp-line > .aro-line-no { grid-row: 1; grid-column: 1; }
  .rcp-line > .rcp-line-desc { grid-row: 1; grid-column: 2 / 5; }
  .rcp-line > .c-center:last-child { grid-row: 1; grid-column: 5; }
  .rcp-line > [data-l="จำนวน"] { grid-row: 2; grid-column: 2; }
  .rcp-line > [data-l="ราคา/หน่วย"] { grid-row: 2; grid-column: 3; }
  .rcp-line > [data-l="ส่วนลด (฿)"] { grid-row: 2; grid-column: 4; }
  .rcp-line > .rcp-line-amt { grid-row: 3; grid-column: 2 / 4; text-align: left; }
  .rcp-line > .rcp-line-calc { grid-row: 3; grid-column: 4; }
  .rcp-line > [data-l]::before { content: attr(data-l); display: block; margin-bottom: 2px; font-size: 10.5px; font-weight: 500; color: var(--text-muted); text-align: left; }
}

/* AR มาตรฐาน (#BUG 20261004-8): Row 1 ชื่อลูกค้า + รหัสสาขา (นิติบุคคล) · บุคคลธรรมดาไม่แสดงช่องสาขา */
.ar-party-row1 { display: flex; gap: 12px; align-items: flex-start; }
.ar-party-row1 > .aro-field:first-child { flex: 1 1 auto; min-width: 0; }
.ar-party-row1 > .ar-branch-field { flex: 0 0 132px; min-width: 0; }
.ar-party-row1 > .ar-branch-field[hidden] { display: none !important; }
.ar-branch-input { text-align: center; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
@container (max-width: 420px) { .ar-party-row1 > .ar-branch-field { flex-basis: 108px; } }

/* สถานะจับคู่ใบเสร็จ – ใบตั้งหนี้ (R-009) */
.ar-match-chip { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.ar-match-chip.is-none { background: #FFF4E0; color: #B26A00; }
.ar-match-chip.is-partial { background: #E3F2FD; color: #1565C0; }
.ar-match-chip.is-full { background: #E8F5E9; color: #1B5E20; }
.ar-match-chip.is-na { background: #F1F2F4; color: #6B7280; }
[data-theme="dark"] .ar-match-chip.is-none { background: rgba(245,158,11,.16); color: #FCD34D; }
[data-theme="dark"] .ar-match-chip.is-partial { background: rgba(59,130,246,.16); color: #93C5FD; }
[data-theme="dark"] .ar-match-chip.is-full { background: rgba(34,197,94,.16); color: #86EFAC; }
[data-theme="dark"] .ar-match-chip.is-na { background: #2B3138; color: #C6CCD3; }

/* เฟส E: มัดจำ Document-Based (R-014 / R-025 / R-026) */
.dep-role-badge, .dep-legacy-badge, .dep-taxcheck-badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; vertical-align: middle; }
.dep-role-badge { background: #EEF2FF; color: #3730A3; }
.dep-legacy-badge { background: #F1F2F4; color: #6B7280; border: 1px dashed #C6CCD3; }
.dep-taxcheck-badge { background: #FDECEC; color: #B42318; }
[data-theme="dark"] .dep-role-badge { background: rgba(99,102,241,.18); color: #C7D2FE; }
[data-theme="dark"] .dep-legacy-badge { background: #2B3138; color: #C6CCD3; border-color: #4B5563; }
[data-theme="dark"] .dep-taxcheck-badge { background: rgba(239,68,68,.16); color: #FCA5A5; }
.dep-tabs { margin: 0 0 14px; }
