@import url('https://fonts.googleapis.com/css2?family=Bai+Jamjuree:wght@300;400;500;600;700&display=swap');
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Bai Jamjuree', sans-serif; background: #eef3f9; color: #111827; font-size: 14px; }
.container { max-width: 1400px; margin: 0 auto; padding: 0 40px; }
.topbar { background: #17253d; color: #fff; padding: 20px 0; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar-inner { display: flex; align-items: center; gap: 20px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: rgba(255,255,255,0.75); text-decoration: none; font-size: 13px; padding: 6px 12px; border-radius: 6px; transition: all 0.2s; }
.back-link:hover { background: rgba(255,255,255,0.1); color: #fff; }
.main { padding: 28px 0; }
.tabs { display: flex; gap: 30px; border-bottom: 1px solid #d9e1ec; margin-bottom: 20px; }
.tab { text-decoration: none; color: #39465d; padding: 10px 20px 12px; font-size: 14px; }
.tab.active { color: #1f4bc2; border-bottom: 3px solid #1f4bc2; font-weight: 700; }
.sub-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.sub-tab { text-decoration: none; color: #475569; padding: 8px 18px; font-size: 13px; border-radius: 20px; background: #f1f5f9; transition: all 0.2s; }
.sub-tab:hover { background: #e2e8f0; }
.sub-tab.active { background: #1f4bc2; color: #fff; font-weight: 500; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0; }
.summary-grid-4 { grid-template-columns: repeat(4, 1fr); }
.summary-grid-3 { grid-template-columns: repeat(3, 1fr); }
.summary-card { background: #fff; border-radius: 9px; padding: 18px 14px; box-shadow: 0 1px 4px rgba(0,0,0,.04); }
.summary-card span { display: block; font-size: 12px; margin-bottom: 5px; }
.summary-card strong { font-size: 20px; }
.green { color: #04b96b; }
.red { color: #e4002b; }
.blue { color: #1f4bc2; }
.action-row { display: flex; justify-content: flex-end; margin: 18px 0 14px; }
.add-btn { background: #2448b8; color: #fff; border: 0; border-radius: 6px; width: 40px; height: 26px; font-size: 22px; cursor: pointer; }
.table-card { background: #fff; border-radius: 9px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.04); }
table { width: 100%; border-collapse: collapse; }
th { background: #fafafa; font-size: 13px; text-align: left; padding: 13px; }
td { padding: 12px 13px; border-top: 1px solid #eef1f5; font-size: 14px; }
.empty { text-align: center; color: #8790a6; font-style: italic; padding: 30px; }
.empty-state { text-align: center; padding: 60px 20px; }
.empty-icon { margin-bottom: 16px; }
.empty-title { font-size: 18px; font-weight: 600; color: #334155; margin-bottom: 8px; }
.empty-desc { font-size: 14px; color: #94a3b8; }
.badge { padding: 5px 9px; border-radius: 999px; font-size: 12px; }
.badge.paid { background: #dcfce7; color: #15803d; }
.badge.debt { background: #fee2e2; color: #b91c1c; }
.actions { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
button { border: 0; border-radius: 5px; background: #e8eef8; padding: 6px 10px; cursor: pointer; }
button.delete { background: #fee2e2; color: #b91c1c; }
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); align-items: center; justify-content: center; padding: 20px; }
.modal.show { display: flex; }
.modal-content { background: #fff; border-radius: 12px; padding: 22px; width: 520px; max-width: 100%; }
.modal-content.small { width: 360px; }
.modal-content h2 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid label { font-size: 12px; color: #4b5563; }
input { width: 100%; padding: 10px; border: 1px solid #d7dce6; border-radius: 7px; }
.modal-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.modal-actions button[type="submit"] { background: #2448b8; color: #fff; }
@media (max-width: 700px) {
  .container { padding-left: 14px; padding-right: 14px; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-grid-4 { grid-template-columns: 1fr; }
  .summary-grid-3 { grid-template-columns: 1fr; }
  .table-card { overflow-x: auto; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ===== Document Form (ใบวางบิล) ===== */
.doc-card { background: #fff; border-radius: 9px; padding: 24px; box-shadow: 0 1px 4px rgba(0,0,0,.04); }
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.doc-title { margin: 0; font-size: 24px; font-weight: 700; color: #17253d; }
.doc-meta { display: flex; gap: 16px; }
.doc-field { display: flex; flex-direction: column; gap: 4px; }
.doc-field label { font-size: 12px; color: #64748b; font-weight: 500; }
.doc-field input { padding: 8px 10px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 14px; width: auto; min-width: 140px; }
.doc-field input[readonly] { background: #f1f5f9; color: #475569; }
.doc-field input.doc-status-field { min-width: 110px; width: 110px; text-align: center; }
.doc-date-picker { font-family: inherit; min-width: 150px !important; cursor: pointer; }
.doc-date-picker::-webkit-calendar-picker-indicator { cursor: pointer; opacity: 0.7; }
.doc-date-picker::-webkit-calendar-picker-indicator:hover { opacity: 1; }
.doc-debtor { display: flex; gap: 20px; align-items: flex-start; margin: 20px 0; flex-wrap: wrap; }
.deposit-info-row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 18px; }
.deposit-info-row select { padding: 8px 10px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 14px; min-width: 140px; font-family: inherit; background: #fff; }
.doc-address { flex: 1; min-width: 240px; padding: 8px 10px; border: 1px solid #d7dce6; border-radius: 6px; font-family: inherit; font-size: 13px; resize: vertical; }
.customer-search { position: relative; }
.customer-search input { padding: 8px 10px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 14px; min-width: 240px; }
.customer-results { display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: #fff; border: 1px solid #d7dce6; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto; z-index: 20; }
.customer-results.show { display: block; }
.customer-item { display: flex; gap: 10px; align-items: center; padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f1f5f9; }
.customer-item:hover { background: #eff4ff; }
.ci-code { color: #1f4bc2; font-weight: 600; min-width: 64px; }
.ci-name { color: #334155; }
.customer-empty { padding: 12px; font-size: 13px; color: #94a3b8; text-align: center; }
.debtor-picker .customer-search input { min-width: 280px; }
.debtor-picker .customer-search input:focus { outline: none; border-color: #334155; box-shadow: 0 0 0 2px rgba(51,65,85,.08); }
.debtor-results { border: 1px solid #334155; border-radius: 4px; max-height: 280px; }
.debtor-item { display: block; padding: 9px 14px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #e5e7eb; text-align: right; }
.debtor-item:last-child { border-bottom: 0; }
.debtor-item:hover { background: #eff4ff; }
.debtor-item .di-code { color: #1f4bc2; font-weight: 600; margin-left: 8px; }
.debtor-item .di-name { color: #334155; }
.date-range { display: flex; align-items: center; gap: 8px; }
.date-range input { padding: 8px 10px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 14px; }
.date-sep { font-size: 13px; color: #64748b; }
.filter-bar { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 18px; }
.filter-bar .doc-field select { padding: 8px 10px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 14px; min-width: 160px; font-family: inherit; background: #fff; }
.filter-bar .btn-save { height: 38px; }
.rv-search-row { cursor: pointer; }
.rv-search-row:hover td { background: #f8fafc; }
.pv-search-row { cursor: pointer; }
.pv-search-row:hover td { background: #f8fafc; }
.qop-search-row { cursor: pointer; }
.qop-search-row:hover td { background: #f8fafc; }
.tr-search-row { cursor: pointer; }
.tr-search-row:hover td { background: #f8fafc; }
#pvDetailBody tr.pv-row-active td { background: #eff6ff; }
#rvDetailBody tr.rv-row-active td { background: #eff6ff; }
.multi-select { position: relative; min-width: 180px; }
.multi-select-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 14px; background: #fff; cursor: pointer; min-width: 180px; }
.multi-select-menu { display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: #fff; border: 1px solid #d7dce6; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto; z-index: 30; padding: 6px; }
.multi-select-menu.show { display: block; }
.multi-option { display: flex; align-items: center; gap: 8px; padding: 7px 10px; font-size: 13px; border-radius: 6px; cursor: pointer; }
.multi-option:hover { background: #eff4ff; }
.multi-option input[type="checkbox"] { width: 16px !important; min-width: 16px; height: 16px; flex: 0 0 auto; padding: 0; margin: 0; }
.multi-option span { flex: 1; color: #334155; white-space: nowrap; }
.multi-divider { height: 1px; background: #eef1f5; margin: 4px 0; }
.inner-tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid #e2e8f0; }
.inner-tab { padding: 8px 16px; font-size: 13px; color: #64748b; cursor: pointer; border-bottom: 2px solid transparent; }
.inner-tab.active { color: #1f4bc2; border-bottom-color: #1f4bc2; font-weight: 600; }
.doc-table-wrap { border: 1px solid #d7dce6; border-radius: 8px; overflow-x: auto; }
.doc-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.doc-table th { background: #f1f5f9; font-size: 13px; font-weight: 600; color: #334155; padding: 10px 12px; text-align: left; border-bottom: 1px solid #d7dce6; white-space: nowrap; }
.doc-table td { padding: 9px 12px; font-size: 13px; border-bottom: 1px solid #eef1f5; white-space: nowrap; }
.doc-table tbody tr:hover { background: #f8fafc; }
.doc-table .num { text-align: right; }
.doc-table .center { text-align: center; }
.doc-table .date-cell { color: #0e7490; font-weight: 500; }
.doc-table tfoot td { padding: 10px 12px; font-size: 13px; border-top: 2px solid #d7dce6; background: #f8fafc; }
.doc-table .red { color: #dc2626; }
.doc-table input[type="checkbox"] { width: auto; }
.doc-footer { display: flex; justify-content: space-between; gap: 20px; margin-top: 18px; flex-wrap: wrap; }
.doc-note { flex: 1; min-width: 260px; padding: 10px; border: 1px solid #d7dce6; border-radius: 6px; font-family: inherit; font-size: 13px; color: #b91c1c; resize: vertical; }
.doc-summary { display: flex; flex-direction: column; gap: 10px; align-items: flex-end; justify-content: center; min-width: 260px; }
.summary-line { display: flex; align-items: center; gap: 14px; }
.summary-line span { font-size: 14px; color: #475569; }
.summary-line strong { font-size: 20px; color: #17253d; }
.link { color: #1f4bc2; font-size: 13px; text-decoration: none; }
.link:hover { text-decoration: underline; }
.check-line { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #475569; cursor: pointer; }
.check-line input { width: auto; }
.doc-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 20px; padding-top: 16px; border-top: 1px solid #eef1f5; flex-wrap: wrap; }
.doc-actions-left { display: flex; gap: 18px; align-items: center; }
.doc-actions-right { display: flex; gap: 10px; align-items: center; }
.btn-save-close, .btn-save, .btn-add-row, .btn-cancel { padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer; border: 0; }
.btn-save-close { background: #dcfce7; color: #15803d; }
.btn-save, .btn-add-row { background: #2448b8; color: #fff; }
.btn-cancel { background: #fee2e2; color: #b91c1c; }
.btn-del-row {
  padding: 4px 8px;
  border: 0;
  border-radius: 4px;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 12px;
  cursor: pointer;
  line-height: 1.2;
}
.btn-del-row:hover { background: #fecaca; }

/* ===== รายละเอียดชำระ (Payment Detail) ===== */
.pay-detail { display: flex; gap: 28px; flex-wrap: wrap; }
.pay-detail-left { flex: 1; min-width: 420px; }
.pay-detail-right { width: 360px; }
.pay-section-title { font-size: 15px; font-weight: 600; color: #334155; margin: 0 0 16px; padding-bottom: 8px; border-bottom: 1px solid #e2e8f0; }
.pay-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pay-row > label { width: 120px; font-size: 13px; color: #475569; flex: 0 0 auto; }
.pay-row.sub > label { width: 120px; text-align: right; padding-right: 6px; color: #64748b; }
.pay-row select { flex: 1; padding: 7px 9px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 13px; font-family: inherit; background: #fff; min-width: 0; }
.pay-row select:disabled { background: #f1f5f9; color: #94a3b8; }
.num-input { width: 120px; flex: 0 0 auto; padding: 7px 9px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 13px; text-align: right; }
.num-input.opening-editable { background: #fff; color: #0f172a; border-color: #0b6e4f; box-shadow: inset 0 0 0 1px #0b6e4f; }
.doc-field input.num-input.opening-editable { background: #fff; color: #0f172a; }
.num-input.sm { width: 90px; }
.tiny-input { width: 44px; flex: 0 0 auto; padding: 7px 6px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 13px; }
.ref-input { flex: 1; padding: 7px 9px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 13px; }
.exchange { font-size: 12px; color: #64748b; }
.pay-cheque-head { display: grid; grid-template-columns: 130px 1fr 1fr 120px; gap: 8px; margin-bottom: 6px; }
.pay-cheque-head label, .pay-cheque-head span { font-size: 12px; color: #64748b; }
.pay-cheque-row { display: grid; grid-template-columns: 130px 1fr 1fr 120px; gap: 8px; margin-bottom: 8px; }
.pay-cheque-row select, .pay-cheque-row input { padding: 7px 9px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 13px; font-family: inherit; min-width: 0; }
.pay-cheque-row input[type="text"], .pay-cheque-row .num-input { text-align: right; }
.pay-summary-box { border: 1px solid #d7dce6; border-radius: 8px; padding: 18px 20px; }
.pay-summary-box legend { font-size: 13px; color: #475569; padding: 0 8px; }
.psum-line { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 0; font-size: 14px; }
.psum-line span { color: #475569; }
.psum-line strong { font-size: 15px; color: #17253d; }
.psum-divider { height: 1px; background: #e2e8f0; margin: 8px 0; }
.psum-foot { text-align: right; margin-top: 8px; }

/* ===== Report Layout ===== */
.report-layout { display: flex; gap: 16px; margin-bottom: 16px; }
.report-sidebar { width: 200px; flex: 0 0 200px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px; max-height: 400px; overflow-y: auto; }
.report-content { flex: 1; overflow-x: auto; }
.tree-list { font-size: 13px; }
.tree-year { font-weight: 600; padding: 4px 0; cursor: pointer; color: #334155; }
.tree-month, .tree-day, .tree-item { padding: 3px 0; cursor: pointer; color: #475569; }
.tree-month:hover, .tree-day:hover, .tree-item:hover { color: #1f4bc2; }
.tree-month.active, .tree-day.active, .tree-item.active { color: #1f4bc2; font-weight: 600; }

/* ===== Loading Spinner ===== */
.loading-spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid #e2e8f0; border-top-color: #1f4bc2; border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Dropdown in Table (rv-code-select) ===== */
.rv-code-select { width: 100%; padding: 6px 28px 6px 10px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 13px; font-family: inherit; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='%2364748b'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") no-repeat right 8px center; appearance: none; -webkit-appearance: none; cursor: pointer; transition: border-color 0.2s, box-shadow 0.2s; min-width: 130px; }
.apo-party-row { display: flex; gap: 24px; align-items: flex-start; margin: 0 0 18px; flex-wrap: wrap; }
.apo-party-left { flex: 1; min-width: 360px; display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.apo-party-right { min-width: 180px; padding-top: 2px; }
.apo-party-right select { padding: 8px 10px; border: 1px solid #d7dce6; border-radius: 6px; font-size: 14px; min-width: 140px; font-family: inherit; background: #fff; }
.apo-totals-box { border: 1px solid #d7dce6; border-radius: 8px; padding: 14px 18px; min-width: 300px; background: #fff; }
.apo-totals-box .psum-line strong { min-width: 110px; text-align: right; }
.doc-table .apo-row-selected { background: #dbeafe !important; }
.doc-table .cell-input { width: 100%; min-width: 70px; padding: 4px 6px; border: 1px solid #d7dce6; border-radius: 4px; font-size: 12px; font-family: inherit; }
.doc-table .cell-input.num { text-align: right; }
.doc-card .table-card { box-shadow: none; border: 1px solid #e2e8f0; margin-bottom: 0; }
.doc-card .summary-grid { margin-top: 0; }
.hidden-row { display: none; }
.vat-table-card { overflow-x: auto; }
.vat-report-table { min-width: 1100px; }
.vat-report-table .num { text-align: right; white-space: nowrap; }
.vat-report-table .center { text-align: center; }
.vat-report-table .vat-desc { min-width: 220px; max-width: 360px; white-space: normal; }
.vat-report-table td.negative,
.vat-report-table .num.negative { color: #dc2626; }
.rv-code-select:focus { outline: none; border-color: #1f4bc2; box-shadow: 0 0 0 3px rgba(31,75,194,0.1); }
