/* =========================================================================
 * document.css — Order / Invoice / Purchase / Return document workspace.
 * Header block · entry grid · totals footer, sized like a desktop window.
 * ========================================================================= */
.doc-ws { height: 100%; }
.doc-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: var(--gap); }
.doc-banner { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 4px 10px; border-radius: var(--radius); font-size: 12px; font-weight: 500; border: 1px solid; }
.doc-banner.lock { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.doc-banner.new { background: var(--info-bg); border-color: var(--primary-200); color: var(--primary-700); }

/* ---- header ---- */
.doc-head { flex: 0 0 auto; }
.doc-title {
  display: flex; align-items: center; gap: 10px; padding: 5px 10px; background: linear-gradient(#f7f9fb, #edf1f5); border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0; flex-wrap: wrap; row-gap: 2px;
}
.doc-title > .bi { font-size: 17px; color: var(--primary); }
.doc-title h2 { font-size: 14px; font-weight: 700; margin: 0; color: var(--text); }
.doc-no { font-size: 13px; font-weight: 700; color: var(--primary-700); background: var(--surface); border: 1px solid var(--primary-200); padding: 0 8px; border-radius: 2px; line-height: 21px; }
.doc-dirty { display: none; color: #b8651b; font-size: 11.5px; font-weight: 600; }
.doc-ws.is-dirty .doc-dirty { display: inline-flex; align-items: center; gap: 4px; }
.doc-meta { margin-inline-start: auto; color: var(--text-3); font-size: 11px; }
.doc-head-grid { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 10px; padding: 8px 10px; }
.doc-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px 14px; align-content: start; --lw: 96px; }
.doc-fields .ff.span-2 { grid-column: span 2; }
.party-host .combo-in { background: #fffef6; }

.party-card { border: 1px solid var(--line); border-radius: 3px; background: var(--surface-2); padding: 6px 8px; font-size: 12px; align-self: start; }
.pc-head { display: flex; align-items: center; gap: 8px; padding-bottom: 5px; margin-bottom: 4px; border-bottom: 1px solid var(--line-soft); }
.pc-head > div { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.pc-head b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-head small { color: var(--text-3); font-size: 11px; }
.pc-open { color: var(--primary); font-size: 13px; }
.pc-table { width: 100%; font-size: 11.8px; }
.pc-table th { color: var(--text-3); font-weight: 500; width: 90px; padding: 1px 0; vertical-align: top; }
.pc-table td { padding: 1px 0; }
.pc-warn { margin-top: 5px; background: var(--bad-bg); color: var(--bad); border: 1px solid var(--bad-line); border-radius: 2px; padding: 3px 6px; font-size: 11.5px; font-weight: 600; }
.pc-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--text-3); min-height: 92px; text-align: center; }
.pc-empty .bi { font-size: 26px; color: var(--line-strong); }
.pc-empty small kbd, .pc-empty small { font-size: 10.5px; }
.ret-hint { display: flex; gap: 8px; color: var(--text-2); line-height: 1.5; background: var(--info-bg); border-color: var(--primary-200); }
.ret-hint .bi { color: var(--primary); font-size: 16px; }

/* ---- lines ---- */
.doc-lines { flex: 1 1 auto; min-height: 170px; display: flex; flex-direction: column; overflow: hidden; }
.doc-lines.is-invalid { border-color: var(--bad); box-shadow: 0 0 0 2px rgba(176,39,31,.15); }
.doc-lines-scroll { flex: 1 1 auto; overflow: auto; min-height: 0; outline: none; }
.lines-table { table-layout: fixed; min-width: 980px; }
.lines-table thead th { position: sticky; top: 0; z-index: 2; }
.lines-table .c-no { width: 38px; text-align: center; color: var(--text-3); }
.lines-table .c-chk { width: 34px; text-align: center; }
.lines-table .c-code { width: 78px; }
.lines-table .c-prod { width: auto; }
.lines-table .c-qty { width: 92px; }
.lines-table .c-unit { width: 118px; }
.lines-table .c-price { width: 104px; }
.lines-table .c-disc { width: 70px; }
.lines-table .c-total { width: 116px; }
.lines-table .c-stock { width: 150px; }
.lines-table .c-act { width: 32px; text-align: center; padding: 0; }
.lines-table tbody tr.ln td { height: 34px; padding-block: 2px; }
.ln-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25; }
.ln-sub { font-size: 10.5px; color: var(--text-3); line-height: 1.2; }
.cell-in {
  width: 100%; height: 26px; border: 1px solid transparent; background: transparent; border-radius: 2px; padding: 0 6px; font-size: 12.5px; color: var(--text);
  font-variant-numeric: tabular-nums;
}
select.cell-in { padding: 0 2px; cursor: pointer; }
.cell-in.num { text-align: end; font-weight: 600; }
tr.ln:hover .cell-in:not(:disabled) { border-color: var(--line); background: var(--surface); }
.cell-in:focus { outline: none; border-color: var(--primary) !important; background: #fff !important; box-shadow: var(--focus-ring); }
.cell-in.warn { color: var(--warn); background: var(--warn-bg); }
.cell-in.is-invalid { border-color: var(--bad) !important; background: var(--bad-bg) !important; }
.cell-in:disabled { color: var(--text); -webkit-text-fill-color: var(--text); opacity: 1; }
.ln-total { font-variant-numeric: tabular-nums; }
.ln-del { border: 0; background: transparent; color: var(--text-3); width: 24px; height: 24px; border-radius: 2px; }
.ln-del:hover { background: var(--bad-bg); color: var(--bad); }
.ln-add { border: 1px solid var(--primary-200); background: var(--surface); color: var(--primary); width: 22px; height: 20px; border-radius: 2px; padding: 0; display: inline-grid; place-items: center; font-size: 12px; }
.ln-add:hover { background: var(--primary); color: #fff; }
.cell-in.code-in { font-family: var(--font-mono); font-size: 12px; padding: 0 4px; }
tr.ln:focus-within td { background: #f1f6fd !important; }
tr.ret-on td { background: #f2f8f1 !important; }

.ln-entry td { background: var(--entry-bg) !important; border-top: 1px solid var(--entry-line); border-bottom: 1px solid var(--entry-line); height: 36px; }
.ln-entry .c-no { color: #b99a1d; }
.entry-wrap { display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--entry-line); border-radius: 2px; height: 28px; padding-inline: 8px 2px; }
.entry-wrap:focus-within { border-color: var(--primary); box-shadow: var(--focus-ring); }
.entry-wrap > .bi { color: #a88a12; }
.entry-in { flex: 1; border: 0; outline: none; background: transparent; height: 100%; font-size: 12.8px; font-weight: 600; min-width: 0; }
.entry-in::placeholder { font-weight: 400; color: #9a8a4e; }
.entry-lk { border: 1px solid var(--line); background: var(--surface-2); height: 22px; font-size: 11px; border-radius: 2px; padding: 0 6px; color: var(--primary); white-space: nowrap; }
.entry-hint { color: #8c7a36; font-size: 11px; }

/* ---- footer ---- */
.doc-foot { flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 12px; padding: 8px 10px; }
.foot-summary { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sum-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
.sum-grid > div { display: flex; flex-direction: column; padding: 4px 8px; border-inline-end: 1px solid var(--line-soft); background: var(--surface-2); min-width: 0; }
.sum-grid > div:last-child { border-inline-end: 0; }
.sum-grid span { font-size: 10.5px; color: var(--text-3); }
.sum-grid b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notes-ff { --lw: 70px; align-items: start; }
.totals { width: 100%; border: 1px solid var(--line); border-radius: 3px; border-collapse: separate; border-spacing: 0; overflow: hidden; font-size: 12.5px; }
.totals th { font-weight: 500; color: var(--text-2); padding: 2px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line-soft); white-space: nowrap; width: 55%; }
.totals td { text-align: end; padding: 2px 10px; border-bottom: 1px solid var(--line-soft); font-weight: 600; font-variant-numeric: tabular-nums; height: 25px; }
.totals td .form-control { height: 22px; min-height: 22px; padding: 0 6px; font-weight: 600; text-align: end; }
.totals .neg { color: var(--bad); }
.totals tr.grand th, .totals tr.grand td { background: var(--titlebar-2); color: #fff; font-size: 15px; font-weight: 700; height: 32px; border-bottom: 0; }
.totals tr.grand td small { font-size: 11px; font-weight: 500; opacity: .8; }
.totals tr.remain td { font-size: 13px; }
.totals tr.remain.due td, .totals tr.remain.due th { color: var(--bad); background: var(--bad-bg); }
.tax-toggle { display: inline-flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; }
.tax-toggle .form-check-input { margin: 0; }
